@kanso-labs/kanso-ui 0.45.33 → 0.46.0

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 (108) hide show
  1. package/dist/button/index.js +13 -9
  2. package/dist/button/index.js.map +1 -1
  3. package/dist/calendar/styles.js +12 -7
  4. package/dist/calendar/styles.js.map +1 -1
  5. package/dist/chip/styles.js +1 -0
  6. package/dist/chip/styles.js.map +1 -1
  7. package/dist/collection/styles.js +1 -1
  8. package/dist/collection/styles.js.map +1 -1
  9. package/dist/components/breadcrumbs/index.js +4 -1
  10. package/dist/components/breadcrumbs/index.js.map +1 -1
  11. package/dist/components/button-group/index.d.ts +16 -3
  12. package/dist/components/button-group/index.js +53 -86
  13. package/dist/components/button-group/index.js.map +1 -1
  14. package/dist/components/calendar/index.d.ts +3 -3
  15. package/dist/components/calendar/index.js.map +1 -1
  16. package/dist/components/card/index.js +5 -1
  17. package/dist/components/card/index.js.map +1 -1
  18. package/dist/components/carousel/index.js +162 -105
  19. package/dist/components/carousel/index.js.map +1 -1
  20. package/dist/components/chip/index.d.ts +38 -15
  21. package/dist/components/chip/index.js +104 -8
  22. package/dist/components/chip/index.js.map +1 -1
  23. package/dist/components/color-area/index.d.ts +5 -3
  24. package/dist/components/color-area/index.js +5 -3
  25. package/dist/components/color-area/index.js.map +1 -1
  26. package/dist/components/color-picker/index.js +6 -3
  27. package/dist/components/color-picker/index.js.map +1 -1
  28. package/dist/components/color-swatch-picker/index.js +24 -9
  29. package/dist/components/color-swatch-picker/index.js.map +1 -1
  30. package/dist/components/combo-box/index.d.ts +11 -3
  31. package/dist/components/combo-box/index.js +66 -62
  32. package/dist/components/combo-box/index.js.map +1 -1
  33. package/dist/components/copy-field/index.js +1 -0
  34. package/dist/components/copy-field/index.js.map +1 -1
  35. package/dist/components/date-picker/index.d.ts +22 -3
  36. package/dist/components/date-picker/index.js +234 -45
  37. package/dist/components/date-picker/index.js.map +1 -1
  38. package/dist/components/date-range-picker/index.d.ts +3 -1
  39. package/dist/components/date-range-picker/index.js +6 -4
  40. package/dist/components/date-range-picker/index.js.map +1 -1
  41. package/dist/components/disclosure/index.d.ts +4 -3
  42. package/dist/components/disclosure/index.js +159 -101
  43. package/dist/components/disclosure/index.js.map +1 -1
  44. package/dist/components/fab/index.d.ts +3 -1
  45. package/dist/components/fab/index.js +25 -12
  46. package/dist/components/fab/index.js.map +1 -1
  47. package/dist/components/fab-menu/index.js +1 -1
  48. package/dist/components/fab-menu/index.js.map +1 -1
  49. package/dist/components/icon-button/index.js.map +1 -1
  50. package/dist/components/index.d.ts +2 -2
  51. package/dist/components/menu/index.js +1 -1
  52. package/dist/components/menu/index.js.map +1 -1
  53. package/dist/components/navigation-rail/index.js +4 -4
  54. package/dist/components/navigation-rail/index.js.map +1 -1
  55. package/dist/components/navigation-tree/index.js +16 -13
  56. package/dist/components/navigation-tree/index.js.map +1 -1
  57. package/dist/components/popover/index.js +35 -33
  58. package/dist/components/popover/index.js.map +1 -1
  59. package/dist/components/range-calendar/index.js +41 -7
  60. package/dist/components/range-calendar/index.js.map +1 -1
  61. package/dist/components/segmented-button/index.d.ts +3 -2
  62. package/dist/components/segmented-button/index.js +46 -95
  63. package/dist/components/segmented-button/index.js.map +1 -1
  64. package/dist/components/select/index.js +5 -2
  65. package/dist/components/select/index.js.map +1 -1
  66. package/dist/components/slider/index.js +42 -10
  67. package/dist/components/slider/index.js.map +1 -1
  68. package/dist/components/time-picker/index.js +2 -0
  69. package/dist/components/time-picker/index.js.map +1 -1
  70. package/dist/components/token-field/index.js +89 -66
  71. package/dist/components/token-field/index.js.map +1 -1
  72. package/dist/components/toolbar/index.d.ts +4 -0
  73. package/dist/components/toolbar/index.js +16 -5
  74. package/dist/components/toolbar/index.js.map +1 -1
  75. package/dist/components/tree/index.js +1 -1
  76. package/dist/components/tree/index.js.map +1 -1
  77. package/dist/fab/styles.js +12 -0
  78. package/dist/fab/styles.js.map +1 -1
  79. package/dist/field/styles.js +2 -2
  80. package/dist/field/styles.js.map +1 -1
  81. package/dist/hooks/useDockedMonths.js +36 -0
  82. package/dist/hooks/useDockedMonths.js.map +1 -0
  83. package/dist/i18n/index.js +1 -0
  84. package/dist/i18n/index.js.map +1 -1
  85. package/dist/i18n/messages.js +34 -0
  86. package/dist/i18n/messages.js.map +1 -1
  87. package/dist/index.d.ts +2 -2
  88. package/dist/navigation/index.js +5 -5
  89. package/dist/navigation/index.js.map +1 -1
  90. package/dist/navigation/styles.js +4 -0
  91. package/dist/navigation/styles.js.map +1 -1
  92. package/dist/row/context.js +6 -0
  93. package/dist/row/context.js.map +1 -0
  94. package/dist/row/index.js +77 -66
  95. package/dist/row/index.js.map +1 -1
  96. package/dist/row/styles.js +15 -0
  97. package/dist/row/styles.js.map +1 -1
  98. package/dist/segments/index.js +2 -1
  99. package/dist/segments/index.js.map +1 -1
  100. package/dist/segments/styles.js +4 -0
  101. package/dist/segments/styles.js.map +1 -1
  102. package/dist/styles/chequer.js +1 -0
  103. package/dist/styles/chequer.js.map +1 -1
  104. package/dist/styles/focus.js.map +1 -1
  105. package/dist/styles.css +158 -35
  106. package/dist/toggle-group/index.js +133 -0
  107. package/dist/toggle-group/index.js.map +1 -0
  108. package/package.json +4 -4
@@ -2,6 +2,12 @@ import { FieldVariant } from "../../field/index.js";
2
2
  import { ReactElement, ReactNode, Ref, RefAttributes } from "react";
3
3
  import { ComboBoxProps as ComboBoxProps$1 } from "react-aria-components";
4
4
  type ComboBoxProps<T extends object = object, M extends ComboBoxSelectionMode = 'single'> = {
5
+ /**
6
+ * Whether the list stays open when a search leaves nothing in it, showing
7
+ * the ListBox's "No results" row, rather than closing.
8
+ * @default true
9
+ */
10
+ allowsEmptyCollection?: boolean;
5
11
  /**
6
12
  * Where to portal the list. Defaults to the container of the `ThemeScope`
7
13
  * around it, which keeps the list on that scope's tokens, or to the end of
@@ -60,7 +66,7 @@ type ComboBoxProps<T extends object = object, M extends ComboBoxSelectionMode =
60
66
  * @default 'filled'
61
67
  */
62
68
  variant?: FieldVariant;
63
- } & Omit<ComboBoxProps$1<T, M>, 'children' | 'defaultSelectedKey' | 'isInvalid' | 'onSelectionChange' | 'selectedKey' | 'validationBehavior'>;
69
+ } & Omit<ComboBoxProps$1<T, M>, 'allowsEmptyCollection' | 'children' | 'defaultSelectedKey' | 'isInvalid' | 'onSelectionChange' | 'selectedKey' | 'validationBehavior'>;
64
70
  type ComboBoxSelectionMode = 'multiple' | 'single';
65
71
  /**
66
72
  * A labelled text field that filters a list as it is typed. Its value is
@@ -85,7 +91,9 @@ type ComboBoxSelectionMode = 'multiple' | 'single';
85
91
  * Filtering is React Aria's: `defaultFilter` takes a predicate, `useFilter`
86
92
  * is re-exported for a locale-aware one, and `items` with `useAsyncList`
87
93
  * feeds a list that is fetched rather than listed. `allowsCustomValue` lets
88
- * the field keep text that matches nothing.
94
+ * the field keep text that matches nothing. A search that matches nothing
95
+ * keeps the list open on a "No results" row; `allowsEmptyCollection={false}`
96
+ * closes it instead.
89
97
  *
90
98
  * The box, label, input, supporting line and error are the field chrome in
91
99
  * `src/field`, shared with every other field; the list is ListBox on the
@@ -94,5 +102,5 @@ type ComboBoxSelectionMode = 'multiple' | 'single';
94
102
  * The call site's `className` and `style` land on the field as a whole,
95
103
  * which is the element a layout positions.
96
104
  */
97
- declare function ComboBox<T extends object = object, M extends ComboBoxSelectionMode = 'single'>({ container, description, error, floatingLabel, inputRef, isDisabled, label, leadingIcon, options, variant, ...props }: ComboBoxProps<T, M> & RefAttributes<HTMLDivElement>): import("react").JSX.Element;
105
+ declare function ComboBox<T extends object = object, M extends ComboBoxSelectionMode = 'single'>({ allowsEmptyCollection, container, description, error, floatingLabel, inputRef, isDisabled, label, leadingIcon, options, variant, ...props }: ComboBoxProps<T, M> & RefAttributes<HTMLDivElement>): import("react").JSX.Element;
98
106
  export { type ComboBoxProps, type ComboBoxSelectionMode, ComboBox as default };
@@ -22,7 +22,6 @@ const styles = {
22
22
  ks0D6T: "x1x1rfll",
23
23
  k7Eaqz: "xeuugli",
24
24
  kORKVm: "x1odjw0f",
25
- k8WAf4: "x1cmllll",
26
25
  $$css: true
27
26
  },
28
27
  toggle: {
@@ -78,7 +77,9 @@ function ChosenValues() {
78
77
  * Filtering is React Aria's: `defaultFilter` takes a predicate, `useFilter`
79
78
  * is re-exported for a locale-aware one, and `items` with `useAsyncList`
80
79
  * feeds a list that is fetched rather than listed. `allowsCustomValue` lets
81
- * the field keep text that matches nothing.
80
+ * the field keep text that matches nothing. A search that matches nothing
81
+ * keeps the list open on a "No results" row; `allowsEmptyCollection={false}`
82
+ * closes it instead.
82
83
  *
83
84
  * The box, label, input, supporting line and error are the field chrome in
84
85
  * `src/field`, shared with every other field; the list is ListBox on the
@@ -88,41 +89,42 @@ function ChosenValues() {
88
89
  * which is the element a layout positions.
89
90
  */
90
91
  function ComboBox(t0) {
91
- const $ = c(32);
92
- const { container, description, error, floatingLabel: t1, inputRef, isDisabled: t2, label, leadingIcon, options, variant: t3, ...props$1 } = t0;
93
- const floatingLabel = t1 === void 0 ? true : t1;
94
- const isDisabled = t2 === void 0 ? false : t2;
95
- const variant = t3 === void 0 ? "filled" : t3;
92
+ const $ = c(33);
93
+ const { allowsEmptyCollection: t1, container, description, error, floatingLabel: t2, inputRef, isDisabled: t3, label, leadingIcon, options, variant: t4, ...props$1 } = t0;
94
+ const allowsEmptyCollection = t1 === void 0 ? true : t1;
95
+ const floatingLabel = t2 === void 0 ? true : t2;
96
+ const isDisabled = t3 === void 0 ? false : t3;
97
+ const variant = t4 === void 0 ? "filled" : t4;
96
98
  const validationBehavior = useFieldValidationBehavior();
97
99
  const boxRef = useRef(null);
98
100
  const T0 = ComboBox$1;
99
- let t4;
101
+ let t5;
100
102
  if ($[0] !== error) {
101
- t4 = invalidFrom(error);
103
+ t5 = invalidFrom(error);
102
104
  $[0] = error;
103
- $[1] = t4;
104
- } else t4 = $[1];
105
- const t5 = mergeStatefulStyles(props(fieldStyles.root), props$1);
106
- let t6;
105
+ $[1] = t5;
106
+ } else t5 = $[1];
107
+ const t6 = mergeStatefulStyles(props(fieldStyles.root), props$1);
108
+ let t7;
107
109
  if ($[2] !== error) {
108
- t6 = invalidFrom(error);
110
+ t7 = invalidFrom(error);
109
111
  $[2] = error;
110
- $[3] = t6;
111
- } else t6 = $[3];
112
- const t7 = props$1.isRequired ?? false;
113
- const t8 = props$1.selectionMode === "multiple";
114
- let t9;
115
- if ($[4] !== floatingLabel || $[5] !== inputRef || $[6] !== isDisabled || $[7] !== label || $[8] !== leadingIcon || $[9] !== t6 || $[10] !== t7 || $[11] !== t8 || $[12] !== variant) {
116
- t9 = /* @__PURE__ */ jsx(ComboBoxBox, {
112
+ $[3] = t7;
113
+ } else t7 = $[3];
114
+ const t8 = props$1.isRequired ?? false;
115
+ const t9 = props$1.selectionMode === "multiple";
116
+ let t10;
117
+ if ($[4] !== floatingLabel || $[5] !== inputRef || $[6] !== isDisabled || $[7] !== label || $[8] !== leadingIcon || $[9] !== t7 || $[10] !== t8 || $[11] !== t9 || $[12] !== variant) {
118
+ t10 = /* @__PURE__ */ jsx(ComboBoxBox, {
117
119
  boxRef,
118
120
  floatingLabel,
119
121
  inputRef,
120
122
  isDisabled,
121
- isInvalid: t6,
122
- isRequired: t7,
123
+ isInvalid: t7,
124
+ isRequired: t8,
123
125
  label,
124
126
  leadingIcon,
125
- multiple: t8,
127
+ multiple: t9,
126
128
  variant
127
129
  });
128
130
  $[4] = floatingLabel;
@@ -130,66 +132,68 @@ function ComboBox(t0) {
130
132
  $[6] = isDisabled;
131
133
  $[7] = label;
132
134
  $[8] = leadingIcon;
133
- $[9] = t6;
134
- $[10] = t7;
135
- $[11] = t8;
135
+ $[9] = t7;
136
+ $[10] = t8;
137
+ $[11] = t9;
136
138
  $[12] = variant;
137
- $[13] = t9;
138
- } else t9 = $[13];
139
- let t10;
139
+ $[13] = t10;
140
+ } else t10 = $[13];
141
+ let t11;
140
142
  if ($[14] !== description || $[15] !== error) {
141
- t10 = /* @__PURE__ */ jsx(FieldMessage, {
143
+ t11 = /* @__PURE__ */ jsx(FieldMessage, {
142
144
  description,
143
145
  error
144
146
  });
145
147
  $[14] = description;
146
148
  $[15] = error;
147
- $[16] = t10;
148
- } else t10 = $[16];
149
- let t11;
149
+ $[16] = t11;
150
+ } else t11 = $[16];
151
+ let t12;
150
152
  if ($[17] !== options) {
151
- t11 = /* @__PURE__ */ jsx(ListBox$1, { children: options });
153
+ t12 = /* @__PURE__ */ jsx(ListBox$1, { children: options });
152
154
  $[17] = options;
153
- $[18] = t11;
154
- } else t11 = $[18];
155
- let t12;
156
- if ($[19] !== container || $[20] !== t11) {
157
- t12 = /* @__PURE__ */ jsx(Popover, {
155
+ $[18] = t12;
156
+ } else t12 = $[18];
157
+ let t13;
158
+ if ($[19] !== container || $[20] !== t12) {
159
+ t13 = /* @__PURE__ */ jsx(Popover, {
158
160
  className: listClassName,
159
161
  triggerRef: boxRef,
160
162
  UNSTABLE_portalContainer: container,
161
- children: t11
163
+ children: t12
162
164
  });
163
165
  $[19] = container;
164
- $[20] = t11;
165
- $[21] = t12;
166
- } else t12 = $[21];
167
- let t13;
168
- if ($[22] !== T0 || $[23] !== isDisabled || $[24] !== props$1 || $[25] !== t10 || $[26] !== t12 || $[27] !== t4 || $[28] !== t5 || $[29] !== t9 || $[30] !== validationBehavior) {
169
- t13 = /* @__PURE__ */ jsxs(T0, {
166
+ $[20] = t12;
167
+ $[21] = t13;
168
+ } else t13 = $[21];
169
+ let t14;
170
+ if ($[22] !== T0 || $[23] !== allowsEmptyCollection || $[24] !== isDisabled || $[25] !== props$1 || $[26] !== t10 || $[27] !== t11 || $[28] !== t13 || $[29] !== t5 || $[30] !== t6 || $[31] !== validationBehavior) {
171
+ t14 = /* @__PURE__ */ jsxs(T0, {
172
+ allowsEmptyCollection,
170
173
  isDisabled,
171
- isInvalid: t4,
174
+ isInvalid: t5,
172
175
  validationBehavior,
173
176
  ...props$1,
174
- ...t5,
177
+ ...t6,
175
178
  children: [
176
- t9,
177
179
  t10,
178
- t12
180
+ t11,
181
+ t13
179
182
  ]
180
183
  });
181
184
  $[22] = T0;
182
- $[23] = isDisabled;
183
- $[24] = props$1;
184
- $[25] = t10;
185
- $[26] = t12;
186
- $[27] = t4;
187
- $[28] = t5;
188
- $[29] = t9;
189
- $[30] = validationBehavior;
190
- $[31] = t13;
191
- } else t13 = $[31];
192
- return t13;
185
+ $[23] = allowsEmptyCollection;
186
+ $[24] = isDisabled;
187
+ $[25] = props$1;
188
+ $[26] = t10;
189
+ $[27] = t11;
190
+ $[28] = t13;
191
+ $[29] = t5;
192
+ $[30] = t6;
193
+ $[31] = validationBehavior;
194
+ $[32] = t14;
195
+ } else t14 = $[32];
196
+ return t14;
193
197
  }
194
198
  /**
195
199
  * The box and what it holds. Its own component so it can read React Aria's
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_c","stylex","useContext","useRef","ComboBoxStateContext","ComboBox","RACComboBox","fieldStyles","invalidFrom","useFieldValidationBehavior","focus","mergeStatefulStyles","overlay","popupOrigin","TOGGLE","styles","list","kWkggS","kaIpWk","kzqmXN","kskxy","ks0D6T","k7Eaqz","kORKVm","k8WAf4","$$css","toggle","kGNEyG","kZKoxP","kMzoRj","kB7OPa","kMwMTN","kkrTdU","k1xSpc","kjj79g","kmVPX3","container","description","error","floatingLabel","inputRef","label","leadingIcon","options","variant","ChosenValues","$","t0","Symbol","for","t1","isDisabled","t2","t3","props","undefined","validationBehavior","boxRef","T0","t4","t5","root","t6","t7","isRequired","t8","selectionMode","t9","t10","t11","t12","listClassName","t13","ComboBoxBox","isInvalid","multiple","state","selectedItems","length","ComboToggle","ring","0","className","1","isOpen","popup","placement","RACComboBoxValue","ListBox","RACPopover","RACButton"],"sources":["../../../src/components/combo-box/index.tsx"],"sourcesContent":["'use client';\n\nimport type { ReactElement, ReactNode, Ref, RefAttributes, RefObject } from 'react';\nimport type { PopoverRenderProps, ComboBoxProps as RACComboBoxProps } from 'react-aria-components';\nimport * as stylex from '@stylexjs/stylex';\nimport { useContext, useRef } from 'react';\nimport { ComboBoxStateContext, Button as RACButton, ComboBox as RACComboBox, ComboBoxValue as RACComboBoxValue, Popover as RACPopover } from 'react-aria-components';\nimport type { FieldVariant } from '../../field';\nimport { FieldBox, FieldInput, FieldMessage, FieldValue } from '../../field';\nimport { fieldStyles, invalidFrom, useFieldValidationBehavior } from '../../field/root';\nimport { ChevronEndGlyph } from '../../glyphs';\nimport { focus } from '../../styles/focus';\nimport { mergeStatefulStyles } from '../../styles/merge';\nimport { overlay, popupOrigin } from '../../styles/overlay';\nimport '../../tokens/design.tokens.stylex';\nimport { colors, motion, radii, spacing } from '../../tokens/design.tokens.stylex';\nimport ListBox from '../list-box';\n\n// The text fields page's autocomplete text field: a text field that filters a\n// list as it is typed. Everything above the list is the field chrome in\n// `src/field` — the same box, label, supporting line and error treatment\n// every other field draws — and the list is ListBox on the shared overlay\n// surface, positioned and sized against the box exactly as Select's is.\n//\n// It is Select's shape with two differences.\n//\n// The control is a real input, so the box is not a press target — typing has\n// to reach the input — and only the chevron at the end opens the list. That\n// is what the page draws too: an autocomplete text field is a text field,\n// with a button on it.\n//\n// And the field is an element tree rather than a function of React Aria's\n// render state, which every other component here writes. React Aria builds a\n// combo box's collection by walking its children for options, and a function\n// is opaque to that walk: with one, the collection is empty until the list\n// has been opened, so a `defaultSelectedKey` resolves to no text and the\n// field starts blank. What needed the render state — whether the list is\n// open — reads the combo box's own state from context instead.\n//\n// Two more things are this component's own.\n//\n// **Filtering is React Aria's, and stays theirs.** `defaultFilter` takes a\n// predicate, and the package re-exports `useFilter` for a locale-aware one;\n// `items` with `useAsyncList` is how a list that is fetched rather than\n// listed gets in. None of that is wrapped, because a combo box's whole job\n// is which options it shows and a wrapper would be a second place to decide\n// it.\n//\n// **A value that is not in the list is allowed or refused, not corrected.**\n// `allowsCustomValue` is React Aria's, and with it off the input reverts to\n// the last chosen option on blur rather than keeping text that means nothing.\n//\n// Choosing more than one is `selectionMode=\"multiple\"`, which draws the\n// chosen options before the input on its line, through React Aria's\n// `ComboBoxValue`, with the label floated over them. For a field that draws\n// each of them as a removable chip, the coverage plan has TokenField.\n\n// Hoisted so it is not a new element on every render, which is what\n// react-perf's jsx-no-jsx-as-prop is after.\nconst TOGGLE = <ComboToggle />;\nconst styles = {\n list: {\n kWkggS: \"x1vnz5z6\",\n kaIpWk: \"x1tfhd1\",\n kzqmXN: \"xlvufjm\",\n kskxy: \"xedcshv\",\n ks0D6T: \"x1x1rfll\",\n k7Eaqz: \"xeuugli\",\n kORKVm: \"x1odjw0f\",\n k8WAf4: \"x1cmllll\",\n $$css: true\n },\n toggle: {\n kGNEyG: \"x6s0dn4\",\n kWkggS: \"xjbqb8w\",\n kZKoxP: \"xxk0z11\",\n kaIpWk: \"x16fbrrb\",\n kMzoRj: \"xc342km\",\n kB7OPa: \"x9f619\",\n kMwMTN: \"x1heor9g\",\n kkrTdU: \"x1ypdohk\",\n k1xSpc: \"x3nfvp2\",\n kzqmXN: \"xvy4d1p\",\n kjj79g: \"xl56j7k\",\n kmVPX3: \"x1717udv\",\n $$css: true\n }\n};\ntype ComboBoxProps<T extends object = object, M extends ComboBoxSelectionMode = 'single'> = {\n /**\n * Where to portal the list. Defaults to the container of the `ThemeScope`\n * around it, which keeps the list on that scope's tokens, or to the end of\n * `<body>` where there is none. A subtree themed through the `themeScope`\n * class has no container of its own, so point this inside it, or the list\n * renders outside and keeps the page's tokens.\n */\n container?: Element;\n /**\n * A hint shown under the field. Replaced by `error` when there is one, so\n * the two never stack.\n */\n description?: string;\n /**\n * The problem with the current value, in words. Its presence is what puts\n * the field in its error state — the message, the red underline, and\n * `aria-invalid` all follow from it.\n *\n * Outside a `Form` the message line arrives with the message, so the\n * field grows when this does and moves what is under it. A `Form` holds\n * that space from the start; so does a permanent `description`.\n */\n error?: string;\n /**\n * Whether the label sits in the empty box and floats to the top once the\n * field is focused or holds a value. `false` keeps it small at the top in\n * every state.\n * @default true\n */\n floatingLabel?: boolean;\n /**\n * A ref to the field's own `<input>`, which is the element a call site moves\n * focus to — after a server's error, say. `ref` is the field as a whole.\n */\n inputRef?: Ref<HTMLInputElement>;\n /**\n * What the field is for. Required rather than optional: a combo box with\n * no label is a box a screen reader cannot name.\n */\n label: string;\n /**\n * An icon at the start of the box, before the label and the value: the\n * page's 24dp leading icon, in the muted role. An icon drawn in `em` takes\n * that size from the slot.\n */\n leadingIcon?: ReactNode;\n /**\n * The options. `ListBox.Item` for each, and `ListBox.Section` to group\n * them — the list inside is a ListBox, and takes everything one does. With\n * `items` or `defaultItems`, a function from an item to its option, which\n * React Aria calls for each item the list shows.\n */\n options?: ((item: T) => ReactElement) | ReactNode;\n /**\n * The filled box, or the outlined one, as the text fields page draws them.\n * @default 'filled'\n */\n variant?: FieldVariant;\n} & Omit<RACComboBoxProps<T, M>, 'children' | 'defaultSelectedKey' | 'isInvalid' | 'onSelectionChange' | 'selectedKey' | 'validationBehavior'>;\n\n// React Aria's combo box takes its own two-value selection mode rather than\n// the collection-wide one, which also has `none`; that type is local to its\n// module, so the two values are named again here.\ntype ComboBoxSelectionMode = 'multiple' | 'single';\n\n/**\n * The chosen options, drawn before the input on its line when more than one\n * may be chosen. The chrome's `FieldValue` is the styled element and React\n * Aria's `ComboBoxValue` sits inside it, as it does in Select.\n */\nfunction ChosenValues() {\n return <FieldValue>\n <RACComboBoxValue className=\"xb3r6kr xlyipyv xuxw1ft\" />\n </FieldValue>;\n}\n\n/**\n * A labelled text field that filters a list as it is typed. Its value is\n * React Aria's: pass `value` with `onChange` to control which option is\n * chosen, `inputValue` with `onInputChange` to control the text, or the\n * `default` forms of either to let it keep its own. React Aria's older\n * `selectedKey` names are deprecated and are left out of this component's\n * props rather than passed through.\n *\n * ```tsx\n * <ComboBox\n * label=\"Label\"\n * options={\n * <>\n * <ListBox.Item id=\"first\">First item</ListBox.Item>\n * <ListBox.Item id=\"second\">Second item</ListBox.Item>\n * </>\n * }\n * />\n * ```\n *\n * Filtering is React Aria's: `defaultFilter` takes a predicate, `useFilter`\n * is re-exported for a locale-aware one, and `items` with `useAsyncList`\n * feeds a list that is fetched rather than listed. `allowsCustomValue` lets\n * the field keep text that matches nothing.\n *\n * The box, label, input, supporting line and error are the field chrome in\n * `src/field`, shared with every other field; the list is ListBox on the\n * overlay surface every anchored panel here draws.\n *\n * The call site's `className` and `style` land on the field as a whole,\n * which is the element a layout positions.\n */\nfunction ComboBox<T extends object = object, M extends ComboBoxSelectionMode = 'single'>({\n container,\n description,\n error,\n floatingLabel = true,\n inputRef,\n isDisabled = false,\n label,\n leadingIcon,\n options,\n variant = 'filled',\n ...props\n}: ComboBoxProps<T, M> & RefAttributes<HTMLDivElement>) {\n const validationBehavior = useFieldValidationBehavior();\n // What the list is anchored to and takes its width from: the box, not the\n // button inside it, which is a 24dp icon.\n const boxRef = useRef<HTMLDivElement>(null);\n return <RACComboBox<T, M> isDisabled={isDisabled} isInvalid={invalidFrom(error)} validationBehavior={validationBehavior} {...props} {...mergeStatefulStyles(stylex.props(fieldStyles.root), props)}>\n <ComboBoxBox boxRef={boxRef} floatingLabel={floatingLabel} inputRef={inputRef} isDisabled={isDisabled} isInvalid={invalidFrom(error)} isRequired={props.isRequired ?? false} label={label} leadingIcon={leadingIcon} multiple={props.selectionMode === 'multiple'} variant={variant} />\n <FieldMessage description={description} error={error} />\n <RACPopover className={listClassName} triggerRef={boxRef}\n // oxlint-disable-next-line typescript/no-deprecated -- its replacement, UNSAFE_PortalProvider, is not exported by react-aria-components\n UNSTABLE_portalContainer={container}>\n <ListBox<T>>{options}</ListBox>\n </RACPopover>\n </RACComboBox>;\n}\n\n/**\n * The box and what it holds. Its own component so it can read React Aria's\n * state for what is chosen: with more than one option allowed, the input is\n * empty while options are chosen, so it cannot be what says the field holds\n * something. The box is told instead, and the label floats over the chosen\n * options rather than resting on them. Otherwise the box reads the input, as\n * it does for one option, which is what floats the label on typed text.\n */\nfunction ComboBoxBox({\n boxRef,\n floatingLabel,\n inputRef,\n isDisabled,\n isInvalid,\n isRequired,\n label,\n leadingIcon,\n multiple,\n variant\n}: {\n boxRef: RefObject<HTMLDivElement | null>;\n floatingLabel: boolean;\n inputRef: Ref<HTMLInputElement> | undefined;\n isDisabled: boolean;\n isInvalid: boolean | undefined;\n isRequired: boolean;\n label: string;\n leadingIcon: ReactNode;\n multiple: boolean;\n variant: FieldVariant;\n}) {\n const state = useContext(ComboBoxStateContext);\n const chosen = multiple && (state?.selectedItems.length ?? 0) > 0;\n return <FieldBox floatingLabel={floatingLabel}\n // React Aria's `TextField` hands its group the field's disabled and\n // invalid state through context; its `ComboBox` does not, so the box\n // is told outright or its label and its underline never turn.\n isDisabled={isDisabled} isInvalid={isInvalid} isPopulated={chosen ? true : undefined} isRequired={isRequired} label={label} leading={leadingIcon} ref={boxRef} trailing={TOGGLE} variant={variant}>\n {multiple ? <span className=\"xpr5407 xrvj5dj xuptkxw\">\n <ChosenValues />\n <FieldInput ref={inputRef} />\n </span> : <FieldInput ref={inputRef} />}\n </FieldBox>;\n}\n\n/**\n * The button that opens the list. It takes its press behaviour from the\n * combo box around it through React Aria's button context, and reads whether\n * the list is open from the combo box's state rather than from a render prop\n * — the whole field cannot be a render function, since React Aria builds its\n * collection by walking the children and a function is opaque to that walk.\n */\nfunction ComboToggle() {\n const state = useContext(ComboBoxStateContext);\n return <RACButton {...stylex.props(styles.toggle, focus.ring)}>\n <ChevronEndGlyph {...{\n 0: {\n className: \"x12w9bfk xxk0z11 xvy4d1p x1iffjtl xkzkux9 x11xpdln xpc4ca7\"\n },\n 1: {\n className: \"x12w9bfk xxk0z11 xvy4d1p xkzkux9 x11xpdln xpc4ca7 x9tu13d\"\n }\n }[!!(state?.isOpen === true) << 0]} />\n </RACButton>;\n}\n\n// The list's classes, from React Aria's render state: it grows from the\n// edge it is anchored by, as every anchored overlay does, so a list that\n// opens above the field grows upward.\nfunction listClassName(state: PopoverRenderProps) {\n return stylex.props(overlay.popup, styles.list, popupOrigin(state.placement)).className ?? '';\n}\nexport type { ComboBoxProps, ComboBoxS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CACE,MAAA4E,QAAc1E,WAAWE,oBAAoB;CAAE,IAAA2C;CAAA,IAAAD,EAAA,OAAAE,OAAAC,IAAA,2BAAA,GAAA;EACzBF,KAAA9C,MAAac,OAAMW,QAAShB,MAAKsE,IAAK;EAAClC,EAAA,KAAAC;CAAA,OAAAA,KAAAD,EAAA;CAAA,IAAAI;CAAA,IAAAJ,EAAA,OAAAE,OAAAC,IAAA,2BAAA,GAAA;EACpCC,KAAA;GAAA+B,GAClB,EAAAC,WACU,6DACb;GAACC,GACE,EAAAD,WACU,4DACb;EACF;EAACpC,EAAA,KAAAI;CAAA,OAAAA,KAAAJ,EAAA;CAPsB,MAAAM,KAAAF,GAOrB,CAAC,EAAE0B,OAAKQ,WAAa,SAAS;CAAE,IAAA/B;CAAA,IAAAP,EAAA,OAAAM,IAAA;EAR7BC,KAAA,oBAACqC,QAAD;GAAU,GAAK3C;GAClB,UAAA,oBAAC,iBAAD,EAAgB,GAAKK,GAOW,CAAA;EARnB,CAAA;EASHN,EAAA,KAAAM;EAAAN,EAAA,KAAAO;CAAA,OAAAA,KAAAP,EAAA;CAAA,OATPO;AASO;AAMhB,SAASkB,cAAcK,OAA2B;CAChD,OAAO3E,MAAaW,QAAQyE,OAAOtE,OAAOC,MAAMH,YAAY+D,MAAMU,SAAS,CAAC,CAAC,CAACJ,aAAa;AAC7F"}
1
+ {"version":3,"file":"index.js","names":["_c","stylex","useContext","useRef","ComboBoxStateContext","ComboBox","RACComboBox","fieldStyles","invalidFrom","useFieldValidationBehavior","focus","mergeStatefulStyles","overlay","popupOrigin","TOGGLE","styles","list","kWkggS","kaIpWk","kzqmXN","kskxy","ks0D6T","k7Eaqz","kORKVm","$$css","toggle","kGNEyG","kZKoxP","kMzoRj","kB7OPa","kMwMTN","kkrTdU","k1xSpc","kjj79g","kmVPX3","allowsEmptyCollection","container","description","error","floatingLabel","inputRef","label","leadingIcon","options","variant","ChosenValues","$","t0","Symbol","for","t1","t2","isDisabled","t3","t4","props","undefined","validationBehavior","boxRef","T0","t5","t6","root","t7","t8","isRequired","t9","selectionMode","t10","t11","t12","t13","listClassName","t14","ComboBoxBox","isInvalid","multiple","state","selectedItems","length","ComboToggle","ring","0","className","1","isOpen","popup","placement","RACComboBoxValue","ListBox","RACPopover","RACButton"],"sources":["../../../src/components/combo-box/index.tsx"],"sourcesContent":["'use client';\n\nimport type { ReactElement, ReactNode, Ref, RefAttributes, RefObject } from 'react';\nimport type { PopoverRenderProps, ComboBoxProps as RACComboBoxProps } from 'react-aria-components';\nimport * as stylex from '@stylexjs/stylex';\nimport { useContext, useRef } from 'react';\nimport { ComboBoxStateContext, Button as RACButton, ComboBox as RACComboBox, ComboBoxValue as RACComboBoxValue, Popover as RACPopover } from 'react-aria-components';\nimport type { FieldVariant } from '../../field';\nimport { FieldBox, FieldInput, FieldMessage, FieldValue } from '../../field';\nimport { fieldStyles, invalidFrom, useFieldValidationBehavior } from '../../field/root';\nimport { ChevronEndGlyph } from '../../glyphs';\nimport { focus } from '../../styles/focus';\nimport { mergeStatefulStyles } from '../../styles/merge';\nimport { overlay, popupOrigin } from '../../styles/overlay';\nimport '../../tokens/design.tokens.stylex';\nimport { colors, motion, radii, spacing } from '../../tokens/design.tokens.stylex';\nimport ListBox from '../list-box';\n\n// The text fields page's autocomplete text field: a text field that filters a\n// list as it is typed. Everything above the list is the field chrome in\n// `src/field` — the same box, label, supporting line and error treatment\n// every other field draws — and the list is ListBox on the shared overlay\n// surface, positioned and sized against the box exactly as Select's is.\n//\n// It is Select's shape with two differences.\n//\n// The control is a real input, so the box is not a press target — typing has\n// to reach the input — and only the chevron at the end opens the list. That\n// is what the page draws too: an autocomplete text field is a text field,\n// with a button on it.\n//\n// And the field is an element tree rather than a function of React Aria's\n// render state, which every other component here writes. React Aria builds a\n// combo box's collection by walking its children for options, and a function\n// is opaque to that walk: with one, the collection is empty until the list\n// has been opened, so a `defaultSelectedKey` resolves to no text and the\n// field starts blank. What needed the render state — whether the list is\n// open — reads the combo box's own state from context instead.\n//\n// Two more things are this component's own.\n//\n// **Filtering is React Aria's, and stays theirs.** `defaultFilter` takes a\n// predicate, and the package re-exports `useFilter` for a locale-aware one;\n// `items` with `useAsyncList` is how a list that is fetched rather than\n// listed gets in. None of that is wrapped, because a combo box's whole job\n// is which options it shows and a wrapper would be a second place to decide\n// it.\n//\n// **A value that is not in the list is allowed or refused, not corrected.**\n// `allowsCustomValue` is React Aria's, and with it off the input reverts to\n// the last chosen option on blur rather than keeping text that means nothing.\n//\n// **A search that matches nothing keeps the list open, saying so.** React\n// Aria closes a list its filter has emptied unless `allowsEmptyCollection`\n// says otherwise, and with it closed the field held its text with no list\n// and no word about why — a list that broke and one with no matches looked\n// the same. So the default here is `true`, and the ListBox inside draws the\n// empty state every ListBox does, a muted \"No results\" row in the\n// I18nProvider's locale, as it does under an Autocomplete. `false` is the\n// call site's for a field that would rather close.\n//\n// Choosing more than one is `selectionMode=\"multiple\"`, which draws the\n// chosen options before the input on its line, through React Aria's\n// `ComboBoxValue`, with the label floated over them. For a field that draws\n// each of them as a removable chip, the coverage plan has TokenField.\n\n// Hoisted so it is not a new element on every render, which is what\n// react-perf's jsx-no-jsx-as-prop is after.\nconst TOGGLE = <ComboToggle />;\nconst styles = {\n list: {\n kWkggS: \"x1vnz5z6\",\n kaIpWk: \"x1tfhd1\",\n kzqmXN: \"xlvufjm\",\n kskxy: \"xedcshv\",\n ks0D6T: \"x1x1rfll\",\n k7Eaqz: \"xeuugli\",\n kORKVm: \"x1odjw0f\",\n $$css: true\n },\n toggle: {\n kGNEyG: \"x6s0dn4\",\n kWkggS: \"xjbqb8w\",\n kZKoxP: \"xxk0z11\",\n kaIpWk: \"x16fbrrb\",\n kMzoRj: \"xc342km\",\n kB7OPa: \"x9f619\",\n kMwMTN: \"x1heor9g\",\n kkrTdU: \"x1ypdohk\",\n k1xSpc: \"x3nfvp2\",\n kzqmXN: \"xvy4d1p\",\n kjj79g: \"xl56j7k\",\n kmVPX3: \"x1717udv\",\n $$css: true\n }\n};\ntype ComboBoxProps<T extends object = object, M extends ComboBoxSelectionMode = 'single'> = {\n /**\n * Whether the list stays open when a search leaves nothing in it, showing\n * the ListBox's \"No results\" row, rather than closing.\n * @default true\n */\n allowsEmptyCollection?: boolean;\n /**\n * Where to portal the list. Defaults to the container of the `ThemeScope`\n * around it, which keeps the list on that scope's tokens, or to the end of\n * `<body>` where there is none. A subtree themed through the `themeScope`\n * class has no container of its own, so point this inside it, or the list\n * renders outside and keeps the page's tokens.\n */\n container?: Element;\n /**\n * A hint shown under the field. Replaced by `error` when there is one, so\n * the two never stack.\n */\n description?: string;\n /**\n * The problem with the current value, in words. Its presence is what puts\n * the field in its error state — the message, the red underline, and\n * `aria-invalid` all follow from it.\n *\n * Outside a `Form` the message line arrives with the message, so the\n * field grows when this does and moves what is under it. A `Form` holds\n * that space from the start; so does a permanent `description`.\n */\n error?: string;\n /**\n * Whether the label sits in the empty box and floats to the top once the\n * field is focused or holds a value. `false` keeps it small at the top in\n * every state.\n * @default true\n */\n floatingLabel?: boolean;\n /**\n * A ref to the field's own `<input>`, which is the element a call site moves\n * focus to — after a server's error, say. `ref` is the field as a whole.\n */\n inputRef?: Ref<HTMLInputElement>;\n /**\n * What the field is for. Required rather than optional: a combo box with\n * no label is a box a screen reader cannot name.\n */\n label: string;\n /**\n * An icon at the start of the box, before the label and the value: the\n * page's 24dp leading icon, in the muted role. An icon drawn in `em` takes\n * that size from the slot.\n */\n leadingIcon?: ReactNode;\n /**\n * The options. `ListBox.Item` for each, and `ListBox.Section` to group\n * them — the list inside is a ListBox, and takes everything one does. With\n * `items` or `defaultItems`, a function from an item to its option, which\n * React Aria calls for each item the list shows.\n */\n options?: ((item: T) => ReactElement) | ReactNode;\n /**\n * The filled box, or the outlined one, as the text fields page draws them.\n * @default 'filled'\n */\n variant?: FieldVariant;\n} & Omit<RACComboBoxProps<T, M>, 'allowsEmptyCollection' | 'children' | 'defaultSelectedKey' | 'isInvalid' | 'onSelectionChange' | 'selectedKey' | 'validationBehavior'>;\n\n// React Aria's combo box takes its own two-value selection mode rather than\n// the collection-wide one, which also has `none`; that type is local to its\n// module, so the two values are named again here.\ntype ComboBoxSelectionMode = 'multiple' | 'single';\n\n/**\n * The chosen options, drawn before the input on its line when more than one\n * may be chosen. The chrome's `FieldValue` is the styled element and React\n * Aria's `ComboBoxValue` sits inside it, as it does in Select.\n */\nfunction ChosenValues() {\n return <FieldValue>\n <RACComboBoxValue className=\"xb3r6kr xlyipyv xuxw1ft\" />\n </FieldValue>;\n}\n\n/**\n * A labelled text field that filters a list as it is typed. Its value is\n * React Aria's: pass `value` with `onChange` to control which option is\n * chosen, `inputValue` with `onInputChange` to control the text, or the\n * `default` forms of either to let it keep its own. React Aria's older\n * `selectedKey` names are deprecated and are left out of this component's\n * props rather than passed through.\n *\n * ```tsx\n * <ComboBox\n * label=\"Label\"\n * options={\n * <>\n * <ListBox.Item id=\"first\">First item</ListBox.Item>\n * <ListBox.Item id=\"second\">Second item</ListBox.Item>\n * </>\n * }\n * />\n * ```\n *\n * Filtering is React Aria's: `defaultFilter` takes a predicate, `useFilter`\n * is re-exported for a locale-aware one, and `items` with `useAsyncList`\n * feeds a list that is fetched rather than listed. `allowsCustomValue` lets\n * the field keep text that matches nothing. A search that matches nothing\n * keeps the list open on a \"No results\" row; `allowsEmptyCollection={false}`\n * closes it instead.\n *\n * The box, label, input, supporting line and error are the field chrome in\n * `src/field`, shared with every other field; the list is ListBox on the\n * overlay surface every anchored panel here draws.\n *\n * The call site's `className` and `style` land on the field as a whole,\n * which is the element a layout positions.\n */\nfunction ComboBox<T extends object = object, M extends ComboBoxSelectionMode = 'single'>({\n allowsEmptyCollection = true,\n container,\n description,\n error,\n floatingLabel = true,\n inputRef,\n isDisabled = false,\n label,\n leadingIcon,\n options,\n variant = 'filled',\n ...props\n}: ComboBoxProps<T, M> & RefAttributes<HTMLDivElement>) {\n const validationBehavior = useFieldValidationBehavior();\n // What the list is anchored to and takes its width from: the box, not the\n // button inside it, which is a 24dp icon.\n const boxRef = useRef<HTMLDivElement>(null);\n return <RACComboBox<T, M> allowsEmptyCollection={allowsEmptyCollection} isDisabled={isDisabled} isInvalid={invalidFrom(error)} validationBehavior={validationBehavior} {...props} {...mergeStatefulStyles(stylex.props(fieldStyles.root), props)}>\n <ComboBoxBox boxRef={boxRef} floatingLabel={floatingLabel} inputRef={inputRef} isDisabled={isDisabled} isInvalid={invalidFrom(error)} isRequired={props.isRequired ?? false} label={label} leadingIcon={leadingIcon} multiple={props.selectionMode === 'multiple'} variant={variant} />\n <FieldMessage description={description} error={error} />\n <RACPopover className={listClassName} triggerRef={boxRef}\n // oxlint-disable-next-line typescript/no-deprecated -- its replacement, UNSAFE_PortalProvider, is not exported by react-aria-components\n UNSTABLE_portalContainer={container}>\n <ListBox<T>>{options}</ListBox>\n </RACPopover>\n </RACComboBox>;\n}\n\n/**\n * The box and what it holds. Its own component so it can read React Aria's\n * state for what is chosen: with more than one option allowed, the input is\n * empty while options are chosen, so it cannot be what says the field holds\n * something. The box is told instead, and the label floats over the chosen\n * options rather than resting on them. Otherwise the box reads the input, as\n * it does for one option, which is what floats the label on typed text.\n */\nfunction ComboBoxBox({\n boxRef,\n floatingLabel,\n inputRef,\n isDisabled,\n isInvalid,\n isRequired,\n label,\n leadingIcon,\n multiple,\n variant\n}: {\n boxRef: RefObject<HTMLDivElement | null>;\n floatingLabel: boolean;\n inputRef: Ref<HTMLInputElement> | undefined;\n isDisabled: boolean;\n isInvalid: boolean | undefined;\n isRequired: boolean;\n label: string;\n leadingIcon: ReactNode;\n multiple: boolean;\n variant: FieldVariant;\n}) {\n const state = useContext(ComboBoxStateContext);\n const chosen = multiple && (state?.selectedItems.length ?? 0) > 0;\n return <FieldBox floatingLabel={floatingLabel}\n // React Aria's `TextField` hands its group the field's disabled and\n // invalid state through context; its `ComboBox` does not, so the box\n // is told outright or its label and its underline never turn.\n isDisabled={isDisabled} isInvalid={isInvalid} isPopulated={chosen ? true : undefined} isRequired={isRequired} label={label} leading={leadingIcon} ref={boxRef} trailing={TOGGLE} variant={variant}>\n {multiple ? <span className=\"xpr5407 xrvj5dj xuptkxw\">\n <ChosenValues />\n <FieldInput ref={inputRef} />\n </span> : <FieldInput ref={inputRef} />}\n </FieldBox>;\n}\n\n/**\n * The button that opens the list. It takes its press behaviour from the\n * combo box around it through React Aria's button context, and reads whether\n * the list is open from the combo box's state rather than from a render prop\n * — the whole field cannot be a render function, since React Aria builds its\n * collection by walking the children and a function is opaque to that walk.\n */\nfunction ComboToggle() {\n const state = useContext(ComboBoxStateContext);\n return <RACButton {...stylex.props(styles.toggle, focus.ring)}>\n <ChevronEndGlyph {...{\n 0: {\n className: \"x12w9bfk xxk0z11 xvy4d1p x1iffjtl xkzkux9 x11xpdln xpc4ca7\"\n },\n 1: {\n className: \"x12w9bfk xxk0z11 xvy4d1p xkzkux9 x11xpdln xpc4ca7 x9tu13d\"\n }\n }[!!(state?.isOpen === true) << 0]} />\n </RACButton>;\n}\n\n// The list's classes, from React Aria's render state: it grows from the\n// edge it is anchored by, as every anchored overlay does, so a list that\n// opens above the field grows upward.\nfunction listClassName(state: PopoverRenderProps) {\n return stylex.props(overlay.popup, styles.list, popupOrigin(state.placement)).className ?? '';\n}\nexport type { ComboBoxProps, ComboBoxSelectionMode };\nexport default ComboBox;"],"mappings":";;;;;;;;;;;;;;AAoEA,MAAMc,SAAS,oBAAC,aAAD,CAAY,CAAA;AAC3B,MAAMC,SAAS;CACbC,MAAM;EACJC,QAAQ;EACRC,QAAQ;EACRC,QAAQ;EACRC,OAAO;EACPC,QAAQ;EACRC,QAAQ;EACRC,QAAQ;EACRC,OAAO;CACT;CACAC,QAAQ;EACNC,QAAQ;EACRT,QAAQ;EACRU,QAAQ;EACRT,QAAQ;EACRU,QAAQ;EACRC,QAAQ;EACRC,QAAQ;EACRC,QAAQ;EACRC,QAAQ;EACRb,QAAQ;EACRc,QAAQ;EACRC,QAAQ;EACRV,OAAO;CACT;AACF;;;;;;AA8EA,SAAAqB,eAAA;CA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rC,EAAA,KAAAI;CAAA,OAAAA,KAAAJ,EAAA;CAPsB,MAAAK,KAAAD,GAOrB,CAAC,EAAE2B,OAAKQ,WAAa,SAAS;CAAE,IAAAhC;CAAA,IAAAP,EAAA,OAAAK,IAAA;EAR7BE,KAAA,oBAACsC,QAAD;GAAU,GAAK5C;GAClB,UAAA,oBAAC,iBAAD,EAAgB,GAAKI,GAOW,CAAA;EARnB,CAAA;EASHL,EAAA,KAAAK;EAAAL,EAAA,KAAAO;CAAA,OAAAA,KAAAP,EAAA;CAAA,OATPO;AASO;AAMhB,SAASmB,cAAcK,OAA2B;CAChD,OAAO5E,MAAaW,QAAQ0E,OAAOvE,OAAOC,MAAMH,YAAYgE,MAAMU,SAAS,CAAC,CAAC,CAACJ,aAAa;AAC7F"}
@@ -101,6 +101,7 @@ function CopyField(t0) {
101
101
  className: "x139gbkf x1iyjqo2 x1b35g6e xdb2kus x9d6959 xwth0xh xybisxh xeuugli x6mezaz xvrbanz x126k92a",
102
102
  children: /* @__PURE__ */ jsx("code", {
103
103
  dir: "ltr",
104
+ lang: "en",
104
105
  ref: code,
105
106
  className: "x9f619 xbppi91 x1qlqyl8 xj0a0fe x4ej8vm",
106
107
  children: value
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_c","useEffect","useId","useRef","useState","useMessages","mergeStyles","COPIED_RESET_MS","copiedLabel","copyLabel","label","onCopied","value","onCopyFailed","error","selectedLabel","CopyField","t0","$","copiedLabelProp","copyLabelProp","selectedLabelProp","props","messages","copied","copy","copySelected","setCopy","shown","text","kind","timer","undefined","code","generatedId","rootId","id","copyId","copiedId","named","role","buttonName","t1","t2","Symbol","for","clearTimeout","current","t3","settle","setTimeout","count","write","navigator","clipboard","writeText","t4","selectAndCopy","reportCopied","handleCopy","className","t5","t6","t7","0","1","t8","t9","t10","t11","t12","t13","t14","t15","t16","t17","t18","thrown","queueMicrotask","element","selection","window","getSelection","range","document","createRange","selectNodeContents","removeAllRanges","addRange","execCommand"],"sources":["../../../src/components/copy-field/index.tsx"],"sourcesContent":["'use client';\n\nimport type { HTMLAttributes, RefAttributes } from 'react';\nimport * as stylex from '@stylexjs/stylex';\nimport { useCallback, useEffect, useId, useRef, useState } from 'react';\nimport { useMessages } from '../../i18n';\nimport { mergeStyles } from '../../styles/merge';\nimport '../../tokens/design.tokens.stylex';\nimport { colors, radii, spacing, typography } from '../../tokens/design.tokens.stylex';\nimport Button from '../button';\n\n// How long the confirmation stands before the control returns to offering the\n// copy again. Not a motion token: those are transition durations, measured in\n// hundreds of milliseconds, and this is a dwell — long enough to be read\n// without being long enough to leave the button lying about what it will do.\nconst COPIED_RESET_MS = 2000;\n\n// No Material Design page draws a read-only value with a copy control. It\n// follows the outlined text field: the 1dp rule in the outline role, the\n// surface behind it, and the control at its trailing end. The value is\n// body-small beside a 32dp text button with 8dp above and below it, so the\n// box is 50dp against the field's 56, which suits a value that is read\n// rather than edited, and its corner is the shape scale's small step for the\n// same reason.\n//\n// The 8dp is what holds the button's focus ring, which reaches 4dp out from\n// it, clear of the rule, and the trailing end gives the button the same 8dp\n// rather than the 12dp the value starts in by. The button brings 12dp of its\n// own around its label, so the label ends 20dp in where the two paddings\n// added up to 24.\n\ntype CopyFieldProps = {\n /**\n * What the button says once the value has been copied, and what is\n * announced. It reverts to `copyLabel` on its own after a couple of\n * seconds. Left out, it is the word for it in the I18nProvider's locale —\n * \"Copied\" in English.\n */\n copiedLabel?: string;\n /**\n * What the button says at rest. Left out, it is the word for it in the\n * I18nProvider's locale — \"Copy\" in English.\n */\n copyLabel?: string;\n /**\n * What the value is — \"Repository URL\", \"Access token\" — for a page with\n * more than one field. It names the field as a group and joins the button's\n * name, so a screen reader hears \"Copy Repository URL\" rather than one\n * \"Copy\" after another; it is not shown. The value itself stays out of the\n * button's name, since a token would be read aloud. Left out, the field is\n * unnamed and its button is \"Copy\" alone, as it always was.\n */\n label?: string;\n /**\n * Called with the value after it reaches the clipboard, never before.\n *\n * Named `onCopied` rather than `onCopy` because the root is a `<div>`, which\n * already has an `onCopy` of its own — React's handler for the native copy\n * event, fired when the reader presses the copy shortcut inside the element.\n * The two are different moments, and a prop that quietly shadowed the\n * built-in would be a trap rather than a convenience.\n */\n onCopied?: (value: string) => void;\n /**\n * Called when the write is refused, with whatever was thrown, and the\n * field's own fallback has not copied the value either. By then the value\n * is selected and the field says so — see `selectedLabel` — so this is for\n * an app that wants to say more, in a snackbar say.\n *\n * Takes the error where `onCopied` takes the value, because the value is\n * the one thing the call site already has and the reason is the one thing\n * it does not. The two refusals throw differently: outside a secure\n * context `navigator.clipboard` is not there at all, and where the\n * permission is denied it is a `DOMException`.\n */\n onCopyFailed?: (error: unknown) => void;\n /**\n * What is announced when the clipboard refused the write and the value has\n * been selected for the reader to copy themselves. The button keeps saying\n * `copyLabel`, since a label slot wide enough for this would double the\n * button's width at rest; the selection itself is what shows. Left out, it\n * is the phrase for it in the I18nProvider's locale — \"Selected to copy\"\n * in English.\n */\n selectedLabel?: string;\n /** The text shown, and the text copied. */\n value: string;\n} & Omit<HTMLAttributes<HTMLDivElement>, 'children'>;\n\n/**\n * A value to be read and taken away — a repository URL, a token, a command.\n * It shows the value in the mono face and copies it on request, confirming\n * on the button itself.\n *\n * A write refused — outside a secure context, or where the permission is\n * denied — does not leave the reader with nothing. The field selects the\n * value and tries the older copy command, which some of those places still\n * allow; failing that, the selection is left ready for the keyboard's own\n * copy, the field announces so, and `onCopyFailed` is called. One click on\n * the value selects exactly the value too.\n */\nfunction CopyField({\n copiedLabel: copiedLabelProp,\n copyLabel: copyLabelProp,\n label,\n onCopied,\n onCopyFailed,\n selectedLabel: selectedLabelProp,\n value,\n ...props\n}: CopyFieldProps & RefAttributes<HTMLDivElement>) {\n const messages = useMessages();\n const copiedLabel = copiedLabelProp ?? messages.copied;\n const copyLabel = copyLabelProp ?? messages.copy;\n const selectedLabel = selectedLabelProp ?? messages.copySelected;\n // What the last write put on the clipboard, and how many writes there have\n // been. The confirmation is that text still being the value shown, so a\n // value that changes inside the dwell — a token regenerated, a selection\n // swapped — takes the label back to Copy at once rather than confirming a\n // copy of something else. The count is what lets a second press be\n // announced, below. `kind` is whether the text reached the clipboard or\n // was only selected for the reader to copy, after a refusal.\n const [copy, setCopy] = useState<null | {\n count: number;\n kind: 'copied' | 'selected';\n text: string;\n }>(null);\n const shown: 'copied' | 'copy' | 'selected' = copy?.text === value ? copy.kind : 'copy';\n const copied = shown === 'copied';\n const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n const code = useRef<HTMLElement>(null);\n const generatedId = useId();\n const rootId = props.id ?? generatedId;\n const copyId = useId();\n const copiedId = useId();\n\n // With a label, the field is a group it names, and the button is named by\n // the label slot on show and then by the group: \"Copy Repository URL\",\n // then \"Copied Repository URL\". The slot on show rather than both, since\n // the two swap `aria-hidden` and a name taking both would say both.\n const named = label === undefined ? undefined : {\n 'aria-label': label,\n id: rootId,\n role: 'group'\n };\n const buttonName = label === undefined ? undefined : `${copied ? copiedId : copyId} ${rootId}`;\n\n // Without this, a field unmounted inside the dwell leaves a timer holding a\n // setState for a tree that is gone.\n useEffect(() => () => {\n clearTimeout(timer.current);\n }, []);\n const handleCopy = useCallback(() => {\n // The component's own state first, the dwell included, and the call\n // site's handler after it: a handler that threw used to skip the timer,\n // leaving the button on Copied for good. Its error is still the call\n // site's to see, raised on its own rather than swallowed.\n const settle = (kind: 'copied' | 'selected') => {\n clearTimeout(timer.current);\n timer.current = setTimeout(() => {\n setCopy(null);\n }, COPIED_RESET_MS);\n setCopy(current => ({\n count: (current?.count ?? 0) + 1,\n kind,\n text: value\n }));\n };\n const write = async () => {\n try {\n await navigator.clipboard.writeText(value);\n } catch (error) {\n // A clipboard write is refused outside a secure context and wherever\n // the permission is denied, neither of which the call site can fix,\n // and a button that did nothing there left the reader with nothing.\n // So the value is selected, which is what the keyboard's own copy\n // acts on, and the older copy command is tried on that selection,\n // since some of those places still allow it. Only where that fails\n // too does the field announce that the value is selected — not that\n // it is copied, which it is not — and report the refusal.\n //\n // Nothing is logged — the library writes to the console nowhere, and\n // a warning an app cannot turn off is not its to emit.\n if (selectAndCopy(code.current)) {\n settle('copied');\n reportCopied(onCopied, value);\n return;\n }\n settle('selected');\n onCopyFailed?.(error);\n return;\n }\n settle('copied');\n reportCopied(onCopied, value);\n };\n void write();\n }, [onCopied, onCopyFailed, value]);\n return <div {...props} {...named} {...mergeStyles({\n className: \"x6s0dn4 x14s9m32 x1fwvt7v x1xdvaa9 x1y0btm7 xmkeg23 x9f619 x78zum5 x126z3so x1cmllll xq7elwu xwde665\"\n }, props)}>\n <span className=\"x139gbkf x1iyjqo2 x1b35g6e xdb2kus x9d6959 xwth0xh xybisxh xeuugli x6mezaz xvrbanz x126k92a\">\n <code dir=\"ltr\" ref={code} className=\"x9f619 xbppi91 x1qlqyl8 xj0a0fe x4ej8vm\">\n {value}\n </code>\n </span>\n <Button aria-labelledby={buttonName} onClick={handleCopy} size=\"xs\" variant=\"text\" className=\"x2lah0s\">\n <span className=\"xrvj5dj x1o2pa38\">\n <span aria-hidden={copied || undefined} id={copyId} {...{\n 0: {\n className: \"x15r89dc\"\n },\n 1: {\n className: \"x15r89dc xlshs6z\"\n }\n }[!!copied << 0]}>\n {copyLabel}\n </span>\n <span aria-hidden={!copied || undefined} id={copiedId} {...{\n 0: {\n className: \"x15r89dc\"\n },\n 1: {\n className: \"x15r89dc xlshs6z\"\n }\n }[!!!copied << 0]}>\n {copiedLabel}\n </span>\n </span>\n </Button>\n {/* The button's own label changes, but a label changing under a screen\n reader is not reliably announced. This is. `<output>` carries an\n implicit role of status, so it needs no role attribute of its own.\n Each write puts a new node in it, keyed by the count, since a second\n press inside the dwell otherwise left the text as it was and the\n region had nothing to announce. */}\n <output className=\"xjm9jq1 x1hyvwdk x1i1rx1s xb3r6kr x10l6tqk xuxw1ft\">\n {copy !== null && shown !== 'copy' ? <span key={copy.count}>\n {shown === 'copied' ? copiedLabel : selectedLabel}\n </span> : null}\n </output>\n </div>;\n}\n\n/**\n * Hands the call site the value it copied. What its handler throws is raised\n * on its own, outside the copy: it still reaches the page's error reporting,\n * where a rejection of the copy's own promise reached nothing but an\n * unhandled-rejection warning. Outside the component, since the React\n * Compiler compiles neither optional chaining nor a captured catch binding\n * inside a `try`.\n */\nfunction reportCopied(onCopied: ((value: string) => void) | undefined, value: string) {\n if (onCopied === undefined) {\n return;\n }\n try {\n onCopied(value);\n } catch (thrown) {\n queueMicrotask(() => {\n throw thrown;\n });\n }\n}\n\n/**\n * Selects the value's text, which is what the keyboard's own copy acts on,\n * and tries the older copy command on that selection, saying whether it\n * copied. The command is deprecated, and still the one way to the clipboard\n * on an insecure origin, which is where the newer one is refused.\n */\nfunction selectAndCopy(element: HTMLElement | null) {\n const selection = window.getSelection();\n if (element === null || selection === null) {\n return false;\n }\n const range = document.createRange();\n range.selectNodeContents(element);\n selection.removeAllRanges();\n selection.addRange(range);\n try {\n // oxlint-disable-next-line typescript/no-deprecated -- the one fallback an insecure origin still allows\n return document.execCommand('copy');\n } catch {\n return false;\n }\n}\nexport type { CopyFieldProps };\nexport default CopyField;"],"mappings":";;;;;;;;AAeA,MAAMO,kBAAkB;;;;;;;;;;;;;AAsFxB,SAAAS,UAAAC,IAAA;CAAA,MAAAC,IAAAlB,EAAA,EAAA;CAAmB,MAAA,EAAAQ,aAAAW,iBAAAV,WAAAW,eAAAV,OAAAC,UAAAE,cAAAE,eAAAM,mBAAAT,OAAA,GAAAU,UAAAL;CAUjB,MAAAM,WAAiBlB,YAAY;CAC7B,MAAAG,cAAoBW,mBAAmBI,SAAQC;CAC/C,MAAAf,YAAkBW,iBAAiBG,SAAQE;CAC3C,MAAAV,gBAAsBM,qBAAqBE,SAAQG;CAQnD,MAAA,CAAAD,MAAAE,WAAwBvB,SAIrB,IAAI;CACP,MAAAwB,QAA8CH,MAAII,SAAWjB,QAAQa,KAAIK,OAA3B;CAC9C,MAAAN,SAAeI,UAAU;CACzB,MAAAG,QAAc5B,OAAkD6B,KAAAA,CAAS;CACzE,MAAAC,OAAa9B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YAAYC,OAAOC,aAAa;CACtC,IAAIH,YAAY,QAAQC,cAAc,MACpC,OAAO;CAET,MAAMG,QAAQC,SAASC,YAAY;CACnCF,MAAMG,mBAAmBP,OAAO;CAChCC,UAAUO,gBAAgB;CAC1BP,UAAUQ,SAASL,KAAK;CACxB,IAAI;EAEF,OAAOC,SAASK,YAAY,MAAM;CACpC,QAAQ;EACN,OAAO;CACT;AACF"}
1
+ {"version":3,"file":"index.js","names":["_c","useEffect","useId","useRef","useState","useMessages","mergeStyles","COPIED_RESET_MS","copiedLabel","copyLabel","label","onCopied","value","onCopyFailed","error","selectedLabel","CopyField","t0","$","copiedLabelProp","copyLabelProp","selectedLabelProp","props","messages","copied","copy","copySelected","setCopy","shown","text","kind","timer","undefined","code","generatedId","rootId","id","copyId","copiedId","named","role","buttonName","t1","t2","Symbol","for","clearTimeout","current","t3","settle","setTimeout","count","write","navigator","clipboard","writeText","t4","selectAndCopy","reportCopied","handleCopy","className","t5","t6","t7","0","1","t8","t9","t10","t11","t12","t13","t14","t15","t16","t17","t18","thrown","queueMicrotask","element","selection","window","getSelection","range","document","createRange","selectNodeContents","removeAllRanges","addRange","execCommand"],"sources":["../../../src/components/copy-field/index.tsx"],"sourcesContent":["'use client';\n\nimport type { HTMLAttributes, RefAttributes } from 'react';\nimport * as stylex from '@stylexjs/stylex';\nimport { useCallback, useEffect, useId, useRef, useState } from 'react';\nimport { useMessages } from '../../i18n';\nimport { mergeStyles } from '../../styles/merge';\nimport '../../tokens/design.tokens.stylex';\nimport { colors, radii, spacing, typography } from '../../tokens/design.tokens.stylex';\nimport Button from '../button';\n\n// How long the confirmation stands before the control returns to offering the\n// copy again. Not a motion token: those are transition durations, measured in\n// hundreds of milliseconds, and this is a dwell — long enough to be read\n// without being long enough to leave the button lying about what it will do.\nconst COPIED_RESET_MS = 2000;\n\n// No Material Design page draws a read-only value with a copy control. It\n// follows the outlined text field: the 1dp rule in the outline role, the\n// surface behind it, and the control at its trailing end. The value is\n// body-small beside a 32dp text button with 8dp above and below it, so the\n// box is 50dp against the field's 56, which suits a value that is read\n// rather than edited, and its corner is the shape scale's small step for the\n// same reason.\n//\n// The 8dp is what holds the button's focus ring, which reaches 4dp out from\n// it, clear of the rule, and the trailing end gives the button the same 8dp\n// rather than the 12dp the value starts in by. The button brings 12dp of its\n// own around its label, so the label ends 20dp in where the two paddings\n// added up to 24.\n\ntype CopyFieldProps = {\n /**\n * What the button says once the value has been copied, and what is\n * announced. It reverts to `copyLabel` on its own after a couple of\n * seconds. Left out, it is the word for it in the I18nProvider's locale —\n * \"Copied\" in English.\n */\n copiedLabel?: string;\n /**\n * What the button says at rest. Left out, it is the word for it in the\n * I18nProvider's locale — \"Copy\" in English.\n */\n copyLabel?: string;\n /**\n * What the value is — \"Repository URL\", \"Access token\" — for a page with\n * more than one field. It names the field as a group and joins the button's\n * name, so a screen reader hears \"Copy Repository URL\" rather than one\n * \"Copy\" after another; it is not shown. The value itself stays out of the\n * button's name, since a token would be read aloud. Left out, the field is\n * unnamed and its button is \"Copy\" alone, as it always was.\n */\n label?: string;\n /**\n * Called with the value after it reaches the clipboard, never before.\n *\n * Named `onCopied` rather than `onCopy` because the root is a `<div>`, which\n * already has an `onCopy` of its own — React's handler for the native copy\n * event, fired when the reader presses the copy shortcut inside the element.\n * The two are different moments, and a prop that quietly shadowed the\n * built-in would be a trap rather than a convenience.\n */\n onCopied?: (value: string) => void;\n /**\n * Called when the write is refused, with whatever was thrown, and the\n * field's own fallback has not copied the value either. By then the value\n * is selected and the field says so — see `selectedLabel` — so this is for\n * an app that wants to say more, in a snackbar say.\n *\n * Takes the error where `onCopied` takes the value, because the value is\n * the one thing the call site already has and the reason is the one thing\n * it does not. The two refusals throw differently: outside a secure\n * context `navigator.clipboard` is not there at all, and where the\n * permission is denied it is a `DOMException`.\n */\n onCopyFailed?: (error: unknown) => void;\n /**\n * What is announced when the clipboard refused the write and the value has\n * been selected for the reader to copy themselves. The button keeps saying\n * `copyLabel`, since a label slot wide enough for this would double the\n * button's width at rest; the selection itself is what shows. Left out, it\n * is the phrase for it in the I18nProvider's locale — \"Selected to copy\"\n * in English.\n */\n selectedLabel?: string;\n /** The text shown, and the text copied. */\n value: string;\n} & Omit<HTMLAttributes<HTMLDivElement>, 'children'>;\n\n/**\n * A value to be read and taken away — a repository URL, a token, a command.\n * It shows the value in the mono face and copies it on request, confirming\n * on the button itself.\n *\n * A write refused — outside a secure context, or where the permission is\n * denied — does not leave the reader with nothing. The field selects the\n * value and tries the older copy command, which some of those places still\n * allow; failing that, the selection is left ready for the keyboard's own\n * copy, the field announces so, and `onCopyFailed` is called. One click on\n * the value selects exactly the value too.\n */\nfunction CopyField({\n copiedLabel: copiedLabelProp,\n copyLabel: copyLabelProp,\n label,\n onCopied,\n onCopyFailed,\n selectedLabel: selectedLabelProp,\n value,\n ...props\n}: CopyFieldProps & RefAttributes<HTMLDivElement>) {\n const messages = useMessages();\n const copiedLabel = copiedLabelProp ?? messages.copied;\n const copyLabel = copyLabelProp ?? messages.copy;\n const selectedLabel = selectedLabelProp ?? messages.copySelected;\n // What the last write put on the clipboard, and how many writes there have\n // been. The confirmation is that text still being the value shown, so a\n // value that changes inside the dwell — a token regenerated, a selection\n // swapped — takes the label back to Copy at once rather than confirming a\n // copy of something else. The count is what lets a second press be\n // announced, below. `kind` is whether the text reached the clipboard or\n // was only selected for the reader to copy, after a refusal.\n const [copy, setCopy] = useState<null | {\n count: number;\n kind: 'copied' | 'selected';\n text: string;\n }>(null);\n const shown: 'copied' | 'copy' | 'selected' = copy?.text === value ? copy.kind : 'copy';\n const copied = shown === 'copied';\n const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n const code = useRef<HTMLElement>(null);\n const generatedId = useId();\n const rootId = props.id ?? generatedId;\n const copyId = useId();\n const copiedId = useId();\n\n // With a label, the field is a group it names, and the button is named by\n // the label slot on show and then by the group: \"Copy Repository URL\",\n // then \"Copied Repository URL\". The slot on show rather than both, since\n // the two swap `aria-hidden` and a name taking both would say both.\n const named = label === undefined ? undefined : {\n 'aria-label': label,\n id: rootId,\n role: 'group'\n };\n const buttonName = label === undefined ? undefined : `${copied ? copiedId : copyId} ${rootId}`;\n\n // Without this, a field unmounted inside the dwell leaves a timer holding a\n // setState for a tree that is gone.\n useEffect(() => () => {\n clearTimeout(timer.current);\n }, []);\n const handleCopy = useCallback(() => {\n // The component's own state first, the dwell included, and the call\n // site's handler after it: a handler that threw used to skip the timer,\n // leaving the button on Copied for good. Its error is still the call\n // site's to see, raised on its own rather than swallowed.\n const settle = (kind: 'copied' | 'selected') => {\n clearTimeout(timer.current);\n timer.current = setTimeout(() => {\n setCopy(null);\n }, COPIED_RESET_MS);\n setCopy(current => ({\n count: (current?.count ?? 0) + 1,\n kind,\n text: value\n }));\n };\n const write = async () => {\n try {\n await navigator.clipboard.writeText(value);\n } catch (error) {\n // A clipboard write is refused outside a secure context and wherever\n // the permission is denied, neither of which the call site can fix,\n // and a button that did nothing there left the reader with nothing.\n // So the value is selected, which is what the keyboard's own copy\n // acts on, and the older copy command is tried on that selection,\n // since some of those places still allow it. Only where that fails\n // too does the field announce that the value is selected — not that\n // it is copied, which it is not — and report the refusal.\n //\n // Nothing is logged — the library writes to the console nowhere, and\n // a warning an app cannot turn off is not its to emit.\n if (selectAndCopy(code.current)) {\n settle('copied');\n reportCopied(onCopied, value);\n return;\n }\n settle('selected');\n onCopyFailed?.(error);\n return;\n }\n settle('copied');\n reportCopied(onCopied, value);\n };\n void write();\n }, [onCopied, onCopyFailed, value]);\n return <div {...props} {...named} {...mergeStyles({\n className: \"x6s0dn4 x14s9m32 x1fwvt7v x1xdvaa9 x1y0btm7 xmkeg23 x9f619 x78zum5 x126z3so x1cmllll xq7elwu xwde665\"\n }, props)}>\n <span className=\"x139gbkf x1iyjqo2 x1b35g6e xdb2kus x9d6959 xwth0xh xybisxh xeuugli x6mezaz xvrbanz x126k92a\">\n <code dir=\"ltr\" lang=\"en\" ref={code} className=\"x9f619 xbppi91 x1qlqyl8 xj0a0fe x4ej8vm\">\n {value}\n </code>\n </span>\n <Button aria-labelledby={buttonName} onClick={handleCopy} size=\"xs\" variant=\"text\" className=\"x2lah0s\">\n <span className=\"xrvj5dj x1o2pa38\">\n <span aria-hidden={copied || undefined} id={copyId} {...{\n 0: {\n className: \"x15r89dc\"\n },\n 1: {\n className: \"x15r89dc xlshs6z\"\n }\n }[!!copied << 0]}>\n {copyLabel}\n </span>\n <span aria-hidden={!copied || undefined} id={copiedId} {...{\n 0: {\n className: \"x15r89dc\"\n },\n 1: {\n className: \"x15r89dc xlshs6z\"\n }\n }[!!!copied << 0]}>\n {copiedLabel}\n </span>\n </span>\n </Button>\n {/* The button's own label changes, but a label changing under a screen\n reader is not reliably announced. This is. `<output>` carries an\n implicit role of status, so it needs no role attribute of its own.\n Each write puts a new node in it, keyed by the count, since a second\n press inside the dwell otherwise left the text as it was and the\n region had nothing to announce. */}\n <output className=\"xjm9jq1 x1hyvwdk x1i1rx1s xb3r6kr x10l6tqk xuxw1ft\">\n {copy !== null && shown !== 'copy' ? <span key={copy.count}>\n {shown === 'copied' ? copiedLabel : selectedLabel}\n </span> : null}\n </output>\n </div>;\n}\n\n/**\n * Hands the call site the value it copied. What its handler throws is raised\n * on its own, outside the copy: it still reaches the page's error reporting,\n * where a rejection of the copy's own promise reached nothing but an\n * unhandled-rejection warning. Outside the component, since the React\n * Compiler compiles neither optional chaining nor a captured catch binding\n * inside a `try`.\n */\nfunction reportCopied(onCopied: ((value: string) => void) | undefined, value: string) {\n if (onCopied === undefined) {\n return;\n }\n try {\n onCopied(value);\n } catch (thrown) {\n queueMicrotask(() => {\n throw thrown;\n });\n }\n}\n\n/**\n * Selects the value's text, which is what the keyboard's own copy acts on,\n * and tries the older copy command on that selection, saying whether it\n * copied. The command is deprecated, and still the one way to the clipboard\n * on an insecure origin, which is where the newer one is refused.\n */\nfunction selectAndCopy(element: HTMLElement | null) {\n const selection = window.getSelection();\n if (element === null || selection === null) {\n return false;\n }\n const range = document.createRange();\n range.selectNodeContents(element);\n selection.removeAllRanges();\n selection.addRange(range);\n try {\n // oxlint-disable-next-line typescript/no-deprecated -- the one fallback an insecure origin still allows\n return document.execCommand('copy');\n } catch {\n return false;\n }\n}\nexport type { CopyFieldProps };\nexport default CopyField;"],"mappings":";;;;;;;;AAeA,MAAMO,kBAAkB;;;;;;;;;;;;;AAsFxB,SAAAS,UAAAC,IAAA;CAAA,MAAAC,IAAAlB,EAAA,EAAA;CAAmB,MAAA,EAAAQ,aAAAW,iBAAAV,WAAAW,eAAAV,OAAAC,UAAAE,cAAAE,eAAAM,mBAAAT,OAAA,GAAAU,UAAAL;CAUjB,MAAAM,WAAiBlB,YAAY;CAC7B,MAAAG,cAAoBW,mBAAmBI,SAAQC;CAC/C,MAAAf,YAAkBW,iBAAiBG,SAAQE;CAC3C,MAAAV,gBAAsBM,qBAAqBE,SAAQG;CAQnD,MAAA,CAAAD,MAAAE,WAAwBvB,SAIrB,IAAI;CACP,MAAAwB,QAA8CH,MAAII,SAAWjB,QAAQa,KAAIK,OAA3B;CAC9C,MAAAN,SAAeI,UAAU;CACzB,MAAAG,QAAc5B,OAAkD6B,KAAAA,CAAS;CACzE,MAAAC,OAAa9B,OAAoB,IAAI;CACrC,MAAA+B,cAAoBhC,MAAM;CAC1B,MAAAiC,SAAeb,MAAKc,MAALF;CACf,MAAAG,SAAenC,MAAM;CACrB,MAAAoC,WAAiBpC,MAAM;CAMvB,MAAAqC,QAAc7B,UAAUsB,KAAAA,IAAVA,KAAAA,IAAA;EAAA,cACEtB;EAAK0B,IACfD;EAAMK,MACJ;CACR;CACA,MAAAC,aAAmB/B,UAAUsB,KAAAA,IAAVA,KAAAA,IAAA,GAAqCR,SAAAc,WAAAD,OAA0B,GAAIF;CAAS,IAAAO;CAAA,IAAAC;CAAA,IAAAzB,EAAA,OAAA0B,OAAAC,IAAA,2BAAA,GAAA;EAIrFH,iBAAM;GACdI,aAAaf,MAAKgB,OAAQ;EAAC;EAC1BJ,KAAA,CAAA;EAAE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MAAAyD;CAAA,OAAAA,MAAAzD,EAAA;CAAA,IAAA0D;CAAA,IAAA1D,EAAA,QAAAqB,SAAArB,EAAA,QAAAI,SAAAJ,EAAA,QAAAuD,OAAAvD,EAAA,QAAAyD,OAAAzD,EAAA,QAAAsC,MAAAtC,EAAA,QAAA2C,IAAA;EA1CNe,MAAA,qBAAA,OAAA;GA2CC,GA3CQtD;GAAK,GAAMiB;GAAK,GAAMiB;GAA/B,UAAA;IAGHK;IAKAY;IA8BAE;GAKI;;EAAAzD,EAAA,MAAAqB;EAAArB,EAAA,MAAAI;EAAAJ,EAAA,MAAAuD;EAAAvD,EAAA,MAAAyD;EAAAzD,EAAA,MAAAsC;EAAAtC,EAAA,MAAA2C;EAAA3C,EAAA,MAAA0D;CAAA,OAAAA,MAAA1D,EAAA;CAAA,OA3CD0D;AA2CC;;;;;;;;;AAWV,SAASlB,aAAa/C,UAAiDC,OAAe;CACpF,IAAID,aAAaqB,KAAAA,GACf;CAEF,IAAI;EACFrB,SAASC,KAAK;CAChB,SAASiE,QAAQ;EACfC,qBAAqB;GACnB,MAAMD;EACR,CAAC;CACH;AACF;;;;;;;AAQA,SAASpB,cAAcsB,SAA6B;CAClD,MAAMC,YAAYC,OAAOC,aAAa;CACtC,IAAIH,YAAY,QAAQC,cAAc,MACpC,OAAO;CAET,MAAMG,QAAQC,SAASC,YAAY;CACnCF,MAAMG,mBAAmBP,OAAO;CAChCC,UAAUO,gBAAgB;CAC1BP,UAAUQ,SAASL,KAAK;CACxB,IAAI;EAEF,OAAOC,SAASK,YAAY,MAAM;CACpC,QAAQ;EACN,OAAO;CACT;AACF"}
@@ -3,8 +3,18 @@ import { ReactNode, RefAttributes } from "react";
3
3
  import { DatePickerProps as DatePickerProps$1, DateValue } from "react-aria-components";
4
4
  import { DateDuration } from "@internationalized/date";
5
5
  type DatePickerProps<T extends DateValue = DateValue> = Omit<DatePickerProps$1<T>, 'children' | 'className' | 'style'> & {
6
+ /**
7
+ * What the modal's dismissing action says. Left out, it is the word for
8
+ * it in the I18nProvider's locale — "Cancel" in English.
9
+ */
10
+ cancelLabel?: string;
6
11
  /** A function may compute the class from the picker's render state. */
7
12
  className?: DatePickerProps$1<T>['className'];
13
+ /**
14
+ * What the modal's confirming action says. Left out, it is the word for
15
+ * it in the I18nProvider's locale — "OK" in English.
16
+ */
17
+ confirmLabel?: string;
8
18
  /**
9
19
  * Where to portal the calendar. Defaults to the container of the `ThemeScope`
10
20
  * around it, which keeps the calendar on that scope's tokens, or to the end
@@ -37,6 +47,11 @@ type DatePickerProps<T extends DateValue = DateValue> = Omit<DatePickerProps$1<T
37
47
  * in `em` takes that size from the slot.
38
48
  */
39
49
  leadingIcon?: ReactNode;
50
+ /**
51
+ * The modal's supporting text, above the date it holds. Left out, it is
52
+ * the I18nProvider's locale's — "Select date" in English.
53
+ */
54
+ selectDateLabel?: string;
40
55
  /**
41
56
  * Whether the calendar's header draws the month and the year as menu
42
57
  * buttons, each opening a list of them in the grid's place — see
@@ -60,7 +75,9 @@ type DatePickerProps<T extends DateValue = DateValue> = Omit<DatePickerProps$1<T
60
75
  /**
61
76
  * How much of the calendar shows at once: `{ months: 2 }` draws two
62
77
  * months side by side. Below the expanded breakpoint, where two do not
63
- * fit, they stack instead — see `Calendar`.
78
+ * fit, they stack instead — see `Calendar` — in the modal; docked, above
79
+ * the medium breakpoint, the calendar shows one month at a time there,
80
+ * since two stacked are taller than the room under the field.
64
81
  * @default { months: 1 }
65
82
  */
66
83
  visibleDuration?: DateDuration;
@@ -80,10 +97,12 @@ type DatePickerProps<T extends DateValue = DateValue> = Omit<DatePickerProps$1<T
80
97
  * The segments are `DateField`'s and the calendar is `Calendar`, so
81
98
  * `granularity`, `minValue`, `maxValue` and `isDateUnavailable` all behave
82
99
  * as they do there. Above the medium breakpoint the calendar is docked to
83
- * the field; below it, it opens centred, which is the page's modal picker.
100
+ * the field and a pick is the answer; below it, it opens centred as the
101
+ * page's modal picker, under a headline holding the date picked, and only
102
+ * its OK writes that date into the field.
84
103
  *
85
104
  * The call site's `className` and `style` land on the picker as a whole,
86
105
  * which is the element a layout positions.
87
106
  */
88
- declare function DatePicker<T extends DateValue>({ container, description, error, floatingLabel, isDisabled, label, leadingIcon, showMonthYearMenus, triggerLabel, variant, visibleDuration, ...props }: DatePickerProps<T> & RefAttributes<HTMLDivElement>): import("react").JSX.Element;
107
+ declare function DatePicker<T extends DateValue>({ cancelLabel, confirmLabel, container, description, error, floatingLabel, isDisabled, label, leadingIcon, selectDateLabel, showMonthYearMenus, triggerLabel, variant, visibleDuration, ...props }: DatePickerProps<T> & RefAttributes<HTMLDivElement>): import("react").JSX.Element;
89
108
  export { type DatePickerProps, DatePicker as default };