@trellixio/roaster-react 2.1.1 → 2.1.2

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 (118) hide show
  1. package/cjs/components/ActionList/components/ActionListDropdown.js +6 -5
  2. package/cjs/components/ActionList/components/ActionListDropdown.js.map +1 -1
  3. package/cjs/components/ActionList/components/ActionListItem.js +7 -6
  4. package/cjs/components/ActionList/components/ActionListItem.js.map +1 -1
  5. package/cjs/components/ActionList/components/ActionListSearch.js +24 -6
  6. package/cjs/components/ActionList/components/ActionListSearch.js.map +1 -1
  7. package/cjs/components/ActionList/components/ActionListSubmenu.js +4 -3
  8. package/cjs/components/ActionList/components/ActionListSubmenu.js.map +1 -1
  9. package/cjs/components/ActionList/components/ActionListSwitchItem.js +6 -5
  10. package/cjs/components/ActionList/components/ActionListSwitchItem.js.map +1 -1
  11. package/cjs/components/AppFrame/AppFrame.js.map +1 -1
  12. package/cjs/components/Avatar/Avatar.js +1 -1
  13. package/cjs/components/Avatar/Avatar.js.map +1 -1
  14. package/cjs/components/Checkbox/Checkbox.js +4 -4
  15. package/cjs/components/Checkbox/Checkbox.js.map +1 -1
  16. package/cjs/components/ColorField/ColorField.js +42 -29
  17. package/cjs/components/ColorField/ColorField.js.map +1 -1
  18. package/cjs/components/DatePicker/DatePicker.js +2 -2
  19. package/cjs/components/DatePicker/DatePicker.js.map +1 -1
  20. package/cjs/components/DropdownCard/components/DropdownCardDropdown.js +6 -5
  21. package/cjs/components/DropdownCard/components/DropdownCardDropdown.js.map +1 -1
  22. package/cjs/components/Field/Field.js +26 -6
  23. package/cjs/components/Field/Field.js.map +1 -1
  24. package/cjs/components/FileField/FileField.js +42 -29
  25. package/cjs/components/FileField/FileField.js.map +1 -1
  26. package/cjs/components/RangeField/RangeField.js +34 -21
  27. package/cjs/components/RangeField/RangeField.js.map +1 -1
  28. package/cjs/components/Select/Select.js +8 -6
  29. package/cjs/components/Select/Select.js.map +1 -1
  30. package/cjs/components/Switch/Switch.js +7 -1
  31. package/cjs/components/Switch/Switch.js.map +1 -1
  32. package/cjs/components/TextField/TextField.js +3 -1
  33. package/cjs/components/TextField/TextField.js.map +1 -1
  34. package/cjs/components/Textarea/Textarea.js +36 -4
  35. package/cjs/components/Textarea/Textarea.js.map +1 -1
  36. package/cjs/components/Tooltip/Tooltip.js +6 -5
  37. package/cjs/components/Tooltip/Tooltip.js.map +1 -1
  38. package/cjs/utils/Slot/index.js +5 -5
  39. package/cjs/utils/Slot/index.js.map +1 -1
  40. package/cjs/utils/useDropdown/DropdownTrigger.js +4 -4
  41. package/cjs/utils/useDropdown/DropdownTrigger.js.map +1 -1
  42. package/cjs/utils/useMergeRefs/index.js +51 -0
  43. package/cjs/utils/useMergeRefs/index.js.map +1 -0
  44. package/esm/components/ActionList/components/ActionListDropdown.js +2 -1
  45. package/esm/components/ActionList/components/ActionListDropdown.js.map +1 -1
  46. package/esm/components/ActionList/components/ActionListItem.js +3 -2
  47. package/esm/components/ActionList/components/ActionListItem.js.map +1 -1
  48. package/esm/components/ActionList/components/ActionListSearch.js +21 -3
  49. package/esm/components/ActionList/components/ActionListSearch.js.map +1 -1
  50. package/esm/components/ActionList/components/ActionListSubmenu.js +2 -1
  51. package/esm/components/ActionList/components/ActionListSubmenu.js.map +1 -1
  52. package/esm/components/ActionList/components/ActionListSwitchItem.js +2 -1
  53. package/esm/components/ActionList/components/ActionListSwitchItem.js.map +1 -1
  54. package/esm/components/AppFrame/AppFrame.js.map +1 -1
  55. package/esm/components/Avatar/Avatar.js +1 -1
  56. package/esm/components/Avatar/Avatar.js.map +1 -1
  57. package/esm/components/Checkbox/Checkbox.js +1 -1
  58. package/esm/components/Checkbox/Checkbox.js.map +1 -1
  59. package/esm/components/ColorField/ColorField.js +42 -29
  60. package/esm/components/ColorField/ColorField.js.map +1 -1
  61. package/esm/components/DatePicker/DatePicker.js +1 -1
  62. package/esm/components/DatePicker/DatePicker.js.map +1 -1
  63. package/esm/components/DropdownCard/components/DropdownCardDropdown.js +2 -1
  64. package/esm/components/DropdownCard/components/DropdownCardDropdown.js.map +1 -1
  65. package/esm/components/Field/Field.js +26 -6
  66. package/esm/components/Field/Field.js.map +1 -1
  67. package/esm/components/FileField/FileField.js +42 -29
  68. package/esm/components/FileField/FileField.js.map +1 -1
  69. package/esm/components/RangeField/RangeField.js +34 -21
  70. package/esm/components/RangeField/RangeField.js.map +1 -1
  71. package/esm/components/Select/Select.js +4 -2
  72. package/esm/components/Select/Select.js.map +1 -1
  73. package/esm/components/Switch/Switch.js +7 -1
  74. package/esm/components/Switch/Switch.js.map +1 -1
  75. package/esm/components/TextField/TextField.js +3 -1
  76. package/esm/components/TextField/TextField.js.map +1 -1
  77. package/esm/components/Textarea/Textarea.js +38 -6
  78. package/esm/components/Textarea/Textarea.js.map +1 -1
  79. package/esm/components/Tooltip/Tooltip.js +2 -1
  80. package/esm/components/Tooltip/Tooltip.js.map +1 -1
  81. package/esm/package.json +4 -1
  82. package/esm/utils/Slot/index.js +1 -1
  83. package/esm/utils/Slot/index.js.map +1 -1
  84. package/esm/utils/useDropdown/DropdownTrigger.js +1 -1
  85. package/esm/utils/useDropdown/DropdownTrigger.js.map +1 -1
  86. package/esm/utils/useMergeRefs/index.js +36 -0
  87. package/esm/utils/useMergeRefs/index.js.map +1 -0
  88. package/lib/components/ActionList/components/ActionListItem.d.ts +4 -1
  89. package/lib/components/ActionList/components/ActionListItem.d.ts.map +1 -1
  90. package/lib/components/ActionList/components/ActionListSearch.d.ts.map +1 -1
  91. package/lib/components/ActionList/components/ActionListSubmenu.d.ts.map +1 -1
  92. package/lib/components/AppFrame/AppFrame.d.ts +5 -1
  93. package/lib/components/AppFrame/AppFrame.d.ts.map +1 -1
  94. package/lib/components/Avatar/Avatar.d.ts +4 -1
  95. package/lib/components/Avatar/Avatar.d.ts.map +1 -1
  96. package/lib/components/Checkbox/Checkbox.d.ts.map +1 -1
  97. package/lib/components/ColorField/ColorField.d.ts.map +1 -1
  98. package/lib/components/DatePicker/DatePicker.d.ts.map +1 -1
  99. package/lib/components/DatePicker/utils/index.d.ts +2 -1
  100. package/lib/components/DatePicker/utils/index.d.ts.map +1 -1
  101. package/lib/components/Field/Field.d.ts +13 -7
  102. package/lib/components/Field/Field.d.ts.map +1 -1
  103. package/lib/components/FileField/FileField.d.ts.map +1 -1
  104. package/lib/components/RangeField/RangeField.d.ts.map +1 -1
  105. package/lib/components/Select/Select.d.ts.map +1 -1
  106. package/lib/components/Switch/Switch.d.ts.map +1 -1
  107. package/lib/components/TextField/TextField.d.ts.map +1 -1
  108. package/lib/components/Textarea/Textarea.d.ts +6 -1
  109. package/lib/components/Textarea/Textarea.d.ts.map +1 -1
  110. package/lib/components/Tooltip/Tooltip.d.ts.map +1 -1
  111. package/lib/utils/Slot/index.d.ts.map +1 -1
  112. package/lib/utils/index.d.ts +1 -0
  113. package/lib/utils/index.d.ts.map +1 -1
  114. package/lib/utils/useDropdown/DropdownTrigger.d.ts.map +1 -1
  115. package/lib/utils/useMergeRefs/index.d.ts +11 -0
  116. package/lib/utils/useMergeRefs/index.d.ts.map +1 -0
  117. package/package.json +1 -1
  118. package/roaster.css +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"Select.js","sources":["../../../../src/components/Select/Select.tsx"],"sourcesContent":["import { useMergeRefs } from '@floating-ui/react';\nimport * as React from 'react';\nimport { classNames, useUid } from '@/utils';\nimport { Field, fieldControlProps, type FieldBaseProps, type InlineFieldProps } from '../Field';\n\n/** One option of the select, as rendered. */\nexport interface SelectOption {\n /** The submitted value. */\n value: string;\n /** The text shown. */\n label: string;\n /** Whether the option can't be chosen. */\n disabled?: boolean;\n /**\n * A line under the label in a `rich` select's list. Where the browser shows its own list, it follows the label after\n * a dot.\n */\n description?: string;\n}\n\n/** The items the select understands without an `optionResolver`. */\nexport type SelectItem = string | SelectOption | { id: string | number; name?: string; title?: string };\n\n/** Turns one item of `data` into the option to render. */\nexport type OptionResolver<T> = (item: T) => SelectOption;\n\n/**\n * Strings are their own value and label, `{ id, name }` and `{ id, title }` objects use the id as the value, and any\n * other object is read as an option (`{ value, label, disabled }`).\n */\nfunction defaultOptionResolver(item: unknown): SelectOption {\n if (typeof item === 'string') return { label: item, value: item };\n\n const record = (item ?? {}) as Record<string, unknown>;\n if ('id' in record && ('name' in record || 'title' in record)) {\n return { label: String(record.name ?? record.title), value: String(record.id) };\n }\n return { ...record, value: String(record.value), label: String(record.label) } as SelectOption;\n}\n\n/**\n * Every native `<select>` prop (`name`, `value`, `required`, `aria-*`, ...) is accepted and forwarded to the select,\n * with the ref. `className` and `style` go to the field's wrapper.\n */\nexport interface SelectProps<T = SelectItem>\n extends\n FieldBaseProps,\n InlineFieldProps,\n Omit<React.ComponentPropsWithoutRef<'select'>, 'prefix' | 'className' | 'style'> {\n /**\n * The options: strings, `{ value, label }` objects, `{ id, name }` objects, or any other shape together with an\n * `optionResolver`.\n */\n options: T[];\n /** A first, empty option such as \"Choose a country\", shown until one is chosen. It can't be chosen back. */\n placeholder?: string;\n /** The element to be displayed to the left of the select field (optional). */\n prefix?: React.ReactNode;\n /** The width of the prefix element (optional). */\n prefixWidth?: number;\n /** Called with the new value when the user picks an option. The native `onChange` gets the event. */\n onValueChange?(value: string): void;\n /** Turns each item of `options` into an option (`{ value, label, disabled }`). Needed for shapes the select doesn't know. */\n optionResolver?: OptionResolver<T>;\n /**\n * Draws the list itself, where the browser allows it (the customizable select: Chrome, Edge, Safari): a check on the\n * chosen option, the theme's hover, and the options' descriptions. Other browsers (Firefox) show their own list.\n */\n rich?: boolean;\n}\n\n/**\n * Keeps the descriptions out of a rich select's field: the field then shows the chosen option's content (a\n * `<selectedcontent>` in a `<button>`, first in the select), whose description the CSS hides. Added after rendering,\n * and only where the browser draws the list itself: React 18 doesn't allow a button in a select, and the other\n * browsers show the option's text.\n */\nfunction useSelectedContent(ref: React.RefObject<HTMLSelectElement | null>, enabled: boolean) {\n React.useEffect(() => {\n const select = ref.current;\n // jsdom has `CSS` without `supports`.\n const drawsItsList = typeof CSS?.supports === 'function' && CSS.supports('appearance', 'base-select');\n if (!enabled || !select || !drawsItsList) return undefined;\n const button = document.createElement('button');\n button.append(document.createElement('selectedcontent'));\n select.prepend(button);\n return () => button.remove();\n }, [ref, enabled]);\n}\n\nconst SelectBase = React.forwardRef<HTMLSelectElement, SelectProps<unknown>>((props, ref) => {\n const {\n label,\n options,\n placeholder,\n description,\n prefix,\n prefixWidth = prefix ? 24 : 12,\n onChange,\n onValueChange,\n id,\n error,\n optionResolver = defaultOptionResolver,\n rich = false,\n inline,\n className,\n style,\n defaultValue,\n ...others\n } = props;\n const uid = useUid(id);\n const selectRef = React.useRef<HTMLSelectElement>(null);\n const mergedRef = useMergeRefs([selectRef, ref]);\n const items = options.map(optionResolver);\n useSelectedContent(selectRef, rich && items.some((item) => item.description));\n const optionElements = items.map((item) => (\n <option key={item.value} value={item.value} disabled={item.disabled}>\n {item.label}\n {item.description && (\n <>\n <span className=\"roaster-select__separator\"> · </span>\n <small className=\"roaster-select__description\">{item.description}</small>\n </>\n )}\n </option>\n ));\n // Uncontrolled with a placeholder and no default: start on the placeholder, which a browser would skip as disabled.\n const startValue = defaultValue ?? (placeholder !== undefined && others.value === undefined ? '' : undefined);\n\n const handleChange = (event: React.ChangeEvent<HTMLSelectElement>) => {\n onChange?.(event);\n onValueChange?.(event.currentTarget.value);\n };\n\n return (\n <Field\n controlId={uid}\n label={label}\n description={description}\n error={error}\n inline={inline}\n className={className}\n style={style}\n >\n <div className={classNames({ 'roaster-input-group': prefix })}>\n {prefix && <span className=\"roaster-input-group__prefix\">{prefix}</span>}\n <select\n {...others}\n {...fieldControlProps(uid, { label, description, error }, others)}\n ref={mergedRef}\n className={classNames('roaster-select', { 'roaster-select--prefixed': prefix, 'roaster-select--rich': rich })}\n style={{ paddingLeft: prefixWidth }}\n defaultValue={startValue}\n onChange={handleChange}\n >\n {placeholder !== undefined && (\n <option value=\"\" disabled>\n {placeholder}\n </option>\n )}\n {optionElements}\n </select>\n </div>\n </Field>\n );\n});\n\nSelectBase.displayName = 'Select';\n\n/**\n * A dropdown to choose one option, from a list of strings or objects, with an optional prefix. The type of `options`'\n * items is passed to `optionResolver`.\n */\nexport const Select = SelectBase as (<T = SelectItem>(\n props: SelectProps<T> & React.RefAttributes<HTMLSelectElement>\n) => React.ReactElement | null) & { displayName?: string };\n"],"names":["React","useUid","useMergeRefs","jsxs","Fragment","jsx","Field","classNames","fieldControlProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAMA,SAAS,qBAAqB,CAAC,IAAI,EAAE;AACrC,EAAE,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE;AACnE,EAAE,MAAM,MAAM,GAAG,IAAI,IAAI,EAAE;AAC3B,EAAE,IAAI,IAAI,IAAI,MAAM,KAAK,MAAM,IAAI,MAAM,IAAI,OAAO,IAAI,MAAM,CAAC,EAAE;AACjE,IAAI,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;AACnF,EAAE;AACF,EAAE,OAAO,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;AAChF;AACA,SAAS,kBAAkB,CAAC,GAAG,EAAE,OAAO,EAAE;AAC1C,EAAEA,gBAAK,CAAC,SAAS,CAAC,MAAM;AACxB,IAAI,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO;AAC9B,IAAI,MAAM,YAAY,GAAG,OAAO,GAAG,EAAE,QAAQ,KAAK,UAAU,IAAI,GAAG,CAAC,QAAQ,CAAC,YAAY,EAAE,aAAa,CAAC;AACzG,IAAI,IAAI,CAAC,OAAO,IAAI,CAAC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Q,MAAM,oBAAoBF,cAAG,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,6BAA6B,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAC7G,wBAAwBF,eAAI;AAC5B,UAAU,QAAQ;AAClB,UAAU;AACV,YAAY,GAAG,MAAM;AACrB,YAAY,GAAGK,uBAAiB,CAAC,GAAG,EAAE,EAAS,WAAW,EAAE,KAAK,EAAE,EAAE,MAAM,CAAC;AAC5E,YAAY,GAAG,EAAE,SAAS;AAC1B,YAAY,SAAS,EAAED,kBAAU,CAAC,gBAAgB,EAAE,EAAE,0BAA0B,EAAE,MAAM,EAAE,sBAAsB,EAAE,IAAI,EAAE,CAAC;AACzH,YAAY,KAAK,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE;AAC/C,YAAY,YAAY,EAAE,UAAU;AACpC,YAAY,QAAQ,EAAE,YAAY;AAClC,YAAY,QAAQ,EAAE;AACtB,cAAc,WAAW,KAAK,MAAM,oBAAoBF,cAAG,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;AAC3H,cAAc;AACd;AACA;AACA;AACA,OAAO,EAAE;AACT;AACA,GAAG;AACH,CAAC,CAAC;AACF,UAAU,CAAC,WAAW,GAAG,QAAQ;AACrB,MAAC,MAAM,GAAG;;"}
1
+ {"version":3,"file":"Select.js","sources":["../../../../src/components/Select/Select.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames, useMergeRefs, useUid } from '@/utils';\nimport { Field, fieldControlProps, type FieldBaseProps, type InlineFieldProps } from '../Field';\n\n/** One option of the select, as rendered. */\nexport interface SelectOption {\n /** The submitted value. */\n value: string;\n /** The text shown. */\n label: string;\n /** Whether the option can't be chosen. */\n disabled?: boolean;\n /**\n * A line under the label in a `rich` select's list. Where the browser shows its own list, it follows the label after\n * a dot.\n */\n description?: string;\n}\n\n/** The items the select understands without an `optionResolver`. */\nexport type SelectItem = string | SelectOption | { id: string | number; name?: string; title?: string };\n\n/** Turns one item of `data` into the option to render. */\nexport type OptionResolver<T> = (item: T) => SelectOption;\n\n/**\n * Strings are their own value and label, `{ id, name }` and `{ id, title }` objects use the id as the value, and any\n * other object is read as an option (`{ value, label, disabled }`).\n */\nfunction defaultOptionResolver(item: unknown): SelectOption {\n if (typeof item === 'string') return { label: item, value: item };\n\n const record = (item ?? {}) as Record<string, unknown>;\n if ('id' in record && ('name' in record || 'title' in record)) {\n return { label: String(record.name ?? record.title), value: String(record.id) };\n }\n return { ...record, value: String(record.value), label: String(record.label) } as SelectOption;\n}\n\n/**\n * Every native `<select>` prop (`name`, `value`, `required`, `aria-*`, ...) is accepted and forwarded to the select,\n * with the ref. `className` and `style` go to the field's wrapper.\n */\nexport interface SelectProps<T = SelectItem>\n extends\n FieldBaseProps,\n InlineFieldProps,\n Omit<React.ComponentPropsWithoutRef<'select'>, 'prefix' | 'className' | 'style'> {\n /**\n * The options: strings, `{ value, label }` objects, `{ id, name }` objects, or any other shape together with an\n * `optionResolver`.\n */\n options: T[];\n /** A first, empty option such as \"Choose a country\", shown until one is chosen. It can't be chosen back. */\n placeholder?: string;\n /** The element to be displayed to the left of the select field (optional). */\n prefix?: React.ReactNode;\n /** The width of the prefix element (optional). */\n prefixWidth?: number;\n /** Called with the new value when the user picks an option. The native `onChange` gets the event. */\n onValueChange?(value: string): void;\n /** Turns each item of `options` into an option (`{ value, label, disabled }`). Needed for shapes the select doesn't know. */\n optionResolver?: OptionResolver<T>;\n /**\n * Draws the list itself, where the browser allows it (the customizable select: Chrome, Edge, Safari): a check on the\n * chosen option, the theme's hover, and the options' descriptions. Other browsers (Firefox) show their own list.\n */\n rich?: boolean;\n}\n\n/**\n * Keeps the descriptions out of a rich select's field: the field then shows the chosen option's content (a\n * `<selectedcontent>` in a `<button>`, first in the select), whose description the CSS hides. Added after rendering,\n * and only where the browser draws the list itself: React 18 doesn't allow a button in a select, and the other\n * browsers show the option's text.\n */\nfunction useSelectedContent(ref: React.RefObject<HTMLSelectElement | null>, enabled: boolean) {\n React.useEffect(() => {\n const select = ref.current;\n // jsdom has `CSS` without `supports`.\n const drawsItsList = typeof CSS?.supports === 'function' && CSS.supports('appearance', 'base-select');\n if (!enabled || !select || !drawsItsList) return undefined;\n const button = document.createElement('button');\n button.append(document.createElement('selectedcontent'));\n select.prepend(button);\n return () => button.remove();\n }, [ref, enabled]);\n}\n\nconst SelectBase = React.forwardRef<HTMLSelectElement, SelectProps<unknown>>((props, ref) => {\n const {\n label,\n options,\n placeholder,\n description,\n keepDescription,\n prefix,\n prefixWidth = prefix ? 24 : 12,\n onChange,\n onValueChange,\n id,\n error,\n optionResolver = defaultOptionResolver,\n rich = false,\n inline,\n className,\n style,\n defaultValue,\n ...others\n } = props;\n const uid = useUid(id);\n const selectRef = React.useRef<HTMLSelectElement>(null);\n const mergedRef = useMergeRefs([selectRef, ref]);\n const items = options.map(optionResolver);\n useSelectedContent(selectRef, rich && items.some((item) => item.description));\n const optionElements = items.map((item) => (\n <option key={item.value} value={item.value} disabled={item.disabled}>\n {item.label}\n {item.description && (\n <>\n <span className=\"roaster-select__separator\"> · </span>\n <small className=\"roaster-select__description\">{item.description}</small>\n </>\n )}\n </option>\n ));\n // Uncontrolled with a placeholder and no default: start on the placeholder, which a browser would skip as disabled.\n const startValue = defaultValue ?? (placeholder !== undefined && others.value === undefined ? '' : undefined);\n\n const handleChange = (event: React.ChangeEvent<HTMLSelectElement>) => {\n onChange?.(event);\n onValueChange?.(event.currentTarget.value);\n };\n\n return (\n <Field\n controlId={uid}\n label={label}\n description={description}\n keepDescription={keepDescription}\n error={error}\n inline={inline}\n className={className}\n style={style}\n >\n <div className={classNames({ 'roaster-input-group': prefix })}>\n {prefix && <span className=\"roaster-input-group__prefix\">{prefix}</span>}\n <select\n {...others}\n {...fieldControlProps(uid, { label, description, error, keepDescription }, others)}\n ref={mergedRef}\n className={classNames('roaster-select', { 'roaster-select--prefixed': prefix, 'roaster-select--rich': rich })}\n style={{ paddingLeft: prefixWidth }}\n defaultValue={startValue}\n onChange={handleChange}\n >\n {placeholder !== undefined && (\n <option value=\"\" disabled>\n {placeholder}\n </option>\n )}\n {optionElements}\n </select>\n </div>\n </Field>\n );\n});\n\nSelectBase.displayName = 'Select';\n\n/**\n * A dropdown to choose one option, from a list of strings or objects, with an optional prefix. The type of `options`'\n * items is passed to `optionResolver`.\n */\nexport const Select = SelectBase as (<T = SelectItem>(\n props: SelectProps<T> & React.RefAttributes<HTMLSelectElement>\n) => React.ReactElement | null) & { displayName?: string };\n"],"names":["React","useUid","useMergeRefs","jsxs","Fragment","jsx","Field","classNames","fieldControlProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAKA,SAAS,qBAAqB,CAAC,IAAI,EAAE;AACrC,EAAE,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE;AACnE,EAAE,MAAM,MAAM,GAAG,IAAI,IAAI,EAAE;AAC3B,EAAE,IAAI,IAAI,IAAI,MAAM,KAAK,MAAM,IAAI,MAAM,IAAI,OAAO,IAAI,MAAM,CAAC,EAAE;AACjE,IAAI,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;AACnF,EAAE;AACF,EAAE,OAAO,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;AAChF;AACA,SAAS,kBAAkB,CAAC,GAAG,EAAE,OAAO,EAAE;AAC1C,EAAEA,gBAAK,CAAC,SAAS,CAAC,MAAM;AACxB,IAAI,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO;AAC9B,IAAI,MAAM,Y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MAAM,SAAS;AACf,MAAM,KAAK;AACX,MAAM,QAAQ,kBAAkBH,eAAI,CAAC,KAAK,EAAE,EAAE,SAAS,EAAEI,kBAAU,CAAC,EAAE,qBAAqB,EAAE,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE;AAClH,QAAQ,MAAM,oBAAoBF,cAAG,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,6BAA6B,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAC7G,wBAAwBF,eAAI;AAC5B,UAAU,QAAQ;AAClB,UAAU;AACV,YAAY,GAAG,MAAM;AACrB,YAAY,GAAGK,uBAAiB,CAAC,GAAG,EAAE,EAAS,WAAW,EAAE,KAAK,EAAE,eAAe,EAAE,EAAE,MAAM,CAAC;AAC7F,YAAY,GAAG,EAAE,SAAS;AAC1B,YAAY,SAAS,EAAED,kBAAU,CAAC,gBAAgB,EAAE,EAAE,0BAA0B,EAAE,MAAM,EAAE,sBAAsB,EAAE,IAAI,EAAE,CAAC;AACzH,YAAY,KAAK,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE;AAC/C,YAAY,YAAY,EAAE,UAAU;AACpC,YAAY,QAAQ,EAAE,YAAY;AAClC,YAAY,QAAQ,EAAE;AACtB,cAAc,WAAW,KAAK,MAAM,oBAAoBF,cAAG,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;AAC3H,cAAc;AACd;AACA;AACA;AACA,OAAO,EAAE;AACT;AACA,GAAG;AACH,CAAC,CAAC;AACF,UAAU,CAAC,WAAW,GAAG,QAAQ;AACrB,MAAC,MAAM,GAAG;;"}
@@ -29,6 +29,7 @@ const Switch = React__namespace.forwardRef((props, ref) => {
29
29
  checked: checkedProp,
30
30
  defaultChecked = false,
31
31
  description,
32
+ keepDescription,
32
33
  error,
33
34
  className,
34
35
  style,
@@ -54,6 +55,7 @@ const Switch = React__namespace.forwardRef((props, ref) => {
54
55
  controlId: uid,
55
56
  label: beside ? void 0 : label,
56
57
  description,
58
+ keepDescription,
57
59
  error,
58
60
  className,
59
61
  style,
@@ -62,7 +64,11 @@ const Switch = React__namespace.forwardRef((props, ref) => {
62
64
  "input",
63
65
  {
64
66
  ...others,
65
- ...Field.fieldControlProps(uid, { description, error }, others),
67
+ ...Field.fieldControlProps(
68
+ uid,
69
+ { description, error, keepDescription },
70
+ others
71
+ ),
66
72
  ref,
67
73
  type: "checkbox",
68
74
  role: "switch",
@@ -1 +1 @@
1
- {"version":3,"file":"Switch.js","sources":["../../../../src/components/Switch/Switch.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useUid, useControllableState } from '@/utils';\nimport { Field, fieldControlProps, type FieldBaseProps } from '../Field';\n\n/**\n * Every native `<input>` prop (`name`, `required`, `aria-*`, ...) is accepted and forwarded to the switch input, with the\n * ref. `className` and `style` go to the field's wrapper.\n */\nexport interface SwitchProps\n extends FieldBaseProps, Omit<React.ComponentPropsWithoutRef<'input'>, 'type' | 'className' | 'style'> {\n /** The HTML ID attribute to be applied to the switch element (optional). */\n id?: string;\n /** The name attribute to be applied to the switch element (optional). */\n name?: string;\n /** Whether the switch toggle should be disabled (optional). */\n disabled?: boolean;\n /** The checked state of the switch toggle, for a controlled switch (optional). */\n checked?: boolean;\n /** The default checked state of the switch toggle, for an uncontrolled switch (optional). */\n defaultChecked?: boolean;\n /** Called with the new state when the user toggles the switch. The native `onChange` gets the event. */\n onCheckedChange?(value: boolean): void;\n /**\n * Where the label goes: over the switch, as a field's label (`top`), or beside it (`end`), as a checkbox's, such as\n * in a list of settings.\n * @defaultValue 'top'\n */\n labelPosition?: 'top' | 'end';\n}\n\n/**\n * A toggle switch with a label, over it or beside it. Control it with checked and onCheckedChange, or leave it\n * uncontrolled with defaultChecked.\n */\nexport const Switch = React.forwardRef<HTMLInputElement, SwitchProps>((props, ref) => {\n const {\n id,\n label,\n name,\n disabled,\n checked: checkedProp,\n defaultChecked = false,\n description,\n error,\n className,\n style,\n onChange,\n onCheckedChange,\n labelPosition = 'top',\n ...others\n } = props;\n const beside = labelPosition === 'end';\n const [checked, setChecked] = useControllableState<boolean>({\n value: checkedProp,\n defaultValue: defaultChecked ?? false,\n onChange: onCheckedChange,\n });\n\n const uid = useUid(id);\n\n const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n onChange?.(event);\n setChecked(event.currentTarget.checked);\n };\n\n return (\n <Field\n controlId={uid}\n label={beside ? undefined : label}\n description={description}\n error={error}\n className={className}\n style={style}\n >\n {/* Its own label too, so a click on the toggle reaches the input; beside it, it holds the text. */}\n <label className=\"roaster-switch\">\n <input\n {...others}\n {...fieldControlProps(uid, { label: beside ? undefined : label, description, error }, others)}\n ref={ref}\n type=\"checkbox\"\n role=\"switch\"\n className=\"roaster-switch__input\"\n name={name}\n checked={checked}\n disabled={disabled}\n onChange={handleChange}\n />\n <span className=\"roaster-switch__track\" />\n {beside && label && <span className=\"roaster-switch__label\">{label}</span>}\n </label>\n </Field>\n );\n});\n\nSwitch.displayName = 'Switch';\n"],"names":["React","useControllableState","useUid","jsx","Field","jsxs","fieldControlProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAKY,MAAC,MAAM,GAAGA,gBAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK;AACvD,EAAE,MAAM;AACR,IAAI,EAAE;AACN,IAAI,KAAK;AACT,IAAI,IAAI;AACR,IAAI,QAAQ;AACZ,IAAI,OAAO,EAAE,WAAW;AACxB,IAAI,cAAc,GAAG,KAAK;AAC1B,IAAI,WAAW;AACf,IAAI,KAAK;AACT,IAAI,SAAS;AACb,IAAI,KAAK;AACT,IAAI,QAAQ;AACZ,IAAI,eAAe;AACnB,IAAI,aAAa,GAAG,KAAK;AACzB,IAAI,GAAG;AACP,GAAG,GAAG,KAAK;AACX,EAAE,MAAM,MAAM,GAAG,aAAa,KAAK,KAAK;AACxC,EAAE,MAAM,CAAC,OAAO,EAAE,U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E,QAAQ,EAAE,KAAK,EAAE;AAC9G,OAAO,EAAE;AACT;AACA,GAAG;AACH,CAAC;AACD,MAAM,CAAC,WAAW,GAAG,QAAQ;;"}
1
+ {"version":3,"file":"Switch.js","sources":["../../../../src/components/Switch/Switch.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useUid, useControllableState } from '@/utils';\nimport { Field, fieldControlProps, type FieldBaseProps } from '../Field';\n\n/**\n * Every native `<input>` prop (`name`, `required`, `aria-*`, ...) is accepted and forwarded to the switch input, with the\n * ref. `className` and `style` go to the field's wrapper.\n */\nexport interface SwitchProps\n extends FieldBaseProps, Omit<React.ComponentPropsWithoutRef<'input'>, 'type' | 'className' | 'style'> {\n /** The HTML ID attribute to be applied to the switch element (optional). */\n id?: string;\n /** The name attribute to be applied to the switch element (optional). */\n name?: string;\n /** Whether the switch toggle should be disabled (optional). */\n disabled?: boolean;\n /** The checked state of the switch toggle, for a controlled switch (optional). */\n checked?: boolean;\n /** The default checked state of the switch toggle, for an uncontrolled switch (optional). */\n defaultChecked?: boolean;\n /** Called with the new state when the user toggles the switch. The native `onChange` gets the event. */\n onCheckedChange?(value: boolean): void;\n /**\n * Where the label goes: over the switch, as a field's label (`top`), or beside it (`end`), as a checkbox's, such as\n * in a list of settings.\n * @defaultValue 'top'\n */\n labelPosition?: 'top' | 'end';\n}\n\n/**\n * A toggle switch with a label, over it or beside it. Control it with checked and onCheckedChange, or leave it\n * uncontrolled with defaultChecked.\n */\nexport const Switch = React.forwardRef<HTMLInputElement, SwitchProps>((props, ref) => {\n const {\n id,\n label,\n name,\n disabled,\n checked: checkedProp,\n defaultChecked = false,\n description,\n keepDescription,\n error,\n className,\n style,\n onChange,\n onCheckedChange,\n labelPosition = 'top',\n ...others\n } = props;\n const beside = labelPosition === 'end';\n const [checked, setChecked] = useControllableState<boolean>({\n value: checkedProp,\n defaultValue: defaultChecked ?? false,\n onChange: onCheckedChange,\n });\n\n const uid = useUid(id);\n\n const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n onChange?.(event);\n setChecked(event.currentTarget.checked);\n };\n\n return (\n <Field\n controlId={uid}\n label={beside ? undefined : label}\n description={description}\n keepDescription={keepDescription}\n error={error}\n className={className}\n style={style}\n >\n {/* Its own label too, so a click on the toggle reaches the input; beside it, it holds the text. */}\n <label className=\"roaster-switch\">\n <input\n {...others}\n {...fieldControlProps(\n uid,\n { label: beside ? undefined : label, description, error, keepDescription },\n others\n )}\n ref={ref}\n type=\"checkbox\"\n role=\"switch\"\n className=\"roaster-switch__input\"\n name={name}\n checked={checked}\n disabled={disabled}\n onChange={handleChange}\n />\n <span className=\"roaster-switch__track\" />\n {beside && label && <span className=\"roaster-switch__label\">{label}</span>}\n </label>\n </Field>\n );\n});\n\nSwitch.displayName = 'Switch';\n"],"names":["React","useControllableState","useUid","jsx","Field","jsxs","fieldControlProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAKY,MAAC,MAAM,GAAGA,gBAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK;AACvD,EAAE,MAAM;AACR,IAAI,EAAE;AACN,IAAI,KAAK;AACT,IAAI,IAAI;AACR,IAAI,QAAQ;AACZ,IAAI,OAAO,EAAE,WAAW;AACxB,IAAI,cAAc,GAAG,KAAK;AAC1B,IAAI,WAAW;AACf,IAAI,eAAe;AACnB,IAAI,KAAK;AACT,IAAI,SAAS;AACb,IAAI,KAAK;AACT,IAAI,QAAQ;AACZ,IAAI,eAAe;AACnB,IAAI,aAAa,GAAG,KAAK;AACzB,IAAI,GAAG;AACP,GAAG,GAAG,KAAK;AACX,EAAE,MAAM,MAAM,GAAG,aAAa,KAAK,KAAK;AACxC,EAAE,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAGC,0BAAoB,CAAC;AACrD,IAAI,KAAK,EAAE,WAAW;AACtB,IAAI,YAAY,EAAE,cAAc,IAAI,KAAK;AACzC,IAAI,QAAQ,EAAE;AACd,GAAG,CAAC;AACJ,EAAE,MAA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 -31,6 +31,7 @@ const TextField = React__namespace.forwardRef((props, ref) => {
31
31
  onChange,
32
32
  onValueChange,
33
33
  description,
34
+ keepDescription,
34
35
  rightSection,
35
36
  type = "text",
36
37
  variant,
@@ -49,7 +50,7 @@ const TextField = React__namespace.forwardRef((props, ref) => {
49
50
  "input",
50
51
  {
51
52
  ...others,
52
- ...Field.fieldControlProps(uid, { description, error }, others),
53
+ ...Field.fieldControlProps(uid, { description, error, keepDescription }, others),
53
54
  ref,
54
55
  type,
55
56
  onChange: handleChange,
@@ -71,6 +72,7 @@ const TextField = React__namespace.forwardRef((props, ref) => {
71
72
  controlId: uid,
72
73
  label,
73
74
  description,
75
+ keepDescription,
74
76
  error,
75
77
  inline,
76
78
  className,
@@ -1 +1 @@
1
- {"version":3,"file":"TextField.js","sources":["../../../../src/components/TextField/TextField.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames, Slot, useUid } from '@/utils';\nimport { Field, fieldControlProps, type FieldBaseProps, type InlineFieldProps } from '../Field';\n\n/**\n * Every native `<input>` prop (`name`, `required`, `aria-*`, ...) is accepted and forwarded to the input, with the\n * ref. `className` and `style` go to the field's wrapper.\n */\nexport interface TextFieldProps\n extends\n FieldBaseProps,\n InlineFieldProps,\n Omit<React.ComponentPropsWithoutRef<'input'>, 'prefix' | 'className' | 'style'> {\n /** `plain` has no edge or fill, such as a reply's field in a card's footer. The focus ring stays. */\n variant?: 'plain';\n /** A prefix to display before the input. */\n prefix?: React.ReactNode;\n /** A suffix to display after the input. */\n suffix?: React.ReactNode;\n /** A section to display on the right side of the input. */\n rightSection?: React.ReactNode;\n /** Called with the new value when the user changes it. The native `onChange` gets the event. */\n onValueChange?(value: string): void;\n /** The type of the input element, such as text, email, tel, url, number, or password. */\n type?: 'text' | 'email' | 'tel' | 'url' | 'number' | 'password';\n}\n\n/**\n * A single-line text field with a label, help text, error message, and an optional prefix, suffix or right-hand\n * section.\n */\nexport const TextField = React.forwardRef<HTMLInputElement, TextFieldProps>((props, ref) => {\n const {\n id,\n label,\n error,\n prefix,\n suffix,\n onChange,\n onValueChange,\n description,\n rightSection,\n type = 'text',\n variant,\n inline,\n className,\n style,\n ...others\n } = props;\n\n const uid = useUid(id);\n const hasRightSection = rightSection != null && rightSection !== false && rightSection !== '';\n\n const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n onChange?.(event);\n onValueChange?.(event.currentTarget.value);\n };\n\n const input = (\n <input\n {...others}\n {...fieldControlProps(uid, { label, description, error }, others)}\n ref={ref}\n type={type}\n onChange={handleChange}\n className={classNames('roaster-input', variant && `roaster-input--${variant}`, {\n 'roaster-merged-inputs__start': hasRightSection,\n 'roaster-input--prefixed': prefix,\n 'roaster-input--suffixed': suffix,\n })}\n />\n );\n // The prefix and suffix sit over the input, in a group as wide as it.\n const control =\n prefix || suffix ? (\n <div className=\"roaster-input-group\">\n {prefix && <span className=\"roaster-input-group__prefix\">{prefix}</span>}\n {input}\n {suffix && <span className=\"roaster-input-group__suffix\">{suffix}</span>}\n </div>\n ) : (\n input\n );\n\n return (\n <Field\n controlId={uid}\n label={label}\n description={description}\n error={error}\n inline={inline}\n className={className}\n style={style}\n >\n {hasRightSection ? (\n <div className=\"roaster-merged-inputs\">\n {control}\n {/* An element (a Button) takes the class; text is wrapped first. */}\n <Slot className=\"roaster-merged-inputs__end\">\n {React.isValidElement(rightSection) ? rightSection : <span>{rightSection}</span>}\n </Slot>\n </div>\n ) : (\n control\n )}\n </Field>\n );\n});\n\nTextField.displayName = 'TextField';\n"],"names":["React","useUid","jsx","fieldControlProps","classNames","jsxs","Field","Slot"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAKY,MAAC,SAAS,GAAGA,gBAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK;AAC1D,EAAE,MAAM;AACR,IAAI,EAAE;AACN,IAAI,KAAK;AACT,IAAI,KAAK;AACT,IAAI,MAAM;AACV,IAAI,MAAM;AACV,IAAI,QAAQ;AACZ,IAAI,aAA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ACT,IAAI,MAAM,oBAAoBA,cAAG,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,6BAA6B,EAAE,QAAQ,EAAE,MAAM,EAAE;AACxG,GAAG,EAAE,CAAC,GAAG,KAAK;AACd,EAAE,uBAAuBA,cAAG;AAC5B,IAAII,WAAK;AACT,IAAI;AACJ,MAAM,SAAS,EAAE,GAAG;AACpB,MAAM,KAAK;AACX,MAAM,WAAW;AACjB,MAAM,KAAK;AACX,MAAM,MAAM;AACZ,MAAM,SAAS;AACf,MAAM,KAAK;AACX,MAAM,QAAQ,EAAE,eAAe,mBAAmBD,eAAI,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,uBAAuB,EAAE,QAAQ,EAAE;AAC9G,QAAQ,OAAO;AACf,wBAAwBH,cAAG,CAACK,YAAI,EAAE,EAAE,SAAS,EAAE,4BAA4B,EAAE,QAAQ,EAAEP,gBAAK,CAAC,cAAc,CAAC,YAAY,CAAC,GAAG,YAAY,mBAAmBE,cAAG,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC,EAAE;AACpM,OAAO,EAAE,CAAC,GAAG;AACb;AACA,GAAG;AACH,CAAC;AACD,SAAS,CAAC,WAAW,GAAG,WAAW;;"}
1
+ {"version":3,"file":"TextField.js","sources":["../../../../src/components/TextField/TextField.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames, Slot, useUid } from '@/utils';\nimport { Field, fieldControlProps, type FieldBaseProps, type InlineFieldProps } from '../Field';\n\n/**\n * Every native `<input>` prop (`name`, `required`, `aria-*`, ...) is accepted and forwarded to the input, with the\n * ref. `className` and `style` go to the field's wrapper.\n */\nexport interface TextFieldProps\n extends\n FieldBaseProps,\n InlineFieldProps,\n Omit<React.ComponentPropsWithoutRef<'input'>, 'prefix' | 'className' | 'style'> {\n /** `plain` has no edge or fill, such as a reply's field in a card's footer. The focus ring stays. */\n variant?: 'plain';\n /** A prefix to display before the input. */\n prefix?: React.ReactNode;\n /** A suffix to display after the input. */\n suffix?: React.ReactNode;\n /** A section to display on the right side of the input. */\n rightSection?: React.ReactNode;\n /** Called with the new value when the user changes it. The native `onChange` gets the event. */\n onValueChange?(value: string): void;\n /** The type of the input element, such as text, email, tel, url, number, or password. */\n type?: 'text' | 'email' | 'tel' | 'url' | 'number' | 'password';\n}\n\n/**\n * A single-line text field with a label, help text, error message, and an optional prefix, suffix or right-hand\n * section.\n */\nexport const TextField = React.forwardRef<HTMLInputElement, TextFieldProps>((props, ref) => {\n const {\n id,\n label,\n error,\n prefix,\n suffix,\n onChange,\n onValueChange,\n description,\n keepDescription,\n rightSection,\n type = 'text',\n variant,\n inline,\n className,\n style,\n ...others\n } = props;\n\n const uid = useUid(id);\n const hasRightSection = rightSection != null && rightSection !== false && rightSection !== '';\n\n const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n onChange?.(event);\n onValueChange?.(event.currentTarget.value);\n };\n\n const input = (\n <input\n {...others}\n {...fieldControlProps(uid, { label, description, error, keepDescription }, others)}\n ref={ref}\n type={type}\n onChange={handleChange}\n className={classNames('roaster-input', variant && `roaster-input--${variant}`, {\n 'roaster-merged-inputs__start': hasRightSection,\n 'roaster-input--prefixed': prefix,\n 'roaster-input--suffixed': suffix,\n })}\n />\n );\n // The prefix and suffix sit over the input, in a group as wide as it.\n const control =\n prefix || suffix ? (\n <div className=\"roaster-input-group\">\n {prefix && <span className=\"roaster-input-group__prefix\">{prefix}</span>}\n {input}\n {suffix && <span className=\"roaster-input-group__suffix\">{suffix}</span>}\n </div>\n ) : (\n input\n );\n\n return (\n <Field\n controlId={uid}\n label={label}\n description={description}\n keepDescription={keepDescription}\n error={error}\n inline={inline}\n className={className}\n style={style}\n >\n {hasRightSection ? (\n <div className=\"roaster-merged-inputs\">\n {control}\n {/* An element (a Button) takes the class; text is wrapped first. */}\n <Slot className=\"roaster-merged-inputs__end\">\n {React.isValidElement(rightSection) ? rightSection : <span>{rightSection}</span>}\n </Slot>\n </div>\n ) : (\n control\n )}\n </Field>\n );\n});\n\nTextField.displayName = 'TextField';\n"],"names":["React","useUid","jsx","fieldControlProps","classNames","jsxs","Field","Slot"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAKY,MAAC,SAAS,GAAGA,gBAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK;AAC1D,EAAE,MAAM;AACR,IAAI,EAAE;AACN,IAAI,KAAK;AACT,IAAI,KAAK;AACT,IAAI,MAAM;AACV,IAAI,MAAM;AACV,IAAI,QAAQ;AACZ,IAAI,aAAa;AACjB,IAAI,WAAW;AACf,IAAI,eAAe;AACnB,IAAI,YAAY;AAChB,IAAI,IAAI,GAAG,MAAM;AACjB,IAAI,OAAO;AACX,IAAI,MAAM;AACV,IAAI,SAAS;AACb,IAAI,KAAK;AACT,IAAI,GAAG;AACP,GAAG,GAAG,KAAK;AACX,EAAE,MAAM,GAAG,GAAGC,YAAM,CAAC,EAAE,CAAC;AACxB,EAAE,MAAM,eAAe,GAAG,YAAY,IAAI,IAAI,IAAI,YAAY,KAAK,KAAK,IAAI,YAAY,KAAK,EAAE;AAC/F,EAAE,MAAM,YAAY,GAAG,CAAC,KAAK,KAAK;AAClC,IAAI,QAAQ,GAAG,KAAK,CAAC;AACrB,IAAI,aAAa,GAAG,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC;AAC9C,EAAE,CAAC;AACH,EAAE,MAAM,KAAK,mBAAmBC,cAAG;AACnC,IAAI,OAAO;AACX,IAAI;AACJ,MAAM,GAAG,MAAM;AACf,MAAM,GAAGC,uBAAiB,CAAC,GAAG,EAAE,EAAS,WAAW,EAAE,KAAK,EAAE,eAAe,EAAE,EAAE,MAAM,CAAC;AACvF,MAAM,GAAG;AACT,MAAM,IAAI;AACV,MAAM,QAAQ,EAAE,YAAY;AAC5B,MAAM,SAAS,EAAEC,kBAAU,CAAC,eAAe,EAAE,OAAO,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC,EAAE;AACrF,QAAQ,8BAA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ceDefault(React);
22
22
 
23
23
  const Textarea = React__namespace.forwardRef((props, ref) => {
24
- const { label, error, id, description, onChange, onValueChange, variant, className, style, ...others } = props;
24
+ const {
25
+ label,
26
+ error,
27
+ id,
28
+ description,
29
+ keepDescription,
30
+ onChange,
31
+ onValueChange,
32
+ variant,
33
+ footer,
34
+ className,
35
+ style,
36
+ ...others
37
+ } = props;
25
38
  const uid = index.useUid(id);
39
+ const hasFooter = !(footer == null || typeof footer === "boolean" || footer === "");
40
+ const footerId = `${uid}-footer`;
26
41
  const handleChange = (event) => {
27
42
  onChange?.(event);
28
43
  onValueChange?.(event.currentTarget.value);
29
44
  };
30
- return /* @__PURE__ */ jsxRuntime.jsx(Field.Field, { controlId: uid, label, description, error, className, style, children: /* @__PURE__ */ jsxRuntime.jsx(
45
+ const describedBy = [others["aria-describedby"], hasFooter && footerId].filter(Boolean).join(" ") || void 0;
46
+ const textarea = /* @__PURE__ */ jsxRuntime.jsx(
31
47
  "textarea",
32
48
  {
33
49
  ...others,
34
- ...Field.fieldControlProps(uid, { description, error }, others),
50
+ ...Field.fieldControlProps(uid, { description, error, keepDescription }, { "aria-describedby": describedBy }),
35
51
  ref,
36
52
  className: index$1.classNames("roaster-textarea", variant && `roaster-input--${variant}`),
37
53
  onChange: handleChange
38
54
  }
39
- ) });
55
+ );
56
+ return /* @__PURE__ */ jsxRuntime.jsx(
57
+ Field.Field,
58
+ {
59
+ controlId: uid,
60
+ label,
61
+ description,
62
+ keepDescription,
63
+ error,
64
+ className,
65
+ style,
66
+ children: hasFooter ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "roaster-textarea-group", children: [
67
+ textarea,
68
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "roaster-textarea-group__footer", id: footerId, children: footer })
69
+ ] }) : textarea
70
+ }
71
+ );
40
72
  });
41
73
  Textarea.displayName = "Textarea";
42
74
 
@@ -1 +1 @@
1
- {"version":3,"file":"Textarea.js","sources":["../../../../src/components/Textarea/Textarea.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames, useUid } from '@/utils';\nimport { Field, fieldControlProps, type FieldBaseProps } from '../Field';\n\n/**\n * Every native `<textarea>` prop (`name`, `rows`, `required`, `aria-*`, ...) is accepted and forwarded to the\n * textarea, with the ref. `className` and `style` go to the field's wrapper.\n */\nexport interface TextareaProps\n extends FieldBaseProps, Omit<React.ComponentPropsWithoutRef<'textarea'>, 'className' | 'style'> {\n /** Called with the new value when the user changes it. The native `onChange` gets the event. */\n onValueChange?(value: string): void;\n /** `plain` has no edge or fill, such as a comment's text area in a card. The focus ring stays. */\n variant?: 'plain';\n}\n\n/** A multiline text field with a label, help text and error message. */\nexport const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>((props, ref) => {\n const { label, error, id, description, onChange, onValueChange, variant, className, style, ...others } = props;\n\n const uid = useUid(id);\n\n const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {\n onChange?.(event);\n onValueChange?.(event.currentTarget.value);\n };\n\n return (\n <Field controlId={uid} label={label} description={description} error={error} className={className} style={style}>\n <textarea\n {...others}\n {...fieldControlProps(uid, { label, description, error }, others)}\n ref={ref}\n className={classNames('roaster-textarea', variant && `roaster-input--${variant}`)}\n onChange={handleChange}\n />\n </Field>\n );\n});\n\nTextarea.displayName = 'Textarea';\n"],"names":["React","useUid","jsx","Field","fieldControlProps","classNames"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAKY,MAAC,QAAQ,GAAGA,gBAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK;AACzD,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,MAAM,EAAE,GAAG,KAAK;AAChH,EAAE,MAAM,GAAG,GAAGC,YAAM,CAAC,EAAE,CAAC;AACxB,EAAE,MAAM,YAAY,GAAG,CAAC,KAAK,KAAK;AAClC,IAAI,QAAQ,GAAG,KAAK,CAAC;AACrB,IAAI,aAAa,GAAG,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC;AAC9C,EAAE,CAAC;AACH,EAAE,uBAAuBC,cAAG,CAACC,WAAK,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,kBAAkBD,cAAG;AAChI,IAAI,UAAU;AACd,IAAI;AACJ,MAAM,GAAG,MAAM;AACf,MAAM,GAAGE,uBAAiB,CAAC,GAAG,EAAE,EAAS,WAAW,EAAE,KAAK,EAAE,EAAE,MAAM,CAAC;AACtE,MAAM,GAAG;AACT,MAAM,SAAS,EAAEC,kBAAU,CAAC,kBAAkB,EAAE,OAAO,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC,CAAC;AACvF,MAAM,QAAQ,EAAE;AAChB;AACA,GAAG,EAAE,CAAC;AACN,CAAC;AACD,QAAQ,CAAC,WAAW,GAAG,UAAU;;"}
1
+ {"version":3,"file":"Textarea.js","sources":["../../../../src/components/Textarea/Textarea.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames, useUid } from '@/utils';\nimport { Field, fieldControlProps, type FieldBaseProps } from '../Field';\n\n/**\n * Every native `<textarea>` prop (`name`, `rows`, `required`, `aria-*`, ...) is accepted and forwarded to the\n * textarea, with the ref. `className` and `style` go to the field's wrapper.\n */\nexport interface TextareaProps\n extends FieldBaseProps, Omit<React.ComponentPropsWithoutRef<'textarea'>, 'className' | 'style'> {\n /** Called with the new value when the user changes it. The native `onChange` gets the event. */\n onValueChange?(value: string): void;\n /** `plain` has no edge or fill, such as a comment's text area in a card. The focus ring stays. */\n variant?: 'plain';\n /**\n * A short text in the box, under the text at its end, such as a count of the characters: `912 / 1000`. The textarea\n * is described by it. Not with `plain`, which has no box: put it beside the card's buttons.\n */\n footer?: React.ReactNode;\n}\n\n/** A multiline text field with a label, help text and error message, and an optional footer in its box. */\nexport const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>((props, ref) => {\n const {\n label,\n error,\n id,\n description,\n keepDescription,\n onChange,\n onValueChange,\n variant,\n footer,\n className,\n style,\n ...others\n } = props;\n\n const uid = useUid(id);\n const hasFooter = !(footer == null || typeof footer === 'boolean' || footer === '');\n const footerId = `${uid}-footer`;\n\n const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {\n onChange?.(event);\n onValueChange?.(event.currentTarget.value);\n };\n\n // The footer describes the textarea after any description it already has, and before the field's texts under it.\n const describedBy = [others['aria-describedby'], hasFooter && footerId].filter(Boolean).join(' ') || undefined;\n const textarea = (\n <textarea\n {...others}\n {...fieldControlProps(uid, { label, description, error, keepDescription }, { 'aria-describedby': describedBy })}\n ref={ref}\n className={classNames('roaster-textarea', variant && `roaster-input--${variant}`)}\n onChange={handleChange}\n />\n );\n\n return (\n <Field\n controlId={uid}\n label={label}\n description={description}\n keepDescription={keepDescription}\n error={error}\n className={className}\n style={style}\n >\n {hasFooter ? (\n <div className=\"roaster-textarea-group\">\n {textarea}\n <div className=\"roaster-textarea-group__footer\" id={footerId}>\n {footer}\n </div>\n </div>\n ) : (\n textarea\n )}\n </Field>\n );\n});\n\nTextarea.displayName = 'Textarea';\n"],"names":["React","useUid","jsx","fieldControlProps","classNames","Field","jsxs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAKY,MAAC,QAAQ,GAAGA,gBAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK;AACzD,EAAE,MAAM;AACR,IAAI,KAAK;AACT,IAAI,KAAK;AACT,IAAI,EAAE;AACN,IAAI,WAAW;AACf,IAAI,eAAe;AACnB,IAAI,QAAQ;AACZ,IAAI,aAAa;AACjB,IAAI,OAAO;AACX,IAAI,MAAM;AACV,IAAI,SAAS;AACb,IAAI,KAAK;AACT,IAAI,GAAG;AACP,GAAG,GAAG,KAAK;AACX,EAAE,MAAM,GAAG,GAAGC,YAAM,C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Q,QAAQ;AAChB,wBAAwBJ,cAAG,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,gCAAgC,EAAE,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE;AAClH,OAAO,EAAE,CAAC,GAAG;AACb;AACA,GAAG;AACH,CAAC;AACD,QAAQ,CAAC,WAAW,GAAG,UAAU;;"}
@@ -4,11 +4,12 @@
4
4
  var jsxRuntime = require('react/jsx-runtime');
5
5
  var React = require('react');
6
6
  var react = require('@floating-ui/react');
7
- var index$1 = require('../../utils/Slot/index.js');
7
+ var index$2 = require('../../utils/Slot/index.js');
8
8
  var useTooltip = require('./useTooltip.js');
9
9
  var TooltipCallout = require('./TooltipCallout.js');
10
10
  var index = require('../../utils/useControllableState/index.js');
11
- var index$2 = require('../../utils/classNames/index.js');
11
+ var index$1 = require('../../utils/useMergeRefs/index.js');
12
+ var index$3 = require('../../utils/classNames/index.js');
12
13
 
13
14
  function _interopNamespaceDefault(e) {
14
15
  var n = Object.create(null);
@@ -39,15 +40,15 @@ const TooltipBase = React__namespace.forwardRef((props, ref) => {
39
40
  } = props;
40
41
  const [open, setOpen] = index.useControllableState({ value: openProp, defaultValue: defaultOpen, onChange: onOpenChange });
41
42
  const tooltip = useTooltip.useTooltip({ placement, open, onOpenChange: setOpen, offset, inline });
42
- const targetRef = react.useMergeRefs([tooltip.refs.setReference, ref]);
43
+ const targetRef = index$1.useMergeRefs([tooltip.refs.setReference, ref]);
43
44
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
44
- /* @__PURE__ */ jsxRuntime.jsx(index$1.Slot, { ...tooltip.getReferenceProps(), ref: targetRef, children }),
45
+ /* @__PURE__ */ jsxRuntime.jsx(index$2.Slot, { ...tooltip.getReferenceProps(), ref: targetRef, children }),
45
46
  open && /* @__PURE__ */ jsxRuntime.jsx(react.FloatingPortal, { children: /* @__PURE__ */ jsxRuntime.jsx(
46
47
  "div",
47
48
  {
48
49
  ...tooltip.getFloatingProps(others),
49
50
  ref: tooltip.refs.setFloating,
50
- className: index$2.classNames("roaster-tooltip", "roaster-tooltip--floating", className),
51
+ className: index$3.classNames("roaster-tooltip", "roaster-tooltip--floating", className),
51
52
  style: { ...tooltip.floatingStyles, ...style },
52
53
  "data-placement": tooltip.placement,
53
54
  children: label
@@ -1 +1 @@
1
- {"version":3,"file":"Tooltip.js","sources":["../../../../src/components/Tooltip/Tooltip.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useMergeRefs, FloatingPortal, Placement } from '@floating-ui/react';\nimport { Slot } from '@/utils/Slot';\nimport { classNames, useControllableState } from '@/utils';\nimport { useTooltip } from './useTooltip';\nimport { TooltipCallout } from './TooltipCallout';\n\nexport type FloatingSide = Placement;\n\n/** Every native `<div>` prop (`id`, `className`, `style`, ...) is accepted and forwarded to the tooltip. */\nexport interface TooltipProps extends Omit<React.ComponentPropsWithoutRef<'div'>, 'children'> {\n /** The target: one element that takes the focus (a button, a link, or an element with `tabIndex={0}`). */\n children: React.ReactNode;\n /** The text of the tooltip. */\n label: React.ReactNode;\n /**\n * Where the tooltip goes relative to its target. It moves to the other side when there is no room.\n * @defaultValue 'top'\n */\n placement?: FloatingSide;\n /** Whether the tooltip is open, when the parent controls it. Leave it out to let hover and focus open it. */\n open?: boolean;\n /**\n * Whether the tooltip starts open, when it is not controlled.\n * @defaultValue false\n */\n defaultOpen?: boolean;\n /** Called when hover, focus or Escape opens or closes the tooltip, controlled or not. */\n onOpenChange?(open: boolean): void;\n /**\n * The distance in pixels between the tooltip and its target.\n * @defaultValue 4\n */\n offset?: number;\n /** Set it when the target is text that may wrap over several lines, so the tooltip follows the hovered line. */\n inline?: boolean;\n}\n\nconst TooltipBase = React.forwardRef<HTMLElement, TooltipProps>((props, ref) => {\n const {\n children,\n label,\n placement = 'top',\n open: openProp,\n defaultOpen = false,\n onOpenChange,\n offset = 4,\n inline = false,\n className,\n style,\n ...others\n } = props;\n\n const [open, setOpen] = useControllableState({ value: openProp, defaultValue: defaultOpen, onChange: onOpenChange });\n const tooltip = useTooltip({ placement, open, onOpenChange: setOpen, offset, inline });\n const targetRef = useMergeRefs([tooltip.refs.setReference, ref]);\n\n return (\n <>\n <Slot {...tooltip.getReferenceProps()} ref={targetRef}>\n {children}\n </Slot>\n {open && (\n <FloatingPortal>\n <div\n {...tooltip.getFloatingProps(others)}\n ref={tooltip.refs.setFloating}\n className={classNames('roaster-tooltip', 'roaster-tooltip--floating', className)}\n style={{ ...tooltip.floatingStyles, ...style }}\n data-placement={tooltip.placement}\n >\n {label}\n </div>\n </FloatingPortal>\n )}\n </>\n );\n});\n\nTooltipBase.displayName = 'Tooltip';\n\n/**\n * A short description of its target, shown while the target is hovered or has the focus, and hidden with Escape. The\n * target is described by it (`aria-describedby`). The ref goes to the target. Tooltip.Callout stays open beside its\n * host until it is closed.\n */\nexport const Tooltip = Object.assign(TooltipBase, { Callout: TooltipCallout });\n"],"names":["React","useControllableState","useTooltip","useMergeRefs","jsxs","Fragment","jsx","Slot","FloatingPortal","classNames","TooltipCallout"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAQA,MAAM,WAAW,GAAGA,gBAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK;AACrD,EAAE,MAAM;AACR,IAAI,QAAQ;AACZ,IAAI,KAAK;AACT,IAAI,SAAS,GAAG,KAAK;AACrB,IAAI,IAAI,EAAE,QAAQ;AAClB,IAAI,WAAW,GAAG,KAAK;AACvB,IAAI,YAAY;AAChB,IAAI,MAAM,GAAG,CAAC;AACd,IAAI,MAAM,GAAG,KAAK;AAClB,IAAI,SAAS;AACb,IAAI,KAAK;AACT,IAAI,GAAG;AACP,GAAG,GAAG,KAAK;AACX,EAAE,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAGC,0BAAoB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC;AACtH,EAAE,MAAM,OAAO,GAAGC,qBAAU,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AACxF,EAAE,MAAM,SAAS,GAAGC,kBAAY,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC;AAClE,EAAE,uBAAuBC,eAAI,CAACC,mBAAQ,EAAE,EAAE,QAAQ,EAAE;AACpD,oBAAoBC,cAAG,CAACC,YAAI,EAAE,EAAE,GAAG,OAAO,CAAC,iBAAiB,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AAC3F,IAAI,IAAI,oBAAoBD,cAAG,CAACE,oBAAc,EAAE,EAAE,QAAQ,kBAAkBF,cAAG;AAC/E,MAAM,KAAK;AACX,MAAM;AACN,QAAQ,GAAG,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAAC;AAC3C,QAAQ,GAAG,EAAE,OAAO,CAAC,IAAI,CAAC,WAAW;AACrC,QAAQ,SAAS,EAAEG,kBAAU,CAAC,iBAAiB,EAAE,2BAA2B,EAAE,SAAS,CAAC;AACxF,QAAQ,KAAK,EAAE,EAAE,GAAG,OAAO,CAAC,cAAc,EAAE,GAAG,KAAK,EAAE;AACtD,QAAQ,gBAAgB,EAAE,OAAO,CAAC,SAAS;AAC3C,QAAQ,QAAQ,EAAE;AAClB;AACA,KAAK,EAAE;AACP,GAAG,EAAE,CAAC;AACN,CAAC,CAAC;AACF,WAAW,CAAC,WAAW,GAAG,SAAS;AACvB,MAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,OAAO,EAAEC,6BAAc,EAAE;;"}
1
+ {"version":3,"file":"Tooltip.js","sources":["../../../../src/components/Tooltip/Tooltip.tsx"],"sourcesContent":["import * as React from 'react';\nimport { FloatingPortal, Placement } from '@floating-ui/react';\nimport { Slot } from '@/utils/Slot';\nimport { classNames, useControllableState, useMergeRefs } from '@/utils';\nimport { useTooltip } from './useTooltip';\nimport { TooltipCallout } from './TooltipCallout';\n\nexport type FloatingSide = Placement;\n\n/** Every native `<div>` prop (`id`, `className`, `style`, ...) is accepted and forwarded to the tooltip. */\nexport interface TooltipProps extends Omit<React.ComponentPropsWithoutRef<'div'>, 'children'> {\n /** The target: one element that takes the focus (a button, a link, or an element with `tabIndex={0}`). */\n children: React.ReactNode;\n /** The text of the tooltip. */\n label: React.ReactNode;\n /**\n * Where the tooltip goes relative to its target. It moves to the other side when there is no room.\n * @defaultValue 'top'\n */\n placement?: FloatingSide;\n /** Whether the tooltip is open, when the parent controls it. Leave it out to let hover and focus open it. */\n open?: boolean;\n /**\n * Whether the tooltip starts open, when it is not controlled.\n * @defaultValue false\n */\n defaultOpen?: boolean;\n /** Called when hover, focus or Escape opens or closes the tooltip, controlled or not. */\n onOpenChange?(open: boolean): void;\n /**\n * The distance in pixels between the tooltip and its target.\n * @defaultValue 4\n */\n offset?: number;\n /** Set it when the target is text that may wrap over several lines, so the tooltip follows the hovered line. */\n inline?: boolean;\n}\n\nconst TooltipBase = React.forwardRef<HTMLElement, TooltipProps>((props, ref) => {\n const {\n children,\n label,\n placement = 'top',\n open: openProp,\n defaultOpen = false,\n onOpenChange,\n offset = 4,\n inline = false,\n className,\n style,\n ...others\n } = props;\n\n const [open, setOpen] = useControllableState({ value: openProp, defaultValue: defaultOpen, onChange: onOpenChange });\n const tooltip = useTooltip({ placement, open, onOpenChange: setOpen, offset, inline });\n const targetRef = useMergeRefs([tooltip.refs.setReference, ref]);\n\n return (\n <>\n <Slot {...tooltip.getReferenceProps()} ref={targetRef}>\n {children}\n </Slot>\n {open && (\n <FloatingPortal>\n <div\n {...tooltip.getFloatingProps(others)}\n ref={tooltip.refs.setFloating}\n className={classNames('roaster-tooltip', 'roaster-tooltip--floating', className)}\n style={{ ...tooltip.floatingStyles, ...style }}\n data-placement={tooltip.placement}\n >\n {label}\n </div>\n </FloatingPortal>\n )}\n </>\n );\n});\n\nTooltipBase.displayName = 'Tooltip';\n\n/**\n * A short description of its target, shown while the target is hovered or has the focus, and hidden with Escape. The\n * target is described by it (`aria-describedby`). The ref goes to the target. Tooltip.Callout stays open beside its\n * host until it is closed.\n */\nexport const Tooltip = Object.assign(TooltipBase, { Callout: TooltipCallout });\n"],"names":["React","useControllableState","useTooltip","useMergeRefs","jsxs","Fragment","jsx","Slot","FloatingPortal","classNames","TooltipCallout"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,MAAM,WAAW,GAAGA,gBAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK;AACrD,EAAE,MAAM;AACR,IAAI,QAAQ;AACZ,IAAI,KAAK;AACT,IAAI,SAAS,GAAG,KAAK;AACrB,IAAI,IAAI,EAAE,QAAQ;AAClB,IAAI,WAAW,GAAG,KAAK;AACvB,IAAI,YAAY;AAChB,IAAI,MAAM,GAAG,CAAC;AACd,IAAI,MAAM,GAAG,KAAK;AAClB,IAAI,SAAS;AACb,IAAI,KAAK;AACT,IAAI,GAAG;AACP,GAAG,GAAG,KAAK;AACX,EAAE,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAGC,0BAAoB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC;AACtH,EAAE,MAAM,OAAO,GAAGC,qBAAU,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AACxF,EAAE,MAAM,SAAS,GAAGC,oBAAY,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC;AAClE,EAAE,uBAAuBC,eAAI,CAACC,mBAAQ,EAAE,EAAE,QAAQ,EAAE;AACpD,oBAAoBC,cAAG,CAACC,YAAI,EAAE,EAAE,GAAG,OAAO,CAAC,iBAAiB,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AAC3F,IAAI,IAAI,oBAAoBD,cAAG,CAACE,oBAAc,EAAE,EAAE,QAAQ,kBAAkBF,cAAG;AAC/E,MAAM,KAAK;AACX,MAAM;AACN,QAAQ,GAAG,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAAC;AAC3C,QAAQ,GAAG,EAAE,OAAO,CAAC,IAAI,CAAC,WAAW;AACrC,QAAQ,SAAS,EAAEG,kBAAU,CAAC,iBAAiB,EAAE,2BAA2B,EAAE,SAAS,CAAC;AACxF,QAAQ,KAAK,EAAE,EAAE,GAAG,OAAO,CAAC,cAAc,EAAE,GAAG,KAAK,EAAE;AACtD,QAAQ,gBAAgB,EAAE,OAAO,CAAC,SAAS;AAC3C,QAAQ,QAAQ,EAAE;AAClB;AACA,KAAK,EAAE;AACP,GAAG,EAAE,CAAC;AACN,CAAC,CAAC;AACF,WAAW,CAAC,WAAW,GAAG,SAAS;AACvB,MAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,OAAO,EAAEC,6BAAc,EAAE;;"}
@@ -1,10 +1,10 @@
1
1
  'use client';
2
2
  'use strict';
3
3
 
4
- var react = require('@floating-ui/react');
5
4
  var React = require('react');
6
- var index$1 = require('../classNames/index.js');
7
- var index = require('../getElementRef/index.js');
5
+ var index$2 = require('../classNames/index.js');
6
+ var index$1 = require('../getElementRef/index.js');
7
+ var index = require('../useMergeRefs/index.js');
8
8
 
9
9
  function _interopNamespaceDefault(e) {
10
10
  var n = Object.create(null);
@@ -30,7 +30,7 @@ function mergeProps(slotProps, childProps) {
30
30
  slotValue(...args);
31
31
  };
32
32
  } else if (key === "className") {
33
- merged.className = index$1.classNames(slotValue, childValue);
33
+ merged.className = index$2.classNames(slotValue, childValue);
34
34
  } else if (key === "style") {
35
35
  merged.style = { ...slotValue, ...childValue };
36
36
  }
@@ -39,7 +39,7 @@ function mergeProps(slotProps, childProps) {
39
39
  }
40
40
  const Slot = React__namespace.forwardRef(({ children, ...slotProps }, forwardedRef) => {
41
41
  const child = React__namespace.isValidElement(children) ? children : null;
42
- const ref = react.useMergeRefs([forwardedRef, child ? index.getElementRef(child) : void 0]);
42
+ const ref = index.useMergeRefs([forwardedRef, child ? index$1.getElementRef(child) : void 0]);
43
43
  if (!child) {
44
44
  if (React__namespace.Children.count(children) > 1) throw new Error("Slot needs a single element as its child.");
45
45
  return null;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../src/utils/Slot/index.tsx"],"sourcesContent":["import { useMergeRefs } from '@floating-ui/react';\nimport * as React from 'react';\nimport { classNames } from '../classNames';\nimport { getElementRef } from '../getElementRef';\n\nexport interface SlotProps extends React.HTMLAttributes<HTMLElement> {\n /** One element, which receives the slot's props and ref. */\n children?: React.ReactNode;\n}\n\ntype AnyProps = Record<string, unknown>;\n\n/**\n * Merges the slot's props into the child's: event handlers both run (the child's first), classes add up, styles merge\n * with the child's winning, and anything else is the child's.\n */\nfunction mergeProps(slotProps: AnyProps, childProps: AnyProps): AnyProps {\n const merged: AnyProps = { ...slotProps, ...childProps };\n Object.keys(slotProps).forEach((key) => {\n const slotValue = slotProps[key];\n const childValue = childProps[key];\n if (/^on[A-Z]/.test(key) && typeof slotValue === 'function' && typeof childValue === 'function') {\n merged[key] = (...args: unknown[]) => {\n childValue(...args);\n slotValue(...args);\n };\n } else if (key === 'className') {\n merged.className = classNames(slotValue as string, childValue as string);\n } else if (key === 'style') {\n merged.style = { ...(slotValue as React.CSSProperties), ...(childValue as React.CSSProperties) };\n }\n });\n return merged;\n}\n\n/**\n * Renders its only child with the slot's props and ref merged in, instead of an element of its own. It is what\n * `asChild` and the triggers use: `<Tooltip label=\"Help\"><Button>?</Button></Tooltip>`.\n */\nexport const Slot = React.forwardRef<HTMLElement, SlotProps>(({ children, ...slotProps }, forwardedRef) => {\n const child = React.isValidElement<AnyProps>(children) ? children : null;\n const ref = useMergeRefs([forwardedRef, child ? getElementRef(child) : undefined]);\n\n if (!child) {\n if (React.Children.count(children) > 1) throw new Error('Slot needs a single element as its child.');\n return null;\n }\n // The ref last: on React 19 the child's own ref is in its props, and it's merged into this one.\n return React.cloneElement(child, { ...mergeProps(slotProps, child.props), ref });\n});\n\nSlot.displayName = 'Slot';\n"],"names":["classNames","React","useMergeRefs","getElementRef"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAKA,SAAS,UAAU,CAAC,SAAS,EAAE,UAAU,EAAE;AAC3C,EAAE,MAAM,MAAM,GAAG,EAAE,GAAG,SAAS,EAAE,GAAG,UAAU,EAAE;AAChD,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,KAAK;AAC1C,IAAI,MAAM,SAAS,GAAG,SAAS,CAAC,GAAG,CAAC;AACpC,IAAI,MAAM,UAAU,GAAG,UAAU,CAAC,GAAG,CAAC;AACtC,IAAI,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,OAAO,SAAS,KAAK,UAAU,IAAI,OAAO,UAAU,KAAK,UAAU,EAAE;AACrG,MAAM,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,KAAK;AACjC,QAAQ,UAAU,CAAC,GAAG,IAAI,CAAC;AAC3B,QAAQ,SAAS,CAAC,GAAG,IAAI,CAAC;AAC1B,MAAM,CAAC;AACP,IAAI,CAAC,MAAM,IAAI,GAAG,KAAK,WAAW,EAAE;AACpC,MAAM,MAAM,CAAC,SAAS,GAAGA,kBAAU,CAAC,SAAS,EAAE,UAAU,CAAC;AAC1D,IAAI,CAAC,MAAM,IAAI,GAAG,KAAK,OAAO,EAAE;AAChC,MAAM,MAAM,CAAC,KAAK,GAAG,EAAE,GAAG,SAAS,EAAE,GAAG,UAAU,EAAE;AACpD,IAAI;AACJ,EAAE,CAAC,CAAC;AACJ,EAAE,OAAO,MAAM;AACf;AACY,MAAC,IAAI,GAAGC,gBAAK,CAAC,UAAU,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAE,EAAE,YAAY,KAAK;AACnF,EAAE,MAAM,KAAK,GAAGA,gBAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,GAAG,QAAQ,GAAG,IAAI;AAChE,EAAE,MAAM,GAAG,GAAGC,kBAAY,CAAC,CAAC,YAAY,EAAE,KAAK,GAAGC,mBAAa,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,CAAC;AACjF,EAAE,IAAI,CAAC,KAAK,EAAE;AACd,IAAI,IAAIF,gBAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC;AACxG,IAAI,OAAO,IAAI;AACf,EAAE;AACF,EAAE,OAAOA,gBAAK,CAAC,YAAY,CAAC,KAAK,EAAE,EAAE,GAAG,UAAU,CAAC,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,CAAC;AAClF,CAAC;AACD,IAAI,CAAC,WAAW,GAAG,MAAM;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../src/utils/Slot/index.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames } from '../classNames';\nimport { getElementRef } from '../getElementRef';\nimport { useMergeRefs } from '../useMergeRefs';\n\nexport interface SlotProps extends React.HTMLAttributes<HTMLElement> {\n /** One element, which receives the slot's props and ref. */\n children?: React.ReactNode;\n}\n\ntype AnyProps = Record<string, unknown>;\n\n/**\n * Merges the slot's props into the child's: event handlers both run (the child's first), classes add up, styles merge\n * with the child's winning, and anything else is the child's.\n */\nfunction mergeProps(slotProps: AnyProps, childProps: AnyProps): AnyProps {\n const merged: AnyProps = { ...slotProps, ...childProps };\n Object.keys(slotProps).forEach((key) => {\n const slotValue = slotProps[key];\n const childValue = childProps[key];\n if (/^on[A-Z]/.test(key) && typeof slotValue === 'function' && typeof childValue === 'function') {\n merged[key] = (...args: unknown[]) => {\n childValue(...args);\n slotValue(...args);\n };\n } else if (key === 'className') {\n merged.className = classNames(slotValue as string, childValue as string);\n } else if (key === 'style') {\n merged.style = { ...(slotValue as React.CSSProperties), ...(childValue as React.CSSProperties) };\n }\n });\n return merged;\n}\n\n/**\n * Renders its only child with the slot's props and ref merged in, instead of an element of its own. It is what\n * `asChild` and the triggers use: `<Tooltip label=\"Help\"><Button>?</Button></Tooltip>`.\n */\nexport const Slot = React.forwardRef<HTMLElement, SlotProps>(({ children, ...slotProps }, forwardedRef) => {\n const child = React.isValidElement<AnyProps>(children) ? children : null;\n const ref = useMergeRefs([forwardedRef, child ? getElementRef(child) : undefined]);\n\n if (!child) {\n if (React.Children.count(children) > 1) throw new Error('Slot needs a single element as its child.');\n return null;\n }\n // The ref last: on React 19 the child's own ref is in its props, and it's merged into this one.\n return React.cloneElement(child, { ...mergeProps(slotProps, child.props), ref });\n});\n\nSlot.displayName = 'Slot';\n"],"names":["classNames","React","useMergeRefs","getElementRef"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAKA,SAAS,UAAU,CAAC,SAAS,EAAE,UAAU,EAAE;AAC3C,EAAE,MAAM,MAAM,GAAG,EAAE,GAAG,SAAS,EAAE,GAAG,UAAU,EAAE;AAChD,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,KAAK;AAC1C,IAAI,MAAM,SAAS,GAAG,SAAS,CAAC,GAAG,CAAC;AACpC,IAAI,MAAM,UAAU,GAAG,UAAU,CAAC,GAAG,CAAC;AACtC,IAAI,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,OAAO,SAAS,KAAK,UAAU,IAAI,OAAO,UAAU,KAAK,UAAU,EAAE;AACrG,MAAM,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,KAAK;AACjC,QAAQ,UAAU,CAAC,GAAG,IAAI,CAAC;AAC3B,QAAQ,SAAS,CAAC,GAAG,IAAI,CAAC;AAC1B,MAAM,CAAC;AACP,IAAI,CAAC,MAAM,IAAI,GAAG,KAAK,WAAW,EAAE;AACpC,MAAM,MAAM,CAAC,SAAS,GAAGA,kBAAU,CAAC,SAAS,EAAE,UAAU,CAAC;AAC1D,IAAI,CAAC,MAAM,IAAI,GAAG,KAAK,OAAO,EAAE;AAChC,MAAM,MAAM,CAAC,KAAK,GAAG,EAAE,GAAG,SAAS,EAAE,GAAG,UAAU,EAAE;AACpD,IAAI;AACJ,EAAE,CAAC,CAAC;AACJ,EAAE,OAAO,MAAM;AACf;AACY,MAAC,IAAI,GAAGC,gBAAK,CAAC,UAAU,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAE,EAAE,YAAY,KAAK;AACnF,EAAE,MAAM,KAAK,GAAGA,gBAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,GAAG,QAAQ,GAAG,IAAI;AAChE,EAAE,MAAM,GAAG,GAAGC,kBAAY,CAAC,CAAC,YAAY,EAAE,KAAK,GAAGC,qBAAa,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,CAAC;AACjF,EAAE,IAAI,CAAC,KAAK,EAAE;AACd,IAAI,IAAIF,gBAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC;AACxG,IAAI,OAAO,IAAI;AACf,EAAE;AACF,EAAE,OAAOA,gBAAK,CAAC,YAAY,CAAC,KAAK,EAAE,EAAE,GAAG,UAAU,CAAC,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,CAAC;AAClF,CAAC;AACD,IAAI,CAAC,WAAW,GAAG,MAAM;;"}
@@ -2,9 +2,9 @@
2
2
  'use strict';
3
3
 
4
4
  var jsxRuntime = require('react/jsx-runtime');
5
- var react = require('@floating-ui/react');
6
5
  var React = require('react');
7
- var index = require('../Slot/index.js');
6
+ var index$1 = require('../Slot/index.js');
7
+ var index = require('../useMergeRefs/index.js');
8
8
 
9
9
  function _interopNamespaceDefault(e) {
10
10
  var n = Object.create(null);
@@ -22,8 +22,8 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
22
22
  function createDropdownTrigger(name, useDropdownContext) {
23
23
  const Trigger = React__namespace.forwardRef(({ children, ...props }, ref) => {
24
24
  const context = useDropdownContext();
25
- const mergedRef = react.useMergeRefs([context.refs.setReference, ref]);
26
- return /* @__PURE__ */ jsxRuntime.jsx(index.Slot, { ...context.getReferenceProps(props), ref: mergedRef, children });
25
+ const mergedRef = index.useMergeRefs([context.refs.setReference, ref]);
26
+ return /* @__PURE__ */ jsxRuntime.jsx(index$1.Slot, { ...context.getReferenceProps(props), ref: mergedRef, children });
27
27
  });
28
28
  Trigger.displayName = `${name}Trigger`;
29
29
  return Trigger;
@@ -1 +1 @@
1
- {"version":3,"file":"DropdownTrigger.js","sources":["../../../../src/utils/useDropdown/DropdownTrigger.tsx"],"sourcesContent":["import { useMergeRefs } from '@floating-ui/react';\nimport * as React from 'react';\nimport { Slot } from '../Slot';\nimport type { useDropdown } from './index';\n\nexport interface DropdownTriggerProps extends React.HTMLAttributes<HTMLElement> {\n /** The element that opens the dropdown, such as a Button. It must accept a ref: not a fragment, text or number. */\n children: React.ReactElement;\n}\n\n/**\n * Makes the trigger component of a dropdown (ActionList.Trigger, DropdownCard.Trigger): it gives its child element\n * the dropdown's ref and props, keeping the child's own.\n */\nexport function createDropdownTrigger(name: string, useDropdownContext: () => ReturnType<typeof useDropdown>) {\n const Trigger = React.forwardRef<HTMLElement, DropdownTriggerProps>(({ children, ...props }, ref) => {\n const context = useDropdownContext();\n const mergedRef = useMergeRefs([context.refs.setReference, ref]);\n\n return (\n <Slot {...context.getReferenceProps(props)} ref={mergedRef}>\n {children}\n </Slot>\n );\n });\n Trigger.displayName = `${name}Trigger`;\n return Trigger;\n}\n"],"names":["React","useMergeRefs","jsx","Slot"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAKO,SAAS,qBAAqB,CAAC,IAAI,EAAE,kBAAkB,EAAE;AAChE,EAAE,MAAM,OAAO,GAAGA,gBAAK,CAAC,UAAU,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,GAAG,KAAK;AACpE,IAAI,MAAM,OAAO,GAAG,kBAAkB,EAAE;AACxC,IAAI,MAAM,SAAS,GAAGC,kBAAY,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC;AACpE,IAAI,uBAAuBC,cAAG,CAACC,UAAI,EAAE,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AACvG,EAAE,CAAC,CAAC;AACJ,EAAE,OAAO,CAAC,WAAW,GAAG,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC;AACxC,EAAE,OAAO,OAAO;AAChB;;"}
1
+ {"version":3,"file":"DropdownTrigger.js","sources":["../../../../src/utils/useDropdown/DropdownTrigger.tsx"],"sourcesContent":["import * as React from 'react';\nimport { Slot } from '../Slot';\nimport { useMergeRefs } from '../useMergeRefs';\nimport type { useDropdown } from './index';\n\nexport interface DropdownTriggerProps extends React.HTMLAttributes<HTMLElement> {\n /** The element that opens the dropdown, such as a Button. It must accept a ref: not a fragment, text or number. */\n children: React.ReactElement;\n}\n\n/**\n * Makes the trigger component of a dropdown (ActionList.Trigger, DropdownCard.Trigger): it gives its child element\n * the dropdown's ref and props, keeping the child's own.\n */\nexport function createDropdownTrigger(name: string, useDropdownContext: () => ReturnType<typeof useDropdown>) {\n const Trigger = React.forwardRef<HTMLElement, DropdownTriggerProps>(({ children, ...props }, ref) => {\n const context = useDropdownContext();\n const mergedRef = useMergeRefs([context.refs.setReference, ref]);\n\n return (\n <Slot {...context.getReferenceProps(props)} ref={mergedRef}>\n {children}\n </Slot>\n );\n });\n Trigger.displayName = `${name}Trigger`;\n return Trigger;\n}\n"],"names":["React","useMergeRefs","jsx","Slot"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAKO,SAAS,qBAAqB,CAAC,IAAI,EAAE,kBAAkB,EAAE;AAChE,EAAE,MAAM,OAAO,GAAGA,gBAAK,CAAC,UAAU,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,GAAG,KAAK;AACpE,IAAI,MAAM,OAAO,GAAG,kBAAkB,EAAE;AACxC,IAAI,MAAM,SAAS,GAAGC,kBAAY,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC;AACpE,IAAI,uBAAuBC,cAAG,CAACC,YAAI,EAAE,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AACvG,EAAE,CAAC,CAAC;AACJ,EAAE,OAAO,CAAC,WAAW,GAAG,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC;AACxC,EAAE,OAAO,OAAO;AAChB;;"}
@@ -0,0 +1,51 @@
1
+ 'use client';
2
+ 'use strict';
3
+
4
+ var React = require('react');
5
+
6
+ function _interopNamespaceDefault(e) {
7
+ var n = Object.create(null);
8
+ if (e) {
9
+ for (var k in e) {
10
+ n[k] = e[k];
11
+ }
12
+ }
13
+ n.default = e;
14
+ return Object.freeze(n);
15
+ }
16
+
17
+ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
18
+
19
+ function useMergeRefs(refs) {
20
+ const cleanup = React__namespace.useRef(void 0);
21
+ return React__namespace.useMemo(
22
+ () => {
23
+ if (refs.every((ref) => ref == null)) return null;
24
+ return (instance) => {
25
+ cleanup.current?.();
26
+ cleanup.current = void 0;
27
+ if (instance == null) return;
28
+ const cleanups = refs.map((ref) => setRef(ref, instance));
29
+ cleanup.current = () => cleanups.forEach((refCleanup) => refCleanup?.());
30
+ };
31
+ },
32
+ // The refs are the dependencies, and each caller passes the same number of them on every render.
33
+ // eslint-disable-next-line react-hooks/exhaustive-deps
34
+ refs
35
+ );
36
+ }
37
+ function setRef(ref, instance) {
38
+ if (ref == null) return void 0;
39
+ if (typeof ref === "function") {
40
+ const refCleanup = ref(instance);
41
+ return typeof refCleanup === "function" ? refCleanup : () => ref(null);
42
+ }
43
+ const objectRef = ref;
44
+ objectRef.current = instance;
45
+ return () => {
46
+ objectRef.current = null;
47
+ };
48
+ }
49
+
50
+ exports.useMergeRefs = useMergeRefs;
51
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../src/utils/useMergeRefs/index.ts"],"sourcesContent":["import * as React from 'react';\n\ntype Cleanup = () => void;\n\n/**\n * One callback ref that sets every ref given, or `null` when none is set: `ref={useMergeRefs([inputRef, ref])}`. It\n * keeps its identity while the refs do. A callback ref that returns a cleanup (React 19) gets it run when the element\n * goes; any other one is called with `null`.\n *\n * Roaster's own, not Floating UI's: Floating UI ships as one file, so importing this hook from it put the whole\n * library in the first load of every app with a Button, beside any component that needs the rest, such as ActionList.\n */\nexport function useMergeRefs<T>(refs: Array<React.Ref<T> | undefined>): React.RefCallback<T> | null {\n const cleanup = React.useRef<Cleanup | undefined>(undefined);\n\n return React.useMemo(\n () => {\n if (refs.every((ref) => ref == null)) return null;\n return (instance: T | null) => {\n cleanup.current?.();\n cleanup.current = undefined;\n if (instance == null) return;\n const cleanups = refs.map((ref) => setRef(ref, instance));\n cleanup.current = () => cleanups.forEach((refCleanup) => refCleanup?.());\n };\n },\n // The refs are the dependencies, and each caller passes the same number of them on every render.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n refs\n );\n}\n\nfunction setRef<T>(ref: React.Ref<T> | undefined, instance: T): Cleanup | undefined {\n if (ref == null) return undefined;\n if (typeof ref === 'function') {\n const refCleanup: unknown = ref(instance);\n return typeof refCleanup === 'function' ? (refCleanup as Cleanup) : () => ref(null);\n }\n const objectRef = ref as React.MutableRefObject<T | null>;\n objectRef.current = instance;\n return () => {\n objectRef.current = null;\n };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AE,CAAC;AACH;;"}
@@ -1,9 +1,10 @@
1
1
  'use client';
2
2
  import { jsx } from 'react/jsx-runtime';
3
- import { useMergeRefs, FloatingFocusManager, FloatingList } from '@floating-ui/react';
3
+ import { FloatingFocusManager, FloatingList } from '@floating-ui/react';
4
4
  import * as React from 'react';
5
5
  import { flushSync } from 'react-dom';
6
6
  import { useActionListContext } from '../ActionList.context.js';
7
+ import { useMergeRefs } from '../../../utils/useMergeRefs/index.js';
7
8
  import { useMediaQuery, PHONE_QUERY } from '../../../utils/useMediaQuery/index.js';
8
9
  import { classNames } from '../../../utils/classNames/index.js';
9
10
 
@@ -1 +1 @@
1
- {"version":3,"file":"ActionListDropdown.js","sources":["../../../../../src/components/ActionList/components/ActionListDropdown.tsx"],"sourcesContent":["import { FloatingFocusManager, FloatingList, useMergeRefs } from '@floating-ui/react';\nimport * as React from 'react';\nimport { flushSync } from 'react-dom';\nimport { PHONE_QUERY, classNames, useMediaQuery } from '@/utils';\nimport { useActionListContext } from '../ActionList.context';\n\n/** Every native `<div>` prop (`aria-label`, `className`, `style`...) is accepted and forwarded to the menu. */\nexport interface ActionListDropdownProps extends React.ComponentPropsWithoutRef<'div'> {\n /**\n * On a phone (480px wide at most), the menu rises from the window's bottom as a sheet, its full width, over the\n * dimmed page; on a wider screen it opens under its trigger as usual. Guidance: keep a menu beside its trigger; a\n * sheet suits a long one, such as a list of filters with a search.\n * @defaultValue false\n */\n sheet?: boolean;\n}\n\n/** The menu: its groups, dividers and items. Rendered while the action list is open. */\nexport const ActionListDropdown = React.forwardRef<HTMLDivElement, ActionListDropdownProps>(\n ({ className, style, children, sheet = false, ...props }, propRef) => {\n const { context: floatingContext, ...context } = useActionListContext();\n const ref = useMergeRefs([context.refs.setFloating, propRef]);\n // A sheet on a phone is placed by the CSS, at the window's bottom, not beside its trigger.\n const asSheet = useMediaQuery(PHONE_QUERY) && sheet;\n // Closing gives the focus back to the trigger, except when tabbing away: then it moves on from the trigger.\n const [returnFocus, setReturnFocus] = React.useState(true);\n React.useEffect(() => {\n if (context.open) setReturnFocus(true);\n }, [context.open]);\n if (!context.open) return null;\n\n return (\n // The list navigation moves the focus to the first item.\n <FloatingFocusManager context={floatingContext} modal={false} initialFocus={-1} returnFocus={returnFocus}>\n <div\n ref={ref}\n {...context.getFloatingProps({\n ...props,\n onKeyDown(event: React.KeyboardEvent<HTMLDivElement>) {\n props.onKeyDown?.(event);\n // Tabbing away closes the menu, and Tab moves on from the trigger, as if the menu weren't there.\n if (event.key === 'Tab') {\n flushSync(() => setReturnFocus(false));\n (context.refs.domReference.current as HTMLElement | null)?.focus();\n context.setOpen(false);\n }\n },\n })}\n // After the spread, so a caller's className and style add to these instead of replacing them.\n className={classNames(\n 'roaster-action-list',\n 'roaster-action-list--floating',\n sheet && 'roaster-action-list--sheet',\n className\n )}\n style={asSheet ? style : { ...context.floatingStyles, ...style }}\n >\n <FloatingList elementsRef={context.elementsRef} labelsRef={context.labelsRef}>\n {children}\n </FloatingList>\n </div>\n </FloatingFocusManager>\n );\n }\n);\n\nActionListDropdown.displayName = 'ActionListDropdown';\n"],"names":[],"mappings":";;;;;;;;;AAOY,MAAC,kBAAkB,GAAG,KAAK,CAAC,UAAU;AAClD,EAAE,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,GAAG,KAAK,EAAE,GAAG,KAAK,EAAE,EAAE,OAAO,KAAK;AACxE,IAAI,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,OAAO,EAAE,GAAG,oBAAoB,EAAE;AAC3E,IAAI,MAAM,GAAG,GAAG,YAAY,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AACjE,IAAI,MAAM,OAAO,GAAG,aAAa,CAAC,WAAW,CAAC,IAAI,KAAK;AACvD,IAAI,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;AAC9D,IAAI,KAAK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QAAQ,EAAE;AAClI;AACA,OAAO,EAAE;AACT;AACA,EAAE;AACF;AACA,kBAAkB,CAAC,WAAW,GAAG,oBAAoB;;"}
1
+ {"version":3,"file":"ActionListDropdown.js","sources":["../../../../../src/components/ActionList/components/ActionListDropdown.tsx"],"sourcesContent":["import { FloatingFocusManager, FloatingList } from '@floating-ui/react';\nimport * as React from 'react';\nimport { flushSync } from 'react-dom';\nimport { PHONE_QUERY, classNames, useMediaQuery, useMergeRefs } from '@/utils';\nimport { useActionListContext } from '../ActionList.context';\n\n/** Every native `<div>` prop (`aria-label`, `className`, `style`...) is accepted and forwarded to the menu. */\nexport interface ActionListDropdownProps extends React.ComponentPropsWithoutRef<'div'> {\n /**\n * On a phone (480px wide at most), the menu rises from the window's bottom as a sheet, its full width, over the\n * dimmed page; on a wider screen it opens under its trigger as usual. Guidance: keep a menu beside its trigger; a\n * sheet suits a long one, such as a list of filters with a search.\n * @defaultValue false\n */\n sheet?: boolean;\n}\n\n/** The menu: its groups, dividers and items. Rendered while the action list is open. */\nexport const ActionListDropdown = React.forwardRef<HTMLDivElement, ActionListDropdownProps>(\n ({ className, style, children, sheet = false, ...props }, propRef) => {\n const { context: floatingContext, ...context } = useActionListContext();\n const ref = useMergeRefs([context.refs.setFloating, propRef]);\n // A sheet on a phone is placed by the CSS, at the window's bottom, not beside its trigger.\n const asSheet = useMediaQuery(PHONE_QUERY) && sheet;\n // Closing gives the focus back to the trigger, except when tabbing away: then it moves on from the trigger.\n const [returnFocus, setReturnFocus] = React.useState(true);\n React.useEffect(() => {\n if (context.open) setReturnFocus(true);\n }, [context.open]);\n if (!context.open) return null;\n\n return (\n // The list navigation moves the focus to the first item.\n <FloatingFocusManager context={floatingContext} modal={false} initialFocus={-1} returnFocus={returnFocus}>\n <div\n ref={ref}\n {...context.getFloatingProps({\n ...props,\n onKeyDown(event: React.KeyboardEvent<HTMLDivElement>) {\n props.onKeyDown?.(event);\n // Tabbing away closes the menu, and Tab moves on from the trigger, as if the menu weren't there.\n if (event.key === 'Tab') {\n flushSync(() => setReturnFocus(false));\n (context.refs.domReference.current as HTMLElement | null)?.focus();\n context.setOpen(false);\n }\n },\n })}\n // After the spread, so a caller's className and style add to these instead of replacing them.\n className={classNames(\n 'roaster-action-list',\n 'roaster-action-list--floating',\n sheet && 'roaster-action-list--sheet',\n className\n )}\n style={asSheet ? style : { ...context.floatingStyles, ...style }}\n >\n <FloatingList elementsRef={context.elementsRef} labelsRef={context.labelsRef}>\n {children}\n </FloatingList>\n </div>\n </FloatingFocusManager>\n );\n }\n);\n\nActionListDropdown.displayName = 'ActionListDropdown';\n"],"names":[],"mappings":";;;;;;;;;;AAOY,MAAC,kBAAkB,GAAG,KAAK,CAAC,UAAU;AAClD,EAAE,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,GAAG,KAAK,EAAE,GAAG,KAAK,EAAE,EAAE,OAAO,KAAK;AACxE,IAAI,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,OAAO,EAAE,GAAG,oBAAoB,EAAE;AAC3E,IAAI,MAAM,GAAG,GAAG,YAAY,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AACjE,IAAI,MAAM,OAAO,GAAG,aAAa,CAAC,WAAW,CAAC,IAAI,KAAK;AACvD,IAAI,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;AAC9D,IAAI,KAAK,CAAC,SAAS,CAAC,MAAM;AAC1B,MAAM,IAAI,OAAO,CAAC,IAAI,EAAE,cAAc,CAAC,IAAI,CAAC;AAC5C,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AACtB,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,IAAI;AAClC,IAAI;AACJ;AACA,sBAAsB,GAAG,CAAC,oBAAoB,EAAE,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE,EAAE,WAAW,EAAE,QAAQ,kBAAkB,GAAG;AACtJ,QAAQ,KAAK;AACb,QAAQ;AACR,UAAU,GAAG;AACb,UAAU,GAAG,OAAO,CAAC,gBAAgB,CAAC;AACtC,YAAY,GAAG,KAAK;AACpB,YAAY,SAAS,CAAC,KAAK,EAAE;AAC7B,cAAc,KAAK,CAAC,SAAS,GAAG,KAAK,CAAC;AACtC,cAAc,IAAI,KAAK,CAAC,GAAG,KAAK,KAAK,EAAE;AACvC,gBAAgB,SAAS,CAAC,MAAM,cAAc,CAAC,KAAK,CAAC,CAAC;AACtD,gBAAgB,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,KAAK,EAAE;AAC1D,gBAAgB,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;AACtC,cAAc;AACd,YAAY;AACZ,WAAW,CAAC;AACZ,UAAU,SAAS,EAAE,UAAU;AAC/B,YAAY,qBAAqB;AACjC,YAAY,+BAA+B;AAC3C,YAAY,KAAK,IAAI,4BAA4B;AACjD,YAAY;AACZ,WAAW;AACX,UAAU,KAAK,EAAE,OAAO,GAAG,KAAK,GAAG,EAAE,GAAG,OAAO,CAAC,cAAc,EAAE,GAAG,KAAK,EAAE;AAC1E,UAAU,QAAQ,kBAAkB,GAAG,CAAC,YAAY,EAAE,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,QAAQ,EAAE;AAClI;AACA,OAAO,EAAE;AACT;AACA,EAAE;AACF;AACA,kBAAkB,CAAC,WAAW,GAAG,oBAAoB;;"}
@@ -1,9 +1,10 @@
1
1
  'use client';
2
2
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
- import { useListItem, useMergeRefs } from '@floating-ui/react';
3
+ import { useListItem } from '@floating-ui/react';
4
4
  import * as React from 'react';
5
5
  import { Icon } from '../../Icon/Icon.js';
6
6
  import { useActionListContext } from '../ActionList.context.js';
7
+ import { useMergeRefs } from '../../../utils/useMergeRefs/index.js';
7
8
  import { Slot } from '../../../utils/Slot/index.js';
8
9
  import { classNames } from '../../../utils/classNames/index.js';
9
10
 
@@ -47,7 +48,7 @@ const ActionListItem = React.forwardRef(
47
48
  ),
48
49
  children: asChild ? children : /* @__PURE__ */ jsxs(Fragment, { children: [
49
50
  children,
50
- checkMark && /* @__PURE__ */ jsx(Icon, { name: "check", className: "roaster-action-list__check" }),
51
+ checkMark && /* @__PURE__ */ jsx(Icon, { name: "check", className: "roaster-action-list__check roaster-action-list__check--end" }),
51
52
  detail != null && detail !== false && /* @__PURE__ */ jsx("span", { className: "roaster-action-list__detail", children: detail })
52
53
  ] })
53
54
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ActionListItem.js","sources":["../../../../../src/components/ActionList/components/ActionListItem.tsx"],"sourcesContent":["import { useListItem, useMergeRefs } from '@floating-ui/react';\nimport * as React from 'react';\nimport { classNames, Slot } from '@/utils';\nimport { Icon } from '../../Icon';\nimport { useActionListContext } from '../ActionList.context';\n\n/** Every native `<button>` prop (`onClick`, `disabled`, ...) is accepted and forwarded to the item. */\nexport interface ActionListItemProps extends React.ComponentPropsWithoutRef<'button'> {\n /** The text of the item, with an optional icon. */\n children: React.ReactNode;\n /** `danger` for a destructive action, such as deleting or logging out. */\n tone?: 'danger';\n /** A short text at the item's end, such as the current choice of a setting. With `asChild`, write it in the child. */\n detail?: React.ReactNode;\n /**\n * Makes the item one of a set of choices (`role=\"menuitemradio\"`), chosen when `true`, such as a sort order. Its\n * icon takes the primary color while it is chosen.\n */\n checked?: boolean;\n /**\n * One of several choices that can be chosen together (`role=\"menuitemcheckbox\"`), such as labels, instead of one of a\n * set. With `checked`.\n */\n multiple?: boolean;\n /**\n * Shows a check at the item's end while it is chosen, such as in a picker whose items carry icons of their own (a\n * status, an avatar). With `checked`.\n */\n checkMark?: boolean;\n /**\n * Renders the child element (such as a link, or a router's Link) as the item, instead of a `<button>`.\n * @defaultValue false\n */\n asChild?: boolean;\n}\n\n/**\n * An item of the menu (`role=\"menuitem\"`, or `menuitemradio` with `checked`): a button, or with `asChild` its child,\n * such as a link. Choosing it closes the menu, after its own `onClick`, unless that calls `event.preventDefault()`.\n */\nexport const ActionListItem = React.forwardRef<HTMLButtonElement, ActionListItemProps>(\n (\n {\n className,\n children,\n tone,\n detail,\n checked,\n multiple,\n checkMark,\n asChild = false,\n onClick,\n type = 'button',\n ...rest\n },\n propRef\n ) => {\n const context = useActionListContext();\n const item = useListItem();\n const ref = useMergeRefs([item.ref, propRef]);\n const Component = asChild ? Slot : 'button';\n\n return (\n <Component\n {...(asChild ? {} : { type })}\n role={checked === undefined ? 'menuitem' : multiple ? 'menuitemcheckbox' : 'menuitemradio'}\n aria-checked={checked}\n {...context.getItemProps({\n ...rest,\n onClick(event: React.MouseEvent<HTMLButtonElement>) {\n onClick?.(event);\n if (!event.defaultPrevented) context.setOpen(false);\n },\n })}\n ref={ref}\n tabIndex={context.activeIndex === item.index ? 0 : -1}\n className={classNames(\n 'roaster-action-list__item',\n { 'roaster-action-list__item--danger': tone === 'danger' },\n className\n )}\n >\n {asChild ? (\n children\n ) : (\n <>\n {children}\n {checkMark && <Icon name=\"check\" className=\"roaster-action-list__check\" />}\n {detail != null && detail !== false && <span className=\"roaster-action-list__detail\">{detail}</span>}\n </>\n )}\n </Component>\n );\n }\n);\nActionListItem.displayName = 'ActionListItem';\n"],"names":[],"mappings":";;;;;;;;;AAOY,MAAC,cAAc,GAAG,KAAK,CAAC,UAAU;AAC9C,EAAE,CAAC;AACH,IAAI,SAAS;AACb,IAAI,QAAQ;AACZ,IAAI,IAAI;AACR,IAAI,MAAM;AACV,IAAI,OAAO;AACX,IAAI,QAAQ;AACZ,IAAI,SAAS;AACb,IAAI,OAAO,GAAG,KAAK;AACnB,IAAI,OAAO;AACX,IAAI,IAAI,GAAG,QAAQ;AACnB,IAAI,GAAG;AACP,GAAG,EAAE,OAAO,KAAK;A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AAM,IAAI,IAAI,IAAI,MAAM,KAAK,KAAK,oBAAoB,GAAG,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,6BAA6B,EAAE,QAAQ,EAAE,MAAM,EAAE;AAC1I,SAAS,EAAE;AACX;AACA,KAAK;AACL,EAAE;AACF;AACA,cAAc,CAAC,WAAW,GAAG,gBAAgB;;"}
1
+ {"version":3,"file":"ActionListItem.js","sources":["../../../../../src/components/ActionList/components/ActionListItem.tsx"],"sourcesContent":["import { useListItem } from '@floating-ui/react';\nimport * as React from 'react';\nimport { classNames, Slot, useMergeRefs } from '@/utils';\nimport { Icon } from '../../Icon';\nimport { useActionListContext } from '../ActionList.context';\n\n/** Every native `<button>` prop (`onClick`, `disabled`, ...) is accepted and forwarded to the item. */\nexport interface ActionListItemProps extends React.ComponentPropsWithoutRef<'button'> {\n /**\n * The text of the item, with an optional icon. An icon after the text goes to the item's end, with the text in a\n * `<span>`: `<span>Privacy</span><Icon name=\"arrow-up-right-from-square\" />`.\n */\n children: React.ReactNode;\n /** `danger` for a destructive action, such as deleting or logging out. */\n tone?: 'danger';\n /** A short text at the item's end, such as the current choice of a setting. With `asChild`, write it in the child. */\n detail?: React.ReactNode;\n /**\n * Makes the item one of a set of choices (`role=\"menuitemradio\"`), chosen when `true`, such as a sort order. Its\n * icon takes the primary color while it is chosen.\n */\n checked?: boolean;\n /**\n * One of several choices that can be chosen together (`role=\"menuitemcheckbox\"`), such as labels, instead of one of a\n * set. With `checked`.\n */\n multiple?: boolean;\n /**\n * Shows a check at the item's end while it is chosen, such as in a picker whose items carry icons of their own (a\n * status, an avatar). With `checked`.\n */\n checkMark?: boolean;\n /**\n * Renders the child element (such as a link, or a router's Link) as the item, instead of a `<button>`.\n * @defaultValue false\n */\n asChild?: boolean;\n}\n\n/**\n * An item of the menu (`role=\"menuitem\"`, or `menuitemradio` with `checked`): a button, or with `asChild` its child,\n * such as a link. Choosing it closes the menu, after its own `onClick`, unless that calls `event.preventDefault()`.\n */\nexport const ActionListItem = React.forwardRef<HTMLButtonElement, ActionListItemProps>(\n (\n {\n className,\n children,\n tone,\n detail,\n checked,\n multiple,\n checkMark,\n asChild = false,\n onClick,\n type = 'button',\n ...rest\n },\n propRef\n ) => {\n const context = useActionListContext();\n const item = useListItem();\n const ref = useMergeRefs([item.ref, propRef]);\n const Component = asChild ? Slot : 'button';\n\n return (\n <Component\n {...(asChild ? {} : { type })}\n role={checked === undefined ? 'menuitem' : multiple ? 'menuitemcheckbox' : 'menuitemradio'}\n aria-checked={checked}\n {...context.getItemProps({\n ...rest,\n onClick(event: React.MouseEvent<HTMLButtonElement>) {\n onClick?.(event);\n if (!event.defaultPrevented) context.setOpen(false);\n },\n })}\n ref={ref}\n tabIndex={context.activeIndex === item.index ? 0 : -1}\n className={classNames(\n 'roaster-action-list__item',\n { 'roaster-action-list__item--danger': tone === 'danger' },\n className\n )}\n >\n {asChild ? (\n children\n ) : (\n <>\n {children}\n {checkMark && <Icon name=\"check\" className=\"roaster-action-list__check roaster-action-list__check--end\" />}\n {detail != null && detail !== false && <span className=\"roaster-action-list__detail\">{detail}</span>}\n </>\n )}\n </Component>\n );\n }\n);\nActionListItem.displayName = 'ActionListItem';\n"],"names":[],"mappings":";;;;;;;;;;AAOY,MAAC,cAAc,GAAG,KAAK,CAAC,UAAU;AAC9C,EAAE,CAAC;AACH,IAAI,SAAS;AACb,IAAI,QAAQ;AACZ,IAAI,IAAI;AACR,IAAI,MAAM;AACV,IAAI,OAAO;AACX,IAAI,QAAQ;AACZ,IAAI,SAAS;AACb,IAAI,OAAO,GAAG,KAAK;AACnB,IAAI,OAAO;AACX,IAAI,IAAI,GAAG,QAAQ;AACnB,IAAI,GAAG;AACP,GAAG,EAAE,OAAO,KAAK;AACjB,IAAI,MAAM,OAAO,GAAG,oBAAoB,EAAE;AAC1C,IAAI,MAAM,IAAI,GAAG,WAAW,EAAE;AAC9B,IAAI,MAAM,GAAG,GAAG,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE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,KAAK;AACL,EAAE;AACF;AACA,cAAc,CAAC,WAAW,GAAG,gBAAgB;;"}
@@ -1,8 +1,8 @@
1
1
  'use client';
2
2
  import { jsxs, jsx } from 'react/jsx-runtime';
3
3
  import * as React from 'react';
4
- import { useMergeRefs } from '@floating-ui/react';
5
4
  import { useActionListContext } from '../ActionList.context.js';
5
+ import { useMergeRefs } from '../../../utils/useMergeRefs/index.js';
6
6
  import { classNames } from '../../../utils/classNames/index.js';
7
7
 
8
8
  const ActionListSearch = React.forwardRef(
@@ -11,14 +11,32 @@ const ActionListSearch = React.forwardRef(
11
11
  const inputRef = React.useRef(null);
12
12
  const ref = useMergeRefs([inputRef, propRef]);
13
13
  React.useEffect(() => {
14
- if (!autoFocus) return void 0;
14
+ const input = inputRef.current;
15
+ const menu = input?.closest(".roaster-action-list");
16
+ if (!autoFocus || !input || !menu) return void 0;
17
+ const armed = new AbortController();
15
18
  let inner = 0;
16
19
  const outer = requestAnimationFrame(() => {
17
- inner = requestAnimationFrame(() => inputRef.current?.focus());
20
+ inner = requestAnimationFrame(() => {
21
+ input.focus();
22
+ const disarm = () => armed.abort();
23
+ menu.addEventListener("keydown", disarm, { capture: true, signal: armed.signal });
24
+ menu.addEventListener("pointerdown", disarm, { capture: true, signal: armed.signal });
25
+ menu.addEventListener(
26
+ "focusin",
27
+ (event) => {
28
+ if (event.target === input) return;
29
+ disarm();
30
+ input.focus();
31
+ },
32
+ { signal: armed.signal }
33
+ );
34
+ });
18
35
  });
19
36
  return () => {
20
37
  cancelAnimationFrame(outer);
21
38
  cancelAnimationFrame(inner);
39
+ armed.abort();
22
40
  };
23
41
  }, [autoFocus]);
24
42
  return /* @__PURE__ */ jsxs("div", { className: classNames("roaster-action-list__search", className), style, children: [