@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":"ActionListSearch.js","sources":["../../../../../src/components/ActionList/components/ActionListSearch.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useMergeRefs } from '@floating-ui/react';\nimport { classNames } from '@/utils';\nimport { useActionListContext } from '../ActionList.context';\n\n/**\n * Every native `<input>` prop (`value`, `onChange`, `placeholder`, ...) is accepted and forwarded to the search field,\n * with the ref. `className` and `style` go to its row.\n */\nexport interface ActionListSearchProps extends Omit<React.ComponentPropsWithoutRef<'input'>, 'type' | 'style'> {\n /** The search field's name, read by screen readers, such as \"Find a filter\". */\n 'aria-label': string;\n /** Called with the text as the user types: hide the items that don't match it. */\n onValueChange?(value: string): void;\n /** A key hint at the row's end, such as the shortcut that opens the menu. */\n shortcut?: React.ReactNode;\n /** Styles added to the row. */\n style?: React.CSSProperties;\n}\n\n/**\n * A search row at the top of a long menu, such as a list of filters: it takes the focus when the menu opens, and the\n * down arrow goes on to the items. Filter the items from its value.\n */\nexport const ActionListSearch = React.forwardRef<HTMLInputElement, ActionListSearchProps>(\n ({ onValueChange, onChange, onKeyDown, shortcut, className, style, autoFocus = true, ...rest }, propRef) => {\n const context = useActionListContext();\n const inputRef = React.useRef<HTMLInputElement>(null);\n const ref = useMergeRefs([inputRef, propRef]);\n // The menu gives the focus to its first item a frame after it opens; the search takes it back after that.\n React.useEffect(() => {\n if (!autoFocus) return undefined;\n let inner = 0;\n const outer = requestAnimationFrame(() => {\n inner = requestAnimationFrame(() => inputRef.current?.focus());\n });\n return () => {\n cancelAnimationFrame(outer);\n cancelAnimationFrame(inner);\n };\n }, [autoFocus]);\n return (\n <div className={classNames('roaster-action-list__search', className)} style={style}>\n <input\n {...rest}\n ref={ref}\n type=\"search\"\n onChange={(event) => {\n onChange?.(event);\n onValueChange?.(event.currentTarget.value);\n }}\n onKeyDown={(event) => {\n onKeyDown?.(event);\n // The menu's own keys move between its items; from the search field, the down arrow goes to the first.\n if (event.key === 'ArrowDown' && !event.defaultPrevented) {\n event.preventDefault();\n context.elementsRef.current.find((element) => element && !element.hidden)?.focus();\n }\n // Typing a letter moves between items elsewhere in the menu; here it is the search.\n event.stopPropagation();\n }}\n />\n {shortcut != null && shortcut !== false && <kbd>{shortcut}</kbd>}\n </div>\n );\n }\n);\nActionListSearch.displayName = 'ActionListSearch';\n"],"names":[],"mappings":";;;;;;;AAMY,MAAC,gBAAgB,GAAG,KAAK,CAAC,UAAU;AAChD,EAAE,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,EAAE,GAAG,IAAI,EAAE,EAAE,OAAO,KAAK;AAC9G,IAAI,MAAM,OAAO,GAAG,oBAAoB,EAAE;AAC1C,IAAI,MAAM,QAAQ,GAAG,KAAK,CAAC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AI,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE;AAChG,YAAY;AACZ,YAAY,KAAK,CAAC,eAAe,EAAE;AACnC,UAAU;AACV;AACA,OAAO;AACP,MAAM,QAAQ,IAAI,IAAI,IAAI,QAAQ,KAAK,KAAK,oBAAoB,GAAG,CAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE;AACjG,KAAK,EAAE,CAAC;AACR,EAAE;AACF;AACA,gBAAgB,CAAC,WAAW,GAAG,kBAAkB;;"}
1
+ {"version":3,"file":"ActionListSearch.js","sources":["../../../../../src/components/ActionList/components/ActionListSearch.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames, useMergeRefs } from '@/utils';\nimport { useActionListContext } from '../ActionList.context';\n\n/**\n * Every native `<input>` prop (`value`, `onChange`, `placeholder`, ...) is accepted and forwarded to the search field,\n * with the ref. `className` and `style` go to its row.\n */\nexport interface ActionListSearchProps extends Omit<React.ComponentPropsWithoutRef<'input'>, 'type' | 'style'> {\n /** The search field's name, read by screen readers, such as \"Find a filter\". */\n 'aria-label': string;\n /** Called with the text as the user types: hide the items that don't match it. */\n onValueChange?(value: string): void;\n /** A key hint at the row's end, such as the shortcut that opens the menu. */\n shortcut?: React.ReactNode;\n /** Styles added to the row. */\n style?: React.CSSProperties;\n}\n\n/**\n * A search row at the top of a long menu, such as a list of filters: it takes the focus when the menu opens, and the\n * down arrow goes on to the items. Filter the items from its value.\n */\nexport const ActionListSearch = React.forwardRef<HTMLInputElement, ActionListSearchProps>(\n ({ onValueChange, onChange, onKeyDown, shortcut, className, style, autoFocus = true, ...rest }, propRef) => {\n const context = useActionListContext();\n const inputRef = React.useRef<HTMLInputElement>(null);\n const ref = useMergeRefs([inputRef, propRef]);\n // The menu gives the focus to its first item a frame after it opens; the search takes it back after that. On a slow\n // device the menu's can come later still: until a key or a click in the menu, the search takes the focus back from\n // an item, once.\n React.useEffect(() => {\n const input = inputRef.current;\n const menu = input?.closest<HTMLElement>('.roaster-action-list');\n if (!autoFocus || !input || !menu) return undefined;\n const armed = new AbortController();\n let inner = 0;\n const outer = requestAnimationFrame(() => {\n inner = requestAnimationFrame(() => {\n input.focus();\n const disarm = () => armed.abort();\n menu.addEventListener('keydown', disarm, { capture: true, signal: armed.signal });\n menu.addEventListener('pointerdown', disarm, { capture: true, signal: armed.signal });\n menu.addEventListener(\n 'focusin',\n (event) => {\n if (event.target === input) return;\n disarm();\n input.focus();\n },\n { signal: armed.signal }\n );\n });\n });\n return () => {\n cancelAnimationFrame(outer);\n cancelAnimationFrame(inner);\n armed.abort();\n };\n }, [autoFocus]);\n return (\n <div className={classNames('roaster-action-list__search', className)} style={style}>\n <input\n {...rest}\n ref={ref}\n type=\"search\"\n onChange={(event) => {\n onChange?.(event);\n onValueChange?.(event.currentTarget.value);\n }}\n onKeyDown={(event) => {\n onKeyDown?.(event);\n // The menu's own keys move between its items; from the search field, the down arrow goes to the first.\n if (event.key === 'ArrowDown' && !event.defaultPrevented) {\n event.preventDefault();\n context.elementsRef.current.find((element) => element && !element.hidden)?.focus();\n }\n // Typing a letter moves between items elsewhere in the menu; here it is the search.\n event.stopPropagation();\n }}\n />\n {shortcut != null && shortcut !== false && <kbd>{shortcut}</kbd>}\n </div>\n );\n }\n);\nActionListSearch.displayName = 'ActionListSearch';\n"],"names":[],"mappings":";;;;;;;AAKY,MAAC,gBAAgB,GAAG,KAAK,CAAC,UAAU;AAChD,EAAE,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,EAAE,GAAG,IAAI,EAAE,EAAE,OAAO,KAAK;AAC9G,IAAI,MAAM,OAAO,GAAG,oBAAoB,EAAE;AAC1C,IAAI,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC;AACvC,IAAI,MAAM,GAAG,GAAG,YAAY,CA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jsx-runtime';
3
- import { useListItem, useFloating, autoUpdate, offset, flip, shift, useInteractions, useClick, useRole, useDismiss, useListNavigation, useTypeahead, useMergeRefs, FloatingFocusManager, FloatingList } from '@floating-ui/react';
3
+ import { useListItem, useFloating, autoUpdate, offset, flip, shift, useInteractions, useClick, useRole, useDismiss, useListNavigation, useTypeahead, FloatingFocusManager, FloatingList } from '@floating-ui/react';
4
4
  import * as React from 'react';
5
5
  import { Icon } from '../../Icon/Icon.js';
6
6
  import { useActionListContext, ActionListProvider } from '../ActionList.context.js';
7
7
  import { readLengthToken } from '../../../utils/useDropdown/index.js';
8
+ import { useMergeRefs } from '../../../utils/useMergeRefs/index.js';
8
9
  import { classNames } from '../../../utils/classNames/index.js';
9
10
 
10
11
  const ActionListSubmenu = React.forwardRef(
@@ -1 +1 @@
1
- {"version":3,"file":"ActionListSubmenu.js","sources":["../../../../../src/components/ActionList/components/ActionListSubmenu.tsx"],"sourcesContent":["import {\n autoUpdate,\n flip,\n FloatingFocusManager,\n FloatingList,\n offset,\n type Placement,\n shift,\n useClick,\n useDismiss,\n useFloating,\n useInteractions,\n useListItem,\n useListNavigation,\n useMergeRefs,\n useRole,\n useTypeahead,\n} from '@floating-ui/react';\nimport * as React from 'react';\nimport { classNames, readLengthToken } from '@/utils';\nimport { Icon } from '../../Icon';\nimport { ActionListProvider, useActionListContext } from '../ActionList.context';\n\n/** Every native `<button>` prop is accepted and forwarded to the item that opens the submenu. */\nexport interface ActionListSubmenuProps extends Omit<React.ComponentPropsWithoutRef<'button'>, 'children'> {\n /** The item that opens the submenu: its text, with an optional icon. */\n label: React.ReactNode;\n /** A short text before the item's chevron, such as the current choice. */\n detail?: React.ReactNode;\n /** The submenu's groups, dividers and items, as in ActionList.Dropdown. */\n children: React.ReactNode;\n /**\n * Where the submenu opens. It moves to the other side when there is no room.\n * @defaultValue 'right-start'\n */\n placement?: Placement;\n}\n\n/**\n * An item that opens a submenu beside it, such as a setting's choices: on click, Enter, or the right arrow (the left\n * arrow and Escape close it). The item names the submenu. Choosing an item of the submenu closes it and its menu.\n */\nexport const ActionListSubmenu = React.forwardRef<HTMLButtonElement, ActionListSubmenuProps>(\n ({ label, detail, children, placement = 'right-start', className, type = 'button', ...rest }, propRef) => {\n const parent = useActionListContext();\n const item = useListItem();\n const [open, setOpen] = React.useState(false);\n const elementsRef = React.useRef<Array<HTMLElement | null>>([]);\n const labelsRef = React.useRef<Array<string | null>>([]);\n const [activeIndex, setActiveIndex] = React.useState<number | null>(null);\n\n const data = useFloating({\n placement,\n strategy: 'fixed',\n transform: false,\n open,\n onOpenChange: setOpen,\n whileElementsMounted: autoUpdate,\n middleware: [\n // As far from its item as the menu is from its button, past the menu's padding.\n offset(\n ({ elements }) =>\n readLengthToken(elements.floating, '--roaster-action-list-offset', 8) +\n readLengthToken(elements.floating, '--roaster-action-list-padding', 0)\n ),\n flip(),\n shift({ padding: 8 }),\n ],\n });\n const { context } = data;\n const interactions = useInteractions([\n useClick(context),\n useRole(context, { role: 'menu' }),\n useDismiss(context),\n useListNavigation(context, {\n listRef: elementsRef,\n activeIndex,\n onNavigate: setActiveIndex,\n loop: true,\n nested: true,\n focusItemOnOpen: true,\n }),\n useTypeahead(context, { listRef: labelsRef, activeIndex, onMatch: open ? setActiveIndex : undefined }),\n ]);\n\n // The submenu's items close it and the menu it came from.\n const parentSetOpen = parent.setOpen;\n const submenu = React.useMemo(\n () => ({\n ...data,\n ...interactions,\n open,\n activeIndex,\n elementsRef,\n labelsRef,\n setOpen: (next: boolean | ((previous: boolean) => boolean)) => {\n const value = typeof next === 'function' ? next(open) : next;\n setOpen(value);\n if (!value) parentSetOpen(false);\n },\n }),\n [data, interactions, open, activeIndex, parentSetOpen]\n );\n\n const triggerRef = useMergeRefs([item.ref, data.refs.setReference, propRef]);\n\n return (\n <>\n <button\n {...parent.getItemProps(interactions.getReferenceProps(rest))}\n ref={triggerRef}\n type={type}\n role=\"menuitem\"\n aria-haspopup=\"menu\"\n tabIndex={parent.activeIndex === item.index ? 0 : -1}\n className={classNames('roaster-action-list__item', className)}\n >\n {label}\n {detail != null && detail !== false && <span className=\"roaster-action-list__detail\">{detail}</span>}\n <Icon name=\"chevron-right\" />\n </button>\n {open && (\n <FloatingFocusManager context={context} modal={false} initialFocus={-1}>\n <div\n ref={data.refs.setFloating}\n {...interactions.getFloatingProps({\n onKeyDown(event: React.KeyboardEvent<HTMLDivElement>) {\n // Its keys are its own: the menu around it doesn't move, nor close on Escape, which closes only\n // the submenu. Tab goes on to close both.\n if (event.key === 'Tab') return;\n event.stopPropagation();\n if (event.key === 'Escape') {\n setOpen(false);\n (data.refs.domReference.current as HTMLElement | null)?.focus();\n }\n },\n })}\n className=\"roaster-action-list roaster-action-list--submenu roaster-action-list--floating\"\n style={data.floatingStyles}\n >\n <ActionListProvider value={submenu}>\n <FloatingList elementsRef={elementsRef} labelsRef={labelsRef}>\n {children}\n </FloatingList>\n </ActionListProvider>\n </div>\n </FloatingFocusManager>\n )}\n </>\n );\n }\n);\nActionListSubmenu.displayName = 'ActionListSubmenu';\n"],"names":[],"mappings":";;;;;;;;;AAuBY,MAAC,iBAAiB,GAAG,KAAK,CAAC,UAAU;AACjD,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,GAAG,aAAa,EAAE,SAAS,EAAE,IAAI,GAAG,QAAQ,EAAE,GAAG,IAAI,EAAE,EAAE,OAAO,KAAK;AAC5G,IAAI,MAAM,MAAM,GAAG,oBAAoB,EAAE;AACzC,IAAI,MAAM,IAAI,GAAG,WAAW,EAAE;AAC9B,IAAI,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC;AACjD,IAAI,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;AACxC,IAAI,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;AACtC,IAAI,MAAM,CAAC,WAAW,EAAE,cAAc,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menu.tsx"],"sourcesContent":["import {\n autoUpdate,\n flip,\n FloatingFocusManager,\n FloatingList,\n offset,\n type Placement,\n shift,\n useClick,\n useDismiss,\n useFloating,\n useInteractions,\n useListItem,\n useListNavigation,\n useRole,\n useTypeahead,\n} from '@floating-ui/react';\nimport * as React from 'react';\nimport { classNames, readLengthToken, useMergeRefs } from '@/utils';\nimport { Icon } from '../../Icon';\nimport { ActionListProvider, useActionListContext } from '../ActionList.context';\n\n/** Every native `<button>` prop is accepted and forwarded to the item that opens the submenu. */\nexport interface ActionListSubmenuProps extends Omit<React.ComponentPropsWithoutRef<'button'>, 'children'> {\n /** The item that opens the submenu: its text, with an optional icon. */\n label: React.ReactNode;\n /** A short text before the item's chevron, such as the current choice. */\n detail?: React.ReactNode;\n /** The submenu's groups, dividers and items, as in ActionList.Dropdown. */\n children: React.ReactNode;\n /**\n * Where the submenu opens. It moves to the other side when there is no room.\n * @defaultValue 'right-start'\n */\n placement?: Placement;\n}\n\n/**\n * An item that opens a submenu beside it, such as a setting's choices: on click, Enter, or the right arrow (the left\n * arrow and Escape close it). The item names the submenu. Choosing an item of the submenu closes it and its menu.\n */\nexport const ActionListSubmenu = React.forwardRef<HTMLButtonElement, ActionListSubmenuProps>(\n ({ label, detail, children, placement = 'right-start', className, type = 'button', ...rest }, propRef) => {\n const parent = useActionListContext();\n const item = useListItem();\n const [open, setOpen] = React.useState(false);\n const elementsRef = React.useRef<Array<HTMLElement | null>>([]);\n const labelsRef = React.useRef<Array<string | null>>([]);\n const [activeIndex, setActiveIndex] = React.useState<number | null>(null);\n\n const data = useFloating({\n placement,\n strategy: 'fixed',\n transform: false,\n open,\n onOpenChange: setOpen,\n whileElementsMounted: autoUpdate,\n middleware: [\n // As far from its item as the menu is from its button, past the menu's padding.\n offset(\n ({ elements }) =>\n readLengthToken(elements.floating, '--roaster-action-list-offset', 8) +\n readLengthToken(elements.floating, '--roaster-action-list-padding', 0)\n ),\n flip(),\n shift({ padding: 8 }),\n ],\n });\n const { context } = data;\n const interactions = useInteractions([\n useClick(context),\n useRole(context, { role: 'menu' }),\n useDismiss(context),\n useListNavigation(context, {\n listRef: elementsRef,\n activeIndex,\n onNavigate: setActiveIndex,\n loop: true,\n nested: true,\n focusItemOnOpen: true,\n }),\n useTypeahead(context, { listRef: labelsRef, activeIndex, onMatch: open ? setActiveIndex : undefined }),\n ]);\n\n // The submenu's items close it and the menu it came from.\n const parentSetOpen = parent.setOpen;\n const submenu = React.useMemo(\n () => ({\n ...data,\n ...interactions,\n open,\n activeIndex,\n elementsRef,\n labelsRef,\n setOpen: (next: boolean | ((previous: boolean) => boolean)) => {\n const value = typeof next === 'function' ? next(open) : next;\n setOpen(value);\n if (!value) parentSetOpen(false);\n },\n }),\n [data, interactions, open, activeIndex, parentSetOpen]\n );\n\n const triggerRef = useMergeRefs([item.ref, data.refs.setReference, propRef]);\n\n return (\n <>\n <button\n {...parent.getItemProps(interactions.getReferenceProps(rest))}\n ref={triggerRef}\n type={type}\n role=\"menuitem\"\n aria-haspopup=\"menu\"\n tabIndex={parent.activeIndex === item.index ? 0 : -1}\n className={classNames('roaster-action-list__item', className)}\n >\n {label}\n {detail != null && detail !== false && <span className=\"roaster-action-list__detail\">{detail}</span>}\n <Icon name=\"chevron-right\" />\n </button>\n {open && (\n <FloatingFocusManager context={context} modal={false} initialFocus={-1}>\n <div\n ref={data.refs.setFloating}\n {...interactions.getFloatingProps({\n onKeyDown(event: React.KeyboardEvent<HTMLDivElement>) {\n // Its keys are its own: the menu around it doesn't move, nor close on Escape, which closes only\n // the submenu. Tab goes on to close both.\n if (event.key === 'Tab') return;\n event.stopPropagation();\n if (event.key === 'Escape') {\n setOpen(false);\n (data.refs.domReference.current as HTMLElement | null)?.focus();\n }\n },\n })}\n className=\"roaster-action-list roaster-action-list--submenu roaster-action-list--floating\"\n style={data.floatingStyles}\n >\n <ActionListProvider value={submenu}>\n <FloatingList elementsRef={elementsRef} labelsRef={labelsRef}>\n {children}\n </FloatingList>\n </ActionListProv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,cAAc,KAAK,CAAC,eAAe,EAAE;AACrC,cAAc,IAAI,KAAK,CAAC,GAAG,KAAK,QAAQ,EAAE;AAC1C,gBAAgB,OAAO,CAAC,KAAK,CAAC;AAC9B,gBAAgB,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,KAAK,EAAE;AACvD,cAAc;AACd,YAAY;AACZ,WAAW,CAAC;AACZ,UAAU,SAAS,EAAE,gFAAgF;AACrG,UAAU,KAAK,EAAE,IAAI,CAAC,cAAc;AACpC,UAAU,QAAQ,kBAAkB,GAAG,CAAC,kBAAkB,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,kBAAkB,GAAG,CAAC,YAAY,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,EAAE;AACjK;AACA,OAAO,EAAE;AACT,KAAK,EAAE,CAAC;AACR,EAAE;AACF;AACA,iBAAiB,CAAC,WAAW,GAAG,mBAAmB;;"}
@@ -1,8 +1,9 @@
1
1
  'use client';
2
2
  import { jsxs, jsx } 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 { useActionListContext } from '../ActionList.context.js';
6
+ import { useMergeRefs } from '../../../utils/useMergeRefs/index.js';
6
7
  import { useControllableState } from '../../../utils/useControllableState/index.js';
7
8
  import { classNames } from '../../../utils/classNames/index.js';
8
9
 
@@ -1 +1 @@
1
- {"version":3,"file":"ActionListSwitchItem.js","sources":["../../../../../src/components/ActionList/components/ActionListSwitchItem.tsx"],"sourcesContent":["import { useListItem, useMergeRefs } from '@floating-ui/react';\nimport * as React from 'react';\nimport { classNames, useControllableState } from '@/utils';\nimport { useActionListContext } from '../ActionList.context';\n\n/**\n * Every native `<input>` prop (`name`, `aria-*`, ...) is accepted and forwarded to the switch, with the ref.\n * `className` and `style` go to the item.\n */\nexport interface ActionListSwitchItemProps extends Omit<\n React.ComponentPropsWithoutRef<'input'>,\n 'type' | 'children' | 'role'\n> {\n /** The setting's name, with an optional icon before it. */\n children: React.ReactNode;\n /** Called with the new state when the user turns the setting on or off. */\n onCheckedChange?(checked: boolean): void;\n}\n\n/**\n * An on/off setting in the menu (`role=\"menuitemcheckbox\"`), drawn as a switch at the item's end, such as showing a\n * chart. Turning it on or off leaves the menu open.\n */\nexport const ActionListSwitchItem = React.forwardRef<HTMLInputElement, ActionListSwitchItemProps>(\n ({ children, checked, defaultChecked, onChange, onCheckedChange, className, style, ...rest }, propRef) => {\n const context = useActionListContext();\n const item = useListItem();\n const ref = useMergeRefs([item.ref, propRef]);\n const [on, setOn] = useControllableState({\n value: checked,\n defaultValue: defaultChecked ?? false,\n onChange: onCheckedChange,\n });\n\n return (\n <label className={classNames('roaster-action-list__item', className)} style={style}>\n {children}\n <span className=\"roaster-switch\">\n <input\n {...context.getItemProps({\n ...rest,\n onChange(event: React.ChangeEvent<HTMLInputElement>) {\n onChange?.(event);\n setOn(event.target.checked);\n },\n })}\n ref={ref}\n type=\"checkbox\"\n role=\"menuitemcheckbox\"\n checked={on}\n aria-checked={on}\n tabIndex={context.activeIndex === item.index ? 0 : -1}\n className=\"roaster-switch__input\"\n />\n <span className=\"roaster-switch__track\" />\n </span>\n </label>\n );\n }\n);\nActionListSwitchItem.displayName = 'ActionListSwitchItem';\n"],"names":[],"mappings":";;;;;;;;AAMY,MAAC,oBAAoB,GAAG,KAAK,CAAC,UAAU;AACpD,EAAE,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,eAAe,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,EAAE,OAAO,KAAK;AAC5G,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,OAAO,CAAC,CAAC;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sourcesContent":["import { useListItem } from '@floating-ui/react';\nimport * as React from 'react';\nimport { classNames, useControllableState, useMergeRefs } from '@/utils';\nimport { useActionListContext } from '../ActionList.context';\n\n/**\n * Every native `<input>` prop (`name`, `aria-*`, ...) is accepted and forwarded to the switch, with the ref.\n * `className` and `style` go to the item.\n */\nexport interface ActionListSwitchItemProps extends Omit<\n React.ComponentPropsWithoutRef<'input'>,\n 'type' | 'children' | 'role'\n> {\n /** The setting's name, with an optional icon before it. */\n children: React.ReactNode;\n /** Called with the new state when the user turns the setting on or off. */\n onCheckedChange?(checked: boolean): void;\n}\n\n/**\n * An on/off setting in the menu (`role=\"menuitemcheckbox\"`), drawn as a switch at the item's end, such as showing a\n * chart. Turning it on or off leaves the menu open.\n */\nexport const ActionListSwitchItem = React.forwardRef<HTMLInputElement, ActionListSwitchItemProps>(\n ({ children, checked, defaultChecked, onChange, onCheckedChange, className, style, ...rest }, propRef) => {\n const context = useActionListContext();\n const item = useListItem();\n const ref = useMergeRefs([item.ref, propRef]);\n const [on, setOn] = useControllableState({\n value: checked,\n defaultValue: defaultChecked ?? false,\n onChange: onCheckedChange,\n });\n\n return (\n <label className={classNames('roaster-action-list__item', className)} style={style}>\n {children}\n <span className=\"roaster-switch\">\n <input\n {...context.getItemProps({\n ...rest,\n onChange(event: React.ChangeEvent<HTMLInputElement>) {\n onChange?.(event);\n setOn(event.target.checked);\n },\n })}\n ref={ref}\n type=\"checkbox\"\n role=\"menuitemcheckbox\"\n checked={on}\n aria-checked={on}\n tabIndex={context.activeIndex === item.index ? 0 : -1}\n className=\"roaster-switch__input\"\n />\n <span className=\"roaster-switch__track\" />\n </span>\n </label>\n );\n }\n);\nActionListSwitchItem.displayName = 'ActionListSwitchItem';\n"],"names":[],"mappings":";;;;;;;;;AAMY,MAAC,oBAAoB,GAAG,KAAK,CAAC,UAAU;AACpD,EAAE,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,eAAe,EAAE,SAA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,GAAG,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,uBAAuB,EAAE;AAC1E,OAAO,EAAE;AACT,KAAK,EAAE,CAAC;AACR,EAAE;AACF;AACA,oBAAoB,CAAC,WAAW,GAAG,sBAAsB;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"AppFrame.js","sources":["../../../../src/components/AppFrame/AppFrame.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames } from '@/utils';\n\n/** Every native `<div>` prop is accepted and forwarded to it. */\nexport type LayoutProps = React.ComponentPropsWithoutRef<'div'>;\n\n/** The page's layout wrapper: it holds the Sidebar (or a HeaderMenu) and the Mainframe. */\nexport const Layout = React.forwardRef<HTMLDivElement, LayoutProps>(({ className, ...others }, ref) => (\n <div {...others} ref={ref} className={classNames('roaster-layout', className)} />\n));\nLayout.displayName = 'Layout';\n\n/** Every native `<div>` prop is accepted and forwarded to it. */\nexport interface MainframeProps extends React.ComponentPropsWithoutRef<'div'> {\n /** The content: the Page, and a Visualizer beside it when `grid` is set. */\n children?: React.ReactNode;\n /** Alerts about the whole app, above the page, such as an outdated payment. */\n alerts?: React.ReactNode;\n /**\n * Makes room for a Visualizer beside the page.\n * @defaultValue false\n */\n grid?: boolean;\n}\n\n/** The frame beside the sidebar: app-wide alerts, then the page (and a Visualizer, with `grid`). */\nexport const Mainframe = React.forwardRef<HTMLDivElement, MainframeProps>(\n ({ children, alerts, grid = false, className, ...others }, ref) => (\n <div\n {...others}\n ref={ref}\n className={classNames('roaster-mainframe', { 'roaster-mainframe--grid': grid }, className)}\n >\n {alerts && <section className=\"roaster-mainframe__alerts\">{alerts}</section>}\n {children}\n </div>\n )\n);\nMainframe.displayName = 'Mainframe';\n\n/** Every native `<header>` prop is accepted and forwarded to it. */\nexport interface HeaderMenuProps extends React.ComponentPropsWithoutRef<'header'> {\n /** The bar's content: a way back (breadcrumbs), the logo, the account menu. */\n children?: React.ReactNode;\n}\n\n/** The sticky bar at the top of pages without a sidebar. */\nexport const HeaderMenu = React.forwardRef<HTMLElement, HeaderMenuProps>(({ className, ...others }, ref) => (\n <header {...others} ref={ref} className={classNames('roaster-header-menu', className)} />\n));\nHeaderMenu.displayName = 'HeaderMenu';\n\n/** Every native `<header>` prop is accepted and forwarded to it. */\nexport interface TopBarProps extends Omit<React.ComponentPropsWithoutRef<'header'>, 'title'> {\n /** The start of the bar, such as a search button (with `className=\"roaster-top-bar__search\"`), or a `Breadcrumbs`. */\n children?: React.ReactNode;\n /**\n * The page's name, on a page without a title of its own: an `<h1>`, with an optional icon before it, at the bar's\n * start, before `children`.\n */\n title?: React.ReactNode;\n /** The end of the bar: buttons, and the account, a `<button className=\"roaster-top-bar__account\">` with an `Avatar`. */\n actions?: React.ReactNode;\n}\n\n/** The bar at the top of the main frame, beside the sidebar: a search, then actions and the account. */\nexport const TopBar = React.forwardRef<HTMLElement, TopBarProps>(\n ({ className, children, title, actions, ...others }, ref) => (\n <header {...others} ref={ref} className={classNames('roaster-top-bar', className)}>\n {title != null && title !== false && <h1 className=\"roaster-top-bar__title\">{title}</h1>}\n {children}\n {actions && <div className=\"roaster-top-bar__actions\">{actions}</div>}\n </header>\n )\n);\nTopBar.displayName = 'TopBar';\n\n/** Every native `<footer>` prop is accepted and forwarded to it. */\nexport interface FooterProps extends React.ComponentPropsWithoutRef<'footer'> {\n /** The bar's content, such as the store's name in `<span className=\"roaster-footer__store\">`. */\n children?: React.ReactNode;\n}\n\n/** The fixed bar at the bottom of the page. */\nexport const Footer = React.forwardRef<HTMLElement, FooterProps>(({ className, ...others }, ref) => (\n <footer {...others} ref={ref} className={classNames('roaster-footer', className)} />\n));\nFooter.displayName = 'Footer';\n"],"names":[],"mappings":";;;;;AAIY,MAAC,MAAM,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,MAAM,EAAE,EAAE,GAAG,qBAAqB,GAAG,CAAC,KAAK,EAAE,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,UAAU,C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KAAK,KAAK,oBAAoB,GAAG,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,wBAAwB,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AAC3H,IAAI,QAAQ;AACZ,IAAI,OAAO,oBAAoB,GAAG,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,0BAA0B,EAAE,QAAQ,EAAE,OAAO,EAAE;AACtG,GAAG,EAAE;AACL;AACA,MAAM,CAAC,WAAW,GAAG,QAAQ;AACjB,MAAC,MAAM,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,MAAM,EAAE,EAAE,GAAG,qBAAqB,GAAG,CAAC,QAAQ,EAAE,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,UAAU,CAAC,gBAAgB,EAAE,SAAS,CAAC,EAAE,CAAC;AAC/K,MAAM,CAAC,WAAW,GAAG,QAAQ;;"}
1
+ {"version":3,"file":"AppFrame.js","sources":["../../../../src/components/AppFrame/AppFrame.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames } from '@/utils';\n\n/** Every native `<div>` prop is accepted and forwarded to it. */\nexport type LayoutProps = React.ComponentPropsWithoutRef<'div'>;\n\n/** The page's layout wrapper: it holds the Sidebar (or a HeaderMenu) and the Mainframe. */\nexport const Layout = React.forwardRef<HTMLDivElement, LayoutProps>(({ className, ...others }, ref) => (\n <div {...others} ref={ref} className={classNames('roaster-layout', className)} />\n));\nLayout.displayName = 'Layout';\n\n/** Every native `<div>` prop is accepted and forwarded to it. */\nexport interface MainframeProps extends React.ComponentPropsWithoutRef<'div'> {\n /** The content: the Page, and a Visualizer beside it when `grid` is set. */\n children?: React.ReactNode;\n /** Alerts about the whole app, above the page, such as an outdated payment. */\n alerts?: React.ReactNode;\n /**\n * Makes room for a Visualizer beside the page.\n * @defaultValue false\n */\n grid?: boolean;\n}\n\n/** The frame beside the sidebar: app-wide alerts, then the page (and a Visualizer, with `grid`). */\nexport const Mainframe = React.forwardRef<HTMLDivElement, MainframeProps>(\n ({ children, alerts, grid = false, className, ...others }, ref) => (\n <div\n {...others}\n ref={ref}\n className={classNames('roaster-mainframe', { 'roaster-mainframe--grid': grid }, className)}\n >\n {alerts && <section className=\"roaster-mainframe__alerts\">{alerts}</section>}\n {children}\n </div>\n )\n);\nMainframe.displayName = 'Mainframe';\n\n/** Every native `<header>` prop is accepted and forwarded to it. */\nexport interface HeaderMenuProps extends React.ComponentPropsWithoutRef<'header'> {\n /**\n * The bar's content: a way back (breadcrumbs), the logo, the account menu. The account opens from a `Button` with a\n * small `Avatar`, the name and a chevron, or from the picture alone, as in the TopBar:\n * `<button className=\"roaster-top-bar__account\">` with an `Avatar`.\n */\n children?: React.ReactNode;\n}\n\n/** The sticky bar at the top of pages without a sidebar. */\nexport const HeaderMenu = React.forwardRef<HTMLElement, HeaderMenuProps>(({ className, ...others }, ref) => (\n <header {...others} ref={ref} className={classNames('roaster-header-menu', className)} />\n));\nHeaderMenu.displayName = 'HeaderMenu';\n\n/** Every native `<header>` prop is accepted and forwarded to it. */\nexport interface TopBarProps extends Omit<React.ComponentPropsWithoutRef<'header'>, 'title'> {\n /** The start of the bar, such as a search button (with `className=\"roaster-top-bar__search\"`), or a `Breadcrumbs`. */\n children?: React.ReactNode;\n /**\n * The page's name, on a page without a title of its own: an `<h1>`, with an optional icon before it, at the bar's\n * start, before `children`.\n */\n title?: React.ReactNode;\n /** The end of the bar: buttons, and the account, a `<button className=\"roaster-top-bar__account\">` with an `Avatar`. */\n actions?: React.ReactNode;\n}\n\n/** The bar at the top of the main frame, beside the sidebar: a search, then actions and the account. */\nexport const TopBar = React.forwardRef<HTMLElement, TopBarProps>(\n ({ className, children, title, actions, ...others }, ref) => (\n <header {...others} ref={ref} className={classNames('roaster-top-bar', className)}>\n {title != null && title !== false && <h1 className=\"roaster-top-bar__title\">{title}</h1>}\n {children}\n {actions && <div className=\"roaster-top-bar__actions\">{actions}</div>}\n </header>\n )\n);\nTopBar.displayName = 'TopBar';\n\n/** Every native `<footer>` prop is accepted and forwarded to it. */\nexport interface FooterProps extends React.ComponentPropsWithoutRef<'footer'> {\n /** The bar's content, such as the store's name in `<span className=\"roaster-footer__store\">`. */\n children?: React.ReactNode;\n}\n\n/** The fixed bar at the bottom of the page. */\nexport const Footer = React.forwardRef<HTMLElement, FooterProps>(({ className, ...others }, ref) => (\n <footer {...others} ref={ref} className={classNames('roaster-footer', className)} />\n));\nFooter.displayName = 'Footer';\n"],"names":[],"mappings":";;;;;AAIY,MAAC,MAAM,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,MAAM,EAAE,EAAE,GAAG,qBAAqB,GAAG,CAAC,KAAK,EAAE,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,UAAU,CAAC,gBAAgB,EAAE,SAAS,CAAC,EAAE,CAAC;AAC5K,MAAM,CAAC,WAAW,GAAG,QAAQ;AACjB,MAAC,SAAS,GAAG,KAAK,CAAC,UAAU;AACzC,EAAE,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,GAAG,KAAK,EAAE,SAAS,EAAE,GAAG,MAAM,EAAE,EAAE,GAAG,qBAAqB,IAAI;AACzF,IAAI,KAAK;AACT,IAAI;AACJ,MAAM,GAAG,MAAM;AACf,MAAM,GAAG;AACT,MAAM,SAAS,EAAE,UAAU,CAAC,mBAAmB,EAAE,EAAE,yBAAyB,EAAE,IAAI,EAAE,EAAE,SAAS,CAAC;AAChG,MAAM,QAAQ,EAAE;AAChB,QAAQ,MAAM,oBAAoB,GAAG,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,2BAA2B,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAC9G,QAAQ;AACR;AACA;AACA;AACA;AACA,SAAS,CAAC,WAAW,GAAG,WAAW;AACvB,MAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,MAAM,EAAE,EAAE,GAAG,qBAAqB,GAAG,CAAC,QAAQ,EAAE,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,UAAU,CAAC,qBAAqB,EAAE,SAAS,CAAC,EAAE,CAAC;AACxL,UAAU,CAAC,WAAW,GAAG,YAAY;AACzB,MAAC,MAAM,GAAG,KAAK,CAAC,UAAU;AACtC,EAAE,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,MAAM,EAAE,EAAE,GAAG,qBAAqB,IAAI,CAAC,QAAQ,EAAE,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,UAAU,CAAC,iBAAiB,EAAE,SAAS,CAAC,EAAE,QAAQ,EAAE;AAC/K,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,KAAK,KAAK,oBAAoB,GAAG,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,wBAAwB,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AAC3H,IAAI,QAAQ;AACZ,IAAI,OAAO,oBAAoB,GAAG,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,0BAA0B,EAAE,QAAQ,EAAE,OAAO,EAAE;AACtG,GAAG,EAAE;AACL;AACA,MAAM,CAAC,WAAW,GAAG,QAAQ;AACjB,MAAC,MAAM,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,MAAM,EAAE,EAAE,GAAG,qBAAqB,GAAG,CAAC,QAAQ,EAAE,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,UAAU,CAAC,gBAAgB,EAAE,SAAS,CAAC,EAAE,CAAC;AAC/K,MAAM,CAAC,WAAW,GAAG,QAAQ;;"}
@@ -25,7 +25,7 @@ const Avatar = React.forwardRef(
25
25
  ),
26
26
  style: { ...typeof size === "number" && { width: size, height: size }, ...style },
27
27
  children: [
28
- icon ? icon : showFallback ? (initials ?? name.charAt(0)).toUpperCase() : /* @__PURE__ */ jsx("img", { src: src ?? void 0, alt: label, onError }),
28
+ icon ? icon : showFallback ? initials ?? name.charAt(0).toUpperCase() : /* @__PURE__ */ jsx("img", { src: src ?? void 0, alt: label, onError }),
29
29
  badge != null && /* @__PURE__ */ jsx("span", { className: "roaster-avatar__badge", children: badge })
30
30
  ]
31
31
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Avatar.js","sources":["../../../../src/components/Avatar/Avatar.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames, useImageFallback } from '@/utils';\n\n/** Every native `<span>` prop (`id`, `aria-*`, `data-*`, ...) is accepted and forwarded to it. */\nexport interface AvatarProps extends React.ComponentPropsWithoutRef<'span'> {\n /** The URL of the picture. Without it, or when it fails to load, the avatar shows the initial of `name`. */\n src?: string | null;\n /**\n * What the avatar says to screen readers. `''` when the name is already written next to it.\n * @defaultValue `name`\n */\n alt?: string;\n /** The name of the person or store. */\n name: string;\n /** The width and height, in pixels, or `small` (28px, such as in a list's rows). */\n size?: number | 'small';\n /** The letters shown without a picture, such as two initials. The first letter of `name` by default. */\n initials?: string;\n /** Fills the initials in one of seven colors, so that neighbors differ, or in gray (`neutral`), for no one. */\n tint?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 'neutral';\n /** An icon in place of the picture and the initials, such as an arrow to a list's other items. */\n icon?: React.ReactNode;\n /** A small mark on the avatar's corner, such as an `Icon` for a linked account. */\n badge?: React.ReactNode;\n}\n\n/** A round picture of a person or a store, showing the initial of the name when there is no picture. */\nexport const Avatar = React.forwardRef<HTMLSpanElement, AvatarProps>(\n ({ src, alt, name, size, initials, tint, icon, badge, className, style, ...others }, ref) => {\n const { showFallback, onError } = useImageFallback(src);\n const label = alt ?? name;\n // The initial is a picture of the name: named like one, or hidden when it is decorative.\n const fallbackProps = label ? { role: 'img', 'aria-label': label } : { 'aria-hidden': true };\n\n return (\n <span\n {...(showFallback ? fallbackProps : {})}\n {...others}\n ref={ref}\n className={classNames(\n 'roaster-avatar',\n {\n [`roaster-avatar--${tint === 'neutral' ? 'neutral' : `tint-${tint}`}`]: tint !== undefined,\n 'roaster-avatar--small': size === 'small',\n },\n className\n )}\n style={{ ...(typeof size === 'number' && { width: size, height: size }), ...style }}\n >\n {icon ? (\n icon\n ) : showFallback ? (\n (initials ?? name.charAt(0)).toUpperCase()\n ) : (\n <img src={src ?? undefined} alt={label} onError={onError} />\n )}\n {badge != null && <span className=\"roaster-avatar__badge\">{badge}</span>}\n </span>\n );\n }\n);\n\nAvatar.displayName = 'Avatar';\n"],"names":[],"mappings":";;;;;;AAIY,MAAC,MAAM,GAAG,KAAK,CAAC,UAAU;AACtC,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,MAAM,EAAE,EAAE,GAAG,KAAK;AAC/F,IAAI,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,GAAG,gBAAgB,CAAC,GAAG,CAAC;AAC3D,IAAI,MAAM,KAAK,GAAG,GAAG,IAAI,IAAI;AAC7B,IAAI,MAAM,aAAa,GAAG,KAAK,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,EAAE,IAAI,EAAE;AAChG,IAAI,uBAAuB,IAAI;AAC/B,MAAM,MAAM;AACZ,MAAM;AACN,QAAQ,GAAG,YAAY,GAAG,aAAa,GAAG,EAAE;AAC5C,QAAQ,GAAG,MAAM;AACjB,QAAQ,GAAG;AACX,QAAQ,SAAS,EAAE,UAAU;AAC7B,UAAU,gBAAgB;AAC1B,UAAU;AACV,YAAY,CAAC,CAAC,gBAAgB,EAAE,IAAI,KAAK,SAAS,GAAG,SAAS,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,KAAK,MAAM;AACnG,YAAY,uBAAuB,EAAE,IAAI,KAAK;AAC9C,WAAW;AACX,UAAU;AACV,SAAS;AACT,QAAQ,KAAK,EAAE,EAAE,GAAG,OAAO,IAAI,KAAK,QAAQ,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,GAAG,KAAK,EAAE;AACzF,QAAQ,QAAQ,EAAE;AAClB,UAAU,IAAI,GAAG,IAAI,GAAG,YAAY,GAAG,CAAC,QAAQ,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,mBAAmB,GAAG,CAAC,KAAK,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAC3J,UAAU,KAAK,IAAI,IAAI,oBAAoB,GAAG,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,uBAAuB,EAAE,QAAQ,EAAE,KAAK,EAAE;AAC9G;AACA;AACA,KAAK;AACL,EAAE;AACF;AACA,MAAM,CAAC,WAAW,GAAG,QAAQ;;"}
1
+ {"version":3,"file":"Avatar.js","sources":["../../../../src/components/Avatar/Avatar.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames, useImageFallback } from '@/utils';\n\n/** Every native `<span>` prop (`id`, `aria-*`, `data-*`, ...) is accepted and forwarded to it. */\nexport interface AvatarProps extends React.ComponentPropsWithoutRef<'span'> {\n /** The URL of the picture. Without it, or when it fails to load, the avatar shows the initial of `name`. */\n src?: string | null;\n /**\n * What the avatar says to screen readers. `''` when the name is already written next to it.\n * @defaultValue `name`\n */\n alt?: string;\n /** The name of the person or store. */\n name: string;\n /** The width and height, in pixels, or `small` (28px, such as in a list's rows). */\n size?: number | 'small';\n /**\n * The letters shown without a picture, such as two initials, as written: a brand's lower-case \"k\" stays one. The first\n * letter of `name`, in capitals, by default.\n */\n initials?: string;\n /** Fills the initials in one of seven colors, so that neighbors differ, or in gray (`neutral`), for no one. */\n tint?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 'neutral';\n /** An icon in place of the picture and the initials, such as an arrow to a list's other items. */\n icon?: React.ReactNode;\n /** A small mark on the avatar's corner, such as an `Icon` for a linked account. */\n badge?: React.ReactNode;\n}\n\n/** A round picture of a person or a store, showing the initial of the name when there is no picture. */\nexport const Avatar = React.forwardRef<HTMLSpanElement, AvatarProps>(\n ({ src, alt, name, size, initials, tint, icon, badge, className, style, ...others }, ref) => {\n const { showFallback, onError } = useImageFallback(src);\n const label = alt ?? name;\n // The initial is a picture of the name: named like one, or hidden when it is decorative.\n const fallbackProps = label ? { role: 'img', 'aria-label': label } : { 'aria-hidden': true };\n\n return (\n <span\n {...(showFallback ? fallbackProps : {})}\n {...others}\n ref={ref}\n className={classNames(\n 'roaster-avatar',\n {\n [`roaster-avatar--${tint === 'neutral' ? 'neutral' : `tint-${tint}`}`]: tint !== undefined,\n 'roaster-avatar--small': size === 'small',\n },\n className\n )}\n style={{ ...(typeof size === 'number' && { width: size, height: size }), ...style }}\n >\n {icon ? (\n icon\n ) : showFallback ? (\n (initials ?? name.charAt(0).toUpperCase())\n ) : (\n <img src={src ?? undefined} alt={label} onError={onError} />\n )}\n {badge != null && <span className=\"roaster-avatar__badge\">{badge}</span>}\n </span>\n );\n }\n);\n\nAvatar.displayName = 'Avatar';\n"],"names":[],"mappings":";;;;;;AAIY,MAAC,MAAM,GAAG,KAAK,CAAC,UAAU;AACtC,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,MAAM,EAAE,EAAE,GAAG,KAAK;AAC/F,IAAI,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,GAAG,gBAAgB,CAAC,GAAG,CAAC;AAC3D,IAAI,MAAM,KAAK,GAAG,GAAG,IAAI,IAAI;AAC7B,IAAI,MAAM,aAAa,GAAG,KAAK,GAAG,EAAE,IAAI,EAAE,KA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5
4
  import { CheckboxGroup } from './CheckboxGroup/CheckboxGroup.js';
6
5
  import { useCheckboxGroupContext } from './CheckboxGroup/CheckboxGroup.context.js';
7
6
  import { leafValues, ChoiceText } from './ChoiceText.js';
8
7
  import { useUid } from '../../utils/useUid/index.js';
9
8
  import { useControllableState } from '../../utils/useControllableState/index.js';
9
+ import { useMergeRefs } from '../../utils/useMergeRefs/index.js';
10
10
  import { classNames } from '../../utils/classNames/index.js';
11
11
 
12
12
  const CheckboxBase = React.forwardRef((props, ref) => {
@@ -1 +1 @@
1
- {"version":3,"file":"Checkbox.js","sources":["../../../../src/components/Checkbox/Checkbox.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useMergeRefs } from '@floating-ui/react';\nimport { classNames, useControllableState, useUid } from '@/utils';\nimport { CheckboxGroup } from './CheckboxGroup/CheckboxGroup';\nimport { useCheckboxGroupContext } from './CheckboxGroup/CheckboxGroup.context';\nimport { ChoiceText, leafValues } from './ChoiceText';\n\n/**\n * Every native `<input>` prop (`name`, `required`, `onChange`, `aria-*`, ...) is accepted and forwarded to the\n * checkbox, with the ref. `className` and `style` go to its label.\n */\nexport interface CheckboxProps extends Omit<React.ComponentPropsWithoutRef<'input'>, 'type' | 'value'> {\n /** The value submitted with the form when checked, and the value a `Checkbox.Group` holds. */\n value: string;\n /** The text next to the box. */\n label?: React.ReactNode;\n /** A line under the label, such as what the choice means. */\n description?: React.ReactNode;\n /** A short text at the end of the row, such as the kind of a name (\"Recipient\"). */\n detail?: React.ReactNode;\n /**\n * The checkboxes under this one, in a `Checkbox.Group`: checking it checks them all, and it is checked when they\n * all are, mixed when some are. Their values stand for its own.\n */\n children?: React.ReactNode;\n /** `card` draws the checkbox as a bordered card, highlighted while checked. */\n variant?: 'default' | 'card';\n /** The mixed state: some of the items this checkbox stands for are checked, not all. */\n indeterminate?: boolean;\n /** Called with the new checked state when the user toggles the checkbox. */\n onCheckedChange?(checked: boolean): void;\n}\n\nconst CheckboxBase = React.forwardRef<HTMLInputElement, CheckboxProps>((props, ref) => {\n const {\n id,\n label,\n description,\n detail,\n children,\n value,\n variant = 'default',\n indeterminate = false,\n checked,\n defaultChecked,\n onChange,\n onCheckedChange,\n className,\n style,\n ...others\n } = props;\n const ctx = useCheckboxGroupContext();\n const uid = useUid(id);\n // On its own, the checkbox follows `checked`, or keeps its own state from `defaultChecked`.\n const [ownChecked, setOwnChecked] = useControllableState({\n value: checked,\n defaultValue: defaultChecked ?? false,\n onChange: onCheckedChange,\n });\n // `indeterminate` is a DOM property, not an attribute.\n const inputRef = React.useRef<HTMLInputElement>(null);\n const mergedRef = useMergeRefs([inputRef, ref]);\n\n // With checkboxes under it, in a group, it stands for them.\n const nested = React.useMemo(() => (children != null ? leafValues(children) : []), [children]);\n const parent = ctx != null && nested.length > 0;\n const nestedChecked = parent ? nested.filter((item) => ctx.value.includes(item)).length : 0;\n const isIndeterminate = parent ? nestedChecked > 0 && nestedChecked < nested.length : indeterminate;\n React.useEffect(() => {\n if (inputRef.current) inputRef.current.indeterminate = isIndeterminate;\n }, [isIndeterminate]);\n\n const isChecked = parent ? nestedChecked === nested.length : ctx ? ctx.value.includes(value) : ownChecked;\n const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n onChange?.(event);\n if (parent) {\n const others = ctx.value.filter((item) => !nested.includes(item));\n ctx.setValue(event.target.checked ? [...others, ...nested] : others);\n } else if (ctx) ctx.onChange(event);\n else setOwnChecked(event.target.checked);\n };\n\n const choice = (\n <label\n className={classNames('roaster-choice', { 'roaster-choice--card': variant === 'card' }, className)}\n style={style}\n >\n <input\n {...others}\n ref={mergedRef}\n id={uid}\n type=\"checkbox\"\n value={value}\n checked={isChecked}\n onChange={handleChange}\n className=\"roaster-choice__input\"\n />\n <span className=\"roaster-choice__box\" />\n <ChoiceText label={label} description={description} detail={detail} labelId={`${uid}-label`} />\n </label>\n );\n if (children == null) return choice;\n return (\n <>\n {choice}\n <div className=\"roaster-choice-group roaster-choice-group--nested\" role=\"group\" aria-labelledby={`${uid}-label`}>\n {children}\n </div>\n </>\n );\n});\n\nCheckboxBase.displayName = 'Checkbox';\n\n/**\n * A checkbox with a label. Use Checkbox.Group to manage several values together, and `variant=\"card\"` for a\n * card-style option.\n */\nexport const Checkbox = Object.assign(CheckboxBase, { Group: CheckboxGroup });\n"],"names":[],"mappings":";;;;;;;;;;;AAQA,MAAM,YAAY,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK;AACtD,EAAE,MAAM;AACR,IAAI,EAAE;AACN,IAAI,KAAK;AACT,IAAI,WAAW;AACf,IAAI,MAAM;AACV,IAAI,QAAQ;AACZ,IAAI,KAAK;AACT,IAAI,OAAO,GAAG,SAAS;AACvB,IAAI,aAAa,GAAG,KAAK;AACzB,IAAI,OAAO;AACX,IAAI,cAAc;AAClB,IAAI,QAAQ;AACZ,IAAI,eAAe;AACnB,IAAI,SAAS;AACb,IAAI,KAAK;AACT,IAAI,GAAG;AACP,GAAG,GAAG,KAAK;AACX,EAAE,MAAM,GAAG,GAAG,uBAAuB,EAAE;AACvC,EAAE,MAAM,GAAG,GAAG,MAAM,CAAC,EAAE,CAAC;AACxB,EAAE,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,oBAAoB,CAAC;AAC3D,IAAI,KAAK,EAAE,OAAO;AAClB,IAAI,YAAY,EAAE,cAAc,IAAI,KAAK;AACzC,IAAI,QAAQ,EAAE;AACd,GAAG,CAAC;AACJ,EAAE,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC;AACrC,EAAE,MAAM,SAAS,GAAG,YAAY,CAAC,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;AACjD,EAAE,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,QAAQ,IAAI,IAAI,GAAG,UAAU,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC;AAC9F,EAAE,MAAM,MAAM,GAAG,G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/Checkbox.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames, useControllableState, useMergeRefs, useUid } from '@/utils';\nimport { CheckboxGroup } from './CheckboxGroup/CheckboxGroup';\nimport { useCheckboxGroupContext } from './CheckboxGroup/CheckboxGroup.context';\nimport { ChoiceText, leafValues } from './ChoiceText';\n\n/**\n * Every native `<input>` prop (`name`, `required`, `onChange`, `aria-*`, ...) is accepted and forwarded to the\n * checkbox, with the ref. `className` and `style` go to its label.\n */\nexport interface CheckboxProps extends Omit<React.ComponentPropsWithoutRef<'input'>, 'type' | 'value'> {\n /** The value submitted with the form when checked, and the value a `Checkbox.Group` holds. */\n value: string;\n /** The text next to the box. */\n label?: React.ReactNode;\n /** A line under the label, such as what the choice means. */\n description?: React.ReactNode;\n /** A short text at the end of the row, such as the kind of a name (\"Recipient\"). */\n detail?: React.ReactNode;\n /**\n * The checkboxes under this one, in a `Checkbox.Group`: checking it checks them all, and it is checked when they\n * all are, mixed when some are. Their values stand for its own.\n */\n children?: React.ReactNode;\n /** `card` draws the checkbox as a bordered card, highlighted while checked. */\n variant?: 'default' | 'card';\n /** The mixed state: some of the items this checkbox stands for are checked, not all. */\n indeterminate?: boolean;\n /** Called with the new checked state when the user toggles the checkbox. */\n onCheckedChange?(checked: boolean): void;\n}\n\nconst CheckboxBase = React.forwardRef<HTMLInputElement, CheckboxProps>((props, ref) => {\n const {\n id,\n label,\n description,\n detail,\n children,\n value,\n variant = 'default',\n indeterminate = false,\n checked,\n defaultChecked,\n onChange,\n onCheckedChange,\n className,\n style,\n ...others\n } = props;\n const ctx = useCheckboxGroupContext();\n const uid = useUid(id);\n // On its own, the checkbox follows `checked`, or keeps its own state from `defaultChecked`.\n const [ownChecked, setOwnChecked] = useControllableState({\n value: checked,\n defaultValue: defaultChecked ?? false,\n onChange: onCheckedChange,\n });\n // `indeterminate` is a DOM property, not an attribute.\n const inputRef = React.useRef<HTMLInputElement>(null);\n const mergedRef = useMergeRefs([inputRef, ref]);\n\n // With checkboxes under it, in a group, it stands for them.\n const nested = React.useMemo(() => (children != null ? leafValues(children) : []), [children]);\n const parent = ctx != null && nested.length > 0;\n const nestedChecked = parent ? nested.filter((item) => ctx.value.includes(item)).length : 0;\n const isIndeterminate = parent ? nestedChecked > 0 && nestedChecked < nested.length : indeterminate;\n React.useEffect(() => {\n if (inputRef.current) inputRef.current.indeterminate = isIndeterminate;\n }, [isIndeterminate]);\n\n const isChecked = parent ? nestedChecked === nested.length : ctx ? ctx.value.includes(value) : ownChecked;\n const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n onChange?.(event);\n if (parent) {\n const others = ctx.value.filter((item) => !nested.includes(item));\n ctx.setValue(event.target.checked ? [...others, ...nested] : others);\n } else if (ctx) ctx.onChange(event);\n else setOwnChecked(event.target.checked);\n };\n\n const choice = (\n <label\n className={classNames('roaster-choice', { 'roaster-choice--card': variant === 'card' }, className)}\n style={style}\n >\n <input\n {...others}\n ref={mergedRef}\n id={uid}\n type=\"checkbox\"\n value={value}\n checked={isChecked}\n onChange={handleChange}\n className=\"roaster-choice__input\"\n />\n <span className=\"roaster-choice__box\" />\n <ChoiceText label={label} description={description} detail={detail} labelId={`${uid}-label`} />\n </label>\n );\n if (children == null) return choice;\n return (\n <>\n {choice}\n <div className=\"roaster-choice-group roaster-choice-group--nested\" role=\"group\" aria-labelledby={`${uid}-label`}>\n {children}\n </div>\n </>\n );\n});\n\nCheckboxBase.displayName = 'Checkbox';\n\n/**\n * A checkbox with a label. Use Checkbox.Group to manage several values together, and `variant=\"card\"` for a\n * card-style option.\n */\nexport const Checkbox = Object.assign(CheckboxBase, { Group: CheckboxGroup });\n"],"names":[],"mappings":";;;;;;;;;;;AAOA,MAAM,YAAY,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK;AACtD,EAAE,MAAM;AACR,IAAI,EAAE;AACN,IAAI,KAAK;AACT,IAAI,WAAW;AACf,IAAI,MAAM;AACV,IAAI,QAAQ;AACZ,IAA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;AAC9B,YAAY,QAAQ,EAAE,YAAY;AAClC,YAAY,SAAS,EAAE;AACvB;AACA,SAAS;AACT,wBAAwB,GAAG,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,qBAAqB,EAAE,CAAC;AACzE,wBAAwB,GAAG,CAAC,UAAU,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE;AAC/F;AACA;AACA,GAAG;AACH,EAAE,IAAI,QAAQ,IAAI,IAAI,EAAE,OAAO,MAAM;AACrC,EAAE,uBAAuB,IAAI,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE;AACpD,IAAI,MAAM;AACV,oBAAoB,GAAG,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,mDAAmD,EAAE,IAAI,EAAE,OAAO,EAAE,iBAAiB,EAAE,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE;AAC7J,GAAG,EAAE,CAAC;AACN,CAAC,CAAC;AACF,YAAY,CAAC,WAAW,GAAG,UAAU;AACzB,MAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE;;"}
@@ -17,6 +17,7 @@ const ColorField = React.forwardRef((props, ref) => {
17
17
  name,
18
18
  disabled,
19
19
  description,
20
+ keepDescription,
20
21
  error,
21
22
  className,
22
23
  style,
@@ -50,35 +51,47 @@ const ColorField = React.forwardRef((props, ref) => {
50
51
  const color = toFullHex(typed);
51
52
  if (color) setInternalValue(color);
52
53
  };
53
- return /* @__PURE__ */ jsx(Field, { controlId: uid, label, description, error, className, style, children: /* @__PURE__ */ jsxs("div", { className: "roaster-merged-inputs", children: [
54
- /* @__PURE__ */ jsxs("span", { className: "roaster-color-swatch roaster-merged-inputs__start", children: [
55
- /* @__PURE__ */ jsx("span", { className: "roaster-color-swatch__preview", style: { backgroundColor: internalValue } }),
56
- /* @__PURE__ */ jsx(
57
- "input",
58
- {
59
- ...others,
60
- ...fieldControlProps(uid, { description, error }, others),
61
- ref,
62
- type: "color",
63
- className: "roaster-color-swatch__input",
64
- name,
65
- disabled,
66
- onChange: handleChange,
67
- value: internalValue
68
- }
69
- )
70
- ] }),
71
- /* @__PURE__ */ jsx(
72
- "input",
73
- {
74
- type: "text",
75
- className: "roaster-input roaster-merged-inputs__end",
76
- "aria-label": text.hex,
77
- value: shownHex,
78
- onChange: handleHexChange
79
- }
80
- )
81
- ] }) });
54
+ return /* @__PURE__ */ jsx(
55
+ Field,
56
+ {
57
+ controlId: uid,
58
+ label,
59
+ description,
60
+ keepDescription,
61
+ error,
62
+ className,
63
+ style,
64
+ children: /* @__PURE__ */ jsxs("div", { className: "roaster-merged-inputs", children: [
65
+ /* @__PURE__ */ jsxs("span", { className: "roaster-color-swatch roaster-merged-inputs__start", children: [
66
+ /* @__PURE__ */ jsx("span", { className: "roaster-color-swatch__preview", style: { backgroundColor: internalValue } }),
67
+ /* @__PURE__ */ jsx(
68
+ "input",
69
+ {
70
+ ...others,
71
+ ...fieldControlProps(uid, { description, error, keepDescription }, others),
72
+ ref,
73
+ type: "color",
74
+ className: "roaster-color-swatch__input",
75
+ name,
76
+ disabled,
77
+ onChange: handleChange,
78
+ value: internalValue
79
+ }
80
+ )
81
+ ] }),
82
+ /* @__PURE__ */ jsx(
83
+ "input",
84
+ {
85
+ type: "text",
86
+ className: "roaster-input roaster-merged-inputs__end",
87
+ "aria-label": text.hex,
88
+ value: shownHex,
89
+ onChange: handleHexChange
90
+ }
91
+ )
92
+ ] })
93
+ }
94
+ );
82
95
  });
83
96
  ColorField.displayName = "ColorField";
84
97
 
@@ -1 +1 @@
1
- {"version":3,"file":"ColorField.js","sources":["../../../../src/components/ColorField/ColorField.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useUid, useControllableState } from '@/utils';\nimport { Field, fieldControlProps, type FieldBaseProps } from '../Field';\n\n/** `#abc` or `#aabbcc` as `#aabbcc`; anything else as `null`. */\nfunction toFullHex(text: string) {\n if (!/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(text)) return null;\n return (text.length === 4 ? text.replace(/[0-9a-f]/gi, (digit) => digit + digit) : text).toLowerCase();\n}\n\n/** The text of the color field, for other languages. */\nexport interface ColorFieldLabels {\n /** The name of the text input that holds the hex code, read by screen readers. */\n hex: string;\n}\n\nconst defaultColorFieldLabels: ColorFieldLabels = { hex: 'Hex color code' };\n\n/**\n * Every native `<input>` prop (`name`, `required`, `aria-*`, ...) is accepted and forwarded to the color input, with the\n * ref. `className` and `style` go to the field's wrapper.\n */\nexport interface ColorFieldProps\n extends FieldBaseProps, Omit<React.ComponentPropsWithoutRef<'input'>, 'type' | 'className' | 'style'> {\n /** The HTML ID attribute to be applied to the color field input element (optional). */\n id?: string;\n /** The name attribute to be applied to the color field input element (optional). */\n name?: string;\n /** Whether the color field input should be disabled (optional). */\n disabled?: boolean;\n /** The current value of the color field input (optional). */\n value?: string;\n /** The default value of the color field input (optional). */\n defaultValue?: string;\n /** Called with the new color when the user picks or types one. The native `onChange` gets the event. */\n onValueChange?(value: string): void;\n /** The text of the field, in English by default. */\n labels?: Partial<ColorFieldLabels>;\n}\n\n/** A color picker with a text field that shows and edits the hex value. */\nexport const ColorField = React.forwardRef<HTMLInputElement, ColorFieldProps>((props, ref) => {\n const {\n id,\n label,\n name,\n disabled,\n description,\n error,\n className,\n style,\n onChange,\n onValueChange,\n value,\n defaultValue,\n labels,\n ...others\n } = props;\n const text = { ...defaultColorFieldLabels, ...labels };\n const [internalValue, setInternalValue] = useControllableState({\n value,\n defaultValue: defaultValue ?? '',\n onChange: onValueChange,\n });\n const uid = useUid(id);\n\n // The hex text as typed: the color only follows once it is a whole code (#RGB or #RRGGBB).\n const [hexText, setHexText] = React.useState(internalValue);\n React.useEffect(() => {\n setHexText((typed) => (toFullHex(typed) === internalValue.toLowerCase() ? typed : internalValue));\n }, [internalValue]);\n\n // A whole code the value doesn't hold (a controlled field the parent didn't update) gives way to the value.\n const typedColor = toFullHex(hexText);\n const shownHex = typedColor && typedColor !== internalValue.toLowerCase() ? internalValue : hexText;\n\n const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n onChange?.(event);\n setInternalValue(event.currentTarget.value);\n };\n const handleHexChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n const typed = event.currentTarget.value;\n setHexText(typed);\n const color = toFullHex(typed);\n if (color) setInternalValue(color);\n };\n\n return (\n <Field controlId={uid} label={label} description={description} error={error} className={className} style={style}>\n <div className=\"roaster-merged-inputs\">\n <span className=\"roaster-color-swatch roaster-merged-inputs__start\">\n <span className=\"roaster-color-swatch__preview\" style={{ backgroundColor: internalValue }} />\n <input\n {...others}\n {...fieldControlProps(uid, { label, description, error }, others)}\n ref={ref}\n type=\"color\"\n className=\"roaster-color-swatch__input\"\n name={name}\n disabled={disabled}\n onChange={handleChange}\n value={internalValue}\n />\n </span>\n <input\n type=\"text\"\n className=\"roaster-input roaster-merged-inputs__end\"\n aria-label={text.hex}\n value={shownHex}\n onChange={handleHexChange}\n />\n </div>\n </Field>\n );\n});\n\nColorField.displayName = 'ColorField';\n"],"names":[],"mappings":";;;;;;;AAKA,SAAS,SAAS,CAAC,IAAI,EAAE;AACzB,EAAE,IAAI,CAAC,+BAA+B,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO,IAAI;AAC9D,EAAE,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,KAAK,KAAK,KAAK,GAAG,KAAK,CAAC,GAAG,IAAI,EAAE,WAAW,EAAE;AACxG;AACA,MAAM,uBAAuB,GAAG,EAAE,GAAG,EAAE,gBAAgB,EAAE;AAC7C,MAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK;AAC3D,EAAE,MAAM;AACR,IAAI,EAAE;AACN,IAAI,KAAK;AACT,IAAI,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GAAG,EAAE,CAAC,EAAE,CAAC;AACT,CAAC;AACD,UAAU,CAAC,WAAW,GAAG,YAAY;;"}
1
+ {"version":3,"file":"ColorField.js","sources":["../../../../src/components/ColorField/ColorField.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useUid, useControllableState } from '@/utils';\nimport { Field, fieldControlProps, type FieldBaseProps } from '../Field';\n\n/** `#abc` or `#aabbcc` as `#aabbcc`; anything else as `null`. */\nfunction toFullHex(text: string) {\n if (!/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(text)) return null;\n return (text.length === 4 ? text.replace(/[0-9a-f]/gi, (digit) => digit + digit) : text).toLowerCase();\n}\n\n/** The text of the color field, for other languages. */\nexport interface ColorFieldLabels {\n /** The name of the text input that holds the hex code, read by screen readers. */\n hex: string;\n}\n\nconst defaultColorFieldLabels: ColorFieldLabels = { hex: 'Hex color code' };\n\n/**\n * Every native `<input>` prop (`name`, `required`, `aria-*`, ...) is accepted and forwarded to the color input, with the\n * ref. `className` and `style` go to the field's wrapper.\n */\nexport interface ColorFieldProps\n extends FieldBaseProps, Omit<React.ComponentPropsWithoutRef<'input'>, 'type' | 'className' | 'style'> {\n /** The HTML ID attribute to be applied to the color field input element (optional). */\n id?: string;\n /** The name attribute to be applied to the color field input element (optional). */\n name?: string;\n /** Whether the color field input should be disabled (optional). */\n disabled?: boolean;\n /** The current value of the color field input (optional). */\n value?: string;\n /** The default value of the color field input (optional). */\n defaultValue?: string;\n /** Called with the new color when the user picks or types one. The native `onChange` gets the event. */\n onValueChange?(value: string): void;\n /** The text of the field, in English by default. */\n labels?: Partial<ColorFieldLabels>;\n}\n\n/** A color picker with a text field that shows and edits the hex value. */\nexport const ColorField = React.forwardRef<HTMLInputElement, ColorFieldProps>((props, ref) => {\n const {\n id,\n label,\n name,\n disabled,\n description,\n keepDescription,\n error,\n className,\n style,\n onChange,\n onValueChange,\n value,\n defaultValue,\n labels,\n ...others\n } = props;\n const text = { ...defaultColorFieldLabels, ...labels };\n const [internalValue, setInternalValue] = useControllableState({\n value,\n defaultValue: defaultValue ?? '',\n onChange: onValueChange,\n });\n const uid = useUid(id);\n\n // The hex text as typed: the color only follows once it is a whole code (#RGB or #RRGGBB).\n const [hexText, setHexText] = React.useState(internalValue);\n React.useEffect(() => {\n setHexText((typed) => (toFullHex(typed) === internalValue.toLowerCase() ? typed : internalValue));\n }, [internalValue]);\n\n // A whole code the value doesn't hold (a controlled field the parent didn't update) gives way to the value.\n const typedColor = toFullHex(hexText);\n const shownHex = typedColor && typedColor !== internalValue.toLowerCase() ? internalValue : hexText;\n\n const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n onChange?.(event);\n setInternalValue(event.currentTarget.value);\n };\n const handleHexChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n const typed = event.currentTarget.value;\n setHexText(typed);\n const color = toFullHex(typed);\n if (color) setInternalValue(color);\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 <div className=\"roaster-merged-inputs\">\n <span className=\"roaster-color-swatch roaster-merged-inputs__start\">\n <span className=\"roaster-color-swatch__preview\" style={{ backgroundColor: internalValue }} />\n <input\n {...others}\n {...fieldControlProps(uid, { label, description, error, keepDescription }, others)}\n ref={ref}\n type=\"color\"\n className=\"roaster-color-swatch__input\"\n name={name}\n disabled={disabled}\n onChange={handleChange}\n value={internalValue}\n />\n </span>\n <input\n type=\"text\"\n className=\"roaster-input roaster-merged-inputs__end\"\n aria-label={text.hex}\n value={shownHex}\n onChange={handleHexChange}\n />\n </div>\n </Field>\n );\n});\n\nColorField.displayName = 'ColorField';\n"],"names":[],"mappings":";;;;;;;AAKA,SAAS,SAAS,CAAC,IAAI,EAAE;AACzB,EAAE,IAAI,CAAC,+BAA+B,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO,IAAI;AAC9D,EAAE,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,GAAG,IAAI,CAA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I,EAAE,OAAO;AAC3B,cAAc,SAAS,EAAE,6BAA6B;AACtD,cAAc,IAAI;AAClB,cAAc,QAAQ;AACtB,cAAc,QAAQ,EAAE,YAAY;AACpC,cAAc,KAAK,EAAE;AACrB;AACA;AACA,SAAS,EAAE,CAAC;AACZ,wBAAwB,GAAG;AAC3B,UAAU,OAAO;AACjB,UAAU;AACV,YAAY,IAAI,EAAE,MAAM;AACxB,YAAY,SAAS,EAAE,0CAA0C;AACjE,YAAY,YAAY,EAAE,IAAI,CAAC,GAAG;AAClC,YAAY,KAAK,EAAE,QAAQ;AAC3B,YAAY,QAAQ,EAAE;AACtB;AACA;AACA,OAAO,EAAE;AACT;AACA,GAAG;AACH,CAAC;AACD,UAAU,CAAC,WAAW,GAAG,YAAY;;"}
@@ -5,8 +5,8 @@ import { pickCalendarProps, formatDate, dateStringParser, isDateValid, getSepara
5
5
  import { Calendar } from './components/Calendar/Calendar.js';
6
6
  import { MonthGrid } from './components/MonthGrid/MonthGrid.js';
7
7
  import { TextField } from '../TextField/TextField.js';
8
- import { useMergeRefs } from '@floating-ui/react';
9
8
  import { useControllableState } from '../../utils/useControllableState/index.js';
9
+ import { useMergeRefs } from '../../utils/useMergeRefs/index.js';
10
10
 
11
11
  const DatePickerBase = React.forwardRef(function DatePicker2(props, ref) {
12
12
  const { calendarProps, others } = pickCalendarProps(props);
@@ -1 +1 @@
1
- {"version":3,"file":"DatePicker.js","sources":["../../../../src/components/DatePicker/DatePicker.tsx"],"sourcesContent":["import * as React from 'react';\nimport { dateStringParser, formatDate, getSeparatorIndex, isDateValid, pickCalendarProps } from './utils';\n\nimport { Calendar, CalendarProps } from './components';\nimport type { CalendarLabels } from './components/Calendar/Calendar';\nimport { TextField, TextFieldProps } from '../TextField';\nimport { useMergeRefs } from '@floating-ui/react';\nimport { useControllableState } from '@/utils';\nimport { MonthGrid } from './components/MonthGrid';\nimport { DateSeparator, DateFormat, DatePickerInputError } from './utils/types';\n\nexport interface DatePickerProps\n extends\n Omit<CalendarProps, 'handleDateSelection' | 'year' | 'month' | 'selected' | 'isOpen' | 'onClose'>,\n Omit<TextFieldProps, 'onChange' | 'onValueChange' | 'defaultValue' | 'value' | 'onAbort' | 'ref'> {\n /** The separator used for the date input fields. Defaults to '-' */\n separator?: DateSeparator;\n /** The format used as input mask. Defaults to 'YYYY MM DD' */\n dateFormat?: DateFormat;\n /** Callback function that will be called when an error occurs when parsing the date */\n onInputError?(type: DatePickerInputError): string;\n /** Called with the new date, or `null` when the field is cleared. */\n onValueChange?(date: Date | null): void;\n /** Default value for uncontrolled input */\n defaultValue?: Date | null;\n /** Selected date, required with controlled input */\n value?: Date | null;\n /** The month to show, from 0 to 11. 0 is January, 1 is February ... 11 is December */\n month?: number;\n /** The year to show */\n year?: number;\n /** The text of the calendar, in English by default. */\n labels?: Partial<CalendarLabels>;\n}\n\nconst DatePickerBase = React.forwardRef<HTMLInputElement, DatePickerProps>(function DatePicker(props, ref) {\n const { calendarProps, others } = pickCalendarProps(props);\n const { labels, ...inputProps } = others as typeof others & { labels?: Partial<CalendarLabels> };\n\n const {\n month,\n year,\n onValueChange,\n onInputError,\n value: passedValue,\n disableSpecificDates,\n dateFormat,\n separator,\n minDate,\n maxDate,\n defaultValue,\n onMonthChange,\n locale,\n weekStartsOn,\n } = calendarProps;\n\n const calendarRef = React.useRef<HTMLDivElement>(null);\n const [isTextFieldFocused, setIsTextFieldFocused] = React.useState(false);\n const [inputError, setInputError] = React.useState<string | boolean>(false);\n const [currentKey, setCurrentKey] = React.useState('');\n // The calendar opens on the default date's month, if there is one.\n const [{ currentDisplayedMonth, currentDisplayedYear }, setCalendarDate] = React.useState({\n currentDisplayedMonth: defaultValue ? defaultValue.getMonth() : month,\n currentDisplayedYear: defaultValue ? defaultValue.getFullYear() : year,\n });\n\n const separatorIndex = getSeparatorIndex(dateFormat);\n\n const handleMonthChange = React.useCallback(\n (targetMonth: number, targetYear: number) => {\n setCalendarDate({ currentDisplayedMonth: targetMonth, currentDisplayedYear: targetYear });\n onMonthChange?.(targetMonth, targetYear);\n },\n [onMonthChange]\n );\n\n const [date, setDate] = useControllableState<Date | null>({\n value: passedValue,\n defaultValue: defaultValue ?? null,\n onChange: onValueChange,\n });\n\n const [inputValue, setInputValue] = React.useState(\n date instanceof Date ? formatDate(date, separator, dateFormat) : ''\n );\n\n const inputRef = React.useRef<HTMLInputElement>(null);\n const mergedRef = useMergeRefs([inputRef, ref]);\n // Set while the focus goes back to the input after closing, so that focus doesn't open the calendar again.\n const returningFocus = React.useRef(false);\n const onFocus = () => {\n if (returningFocus.current) returningFocus.current = false;\n else setIsTextFieldFocused(true);\n };\n const onBlur = () => setIsTextFieldFocused(false);\n // Escape closes the calendar, and the focus goes back to the input.\n const closeToInput = React.useCallback(() => {\n setIsTextFieldFocused(false);\n // Only when the focus really moves: focusing the focused input fires no focus event to clear the flag.\n if (inputRef.current && document.activeElement !== inputRef.current) {\n returningFocus.current = true;\n inputRef.current.focus();\n }\n }, []);\n\n const handleDateSelection = React.useCallback(\n (selectedDate: Date) => {\n setInputValue(formatDate(selectedDate, separator, dateFormat));\n setDate(selectedDate);\n setCalendarDate({\n currentDisplayedMonth: selectedDate.getMonth(),\n currentDisplayedYear: selectedDate.getFullYear(),\n });\n setInputError('');\n // Chosen: the calendar closes and the focus goes back to the input.\n window.setTimeout(closeToInput, 10);\n },\n [setDate, separator, dateFormat, closeToInput]\n );\n\n // A controlled date picker shows the new value whenever the parent changes it. Compared by time, since the parent\n // may pass a new Date object for the same day on every render.\n const controlledTime = passedValue === undefined ? undefined : (passedValue?.getTime() ?? null);\n React.useEffect(() => {\n if (controlledTime === undefined) return;\n setInputValue(controlledTime === null ? '' : formatDate(new Date(controlledTime), separator, dateFormat));\n }, [controlledTime, separator, dateFormat]);\n\n function handleInputChange(value: string) {\n const valueLength = value.length;\n\n if (currentKey !== 'Backspace' && (valueLength === separatorIndex.first || valueLength === separatorIndex.second)) {\n return setInputValue(value + separator);\n }\n\n if (valueLength === 0) {\n setDate(null);\n }\n\n setInputValue(value);\n\n if (valueLength === 10) {\n const dateValue = dateStringParser(value, dateFormat, separator);\n if (!dateValue) {\n return setInputError(onInputError?.('INVALID_DATE') ?? true);\n }\n setInputError('');\n\n if (isDateValid({ date: dateValue, minDate, maxDate })) {\n return handleDateSelection(dateValue);\n }\n return setInputError(onInputError?.('OUT_OF_RANGE') ?? true);\n }\n // Still typing: the error, if any, waits for the field to lose the focus.\n setInputError('');\n }\n\n const handleInputBlur = (event: React.FocusEvent<HTMLInputElement>) => {\n others.onBlur?.(event);\n if (inputValue.length > 0 && inputValue.length < 10) setInputError(onInputError?.('INVALID_DATE') ?? true);\n };\n\n return (\n <div\n className=\"roaster-date-picker\"\n ref={calendarRef}\n // Close when the focus leaves the date picker (Tab past the calendar, or a click elsewhere).\n onBlur={(event) => {\n if (!event.currentTarget.contains(event.relatedTarget as Node | null)) onBlur();\n }}\n >\n <TextField\n {...inputProps}\n value={inputValue}\n ref={mergedRef}\n onFocus={onFocus}\n onBlur={handleInputBlur}\n maxLength={10}\n // The WAI-ARIA date picker combobox: a text input that opens a calendar dialog.\n role=\"combobox\"\n aria-haspopup=\"dialog\"\n aria-expanded={isTextFieldFocused}\n onValueChange={(value) => handleInputChange(value)}\n onKeyDown={(event) => {\n setCurrentKey(event.key);\n if (event.key === 'Escape') onBlur();\n }}\n // A typing error wins over the one the parent passes.\n error={inputError || others.error}\n />\n <Calendar\n selected={date ?? undefined}\n onClose={closeToInput}\n minDate={minDate}\n maxDate={maxDate}\n isOpen={isTextFieldFocused}\n year={currentDisplayedYear}\n month={currentDisplayedMonth}\n onMonthChange={handleMonthChange}\n handleDateSelection={handleDateSelection}\n disableSpecificDates={disableSpecificDates}\n locale={locale}\n weekStartsOn={weekStartsOn}\n labels={labels}\n />\n </div>\n );\n});\n\n/**\n * A text field with a calendar, to type or pick a date, with optional minimum and maximum dates. DatePicker.MonthGrid\n * chooses a range of whole months instead.\n */\nexport const DatePicker = Object.assign(DatePickerBase, { MonthGrid });\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,CAAC;AACU,MAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,EAAE,SAAS,EAAE;;"}
1
+ {"version":3,"file":"DatePicker.js","sources":["../../../../src/components/DatePicker/DatePicker.tsx"],"sourcesContent":["import * as React from 'react';\nimport { dateStringParser, formatDate, getSeparatorIndex, isDateValid, pickCalendarProps } from './utils';\n\nimport { Calendar, CalendarProps } from './components';\nimport type { CalendarLabels } from './components/Calendar/Calendar';\nimport { TextField, TextFieldProps } from '../TextField';\nimport { useControllableState, useMergeRefs } from '@/utils';\nimport { MonthGrid } from './components/MonthGrid';\nimport { DateSeparator, DateFormat, DatePickerInputError } from './utils/types';\n\nexport interface DatePickerProps\n extends\n Omit<CalendarProps, 'handleDateSelection' | 'year' | 'month' | 'selected' | 'isOpen' | 'onClose'>,\n Omit<TextFieldProps, 'onChange' | 'onValueChange' | 'defaultValue' | 'value' | 'onAbort' | 'ref'> {\n /** The separator used for the date input fields. Defaults to '-' */\n separator?: DateSeparator;\n /** The format used as input mask. Defaults to 'YYYY MM DD' */\n dateFormat?: DateFormat;\n /** Callback function that will be called when an error occurs when parsing the date */\n onInputError?(type: DatePickerInputError): string;\n /** Called with the new date, or `null` when the field is cleared. */\n onValueChange?(date: Date | null): void;\n /** Default value for uncontrolled input */\n defaultValue?: Date | null;\n /** Selected date, required with controlled input */\n value?: Date | null;\n /** The month to show, from 0 to 11. 0 is January, 1 is February ... 11 is December */\n month?: number;\n /** The year to show */\n year?: number;\n /** The text of the calendar, in English by default. */\n labels?: Partial<CalendarLabels>;\n}\n\nconst DatePickerBase = React.forwardRef<HTMLInputElement, DatePickerProps>(function DatePicker(props, ref) {\n const { calendarProps, others } = pickCalendarProps(props);\n const { labels, ...inputProps } = others as typeof others & { labels?: Partial<CalendarLabels> };\n\n const {\n month,\n year,\n onValueChange,\n onInputError,\n value: passedValue,\n disableSpecificDates,\n dateFormat,\n separator,\n minDate,\n maxDate,\n defaultValue,\n onMonthChange,\n locale,\n weekStartsOn,\n } = calendarProps;\n\n const calendarRef = React.useRef<HTMLDivElement>(null);\n const [isTextFieldFocused, setIsTextFieldFocused] = React.useState(false);\n const [inputError, setInputError] = React.useState<string | boolean>(false);\n const [currentKey, setCurrentKey] = React.useState('');\n // The calendar opens on the default date's month, if there is one.\n const [{ currentDisplayedMonth, currentDisplayedYear }, setCalendarDate] = React.useState({\n currentDisplayedMonth: defaultValue ? defaultValue.getMonth() : month,\n currentDisplayedYear: defaultValue ? defaultValue.getFullYear() : year,\n });\n\n const separatorIndex = getSeparatorIndex(dateFormat);\n\n const handleMonthChange = React.useCallback(\n (targetMonth: number, targetYear: number) => {\n setCalendarDate({ currentDisplayedMonth: targetMonth, currentDisplayedYear: targetYear });\n onMonthChange?.(targetMonth, targetYear);\n },\n [onMonthChange]\n );\n\n const [date, setDate] = useControllableState<Date | null>({\n value: passedValue,\n defaultValue: defaultValue ?? null,\n onChange: onValueChange,\n });\n\n const [inputValue, setInputValue] = React.useState(\n date instanceof Date ? formatDate(date, separator, dateFormat) : ''\n );\n\n const inputRef = React.useRef<HTMLInputElement>(null);\n const mergedRef = useMergeRefs([inputRef, ref]);\n // Set while the focus goes back to the input after closing, so that focus doesn't open the calendar again.\n const returningFocus = React.useRef(false);\n const onFocus = () => {\n if (returningFocus.current) returningFocus.current = false;\n else setIsTextFieldFocused(true);\n };\n const onBlur = () => setIsTextFieldFocused(false);\n // Escape closes the calendar, and the focus goes back to the input.\n const closeToInput = React.useCallback(() => {\n setIsTextFieldFocused(false);\n // Only when the focus really moves: focusing the focused input fires no focus event to clear the flag.\n if (inputRef.current && document.activeElement !== inputRef.current) {\n returningFocus.current = true;\n inputRef.current.focus();\n }\n }, []);\n\n const handleDateSelection = React.useCallback(\n (selectedDate: Date) => {\n setInputValue(formatDate(selectedDate, separator, dateFormat));\n setDate(selectedDate);\n setCalendarDate({\n currentDisplayedMonth: selectedDate.getMonth(),\n currentDisplayedYear: selectedDate.getFullYear(),\n });\n setInputError('');\n // Chosen: the calendar closes and the focus goes back to the input.\n window.setTimeout(closeToInput, 10);\n },\n [setDate, separator, dateFormat, closeToInput]\n );\n\n // A controlled date picker shows the new value whenever the parent changes it. Compared by time, since the parent\n // may pass a new Date object for the same day on every render.\n const controlledTime = passedValue === undefined ? undefined : (passedValue?.getTime() ?? null);\n React.useEffect(() => {\n if (controlledTime === undefined) return;\n setInputValue(controlledTime === null ? '' : formatDate(new Date(controlledTime), separator, dateFormat));\n }, [controlledTime, separator, dateFormat]);\n\n function handleInputChange(value: string) {\n const valueLength = value.length;\n\n if (currentKey !== 'Backspace' && (valueLength === separatorIndex.first || valueLength === separatorIndex.second)) {\n return setInputValue(value + separator);\n }\n\n if (valueLength === 0) {\n setDate(null);\n }\n\n setInputValue(value);\n\n if (valueLength === 10) {\n const dateValue = dateStringParser(value, dateFormat, separator);\n if (!dateValue) {\n return setInputError(onInputError?.('INVALID_DATE') ?? true);\n }\n setInputError('');\n\n if (isDateValid({ date: dateValue, minDate, maxDate })) {\n return handleDateSelection(dateValue);\n }\n return setInputError(onInputError?.('OUT_OF_RANGE') ?? true);\n }\n // Still typing: the error, if any, waits for the field to lose the focus.\n setInputError('');\n }\n\n const handleInputBlur = (event: React.FocusEvent<HTMLInputElement>) => {\n others.onBlur?.(event);\n if (inputValue.length > 0 && inputValue.length < 10) setInputError(onInputError?.('INVALID_DATE') ?? true);\n };\n\n return (\n <div\n className=\"roaster-date-picker\"\n ref={calendarRef}\n // Close when the focus leaves the date picker (Tab past the calendar, or a click elsewhere).\n onBlur={(event) => {\n if (!event.currentTarget.contains(event.relatedTarget as Node | null)) onBlur();\n }}\n >\n <TextField\n {...inputProps}\n value={inputValue}\n ref={mergedRef}\n onFocus={onFocus}\n onBlur={handleInputBlur}\n maxLength={10}\n // The WAI-ARIA date picker combobox: a text input that opens a calendar dialog.\n role=\"combobox\"\n aria-haspopup=\"dialog\"\n aria-expanded={isTextFieldFocused}\n onValueChange={(value) => handleInputChange(value)}\n onKeyDown={(event) => {\n setCurrentKey(event.key);\n if (event.key === 'Escape') onBlur();\n }}\n // A typing error wins over the one the parent passes.\n error={inputError || others.error}\n />\n <Calendar\n selected={date ?? undefined}\n onClose={closeToInput}\n minDate={minDate}\n maxDate={maxDate}\n isOpen={isTextFieldFocused}\n year={currentDisplayedYear}\n month={currentDisplayedMonth}\n onMonthChange={handleMonthChange}\n handleDateSelection={handleDateSelection}\n disableSpecificDates={disableSpecificDates}\n locale={locale}\n weekStartsOn={weekStartsOn}\n labels={labels}\n />\n </div>\n );\n});\n\n/**\n * A text field with a calendar, to type or pick a date, with optional minimum and maximum dates. DatePicker.MonthGrid\n * chooses a range of whole months instead.\n */\nexport const DatePicker = Object.assign(DatePickerBase, { MonthGrid });\n"],"names":[],"mappings":";;;;;;;;;;AAQA,MAAM,cAAc,GAAG,KAAK,CAAC,UAAU,CAAC,SAAS,WAAW,CAAC,KAAK,EAAE,GAAG,EAAE;AACzE,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,iBAAiB,CAAC,KAAK,CAAC;AAC5D,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,GAAG,MAAM;AAC1C,EAAE,MAAM;AACR,IAAI,KAAK;AACT,IAAI,IAAI;AACR,IAAI,aAAa;AACjB,IAAI,YAAY;AAChB,IAAI,KAAK,EAAE,WAAW;AACtB,IAAI,oBAAoB;AACxB,IAAI,UAAU;AACd,IAAI,SAAS;AACb,IAAI,OAAO;AACX,IAAI,OAAO;AACX,IAAI,YAAY;AAChB,IAAI,aAAa;AACjB,IAAI,MAAM;AACV,IAAI;AACJ,GAAG,GAAG,aAAa;AACnB,EAAE,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC;AACxC,EAAE,MAAM,CAAC,kBAAkB,EAAE,qBAAqB,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC;AAC3E,EAAE,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,KAAK,C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M,CAAC;AACxC;AACA,SAAS;AACT,wBAAwB,GAAG;AAC3B,UAAU,QAAQ;AAClB,UAAU;AACV,YAAY,QAAQ,EAAE,IAAI,IAAI,MAAM;AACpC,YAAY,OAAO,EAAE,YAAY;AACjC,YAAY,OAAO;AACnB,YAAY,OAAO;AACnB,YAAY,MAAM,EAAE,kBAAkB;AACtC,YAAY,IAAI,EAAE,oBAAoB;AACtC,YAAY,KAAK,EAAE,qBAAqB;AACxC,YAAY,aAAa,EAAE,iBAAiB;AAC5C,YAAY,mBAAmB;AAC/B,YAAY,oBAAoB;AAChC,YAAY,MAAM;AAClB,YAAY,YAAY;AACxB,YAAY;AACZ;AACA;AACA;AACA;AACA,GAAG;AACH,CAAC,CAAC;AACU,MAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,EAAE,SAAS,EAAE;;"}
@@ -1,8 +1,9 @@
1
1
  'use client';
2
2
  import { jsx } from 'react/jsx-runtime';
3
3
  import * as React from 'react';
4
- import { useMergeRefs, FloatingFocusManager } from '@floating-ui/react';
4
+ import { FloatingFocusManager } from '@floating-ui/react';
5
5
  import { useDropdownCardContext } from '../DropdownCard.context.js';
6
+ import { useMergeRefs } from '../../../utils/useMergeRefs/index.js';
6
7
  import { useMediaQuery, PHONE_QUERY } from '../../../utils/useMediaQuery/index.js';
7
8
  import { classNames } from '../../../utils/classNames/index.js';
8
9
 
@@ -1 +1 @@
1
- {"version":3,"file":"DropdownCardDropdown.js","sources":["../../../../../src/components/DropdownCard/components/DropdownCardDropdown.tsx"],"sourcesContent":["import * as React from 'react';\nimport { FloatingFocusManager, useMergeRefs } from '@floating-ui/react';\nimport { useDropdownCardContext } from '../DropdownCard.context';\nimport { PHONE_QUERY, classNames, useMediaQuery } from '@/utils';\n\n/** Every native `<div>` prop (`aria-label`, `className`, `style`...) is accepted and forwarded to the card. */\nexport interface DropdownCardDropdownProps extends React.ComponentPropsWithoutRef<'div'> {\n /**\n * `compact`: a row or two of fields in a menu's frame, such as a sort order. `tabs`: a list of tabs beside the\n * content, with DropdownCard.Tabs.\n */\n variant?: 'default' | 'compact' | 'tabs';\n /**\n * On a phone (480px wide at most), the card 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: a sheet suits a large card, such as\n * filters or a date; a small one (`compact`) stays beside its trigger.\n * @defaultValue false\n */\n sheet?: boolean;\n}\n\n/**\n * The card: its content and actions. Rendered while the dropdown card is open, after its trigger, so Tab goes from one\n * to the other; fixed, so a parent's overflow doesn't cut it.\n */\nexport const DropdownCardDropdown = React.forwardRef<HTMLDivElement, DropdownCardDropdownProps>(\n ({ className, style, children, variant = 'default', sheet = false, ...props }, propRef) => {\n const { context: floatingContext, ...context } = useDropdownCardContext();\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 if (!context.open) return null;\n\n return (\n <FloatingFocusManager context={floatingContext} modal={false}>\n <div\n ref={ref}\n {...context.getFloatingProps(props)}\n // After the spread, so a caller's className and style add to these instead of replacing them.\n className={classNames(\n 'roaster-dropdown-card',\n 'roaster-dropdown-card--floating',\n {\n 'roaster-dropdown-card--compact': variant === 'compact',\n 'roaster-dropdown-card--tabs': variant === 'tabs',\n 'roaster-dropdown-card--sheet': sheet,\n },\n className\n )}\n style={asSheet ? style : { ...context.floatingStyles, ...style }}\n >\n {children}\n </div>\n </FloatingFocusManager>\n );\n }\n);\n\nDropdownCardDropdown.displayName = 'DropdownCardDropdown';\n"],"names":[],"mappings":";;;;;;;;AAMY,MAAC,oBAAoB,GAAG,KAAK,CAAC,UAAU;AACpD,EAAE,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,GAAG,SAAS,EAAE,KAAK,GAAG,KAAK,EAAE,GAAG,KAAK,EAAE,EAAE,OAAO,KAAK;AAC7F,IAAI,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,OAAO,EAAE,GAAG,sBAAsB,EAAE;AAC7E,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,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,IAAI;AAClC,IAAI,uBAAuB,GAAG,CAAC,oBAAoB,EAAE,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,kBAAkB,GAAG;AAC5H,MAAM,KAAK;AACX,MAAM;AACN,QAAQ,GAAG;AACX,QAAQ,GAAG,OAAO,CAAC,gBAAgB,CAAC,KAAK,CAAC;AAC1C,QAAQ,SAAS,EAAE,UAAU;AAC7B,UAAU,uBAAuB;AACjC,UAAU,iCAAiC;AAC3C,UAAU;AACV,YAAY,gCAAgC,EAAE,OAAO,KAAK,SAAS;AACnE,YAAY,6BAA6B,EAAE,OAAO,KAAK,MAAM;AAC7D,YAAY,8BAA8B,EAAE;AAC5C,WAAW;AACX,UAAU;AACV,SAAS;AACT,QAAQ,KAAK,EAAE,OAAO,GAAG,KAAK,GAAG,EAAE,GAAG,OAAO,CAAC,cAAc,EAAE,GAAG,KAAK,EAAE;AACxE,QAAQ;AACR;AACA,KAAK,EAAE,CAAC;AACR,EAAE;AACF;AACA,oBAAoB,CAAC,WAAW,GAAG,sBAAsB;;"}
1
+ {"version":3,"file":"DropdownCardDropdown.js","sources":["../../../../../src/components/DropdownCard/components/DropdownCardDropdown.tsx"],"sourcesContent":["import * as React from 'react';\nimport { FloatingFocusManager } from '@floating-ui/react';\nimport { useDropdownCardContext } from '../DropdownCard.context';\nimport { PHONE_QUERY, classNames, useMediaQuery, useMergeRefs } from '@/utils';\n\n/** Every native `<div>` prop (`aria-label`, `className`, `style`...) is accepted and forwarded to the card. */\nexport interface DropdownCardDropdownProps extends React.ComponentPropsWithoutRef<'div'> {\n /**\n * `compact`: a row or two of fields in a menu's frame, such as a sort order. `tabs`: a list of tabs beside the\n * content, with DropdownCard.Tabs.\n */\n variant?: 'default' | 'compact' | 'tabs';\n /**\n * On a phone (480px wide at most), the card 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: a sheet suits a large card, such as\n * filters or a date; a small one (`compact`) stays beside its trigger.\n * @defaultValue false\n */\n sheet?: boolean;\n}\n\n/**\n * The card: its content and actions. Rendered while the dropdown card is open, after its trigger, so Tab goes from one\n * to the other; fixed, so a parent's overflow doesn't cut it.\n */\nexport const DropdownCardDropdown = React.forwardRef<HTMLDivElement, DropdownCardDropdownProps>(\n ({ className, style, children, variant = 'default', sheet = false, ...props }, propRef) => {\n const { context: floatingContext, ...context } = useDropdownCardContext();\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 if (!context.open) return null;\n\n return (\n <FloatingFocusManager context={floatingContext} modal={false}>\n <div\n ref={ref}\n {...context.getFloatingProps(props)}\n // After the spread, so a caller's className and style add to these instead of replacing them.\n className={classNames(\n 'roaster-dropdown-card',\n 'roaster-dropdown-card--floating',\n {\n 'roaster-dropdown-card--compact': variant === 'compact',\n 'roaster-dropdown-card--tabs': variant === 'tabs',\n 'roaster-dropdown-card--sheet': sheet,\n },\n className\n )}\n style={asSheet ? style : { ...context.floatingStyles, ...style }}\n >\n {children}\n </div>\n </FloatingFocusManager>\n );\n }\n);\n\nDropdownCardDropdown.displayName = 'DropdownCardDropdown';\n"],"names":[],"mappings":";;;;;;;;;AAMY,MAAC,oBAAoB,GAAG,KAAK,CAAC,UAAU;AACpD,EAAE,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,GAAG,SAAS,EAAE,KAAK,GAAG,KAAK,EAAE,GAAG,KAAK,EAAE,EAAE,OAAO,KAAK;AAC7F,IAAI,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,OAAO,EAAE,GAAG,sBAAsB,EAAE;AAC7E,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,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,IAAI;AAClC,IAAI,uBAAuB,GAAG,CAAC,oBAAoB,EAAE,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,kBAAkB,GAAG;AAC5H,MAAM,KAAK;AACX,MAAM;AACN,QAAQ,GAAG;AACX,QAAQ,GAAG,OAAO,CAAC,gBAAgB,CAAC,KAAK,CAAC;AAC1C,QAAQ,SAAS,EAAE,UAAU;AAC7B,UAAU,uBAAuB;AACjC,UAAU,iCAAiC;AAC3C,UAAU;AACV,YAAY,gCAAgC,EAAE,OAAO,KAAK,SAAS;AACnE,YAAY,6BAA6B,EAAE,OAAO,KAAK,MAAM;AAC7D,YAAY,8BAA8B,EAAE;AAC5C,WAAW;AACX,UAAU;AACV,SAAS;AACT,QAAQ,KAAK,EAAE,OAAO,GAAG,KAAK,GAAG,EAAE,GAAG,OAAO,CAAC,cAAc,EAAE,GAAG,KAAK,EAAE;AACxE,QAAQ;AACR;AACA,KAAK,EAAE,CAAC;AACR,EAAE;AACF;AACA,oBAAoB,CAAC,WAAW,GAAG,sBAAsB;;"}
@@ -4,19 +4,39 @@ import { classNames } from '../../utils/classNames/index.js';
4
4
 
5
5
  const hasContent = (node) => !(node == null || typeof node === "boolean" || node === "");
6
6
  const isInvalid = (error) => error != null && error !== false && error !== "";
7
- function fieldControlProps(controlId, { description, error }, ariaProps = {}) {
8
- const hasMessage = hasContent(error) || hasContent(description);
7
+ function messageIds(controlId, { description, error, keepDescription }) {
8
+ const showsError = hasContent(error);
9
+ const showsDescription = hasContent(description) && (!showsError || !!keepDescription);
10
+ return {
11
+ descriptionId: showsDescription ? `${controlId}-message` : void 0,
12
+ errorId: showsError ? `${controlId}-${showsDescription ? "error" : "message"}` : void 0
13
+ };
14
+ }
15
+ function fieldControlProps(controlId, messages, ariaProps = {}) {
16
+ const { descriptionId, errorId } = messageIds(controlId, messages);
9
17
  return {
10
18
  id: controlId,
11
- "aria-invalid": isInvalid(error) ? true : void 0,
12
- "aria-describedby": [ariaProps["aria-describedby"], hasMessage && `${controlId}-message`].filter(Boolean).join(" ") || void 0
19
+ "aria-invalid": isInvalid(messages.error) ? true : void 0,
20
+ "aria-describedby": [ariaProps["aria-describedby"], descriptionId, errorId].filter(Boolean).join(" ") || void 0
13
21
  };
14
22
  }
15
- function Field({ controlId, label, description, error, inline, className, style, children }) {
23
+ function Field({
24
+ controlId,
25
+ label,
26
+ description,
27
+ error,
28
+ keepDescription,
29
+ inline,
30
+ className,
31
+ style,
32
+ children
33
+ }) {
34
+ const { descriptionId, errorId } = messageIds(controlId, { description, error, keepDescription });
16
35
  return /* @__PURE__ */ jsxs("div", { className: classNames("roaster-field", { "roaster-field--inline": inline }, className), style, children: [
17
36
  hasContent(label) && /* @__PURE__ */ jsx("label", { className: "roaster-field__label", htmlFor: controlId, children: label }),
18
37
  children,
19
- hasContent(error) ? /* @__PURE__ */ jsx("small", { className: "roaster-field__error", id: `${controlId}-message`, children: error }) : hasContent(description) && /* @__PURE__ */ jsx("small", { className: "roaster-field__help", id: `${controlId}-message`, children: description })
38
+ descriptionId && /* @__PURE__ */ jsx("small", { className: "roaster-field__help", id: descriptionId, children: description }),
39
+ errorId && /* @__PURE__ */ jsx("small", { className: "roaster-field__error", id: errorId, children: error })
20
40
  ] });
21
41
  }
22
42
 
@@ -1 +1 @@
1
- {"version":3,"file":"Field.js","sources":["../../../../src/components/Field/Field.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames } from '@/utils';\n\n/** The props every form field shares: its label, help text and error. */\nexport interface FieldBaseProps {\n /** The label shown above the control. */\n label?: React.ReactNode;\n /** Help text shown under the control. */\n description?: React.ReactNode;\n /**\n * An error shown under the control, in place of the help text. It also marks the control as invalid; `true` marks it\n * invalid without a message.\n */\n error?: React.ReactNode;\n /** Classes added to the field's wrapper (the label, the control and the text under it). */\n className?: string;\n /** Styles added to the field's wrapper. */\n style?: React.CSSProperties;\n}\n\n/** A field whose control can sit on its label's row: TextField and Select. */\nexport interface InlineFieldProps {\n /** The label at the start of a row and the control at its end, at its own width, such as a setting in a menu. */\n inline?: boolean;\n}\n\nexport interface FieldProps extends FieldBaseProps, InlineFieldProps {\n /** The id of the control, which the label points at. */\n controlId: string;\n /** The control, with the props that tie it to the label and the text under it (`fieldControlProps`). */\n children: React.ReactNode;\n}\n\n/** Whether there is something to show: not nothing, not a boolean, not an empty string. */\nconst hasContent = (node: React.ReactNode) => !(node == null || typeof node === 'boolean' || node === '');\nconst isInvalid = (error: React.ReactNode) => error != null && error !== false && error !== '';\n\n/** The ARIA props a control may already have, which the field keeps. */\nexport interface ControlAriaProps {\n 'aria-describedby'?: string;\n}\n\n/**\n * The props that tie a control to its field: its id, `aria-invalid` when there is an error, and `aria-describedby`\n * pointing at the help text or error (after any the control already has). The label names it through `for`.\n */\nexport function fieldControlProps(\n controlId: string,\n { description, error }: Pick<FieldBaseProps, 'label' | 'description' | 'error'>,\n ariaProps: ControlAriaProps = {}\n) {\n const hasMessage = hasContent(error) || hasContent(description);\n return {\n id: controlId,\n 'aria-invalid': isInvalid(error) ? true : undefined,\n 'aria-describedby':\n [ariaProps['aria-describedby'], hasMessage && `${controlId}-message`].filter(Boolean).join(' ') || undefined,\n };\n}\n\n/**\n * The frame of a form field: the label, the control, and the help text or error under it. Each field renders one,\n * and passes `fieldControlProps` to its control.\n */\nexport function Field({ controlId, label, description, error, inline, className, style, children }: FieldProps) {\n return (\n <div className={classNames('roaster-field', { 'roaster-field--inline': inline }, className)} style={style}>\n {hasContent(label) && (\n <label className=\"roaster-field__label\" htmlFor={controlId}>\n {label}\n </label>\n )}\n {children}\n {hasContent(error) ? (\n <small className=\"roaster-field__error\" id={`${controlId}-message`}>\n {error}\n </small>\n ) : (\n hasContent(description) && (\n <small className=\"roaster-field__help\" id={`${controlId}-message`}>\n {description}\n </small>\n )\n )}\n </div>\n );\n}\n"],"names":[],"mappings":";;;;AAGA,MAAM,UAAU,GAAG,CAAC,IAAI,KAAK,EAAE,IAAI,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,EAAE,CAAC;AACxF,MAAM,SAAS,GAAG,CAAC,KAAK,KAAK,KAAK,IAAI,IAAI,IAAI,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,EAAE;AACtE,SAAS,iBAAiB,CAAC,SAAS,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,EAAE,SAAS,GAAG,EAAE,EAAE;AACrF,EAAE,MAAM,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,UAAU,CAAC,WAAW,CAAC;AACjE,EAAE,OAAO;AACT,IAAI,EAAE,EAAE,SAAS;AACjB,IAAI,cAAc,EAAE,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,MAAM;AACpD,IAAI,kBAAkB,EAAE,CAAC,SAAS,CAAC,kBAAkB,CAAC,EAAE,UAAU,IAAI,CAAC,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI;AAC3H,GAAG;AACH;AACO,SAAS,KAAK,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;AACpG,EAAE,uBAAuB,IAAI,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,UAAU,CAAC,eAAe,EAAE,EAAE,uBAAuB,EAAE,MAAM,EAAE,EAAE,SAAS,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE;AAChJ,IAAI,UAAU,CAAC,KAAK,CAAC,oBAAoB,GAAG,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,sBAAsB,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AACjI,IAAI,QAAQ;AACZ,IAAI,UAAU,CAAC,KAAK,CAAC,mBAAmB,GAAG,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,sBAAsB,EAAE,EAAE,EAAE,CAAC,EAAE,SAAS,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,GAAG,UAAU,CAAC,WAAW,CAAC,oBAAoB,GAAG,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,qBAAqB,EAAE,EAAE,EAAE,CAAC,EAAE,SAAS,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE;AAC1R,GAAG,EAAE,CAAC;AACN;;"}
1
+ {"version":3,"file":"Field.js","sources":["../../../../src/components/Field/Field.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames } from '@/utils';\n\n/** The props every form field shares: its label, help text and error. */\nexport interface FieldBaseProps {\n /** The label shown above the control. */\n label?: React.ReactNode;\n /** Help text shown under the control. */\n description?: React.ReactNode;\n /**\n * An error shown under the control, in place of the help text unless `keepDescription`. It also marks the control as\n * invalid; `true` marks it invalid without a message.\n */\n error?: React.ReactNode;\n /**\n * Keeps the help text when there is an error, which then shows under it: for help that stays useful while the value\n * is wrong, such as the format it needs. A count of the characters goes in a Textarea's `footer`.\n * @defaultValue false\n */\n keepDescription?: boolean;\n /** Classes added to the field's wrapper (the label, the control and the text under it). */\n className?: string;\n /** Styles added to the field's wrapper. */\n style?: React.CSSProperties;\n}\n\n/** A field whose control can sit on its label's row: TextField and Select. */\nexport interface InlineFieldProps {\n /** The label at the start of a row and the control at its end, at its own width, such as a setting in a menu. */\n inline?: boolean;\n}\n\nexport interface FieldProps extends FieldBaseProps, InlineFieldProps {\n /** The id of the control, which the label points at. */\n controlId: string;\n /** The control, with the props that tie it to the label and the text under it (`fieldControlProps`). */\n children: React.ReactNode;\n}\n\n/** Whether there is something to show: not nothing, not a boolean, not an empty string. */\nconst hasContent = (node: React.ReactNode) => !(node == null || typeof node === 'boolean' || node === '');\nconst isInvalid = (error: React.ReactNode) => error != null && error !== false && error !== '';\n\n/**\n * The ids of the texts under the control: the help text or the error, both with `keepDescription`. The one shown alone\n * is `<id>-message`; with both, the error is `<id>-error`.\n */\nfunction messageIds(\n controlId: string,\n { description, error, keepDescription }: Pick<FieldBaseProps, 'description' | 'error' | 'keepDescription'>\n) {\n const showsError = hasContent(error);\n const showsDescription = hasContent(description) && (!showsError || !!keepDescription);\n return {\n descriptionId: showsDescription ? `${controlId}-message` : undefined,\n errorId: showsError ? `${controlId}-${showsDescription ? 'error' : 'message'}` : undefined,\n };\n}\n\n/** The ARIA props a control may already have, which the field keeps. */\nexport interface ControlAriaProps {\n 'aria-describedby'?: string;\n}\n\n/**\n * The props that tie a control to its field: its id, `aria-invalid` when there is an error, and `aria-describedby`\n * pointing at the help text, the error, or both (after any the control already has). The label names it through `for`.\n */\nexport function fieldControlProps(\n controlId: string,\n messages: Pick<FieldBaseProps, 'label' | 'description' | 'error' | 'keepDescription'>,\n ariaProps: ControlAriaProps = {}\n) {\n const { descriptionId, errorId } = messageIds(controlId, messages);\n return {\n id: controlId,\n 'aria-invalid': isInvalid(messages.error) ? true : undefined,\n 'aria-describedby': [ariaProps['aria-describedby'], descriptionId, errorId].filter(Boolean).join(' ') || undefined,\n };\n}\n\n/**\n * The frame of a form field: the label, the control, and the help text or error under it, or both. Each field renders\n * one, and passes `fieldControlProps` to its control.\n */\nexport function Field({\n controlId,\n label,\n description,\n error,\n keepDescription,\n inline,\n className,\n style,\n children,\n}: FieldProps) {\n const { descriptionId, errorId } = messageIds(controlId, { description, error, keepDescription });\n return (\n <div className={classNames('roaster-field', { 'roaster-field--inline': inline }, className)} style={style}>\n {hasContent(label) && (\n <label className=\"roaster-field__label\" htmlFor={controlId}>\n {label}\n </label>\n )}\n {children}\n {descriptionId && (\n <small className=\"roaster-field__help\" id={descriptionId}>\n {description}\n </small>\n )}\n {errorId && (\n <small className=\"roaster-field__error\" id={errorId}>\n {error}\n </small>\n )}\n </div>\n );\n}\n"],"names":[],"mappings":";;;;AAGA,MAAM,UAAU,GAAG,CAAC,IAAI,KAAK,EAAE,IAAI,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,EAAE,CAAC;AACxF,MAAM,SAAS,GAAG,CAAC,KAAK,KAAK,KAAK,IAAI,IAAI,IAAI,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,EAAE;AAC7E,SAAS,UAAU,CAAC,SAAS,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,eAAe,EAAE,EAAE;AACxE,EAAE,MAAM,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC;AACtC,EAAE,MAAM,gBAAgB,GAAG,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,UAAU,IAAI,CAAC,CAAC,eAAe,CAAC;AACxF,EAAE,OAAO;AACT,IAAI,aAAa,EAAE,gBAAgB,GAAG,CAAC,EAAE,SAAS,CAAC,QAAQ,CAAC,GAAG,MAAM;AACrE,IAAI,OAAO,EAAE,UAAU,GAAG,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,gBAAgB,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC,GAAG;AACrF,GAAG;AACH;AACO,SAAS,iBAAiB,CAAC,SAAS,EAAE,QAAQ,EAAE,SAAS,GAAG,EAAE,EAAE;AACvE,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC,SAAS,EAAE,QAAQ,CAAC;AACpE,EAAE,OAAO;AACT,IAAI,EAAE,EAAE,SAAS;AACjB,IAAI,cAA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