@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.
Files changed (140) hide show
  1. package/build/alert/Alert.js +1 -1
  2. package/build/alert/Alert.js.map +1 -1
  3. package/build/alert/Alert.mjs +1 -1
  4. package/build/alert/Alert.mjs.map +1 -1
  5. package/build/checkbox/Checkbox.js +1 -1
  6. package/build/checkbox/Checkbox.js.map +1 -1
  7. package/build/checkbox/Checkbox.mjs +1 -1
  8. package/build/checkbox/Checkbox.mjs.map +1 -1
  9. package/build/common/initials.js +17 -7
  10. package/build/common/initials.js.map +1 -1
  11. package/build/common/initials.mjs +17 -7
  12. package/build/common/initials.mjs.map +1 -1
  13. package/build/field/Field.js +8 -4
  14. package/build/field/Field.js.map +1 -1
  15. package/build/field/Field.mjs +8 -4
  16. package/build/field/Field.mjs.map +1 -1
  17. package/build/inlineAlert/InlineAlert.js +1 -7
  18. package/build/inlineAlert/InlineAlert.js.map +1 -1
  19. package/build/inlineAlert/InlineAlert.mjs +1 -7
  20. package/build/inlineAlert/InlineAlert.mjs.map +1 -1
  21. package/build/main.css +20 -1
  22. package/build/prompt/InlinePrompt/InlinePrompt.js +2 -0
  23. package/build/prompt/InlinePrompt/InlinePrompt.js.map +1 -1
  24. package/build/prompt/InlinePrompt/InlinePrompt.mjs +2 -0
  25. package/build/prompt/InlinePrompt/InlinePrompt.mjs.map +1 -1
  26. package/build/radioGroup/RadioGroup.js +1 -0
  27. package/build/radioGroup/RadioGroup.js.map +1 -1
  28. package/build/radioGroup/RadioGroup.mjs +1 -0
  29. package/build/radioGroup/RadioGroup.mjs.map +1 -1
  30. package/build/styles/field/Field.css +10 -1
  31. package/build/styles/main.css +20 -1
  32. package/build/styles/prompt/InlinePrompt/InlinePrompt.css +3 -0
  33. package/build/styles/radioGroup/RadioGroup.css +3 -0
  34. package/build/styles/typeahead/Typeahead.css +4 -0
  35. package/build/typeahead/Typeahead.js +20 -7
  36. package/build/typeahead/Typeahead.js.map +1 -1
  37. package/build/typeahead/Typeahead.mjs +20 -7
  38. package/build/typeahead/Typeahead.mjs.map +1 -1
  39. package/build/types/alert/Alert.d.ts +1 -1
  40. package/build/types/alert/Alert.d.ts.map +1 -1
  41. package/build/types/common/initials.d.ts.map +1 -1
  42. package/build/types/field/Field.d.ts +8 -4
  43. package/build/types/field/Field.d.ts.map +1 -1
  44. package/build/types/inlineAlert/InlineAlert.d.ts +1 -7
  45. package/build/types/inlineAlert/InlineAlert.d.ts.map +1 -1
  46. package/build/types/listItem/_stories/variants/helpers.d.ts +7 -4
  47. package/build/types/listItem/_stories/variants/helpers.d.ts.map +1 -1
  48. package/build/types/prompt/InlinePrompt/InlinePrompt.d.ts +6 -1
  49. package/build/types/prompt/InlinePrompt/InlinePrompt.d.ts.map +1 -1
  50. package/build/types/radioGroup/RadioGroup.d.ts.map +1 -1
  51. package/build/types/test-utils/index.d.ts +0 -1
  52. package/build/types/test-utils/index.d.ts.map +1 -1
  53. package/build/types/typeahead/Typeahead.d.ts +8 -4
  54. package/build/types/typeahead/Typeahead.d.ts.map +1 -1
  55. package/build/types/upload/Upload.d.ts +1 -1
  56. package/build/types/upload/steps/uploadImageStep/uploadImageStep.d.ts.map +1 -1
  57. package/build/upload/Upload.js.map +1 -1
  58. package/build/upload/Upload.mjs.map +1 -1
  59. package/build/upload/steps/uploadImageStep/uploadImageStep.js +5 -4
  60. package/build/upload/steps/uploadImageStep/uploadImageStep.js.map +1 -1
  61. package/build/upload/steps/uploadImageStep/uploadImageStep.mjs +5 -4
  62. package/build/upload/steps/uploadImageStep/uploadImageStep.mjs.map +1 -1
  63. package/package.json +9 -8
  64. package/src/DisabledComponents.story.tsx +1 -3
  65. package/src/actionButton/ActionButton.story.tsx +42 -45
  66. package/src/alert/Alert.spec.tsx +1 -1
  67. package/src/alert/Alert.tsx +2 -2
  68. package/src/avatar/Avatar.story.tsx +192 -188
  69. package/src/button/_stories/Button.tests.story.tsx +122 -119
  70. package/src/carousel/Carousel.story.tsx +4 -7
  71. package/src/checkbox/Checkbox.story.tsx +42 -21
  72. package/src/checkbox/Checkbox.tsx +1 -1
  73. package/src/checkbox/__snapshots__/Checkbox.spec.tsx.snap +1 -1
  74. package/src/circularButton/CircularButton.story.tsx +10 -2
  75. package/src/common/bottomSheet/BottomSheet.story.tsx +48 -14
  76. package/src/common/circle/Circle.story.tsx +62 -55
  77. package/src/common/initials.spec.tsx +31 -0
  78. package/src/common/initials.ts +19 -8
  79. package/src/criticalBanner/CriticalCommsBanner.story.tsx +30 -19
  80. package/src/dateInput/DateInput.tests.story.tsx +101 -74
  81. package/src/dateLookup/DateLookup.story.tsx +69 -59
  82. package/src/field/Field.css +10 -1
  83. package/src/field/Field.less +13 -2
  84. package/src/field/Field.spec.tsx +19 -3
  85. package/src/field/Field.story.tsx +18 -0
  86. package/src/field/Field.tsx +17 -5
  87. package/src/header/Header.story.tsx +5 -16
  88. package/src/header/Header.tests.story.tsx +95 -69
  89. package/src/info/Info.story.tsx +27 -11
  90. package/src/inlineAlert/InlineAlert.story.tsx +4 -0
  91. package/src/inlineAlert/InlineAlert.tsx +1 -7
  92. package/src/instructionsList/InstructionsList.story.tsx +0 -1
  93. package/src/listItem/_stories/ListItem.layout.test.story.tsx +1 -3
  94. package/src/listItem/_stories/variants/ListItem.brightGreen.test.story.tsx +77 -35
  95. package/src/listItem/_stories/variants/ListItem.dark.test.story.tsx +65 -29
  96. package/src/listItem/_stories/variants/ListItem.forestGreen.test.story.tsx +77 -35
  97. package/src/listItem/_stories/variants/ListItem.medium.test.story.tsx +38 -18
  98. package/src/listItem/_stories/variants/ListItem.neutral.test.story.tsx +0 -1
  99. package/src/listItem/_stories/variants/ListItem.personal.test.story.tsx +38 -18
  100. package/src/listItem/_stories/variants/ListItem.rtl.test.story.tsx +77 -29
  101. package/src/listItem/_stories/variants/ListItem.small.test.story.tsx +65 -18
  102. package/src/listItem/_stories/variants/helpers.tsx +136 -133
  103. package/src/main.css +20 -1
  104. package/src/main.less +1 -0
  105. package/src/modal/Modal.story.tsx +47 -8
  106. package/src/moneyInput/MoneyInput.story.tsx +2 -2
  107. package/src/primitives/PrimitiveAnchor/stories/PrimitiveAnchor.story.tsx +1 -0
  108. package/src/primitives/PrimitiveAnchor/stories/PrimitiveAnchor.tests.story.tsx +1 -0
  109. package/src/primitives/PrimitiveButton/stories/PrimitiveButton.story.tsx +1 -0
  110. package/src/primitives/PrimitiveButton/stories/PrimitiveButton.tests.story.tsx +1 -0
  111. package/src/prompt/InlinePrompt/InlinePrompt.css +3 -0
  112. package/src/prompt/InlinePrompt/InlinePrompt.less +5 -1
  113. package/src/prompt/InlinePrompt/InlinePrompt.spec.tsx +17 -0
  114. package/src/prompt/InlinePrompt/InlinePrompt.story.tsx +35 -0
  115. package/src/prompt/InlinePrompt/InlinePrompt.tsx +7 -0
  116. package/src/provider/theme/ThemeProvider.story.tsx +1 -0
  117. package/src/radioGroup/RadioGroup.css +3 -0
  118. package/src/radioGroup/RadioGroup.less +3 -0
  119. package/src/radioGroup/RadioGroup.story.tsx +2 -0
  120. package/src/radioGroup/RadioGroup.test.story.tsx +62 -0
  121. package/src/radioGroup/RadioGroup.tsx +6 -1
  122. package/src/segmentedControl/SegmentedControl.story.tsx +71 -67
  123. package/src/snackbar/Snackbar.tests.story.tsx +116 -114
  124. package/src/statusIcon/StatusIcon.story.tsx +41 -38
  125. package/src/test-utils/index.tsx +0 -2
  126. package/src/tokens/tokens.story.tsx +1 -1
  127. package/src/tooltip/Tooltip.story.tsx +10 -2
  128. package/src/typeahead/Typeahead.css +4 -0
  129. package/src/typeahead/Typeahead.less +5 -1
  130. package/src/typeahead/Typeahead.spec.tsx +1 -1
  131. package/src/typeahead/Typeahead.story.tsx +151 -3
  132. package/src/typeahead/Typeahead.tsx +33 -9
  133. package/src/upload/Upload.story.tsx +1 -1
  134. package/src/upload/Upload.tests.story.tsx +36 -1
  135. package/src/upload/Upload.tsx +1 -1
  136. package/src/upload/steps/uploadImageStep/uploadImageStep.tsx +7 -3
  137. package/src/withId/withId.story.tsx +1 -1
  138. package/build/types/test-utils/story-config.d.ts +0 -64
  139. package/build/types/test-utils/story-config.d.ts.map +0 -1
  140. package/src/test-utils/story-config.ts +0 -95
package/src/main.css CHANGED
@@ -949,6 +949,9 @@
949
949
  .wds-inline-prompt:has(button):active {
950
950
  background-color: var(--color-sentiment-background-surface-active);
951
951
  }
952
+ .wds-inline-prompt--full-width {
953
+ width: 100%;
954
+ }
952
955
  .wds-inline-prompt--muted {
953
956
  opacity: 0.93;
954
957
  filter: grayscale(1);
@@ -3822,10 +3825,19 @@ html:not([dir="rtl"]) .np-flow-navigation--sm .np-flow-navigation__stepper {
3822
3825
  stroke-dasharray: calc(12px * 0.5) calc(12px * 0.5);
3823
3826
  stroke-dasharray: var(--wds-list-item-spotlight-strokeDashSize) var(--wds-list-item-spotlight-strokeDashSize);
3824
3827
  }
3825
- .np-field-control {
3828
+ .np-field-control,
3829
+ .np-field__prompt {
3826
3830
  margin-top: 4px;
3827
3831
  margin-top: var(--size-4);
3828
3832
  }
3833
+ .np-field .form-group--typeahead[class],
3834
+ .np-field .np-checkbox-label[class] {
3835
+ margin-bottom: 0;
3836
+ }
3837
+ .np-field:has(.wds-radio-group) .np-field__prompt {
3838
+ margin-top: 12px;
3839
+ margin-top: var(--size-12);
3840
+ }
3829
3841
  .np-input-group {
3830
3842
  display: inline-grid;
3831
3843
  width: 100%;
@@ -5394,6 +5406,9 @@ html:not([dir="rtl"]) .np-navigation-option {
5394
5406
  .np-CardGroup .np-Card.np-Card--promoCard {
5395
5407
  max-width: 100%;
5396
5408
  }
5409
+ .wds-radio-group .np-radio:last-child label {
5410
+ margin-bottom: 0;
5411
+ }
5397
5412
  .np-section {
5398
5413
  margin-top: 32px;
5399
5414
  margin-top: var(--size-32);
@@ -6920,6 +6935,10 @@ html:not([dir="rtl"]) .np-navigation-option {
6920
6935
  padding: 0;
6921
6936
  margin: 0;
6922
6937
  }
6938
+ .typeahead--prompt {
6939
+ margin-top: 4px;
6940
+ margin-top: var(--size-4);
6941
+ }
6923
6942
  .typeahead-sm.typeahead--multiple .typeahead__input-container {
6924
6943
  min-height: 32px;
6925
6944
  }
package/src/main.less CHANGED
@@ -61,6 +61,7 @@
61
61
  @import "./phoneNumberInput/PhoneNumberInput.less";
62
62
  @import "./popover/Popover.less";
63
63
  @import "./promoCard/PromoCard.less";
64
+ @import "./radioGroup/RadioGroup.less";
64
65
  @import "./section/Section.less";
65
66
  @import "./slidingPanel/SlidingPanel.less";
66
67
  @import "./snackbar/Snackbar.less";
@@ -5,7 +5,8 @@ import { useState } from 'react';
5
5
 
6
6
  import { Button, Modal, ModalProps } from '..';
7
7
  import { CommonProps, Scroll } from '../common';
8
- import { lorem10, lorem100, lorem1000, storyConfig } from '../test-utils';
8
+ import { lorem10, lorem100, lorem1000 } from '../test-utils';
9
+ import { allModes } from '../../.storybook/modes';
9
10
 
10
11
  export default {
11
12
  component: Modal,
@@ -75,7 +76,15 @@ export const Basic: Story = {
75
76
  render: (args, context) => <StoryContent args={args} viewMode={context.viewMode} />,
76
77
  };
77
78
 
78
- export const BasicMobile: Story = storyConfig(Basic, { variants: ['mobile'] });
79
+ export const BasicMobile: Story = {
80
+ ...Basic,
81
+ parameters: {
82
+ variants: ['mobile'],
83
+ chromatic: {
84
+ mobile: allModes.largeMobile,
85
+ },
86
+ },
87
+ };
79
88
 
80
89
  export const ContentScroll: Story = {
81
90
  args: {
@@ -86,7 +95,15 @@ export const ContentScroll: Story = {
86
95
  render: (args, context) => <StoryContent args={args} viewMode={context.viewMode} />,
87
96
  };
88
97
 
89
- export const ContentScrollMobile: Story = storyConfig(ContentScroll, { variants: ['mobile'] });
98
+ export const ContentScrollMobile: Story = {
99
+ ...ContentScroll,
100
+ parameters: {
101
+ variants: ['mobile'],
102
+ chromatic: {
103
+ mobile: allModes.largeMobile,
104
+ },
105
+ },
106
+ };
90
107
 
91
108
  export const ViewportScroll: Story = {
92
109
  args: {
@@ -97,7 +114,15 @@ export const ViewportScroll: Story = {
97
114
  render: (args, context) => <StoryContent args={args} viewMode={context.viewMode} />,
98
115
  };
99
116
 
100
- export const ViewportScrollMobile: Story = storyConfig(ViewportScroll, { variants: ['mobile'] });
117
+ export const ViewportScrollMobile: Story = {
118
+ ...ViewportScroll,
119
+ parameters: {
120
+ variants: ['mobile'],
121
+ chromatic: {
122
+ mobile: allModes.largeMobile,
123
+ },
124
+ },
125
+ };
101
126
 
102
127
  export const WithoutTitle: Story = {
103
128
  args: {
@@ -107,7 +132,15 @@ export const WithoutTitle: Story = {
107
132
  render: (args, context) => <StoryContent args={args} viewMode={context.viewMode} />,
108
133
  };
109
134
 
110
- export const WithoutTitleMobile: Story = storyConfig(WithoutTitle, { variants: ['mobile'] });
135
+ export const WithoutTitleMobile: Story = {
136
+ ...WithoutTitle,
137
+ parameters: {
138
+ variants: ['mobile'],
139
+ chromatic: {
140
+ mobile: allModes.largeMobile,
141
+ },
142
+ },
143
+ };
111
144
 
112
145
  export const WithThemeProviderInContent: Story = {
113
146
  args: {
@@ -126,6 +159,12 @@ export const WithThemeProviderInContent: Story = {
126
159
  ),
127
160
  };
128
161
 
129
- export const WithThemeProviderInContentMobile: Story = storyConfig(WithThemeProviderInContent, {
130
- variants: ['mobile'],
131
- });
162
+ export const WithThemeProviderInContentMobile: Story = {
163
+ ...WithThemeProviderInContent,
164
+ parameters: {
165
+ variants: ['mobile'],
166
+ chromatic: {
167
+ mobile: allModes.largeMobile,
168
+ },
169
+ },
170
+ };
@@ -191,14 +191,14 @@ export const SmallInput: Story = {
191
191
  };
192
192
 
193
193
  export const MediumInput: Story = {
194
- render: SmallInput.render,
194
+ ...SmallInput,
195
195
  args: {
196
196
  size: 'md',
197
197
  },
198
198
  };
199
199
 
200
200
  export const LargeInput: Story = {
201
- render: SmallInput.render,
201
+ ...SmallInput,
202
202
  args: {
203
203
  size: 'lg',
204
204
  },
@@ -5,6 +5,7 @@ import PrimitiveAnchor from '..';
5
5
  const meta: Meta<typeof PrimitiveAnchor> = {
6
6
  component: PrimitiveAnchor,
7
7
  title: 'Primitives/Anchor',
8
+ tags: ['!manifest'],
8
9
  args: {
9
10
  children: 'Click me',
10
11
  href: 'https://example.com',
@@ -6,6 +6,7 @@ import PrimitiveAnchor from '..';
6
6
  const meta = {
7
7
  title: 'Primitives/Anchor/Tests',
8
8
  component: PrimitiveAnchor,
9
+ tags: ['!manifest'],
9
10
  args: {
10
11
  children: 'Click me',
11
12
  href: 'https://example.com',
@@ -5,6 +5,7 @@ import PrimitiveButton from '..';
5
5
  const meta: Meta<typeof PrimitiveButton> = {
6
6
  component: PrimitiveButton,
7
7
  title: 'Primitives/Button',
8
+ tags: ['!manifest'],
8
9
  args: {
9
10
  children: 'Button text',
10
11
  onClick: fn(),
@@ -6,6 +6,7 @@ import PrimitiveButton from '..';
6
6
  const meta = {
7
7
  title: 'Primitives/Button/Tests',
8
8
  component: PrimitiveButton,
9
+ tags: ['!manifest'],
9
10
  args: {
10
11
  children: 'Button text',
11
12
  },
@@ -27,6 +27,9 @@
27
27
  .wds-inline-prompt:has(button):active {
28
28
  background-color: var(--color-sentiment-background-surface-active);
29
29
  }
30
+ .wds-inline-prompt--full-width {
31
+ width: 100%;
32
+ }
30
33
  .wds-inline-prompt--muted {
31
34
  opacity: 0.93;
32
35
  filter: grayscale(1);
@@ -23,6 +23,10 @@
23
23
  }
24
24
  }
25
25
 
26
+ &--full-width {
27
+ width: 100%;
28
+ }
29
+
26
30
  &--muted {
27
31
  opacity: 0.93;
28
32
  filter: grayscale(1);
@@ -69,6 +73,6 @@
69
73
  // styles in the CSS package, so keeping it colocated for now.
70
74
  .process-circle {
71
75
  stroke: currentColor;
72
- };
76
+ }
73
77
  }
74
78
  }
@@ -155,4 +155,21 @@ describe('InlinePrompt', () => {
155
155
  expect(el).toHaveClass('wds-sentiment-surface');
156
156
  });
157
157
  });
158
+
159
+ describe('width', () => {
160
+ it('defaults to auto width (no full-width class)', () => {
161
+ render(<InlinePrompt {...defaultProps} data-testid="prompt" />);
162
+ expect(screen.getByTestId('prompt')).not.toHaveClass('wds-inline-prompt--full-width');
163
+ });
164
+
165
+ it('applies auto width (no full-width class) when explicitly set', () => {
166
+ render(<InlinePrompt {...defaultProps} width="auto" data-testid="prompt" />);
167
+ expect(screen.getByTestId('prompt')).not.toHaveClass('wds-inline-prompt--full-width');
168
+ });
169
+
170
+ it('applies full width class when set to full', () => {
171
+ render(<InlinePrompt {...defaultProps} width="full" data-testid="prompt" />);
172
+ expect(screen.getByTestId('prompt')).toHaveClass('wds-inline-prompt--full-width');
173
+ });
174
+ });
158
175
  });
@@ -14,6 +14,9 @@ const withComponentGrid =
14
14
  width: '100%',
15
15
  display: 'flex',
16
16
  flexDirection: 'column',
17
+ justifyContent: 'flex-start',
18
+ alignItems: 'flex-start',
19
+ alignContent: 'flex-start',
17
20
  gap,
18
21
  maxWidth,
19
22
  }}
@@ -26,6 +29,7 @@ export default {
26
29
  title: 'Prompts/InlinePrompt',
27
30
  component: InlinePrompt,
28
31
  tags: ['new'],
32
+ decorators: [withComponentGrid()],
29
33
  args: {
30
34
  loading: false,
31
35
  muted: false,
@@ -243,6 +247,37 @@ export const IconOverrides: StoryObj<PreviewStoryArgs> = {
243
247
  decorators: [withComponentGrid()],
244
248
  };
245
249
 
250
+ /**
251
+ * `InlinePrompt` can either hug its content or take the full width of its container,
252
+ * depending on the `width` prop.
253
+ * Components like `ListItem`, `ExpressiveMoneyInput` or similar will often set it to
254
+ * `auto`, while plain inputs will prefer `full` to visually match their boundaries.
255
+ *
256
+ * **NB**: `InlinePrompt` in its default – `auto` – width will expand to the full width of its container when the content spans across multiple lines.
257
+ */
258
+ export const SizingStrategies: StoryObj<PreviewStoryArgs> = {
259
+ render: (args: PreviewStoryArgs) => {
260
+ return (
261
+ <>
262
+ <InlinePrompt {...args} media={<Travel />} sentiment="positive" width="full">
263
+ This prompt will take the full width of its container.
264
+ </InlinePrompt>
265
+ <InlinePrompt {...args} media={<Travel />} sentiment="positive">
266
+ This prompt will hug its content.
267
+ </InlinePrompt>
268
+ <InlinePrompt {...args} media={<Travel />} sentiment="positive">
269
+ This prompt is configured to hug its content, but since the content is long enough to span
270
+ across multiple lines, it will expand to the full width of its container. And no, you
271
+ should not put pages of text here in the first place, but we recognise that some
272
+ translations are longer than others, and people also use accessibility features that
273
+ increase font size.
274
+ </InlinePrompt>
275
+ </>
276
+ );
277
+ },
278
+ decorators: [withComponentGrid()],
279
+ };
280
+
246
281
  /**
247
282
  * When configured with any of the supported sentiments, the colour scheme of the component will propagate to all of its supported descendants, such as instances of a `Link`, `Icon`, and `StatusIcon`.
248
283
  */
@@ -33,6 +33,11 @@ export type InlinePromptProps = {
33
33
  * To be used primarily for `proposition` sentiment.
34
34
  */
35
35
  mediaLabel?: string;
36
+ /**
37
+ * Defines the sizing strategy of the prompt component - either hugging the content or taking full width of the container.
38
+ * @default auto
39
+ */
40
+ width?: 'auto' | 'full';
36
41
  id?: string;
37
42
  className?: string;
38
43
  'data-testid'?: string;
@@ -53,6 +58,7 @@ export const InlinePrompt = ({
53
58
  children,
54
59
  media = null,
55
60
  mediaLabel,
61
+ width = 'auto',
56
62
  'data-testid': dataTestId,
57
63
  ...rest
58
64
  }: InlinePromptProps) => {
@@ -91,6 +97,7 @@ export const InlinePrompt = ({
91
97
  'wds-inline-prompt',
92
98
  `wds-inline-prompt--${sentiment}`,
93
99
  {
100
+ 'wds-inline-prompt--full-width': width === 'full',
94
101
  'wds-inline-prompt--muted': muted,
95
102
  'wds-inline-prompt--loading': loading,
96
103
  },
@@ -23,6 +23,7 @@ function ThemeProvider(props: ThemeProviderProps) {
23
23
  export default {
24
24
  component: ThemeProvider,
25
25
  title: 'Foundations/ThemeProvider',
26
+ tags: ['!manifest'],
26
27
  } satisfies Meta<typeof ThemeProvider>;
27
28
 
28
29
  type Story = StoryObj<typeof ThemeProvider>;
@@ -0,0 +1,3 @@
1
+ .wds-radio-group .np-radio:last-child label {
2
+ margin-bottom: 0;
3
+ }
@@ -0,0 +1,3 @@
1
+ .wds-radio-group .np-radio:last-child label {
2
+ margin-bottom: 0;
3
+ }
@@ -66,6 +66,8 @@ export const WithinField = {
66
66
  const hasError = selectedValue === 'radio-2';
67
67
  return (
68
68
  <Field
69
+ label="Field label"
70
+ description="Field description"
69
71
  {...(hasError
70
72
  ? {
71
73
  message: 'Something went wrong',
@@ -0,0 +1,62 @@
1
+ import RadioGroup, { RadioGroupProps } from './RadioGroup';
2
+ import { Field } from '../field/Field';
3
+ import { Meta, StoryObj } from '@storybook/react-webpack5';
4
+ import { fn } from 'storybook/test';
5
+
6
+ const meta = {
7
+ component: RadioGroup,
8
+ title: 'Forms/RadioGroup/tests',
9
+ tags: ['!autodocs'],
10
+ args: {
11
+ selectedValue: 'radio-2',
12
+ name: 'radio-group',
13
+ radios: [
14
+ {
15
+ value: 'radio-1',
16
+ label: 'Radio1',
17
+ },
18
+ {
19
+ value: 'radio-2',
20
+ label: 'Radio2',
21
+ },
22
+ ],
23
+ onChange: fn(),
24
+ },
25
+ } satisfies Meta<typeof RadioGroup>;
26
+
27
+ export default meta;
28
+ type Story<T extends string | number = string> = StoryObj<RadioGroupProps<T>>;
29
+
30
+ export const FieldsWithPrompt = {
31
+ render: function Render(args) {
32
+ return (
33
+ <>
34
+ {['i1', 'i2'].map((id) => (
35
+ <Field
36
+ key={id}
37
+ label="Field label"
38
+ description="Field description"
39
+ message="Something went great"
40
+ sentiment="positive"
41
+ >
42
+ <RadioGroup {...args} selectedValue="radio-2" />
43
+ </Field>
44
+ ))}
45
+ </>
46
+ );
47
+ },
48
+ } satisfies Story;
49
+
50
+ export const FieldsWithoutPrompt = {
51
+ render: function Render(args) {
52
+ return (
53
+ <>
54
+ {['i1', 'i2'].map((id) => (
55
+ <Field key={id} label="Field label" sentiment="positive">
56
+ <RadioGroup {...args} selectedValue="radio-2" />
57
+ </Field>
58
+ ))}
59
+ </>
60
+ );
61
+ },
62
+ } satisfies Story;
@@ -29,7 +29,12 @@ export default function RadioGroup<T extends string | number = never>({
29
29
  const [uncontrolledValue, setUncontrolledValue] = useState(controlledValue);
30
30
 
31
31
  return radios.length > 0 ? (
32
- <div role="radiogroup" {...inputAttributes} {...UNSAFE_inputAttributes}>
32
+ <div
33
+ role="radiogroup"
34
+ {...inputAttributes}
35
+ {...UNSAFE_inputAttributes}
36
+ className="wds-radio-group"
37
+ >
33
38
  {radios.map(({ value = '' as T, ...restProps }, index) => (
34
39
  <Radio
35
40
  // eslint-disable-next-line react/no-array-index-key
@@ -1,4 +1,4 @@
1
- import { StoryFn } from '@storybook/react-webpack5';
1
+ import { StoryFn, StoryObj } from '@storybook/react-webpack5';
2
2
  import React from 'react';
3
3
 
4
4
  import Button from '../button';
@@ -10,83 +10,87 @@ export default {
10
10
  title: 'Forms/SegmentedControl',
11
11
  };
12
12
 
13
- const Template: StoryFn = (args) => {
14
- const [segments, setSegments] = React.useState([
15
- { id: 'CUPCAKE', label: 'Cupcakes', value: 'cupcakes' },
16
- { id: 'SPONGECAKE', label: 'Sponge cake', value: 'spongecake' },
17
- { id: 'CARROT_CAKE', label: 'Carrot cake', value: 'carrotcake' },
18
- ]);
13
+ type Story = StoryObj<typeof SegmentedControl>;
19
14
 
20
- const [segmentsWithControls, setSegmentsWithControls] = React.useState([
21
- { id: 'CUPCAKE', label: 'Cupcakes', value: 'cupcakes', controls: 'aControlId' },
22
- { id: 'SPONGECAKE', label: 'Sponge cake', value: 'spongecake', controls: 'aControlId' },
23
- { id: 'CARROT_CAKE', label: 'Carrot cake', value: 'carrotcake', controls: 'aControlId' },
24
- ]);
15
+ const Template: Story = {
16
+ render: (args) => {
17
+ const [segments, setSegments] = React.useState([
18
+ { id: 'CUPCAKE', label: 'Cupcakes', value: 'cupcakes' },
19
+ { id: 'SPONGECAKE', label: 'Sponge cake', value: 'spongecake' },
20
+ { id: 'CARROT_CAKE', label: 'Carrot cake', value: 'carrotcake' },
21
+ ]);
25
22
 
26
- const [value, setValue] = React.useState(segments[0].value);
23
+ const [segmentsWithControls, setSegmentsWithControls] = React.useState([
24
+ { id: 'CUPCAKE', label: 'Cupcakes', value: 'cupcakes', controls: 'aControlId' },
25
+ { id: 'SPONGECAKE', label: 'Sponge cake', value: 'spongecake', controls: 'aControlId' },
26
+ { id: 'CARROT_CAKE', label: 'Carrot cake', value: 'carrotcake', controls: 'aControlId' },
27
+ ]);
27
28
 
28
- console.log('render: segments.length', segments.length);
29
- return (
30
- <div className="p-a-2">
31
- <SegmentedControl
32
- name="aSegmentedControl"
33
- value={value}
34
- onChange={setValue}
35
- {...(args.mode === 'view'
36
- ? { segments: segmentsWithControls, mode: 'view', controls: 'aControlId' }
37
- : { segments, mode: 'input' })}
38
- />
39
- <div className="m-a-2" id="aControlId">
40
- <p>Selected value: {value}</p>
41
- </div>
42
- <div className="m-a-2">
43
- <p>
44
- Force the <b>selectedValue</b> to be one of the following:
45
- <ul>
46
- {segments.map((segment) => (
47
- <li key={segment.id}>
48
- <a
49
- href="/"
50
- onClick={(e) => {
51
- e.preventDefault();
52
- setValue(segment.value);
53
- }}
54
- >
55
- {segment.label}
56
- </a>
57
- </li>
58
- ))}
59
- </ul>
60
- </p>
61
- </div>
62
- <div className="m-a-2">
63
- <Button
64
- priority="secondary"
65
- type="danger"
66
- size="sm"
67
- disabled={segments.length < 2}
68
- onClick={() => {
69
- const index = segments.findIndex((s) => s.value !== value);
70
- setSegments((prev) => prev.filter((_, i) => i !== index));
71
- setSegmentsWithControls((prev) => prev.filter((_, i) => i !== index));
72
- }}
73
- >
74
- Remove one segment
75
- </Button>
29
+ const [value, setValue] = React.useState(segments[0].value);
30
+
31
+ console.log('render: segments.length', segments.length);
32
+ return (
33
+ <div className="p-a-2">
34
+ <SegmentedControl
35
+ name="aSegmentedControl"
36
+ value={value}
37
+ onChange={setValue}
38
+ {...(args.mode === 'view'
39
+ ? { segments: segmentsWithControls, mode: 'view', controls: 'aControlId' }
40
+ : { segments, mode: 'input' })}
41
+ />
42
+ <div className="m-a-2" id="aControlId">
43
+ <p>Selected value: {value}</p>
44
+ </div>
45
+ <div className="m-a-2">
46
+ <p>
47
+ Force the <b>selectedValue</b> to be one of the following:
48
+ <ul>
49
+ {segments.map((segment) => (
50
+ <li key={segment.id}>
51
+ <a
52
+ href="/"
53
+ onClick={(e) => {
54
+ e.preventDefault();
55
+ setValue(segment.value);
56
+ }}
57
+ >
58
+ {segment.label}
59
+ </a>
60
+ </li>
61
+ ))}
62
+ </ul>
63
+ </p>
64
+ </div>
65
+ <div className="m-a-2">
66
+ <Button
67
+ priority="secondary"
68
+ type="danger"
69
+ size="sm"
70
+ disabled={segments.length < 2}
71
+ onClick={() => {
72
+ const index = segments.findIndex((s) => s.value !== value);
73
+ setSegments((prev) => prev.filter((_, i) => i !== index));
74
+ setSegmentsWithControls((prev) => prev.filter((_, i) => i !== index));
75
+ }}
76
+ >
77
+ Remove one segment
78
+ </Button>
79
+ </div>
76
80
  </div>
77
- </div>
78
- );
81
+ );
82
+ },
79
83
  };
80
84
 
81
- export const SegmentedControlDefault = {
82
- render: Template,
85
+ export const SegmentedControlDefault: Story = {
86
+ ...Template,
83
87
  args: {
84
88
  mode: 'input',
85
89
  },
86
90
  };
87
91
 
88
- export const SegmentedControlView = {
89
- render: Template,
92
+ export const SegmentedControlView: Story = {
93
+ ...Template,
90
94
  args: {
91
95
  mode: 'view',
92
96
  },