Skip to content

Commit 34c3b52

Browse files
committed
feat(suite): Add cursor: not-allowed to some components when disabled (#12945)
1 parent 510ba01 commit 34c3b52

12 files changed

+292
-80
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,37 @@
1-
import styled from 'styled-components';
2-
import { AutoScalingInput as Input } from './AutoScalingInput';
3-
import { Meta } from '@storybook/react';
4-
5-
const Wrapper = styled.div`
6-
display: flex;
7-
flex: 1;
8-
flex-direction: column;
9-
`;
10-
11-
const BorderAutoScalingInput = styled(Input)`
12-
padding: 1px 5px;
13-
border-radius: 3px;
14-
border-style: solid;
15-
border-width: 1px;
16-
`;
17-
18-
const BorderlessAutoScalingInput = styled(Input)`
19-
padding: 1px 5px;
20-
border-style: solid;
21-
border-width: 0;
22-
background-color: #ccc;
23-
`;
1+
import { ForwardRefExoticComponent, RefAttributes } from 'react';
2+
import { AutoScalingInput as AutoScalingInputComponent, Props } from './AutoScalingInput';
3+
import { Meta, StoryObj } from '@storybook/react';
244

255
const meta: Meta = {
266
title: 'Form/AutoScalingInput',
7+
component: AutoScalingInputComponent,
278
};
289
export default meta;
2910

30-
export const AutoScalingInput = {
31-
render: () => (
32-
<>
33-
<Wrapper>
34-
<div>Border</div>
35-
<BorderAutoScalingInput minWidth={130} />
36-
<BorderAutoScalingInput
37-
minWidth={120}
38-
placeholder="Chancellor on the Brink of Second Bailout for Banks"
39-
/>
40-
<div>Borderless</div>
41-
<BorderlessAutoScalingInput minWidth={130} />
42-
<BorderlessAutoScalingInput
43-
minWidth={120}
44-
placeholder="Chancellor on the Brink of Second Bailout for Banks"
45-
/>
46-
</Wrapper>
47-
</>
48-
),
11+
export const AutoScalingInput: StoryObj<
12+
ForwardRefExoticComponent<Omit<Props, 'ref'> & RefAttributes<HTMLInputElement>>
13+
> = {
14+
render: props => <AutoScalingInputComponent {...props} />,
15+
args: {
16+
value: undefined,
17+
minWidth: 120,
18+
placeholder: 'Chancellor on the Brink of Second Bailout for Banks',
19+
disabled: false,
20+
},
21+
argTypes: {
22+
value: {
23+
control: { type: 'text' },
24+
},
25+
minWidth: {
26+
control: { type: 'number' },
27+
},
28+
placeholder: {
29+
control: { type: 'text' },
30+
},
31+
disabled: {
32+
control: {
33+
type: 'boolean',
34+
},
35+
},
36+
},
4937
};

packages/components/src/components/AutoScalingInput/AutoScalingInput.tsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,18 @@ const createHandleOnChangeAndApplyNewWidth =
4343
onChange?.(event);
4444
};
4545

46-
interface Props
46+
export interface Props
4747
extends React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> {
4848
minWidth: number;
4949
}
5050

51+
const StyledInput = styled.input`
52+
&:disabled {
53+
pointer-events: auto;
54+
cursor: not-allowed;
55+
}
56+
`;
57+
5158
/**
5259
* TODO: This is Labeling Input and this maybe consolidated with `withEditable`
5360
*/
@@ -104,7 +111,7 @@ export const AutoScalingInput = forwardRef<HTMLInputElement, Props>(
104111
value={props.placeholder}
105112
readOnly
106113
/>
107-
<input
114+
<StyledInput
108115
{...props}
109116
ref={innerRef}
110117
type="text"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import styled from 'styled-components';
2+
import { AutoScalingInput as Input } from './AutoScalingInput';
3+
import { Meta } from '@storybook/react';
4+
5+
const Wrapper = styled.div`
6+
display: flex;
7+
flex: 1;
8+
flex-direction: column;
9+
`;
10+
11+
const BorderAutoScalingInput = styled(Input)`
12+
padding: 1px 5px;
13+
border-radius: 3px;
14+
border-style: solid;
15+
border-width: 1px;
16+
`;
17+
18+
const BorderlessAutoScalingInput = styled(Input)`
19+
padding: 1px 5px;
20+
border-style: solid;
21+
border-width: 0;
22+
background-color: #ccc;
23+
`;
24+
25+
const meta: Meta = {
26+
title: 'Form/AutoScalingInput',
27+
};
28+
export default meta;
29+
30+
export const AutoScalingInputExamples = {
31+
render: () => (
32+
<>
33+
<Wrapper>
34+
<div>Border</div>
35+
<BorderAutoScalingInput minWidth={130} />
36+
<BorderAutoScalingInput
37+
minWidth={120}
38+
placeholder="Chancellor on the Brink of Second Bailout for Banks"
39+
/>
40+
<div>Borderless</div>
41+
<BorderlessAutoScalingInput minWidth={130} />
42+
<BorderlessAutoScalingInput
43+
minWidth={120}
44+
placeholder="Chancellor on the Brink of Second Bailout for Banks"
45+
/>
46+
</Wrapper>
47+
</>
48+
),
49+
};

packages/components/src/components/buttons/Button/Button.stories.tsx

+34-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ export const Button: StoryObj<ButtonProps> = {
2222
...framePropsStory.args,
2323
},
2424
argTypes: {
25+
children: {
26+
table: {
27+
type: {
28+
summary: 'ReactNode',
29+
},
30+
},
31+
},
2532
variant: {
2633
control: {
2734
type: 'radio',
@@ -34,20 +41,44 @@ export const Button: StoryObj<ButtonProps> = {
3441
},
3542
options: ['large', 'medium', 'small', 'tiny'],
3643
},
44+
isDisabled: {
45+
control: {
46+
type: 'boolean',
47+
},
48+
},
49+
isLoading: {
50+
control: {
51+
type: 'boolean',
52+
},
53+
},
54+
isFullWidth: {
55+
control: {
56+
type: 'boolean',
57+
},
58+
},
3759
icon: {
38-
options: variables.ICONS,
60+
options: {
61+
'No icon': null,
62+
...variables.ICONS.reduce((acc, icon) => ({ ...acc, [icon]: icon }), {}),
63+
},
3964
control: {
4065
type: 'select',
4166
},
4267
},
43-
iconSize: { control: 'number' },
68+
iconSize: {
69+
control: {
70+
type: 'number',
71+
},
72+
},
4473
iconAlignment: {
4574
control: {
4675
type: 'radio',
4776
},
4877
options: ['left', 'right'],
4978
},
50-
title: { control: 'text' },
79+
title: {
80+
control: { type: 'text' },
81+
},
5182
...framePropsStory.argTypes,
5283
},
5384
};

packages/components/src/components/form/Range/Range.stories.tsx

+35-4
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,49 @@ export const Range: StoryObj<RangeProps> = {
1616
return <RangeComponent {...args} onChange={e => updateArgs({ value: e.target.value })} />;
1717
},
1818
args: {
19-
max: 100,
20-
min: 0,
21-
value: 21,
19+
disabled: false,
2220
labels: [
2321
{ component: '0', value: 0 },
2422
{ component: '50', value: 50 },
2523
{ component: '100', value: 100 },
2624
],
25+
max: 100,
26+
min: 0,
27+
value: 21,
2728
},
2829
argTypes: {
2930
disabled: {
30-
control: 'boolean',
31+
control: {
32+
type: 'boolean',
33+
},
34+
},
35+
labels: {
36+
control: {
37+
type: 'array',
38+
},
39+
table: {
40+
type: {
41+
summary: 'Array<{ component: string; value: number }>',
42+
},
43+
},
44+
},
45+
max: {
46+
control: {
47+
type: 'number',
48+
},
49+
},
50+
min: {
51+
control: {
52+
type: 'number',
53+
},
54+
},
55+
value: {
56+
control: {
57+
type: 'number',
58+
},
59+
},
60+
step: {
61+
control: { type: 'text' },
3162
},
3263
className: {
3364
control: false,

packages/components/src/components/form/Range/Range.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ const Input = styled.input<{ $trackStyle?: CSSObject; disabled?: boolean }>`
8383
${focusStyle}
8484
}
8585
}
86+
87+
&:disabled {
88+
pointer-events: auto;
89+
cursor: not-allowed;
90+
}
8691
`;
8792

8893
const Label = styled.div<{ disabled?: boolean; $width?: number }>`
@@ -123,7 +128,7 @@ export interface RangeProps {
123128

124129
export const Range = ({
125130
className,
126-
disabled,
131+
disabled = false,
127132
labels,
128133
onLabelClick,
129134
trackStyle,

packages/components/src/components/form/Select/Select.stories.tsx

+47-6
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,26 @@ export const Select: StoryObj<SelectProps> = {
2929

3030
return <SelectComponent {...args} value={option} onChange={setOption} options={options} />;
3131
},
32+
args: {
33+
label: 'Label',
34+
isClean: false,
35+
isDisabled: false,
36+
isSearchable: false,
37+
hasBottomPadding: true,
38+
size: 'large',
39+
minValueWidth: 'initial',
40+
menuIsOpen: undefined,
41+
useKeyPressScroll: undefined,
42+
},
3243
argTypes: {
33-
isSearchable: {
44+
label: {
45+
table: {
46+
type: {
47+
summary: 'ReactNode',
48+
},
49+
},
50+
},
51+
isClean: {
3452
control: {
3553
type: 'boolean',
3654
},
@@ -40,23 +58,46 @@ export const Select: StoryObj<SelectProps> = {
4058
type: 'boolean',
4159
},
4260
},
61+
isSearchable: {
62+
control: {
63+
type: 'boolean',
64+
},
65+
},
4366
bottomText: {
4467
control: { type: 'text' },
4568
},
69+
hasBottomPadding: {
70+
control: {
71+
type: 'boolean',
72+
},
73+
},
4674
size: {
4775
control: {
48-
options: { 'Large (default)': null, Small: 'small' },
4976
type: 'radio',
5077
},
78+
options: ['large', 'small'],
5179
},
52-
label: {
80+
minValueWidth: {
5381
control: { type: 'text' },
5482
},
83+
menuIsOpen: {
84+
control: {
85+
type: 'boolean',
86+
},
87+
},
88+
useKeyPressScroll: {
89+
control: {
90+
type: 'boolean',
91+
},
92+
},
93+
inputState: {
94+
control: {
95+
type: 'radio',
96+
},
97+
options: [null, 'warning', 'error'],
98+
},
5599
placeholder: {
56100
control: { type: 'text' },
57101
},
58102
},
59-
args: {
60-
label: 'Label',
61-
},
62103
};

packages/components/src/components/form/Select/Select.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ const Wrapper = styled.div<WrapperProps>`
217217
border: none;
218218
z-index: ${zIndices.base};
219219
}
220+
221+
${({ $isDisabled }) => $isDisabled && `pointer-events: auto; cursor: not-allowed;`};
220222
`;
221223

222224
const SelectLabel = styled(Label)`
@@ -272,7 +274,7 @@ export const Select = ({
272274
components,
273275
onChange,
274276
placeholder,
275-
isDisabled,
277+
isDisabled = false,
276278
'data-test': dataTest,
277279
...props
278280
}: SelectProps) => {

0 commit comments

Comments
 (0)