Skip to content

Commit 0ee81b6

Browse files
authored
Merge pull request #117 from openinfradev/bugfix
Bugfix. Resolve TStepBox and TTabBox onChange not working in Storybook
2 parents 44e58fe + 35c9760 commit 0ee81b6

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tksui-components",
3-
"version": "0.9.1",
3+
"version": "0.9.2",
44
"private": false,
55
"type": "module",
66
"module": "lib/esm/index.js",

src/components/data-container/step-box/TStepBox.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const TStepBox = ({
1212
nextButtonLabel = 'Next',
1313
completeButtonLabel = 'Complete',
1414
value,
15+
onChange,
1516
children,
1617
style,
1718
className,
@@ -24,6 +25,7 @@ const TStepBox = ({
2425
nextButtonLabel,
2526
completeButtonLabel,
2627
value,
28+
onChange,
2729
children,
2830
style,
2931
className,
@@ -43,11 +45,12 @@ const TStepBox = ({
4345
let content = null;
4446

4547
if (children?.length === undefined) {
48+
// children 안 들어옴
4649
if (!children) {
47-
// children 안들어옴
4850
return null;
4951
}
50-
content = children; // children 1개
52+
// children 1개
53+
content = children;
5154
} else {
5255
// children 2개 이상
5356
content = children[value - 1];

src/components/data-container/step-box/TStepBoxContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type stepBoxContext = {
1616
export const tabBoxContext = createContext<stepBoxContext>({
1717
totalStep: 0,
1818
currentStep: 0,
19-
onChangeCurrentStep: null,
19+
onChangeCurrentStep: () => {},
2020
prevButtonLabel: '',
2121
nextButtonLabel: '',
2222
completeButtonLabel: '',

stories/components/data-container/step-box/TStepBox.stories.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ type Story = StoryObj<typeof TStepBox>;
1616
const Template = (args) => {
1717
const [stepNumber, setStepNumber] = useState<number>(1);
1818

19+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
20+
const {onChange, ...restArgs} = args;
21+
1922
return (
2023
<>
24+
{stepNumber}
2125
<TStepBox
2226
value={stepNumber}
2327
onChange={setStepNumber}
@@ -29,7 +33,7 @@ const Template = (args) => {
2933
'정책 선택',
3034
'확인 및 생성',
3135
]}
32-
{...args}
36+
{...restArgs}
3337
>
3438
<TStepBoxItem contentDirection={'top-bottom'}>
3539
<div>Step 1-1 Content</div>
@@ -68,7 +72,7 @@ const Template = (args) => {
6872
'정책 선택',
6973
'확인 및 생성',
7074
]}
71-
{...args}
75+
{...restArgs}
7276
>
7377
<TStepBoxItem contentDirection={'left-right'}>
7478
<div>Step 1-1 Content</div>

stories/components/data-container/tab-box/TTabBox.stories.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type {Meta, StoryObj} from '@storybook/react';
2+
import {useState} from 'react';
23

3-
import useInputState from '@/common/hook/UseInputState';
44
import TTabBox from '@/components/data-container/tab-box/TTabBox';
55
import type {TTabBoxValue} from '@/components/data-container/tab-box/TTabBox.interface';
66
import TTabItem from '@/components/data-container/tab-box/TTabItem';
@@ -15,11 +15,14 @@ export default meta;
1515
type Story = StoryObj<typeof TTabBox>;
1616

1717
const Template = (args) => {
18-
const tab = useInputState<TTabBoxValue>(0);
18+
const [tab, setTab] = useState<TTabBoxValue>(0);
19+
20+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
21+
const {onChange, ...restArgs} = args;
1922

2023
return (
2124
<>
22-
<TTabBox {...tab} {...args}>
25+
<TTabBox value={tab} onChange={setTab} {...restArgs}>
2326
<TTabItem label={'One'} content={<div>Tab One</div>} />
2427
<TTabItem label={'Two'} content={<div>Tab Two</div>} />
2528
<TTabItem label={'Three'} content={<div>Tab Three</div>} />

0 commit comments

Comments
 (0)