@cimpress-ui/react 1.7.1 → 1.8.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 (230) hide show
  1. package/dist/commonjs/components/app-header/app-header.d.ts.map +1 -1
  2. package/dist/commonjs/components/app-header/app-header.js +1 -1
  3. package/dist/commonjs/components/app-header/app-header.js.map +1 -1
  4. package/dist/commonjs/components/app-header/side-nav.d.ts +4 -5
  5. package/dist/commonjs/components/app-header/side-nav.d.ts.map +1 -1
  6. package/dist/commonjs/components/app-header/side-nav.js +3 -2
  7. package/dist/commonjs/components/app-header/side-nav.js.map +1 -1
  8. package/dist/commonjs/components/combo-box/combo-box.d.ts +16 -4
  9. package/dist/commonjs/components/combo-box/combo-box.d.ts.map +1 -1
  10. package/dist/commonjs/components/combo-box/combo-box.js +9 -4
  11. package/dist/commonjs/components/combo-box/combo-box.js.map +1 -1
  12. package/dist/commonjs/components/copy/copy-button.d.ts +20 -0
  13. package/dist/commonjs/components/copy/copy-button.d.ts.map +1 -0
  14. package/dist/commonjs/components/copy/copy-button.js +68 -0
  15. package/dist/commonjs/components/copy/copy-button.js.map +1 -0
  16. package/dist/commonjs/components/copy/inline-copy.d.ts +12 -0
  17. package/dist/commonjs/components/copy/inline-copy.d.ts.map +1 -0
  18. package/dist/commonjs/components/copy/inline-copy.js +33 -0
  19. package/dist/commonjs/components/copy/inline-copy.js.map +1 -0
  20. package/dist/commonjs/components/copy/use-copy.d.ts +10 -0
  21. package/dist/commonjs/components/copy/use-copy.d.ts.map +1 -0
  22. package/dist/commonjs/components/copy/use-copy.js +30 -0
  23. package/dist/commonjs/components/copy/use-copy.js.map +1 -0
  24. package/dist/commonjs/components/date-picker/date-picker.d.ts +7 -2
  25. package/dist/commonjs/components/date-picker/date-picker.d.ts.map +1 -1
  26. package/dist/commonjs/components/date-picker/date-picker.js +6 -2
  27. package/dist/commonjs/components/date-picker/date-picker.js.map +1 -1
  28. package/dist/commonjs/components/date-picker/views/multi-year/use-multi-year-view-state.js +4 -7
  29. package/dist/commonjs/components/date-picker/views/multi-year/use-multi-year-view-state.js.map +1 -1
  30. package/dist/commonjs/components/disclosure/disclosure-group.d.ts +4 -2
  31. package/dist/commonjs/components/disclosure/disclosure-group.d.ts.map +1 -1
  32. package/dist/commonjs/components/disclosure/disclosure-group.js.map +1 -1
  33. package/dist/commonjs/components/disclosure/disclosure.d.ts +4 -2
  34. package/dist/commonjs/components/disclosure/disclosure.d.ts.map +1 -1
  35. package/dist/commonjs/components/disclosure/disclosure.js.map +1 -1
  36. package/dist/commonjs/components/link-tabs/link-tabs.d.ts.map +1 -1
  37. package/dist/commonjs/components/link-tabs/link-tabs.js +1 -1
  38. package/dist/commonjs/components/link-tabs/link-tabs.js.map +1 -1
  39. package/dist/commonjs/components/menu/menu.d.ts +5 -3
  40. package/dist/commonjs/components/menu/menu.d.ts.map +1 -1
  41. package/dist/commonjs/components/menu/menu.js.map +1 -1
  42. package/dist/commonjs/components/number-field/number-field.d.ts +9 -2
  43. package/dist/commonjs/components/number-field/number-field.d.ts.map +1 -1
  44. package/dist/commonjs/components/number-field/number-field.js +8 -2
  45. package/dist/commonjs/components/number-field/number-field.js.map +1 -1
  46. package/dist/commonjs/components/select/select.d.ts +20 -4
  47. package/dist/commonjs/components/select/select.d.ts.map +1 -1
  48. package/dist/commonjs/components/select/select.js +9 -3
  49. package/dist/commonjs/components/select/select.js.map +1 -1
  50. package/dist/commonjs/components/spacing/types.d.ts.map +1 -1
  51. package/dist/commonjs/components/spacing/types.js +6 -4
  52. package/dist/commonjs/components/spacing/types.js.map +1 -1
  53. package/dist/commonjs/components/stepper/context.d.ts +2 -0
  54. package/dist/commonjs/components/stepper/context.d.ts.map +1 -1
  55. package/dist/commonjs/components/stepper/context.js +2 -0
  56. package/dist/commonjs/components/stepper/context.js.map +1 -1
  57. package/dist/commonjs/components/stepper/stepper-item.d.ts.map +1 -1
  58. package/dist/commonjs/components/stepper/stepper-item.js +3 -2
  59. package/dist/commonjs/components/stepper/stepper-item.js.map +1 -1
  60. package/dist/commonjs/components/stepper/stepper.d.ts.map +1 -1
  61. package/dist/commonjs/components/stepper/stepper.js +14 -8
  62. package/dist/commonjs/components/stepper/stepper.js.map +1 -1
  63. package/dist/commonjs/components/table/contexts/column-collection.d.ts.map +1 -1
  64. package/dist/commonjs/components/table/contexts/column-collection.js +0 -1
  65. package/dist/commonjs/components/table/contexts/column-collection.js.map +1 -1
  66. package/dist/commonjs/components/table/contexts/row-state.js.map +1 -1
  67. package/dist/commonjs/components/table/contexts/table-state.js.map +1 -1
  68. package/dist/commonjs/components/table/hooks/use-table-cell.js.map +1 -1
  69. package/dist/commonjs/components/tabs/tabs.d.ts +3 -1
  70. package/dist/commonjs/components/tabs/tabs.d.ts.map +1 -1
  71. package/dist/commonjs/components/tabs/tabs.js.map +1 -1
  72. package/dist/commonjs/components/tag-field/tag-field-input.js +2 -2
  73. package/dist/commonjs/components/tag-field/tag-field-input.js.map +1 -1
  74. package/dist/commonjs/components/tag-field/tag-field-list-box.js +5 -2
  75. package/dist/commonjs/components/tag-field/tag-field-list-box.js.map +1 -1
  76. package/dist/commonjs/components/tag-field/tag-field-tags.js +2 -0
  77. package/dist/commonjs/components/tag-field/tag-field-tags.js.map +1 -1
  78. package/dist/commonjs/components/tag-field/tag-field.d.ts +14 -4
  79. package/dist/commonjs/components/tag-field/tag-field.d.ts.map +1 -1
  80. package/dist/commonjs/components/tag-field/tag-field.js +7 -3
  81. package/dist/commonjs/components/tag-field/tag-field.js.map +1 -1
  82. package/dist/commonjs/components/text-inputs/search-field.d.ts +9 -2
  83. package/dist/commonjs/components/text-inputs/search-field.d.ts.map +1 -1
  84. package/dist/commonjs/components/text-inputs/search-field.js +5 -1
  85. package/dist/commonjs/components/text-inputs/search-field.js.map +1 -1
  86. package/dist/commonjs/components/text-inputs/text-area.d.ts +15 -5
  87. package/dist/commonjs/components/text-inputs/text-area.d.ts.map +1 -1
  88. package/dist/commonjs/components/text-inputs/text-area.js.map +1 -1
  89. package/dist/commonjs/components/text-inputs/text-field.d.ts +2 -5
  90. package/dist/commonjs/components/text-inputs/text-field.d.ts.map +1 -1
  91. package/dist/commonjs/components/text-inputs/text-field.js.map +1 -1
  92. package/dist/commonjs/components/toggle-button/internal-toggle-button.js +7 -7
  93. package/dist/commonjs/components/toggle-button/internal-toggle-button.js.map +1 -1
  94. package/dist/commonjs/components/toggle-button/toggle-button-group.d.ts.map +1 -1
  95. package/dist/commonjs/components/toggle-button/toggle-button-group.js +3 -0
  96. package/dist/commonjs/components/toggle-button/toggle-button-group.js.map +1 -1
  97. package/dist/commonjs/components/top-nav/top-nav.d.ts +12 -0
  98. package/dist/commonjs/components/top-nav/top-nav.d.ts.map +1 -0
  99. package/dist/commonjs/components/top-nav/top-nav.js +18 -0
  100. package/dist/commonjs/components/top-nav/top-nav.js.map +1 -0
  101. package/dist/commonjs/components/types.d.ts +6 -1
  102. package/dist/commonjs/components/types.d.ts.map +1 -1
  103. package/dist/commonjs/components/types.js.map +1 -1
  104. package/dist/commonjs/index.d.ts +3 -0
  105. package/dist/commonjs/index.d.ts.map +1 -1
  106. package/dist/commonjs/index.js +3 -0
  107. package/dist/commonjs/index.js.map +1 -1
  108. package/dist/commonjs/utils/string-like-children-to-string.d.ts +3 -0
  109. package/dist/commonjs/utils/string-like-children-to-string.d.ts.map +1 -0
  110. package/dist/commonjs/utils/string-like-children-to-string.js +7 -0
  111. package/dist/commonjs/utils/string-like-children-to-string.js.map +1 -0
  112. package/dist/esm/components/app-header/app-header.d.ts.map +1 -1
  113. package/dist/esm/components/app-header/app-header.js +1 -1
  114. package/dist/esm/components/app-header/app-header.js.map +1 -1
  115. package/dist/esm/components/app-header/side-nav.d.ts +4 -5
  116. package/dist/esm/components/app-header/side-nav.d.ts.map +1 -1
  117. package/dist/esm/components/app-header/side-nav.js +3 -2
  118. package/dist/esm/components/app-header/side-nav.js.map +1 -1
  119. package/dist/esm/components/combo-box/combo-box.d.ts +16 -4
  120. package/dist/esm/components/combo-box/combo-box.d.ts.map +1 -1
  121. package/dist/esm/components/combo-box/combo-box.js +10 -5
  122. package/dist/esm/components/combo-box/combo-box.js.map +1 -1
  123. package/dist/esm/components/copy/copy-button.d.ts +20 -0
  124. package/dist/esm/components/copy/copy-button.d.ts.map +1 -0
  125. package/dist/esm/components/copy/copy-button.js +65 -0
  126. package/dist/esm/components/copy/copy-button.js.map +1 -0
  127. package/dist/esm/components/copy/inline-copy.d.ts +12 -0
  128. package/dist/esm/components/copy/inline-copy.d.ts.map +1 -0
  129. package/dist/esm/components/copy/inline-copy.js +27 -0
  130. package/dist/esm/components/copy/inline-copy.js.map +1 -0
  131. package/dist/esm/components/copy/use-copy.d.ts +10 -0
  132. package/dist/esm/components/copy/use-copy.d.ts.map +1 -0
  133. package/dist/esm/components/copy/use-copy.js +27 -0
  134. package/dist/esm/components/copy/use-copy.js.map +1 -0
  135. package/dist/esm/components/date-picker/date-picker.d.ts +7 -2
  136. package/dist/esm/components/date-picker/date-picker.d.ts.map +1 -1
  137. package/dist/esm/components/date-picker/date-picker.js +7 -3
  138. package/dist/esm/components/date-picker/date-picker.js.map +1 -1
  139. package/dist/esm/components/date-picker/views/multi-year/use-multi-year-view-state.js +4 -7
  140. package/dist/esm/components/date-picker/views/multi-year/use-multi-year-view-state.js.map +1 -1
  141. package/dist/esm/components/disclosure/disclosure-group.d.ts +4 -2
  142. package/dist/esm/components/disclosure/disclosure-group.d.ts.map +1 -1
  143. package/dist/esm/components/disclosure/disclosure-group.js.map +1 -1
  144. package/dist/esm/components/disclosure/disclosure.d.ts +4 -2
  145. package/dist/esm/components/disclosure/disclosure.d.ts.map +1 -1
  146. package/dist/esm/components/disclosure/disclosure.js.map +1 -1
  147. package/dist/esm/components/link-tabs/link-tabs.d.ts.map +1 -1
  148. package/dist/esm/components/link-tabs/link-tabs.js +1 -1
  149. package/dist/esm/components/link-tabs/link-tabs.js.map +1 -1
  150. package/dist/esm/components/menu/menu.d.ts +5 -3
  151. package/dist/esm/components/menu/menu.d.ts.map +1 -1
  152. package/dist/esm/components/menu/menu.js.map +1 -1
  153. package/dist/esm/components/number-field/number-field.d.ts +9 -2
  154. package/dist/esm/components/number-field/number-field.d.ts.map +1 -1
  155. package/dist/esm/components/number-field/number-field.js +8 -2
  156. package/dist/esm/components/number-field/number-field.js.map +1 -1
  157. package/dist/esm/components/select/select.d.ts +20 -4
  158. package/dist/esm/components/select/select.d.ts.map +1 -1
  159. package/dist/esm/components/select/select.js +9 -3
  160. package/dist/esm/components/select/select.js.map +1 -1
  161. package/dist/esm/components/spacing/types.d.ts.map +1 -1
  162. package/dist/esm/components/spacing/types.js +6 -4
  163. package/dist/esm/components/spacing/types.js.map +1 -1
  164. package/dist/esm/components/stepper/context.d.ts +2 -0
  165. package/dist/esm/components/stepper/context.d.ts.map +1 -1
  166. package/dist/esm/components/stepper/context.js +2 -0
  167. package/dist/esm/components/stepper/context.js.map +1 -1
  168. package/dist/esm/components/stepper/stepper-item.d.ts.map +1 -1
  169. package/dist/esm/components/stepper/stepper-item.js +3 -2
  170. package/dist/esm/components/stepper/stepper-item.js.map +1 -1
  171. package/dist/esm/components/stepper/stepper.d.ts.map +1 -1
  172. package/dist/esm/components/stepper/stepper.js +15 -9
  173. package/dist/esm/components/stepper/stepper.js.map +1 -1
  174. package/dist/esm/components/table/contexts/column-collection.d.ts.map +1 -1
  175. package/dist/esm/components/table/contexts/column-collection.js +0 -1
  176. package/dist/esm/components/table/contexts/column-collection.js.map +1 -1
  177. package/dist/esm/components/table/contexts/row-state.js +2 -2
  178. package/dist/esm/components/table/contexts/row-state.js.map +1 -1
  179. package/dist/esm/components/table/contexts/table-state.js +2 -2
  180. package/dist/esm/components/table/contexts/table-state.js.map +1 -1
  181. package/dist/esm/components/table/hooks/use-table-cell.js +2 -2
  182. package/dist/esm/components/table/hooks/use-table-cell.js.map +1 -1
  183. package/dist/esm/components/tabs/tabs.d.ts +3 -1
  184. package/dist/esm/components/tabs/tabs.d.ts.map +1 -1
  185. package/dist/esm/components/tabs/tabs.js.map +1 -1
  186. package/dist/esm/components/tag-field/tag-field-input.js +2 -2
  187. package/dist/esm/components/tag-field/tag-field-input.js.map +1 -1
  188. package/dist/esm/components/tag-field/tag-field-list-box.js +5 -2
  189. package/dist/esm/components/tag-field/tag-field-list-box.js.map +1 -1
  190. package/dist/esm/components/tag-field/tag-field-tags.js +2 -0
  191. package/dist/esm/components/tag-field/tag-field-tags.js.map +1 -1
  192. package/dist/esm/components/tag-field/tag-field.d.ts +14 -4
  193. package/dist/esm/components/tag-field/tag-field.d.ts.map +1 -1
  194. package/dist/esm/components/tag-field/tag-field.js +8 -4
  195. package/dist/esm/components/tag-field/tag-field.js.map +1 -1
  196. package/dist/esm/components/text-inputs/search-field.d.ts +9 -2
  197. package/dist/esm/components/text-inputs/search-field.d.ts.map +1 -1
  198. package/dist/esm/components/text-inputs/search-field.js +6 -2
  199. package/dist/esm/components/text-inputs/search-field.js.map +1 -1
  200. package/dist/esm/components/text-inputs/text-area.d.ts +15 -5
  201. package/dist/esm/components/text-inputs/text-area.d.ts.map +1 -1
  202. package/dist/esm/components/text-inputs/text-area.js +1 -1
  203. package/dist/esm/components/text-inputs/text-area.js.map +1 -1
  204. package/dist/esm/components/text-inputs/text-field.d.ts +2 -5
  205. package/dist/esm/components/text-inputs/text-field.d.ts.map +1 -1
  206. package/dist/esm/components/text-inputs/text-field.js.map +1 -1
  207. package/dist/esm/components/toggle-button/internal-toggle-button.js +7 -7
  208. package/dist/esm/components/toggle-button/internal-toggle-button.js.map +1 -1
  209. package/dist/esm/components/toggle-button/toggle-button-group.d.ts.map +1 -1
  210. package/dist/esm/components/toggle-button/toggle-button-group.js +3 -0
  211. package/dist/esm/components/toggle-button/toggle-button-group.js.map +1 -1
  212. package/dist/esm/components/top-nav/top-nav.d.ts +12 -0
  213. package/dist/esm/components/top-nav/top-nav.d.ts.map +1 -0
  214. package/dist/esm/components/top-nav/top-nav.js +11 -0
  215. package/dist/esm/components/top-nav/top-nav.js.map +1 -0
  216. package/dist/esm/components/types.d.ts +6 -1
  217. package/dist/esm/components/types.d.ts.map +1 -1
  218. package/dist/esm/components/types.js.map +1 -1
  219. package/dist/esm/index.d.ts +3 -0
  220. package/dist/esm/index.d.ts.map +1 -1
  221. package/dist/esm/index.js +3 -0
  222. package/dist/esm/index.js.map +1 -1
  223. package/dist/esm/utils/string-like-children-to-string.d.ts +3 -0
  224. package/dist/esm/utils/string-like-children-to-string.d.ts.map +1 -0
  225. package/dist/esm/utils/string-like-children-to-string.js +4 -0
  226. package/dist/esm/utils/string-like-children-to-string.js.map +1 -0
  227. package/dist-styles/core.css +1 -1
  228. package/dist-styles/normalize.css +1 -1
  229. package/dist-styles/styles.css +1 -1
  230. package/package.json +17 -17
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import clsx from 'clsx';
4
- import { useContext } from 'react';
4
+ import { useContext, useImperativeHandle, useRef, } from 'react';
5
5
  import { usePreventScroll } from 'react-aria';
6
6
  import { Button as RACButton, Collection as RACCollection, ComboBox as RACComboBox, ComboBoxStateContext as RACComboBoxStateContext, Group as RACGroup, Header as RACHeader, Input as RACInput, ListBox as RACListBox, ListBoxLoadMoreItem as RACListBoxLoadMoreItem, ListBoxItem as RACListBoxItem, ListBoxSection as RACListBoxSection, ListLayout as RACListLayout, Text as RACText, Virtualizer as RACVirtualizer, } from 'react-aria-components';
7
7
  import { forwardRef } from '../../forward-ref.js';
@@ -21,7 +21,8 @@ const VIRTUAL_LAYOUT_OPTIONS = {
21
21
  padding: 0,
22
22
  gap: 0,
23
23
  };
24
- function ComboBox({ label, description, error, items, children, placeholder, UNSAFE_className, UNSAFE_style, isReadOnly, onScroll, isVirtualized = false, UNSTABLE_isLoading: isLoading, UNSTABLE_onLoadMore: onLoadMore, ...props }, ref) {
24
+ function ComboBox({ label, description, error, items, children, placeholder, UNSAFE_className, UNSAFE_style, isReadOnly, onScroll, isVirtualized = false, UNSTABLE_isLoading: isLoading, UNSTABLE_onLoadMore: onLoadMore, apiRef, ...props }, ref) {
25
+ const inputRef = useRef(null);
25
26
  const { 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy } = props;
26
27
  useProductionWarning(() => {
27
28
  if (!label && !ariaLabel && !ariaLabelledBy) {
@@ -31,8 +32,12 @@ function ComboBox({ label, description, error, items, children, placeholder, UNS
31
32
  if (!isProduction() && items != null && typeof children !== 'function') {
32
33
  console.warn('`ComboBox` requires `children` to be a function when using `items` prop');
33
34
  }
35
+ useImperativeHandle(apiRef, () => ({
36
+ focus: () => inputRef.current?.focus(),
37
+ select: () => inputRef.current?.select(),
38
+ }), []);
34
39
  const listBox = (_jsx(ComboBoxList, { items: items, isLoading: isLoading, onLoadMore: onLoadMore, onScroll: onScroll, children: children }));
35
- return (_jsxs(RACComboBox, { ...props, ref: ref, className: clsx('cim-combo-box', UNSAFE_className), style: UNSAFE_style, menuTrigger: "focus", isReadOnly: isReadOnly, "data-readonly": isReadOnly ? true : undefined, children: [_jsx(FormFieldLabel, { isRequired: props.isRequired, isDisabled: props.isDisabled, children: label }), _jsxs(RACGroup, { className: "cim-combo-box-input-group", children: [_jsx(ComboBoxInput, { isReadOnly: isReadOnly, placeholder: placeholder }), _jsx(RACButton, { className: "cim-combo-box-button", children: _jsx(IconChevronDown, {}) })] }), _jsx(FormFieldError, { children: error }), _jsx(FormFieldDescription, { children: description }), _jsx(CollapsibleList, { offset: 5, maxHeight: 315, children: isVirtualized ? (_jsx(RACVirtualizer, { layout: RACListLayout, layoutOptions: VIRTUAL_LAYOUT_OPTIONS, children: listBox })) : (listBox) })] }));
40
+ return (_jsxs(RACComboBox, { ...props, ref: ref, className: clsx('cim-combo-box', UNSAFE_className), style: UNSAFE_style, menuTrigger: "focus", isReadOnly: isReadOnly, "data-readonly": isReadOnly ? true : undefined, children: [_jsx(FormFieldLabel, { isRequired: props.isRequired, isDisabled: props.isDisabled, children: label }), _jsxs(RACGroup, { className: "cim-combo-box-input-group", children: [_jsx(ComboBoxInput, { inputRef: inputRef, isReadOnly: isReadOnly, placeholder: placeholder }), _jsx(RACButton, { className: "cim-combo-box-button", children: _jsx(IconChevronDown, {}) })] }), _jsx(FormFieldError, { children: error }), _jsx(FormFieldDescription, { children: description }), _jsx(CollapsibleList, { offset: 5, maxHeight: 315, children: isVirtualized ? (_jsx(RACVirtualizer, { layout: RACListLayout, layoutOptions: VIRTUAL_LAYOUT_OPTIONS, children: listBox })) : (listBox) })] }));
36
41
  }
37
42
  /**
38
43
  * Allows users to filter a collapsible list and select one item from it.
@@ -41,9 +46,9 @@ function ComboBox({ label, description, error, items, children, placeholder, UNS
41
46
  */
42
47
  const _ComboBox = withStyleProps(forwardRef(ComboBox), 'ComboBox');
43
48
  export { _ComboBox as ComboBox };
44
- function ComboBoxInput({ isReadOnly, placeholder, }) {
49
+ function ComboBoxInput({ inputRef, isReadOnly, placeholder, }) {
45
50
  const comboBoxState = useContext(RACComboBoxStateContext);
46
- return (_jsx(RACInput, { className: clsx('cim-combo-box-input', textStyle({ variant: 'body' })),
51
+ return (_jsx(RACInput, { ref: inputRef, className: clsx('cim-combo-box-input', textStyle({ variant: 'body' })),
47
52
  // Ensure the popover opens when the input is clicked.
48
53
  // By default, React Aria only opens the popover when the input is focused.
49
54
  onClick: () => !isReadOnly && comboBoxState.open(), placeholder: placeholder }));
@@ -1 +1 @@
1
- {"version":3,"file":"combo-box.js","sourceRoot":"","sources":["../../../../src/components/combo-box/combo-box.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAqB,MAAM,OAAO,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EACL,MAAM,IAAI,SAAS,EACnB,UAAU,IAAI,aAAa,EAC3B,QAAQ,IAAI,WAAW,EACvB,oBAAoB,IAAI,uBAA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AY,CAAC,WAAW,GAAG,cAAc,CAAC;AAS1C,0DAA0D;AAC1D,MAAM,UAAU,eAAe,CAA2B,EACxD,KAAK,EACL,QAAQ,EACR,KAAK,EACL,GAAG,KAAK,EACgB;IACxB,IAAI,CAAC,YAAY,EAAE,IAAI,KAAK,IAAI,IAAI,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;QACvE,OAAO,CAAC,IAAI,CAAC,gFAAgF,CAAC,CAAC;IACjG,CAAC;IAED,OAAO,CACL,MAAC,iBAAiB,OAAK,KAAK,EAAE,SAAS,EAAC,uBAAuB,aAC7D,KAAC,SAAS,IACR,SAAS,EAAE,IAAI,CAAC,8BAA8B,EAAE,SAAS,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,YAExG,KAAK,GACI,EACZ,KAAC,aAAa,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAiB,IACrC,CACrB,CAAC;AACJ,CAAC;AAED,eAAe,CAAC,WAAW,GAAG,iBAAiB,CAAC","sourcesContent":["'use client';\n\nimport clsx from 'clsx';\nimport { useContext, type ForwardedRef } from 'react';\nimport { usePreventScroll } from 'react-aria';\nimport {\n Button as RACButton,\n Collection as RACCollection,\n ComboBox as RACComboBox,\n ComboBoxStateContext as RACComboBoxStateContext,\n Group as RACGroup,\n Header as RACHeader,\n Input as RACInput,\n ListBox as RACListBox,\n type ListBoxProps as RACListBoxProps,\n ListBoxLoadMoreItem as RACListBoxLoadMoreItem,\n ListBoxItem as RACListBoxItem,\n ListBoxSection as RACListBoxSection,\n ListLayout as RACListLayout,\n type ListLayoutOptions as RACListLayoutOptions,\n Text as RACText,\n type ComboBoxProps as RACComboBoxProps,\n type ListBoxItemProps as RACListBoxItemProps,\n Virtualizer as RACVirtualizer,\n} from 'react-aria-components';\nimport { forwardRef } from '../../forward-ref.js';\nimport { useLocalizedMessages } from '../../i18n/index.js';\nimport { IconCheck, IconChevronDown } from '../../icons/index.js';\nimport { isProduction } from '../../utils/is-production.js';\nimport { useProductionWarning } from '../../utils/use-production-warning.js';\nimport { withStyleProps } from '../../with-style-props.js';\nimport { CollapsibleList } from '../internal/collapsible-list/collapsible-list.js';\nimport { FormFieldDescription, FormFieldError, FormFieldLabel } from '../internal/form-field/form-field.js';\nimport { Spinner } from '../spinner/spinner.js';\nimport type {\n AsyncItemLoadingProps,\n CollectionItem,\n CollectionProps,\n CommonProps,\n FieldWithPlaceholderProps,\n Key,\n StringLikeChildren,\n} from '../types.js';\nimport { textStyle } from '../typography/utils.js';\n\nconst VIRTUAL_LAYOUT_OPTIONS: RACListLayoutOptions = {\n rowHeight: 40,\n headingHeight: 32,\n loaderHeight: 40,\n padding: 0,\n gap: 0,\n};\n\n/** Represents the state of the `ComboBox` component for validation purposes. */\nexport interface ComboBoxValidationValue {\n /** The selected key in the ComboBox. */\n selectedKey: Key | null;\n /** The value of the ComboBox input. */\n inputValue: string;\n}\n\nexport interface ComboBoxProps<T extends CollectionItem = CollectionItem>\n extends CommonProps,\n FieldWithPlaceholderProps<ComboBoxValidationValue>,\n CollectionProps<T>,\n AsyncItemLoadingProps,\n Pick<\n RACComboBoxProps<T>,\n | 'isDisabled'\n | 'isRequired'\n | 'isInvalid'\n | 'isReadOnly'\n | 'selectedKey'\n | 'defaultSelectedKey'\n | 'inputValue'\n | 'defaultInputValue'\n | 'autoFocus'\n | 'onSelectionChange'\n | 'onInputChange'\n | 'onFocus'\n | 'onBlur'\n | 'onOpenChange'\n >,\n Pick<RACListBoxProps<T>, 'onScroll'> {\n /**\n * Whether the list of options should be virtualized. Use this as a performance optimization for large lists.\n * @default false\n */\n isVirtualized?: boolean;\n}\n\nfunction ComboBox<T extends CollectionItem>(\n {\n label,\n description,\n error,\n items,\n children,\n placeholder,\n UNSAFE_className,\n UNSAFE_style,\n isReadOnly,\n onScroll,\n isVirtualized = false,\n UNSTABLE_isLoading: isLoading,\n UNSTABLE_onLoadMore: onLoadMore,\n ...props\n }: ComboBoxProps<T>,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n const { 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy } = props;\n\n useProductionWarning(() => {\n if (!label && !ariaLabel && !ariaLabelledBy) {\n console.warn('ComboBox requires one of label / aria-label / aria-labelledby for accessibility');\n }\n }, [label, ariaLabel, ariaLabelledBy]);\n\n if (!isProduction() && items != null && typeof children !== 'function') {\n console.warn('`ComboBox` requires `children` to be a function when using `items` prop');\n }\n\n const listBox = (\n <ComboBoxList<T> items={items} isLoading={isLoading} onLoadMore={onLoadMore} onScroll={onScroll}>\n {children}\n </ComboBoxList>\n );\n\n return (\n <RACComboBox\n {...props}\n ref={ref}\n className={clsx('cim-combo-box', UNSAFE_className)}\n style={UNSAFE_style}\n menuTrigger=\"focus\"\n isReadOnly={isReadOnly}\n data-readonly={isReadOnly ? true : undefined}\n >\n <FormFieldLabel isRequired={props.isRequired} isDisabled={props.isDisabled}>\n {label}\n </FormFieldLabel>\n <RACGroup className=\"cim-combo-box-input-group\">\n <ComboBoxInput isReadOnly={isReadOnly} placeholder={placeholder} />\n <RACButton className=\"cim-combo-box-button\">\n <IconChevronDown />\n </RACButton>\n </RACGroup>\n <FormFieldError>{error}</FormFieldError>\n <FormFieldDescription>{description}</FormFieldDescription>\n <CollapsibleList\n offset={5} // 1px border + 4px actual offset\n maxHeight={315}\n >\n {isVirtualized ? (\n <RACVirtualizer layout={RACListLayout} layoutOptions={VIRTUAL_LAYOUT_OPTIONS}>\n {listBox}\n </RACVirtualizer>\n ) : (\n listBox\n )}\n </CollapsibleList>\n </RACComboBox>\n );\n}\n\n/**\n * Allows users to filter a collapsible list and select one item from it.\n *\n * See [combo box usage guidelines](https://ui.cimpress.io/components/combo-box)\n */\nconst _ComboBox = withStyleProps(forwardRef(ComboBox), 'ComboBox');\n\nexport { _ComboBox as ComboBox };\n\nfunction ComboBoxInput({\n isReadOnly,\n placeholder,\n}: {\n isReadOnly: boolean | undefined;\n placeholder: string | undefined;\n}) {\n const comboBoxState = useContext(RACComboBoxStateContext);\n\n return (\n <RACInput\n className={clsx('cim-combo-box-input', textStyle({ variant: 'body' }))}\n // Ensure the popover opens when the input is clicked.\n // By default, React Aria only opens the popover when the input is focused.\n onClick={() => !isReadOnly && comboBoxState!.open()}\n placeholder={placeholder}\n />\n );\n}\n\nfunction ComboBoxList<T extends CollectionItem = CollectionItem>({\n items,\n children,\n isLoading,\n onLoadMore,\n onScroll,\n}: Pick<ComboBoxProps<T>, 'items' | 'children' | 'onScroll'> & {\n isLoading: ComboBoxProps['UNSTABLE_isLoading'];\n onLoadMore: ComboBoxProps['UNSTABLE_onLoadMore'];\n}) {\n const comboBoxState = useContext(RACComboBoxStateContext);\n const collectionMessages = useLocalizedMessages('UNSTABLE_collection');\n\n usePreventScroll({ isDisabled: !comboBoxState?.isOpen });\n\n return (\n <RACListBox\n className=\"cim-combo-box-listbox\"\n onScroll={onScroll}\n renderEmptyState={() =>\n isLoading ? <Spinner aria-label={collectionMessages.format('loading')} size=\"small\" marginY={8} /> : null\n }\n >\n <RACCollection items={items}>{children}</RACCollection>\n <RACListBoxLoadMoreItem onLoadMore={onLoadMore} isLoading={isLoading}>\n <Spinner aria-label={collectionMessages.format('loadingMore')} size=\"small\" marginY={8} />\n </RACListBoxLoadMoreItem>\n </RACListBox>\n );\n}\n\nexport interface ComboBoxItemProps<T extends CollectionItem>\n extends Pick<RACListBoxItemProps<T>, 'id' | 'isDisabled' | 'onHoverStart' | 'onHoverEnd'> {\n /** The content to display as the label. */\n children: StringLikeChildren;\n}\n\n/** Renders a single list item within `ComboBox`. */\nexport function ComboBoxItem<T extends CollectionItem>({ children, ...props }: ComboBoxItemProps<T>) {\n const textValue =\n typeof children === 'string' ? children : typeof children === 'number' ? String(children) : children.join('');\n\n return (\n <RACListBoxItem {...props} className=\"cim-combo-box-item\" textValue={textValue}>\n {({ isDisabled }) => (\n <>\n <IconCheck />\n\n <RACText slot=\"label\" className={textStyle({ variant: 'body', tone: isDisabled ? 'muted' : 'base' })}>\n {children}\n </RACText>\n </>\n )}\n </RACListBoxItem>\n );\n}\n\nComboBoxItem.displayName = 'ComboBoxItem';\n\nexport interface ComboBoxSectionProps<T extends CollectionItem> extends CollectionProps<T> {\n /** The ID of the section. Has to be unique across all sections and items. */\n id?: Key;\n /** The content to display as the section title. */\n title: string;\n}\n\n/** Groups list items within `ComboBox` into a section. */\nexport function ComboBoxSection<T extends CollectionItem>({\n title,\n children,\n items,\n ...props\n}: ComboBoxSectionProps<T>) {\n if (!isProduction() && items != null && typeof children !== 'function') {\n console.warn('`ComboBoxSection` requires `children` to be a function when using `items` prop');\n }\n\n return (\n <RACListBoxSection {...props} className=\"cim-combo-box-section\">\n <RACHeader\n className={clsx('cim-combo-box-section-header', textStyle({ variant: 'small-semibold', tone: 'subtle' }))}\n >\n {title}\n </RACHeader>\n <RACCollection items={items}>{children}</RACCollection>\n </RACListBoxSection>\n );\n}\n\nComboBoxSection.displayName = 'ComboBoxSection';\n"]}
1
+ {"version":3,"file":"combo-box.js","sourceRoot":"","sources":["../../../../src/components/combo-box/combo-box.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAIL,UAAU,EACV,mBAAmB,EACnB,MAAM,GACP,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EACL,MAAM,IAAI,SAAS,EACnB,UAAU,IAAI,aAAa,EAC3B,QAAQ,IAAI,WAAW,EACvB,oBAAoB,IAAI,uBAAuB,EAC/C,KAAK,IAAI,QAAQ,EACjB,MAAM,IAAI,SAAS,EACnB,KAAK,IAAI,QAAQ,EACjB,OAAO,IAAI,UAAU,EACrB,mBAAmB,IAAI,sBAAsB,EAC7C,WAAW,IAAI,cAAc,EAC7B,cAAc,IAAI,iBAAiB,EACnC,UAAU,IAAI,aAAa,EAE3B,IAAI,IAAI,OAAO,EAGf,W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AAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,YACjG,QAAQ,GACD,IACT,CACJ,GACc,CAClB,CAAC;AACJ,CAAC;AAED,YAAY,CAAC,WAAW,GAAG,cAAc,CAAC;AAS1C,0DAA0D;AAC1D,MAAM,UAAU,eAAe,CAA2B,EACxD,KAAK,EACL,QAAQ,EACR,KAAK,EACL,GAAG,KAAK,EACgB;IACxB,IAAI,CAAC,YAAY,EAAE,IAAI,KAAK,IAAI,IAAI,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;QACvE,OAAO,CAAC,IAAI,CAAC,gFAAgF,CAAC,CAAC;IACjG,CAAC;IAED,OAAO,CACL,MAAC,iBAAiB,OAAK,KAAK,EAAE,SAAS,EAAC,uBAAuB,aAC7D,KAAC,SAAS,IACR,SAAS,EAAE,IAAI,CAAC,8BAA8B,EAAE,SAAS,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,YAExG,KAAK,GACI,EACZ,KAAC,aAAa,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAiB,IACrC,CACrB,CAAC;AACJ,CAAC;AAED,eAAe,CAAC,WAAW,GAAG,iBAAiB,CAAC","sourcesContent":["'use client';\n\nimport clsx from 'clsx';\nimport {\n type ForwardedRef,\n type MutableRefObject,\n type UIEventHandler,\n useContext,\n useImperativeHandle,\n useRef,\n} from 'react';\nimport { usePreventScroll } from 'react-aria';\nimport {\n Button as RACButton,\n Collection as RACCollection,\n ComboBox as RACComboBox,\n ComboBoxStateContext as RACComboBoxStateContext,\n Group as RACGroup,\n Header as RACHeader,\n Input as RACInput,\n ListBox as RACListBox,\n ListBoxLoadMoreItem as RACListBoxLoadMoreItem,\n ListBoxItem as RACListBoxItem,\n ListBoxSection as RACListBoxSection,\n ListLayout as RACListLayout,\n type ListLayoutOptions as RACListLayoutOptions,\n Text as RACText,\n type ComboBoxProps as RACComboBoxProps,\n type ListBoxItemProps as RACListBoxItemProps,\n Virtualizer as RACVirtualizer,\n} from 'react-aria-components';\nimport { forwardRef } from '../../forward-ref.js';\nimport { useLocalizedMessages } from '../../i18n/index.js';\nimport { IconCheck, IconChevronDown } from '../../icons/index.js';\nimport { isProduction } from '../../utils/is-production.js';\nimport { useProductionWarning } from '../../utils/use-production-warning.js';\nimport { withStyleProps } from '../../with-style-props.js';\nimport { CollapsibleList } from '../internal/collapsible-list/collapsible-list.js';\nimport { FormFieldDescription, FormFieldError, FormFieldLabel } from '../internal/form-field/form-field.js';\nimport { Spinner } from '../spinner/spinner.js';\nimport type {\n ApiProps,\n AsyncItemLoadingProps,\n CollectionItem,\n CollectionProps,\n CommonProps,\n FieldWithPlaceholderProps,\n Key,\n StringLikeChildren,\n} from '../types.js';\nimport { textStyle } from '../typography/utils.js';\n\nconst VIRTUAL_LAYOUT_OPTIONS: RACListLayoutOptions = {\n rowHeight: 40,\n headingHeight: 32,\n loaderHeight: 40,\n padding: 0,\n gap: 0,\n};\n\n/** Represents the state of the `ComboBox` component for validation purposes. */\nexport interface ComboBoxValidationValue {\n /** The selected key in the ComboBox. */\n selectedKey: Key | null;\n /** The value of the ComboBox input. */\n inputValue: string;\n}\n\nexport interface ComboBoxProps<T extends CollectionItem = CollectionItem>\n extends CommonProps,\n FieldWithPlaceholderProps<ComboBoxValidationValue>,\n CollectionProps<T>,\n AsyncItemLoadingProps,\n ApiProps<ComboBoxApi>,\n Pick<\n RACComboBoxProps<T>,\n | 'isDisabled'\n | 'isRequired'\n | 'isInvalid'\n | 'isReadOnly'\n | 'selectedKey'\n | 'defaultSelectedKey'\n | 'inputValue'\n | 'defaultInputValue'\n | 'autoFocus'\n | 'onSelectionChange'\n | 'onInputChange'\n | 'onFocus'\n | 'onBlur'\n | 'onOpenChange'\n > {\n /**\n * Whether the list of options should be virtualized. Use this as a performance optimization for large lists.\n * @default false\n */\n isVirtualized?: boolean;\n /** Handler that is called when the list of items is scrolled. */\n onScroll?: UIEventHandler<HTMLDivElement>;\n}\n\n/** The imperative API exposed by the `ComboBox` component. */\nexport interface ComboBoxApi {\n /** Focuses the input field and opens the list of items. */\n focus: () => void;\n /** Selects the contents of the input field. */\n select: () => void;\n}\n\nfunction ComboBox<T extends CollectionItem>(\n {\n label,\n description,\n error,\n items,\n children,\n placeholder,\n UNSAFE_className,\n UNSAFE_style,\n isReadOnly,\n onScroll,\n isVirtualized = false,\n UNSTABLE_isLoading: isLoading,\n UNSTABLE_onLoadMore: onLoadMore,\n apiRef,\n ...props\n }: ComboBoxProps<T>,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n const inputRef = useRef<HTMLInputElement>(null);\n\n const { 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy } = props;\n\n useProductionWarning(() => {\n if (!label && !ariaLabel && !ariaLabelledBy) {\n console.warn('ComboBox requires one of label / aria-label / aria-labelledby for accessibility');\n }\n }, [label, ariaLabel, ariaLabelledBy]);\n\n if (!isProduction() && items != null && typeof children !== 'function') {\n console.warn('`ComboBox` requires `children` to be a function when using `items` prop');\n }\n\n useImperativeHandle(\n apiRef,\n () => ({\n focus: () => inputRef.current?.focus(),\n select: () => inputRef.current?.select(),\n }),\n [],\n );\n\n const listBox = (\n <ComboBoxList<T> items={items} isLoading={isLoading} onLoadMore={onLoadMore} onScroll={onScroll}>\n {children}\n </ComboBoxList>\n );\n\n return (\n <RACComboBox\n {...props}\n ref={ref}\n className={clsx('cim-combo-box', UNSAFE_className)}\n style={UNSAFE_style}\n menuTrigger=\"focus\"\n isReadOnly={isReadOnly}\n data-readonly={isReadOnly ? true : undefined}\n >\n <FormFieldLabel isRequired={props.isRequired} isDisabled={props.isDisabled}>\n {label}\n </FormFieldLabel>\n <RACGroup className=\"cim-combo-box-input-group\">\n <ComboBoxInput inputRef={inputRef} isReadOnly={isReadOnly} placeholder={placeholder} />\n <RACButton className=\"cim-combo-box-button\">\n <IconChevronDown />\n </RACButton>\n </RACGroup>\n <FormFieldError>{error}</FormFieldError>\n <FormFieldDescription>{description}</FormFieldDescription>\n <CollapsibleList\n offset={5} // 1px border + 4px actual offset\n maxHeight={315}\n >\n {isVirtualized ? (\n <RACVirtualizer layout={RACListLayout} layoutOptions={VIRTUAL_LAYOUT_OPTIONS}>\n {listBox}\n </RACVirtualizer>\n ) : (\n listBox\n )}\n </CollapsibleList>\n </RACComboBox>\n );\n}\n\n/**\n * Allows users to filter a collapsible list and select one item from it.\n *\n * See [combo box usage guidelines](https://ui.cimpress.io/components/combo-box)\n */\nconst _ComboBox = withStyleProps(forwardRef(ComboBox), 'ComboBox');\n\nexport { _ComboBox as ComboBox };\n\nfunction ComboBoxInput({\n inputRef,\n isReadOnly,\n placeholder,\n}: {\n inputRef: MutableRefObject<HTMLInputElement | null>;\n isReadOnly: boolean | undefined;\n placeholder: string | undefined;\n}) {\n const comboBoxState = useContext(RACComboBoxStateContext);\n\n return (\n <RACInput\n ref={inputRef}\n className={clsx('cim-combo-box-input', textStyle({ variant: 'body' }))}\n // Ensure the popover opens when the input is clicked.\n // By default, React Aria only opens the popover when the input is focused.\n onClick={() => !isReadOnly && comboBoxState!.open()}\n placeholder={placeholder}\n />\n );\n}\n\nfunction ComboBoxList<T extends CollectionItem = CollectionItem>({\n items,\n children,\n isLoading,\n onLoadMore,\n onScroll,\n}: Pick<ComboBoxProps<T>, 'items' | 'children' | 'onScroll'> & {\n isLoading: ComboBoxProps['UNSTABLE_isLoading'];\n onLoadMore: ComboBoxProps['UNSTABLE_onLoadMore'];\n}) {\n const comboBoxState = useContext(RACComboBoxStateContext);\n const collectionMessages = useLocalizedMessages('UNSTABLE_collection');\n\n usePreventScroll({ isDisabled: !comboBoxState?.isOpen });\n\n return (\n <RACListBox\n className=\"cim-combo-box-listbox\"\n onScroll={onScroll}\n renderEmptyState={() =>\n isLoading ? <Spinner aria-label={collectionMessages.format('loading')} size=\"small\" marginY={8} /> : null\n }\n >\n <RACCollection items={items}>{children}</RACCollection>\n <RACListBoxLoadMoreItem onLoadMore={onLoadMore} isLoading={isLoading}>\n <Spinner aria-label={collectionMessages.format('loadingMore')} size=\"small\" marginY={8} />\n </RACListBoxLoadMoreItem>\n </RACListBox>\n );\n}\n\nexport interface ComboBoxItemProps<T extends CollectionItem>\n extends Pick<RACListBoxItemProps<T>, 'isDisabled' | 'onHoverStart' | 'onHoverEnd'> {\n /** The ID of the item. Has to be unique across all sections and items. */\n id?: Key;\n /** The content to display as the label. */\n children: StringLikeChildren;\n}\n\n/** Renders a single list item within `ComboBox`. */\nexport function ComboBoxItem<T extends CollectionItem>({ children, ...props }: ComboBoxItemProps<T>) {\n const textValue =\n typeof children === 'string' ? children : typeof children === 'number' ? String(children) : children.join('');\n\n return (\n <RACListBoxItem {...props} className=\"cim-combo-box-item\" textValue={textValue}>\n {({ isDisabled }) => (\n <>\n <IconCheck />\n\n <RACText slot=\"label\" className={textStyle({ variant: 'body', tone: isDisabled ? 'muted' : 'base' })}>\n {children}\n </RACText>\n </>\n )}\n </RACListBoxItem>\n );\n}\n\nComboBoxItem.displayName = 'ComboBoxItem';\n\nexport interface ComboBoxSectionProps<T extends CollectionItem> extends CollectionProps<T> {\n /** The ID of the section. Has to be unique across all sections and items. */\n id?: Key;\n /** The content to display as the section title. */\n title: string;\n}\n\n/** Groups list items within `ComboBox` into a section. */\nexport function ComboBoxSection<T extends CollectionItem>({\n title,\n children,\n items,\n ...props\n}: ComboBoxSectionProps<T>) {\n if (!isProduction() && items != null && typeof children !== 'function') {\n console.warn('`ComboBoxSection` requires `children` to be a function when using `items` prop');\n }\n\n return (\n <RACListBoxSection {...props} className=\"cim-combo-box-section\">\n <RACHeader\n className={clsx('cim-combo-box-section-header', textStyle({ variant: 'small-semibold', tone: 'subtle' }))}\n >\n {title}\n </RACHeader>\n <RACCollection items={items}>{children}</RACCollection>\n </RACListBoxSection>\n );\n}\n\nComboBoxSection.displayName = 'ComboBoxSection';\n"]}
@@ -0,0 +1,20 @@
1
+ import type { ActionButtonProps, BaseButtonProps } from '../button/types.js';
2
+ import type { AriaLabelingProps, CommonProps, StringLikeChildren } from '../types.js';
3
+ export interface UNSTABLE_CopyButtonProps extends CommonProps, AriaLabelingProps, Pick<BaseButtonProps, 'size'>, Pick<ActionButtonProps, 'isDisabled' | 'onHoverStart' | 'onHoverEnd'> {
4
+ /** The text displayed on the button. */
5
+ children?: StringLikeChildren;
6
+ /**
7
+ * Determines the visual appearance of the button.
8
+ * @default 'secondary'
9
+ */
10
+ variant?: 'secondary' | 'tertiary';
11
+ /** The content to be copied. */
12
+ value: string;
13
+ /** The help text that appears in a tooltip when the user hovers or focuses the button. */
14
+ helpText?: string;
15
+ /** A handler that gets called when the user triggers the copying. */
16
+ onCopy?: () => void;
17
+ }
18
+ declare const _UNSTABLE_CopyButton: (props: UNSTABLE_CopyButtonProps & import("react").RefAttributes<HTMLButtonElement> & import("../../with-style-props.js").StyleProps) => import("react").JSX.Element | null;
19
+ export { _UNSTABLE_CopyButton as UNSTABLE_CopyButton };
20
+ //# sourceMappingURL=copy-button.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copy-button.d.ts","sourceRoot":"","sources":["../../../../src/components/copy/copy-button.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE7E,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGtF,MAAM,WAAW,wBACf,SAAQ,WAAW,EACjB,iBAAiB,EACjB,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC,EAC7B,IAAI,CAAC,iBAAiB,EAAE,YAAY,GAAG,cAAc,GAAG,YAAY,CAAC;IACvE,wCAAwC;IACxC,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAC9B;;;OAGG;IACH,OAAO,CAAC,EAAE,WAAW,GAAG,UAAU,CAAC;IACnC,gCAAgC;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,0FAA0F;IAC1F,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qEAAqE;IACrE,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;CACrB;AAyDD,QAAA,MAAM,oBAAoB,6KAAgE,CAAC;AAE3F,OAAO,EAAE,oBAAoB,IAAI,mBAAmB,EAAE,CAAC"}
@@ -0,0 +1,65 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useContext, useEffect, useState } from 'react';
4
+ import { TooltipTriggerStateContext as RACTooltipTriggerStateContext } from 'react-aria-components';
5
+ import { forwardRef } from '../../forward-ref.js';
6
+ import { IconCheckCircle, IconCopy } from '../../icons/index.js';
7
+ import { useProductionWarning } from '../../utils/use-production-warning.js';
8
+ import { withStyleProps } from '../../with-style-props.js';
9
+ import { Button } from '../button/button.js';
10
+ import { IconButton } from '../button/icon-button.js';
11
+ import { Tooltip } from '../tooltip/tooltip.js';
12
+ import { useCopyToClipboard } from './use-copy.js';
13
+ function UNSTABLE_CopyButton({ onCopy, helpText, ...props }, ref) {
14
+ const [copyStatus, showCopyFeedback, copyToClipboard] = useCopyToClipboard();
15
+ const [showCopyFeedbackLabel, setShowCopyFeedbackLabel] = useState(showCopyFeedback);
16
+ useEffect(() => {
17
+ let labelChangeTimeout;
18
+ if (showCopyFeedback) {
19
+ setShowCopyFeedbackLabel(true);
20
+ }
21
+ else {
22
+ // Wait until the tooltip has animated away before changing the label
23
+ labelChangeTimeout = setTimeout(() => setShowCopyFeedbackLabel(false), 200);
24
+ }
25
+ return () => {
26
+ if (labelChangeTimeout) {
27
+ clearTimeout(labelChangeTimeout);
28
+ }
29
+ };
30
+ }, [showCopyFeedback]);
31
+ const { children, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy } = props;
32
+ useProductionWarning(() => {
33
+ if (!children && !ariaLabel && !ariaLabelledBy) {
34
+ console.warn('CopyButton requires one of children / aria-label / aria-labelledby for accessibility');
35
+ }
36
+ }, [children, ariaLabel, ariaLabelledBy]);
37
+ const onPress = () => {
38
+ copyToClipboard(props.value);
39
+ onCopy?.();
40
+ };
41
+ return (_jsx(Tooltip, { isDisabled: props.isDisabled || (!showCopyFeedback && !helpText), label: showCopyFeedbackLabel
42
+ ? copyStatus?.success
43
+ ? // TODO: i18n
44
+ 'Copied to clipboard.'
45
+ : 'Failed to copy to clipboard.'
46
+ : (helpText ?? ''), placement: "top", children: _jsx(CopyButtonInner, { ...props, buttonRef: ref, onCopy: onPress, showCopyFeedback: showCopyFeedback }) }));
47
+ }
48
+ const _UNSTABLE_CopyButton = withStyleProps(forwardRef(UNSTABLE_CopyButton), 'CopyButton');
49
+ export { _UNSTABLE_CopyButton as UNSTABLE_CopyButton };
50
+ // eslint-disable-next-line react-refresh/only-export-components
51
+ function CopyButtonInner({ UNSAFE_className, UNSAFE_style, children, value, onCopy, buttonRef, showCopyFeedback, ...props }) {
52
+ const tooltipTriggerState = useContext(RACTooltipTriggerStateContext);
53
+ const icon = showCopyFeedback ? _jsx(IconCheckCircle, {}) : _jsx(IconCopy, {});
54
+ useEffect(() => {
55
+ if (showCopyFeedback) {
56
+ tooltipTriggerState?.open(true);
57
+ }
58
+ else {
59
+ tooltipTriggerState?.close(true);
60
+ }
61
+ // eslint-disable-next-line react-hooks/exhaustive-deps
62
+ }, [showCopyFeedback]);
63
+ return children ? (_jsx(Button, { ...props, ref: buttonRef, iconStart: icon, tone: "base", onPress: onCopy, children: children })) : (_jsx(IconButton, { ...props, ref: buttonRef, icon: icon, tone: "base", "aria-label": props['aria-label'] ?? '', onPress: onCopy }));
64
+ }
65
+ //# sourceMappingURL=copy-button.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copy-button.js","sourceRoot":"","sources":["../../../../src/components/copy/copy-button.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAqB,MAAM,OAAO,CAAC;AAC3E,OAAO,EAAE,0BAA0B,IAAI,6BAA6B,EAA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AM,IAAI,GAAG,gBAAgB,CAAC,CAAC,CAAC,KAAC,eAAe,KAAG,CAAC,CAAC,CAAC,KAAC,QAAQ,KAAG,CAAC;IAEnE,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,gBAAgB,EAAE,CAAC;YACrB,mBAAmB,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAClC,CAAC;aAAM,CAAC;YACN,mBAAmB,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QACnC,CAAC;QACD,uDAAuD;IACzD,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAEvB,OAAO,QAAQ,CAAC,CAAC,CAAC,CAChB,KAAC,MAAM,OAAK,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAC,MAAM,EAAC,OAAO,EAAE,MAAM,YAC5E,QAAQ,GACF,CACV,CAAC,CAAC,CAAC,CACF,KAAC,UAAU,OACL,KAAK,EACT,GAAG,EAAE,SAAS,EACd,IAAI,EAAE,IAAI,EACV,IAAI,EAAC,MAAM,gBACC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,EACrC,OAAO,EAAE,MAAM,GACf,CACH,CAAC;AACJ,CAAC","sourcesContent":["'use client';\n\nimport { useContext, useEffect, useState, type ForwardedRef } from 'react';\nimport { TooltipTriggerStateContext as RACTooltipTriggerStateContext } from 'react-aria-components';\nimport { forwardRef } from '../../forward-ref.js';\nimport { IconCheckCircle, IconCopy } from '../../icons/index.js';\nimport { useProductionWarning } from '../../utils/use-production-warning.js';\nimport { withStyleProps } from '../../with-style-props.js';\nimport { Button } from '../button/button.js';\nimport { IconButton } from '../button/icon-button.js';\nimport type { ActionButtonProps, BaseButtonProps } from '../button/types.js';\nimport { Tooltip } from '../tooltip/tooltip.js';\nimport type { AriaLabelingProps, CommonProps, StringLikeChildren } from '../types.js';\nimport { useCopyToClipboard } from './use-copy.js';\n\nexport interface UNSTABLE_CopyButtonProps\n extends CommonProps,\n AriaLabelingProps,\n Pick<BaseButtonProps, 'size'>,\n Pick<ActionButtonProps, 'isDisabled' | 'onHoverStart' | 'onHoverEnd'> {\n /** The text displayed on the button. */\n children?: StringLikeChildren;\n /**\n * Determines the visual appearance of the button.\n * @default 'secondary'\n */\n variant?: 'secondary' | 'tertiary';\n /** The content to be copied. */\n value: string;\n /** The help text that appears in a tooltip when the user hovers or focuses the button. */\n helpText?: string;\n /** A handler that gets called when the user triggers the copying. */\n onCopy?: () => void;\n}\n\nfunction UNSTABLE_CopyButton(\n { onCopy, helpText, ...props }: UNSTABLE_CopyButtonProps,\n ref: ForwardedRef<HTMLButtonElement>,\n) {\n const [copyStatus, showCopyFeedback, copyToClipboard] = useCopyToClipboard();\n const [showCopyFeedbackLabel, setShowCopyFeedbackLabel] = useState(showCopyFeedback);\n\n useEffect(() => {\n let labelChangeTimeout: ReturnType<typeof setTimeout> | undefined;\n\n if (showCopyFeedback) {\n setShowCopyFeedbackLabel(true);\n } else {\n // Wait until the tooltip has animated away before changing the label\n labelChangeTimeout = setTimeout(() => setShowCopyFeedbackLabel(false), 200);\n }\n\n return () => {\n if (labelChangeTimeout) {\n clearTimeout(labelChangeTimeout);\n }\n };\n }, [showCopyFeedback]);\n\n const { children, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy } = props;\n\n useProductionWarning(() => {\n if (!children && !ariaLabel && !ariaLabelledBy) {\n console.warn('CopyButton requires one of children / aria-label / aria-labelledby for accessibility');\n }\n }, [children, ariaLabel, ariaLabelledBy]);\n\n const onPress = () => {\n copyToClipboard(props.value);\n onCopy?.();\n };\n\n return (\n <Tooltip\n isDisabled={props.isDisabled || (!showCopyFeedback && !helpText)}\n label={\n showCopyFeedbackLabel\n ? copyStatus?.success\n ? // TODO: i18n\n 'Copied to clipboard.'\n : 'Failed to copy to clipboard.'\n : (helpText ?? '')\n }\n placement=\"top\"\n >\n <CopyButtonInner {...props} buttonRef={ref} onCopy={onPress} showCopyFeedback={showCopyFeedback} />\n </Tooltip>\n );\n}\n\nconst _UNSTABLE_CopyButton = withStyleProps(forwardRef(UNSTABLE_CopyButton), 'CopyButton');\n\nexport { _UNSTABLE_CopyButton as UNSTABLE_CopyButton };\n\n// eslint-disable-next-line react-refresh/only-export-components\nfunction CopyButtonInner({\n UNSAFE_className,\n UNSAFE_style,\n children,\n value,\n onCopy,\n buttonRef,\n showCopyFeedback,\n ...props\n}: Omit<UNSTABLE_CopyButtonProps, 'helpText'> & {\n buttonRef: ForwardedRef<HTMLButtonElement>;\n showCopyFeedback: boolean;\n}) {\n const tooltipTriggerState = useContext(RACTooltipTriggerStateContext);\n\n const icon = showCopyFeedback ? <IconCheckCircle /> : <IconCopy />;\n\n useEffect(() => {\n if (showCopyFeedback) {\n tooltipTriggerState?.open(true);\n } else {\n tooltipTriggerState?.close(true);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [showCopyFeedback]);\n\n return children ? (\n <Button {...props} ref={buttonRef} iconStart={icon} tone=\"base\" onPress={onCopy}>\n {children}\n </Button>\n ) : (\n <IconButton\n {...props}\n ref={buttonRef}\n icon={icon}\n tone=\"base\"\n aria-label={props['aria-label'] ?? ''}\n onPress={onCopy}\n />\n );\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import type { ActionButtonProps } from '../button/types.js';
2
+ import type { AriaLabelingProps, CommonProps, StringLikeChildren } from '../types.js';
3
+ import type { TextStyleOptions } from '../typography/types.js';
4
+ export interface UNSTABLE_InlineCopyProps extends CommonProps, AriaLabelingProps, Pick<TextStyleOptions, 'variant' | 'tone' | 'fontStyle'>, Pick<ActionButtonProps, 'isDisabled' | 'onHoverStart' | 'onHoverEnd'> {
5
+ /** The content to be copied. */
6
+ children: StringLikeChildren;
7
+ /** A handler that gets called when the user triggers the copying. */
8
+ onCopy?: () => void;
9
+ }
10
+ declare const _UNSTABLE_InlineCopy: (props: UNSTABLE_InlineCopyProps & import("react").RefAttributes<HTMLButtonElement> & import("../../with-style-props.js").StyleProps) => import("react").JSX.Element | null;
11
+ export { _UNSTABLE_InlineCopy as UNSTABLE_InlineCopy };
12
+ //# sourceMappingURL=inline-copy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline-copy.d.ts","sourceRoot":"","sources":["../../../../src/components/copy/inline-copy.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAO/D,MAAM,WAAW,wBACf,SAAQ,WAAW,EACjB,iBAAiB,EACjB,IAAI,CAAC,gBAAgB,EAAE,SAAS,GAAG,MAAM,GAAG,WAAW,CAAC,EACxD,IAAI,CAAC,iBAAiB,EAAE,YAAY,GAAG,cAAc,GAAG,YAAY,CAAC;IACvE,gCAAgC;IAChC,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,qEAAqE;IACrE,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;CACrB;AAyCD,QAAA,MAAM,oBAAoB,6KAAgE,CAAC;AAE3F,OAAO,EAAE,oBAAoB,IAAI,mBAAmB,EAAE,CAAC"}
@@ -0,0 +1,27 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import clsx from 'clsx';
4
+ import { useRef } from 'react';
5
+ import { Button as RACButton } from 'react-aria-components';
6
+ import { forwardRef } from '../../forward-ref.js';
7
+ import { IconCheckCircle, IconCopy } from '../../icons/index.js';
8
+ import { withStyleProps } from '../../with-style-props.js';
9
+ import { Tooltip } from '../tooltip/tooltip.js';
10
+ import { textStyle } from '../typography/utils.js';
11
+ import { useCopyToClipboard } from './use-copy.js';
12
+ // Used to prevent word wrap between icons and text
13
+ const WORD_JOINER = '\u2060';
14
+ function UNSTABLE_InlineCopy({ children, UNSAFE_className, UNSAFE_style, variant, tone, fontStyle, onCopy, ...props }, ref) {
15
+ const tooltipTriggerRef = useRef(null);
16
+ const [copyStatus, showCopyFeedback, copyToClipboard] = useCopyToClipboard();
17
+ const textValue = typeof children === 'string' ? children : typeof children === 'number' ? String(children) : children.join('');
18
+ return (_jsx(Tooltip, { isOpen: showCopyFeedback, isDisabled: props.isDisabled,
19
+ // TODO: i18n
20
+ label: copyStatus?.success ? 'Copied to clipboard.' : 'Failed to copy to clipboard.', placement: "top", triggerRef: tooltipTriggerRef, children: _jsxs(RACButton, { ...props, ref: ref, className: clsx('cim-inline-copy', textStyle({ variant, tone, fontStyle }), UNSAFE_className), style: UNSAFE_style, onPress: () => {
21
+ copyToClipboard(textValue);
22
+ onCopy?.();
23
+ }, children: [_jsx("span", { className: "cim-inline-copy-text", children: children }), WORD_JOINER, _jsx("span", { className: "cim-inline-copy-icon", ref: tooltipTriggerRef, children: showCopyFeedback ? _jsx(IconCheckCircle, {}) : _jsx(IconCopy, {}) })] }) }));
24
+ }
25
+ const _UNSTABLE_InlineCopy = withStyleProps(forwardRef(UNSTABLE_InlineCopy), 'InlineCopy');
26
+ export { _UNSTABLE_InlineCopy as UNSTABLE_InlineCopy };
27
+ //# sourceMappingURL=inline-copy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline-copy.js","sourceRoot":"","sources":["../../../../src/components/copy/inline-copy.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,EAAqB,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,OAAO,EAAE,OAAO,EAAE,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AAE,CAAC;YACb,CAAC,aAED,eAAM,SAAS,EAAC,sBAAsB,YAAE,QAAQ,GAAQ,EACvD,WAAW,EACZ,eAAM,SAAS,EAAC,sBAAsB,EAAC,GAAG,EAAE,iBAAiB,YAC1D,gBAAgB,CAAC,CAAC,CAAC,KAAC,eAAe,KAAG,CAAC,CAAC,CAAC,KAAC,QAAQ,KAAG,GACjD,IACG,GACJ,CACX,CAAC;AACJ,CAAC;AAED,MAAM,oBAAoB,GAAG,cAAc,CAAC,UAAU,CAAC,mBAAmB,CAAC,EAAE,YAAY,CAAC,CAAC;AAE3F,OAAO,EAAE,oBAAoB,IAAI,mBAAmB,EAAE,CAAC","sourcesContent":["'use client';\n\nimport clsx from 'clsx';\nimport { useRef, type ForwardedRef } from 'react';\nimport { Button as RACButton } from 'react-aria-components';\nimport { forwardRef } from '../../forward-ref.js';\nimport { IconCheckCircle, IconCopy } from '../../icons/index.js';\nimport { withStyleProps } from '../../with-style-props.js';\nimport type { ActionButtonProps } from '../button/types.js';\nimport { Tooltip } from '../tooltip/tooltip.js';\nimport type { AriaLabelingProps, CommonProps, StringLikeChildren } from '../types.js';\nimport type { TextStyleOptions } from '../typography/types.js';\nimport { textStyle } from '../typography/utils.js';\nimport { useCopyToClipboard } from './use-copy.js';\n\n// Used to prevent word wrap between icons and text\nconst WORD_JOINER = '\\u2060';\n\nexport interface UNSTABLE_InlineCopyProps\n extends CommonProps,\n AriaLabelingProps,\n Pick<TextStyleOptions, 'variant' | 'tone' | 'fontStyle'>,\n Pick<ActionButtonProps, 'isDisabled' | 'onHoverStart' | 'onHoverEnd'> {\n /** The content to be copied. */\n children: StringLikeChildren;\n /** A handler that gets called when the user triggers the copying. */\n onCopy?: () => void;\n}\n\nfunction UNSTABLE_InlineCopy(\n { children, UNSAFE_className, UNSAFE_style, variant, tone, fontStyle, onCopy, ...props }: UNSTABLE_InlineCopyProps,\n ref: ForwardedRef<HTMLButtonElement>,\n) {\n const tooltipTriggerRef = useRef<HTMLSpanElement>(null);\n const [copyStatus, showCopyFeedback, copyToClipboard] = useCopyToClipboard();\n\n const textValue =\n typeof children === 'string' ? children : typeof children === 'number' ? String(children) : children.join('');\n\n return (\n <Tooltip\n isOpen={showCopyFeedback}\n isDisabled={props.isDisabled}\n // TODO: i18n\n label={copyStatus?.success ? 'Copied to clipboard.' : 'Failed to copy to clipboard.'}\n placement=\"top\"\n triggerRef={tooltipTriggerRef}\n >\n <RACButton\n {...props}\n ref={ref}\n className={clsx('cim-inline-copy', textStyle({ variant, tone, fontStyle }), UNSAFE_className)}\n style={UNSAFE_style}\n onPress={() => {\n copyToClipboard(textValue);\n onCopy?.();\n }}\n >\n <span className=\"cim-inline-copy-text\">{children}</span>\n {WORD_JOINER}\n <span className=\"cim-inline-copy-icon\" ref={tooltipTriggerRef}>\n {showCopyFeedback ? <IconCheckCircle /> : <IconCopy />}\n </span>\n </RACButton>\n </Tooltip>\n );\n}\n\nconst _UNSTABLE_InlineCopy = withStyleProps(forwardRef(UNSTABLE_InlineCopy), 'InlineCopy');\n\nexport { _UNSTABLE_InlineCopy as UNSTABLE_InlineCopy };\n"]}
@@ -0,0 +1,10 @@
1
+ export interface CopyStatus {
2
+ success: boolean;
3
+ timestamp: number;
4
+ }
5
+ export declare function useCopyToClipboard(): [
6
+ copyStatus: CopyStatus | undefined,
7
+ showCopyFeedback: boolean,
8
+ copyToClipboard: (text: string) => void
9
+ ];
10
+ //# sourceMappingURL=use-copy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-copy.d.ts","sourceRoot":"","sources":["../../../../src/components/copy/use-copy.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,kBAAkB,IAAI;IACpC,UAAU,EAAE,UAAU,GAAG,SAAS;IAClC,gBAAgB,EAAE,OAAO;IACzB,eAAe,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI;CACxC,CA2BA"}
@@ -0,0 +1,27 @@
1
+ import { useCallback, useRef, useState } from 'react';
2
+ export function useCopyToClipboard() {
3
+ const [copyStatus, setCopyStatus] = useState(undefined);
4
+ const [showCopyFeedback, setShowCopyFeedback] = useState(false);
5
+ const timeoutRef = useRef(undefined);
6
+ const copyToClipboard = useCallback((text) => {
7
+ setCopyStatus(undefined);
8
+ setShowCopyFeedback(false);
9
+ clearTimeout(timeoutRef.current);
10
+ navigator.clipboard
11
+ .writeText(text)
12
+ .then(() => {
13
+ setCopyStatus({ success: true, timestamp: Date.now() });
14
+ })
15
+ .catch(() => {
16
+ setCopyStatus({ success: false, timestamp: Date.now() });
17
+ })
18
+ .finally(() => {
19
+ setShowCopyFeedback(true);
20
+ timeoutRef.current = setTimeout(() => {
21
+ setShowCopyFeedback(false);
22
+ }, 2000);
23
+ });
24
+ }, []);
25
+ return [copyStatus, showCopyFeedback, copyToClipboard];
26
+ }
27
+ //# sourceMappingURL=use-copy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-copy.js","sourceRoot":"","sources":["../../../../src/components/copy/use-copy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAOtD,MAAM,UAAU,kBAAkB;IAKhC,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAyB,SAAS,CAAC,CAAC;IAChF,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChE,MAAM,UAAU,GAAG,MAAM,CAA4C,SAAS,CAAC,CAAC;IAEhF,MAAM,eAAe,GAAG,WAAW,CAAC,CAAC,IAAY,EAAE,EAAE;QACnD,aAAa,CAAC,SAAS,CAAC,CAAC;QACzB,mBAAmB,CAAC,KAAK,CAAC,CAAC;QAC3B,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAEjC,SAAS,CAAC,SAAS;aAChB,SAAS,CAAC,IAAI,CAAC;aACf,IAAI,CAAC,GAAG,EAAE;YACT,aAAa,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAC1D,CAAC,CAAC;aACD,KAAK,CAAC,GAAG,EAAE;YACV,aAAa,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAC3D,CAAC,CAAC;aACD,OAAO,CAAC,GAAG,EAAE;YACZ,mBAAmB,CAAC,IAAI,CAAC,CAAC;YAC1B,UAAU,CAAC,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;gBACnC,mBAAmB,CAAC,KAAK,CAAC,CAAC;YAC7B,CAAC,EAAE,IAAI,CAAC,CAAC;QACX,CAAC,CAAC,CAAC;IACP,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CAAC,UAAU,EAAE,gBAAgB,EAAE,eAAe,CAAC,CAAC;AACzD,CAAC","sourcesContent":["import { useCallback, useRef, useState } from 'react';\n\nexport interface CopyStatus {\n success: boolean;\n timestamp: number;\n}\n\nexport function useCopyToClipboard(): [\n copyStatus: CopyStatus | undefined,\n showCopyFeedback: boolean,\n copyToClipboard: (text: string) => void,\n] {\n const [copyStatus, setCopyStatus] = useState<CopyStatus | undefined>(undefined);\n const [showCopyFeedback, setShowCopyFeedback] = useState(false);\n const timeoutRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n\n const copyToClipboard = useCallback((text: string) => {\n setCopyStatus(undefined);\n setShowCopyFeedback(false);\n clearTimeout(timeoutRef.current);\n\n navigator.clipboard\n .writeText(text)\n .then(() => {\n setCopyStatus({ success: true, timestamp: Date.now() });\n })\n .catch(() => {\n setCopyStatus({ success: false, timestamp: Date.now() });\n })\n .finally(() => {\n setShowCopyFeedback(true);\n timeoutRef.current = setTimeout(() => {\n setShowCopyFeedback(false);\n }, 2000);\n });\n }, []);\n\n return [copyStatus, showCopyFeedback, copyToClipboard];\n}\n"]}
@@ -1,11 +1,16 @@
1
1
  import type { CalendarDate, CalendarDateTime, ZonedDateTime } from '@internationalized/date';
2
2
  import { type CalendarProps as RACCalendarProps, type DatePickerProps as RACDatePickerProps } from 'react-aria-components';
3
- import type { CommonProps, FieldProps } from '../types.js';
3
+ import type { ApiProps, CommonProps, FieldProps } from '../types.js';
4
4
  /** Represents a date with optional time and timezone components. */
5
5
  export type DateValue = CalendarDate | CalendarDateTime | ZonedDateTime;
6
6
  /** Maps a date value to a specific subtype depending on which components it contains. */
7
7
  export type MappedDateValue<T> = T extends ZonedDateTime ? ZonedDateTime : T extends CalendarDateTime ? CalendarDateTime : T extends CalendarDate ? CalendarDate : never;
8
- export interface DatePickerProps<T extends DateValue> extends CommonProps, FieldProps<MappedDateValue<T>>, Pick<RACDatePickerProps<T>, 'value' | 'defaultValue' | 'placeholderValue' | 'onChange' | 'isDisabled' | 'isRequired' | 'isInvalid' | 'isReadOnly' | 'autoFocus' | 'onFocus' | 'onBlur' | 'isOpen' | 'defaultOpen' | 'onOpenChange' | 'minValue' | 'maxValue' | 'isDateUnavailable' | 'granularity' | 'firstDayOfWeek' | 'autoComplete'>, Pick<RACCalendarProps<T>, 'focusedValue' | 'defaultFocusedValue'> {
8
+ export interface DatePickerProps<T extends DateValue> extends CommonProps, FieldProps<MappedDateValue<T>>, ApiProps<DatePickerApi>, Pick<RACDatePickerProps<T>, 'value' | 'defaultValue' | 'placeholderValue' | 'onChange' | 'isDisabled' | 'isRequired' | 'isInvalid' | 'isReadOnly' | 'autoFocus' | 'onFocus' | 'onBlur' | 'isOpen' | 'defaultOpen' | 'onOpenChange' | 'minValue' | 'maxValue' | 'isDateUnavailable' | 'granularity' | 'firstDayOfWeek' | 'autoComplete'>, Pick<RACCalendarProps<T>, 'focusedValue' | 'defaultFocusedValue'> {
9
+ }
10
+ /** The imperative API exposed by the `DatePicker` component. */
11
+ export interface DatePickerApi {
12
+ /** Focuses the first editable segment in the input field. */
13
+ focus: () => void;
9
14
  }
10
15
  /**
11
16
  * Allows users to enter or select a date and time value.
@@ -1 +1 @@
1
- {"version":3,"file":"date-picker.d.ts","sourceRoot":"","sources":["../../../../src/components/date-picker/date-picker.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAG7F,OAAO,EACL,KAAK,aAAa,IAAI,gBAAgB,EAGtC,KAAK,eAAe,IAAI,kBAAkB,EAM3C,MAAM,uBAAuB,CAAC;AAQ/B,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAI3D,oEAAoE;AACpE,MAAM,MAAM,SAAS,GAAG,YAAY,GAAG,gBAAgB,GAAG,aAAa,CAAC;AAExE,yFAAyF;AACzF,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,CAAC,SAAS,aAAa,GACpD,aAAa,GACb,CAAC,SAAS,gBAAgB,GACxB,gBAAgB,GAChB,CAAC,SAAS,YAAY,GACpB,YAAY,GACZ,KAAK,CAAC;AAEd,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,SAAS,CAClD,SAAQ,WAAW,EACjB,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,EAC9B,IAAI,CACF,kBAAkB,CAAC,CAAC,CAAC,EACnB,OAAO,GACP,cAAc,GACd,kBAAkB,GAClB,UAAU,GACV,YAAY,GACZ,YAAY,GACZ,WAAW,GACX,YAAY,GACZ,WAAW,GACX,SAAS,GACT,QAAQ,GACR,QAAQ,GACR,aAAa,GACb,cAAc,GACd,UAAU,GACV,UAAU,GACV,mBAAmB,GACnB,aAAa,GACb,gBAAgB,GAChB,cAAc,CACjB,EACD,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,cAAc,GAAG,qBAAqB,CAAC;CAAG;AAqExE;;;;GAIG;AACH,QAAA,MAAM,WAAW,GAxEG,CAAC,SAAS,SAAS,mKAwEiC,CAAC;AAEzE,OAAO,EAAE,WAAW,IAAI,UAAU,EAAE,CAAC"}
1
+ {"version":3,"file":"date-picker.d.ts","sourceRoot":"","sources":["../../../../src/components/date-picker/date-picker.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAG7F,OAAO,EACL,KAAK,aAAa,IAAI,gBAAgB,EAGtC,KAAK,eAAe,IAAI,kBAAkB,EAM3C,MAAM,uBAAuB,CAAC;AAQ/B,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAoB,MAAM,aAAa,CAAC;AAIvF,oEAAoE;AACpE,MAAM,MAAM,SAAS,GAAG,YAAY,GAAG,gBAAgB,GAAG,aAAa,CAAC;AAExE,yFAAyF;AACzF,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,CAAC,SAAS,aAAa,GACpD,aAAa,GACb,CAAC,SAAS,gBAAgB,GACxB,gBAAgB,GAChB,CAAC,SAAS,YAAY,GACpB,YAAY,GACZ,KAAK,CAAC;AAEd,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,SAAS,CAClD,SAAQ,WAAW,EACjB,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,EAC9B,QAAQ,CAAC,aAAa,CAAC,EACvB,IAAI,CACF,kBAAkB,CAAC,CAAC,CAAC,EACnB,OAAO,GACP,cAAc,GACd,kBAAkB,GAClB,UAAU,GACV,YAAY,GACZ,YAAY,GACZ,WAAW,GACX,YAAY,GACZ,WAAW,GACX,SAAS,GACT,QAAQ,GACR,QAAQ,GACR,aAAa,GACb,cAAc,GACd,UAAU,GACV,UAAU,GACV,mBAAmB,GACnB,aAAa,GACb,gBAAgB,GAChB,cAAc,CACjB,EACD,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,cAAc,GAAG,qBAAqB,CAAC;CAAG;AAExE,gEAAgE;AAChE,MAAM,WAAW,aAAa;IAC5B,6DAA6D;IAC7D,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAiFD;;;;GAIG;AACH,QAAA,MAAM,WAAW,GApFG,CAAC,SAAS,SAAS,mKAoFiC,CAAC;AAEzE,OAAO,EAAE,WAAW,IAAI,UAAU,EAAE,CAAC"}
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import clsx from 'clsx';
4
- import { useContext } from 'react';
4
+ import { useContext, useImperativeHandle, useRef } from 'react';
5
5
  import { DateInput as RACDateInput, DatePicker as RACDatePicker, DatePickerStateContext as RACDatePickerStateContext, DateSegment as RACDateSegment, Dialog as RACDialog, Group as RACGroup, Popover as RACPopover, } from 'react-aria-components';
6
6
  import { forwardRef } from '../../forward-ref.js';
7
7
  import { useLocalizedMessages } from '../../i18n/index.js';
@@ -12,7 +12,8 @@ import { IconButton } from '../button/icon-button.js';
12
12
  import { FormFieldDescription, FormFieldError, FormFieldLabel } from '../internal/form-field/form-field.js';
13
13
  import { textStyle } from '../typography/utils.js';
14
14
  import { DatePickerCalendar } from './date-picker-calendar.js';
15
- function DatePicker({ label, description, error: errorMessage, focusedValue, defaultFocusedValue, UNSAFE_className, UNSAFE_style, ...props }, ref) {
15
+ function DatePicker({ label, description, error: errorMessage, focusedValue, defaultFocusedValue, UNSAFE_className, UNSAFE_style, apiRef, ...props }, ref) {
16
+ const inputRef = useRef(null);
16
17
  const { 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy } = props;
17
18
  useProductionWarning(() => {
18
19
  if (!label && !ariaLabel && !ariaLabelledBy) {
@@ -20,7 +21,10 @@ function DatePicker({ label, description, error: errorMessage, focusedValue, def
20
21
  }
21
22
  }, [label, ariaLabel, ariaLabelledBy]);
22
23
  const messages = useLocalizedMessages('datePicker');
23
- return (_jsxs(RACDatePicker, { ...props, ref: ref, className: clsx('cim-date-picker', UNSAFE_className), style: UNSAFE_style, children: [_jsx(FormFieldLabel, { isRequired: props.isRequired, isDisabled: props.isDisabled, children: label }), _jsxs(RACGroup, { className: "cim-date-picker-input-group", "data-readonly": props.isReadOnly || undefined, children: [_jsx(RACDateInput, { className: clsx('cim-date-picker-input', textStyle({ variant: 'body' })), children: (segment) => (_jsx("span", { className: "cim-date-picker-segment-wrapper", children: _jsx(RACDateSegment, { segment: segment }) })) }), _jsxs("div", { className: "cim-date-picker-input-controls", children: [_jsx(DatePickerClearButton, { isDisabled: props.isDisabled || props.isReadOnly }), _jsx(IconButton, { icon: _jsx(IconCalendarEmpty, {}), "aria-label": messages.format('openCalendar'), variant: "tertiary", size: "small" })] })] }), _jsx(FormFieldError, { children: errorMessage }), _jsx(FormFieldDescription, { children: description }), _jsx(RACPopover, { className: "cim-date-picker-popover", placement: "bottom end", offset: 5, containerPadding: 16, "data-cim-style-root": true, children: _jsx(RACDialog, { children: _jsx(DatePickerCalendar, { focusedValue: focusedValue, defaultFocusedValue: defaultFocusedValue, placeholderValue: props.placeholderValue }) }) })] }));
24
+ useImperativeHandle(apiRef, () => ({
25
+ focus: () => inputRef.current?.querySelector('[role=spinbutton]:not([data-disabled])')?.focus(),
26
+ }), []);
27
+ return (_jsxs(RACDatePicker, { ...props, ref: ref, className: clsx('cim-date-picker', UNSAFE_className), style: UNSAFE_style, children: [_jsx(FormFieldLabel, { isRequired: props.isRequired, isDisabled: props.isDisabled, children: label }), _jsxs(RACGroup, { className: "cim-date-picker-input-group", "data-readonly": props.isReadOnly || undefined, children: [_jsx(RACDateInput, { ref: inputRef, className: clsx('cim-date-picker-input', textStyle({ variant: 'body' })), children: (segment) => (_jsx("span", { className: "cim-date-picker-segment-wrapper", children: _jsx(RACDateSegment, { segment: segment }) })) }), _jsxs("div", { className: "cim-date-picker-input-controls", children: [_jsx(DatePickerClearButton, { isDisabled: props.isDisabled || props.isReadOnly }), _jsx(IconButton, { icon: _jsx(IconCalendarEmpty, {}), "aria-label": messages.format('openCalendar'), variant: "tertiary", size: "small" })] })] }), _jsx(FormFieldError, { children: errorMessage }), _jsx(FormFieldDescription, { children: description }), _jsx(RACPopover, { className: "cim-date-picker-popover", placement: "bottom end", offset: 5, containerPadding: 16, "data-cim-style-root": true, children: _jsx(RACDialog, { children: _jsx(DatePickerCalendar, { focusedValue: focusedValue, defaultFocusedValue: defaultFocusedValue, placeholderValue: props.placeholderValue }) }) })] }));
24
28
  }
25
29
  /**
26
30
  * Allows users to enter or select a date and time value.
@@ -1 +1 @@
1
- {"version":3,"file":"date-picker.js","sourceRoot":"","sources":["../../../../src/components/date-picker/date-picker.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAGb,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAqB,MAAM,OAAO,CAAC;AACtD,OAAO,EAEL,SAAS,IAAI,YAAY,EACzB,UAAU,IAAI,aAAa,EAE3B,sBAAsB,IAAI,yBAAyB,EACnD,WAAW,IAAI,cAAc,EAC7B,MAAM,IAAI,SAAS,EACnB,KAAK,IAAI,QAAQ,EACjB,OAAO,IAAI,UAAU,GACtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AAE5G,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAA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,EAC3B,OAAO,EAAC,UAAU,EAClB,IAAI,EAAC,OAAO,EACZ,UAAU,EAAE,UAAU,GACtB,CACH,CAAC;AACJ,CAAC;AAED,iEAAiE;AACjE,SAAS,iBAAiB;IACxB,OAAO,CACL,cAAK,OAAO,EAAC,WAAW,EAAC,KAAK,EAAC,4BAA4B,EAAC,SAAS,EAAC,UAAU,EAAC,IAAI,EAAC,cAAc,+BAClG,eACE,QAAQ,EAAC,SAAS,EAClB,QAAQ,EAAC,SAAS,EAClB,CAAC,EAAC,2hBAA2hB,GAC7hB,GACE,CACP,CAAC;AACJ,CAAC","sourcesContent":["'use client';\n\nimport type { CalendarDate, CalendarDateTime, ZonedDateTime } from '@internationalized/date';\nimport clsx from 'clsx';\nimport { useContext, type ForwardedRef } from 'react';\nimport {\n type CalendarProps as RACCalendarProps,\n DateInput as RACDateInput,\n DatePicker as RACDatePicker,\n type DatePickerProps as RACDatePickerProps,\n DatePickerStateContext as RACDatePickerStateContext,\n DateSegment as RACDateSegment,\n Dialog as RACDialog,\n Group as RACGroup,\n Popover as RACPopover,\n} from 'react-aria-components';\nimport { forwardRef } from '../../forward-ref.js';\nimport { useLocalizedMessages } from '../../i18n/index.js';\nimport { IconCalendarEmpty } from '../../icons/index.js';\nimport { useProductionWarning } from '../../utils/use-production-warning.js';\nimport { withStyleProps } from '../../with-style-props.js';\nimport { IconButton } from '../button/icon-button.js';\nimport { FormFieldDescription, FormFieldError, FormFieldLabel } from '../internal/form-field/form-field.js';\nimport type { CommonProps, FieldProps } from '../types.js';\nimport { textStyle } from '../typography/utils.js';\nimport { DatePickerCalendar } from './date-picker-calendar.js';\n\n/** Represents a date with optional time and timezone components. */\nexport type DateValue = CalendarDate | CalendarDateTime | ZonedDateTime;\n\n/** Maps a date value to a specific subtype depending on which components it contains. */\nexport type MappedDateValue<T> = T extends ZonedDateTime\n ? ZonedDateTime\n : T extends CalendarDateTime\n ? CalendarDateTime\n : T extends CalendarDate\n ? CalendarDate\n : never;\n\nexport interface DatePickerProps<T extends DateValue>\n extends CommonProps,\n FieldProps<MappedDateValue<T>>,\n Pick<\n RACDatePickerProps<T>,\n | 'value'\n | 'defaultValue'\n | 'placeholderValue'\n | 'onChange'\n | 'isDisabled'\n | 'isRequired'\n | 'isInvalid'\n | 'isReadOnly'\n | 'autoFocus'\n | 'onFocus'\n | 'onBlur'\n | 'isOpen'\n | 'defaultOpen'\n | 'onOpenChange'\n | 'minValue'\n | 'maxValue'\n | 'isDateUnavailable'\n | 'granularity'\n | 'firstDayOfWeek'\n | 'autoComplete'\n >,\n Pick<RACCalendarProps<T>, 'focusedValue' | 'defaultFocusedValue'> {}\n\nfunction DatePicker<T extends DateValue>(\n {\n label,\n description,\n error: errorMessage,\n focusedValue,\n defaultFocusedValue,\n UNSAFE_className,\n UNSAFE_style,\n ...props\n }: DatePickerProps<T>,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n const { 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy } = props;\n\n useProductionWarning(() => {\n if (!label && !ariaLabel && !ariaLabelledBy) {\n console.warn('DatePicker requires one of label / aria-label / aria-labelledby for accessibility');\n }\n }, [label, ariaLabel, ariaLabelledBy]);\n\n const messages = useLocalizedMessages('datePicker');\n\n return (\n <RACDatePicker {...props} ref={ref} className={clsx('cim-date-picker', UNSAFE_className)} style={UNSAFE_style}>\n <FormFieldLabel isRequired={props.isRequired} isDisabled={props.isDisabled}>\n {label}\n </FormFieldLabel>\n <RACGroup className=\"cim-date-picker-input-group\" data-readonly={props.isReadOnly || undefined}>\n <RACDateInput className={clsx('cim-date-picker-input', textStyle({ variant: 'body' }))}>\n {(segment) => (\n <span className=\"cim-date-picker-segment-wrapper\">\n <RACDateSegment segment={segment} />\n </span>\n )}\n </RACDateInput>\n <div className=\"cim-date-picker-input-controls\">\n <DatePickerClearButton isDisabled={props.isDisabled || props.isReadOnly} />\n <IconButton\n icon={<IconCalendarEmpty />}\n aria-label={messages.format('openCalendar')}\n variant=\"tertiary\"\n size=\"small\"\n />\n </div>\n </RACGroup>\n <FormFieldError>{errorMessage}</FormFieldError>\n <FormFieldDescription>{description}</FormFieldDescription>\n <RACPopover\n className=\"cim-date-picker-popover\"\n placement=\"bottom end\"\n offset={5} // 1px border + 4px actual offset\n containerPadding={16}\n data-cim-style-root\n >\n <RACDialog>\n <DatePickerCalendar<T>\n focusedValue={focusedValue}\n defaultFocusedValue={defaultFocusedValue}\n placeholderValue={props.placeholderValue}\n />\n </RACDialog>\n </RACPopover>\n </RACDatePicker>\n );\n}\n\n/**\n * Allows users to enter or select a date and time value.\n *\n * See [date picker usage guidelines](https://ui.cimpress.io/components/date-picker/).\n */\nconst _DatePicker = withStyleProps(forwardRef(DatePicker), 'DatePicker');\n\nexport { _DatePicker as DatePicker };\n\nfunction DatePickerClearButton({ isDisabled }: { isDisabled: boolean | undefined }) {\n const datePickerState = useContext(RACDatePickerStateContext)!;\n const messages = useLocalizedMessages('datePicker');\n\n if (!datePickerState.value) {\n return null;\n }\n\n return (\n <IconButton\n // Don't inherit default Button behavior from DatePicker\n slot={null}\n UNSAFE_className=\"cim-date-picker-clear\"\n aria-label={messages.format('clearValue')}\n onPress={() => datePickerState.setValue(null)}\n icon={<IconCloseDetached />}\n variant=\"tertiary\"\n size=\"small\"\n isDisabled={isDisabled}\n />\n );\n}\n\n// TODO: use one of our standard icons instead of this custom one\nfunction IconCloseDetached() {\n return (\n <svg viewBox=\"0 0 12 12\" xmlns=\"http://www.w3.org/2000/svg\" className=\"cim-icon\" fill=\"currentcolor\" data-icon>\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M0.21967 0.21967C0.512563 -0.0732233 0.987437 -0.0732233 1.28033 0.21967L6 4.93934L10.7197 0.21967C11.0126 -0.0732233 11.4874 -0.0732233 11.7803 0.21967C12.0732 0.512563 12.0732 0.987437 11.7803 1.28033L7.06066 6L11.7803 10.7197C12.0732 11.0126 12.0732 11.4874 11.7803 11.7803C11.4874 12.0732 11.0126 12.0732 10.7197 11.7803L6 7.06066L1.28033 11.7803C0.987437 12.0732 0.512563 12.0732 0.21967 11.7803C-0.0732233 11.4874 -0.0732233 11.0126 0.21967 10.7197L4.93934 6L0.21967 1.28033C-0.0732233 0.987437 -0.0732233 0.512563 0.21967 0.21967Z\"\n />\n </svg>\n );\n}\n"]}
1
+ {"version":3,"file":"date-picker.js","sourceRoot":"","sources":["../../../../src/components/date-picker/date-picker.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAGb,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAqB,UAAU,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACnF,OAAO,EAEL,SAAS,IAAI,YAAY,EACzB,UAAU,IAAI,aAAa,EAE3B,sBAAsB,IAAI,yBAAyB,EACnD,WAAW,IAAI,cAAc,EAC7B,MAAM,IAAI,SAAS,EACnB,KAAK,IAAI,QAAQ,EACjB,OAAO,IAAI,UAAU,GACtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AAE5G,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAiD/D,SAAS,UAAU,CACjB,EACE,KAAK,EACL,WAAW,EACX,KAAK,EAAE,YAAY,EACnB,YAAY,EACZ,mBAAmB,EACnB,gBAAg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gB,EAAC,uBAAuB,gBAC5B,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,EACzC,OAAO,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,EAC7C,IAAI,EAAE,KAAC,iBAAiB,KAAG,EAC3B,OAAO,EAAC,UAAU,EAClB,IAAI,EAAC,OAAO,EACZ,UAAU,EAAE,UAAU,GACtB,CACH,CAAC;AACJ,CAAC;AAED,iEAAiE;AACjE,SAAS,iBAAiB;IACxB,OAAO,CACL,cAAK,OAAO,EAAC,WAAW,EAAC,KAAK,EAAC,4BAA4B,EAAC,SAAS,EAAC,UAAU,EAAC,IAAI,EAAC,cAAc,+BAClG,eACE,QAAQ,EAAC,SAAS,EAClB,QAAQ,EAAC,SAAS,EAClB,CAAC,EAAC,2hBAA2hB,GAC7hB,GACE,CACP,CAAC;AACJ,CAAC","sourcesContent":["'use client';\n\nimport type { CalendarDate, CalendarDateTime, ZonedDateTime } from '@internationalized/date';\nimport clsx from 'clsx';\nimport { type ForwardedRef, useContext, useImperativeHandle, useRef } from 'react';\nimport {\n type CalendarProps as RACCalendarProps,\n DateInput as RACDateInput,\n DatePicker as RACDatePicker,\n type DatePickerProps as RACDatePickerProps,\n DatePickerStateContext as RACDatePickerStateContext,\n DateSegment as RACDateSegment,\n Dialog as RACDialog,\n Group as RACGroup,\n Popover as RACPopover,\n} from 'react-aria-components';\nimport { forwardRef } from '../../forward-ref.js';\nimport { useLocalizedMessages } from '../../i18n/index.js';\nimport { IconCalendarEmpty } from '../../icons/index.js';\nimport { useProductionWarning } from '../../utils/use-production-warning.js';\nimport { withStyleProps } from '../../with-style-props.js';\nimport { IconButton } from '../button/icon-button.js';\nimport { FormFieldDescription, FormFieldError, FormFieldLabel } from '../internal/form-field/form-field.js';\nimport type { ApiProps, CommonProps, FieldProps, FocusableElement } from '../types.js';\nimport { textStyle } from '../typography/utils.js';\nimport { DatePickerCalendar } from './date-picker-calendar.js';\n\n/** Represents a date with optional time and timezone components. */\nexport type DateValue = CalendarDate | CalendarDateTime | ZonedDateTime;\n\n/** Maps a date value to a specific subtype depending on which components it contains. */\nexport type MappedDateValue<T> = T extends ZonedDateTime\n ? ZonedDateTime\n : T extends CalendarDateTime\n ? CalendarDateTime\n : T extends CalendarDate\n ? CalendarDate\n : never;\n\nexport interface DatePickerProps<T extends DateValue>\n extends CommonProps,\n FieldProps<MappedDateValue<T>>,\n ApiProps<DatePickerApi>,\n Pick<\n RACDatePickerProps<T>,\n | 'value'\n | 'defaultValue'\n | 'placeholderValue'\n | 'onChange'\n | 'isDisabled'\n | 'isRequired'\n | 'isInvalid'\n | 'isReadOnly'\n | 'autoFocus'\n | 'onFocus'\n | 'onBlur'\n | 'isOpen'\n | 'defaultOpen'\n | 'onOpenChange'\n | 'minValue'\n | 'maxValue'\n | 'isDateUnavailable'\n | 'granularity'\n | 'firstDayOfWeek'\n | 'autoComplete'\n >,\n Pick<RACCalendarProps<T>, 'focusedValue' | 'defaultFocusedValue'> {}\n\n/** The imperative API exposed by the `DatePicker` component. */\nexport interface DatePickerApi {\n /** Focuses the first editable segment in the input field. */\n focus: () => void;\n}\n\nfunction DatePicker<T extends DateValue>(\n {\n label,\n description,\n error: errorMessage,\n focusedValue,\n defaultFocusedValue,\n UNSAFE_className,\n UNSAFE_style,\n apiRef,\n ...props\n }: DatePickerProps<T>,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n const inputRef = useRef<HTMLDivElement>(null);\n\n const { 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy } = props;\n\n useProductionWarning(() => {\n if (!label && !ariaLabel && !ariaLabelledBy) {\n console.warn('DatePicker requires one of label / aria-label / aria-labelledby for accessibility');\n }\n }, [label, ariaLabel, ariaLabelledBy]);\n\n const messages = useLocalizedMessages('datePicker');\n\n useImperativeHandle(\n apiRef,\n () => ({\n focus: () =>\n (inputRef.current?.querySelector('[role=spinbutton]:not([data-disabled])') as FocusableElement | null)?.focus(),\n }),\n [],\n );\n\n return (\n <RACDatePicker {...props} ref={ref} className={clsx('cim-date-picker', UNSAFE_className)} style={UNSAFE_style}>\n <FormFieldLabel isRequired={props.isRequired} isDisabled={props.isDisabled}>\n {label}\n </FormFieldLabel>\n <RACGroup className=\"cim-date-picker-input-group\" data-readonly={props.isReadOnly || undefined}>\n <RACDateInput ref={inputRef} className={clsx('cim-date-picker-input', textStyle({ variant: 'body' }))}>\n {(segment) => (\n <span className=\"cim-date-picker-segment-wrapper\">\n <RACDateSegment segment={segment} />\n </span>\n )}\n </RACDateInput>\n <div className=\"cim-date-picker-input-controls\">\n <DatePickerClearButton isDisabled={props.isDisabled || props.isReadOnly} />\n <IconButton\n icon={<IconCalendarEmpty />}\n aria-label={messages.format('openCalendar')}\n variant=\"tertiary\"\n size=\"small\"\n />\n </div>\n </RACGroup>\n <FormFieldError>{errorMessage}</FormFieldError>\n <FormFieldDescription>{description}</FormFieldDescription>\n <RACPopover\n className=\"cim-date-picker-popover\"\n placement=\"bottom end\"\n offset={5} // 1px border + 4px actual offset\n containerPadding={16}\n data-cim-style-root\n >\n <RACDialog>\n <DatePickerCalendar<T>\n focusedValue={focusedValue}\n defaultFocusedValue={defaultFocusedValue}\n placeholderValue={props.placeholderValue}\n />\n </RACDialog>\n </RACPopover>\n </RACDatePicker>\n );\n}\n\n/**\n * Allows users to enter or select a date and time value.\n *\n * See [date picker usage guidelines](https://ui.cimpress.io/components/date-picker/).\n */\nconst _DatePicker = withStyleProps(forwardRef(DatePicker), 'DatePicker');\n\nexport { _DatePicker as DatePicker };\n\nfunction DatePickerClearButton({ isDisabled }: { isDisabled: boolean | undefined }) {\n const datePickerState = useContext(RACDatePickerStateContext)!;\n const messages = useLocalizedMessages('datePicker');\n\n if (!datePickerState.value) {\n return null;\n }\n\n return (\n <IconButton\n // Don't inherit default Button behavior from DatePicker\n slot={null}\n UNSAFE_className=\"cim-date-picker-clear\"\n aria-label={messages.format('clearValue')}\n onPress={() => datePickerState.setValue(null)}\n icon={<IconCloseDetached />}\n variant=\"tertiary\"\n size=\"small\"\n isDisabled={isDisabled}\n />\n );\n}\n\n// TODO: use one of our standard icons instead of this custom one\nfunction IconCloseDetached() {\n return (\n <svg viewBox=\"0 0 12 12\" xmlns=\"http://www.w3.org/2000/svg\" className=\"cim-icon\" fill=\"currentcolor\" data-icon>\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M0.21967 0.21967C0.512563 -0.0732233 0.987437 -0.0732233 1.28033 0.21967L6 4.93934L10.7197 0.21967C11.0126 -0.0732233 11.4874 -0.0732233 11.7803 0.21967C12.0732 0.512563 12.0732 0.987437 11.7803 1.28033L7.06066 6L11.7803 10.7197C12.0732 11.0126 12.0732 11.4874 11.7803 11.7803C11.4874 12.0732 11.0126 12.0732 10.7197 11.7803L6 7.06066L1.28033 11.7803C0.987437 12.0732 0.512563 12.0732 0.21967 11.7803C-0.0732233 11.4874 -0.0732233 11.0126 0.21967 10.7197L4.93934 6L0.21967 1.28033C-0.0732233 0.987437 -0.0732233 0.512563 0.21967 0.21967Z\"\n />\n </svg>\n );\n}\n"]}
@@ -21,16 +21,13 @@ export function useMultiYearViewState() {
21
21
  calendar: focusedDate.calendar.identifier,
22
22
  timeZone: calendarState.timeZone,
23
23
  });
24
- let startYear = (Math.ceil(focusedDate.year / YEARS_PER_SECTION) - 1) * YEARS_PER_SECTION + 1;
25
- let endYear = startYear + YEARS_PER_SECTION - 1;
24
+ const lowerYear = (Math.ceil(focusedDate.year / YEARS_PER_SECTION) - 1) * YEARS_PER_SECTION + 1;
25
+ const higherYear = lowerYear + YEARS_PER_SECTION - 1;
26
26
  // Years are always represented by positive numbers.
27
27
  // If era implies negative years, flip start and end.
28
28
  const isNegativeEra = focusedDate.era === 'BC';
29
- if (isNegativeEra) {
30
- const temp = startYear;
31
- startYear = endYear;
32
- endYear = temp;
33
- }
29
+ const startYear = isNegativeEra ? higherYear : lowerYear;
30
+ const endYear = isNegativeEra ? lowerYear : higherYear;
34
31
  const data = useMemo(() => {
35
32
  const rowCount = Math.ceil(YEARS_PER_SECTION / ITEMS_PER_ROW);
36
33
  const result = new Array(rowCount);
@@ -1 +1 @@
1
- {"version":3,"file":"use-multi-year-view-state.js","sourceRoot":"","sources":["../../../../../../src/components/date-picker/views/multi-year/use-multi-year-view-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,EAAqB,MAAM,yBAAyB,CAAC;AAClH,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,oBAAoB,IAAI,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AACxF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAC7B,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAE9B,gBAAgB;AAChB,MAAM,UAAU,qBAAqB;IACnC,MAAM,aAAa,GAAG,UAAU,CAAC,uBAAuB,CAAE,CAAC;IAC3D,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,GAAG,iBAAiB,EAAE,CAAC;IAC1E,MAAM,QAAQ,GAAG,oBAAoB,CAAC,YAAY,CAAC,CAAC;IACpD,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAEjD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC,aAAa,CAAC,QAAQ,C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AAa,CAAC,QAAQ,EAAE,IAAI,CAAC;gBAC5D,aAAa,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,aAAa,CAAC,QAAQ,CAAC,CAC/D,CAAC;QACJ,CAAC;QACD,cAAc,CAAC,IAAI;YACjB,OAAO,aAAa,CAAC,KAAK,KAAK,IAAI,IAAI,UAAU,CAAC,IAAI,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC;QAC/E,CAAC;QACD,cAAc,CAAC,IAAI;YACjB,OAAO,UAAU,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;QACvC,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { endOfYear, isSameDay, isSameYear, startOfYear, today, type CalendarDate } from '@internationalized/date';\nimport { useContext, useMemo, useState } from 'react';\nimport { useDateFormatter } from 'react-aria';\nimport { CalendarStateContext as RACCalendarStateContext } from 'react-aria-components';\nimport { useLocalizedMessages } from '../../../../i18n/index.js';\nimport { constrainValue, getEraFormat, isDateInvalid } from '../../utils.js';\nimport type { ViewGridCellData, ViewGridState } from '../types.js';\nimport { useDatePickerView } from '../view-provider.js';\n\nconst ITEMS_PER_ROW = 4;\nconst YEARS_PER_SECTION = 20;\nconst YEARS_SKIP_AMOUNT = 100;\n\n/** @internal */\nexport function useMultiYearViewState(): ViewGridState {\n const calendarState = useContext(RACCalendarStateContext)!;\n const { switchToView, focusedDate, setFocusedDate } = useDatePickerView();\n const messages = useLocalizedMessages('datePicker');\n const [isFocused, setIsFocused] = useState(true);\n\n const currentDate = useMemo(() => today(calendarState.timeZone), [calendarState.timeZone]);\n\n const yearFormatter = useDateFormatter({\n year: 'numeric',\n era: getEraFormat(focusedDate),\n calendar: focusedDate.calendar.identifier,\n timeZone: calendarState.timeZone,\n });\n\n let startYear = (Math.ceil(focusedDate.year / YEARS_PER_SECTION) - 1) * YEARS_PER_SECTION + 1;\n let endYear = startYear + YEARS_PER_SECTION - 1;\n\n // Years are always represented by positive numbers.\n // If era implies negative years, flip start and end.\n const isNegativeEra = focusedDate.era === 'BC';\n if (isNegativeEra) {\n const temp = startYear;\n startYear = endYear;\n endYear = temp;\n }\n\n const data: (ViewGridCellData | null)[][] = useMemo(() => {\n const rowCount = Math.ceil(YEARS_PER_SECTION / ITEMS_PER_ROW);\n const result: (ViewGridCellData | null)[][] = new Array(rowCount);\n\n for (let rowIdx = 0; rowIdx < rowCount; rowIdx++) {\n result[rowIdx] = new Array(ITEMS_PER_ROW).fill(null);\n }\n\n for (let yearIdx = 0; yearIdx < YEARS_PER_SECTION; yearIdx++) {\n const rowIdx = Math.floor(yearIdx / ITEMS_PER_ROW);\n const colIdx = yearIdx % ITEMS_PER_ROW;\n\n const yearToSet = startYear + (isNegativeEra ? -yearIdx : yearIdx);\n const date = focusedDate.set({ year: yearToSet });\n\n if (date.year !== yearToSet) {\n // Reached minimum/maximum date\n continue;\n }\n\n const content = yearFormatter.format(date.toDate(calendarState.timeZone));\n\n result[rowIdx]![colIdx] = {\n date,\n content,\n ariaLabel: content,\n isCurrent: isSameYear(date, currentDate),\n };\n }\n\n return result;\n }, [startYear, calendarState.timeZone, focusedDate, yearFormatter, isNegativeEra, currentDate]);\n\n const focusCell = (date: CalendarDate) => {\n setFocusedDate(constrainValue(date, calendarState.minValue, calendarState.maxValue));\n };\n\n return {\n header: yearFormatter.formatRange(\n focusedDate.set({ year: startYear }).toDate(calendarState.timeZone),\n focusedDate.set({ year: endYear }).toDate(calendarState.timeZone),\n ),\n previousLabel: messages.format('previousMultiYearSection', { yearCount: 20 }),\n nextLabel: messages.format('nextMultiYearSection', { yearCount: 20 }),\n data,\n isReadOnly: calendarState.isReadOnly,\n isDisabled: calendarState.isDisabled,\n isFocused,\n setIsFocused,\n focusedDate,\n setFocusedDate,\n timeZone: calendarState.timeZone,\n focusPreviousItem() {\n focusCell(focusedDate.subtract({ years: 1 }));\n },\n focusNextItem() {\n focusCell(focusedDate.add({ years: 1 }));\n },\n focusPreviousRow() {\n focusCell(focusedDate.subtract({ years: ITEMS_PER_ROW }));\n },\n focusNextRow() {\n focusCell(focusedDate.add({ years: ITEMS_PER_ROW }));\n },\n focusSectionStart() {\n focusCell(focusedDate.set({ year: startYear }));\n },\n focusSectionEnd() {\n focusCell(focusedDate.set({ year: endYear }));\n },\n focusPreviousSection(shouldSkip) {\n focusCell(focusedDate.subtract({ years: shouldSkip ? YEARS_SKIP_AMOUNT : YEARS_PER_SECTION }));\n },\n focusNextSection(shouldSkip) {\n focusCell(focusedDate.add({ years: shouldSkip ? YEARS_SKIP_AMOUNT : YEARS_PER_SECTION }));\n },\n isPreviousSectionInvalid() {\n const current = startOfYear(focusedDate.set({ year: startYear }));\n const prev = current.subtract({ days: 1 });\n\n return (\n isDateInvalid(current, calendarState.minValue, calendarState.maxValue) ||\n isDateInvalid(prev, calendarState.minValue, calendarState.maxValue) ||\n isSameDay(prev, current)\n );\n },\n isNextSectionInvalid() {\n const current = endOfYear(focusedDate.set({ year: endYear }));\n const next = current.add({ days: 1 });\n\n return (\n isDateInvalid(current, calendarState.minValue, calendarState.maxValue) ||\n isDateInvalid(next, calendarState.minValue, calendarState.maxValue) ||\n isSameDay(next, current)\n );\n },\n selectFocusedDate() {\n switchToView('year');\n },\n isCellDisabled(date) {\n return (\n isDateInvalid(endOfYear(date), calendarState.minValue, null) ||\n isDateInvalid(startOfYear(date), null, calendarState.maxValue)\n );\n },\n isCellSelected(date) {\n return calendarState.value !== null && isSameYear(date, calendarState.value);\n },\n isCellTabbable(date) {\n return isSameYear(date, focusedDate);\n },\n };\n}\n"]}
1
+ {"version":3,"file":"use-multi-year-view-state.js","sourceRoot":"","sources":["../../../../../../src/components/date-picker/views/multi-year/use-multi-year-view-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,EAAqB,MAAM,yBAAyB,CAAC;AAClH,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;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AE,WAAW,CAAC,CAAC;QACvC,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { endOfYear, isSameDay, isSameYear, startOfYear, today, type CalendarDate } from '@internationalized/date';\nimport { useContext, useMemo, useState } from 'react';\nimport { useDateFormatter } from 'react-aria';\nimport { CalendarStateContext as RACCalendarStateContext } from 'react-aria-components';\nimport { useLocalizedMessages } from '../../../../i18n/index.js';\nimport { constrainValue, getEraFormat, isDateInvalid } from '../../utils.js';\nimport type { ViewGridCellData, ViewGridState } from '../types.js';\nimport { useDatePickerView } from '../view-provider.js';\n\nconst ITEMS_PER_ROW = 4;\nconst YEARS_PER_SECTION = 20;\nconst YEARS_SKIP_AMOUNT = 100;\n\n/** @internal */\nexport function useMultiYearViewState(): ViewGridState {\n const calendarState = useContext(RACCalendarStateContext)!;\n const { switchToView, focusedDate, setFocusedDate } = useDatePickerView();\n const messages = useLocalizedMessages('datePicker');\n const [isFocused, setIsFocused] = useState(true);\n\n const currentDate = useMemo(() => today(calendarState.timeZone), [calendarState.timeZone]);\n\n const yearFormatter = useDateFormatter({\n year: 'numeric',\n era: getEraFormat(focusedDate),\n calendar: focusedDate.calendar.identifier,\n timeZone: calendarState.timeZone,\n });\n\n const lowerYear = (Math.ceil(focusedDate.year / YEARS_PER_SECTION) - 1) * YEARS_PER_SECTION + 1;\n const higherYear = lowerYear + YEARS_PER_SECTION - 1;\n\n // Years are always represented by positive numbers.\n // If era implies negative years, flip start and end.\n const isNegativeEra = focusedDate.era === 'BC';\n const startYear = isNegativeEra ? higherYear : lowerYear;\n const endYear = isNegativeEra ? lowerYear : higherYear;\n\n const data: (ViewGridCellData | null)[][] = useMemo(() => {\n const rowCount = Math.ceil(YEARS_PER_SECTION / ITEMS_PER_ROW);\n const result: (ViewGridCellData | null)[][] = new Array(rowCount);\n\n for (let rowIdx = 0; rowIdx < rowCount; rowIdx++) {\n result[rowIdx] = new Array(ITEMS_PER_ROW).fill(null);\n }\n\n for (let yearIdx = 0; yearIdx < YEARS_PER_SECTION; yearIdx++) {\n const rowIdx = Math.floor(yearIdx / ITEMS_PER_ROW);\n const colIdx = yearIdx % ITEMS_PER_ROW;\n\n const yearToSet = startYear + (isNegativeEra ? -yearIdx : yearIdx);\n const date = focusedDate.set({ year: yearToSet });\n\n if (date.year !== yearToSet) {\n // Reached minimum/maximum date\n continue;\n }\n\n const content = yearFormatter.format(date.toDate(calendarState.timeZone));\n\n result[rowIdx]![colIdx] = {\n date,\n content,\n ariaLabel: content,\n isCurrent: isSameYear(date, currentDate),\n };\n }\n\n return result;\n }, [startYear, calendarState.timeZone, focusedDate, yearFormatter, isNegativeEra, currentDate]);\n\n const focusCell = (date: CalendarDate) => {\n setFocusedDate(constrainValue(date, calendarState.minValue, calendarState.maxValue));\n };\n\n return {\n header: yearFormatter.formatRange(\n focusedDate.set({ year: startYear }).toDate(calendarState.timeZone),\n focusedDate.set({ year: endYear }).toDate(calendarState.timeZone),\n ),\n previousLabel: messages.format('previousMultiYearSection', { yearCount: 20 }),\n nextLabel: messages.format('nextMultiYearSection', { yearCount: 20 }),\n data,\n isReadOnly: calendarState.isReadOnly,\n isDisabled: calendarState.isDisabled,\n isFocused,\n setIsFocused,\n focusedDate,\n setFocusedDate,\n timeZone: calendarState.timeZone,\n focusPreviousItem() {\n focusCell(focusedDate.subtract({ years: 1 }));\n },\n focusNextItem() {\n focusCell(focusedDate.add({ years: 1 }));\n },\n focusPreviousRow() {\n focusCell(focusedDate.subtract({ years: ITEMS_PER_ROW }));\n },\n focusNextRow() {\n focusCell(focusedDate.add({ years: ITEMS_PER_ROW }));\n },\n focusSectionStart() {\n focusCell(focusedDate.set({ year: startYear }));\n },\n focusSectionEnd() {\n focusCell(focusedDate.set({ year: endYear }));\n },\n focusPreviousSection(shouldSkip) {\n focusCell(focusedDate.subtract({ years: shouldSkip ? YEARS_SKIP_AMOUNT : YEARS_PER_SECTION }));\n },\n focusNextSection(shouldSkip) {\n focusCell(focusedDate.add({ years: shouldSkip ? YEARS_SKIP_AMOUNT : YEARS_PER_SECTION }));\n },\n isPreviousSectionInvalid() {\n const current = startOfYear(focusedDate.set({ year: startYear }));\n const prev = current.subtract({ days: 1 });\n\n return (\n isDateInvalid(current, calendarState.minValue, calendarState.maxValue) ||\n isDateInvalid(prev, calendarState.minValue, calendarState.maxValue) ||\n isSameDay(prev, current)\n );\n },\n isNextSectionInvalid() {\n const current = endOfYear(focusedDate.set({ year: endYear }));\n const next = current.add({ days: 1 });\n\n return (\n isDateInvalid(current, calendarState.minValue, calendarState.maxValue) ||\n isDateInvalid(next, calendarState.minValue, calendarState.maxValue) ||\n isSameDay(next, current)\n );\n },\n selectFocusedDate() {\n switchToView('year');\n },\n isCellDisabled(date) {\n return (\n isDateInvalid(endOfYear(date), calendarState.minValue, null) ||\n isDateInvalid(startOfYear(date), null, calendarState.maxValue)\n );\n },\n isCellSelected(date) {\n return calendarState.value !== null && isSameYear(date, calendarState.value);\n },\n isCellTabbable(date) {\n return isSameYear(date, focusedDate);\n },\n };\n}\n"]}
@@ -1,8 +1,8 @@
1
1
  import { type ReactNode } from 'react';
2
2
  import { type DisclosureGroupProps as RACDisclosureGroupProps } from 'react-aria-components';
3
- import type { CommonProps } from '../types.js';
3
+ import type { CommonProps, Key } from '../types.js';
4
4
  import { type DisclosureSize, type DisclosureVariant } from './context.js';
5
- export interface DisclosureGroupProps extends CommonProps, Pick<RACDisclosureGroupProps, 'isDisabled' | 'allowsMultipleExpanded' | 'defaultExpandedKeys' | 'expandedKeys' | 'onExpandedChange'> {
5
+ export interface DisclosureGroupProps extends CommonProps, Pick<RACDisclosureGroupProps, 'isDisabled' | 'allowsMultipleExpanded' | 'defaultExpandedKeys' | 'expandedKeys'> {
6
6
  /** The disclosures to group together. */
7
7
  children: ReactNode;
8
8
  /**
@@ -15,6 +15,8 @@ export interface DisclosureGroupProps extends CommonProps, Pick<RACDisclosureGro
15
15
  * @default 'medium'
16
16
  */
17
17
  size?: DisclosureSize;
18
+ /** Handler that is called when any disclosure in this group is expanded or collapsed. */
19
+ onExpandedChange?: (keys: Set<Key>) => void;
18
20
  }
19
21
  /**
20
22
  * Displays a grouping of related disclosures.
@@ -1 +1 @@
1
- {"version":3,"file":"disclosure-group.d.ts","sourceRoot":"","sources":["../../../../src/components/disclosure/disclosure-group.tsx"],"names":[],"mappings":"AAGA,OAAO,EAA8B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACnE,OAAO,EAEL,KAAK,oBAAoB,IAAI,uBAAuB,EACrD,MAAM,uBAAuB,CAAC;AAG/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACvB,MAAM,cAAc,CAAC;AAEtB,MAAM,WAAW,oBACf,SAAQ,WAAW,EACjB,IAAI,CACF,uBAAuB,EACvB,YAAY,GAAG,wBAAwB,GAAG,qBAAqB,GAAG,cAAc,GAAG,kBAAkB,CACtG;IACH,yCAAyC;IACzC,QAAQ,EAAE,SAAS,CAAC;IACpB;;;OAGG;IACH,OAAO,CAAC,EAAE,iBAAiB,CAAC;IAC5B;;;OAGG;IACH,IAAI,CAAC,EAAE,cAAc,CAAC;CACvB;AA4BD;;;;GAIG;AACH,QAAA,MAAM,gBAAgB,sKAAiE,CAAC;AAExF,OAAO,EAAE,gBAAgB,IAAI,eAAe,EAAE,CAAC"}
1
+ {"version":3,"file":"disclosure-group.d.ts","sourceRoot":"","sources":["../../../../src/components/disclosure/disclosure-group.tsx"],"names":[],"mappings":"AAGA,OAAO,EAA8B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACnE,OAAO,EAEL,KAAK,oBAAoB,IAAI,uBAAuB,EACrD,MAAM,uBAAuB,CAAC;AAG/B,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACvB,MAAM,cAAc,CAAC;AAEtB,MAAM,WAAW,oBACf,SAAQ,WAAW,EACjB,IAAI,CAAC,uBAAuB,EAAE,YAAY,GAAG,wBAAwB,GAAG,qBAAqB,GAAG,cAAc,CAAC;IACjH,yCAAyC;IACzC,QAAQ,EAAE,SAAS,CAAC;IACpB;;;OAGG;IACH,OAAO,CAAC,EAAE,iBAAiB,CAAC;IAC5B;;;OAGG;IACH,IAAI,CAAC,EAAE,cAAc,CAAC;IACtB,yFAAyF;IACzF,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;CAC7C;AA4BD;;;;GAIG;AACH,QAAA,MAAM,gBAAgB,sKAAiE,CAAC;AAExF,OAAO,EAAE,gBAAgB,IAAI,eAAe,EAAE,CAAC"}