Skip to content

Commit 4526961

Browse files
committed
simplify
1 parent f3ef57c commit 4526961

File tree

4 files changed

+32
-85
lines changed

4 files changed

+32
-85
lines changed

packages/components/src/inputs/AltRadio/AltRadio.stories.tsx

Lines changed: 16 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,9 @@ import React from 'react';
33
import type { Meta, StoryObj } from '@storybook/react';
44
import { action } from 'storybook/actions';
55

6-
import { AltRadioProps } from './AltRadio.types';
7-
import { WrappedComponentProps } from '@ids-internal/hoc/withStateChecked';
8-
96
import { AltRadioStateful } from './AltRadio';
107

11-
type StoryProps = WrappedComponentProps<AltRadioProps> & {
12-
'inputProps.checked'?: boolean;
13-
'inputProps.disabled'?: boolean;
14-
'inputProps.error'?: boolean;
15-
'inputProps.name'?: string;
16-
};
17-
18-
const meta: Meta<StoryProps> = {
8+
const meta: Meta<typeof AltRadioStateful> = {
199
component: AltRadioStateful,
2010
parameters: {
2111
layout: 'centered',
@@ -28,44 +18,20 @@ const meta: Meta<StoryProps> = {
2818
title: {
2919
control: 'text',
3020
},
31-
inputProps: {
32-
control: false,
33-
},
34-
'inputProps.checked': {
35-
control: 'boolean',
36-
},
37-
'inputProps.disabled': {
38-
control: 'boolean',
39-
},
40-
'inputProps.error': {
41-
control: 'boolean',
42-
},
43-
'inputProps.name': {
44-
control: 'text',
45-
},
4621
},
4722
args: {
4823
label: '1:1',
49-
inputProps: {
50-
name: 'default-input',
51-
onBlur: action('on-blur'),
52-
onChange: action('on-change'),
53-
onFocus: action('on-focus'),
54-
onInput: action('on-input'),
55-
},
24+
name: 'default-input',
25+
onBlur: action('on-blur'),
26+
onChange: action('on-change'),
27+
onFocus: action('on-focus'),
28+
onInput: action('on-input'),
5629
},
5730
decorators: [
58-
(Story, { args }) => {
59-
const inputProps = { ...args.inputProps };
60-
61-
inputProps.checked = args['inputProps.checked'] ?? false;
62-
inputProps.disabled = args['inputProps.disabled'] ?? false;
63-
inputProps.error = args['inputProps.error'] ?? false;
64-
inputProps.name = args['inputProps.name'] ?? '';
65-
31+
(Story) => {
6632
return (
6733
<form name="default-form">
68-
<Story args={{ ...args, inputProps }} />
34+
<Story />
6935
</form>
7036
);
7137
},
@@ -74,7 +40,7 @@ const meta: Meta<StoryProps> = {
7440

7541
export default meta;
7642

77-
type Story = StoryObj<StoryProps>;
43+
type Story = StoryObj<typeof AltRadioStateful>;
7844

7945
export const Empty: Story = {
8046
name: 'Empty',
@@ -83,36 +49,36 @@ export const Empty: Story = {
8349
export const EmptyDisabled: Story = {
8450
name: 'Empty (Disabled)',
8551
args: {
86-
'inputProps.disabled': true,
52+
disabled: true,
8753
},
8854
};
8955

9056
export const EmptyError: Story = {
9157
name: 'Empty (Error)',
9258
args: {
93-
'inputProps.error': true,
59+
error: true,
9460
},
9561
};
9662

9763
export const Checked: Story = {
9864
name: 'Checked',
9965
args: {
100-
'inputProps.checked': true,
66+
checked: true,
10167
},
10268
};
10369

10470
export const CheckedDisabled: Story = {
10571
name: 'Checked (Disabled)',
10672
args: {
107-
'inputProps.disabled': true,
108-
'inputProps.checked': true,
73+
disabled: true,
74+
checked: true,
10975
},
11076
};
11177

11278
export const CheckedError: Story = {
11379
name: 'Checked (Error)',
11480
args: {
115-
'inputProps.error': true,
116-
'inputProps.checked': true,
81+
error: true,
82+
checked: true,
11783
},
11884
};

packages/components/src/inputs/AltRadio/AltRadio.test.stories.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ const meta: Meta<typeof AltRadioStateful> = {
1111
tags: ['!dev'],
1212
args: {
1313
label: '1:1',
14-
inputProps: {
15-
name: 'default-input',
16-
onBlur: fn(),
17-
onChange: fn(),
18-
onFocus: fn(),
19-
onInput: fn(),
20-
},
14+
name: 'default-input',
15+
onBlur: fn(),
16+
onChange: fn(),
17+
onFocus: fn(),
18+
onInput: fn(),
2119
},
2220
};
2321

@@ -32,21 +30,21 @@ export const Default: Story = {
3230
const input = canvas.getByRole('button');
3331

3432
await step('Radio Button handles focus event', async () => {
35-
await expect(args.inputProps.onFocus).not.toHaveBeenCalled();
33+
await expect(args.onFocus).not.toHaveBeenCalled();
3634

3735
await userEvent.click(input);
3836

39-
await expect(args.inputProps.onFocus).toHaveBeenCalledOnce();
40-
await expect(args.inputProps.onChange).toHaveBeenCalledOnce();
41-
await expect(args.inputProps.onInput).toHaveBeenCalledOnce();
37+
await expect(args.onFocus).toHaveBeenCalledOnce();
38+
await expect(args.onChange).toHaveBeenCalledOnce();
39+
await expect(args.onInput).toHaveBeenCalledOnce();
4240
});
4341

4442
await step('Radio Button handles blur event', async () => {
45-
await expect(args.inputProps.onBlur).not.toHaveBeenCalled();
43+
await expect(args.onBlur).not.toHaveBeenCalled();
4644

4745
await userEvent.click(canvasElement);
4846

49-
await expect(args.inputProps.onBlur).toHaveBeenCalledOnce();
47+
await expect(args.onBlur).toHaveBeenCalledOnce();
5048
});
5149
},
5250
};

packages/components/src/inputs/AltRadio/AltRadio.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import withStateChecked from '@ids-internal/hoc/withStateChecked';
66

77
import { AltRadioProps } from './AltRadio.types';
88

9-
const AltRadio = ({ className = '', label, inputProps }: AltRadioProps) => {
9+
const AltRadio = ({ className = '', label, ...inputProps }: AltRadioProps) => {
1010
const { checked = false, disabled = false, error = false, onBlur, onChange, onFocus, onInput } = inputProps;
1111
const inputRef = useRef<HTMLInputElement>(null);
1212
const [isFocused, setIsFocused] = useState(false);
Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,7 @@
1-
import { ReactNode, Ref } from 'react';
1+
import { ReactNode } from 'react';
22

3-
import { BaseComponentAriaAttributes } from '@ids-types/general';
3+
import { BaseChoiceInputProps } from '@ids-internal/partials/BaseChoiceInput';
44

5-
interface InputPropsType {
6-
name: string;
7-
onBlur?: React.FocusEventHandler<HTMLInputElement>;
8-
onChange?: (value: boolean, event?: React.ChangeEvent<HTMLInputElement>) => void;
9-
onFocus?: React.FocusEventHandler<HTMLInputElement>;
10-
onInput?: (value: boolean, event?: React.ChangeEvent<HTMLInputElement>) => void;
11-
checked?: boolean;
12-
disabled?: boolean;
13-
error?: boolean;
14-
id?: string;
15-
className?: string;
16-
ref?: Ref<HTMLInputElement>;
17-
required?: boolean;
18-
value?: string;
19-
}
20-
21-
export interface AltRadioProps extends BaseComponentAriaAttributes {
5+
export interface AltRadioProps extends Omit<BaseChoiceInputProps, 'type'> {
226
label: ReactNode;
23-
inputProps: InputPropsType;
24-
}
7+
};

0 commit comments

Comments
 (0)