@doist/reactist 24.2.0-beta → 25.0.0-beta.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 (144) hide show
  1. package/dist/reactist.cjs.development.js +336 -261
  2. package/dist/reactist.cjs.development.js.map +1 -1
  3. package/dist/reactist.cjs.production.min.js +1 -1
  4. package/dist/reactist.cjs.production.min.js.map +1 -1
  5. package/es/avatar/avatar.js.map +1 -1
  6. package/es/banner/banner.js.map +1 -1
  7. package/es/box/box.js +94 -19
  8. package/es/box/box.js.map +1 -1
  9. package/es/button/button.js +93 -18
  10. package/es/button/button.js.map +1 -1
  11. package/es/button/button.module.css.js +4 -0
  12. package/es/button/button.module.css.js.map +1 -0
  13. package/es/checkbox-field/checkbox-field.js.map +1 -1
  14. package/es/components/deprecated-dropdown/dropdown.js.map +1 -1
  15. package/es/components/deprecated-input/input.js +5 -1
  16. package/es/components/deprecated-input/input.js.map +1 -1
  17. package/es/heading/heading.js.map +1 -1
  18. package/es/index.js +2 -3
  19. package/es/index.js.map +1 -1
  20. package/es/loading/loading.js.map +1 -1
  21. package/es/menu/menu.js +56 -34
  22. package/es/menu/menu.js.map +1 -1
  23. package/es/modal/modal.js +18 -16
  24. package/es/modal/modal.js.map +1 -1
  25. package/es/password-field/password-field.js +2 -2
  26. package/es/password-field/password-field.js.map +1 -1
  27. package/es/prose/prose.js.map +1 -1
  28. package/es/select-field/select-field.js.map +1 -1
  29. package/es/switch-field/switch-field.js.map +1 -1
  30. package/es/tabs/tabs.js +26 -32
  31. package/es/tabs/tabs.js.map +1 -1
  32. package/es/text-area/text-area.js.map +1 -1
  33. package/es/text-field/text-field.js.map +1 -1
  34. package/es/toast/static-toast.js +2 -2
  35. package/es/toast/static-toast.js.map +1 -1
  36. package/es/tooltip/tooltip.js +13 -12
  37. package/es/tooltip/tooltip.js.map +1 -1
  38. package/es/utils/polymorphism.js +1 -1
  39. package/es/utils/polymorphism.js.map +1 -1
  40. package/lib/alert/alert.d.ts +1 -1
  41. package/lib/avatar/avatar.d.ts +4 -4
  42. package/lib/avatar/avatar.js.map +1 -1
  43. package/lib/badge/badge.d.ts +2 -2
  44. package/lib/banner/banner.d.ts +2 -2
  45. package/lib/banner/banner.js.map +1 -1
  46. package/lib/base-field/base-field.d.ts +3 -3
  47. package/lib/box/box.d.ts +2 -1
  48. package/lib/box/box.js +1 -1
  49. package/lib/box/box.js.map +1 -1
  50. package/lib/button/button.d.ts +123 -11
  51. package/lib/button/button.js +1 -1
  52. package/lib/button/button.js.map +1 -1
  53. package/lib/button/button.module.css.js +2 -0
  54. package/lib/button/button.module.css.js.map +1 -0
  55. package/lib/checkbox-field/checkbox-field.d.ts +29 -17
  56. package/lib/checkbox-field/checkbox-field.js.map +1 -1
  57. package/lib/checkbox-field/checkbox-icon.d.ts +1 -1
  58. package/lib/components/color-picker/color-picker.d.ts +2 -2
  59. package/lib/components/deprecated-dropdown/dropdown.d.ts +5 -5
  60. package/lib/components/deprecated-dropdown/dropdown.js.map +1 -1
  61. package/lib/components/deprecated-input/input.d.ts +6 -6
  62. package/lib/components/deprecated-input/input.js +1 -1
  63. package/lib/components/deprecated-input/input.js.map +1 -1
  64. package/lib/components/deprecated-select/select.d.ts +2 -2
  65. package/lib/components/icons/CloseIcon.svg.d.ts +2 -2
  66. package/lib/components/icons/ThinQuestionMarkIcon.svg.d.ts +2 -2
  67. package/lib/components/icons/ThreeDotsIcon.svg.d.ts +2 -2
  68. package/lib/components/keyboard-shortcut/keyboard-shortcut.d.ts +1 -1
  69. package/lib/components/progress-bar/progress-bar.d.ts +2 -2
  70. package/lib/components/time/time.d.ts +1 -1
  71. package/lib/divider/divider.d.ts +2 -2
  72. package/lib/heading/heading.d.ts +4 -12
  73. package/lib/heading/heading.js.map +1 -1
  74. package/lib/icons/alert-icon.d.ts +2 -2
  75. package/lib/icons/close-icon.d.ts +2 -2
  76. package/lib/icons/password-hidden-icon.d.ts +2 -2
  77. package/lib/icons/password-visible-icon.d.ts +2 -2
  78. package/lib/index.d.ts +0 -1
  79. package/lib/index.js +1 -1
  80. package/lib/loading/loading.d.ts +6 -7
  81. package/lib/loading/loading.js.map +1 -1
  82. package/lib/menu/menu.d.ts +20 -20
  83. package/lib/menu/menu.js +1 -1
  84. package/lib/menu/menu.js.map +1 -1
  85. package/lib/modal/modal-stories-components.d.ts +9 -9
  86. package/lib/modal/modal.d.ts +24 -35
  87. package/lib/modal/modal.js +1 -1
  88. package/lib/modal/modal.js.map +1 -1
  89. package/lib/notice/notice.d.ts +1 -1
  90. package/lib/password-field/password-field.d.ts +3 -8
  91. package/lib/password-field/password-field.js +1 -1
  92. package/lib/password-field/password-field.js.map +1 -1
  93. package/lib/prose/prose.d.ts +4 -7
  94. package/lib/prose/prose.js.map +1 -1
  95. package/lib/select-field/select-field.d.ts +3 -7
  96. package/lib/select-field/select-field.js.map +1 -1
  97. package/lib/spinner/spinner.d.ts +2 -2
  98. package/lib/switch-field/switch-field.d.ts +12 -11
  99. package/lib/switch-field/switch-field.js.map +1 -1
  100. package/lib/tabs/tabs.d.ts +24 -16
  101. package/lib/tabs/tabs.js +1 -1
  102. package/lib/tabs/tabs.js.map +1 -1
  103. package/lib/text-area/text-area.d.ts +3 -8
  104. package/lib/text-area/text-area.js.map +1 -1
  105. package/lib/text-field/text-field.d.ts +5 -10
  106. package/lib/text-field/text-field.js.map +1 -1
  107. package/lib/toast/static-toast.js +1 -1
  108. package/lib/toast/static-toast.js.map +1 -1
  109. package/lib/toast/use-toasts.d.ts +1 -1
  110. package/lib/tooltip/tooltip.d.ts +4 -7
  111. package/lib/tooltip/tooltip.js +1 -1
  112. package/lib/tooltip/tooltip.js.map +1 -1
  113. package/lib/utils/common-types.d.ts +19 -0
  114. package/lib/utils/polymorphism.d.ts +5 -21
  115. package/lib/utils/polymorphism.js.map +1 -1
  116. package/lib/utils/test-helpers.d.ts +2 -2
  117. package/package.json +3 -3
  118. package/styles/alert.css +2 -2
  119. package/styles/{base-button.css → button.css} +2 -2
  120. package/styles/button.module.css.css +1 -0
  121. package/styles/modal.css +2 -2
  122. package/styles/password-field.css +2 -2
  123. package/styles/reactist.css +1 -1
  124. package/styles/static-toast.css +2 -2
  125. package/styles/use-toasts.css +2 -2
  126. package/es/base-button/base-button.js +0 -75
  127. package/es/base-button/base-button.js.map +0 -1
  128. package/es/base-button/base-button.module.css.js +0 -4
  129. package/es/base-button/base-button.module.css.js.map +0 -1
  130. package/es/button-link/button-link.js +0 -38
  131. package/es/button-link/button-link.js.map +0 -1
  132. package/lib/base-button/base-button.d.ts +0 -80
  133. package/lib/base-button/base-button.js +0 -2
  134. package/lib/base-button/base-button.js.map +0 -1
  135. package/lib/base-button/base-button.module.css.js +0 -2
  136. package/lib/base-button/base-button.module.css.js.map +0 -1
  137. package/lib/base-button/index.d.ts +0 -1
  138. package/lib/button-link/button-link-story-wrapper.d.ts +0 -7
  139. package/lib/button-link/button-link.d.ts +0 -13
  140. package/lib/button-link/button-link.js +0 -2
  141. package/lib/button-link/button-link.js.map +0 -1
  142. package/lib/button-link/button-link.test.d.ts +0 -1
  143. package/lib/button-link/index.d.ts +0 -1
  144. package/styles/base-button.module.css.css +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"heading.js","sources":["../../src/heading/heading.tsx"],"sourcesContent":["import * as React from 'react'\nimport { getClassNames } from '../utils/responsive-props'\nimport { Box } from '../box'\nimport styles from './heading.module.css'\nimport type { ObfuscatedClassName } from '../utils/polymorphism'\nimport type { Tone } from '../utils/common-types'\nimport type { BoxProps } from '../box'\n\ntype HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6 | '1' | '2' | '3' | '4' | '5' | '6'\ntype HeadingElement = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'\n\n/**\n * FIXME: This is a workaround for consumers that are using newer versions of React types that no longer have these props.\n * Once we upgrade Reactist to the newest React types, we should be able to remove these.\n */\ntype DeprecatedProps = 'placeholder' | 'onPointerEnterCapture' | 'onPointerLeaveCapture'\n\ntype SupportedHeadingElementProps = Omit<\n JSX.IntrinsicElements[HeadingElement],\n 'className' | 'children' | DeprecatedProps\n>\n\ntype HeadingProps = SupportedHeadingElementProps & {\n children: React.ReactNode\n /**\n * The semantic level of the heading.\n */\n level: HeadingLevel\n /**\n * The weight of the heading. Used to de-emphasize the heading visually when using 'medium' or 'light'.\n *\n * @default 'regular'\n */\n weight?: 'regular' | 'medium' | 'light'\n /**\n * Shifts the default heading visual text size up or down, depending on the original size\n * imposed by the `level`. The heading continues to be semantically at the given level.\n *\n * By default, no value is applied, and the default size from the level is applied. The values\n * have the following effect:\n *\n * - 'smaller' shifts the default level size down in the font-size scale (it tends to make the\n * level look visually as if it were of the immediately lower level).\n * - 'larger' has the opposite effect than 'smaller' shifting the visual font size up in the\n * scale.\n * - 'largest' can be thought of as applying 'larger' twice.\n *\n * @see level\n * @default undefined\n */\n size?: 'smaller' | 'larger' | 'largest'\n /**\n * The tone (semantic color) of the heading.\n *\n * @default 'normal'\n */\n tone?: Tone\n /**\n * Used to truncate the heading to a given number of lines.\n *\n * It will add an ellipsis (`…`) to the text at the end of the last line, only if the text was\n * truncated. If the text fits without it being truncated, no ellipsis is added.\n *\n * By default, the text is not truncated at all, no matter how many lines it takes to render it.\n *\n * @default undefined\n */\n lineClamp?: 1 | 2 | 3 | 4 | 5 | '1' | '2' | '3' | '4' | '5'\n /**\n * How to align the heading text horizontally.\n *\n * @default 'start'\n */\n align?: BoxProps['textAlign']\n}\n\nconst Heading = React.forwardRef<HTMLHeadingElement, HeadingProps & ObfuscatedClassName>(\n function Heading(\n {\n level,\n weight = 'regular',\n size,\n tone = 'normal',\n children,\n lineClamp,\n align,\n exceptionallySetClassName,\n ...props\n },\n ref,\n ) {\n // In TypeScript v4.1, this would be properly recognized without needing the type assertion\n // https://devblogs.microsoft.com/typescript/announcing-typescript-4-1-beta/#template-literal-types\n const headingElementName = `h${level}` as HeadingElement\n const lineClampMultipleLines =\n typeof lineClamp === 'string' ? parseInt(lineClamp, 10) > 1 : (lineClamp || 0) > 1\n\n return (\n <Box\n {...props}\n className={[\n exceptionallySetClassName,\n styles.heading,\n weight !== 'regular' ? getClassNames(styles, 'weight', weight) : null,\n tone !== 'normal' ? getClassNames(styles, 'tone', tone) : null,\n getClassNames(styles, 'size', size),\n lineClampMultipleLines ? styles.lineClampMultipleLines : null,\n lineClamp ? getClassNames(styles, 'lineClamp', lineClamp.toString()) : null,\n ]}\n textAlign={align}\n // Prevents emojis from being cut-off\n // See https://github.com/Doist/reactist/pull/528\n paddingRight={lineClamp ? 'xsmall' : undefined}\n as={headingElementName}\n ref={ref}\n >\n {children}\n </Box>\n )\n },\n)\n\nexport type { HeadingProps, HeadingLevel }\nexport { Heading }\n"],"names":["Heading","React","ref","level","weight","size","tone","children","lineClamp","align","exceptionallySetClassName","props","headingElementName","lineClampMultipleLines","parseInt","Box","className","styles","heading","getClassNames","toString","textAlign","paddingRight","undefined","as"],"mappings":";;;;;;;MA4EMA,OAAO,gBAAGC,UAAA,CACZ,SAASD,OAAT,OAYIE,GAZJ;MACI;IACIC,KADJ;IAEIC,MAAM,GAAG,SAFb;IAGIC,IAHJ;IAIIC,IAAI,GAAG,QAJX;IAKIC,QALJ;IAMIC,SANJ;IAOIC,KAPJ;IAQIC;;MACGC;;;;EAMP,MAAMC,kBAAkB,SAAOT,KAA/B;EACA,MAAMU,sBAAsB,GACxB,OAAOL,SAAP,KAAqB,QAArB,GAAgCM,QAAQ,CAACN,SAAD,EAAY,EAAZ,CAAR,GAA0B,CAA1D,GAA8D,CAACA,SAAS,IAAI,CAAd,IAAmB,CADrF;EAGA,oBACIP,aAAA,CAACc,GAAD,oCACQJ,KADR;IAEIK,SAAS,EAAE,CACPN,yBADO,EAEPO,MAAM,CAACC,OAFA,EAGPd,MAAM,KAAK,SAAX,GAAuBe,aAAa,CAACF,MAAD,EAAS,QAAT,EAAmBb,MAAnB,CAApC,GAAiE,IAH1D,EAIPE,IAAI,KAAK,QAAT,GAAoBa,aAAa,CAACF,MAAD,EAAS,MAAT,EAAiBX,IAAjB,CAAjC,GAA0D,IAJnD,EAKPa,aAAa,CAACF,MAAD,EAAS,MAAT,EAAiBZ,IAAjB,CALN,EAMPQ,sBAAsB,GAAGI,MAAM,CAACJ,sBAAV,GAAmC,IANlD,EAOPL,SAAS,GAAGW,aAAa,CAACF,MAAD,EAAS,WAAT,EAAsBT,SAAS,CAACY,QAAV,EAAtB,CAAhB,GAA8D,IAPhE,CAFf;IAWIC,SAAS,EAAEZ,KAXf;;;IAcIa,YAAY,EAAEd,SAAS,GAAG,QAAH,GAAce,SAdzC;IAeIC,EAAE,EAAEZ,kBAfR;IAgBIV,GAAG,EAAEA;MAEJK,QAlBL,CADJ;AAsBH,CA3CW;;;;"}
1
+ {"version":3,"file":"heading.js","sources":["../../src/heading/heading.tsx"],"sourcesContent":["import * as React from 'react'\nimport { getClassNames } from '../utils/responsive-props'\nimport { Box } from '../box'\nimport styles from './heading.module.css'\nimport type { ObfuscatedClassName, Tone } from '../utils/common-types'\nimport type { BoxProps } from '../box'\n\ntype HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6 | '1' | '2' | '3' | '4' | '5' | '6'\ntype HeadingElement = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'\n\ntype HeadingProps = Omit<React.HTMLAttributes<HTMLHeadingElement>, 'className' | 'children'> & {\n children: React.ReactNode\n /**\n * The semantic level of the heading.\n */\n level: HeadingLevel\n\n /**\n * The weight of the heading. Used to de-emphasize the heading visually when using 'medium' or 'light'.\n *\n * @default 'regular'\n */\n weight?: 'regular' | 'medium' | 'light'\n\n /**\n * Shifts the default heading visual text size up or down, depending on the original size\n * imposed by the `level`. The heading continues to be semantically at the given level.\n *\n * By default, no value is applied, and the default size from the level is applied. The values\n * have the following effect:\n *\n * - 'smaller' shifts the default level size down in the font-size scale (it tends to make the\n * level look visually as if it were of the immediately lower level).\n * - 'larger' has the opposite effect than 'smaller' shifting the visual font size up in the\n * scale.\n * - 'largest' can be thought of as applying 'larger' twice.\n *\n * @see level\n * @default undefined\n */\n size?: 'smaller' | 'larger' | 'largest'\n\n /**\n * The tone (semantic color) of the heading.\n *\n * @default 'normal'\n */\n tone?: Tone\n\n /**\n * Used to truncate the heading to a given number of lines.\n *\n * It will add an ellipsis (`…`) to the text at the end of the last line, only if the text was\n * truncated. If the text fits without it being truncated, no ellipsis is added.\n *\n * By default, the text is not truncated at all, no matter how many lines it takes to render it.\n *\n * @default undefined\n */\n lineClamp?: 1 | 2 | 3 | 4 | 5 | '1' | '2' | '3' | '4' | '5'\n\n /**\n * How to align the heading text horizontally.\n *\n * @default 'start'\n */\n align?: BoxProps['textAlign']\n}\n\nconst Heading = React.forwardRef<HTMLHeadingElement, HeadingProps & ObfuscatedClassName>(\n function Heading(\n {\n level,\n weight = 'regular',\n size,\n tone = 'normal',\n children,\n lineClamp,\n align,\n exceptionallySetClassName,\n ...props\n },\n ref,\n ) {\n // In TypeScript v4.1, this would be properly recognized without needing the type assertion\n // https://devblogs.microsoft.com/typescript/announcing-typescript-4-1-beta/#template-literal-types\n const headingElementName = `h${level}` as HeadingElement\n const lineClampMultipleLines =\n typeof lineClamp === 'string' ? parseInt(lineClamp, 10) > 1 : (lineClamp || 0) > 1\n\n return (\n <Box\n {...props}\n className={[\n exceptionallySetClassName,\n styles.heading,\n weight !== 'regular' ? getClassNames(styles, 'weight', weight) : null,\n tone !== 'normal' ? getClassNames(styles, 'tone', tone) : null,\n getClassNames(styles, 'size', size),\n lineClampMultipleLines ? styles.lineClampMultipleLines : null,\n lineClamp ? getClassNames(styles, 'lineClamp', lineClamp.toString()) : null,\n ]}\n textAlign={align}\n // Prevents emojis from being cut-off\n // See https://github.com/Doist/reactist/pull/528\n paddingRight={lineClamp ? 'xsmall' : undefined}\n as={headingElementName}\n ref={ref}\n >\n {children}\n </Box>\n )\n },\n)\n\nexport type { HeadingProps, HeadingLevel }\nexport { Heading }\n"],"names":["Heading","React","ref","level","weight","size","tone","children","lineClamp","align","exceptionallySetClassName","props","headingElementName","lineClampMultipleLines","parseInt","Box","className","styles","heading","getClassNames","toString","textAlign","paddingRight","undefined","as"],"mappings":";;;;;;;MAqEMA,OAAO,gBAAGC,UAAA,CACZ,SAASD,OAAT,OAYIE,GAZJ;MACI;IACIC,KADJ;IAEIC,MAAM,GAAG,SAFb;IAGIC,IAHJ;IAIIC,IAAI,GAAG,QAJX;IAKIC,QALJ;IAMIC,SANJ;IAOIC,KAPJ;IAQIC;;MACGC;;;;EAMP,MAAMC,kBAAkB,SAAOT,KAA/B;EACA,MAAMU,sBAAsB,GACxB,OAAOL,SAAP,KAAqB,QAArB,GAAgCM,QAAQ,CAACN,SAAD,EAAY,EAAZ,CAAR,GAA0B,CAA1D,GAA8D,CAACA,SAAS,IAAI,CAAd,IAAmB,CADrF;EAGA,oBACIP,aAAA,CAACc,GAAD,oCACQJ,KADR;IAEIK,SAAS,EAAE,CACPN,yBADO,EAEPO,MAAM,CAACC,OAFA,EAGPd,MAAM,KAAK,SAAX,GAAuBe,aAAa,CAACF,MAAD,EAAS,QAAT,EAAmBb,MAAnB,CAApC,GAAiE,IAH1D,EAIPE,IAAI,KAAK,QAAT,GAAoBa,aAAa,CAACF,MAAD,EAAS,MAAT,EAAiBX,IAAjB,CAAjC,GAA0D,IAJnD,EAKPa,aAAa,CAACF,MAAD,EAAS,MAAT,EAAiBZ,IAAjB,CALN,EAMPQ,sBAAsB,GAAGI,MAAM,CAACJ,sBAAV,GAAmC,IANlD,EAOPL,SAAS,GAAGW,aAAa,CAACF,MAAD,EAAS,WAAT,EAAsBT,SAAS,CAACY,QAAV,EAAtB,CAAhB,GAA8D,IAPhE,CAFf;IAWIC,SAAS,EAAEZ,KAXf;;;IAcIa,YAAY,EAAEd,SAAS,GAAG,QAAH,GAAce,SAdzC;IAeIC,EAAE,EAAEZ,kBAfR;IAgBIV,GAAG,EAAEA;MAEJK,QAlBL,CADJ;AAsBH,CA3CW;;;;"}
package/es/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { Box } from './box/box.js';
1
+ export { Box, getBoxClassNames } from './box/box.js';
2
2
  export { Column, Columns } from './columns/columns.js';
3
3
  export { Divider } from './divider/divider.js';
4
4
  export { Inline } from './inline/inline.js';
@@ -6,7 +6,7 @@ export { Stack } from './stack/stack.js';
6
6
  export { Hidden } from './hidden/hidden.js';
7
7
  export { HiddenVisually } from './hidden-visually/hidden-visually.js';
8
8
  export { Tooltip } from './tooltip/tooltip.js';
9
- export { Button } from './button/button.js';
9
+ export { Button, IconButton } from './button/button.js';
10
10
  export { Alert } from './alert/alert.js';
11
11
  export { Banner } from './banner/banner.js';
12
12
  export { Loading } from './loading/loading.js';
@@ -16,7 +16,6 @@ export { StaticToast } from './toast/static-toast.js';
16
16
  export { Toast, ToastsProvider, useToasts } from './toast/use-toasts.js';
17
17
  export { Heading } from './heading/heading.js';
18
18
  export { Prose } from './prose/prose.js';
19
- export { ButtonLink } from './button-link/button-link.js';
20
19
  export { TextLink } from './text-link/text-link.js';
21
20
  export { CheckboxField } from './checkbox-field/checkbox-field.js';
22
21
  export { TextField } from './text-field/text-field.js';
package/es/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"loading.js","sources":["../../src/loading/loading.tsx"],"sourcesContent":["import * as React from 'react'\nimport { Box } from '../box'\nimport { Spinner } from '../spinner'\n\ntype Size = 'xsmall' | 'small' | 'medium' | 'large'\n\ntype NativeProps = Omit<\n JSX.IntrinsicElements['div'],\n 'className' | 'aria-describedby' | 'aria-label' | 'aria-labelledby' | 'role' | 'size'\n>\n\ntype LoadingProps = NativeProps & {\n /**\n * The size of the loading spinner.\n * @default 'small'\n */\n size?: Size\n /**\n * A escape hatch in case you need to provide a custom class name to the container element.\n */\n exceptionallySetClassName?: string\n /** Identifies the element (or elements) that describes the loading component for assistive technologies. */\n 'aria-describedby'?: string\n} & (\n | {\n /** Defines a string value that labels the current loading component for assistive technologies. */\n 'aria-label': string\n 'aria-labelledby'?: never\n }\n | {\n /** Identifies the element (or elements) that labels the current loading component for assistive technologies. */\n 'aria-labelledby': string\n 'aria-label'?: never\n }\n )\n\nconst sizeMapping: Record<Size, number> = {\n xsmall: 16,\n small: 24,\n medium: 36,\n large: 48,\n}\n\nfunction Loading({ size = 'small', exceptionallySetClassName, ...props }: LoadingProps) {\n const numericSize = sizeMapping[size] ?? sizeMapping.small\n const ariaLabel = props['aria-label']\n ? props['aria-label']\n : !props['aria-labelledby']\n ? 'Loading…'\n : undefined\n\n return (\n <Box\n {...props}\n aria-label={ariaLabel}\n className={exceptionallySetClassName}\n display=\"flex\"\n alignItems=\"center\"\n justifyContent=\"center\"\n role=\"progressbar\"\n >\n <Spinner size={numericSize} aria-hidden />\n </Box>\n )\n}\n\nexport { Loading }\nexport type { LoadingProps }\n"],"names":["sizeMapping","xsmall","small","medium","large","Loading","size","exceptionallySetClassName","props","numericSize","ariaLabel","undefined","React","Box","className","display","alignItems","justifyContent","role","Spinner"],"mappings":";;;;;;AAoCA,MAAMA,WAAW,GAAyB;EACtCC,MAAM,EAAE,EAD8B;EAEtCC,KAAK,EAAE,EAF+B;EAGtCC,MAAM,EAAE,EAH8B;EAItCC,KAAK,EAAE;AAJ+B,CAA1C;;AAOA,SAASC,OAAT;;;MAAiB;IAAEC,IAAI,GAAG,OAAT;IAAkBC;;MAA8BC;;EAC7D,MAAMC,WAAW,wBAAGT,WAAW,CAACM,IAAD,CAAd,gCAAwBN,WAAW,CAACE,KAArD;EACA,MAAMQ,SAAS,GAAGF,KAAK,CAAC,YAAD,CAAL,GACZA,KAAK,CAAC,YAAD,CADO,GAEZ,CAACA,KAAK,CAAC,iBAAD,CAAN,GACA,UADA,GAEAG,SAJN;EAMA,oBACIC,aAAA,CAACC,GAAD,oCACQL,KADR;kBAEgBE,SAFhB;IAGII,SAAS,EAAEP,yBAHf;IAIIQ,OAAO,EAAC,MAJZ;IAKIC,UAAU,EAAC,QALf;IAMIC,cAAc,EAAC,QANnB;IAOIC,IAAI,EAAC;mBAELN,aAAA,CAACO,OAAD;IAASb,IAAI,EAAEG;;GAAf,CATJ,CADJ;AAaH;;;;"}
1
+ {"version":3,"file":"loading.js","sources":["../../src/loading/loading.tsx"],"sourcesContent":["import * as React from 'react'\nimport { Box } from '../box'\nimport { Spinner } from '../spinner'\nimport type { ObfuscatedClassName } from '../utils/common-types'\n\ntype Size = 'xsmall' | 'small' | 'medium' | 'large'\n\ntype NativeProps = Omit<\n React.HTMLAttributes<HTMLDivElement>,\n 'className' | 'aria-describedby' | 'aria-label' | 'aria-labelledby' | 'role' | 'size'\n>\n\ntype LoadingProps = NativeProps &\n ObfuscatedClassName & {\n /**\n * The size of the loading spinner.\n * @default 'small'\n */\n size?: Size\n\n /**\n * Identifies the element (or elements) that describes the loading component for assistive technologies.\n */\n 'aria-describedby'?: string\n } & (\n | {\n /** Defines a string value that labels the current loading component for assistive technologies. */\n 'aria-label': string\n 'aria-labelledby'?: never\n }\n | {\n /** Identifies the element (or elements) that labels the current loading component for assistive technologies. */\n 'aria-labelledby': string\n 'aria-label'?: never\n }\n )\n\nconst sizeMapping: Record<Size, number> = {\n xsmall: 16,\n small: 24,\n medium: 36,\n large: 48,\n}\n\nfunction Loading({ size = 'small', exceptionallySetClassName, ...props }: LoadingProps) {\n const numericSize = sizeMapping[size] ?? sizeMapping.small\n const ariaLabel = props['aria-label']\n ? props['aria-label']\n : !props['aria-labelledby']\n ? 'Loading…'\n : undefined\n\n return (\n <Box\n {...props}\n aria-label={ariaLabel}\n className={exceptionallySetClassName}\n display=\"flex\"\n alignItems=\"center\"\n justifyContent=\"center\"\n role=\"progressbar\"\n >\n <Spinner size={numericSize} aria-hidden />\n </Box>\n )\n}\n\nexport { Loading }\nexport type { LoadingProps }\n"],"names":["sizeMapping","xsmall","small","medium","large","Loading","size","exceptionallySetClassName","props","numericSize","ariaLabel","undefined","React","Box","className","display","alignItems","justifyContent","role","Spinner"],"mappings":";;;;;;AAqCA,MAAMA,WAAW,GAAyB;EACtCC,MAAM,EAAE,EAD8B;EAEtCC,KAAK,EAAE,EAF+B;EAGtCC,MAAM,EAAE,EAH8B;EAItCC,KAAK,EAAE;AAJ+B,CAA1C;;AAOA,SAASC,OAAT;;;MAAiB;IAAEC,IAAI,GAAG,OAAT;IAAkBC;;MAA8BC;;EAC7D,MAAMC,WAAW,wBAAGT,WAAW,CAACM,IAAD,CAAd,gCAAwBN,WAAW,CAACE,KAArD;EACA,MAAMQ,SAAS,GAAGF,KAAK,CAAC,YAAD,CAAL,GACZA,KAAK,CAAC,YAAD,CADO,GAEZ,CAACA,KAAK,CAAC,iBAAD,CAAN,GACA,UADA,GAEAG,SAJN;EAMA,oBACIC,aAAA,CAACC,GAAD,oCACQL,KADR;kBAEgBE,SAFhB;IAGII,SAAS,EAAEP,yBAHf;IAIIQ,OAAO,EAAC,MAJZ;IAKIC,UAAU,EAAC,QALf;IAMIC,cAAc,EAAC,QANnB;IAOIC,IAAI,EAAC;mBAELN,aAAA,CAACO,OAAD;IAASb,IAAI,EAAEG;;GAAf,CATJ,CADJ;AAaH;;;;"}
package/es/menu/menu.js CHANGED
@@ -1,21 +1,20 @@
1
1
  import { objectWithoutProperties as _objectWithoutProperties, objectSpread2 as _objectSpread2 } from '../_virtual/_rollupPluginBabelHelpers.js';
2
- import { useState, useMemo, createElement, useContext, useCallback, useEffect, forwardRef, Children, cloneElement, createContext } from 'react';
2
+ import { useState, useMemo, createElement, forwardRef, useContext, useCallback, useEffect, Children, createContext } from 'react';
3
3
  import classNames from 'classnames';
4
- import { polymorphicComponent } from '../utils/polymorphism.js';
5
- import { useMenuStore, MenuButton as MenuButton$1, Portal, Menu as Menu$1, MenuItem as MenuItem$1, MenuGroup as MenuGroup$1 } from '@ariakit/react';
4
+ import { useMenuStore, MenuButton as MenuButton$1, Role, Portal, Menu as Menu$1, MenuItem as MenuItem$1, MenuGroup as MenuGroup$1 } from '@ariakit/react';
6
5
 
7
6
  const _excluded = ["children", "onItemSelect"],
8
7
  _excluded2 = ["exceptionallySetClassName"],
9
- _excluded3 = ["as"],
8
+ _excluded3 = ["render"],
10
9
  _excluded4 = ["exceptionallySetClassName", "modal"],
11
- _excluded5 = ["value", "children", "onSelect", "hideOnSelect", "onClick", "exceptionallySetClassName", "as"],
10
+ _excluded5 = ["value", "children", "onSelect", "hideOnSelect", "onClick", "exceptionallySetClassName"],
12
11
  _excluded6 = ["label", "children", "exceptionallySetClassName"];
13
- const MenuContext = /*#__PURE__*/createContext( // Ariakit gives us no means to obtain a valid initial/default value of type MenuStateReturn
14
- // (it is normally obtained by calling useMenuState but we can't call hooks outside components).
15
- // This is however of little consequence since this value is only used if some of the components
16
- // are used outside Menu, something that should not happen and we do not support.
17
- // @ts-expect-error
18
- {});
12
+ const MenuContext = /*#__PURE__*/createContext({
13
+ menuStore: null,
14
+ handleItemSelect: () => undefined,
15
+ getAnchorRect: null,
16
+ setAnchorRect: () => undefined
17
+ });
19
18
  /**
20
19
  * Wrapper component to control a menu. It does not render anything, only providing the state
21
20
  * management for the menu components inside it.
@@ -48,7 +47,7 @@ function Menu(_ref) {
48
47
  */
49
48
 
50
49
 
51
- const MenuButton = /*#__PURE__*/polymorphicComponent(function MenuButton(_ref2, ref) {
50
+ const MenuButton = /*#__PURE__*/forwardRef(function MenuButton(_ref2, ref) {
52
51
  let {
53
52
  exceptionallySetClassName
54
53
  } = _ref2,
@@ -57,18 +56,20 @@ const MenuButton = /*#__PURE__*/polymorphicComponent(function MenuButton(_ref2,
57
56
  const {
58
57
  menuStore
59
58
  } = useContext(MenuContext);
59
+
60
+ if (!menuStore) {
61
+ throw new Error('MenuButton must be wrapped in <Menu/>');
62
+ }
63
+
60
64
  return /*#__PURE__*/createElement(MenuButton$1, _objectSpread2(_objectSpread2({}, props), {}, {
61
65
  store: menuStore,
62
66
  ref: ref,
63
67
  className: classNames('reactist_menubutton', exceptionallySetClassName)
64
68
  }));
65
- }); //
66
- // ContextMenuTrigger
67
- //
68
-
69
- const ContextMenuTrigger = /*#__PURE__*/polymorphicComponent(function ContextMenuTrigger(_ref3, ref) {
69
+ });
70
+ const ContextMenuTrigger = /*#__PURE__*/forwardRef(function ContextMenuTrigger(_ref3, ref) {
70
71
  let {
71
- as: component = 'div'
72
+ render
72
73
  } = _ref3,
73
74
  props = _objectWithoutProperties(_ref3, _excluded3);
74
75
 
@@ -76,6 +77,11 @@ const ContextMenuTrigger = /*#__PURE__*/polymorphicComponent(function ContextMen
76
77
  setAnchorRect,
77
78
  menuStore
78
79
  } = useContext(MenuContext);
80
+
81
+ if (!menuStore) {
82
+ throw new Error('ContextMenuTrigger must be wrapped in <Menu/>');
83
+ }
84
+
79
85
  const handleContextMenu = useCallback(function handleContextMenu(event) {
80
86
  event.preventDefault();
81
87
  setAnchorRect({
@@ -88,16 +94,17 @@ const ContextMenuTrigger = /*#__PURE__*/polymorphicComponent(function ContextMen
88
94
  useEffect(() => {
89
95
  if (!isOpen) setAnchorRect(null);
90
96
  }, [isOpen, setAnchorRect]);
91
- return /*#__PURE__*/createElement(component, _objectSpread2(_objectSpread2({}, props), {}, {
97
+ return /*#__PURE__*/createElement(Role.div, _objectSpread2(_objectSpread2({}, props), {}, {
92
98
  onContextMenu: handleContextMenu,
93
- ref
99
+ ref: ref,
100
+ render: render
94
101
  }));
95
102
  });
96
103
  /**
97
104
  * The dropdown menu itself, containing a list of menu items.
98
105
  */
99
106
 
100
- const MenuList = /*#__PURE__*/polymorphicComponent(function MenuList(_ref4, ref) {
107
+ const MenuList = /*#__PURE__*/forwardRef(function MenuList(_ref4, ref) {
101
108
  let {
102
109
  exceptionallySetClassName,
103
110
  modal = true
@@ -108,6 +115,11 @@ const MenuList = /*#__PURE__*/polymorphicComponent(function MenuList(_ref4, ref)
108
115
  menuStore,
109
116
  getAnchorRect
110
117
  } = useContext(MenuContext);
118
+
119
+ if (!menuStore) {
120
+ throw new Error('MenuList must be wrapped in <Menu/>');
121
+ }
122
+
111
123
  const isOpen = menuStore.useState('open');
112
124
  return isOpen ? /*#__PURE__*/createElement(Portal, {
113
125
  preserveTabOrder: true
@@ -126,15 +138,14 @@ const MenuList = /*#__PURE__*/polymorphicComponent(function MenuList(_ref4, ref)
126
138
  * callback.
127
139
  */
128
140
 
129
- const MenuItem = /*#__PURE__*/polymorphicComponent(function MenuItem(_ref5, ref) {
141
+ const MenuItem = /*#__PURE__*/forwardRef(function MenuItem(_ref5, ref) {
130
142
  let {
131
143
  value,
132
144
  children,
133
145
  onSelect,
134
146
  hideOnSelect = true,
135
147
  onClick,
136
- exceptionallySetClassName,
137
- as = 'button'
148
+ exceptionallySetClassName
138
149
  } = _ref5,
139
150
  props = _objectWithoutProperties(_ref5, _excluded5);
140
151
 
@@ -142,6 +153,11 @@ const MenuItem = /*#__PURE__*/polymorphicComponent(function MenuItem(_ref5, ref)
142
153
  handleItemSelect,
143
154
  menuStore
144
155
  } = useContext(MenuContext);
156
+
157
+ if (!menuStore) {
158
+ throw new Error('MenuItem must be wrapped in <Menu/>');
159
+ }
160
+
145
161
  const {
146
162
  hide
147
163
  } = menuStore;
@@ -153,7 +169,6 @@ const MenuItem = /*#__PURE__*/polymorphicComponent(function MenuItem(_ref5, ref)
153
169
  if (shouldClose) hide();
154
170
  }, [onSelect, onClick, handleItemSelect, hideOnSelect, hide, value]);
155
171
  return /*#__PURE__*/createElement(MenuItem$1, _objectSpread2(_objectSpread2({}, props), {}, {
156
- as: as,
157
172
  store: menuStore,
158
173
  ref: ref,
159
174
  onClick: handleClick,
@@ -191,6 +206,11 @@ const SubMenu = /*#__PURE__*/forwardRef(function SubMenu({
191
206
  handleItemSelect: parentMenuItemSelect,
192
207
  menuStore
193
208
  } = useContext(MenuContext);
209
+
210
+ if (!menuStore) {
211
+ throw new Error('SubMenu must be wrapped in <Menu/>');
212
+ }
213
+
194
214
  const {
195
215
  hide: parentMenuHide
196
216
  } = menuStore;
@@ -199,19 +219,16 @@ const SubMenu = /*#__PURE__*/forwardRef(function SubMenu({
199
219
  parentMenuItemSelect == null ? void 0 : parentMenuItemSelect(value);
200
220
  parentMenuHide();
201
221
  }, [parentMenuHide, parentMenuItemSelect, onItemSelect]);
202
- const [button, list] = Children.toArray(children); // Ariakit needs to be able to pass props to the MenuButton and combine it with the MenuItem component
203
-
204
- const renderMenuButton = useCallback(function renderMenuButton(props) {
205
- return /*#__PURE__*/cloneElement(button, props);
206
- }, [button]);
222
+ const [button, list] = Children.toArray(children);
223
+ const buttonElement = button;
207
224
  return /*#__PURE__*/createElement(Menu, {
208
225
  onItemSelect: handleSubItemSelect
209
226
  }, /*#__PURE__*/createElement(MenuItem$1, {
210
- as: "div",
211
227
  store: menuStore,
212
228
  ref: ref,
213
- hideOnClick: false
214
- }, renderMenuButton), list);
229
+ hideOnClick: false,
230
+ render: buttonElement
231
+ }, buttonElement.props.children), list);
215
232
  });
216
233
  /**
217
234
  * A way to semantically group some menu items.
@@ -220,7 +237,7 @@ const SubMenu = /*#__PURE__*/forwardRef(function SubMenu({
220
237
  * before and/or after the group if you so wish.
221
238
  */
222
239
 
223
- const MenuGroup = /*#__PURE__*/polymorphicComponent(function MenuGroup(_ref6, ref) {
240
+ const MenuGroup = /*#__PURE__*/forwardRef(function MenuGroup(_ref6, ref) {
224
241
  let {
225
242
  label,
226
243
  children,
@@ -231,6 +248,11 @@ const MenuGroup = /*#__PURE__*/polymorphicComponent(function MenuGroup(_ref6, re
231
248
  const {
232
249
  menuStore
233
250
  } = useContext(MenuContext);
251
+
252
+ if (!menuStore) {
253
+ throw new Error('MenuGroup must be wrapped in <Menu/>');
254
+ }
255
+
234
256
  return /*#__PURE__*/createElement(MenuGroup$1, _objectSpread2(_objectSpread2({}, props), {}, {
235
257
  ref: ref,
236
258
  store: menuStore,
@@ -1 +1 @@
1
- {"version":3,"file":"menu.js","sources":["../../src/menu/menu.tsx"],"sourcesContent":["import * as React from 'react'\nimport classNames from 'classnames'\n\nimport { polymorphicComponent } from '../utils/polymorphism'\n\n//\n// Reactist menu is a thin wrapper around Ariakit's menu components. This may or may not be\n// temporary. Our goal is to make it transparent for the users of Reactist of this implementation\n// detail. We may change in the future the external lib we use, or even implement it all internally,\n// as long as we keep the same outer interface as intact as possible.\n//\n// Around the heavy lifting of the external lib we just add some features to better integrate the\n// menu to Reactist's more opinionated approach (e.g. using our button with its custom variants and\n// other features, easily show keyboard shortcuts in menu items, etc.)\n//\nimport {\n Portal,\n MenuStore,\n MenuStoreProps,\n useMenuStore,\n MenuProps as AriakitMenuProps,\n Menu as AriakitMenu,\n MenuGroup as AriakitMenuGroup,\n MenuItem as AriakitMenuItem,\n MenuButton as AriakitMenuButton,\n MenuButtonProps as AriakitMenuButtonProps,\n} from '@ariakit/react'\n\nimport './menu.less'\n\ntype NativeProps<E extends HTMLElement> = React.DetailedHTMLProps<React.HTMLAttributes<E>, E>\n\ntype MenuContextState = {\n menuStore: MenuStore\n handleItemSelect?: (value: string | null | undefined) => void\n getAnchorRect: (() => { x: number; y: number }) | null\n setAnchorRect: (rect: { x: number; y: number } | null) => void\n}\n\nconst MenuContext = React.createContext<MenuContextState>(\n // Ariakit gives us no means to obtain a valid initial/default value of type MenuStateReturn\n // (it is normally obtained by calling useMenuState but we can't call hooks outside components).\n // This is however of little consequence since this value is only used if some of the components\n // are used outside Menu, something that should not happen and we do not support.\n // @ts-expect-error\n {},\n)\n\n//\n// Menu\n//\n\ntype MenuProps = Omit<MenuStoreProps, 'visible'> & {\n /**\n * The `Menu` must contain a `MenuList` that defines the menu options. It must also contain a\n * `MenuButton` that triggers the menu to be opened or closed.\n */\n children: React.ReactNode\n\n /**\n * An optional callback that will be called back whenever a menu item is selected. It receives\n * the `value` of the selected `MenuItem`.\n *\n * If you pass down this callback, it is recommended that you properly memoize it so it does not\n * change on every render.\n */\n onItemSelect?: (value: string | null | undefined) => void\n}\n\n/**\n * Wrapper component to control a menu. It does not render anything, only providing the state\n * management for the menu components inside it.\n */\nfunction Menu({ children, onItemSelect, ...props }: MenuProps) {\n const [anchorRect, setAnchorRect] = React.useState<{ x: number; y: number } | null>(null)\n const getAnchorRect = React.useMemo(() => (anchorRect ? () => anchorRect : null), [anchorRect])\n const menuStore = useMenuStore({ focusLoop: true, ...props })\n\n const value: MenuContextState = React.useMemo(\n () => ({ menuStore, handleItemSelect: onItemSelect, getAnchorRect, setAnchorRect }),\n [menuStore, onItemSelect, getAnchorRect, setAnchorRect],\n )\n\n return <MenuContext.Provider value={value}>{children}</MenuContext.Provider>\n}\n\n//\n// MenuButton\n//\n\ntype MenuButtonProps = Omit<AriakitMenuButtonProps, 'store' | 'className' | 'as'>\n\n/**\n * A button to toggle a dropdown menu open or closed.\n */\nconst MenuButton = polymorphicComponent<'button', MenuButtonProps>(function MenuButton(\n { exceptionallySetClassName, ...props },\n ref,\n) {\n const { menuStore } = React.useContext(MenuContext)\n return (\n <AriakitMenuButton\n {...props}\n store={menuStore}\n ref={ref}\n className={classNames('reactist_menubutton', exceptionallySetClassName)}\n />\n )\n})\n\n//\n// ContextMenuTrigger\n//\nconst ContextMenuTrigger = polymorphicComponent<'div', unknown>(function ContextMenuTrigger(\n { as: component = 'div', ...props },\n ref,\n) {\n const { setAnchorRect, menuStore } = React.useContext(MenuContext)\n\n const handleContextMenu = React.useCallback(\n function handleContextMenu(event: React.MouseEvent) {\n event.preventDefault()\n setAnchorRect({ x: event.clientX, y: event.clientY })\n menuStore.show()\n },\n [setAnchorRect, menuStore],\n )\n\n const isOpen = menuStore.useState('open')\n React.useEffect(() => {\n if (!isOpen) setAnchorRect(null)\n }, [isOpen, setAnchorRect])\n\n return React.createElement(component, { ...props, onContextMenu: handleContextMenu, ref })\n})\n\n//\n// MenuList\n//\n\ntype MenuListProps = Omit<AriakitMenuProps, 'store' | 'className'>\n\n/**\n * The dropdown menu itself, containing a list of menu items.\n */\nconst MenuList = polymorphicComponent<'div', MenuListProps>(function MenuList(\n { exceptionallySetClassName, modal = true, ...props },\n ref,\n) {\n const { menuStore, getAnchorRect } = React.useContext(MenuContext)\n const isOpen = menuStore.useState('open')\n\n return isOpen ? (\n <Portal preserveTabOrder>\n <AriakitMenu\n {...props}\n store={menuStore}\n gutter={8}\n shift={4}\n ref={ref}\n className={classNames('reactist_menulist', exceptionallySetClassName)}\n getAnchorRect={getAnchorRect ?? undefined}\n modal={modal}\n />\n </Portal>\n ) : null\n})\n\n//\n// MenuItem\n//\n\ntype MenuItemProps = {\n /**\n * An optional value given to this menu item. It is passed on to the parent `Menu`'s\n * `onItemSelect` when you provide that instead of (or alongside) providing individual\n * `onSelect` callbacks to each menu item.\n */\n value?: string\n\n /**\n * The content inside the menu item.\n */\n children: React.ReactNode\n\n /**\n * When `true` the menu item is disabled and won't be selectable or be part of the keyboard\n * navigation across the menu options.\n *\n * @default true\n */\n disabled?: boolean\n\n /**\n * When `true` the menu will close when the menu item is selected, in addition to performing the\n * action that the menu item is set out to do.\n *\n * Set this to `false` to make sure that a given menu item does not auto-closes the menu when\n * selected. This should be the exception and not the norm, as the default is to auto-close.\n *\n * @default true\n */\n hideOnSelect?: boolean\n\n /**\n * The action to perform when the menu item is selected.\n *\n * If you return `false` from this function, the menu will not auto-close when this menu item\n * is selected. Though you should use `hideOnSelect` for this purpose, this allows you to\n * achieve the same effect conditionally and dynamically deciding at run time.\n */\n onSelect?: () => unknown\n\n /**\n * The event handler called when the menu item is clicked.\n *\n * This is similar to `onSelect`, but a bit different. You can certainly use it to trigger the\n * action that the menu item represents. But in general you should prefer `onSelect` for that.\n *\n * The main use for this handler is to get access to the click event. This can be used, for\n * example, to call `event.preventDefault()`, which will effectively prevent the rest of the\n * consequences of the click, including preventing `onSelect` from being called. In particular,\n * this is useful in menu items that are links, and you want the click to not trigger navigation\n * under some circumstances.\n */\n onClick?: (event: React.MouseEvent) => void\n}\n\n/**\n * A menu item inside a menu list. It can be selected by the user, triggering the `onSelect`\n * callback.\n */\nconst MenuItem = polymorphicComponent<'button', MenuItemProps>(function MenuItem(\n {\n value,\n children,\n onSelect,\n hideOnSelect = true,\n onClick,\n exceptionallySetClassName,\n as = 'button',\n ...props\n },\n ref,\n) {\n const { handleItemSelect, menuStore } = React.useContext(MenuContext)\n const { hide } = menuStore\n\n const handleClick = React.useCallback(\n function handleClick(event: React.MouseEvent<HTMLButtonElement>) {\n onClick?.(event)\n const onSelectResult: unknown =\n onSelect && !event.defaultPrevented ? onSelect() : undefined\n const shouldClose = onSelectResult !== false && hideOnSelect\n handleItemSelect?.(value)\n if (shouldClose) hide()\n },\n [onSelect, onClick, handleItemSelect, hideOnSelect, hide, value],\n )\n\n return (\n <AriakitMenuItem\n {...props}\n as={as}\n store={menuStore}\n ref={ref}\n onClick={handleClick}\n className={exceptionallySetClassName}\n hideOnClick={false}\n >\n {children}\n </AriakitMenuItem>\n )\n})\n\n//\n// SubMenu\n//\n\ntype SubMenuProps = Pick<MenuProps, 'children' | 'onItemSelect'>\n\n/**\n * This component can be rendered alongside other `MenuItem` inside a `MenuList` in order to have\n * a sub-menu.\n *\n * Its children are expected to have the structure of a first level menu (a `MenuButton` and a\n * `MenuList`).\n *\n * ```jsx\n * <MenuItem label=\"Edit profile\" />\n * <SubMenu>\n * <MenuButton>More options</MenuButton>\n * <MenuList>\n * <MenuItem label=\"Preferences\" />\n * <MenuItem label=\"Sign out\" />\n * </MenuList>\n * </SubMenu>\n * ```\n *\n * The `MenuButton` will become a menu item in the current menu items list, and it will lead to\n * opening a sub-menu with the menu items list below it.\n */\nconst SubMenu = React.forwardRef<HTMLDivElement, SubMenuProps>(function SubMenu(\n { children, onItemSelect },\n ref,\n) {\n const { handleItemSelect: parentMenuItemSelect, menuStore } = React.useContext(MenuContext)\n const { hide: parentMenuHide } = menuStore\n\n const handleSubItemSelect = React.useCallback(\n function handleSubItemSelect(value: string | null | undefined) {\n onItemSelect?.(value)\n parentMenuItemSelect?.(value)\n parentMenuHide()\n },\n [parentMenuHide, parentMenuItemSelect, onItemSelect],\n )\n\n const [button, list] = React.Children.toArray(children)\n\n // Ariakit needs to be able to pass props to the MenuButton and combine it with the MenuItem component\n const renderMenuButton = React.useCallback(\n function renderMenuButton(props: MenuButtonProps) {\n return React.cloneElement(button as React.ReactElement, props)\n },\n [button],\n )\n\n return (\n <Menu onItemSelect={handleSubItemSelect}>\n <AriakitMenuItem as=\"div\" store={menuStore} ref={ref} hideOnClick={false}>\n {renderMenuButton}\n </AriakitMenuItem>\n {list}\n </Menu>\n )\n})\n\n//\n// MenuGroup\n//\n\ntype MenuGroupProps = Omit<NativeProps<HTMLDivElement>, 'className'> & {\n /**\n * A label to be shown visually and also used to semantically label the group.\n */\n label: string\n}\n\n/**\n * A way to semantically group some menu items.\n *\n * This group does not add any visual separator. You can do that yourself adding `<hr />` elements\n * before and/or after the group if you so wish.\n */\nconst MenuGroup = polymorphicComponent<'div', MenuGroupProps>(function MenuGroup(\n { label, children, exceptionallySetClassName, ...props },\n ref,\n) {\n const { menuStore } = React.useContext(MenuContext)\n return (\n <AriakitMenuGroup\n {...props}\n ref={ref}\n store={menuStore}\n className={exceptionallySetClassName}\n >\n {label ? (\n <div role=\"presentation\" className=\"reactist_menugroup__label\">\n {label}\n </div>\n ) : null}\n {children}\n </AriakitMenuGroup>\n )\n})\n\nexport { ContextMenuTrigger, Menu, MenuButton, MenuList, MenuItem, SubMenu, MenuGroup }\nexport type { MenuButtonProps, MenuListProps, MenuItemProps, MenuGroupProps }\n"],"names":["MenuContext","React","Menu","children","onItemSelect","props","anchorRect","setAnchorRect","getAnchorRect","menuStore","useMenuStore","focusLoop","value","handleItemSelect","Provider","MenuButton","polymorphicComponent","ref","exceptionallySetClassName","AriakitMenuButton","store","className","classNames","ContextMenuTrigger","as","component","handleContextMenu","event","preventDefault","x","clientX","y","clientY","show","isOpen","useState","onContextMenu","MenuList","modal","Portal","preserveTabOrder","AriakitMenu","gutter","shift","undefined","MenuItem","onSelect","hideOnSelect","onClick","hide","handleClick","onSelectResult","defaultPrevented","shouldClose","AriakitMenuItem","hideOnClick","SubMenu","parentMenuItemSelect","parentMenuHide","handleSubItemSelect","button","list","toArray","renderMenuButton","MenuGroup","label","AriakitMenuGroup","role"],"mappings":";;;;;;;;;;;;AAuCA,MAAMA,WAAW,gBAAGC,aAAA;AAEhB;AACA;AACA;AACA;AACA,EANgB,CAApB;AA8BA;;;;;AAIA,SAASC,IAAT;MAAc;IAAEC,QAAF;IAAYC;;MAAiBC;;EACvC,MAAM,CAACC,UAAD,EAAaC,aAAb,IAA8BN,QAAA,CAAgD,IAAhD,CAApC;EACA,MAAMO,aAAa,GAAGP,OAAA,CAAc,MAAOK,UAAU,GAAG,MAAMA,UAAT,GAAsB,IAArD,EAA4D,CAACA,UAAD,CAA5D,CAAtB;EACA,MAAMG,SAAS,GAAGC,YAAY;IAAGC,SAAS,EAAE;KAASN,KAAvB,EAA9B;EAEA,MAAMO,KAAK,GAAqBX,OAAA,CAC5B,OAAO;IAAEQ,SAAF;IAAaI,gBAAgB,EAAET,YAA/B;IAA6CI,aAA7C;IAA4DD;GAAnE,CAD4B,EAE5B,CAACE,SAAD,EAAYL,YAAZ,EAA0BI,aAA1B,EAAyCD,aAAzC,CAF4B,CAAhC;EAKA,oBAAON,aAAA,CAACD,WAAW,CAACc,QAAb;IAAsBF,KAAK,EAAEA;GAA7B,EAAqCT,QAArC,CAAP;AACH;AAQD;;;;;MAGMY,UAAU,gBAAGC,oBAAoB,CAA4B,SAASD,UAAT,QAE/DE,GAF+D;MAC/D;IAAEC;;MAA8Bb;;EAGhC,MAAM;IAAEI;MAAcR,UAAA,CAAiBD,WAAjB,CAAtB;EACA,oBACIC,aAAA,CAACkB,YAAD,oCACQd,KADR;IAEIe,KAAK,EAAEX,SAFX;IAGIQ,GAAG,EAAEA,GAHT;IAIII,SAAS,EAAEC,UAAU,CAAC,qBAAD,EAAwBJ,yBAAxB;KAL7B;AAQH,CAbsC;AAgBv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MAA8Bb;;EAGjD,MAAM;IAAEI;MAAcR,UAAA,CAAiBD,WAAjB,CAAtB;EACA,oBACIC,aAAA,CAACiE,WAAD,oCACQ7D,KADR;IAEIY,GAAG,EAAEA,GAFT;IAGIG,KAAK,EAAEX,SAHX;IAIIY,SAAS,EAAEH;MAEV+C,KAAK,gBACFhE,aAAA,MAAA;IAAKkE,IAAI,EAAC;IAAe9C,SAAS,EAAC;GAAnC,EACK4C,KADL,CADE,GAIF,IAVR,EAWK9D,QAXL,CADJ;AAeH,CApBqC;;;;"}
1
+ {"version":3,"file":"menu.js","sources":["../../src/menu/menu.tsx"],"sourcesContent":["import * as React from 'react'\nimport classNames from 'classnames'\n\nimport {\n Portal,\n MenuStore,\n MenuStoreProps,\n useMenuStore,\n MenuProps as AriakitMenuProps,\n Menu as AriakitMenu,\n MenuGroup as AriakitMenuGroup,\n MenuItem as AriakitMenuItem,\n MenuItemProps as AriakitMenuItemProps,\n MenuButton as AriakitMenuButton,\n MenuButtonProps as AriakitMenuButtonProps,\n Role,\n RoleProps,\n} from '@ariakit/react'\n\nimport './menu.less'\nimport type { ObfuscatedClassName } from '../utils/common-types'\n\ntype MenuContextState = {\n menuStore: MenuStore | null\n handleItemSelect?: (value: string | null | undefined) => void\n getAnchorRect: (() => { x: number; y: number }) | null\n setAnchorRect: (rect: { x: number; y: number } | null) => void\n}\n\nconst MenuContext = React.createContext<MenuContextState>({\n menuStore: null,\n handleItemSelect: () => undefined,\n getAnchorRect: null,\n setAnchorRect: () => undefined,\n})\n\n//\n// Menu\n//\n\ninterface MenuProps extends Omit<MenuStoreProps, 'visible'> {\n /**\n * The `Menu` must contain a `MenuList` that defines the menu options. It must also contain a\n * `MenuButton` that triggers the menu to be opened or closed.\n */\n children: React.ReactNode\n\n /**\n * An optional callback that will be called back whenever a menu item is selected. It receives\n * the `value` of the selected `MenuItem`.\n *\n * If you pass down this callback, it is recommended that you properly memoize it so it does not\n * change on every render.\n */\n onItemSelect?: (value: string | null | undefined) => void\n}\n\n/**\n * Wrapper component to control a menu. It does not render anything, only providing the state\n * management for the menu components inside it.\n */\nfunction Menu({ children, onItemSelect, ...props }: MenuProps) {\n const [anchorRect, setAnchorRect] = React.useState<{ x: number; y: number } | null>(null)\n const getAnchorRect = React.useMemo(() => (anchorRect ? () => anchorRect : null), [anchorRect])\n const menuStore = useMenuStore({ focusLoop: true, ...props })\n\n const value: MenuContextState = React.useMemo(\n () => ({ menuStore, handleItemSelect: onItemSelect, getAnchorRect, setAnchorRect }),\n [menuStore, onItemSelect, getAnchorRect, setAnchorRect],\n )\n\n return <MenuContext.Provider value={value}>{children}</MenuContext.Provider>\n}\n\n//\n// MenuButton\n//\n\ninterface MenuButtonProps\n extends Omit<AriakitMenuButtonProps, 'store' | 'className' | 'as'>,\n ObfuscatedClassName {}\n\n/**\n * A button to toggle a dropdown menu open or closed.\n */\nconst MenuButton = React.forwardRef<HTMLButtonElement, MenuButtonProps>(function MenuButton(\n { exceptionallySetClassName, ...props },\n ref,\n) {\n const { menuStore } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('MenuButton must be wrapped in <Menu/>')\n }\n return (\n <AriakitMenuButton\n {...props}\n store={menuStore}\n ref={ref}\n className={classNames('reactist_menubutton', exceptionallySetClassName)}\n />\n )\n})\n\n//\n// ContextMenuTrigger\n//\n\ninterface ContextMenuTriggerProps\n extends ObfuscatedClassName,\n React.HTMLAttributes<HTMLDivElement>,\n Pick<RoleProps, 'render'> {}\n\nconst ContextMenuTrigger = React.forwardRef<HTMLDivElement, ContextMenuTriggerProps>(\n function ContextMenuTrigger({ render, ...props }, ref) {\n const { setAnchorRect, menuStore } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('ContextMenuTrigger must be wrapped in <Menu/>')\n }\n\n const handleContextMenu = React.useCallback(\n function handleContextMenu(event: React.MouseEvent) {\n event.preventDefault()\n setAnchorRect({ x: event.clientX, y: event.clientY })\n menuStore.show()\n },\n [setAnchorRect, menuStore],\n )\n\n const isOpen = menuStore.useState('open')\n React.useEffect(() => {\n if (!isOpen) setAnchorRect(null)\n }, [isOpen, setAnchorRect])\n\n return <Role.div {...props} onContextMenu={handleContextMenu} ref={ref} render={render} />\n },\n)\n\n//\n// MenuList\n//\n\ninterface MenuListProps\n extends Omit<AriakitMenuProps, 'store' | 'className'>,\n ObfuscatedClassName {}\n\n/**\n * The dropdown menu itself, containing a list of menu items.\n */\nconst MenuList = React.forwardRef<HTMLDivElement, MenuListProps>(function MenuList(\n { exceptionallySetClassName, modal = true, ...props },\n ref,\n) {\n const { menuStore, getAnchorRect } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('MenuList must be wrapped in <Menu/>')\n }\n\n const isOpen = menuStore.useState('open')\n\n return isOpen ? (\n <Portal preserveTabOrder>\n <AriakitMenu\n {...props}\n store={menuStore}\n gutter={8}\n shift={4}\n ref={ref}\n className={classNames('reactist_menulist', exceptionallySetClassName)}\n getAnchorRect={getAnchorRect ?? undefined}\n modal={modal}\n />\n </Portal>\n ) : null\n})\n\n//\n// MenuItem\n//\n\ninterface MenuItemProps extends AriakitMenuItemProps, ObfuscatedClassName {\n /**\n * An optional value given to this menu item. It is passed on to the parent `Menu`'s\n * `onItemSelect` when you provide that instead of (or alongside) providing individual\n * `onSelect` callbacks to each menu item.\n */\n value?: string\n\n /**\n * When `true` the menu item is disabled and won't be selectable or be part of the keyboard\n * navigation across the menu options.\n *\n * @default true\n */\n disabled?: boolean\n\n /**\n * When `true` the menu will close when the menu item is selected, in addition to performing the\n * action that the menu item is set out to do.\n *\n * Set this to `false` to make sure that a given menu item does not auto-closes the menu when\n * selected. This should be the exception and not the norm, as the default is to auto-close.\n *\n * @default true\n */\n hideOnSelect?: boolean\n\n /**\n * The action to perform when the menu item is selected.\n *\n * If you return `false` from this function, the menu will not auto-close when this menu item\n * is selected. Though you should use `hideOnSelect` for this purpose, this allows you to\n * achieve the same effect conditionally and dynamically deciding at run time.\n */\n onSelect?: () => unknown\n\n /**\n * The event handler called when the menu item is clicked.\n *\n * This is similar to `onSelect`, but a bit different. You can certainly use it to trigger the\n * action that the menu item represents. But in general you should prefer `onSelect` for that.\n *\n * The main use for this handler is to get access to the click event. This can be used, for\n * example, to call `event.preventDefault()`, which will effectively prevent the rest of the\n * consequences of the click, including preventing `onSelect` from being called. In particular,\n * this is useful in menu items that are links, and you want the click to not trigger navigation\n * under some circumstances.\n */\n onClick?: (event: React.MouseEvent) => void\n}\n\n/**\n * A menu item inside a menu list. It can be selected by the user, triggering the `onSelect`\n * callback.\n */\nconst MenuItem = React.forwardRef<HTMLDivElement, MenuItemProps>(function MenuItem(\n {\n value,\n children,\n onSelect,\n hideOnSelect = true,\n onClick,\n exceptionallySetClassName,\n ...props\n },\n ref,\n) {\n const { handleItemSelect, menuStore } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('MenuItem must be wrapped in <Menu/>')\n }\n\n const { hide } = menuStore\n const handleClick = React.useCallback(\n function handleClick(event: React.MouseEvent) {\n onClick?.(event)\n const onSelectResult: unknown =\n onSelect && !event.defaultPrevented ? onSelect() : undefined\n const shouldClose = onSelectResult !== false && hideOnSelect\n handleItemSelect?.(value)\n if (shouldClose) hide()\n },\n [onSelect, onClick, handleItemSelect, hideOnSelect, hide, value],\n )\n\n return (\n <AriakitMenuItem\n {...props}\n store={menuStore}\n ref={ref}\n onClick={handleClick}\n className={exceptionallySetClassName}\n hideOnClick={false}\n >\n {children}\n </AriakitMenuItem>\n )\n})\n\n//\n// SubMenu\n//\n\ntype SubMenuProps = Pick<MenuProps, 'children' | 'onItemSelect'>\n\n/**\n * This component can be rendered alongside other `MenuItem` inside a `MenuList` in order to have\n * a sub-menu.\n *\n * Its children are expected to have the structure of a first level menu (a `MenuButton` and a\n * `MenuList`).\n *\n * ```jsx\n * <MenuItem label=\"Edit profile\" />\n * <SubMenu>\n * <MenuButton>More options</MenuButton>\n * <MenuList>\n * <MenuItem label=\"Preferences\" />\n * <MenuItem label=\"Sign out\" />\n * </MenuList>\n * </SubMenu>\n * ```\n *\n * The `MenuButton` will become a menu item in the current menu items list, and it will lead to\n * opening a sub-menu with the menu items list below it.\n */\nconst SubMenu = React.forwardRef<HTMLDivElement, SubMenuProps>(function SubMenu(\n { children, onItemSelect },\n ref,\n) {\n const { handleItemSelect: parentMenuItemSelect, menuStore } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('SubMenu must be wrapped in <Menu/>')\n }\n\n const { hide: parentMenuHide } = menuStore\n const handleSubItemSelect = React.useCallback(\n function handleSubItemSelect(value: string | null | undefined) {\n onItemSelect?.(value)\n parentMenuItemSelect?.(value)\n parentMenuHide()\n },\n [parentMenuHide, parentMenuItemSelect, onItemSelect],\n )\n\n const [button, list] = React.Children.toArray(children)\n const buttonElement = button as React.ReactElement<MenuButtonProps>\n\n return (\n <Menu onItemSelect={handleSubItemSelect}>\n <AriakitMenuItem store={menuStore} ref={ref} hideOnClick={false} render={buttonElement}>\n {buttonElement.props.children}\n </AriakitMenuItem>\n {list}\n </Menu>\n )\n})\n\n//\n// MenuGroup\n//\n\ninterface MenuGroupProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, 'className'>,\n ObfuscatedClassName {\n /**\n * A label to be shown visually and also used to semantically label the group.\n */\n label: string\n}\n\n/**\n * A way to semantically group some menu items.\n *\n * This group does not add any visual separator. You can do that yourself adding `<hr />` elements\n * before and/or after the group if you so wish.\n */\nconst MenuGroup = React.forwardRef<HTMLDivElement, MenuGroupProps>(function MenuGroup(\n { label, children, exceptionallySetClassName, ...props },\n ref,\n) {\n const { menuStore } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('MenuGroup must be wrapped in <Menu/>')\n }\n\n return (\n <AriakitMenuGroup\n {...props}\n ref={ref}\n store={menuStore}\n className={exceptionallySetClassName}\n >\n {label ? (\n <div role=\"presentation\" className=\"reactist_menugroup__label\">\n {label}\n </div>\n ) : null}\n {children}\n </AriakitMenuGroup>\n )\n})\n\nexport { ContextMenuTrigger, Menu, MenuButton, MenuList, MenuItem, SubMenu, MenuGroup }\nexport type { MenuButtonProps, MenuListProps, MenuItemProps, MenuGroupProps }\n"],"names":["MenuContext","React","menuStore","handleItemSelect","undefined","getAnchorRect","setAnchorRect","Menu","children","onItemSelect","props","anchorRect","useMenuStore","focusLoop","value","Provider","MenuButton","ref","exceptionallySetClassName","Error","AriakitMenuButton","store","className","classNames","ContextMenuTrigger","render","handleContextMenu","event","preventDefault","x","clientX","y","clientY","show","isOpen","useState","Role","div","onContextMenu","MenuList","modal","Portal","preserveTabOrder","AriakitMenu","gutter","shift","MenuItem","onSelect","hideOnSelect","onClick","hide","handleClick","onSelectResult","defaultPrevented","shouldClose","AriakitMenuItem","hideOnClick","SubMenu","parentMenuItemSelect","parentMenuHide","handleSubItemSelect","button","list","toArray","buttonElement","MenuGroup","label","AriakitMenuGroup","role"],"mappings":";;;;;;;;;;;AA6BA,MAAMA,WAAW,gBAAGC,aAAA,CAAsC;EACtDC,SAAS,EAAE,IAD2C;EAEtDC,gBAAgB,EAAE,MAAMC,SAF8B;EAGtDC,aAAa,EAAE,IAHuC;EAItDC,aAAa,EAAE,MAAMF;AAJiC,CAAtC,CAApB;AA4BA;;;;;AAIA,SAASG,IAAT;MAAc;IAAEC,QAAF;IAAYC;;MAAiBC;;EACvC,MAAM,CAACC,UAAD,EAAaL,aAAb,IAA8BL,QAAA,CAAgD,IAAhD,CAApC;EACA,MAAMI,aAAa,GAAGJ,OAAA,CAAc,MAAOU,UAAU,GAAG,MAAMA,UAAT,GAAsB,IAArD,EAA4D,CAACA,UAAD,CAA5D,CAAtB;EACA,MAAMT,SAAS,GAAGU,YAAY;IAAGC,SAAS,EAAE;KAASH,KAAvB,EAA9B;EAEA,MAAMI,KAAK,GAAqBb,OAAA,CAC5B,OAAO;IAAEC,SAAF;IAAaC,gBAAgB,EAAEM,YAA/B;IAA6CJ,aAA7C;IAA4DC;GAAnE,CAD4B,EAE5B,CAACJ,SAAD,EAAYO,YAAZ,EAA0BJ,aAA1B,EAAyCC,aA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,KAA7B;IACIL,YAAY,QAAZ,YAAAA,YAAY,CAAGK,KAAH,CAAZ;IACA4C,oBAAoB,QAApB,YAAAA,oBAAoB,CAAG5C,KAAH,CAApB;IACA6C,cAAc;GAJM,EAMxB,CAACA,cAAD,EAAiBD,oBAAjB,EAAuCjD,YAAvC,CANwB,CAA5B;EASA,MAAM,CAACoD,MAAD,EAASC,IAAT,IAAiB7D,QAAA,CAAe8D,OAAf,CAAuBvD,QAAvB,CAAvB;EACA,MAAMwD,aAAa,GAAGH,MAAtB;EAEA,oBACI5D,aAAA,CAACM,IAAD;IAAME,YAAY,EAAEmD;GAApB,eACI3D,aAAA,CAACsD,UAAD;IAAiBlC,KAAK,EAAEnB;IAAWe,GAAG,EAAEA;IAAKuC,WAAW,EAAE;IAAO/B,MAAM,EAAEuC;GAAzE,EACKA,aAAa,CAACtD,KAAd,CAAoBF,QADzB,CADJ,EAIKsD,IAJL,CADJ;AAQH,CA9Be;AA6ChB;;;;;;;MAMMG,SAAS,gBAAGhE,UAAA,CAAiD,SAASgE,SAAT,QAE/DhD,GAF+D;MAC/D;IAAEiD,KAAF;IAAS1D,QAAT;IAAmBU;;MAA8BR;;EAGjD,MAAM;IAAER;MAAcD,UAAA,CAAiBD,WAAjB,CAAtB;;EACA,IAAI,CAACE,SAAL,EAAgB;IACZ,MAAM,IAAIiB,KAAJ,CAAU,sCAAV,CAAN;;;EAGJ,oBACIlB,aAAA,CAACkE,WAAD,oCACQzD,KADR;IAEIO,GAAG,EAAEA,GAFT;IAGII,KAAK,EAAEnB,SAHX;IAIIoB,SAAS,EAAEJ;MAEVgD,KAAK,gBACFjE,aAAA,MAAA;IAAKmE,IAAI,EAAC;IAAe9C,SAAS,EAAC;GAAnC,EACK4C,KADL,CADE,GAIF,IAVR,EAWK1D,QAXL,CADJ;AAeH,CAxBiB;;;;"}
package/es/modal/modal.js CHANGED
@@ -6,13 +6,13 @@ import { Columns, Column } from '../columns/columns.js';
6
6
  import { Divider } from '../divider/divider.js';
7
7
  import { Inline } from '../inline/inline.js';
8
8
  import { useDialogStore, Portal, Dialog } from '@ariakit/react';
9
- import { Button } from '../button/button.js';
9
+ import { IconButton } from '../button/button.js';
10
10
  import { CloseIcon } from '../icons/close-icon.js';
11
11
  import FocusLock from 'react-focus-lock';
12
12
  import { hideOthers } from 'aria-hidden';
13
13
  import styles from './modal.module.css.js';
14
14
 
15
- const _excluded = ["isOpen", "onDismiss", "height", "width", "exceptionallySetClassName", "exceptionallySetOverlayClassName", "autoFocus", "hideOnEscape", "hideOnInteractOutside", "children", "portalElement", "onKeyDown"],
15
+ const _excluded = ["isOpen", "onDismiss", "height", "width", "exceptionallySetClassName", "exceptionallySetOverlayClassName", "autoFocus", "hideOnEscape", "hideOnInteractOutside", "children", "portalElement", "onKeyDown", "className"],
16
16
  _excluded2 = ["children", "button", "withDivider", "exceptionallySetClassName"],
17
17
  _excluded3 = ["exceptionallySetClassName", "children"],
18
18
  _excluded4 = ["exceptionallySetClassName", "withDivider"],
@@ -49,7 +49,9 @@ function Modal(_ref) {
49
49
  hideOnInteractOutside = true,
50
50
  children,
51
51
  portalElement,
52
- onKeyDown
52
+ onKeyDown,
53
+ // @ts-expect-error we want to make sure to not pass it to the Dialog component
54
+ className
53
55
  } = _ref,
54
56
  props = _objectWithoutProperties(_ref, _excluded);
55
57
 
@@ -109,9 +111,8 @@ function Modal(_ref) {
109
111
  className: classNames(styles.overlay, styles[height], styles[width], exceptionallySetOverlayClassName),
110
112
 
111
113
  /**
112
- * We're using `onPointerDown` instead of `onClick` to prevent
113
- * the modal from closing when the click starts inside the modal
114
- * and ends on the backdrop.
114
+ * We're using `onPointerDown` instead of `onClick` to prevent the modal from
115
+ * closing when the click starts inside the modal and ends on the backdrop.
115
116
  */
116
117
  onPointerDown: hideOnInteractOutside ? handleBackdropClick : undefined,
117
118
  ref: backdropRef
@@ -121,17 +122,18 @@ function Modal(_ref) {
121
122
  returnFocus: true
122
123
  }, /*#__PURE__*/createElement(Dialog, _objectSpread2(_objectSpread2({}, props), {}, {
123
124
  ref: dialogRef,
124
- as: Box,
125
+ render: /*#__PURE__*/createElement(Box, {
126
+ borderRadius: "full",
127
+ background: "default",
128
+ display: "flex",
129
+ flexDirection: "column",
130
+ overflow: "hidden",
131
+ height: height === 'expand' ? 'full' : undefined,
132
+ flexGrow: height === 'expand' ? 1 : 0
133
+ }),
134
+ className: classNames(exceptionallySetClassName, styles.container),
125
135
  store: store,
126
136
  preventBodyScroll: true,
127
- borderRadius: "full",
128
- background: "default",
129
- display: "flex",
130
- flexDirection: "column",
131
- overflow: "hidden",
132
- height: height === 'expand' ? 'full' : undefined,
133
- flexGrow: height === 'expand' ? 1 : 0,
134
- className: [exceptionallySetClassName, styles.container],
135
137
  // Disable focus lock as we set up our own using ReactFocusLock
136
138
  modal: false,
137
139
  autoFocus: false,
@@ -167,7 +169,7 @@ function ModalCloseButton(props) {
167
169
  setIsMounted(true);
168
170
  }
169
171
  }, [isMounted]);
170
- return /*#__PURE__*/createElement(Button, _objectSpread2(_objectSpread2({}, props), {}, {
172
+ return /*#__PURE__*/createElement(IconButton, _objectSpread2(_objectSpread2({}, props), {}, {
171
173
  variant: "quaternary",
172
174
  onClick: onDismiss,
173
175
  icon: /*#__PURE__*/createElement(CloseIcon, null),
@@ -1 +1 @@
1
- {"version":3,"file":"modal.js","sources":["../../src/modal/modal.tsx"],"sourcesContent":["import * as React from 'react'\nimport classNames from 'classnames'\nimport FocusLock from 'react-focus-lock'\nimport { hideOthers } from 'aria-hidden'\n\nimport { Dialog, DialogOptions, useDialogStore, Portal, PortalOptions } from '@ariakit/react'\n\nimport { CloseIcon } from '../icons/close-icon'\nimport { Column, Columns } from '../columns'\nimport { Inline } from '../inline'\nimport { Divider } from '../divider'\nimport { Box } from '../box'\nimport { Button, ButtonProps } from '../button'\n\nimport styles from './modal.module.css'\n\ntype ModalWidth = 'small' | 'medium' | 'large' | 'xlarge' | 'full'\ntype ModalHeightMode = 'expand' | 'fitContent'\n\n//\n// ModalContext\n//\n\ntype ModalContextValue = {\n onDismiss?(this: void): void\n height: ModalHeightMode\n}\n\nconst ModalContext = React.createContext<ModalContextValue>({\n onDismiss: undefined,\n height: 'fitContent',\n})\n\n//\n// Modal container\n//\n\ntype DivProps = Omit<\n React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLDivElement>, HTMLDivElement>,\n 'className' | 'children' | `aria-label` | `aria-labelledby`\n>\n\nexport type ModalProps = DivProps & {\n /**\n * The content of the modal.\n */\n children: React.ReactNode\n /**\n * Whether the modal is open and visible or not.\n */\n isOpen: boolean\n /**\n * Called when the user triggers closing the modal.\n */\n onDismiss?(): void\n /**\n * A descriptive setting for how wide the modal should aim to be, depending on how much space\n * it has on screen.\n * @default 'medium'\n */\n width?: ModalWidth\n /**\n * A descriptive setting for how tall the modal should aim to be.\n *\n * - 'expand': the modal aims to fill most of the available screen height, leaving only a small\n * padding above and below.\n * - 'fitContent': the modal shrinks to the smallest size that allow it to fit its content.\n *\n * In either case, if content does not fit, the content of the main body is set to scroll\n * (provided you use `ModalBody`) so that the modal never has to strech vertically beyond the\n * viewport boundaries.\n *\n * If you do not use `ModalBody`, the modal still prevents overflow, and you are in charge of\n * the inner layout to ensure scroll, or whatever other strategy you may want.\n */\n height?: ModalHeightMode\n /**\n * Whether to set or not the focus initially to the first focusable element inside the modal.\n */\n autoFocus?: boolean\n /**\n * Controls if the modal is dismissed when pressing \"Escape\".\n */\n hideOnEscape?: DialogOptions['hideOnEscape']\n /**\n * Controls if the modal is dismissed when clicking outside the modal body, on the overlay.\n */\n hideOnInteractOutside?: DialogOptions['hideOnInteractOutside']\n /**\n * An escape hatch in case you need to provide a custom class name to the container element.\n */\n exceptionallySetClassName?: string\n /**\n * An escape hatch in case you need to provide a custom class name to the overlay element.\n */\n exceptionallySetOverlayClassName?: string\n /** Defines a string value that labels the current modal for assistive technologies. */\n 'aria-label'?: string\n /** Identifies the element (or elements) that labels the current modal for assistive technologies. */\n 'aria-labelledby'?: string\n /**\n * An HTML element or a memoized callback function that returns an HTML element to be used as\n * the portal element. By default, the portal element will be a `div` element appended to the\n * `document.body`.\n *\n * @default HTMLDivElement\n *\n * @example\n * const [portal, setPortal] = useState(null);\n * <Portal portalElement={portal} />;\n * <div ref={setPortal} />;\n *\n * @example\n * const getPortalElement = useCallback(() => {\n * const div = document.createElement(\"div\");\n * const portalRoot = document.getElementById(\"portal-root\");\n * portalRoot.appendChild(div);\n * return div;\n * }, []);\n * <Portal portalElement={getPortalElement} />;\n */\n portalElement?: PortalOptions['portalElement']\n}\n\nfunction isNotInternalFrame(element: HTMLElement) {\n return !(element.ownerDocument === document && element.tagName.toLowerCase() === 'iframe')\n}\n\n/**\n * Renders a modal that sits on top of the rest of the content in the entire page.\n *\n * Follows the WAI-ARIA Dialog (Modal) Pattern.\n *\n * @see ModalHeader\n * @see ModalFooter\n * @see ModalBody\n */\nexport function Modal({\n isOpen,\n onDismiss,\n height = 'fitContent',\n width = 'medium',\n exceptionallySetClassName,\n exceptionallySetOverlayClassName,\n autoFocus = true,\n hideOnEscape = true,\n hideOnInteractOutside = true,\n children,\n portalElement,\n onKeyDown,\n ...props\n}: ModalProps) {\n const setOpen = React.useCallback(\n (visible: boolean) => {\n if (!visible) {\n onDismiss?.()\n }\n },\n [onDismiss],\n )\n const store = useDialogStore({ open: isOpen, setOpen })\n\n const contextValue: ModalContextValue = React.useMemo(() => ({ onDismiss, height }), [\n onDismiss,\n height,\n ])\n\n const portalRef = React.useRef<HTMLElement | null>(null)\n const dialogRef = React.useRef<HTMLDivElement | null>(null)\n const backdropRef = React.useRef<HTMLDivElement | null>(null)\n const handleBackdropClick = React.useCallback(\n (event: React.MouseEvent) => {\n if (\n // The focus lock element takes up the same space as the backdrop and is where the event bubbles up from,\n // so instead of checking the backdrop as the event target, we need to make sure it's just above the dialog\n !dialogRef.current?.contains(event.target as Node) &&\n // Events fired from other portals will bubble up to the backdrop, even if it isn't a child in the DOM\n backdropRef.current?.contains(event.target as Node)\n ) {\n event.stopPropagation()\n onDismiss?.()\n }\n },\n [onDismiss],\n )\n\n React.useLayoutEffect(\n function disableAccessibilityTreeOutside() {\n if (!isOpen || !portalRef.current) {\n return\n }\n\n return hideOthers(portalRef.current)\n },\n [isOpen],\n )\n\n const handleKeyDown = React.useCallback(\n function handleKeyDown(event: React.KeyboardEvent<HTMLDivElement>) {\n if (\n hideOnEscape &&\n onDismiss != null &&\n event.key === 'Escape' &&\n !event.defaultPrevented\n ) {\n event.stopPropagation()\n onDismiss()\n }\n onKeyDown?.(event)\n },\n [onDismiss, hideOnEscape, onKeyDown],\n )\n\n if (!isOpen) {\n return null\n }\n\n return (\n <Portal portalRef={portalRef} portalElement={portalElement}>\n <Box\n data-testid=\"modal-overlay\"\n data-overlay\n className={classNames(\n styles.overlay,\n styles[height],\n styles[width],\n exceptionallySetOverlayClassName,\n )}\n /**\n * We're using `onPointerDown` instead of `onClick` to prevent\n * the modal from closing when the click starts inside the modal\n * and ends on the backdrop.\n */\n onPointerDown={hideOnInteractOutside ? handleBackdropClick : undefined}\n ref={backdropRef}\n >\n <FocusLock autoFocus={autoFocus} whiteList={isNotInternalFrame} returnFocus={true}>\n <Dialog\n {...props}\n ref={dialogRef}\n as={Box}\n store={store}\n preventBodyScroll\n borderRadius=\"full\"\n background=\"default\"\n display=\"flex\"\n flexDirection=\"column\"\n overflow=\"hidden\"\n height={height === 'expand' ? 'full' : undefined}\n flexGrow={height === 'expand' ? 1 : 0}\n className={[exceptionallySetClassName, styles.container]}\n // Disable focus lock as we set up our own using ReactFocusLock\n modal={false}\n autoFocus={false}\n autoFocusOnShow={false}\n autoFocusOnHide={false}\n // Disable portal and backdrop as we control their markup\n portal={false}\n backdrop={false}\n hideOnInteractOutside={false}\n hideOnEscape={false}\n onKeyDown={handleKeyDown}\n >\n <ModalContext.Provider value={contextValue}>\n {children}\n </ModalContext.Provider>\n </Dialog>\n </FocusLock>\n </Box>\n </Portal>\n )\n}\n\n//\n// ModalCloseButton\n//\n\nexport type ModalCloseButtonProps = Omit<\n ButtonProps,\n | 'type'\n | 'children'\n | 'variant'\n | 'icon'\n | 'startIcon'\n | 'endIcon'\n | 'disabled'\n | 'loading'\n | 'tabIndex'\n | 'width'\n | 'align'\n> & {\n /**\n * The descriptive label of the button.\n */\n 'aria-label': string\n}\n\n/**\n * The close button rendered by ModalHeader. Provided independently so that consumers can customize\n * the button's label.\n *\n * @see ModalHeader\n */\nexport function ModalCloseButton(props: ModalCloseButtonProps) {\n const { onDismiss } = React.useContext(ModalContext)\n const [includeInTabOrder, setIncludeInTabOrder] = React.useState(false)\n const [isMounted, setIsMounted] = React.useState(false)\n\n React.useEffect(\n function skipAutoFocus() {\n if (isMounted) {\n setIncludeInTabOrder(true)\n } else {\n setIsMounted(true)\n }\n },\n [isMounted],\n )\n\n return (\n <Button\n {...props}\n variant=\"quaternary\"\n onClick={onDismiss}\n icon={<CloseIcon />}\n tabIndex={includeInTabOrder ? 0 : -1}\n />\n )\n}\n\n//\n// ModalHeader\n//\n\nexport type ModalHeaderProps = DivProps & {\n /**\n * The content of the header.\n */\n children: React.ReactNode\n /**\n * Allows to provide a custom button element, or to omit the close button if set to false.\n * @see ModalCloseButton\n */\n button?: React.ReactNode | boolean\n /**\n * Whether to render a divider line below the header.\n * @default false\n */\n withDivider?: boolean\n /**\n * A escape hatch in case you need to provide a custom class name to the container element.\n */\n exceptionallySetClassName?: string\n}\n\n/**\n * Renders a standard modal header area with an optional close button.\n *\n * @see Modal\n * @see ModalFooter\n * @see ModalBody\n */\nexport function ModalHeader({\n children,\n button = true,\n withDivider = false,\n exceptionallySetClassName,\n ...props\n}: ModalHeaderProps) {\n return (\n <>\n <Box\n {...props}\n as=\"header\"\n paddingLeft=\"large\"\n paddingRight={button === false || button === null ? 'large' : 'small'}\n paddingY=\"small\"\n className={exceptionallySetClassName}\n >\n <Columns space=\"large\" alignY=\"center\">\n <Column width=\"auto\">{children}</Column>\n {button === false || button === null ? (\n <div className={styles.headerContent} />\n ) : (\n <Column\n width=\"content\"\n exceptionallySetClassName={styles.buttonContainer}\n data-testid=\"button-container\"\n >\n {typeof button === 'boolean' ? (\n <ModalCloseButton aria-label=\"Close modal\" autoFocus={false} />\n ) : (\n button\n )}\n </Column>\n )}\n </Columns>\n </Box>\n {withDivider ? <Divider /> : null}\n </>\n )\n}\n\n//\n// ModalBody\n//\n\nexport type ModalBodyProps = DivProps & {\n /**\n * The content of the modal body.\n */\n children: React.ReactNode\n /**\n * A escape hatch in case you need to provide a custom class name to the container element.\n */\n exceptionallySetClassName?: string\n}\n\n/**\n * Renders the body of a modal.\n *\n * Convenient to use alongside ModalHeader and/or ModalFooter as needed. It ensures, among other\n * things, that the contet of the modal body expands or contracts depending on the modal height\n * setting or the size of the content. The body content also automatically scrolls when it's too\n * large to fit the available space.\n *\n * @see Modal\n * @see ModalHeader\n * @see ModalFooter\n */\nexport function ModalBody({ exceptionallySetClassName, children, ...props }: ModalBodyProps) {\n const { height } = React.useContext(ModalContext)\n return (\n <Box\n {...props}\n className={exceptionallySetClassName}\n flexGrow={height === 'expand' ? 1 : 0}\n height={height === 'expand' ? 'full' : undefined}\n overflow=\"auto\"\n >\n <Box padding=\"large\" paddingBottom=\"xxlarge\">\n {children}\n </Box>\n </Box>\n )\n}\n\n//\n// ModalFooter\n//\n\nexport type ModalFooterProps = DivProps & {\n /**\n * The contant of the modal footer.\n */\n children: React.ReactNode\n /**\n * Whether to render a divider line below the footer.\n * @default false\n */\n withDivider?: boolean\n /**\n * A escape hatch in case you need to provide a custom class name to the container element.\n */\n exceptionallySetClassName?: string\n}\n\n/**\n * Renders a standard modal footer area.\n *\n * @see Modal\n * @see ModalHeader\n * @see ModalBody\n */\nexport function ModalFooter({\n exceptionallySetClassName,\n withDivider = false,\n ...props\n}: ModalFooterProps) {\n return (\n <>\n {withDivider ? <Divider /> : null}\n <Box as=\"footer\" {...props} className={exceptionallySetClassName} padding=\"large\" />\n </>\n )\n}\n\n//\n// ModalActions\n//\n\nexport type ModalActionsProps = ModalFooterProps\n\n/**\n * A specific version of the ModalFooter, tailored to showing an inline list of actions (buttons).\n * @see ModalFooter\n */\nexport function ModalActions({ children, ...props }: ModalActionsProps) {\n return (\n <ModalFooter {...props}>\n <Inline align=\"right\" space=\"large\">\n {children}\n </Inline>\n </ModalFooter>\n )\n}\n"],"names":["ModalContext","React","onDismiss","undefined","height","isNotInternalFrame","element","ownerDocument","document","tagName","toLowerCase","Modal","isOpen","width","exceptionallySetClassName","exceptionallySetOverlayClassName","autoFocus","hideOnEscape","hideOnInteractOutside","children","portalElement","onKeyDown","props","setOpen","visible","store","useDialogStore","open","contextValue","portalRef","dialogRef","backdropRef","handleBackdropClick","event","current","contains","target","stopPropagation","disableAccessibilityTreeOutside","hideOthers","handleKeyDown","key","defaultPrevented","Portal","Box","className","classNames","styles","overlay","onPointerDown","ref","FocusLock","whiteList","returnFocus","Dialog","as","preventBodyScroll","borderRadius","background","display","flexDirection","overflow","flexGrow","container","modal","autoFocusOnShow","autoFocusOnHide","portal","backdrop","Provider","value","ModalCloseButton","includeInTabOrder","setIncludeInTabOrder","isMounted","setIsMounted","skipAutoFocus","Button","variant","onClick","icon","CloseIcon","tabIndex","ModalHeader","button","withDivider","paddingLeft","paddingRight","paddingY","Columns","space","alignY","Column","headerContent","buttonContainer","Divider","ModalBody","padding","paddingBottom","ModalFooter","ModalActions","Inline","align"],"mappings":";;;;;;;;;;;;;;;;;;;AA4BA,MAAMA,YAAY,gBAAGC,aAAA,CAAuC;EACxDC,SAAS,EAAEC,SAD6C;EAExDC,MAAM,EAAE;AAFgD,CAAvC,CAArB;;AAgGA,SAASC,kBAAT,CAA4BC,OAA5B;EACI,OAAO,EAAEA,OAAO,CAACC,aAAR,KAA0BC,QAA1B,IAAsCF,OAAO,CAACG,OAAR,CAAgBC,WAAhB,OAAkC,QAA1E,CAAP;AACH;AAED;;;;;;;;;;;SASgBC;MAAM;IAClBC,MADkB;IAElBV,SAFkB;IAGlBE,MAAM,GAAG,YAHS;IAIlBS,KAAK,GAAG,QA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;IAAKqD,OAAO,EAAC;IAAQC,aAAa,EAAC;GAAnC,EACK/E,QADL,CAPJ,CADJ;AAaH;AAsBD;;;;;;;;SAOgBgF;MAAY;IACxBrF,yBADwB;IAExBuE,WAAW,GAAG;;MACX/D;;EAEH,oBACIrB,aAAA,SAAA,MAAA,EACKoF,WAAW,gBAAGpF,aAAA,CAAC8F,OAAD,MAAA,CAAH,GAAiB,IADjC,eAEI9F,aAAA,CAAC2C,GAAD;IAAKW,EAAE,EAAC;KAAajC,KAArB;IAA4BuB,SAAS,EAAE/B,yBAAvC;IAAkEmF,OAAO,EAAC;KAF9E,CADJ;AAMH;AAQD;;;;;SAIgBG;MAAa;IAAEjF;;MAAaG;;EACxC,oBACIrB,aAAA,CAACkG,WAAD,qBAAiB7E,KAAjB,gBACIrB,aAAA,CAACoG,MAAD;IAAQC,KAAK,EAAC;IAAQZ,KAAK,EAAC;GAA5B,EACKvE,QADL,CADJ,CADJ;AAOH;;;;"}
1
+ {"version":3,"file":"modal.js","sources":["../../src/modal/modal.tsx"],"sourcesContent":["import * as React from 'react'\nimport classNames from 'classnames'\nimport FocusLock from 'react-focus-lock'\nimport { hideOthers } from 'aria-hidden'\n\nimport { Dialog, DialogOptions, useDialogStore, Portal, PortalOptions } from '@ariakit/react'\n\nimport { CloseIcon } from '../icons/close-icon'\nimport { Column, Columns } from '../columns'\nimport { Inline } from '../inline'\nimport { Divider } from '../divider'\nimport { Box } from '../box'\nimport { IconButtonProps, IconButton } from '../button'\n\nimport styles from './modal.module.css'\nimport type { ObfuscatedClassName } from '../utils/common-types'\n\ntype ModalWidth = 'small' | 'medium' | 'large' | 'xlarge' | 'full'\ntype ModalHeightMode = 'expand' | 'fitContent'\n\n//\n// ModalContext\n//\n\ntype ModalContextValue = {\n onDismiss?(this: void): void\n height: ModalHeightMode\n}\n\nconst ModalContext = React.createContext<ModalContextValue>({\n onDismiss: undefined,\n height: 'fitContent',\n})\n\n//\n// Modal container\n//\n\ntype DivProps = Omit<\n React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLDivElement>, HTMLDivElement>,\n 'className' | 'children' | `aria-label` | `aria-labelledby`\n>\n\nexport interface ModalProps extends DivProps, ObfuscatedClassName {\n /**\n * The content of the modal.\n */\n children: React.ReactNode\n\n /**\n * Whether the modal is open and visible or not.\n */\n isOpen: boolean\n\n /**\n * Called when the user triggers closing the modal.\n */\n onDismiss?(): void\n\n /**\n * A descriptive setting for how wide the modal should aim to be, depending on how much space\n * it has on screen.\n * @default 'medium'\n */\n width?: ModalWidth\n\n /**\n * A descriptive setting for how tall the modal should aim to be.\n *\n * - 'expand': the modal aims to fill most of the available screen height, leaving only a small\n * padding above and below.\n * - 'fitContent': the modal shrinks to the smallest size that allow it to fit its content.\n *\n * In either case, if content does not fit, the content of the main body is set to scroll\n * (provided you use `ModalBody`) so that the modal never has to strech vertically beyond the\n * viewport boundaries.\n *\n * If you do not use `ModalBody`, the modal still prevents overflow, and you are in charge of\n * the inner layout to ensure scroll, or whatever other strategy you may want.\n */\n height?: ModalHeightMode\n\n /**\n * Whether to set or not the focus initially to the first focusable element inside the modal.\n */\n autoFocus?: boolean\n\n /**\n * Controls if the modal is dismissed when pressing \"Escape\".\n */\n hideOnEscape?: DialogOptions['hideOnEscape']\n\n /**\n * Controls if the modal is dismissed when clicking outside the modal body, on the overlay.\n */\n hideOnInteractOutside?: DialogOptions['hideOnInteractOutside']\n\n /**\n * An escape hatch in case you need to provide a custom class name to the overlay element.\n */\n exceptionallySetOverlayClassName?: string\n\n /**\n * Defines a string value that labels the current modal for assistive technologies.\n */\n 'aria-label'?: string\n\n /**\n * Identifies the element (or elements) that labels the current modal for assistive technologies.\n */\n 'aria-labelledby'?: string\n\n /**\n * An HTML element or a memoized callback function that returns an HTML element to be used as\n * the portal element. By default, the portal element will be a `div` element appended to the\n * `document.body`.\n *\n * @default HTMLDivElement\n *\n * @example\n * const [portal, setPortal] = useState(null);\n * <Portal portalElement={portal} />;\n * <div ref={setPortal} />;\n *\n * @example\n * const getPortalElement = useCallback(() => {\n * const div = document.createElement(\"div\");\n * const portalRoot = document.getElementById(\"portal-root\");\n * portalRoot.appendChild(div);\n * return div;\n * }, []);\n * <Portal portalElement={getPortalElement} />;\n */\n portalElement?: PortalOptions['portalElement']\n}\n\nfunction isNotInternalFrame(element: HTMLElement) {\n return !(element.ownerDocument === document && element.tagName.toLowerCase() === 'iframe')\n}\n\n/**\n * Renders a modal that sits on top of the rest of the content in the entire page.\n *\n * Follows the WAI-ARIA Dialog (Modal) Pattern.\n *\n * @see ModalHeader\n * @see ModalFooter\n * @see ModalBody\n */\nexport function Modal({\n isOpen,\n onDismiss,\n height = 'fitContent',\n width = 'medium',\n exceptionallySetClassName,\n exceptionallySetOverlayClassName,\n autoFocus = true,\n hideOnEscape = true,\n hideOnInteractOutside = true,\n children,\n portalElement,\n onKeyDown,\n // @ts-expect-error we want to make sure to not pass it to the Dialog component\n className,\n ...props\n}: ModalProps) {\n const setOpen = React.useCallback(\n (visible: boolean) => {\n if (!visible) {\n onDismiss?.()\n }\n },\n [onDismiss],\n )\n const store = useDialogStore({ open: isOpen, setOpen })\n\n const contextValue: ModalContextValue = React.useMemo(() => ({ onDismiss, height }), [\n onDismiss,\n height,\n ])\n\n const portalRef = React.useRef<HTMLElement | null>(null)\n const dialogRef = React.useRef<HTMLDivElement | null>(null)\n const backdropRef = React.useRef<HTMLDivElement | null>(null)\n const handleBackdropClick = React.useCallback(\n (event: React.MouseEvent) => {\n if (\n // The focus lock element takes up the same space as the backdrop and is where the event bubbles up from,\n // so instead of checking the backdrop as the event target, we need to make sure it's just above the dialog\n !dialogRef.current?.contains(event.target as Node) &&\n // Events fired from other portals will bubble up to the backdrop, even if it isn't a child in the DOM\n backdropRef.current?.contains(event.target as Node)\n ) {\n event.stopPropagation()\n onDismiss?.()\n }\n },\n [onDismiss],\n )\n\n React.useLayoutEffect(\n function disableAccessibilityTreeOutside() {\n if (!isOpen || !portalRef.current) {\n return\n }\n\n return hideOthers(portalRef.current)\n },\n [isOpen],\n )\n\n const handleKeyDown = React.useCallback(\n function handleKeyDown(event: React.KeyboardEvent<HTMLDivElement>) {\n if (\n hideOnEscape &&\n onDismiss != null &&\n event.key === 'Escape' &&\n !event.defaultPrevented\n ) {\n event.stopPropagation()\n onDismiss()\n }\n onKeyDown?.(event)\n },\n [onDismiss, hideOnEscape, onKeyDown],\n )\n\n if (!isOpen) {\n return null\n }\n\n return (\n <Portal portalRef={portalRef} portalElement={portalElement}>\n <Box\n data-testid=\"modal-overlay\"\n data-overlay\n className={classNames(\n styles.overlay,\n styles[height],\n styles[width],\n exceptionallySetOverlayClassName,\n )}\n /**\n * We're using `onPointerDown` instead of `onClick` to prevent the modal from\n * closing when the click starts inside the modal and ends on the backdrop.\n */\n onPointerDown={hideOnInteractOutside ? handleBackdropClick : undefined}\n ref={backdropRef}\n >\n <FocusLock autoFocus={autoFocus} whiteList={isNotInternalFrame} returnFocus={true}>\n <Dialog\n {...props}\n ref={dialogRef}\n render={\n <Box\n borderRadius=\"full\"\n background=\"default\"\n display=\"flex\"\n flexDirection=\"column\"\n overflow=\"hidden\"\n height={height === 'expand' ? 'full' : undefined}\n flexGrow={height === 'expand' ? 1 : 0}\n />\n }\n className={classNames(exceptionallySetClassName, styles.container)}\n store={store}\n preventBodyScroll\n // Disable focus lock as we set up our own using ReactFocusLock\n modal={false}\n autoFocus={false}\n autoFocusOnShow={false}\n autoFocusOnHide={false}\n // Disable portal and backdrop as we control their markup\n portal={false}\n backdrop={false}\n hideOnInteractOutside={false}\n hideOnEscape={false}\n onKeyDown={handleKeyDown}\n >\n <ModalContext.Provider value={contextValue}>\n {children}\n </ModalContext.Provider>\n </Dialog>\n </FocusLock>\n </Box>\n </Portal>\n )\n}\n\n//\n// ModalCloseButton\n//\n\nexport interface ModalCloseButtonProps\n extends Omit<\n IconButtonProps,\n 'type' | 'variant' | 'icon' | 'disabled' | 'loading' | 'tabIndex' | 'ref'\n > {\n /**\n * The descriptive label of the button.\n */\n 'aria-label': string\n}\n\n/**\n * The close button rendered by ModalHeader. Provided independently so that consumers can customize\n * the button's label.\n *\n * @see ModalHeader\n */\nexport function ModalCloseButton(props: ModalCloseButtonProps) {\n const { onDismiss } = React.useContext(ModalContext)\n const [includeInTabOrder, setIncludeInTabOrder] = React.useState(false)\n const [isMounted, setIsMounted] = React.useState(false)\n\n React.useEffect(\n function skipAutoFocus() {\n if (isMounted) {\n setIncludeInTabOrder(true)\n } else {\n setIsMounted(true)\n }\n },\n [isMounted],\n )\n\n return (\n <IconButton\n {...props}\n variant=\"quaternary\"\n onClick={onDismiss}\n icon={<CloseIcon />}\n tabIndex={includeInTabOrder ? 0 : -1}\n />\n )\n}\n\n//\n// ModalHeader\n//\n\nexport interface ModalHeaderProps extends DivProps, ObfuscatedClassName {\n /**\n * The content of the header.\n */\n children: React.ReactNode\n\n /**\n * Allows to provide a custom button element, or to omit the close button if set to false.\n * @see ModalCloseButton\n */\n button?: React.ReactNode | boolean\n\n /**\n * Whether to render a divider line below the header.\n * @default false\n */\n withDivider?: boolean\n}\n\n/**\n * Renders a standard modal header area with an optional close button.\n *\n * @see Modal\n * @see ModalFooter\n * @see ModalBody\n */\nexport function ModalHeader({\n children,\n button = true,\n withDivider = false,\n exceptionallySetClassName,\n ...props\n}: ModalHeaderProps) {\n return (\n <>\n <Box\n {...props}\n as=\"header\"\n paddingLeft=\"large\"\n paddingRight={button === false || button === null ? 'large' : 'small'}\n paddingY=\"small\"\n className={exceptionallySetClassName}\n >\n <Columns space=\"large\" alignY=\"center\">\n <Column width=\"auto\">{children}</Column>\n {button === false || button === null ? (\n <div className={styles.headerContent} />\n ) : (\n <Column\n width=\"content\"\n exceptionallySetClassName={styles.buttonContainer}\n data-testid=\"button-container\"\n >\n {typeof button === 'boolean' ? (\n <ModalCloseButton aria-label=\"Close modal\" autoFocus={false} />\n ) : (\n button\n )}\n </Column>\n )}\n </Columns>\n </Box>\n {withDivider ? <Divider /> : null}\n </>\n )\n}\n\n//\n// ModalBody\n//\n\nexport interface ModalBodyProps extends DivProps, ObfuscatedClassName {\n /**\n * The content of the modal body.\n */\n children: React.ReactNode\n}\n\n/**\n * Renders the body of a modal.\n *\n * Convenient to use alongside ModalHeader and/or ModalFooter as needed. It ensures, among other\n * things, that the contet of the modal body expands or contracts depending on the modal height\n * setting or the size of the content. The body content also automatically scrolls when it's too\n * large to fit the available space.\n *\n * @see Modal\n * @see ModalHeader\n * @see ModalFooter\n */\nexport function ModalBody({ exceptionallySetClassName, children, ...props }: ModalBodyProps) {\n const { height } = React.useContext(ModalContext)\n return (\n <Box\n {...props}\n className={exceptionallySetClassName}\n flexGrow={height === 'expand' ? 1 : 0}\n height={height === 'expand' ? 'full' : undefined}\n overflow=\"auto\"\n >\n <Box padding=\"large\" paddingBottom=\"xxlarge\">\n {children}\n </Box>\n </Box>\n )\n}\n\n//\n// ModalFooter\n//\n\nexport interface ModalFooterProps extends DivProps, ObfuscatedClassName {\n /**\n * The contant of the modal footer.\n */\n children: React.ReactNode\n /**\n * Whether to render a divider line below the footer.\n * @default false\n */\n withDivider?: boolean\n}\n\n/**\n * Renders a standard modal footer area.\n *\n * @see Modal\n * @see ModalHeader\n * @see ModalBody\n */\nexport function ModalFooter({\n exceptionallySetClassName,\n withDivider = false,\n ...props\n}: ModalFooterProps) {\n return (\n <>\n {withDivider ? <Divider /> : null}\n <Box as=\"footer\" {...props} className={exceptionallySetClassName} padding=\"large\" />\n </>\n )\n}\n\n//\n// ModalActions\n//\n\nexport type ModalActionsProps = ModalFooterProps\n\n/**\n * A specific version of the ModalFooter, tailored to showing an inline list of actions (buttons).\n * @see ModalFooter\n */\nexport function ModalActions({ children, ...props }: ModalActionsProps) {\n return (\n <ModalFooter {...props}>\n <Inline align=\"right\" space=\"large\">\n {children}\n </Inline>\n </ModalFooter>\n )\n}\n"],"names":["ModalContext","React","onDismiss","undefined","height","isNotInternalFrame","element","ownerDocument","document","tagName","toLowerCase","Modal","isOpen","width","exceptionallySetClassName","exceptionallySetOverlayClassName","autoFocus","hideOnEscape","hideOnInteractOutside","children","portalElement","onKeyDown","className","props","setOpen","visible","store","useDialogStore","open","contextValue","portalRef","dialogRef","backdropRef","handleBackdropClick","event","current","contains","target","stopPropagation","disableAccessibilityTreeOutside","hideOthers","handleKeyDown","key","defaultPrevented","Portal","Box","classNames","styles","overlay","onPointerDown","ref","FocusLock","whiteList","returnFocus","Dialog","render","borderRadius","background","display","flexDirection","overflow","flexGrow","container","preventBodyScroll","modal","autoFocusOnShow","autoFocusOnHide","portal","backdrop","Provider","value","ModalCloseButton","includeInTabOrder","setIncludeInTabOrder","isMounted","setIsMounted","skipAutoFocus","IconButton","variant","onClick","icon","CloseIcon","tabIndex","ModalHeader","button","withDivider","as","paddingLeft","paddingRight","paddingY","Columns","space","alignY","Column","headerContent","buttonContainer","Divider","ModalBody","padding","paddingBottom","ModalFooter","ModalActions","Inline","align"],"mappings":";;;;;;;;;;;;;;;;;;;AA6BA,MAAMA,YAAY,gBAAGC,aAAA,CAAuC;EACxDC,SAAS,EAAEC,SAD6C;EAExDC,MAAM,EAAE;AAFgD,CAAvC,CAArB;;AA2GA,SAASC,kBAAT,CAA4BC,OAA5B;EACI,OAAO,EAAEA,OAAO,CAACC,aAAR,KAA0BC,QAA1B,IAAsCF,OAAO,CAACG,OAAR,CAAgBC,WAAhB,OAAkC,QAA1E,CAAP;AACH;AAED;;;;;;;;;;;SASgBC;MAAM;IAClBC,MADkB;IAElBV,SAFkB;IAGlBE,MAAM,GAAG,YAHS;IAIlBS,KAAK,GAAG,QAJU;IAKlBC,yBALkB;IAMlBC,gCANkB;IAOlBC,SAAS,GAAG,IAPM;IAQlBC,YAAY,GAAG,IARG;IASlBC,qBAAqB,GAAG,IATN;IAUlBC,QAVkB;IAWlBC,aAXkB;IAYlBC,SAZkB;;IAclBC;;MACGC;;EAEH,MAAMC,OAAO,GAAGvB,WAAA,CACXwB,OAAD;IACI,IAAI,CAACA,OAAL,EAAc;MACVvB,SAAS,QAAT,YAAAA,SAAS;;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C,EAAE,EAAC;KAAa/D,KAArB;IAA4BD,SAAS,EAAER,yBAAvC;IAAkEoF,OAAO,EAAC;KAF9E,CADJ;AAMH;AAQD;;;;;SAIgBG;MAAa;IAAElF;;MAAaI;;EACxC,oBACItB,aAAA,CAACmG,WAAD,qBAAiB7E,KAAjB,gBACItB,aAAA,CAACqG,MAAD;IAAQC,KAAK,EAAC;IAAQZ,KAAK,EAAC;GAA5B,EACKxE,QADL,CADJ,CADJ;AAOH;;;;"}
@@ -1,6 +1,6 @@
1
1
  import { objectWithoutProperties as _objectWithoutProperties, objectSpread2 as _objectSpread2 } from '../_virtual/_rollupPluginBabelHelpers.js';
2
2
  import { forwardRef, useState, createElement } from 'react';
3
- import { Button } from '../button/button.js';
3
+ import { IconButton } from '../button/button.js';
4
4
  import { PasswordVisibleIcon } from '../icons/password-visible-icon.js';
5
5
  import { PasswordHiddenIcon } from '../icons/password-hidden-icon.js';
6
6
  import { TextField } from '../text-field/text-field.js';
@@ -18,7 +18,7 @@ const PasswordField = /*#__PURE__*/forwardRef(function PasswordField(_ref, ref)
18
18
  ref: ref,
19
19
  // @ts-expect-error TextField does not support type="password", so we override the type check here
20
20
  type: isPasswordVisible ? 'text' : 'password',
21
- endSlot: /*#__PURE__*/createElement(Button, {
21
+ endSlot: /*#__PURE__*/createElement(IconButton, {
22
22
  variant: "quaternary",
23
23
  icon: /*#__PURE__*/createElement(Icon, {
24
24
  "aria-hidden": true
@@ -1 +1 @@
1
- {"version":3,"file":"password-field.js","sources":["../../src/password-field/password-field.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport { PasswordVisibleIcon } from '../icons/password-visible-icon'\nimport { PasswordHiddenIcon } from '../icons/password-hidden-icon'\n\nimport { TextField, TextFieldProps } from '../text-field'\nimport { Button } from '../button'\n\nimport type { BaseFieldVariantProps } from '../base-field'\n\n/**\n * FIXME: This is a workaround for consumers that are using newer versions of React types that no longer have these props.\n * Once we upgrade Reactist to the newest React types, we should be able to remove these.\n */\ntype DeprecatedProps = 'crossOrigin' | 'onPointerEnterCapture' | 'onPointerLeaveCapture'\n\ntype PasswordFieldProps = Omit<TextFieldProps, 'type' | 'startSlot' | 'endSlot' | DeprecatedProps> &\n BaseFieldVariantProps & {\n togglePasswordLabel?: string\n }\n\nconst PasswordField = React.forwardRef<HTMLInputElement, PasswordFieldProps>(function PasswordField(\n { togglePasswordLabel = 'Toggle password visibility', ...props },\n ref,\n) {\n const [isPasswordVisible, setPasswordVisible] = React.useState(false)\n const Icon = isPasswordVisible ? PasswordVisibleIcon : PasswordHiddenIcon\n return (\n <TextField\n {...props}\n ref={ref}\n // @ts-expect-error TextField does not support type=\"password\", so we override the type check here\n type={isPasswordVisible ? 'text' : 'password'}\n endSlot={\n <Button\n variant=\"quaternary\"\n icon={<Icon aria-hidden />}\n aria-label={togglePasswordLabel}\n onClick={() => setPasswordVisible((v) => !v)}\n />\n }\n />\n )\n})\n\nexport { PasswordField }\nexport type { PasswordFieldProps }\n"],"names":["PasswordField","React","ref","togglePasswordLabel","props","isPasswordVisible","setPasswordVisible","Icon","PasswordVisibleIcon","PasswordHiddenIcon","TextField","type","endSlot","Button","variant","icon","onClick","v"],"mappings":";;;;;;;;MAqBMA,aAAa,gBAAGC,UAAA,CAAuD,SAASD,aAAT,OAEzEE,GAFyE;MACzE;IAAEC,mBAAmB,GAAG;;MAAiCC;;EAGzD,MAAM,CAACC,iBAAD,EAAoBC,kBAApB,IAA0CL,QAAA,CAAe,KAAf,CAAhD;EACA,MAAMM,IAAI,GAAGF,iBAAiB,GAAGG,mBAAH,GAAyBC,kBAAvD;EACA,oBACIR,aAAA,CAACS,SAAD,oCACQN,KADR;IAEIF,GAAG,EAAEA,GAFT;;IAIIS,IAAI,EAAEN,iBAAiB,GAAG,MAAH,GAAY,UAJvC;IAKIO,OAAO,eACHX,aAAA,CAACY,MAAD;MACIC,OAAO,EAAC;MACRC,IAAI,eAAEd,aAAA,CAACM,IAAD;;OAAA;oBACMJ;MACZa,OAAO,EAAE,MAAMV,kBAAkB,CAAEW,CAAD,IAAO,CAACA,CAAT;KAJrC;KAPZ;AAgBH,CAtBqB;;;;"}
1
+ {"version":3,"file":"password-field.js","sources":["../../src/password-field/password-field.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport { PasswordVisibleIcon } from '../icons/password-visible-icon'\nimport { PasswordHiddenIcon } from '../icons/password-hidden-icon'\n\nimport { TextField, TextFieldProps } from '../text-field'\nimport { IconButton } from '../button'\n\nimport type { BaseFieldVariantProps } from '../base-field'\n\ninterface PasswordFieldProps\n extends Omit<TextFieldProps, 'type' | 'startSlot' | 'endSlot'>,\n BaseFieldVariantProps {\n togglePasswordLabel?: string\n}\n\nconst PasswordField = React.forwardRef<HTMLInputElement, PasswordFieldProps>(function PasswordField(\n { togglePasswordLabel = 'Toggle password visibility', ...props },\n ref,\n) {\n const [isPasswordVisible, setPasswordVisible] = React.useState(false)\n const Icon = isPasswordVisible ? PasswordVisibleIcon : PasswordHiddenIcon\n return (\n <TextField\n {...props}\n ref={ref}\n // @ts-expect-error TextField does not support type=\"password\", so we override the type check here\n type={isPasswordVisible ? 'text' : 'password'}\n endSlot={\n <IconButton\n variant=\"quaternary\"\n icon={<Icon aria-hidden />}\n aria-label={togglePasswordLabel}\n onClick={() => setPasswordVisible((v) => !v)}\n />\n }\n />\n )\n})\n\nexport { PasswordField }\nexport type { PasswordFieldProps }\n"],"names":["PasswordField","React","ref","togglePasswordLabel","props","isPasswordVisible","setPasswordVisible","Icon","PasswordVisibleIcon","PasswordHiddenIcon","TextField","type","endSlot","IconButton","variant","icon","onClick","v"],"mappings":";;;;;;;;MAgBMA,aAAa,gBAAGC,UAAA,CAAuD,SAASD,aAAT,OAEzEE,GAFyE;MACzE;IAAEC,mBAAmB,GAAG;;MAAiCC;;EAGzD,MAAM,CAACC,iBAAD,EAAoBC,kBAApB,IAA0CL,QAAA,CAAe,KAAf,CAAhD;EACA,MAAMM,IAAI,GAAGF,iBAAiB,GAAGG,mBAAH,GAAyBC,kBAAvD;EACA,oBACIR,aAAA,CAACS,SAAD,oCACQN,KADR;IAEIF,GAAG,EAAEA,GAFT;;IAIIS,IAAI,EAAEN,iBAAiB,GAAG,MAAH,GAAY,UAJvC;IAKIO,OAAO,eACHX,aAAA,CAACY,UAAD;MACIC,OAAO,EAAC;MACRC,IAAI,eAAEd,aAAA,CAACM,IAAD;;OAAA;oBACMJ;MACZa,OAAO,EAAE,MAAMV,kBAAkB,CAAEW,CAAD,IAAO,CAACA,CAAT;KAJrC;KAPZ;AAgBH,CAtBqB;;;;"}