Skip to content

Commit

Permalink
Remove forwardRef.
Browse files Browse the repository at this point in the history
  • Loading branch information
novykh committed Dec 18, 2024
1 parent 35965ad commit dacc9aa
Show file tree
Hide file tree
Showing 27 changed files with 1,525 additions and 1,636 deletions.
90 changes: 43 additions & 47 deletions src/components/button/button.js
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>
)
28 changes: 13 additions & 15 deletions src/components/button/iconButton.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { forwardRef } from "react"
import React from "react"
import Box from "@/components/templates/box"
import Flex from "@/components/templates/flex"
import Tooltip from "@/components/drops/tooltip"
Expand All @@ -11,20 +11,18 @@ const CustomTooltipContent = ({ content }) => (
</Flex>
)

const IconButton = forwardRef(
({ width = "14px", height = "14px", tooltip = "", ...props }, ref) => (
<Tooltip plain animation content={tooltip && <CustomTooltipContent content={tooltip} />}>
<Box
as={Button}
iconWidth={width}
iconHeight={height}
ref={ref}
flavour="borderless"
neutral
{...props}
/>
</Tooltip>
)
const IconButton = ({ width = "14px", height = "14px", tooltip = "", ref, ...props }) => (
<Tooltip plain animation content={tooltip && <CustomTooltipContent content={tooltip} />}>
<Box
as={Button}
iconWidth={width}
iconHeight={height}
ref={ref}
flavour="borderless"
neutral
{...props}
/>
</Tooltip>
)

export default IconButton
128 changes: 62 additions & 66 deletions src/components/checkbox/checkbox.js
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>
)
}
Loading

0 comments on commit dacc9aa

Please sign in to comment.