-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,525 additions
and
1,636 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,50 @@ | ||
import React, { forwardRef } from "react" | ||
import React from "react" | ||
import { StyledButton } from "./styled" | ||
import { Icon } from "@/components/icon" | ||
import { LoaderIcon } from "@/components/icon/components" | ||
import Flex from "@/components/templates/flex" | ||
|
||
export const Button = forwardRef( | ||
( | ||
{ | ||
label, | ||
icon = null, | ||
flavour, | ||
isLoading, | ||
loadingLabel, | ||
onClick = () => {}, | ||
textTransform = "firstLetter", | ||
iconColor, | ||
iconSize, | ||
iconWidth, | ||
iconHeight, | ||
children = label, | ||
...rest | ||
}, | ||
ref | ||
) => ( | ||
<StyledButton | ||
flavour={flavour} | ||
textTransform={textTransform} | ||
hasIcon={!!icon || isLoading} | ||
onClick={isLoading ? undefined : onClick} | ||
ref={ref} | ||
iconColor={iconColor} | ||
iconWidth={iconWidth} | ||
iconHeight={iconHeight} | ||
{...rest} | ||
> | ||
{isLoading && <LoaderIcon className="button-icon" />} | ||
{icon && !isLoading && ( | ||
<Flex justifyContent="center" alignItems="center" width="auto" height="100%"> | ||
<Icon | ||
size={iconSize} | ||
className="button-icon" | ||
title={icon} | ||
name={icon} | ||
width={iconWidth} | ||
height={iconHeight} | ||
/> | ||
</Flex> | ||
)} | ||
export const Button = ({ | ||
label, | ||
icon = null, | ||
flavour, | ||
isLoading, | ||
loadingLabel, | ||
onClick = () => {}, | ||
textTransform = "firstLetter", | ||
iconColor, | ||
iconSize, | ||
iconWidth, | ||
iconHeight, | ||
children = label, | ||
ref, | ||
...rest | ||
}) => ( | ||
<StyledButton | ||
flavour={flavour} | ||
textTransform={textTransform} | ||
hasIcon={!!icon || isLoading} | ||
onClick={isLoading ? undefined : onClick} | ||
ref={ref} | ||
iconColor={iconColor} | ||
iconWidth={iconWidth} | ||
iconHeight={iconHeight} | ||
{...rest} | ||
> | ||
{isLoading && <LoaderIcon className="button-icon" />} | ||
{icon && !isLoading && ( | ||
<Flex justifyContent="center" alignItems="center" width="auto" height="100%"> | ||
<Icon | ||
size={iconSize} | ||
className="button-icon" | ||
title={icon} | ||
name={icon} | ||
width={iconWidth} | ||
height={iconHeight} | ||
/> | ||
</Flex> | ||
)} | ||
|
||
{!!children && <span>{(isLoading && loadingLabel) || children}</span>} | ||
</StyledButton> | ||
) | ||
{!!children && <span>{(isLoading && loadingLabel) || children}</span>} | ||
</StyledButton> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,71 @@ | ||
import React, { forwardRef } from "react" | ||
import React from "react" | ||
import { Text } from "@/components/typography" | ||
import { Icon } from "@/components/icon" | ||
import Box from "@/components/templates/box" | ||
import Flex from "@/components/templates/flex" | ||
import { HiddenCheckboxInput, Checkbox as StyledCheckbox } from "./styled" | ||
|
||
export const Checkbox = forwardRef( | ||
( | ||
{ | ||
checked, | ||
disabled, | ||
iconProps, | ||
indeterminate, | ||
Label = Text, | ||
label, | ||
labelProps, | ||
labelPosition = "right", | ||
onChange, | ||
...rest | ||
}, | ||
ref | ||
) => { | ||
const onClick = e => { | ||
e.preventDefault() | ||
export const Checkbox = ({ | ||
checked, | ||
disabled, | ||
iconProps, | ||
indeterminate, | ||
Label = Text, | ||
label, | ||
labelProps, | ||
labelPosition = "right", | ||
onChange, | ||
ref, | ||
...rest | ||
}) => { | ||
const onClick = e => { | ||
e.preventDefault() | ||
|
||
if (disabled) return | ||
if (disabled) return | ||
|
||
onChange?.(!checked, e) | ||
} | ||
|
||
return ( | ||
<Flex | ||
as="label" | ||
position="relative" | ||
alignItems="center" | ||
gap={1} | ||
cursor={disabled ? "auto" : "pointer"} | ||
rowReverse={labelPosition === "right"} | ||
data-testid="checkbox" | ||
disabled={disabled} | ||
{...rest} | ||
onClick={onClick} | ||
> | ||
{label && ( | ||
<Text as={Label} opacity={disabled ? 0.4 : 1} {...labelProps}> | ||
{label} | ||
</Text> | ||
)} | ||
<Box width="16px" height="16px"> | ||
<HiddenCheckboxInput | ||
data-testid="checkbox-input" | ||
ref={ref} | ||
disabled={disabled} | ||
{...(indeterminate && { "data-indeterminate": true })} | ||
data-checked={checked} | ||
/> | ||
<StyledCheckbox data-testid="styled-checkbox" disabled={disabled}> | ||
{(!!checked || !!indeterminate) && ( | ||
<Icon | ||
disabled={disabled} | ||
name={indeterminate ? "checkmark_partial_s" : "checkmark_s"} | ||
width="16px" | ||
height="16px" | ||
color="accent" | ||
hoverColor="primary" | ||
{...iconProps} | ||
/> | ||
)} | ||
</StyledCheckbox> | ||
</Box> | ||
</Flex> | ||
) | ||
onChange?.(!checked, e) | ||
} | ||
) | ||
|
||
return ( | ||
<Flex | ||
as="label" | ||
position="relative" | ||
alignItems="center" | ||
gap={1} | ||
cursor={disabled ? "auto" : "pointer"} | ||
rowReverse={labelPosition === "right"} | ||
data-testid="checkbox" | ||
disabled={disabled} | ||
{...rest} | ||
onClick={onClick} | ||
> | ||
{label && ( | ||
<Text as={Label} opacity={disabled ? 0.4 : 1} {...labelProps}> | ||
{label} | ||
</Text> | ||
)} | ||
<Box width="16px" height="16px"> | ||
<HiddenCheckboxInput | ||
data-testid="checkbox-input" | ||
ref={ref} | ||
disabled={disabled} | ||
{...(indeterminate && { "data-indeterminate": true })} | ||
data-checked={checked} | ||
/> | ||
<StyledCheckbox data-testid="styled-checkbox" disabled={disabled}> | ||
{(!!checked || !!indeterminate) && ( | ||
<Icon | ||
disabled={disabled} | ||
name={indeterminate ? "checkmark_partial_s" : "checkmark_s"} | ||
width="16px" | ||
height="16px" | ||
color="accent" | ||
hoverColor="primary" | ||
{...iconProps} | ||
/> | ||
)} | ||
</StyledCheckbox> | ||
</Box> | ||
</Flex> | ||
) | ||
} |
Oops, something went wrong.