@transferwise/components 46.119.5 → 46.120.1
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/alert/Alert.js +1 -1
- package/build/alert/Alert.js.map +1 -1
- package/build/alert/Alert.mjs +1 -1
- package/build/alert/Alert.mjs.map +1 -1
- package/build/checkbox/Checkbox.js +1 -1
- package/build/checkbox/Checkbox.js.map +1 -1
- package/build/checkbox/Checkbox.mjs +1 -1
- package/build/checkbox/Checkbox.mjs.map +1 -1
- package/build/common/initials.js +17 -7
- package/build/common/initials.js.map +1 -1
- package/build/common/initials.mjs +17 -7
- package/build/common/initials.mjs.map +1 -1
- package/build/field/Field.js +8 -4
- package/build/field/Field.js.map +1 -1
- package/build/field/Field.mjs +8 -4
- package/build/field/Field.mjs.map +1 -1
- package/build/inlineAlert/InlineAlert.js +1 -7
- package/build/inlineAlert/InlineAlert.js.map +1 -1
- package/build/inlineAlert/InlineAlert.mjs +1 -7
- package/build/inlineAlert/InlineAlert.mjs.map +1 -1
- package/build/main.css +20 -1
- package/build/prompt/InlinePrompt/InlinePrompt.js +2 -0
- package/build/prompt/InlinePrompt/InlinePrompt.js.map +1 -1
- package/build/prompt/InlinePrompt/InlinePrompt.mjs +2 -0
- package/build/prompt/InlinePrompt/InlinePrompt.mjs.map +1 -1
- package/build/radioGroup/RadioGroup.js +1 -0
- package/build/radioGroup/RadioGroup.js.map +1 -1
- package/build/radioGroup/RadioGroup.mjs +1 -0
- package/build/radioGroup/RadioGroup.mjs.map +1 -1
- package/build/styles/field/Field.css +10 -1
- package/build/styles/main.css +20 -1
- package/build/styles/prompt/InlinePrompt/InlinePrompt.css +3 -0
- package/build/styles/radioGroup/RadioGroup.css +3 -0
- package/build/styles/typeahead/Typeahead.css +4 -0
- package/build/typeahead/Typeahead.js +20 -7
- package/build/typeahead/Typeahead.js.map +1 -1
- package/build/typeahead/Typeahead.mjs +20 -7
- package/build/typeahead/Typeahead.mjs.map +1 -1
- package/build/types/alert/Alert.d.ts +1 -1
- package/build/types/alert/Alert.d.ts.map +1 -1
- package/build/types/common/initials.d.ts.map +1 -1
- package/build/types/field/Field.d.ts +8 -4
- package/build/types/field/Field.d.ts.map +1 -1
- package/build/types/inlineAlert/InlineAlert.d.ts +1 -7
- package/build/types/inlineAlert/InlineAlert.d.ts.map +1 -1
- package/build/types/listItem/_stories/variants/helpers.d.ts +7 -4
- package/build/types/listItem/_stories/variants/helpers.d.ts.map +1 -1
- package/build/types/prompt/InlinePrompt/InlinePrompt.d.ts +6 -1
- package/build/types/prompt/InlinePrompt/InlinePrompt.d.ts.map +1 -1
- package/build/types/radioGroup/RadioGroup.d.ts.map +1 -1
- package/build/types/test-utils/index.d.ts +0 -1
- package/build/types/test-utils/index.d.ts.map +1 -1
- package/build/types/typeahead/Typeahead.d.ts +8 -4
- package/build/types/typeahead/Typeahead.d.ts.map +1 -1
- package/build/types/upload/Upload.d.ts +1 -1
- package/build/types/upload/steps/uploadImageStep/uploadImageStep.d.ts.map +1 -1
- package/build/upload/Upload.js.map +1 -1
- package/build/upload/Upload.mjs.map +1 -1
- package/build/upload/steps/uploadImageStep/uploadImageStep.js +5 -4
- package/build/upload/steps/uploadImageStep/uploadImageStep.js.map +1 -1
- package/build/upload/steps/uploadImageStep/uploadImageStep.mjs +5 -4
- package/build/upload/steps/uploadImageStep/uploadImageStep.mjs.map +1 -1
- package/package.json +9 -8
- package/src/DisabledComponents.story.tsx +1 -3
- package/src/actionButton/ActionButton.story.tsx +42 -45
- package/src/alert/Alert.spec.tsx +1 -1
- package/src/alert/Alert.tsx +2 -2
- package/src/avatar/Avatar.story.tsx +192 -188
- package/src/button/_stories/Button.tests.story.tsx +122 -119
- package/src/carousel/Carousel.story.tsx +4 -7
- package/src/checkbox/Checkbox.story.tsx +42 -21
- package/src/checkbox/Checkbox.tsx +1 -1
- package/src/checkbox/__snapshots__/Checkbox.spec.tsx.snap +1 -1
- package/src/circularButton/CircularButton.story.tsx +10 -2
- package/src/common/bottomSheet/BottomSheet.story.tsx +48 -14
- package/src/common/circle/Circle.story.tsx +62 -55
- package/src/common/initials.spec.tsx +31 -0
- package/src/common/initials.ts +19 -8
- package/src/criticalBanner/CriticalCommsBanner.story.tsx +30 -19
- package/src/dateInput/DateInput.tests.story.tsx +101 -74
- package/src/dateLookup/DateLookup.story.tsx +69 -59
- package/src/field/Field.css +10 -1
- package/src/field/Field.less +13 -2
- package/src/field/Field.spec.tsx +19 -3
- package/src/field/Field.story.tsx +18 -0
- package/src/field/Field.tsx +17 -5
- package/src/header/Header.story.tsx +5 -16
- package/src/header/Header.tests.story.tsx +95 -69
- package/src/info/Info.story.tsx +27 -11
- package/src/inlineAlert/InlineAlert.story.tsx +4 -0
- package/src/inlineAlert/InlineAlert.tsx +1 -7
- package/src/instructionsList/InstructionsList.story.tsx +0 -1
- package/src/listItem/_stories/ListItem.layout.test.story.tsx +1 -3
- package/src/listItem/_stories/variants/ListItem.brightGreen.test.story.tsx +77 -35
- package/src/listItem/_stories/variants/ListItem.dark.test.story.tsx +65 -29
- package/src/listItem/_stories/variants/ListItem.forestGreen.test.story.tsx +77 -35
- package/src/listItem/_stories/variants/ListItem.medium.test.story.tsx +38 -18
- package/src/listItem/_stories/variants/ListItem.neutral.test.story.tsx +0 -1
- package/src/listItem/_stories/variants/ListItem.personal.test.story.tsx +38 -18
- package/src/listItem/_stories/variants/ListItem.rtl.test.story.tsx +77 -29
- package/src/listItem/_stories/variants/ListItem.small.test.story.tsx +65 -18
- package/src/listItem/_stories/variants/helpers.tsx +136 -133
- package/src/main.css +20 -1
- package/src/main.less +1 -0
- package/src/modal/Modal.story.tsx +47 -8
- package/src/moneyInput/MoneyInput.story.tsx +2 -2
- package/src/primitives/PrimitiveAnchor/stories/PrimitiveAnchor.story.tsx +1 -0
- package/src/primitives/PrimitiveAnchor/stories/PrimitiveAnchor.tests.story.tsx +1 -0
- package/src/primitives/PrimitiveButton/stories/PrimitiveButton.story.tsx +1 -0
- package/src/primitives/PrimitiveButton/stories/PrimitiveButton.tests.story.tsx +1 -0
- package/src/prompt/InlinePrompt/InlinePrompt.css +3 -0
- package/src/prompt/InlinePrompt/InlinePrompt.less +5 -1
- package/src/prompt/InlinePrompt/InlinePrompt.spec.tsx +17 -0
- package/src/prompt/InlinePrompt/InlinePrompt.story.tsx +35 -0
- package/src/prompt/InlinePrompt/InlinePrompt.tsx +7 -0
- package/src/provider/theme/ThemeProvider.story.tsx +1 -0
- package/src/radioGroup/RadioGroup.css +3 -0
- package/src/radioGroup/RadioGroup.less +3 -0
- package/src/radioGroup/RadioGroup.story.tsx +2 -0
- package/src/radioGroup/RadioGroup.test.story.tsx +62 -0
- package/src/radioGroup/RadioGroup.tsx +6 -1
- package/src/segmentedControl/SegmentedControl.story.tsx +71 -67
- package/src/snackbar/Snackbar.tests.story.tsx +116 -114
- package/src/statusIcon/StatusIcon.story.tsx +41 -38
- package/src/test-utils/index.tsx +0 -2
- package/src/tokens/tokens.story.tsx +1 -1
- package/src/tooltip/Tooltip.story.tsx +10 -2
- package/src/typeahead/Typeahead.css +4 -0
- package/src/typeahead/Typeahead.less +5 -1
- package/src/typeahead/Typeahead.spec.tsx +1 -1
- package/src/typeahead/Typeahead.story.tsx +151 -3
- package/src/typeahead/Typeahead.tsx +33 -9
- package/src/upload/Upload.story.tsx +1 -1
- package/src/upload/Upload.tests.story.tsx +36 -1
- package/src/upload/Upload.tsx +1 -1
- package/src/upload/steps/uploadImageStep/uploadImageStep.tsx +7 -3
- package/src/withId/withId.story.tsx +1 -1
- package/build/types/test-utils/story-config.d.ts +0 -64
- package/build/types/test-utils/story-config.d.ts.map +0 -1
- package/src/test-utils/story-config.ts +0 -95
|
@@ -16,8 +16,7 @@ import {
|
|
|
16
16
|
removeClickClassFromDocumentOnIos,
|
|
17
17
|
stopPropagation,
|
|
18
18
|
} from '../common';
|
|
19
|
-
import
|
|
20
|
-
import { InlineAlertProps } from '../inlineAlert/InlineAlert';
|
|
19
|
+
import { InlinePrompt, InlinePromptProps } from '../prompt';
|
|
21
20
|
import { withInputAttributes, WithInputAttributesProps } from '../inputs/contexts';
|
|
22
21
|
|
|
23
22
|
import TypeaheadInput from './typeaheadInput/TypeaheadInput';
|
|
@@ -40,9 +39,17 @@ export interface TypeaheadProps<T> extends Partial<WrappedComponentProps> {
|
|
|
40
39
|
id: string;
|
|
41
40
|
name: string;
|
|
42
41
|
addon?: ReactNode;
|
|
42
|
+
/**
|
|
43
|
+
* @deprecated Please use [`Field`](?path=/docs/forms-field--docs) component and its `message` and `sentiment` props instead.
|
|
44
|
+
* @deprecated `error`, `info` and `success` are deprecated as alert types and will be soon removed.
|
|
45
|
+
*/
|
|
43
46
|
alert?: {
|
|
44
|
-
message:
|
|
45
|
-
type?:
|
|
47
|
+
message: InlinePromptProps['children'];
|
|
48
|
+
type?:
|
|
49
|
+
| InlinePromptProps['sentiment']
|
|
50
|
+
| `${Sentiment.ERROR}`
|
|
51
|
+
| `${Sentiment.INFO}`
|
|
52
|
+
| `${Sentiment.SUCCESS}`;
|
|
46
53
|
};
|
|
47
54
|
allowNew?: boolean;
|
|
48
55
|
autoFillOnBlur?: boolean;
|
|
@@ -474,9 +481,20 @@ class Typeahead<T> extends Component<TypeaheadPropsWithInputAttributes<T>, Typea
|
|
|
474
481
|
dropdownOpen,
|
|
475
482
|
});
|
|
476
483
|
|
|
477
|
-
const alertType =
|
|
478
|
-
|
|
479
|
-
|
|
484
|
+
const alertType = (() => {
|
|
485
|
+
if (!alert?.type || alert.type === Sentiment.INFO) {
|
|
486
|
+
return Sentiment.NEUTRAL;
|
|
487
|
+
}
|
|
488
|
+
if (alert.type === Sentiment.ERROR) {
|
|
489
|
+
return Sentiment.NEGATIVE;
|
|
490
|
+
}
|
|
491
|
+
if (alert.type === Sentiment.SUCCESS) {
|
|
492
|
+
return Sentiment.POSITIVE;
|
|
493
|
+
}
|
|
494
|
+
return alert.type;
|
|
495
|
+
})();
|
|
496
|
+
const hasError = errorState || (alert && alertType === Sentiment.NEGATIVE);
|
|
497
|
+
const displayAlert = (!errorState && alert) || (alert && alertType === Sentiment.NEGATIVE);
|
|
480
498
|
const hasWarning = displayAlert && alertType === Sentiment.WARNING;
|
|
481
499
|
const hasInfo = displayAlert && alertType === Sentiment.NEUTRAL;
|
|
482
500
|
return (
|
|
@@ -494,7 +512,7 @@ class Typeahead<T> extends Component<TypeaheadPropsWithInputAttributes<T>, Typea
|
|
|
494
512
|
onClick={stopPropagation}
|
|
495
513
|
>
|
|
496
514
|
<div
|
|
497
|
-
className={clsx('form-group', {
|
|
515
|
+
className={clsx('form-group', 'form-group--typeahead', {
|
|
498
516
|
'has-error': hasError,
|
|
499
517
|
'has-warning': hasWarning,
|
|
500
518
|
'has-info': hasInfo,
|
|
@@ -546,7 +564,13 @@ class Typeahead<T> extends Component<TypeaheadPropsWithInputAttributes<T>, Typea
|
|
|
546
564
|
</div>
|
|
547
565
|
)}
|
|
548
566
|
</div>
|
|
549
|
-
{displayAlert ?
|
|
567
|
+
{displayAlert ? (
|
|
568
|
+
<InlinePrompt sentiment={alertType} className="typeahead--prompt" width="full">
|
|
569
|
+
{alert.message}
|
|
570
|
+
</InlinePrompt>
|
|
571
|
+
) : (
|
|
572
|
+
menu
|
|
573
|
+
)}
|
|
550
574
|
</div>
|
|
551
575
|
</div>
|
|
552
576
|
);
|
|
@@ -71,7 +71,7 @@ const meta = {
|
|
|
71
71
|
},
|
|
72
72
|
errorIconLabel: {
|
|
73
73
|
description:
|
|
74
|
-
"Override for the
|
|
74
|
+
"Override for the InlinePrompt icon's default, accessible name announced by the screen readers",
|
|
75
75
|
},
|
|
76
76
|
usHelpImage: {
|
|
77
77
|
control: false,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Meta } from '@storybook/react-webpack5';
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-webpack5';
|
|
2
|
+
import { userEvent, within, waitFor } from 'storybook/test';
|
|
2
3
|
|
|
3
4
|
import Upload from '.';
|
|
4
5
|
import { Field } from '../field/Field';
|
|
@@ -73,6 +74,40 @@ export const MaxSizes = () => {
|
|
|
73
74
|
);
|
|
74
75
|
};
|
|
75
76
|
|
|
77
|
+
export const WithError: StoryObj<typeof meta> = {
|
|
78
|
+
render: () => (
|
|
79
|
+
<Field label="Upload a file">
|
|
80
|
+
<Upload
|
|
81
|
+
usAccept="*"
|
|
82
|
+
usLabel="Upload a file"
|
|
83
|
+
usPlaceholder="Maximum filesize is 1B"
|
|
84
|
+
usDisabled={false}
|
|
85
|
+
maxSize={1}
|
|
86
|
+
errorIconLabel="File too large error"
|
|
87
|
+
httpOptions={{
|
|
88
|
+
url: 'https://httpbin.org/post',
|
|
89
|
+
method: 'POST',
|
|
90
|
+
}}
|
|
91
|
+
/>
|
|
92
|
+
</Field>
|
|
93
|
+
),
|
|
94
|
+
play: async ({ canvasElement }) => {
|
|
95
|
+
const canvas = within(canvasElement);
|
|
96
|
+
const fileInput = canvasElement.querySelector<HTMLInputElement>('input[type="file"]');
|
|
97
|
+
|
|
98
|
+
if (!fileInput) {
|
|
99
|
+
throw new Error('File input not found');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const file = new File(['This file content is definitely more than 1 byte'], 'test-file.txt', {
|
|
103
|
+
type: 'text/plain',
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
await userEvent.upload(fileInput, file);
|
|
107
|
+
await waitFor(async () => canvas.findByText(/Maximum filesize is/i), { timeout: 3000 });
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
|
|
76
111
|
export const AllVariants = () => {
|
|
77
112
|
return (
|
|
78
113
|
<div style={{ display: 'flex', gap: '1rem' }}>
|
package/src/upload/Upload.tsx
CHANGED
|
@@ -55,7 +55,7 @@ export interface UploadProps extends WrappedComponentProps {
|
|
|
55
55
|
usLabel?: string;
|
|
56
56
|
usPlaceholder?: string;
|
|
57
57
|
/**
|
|
58
|
-
* Override for the [
|
|
58
|
+
* Override for the [InlinePrompt icon's default, accessible name](/?path=/docs/other-statusicon-accessibility--docs)
|
|
59
59
|
* announced by the screen readers
|
|
60
60
|
* */
|
|
61
61
|
errorIconLabel?: string;
|
|
@@ -2,7 +2,7 @@ import { Upload as UploadIcon } from '@transferwise/icons';
|
|
|
2
2
|
import { createRef, PureComponent } from 'react';
|
|
3
3
|
import StatusIcon from '../../../statusIcon';
|
|
4
4
|
import { Sentiment, Size } from '../../../common';
|
|
5
|
-
import
|
|
5
|
+
import { InlinePrompt } from '../../../prompt/InlinePrompt/InlinePrompt';
|
|
6
6
|
|
|
7
7
|
export interface UploadImageStepProps {
|
|
8
8
|
fileDropped: (file: File) => void;
|
|
@@ -105,9 +105,13 @@ export default class UploadImageStep extends PureComponent<UploadImageStepProps>
|
|
|
105
105
|
{errorMessage && (
|
|
106
106
|
<div className="upload-error-message">
|
|
107
107
|
<div className="m-t-3 has-error">
|
|
108
|
-
<
|
|
108
|
+
<InlinePrompt
|
|
109
|
+
sentiment={Sentiment.NEGATIVE}
|
|
110
|
+
mediaLabel={errorIconLabel}
|
|
111
|
+
width="full"
|
|
112
|
+
>
|
|
109
113
|
{errorMessage}
|
|
110
|
-
</
|
|
114
|
+
</InlinePrompt>
|
|
111
115
|
</div>
|
|
112
116
|
</div>
|
|
113
117
|
)}
|
|
@@ -27,7 +27,7 @@ DescribedButton.displayName = 'DescribedButton';
|
|
|
27
27
|
export default {
|
|
28
28
|
component: DescribedButton,
|
|
29
29
|
title: 'HoCs/withId',
|
|
30
|
-
tags: ['docs-only'],
|
|
30
|
+
tags: ['docs-only', '!manifest'],
|
|
31
31
|
} satisfies Meta<typeof withId>;
|
|
32
32
|
|
|
33
33
|
export const WithoutId: Story = {};
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { StoryObj } from '@storybook/react-webpack5';
|
|
2
|
-
export declare const viewports: {
|
|
3
|
-
mobile3: {
|
|
4
|
-
name: string;
|
|
5
|
-
styles: {
|
|
6
|
-
height: string;
|
|
7
|
-
width: string;
|
|
8
|
-
};
|
|
9
|
-
type: string;
|
|
10
|
-
};
|
|
11
|
-
desktop: {
|
|
12
|
-
name: string;
|
|
13
|
-
styles: {
|
|
14
|
-
height: string;
|
|
15
|
-
width: string;
|
|
16
|
-
};
|
|
17
|
-
type: string;
|
|
18
|
-
};
|
|
19
|
-
mobile1: {
|
|
20
|
-
readonly name: "Small mobile";
|
|
21
|
-
readonly styles: {
|
|
22
|
-
readonly height: "568px";
|
|
23
|
-
readonly width: "320px";
|
|
24
|
-
};
|
|
25
|
-
readonly type: "mobile";
|
|
26
|
-
};
|
|
27
|
-
mobile2: {
|
|
28
|
-
readonly name: "Large mobile";
|
|
29
|
-
readonly styles: {
|
|
30
|
-
readonly height: "896px";
|
|
31
|
-
readonly width: "414px";
|
|
32
|
-
};
|
|
33
|
-
readonly type: "mobile";
|
|
34
|
-
};
|
|
35
|
-
tablet: {
|
|
36
|
-
readonly name: "Tablet";
|
|
37
|
-
readonly styles: {
|
|
38
|
-
readonly height: "1112px";
|
|
39
|
-
readonly width: "834px";
|
|
40
|
-
};
|
|
41
|
-
readonly type: "tablet";
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
export interface StoryConfig {
|
|
45
|
-
/**
|
|
46
|
-
* Creates variations of the component for the current story. Some
|
|
47
|
-
* padding is applied to the variants for spacing.
|
|
48
|
-
*
|
|
49
|
-
* - `default` adds just the story itself with some padding.
|
|
50
|
-
* - `light` adds a light theme variant.
|
|
51
|
-
* - `dark` adds a dark theme variant.
|
|
52
|
-
* - `rtl` adds a right-to-left writing mode variant.
|
|
53
|
-
* - `mobile` sets the default viewport for the Story with mobile
|
|
54
|
-
* dimensions and uses those dimensions for snapshots.
|
|
55
|
-
*
|
|
56
|
-
* @default undefined
|
|
57
|
-
*/
|
|
58
|
-
variants?: ('default' | 'light' | 'dark' | 'bright-green' | 'forest-green' | 'business' | 'business--forest-green' | 'business--bright-green' | 'platform' | 'platform--forest-green' | 'rtl' | 'mobile' | '400%')[];
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Utility function for creating variants of a CSFv3 story.
|
|
62
|
-
*/
|
|
63
|
-
export declare const storyConfig: <Args>(storyObject: StoryObj<Args>, { variants }: StoryConfig) => StoryObj<Args>;
|
|
64
|
-
//# sourceMappingURL=story-config.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"story-config.d.ts","sourceRoot":"","sources":["../../../src/test-utils/story-config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAErD,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAarB,CAAC;AAEF,MAAM,WAAW,WAAW;IAC1B;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,EAAE,CACP,SAAS,GACT,OAAO,GACP,MAAM,GACN,cAAc,GACd,cAAc,GACd,UAAU,GACV,wBAAwB,GACxB,wBAAwB,GACxB,UAAU,GACV,wBAAwB,GACxB,KAAK,GACL,QAAQ,GACR,MAAM,CACT,EAAE,CAAC;CACL;AAkBD;;GAEG;AACH,eAAO,MAAM,WAAW,GAAI,IAAI,EAC9B,aAAa,QAAQ,CAAC,IAAI,CAAC,EAC3B,cAAc,WAAW,KACxB,QAAQ,CAAC,IAAI,CAuBf,CAAC"}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { MINIMAL_VIEWPORTS } from 'storybook/viewport';
|
|
2
|
-
import { StoryObj } from '@storybook/react-webpack5';
|
|
3
|
-
|
|
4
|
-
export const viewports = {
|
|
5
|
-
...MINIMAL_VIEWPORTS,
|
|
6
|
-
mobile3: {
|
|
7
|
-
name: '400% Zoom',
|
|
8
|
-
// 320x256 https://www.w3.org/WAI/WCAG21/Understanding/reflow.html
|
|
9
|
-
styles: { height: '256px', width: '320px' },
|
|
10
|
-
type: 'mobile',
|
|
11
|
-
},
|
|
12
|
-
desktop: {
|
|
13
|
-
name: 'Desktop',
|
|
14
|
-
styles: { height: '1024px', width: '1280px' },
|
|
15
|
-
type: 'desktop',
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export interface StoryConfig {
|
|
20
|
-
/**
|
|
21
|
-
* Creates variations of the component for the current story. Some
|
|
22
|
-
* padding is applied to the variants for spacing.
|
|
23
|
-
*
|
|
24
|
-
* - `default` adds just the story itself with some padding.
|
|
25
|
-
* - `light` adds a light theme variant.
|
|
26
|
-
* - `dark` adds a dark theme variant.
|
|
27
|
-
* - `rtl` adds a right-to-left writing mode variant.
|
|
28
|
-
* - `mobile` sets the default viewport for the Story with mobile
|
|
29
|
-
* dimensions and uses those dimensions for snapshots.
|
|
30
|
-
*
|
|
31
|
-
* @default undefined
|
|
32
|
-
*/
|
|
33
|
-
variants?: (
|
|
34
|
-
| 'default'
|
|
35
|
-
| 'light'
|
|
36
|
-
| 'dark'
|
|
37
|
-
| 'bright-green'
|
|
38
|
-
| 'forest-green'
|
|
39
|
-
| 'business'
|
|
40
|
-
| 'business--forest-green'
|
|
41
|
-
| 'business--bright-green'
|
|
42
|
-
| 'platform'
|
|
43
|
-
| 'platform--forest-green'
|
|
44
|
-
| 'rtl'
|
|
45
|
-
| 'mobile'
|
|
46
|
-
| '400%'
|
|
47
|
-
)[];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const getViewportWidth = (viewport: (typeof viewports)[keyof typeof viewports]) => {
|
|
51
|
-
if (viewport.styles && typeof viewport.styles === 'object') {
|
|
52
|
-
return Number.parseInt(viewport.styles.width, 10);
|
|
53
|
-
}
|
|
54
|
-
throw new Error('Unknown viewport styles');
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* The key to 'Large mobile' viewport {@link viewports.mobile2}
|
|
59
|
-
*/
|
|
60
|
-
const mobileViewportKey = 'mobile2';
|
|
61
|
-
const mobileViewportWidth = getViewportWidth(viewports.mobile2);
|
|
62
|
-
|
|
63
|
-
const zoom400perViewportKey = 'mobile3';
|
|
64
|
-
const zoom400perViewportWidth = getViewportWidth(viewports.mobile3);
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Utility function for creating variants of a CSFv3 story.
|
|
68
|
-
*/
|
|
69
|
-
export const storyConfig = <Args>(
|
|
70
|
-
storyObject: StoryObj<Args>,
|
|
71
|
-
{ variants }: StoryConfig,
|
|
72
|
-
): StoryObj<Args> => {
|
|
73
|
-
const isMobile = variants?.includes('mobile') || undefined;
|
|
74
|
-
const is400Zoom = variants?.includes('400%') || undefined;
|
|
75
|
-
|
|
76
|
-
return {
|
|
77
|
-
...storyObject,
|
|
78
|
-
parameters: {
|
|
79
|
-
...storyObject.parameters,
|
|
80
|
-
variants,
|
|
81
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
82
|
-
chromatic: {
|
|
83
|
-
...storyObject.parameters?.chromatic,
|
|
84
|
-
viewports: (isMobile && [mobileViewportWidth]) || (is400Zoom && [zoom400perViewportWidth]),
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
globals: {
|
|
88
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
89
|
-
viewport: {
|
|
90
|
-
...storyObject.globals?.viewport,
|
|
91
|
-
value: (isMobile && mobileViewportKey) || (is400Zoom && zoom400perViewportKey),
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
};
|
|
95
|
-
};
|