Skip to content

Commit

Permalink
feat(suite): Add cursor: not-allowed to disabled components (#12945)
Browse files Browse the repository at this point in the history
  • Loading branch information
hstastna authored and Hilda Stastna committed Jul 1, 2024
1 parent 49e0bfd commit 204416f
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,37 @@ export default meta;
export const Button: StoryObj<ButtonProps> = {
args: {
children: 'Button label',
variant: 'primary',
size: 'medium',
isDisabled: false,
isLoading: false,
isFullWidth: false,
iconAlignment: 'left',
title: 'Button title',
...framePropsStory.args,
},
argTypes: framePropsStory.argTypes,
argTypes: {
variant: {
control: {
type: 'radio',
},
options: ['primary', 'secondary', 'tertiary', 'info', 'warning', 'destructive'],
},
size: {
control: {
type: 'radio',
},
options: ['large', 'medium', 'small', 'tiny'],
},
icon: { control: 'text' },
iconSize: { control: 'number' },
iconAlignment: {
control: {
type: 'radio',
},
options: ['left', 'right'],
},
title: { control: 'text' },
...framePropsStory.argTypes,
},
};
4 changes: 2 additions & 2 deletions packages/components/src/components/buttons/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ export const ButtonContainer = styled.button<ButtonContainerProps>`
&:disabled {
background: ${({ theme }) => theme.BG_GREY};
color: ${({ theme }) => theme.textDisabled};
pointer-events: none;
cursor: default;
cursor: not-allowed;
}
${withFrameProps}
Expand Down Expand Up @@ -142,6 +141,7 @@ export const Button = ({
$hasIcon={!!icon || isLoading}
$elevation={elevation}
{...rest}
onClick={isDisabled ? undefined : rest?.onClick}
{...makePropsTransient(frameProps)}
>
{!isLoading && icon && IconComponent}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,26 @@ export const Checkbox: StoryObj<CheckboxProps> = {
},
args: {
children: 'Checkbox',
variant: 'primary',
isChecked: false,
isDisabled: false,
labelAlignment: 'right',
...framePropsStory.args,
},

argTypes: framePropsStory.argTypes,
argTypes: {
variant: {
control: {
type: 'radio',
},
options: ['primary', 'warning', 'destructive'],
},
labelAlignment: {
control: {
type: 'radio',
},
options: ['left', 'right'],
},
...framePropsStory.argTypes,
},
};
20 changes: 14 additions & 6 deletions packages/components/src/components/form/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,22 @@ export const CheckContainer = styled.div<{ $variant: CheckboxVariant }>`
background 0.1s,
box-shadow 0.1s ease-out;
input:checked + && {
input:checked + & {
background: ${({ theme, $variant }) => theme[variantStyles[$variant].backgroundChecked]};
border-color: ${({ theme, $variant }) => theme[variantStyles[$variant].borderChecked]};
}
input:disabled:not(:checked) + && {
input:disabled + & {
cursor: not-allowed;
pointer-events: auto;
}
input:disabled:not(:checked) + & {
background: ${({ theme, $variant }) => theme[variantStyles[$variant].backgroundDisabled]};
border-color: ${({ theme, $variant }) => theme[variantStyles[$variant].borderDisabled]};
}
input:disabled:checked + && {
input:disabled:checked + & {
background: ${({ theme, $variant }) =>
theme[variantStyles[$variant].backgroundDisabledChecked]};
border-color: ${({ theme, $variant }) =>
Expand Down Expand Up @@ -160,7 +165,7 @@ export type CheckboxProps = {
export const Checkbox = ({
variant = 'primary',
isChecked,
isDisabled,
isDisabled = false,
labelAlignment = 'right',
onClick,
'data-test': dataTest,
Expand All @@ -171,7 +176,10 @@ export const Checkbox = ({
const theme = useTheme();

const handleKeyUp = (event: KeyboardEvent<HTMLElement>) => {
if (event.code === KEYBOARD_CODE.SPACE || event.code === KEYBOARD_CODE.ENTER) {
if (
!isDisabled &&
(event.code === KEYBOARD_CODE.SPACE || event.code === KEYBOARD_CODE.ENTER)
) {
onClick(event);
}
};
Expand All @@ -184,7 +192,7 @@ export const Checkbox = ({
<Container
$isDisabled={isDisabled}
$labelAlignment={labelAlignment}
onClick={onClick}
onClick={isDisabled ? undefined : onClick}
onKeyUp={handleKeyUp}
data-test={dataTest}
className={className}
Expand Down
38 changes: 23 additions & 15 deletions packages/components/src/components/form/Input/Input.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,42 @@ const meta: Meta = {
args: {
value: 'Input',
label: 'Label',
bottomText: '',
isDisabled: false,
size: 'large',
inputState: null,
variant: null,
innerAddonAlign: 'right',
hasBottomPadding: true,
},
argTypes: {
labelRight: {
type: 'string',
bottomText: { control: 'text' },
labelHoverRight: { control: 'text' },
labelLeft: { control: 'text' },
labelRight: { control: 'text' },
innerAddon: { control: 'text' },
placeholder: { control: 'text' },
size: {
control: {
type: 'radio',
},
options: ['large', 'small'],
},
placeholder: {
type: 'string',
inputState: {
control: {
type: 'radio',
},
options: [null, 'warning', 'error'],
},
state: {
innerAddonAlign: {
control: {
options: {
'None (default)': null,
Success: 'success',
Warning: 'warning',
Error: 'error',
},
type: 'radio',
},
options: ['right', 'left'],
},
variant: {
showClearButton: {
control: {
options: { 'Large (default)': null, Small: 'small' },
type: 'radio',
},
options: [null, 'hover', 'always'],
},
},
} as Meta;
Expand Down
5 changes: 5 additions & 0 deletions packages/components/src/components/form/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ const StyledInput = styled.input<StyledInputProps & { $isWithLabel: boolean }>`
height: ${({ $size }) => `${INPUT_HEIGHTS[$size as InputSize]}px`};
${baseInputStyle}
${({ $size }) => $size === 'small' && typography.hint};
&:disabled {
pointer-events: auto;
cursor: not-allowed;
}
`;

const InputWrapper = styled.div`
Expand Down
21 changes: 20 additions & 1 deletion packages/components/src/components/form/Radio/Radio.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,26 @@ export const RadioButton: StoryObj<RadioProps> = {
</RadioComponent>
);
},
args: { children: 'RadioButton' },
args: {
children: 'RadioButton',
variant: 'primary',
isChecked: false,
isDisabled: false,
},
argTypes: {
variant: {
control: {
type: 'radio',
},
options: ['primary', 'warning', 'destructive'],
},
labelAlignment: {
control: {
type: 'radio',
},
options: [null, 'left', 'right'],
},
},
};

export const RadioButtonGroup: StoryObj = {
Expand Down
25 changes: 15 additions & 10 deletions packages/components/src/components/form/Radio/Radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const RadioIcon = styled(CheckContainer)`
transition: background 0.1s;
}
input:checked + && {
input:checked + & {
background: ${({ theme }) => theme.backgroundSurfaceElevation0};
border-color: ${({ theme, $variant }) => theme[radioVariantStyles[$variant].borderChecked]};
Expand All @@ -64,7 +64,11 @@ const RadioIcon = styled(CheckContainer)`
}
}
input:disabled:not(:checked) + && {
input:disabled + & {
cursor: not-allowed;
}
input:disabled:not(:checked) + & {
background: ${({ theme }) => theme.backgroundSurfaceElevation0};
border-color: ${({ theme, $variant }) => theme[variantStyles[$variant].borderDisabled]};
Expand All @@ -73,7 +77,7 @@ const RadioIcon = styled(CheckContainer)`
}
}
input:disabled:checked + && {
input:disabled:checked + & {
background: transparent;
border-color: ${({ theme, $variant }) =>
theme[radioVariantStyles[$variant].borderDisabledChecked]};
Expand All @@ -84,15 +88,13 @@ const RadioIcon = styled(CheckContainer)`
}
}
${/* sc-selector */ Container}:hover input:not(:disabled):not(:checked) + && {
${/* sc-selector */ Container}:hover input:not(:disabled):not(:checked) + & {
&::after {
background: ${({ theme, $variant }) => theme[variantStyles[$variant].backgroundHover]};
}
}
&&& {
${getFocusShadowStyle()}
}
${getFocusShadowStyle()}
`;

export interface RadioProps {
Expand All @@ -109,20 +111,23 @@ export const Radio = ({
variant = 'primary',
isChecked,
labelAlignment,
isDisabled,
isDisabled = false,
onClick,
'data-test': dataTest,
children,
}: RadioProps) => {
const handleKeyUp = (event: KeyboardEvent<HTMLElement>) => {
if (event.code === KEYBOARD_CODE.SPACE || event.code === KEYBOARD_CODE.ENTER) {
if (
!isDisabled &&
(event.code === KEYBOARD_CODE.SPACE || event.code === KEYBOARD_CODE.ENTER)
) {
onClick(event);
}
};

return (
<Container
onClick={onClick}
onClick={isDisabled ? undefined : onClick}
onKeyUp={handleKeyUp}
$isDisabled={isDisabled}
$labelAlignment={labelAlignment}
Expand Down

0 comments on commit 204416f

Please sign in to comment.