diff --git a/packages/twenty-front/src/modules/ui/input/components/Checkbox.tsx b/packages/twenty-front/src/modules/ui/input/components/Checkbox.tsx index f3d6df936..aa6e4d19a 100644 --- a/packages/twenty-front/src/modules/ui/input/components/Checkbox.tsx +++ b/packages/twenty-front/src/modules/ui/input/components/Checkbox.tsx @@ -22,39 +22,63 @@ export enum CheckboxSize { type CheckboxProps = { checked: boolean; indeterminate?: boolean; + hoverable?: boolean; onChange?: (event: React.ChangeEvent) => void; onCheckedChange?: (value: boolean) => void; variant?: CheckboxVariant; size?: CheckboxSize; shape?: CheckboxShape; className?: string; + disabled?: boolean; }; -const StyledInputContainer = styled.div` - align-items: center; - display: flex; - position: relative; -`; - type InputProps = { checkboxSize: CheckboxSize; variant: CheckboxVariant; indeterminate?: boolean; + hoverable?: boolean; shape?: CheckboxShape; isChecked?: boolean; + disabled?: boolean; }; +const StyledInputContainer = styled.div` + --size: ${({ checkboxSize }) => + checkboxSize === CheckboxSize.Large ? '32px' : '24px'}; + align-items: center; + border-radius: ${({ theme, shape }) => + shape === CheckboxShape.Rounded + ? theme.border.radius.rounded + : theme.border.radius.sm}; + + cursor: ${({ disabled }) => (disabled ? 'not-allowed' : 'pointer')}; + display: flex; + padding: ${({ checkboxSize }) => + checkboxSize === CheckboxSize.Large ? '6px' : '5px'}; + position: relative; + ${({ hoverable, isChecked, theme, indeterminate, disabled }) => { + if (!hoverable || disabled === true) return ''; + return `&:hover{ + background-color: ${ + indeterminate || isChecked + ? theme.color.blue10 + : theme.background.transparent.light + }; + }} + }`; + }} +`; + const StyledInput = styled.input` - cursor: pointer; + cursor: ${({ disabled }) => (disabled ? 'not-allowed' : 'pointer')}; margin: 0; opacity: 0; position: absolute; z-index: 10; - & + label { --size: ${({ checkboxSize }) => checkboxSize === CheckboxSize.Large ? '18px' : '12px'}; - cursor: pointer; + cursor: ${({ disabled }) => (disabled ? 'not-allowed' : 'pointer')}; height: calc(var(--size) + 2px); padding: 0; position: relative; @@ -66,8 +90,16 @@ const StyledInput = styled.input` checkboxSize === CheckboxSize.Large ? '18px' : '12px'}; background: ${({ theme, indeterminate, isChecked }) => indeterminate || isChecked ? theme.color.blue : 'transparent'}; - border-color: ${({ theme, indeterminate, isChecked, variant }) => { + border-color: ${({ + theme, + indeterminate, + isChecked, + variant, + disabled, + }) => { switch (true) { + case disabled: + return theme.background.transparent.medium; case indeterminate || isChecked: return theme.color.blue; case variant === CheckboxVariant.Primary: @@ -83,21 +115,21 @@ const StyledInput = styled.input` ? theme.border.radius.rounded : theme.border.radius.sm}; border-style: solid; - border-width: ${({ variant }) => - variant === CheckboxVariant.Tertiary ? '2px' : '1px'}; + border-width: ${({ variant, checkboxSize }) => + checkboxSize === CheckboxSize.Large || + variant === CheckboxVariant.Tertiary + ? '1.43px' + : '1px'}; content: ''; - cursor: pointer; + cursor: ${({ disabled }) => (disabled ? 'not-allowed' : 'pointer')}; display: inline-block; height: var(--size); width: var(--size); } & + label > svg { - --padding: ${({ checkboxSize, variant }) => - checkboxSize === CheckboxSize.Large || - variant === CheckboxVariant.Tertiary - ? '2px' - : '1px'}; + --padding: ${({ checkboxSize }) => + checkboxSize === CheckboxSize.Large ? '2px' : '1px'}; --size: ${({ checkboxSize }) => checkboxSize === CheckboxSize.Large ? '16px' : '12px'}; height: var(--size); @@ -117,7 +149,9 @@ export const Checkbox = ({ variant = CheckboxVariant.Primary, size = CheckboxSize.Small, shape = CheckboxShape.Squared, + hoverable = false, className, + disabled = false, }: CheckboxProps) => { const [isInternalChecked, setIsInternalChecked] = React.useState(false); @@ -135,7 +169,16 @@ export const Checkbox = ({ const checkboxId = 'checkbox' + v4(); return ( - +