@transferwise/components 0.0.0-experimental-a8f3db2 → 0.0.0-experimental-8abc58f

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 (71) hide show
  1. package/build/main.css +11 -15
  2. package/build/styles/main.css +11 -15
  3. package/build/styles/switch/Switch.css +22 -41
  4. package/build/styles/switchOption/SwitchOption.css +4 -0
  5. package/build/switch/Switch.js +7 -18
  6. package/build/switch/Switch.js.map +1 -1
  7. package/build/switch/Switch.mjs +8 -19
  8. package/build/switch/Switch.mjs.map +1 -1
  9. package/build/switchOption/SwitchOption.js +1 -0
  10. package/build/switchOption/SwitchOption.js.map +1 -1
  11. package/build/switchOption/SwitchOption.mjs +1 -0
  12. package/build/switchOption/SwitchOption.mjs.map +1 -1
  13. package/build/types/switch/Switch.d.ts.map +1 -1
  14. package/build/types/switchOption/SwitchOption.d.ts.map +1 -1
  15. package/package.json +1 -1
  16. package/src/accordion/Accordion.story.tsx +31 -21
  17. package/src/avatarView/AvatarView.story.tsx +1 -6
  18. package/src/carousel/Carousel.story.tsx +1 -0
  19. package/src/common/bottomSheet/BottomSheet.story.tsx +5 -4
  20. package/src/common/circle/Circle.story.tsx +1 -0
  21. package/src/dateLookup/DateLookup.story.tsx +1 -0
  22. package/src/decision/Decision.story.tsx +1 -0
  23. package/src/definitionList/DefinitionList.story.tsx +1 -0
  24. package/src/dimmer/Dimmer.story.tsx +1 -0
  25. package/src/display/Display.story.tsx +1 -0
  26. package/src/drawer/Drawer.story.tsx +1 -0
  27. package/src/dropFade/DropFade.story.tsx +1 -0
  28. package/src/flowNavigation/FlowNavigation.story.tsx +1 -0
  29. package/src/header/Header.story.tsx +1 -0
  30. package/src/iconButton/IconButton.story.tsx +1 -0
  31. package/src/image/Image.story.tsx +1 -0
  32. package/src/info/Info.story.tsx +1 -0
  33. package/src/inlineAlert/InlineAlert.story.tsx +1 -0
  34. package/src/inputWithDisplayFormat/InputWithDisplayFormat.story.tsx +1 -0
  35. package/src/inputs/InputGroup.story.tsx +1 -0
  36. package/src/inputs/SearchInput.story.tsx +1 -0
  37. package/src/legacylistItem/LegacyListItem.tests.story.tsx +1 -0
  38. package/src/link/Link.story.tsx +1 -0
  39. package/src/main.css +11 -15
  40. package/src/main.less +1 -0
  41. package/src/modal/Modal.story.tsx +11 -6
  42. package/src/money/Money.story.tsx +1 -0
  43. package/src/navigationOptionsList/NavigationOptionsList.story.tsx +1 -0
  44. package/src/nudge/Nudge.story.tsx +1 -0
  45. package/src/overlayHeader/OverlayHeader.story.tsx +1 -0
  46. package/src/progress/Progress.story.tsx +1 -0
  47. package/src/provider/Provider.story.tsx +1 -0
  48. package/src/radio/Radio.story.tsx +1 -0
  49. package/src/radioGroup/RadioGroup.story.tsx +1 -0
  50. package/src/radioOption/RadioOption.story.tsx +1 -0
  51. package/src/section/Section.story.tsx +1 -0
  52. package/src/segmentedControl/SegmentedControl.story.tsx +1 -0
  53. package/src/select/Select.story.tsx +1 -0
  54. package/src/slidingPanel/SlidingPanel.story.tsx +1 -0
  55. package/src/snackbar/Snackbar.story.tsx +1 -0
  56. package/src/summary/Summary.story.tsx +1 -0
  57. package/src/switch/Switch.css +22 -41
  58. package/src/switch/Switch.less +6 -12
  59. package/src/switch/Switch.spec.tsx +11 -9
  60. package/src/switch/Switch.story.tsx +158 -33
  61. package/src/switch/Switch.tsx +6 -15
  62. package/src/switchOption/SwitchOption.css +4 -0
  63. package/src/switchOption/SwitchOption.less +8 -0
  64. package/src/switchOption/SwitchOption.spec.tsx +4 -5
  65. package/src/switchOption/SwitchOption.story.tsx +42 -38
  66. package/src/switchOption/SwitchOption.tsx +1 -0
  67. package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.story.tsx +1 -0
  68. package/src/tile/Tile.story.tsx +1 -0
  69. package/src/title/Title.story.tsx +1 -0
  70. package/src/typeahead/Typeahead.story.tsx +1 -0
  71. package/src/switch/__snapshots__/Switch.spec.tsx.snap +0 -44
package/build/main.css CHANGED
@@ -5149,6 +5149,8 @@ html:not([dir="rtl"]) .np-navigation-option {
5149
5149
  margin-top: var(--size-24);
5150
5150
  }
5151
5151
  .np-switch {
5152
+ all: unset;
5153
+ box-sizing: border-box;
5152
5154
  display: inline-flex;
5153
5155
  overflow: hidden;
5154
5156
  width: 50px;
@@ -5157,6 +5159,7 @@ html:not([dir="rtl"]) .np-navigation-option {
5157
5159
  -webkit-user-select: none;
5158
5160
  -moz-user-select: none;
5159
5161
  user-select: none;
5162
+ cursor: pointer;
5160
5163
  }
5161
5164
  .np-switch:focus {
5162
5165
  outline: none;
@@ -5189,21 +5192,10 @@ html:not([dir="rtl"]) .np-navigation-option {
5189
5192
  [dir="rtl"] .np-switch--checked .np-switch--thumb {
5190
5193
  transform: translateX(-20px) ;
5191
5194
  }
5192
- .np-switch input {
5193
- position: absolute;
5194
- left: -100%;
5195
- display: none;
5196
- width: 0;
5197
- height: 0;
5198
- opacity: 0;
5199
- }
5200
- [dir="rtl"] .np-switch input {
5201
- right: -100%;
5202
- left: auto;
5203
- left: initial;
5204
- }
5205
- .np-switch:not([aria-disabled]) {
5206
- cursor: pointer;
5195
+ .np-switch.disabled {
5196
+ filter: grayscale(1);
5197
+ opacity: 0.45;
5198
+ cursor: not-allowed !important;
5207
5199
  }
5208
5200
  .np-theme-personal .np-switch {
5209
5201
  padding: 1px 2px;
@@ -5219,6 +5211,10 @@ html:not([dir="rtl"]) .np-navigation-option {
5219
5211
  background-color: #ffffff;
5220
5212
  background-color: var(--color-background-screen);
5221
5213
  }
5214
+ .np-switch-option.disabled .np-switch {
5215
+ filter: none;
5216
+ opacity: 1;
5217
+ }
5222
5218
  .tabs {
5223
5219
  position: relative;
5224
5220
  }
@@ -5149,6 +5149,8 @@ html:not([dir="rtl"]) .np-navigation-option {
5149
5149
  margin-top: var(--size-24);
5150
5150
  }
5151
5151
  .np-switch {
5152
+ all: unset;
5153
+ box-sizing: border-box;
5152
5154
  display: inline-flex;
5153
5155
  overflow: hidden;
5154
5156
  width: 50px;
@@ -5157,6 +5159,7 @@ html:not([dir="rtl"]) .np-navigation-option {
5157
5159
  -webkit-user-select: none;
5158
5160
  -moz-user-select: none;
5159
5161
  user-select: none;
5162
+ cursor: pointer;
5160
5163
  }
5161
5164
  .np-switch:focus {
5162
5165
  outline: none;
@@ -5189,21 +5192,10 @@ html:not([dir="rtl"]) .np-navigation-option {
5189
5192
  [dir="rtl"] .np-switch--checked .np-switch--thumb {
5190
5193
  transform: translateX(-20px) ;
5191
5194
  }
5192
- .np-switch input {
5193
- position: absolute;
5194
- left: -100%;
5195
- display: none;
5196
- width: 0;
5197
- height: 0;
5198
- opacity: 0;
5199
- }
5200
- [dir="rtl"] .np-switch input {
5201
- right: -100%;
5202
- left: auto;
5203
- left: initial;
5204
- }
5205
- .np-switch:not([aria-disabled]) {
5206
- cursor: pointer;
5195
+ .np-switch.disabled {
5196
+ filter: grayscale(1);
5197
+ opacity: 0.45;
5198
+ cursor: not-allowed !important;
5207
5199
  }
5208
5200
  .np-theme-personal .np-switch {
5209
5201
  padding: 1px 2px;
@@ -5219,6 +5211,10 @@ html:not([dir="rtl"]) .np-navigation-option {
5219
5211
  background-color: #ffffff;
5220
5212
  background-color: var(--color-background-screen);
5221
5213
  }
5214
+ .np-switch-option.disabled .np-switch {
5215
+ filter: none;
5216
+ opacity: 1;
5217
+ }
5222
5218
  .tabs {
5223
5219
  position: relative;
5224
5220
  }
@@ -1,4 +1,8 @@
1
- .np-switch {
1
+ @media (min-width: 768px) {
2
+ }@media (min-width: 768px) {
3
+ }.np-switch {
4
+ all: unset;
5
+ box-sizing: border-box;
2
6
  display: inline-flex;
3
7
  overflow: hidden;
4
8
  width: 50px;
@@ -7,61 +11,38 @@
7
11
  -webkit-user-select: none;
8
12
  -moz-user-select: none;
9
13
  user-select: none;
10
- }
11
- .np-switch:focus {
14
+ cursor: pointer;
15
+ }.np-switch:focus {
12
16
  outline: none;
13
- }
14
- .np-switch:focus-visible {
17
+ }.np-switch:focus-visible {
15
18
  outline: var(--ring-outline-color) solid var(--ring-outline-width);
16
19
  outline-offset: var(--ring-outline-offset);
17
- }
18
- .np-switch--thumb {
20
+ }.np-switch--thumb {
19
21
  display: flex;
20
22
  transition: transform cubic-bezier(0, 0.94, 0.62, 1) 350ms;
21
- }
22
- .np-switch--thumb .tw-icon {
23
+ }.np-switch--thumb .tw-icon {
23
24
  color: #fff;
24
- }
25
- .np-switch--unchecked {
25
+ }.np-switch--unchecked {
26
26
  background: #c9cbce;
27
27
  background: var(--color-interactive-secondary);
28
- }
29
- .np-switch--unchecked .switch--thumb {
28
+ }.np-switch--unchecked .switch--thumb {
30
29
  transform: translateX(0);
31
- }
32
- .np-switch--checked {
30
+ }.np-switch--checked {
33
31
  background: #00a2dd;
34
32
  background: var(--color-interactive-accent);
35
- }
36
- .np-switch--checked .np-switch--thumb {
33
+ }.np-switch--checked .np-switch--thumb {
37
34
  transform: translateX(20px) ;
38
- }
39
- [dir="rtl"] .np-switch--checked .np-switch--thumb {
35
+ }[dir="rtl"] .np-switch--checked .np-switch--thumb {
40
36
  transform: translateX(-20px) ;
41
- }
42
- .np-switch input {
43
- position: absolute;
44
- left: -100%;
45
- display: none;
46
- width: 0;
47
- height: 0;
48
- opacity: 0;
49
- }
50
- [dir="rtl"] .np-switch input {
51
- right: -100%;
52
- left: auto;
53
- left: initial;
54
- }
55
- .np-switch:not([aria-disabled]) {
56
- cursor: pointer;
57
- }
58
- .np-theme-personal .np-switch {
37
+ }.np-switch.disabled {
38
+ filter: grayscale(1);
39
+ opacity: 0.45;
40
+ cursor: not-allowed !important;
41
+ }.np-theme-personal .np-switch {
59
42
  padding: 1px 2px;
60
- }
61
- .np-theme-personal .np-switch--checked {
43
+ }.np-theme-personal .np-switch--checked {
62
44
  background: var(--color-interactive-primary);
63
- }
64
- .np-theme-personal .np-switch--thumb {
45
+ }.np-theme-personal .np-switch--thumb {
65
46
  width: 20px;
66
47
  height: 20px;
67
48
  margin: 3px;
@@ -0,0 +1,4 @@
1
+ .np-switch-option.disabled .np-switch {
2
+ filter: none;
3
+ opacity: 1;
4
+ }
@@ -19,36 +19,25 @@ const Switch = props => {
19
19
  onClick,
20
20
  disabled
21
21
  } = props;
22
- const handleKeyDown = event => {
23
- if (event.key === ' ') {
24
- event.preventDefault();
25
- onClick();
26
- }
27
- };
28
22
  const ariaLabelledby = (ariaLabel ? undefined : ariaLabelledbyProp) ?? inputAttributes['aria-labelledby'];
29
- return /*#__PURE__*/jsxRuntime.jsxs("span", {
23
+ return /*#__PURE__*/jsxRuntime.jsx("button", {
30
24
  className: clsx.clsx('np-switch', {
31
25
  'np-switch--unchecked': !checked,
32
26
  'np-switch--checked': checked,
33
27
  disabled
34
28
  }, className),
35
- tabIndex: 0,
29
+ type: "button",
36
30
  role: "switch",
31
+ ...inputAttributes,
32
+ id: id,
37
33
  "aria-checked": checked,
38
34
  "aria-label": ariaLabel,
39
- ...inputAttributes,
40
35
  "aria-labelledby": ariaLabelledby,
41
- id: id,
42
- "aria-disabled": disabled,
36
+ disabled: disabled,
43
37
  onClick: !disabled ? onClick : undefined,
44
- onKeyDown: !disabled ? handleKeyDown : undefined,
45
- children: [/*#__PURE__*/jsxRuntime.jsx("span", {
38
+ children: /*#__PURE__*/jsxRuntime.jsx("span", {
46
39
  className: "np-switch--thumb"
47
- }), /*#__PURE__*/jsxRuntime.jsx("input", {
48
- type: "checkbox",
49
- checked: checked,
50
- readOnly: true
51
- })]
40
+ })
52
41
  });
53
42
  };
54
43
 
@@ -1 +1 @@
1
- {"version":3,"file":"Switch.js","sources":["../../src/switch/Switch.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport type { KeyboardEventHandler, MouseEvent } from 'react';\n\nimport type { CommonProps } from '../common';\nimport { useInputAttributes } from '../inputs/contexts';\n\nexport type SwitchProps = CommonProps & {\n /**\n * Used to describe the purpose of the switch. To be used if there is no external label (i.e. aria-labelledby is null)\n * @deprecated Use `Field` wrapper or the `aria-labelledby` attribute instead.\n */\n 'aria-label'?: string;\n /** A reference to a label that describes the purpose of the switch. Ignored if aria-label is provided */\n 'aria-labelledby'?: string;\n /** Whether the switch is checked or not */\n checked?: boolean;\n disabled?: boolean;\n /** ID to apply to the switch container */\n id?: string;\n /** Function called when the switch is toggled */\n onClick: (event?: MouseEvent<HTMLSpanElement>) => void;\n};\n\nconst Switch = (props: SwitchProps) => {\n const inputAttributes = useInputAttributes({ nonLabelable: true });\n\n const {\n checked,\n className,\n id = inputAttributes.id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledbyProp,\n onClick,\n disabled,\n } = props;\n\n const handleKeyDown: KeyboardEventHandler = (event) => {\n if (event.key === ' ') {\n event.preventDefault();\n onClick();\n }\n };\n\n const ariaLabelledby =\n (ariaLabel ? undefined : ariaLabelledbyProp) ?? inputAttributes['aria-labelledby'];\n\n return (\n <span\n className={clsx(\n 'np-switch',\n {\n 'np-switch--unchecked': !checked,\n 'np-switch--checked': checked,\n disabled,\n },\n className,\n )}\n tabIndex={0}\n role=\"switch\"\n aria-checked={checked}\n aria-label={ariaLabel}\n {...inputAttributes}\n aria-labelledby={ariaLabelledby}\n id={id}\n aria-disabled={disabled}\n onClick={!disabled ? onClick : undefined}\n onKeyDown={!disabled ? handleKeyDown : undefined}\n >\n <span className=\"np-switch--thumb\" />\n <input type=\"checkbox\" checked={checked} readOnly />\n </span>\n );\n};\n\nexport default Switch;\n"],"names":["Switch","props","inputAttributes","useInputAttributes","nonLabelable","checked","className","id","ariaLabel","ariaLabelledbyProp","onClick","disabled","handleKeyDown","event","key","preventDefault","ariaLabelledby","undefined","_jsxs","clsx","tabIndex","role","onKeyDown","children","_jsx","type","readOnly"],"mappings":";;;;;;;;AAuBMA,MAAAA,MAAM,GAAIC,KAAkB,IAAI;EACpC,MAAMC,eAAe,GAAGC,2BAAkB,CAAC;AAAEC,IAAAA,YAAY,EAAE;AAAM,GAAA,CAAC;EAElE,MAAM;IACJC,OAAO;IACPC,SAAS;IACTC,EAAE,GAAGL,eAAe,CAACK,EAAE;AACvB,IAAA,YAAY,EAAEC,SAAS;AACvB,IAAA,iBAAiB,EAAEC,kBAAkB;IACrCC,OAAO;AACPC,IAAAA;AAAQ,GACT,GAAGV,KAAK;EAET,MAAMW,aAAa,GAA0BC,KAAK,IAAI;AACpD,IAAA,IAAIA,KAAK,CAACC,GAAG,KAAK,GAAG,EAAE;MACrBD,KAAK,CAACE,cAAc,EAAE;AACtBL,MAAAA,OAAO,EAAE;AACX;GACD;AAED,EAAA,MAAMM,cAAc,GAClB,CAACR,SAAS,GAAGS,SAAS,GAAGR,kBAAkB,KAAKP,eAAe,CAAC,iBAAiB,CAAC;AAEpF,EAAA,oBACEgB,eAAA,CAAA,MAAA,EAAA;AACEZ,IAAAA,SAAS,EAAEa,SAAI,CACb,WAAW,EACX;MACE,sBAAsB,EAAE,CAACd,OAAO;AAChC,MAAA,oBAAoB,EAAEA,OAAO;AAC7BM,MAAAA;KACD,EACDL,SAAS,CACT;AACFc,IAAAA,QAAQ,EAAE,CAAE;AACZC,IAAAA,IAAI,EAAC,QAAQ;AACb,IAAA,cAAA,EAAchB,OAAQ;AACtB,IAAA,YAAA,EAAYG,SAAU;AAAA,IAAA,GAClBN,eAAe;AACnB,IAAA,iBAAA,EAAiBc,cAAe;AAChCT,IAAAA,EAAE,EAAEA,EAAG;AACP,IAAA,eAAA,EAAeI,QAAS;AACxBD,IAAAA,OAAO,EAAE,CAACC,QAAQ,GAAGD,OAAO,GAAGO,SAAU;AACzCK,IAAAA,SAAS,EAAE,CAACX,QAAQ,GAAGC,aAAa,GAAGK,SAAU;AAAAM,IAAAA,QAAA,gBAEjDC,cAAA,CAAA,MAAA,EAAA;AAAMlB,MAAAA,SAAS,EAAC;KAChB,CAAA,eAAAkB,cAAA,CAAA,OAAA,EAAA;AAAOC,MAAAA,IAAI,EAAC,UAAU;AAACpB,MAAAA,OAAO,EAAEA,OAAQ;MAACqB,QAAQ,EAAA;AAAA,KACnD,CAAA;AAAA,GAAM,CAAC;AAEX;;;;"}
1
+ {"version":3,"file":"Switch.js","sources":["../../src/switch/Switch.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport type { KeyboardEventHandler, MouseEvent } from 'react';\n\nimport type { CommonProps } from '../common';\nimport { useInputAttributes } from '../inputs/contexts';\n\nexport type SwitchProps = CommonProps & {\n /**\n * Used to describe the purpose of the switch. To be used if there is no external label (i.e. aria-labelledby is null)\n * @deprecated Use `Field` wrapper or the `aria-labelledby` attribute instead.\n */\n 'aria-label'?: string;\n /** A reference to a label that describes the purpose of the switch. Ignored if aria-label is provided */\n 'aria-labelledby'?: string;\n /** Whether the switch is checked or not */\n checked?: boolean;\n disabled?: boolean;\n /** ID to apply to the switch container */\n id?: string;\n /** Function called when the switch is toggled */\n onClick: (event?: MouseEvent<HTMLSpanElement>) => void;\n};\n\nconst Switch = (props: SwitchProps) => {\n const inputAttributes = useInputAttributes({ nonLabelable: true });\n\n const {\n checked,\n className,\n id = inputAttributes.id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledbyProp,\n onClick,\n disabled,\n } = props;\n\n const ariaLabelledby =\n (ariaLabel ? undefined : ariaLabelledbyProp) ?? inputAttributes['aria-labelledby'];\n\n return (\n <button\n className={clsx(\n 'np-switch',\n {\n 'np-switch--unchecked': !checked,\n 'np-switch--checked': checked,\n disabled,\n },\n className,\n )}\n type=\"button\"\n role=\"switch\"\n {...inputAttributes}\n id={id}\n aria-checked={checked}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledby}\n disabled={disabled}\n onClick={!disabled ? onClick : undefined}\n >\n <span className=\"np-switch--thumb\" />\n </button>\n );\n};\n\nexport default Switch;\n"],"names":["Switch","props","inputAttributes","useInputAttributes","nonLabelable","checked","className","id","ariaLabel","ariaLabelledbyProp","onClick","disabled","ariaLabelledby","undefined","_jsx","clsx","type","role","children"],"mappings":";;;;;;;;AAuBMA,MAAAA,MAAM,GAAIC,KAAkB,IAAI;EACpC,MAAMC,eAAe,GAAGC,2BAAkB,CAAC;AAAEC,IAAAA,YAAY,EAAE;AAAM,GAAA,CAAC;EAElE,MAAM;IACJC,OAAO;IACPC,SAAS;IACTC,EAAE,GAAGL,eAAe,CAACK,EAAE;AACvB,IAAA,YAAY,EAAEC,SAAS;AACvB,IAAA,iBAAiB,EAAEC,kBAAkB;IACrCC,OAAO;AACPC,IAAAA;AAAQ,GACT,GAAGV,KAAK;AAET,EAAA,MAAMW,cAAc,GAClB,CAACJ,SAAS,GAAGK,SAAS,GAAGJ,kBAAkB,KAAKP,eAAe,CAAC,iBAAiB,CAAC;AAEpF,EAAA,oBACEY,cAAA,CAAA,QAAA,EAAA;AACER,IAAAA,SAAS,EAAES,SAAI,CACb,WAAW,EACX;MACE,sBAAsB,EAAE,CAACV,OAAO;AAChC,MAAA,oBAAoB,EAAEA,OAAO;AAC7BM,MAAAA;KACD,EACDL,SAAS,CACT;AACFU,IAAAA,IAAI,EAAC,QAAQ;AACbC,IAAAA,IAAI,EAAC,QAAQ;AAAA,IAAA,GACTf,eAAe;AACnBK,IAAAA,EAAE,EAAEA,EAAG;AACP,IAAA,cAAA,EAAcF,OAAQ;AACtB,IAAA,YAAA,EAAYG,SAAU;AACtB,IAAA,iBAAA,EAAiBI,cAAe;AAChCD,IAAAA,QAAQ,EAAEA,QAAS;AACnBD,IAAAA,OAAO,EAAE,CAACC,QAAQ,GAAGD,OAAO,GAAGG,SAAU;AAAAK,IAAAA,QAAA,eAEzCJ,cAAA,CAAA,MAAA,EAAA;AAAMR,MAAAA,SAAS,EAAC;KAClB;AAAA,GAAQ,CAAC;AAEb;;;;"}
@@ -1,6 +1,6 @@
1
1
  import { clsx } from 'clsx';
2
2
  import { useInputAttributes } from '../inputs/contexts.mjs';
3
- import { jsxs, jsx } from 'react/jsx-runtime';
3
+ import { jsx } from 'react/jsx-runtime';
4
4
 
5
5
  const Switch = props => {
6
6
  const inputAttributes = useInputAttributes({
@@ -15,36 +15,25 @@ const Switch = props => {
15
15
  onClick,
16
16
  disabled
17
17
  } = props;
18
- const handleKeyDown = event => {
19
- if (event.key === ' ') {
20
- event.preventDefault();
21
- onClick();
22
- }
23
- };
24
18
  const ariaLabelledby = (ariaLabel ? undefined : ariaLabelledbyProp) ?? inputAttributes['aria-labelledby'];
25
- return /*#__PURE__*/jsxs("span", {
19
+ return /*#__PURE__*/jsx("button", {
26
20
  className: clsx('np-switch', {
27
21
  'np-switch--unchecked': !checked,
28
22
  'np-switch--checked': checked,
29
23
  disabled
30
24
  }, className),
31
- tabIndex: 0,
25
+ type: "button",
32
26
  role: "switch",
27
+ ...inputAttributes,
28
+ id: id,
33
29
  "aria-checked": checked,
34
30
  "aria-label": ariaLabel,
35
- ...inputAttributes,
36
31
  "aria-labelledby": ariaLabelledby,
37
- id: id,
38
- "aria-disabled": disabled,
32
+ disabled: disabled,
39
33
  onClick: !disabled ? onClick : undefined,
40
- onKeyDown: !disabled ? handleKeyDown : undefined,
41
- children: [/*#__PURE__*/jsx("span", {
34
+ children: /*#__PURE__*/jsx("span", {
42
35
  className: "np-switch--thumb"
43
- }), /*#__PURE__*/jsx("input", {
44
- type: "checkbox",
45
- checked: checked,
46
- readOnly: true
47
- })]
36
+ })
48
37
  });
49
38
  };
50
39
 
@@ -1 +1 @@
1
- {"version":3,"file":"Switch.mjs","sources":["../../src/switch/Switch.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport type { KeyboardEventHandler, MouseEvent } from 'react';\n\nimport type { CommonProps } from '../common';\nimport { useInputAttributes } from '../inputs/contexts';\n\nexport type SwitchProps = CommonProps & {\n /**\n * Used to describe the purpose of the switch. To be used if there is no external label (i.e. aria-labelledby is null)\n * @deprecated Use `Field` wrapper or the `aria-labelledby` attribute instead.\n */\n 'aria-label'?: string;\n /** A reference to a label that describes the purpose of the switch. Ignored if aria-label is provided */\n 'aria-labelledby'?: string;\n /** Whether the switch is checked or not */\n checked?: boolean;\n disabled?: boolean;\n /** ID to apply to the switch container */\n id?: string;\n /** Function called when the switch is toggled */\n onClick: (event?: MouseEvent<HTMLSpanElement>) => void;\n};\n\nconst Switch = (props: SwitchProps) => {\n const inputAttributes = useInputAttributes({ nonLabelable: true });\n\n const {\n checked,\n className,\n id = inputAttributes.id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledbyProp,\n onClick,\n disabled,\n } = props;\n\n const handleKeyDown: KeyboardEventHandler = (event) => {\n if (event.key === ' ') {\n event.preventDefault();\n onClick();\n }\n };\n\n const ariaLabelledby =\n (ariaLabel ? undefined : ariaLabelledbyProp) ?? inputAttributes['aria-labelledby'];\n\n return (\n <span\n className={clsx(\n 'np-switch',\n {\n 'np-switch--unchecked': !checked,\n 'np-switch--checked': checked,\n disabled,\n },\n className,\n )}\n tabIndex={0}\n role=\"switch\"\n aria-checked={checked}\n aria-label={ariaLabel}\n {...inputAttributes}\n aria-labelledby={ariaLabelledby}\n id={id}\n aria-disabled={disabled}\n onClick={!disabled ? onClick : undefined}\n onKeyDown={!disabled ? handleKeyDown : undefined}\n >\n <span className=\"np-switch--thumb\" />\n <input type=\"checkbox\" checked={checked} readOnly />\n </span>\n );\n};\n\nexport default Switch;\n"],"names":["Switch","props","inputAttributes","useInputAttributes","nonLabelable","checked","className","id","ariaLabel","ariaLabelledbyProp","onClick","disabled","handleKeyDown","event","key","preventDefault","ariaLabelledby","undefined","_jsxs","clsx","tabIndex","role","onKeyDown","children","_jsx","type","readOnly"],"mappings":";;;;AAuBMA,MAAAA,MAAM,GAAIC,KAAkB,IAAI;EACpC,MAAMC,eAAe,GAAGC,kBAAkB,CAAC;AAAEC,IAAAA,YAAY,EAAE;AAAM,GAAA,CAAC;EAElE,MAAM;IACJC,OAAO;IACPC,SAAS;IACTC,EAAE,GAAGL,eAAe,CAACK,EAAE;AACvB,IAAA,YAAY,EAAEC,SAAS;AACvB,IAAA,iBAAiB,EAAEC,kBAAkB;IACrCC,OAAO;AACPC,IAAAA;AAAQ,GACT,GAAGV,KAAK;EAET,MAAMW,aAAa,GAA0BC,KAAK,IAAI;AACpD,IAAA,IAAIA,KAAK,CAACC,GAAG,KAAK,GAAG,EAAE;MACrBD,KAAK,CAACE,cAAc,EAAE;AACtBL,MAAAA,OAAO,EAAE;AACX;GACD;AAED,EAAA,MAAMM,cAAc,GAClB,CAACR,SAAS,GAAGS,SAAS,GAAGR,kBAAkB,KAAKP,eAAe,CAAC,iBAAiB,CAAC;AAEpF,EAAA,oBACEgB,IAAA,CAAA,MAAA,EAAA;AACEZ,IAAAA,SAAS,EAAEa,IAAI,CACb,WAAW,EACX;MACE,sBAAsB,EAAE,CAACd,OAAO;AAChC,MAAA,oBAAoB,EAAEA,OAAO;AAC7BM,MAAAA;KACD,EACDL,SAAS,CACT;AACFc,IAAAA,QAAQ,EAAE,CAAE;AACZC,IAAAA,IAAI,EAAC,QAAQ;AACb,IAAA,cAAA,EAAchB,OAAQ;AACtB,IAAA,YAAA,EAAYG,SAAU;AAAA,IAAA,GAClBN,eAAe;AACnB,IAAA,iBAAA,EAAiBc,cAAe;AAChCT,IAAAA,EAAE,EAAEA,EAAG;AACP,IAAA,eAAA,EAAeI,QAAS;AACxBD,IAAAA,OAAO,EAAE,CAACC,QAAQ,GAAGD,OAAO,GAAGO,SAAU;AACzCK,IAAAA,SAAS,EAAE,CAACX,QAAQ,GAAGC,aAAa,GAAGK,SAAU;AAAAM,IAAAA,QAAA,gBAEjDC,GAAA,CAAA,MAAA,EAAA;AAAMlB,MAAAA,SAAS,EAAC;KAChB,CAAA,eAAAkB,GAAA,CAAA,OAAA,EAAA;AAAOC,MAAAA,IAAI,EAAC,UAAU;AAACpB,MAAAA,OAAO,EAAEA,OAAQ;MAACqB,QAAQ,EAAA;AAAA,KACnD,CAAA;AAAA,GAAM,CAAC;AAEX;;;;"}
1
+ {"version":3,"file":"Switch.mjs","sources":["../../src/switch/Switch.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport type { KeyboardEventHandler, MouseEvent } from 'react';\n\nimport type { CommonProps } from '../common';\nimport { useInputAttributes } from '../inputs/contexts';\n\nexport type SwitchProps = CommonProps & {\n /**\n * Used to describe the purpose of the switch. To be used if there is no external label (i.e. aria-labelledby is null)\n * @deprecated Use `Field` wrapper or the `aria-labelledby` attribute instead.\n */\n 'aria-label'?: string;\n /** A reference to a label that describes the purpose of the switch. Ignored if aria-label is provided */\n 'aria-labelledby'?: string;\n /** Whether the switch is checked or not */\n checked?: boolean;\n disabled?: boolean;\n /** ID to apply to the switch container */\n id?: string;\n /** Function called when the switch is toggled */\n onClick: (event?: MouseEvent<HTMLSpanElement>) => void;\n};\n\nconst Switch = (props: SwitchProps) => {\n const inputAttributes = useInputAttributes({ nonLabelable: true });\n\n const {\n checked,\n className,\n id = inputAttributes.id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledbyProp,\n onClick,\n disabled,\n } = props;\n\n const ariaLabelledby =\n (ariaLabel ? undefined : ariaLabelledbyProp) ?? inputAttributes['aria-labelledby'];\n\n return (\n <button\n className={clsx(\n 'np-switch',\n {\n 'np-switch--unchecked': !checked,\n 'np-switch--checked': checked,\n disabled,\n },\n className,\n )}\n type=\"button\"\n role=\"switch\"\n {...inputAttributes}\n id={id}\n aria-checked={checked}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledby}\n disabled={disabled}\n onClick={!disabled ? onClick : undefined}\n >\n <span className=\"np-switch--thumb\" />\n </button>\n );\n};\n\nexport default Switch;\n"],"names":["Switch","props","inputAttributes","useInputAttributes","nonLabelable","checked","className","id","ariaLabel","ariaLabelledbyProp","onClick","disabled","ariaLabelledby","undefined","_jsx","clsx","type","role","children"],"mappings":";;;;AAuBMA,MAAAA,MAAM,GAAIC,KAAkB,IAAI;EACpC,MAAMC,eAAe,GAAGC,kBAAkB,CAAC;AAAEC,IAAAA,YAAY,EAAE;AAAM,GAAA,CAAC;EAElE,MAAM;IACJC,OAAO;IACPC,SAAS;IACTC,EAAE,GAAGL,eAAe,CAACK,EAAE;AACvB,IAAA,YAAY,EAAEC,SAAS;AACvB,IAAA,iBAAiB,EAAEC,kBAAkB;IACrCC,OAAO;AACPC,IAAAA;AAAQ,GACT,GAAGV,KAAK;AAET,EAAA,MAAMW,cAAc,GAClB,CAACJ,SAAS,GAAGK,SAAS,GAAGJ,kBAAkB,KAAKP,eAAe,CAAC,iBAAiB,CAAC;AAEpF,EAAA,oBACEY,GAAA,CAAA,QAAA,EAAA;AACER,IAAAA,SAAS,EAAES,IAAI,CACb,WAAW,EACX;MACE,sBAAsB,EAAE,CAACV,OAAO;AAChC,MAAA,oBAAoB,EAAEA,OAAO;AAC7BM,MAAAA;KACD,EACDL,SAAS,CACT;AACFU,IAAAA,IAAI,EAAC,QAAQ;AACbC,IAAAA,IAAI,EAAC,QAAQ;AAAA,IAAA,GACTf,eAAe;AACnBK,IAAAA,EAAE,EAAEA,EAAG;AACP,IAAA,cAAA,EAAcF,OAAQ;AACtB,IAAA,YAAA,EAAYG,SAAU;AACtB,IAAA,iBAAA,EAAiBI,cAAe;AAChCD,IAAAA,QAAQ,EAAEA,QAAS;AACnBD,IAAAA,OAAO,EAAE,CAACC,QAAQ,GAAGD,OAAO,GAAGG,SAAU;AAAAK,IAAAA,QAAA,eAEzCJ,GAAA,CAAA,MAAA,EAAA;AAAMR,MAAAA,SAAS,EAAC;KAClB;AAAA,GAAQ,CAAC;AAEb;;;;"}
@@ -46,6 +46,7 @@ const SwitchOption = ({
46
46
  };
47
47
  return /*#__PURE__*/jsxRuntime.jsx(Option.default, {
48
48
  ...sharedProps,
49
+ className: "np-switch-option",
49
50
  button: /*#__PURE__*/jsxRuntime.jsx(Switch.default, {
50
51
  id: id,
51
52
  checked: checked,
@@ -1 +1 @@
1
- {"version":3,"file":"SwitchOption.js","sources":["../../src/switchOption/SwitchOption.tsx"],"sourcesContent":["import { MouseEvent } from 'react';\n\nimport Option from '../common/Option';\nimport Switch from '../switch';\n\nexport type SwitchOptionProps = {\n checked?: boolean;\n complex?: boolean;\n content?: React.ReactNode;\n disabled?: boolean;\n showMediaCircle?: boolean;\n showMediaAtAllSizes?: boolean;\n isContainerAligned?: boolean;\n id?: string;\n media?: React.ReactNode;\n onChange: (newValue: boolean) => void;\n title: React.ReactNode;\n 'aria-label': string;\n};\n\nconst stopPropagation = (event?: MouseEvent<HTMLSpanElement>) => {\n if (event) {\n event.stopPropagation();\n event.preventDefault();\n event.nativeEvent?.stopImmediatePropagation?.();\n }\n};\n\nconst SwitchOption = ({\n checked,\n complex,\n content,\n disabled,\n id,\n media,\n onChange,\n title,\n showMediaCircle,\n showMediaAtAllSizes,\n isContainerAligned,\n 'aria-label': ariaLabel,\n}: SwitchOptionProps) => {\n const sharedProps = {\n media,\n title,\n content,\n complex,\n disabled,\n showMediaCircle,\n showMediaAtAllSizes,\n isContainerAligned,\n };\n const toggle = (event?: MouseEvent<HTMLSpanElement>) => {\n stopPropagation(event);\n if (disabled) {\n return;\n }\n\n onChange(!checked);\n };\n\n return (\n <Option\n {...sharedProps}\n button={\n <Switch\n id={id}\n checked={checked}\n disabled={disabled}\n aria-label={ariaLabel}\n onClick={toggle}\n />\n }\n onClick={toggle}\n />\n );\n};\n\nexport default SwitchOption;\n"],"names":["stopPropagation","event","preventDefault","nativeEvent","stopImmediatePropagation","SwitchOption","checked","complex","content","disabled","id","media","onChange","title","showMediaCircle","showMediaAtAllSizes","isContainerAligned","ariaLabel","sharedProps","toggle","_jsx","Option","button","Switch","onClick"],"mappings":";;;;;;;;AAoBA,MAAMA,eAAe,GAAIC,KAAmC,IAAI;AAC9D,EAAA,IAAIA,KAAK,EAAE;IACTA,KAAK,CAACD,eAAe,EAAE;IACvBC,KAAK,CAACC,cAAc,EAAE;AACtBD,IAAAA,KAAK,CAACE,WAAW,EAAEC,wBAAwB,IAAI;AACjD;AACF,CAAC;AAEKC,MAAAA,YAAY,GAAGA,CAAC;EACpBC,OAAO;EACPC,OAAO;EACPC,OAAO;EACPC,QAAQ;EACRC,EAAE;EACFC,KAAK;EACLC,QAAQ;EACRC,KAAK;EACLC,eAAe;EACfC,mBAAmB;EACnBC,kBAAkB;AAClB,EAAA,YAAY,EAAEC;AAAS,CACL,KAAI;AACtB,EAAA,MAAMC,WAAW,GAAG;IAClBP,KAAK;IACLE,KAAK;IACLL,OAAO;IACPD,OAAO;IACPE,QAAQ;IACRK,eAAe;IACfC,mBAAmB;AACnBC,IAAAA;GACD;EACD,MAAMG,MAAM,GAAIlB,KAAmC,IAAI;IACrDD,eAAe,CAACC,KAAK,CAAC;AACtB,IAAA,IAAIQ,QAAQ,EAAE;AACZ,MAAA;AACF;IAEAG,QAAQ,CAAC,CAACN,OAAO,CAAC;GACnB;EAED,oBACEc,cAAA,CAACC,cAAM,EAAA;AAAA,IAAA,GACDH,WAAW;IACfI,MAAM,eACJF,cAAA,CAACG,cAAM,EAAA;AACLb,MAAAA,EAAE,EAAEA,EAAG;AACPJ,MAAAA,OAAO,EAAEA,OAAQ;AACjBG,MAAAA,QAAQ,EAAEA,QAAS;AACnB,MAAA,YAAA,EAAYQ,SAAU;AACtBO,MAAAA,OAAO,EAAEL;AAAO,KAEpB,CAAC;AACDK,IAAAA,OAAO,EAAEL;AAAO,GAChB,CAAA;AAEN;;;;"}
1
+ {"version":3,"file":"SwitchOption.js","sources":["../../src/switchOption/SwitchOption.tsx"],"sourcesContent":["import { MouseEvent } from 'react';\n\nimport Option from '../common/Option';\nimport Switch from '../switch';\n\nexport type SwitchOptionProps = {\n checked?: boolean;\n complex?: boolean;\n content?: React.ReactNode;\n disabled?: boolean;\n showMediaCircle?: boolean;\n showMediaAtAllSizes?: boolean;\n isContainerAligned?: boolean;\n id?: string;\n media?: React.ReactNode;\n onChange: (newValue: boolean) => void;\n title: React.ReactNode;\n 'aria-label': string;\n};\n\nconst stopPropagation = (event?: MouseEvent<HTMLSpanElement>) => {\n if (event) {\n event.stopPropagation();\n event.preventDefault();\n event.nativeEvent?.stopImmediatePropagation?.();\n }\n};\n\nconst SwitchOption = ({\n checked,\n complex,\n content,\n disabled,\n id,\n media,\n onChange,\n title,\n showMediaCircle,\n showMediaAtAllSizes,\n isContainerAligned,\n 'aria-label': ariaLabel,\n}: SwitchOptionProps) => {\n const sharedProps = {\n media,\n title,\n content,\n complex,\n disabled,\n showMediaCircle,\n showMediaAtAllSizes,\n isContainerAligned,\n };\n const toggle = (event?: MouseEvent<HTMLSpanElement>) => {\n stopPropagation(event);\n if (disabled) {\n return;\n }\n\n onChange(!checked);\n };\n\n return (\n <Option\n {...sharedProps}\n className=\"np-switch-option\"\n button={\n <Switch\n id={id}\n checked={checked}\n disabled={disabled}\n aria-label={ariaLabel}\n onClick={toggle}\n />\n }\n onClick={toggle}\n />\n );\n};\n\nexport default SwitchOption;\n"],"names":["stopPropagation","event","preventDefault","nativeEvent","stopImmediatePropagation","SwitchOption","checked","complex","content","disabled","id","media","onChange","title","showMediaCircle","showMediaAtAllSizes","isContainerAligned","ariaLabel","sharedProps","toggle","_jsx","Option","className","button","Switch","onClick"],"mappings":";;;;;;;;AAoBA,MAAMA,eAAe,GAAIC,KAAmC,IAAI;AAC9D,EAAA,IAAIA,KAAK,EAAE;IACTA,KAAK,CAACD,eAAe,EAAE;IACvBC,KAAK,CAACC,cAAc,EAAE;AACtBD,IAAAA,KAAK,CAACE,WAAW,EAAEC,wBAAwB,IAAI;AACjD;AACF,CAAC;AAEKC,MAAAA,YAAY,GAAGA,CAAC;EACpBC,OAAO;EACPC,OAAO;EACPC,OAAO;EACPC,QAAQ;EACRC,EAAE;EACFC,KAAK;EACLC,QAAQ;EACRC,KAAK;EACLC,eAAe;EACfC,mBAAmB;EACnBC,kBAAkB;AAClB,EAAA,YAAY,EAAEC;AAAS,CACL,KAAI;AACtB,EAAA,MAAMC,WAAW,GAAG;IAClBP,KAAK;IACLE,KAAK;IACLL,OAAO;IACPD,OAAO;IACPE,QAAQ;IACRK,eAAe;IACfC,mBAAmB;AACnBC,IAAAA;GACD;EACD,MAAMG,MAAM,GAAIlB,KAAmC,IAAI;IACrDD,eAAe,CAACC,KAAK,CAAC;AACtB,IAAA,IAAIQ,QAAQ,EAAE;AACZ,MAAA;AACF;IAEAG,QAAQ,CAAC,CAACN,OAAO,CAAC;GACnB;EAED,oBACEc,cAAA,CAACC,cAAM,EAAA;AAAA,IAAA,GACDH,WAAW;AACfI,IAAAA,SAAS,EAAC,kBAAkB;IAC5BC,MAAM,eACJH,cAAA,CAACI,cAAM,EAAA;AACLd,MAAAA,EAAE,EAAEA,EAAG;AACPJ,MAAAA,OAAO,EAAEA,OAAQ;AACjBG,MAAAA,QAAQ,EAAEA,QAAS;AACnB,MAAA,YAAA,EAAYQ,SAAU;AACtBQ,MAAAA,OAAO,EAAEN;AAAO,KAEpB,CAAC;AACDM,IAAAA,OAAO,EAAEN;AAAO,GAChB,CAAA;AAEN;;;;"}
@@ -42,6 +42,7 @@ const SwitchOption = ({
42
42
  };
43
43
  return /*#__PURE__*/jsx(Option, {
44
44
  ...sharedProps,
45
+ className: "np-switch-option",
45
46
  button: /*#__PURE__*/jsx(Switch, {
46
47
  id: id,
47
48
  checked: checked,
@@ -1 +1 @@
1
- {"version":3,"file":"SwitchOption.mjs","sources":["../../src/switchOption/SwitchOption.tsx"],"sourcesContent":["import { MouseEvent } from 'react';\n\nimport Option from '../common/Option';\nimport Switch from '../switch';\n\nexport type SwitchOptionProps = {\n checked?: boolean;\n complex?: boolean;\n content?: React.ReactNode;\n disabled?: boolean;\n showMediaCircle?: boolean;\n showMediaAtAllSizes?: boolean;\n isContainerAligned?: boolean;\n id?: string;\n media?: React.ReactNode;\n onChange: (newValue: boolean) => void;\n title: React.ReactNode;\n 'aria-label': string;\n};\n\nconst stopPropagation = (event?: MouseEvent<HTMLSpanElement>) => {\n if (event) {\n event.stopPropagation();\n event.preventDefault();\n event.nativeEvent?.stopImmediatePropagation?.();\n }\n};\n\nconst SwitchOption = ({\n checked,\n complex,\n content,\n disabled,\n id,\n media,\n onChange,\n title,\n showMediaCircle,\n showMediaAtAllSizes,\n isContainerAligned,\n 'aria-label': ariaLabel,\n}: SwitchOptionProps) => {\n const sharedProps = {\n media,\n title,\n content,\n complex,\n disabled,\n showMediaCircle,\n showMediaAtAllSizes,\n isContainerAligned,\n };\n const toggle = (event?: MouseEvent<HTMLSpanElement>) => {\n stopPropagation(event);\n if (disabled) {\n return;\n }\n\n onChange(!checked);\n };\n\n return (\n <Option\n {...sharedProps}\n button={\n <Switch\n id={id}\n checked={checked}\n disabled={disabled}\n aria-label={ariaLabel}\n onClick={toggle}\n />\n }\n onClick={toggle}\n />\n );\n};\n\nexport default SwitchOption;\n"],"names":["stopPropagation","event","preventDefault","nativeEvent","stopImmediatePropagation","SwitchOption","checked","complex","content","disabled","id","media","onChange","title","showMediaCircle","showMediaAtAllSizes","isContainerAligned","ariaLabel","sharedProps","toggle","_jsx","Option","button","Switch","onClick"],"mappings":";;;;AAoBA,MAAMA,eAAe,GAAIC,KAAmC,IAAI;AAC9D,EAAA,IAAIA,KAAK,EAAE;IACTA,KAAK,CAACD,eAAe,EAAE;IACvBC,KAAK,CAACC,cAAc,EAAE;AACtBD,IAAAA,KAAK,CAACE,WAAW,EAAEC,wBAAwB,IAAI;AACjD;AACF,CAAC;AAEKC,MAAAA,YAAY,GAAGA,CAAC;EACpBC,OAAO;EACPC,OAAO;EACPC,OAAO;EACPC,QAAQ;EACRC,EAAE;EACFC,KAAK;EACLC,QAAQ;EACRC,KAAK;EACLC,eAAe;EACfC,mBAAmB;EACnBC,kBAAkB;AAClB,EAAA,YAAY,EAAEC;AAAS,CACL,KAAI;AACtB,EAAA,MAAMC,WAAW,GAAG;IAClBP,KAAK;IACLE,KAAK;IACLL,OAAO;IACPD,OAAO;IACPE,QAAQ;IACRK,eAAe;IACfC,mBAAmB;AACnBC,IAAAA;GACD;EACD,MAAMG,MAAM,GAAIlB,KAAmC,IAAI;IACrDD,eAAe,CAACC,KAAK,CAAC;AACtB,IAAA,IAAIQ,QAAQ,EAAE;AACZ,MAAA;AACF;IAEAG,QAAQ,CAAC,CAACN,OAAO,CAAC;GACnB;EAED,oBACEc,GAAA,CAACC,MAAM,EAAA;AAAA,IAAA,GACDH,WAAW;IACfI,MAAM,eACJF,GAAA,CAACG,MAAM,EAAA;AACLb,MAAAA,EAAE,EAAEA,EAAG;AACPJ,MAAAA,OAAO,EAAEA,OAAQ;AACjBG,MAAAA,QAAQ,EAAEA,QAAS;AACnB,MAAA,YAAA,EAAYQ,SAAU;AACtBO,MAAAA,OAAO,EAAEL;AAAO,KAEpB,CAAC;AACDK,IAAAA,OAAO,EAAEL;AAAO,GAChB,CAAA;AAEN;;;;"}
1
+ {"version":3,"file":"SwitchOption.mjs","sources":["../../src/switchOption/SwitchOption.tsx"],"sourcesContent":["import { MouseEvent } from 'react';\n\nimport Option from '../common/Option';\nimport Switch from '../switch';\n\nexport type SwitchOptionProps = {\n checked?: boolean;\n complex?: boolean;\n content?: React.ReactNode;\n disabled?: boolean;\n showMediaCircle?: boolean;\n showMediaAtAllSizes?: boolean;\n isContainerAligned?: boolean;\n id?: string;\n media?: React.ReactNode;\n onChange: (newValue: boolean) => void;\n title: React.ReactNode;\n 'aria-label': string;\n};\n\nconst stopPropagation = (event?: MouseEvent<HTMLSpanElement>) => {\n if (event) {\n event.stopPropagation();\n event.preventDefault();\n event.nativeEvent?.stopImmediatePropagation?.();\n }\n};\n\nconst SwitchOption = ({\n checked,\n complex,\n content,\n disabled,\n id,\n media,\n onChange,\n title,\n showMediaCircle,\n showMediaAtAllSizes,\n isContainerAligned,\n 'aria-label': ariaLabel,\n}: SwitchOptionProps) => {\n const sharedProps = {\n media,\n title,\n content,\n complex,\n disabled,\n showMediaCircle,\n showMediaAtAllSizes,\n isContainerAligned,\n };\n const toggle = (event?: MouseEvent<HTMLSpanElement>) => {\n stopPropagation(event);\n if (disabled) {\n return;\n }\n\n onChange(!checked);\n };\n\n return (\n <Option\n {...sharedProps}\n className=\"np-switch-option\"\n button={\n <Switch\n id={id}\n checked={checked}\n disabled={disabled}\n aria-label={ariaLabel}\n onClick={toggle}\n />\n }\n onClick={toggle}\n />\n );\n};\n\nexport default SwitchOption;\n"],"names":["stopPropagation","event","preventDefault","nativeEvent","stopImmediatePropagation","SwitchOption","checked","complex","content","disabled","id","media","onChange","title","showMediaCircle","showMediaAtAllSizes","isContainerAligned","ariaLabel","sharedProps","toggle","_jsx","Option","className","button","Switch","onClick"],"mappings":";;;;AAoBA,MAAMA,eAAe,GAAIC,KAAmC,IAAI;AAC9D,EAAA,IAAIA,KAAK,EAAE;IACTA,KAAK,CAACD,eAAe,EAAE;IACvBC,KAAK,CAACC,cAAc,EAAE;AACtBD,IAAAA,KAAK,CAACE,WAAW,EAAEC,wBAAwB,IAAI;AACjD;AACF,CAAC;AAEKC,MAAAA,YAAY,GAAGA,CAAC;EACpBC,OAAO;EACPC,OAAO;EACPC,OAAO;EACPC,QAAQ;EACRC,EAAE;EACFC,KAAK;EACLC,QAAQ;EACRC,KAAK;EACLC,eAAe;EACfC,mBAAmB;EACnBC,kBAAkB;AAClB,EAAA,YAAY,EAAEC;AAAS,CACL,KAAI;AACtB,EAAA,MAAMC,WAAW,GAAG;IAClBP,KAAK;IACLE,KAAK;IACLL,OAAO;IACPD,OAAO;IACPE,QAAQ;IACRK,eAAe;IACfC,mBAAmB;AACnBC,IAAAA;GACD;EACD,MAAMG,MAAM,GAAIlB,KAAmC,IAAI;IACrDD,eAAe,CAACC,KAAK,CAAC;AACtB,IAAA,IAAIQ,QAAQ,EAAE;AACZ,MAAA;AACF;IAEAG,QAAQ,CAAC,CAACN,OAAO,CAAC;GACnB;EAED,oBACEc,GAAA,CAACC,MAAM,EAAA;AAAA,IAAA,GACDH,WAAW;AACfI,IAAAA,SAAS,EAAC,kBAAkB;IAC5BC,MAAM,eACJH,GAAA,CAACI,MAAM,EAAA;AACLd,MAAAA,EAAE,EAAEA,EAAG;AACPJ,MAAAA,OAAO,EAAEA,OAAQ;AACjBG,MAAAA,QAAQ,EAAEA,QAAS;AACnB,MAAA,YAAA,EAAYQ,SAAU;AACtBQ,MAAAA,OAAO,EAAEN;AAAO,KAEpB,CAAC;AACDM,IAAAA,OAAO,EAAEN;AAAO,GAChB,CAAA;AAEN;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"Switch.d.ts","sourceRoot":"","sources":["../../../src/switch/Switch.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAwB,UAAU,EAAE,MAAM,OAAO,CAAC;AAE9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAG7C,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG;IACtC;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yGAAyG;IACzG,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,2CAA2C;IAC3C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,0CAA0C;IAC1C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,iDAAiD;IACjD,OAAO,EAAE,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC,eAAe,CAAC,KAAK,IAAI,CAAC;CACxD,CAAC;AAEF,QAAA,MAAM,MAAM,GAAI,OAAO,WAAW,gCAiDjC,CAAC;AAEF,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"Switch.d.ts","sourceRoot":"","sources":["../../../src/switch/Switch.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAwB,UAAU,EAAE,MAAM,OAAO,CAAC;AAE9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAG7C,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG;IACtC;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yGAAyG;IACzG,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,2CAA2C;IAC3C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,0CAA0C;IAC1C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,iDAAiD;IACjD,OAAO,EAAE,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC,eAAe,CAAC,KAAK,IAAI,CAAC;CACxD,CAAC;AAEF,QAAA,MAAM,MAAM,GAAI,OAAO,WAAW,gCAwCjC,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"SwitchOption.d.ts","sourceRoot":"","sources":["../../../src/switchOption/SwitchOption.tsx"],"names":[],"mappings":"AAKA,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACxB,QAAQ,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;IACtC,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAUF,QAAA,MAAM,YAAY,GAAI,yJAanB,iBAAiB,gCAmCnB,CAAC;AAEF,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"SwitchOption.d.ts","sourceRoot":"","sources":["../../../src/switchOption/SwitchOption.tsx"],"names":[],"mappings":"AAKA,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACxB,QAAQ,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;IACtC,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAUF,QAAA,MAAM,YAAY,GAAI,yJAanB,iBAAiB,gCAoCnB,CAAC;AAEF,eAAe,YAAY,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transferwise/components",
3
- "version": "0.0.0-experimental-a8f3db2",
3
+ "version": "0.0.0-experimental-8abc58f",
4
4
  "description": "Neptune React components",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -1,3 +1,4 @@
1
+ import React, { useState } from 'react';
1
2
  import { Meta, StoryObj } from '@storybook/react';
2
3
  import { FastFlag as FastFlagIcon, CardWise as CardWiseIcon } from '@transferwise/icons';
3
4
 
@@ -6,6 +7,7 @@ import Modal from '../modal';
6
7
  import { lorem10, lorem40 } from '../test-utils';
7
8
 
8
9
  import Accordion from './Accordion';
10
+ import Button from '../button/Button';
9
11
 
10
12
  /**
11
13
  * Metadata for the Accordion component story.
@@ -20,8 +22,8 @@ const meta: Meta<typeof Accordion> = {
20
22
  'A simple accordion component that displays a list of items that can be expanded or collapsed.',
21
23
  },
22
24
  },
23
- tags: ['autodocs'],
24
25
  },
26
+ tags: ['autodocs'],
25
27
  args: {
26
28
  items: [
27
29
  {
@@ -133,28 +135,36 @@ export const WithinModal: Story = {
133
135
  delay: 1000,
134
136
  },
135
137
  },
136
- render: (args) => {
138
+ render: (args, { viewMode }) => {
139
+ // Modal is open by default unless in docs view
140
+ const [open, setOpen] = useState(viewMode !== 'docs');
137
141
  const { items } = args;
142
+
138
143
  return (
139
- <Modal
140
- body={
141
- <div className="p-a-1">
142
- <h3 className="m-t-2 m-b-4 text-xs-center">Large transfer tips</h3>
143
- <Accordion {...args} items={[items[0]]} />
144
- <Accordion {...args} items={[items[0]]} indexOpen={0} />
145
- <Accordion {...args} items={items} />
146
- </div>
147
- }
148
- scroll={Scroll.CONTENT}
149
- size={Size.LARGE}
150
- open
151
- footer={
152
- <div className="p-a-3 text-xs-center">
153
- <a href="/large-amounts">Learn more</a>
154
- </div>
155
- }
156
- onClose={() => {}}
157
- />
144
+ <>
145
+ <Button v2 onClick={() => setOpen(true)}>
146
+ Open Modal
147
+ </Button>
148
+ <Modal
149
+ body={
150
+ <div className="p-a-1">
151
+ <h3 className="m-t-2 m-b-4 text-xs-center">Large transfer tips</h3>
152
+ <Accordion {...args} items={[items[0]]} />
153
+ <Accordion {...args} items={[items[0]]} indexOpen={0} />
154
+ <Accordion {...args} items={items} />
155
+ </div>
156
+ }
157
+ scroll={Scroll.CONTENT}
158
+ size={Size.LARGE}
159
+ open={open}
160
+ footer={
161
+ <div className="p-a-3 text-xs-center">
162
+ <a href="/large-amounts">Learn more</a>
163
+ </div>
164
+ }
165
+ onClose={() => setOpen(false)}
166
+ />
167
+ </>
158
168
  );
159
169
  },
160
170
  };
@@ -26,6 +26,7 @@ import Body from '../body';
26
26
 
27
27
  export default {
28
28
  title: 'Content/AvatarView',
29
+ tags: ['autodocs'],
29
30
  } satisfies Meta<typeof AvatarView>;
30
31
 
31
32
  type Story = StoryObj<typeof AvatarView>;
@@ -35,7 +36,6 @@ const profileName2 = 'Tyler Durden';
35
36
  const sizes: AvatarViewProps['size'][] = [16, 24, 32, 40, 48, 56, 72];
36
37
 
37
38
  export const Selected: Story = {
38
- tags: ['autodocs'],
39
39
  render: () => {
40
40
  return (
41
41
  <div
@@ -69,7 +69,6 @@ export const Selected: Story = {
69
69
  };
70
70
 
71
71
  export const Notification: Story = {
72
- tags: ['autodocs'],
73
72
  render: () => (
74
73
  <div
75
74
  style={{
@@ -106,7 +105,6 @@ export const Notification: Story = {
106
105
  };
107
106
 
108
107
  export const Badge: Story = {
109
- tags: ['autodocs'],
110
108
  render: () => {
111
109
  const currencies = ['USD', 'EUR', 'GBP', 'AUD', 'CAD', 'JPY', 'CNY'];
112
110
  const icons = [
@@ -250,7 +248,6 @@ export const Badge: Story = {
250
248
  };
251
249
 
252
250
  export const Images: Story = {
253
- tags: ['autodocs'],
254
251
  render: () => {
255
252
  return (
256
253
  <div
@@ -305,7 +302,6 @@ export const Images: Story = {
305
302
  };
306
303
 
307
304
  export const Profiles: Story = {
308
- tags: ['autodocs'],
309
305
  render: () => {
310
306
  return (
311
307
  <div
@@ -388,7 +384,6 @@ export const ProfileBrokenImageFallback: Story = {
388
384
  };
389
385
 
390
386
  export const EdgeInstaces: Story = {
391
- tags: ['autodocs'],
392
387
  render: () => {
393
388
  const css = `.custom-variant {
394
389
  border: 1px dashed var(--color-border-neutral);
@@ -9,6 +9,7 @@ import Carousel, { type CarouselCard } from './Carousel';
9
9
  export default {
10
10
  component: Carousel,
11
11
  title: 'Navigation/Carousel',
12
+ tags: ['autodocs'],
12
13
  };
13
14
 
14
15
  const carouselCards: CarouselCard[] = [
@@ -16,13 +16,14 @@ export default {
16
16
  component: BottomSheet,
17
17
  title: 'Dialogs/BottomSheet',
18
18
  args: {
19
- open: true,
19
+ open: false,
20
20
  },
21
- render: (args) => {
22
- const [open, setOpen] = useState(args.open);
21
+ tags: ['autodocs'],
22
+ render: (args, { viewMode }) => {
23
+ const [open, setOpen] = useState(viewMode !== 'docs');
23
24
 
24
25
  return (
25
- <div style={{ height: '2000px' }}>
26
+ <div>
26
27
  <Button onClick={() => setOpen(true)}>Open BottomSheet</Button>
27
28
  <BottomSheet
28
29
  {...args}
@@ -9,6 +9,7 @@ import Body from '../../body';
9
9
  export default {
10
10
  title: 'Internal/Circle',
11
11
  component: Circle,
12
+ tags: ['autodocs'],
12
13
  } satisfies Meta<typeof Circle>;
13
14
 
14
15
  type Story = StoryObj<typeof Circle>;
@@ -11,6 +11,7 @@ import DateLookup from './DateLookup';
11
11
  export default {
12
12
  component: DateLookup,
13
13
  title: 'Forms/DateLookup',
14
+ tags: ['autodocs'],
14
15
  };
15
16
 
16
17
  const epoch = new Date('2011-01-01');
@@ -10,6 +10,7 @@ import AvatarView from '../avatarView';
10
10
  export default {
11
11
  component: Decision,
12
12
  title: 'Layouts/Decision',
13
+ tags: ['autodocs'],
13
14
  };
14
15
 
15
16
  export const Basic = () => {
@@ -10,6 +10,7 @@ import Header from '../header';
10
10
  export default {
11
11
  component: DefinitionList,
12
12
  title: 'Typography/DefinitionList',
13
+ tags: ['autodocs'],
13
14
  };
14
15
 
15
16
  const layouts: DefinitionListLayout[] = [
@@ -12,6 +12,7 @@ export default {
12
12
  fadeContentOnExit: false,
13
13
  disableClickToClose: false,
14
14
  },
15
+ tags: ['autodocs'],
15
16
  } satisfies Meta<typeof Dimmer>;
16
17
 
17
18
  type Story = StoryObj<typeof Dimmer>;
@@ -6,6 +6,7 @@ import Display from './Display';
6
6
 
7
7
  export default {
8
8
  title: 'Typography/Display',
9
+ tags: ['autodocs'],
9
10
  };
10
11
 
11
12
  export const Basic = () => {
@@ -9,6 +9,7 @@ import Drawer from './Drawer';
9
9
  export default {
10
10
  component: Drawer,
11
11
  title: 'Dialogs/Drawer',
12
+ tags: ['autodocs'],
12
13
  };
13
14
 
14
15
  export const Basic = () => {