@transferwise/components 0.0.0-experimental-44efb60 → 0.0.0-experimental-95044f9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.js +27 -33
- package/build/index.js.map +1 -1
- package/build/index.mjs +27 -33
- package/build/index.mjs.map +1 -1
- package/build/main.css +2 -2
- package/build/styles/main.css +2 -2
- package/build/styles/segmentedControl/SegmentedControl.css +2 -2
- package/build/types/field/Field.d.ts.map +1 -1
- package/build/types/inlineAlert/InlineAlert.d.ts.map +1 -1
- package/build/types/inputs/contexts.d.ts.map +1 -1
- package/build/types/segmentedControl/SegmentedControl.d.ts.map +1 -1
- package/build/types/tabs/TabList.d.ts +8 -3
- package/build/types/tabs/TabList.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/field/Field.tsx +7 -5
- package/src/inlineAlert/InlineAlert.spec.tsx +7 -0
- package/src/inlineAlert/InlineAlert.tsx +9 -3
- package/src/inputs/contexts.tsx +1 -2
- package/src/main.css +2 -2
- package/src/segmentedControl/SegmentedControl.css +2 -2
- package/src/segmentedControl/SegmentedControl.less +1 -1
- package/src/segmentedControl/SegmentedControl.spec.tsx +0 -10
- package/src/segmentedControl/SegmentedControl.story.tsx +4 -42
- package/src/segmentedControl/SegmentedControl.tsx +1 -5
- package/src/tabs/TabList.js +15 -0
- package/src/tabs/Tabs.story.js +135 -0
- package/src/tabs/TabList.tsx +0 -15
- package/src/tabs/Tabs.rtl.spec.tsx +0 -40
- package/src/tabs/Tabs.story.tsx +0 -88
package/build/main.css
CHANGED
|
@@ -4741,8 +4741,8 @@ html:not([dir="rtl"]) .np-navigation-option {
|
|
|
4741
4741
|
flex-flow: column;
|
|
4742
4742
|
padding: 8px 16px;
|
|
4743
4743
|
padding: var(--size-8) var(--size-16);
|
|
4744
|
-
margin: 0 0 0 4px
|
|
4745
|
-
margin: 0 0 0 var(--size-4)
|
|
4744
|
+
margin: 0 0 0 4px;
|
|
4745
|
+
margin: 0 0 0 var(--size-4);
|
|
4746
4746
|
min-width: 0;
|
|
4747
4747
|
line-height: inherit;
|
|
4748
4748
|
align-items: center;
|
package/build/styles/main.css
CHANGED
|
@@ -4741,8 +4741,8 @@ html:not([dir="rtl"]) .np-navigation-option {
|
|
|
4741
4741
|
flex-flow: column;
|
|
4742
4742
|
padding: 8px 16px;
|
|
4743
4743
|
padding: var(--size-8) var(--size-16);
|
|
4744
|
-
margin: 0 0 0 4px
|
|
4745
|
-
margin: 0 0 0 var(--size-4)
|
|
4744
|
+
margin: 0 0 0 4px;
|
|
4745
|
+
margin: 0 0 0 var(--size-4);
|
|
4746
4746
|
min-width: 0;
|
|
4747
4747
|
line-height: inherit;
|
|
4748
4748
|
align-items: center;
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
flex-flow: column;
|
|
47
47
|
padding: 8px 16px;
|
|
48
48
|
padding: var(--size-8) var(--size-16);
|
|
49
|
-
margin: 0 0 0 4px
|
|
50
|
-
margin: 0 0 0 var(--size-4)
|
|
49
|
+
margin: 0 0 0 4px;
|
|
50
|
+
margin: 0 0 0 var(--size-4);
|
|
51
51
|
min-width: 0;
|
|
52
52
|
line-height: inherit;
|
|
53
53
|
align-items: center;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Field.d.ts","sourceRoot":"","sources":["../../../src/field/Field.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAUtC,MAAM,MAAM,UAAU,GAAG;IACvB,6IAA6I;IAC7I,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,sGAAsG;IACtG,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACxB,4EAA4E;IAC5E,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,OAAO,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,6EAA6E;IAC7E,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACxB,SAAS,CAAC,EAAE,GAAG,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC,OAAO,GAAG,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC,OAAO,EAAE,CAAC;IACjG,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B,CAAC;AAEF,eAAO,MAAM,KAAK,4FAQf,UAAU,
|
|
1
|
+
{"version":3,"file":"Field.d.ts","sourceRoot":"","sources":["../../../src/field/Field.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAUtC,MAAM,MAAM,UAAU,GAAG;IACvB,6IAA6I;IAC7I,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,sGAAsG;IACtG,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACxB,4EAA4E;IAC5E,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,OAAO,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,6EAA6E;IAC7E,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACxB,SAAS,CAAC,EAAE,GAAG,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC,OAAO,GAAG,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC,OAAO,EAAE,CAAC;IACjG,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B,CAAC;AAEF,eAAO,MAAM,KAAK,4FAQf,UAAU,gCAiDZ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InlineAlert.d.ts","sourceRoot":"","sources":["../../../src/inlineAlert/InlineAlert.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,EAAE,SAAS,EAAQ,MAAM,WAAW,CAAC;AAG5C,MAAM,WAAW,gBAAgB;IAC/B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,GAAG,SAAS,EAAE,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,SAAS,CAAC;CACrB;
|
|
1
|
+
{"version":3,"file":"InlineAlert.d.ts","sourceRoot":"","sources":["../../../src/inlineAlert/InlineAlert.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,EAAE,SAAS,EAAQ,MAAM,WAAW,CAAC;AAG5C,MAAM,WAAW,gBAAgB;IAC/B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,GAAG,SAAS,EAAE,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAUD,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,EAClC,EAAE,EACF,IAAgB,EAChB,SAAS,EACT,QAAQ,GACT,EAAE,gBAAgB,+BAelB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contexts.d.ts","sourceRoot":"","sources":["../../../src/inputs/contexts.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,2BAA2B,8CAA+B,CAAC;AAGxE,eAAO,MAAM,sBAAsB,8CAA0B,CAAC;AAG9D,eAAO,MAAM,wBAAwB,8CAAmC,CAAC;AAGzE,eAAO,MAAM,oBAAoB,+CAA+B,CAAC;AAEjE,UAAU,sBAAsB;IAC9B,gLAAgL;IAChL,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,wBAAgB,kBAAkB,CAAC,EAAE,YAAY,EAAE,GAAE,sBAA2B;;;;;
|
|
1
|
+
{"version":3,"file":"contexts.d.ts","sourceRoot":"","sources":["../../../src/inputs/contexts.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,2BAA2B,8CAA+B,CAAC;AAGxE,eAAO,MAAM,sBAAsB,8CAA0B,CAAC;AAG9D,eAAO,MAAM,wBAAwB,8CAAmC,CAAC;AAGzE,eAAO,MAAM,oBAAoB,+CAA+B,CAAC;AAEjE,UAAU,sBAAsB;IAC9B,gLAAgL;IAChL,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,wBAAgB,kBAAkB,CAAC,EAAE,YAAY,EAAE,GAAE,sBAA2B;;;;;EAQ/E;AAED,MAAM,WAAW,wBAAwB;IACvC,eAAe,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC;CACxD;AAED,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,OAAO,CAAC,wBAAwB,CAAC,EAC7E,SAAS,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,EACjC,IAAI,CAAC,EAAE,sBAAsB;YAEgB,IAAI,CAAC,CAAC,EAAE,MAAM,wBAAwB,CAAC;;EAOrF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SegmentedControl.d.ts","sourceRoot":"","sources":["../../../src/segmentedControl/SegmentedControl.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SegmentedControl.d.ts","sourceRoot":"","sources":["../../../src/segmentedControl/SegmentedControl.tsx"],"names":[],"mappings":"AAMA,KAAK,WAAW,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhE,KAAK,OAAO,GAAG,WAAW,GAAG;IAAE,QAAQ,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC;AAClD,KAAK,mBAAmB,GAAG,WAAW,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9D,MAAM,MAAM,QAAQ,GAAG,SAAS,OAAO,EAAE,GAAG,SAAS,mBAAmB,EAAE,CAAC;AAE3E,KAAK,yBAAyB,GAAG;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC;IACvB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC,CAAC;AAEF,KAAK,yBAAyB,GAAG;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,SAAS,mBAAmB,EAAE,CAAC;CAC1C,CAAC;AAEF,KAAK,0BAA0B,GAAG;IAChC,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,yBAAyB,GAC3D,CAAC,yBAAyB,GAAG,0BAA0B,CAAC,CAAC;AAE3D,QAAA,MAAM,gBAAgB,+CAMnB,qBAAqB,gCA0HvB,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
1
|
+
export default TabList;
|
|
2
|
+
declare function TabList({ children }: {
|
|
3
|
+
children: any;
|
|
4
|
+
}): import("react").JSX.Element;
|
|
5
|
+
declare namespace TabList {
|
|
6
|
+
namespace propTypes {
|
|
7
|
+
let children: any;
|
|
8
|
+
}
|
|
3
9
|
}
|
|
4
|
-
export default function TabList({ children }: TabListProps): import("react").JSX.Element;
|
|
5
10
|
//# sourceMappingURL=TabList.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TabList.d.ts","sourceRoot":"","sources":["../../../src/tabs/TabList.
|
|
1
|
+
{"version":3,"file":"TabList.d.ts","sourceRoot":"","sources":["../../../src/tabs/TabList.js"],"names":[],"mappings":";AAEA;;gCAMC"}
|
package/package.json
CHANGED
package/src/field/Field.tsx
CHANGED
|
@@ -63,12 +63,14 @@ export const Field = ({
|
|
|
63
63
|
className,
|
|
64
64
|
)}
|
|
65
65
|
>
|
|
66
|
-
{label ? (
|
|
67
|
-
<
|
|
66
|
+
{label != null ? (
|
|
67
|
+
<Label id={labelId} htmlFor={inputId}>
|
|
68
68
|
{label}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
{children}
|
|
70
|
+
</Label>
|
|
71
|
+
) : (
|
|
72
|
+
children
|
|
73
|
+
)}
|
|
72
74
|
|
|
73
75
|
{message && (
|
|
74
76
|
<InlineAlert type={sentiment} id={descriptionId}>
|
|
@@ -28,6 +28,7 @@ describe('InlineAlert', () => {
|
|
|
28
28
|
const component = screen.getByRole('alert');
|
|
29
29
|
|
|
30
30
|
expect(component).toHaveClass('alert-info');
|
|
31
|
+
expect(screen.queryByTestId('status-icon')).not.toBeInTheDocument();
|
|
31
32
|
});
|
|
32
33
|
|
|
33
34
|
it('renders neutral', () => {
|
|
@@ -35,6 +36,7 @@ describe('InlineAlert', () => {
|
|
|
35
36
|
const component = screen.getByRole('alert');
|
|
36
37
|
|
|
37
38
|
expect(component).toHaveClass('alert-neutral');
|
|
39
|
+
expect(screen.queryByTestId('status-icon')).not.toBeInTheDocument();
|
|
38
40
|
});
|
|
39
41
|
|
|
40
42
|
it('renders success', () => {
|
|
@@ -42,6 +44,7 @@ describe('InlineAlert', () => {
|
|
|
42
44
|
const component = screen.getByRole('alert');
|
|
43
45
|
|
|
44
46
|
expect(component).toHaveClass('alert-success');
|
|
47
|
+
expect(screen.getByTestId('status-icon')).toBeInTheDocument();
|
|
45
48
|
});
|
|
46
49
|
|
|
47
50
|
it('renders positive', () => {
|
|
@@ -49,6 +52,7 @@ describe('InlineAlert', () => {
|
|
|
49
52
|
const component = screen.getByRole('alert');
|
|
50
53
|
|
|
51
54
|
expect(component).toHaveClass('alert-positive');
|
|
55
|
+
expect(screen.getByTestId('status-icon')).toBeInTheDocument();
|
|
52
56
|
});
|
|
53
57
|
|
|
54
58
|
it('renders error as danger', () => {
|
|
@@ -56,6 +60,7 @@ describe('InlineAlert', () => {
|
|
|
56
60
|
const component = screen.getByRole('alert');
|
|
57
61
|
|
|
58
62
|
expect(component).toHaveClass('alert-danger');
|
|
63
|
+
expect(screen.getByTestId('status-icon')).toBeInTheDocument();
|
|
59
64
|
});
|
|
60
65
|
|
|
61
66
|
it('renders negative as danger', () => {
|
|
@@ -63,6 +68,7 @@ describe('InlineAlert', () => {
|
|
|
63
68
|
const component = screen.getByRole('alert');
|
|
64
69
|
|
|
65
70
|
expect(component).toHaveClass('alert-danger');
|
|
71
|
+
expect(screen.getByTestId('status-icon')).toBeInTheDocument();
|
|
66
72
|
});
|
|
67
73
|
|
|
68
74
|
it('renders warning', () => {
|
|
@@ -70,6 +76,7 @@ describe('InlineAlert', () => {
|
|
|
70
76
|
const component = screen.getByRole('alert');
|
|
71
77
|
|
|
72
78
|
expect(component).toHaveClass('alert-warning');
|
|
79
|
+
expect(screen.getByTestId('status-icon')).toBeInTheDocument();
|
|
73
80
|
});
|
|
74
81
|
});
|
|
75
82
|
});
|
|
@@ -11,6 +11,14 @@ export interface InlineAlertProps {
|
|
|
11
11
|
children: ReactNode;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
const iconTypes = new Set<NonNullable<InlineAlertProps['type']>>([
|
|
15
|
+
Sentiment.NEGATIVE,
|
|
16
|
+
Sentiment.ERROR,
|
|
17
|
+
Sentiment.POSITIVE,
|
|
18
|
+
Sentiment.SUCCESS,
|
|
19
|
+
Sentiment.WARNING,
|
|
20
|
+
]);
|
|
21
|
+
|
|
14
22
|
export default function InlineAlert({
|
|
15
23
|
id,
|
|
16
24
|
type = 'neutral',
|
|
@@ -27,9 +35,7 @@ export default function InlineAlert({
|
|
|
27
35
|
className,
|
|
28
36
|
)}
|
|
29
37
|
>
|
|
30
|
-
{type
|
|
31
|
-
<StatusIcon sentiment={type} size={Size.SMALL} />
|
|
32
|
-
)}
|
|
38
|
+
{iconTypes.has(type) && <StatusIcon sentiment={type} size={Size.SMALL} />}
|
|
33
39
|
<div className="np-text-body-default">{children}</div>
|
|
34
40
|
</div>
|
|
35
41
|
);
|
package/src/inputs/contexts.tsx
CHANGED
|
@@ -18,10 +18,9 @@ interface UseInputAttributesArgs {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export function useInputAttributes({ nonLabelable }: UseInputAttributesArgs = {}) {
|
|
21
|
-
const id = useContext(InputIdContext);
|
|
22
21
|
const labelId = useContext(FieldLabelIdContext);
|
|
23
22
|
return {
|
|
24
|
-
id:
|
|
23
|
+
id: useContext(InputIdContext),
|
|
25
24
|
'aria-labelledby': nonLabelable ? labelId : undefined,
|
|
26
25
|
'aria-describedby': useContext(InputDescribedByContext),
|
|
27
26
|
'aria-invalid': useContext(InputInvalidContext),
|
package/src/main.css
CHANGED
|
@@ -4741,8 +4741,8 @@ html:not([dir="rtl"]) .np-navigation-option {
|
|
|
4741
4741
|
flex-flow: column;
|
|
4742
4742
|
padding: 8px 16px;
|
|
4743
4743
|
padding: var(--size-8) var(--size-16);
|
|
4744
|
-
margin: 0 0 0 4px
|
|
4745
|
-
margin: 0 0 0 var(--size-4)
|
|
4744
|
+
margin: 0 0 0 4px;
|
|
4745
|
+
margin: 0 0 0 var(--size-4);
|
|
4746
4746
|
min-width: 0;
|
|
4747
4747
|
line-height: inherit;
|
|
4748
4748
|
align-items: center;
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
flex-flow: column;
|
|
47
47
|
padding: 8px 16px;
|
|
48
48
|
padding: var(--size-8) var(--size-16);
|
|
49
|
-
margin: 0 0 0 4px
|
|
50
|
-
margin: 0 0 0 var(--size-4)
|
|
49
|
+
margin: 0 0 0 4px;
|
|
50
|
+
margin: 0 0 0 var(--size-4);
|
|
51
51
|
min-width: 0;
|
|
52
52
|
line-height: inherit;
|
|
53
53
|
align-items: center;
|
|
@@ -3,7 +3,6 @@ import React from 'react';
|
|
|
3
3
|
import { render, screen, userEvent, waitFor } from '../test-utils';
|
|
4
4
|
|
|
5
5
|
import SegmentedControl, { SegmentedControlProps } from './SegmentedControl';
|
|
6
|
-
import { Field } from '../field/Field';
|
|
7
6
|
|
|
8
7
|
const defaultSegments = [
|
|
9
8
|
{
|
|
@@ -189,13 +188,4 @@ describe('SegmentedControl', () => {
|
|
|
189
188
|
'SegmentedControl only supports up to 3 segments. Please refer to: https://wise.design/components/segmented-control',
|
|
190
189
|
);
|
|
191
190
|
});
|
|
192
|
-
|
|
193
|
-
it('supports `Field` for labeling', () => {
|
|
194
|
-
render(
|
|
195
|
-
<Field label="Label">
|
|
196
|
-
<SegmentedControl {...defaultProps} />
|
|
197
|
-
</Field>,
|
|
198
|
-
);
|
|
199
|
-
expect(screen.getAllByRole('group')[0]).toHaveAccessibleName(/^Label/);
|
|
200
|
-
});
|
|
201
191
|
});
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import React
|
|
1
|
+
import { StoryFn } from '@storybook/react';
|
|
2
|
+
import React from 'react';
|
|
3
3
|
|
|
4
4
|
import Button from '../button';
|
|
5
5
|
|
|
6
6
|
import SegmentedControl from './SegmentedControl';
|
|
7
|
-
import { Field } from '../field/Field';
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
export default {
|
|
10
9
|
component: SegmentedControl,
|
|
11
10
|
title: 'Forms/SegmentedControl',
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export default meta;
|
|
15
|
-
type Story = StoryObj<typeof meta>;
|
|
11
|
+
};
|
|
16
12
|
|
|
17
13
|
const Template: StoryFn = (args) => {
|
|
18
14
|
const [segments, setSegments] = React.useState([
|
|
@@ -95,37 +91,3 @@ export const SegmentedControlView = {
|
|
|
95
91
|
mode: 'view',
|
|
96
92
|
},
|
|
97
93
|
};
|
|
98
|
-
|
|
99
|
-
export const WithinField = {
|
|
100
|
-
args: {
|
|
101
|
-
name: 'aSegmentedControl',
|
|
102
|
-
mode: 'input',
|
|
103
|
-
value: 'cupcakes',
|
|
104
|
-
segments: [
|
|
105
|
-
{ id: 'CUPCAKE', label: 'Cupcakes', value: 'cupcakes' },
|
|
106
|
-
{ id: 'SPONGECAKE', label: 'Sponge cake', value: 'spongecake' },
|
|
107
|
-
{ id: 'CARROT_CAKE', label: 'Carrot cake', value: 'carrotcake' },
|
|
108
|
-
],
|
|
109
|
-
onChange: () => {},
|
|
110
|
-
},
|
|
111
|
-
render: function Render({ value: initialValue, onChange, ...args }) {
|
|
112
|
-
const [value, setValue] = useState(initialValue);
|
|
113
|
-
return (
|
|
114
|
-
<SegmentedControl
|
|
115
|
-
value={value}
|
|
116
|
-
onChange={(nextValue) => {
|
|
117
|
-
setValue(nextValue);
|
|
118
|
-
onChange?.(nextValue);
|
|
119
|
-
}}
|
|
120
|
-
{...args}
|
|
121
|
-
/>
|
|
122
|
-
);
|
|
123
|
-
},
|
|
124
|
-
decorators: [
|
|
125
|
-
(Story) => (
|
|
126
|
-
<Field label="Label">
|
|
127
|
-
<Story />
|
|
128
|
-
</Field>
|
|
129
|
-
),
|
|
130
|
-
],
|
|
131
|
-
} satisfies Story;
|
|
@@ -3,7 +3,6 @@ import { createRef, useEffect, useRef, useState } from 'react';
|
|
|
3
3
|
|
|
4
4
|
import Body from '../body';
|
|
5
5
|
import { Typography } from '../common';
|
|
6
|
-
import { useInputAttributes } from '../inputs/contexts';
|
|
7
6
|
|
|
8
7
|
type SegmentBase = { id: string; label: string; value: string };
|
|
9
8
|
|
|
@@ -39,8 +38,6 @@ const SegmentedControl = ({
|
|
|
39
38
|
segments,
|
|
40
39
|
onChange,
|
|
41
40
|
}: SegmentedControlProps) => {
|
|
42
|
-
const inputAttributes = useInputAttributes({ nonLabelable: true });
|
|
43
|
-
|
|
44
41
|
const [animate, setAnimate] = useState(false);
|
|
45
42
|
|
|
46
43
|
const segmentsRef = useRef<HTMLDivElement>(null);
|
|
@@ -98,8 +95,7 @@ const SegmentedControl = ({
|
|
|
98
95
|
className={classNames('segmented-control__segments', {
|
|
99
96
|
'segmented-control__segments--no-animate': !animate,
|
|
100
97
|
})}
|
|
101
|
-
role={mode !== 'input' ? 'tablist' :
|
|
102
|
-
{...inputAttributes}
|
|
98
|
+
role={mode !== 'input' ? 'tablist' : undefined}
|
|
103
99
|
>
|
|
104
100
|
{segmentsWithRefs.map((segment) => {
|
|
105
101
|
const onSelect = () => {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
|
|
3
|
+
const TabList = ({ children }) => {
|
|
4
|
+
return (
|
|
5
|
+
<ul className="tabs__tab-list" role="tablist">
|
|
6
|
+
{children}
|
|
7
|
+
</ul>
|
|
8
|
+
);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
TabList.propTypes = {
|
|
12
|
+
children: PropTypes.oneOfType([PropTypes.object, PropTypes.array]).isRequired,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default TabList;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { Size, Width } from '../common';
|
|
4
|
+
|
|
5
|
+
import Tabs from './Tabs';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
component: Tabs,
|
|
9
|
+
title: 'Navigation/Tabs',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const Basic = () => {
|
|
13
|
+
const [selected, setSelected] = useState(0);
|
|
14
|
+
return (
|
|
15
|
+
<Tabs
|
|
16
|
+
className="tabs-custom-class"
|
|
17
|
+
name="tabs-docs"
|
|
18
|
+
transitionSpacing={Size.MEDIUM}
|
|
19
|
+
tabs={[
|
|
20
|
+
{
|
|
21
|
+
title: 'Title 1',
|
|
22
|
+
disabled: false,
|
|
23
|
+
content: (
|
|
24
|
+
<div className="p-a-2">
|
|
25
|
+
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Cum totam debitis similique
|
|
26
|
+
</div>
|
|
27
|
+
),
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
title: 'Title 2',
|
|
31
|
+
disabled: false,
|
|
32
|
+
content: (
|
|
33
|
+
<div className="p-a-2">Lorem ipsum dolor, sit amet consectetur adipisicing elit.</div>
|
|
34
|
+
),
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
title: 'Title 3',
|
|
38
|
+
disabled: true,
|
|
39
|
+
content: (
|
|
40
|
+
<div className="p-a-2">
|
|
41
|
+
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Cum totam debitis similique
|
|
42
|
+
</div>
|
|
43
|
+
),
|
|
44
|
+
},
|
|
45
|
+
]}
|
|
46
|
+
selected={selected}
|
|
47
|
+
animatePanelsOnClick
|
|
48
|
+
onTabSelect={(index) => setSelected(index)}
|
|
49
|
+
/>
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const AutoTabHeaderWidth = () => {
|
|
54
|
+
const [selected, setSelected] = useState(0);
|
|
55
|
+
return (
|
|
56
|
+
<Tabs
|
|
57
|
+
className="tabs-custom-class"
|
|
58
|
+
name="tabs-docs"
|
|
59
|
+
transitionSpacing={Size.MEDIUM}
|
|
60
|
+
headerWidth={Width.AUTO}
|
|
61
|
+
tabs={[
|
|
62
|
+
{
|
|
63
|
+
title: 'Title 1',
|
|
64
|
+
disabled: false,
|
|
65
|
+
content: (
|
|
66
|
+
<div className="p-a-2">
|
|
67
|
+
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Cum totam debitis similique
|
|
68
|
+
</div>
|
|
69
|
+
),
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
title: 'Title 2',
|
|
73
|
+
disabled: false,
|
|
74
|
+
content: (
|
|
75
|
+
<div className="p-a-2">
|
|
76
|
+
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Cum totam debitis similique
|
|
77
|
+
</div>
|
|
78
|
+
),
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
title: 'Title 3',
|
|
82
|
+
disabled: true,
|
|
83
|
+
content: (
|
|
84
|
+
<div className="p-a-2">
|
|
85
|
+
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Cum totam debitis similique
|
|
86
|
+
</div>
|
|
87
|
+
),
|
|
88
|
+
},
|
|
89
|
+
]}
|
|
90
|
+
selected={selected}
|
|
91
|
+
onTabSelect={(index) => setSelected(index)}
|
|
92
|
+
/>
|
|
93
|
+
);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export const NoPanelAnimation = () => {
|
|
97
|
+
const [selected, setSelected] = useState(0);
|
|
98
|
+
return (
|
|
99
|
+
<Tabs
|
|
100
|
+
animatePanels={false}
|
|
101
|
+
className="tabs-custom-class"
|
|
102
|
+
name="tabs-docs"
|
|
103
|
+
transitionSpacing={Size.MEDIUM}
|
|
104
|
+
tabs={[
|
|
105
|
+
{
|
|
106
|
+
title: 'Title 1',
|
|
107
|
+
disabled: false,
|
|
108
|
+
content: (
|
|
109
|
+
<div className="p-a-2">
|
|
110
|
+
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Cum totam debitis similique
|
|
111
|
+
</div>
|
|
112
|
+
),
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
title: 'Title 2',
|
|
116
|
+
disabled: false,
|
|
117
|
+
content: (
|
|
118
|
+
<div className="p-a-2">Lorem ipsum dolor, sit amet consectetur adipisicing elit.</div>
|
|
119
|
+
),
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
title: 'Title 3',
|
|
123
|
+
disabled: true,
|
|
124
|
+
content: (
|
|
125
|
+
<div className="p-a-2">
|
|
126
|
+
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Cum totam debitis similique
|
|
127
|
+
</div>
|
|
128
|
+
),
|
|
129
|
+
},
|
|
130
|
+
]}
|
|
131
|
+
selected={selected}
|
|
132
|
+
onTabSelect={(index) => setSelected(index)}
|
|
133
|
+
/>
|
|
134
|
+
);
|
|
135
|
+
};
|
package/src/tabs/TabList.tsx
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { useInputAttributes } from '../inputs/contexts';
|
|
2
|
-
|
|
3
|
-
export interface TabListProps {
|
|
4
|
-
children?: React.ReactNode;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export default function TabList({ children }: TabListProps) {
|
|
8
|
-
const inputAttributes = useInputAttributes({ nonLabelable: true });
|
|
9
|
-
|
|
10
|
-
return (
|
|
11
|
-
<ul className="tabs__tab-list" role="tablist" {...inputAttributes}>
|
|
12
|
-
{children}
|
|
13
|
-
</ul>
|
|
14
|
-
);
|
|
15
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { Field } from '../field/Field';
|
|
2
|
-
import { render, screen } from '../test-utils';
|
|
3
|
-
|
|
4
|
-
import Tabs from '.';
|
|
5
|
-
|
|
6
|
-
describe('Tabs', () => {
|
|
7
|
-
it('supports `Field` for labeling', () => {
|
|
8
|
-
render(
|
|
9
|
-
<Field label="Label">
|
|
10
|
-
<Tabs
|
|
11
|
-
tabs={[
|
|
12
|
-
{
|
|
13
|
-
title: 'Title 1',
|
|
14
|
-
disabled: false,
|
|
15
|
-
content: (
|
|
16
|
-
<div className="p-a-2">
|
|
17
|
-
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Cum totam debitis
|
|
18
|
-
similique
|
|
19
|
-
</div>
|
|
20
|
-
),
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
title: 'Title 2',
|
|
24
|
-
disabled: false,
|
|
25
|
-
content: (
|
|
26
|
-
<div className="p-a-2">
|
|
27
|
-
Lorem ipsum dolor, sit amet consectetur adipisicing elit.
|
|
28
|
-
</div>
|
|
29
|
-
),
|
|
30
|
-
},
|
|
31
|
-
]}
|
|
32
|
-
name="tabs-test"
|
|
33
|
-
selected={0}
|
|
34
|
-
onTabSelect={() => {}}
|
|
35
|
-
/>
|
|
36
|
-
</Field>,
|
|
37
|
-
);
|
|
38
|
-
expect(screen.getByRole('tablist')).toHaveAccessibleName(/^Label/);
|
|
39
|
-
});
|
|
40
|
-
});
|
package/src/tabs/Tabs.story.tsx
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
import { useState } from 'react';
|
|
3
|
-
|
|
4
|
-
import { Size, Width } from '../common';
|
|
5
|
-
import { Field } from '../field/Field';
|
|
6
|
-
|
|
7
|
-
import Tabs from './Tabs';
|
|
8
|
-
|
|
9
|
-
const meta = {
|
|
10
|
-
component: Tabs,
|
|
11
|
-
title: 'Navigation/Tabs',
|
|
12
|
-
} satisfies Meta<typeof Tabs>;
|
|
13
|
-
|
|
14
|
-
export default meta;
|
|
15
|
-
type Story = StoryObj<typeof meta>;
|
|
16
|
-
|
|
17
|
-
export const Basic = {
|
|
18
|
-
args: {
|
|
19
|
-
tabs: [
|
|
20
|
-
{
|
|
21
|
-
title: 'Title 1',
|
|
22
|
-
disabled: false,
|
|
23
|
-
content: (
|
|
24
|
-
<div className="p-a-2">
|
|
25
|
-
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Cum totam debitis similique
|
|
26
|
-
</div>
|
|
27
|
-
),
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
title: 'Title 2',
|
|
31
|
-
disabled: false,
|
|
32
|
-
content: (
|
|
33
|
-
<div className="p-a-2">Lorem ipsum dolor, sit amet consectetur adipisicing elit.</div>
|
|
34
|
-
),
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
title: 'Title 3',
|
|
38
|
-
disabled: true,
|
|
39
|
-
content: (
|
|
40
|
-
<div className="p-a-2">
|
|
41
|
-
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Cum totam debitis similique
|
|
42
|
-
</div>
|
|
43
|
-
),
|
|
44
|
-
},
|
|
45
|
-
],
|
|
46
|
-
},
|
|
47
|
-
render: function Render(args) {
|
|
48
|
-
const [selected, setSelected] = useState(0);
|
|
49
|
-
return (
|
|
50
|
-
<Tabs
|
|
51
|
-
className="tabs-custom-class"
|
|
52
|
-
name="tabs-docs"
|
|
53
|
-
transitionSpacing={Size.MEDIUM}
|
|
54
|
-
selected={selected}
|
|
55
|
-
animatePanelsOnClick
|
|
56
|
-
onTabSelect={(index: number) => setSelected(index)}
|
|
57
|
-
{...args}
|
|
58
|
-
/>
|
|
59
|
-
);
|
|
60
|
-
},
|
|
61
|
-
} satisfies Story;
|
|
62
|
-
|
|
63
|
-
export const AutoTabHeaderWidth = {
|
|
64
|
-
...Basic,
|
|
65
|
-
args: {
|
|
66
|
-
...Basic.args,
|
|
67
|
-
headerWidth: Width.AUTO,
|
|
68
|
-
},
|
|
69
|
-
} satisfies Story;
|
|
70
|
-
|
|
71
|
-
export const NoPanelAnimation = {
|
|
72
|
-
...Basic,
|
|
73
|
-
args: {
|
|
74
|
-
...Basic.args,
|
|
75
|
-
animatePanelsOnClick: false,
|
|
76
|
-
},
|
|
77
|
-
} satisfies Story;
|
|
78
|
-
|
|
79
|
-
export const WithinField = {
|
|
80
|
-
...Basic,
|
|
81
|
-
decorators: [
|
|
82
|
-
(Story) => (
|
|
83
|
-
<Field label="Label">
|
|
84
|
-
<Story />
|
|
85
|
-
</Field>
|
|
86
|
-
),
|
|
87
|
-
],
|
|
88
|
-
} satisfies Story;
|