@korzun/design 0.0.4 → 0.0.6

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 (199) hide show
  1. package/AGENTS.md +3 -0
  2. package/dist/component/card/index.d.ts +13 -2
  3. package/dist/component/card/index.d.ts.map +1 -1
  4. package/dist/component/card/index.js +1 -0
  5. package/dist/component/card/index.js.map +1 -1
  6. package/dist/component/card/style.d.ts.map +1 -1
  7. package/dist/component/card/style.js +3 -1
  8. package/dist/component/card/style.js.map +1 -1
  9. package/dist/component/card-divider/index.d.ts +15 -0
  10. package/dist/component/card-divider/index.d.ts.map +1 -1
  11. package/dist/component/card-divider/index.js +4 -0
  12. package/dist/component/card-divider/index.js.map +1 -1
  13. package/dist/component/card-row/index.d.ts +5 -0
  14. package/dist/component/card-row/index.d.ts.map +1 -1
  15. package/dist/component/card-row/index.js +1 -0
  16. package/dist/component/card-row/index.js.map +1 -1
  17. package/dist/component/card-row/style.js +1 -1
  18. package/dist/component/card-row/style.js.map +1 -1
  19. package/dist/component/collapsible-section/index.d.ts +8 -3
  20. package/dist/component/collapsible-section/index.d.ts.map +1 -1
  21. package/dist/component/collapsible-section/index.js +1 -0
  22. package/dist/component/collapsible-section/index.js.map +1 -1
  23. package/dist/component/empty-state/index.d.ts +2 -2
  24. package/dist/component/empty-state/index.d.ts.map +1 -1
  25. package/dist/component/empty-state/index.js.map +1 -1
  26. package/dist/component/index.d.ts +10 -10
  27. package/dist/component/index.d.ts.map +1 -1
  28. package/dist/component/index.js.map +1 -1
  29. package/dist/component/meta-line/index.d.ts +1 -1
  30. package/dist/component/meta-line/index.d.ts.map +1 -1
  31. package/dist/component/meta-line/index.js.map +1 -1
  32. package/dist/component/metadata/index.d.ts +2 -0
  33. package/dist/component/metadata/index.d.ts.map +1 -1
  34. package/dist/component/metadata/index.js +1 -0
  35. package/dist/component/metadata/index.js.map +1 -1
  36. package/dist/component/metadata-list/index.d.ts +6 -2
  37. package/dist/component/metadata-list/index.d.ts.map +1 -1
  38. package/dist/component/metadata-list/index.js +1 -0
  39. package/dist/component/metadata-list/index.js.map +1 -1
  40. package/dist/component/nav-desktop/index.d.ts +6 -0
  41. package/dist/component/nav-desktop/index.d.ts.map +1 -1
  42. package/dist/component/nav-desktop/index.js +5 -2
  43. package/dist/component/nav-desktop/index.js.map +1 -1
  44. package/dist/component/nav-mobile/index.d.ts +11 -3
  45. package/dist/component/nav-mobile/index.d.ts.map +1 -1
  46. package/dist/component/nav-mobile/index.js +5 -0
  47. package/dist/component/nav-mobile/index.js.map +1 -1
  48. package/dist/component/nav-types.d.ts +4 -0
  49. package/dist/component/nav-types.d.ts.map +1 -1
  50. package/dist/component/nav-types.js.map +1 -1
  51. package/dist/component/page/index.d.ts +10 -2
  52. package/dist/component/page/index.d.ts.map +1 -1
  53. package/dist/component/page/index.js +1 -0
  54. package/dist/component/page/index.js.map +1 -1
  55. package/dist/component/progress-indicator/index.d.ts +4 -2
  56. package/dist/component/progress-indicator/index.d.ts.map +1 -1
  57. package/dist/component/progress-indicator/index.js +1 -0
  58. package/dist/component/progress-indicator/index.js.map +1 -1
  59. package/dist/component/tag/index.d.ts +6 -3
  60. package/dist/component/tag/index.d.ts.map +1 -1
  61. package/dist/component/tag/index.js +1 -0
  62. package/dist/component/tag/index.js.map +1 -1
  63. package/dist/component/theme-setting/index.d.ts +6 -0
  64. package/dist/component/theme-setting/index.d.ts.map +1 -1
  65. package/dist/component/theme-setting/index.js +4 -0
  66. package/dist/component/theme-setting/index.js.map +1 -1
  67. package/dist/component/top-fade/index.d.ts +7 -0
  68. package/dist/component/top-fade/index.d.ts.map +1 -1
  69. package/dist/component/top-fade/index.js +5 -2
  70. package/dist/component/top-fade/index.js.map +1 -1
  71. package/dist/control/action-menu-list/index.d.ts +7 -0
  72. package/dist/control/action-menu-list/index.d.ts.map +1 -1
  73. package/dist/control/action-menu-list/index.js.map +1 -1
  74. package/dist/control/back-button/index.d.ts +9 -2
  75. package/dist/control/back-button/index.d.ts.map +1 -1
  76. package/dist/control/back-button/index.js +4 -0
  77. package/dist/control/back-button/index.js.map +1 -1
  78. package/dist/control/button/index.d.ts +30 -1
  79. package/dist/control/button/index.d.ts.map +1 -1
  80. package/dist/control/button/index.js +4 -0
  81. package/dist/control/button/index.js.map +1 -1
  82. package/dist/control/chips-input/index.d.ts +20 -0
  83. package/dist/control/chips-input/index.d.ts.map +1 -1
  84. package/dist/control/chips-input/index.js +4 -0
  85. package/dist/control/chips-input/index.js.map +1 -1
  86. package/dist/control/confirm-modal/index.d.ts +15 -2
  87. package/dist/control/confirm-modal/index.d.ts.map +1 -1
  88. package/dist/control/confirm-modal/index.js +4 -0
  89. package/dist/control/confirm-modal/index.js.map +1 -1
  90. package/dist/control/date-time-input/index.d.ts +4 -0
  91. package/dist/control/date-time-input/index.d.ts.map +1 -1
  92. package/dist/control/date-time-input/index.js.map +1 -1
  93. package/dist/control/field-list/index.d.ts +20 -2
  94. package/dist/control/field-list/index.d.ts.map +1 -1
  95. package/dist/control/field-list/index.js +4 -0
  96. package/dist/control/field-list/index.js.map +1 -1
  97. package/dist/control/index.d.ts +16 -21
  98. package/dist/control/index.d.ts.map +1 -1
  99. package/dist/control/index.js +5 -5
  100. package/dist/control/index.js.map +1 -1
  101. package/dist/control/number-input/index.d.ts +12 -0
  102. package/dist/control/number-input/index.d.ts.map +1 -1
  103. package/dist/control/number-input/index.js +4 -0
  104. package/dist/control/number-input/index.js.map +1 -1
  105. package/dist/control/page-actions-bar/index.d.ts +11 -3
  106. package/dist/control/page-actions-bar/index.d.ts.map +1 -1
  107. package/dist/control/page-actions-bar/index.js +5 -1
  108. package/dist/control/page-actions-bar/index.js.map +1 -1
  109. package/dist/control/page-actions-menu/index.d.ts +6 -1
  110. package/dist/control/page-actions-menu/index.d.ts.map +1 -1
  111. package/dist/control/page-actions-menu/index.js +4 -0
  112. package/dist/control/page-actions-menu/index.js.map +1 -1
  113. package/dist/control/page-footer-actions/index.d.ts +16 -2
  114. package/dist/control/page-footer-actions/index.d.ts.map +1 -1
  115. package/dist/control/page-footer-actions/index.js +4 -0
  116. package/dist/control/page-footer-actions/index.js.map +1 -1
  117. package/dist/control/popover/index.d.ts +6 -3
  118. package/dist/control/popover/index.d.ts.map +1 -1
  119. package/dist/control/popover/index.js +2 -0
  120. package/dist/control/popover/index.js.map +1 -1
  121. package/dist/control/segmented-control/index.d.ts +10 -3
  122. package/dist/control/segmented-control/index.d.ts.map +1 -1
  123. package/dist/control/segmented-control/index.js.map +1 -1
  124. package/dist/control/select/index.d.ts +17 -0
  125. package/dist/control/select/index.d.ts.map +1 -1
  126. package/dist/control/select/index.js +4 -0
  127. package/dist/control/select/index.js.map +1 -1
  128. package/dist/control/switch/index.d.ts +16 -2
  129. package/dist/control/switch/index.d.ts.map +1 -1
  130. package/dist/control/switch/index.js +4 -0
  131. package/dist/control/switch/index.js.map +1 -1
  132. package/dist/control/switch/style.d.ts.map +1 -1
  133. package/dist/control/switch/style.js +1 -3
  134. package/dist/control/switch/style.js.map +1 -1
  135. package/dist/control/text-area/index.d.ts +15 -0
  136. package/dist/control/text-area/index.d.ts.map +1 -1
  137. package/dist/control/text-area/index.js +4 -0
  138. package/dist/control/text-area/index.js.map +1 -1
  139. package/dist/control/text-input/index.d.ts +23 -1
  140. package/dist/control/text-input/index.d.ts.map +1 -1
  141. package/dist/control/text-input/index.js +4 -0
  142. package/dist/control/text-input/index.js.map +1 -1
  143. package/dist/control/use-modal-dialog/index.d.ts +7 -1
  144. package/dist/control/use-modal-dialog/index.d.ts.map +1 -1
  145. package/dist/control/use-modal-dialog/index.js +5 -0
  146. package/dist/control/use-modal-dialog/index.js.map +1 -1
  147. package/dist/theme/theme.d.ts +2 -0
  148. package/dist/theme/theme.d.ts.map +1 -1
  149. package/dist/theme/theme.js +5 -0
  150. package/dist/theme/theme.js.map +1 -1
  151. package/docs/component/card-row.md +11 -12
  152. package/docs/component/card.md +4 -5
  153. package/docs/control/confirm-modal.md +1 -2
  154. package/docs/control/segmented-control.md +2 -2
  155. package/docs/corners.md +4 -4
  156. package/docs/philosophy.md +1 -1
  157. package/docs/theme.md +1 -0
  158. package/docs/tokens.md +1 -0
  159. package/package.json +1 -1
  160. package/src/component/card/index.tsx +14 -2
  161. package/src/component/card/style.ts +3 -1
  162. package/src/component/card-divider/index.tsx +15 -6
  163. package/src/component/card-row/index.tsx +6 -0
  164. package/src/component/card-row/style.ts +1 -1
  165. package/src/component/collapsible-section/index.tsx +8 -2
  166. package/src/component/empty-state/index.tsx +2 -2
  167. package/src/component/index.ts +10 -10
  168. package/src/component/meta-line/index.tsx +1 -1
  169. package/src/component/metadata/index.tsx +6 -1
  170. package/src/component/metadata-list/index.tsx +13 -2
  171. package/src/component/nav-desktop/index.tsx +6 -2
  172. package/src/component/nav-mobile/index.tsx +11 -3
  173. package/src/component/nav-types.ts +4 -0
  174. package/src/component/page/index.tsx +11 -1
  175. package/src/component/progress-indicator/index.tsx +4 -1
  176. package/src/component/tag/index.tsx +6 -3
  177. package/src/component/theme-setting/index.tsx +7 -0
  178. package/src/component/top-fade/index.tsx +8 -2
  179. package/src/control/action-menu-list/index.tsx +7 -0
  180. package/src/control/back-button/index.tsx +9 -1
  181. package/src/control/button/index.tsx +39 -5
  182. package/src/control/chips-input/index.tsx +20 -3
  183. package/src/control/confirm-modal/index.tsx +15 -1
  184. package/src/control/date-time-input/index.tsx +4 -0
  185. package/src/control/field-list/index.tsx +20 -1
  186. package/src/control/index.ts +39 -22
  187. package/src/control/number-input/index.tsx +12 -0
  188. package/src/control/page-actions-bar/index.tsx +16 -2
  189. package/src/control/page-actions-menu/index.tsx +6 -1
  190. package/src/control/page-footer-actions/index.tsx +16 -1
  191. package/src/control/popover/index.tsx +6 -2
  192. package/src/control/segmented-control/index.tsx +10 -3
  193. package/src/control/select/index.tsx +17 -1
  194. package/src/control/switch/index.tsx +17 -1
  195. package/src/control/switch/style.ts +1 -3
  196. package/src/control/text-area/index.tsx +15 -0
  197. package/src/control/text-input/index.tsx +25 -0
  198. package/src/control/use-modal-dialog/index.ts +11 -2
  199. package/src/theme/theme.ts +7 -0
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/control/select/index.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjF,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAsCtC,SAAS,SAAS,CAAC,MAAoB;IACrC,OAAO,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;AAChF,CAAC;AAED,SAAS,SAAS,CAAC,IAAY,EAAE,KAAa,EAAE,SAAiB;IAC/D,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IACxB,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;IAC5D,IAAI,GAAG,KAAK,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IAC5B,OAAO,CACL,8BACG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EACnB,eAAM,SAAS,EAAE,SAAS,YAAG,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,GAAQ,EACvE,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,IAC9B,CACJ,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,MAAM,GAAG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AAS,CAAC,CAAC,CAAC,aAAa,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAuBtD,CACN,CAAC,CACH,GACE,GACD,GACE,IACN,IACF,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import cx from 'classnames';\nimport { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react';\n\nimport { ChevronIcon, SpinnerIcon } from '../../icon/index.js';\nimport { Popover } from '../popover/index.js';\nimport { useStyle } from './style.js';\n\nexport type SelectOption = string | { label: string; value: string; description?: string };\n\ntype InternalOption = { label: string; value: string; description?: string; _isCreate?: boolean };\n\nexport type SelectProps = {\n allowCreate?: boolean;\n // Show the inline \"clear\" (✕) control when a value is selected (default true).\n clearable?: boolean;\n disabled?: boolean;\n label?: string;\n layout?: 'horizontal' | 'vertical' | 'inline';\n loading?: boolean;\n name: string;\n onChange?: (value: string | undefined) => void;\n options: SelectOption[];\n placeholder?: string;\n /**\n * Which surface this select sits on, which decides its corner radius AND its\n * elevation together — they are one decision, not two.\n *\n * `'card'` (default) is the control as it has always looked: `radius.md`, no\n * shadow, because the card around it already provides both.\n *\n * `'page'` matches `theme.recipe.card.shell` — `radius.lg` plus\n * `shadow.cardStack` — so a select sitting directly on the page reads as its\n * own raised surface alongside the cards it shares that page with, instead of\n * a flat control missing the elevation everything around it has.\n *\n * Named for the surface rather than for `radius` (as `Button`'s own prop is),\n * because here the radius is a consequence, not the choice.\n */\n surface?: 'card' | 'page';\n searchable?: boolean;\n value: string | undefined;\n};\n\nfunction normalise(option: SelectOption): InternalOption {\n return typeof option === 'string' ? { label: option, value: option } : option;\n}\n\nfunction highlight(text: string, query: string, className: string): React.ReactNode {\n if (!query) return text;\n const idx = text.toLowerCase().indexOf(query.toLowerCase());\n if (idx === -1) return text;\n return (\n <>\n {text.slice(0, idx)}\n <span className={className}>{text.slice(idx, idx + query.length)}</span>\n {text.slice(idx + query.length)}\n </>\n );\n}\n\nexport const Select = ({\n allowCreate = false,\n clearable = true,\n disabled = false,\n label,\n layout = 'horizontal',\n loading = false,\n name,\n onChange = () => {},\n options,\n placeholder = 'Select…',\n surface = 'card',\n searchable = true,\n value,\n}: SelectProps) => {\n const style = useStyle();\n // Per-instance DOM id so label/input association stays unique when two forms\n // sharing a `name` mount at once (e.g. the device create + edit forms).\n const inputId = useId();\n const [isOpen, setIsOpen] = useState(false);\n const [query, setQuery] = useState('');\n const [highlightedIndex, setHighlightedIndex] = useState(0);\n const triggerWrapperRef = useRef<HTMLDivElement>(null);\n const inputRef = useRef<HTMLInputElement>(null);\n\n const normalisedOptions = useMemo(() => options.map(normalise), [options]);\n const filteredOptions = useMemo<InternalOption[]>(\n () => normalisedOptions.filter((o) => o.label.toLowerCase().includes(query.toLowerCase())),\n [normalisedOptions, query]\n );\n\n const createEntry = useMemo<InternalOption | null>(() => {\n if (!allowCreate || !query.trim()) return null;\n const trimmed = query.trim();\n const exactMatch = normalisedOptions.some(\n (o) => o.label.toLowerCase() === trimmed.toLowerCase()\n );\n if (exactMatch) return null;\n return { label: trimmed, value: trimmed, _isCreate: true };\n }, [allowCreate, query, normalisedOptions]);\n\n const visibleOptions = useMemo<InternalOption[]>(\n () => (createEntry ? [...filteredOptions, createEntry] : filteredOptions),\n [filteredOptions, createEntry]\n );\n\n const selectedLabel = normalisedOptions.find((o) => o.value === value)?.label ?? value;\n\n const open = useCallback(() => {\n if (disabled || loading) return;\n setIsOpen(true);\n setHighlightedIndex(0);\n }, [disabled, loading]);\n\n const close = useCallback(() => {\n setIsOpen(false);\n setQuery('');\n setHighlightedIndex(0);\n }, []);\n\n const select = useCallback(\n (optValue: string) => {\n onChange(optValue);\n close();\n },\n [onChange, close]\n );\n\n const clear = useCallback(() => {\n onChange(undefined);\n }, [onChange]);\n\n useEffect(() => {\n if (isOpen && searchable) {\n inputRef.current?.focus();\n }\n }, [isOpen, searchable]);\n\n const handleTriggerKeyDown = useCallback(\n (e: React.KeyboardEvent) => {\n if (e.key === 'ArrowDown' || e.key === 'Enter' || e.key === ' ') {\n e.preventDefault();\n open();\n }\n },\n [open]\n );\n\n const handleOpenTriggerKeyDown = useCallback(\n (e: React.KeyboardEvent) => {\n if (e.key === 'ArrowDown') {\n e.preventDefault();\n setHighlightedIndex((i) =>\n visibleOptions.length === 0 ? 0 : (i + 1) % visibleOptions.length\n );\n } else if (e.key === 'ArrowUp') {\n e.preventDefault();\n setHighlightedIndex((i) =>\n visibleOptions.length === 0 ? 0 : (i - 1 + visibleOptions.length) % visibleOptions.length\n );\n } else if (e.key === 'Enter' || e.key === ' ') {\n e.preventDefault();\n const opt = visibleOptions[highlightedIndex];\n if (opt) select(opt.value);\n } else if (e.key === 'Escape') {\n e.preventDefault();\n close();\n } else if (e.key === 'Tab') {\n close();\n }\n },\n [visibleOptions, highlightedIndex, select, close]\n );\n\n const handleInputKeyDown = useCallback(\n (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (e.key === 'ArrowDown') {\n e.preventDefault();\n setHighlightedIndex((i) =>\n visibleOptions.length === 0 ? 0 : (i + 1) % visibleOptions.length\n );\n } else if (e.key === 'ArrowUp') {\n e.preventDefault();\n setHighlightedIndex((i) =>\n visibleOptions.length === 0 ? 0 : (i - 1 + visibleOptions.length) % visibleOptions.length\n );\n } else if (e.key === 'Enter') {\n e.preventDefault();\n const opt = visibleOptions[highlightedIndex];\n if (opt) select(opt.value);\n } else if (e.key === 'Escape') {\n e.preventDefault();\n close();\n } else if (e.key === 'Tab') {\n close();\n }\n },\n [visibleOptions, highlightedIndex, select, close]\n );\n\n return (\n <div className={cx(style.root, style[layout], style[surface])}>\n {label && (\n <label className={style.label} htmlFor={inputId}>\n {label}\n </label>\n )}\n <div ref={triggerWrapperRef} className={style.triggerWrapper}>\n {isOpen && searchable ? (\n <div className={cx(style.trigger, style[surface])}>\n <input\n ref={inputRef}\n id={inputId}\n name={name}\n autoComplete=\"off\"\n className={style.searchInput}\n aria-label=\"Search\"\n placeholder=\"Type to search…\"\n value={query}\n onChange={(e) => {\n setQuery(e.target.value);\n setHighlightedIndex(0);\n }}\n onKeyDown={handleInputKeyDown}\n />\n <span\n className={cx(style.chevron, style.open)}\n role=\"button\"\n tabIndex={-1}\n aria-label=\"Close\"\n onMouseDown={(e) => e.preventDefault()}\n onClick={close}\n >\n <ChevronIcon height={12} width={12} />\n </span>\n </div>\n ) : (\n <div\n className={cx(style.trigger, style[surface], {\n [style.loading]: loading,\n [style.disabled]: disabled,\n [style.open]: isOpen,\n })}\n role=\"button\"\n tabIndex={disabled || loading ? -1 : 0}\n aria-label={selectedLabel ?? placeholder}\n onClick={isOpen ? close : open}\n onKeyDown={isOpen ? handleOpenTriggerKeyDown : handleTriggerKeyDown}\n >\n {loading && <SpinnerIcon className={style.spinner} />}\n <span className={cx(style.triggerText, { [style.placeholder]: !selectedLabel })}>\n {loading ? 'Loading…' : (selectedLabel ?? placeholder)}\n </span>\n {value && clearable && !disabled && !loading && (\n <span\n className={style.clearButton}\n role=\"button\"\n tabIndex={0}\n aria-label=\"Clear\"\n onClick={(e) => {\n e.stopPropagation();\n clear();\n }}\n onKeyDown={(e) => {\n if (e.key === 'Enter' || e.key === ' ') {\n e.preventDefault();\n e.stopPropagation();\n clear();\n }\n }}\n >\n ✕\n </span>\n )}\n <span className={style.chevron}>\n <ChevronIcon height={12} width={12} />\n </span>\n </div>\n )}\n <Popover anchorRef={triggerWrapperRef} open={isOpen} onClose={close}>\n <div className={style.dropdown}>\n <ul className={style.optionList} role=\"listbox\">\n {visibleOptions.length === 0 ? (\n <li\n className={cx(style.option, style.emptyOption)}\n role=\"option\"\n aria-selected={false}\n >\n No results\n </li>\n ) : (\n visibleOptions.map((opt, index) => (\n <li\n key={opt._isCreate ? `__create__${opt.value}` : opt.value}\n className={cx(style.option, {\n [style.highlighted]: index === highlightedIndex,\n [style.selected]: !opt._isCreate && opt.value === value,\n [style.createOption]: opt._isCreate,\n })}\n role=\"option\"\n aria-selected={!opt._isCreate && opt.value === value}\n onMouseDown={(e) => e.preventDefault()}\n onClick={() => select(opt.value)}\n >\n {opt._isCreate ? (\n <>\n Add: <strong>{opt.label}</strong>\n </>\n ) : (\n <>\n <div>{highlight(opt.label, query, style.matchHighlight)}</div>\n {opt.description && (\n <div className={style.optionDescription}>{opt.description}</div>\n )}\n </>\n )}\n </li>\n ))\n )}\n </ul>\n </div>\n </Popover>\n </div>\n </div>\n );\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/control/select/index.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjF,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAkDtC,SAAS,SAAS,CAAC,MAAoB;IACrC,OAAO,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;AAChF,CAAC;AAED,SAAS,SAAS,CAAC,IAAY,EAAE,KAAa,EAAE,SAAiB;IAC/D,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IACxB,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;IAC5D,IAAI,GAAG,KAAK,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IAC5B,OAAO,CACL,8BACG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EACnB,eAAM,SAAS,EAAE,SAAS,YAAG,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,GAAG,KA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KAAK,CAAC,cAAc,CAAC,GAAO,EAC7D,GAAG,CAAC,WAAW,IAAI,CAClB,cAAK,SAAS,EAAE,KAAK,CAAC,iBAAiB,YAAG,GAAG,CAAC,WAAW,GAAO,CACjE,IACA,CACJ,IAtBI,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,aAAa,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAuBtD,CACN,CAAC,CACH,GACE,GACD,GACE,IACN,IACF,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import cx from 'classnames';\nimport { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react';\n\nimport { ChevronIcon, SpinnerIcon } from '../../icon/index.js';\nimport { Popover } from '../popover/index.js';\nimport { useStyle } from './style.js';\n\n/** A `Select` option: a plain string (label and value alike), or `{ label, value, description? }`. */\nexport type SelectOption = string | { label: string; value: string; description?: string };\n\ntype InternalOption = { label: string; value: string; description?: string; _isCreate?: boolean };\n\nexport type SelectProps = {\n /** With a search query that matches no label exactly, offers an \"Add: *query*\" option. */\n allowCreate?: boolean;\n /** Show the inline \"clear\" (✕) control when a value is selected (default true). */\n clearable?: boolean;\n /** Faded; can't open; no clear button. */\n disabled?: boolean;\n /** Visible label; it targets the search box, not the closed trigger. */\n label?: string;\n /** Default `'horizontal'`; `horizontal`/`vertical` paint a card-header row. */\n layout?: 'horizontal' | 'vertical' | 'inline';\n /** Shows a spinner and \"Loading…\"; can't open. */\n loading?: boolean;\n /** Only lands on the search box while open: form data never carries the selection. */\n name: string;\n /** Receives the option's `value`, `undefined` from clear, or the trimmed typed text from \"Add:\"; not an event. */\n onChange?: (value: string | undefined) => void;\n /** Strings or `{ label, value, description? }` objects, mixed freely. */\n options: SelectOption[];\n /** Shown when nothing is selected. Default `'Select…'`. */\n placeholder?: string;\n /**\n * Which surface this select sits on, which decides its corner radius AND its\n * elevation together — they are one decision, not two.\n *\n * `'card'` (default) is the control as it has always looked: `radius.md`, no\n * shadow, because the card around it already provides both.\n *\n * `'page'` matches `theme.recipe.card.shell` — `radius.lg` plus\n * `shadow.cardStack` — so a select sitting directly on the page reads as its\n * own raised surface alongside the cards it shares that page with, instead of\n * a flat control missing the elevation everything around it has.\n *\n * Named for the surface rather than for `radius` (as `Button`'s own prop is),\n * because here the radius is a consequence, not the choice.\n */\n surface?: 'card' | 'page';\n /** Opening swaps the trigger for a search box (default `true`); `false` is a plain list, arrow keys only. */\n searchable?: boolean;\n /** Controlled selection; a value not in `options` displays as the raw string. */\n value: string | undefined;\n};\n\nfunction normalise(option: SelectOption): InternalOption {\n return typeof option === 'string' ? { label: option, value: option } : option;\n}\n\nfunction highlight(text: string, query: string, className: string): React.ReactNode {\n if (!query) return text;\n const idx = text.toLowerCase().indexOf(query.toLowerCase());\n if (idx === -1) return text;\n return (\n <>\n {text.slice(0, idx)}\n <span className={className}>{text.slice(idx, idx + query.length)}</span>\n {text.slice(idx + query.length)}\n </>\n );\n}\n\n/**\n * Controlled single-value picker with an optional search box and \"Add:\" entry,\n * its list in a `Popover`. No hidden input: submit `value` from state.\n */\nexport const Select = ({\n allowCreate = false,\n clearable = true,\n disabled = false,\n label,\n layout = 'horizontal',\n loading = false,\n name,\n onChange = () => {},\n options,\n placeholder = 'Select…',\n surface = 'card',\n searchable = true,\n value,\n}: SelectProps) => {\n const style = useStyle();\n // Per-instance DOM id so label/input association stays unique when two forms\n // sharing a `name` mount at once (e.g. the device create + edit forms).\n const inputId = useId();\n const [isOpen, setIsOpen] = useState(false);\n const [query, setQuery] = useState('');\n const [highlightedIndex, setHighlightedIndex] = useState(0);\n const triggerWrapperRef = useRef<HTMLDivElement>(null);\n const inputRef = useRef<HTMLInputElement>(null);\n\n const normalisedOptions = useMemo(() => options.map(normalise), [options]);\n const filteredOptions = useMemo<InternalOption[]>(\n () => normalisedOptions.filter((o) => o.label.toLowerCase().includes(query.toLowerCase())),\n [normalisedOptions, query]\n );\n\n const createEntry = useMemo<InternalOption | null>(() => {\n if (!allowCreate || !query.trim()) return null;\n const trimmed = query.trim();\n const exactMatch = normalisedOptions.some(\n (o) => o.label.toLowerCase() === trimmed.toLowerCase()\n );\n if (exactMatch) return null;\n return { label: trimmed, value: trimmed, _isCreate: true };\n }, [allowCreate, query, normalisedOptions]);\n\n const visibleOptions = useMemo<InternalOption[]>(\n () => (createEntry ? [...filteredOptions, createEntry] : filteredOptions),\n [filteredOptions, createEntry]\n );\n\n const selectedLabel = normalisedOptions.find((o) => o.value === value)?.label ?? value;\n\n const open = useCallback(() => {\n if (disabled || loading) return;\n setIsOpen(true);\n setHighlightedIndex(0);\n }, [disabled, loading]);\n\n const close = useCallback(() => {\n setIsOpen(false);\n setQuery('');\n setHighlightedIndex(0);\n }, []);\n\n const select = useCallback(\n (optValue: string) => {\n onChange(optValue);\n close();\n },\n [onChange, close]\n );\n\n const clear = useCallback(() => {\n onChange(undefined);\n }, [onChange]);\n\n useEffect(() => {\n if (isOpen && searchable) {\n inputRef.current?.focus();\n }\n }, [isOpen, searchable]);\n\n const handleTriggerKeyDown = useCallback(\n (e: React.KeyboardEvent) => {\n if (e.key === 'ArrowDown' || e.key === 'Enter' || e.key === ' ') {\n e.preventDefault();\n open();\n }\n },\n [open]\n );\n\n const handleOpenTriggerKeyDown = useCallback(\n (e: React.KeyboardEvent) => {\n if (e.key === 'ArrowDown') {\n e.preventDefault();\n setHighlightedIndex((i) =>\n visibleOptions.length === 0 ? 0 : (i + 1) % visibleOptions.length\n );\n } else if (e.key === 'ArrowUp') {\n e.preventDefault();\n setHighlightedIndex((i) =>\n visibleOptions.length === 0 ? 0 : (i - 1 + visibleOptions.length) % visibleOptions.length\n );\n } else if (e.key === 'Enter' || e.key === ' ') {\n e.preventDefault();\n const opt = visibleOptions[highlightedIndex];\n if (opt) select(opt.value);\n } else if (e.key === 'Escape') {\n e.preventDefault();\n close();\n } else if (e.key === 'Tab') {\n close();\n }\n },\n [visibleOptions, highlightedIndex, select, close]\n );\n\n const handleInputKeyDown = useCallback(\n (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (e.key === 'ArrowDown') {\n e.preventDefault();\n setHighlightedIndex((i) =>\n visibleOptions.length === 0 ? 0 : (i + 1) % visibleOptions.length\n );\n } else if (e.key === 'ArrowUp') {\n e.preventDefault();\n setHighlightedIndex((i) =>\n visibleOptions.length === 0 ? 0 : (i - 1 + visibleOptions.length) % visibleOptions.length\n );\n } else if (e.key === 'Enter') {\n e.preventDefault();\n const opt = visibleOptions[highlightedIndex];\n if (opt) select(opt.value);\n } else if (e.key === 'Escape') {\n e.preventDefault();\n close();\n } else if (e.key === 'Tab') {\n close();\n }\n },\n [visibleOptions, highlightedIndex, select, close]\n );\n\n return (\n <div className={cx(style.root, style[layout], style[surface])}>\n {label && (\n <label className={style.label} htmlFor={inputId}>\n {label}\n </label>\n )}\n <div ref={triggerWrapperRef} className={style.triggerWrapper}>\n {isOpen && searchable ? (\n <div className={cx(style.trigger, style[surface])}>\n <input\n ref={inputRef}\n id={inputId}\n name={name}\n autoComplete=\"off\"\n className={style.searchInput}\n aria-label=\"Search\"\n placeholder=\"Type to search…\"\n value={query}\n onChange={(e) => {\n setQuery(e.target.value);\n setHighlightedIndex(0);\n }}\n onKeyDown={handleInputKeyDown}\n />\n <span\n className={cx(style.chevron, style.open)}\n role=\"button\"\n tabIndex={-1}\n aria-label=\"Close\"\n onMouseDown={(e) => e.preventDefault()}\n onClick={close}\n >\n <ChevronIcon height={12} width={12} />\n </span>\n </div>\n ) : (\n <div\n className={cx(style.trigger, style[surface], {\n [style.loading]: loading,\n [style.disabled]: disabled,\n [style.open]: isOpen,\n })}\n role=\"button\"\n tabIndex={disabled || loading ? -1 : 0}\n aria-label={selectedLabel ?? placeholder}\n onClick={isOpen ? close : open}\n onKeyDown={isOpen ? handleOpenTriggerKeyDown : handleTriggerKeyDown}\n >\n {loading && <SpinnerIcon className={style.spinner} />}\n <span className={cx(style.triggerText, { [style.placeholder]: !selectedLabel })}>\n {loading ? 'Loading…' : (selectedLabel ?? placeholder)}\n </span>\n {value && clearable && !disabled && !loading && (\n <span\n className={style.clearButton}\n role=\"button\"\n tabIndex={0}\n aria-label=\"Clear\"\n onClick={(e) => {\n e.stopPropagation();\n clear();\n }}\n onKeyDown={(e) => {\n if (e.key === 'Enter' || e.key === ' ') {\n e.preventDefault();\n e.stopPropagation();\n clear();\n }\n }}\n >\n ✕\n </span>\n )}\n <span className={style.chevron}>\n <ChevronIcon height={12} width={12} />\n </span>\n </div>\n )}\n <Popover anchorRef={triggerWrapperRef} open={isOpen} onClose={close}>\n <div className={style.dropdown}>\n <ul className={style.optionList} role=\"listbox\">\n {visibleOptions.length === 0 ? (\n <li\n className={cx(style.option, style.emptyOption)}\n role=\"option\"\n aria-selected={false}\n >\n No results\n </li>\n ) : (\n visibleOptions.map((opt, index) => (\n <li\n key={opt._isCreate ? `__create__${opt.value}` : opt.value}\n className={cx(style.option, {\n [style.highlighted]: index === highlightedIndex,\n [style.selected]: !opt._isCreate && opt.value === value,\n [style.createOption]: opt._isCreate,\n })}\n role=\"option\"\n aria-selected={!opt._isCreate && opt.value === value}\n onMouseDown={(e) => e.preventDefault()}\n onClick={() => select(opt.value)}\n >\n {opt._isCreate ? (\n <>\n Add: <strong>{opt.label}</strong>\n </>\n ) : (\n <>\n <div>{highlight(opt.label, query, style.matchHighlight)}</div>\n {opt.description && (\n <div className={style.optionDescription}>{opt.description}</div>\n )}\n </>\n )}\n </li>\n ))\n )}\n </ul>\n </div>\n </Popover>\n </div>\n </div>\n );\n};\n"]}
@@ -1,6 +1,7 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { SwitchRadiusValue } from './style.js';
3
- type SwitchProps = {
3
+ export type { SwitchRadiusValue };
4
+ export type SwitchProps = {
4
5
  /**
5
6
  * Accessible name when the visible `label` is absent because something
6
7
  * OUTSIDE the switch already carries it — a grid's row and column headers,
@@ -8,10 +9,18 @@ type SwitchProps = {
8
9
  * machine key (`BOOK_REQUEST_FULFILLED:EMAIL`), not a name.
9
10
  */
10
11
  ariaLabel?: string;
12
+ /** Controlled on/off state. */
11
13
  checked: boolean;
14
+ /** Helper text under the label, linked by `aria-describedby`. */
12
15
  description?: ReactNode;
16
+ /** Fades the switch and removes it from the tab order. */
13
17
  disabled?: boolean;
18
+ /** Visible label and accessible name (`ariaLabel` wins over it). */
14
19
  label?: string;
20
+ /**
21
+ * `'default'`: track then label, inline. `'horizontal'`: full-width shaded
22
+ * row, track on the right; the whole row toggles, description included.
23
+ */
15
24
  layout?: 'default' | 'horizontal';
16
25
  /**
17
26
  * A save driven by this switch is in flight. The thumb becomes a spinner
@@ -24,7 +33,9 @@ type SwitchProps = {
24
33
  * where the click is taking it.
25
34
  */
26
35
  loading?: boolean;
36
+ /** Not a form field (no hidden input); only the last-resort accessible name. */
27
37
  name: string;
38
+ /** Receives the new value, not an event. Not called while `disabled` or `loading`. */
28
39
  onChange: (checked: boolean) => void;
29
40
  /**
30
41
  * The corner shape of the track, named for what the switch sits in. Defaults
@@ -34,6 +45,9 @@ type SwitchProps = {
34
45
  */
35
46
  radius?: SwitchRadiusValue;
36
47
  };
48
+ /**
49
+ * Controlled on/off toggle with an optional label and description. Enter and
50
+ * Space toggle; clicks don't propagate to a clickable parent row.
51
+ */
37
52
  export declare const Switch: ({ ariaLabel, checked, description, disabled, label, layout, loading, name, onChange, radius, }: SwitchProps) => import("react").JSX.Element;
38
- export {};
39
53
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/control/switch/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAA2C,MAAM,OAAO,CAAC;AAG3E,OAAO,EAAgB,iBAAiB,EAAY,MAAM,YAAY,CAAC;AAqCvE,KAAK,WAAW,GAAG;IACjB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,QAAQ,CAAC,EAA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}
@@ -36,6 +36,10 @@ function useDelayedFlag(active, delayMs) {
36
36
  }, [active, delayMs]);
37
37
  return elapsed;
38
38
  }
39
+ /**
40
+ * Controlled on/off toggle with an optional label and description. Enter and
41
+ * Space toggle; clicks don't propagate to a clickable parent row.
42
+ */
39
43
  export const Switch = ({ ariaLabel, checked, description, disabled = false, label, layout = 'default', loading = false, name, onChange, radius = SwitchRadius.Inset, }) => {
40
44
  const style = useStyle();
41
45
  const showSpinner = useDelayedFlag(loading, SPINNER_DELAY_MS);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/control/switch/index.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAa,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE3E,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAqB,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEvE;;;;;;;;;GASG;AACH,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAE7B;;;;;;;;;GASG;AACH,SAAS,cAAc,CAAC,MAAe,EAAE,OAAe;IACtD,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9C,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,UAAU,CAAC,KAAK,CAAC,CAAC;YAClB,OAAO;QACT,CAAC;QACD,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC;QAC1D,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACtB,OAAO,OAAO,CAAC;AACjB,CAAC;AAq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,SAAS,EAAE,aAAa;KACzB,CAAC;IAEF,+EAA+E;IAC/E,wEAAwE;IACxE,IAAI,MAAM,KAAK,YAAY,EAAE,CAAC;QAC5B,OAAO,CACL,kBAAS,WAAW,EAAE,SAAS,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,UAAU,CAAC,aAC/D,eAAK,SAAS,EAAE,KAAK,CAAC,OAAO,aAC1B,KAAK,IAAI,eAAM,SAAS,EAAE,KAAK,CAAC,KAAK,YAAG,KAAK,GAAQ,EACrD,aAAa,IACV,EACL,KAAK,IACF,CACP,CAAC;IACJ,CAAC;IAED,OAAO,CACL,kBAAS,WAAW,EAAE,SAAS,EAAE,KAAK,CAAC,IAAI,aACzC,eAAK,SAAS,EAAE,KAAK,CAAC,GAAG,aACtB,KAAK,EACL,KAAK,IAAI,eAAM,SAAS,EAAE,KAAK,CAAC,KAAK,YAAG,KAAK,GAAQ,IAClD,EACL,aAAa,IACV,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import cx from 'classnames';\nimport { ReactNode, useCallback, useEffect, useId, useState } from 'react';\n\nimport { SpinnerIcon } from '../../icon/index.js';\nimport { SwitchRadius, SwitchRadiusValue, useStyle } from './style.js';\n\n/**\n * How long a save may run before the switch admits to it.\n *\n * Every mutation behind a switch in this app is local — a preference row, a\n * push subscription — and normally settles in well under this. Showing the\n * spinner the instant a click fires would therefore flash it for two or three\n * frames on nearly every interaction, which reads as a glitch rather than as\n * feedback. Waiting means the common path shows nothing at all, and only a\n * genuinely slow save (a busy server, a dropped connection) ever draws one.\n */\nconst SPINNER_DELAY_MS = 150;\n\n/**\n * True once `active` has been continuously true for `delayMs`, false the\n * moment it clears.\n *\n * The delay is PURELY VISUAL. Both the click guard and `aria-busy` below read\n * the undelayed prop instead, because suppressing the spinner for 150ms must\n * not also open a 150ms window in which a second click fires a second\n * mutation, nor hide the state from a screen reader that has no flicker to be\n * spared.\n */\nfunction useDelayedFlag(active: boolean, delayMs: number): boolean {\n const [elapsed, setElapsed] = useState(false);\n useEffect(() => {\n if (!active) {\n setElapsed(false);\n return;\n }\n const timer = setTimeout(() => setElapsed(true), delayMs);\n return () => clearTimeout(timer);\n }, [active, delayMs]);\n return elapsed;\n}\n\ntype SwitchProps = {\n /**\n * Accessible name when the visible `label` is absent because something\n * OUTSIDE the switch already carries it — a grid's row and column headers,\n * say. Without it such a switch falls back to announcing `name`, which is a\n * machine key (`BOOK_REQUEST_FULFILLED:EMAIL`), not a name.\n */\n ariaLabel?: string;\n checked: boolean;\n description?: ReactNode;\n disabled?: boolean;\n label?: string;\n layout?: 'default' | 'horizontal';\n /**\n * A save driven by this switch is in flight. The thumb becomes a spinner\n * (after a short delay — see `SPINNER_DELAY_MS`) and further clicks are\n * ignored until it clears.\n *\n * Distinct from `disabled`, which means \"you may not change this\" and fades\n * the whole control. A loading switch keeps its colour and shows the\n * position it is SAVING, not the one it came from, so the reader can see\n * where the click is taking it.\n */\n loading?: boolean;\n name: string;\n onChange: (checked: boolean) => void;\n /**\n * The corner shape of the track, named for what the switch sits in. Defaults\n * to `inset` — concentric with the shaded input row every switch in this app\n * currently sits in. Pass `pill` for the classic capsule on an unshaded\n * surface.\n */\n radius?: SwitchRadiusValue;\n};\n\nexport const Switch = ({\n ariaLabel,\n checked,\n description,\n disabled = false,\n label,\n layout = 'default',\n loading = false,\n name,\n onChange,\n radius = SwitchRadius.Inset as SwitchRadiusValue,\n}: SwitchProps) => {\n const style = useStyle();\n const showSpinner = useDelayedFlag(loading, SPINNER_DELAY_MS);\n // Per-instance id so the description's aria target stays unique even when two\n // switches sharing a `name` mount at once (e.g. the device create + edit forms).\n const generatedId = useId();\n const descriptionId = description ? generatedId : undefined;\n\n const handleClick = useCallback(\n (event: React.MouseEvent) => {\n event.stopPropagation();\n if (!disabled && !loading) onChange(!checked);\n },\n [checked, disabled, loading, onChange]\n );\n\n const handleKeyDown = useCallback(\n (event: React.KeyboardEvent) => {\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault();\n event.stopPropagation();\n if (!disabled && !loading) onChange(!checked);\n }\n },\n [checked, disabled, loading, onChange]\n );\n\n // The description is helper text, not a toggle target — clicking it should\n // not flip the switch.\n const handleDescriptionClick = useCallback((event: React.MouseEvent) => {\n event.stopPropagation();\n }, []);\n\n // The radius class lands on the track rather than the root because it styles\n // the track and its thumb, and the track is the one element both layouts\n // below render identically.\n const track = (\n <div\n className={cx(style.track, style[radius], {\n [style.checked]: checked,\n [style.disabled]: disabled,\n [style.loading]: showSpinner,\n })}\n >\n {showSpinner ? (\n // `aria-hidden` because `aria-busy` on the switch itself already\n // carries this to assistive tech, and from the undelayed prop.\n <SpinnerIcon aria-hidden={true} className={style.spinner} />\n ) : (\n <div className={style.thumb} />\n )}\n </div>\n );\n\n const descriptionEl = description ? (\n <div\n id={descriptionId}\n className={style.description}\n // In the horizontal layout the whole shaded row is a toggle target, so let\n // description clicks bubble up. Elsewhere the description stays inert helper text.\n onClick={layout === 'horizontal' ? undefined : handleDescriptionClick}\n >\n {description}\n </div>\n ) : null;\n\n const commonProps = {\n role: 'switch' as const,\n 'aria-checked': checked,\n 'aria-label': ariaLabel ?? label ?? name,\n 'aria-describedby': descriptionId,\n 'aria-disabled': disabled,\n 'aria-busy': loading,\n tabIndex: disabled ? -1 : 0,\n onClick: handleClick,\n onKeyDown: handleKeyDown,\n };\n\n // Horizontal keeps the toggle in its own right-hand column so the description,\n // stacked under the label in the content column, never runs beneath it.\n if (layout === 'horizontal') {\n return (\n <div {...commonProps} className={cx(style.root, style.horizontal)}>\n <div className={style.content}>\n {label && <span className={style.label}>{label}</span>}\n {descriptionEl}\n </div>\n {track}\n </div>\n );\n }\n\n return (\n <div {...commonProps} className={style.root}>\n <div className={style.row}>\n {track}\n {label && <span className={style.label}>{label}</span>}\n </div>\n {descriptionEl}\n </div>\n );\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/control/switch/index.tsx"],"names":[],"mappings":";AAAA,OAAO,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AS,WAAW,EAAE,SAAS,EAAE,KAAK,CAAC,IAAI,aACzC,eAAK,SAAS,EAAE,KAAK,CAAC,GAAG,aACtB,KAAK,EACL,KAAK,IAAI,eAAM,SAAS,EAAE,KAAK,CAAC,KAAK,YAAG,KAAK,GAAQ,IAClD,EACL,aAAa,IACV,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import cx from 'classnames';\nimport { ReactNode, useCallback, useEffect, useId, useState } from 'react';\n\nimport { SpinnerIcon } from '../../icon/index.js';\nimport { SwitchRadius, SwitchRadiusValue, useStyle } from './style.js';\n\n/**\n * How long a save may run before the switch admits to it.\n *\n * Every mutation behind a switch in this app is local — a preference row, a\n * push subscription — and normally settles in well under this. Showing the\n * spinner the instant a click fires would therefore flash it for two or three\n * frames on nearly every interaction, which reads as a glitch rather than as\n * feedback. Waiting means the common path shows nothing at all, and only a\n * genuinely slow save (a busy server, a dropped connection) ever draws one.\n */\nconst SPINNER_DELAY_MS = 150;\n\n/**\n * True once `active` has been continuously true for `delayMs`, false the\n * moment it clears.\n *\n * The delay is PURELY VISUAL. Both the click guard and `aria-busy` below read\n * the undelayed prop instead, because suppressing the spinner for 150ms must\n * not also open a 150ms window in which a second click fires a second\n * mutation, nor hide the state from a screen reader that has no flicker to be\n * spared.\n */\nfunction useDelayedFlag(active: boolean, delayMs: number): boolean {\n const [elapsed, setElapsed] = useState(false);\n useEffect(() => {\n if (!active) {\n setElapsed(false);\n return;\n }\n const timer = setTimeout(() => setElapsed(true), delayMs);\n return () => clearTimeout(timer);\n }, [active, delayMs]);\n return elapsed;\n}\n\nexport type { SwitchRadiusValue };\n\nexport type SwitchProps = {\n /**\n * Accessible name when the visible `label` is absent because something\n * OUTSIDE the switch already carries it — a grid's row and column headers,\n * say. Without it such a switch falls back to announcing `name`, which is a\n * machine key (`BOOK_REQUEST_FULFILLED:EMAIL`), not a name.\n */\n ariaLabel?: string;\n /** Controlled on/off state. */\n checked: boolean;\n /** Helper text under the label, linked by `aria-describedby`. */\n description?: ReactNode;\n /** Fades the switch and removes it from the tab order. */\n disabled?: boolean;\n /** Visible label and accessible name (`ariaLabel` wins over it). */\n label?: string;\n /**\n * `'default'`: track then label, inline. `'horizontal'`: full-width shaded\n * row, track on the right; the whole row toggles, description included.\n */\n layout?: 'default' | 'horizontal';\n /**\n * A save driven by this switch is in flight. The thumb becomes a spinner\n * (after a short delay — see `SPINNER_DELAY_MS`) and further clicks are\n * ignored until it clears.\n *\n * Distinct from `disabled`, which means \"you may not change this\" and fades\n * the whole control. A loading switch keeps its colour and shows the\n * position it is SAVING, not the one it came from, so the reader can see\n * where the click is taking it.\n */\n loading?: boolean;\n /** Not a form field (no hidden input); only the last-resort accessible name. */\n name: string;\n /** Receives the new value, not an event. Not called while `disabled` or `loading`. */\n onChange: (checked: boolean) => void;\n /**\n * The corner shape of the track, named for what the switch sits in. Defaults\n * to `inset` — concentric with the shaded input row every switch in this app\n * currently sits in. Pass `pill` for the classic capsule on an unshaded\n * surface.\n */\n radius?: SwitchRadiusValue;\n};\n\n/**\n * Controlled on/off toggle with an optional label and description. Enter and\n * Space toggle; clicks don't propagate to a clickable parent row.\n */\nexport const Switch = ({\n ariaLabel,\n checked,\n description,\n disabled = false,\n label,\n layout = 'default',\n loading = false,\n name,\n onChange,\n radius = SwitchRadius.Inset as SwitchRadiusValue,\n}: SwitchProps) => {\n const style = useStyle();\n const showSpinner = useDelayedFlag(loading, SPINNER_DELAY_MS);\n // Per-instance id so the description's aria target stays unique even when two\n // switches sharing a `name` mount at once (e.g. the device create + edit forms).\n const generatedId = useId();\n const descriptionId = description ? generatedId : undefined;\n\n const handleClick = useCallback(\n (event: React.MouseEvent) => {\n event.stopPropagation();\n if (!disabled && !loading) onChange(!checked);\n },\n [checked, disabled, loading, onChange]\n );\n\n const handleKeyDown = useCallback(\n (event: React.KeyboardEvent) => {\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault();\n event.stopPropagation();\n if (!disabled && !loading) onChange(!checked);\n }\n },\n [checked, disabled, loading, onChange]\n );\n\n // The description is helper text, not a toggle target — clicking it should\n // not flip the switch.\n const handleDescriptionClick = useCallback((event: React.MouseEvent) => {\n event.stopPropagation();\n }, []);\n\n // The radius class lands on the track rather than the root because it styles\n // the track and its thumb, and the track is the one element both layouts\n // below render identically.\n const track = (\n <div\n className={cx(style.track, style[radius], {\n [style.checked]: checked,\n [style.disabled]: disabled,\n [style.loading]: showSpinner,\n })}\n >\n {showSpinner ? (\n // `aria-hidden` because `aria-busy` on the switch itself already\n // carries this to assistive tech, and from the undelayed prop.\n <SpinnerIcon aria-hidden={true} className={style.spinner} />\n ) : (\n <div className={style.thumb} />\n )}\n </div>\n );\n\n const descriptionEl = description ? (\n <div\n id={descriptionId}\n className={style.description}\n // In the horizontal layout the whole shaded row is a toggle target, so let\n // description clicks bubble up. Elsewhere the description stays inert helper text.\n onClick={layout === 'horizontal' ? undefined : handleDescriptionClick}\n >\n {description}\n </div>\n ) : null;\n\n const commonProps = {\n role: 'switch' as const,\n 'aria-checked': checked,\n 'aria-label': ariaLabel ?? label ?? name,\n 'aria-describedby': descriptionId,\n 'aria-disabled': disabled,\n 'aria-busy': loading,\n tabIndex: disabled ? -1 : 0,\n onClick: handleClick,\n onKeyDown: handleKeyDown,\n };\n\n // Horizontal keeps the toggle in its own right-hand column so the description,\n // stacked under the label in the content column, never runs beneath it.\n if (layout === 'horizontal') {\n return (\n <div {...commonProps} className={cx(style.root, style.horizontal)}>\n <div className={style.content}>\n {label && <span className={style.label}>{label}</span>}\n {descriptionEl}\n </div>\n {track}\n </div>\n );\n }\n\n return (\n <div {...commonProps} className={style.root}>\n <div className={style.row}>\n {track}\n {label && <span className={style.label}>{label}</span>}\n </div>\n {descriptionEl}\n </div>\n );\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../../../src/control/switch/style.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAEnE;;;;;;;;;GASG;AACH,MAAM,MAAM,iBAAiB,GAAG,OAAO,GAAG,MAAM,CAAC;AACjD,oBAAY,YAAY;IACtB;;;;OAIG;IACH,KAAK,UAAU;IACf;;;;;;;;;;OAUG;IACH,IAAI,SAAS;CACd;AAED,eAAO,MAAM,QAAQ;;2MAyIlB,CAAC"}
1
+ {"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../../../src/control/switch/style.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAEnE;;;;;;;;;GASG;AACH,MAAM,MAAM,iBAAiB,GAAG,OAAO,GAAG,MAAM,CAAC;AACjD,oBAAY,YAAY;IACtB;;;;OAIG;IACH,KAAK,UAAU;IACf;;;;;;;;;;OAUG;IACH,IAAI,SAAS;CACd;AAED,eAAO,MAAM,QAAQ;;2MAuIlB,CAAC"}
@@ -128,9 +128,7 @@ export const useStyle = createUseStyles((theme) => ({
128
128
  alignItems: 'center',
129
129
  gap: theme.space.md,
130
130
  width: '100%',
131
- backgroundColor: theme.color.bg.cardHeader,
132
- borderRadius: theme.radius.md,
133
- padding: `${theme.space.md} ${theme.space.lg} ${theme.space.md} ${theme.space.sm}`,
131
+ ...theme.recipe.row,
134
132
  '& $content': {
135
133
  display: 'flex',
136
134
  flexDirection: 'column',
@@ -1 +1 @@
1
- {"version":3,"file":"style.js","sourceRoot":"","sources":["../../../src/control/switch/style.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAc,MAAM,sBAAsB,CAAC;AAanE,MAAM,CAAN,IAAY,YAmBX;AAnBD,WAAY,YAAY;IACtB;;;;OAIG;IACH,+BAAe,CAAA;IACf;;;;;;;;;;OAUG;IACH,6BAAa,CAAA;AACf,CAAC,EAnBW,YAAY,KAAZ,YAAY,QAmBvB;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,eAAe,CAAC,CAAC,KAAY,EAAE,EAAE,CAAC,CAAC;IACzD,IAAI,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,IAAI,CAAC,KAAK;QAC7B,WAAW,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE;KAC7C;IAED,KAAK,EAAE;QACL,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK;KACtB;IACD,OAAO,EAAE,EAAE;IACX,UAAU,EAAE;QACV,+EAA+E;QAC/E,OAAO,EAAE,MAAM;QACf,aAAa,EAAE,KAAK;QACpB,UAAU,EAAE,QAAQ;QACpB,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE;QACnB,KAAK,EAAE,MAAM;QACb,eAAe,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,UAAU;QAC1C,YAAY,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE;QAC7B,OAAO,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE,EAAE;QAClF,YAAY,EAAE;YACZ,OAAO,EAAE,MAAM;YACf,aAAa,EAAE,QAAQ;YACvB,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE;YACnB,QAAQ,EAAE,CAAC;YACX,QAAQ,EAAE,CAAC;SACZ;QACD,UAAU,EAAE;YACV,6DAA6D;YAC7D,SAAS,EAAE,MAAM;SAClB;QACD,gBAAgB,EAAE;YAChB,MAAM,EAAE,CAAC;YACT,gFAAgF;YAChF,MAAM,EAAE,SAAS;SAClB;QACD,UAAU,EAAE;YACV,mEAAmE;YACnE,UAAU,EAAE,CAAC;SACd;KACF;IACD,OAAO,EAAE,EAAE;IACX,QAAQ,EAAE,EAAE;IACZ,MAAM,EAAE,EAAE;CACX,CAAC,CAAC,CAAC","sourcesContent":["import { createUseStyles, type Theme } from '../../theme/index.js';\n\n/**\n * Named for what the switch SITS IN rather than for a size, matching\n * `ButtonRadius`: a caller knows its own surroundings, not which step of the\n * radius scale suits a 16px-tall track.\n *\n * Deliberately two values, where `ButtonRadius` has four. A switch's track is\n * 16px tall, so any radius of 8px or more clamps to a full pill — `card`\n * (`radius.md`) and `pill` would be the same shape, named twice, and could\n * never diverge while the track keeps that height.\n */\nexport type SwitchRadiusValue = 'inset' | 'pill';\nexport enum SwitchRadius {\n /**\n * Concentric with the shaded input row the switch sits in: 16px card, 8px\n * row, 4px track, 2px thumb. The default, because that row is where every\n * switch in this app currently lives.\n */\n Inset = 'inset',\n /**\n * The classic capsule, and the rule for a switch in a CARD HEADER.\n *\n * Not about shading — a card header is painted `bg.cardHeader`, the same\n * colour as the input row. It is about whether there is anything nearby to\n * be concentric WITH. An input row is a small rounded rectangle wrapping the\n * switch, so a 4px track echoes its 8px corner a few pixels away. A card\n * header is a full-width bar whose only corners are the card's own, far off\n * at either end: nothing for the track to relate to, so it reads better as a\n * self-contained control than as a square-ish chip floating in a bar.\n */\n Pill = 'pill',\n}\n\nexport const useStyle = createUseStyles((theme: Theme) => ({\n root: {\n display: 'inline-flex',\n flexDirection: 'column',\n alignItems: 'flex-start',\n gap: theme.space.xs,\n cursor: 'pointer',\n userSelect: 'none',\n '-webkit-user-select': 'none',\n },\n row: {\n display: 'flex',\n alignItems: 'center',\n gap: theme.space.md,\n },\n description: {\n // Indent under the label (past the 28px track + row gap) so it reads as\n // helper text for this toggle rather than a separate row.\n marginLeft: `calc(28px + ${theme.space.md})`,\n fontSize: theme.fontSize.sm,\n // Dedicated description colour — darker than faint for readable helper text,\n // especially on the shaded background of the horizontal layout.\n color: theme.color.text.description,\n cursor: 'auto',\n },\n track: {\n position: 'relative',\n width: '28px',\n height: '16px',\n backgroundColor: theme.color.border.default,\n ...theme.recipe.focusRing,\n transitionProperty: 'background-color, outline-color',\n transitionDuration: '0.1s',\n transitionTimingFunction: 'ease-in',\n '$root:hover &': { outlineColor: theme.color.brand.outline },\n '$root:focus &': { outlineColor: theme.color.brand.outline },\n '&$checked': { backgroundColor: theme.color.brand.default },\n '&$disabled': { opacity: 0.4, cursor: 'not-allowed' },\n },\n thumb: {\n position: 'absolute',\n top: '2px',\n left: '2px',\n width: '12px',\n height: '12px',\n backgroundColor: theme.color.bg.input,\n transitionProperty: 'left',\n transitionDuration: '0.1s',\n transitionTimingFunction: 'ease-in',\n '$checked &': { left: '14px' },\n },\n /**\n * Each value sets the track AND its thumb together, because the two are not\n * independent: the thumb is inset 2px on every side, so a concentric thumb\n * is always the track's radius less that inset. Splitting them into two\n * props would let a caller produce a square thumb in a capsule track.\n */\n [SwitchRadius.Inset]: {\n borderRadius: theme.radius.sm,\n // Arithmetic rather than a token so it follows the track automatically if\n // that radius ever changes — and because the scale has no 2px step.\n '& $thumb': { borderRadius: `calc(${theme.radius.sm} - 2px)` },\n },\n [SwitchRadius.Pill]: {\n borderRadius: theme.radius.pill,\n '& $thumb': { borderRadius: theme.radius.circle },\n },\n\n /**\n * Replaces the thumb while a save is in flight. Sized to the thumb it\n * stands in for, and inheriting `currentColor` from `$track` below so it\n * stays legible against both track colours.\n */\n spinner: {\n ...theme.recipe.spinner,\n position: 'absolute',\n top: '2px',\n width: '12px',\n height: '12px',\n // Matches the thumb's own transition, so a click that both moves the\n // switch AND starts a save does not animate the two at different speeds.\n transitionProperty: 'left',\n transitionDuration: '0.1s',\n transitionTimingFunction: 'ease-in',\n left: '2px',\n '$checked &': { left: '14px' },\n },\n loading: {\n // The track keeps its colour — this is \"working\", not \"unavailable\",\n // which `disabled` already says by fading to 40%. Only the cursor and the\n // thumb change.\n cursor: 'progress',\n // `currentColor` for the spinner: muted against the pale unchecked track,\n // white against the saturated checked one. A single colour would vanish\n // into one of the two.\n color: theme.color.text.muted,\n '&$checked': { color: theme.color.bg.input },\n },\n\n label: {\n ...theme.recipe.label,\n },\n content: {},\n horizontal: {\n // Two columns: content (label + description) on the left, toggle on the right.\n display: 'flex',\n flexDirection: 'row',\n alignItems: 'center',\n gap: theme.space.md,\n width: '100%',\n backgroundColor: theme.color.bg.cardHeader,\n borderRadius: theme.radius.md,\n padding: `${theme.space.md} ${theme.space.lg} ${theme.space.md} ${theme.space.sm}`,\n '& $content': {\n display: 'flex',\n flexDirection: 'column',\n gap: theme.space.xs,\n flexGrow: 1,\n minWidth: 0,\n },\n '& $label': {\n // Left-aligned to the same edge as the other fields' labels.\n textAlign: 'left',\n },\n '& $description': {\n margin: 0,\n // The whole shaded row toggles, so the description shows the toggle cursor too.\n cursor: 'pointer',\n },\n '& $track': {\n // Kept in its own column so the description never runs beneath it.\n flexShrink: 0,\n },\n },\n checked: {},\n disabled: {},\n danger: {},\n}));\n"]}
1
+ {"version":3,"file":"style.js","sourceRoot":"","sources":["../../../src/control/switch/style.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAc,MAAM,sBAAsB,CAAC;AAanE,MAAM,CAAN,IAAY,YAmBX;AAnBD,WAAY,YAAY;IACtB;;;;OAIG;IACH,+BAAe,CAAA;IACf;;;;;;;;;;OAUG;IACH,6BAAa,CAAA;AACf,CAAC,EAnBW,YAAY,KAAZ,YAAY,QAmBvB;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,eAAe,CAAC,CAAC,KAAY,EAAE,EAAE,CAAC,CAAC;IACzD,IAAI,EAAE;QACJ,OAAO,EAAE,aAAa;QACtB,aAAa,EAAE,QAAQ;QACvB,UAAU,EAAE,YAAY;QACxB,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE;QACnB,MAAM,EAAE,SAAS;QACjB,UAAU,EAAE,MAAM;QAClB,qBAAqB,EAAE,MAAM;KAC9B;IACD,GAAG,EAAE;QACH,OAAO,EAAE,MAAM;QACf,UAAU,EAAE,QAAQ;QACpB,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE;KACpB;IACD,WAAW,EAAE;QACX,wEAAwE;QACxE,0DAA0D;QAC1D,UAAU,EAAE,eAAe,KAAK,CAAC,KAAK,CAAC,EAAE,GAAG;QAC5C,QAAQ,EAAE,KAAK,CAAC,QAAQ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E,QAAQ;YACvB,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE;YACnB,QAAQ,EAAE,CAAC;YACX,QAAQ,EAAE,CAAC;SACZ;QACD,UAAU,EAAE;YACV,6DAA6D;YAC7D,SAAS,EAAE,MAAM;SAClB;QACD,gBAAgB,EAAE;YAChB,MAAM,EAAE,CAAC;YACT,gFAAgF;YAChF,MAAM,EAAE,SAAS;SAClB;QACD,UAAU,EAAE;YACV,mEAAmE;YACnE,UAAU,EAAE,CAAC;SACd;KACF;IACD,OAAO,EAAE,EAAE;IACX,QAAQ,EAAE,EAAE;IACZ,MAAM,EAAE,EAAE;CACX,CAAC,CAAC,CAAC","sourcesContent":["import { createUseStyles, type Theme } from '../../theme/index.js';\n\n/**\n * Named for what the switch SITS IN rather than for a size, matching\n * `ButtonRadius`: a caller knows its own surroundings, not which step of the\n * radius scale suits a 16px-tall track.\n *\n * Deliberately two values, where `ButtonRadius` has four. A switch's track is\n * 16px tall, so any radius of 8px or more clamps to a full pill — `card`\n * (`radius.md`) and `pill` would be the same shape, named twice, and could\n * never diverge while the track keeps that height.\n */\nexport type SwitchRadiusValue = 'inset' | 'pill';\nexport enum SwitchRadius {\n /**\n * Concentric with the shaded input row the switch sits in: 16px card, 8px\n * row, 4px track, 2px thumb. The default, because that row is where every\n * switch in this app currently lives.\n */\n Inset = 'inset',\n /**\n * The classic capsule, and the rule for a switch in a CARD HEADER.\n *\n * Not about shading — a card header is painted `bg.cardHeader`, the same\n * colour as the input row. It is about whether there is anything nearby to\n * be concentric WITH. An input row is a small rounded rectangle wrapping the\n * switch, so a 4px track echoes its 8px corner a few pixels away. A card\n * header is a full-width bar whose only corners are the card's own, far off\n * at either end: nothing for the track to relate to, so it reads better as a\n * self-contained control than as a square-ish chip floating in a bar.\n */\n Pill = 'pill',\n}\n\nexport const useStyle = createUseStyles((theme: Theme) => ({\n root: {\n display: 'inline-flex',\n flexDirection: 'column',\n alignItems: 'flex-start',\n gap: theme.space.xs,\n cursor: 'pointer',\n userSelect: 'none',\n '-webkit-user-select': 'none',\n },\n row: {\n display: 'flex',\n alignItems: 'center',\n gap: theme.space.md,\n },\n description: {\n // Indent under the label (past the 28px track + row gap) so it reads as\n // helper text for this toggle rather than a separate row.\n marginLeft: `calc(28px + ${theme.space.md})`,\n fontSize: theme.fontSize.sm,\n // Dedicated description colour — darker than faint for readable helper text,\n // especially on the shaded background of the horizontal layout.\n color: theme.color.text.description,\n cursor: 'auto',\n },\n track: {\n position: 'relative',\n width: '28px',\n height: '16px',\n backgroundColor: theme.color.border.default,\n ...theme.recipe.focusRing,\n transitionProperty: 'background-color, outline-color',\n transitionDuration: '0.1s',\n transitionTimingFunction: 'ease-in',\n '$root:hover &': { outlineColor: theme.color.brand.outline },\n '$root:focus &': { outlineColor: theme.color.brand.outline },\n '&$checked': { backgroundColor: theme.color.brand.default },\n '&$disabled': { opacity: 0.4, cursor: 'not-allowed' },\n },\n thumb: {\n position: 'absolute',\n top: '2px',\n left: '2px',\n width: '12px',\n height: '12px',\n backgroundColor: theme.color.bg.input,\n transitionProperty: 'left',\n transitionDuration: '0.1s',\n transitionTimingFunction: 'ease-in',\n '$checked &': { left: '14px' },\n },\n /**\n * Each value sets the track AND its thumb together, because the two are not\n * independent: the thumb is inset 2px on every side, so a concentric thumb\n * is always the track's radius less that inset. Splitting them into two\n * props would let a caller produce a square thumb in a capsule track.\n */\n [SwitchRadius.Inset]: {\n borderRadius: theme.radius.sm,\n // Arithmetic rather than a token so it follows the track automatically if\n // that radius ever changes — and because the scale has no 2px step.\n '& $thumb': { borderRadius: `calc(${theme.radius.sm} - 2px)` },\n },\n [SwitchRadius.Pill]: {\n borderRadius: theme.radius.pill,\n '& $thumb': { borderRadius: theme.radius.circle },\n },\n\n /**\n * Replaces the thumb while a save is in flight. Sized to the thumb it\n * stands in for, and inheriting `currentColor` from `$track` below so it\n * stays legible against both track colours.\n */\n spinner: {\n ...theme.recipe.spinner,\n position: 'absolute',\n top: '2px',\n width: '12px',\n height: '12px',\n // Matches the thumb's own transition, so a click that both moves the\n // switch AND starts a save does not animate the two at different speeds.\n transitionProperty: 'left',\n transitionDuration: '0.1s',\n transitionTimingFunction: 'ease-in',\n left: '2px',\n '$checked &': { left: '14px' },\n },\n loading: {\n // The track keeps its colour — this is \"working\", not \"unavailable\",\n // which `disabled` already says by fading to 40%. Only the cursor and the\n // thumb change.\n cursor: 'progress',\n // `currentColor` for the spinner: muted against the pale unchecked track,\n // white against the saturated checked one. A single colour would vanish\n // into one of the two.\n color: theme.color.text.muted,\n '&$checked': { color: theme.color.bg.input },\n },\n\n label: {\n ...theme.recipe.label,\n },\n content: {},\n horizontal: {\n // Two columns: content (label + description) on the left, toggle on the right.\n display: 'flex',\n flexDirection: 'row',\n alignItems: 'center',\n gap: theme.space.md,\n width: '100%',\n ...theme.recipe.row,\n '& $content': {\n display: 'flex',\n flexDirection: 'column',\n gap: theme.space.xs,\n flexGrow: 1,\n minWidth: 0,\n },\n '& $label': {\n // Left-aligned to the same edge as the other fields' labels.\n textAlign: 'left',\n },\n '& $description': {\n margin: 0,\n // The whole shaded row toggles, so the description shows the toggle cursor too.\n cursor: 'pointer',\n },\n '& $track': {\n // Kept in its own column so the description never runs beneath it.\n flexShrink: 0,\n },\n },\n checked: {},\n disabled: {},\n danger: {},\n}));\n"]}
@@ -1,15 +1,30 @@
1
1
  export type TextAreaProps = {
2
+ /** Grows to fit content (min height 7rem, else 10rem; set inline, so a class can't lower it). */
2
3
  autoResize?: boolean;
4
+ /** Visible label. Not linked to the textarea (no `htmlFor`). */
3
5
  label?: string;
6
+ /** Default `'horizontal'`; `horizontal`/`vertical` paint a card-header row. */
4
7
  layout?: 'horizontal' | 'vertical' | 'inline';
8
+ /** Native limit, plus an `n/max` counter once within `max(10% of max, 50)` characters. */
5
9
  maxLength?: number;
10
+ /** The textarea's `name` and the key passed to `onValidChange`. */
6
11
  name: string;
12
+ /** Receives the string, or `undefined` when emptied; not an event. Not called while `validate` fails. */
7
13
  onChange?: (newValue: string | undefined) => void;
14
+ /** Called with `name` and the new validity; fires only when validity flips. */
8
15
  onValidChange?: (fieldName: string, newValid: boolean) => void;
16
+ /** Placeholder text for the textarea. */
9
17
  placeholder?: string;
18
+ /** Receives the raw text on each keystroke; `false` turns the label red. Default accepts all. */
10
19
  validate?: (newValue: string) => boolean;
20
+ /** Typed as required (pass `undefined` for empty). Re-syncs into the field only when the prop changes. */
11
21
  value: string | undefined;
22
+ /** `'outlined'` (default) has border and input background; `'borderless'` drops both (check dark mode). */
12
23
  variant?: 'outlined' | 'borderless';
13
24
  };
25
+ /**
26
+ * Multi-line text field with optional auto-resize and a length counter.
27
+ * Keeps its own text and re-syncs from `value` only when the prop changes.
28
+ */
14
29
  export declare const TextArea: ({ autoResize, label, layout, maxLength, name, onChange, onValidChange, placeholder, validate, value, variant, }: TextAreaProps) => import("react").JSX.Element;
15
30
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/control/text-area/index.tsx"],"names":[],"mappings":"AAKA,MAAM,MAAM,aAAa,GAAG;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,YAAY,GAAG,UAAU,GAAG,QAAQ,CAAC;IAC9C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,CAAC;IAClD,aAAa,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;IAC/D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;IACzC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,OAAO,CAAC,EAAE,UAAU,GAAG,YAAY,CAAC;CACrC,CAAC;AAEF,eAAO,MAAM,QAAQ,oHAYlB,aAAa,gCA0Ef,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/control/text-area/index.tsx"],"names":[],"mappings":"AAKA,MAAM,MAAM,aAAa,GAAG;IAC1B,iGAAiG;IACjG,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,gEAAgE;IAChE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+EAA+E;IAC/E,MAAM,CAAC,EAAE,YAAY,GAAG,UAAU,GAAG,QAAQ,CAAC;IAC9C,0FAA0F;IAC1F,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAC;IACb,yGAAyG;IACzG,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,CAAC;IAClD,+EAA+E;IAC/E,aAAa,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;IAC/D,yCAAyC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iGAAiG;IACjG,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;IACzC,0GAA0G;IAC1G,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,2GAA2G;IAC3G,OAAO,CAAC,EAAE,UAAU,GAAG,YAAY,CAAC;CACrC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,QAAQ,oHAYlB,aAAa,gCA0Ef,CAAC"}
@@ -2,6 +2,10 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import cx from 'classnames';
3
3
  import { useCallback, useEffect, useRef, useState } from 'react';
4
4
  import { useStyle } from './style.js';
5
+ /**
6
+ * Multi-line text field with optional auto-resize and a length counter.
7
+ * Keeps its own text and re-syncs from `value` only when the prop changes.
8
+ */
5
9
  export const TextArea = ({ autoResize = false, label, layout = 'horizontal', maxLength, name, onChange = () => { }, onValidChange = () => { }, placeholder, validate = () => true, value = '', variant = 'outlined', }) => {
6
10
  const style = useStyle();
7
11
  const ref = useRef(null);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/control/text-area/index.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAgBtC,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,EACvB,UAAU,GAAG,KAAK,EAClB,KAAK,EACL,MAAM,GAAG,YAAY,EACrB,SAAS,EACT,IAAI,EACJ,QAAQ,GAAG,GAAG,EAAE,GAAE,CAAC,EACnB,aAAa,GAAG,GAAG,EAAE,GAAE,CAAC,EACxB,WAAW,EACX,QAAQ,GAAG,GAAG,EAAE,CAAC,IAAI,EACrB,KAAK,GAAG,EAAE,EACV,OAAO,GAAG,UAAU,GACN,EAAE,EAAE;IAClB,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAC;IACzB,MAAM,GAAG,GAAG,MAAM,CAAsB,IAAI,CAAC,CAAC;IAE9C,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAU,IAAI,CAAC,CAAC;IACtD,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAAqB,KAAK,CAAC,CAAC;IAC9E,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAqB,KAAK,CAAC,CAAC;IAEtE,MAAM,iBAAiB,GAAG,WAAW,CACnC,CAAC,KAA6C,EAAE,EAAE;QAChD,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;QACpC,gBAAgB,CAA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;IAClF,MAAM,WAAW,GACf,SAAS,KAAK,SAAS,IAAI,SAAS,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,GAAG,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;IAE3F,OAAO,CACL,eAAK,SAAS,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,aAC1C,KAAK,IAAI,CACR,gBAAO,SAAS,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,YAAG,KAAK,GAAS,CACtF,EACD,eAAK,SAAS,EAAE,KAAK,CAAC,eAAe,aACnC,mBACE,SAAS,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,UAAU,EAAE,CAAC,EAC9E,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,iBAAiB,EAC3B,WAAW,EAAE,WAAW,EACxB,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,EACnD,KAAK,EAAE,aAAa,GACpB,EACD,WAAW,IAAI,CACd,gBACE,SAAS,EAAE,EAAE,CACX,KAAK,CAAC,OAAO,EACb,SAAS,KAAK,SAAS,IAAI,SAAS,IAAI,CAAC,IAAI,KAAK,CAAC,aAAa,CACjE,aAEA,aAAa,OAAG,SAAS,IACrB,CACR,IACG,IACF,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import cx from 'classnames';\nimport { useCallback, useEffect, useRef, useState } from 'react';\n\nimport { useStyle } from './style.js';\n\nexport type TextAreaProps = {\n autoResize?: boolean;\n label?: string;\n layout?: 'horizontal' | 'vertical' | 'inline';\n maxLength?: number;\n name: string;\n onChange?: (newValue: string | undefined) => void;\n onValidChange?: (fieldName: string, newValid: boolean) => void;\n placeholder?: string;\n validate?: (newValue: string) => boolean;\n value: string | undefined;\n variant?: 'outlined' | 'borderless';\n};\n\nexport const TextArea = ({\n autoResize = false,\n label,\n layout = 'horizontal',\n maxLength,\n name,\n onChange = () => {},\n onValidChange = () => {},\n placeholder,\n validate = () => true,\n value = '',\n variant = 'outlined',\n}: TextAreaProps) => {\n const style = useStyle();\n const ref = useRef<HTMLTextAreaElement>(null);\n\n const [isValid, setIsValid] = useState<boolean>(true);\n const [internalValue, setInternalValue] = useState<string | undefined>(value);\n const [prevValue, setPrevValue] = useState<string | undefined>(value);\n\n const handleValueChange = useCallback(\n (event: React.ChangeEvent<HTMLTextAreaElement>) => {\n const newValue = event.target.value;\n setInternalValue(newValue);\n if (validate(newValue)) {\n if (isValid === false) {\n setIsValid(true);\n onValidChange(name, true);\n }\n onChange(newValue === '' ? undefined : newValue);\n } else {\n if (isValid === true) {\n setIsValid(false);\n onValidChange(name, false);\n }\n }\n },\n [isValid, name, onChange, onValidChange, validate]\n );\n\n if (value !== prevValue) {\n setPrevValue(value);\n setInternalValue(value);\n }\n\n useEffect(() => {\n if (!autoResize || !ref.current) return;\n const el = ref.current;\n el.style.height = 'auto';\n el.style.height = `${el.scrollHeight}px`;\n }, [autoResize, internalValue]);\n\n const currentLength = (internalValue ?? '').length;\n const remaining = maxLength !== undefined ? maxLength - currentLength : undefined;\n const showCounter =\n remaining !== undefined && remaining <= Math.max(Math.floor((maxLength ?? 0) * 0.1), 50);\n\n return (\n <div className={cx(style.root, style[layout])}>\n {label && (\n <label className={cx(style.label, { [`${style.danger}`]: !isValid })}>{label}</label>\n )}\n <div className={style.textareaWrapper}>\n <textarea\n className={cx(style.input, style[variant], { [style.autoResize]: autoResize })}\n maxLength={maxLength}\n name={name}\n onChange={handleValueChange}\n placeholder={placeholder}\n ref={ref}\n style={{ minHeight: autoResize ? '7rem' : '10rem' }}\n value={internalValue}\n />\n {showCounter && (\n <span\n className={cx(\n style.counter,\n remaining !== undefined && remaining <= 0 && style.counterDanger\n )}\n >\n {currentLength}/{maxLength}\n </span>\n )}\n </div>\n </div>\n );\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/control/text-area/index.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AA2BtC;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,EACvB,UAAU,GAAG,KAAK,EAClB,KAAK,EACL,MAAM,GAAG,YAAY,EACrB,SAAS,EACT,IAAI,EACJ,QAAQ,GAAG,GAAG,EAAE,GAAE,CAAC,EACnB,aAAa,GAAG,GAAG,EAAE,GAAE,CAAC,EACxB,WAAW,EACX,QAAQ,GAAG,GAAG,EAAE,CAAC,IAAI,EACrB,KAAK,GAAG,EAAE,EACV,OAAO,GAAG,UAAU,GACN,EAAE,EAAE;IAClB,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAC;IACzB,MAAM,GAAG,GAAG,MAAM,CAAsB,IAAI,CAAC,CAAC;IAE9C,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAU,IAAI,CAAC,CAAC;IACtD,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAAqB,KAAK,CAAC,CAAC;IAC9E,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAqB,KAAK,CAAC,CAAC;IAEtE,MAAM,iBAAiB,GAAG,WAAW,CACnC,CAAC,KAA6C,EAAE,EAAE;QAChD,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM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G,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC;IAClF,MAAM,WAAW,GACf,SAAS,KAAK,SAAS,IAAI,SAAS,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,GAAG,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;IAE3F,OAAO,CACL,eAAK,SAAS,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,aAC1C,KAAK,IAAI,CACR,gBAAO,SAAS,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,YAAG,KAAK,GAAS,CACtF,EACD,eAAK,SAAS,EAAE,KAAK,CAAC,eAAe,aACnC,mBACE,SAAS,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,UAAU,EAAE,CAAC,EAC9E,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,iBAAiB,EAC3B,WAAW,EAAE,WAAW,EACxB,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,EACnD,KAAK,EAAE,aAAa,GACpB,EACD,WAAW,IAAI,CACd,gBACE,SAAS,EAAE,EAAE,CACX,KAAK,CAAC,OAAO,EACb,SAAS,KAAK,SAAS,IAAI,SAAS,IAAI,CAAC,IAAI,KAAK,CAAC,aAAa,CACjE,aAEA,aAAa,OAAG,SAAS,IACrB,CACR,IACG,IACF,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import cx from 'classnames';\nimport { useCallback, useEffect, useRef, useState } from 'react';\n\nimport { useStyle } from './style.js';\n\nexport type TextAreaProps = {\n /** Grows to fit content (min height 7rem, else 10rem; set inline, so a class can't lower it). */\n autoResize?: boolean;\n /** Visible label. Not linked to the textarea (no `htmlFor`). */\n label?: string;\n /** Default `'horizontal'`; `horizontal`/`vertical` paint a card-header row. */\n layout?: 'horizontal' | 'vertical' | 'inline';\n /** Native limit, plus an `n/max` counter once within `max(10% of max, 50)` characters. */\n maxLength?: number;\n /** The textarea's `name` and the key passed to `onValidChange`. */\n name: string;\n /** Receives the string, or `undefined` when emptied; not an event. Not called while `validate` fails. */\n onChange?: (newValue: string | undefined) => void;\n /** Called with `name` and the new validity; fires only when validity flips. */\n onValidChange?: (fieldName: string, newValid: boolean) => void;\n /** Placeholder text for the textarea. */\n placeholder?: string;\n /** Receives the raw text on each keystroke; `false` turns the label red. Default accepts all. */\n validate?: (newValue: string) => boolean;\n /** Typed as required (pass `undefined` for empty). Re-syncs into the field only when the prop changes. */\n value: string | undefined;\n /** `'outlined'` (default) has border and input background; `'borderless'` drops both (check dark mode). */\n variant?: 'outlined' | 'borderless';\n};\n\n/**\n * Multi-line text field with optional auto-resize and a length counter.\n * Keeps its own text and re-syncs from `value` only when the prop changes.\n */\nexport const TextArea = ({\n autoResize = false,\n label,\n layout = 'horizontal',\n maxLength,\n name,\n onChange = () => {},\n onValidChange = () => {},\n placeholder,\n validate = () => true,\n value = '',\n variant = 'outlined',\n}: TextAreaProps) => {\n const style = useStyle();\n const ref = useRef<HTMLTextAreaElement>(null);\n\n const [isValid, setIsValid] = useState<boolean>(true);\n const [internalValue, setInternalValue] = useState<string | undefined>(value);\n const [prevValue, setPrevValue] = useState<string | undefined>(value);\n\n const handleValueChange = useCallback(\n (event: React.ChangeEvent<HTMLTextAreaElement>) => {\n const newValue = event.target.value;\n setInternalValue(newValue);\n if (validate(newValue)) {\n if (isValid === false) {\n setIsValid(true);\n onValidChange(name, true);\n }\n onChange(newValue === '' ? undefined : newValue);\n } else {\n if (isValid === true) {\n setIsValid(false);\n onValidChange(name, false);\n }\n }\n },\n [isValid, name, onChange, onValidChange, validate]\n );\n\n if (value !== prevValue) {\n setPrevValue(value);\n setInternalValue(value);\n }\n\n useEffect(() => {\n if (!autoResize || !ref.current) return;\n const el = ref.current;\n el.style.height = 'auto';\n el.style.height = `${el.scrollHeight}px`;\n }, [autoResize, internalValue]);\n\n const currentLength = (internalValue ?? '').length;\n const remaining = maxLength !== undefined ? maxLength - currentLength : undefined;\n const showCounter =\n remaining !== undefined && remaining <= Math.max(Math.floor((maxLength ?? 0) * 0.1), 50);\n\n return (\n <div className={cx(style.root, style[layout])}>\n {label && (\n <label className={cx(style.label, { [`${style.danger}`]: !isValid })}>{label}</label>\n )}\n <div className={style.textareaWrapper}>\n <textarea\n className={cx(style.input, style[variant], { [style.autoResize]: autoResize })}\n maxLength={maxLength}\n name={name}\n onChange={handleValueChange}\n placeholder={placeholder}\n ref={ref}\n style={{ minHeight: autoResize ? '7rem' : '10rem' }}\n value={internalValue}\n />\n {showCounter && (\n <span\n className={cx(\n style.counter,\n remaining !== undefined && remaining <= 0 && style.counterDanger\n )}\n >\n {currentLength}/{maxLength}\n </span>\n )}\n </div>\n </div>\n );\n};\n"]}
@@ -1,25 +1,47 @@
1
1
  import { IconProps } from '../../icon/index.js';
2
+ /** Trailing icon button of a `TextInput`. Broken: `action` is never called. */
2
3
  type Action = {
4
+ /** Icon component, not an element. */
3
5
  icon: React.ComponentType<IconProps>;
6
+ /** Never wired up: clicking the icon does nothing. */
4
7
  action: () => void;
8
+ /** Red icon. */
5
9
  danger?: boolean;
6
10
  };
11
+ export type { Action as TextInputAction };
7
12
  export type TextInputProps = {
13
+ /** Broken, do not use: the icon button is drawn but its `action` callback is never wired up. */
8
14
  action?: Action;
15
+ /** Passed through to the input. */
9
16
  autoCapitalize?: 'none' | 'sentences' | 'words' | 'characters';
17
+ /** Passed through to the input. */
10
18
  autoComplete?: React.HTMLInputAutoCompleteAttribute | undefined;
19
+ /** Visible label. Not linked to the input (no `htmlFor`). */
11
20
  label?: string;
21
+ /** Default `'horizontal'`; `horizontal`/`vertical` paint a card-header row, `inline` paints nothing. */
12
22
  layout?: 'horizontal' | 'vertical' | 'inline';
23
+ /** Native limit, plus an `n/max` counter once within `max(10% of max, 10)` characters. */
13
24
  maxLength?: number;
25
+ /** The input's `name` (form data) and the key passed to `onValidChange`. */
14
26
  name: string;
27
+ /** Receives the string, or `undefined` when emptied; not an event. Not called while `validate` fails. */
15
28
  onChange?: (newValue: string | undefined) => void;
29
+ /** Passed through; unlike `onChange`, this one receives the event. */
16
30
  onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>) => void;
31
+ /** Called with `name` and the new validity; fires only when validity flips. */
17
32
  onValidChange?: (fieldName: string, newValid: boolean) => void;
33
+ /** Renders `type="password"`. */
18
34
  password?: boolean;
35
+ /** Placeholder text for the input. */
19
36
  placeholder?: string;
37
+ /** Receives the raw text on each keystroke; `false` turns label and border red. Default accepts all. */
20
38
  validate?: (newValue: string) => boolean;
39
+ /** Typed as required (pass `undefined` for empty). Re-syncs into the field only when the prop changes. */
21
40
  value: string | undefined;
22
41
  };
42
+ /**
43
+ * Single-line text field. Keeps its own text and re-syncs from `value` only
44
+ * when the prop changes; `onChange` is skipped while `validate` fails.
45
+ */
23
46
  export declare const TextInput: ({ autoCapitalize, autoComplete, action, label, layout, maxLength, name, onChange, onKeyDown, onValidChange, password, placeholder, validate, value, }: TextInputProps) => import("react").JSX.Element;
24
- export {};
25
47
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/control/text-input/index.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAIhD,KAAK,MAAM,GAAG;IACZ,IAAI,EAAE,KAAK,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IACrC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,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'react';
4
4
  import { Button } from '../button/index.js';
5
5
  import { useStyle } from './style.js';
6
+ /**
7
+ * Single-line text field. Keeps its own text and re-syncs from `value` only
8
+ * when the prop changes; `onChange` is skipped while `validate` fails.
9
+ */
6
10
  export const TextInput = ({ autoCapitalize, autoComplete, action, label, layout = 'horizontal', maxLength, name, onChange = () => { }, onKeyDown, onValidChange = () => { }, password = false, placeholder, validate = () => true, value = '', }) => {
7
11
  const style = useStyle();
8
12
  const [isValid, setIsValid] = useState(true);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/control/text-input/index.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAG9C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAwBtC,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,EACxB,cAAc,EACd,YAAY,EACZ,MAAM,EACN,KAAK,EACL,MAAM,GAAG,YAAY,EACrB,SAAS,EACT,IAAI,EACJ,QAAQ,GAAG,GAAG,EAAE,GAAE,CAAC,EACnB,SAAS,EACT,aAAa,GAAG,GAAG,EAAE,GAAE,CAAC,EACxB,QAAQ,GAAG,KAAK,EAChB,WAAW,EACX,QAAQ,GAAG,GAAG,EAAE,CAAC,IAAI,EACrB,KAAK,GAAG,EAAE,GACK,EAAE,EAAE;IACnB,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAC;IAEzB,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAU,IAAI,CAAC,CAAC;IACtD,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAAqB,KAAK,CAAC,CAAC;IAC9E,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAqB,KAAK,CAAC,C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CACjE,aAEA,aAAa,OAAG,SAAS,IACrB,CACR,IACG,IACF,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import cx from 'classnames';\nimport { useCallback, useState } from 'react';\n\nimport { IconProps } from '../../icon/index.js';\nimport { Button } from '../button/index.js';\nimport { useStyle } from './style.js';\n\ntype Action = {\n icon: React.ComponentType<IconProps>;\n action: () => void;\n danger?: boolean;\n};\nexport type TextInputProps = {\n action?: Action;\n autoCapitalize?: 'none' | 'sentences' | 'words' | 'characters';\n autoComplete?: React.HTMLInputAutoCompleteAttribute | undefined;\n label?: string;\n layout?: 'horizontal' | 'vertical' | 'inline';\n maxLength?: number;\n name: string;\n onChange?: (newValue: string | undefined) => void;\n onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>) => void;\n onValidChange?: (fieldName: string, newValid: boolean) => void;\n password?: boolean;\n placeholder?: string;\n validate?: (newValue: string) => boolean;\n value: string | undefined;\n};\n\nexport const TextInput = ({\n autoCapitalize,\n autoComplete,\n action,\n label,\n layout = 'horizontal',\n maxLength,\n name,\n onChange = () => {},\n onKeyDown,\n onValidChange = () => {},\n password = false,\n placeholder,\n validate = () => true,\n value = '',\n}: TextInputProps) => {\n const style = useStyle();\n\n const [isValid, setIsValid] = useState<boolean>(true);\n const [internalValue, setInternalValue] = useState<string | undefined>(value);\n const [prevValue, setPrevValue] = useState<string | undefined>(value);\n\n const handleValueChange = useCallback(\n (event: React.ChangeEvent<HTMLInputElement>) => {\n const newValue = event.target.value;\n setInternalValue(newValue);\n if (validate(newValue)) {\n if (isValid === false) {\n setIsValid(true);\n onValidChange(name, true);\n }\n onChange(newValue === '' ? undefined : newValue);\n } else {\n if (isValid === true) {\n setIsValid(false);\n onValidChange(name, false);\n }\n }\n },\n [isValid, name, onChange, onValidChange, validate]\n );\n\n if (value !== prevValue) {\n setPrevValue(value);\n setInternalValue(value);\n }\n\n const currentLength = (internalValue ?? '').length;\n const remaining = maxLength !== undefined ? maxLength - currentLength : undefined;\n // Show the counter only as the field approaches its limit. Scale the threshold\n // to the field size (10% of the max, minimum 10 chars) so a short field like a\n // name doesn't show it constantly the way a large description field would.\n const showCounter =\n remaining !== undefined && remaining <= Math.max(Math.floor((maxLength ?? 0) * 0.1), 10);\n\n return (\n <div className={cx(style.root, style[layout])}>\n {label && <label className={cx(style.label, { [style.danger]: !isValid })}>{label}</label>}\n <div className={style.inputContainer}>\n <input\n autoCapitalize={autoCapitalize}\n autoComplete={autoComplete}\n className={cx(style.input, {\n [style.danger]: !isValid,\n [style.isAction]: action !== undefined,\n })}\n maxLength={maxLength}\n name={name}\n onChange={handleValueChange}\n onKeyDown={onKeyDown}\n placeholder={placeholder}\n type={password ? 'password' : 'text'}\n value={internalValue}\n />\n {action && (\n <div className={cx(style.action)}>\n <Button type=\"link\" danger={action.danger}>\n <action.icon height={20} width={20} strokeWidth={2} />\n </Button>\n </div>\n )}\n {showCounter && (\n <span\n className={cx(\n style.counter,\n remaining !== undefined && remaining <= 0 && style.counterDanger\n )}\n >\n {currentLength}/{maxLength}\n </span>\n )}\n </div>\n </div>\n );\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/control/text-input/index.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAG9C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AA6CtC;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,EACxB,cAAc,EACd,YAAY,EACZ,MAAM,EACN,KAAK,EACL,MAAM,GAAG,YAAY,EACrB,SAAS,EACT,IAAI,EACJ,QAAQ,GAAG,GAAG,EAAE,GAAE,CAAC,EACnB,SAAS,EACT,aAAa,GAAG,GAAG,EAAE,GAAE,CAAC,EACxB,QAAQ,GAAG,KAAK,EAChB,WAAW,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AAK,CAAC,MAAM,CAAC,YAC9B,KAAC,MAAM,IAAC,IAAI,EAAC,MAAM,EAAC,MAAM,EAAE,MAAM,CAAC,MAAM,YACvC,KAAC,MAAM,CAAC,IAAI,IAAC,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC,GAAI,GAC/C,GACL,CACP,EACA,WAAW,IAAI,CACd,gBACE,SAAS,EAAE,EAAE,CACX,KAAK,CAAC,OAAO,EACb,SAAS,KAAK,SAAS,IAAI,SAAS,IAAI,CAAC,IAAI,KAAK,CAAC,aAAa,CACjE,aAEA,aAAa,OAAG,SAAS,IACrB,CACR,IACG,IACF,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import cx from 'classnames';\nimport { useCallback, useState } from 'react';\n\nimport { IconProps } from '../../icon/index.js';\nimport { Button } from '../button/index.js';\nimport { useStyle } from './style.js';\n\n/** Trailing icon button of a `TextInput`. Broken: `action` is never called. */\ntype Action = {\n /** Icon component, not an element. */\n icon: React.ComponentType<IconProps>;\n /** Never wired up: clicking the icon does nothing. */\n action: () => void;\n /** Red icon. */\n danger?: boolean;\n};\n\nexport type { Action as TextInputAction };\n\nexport type TextInputProps = {\n /** Broken, do not use: the icon button is drawn but its `action` callback is never wired up. */\n action?: Action;\n /** Passed through to the input. */\n autoCapitalize?: 'none' | 'sentences' | 'words' | 'characters';\n /** Passed through to the input. */\n autoComplete?: React.HTMLInputAutoCompleteAttribute | undefined;\n /** Visible label. Not linked to the input (no `htmlFor`). */\n label?: string;\n /** Default `'horizontal'`; `horizontal`/`vertical` paint a card-header row, `inline` paints nothing. */\n layout?: 'horizontal' | 'vertical' | 'inline';\n /** Native limit, plus an `n/max` counter once within `max(10% of max, 10)` characters. */\n maxLength?: number;\n /** The input's `name` (form data) and the key passed to `onValidChange`. */\n name: string;\n /** Receives the string, or `undefined` when emptied; not an event. Not called while `validate` fails. */\n onChange?: (newValue: string | undefined) => void;\n /** Passed through; unlike `onChange`, this one receives the event. */\n onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>) => void;\n /** Called with `name` and the new validity; fires only when validity flips. */\n onValidChange?: (fieldName: string, newValid: boolean) => void;\n /** Renders `type=\"password\"`. */\n password?: boolean;\n /** Placeholder text for the input. */\n placeholder?: string;\n /** Receives the raw text on each keystroke; `false` turns label and border red. Default accepts all. */\n validate?: (newValue: string) => boolean;\n /** Typed as required (pass `undefined` for empty). Re-syncs into the field only when the prop changes. */\n value: string | undefined;\n};\n\n/**\n * Single-line text field. Keeps its own text and re-syncs from `value` only\n * when the prop changes; `onChange` is skipped while `validate` fails.\n */\nexport const TextInput = ({\n autoCapitalize,\n autoComplete,\n action,\n label,\n layout = 'horizontal',\n maxLength,\n name,\n onChange = () => {},\n onKeyDown,\n onValidChange = () => {},\n password = false,\n placeholder,\n validate = () => true,\n value = '',\n}: TextInputProps) => {\n const style = useStyle();\n\n const [isValid, setIsValid] = useState<boolean>(true);\n const [internalValue, setInternalValue] = useState<string | undefined>(value);\n const [prevValue, setPrevValue] = useState<string | undefined>(value);\n\n const handleValueChange = useCallback(\n (event: React.ChangeEvent<HTMLInputElement>) => {\n const newValue = event.target.value;\n setInternalValue(newValue);\n if (validate(newValue)) {\n if (isValid === false) {\n setIsValid(true);\n onValidChange(name, true);\n }\n onChange(newValue === '' ? undefined : newValue);\n } else {\n if (isValid === true) {\n setIsValid(false);\n onValidChange(name, false);\n }\n }\n },\n [isValid, name, onChange, onValidChange, validate]\n );\n\n if (value !== prevValue) {\n setPrevValue(value);\n setInternalValue(value);\n }\n\n const currentLength = (internalValue ?? '').length;\n const remaining = maxLength !== undefined ? maxLength - currentLength : undefined;\n // Show the counter only as the field approaches its limit. Scale the threshold\n // to the field size (10% of the max, minimum 10 chars) so a short field like a\n // name doesn't show it constantly the way a large description field would.\n const showCounter =\n remaining !== undefined && remaining <= Math.max(Math.floor((maxLength ?? 0) * 0.1), 10);\n\n return (\n <div className={cx(style.root, style[layout])}>\n {label && <label className={cx(style.label, { [style.danger]: !isValid })}>{label}</label>}\n <div className={style.inputContainer}>\n <input\n autoCapitalize={autoCapitalize}\n autoComplete={autoComplete}\n className={cx(style.input, {\n [style.danger]: !isValid,\n [style.isAction]: action !== undefined,\n })}\n maxLength={maxLength}\n name={name}\n onChange={handleValueChange}\n onKeyDown={onKeyDown}\n placeholder={placeholder}\n type={password ? 'password' : 'text'}\n value={internalValue}\n />\n {action && (\n <div className={cx(style.action)}>\n <Button type=\"link\" danger={action.danger}>\n <action.icon height={20} width={20} strokeWidth={2} />\n </Button>\n </div>\n )}\n {showCounter && (\n <span\n className={cx(\n style.counter,\n remaining !== undefined && remaining <= 0 && style.counterDanger\n )}\n >\n {currentLength}/{maxLength}\n </span>\n )}\n </div>\n </div>\n );\n};\n"]}
@@ -1,3 +1,4 @@
1
+ import { type RefObject } from 'react';
1
2
  /**
2
3
  * Drives a native `<dialog>` from an `isOpen` flag and wires up ESC-to-dismiss.
3
4
  *
@@ -19,6 +20,11 @@
19
20
  * released over the backdrop also clicks the `<dialog>` — and must not close
20
21
  * it. Modals keep their own `onClick` only to stop the click bubbling to a
21
22
  * clickable ancestor; they no longer decide dismissal.
23
+ *
24
+ * @param isOpen The single source of truth: `true` calls `showModal()`, `false` calls `close()`.
25
+ * @param onDismiss Called on Escape and a backdrop click; receives no event and closes nothing itself.
26
+ * @param canDismiss When `false`, Escape and backdrop clicks are swallowed; pass `!loading`. Default `true`.
27
+ * @returns A ref to attach to a `<dialog>` that stays mounted.
22
28
  */
23
- export declare function useModalDialog(isOpen: boolean, onDismiss: () => void, canDismiss?: boolean): import("react").RefObject<HTMLDialogElement | null>;
29
+ export declare function useModalDialog(isOpen: boolean, onDismiss: () => void, canDismiss?: boolean): RefObject<HTMLDialogElement | null>;
24
30
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/control/use-modal-dialog/index.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,EAAE,UAAU,UAAO,uDAkDvF"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/control/use-modal-dialog/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAqB,MAAM,OAAO,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,MAAM,IAAI,EACrB,UAAU,UAAO,GAChB,SAAS,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAkDrC"}
@@ -20,6 +20,11 @@ import { useEffect, useRef } from 'react';
20
20
  * released over the backdrop also clicks the `<dialog>` — and must not close
21
21
  * it. Modals keep their own `onClick` only to stop the click bubbling to a
22
22
  * clickable ancestor; they no longer decide dismissal.
23
+ *
24
+ * @param isOpen The single source of truth: `true` calls `showModal()`, `false` calls `close()`.
25
+ * @param onDismiss Called on Escape and a backdrop click; receives no event and closes nothing itself.
26
+ * @param canDismiss When `false`, Escape and backdrop clicks are swallowed; pass `!loading`. Default `true`.
27
+ * @returns A ref to attach to a `<dialog>` that stays mounted.
23
28
  */
24
29
  export function useModalDialog(isOpen, onDismiss, canDismiss = true) {
25
30
  const ref = useRef(null);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/control/use-modal-dialog/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,cAAc,CAAC,MAAe,EAAE,SAAqB,EAAE,UAAU,GAAG,IAAI;IACtF,MAAM,GAAG,GAAG,MAAM,CAAoB,IAAI,CAAC,CAAC;IAE5C,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,OAAO,GA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C/C,OAAO,GAAG,EAAE;YACV,OAAO,CAAC,mBAAmB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;YACpD,OAAO,CAAC,mBAAmB,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;YAC1D,OAAO,CAAC,mBAAmB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QACpD,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC;IAE5B,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { useEffect, useRef } from 'react';\n\n/**\n * Drives a native `<dialog>` from an `isOpen` flag and wires up ESC-to-dismiss.\n *\n * The dialog stays fully controlled: pressing Escape fires the `cancel` event,\n * which we intercept — calling `preventDefault()` so the browser never closes\n * the dialog behind React's back — and route through `onDismiss` so the\n * `isOpen` prop remains the single source of truth.\n *\n * When `canDismiss` is false the Escape press is swallowed, so a modal whose\n * only exit is gated (a countdown, an in-flight request) can't be escaped —\n * matching a disabled confirm/done button.\n *\n * Backdrop clicks are handled here too — a modal `<dialog>` shown via\n * `showModal()` never light-dismisses on its own. A click only counts as a\n * backdrop click when the press AND the release both landed on the `<dialog>`\n * element itself (the backdrop is the dialog's own box; its content sits in a\n * child). The browser fires `click` on the common ancestor of the mousedown\n * and mouseup targets, so a text selection dragged out of an input and\n * released over the backdrop also clicks the `<dialog>` — and must not close\n * it. Modals keep their own `onClick` only to stop the click bubbling to a\n * clickable ancestor; they no longer decide dismissal.\n */\nexport function useModalDialog(isOpen: boolean, onDismiss: () => void, canDismiss = true) {\n const ref = useRef<HTMLDialogElement>(null);\n\n useEffect(() => {\n const element = ref.current;\n if (!element) {\n return;\n }\n if (isOpen) {\n element.showModal();\n } else {\n element.close();\n }\n }, [isOpen]);\n\n useEffect(() => {\n const element = ref.current;\n if (!element) {\n return;\n }\n const handleCancel = (event: Event) => {\n // Keep React in control of open/closed; never let the UA close it for us.\n event.preventDefault();\n if (canDismiss) {\n onDismiss();\n }\n };\n let pressedOnBackdrop = false;\n const handleMouseDown = (event: MouseEvent) => {\n pressedOnBackdrop = event.target === element;\n };\n const handleClick = (event: MouseEvent) => {\n const releasedOnBackdrop = event.target === element;\n const isBackdropClick = pressedOnBackdrop && releasedOnBackdrop;\n pressedOnBackdrop = false;\n if (isBackdropClick && canDismiss) {\n onDismiss();\n }\n };\n element.addEventListener('cancel', handleCancel);\n element.addEventListener('mousedown', handleMouseDown);\n element.addEventListener('click', handleClick);\n return () => {\n element.removeEventListener('cancel', handleCancel);\n element.removeEventListener('mousedown', handleMouseDown);\n element.removeEventListener('click', handleClick);\n };\n }, [onDismiss, canDismiss]);\n\n return ref;\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/control/use-modal-dialog/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,cAAc,CAC5B,MAAe,EACf,SAAqB,EACrB,UAAU,GAAG,IAAI;IAEjB,MAAM,GAAG,GAAG,MAAM,CAAoB,IAAI,CAAC,CAAC;IAE5C,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;QAC5B,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO;QACT,CAAC;QACD,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,CAAC,SAAS,EAAE,CAAC;QACtB,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,KAAK,EAAE,CAAC;QAClB,CAAC;IACH,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEb,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;QAC5B,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO;QACT,CAAC;QACD,MAAM,YAAY,GAAG,CAAC,KAAY,EAAE,EAAE;YACpC,0EAA0E;YAC1E,KAAK,CAAC,cAAc,EAAE,CAAC;YACvB,IAAI,UAAU,EAAE,CAAC;gBACf,SAAS,EAAE,CAAC;YACd,CAAC;QACH,CAAC,CAAC;QACF,IAAI,iBAAiB,GAAG,KAAK,CAAC;QAC9B,MAAM,eAAe,GAAG,CAAC,KAAiB,EAAE,EAAE;YAC5C,iBAAiB,GAAG,KAAK,CAAC,MAAM,KAAK,OAAO,CAAC;QAC/C,CAAC,CAAC;QACF,MAAM,WAAW,GAAG,CAAC,KAAiB,EAAE,EAAE;YACxC,MAAM,kBAAkB,GAAG,KAAK,CAAC,MAAM,KAAK,OAAO,CAAC;YACpD,MAAM,eAAe,GAAG,iBAAiB,IAAI,kBAAkB,CAAC;YAChE,iBAAiB,GAAG,KAAK,CAAC;YAC1B,IAAI,eAAe,IAAI,UAAU,EAAE,CAAC;gBAClC,SAAS,EAAE,CAAC;YACd,CAAC;QACH,CAAC,CAAC;QACF,OAAO,CAAC,gBAAgB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QACjD,OAAO,CAAC,gBAAgB,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;QACvD,OAAO,CAAC,gBAAgB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QAC/C,OAAO,GAAG,EAAE;YACV,OAAO,CAAC,mBAAmB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;YACpD,OAAO,CAAC,mBAAmB,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;YAC1D,OAAO,CAAC,mBAAmB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QACpD,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC;IAE5B,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { type RefObject, useEffect, useRef } from 'react';\n\n/**\n * Drives a native `<dialog>` from an `isOpen` flag and wires up ESC-to-dismiss.\n *\n * The dialog stays fully controlled: pressing Escape fires the `cancel` event,\n * which we intercept — calling `preventDefault()` so the browser never closes\n * the dialog behind React's back — and route through `onDismiss` so the\n * `isOpen` prop remains the single source of truth.\n *\n * When `canDismiss` is false the Escape press is swallowed, so a modal whose\n * only exit is gated (a countdown, an in-flight request) can't be escaped —\n * matching a disabled confirm/done button.\n *\n * Backdrop clicks are handled here too — a modal `<dialog>` shown via\n * `showModal()` never light-dismisses on its own. A click only counts as a\n * backdrop click when the press AND the release both landed on the `<dialog>`\n * element itself (the backdrop is the dialog's own box; its content sits in a\n * child). The browser fires `click` on the common ancestor of the mousedown\n * and mouseup targets, so a text selection dragged out of an input and\n * released over the backdrop also clicks the `<dialog>` — and must not close\n * it. Modals keep their own `onClick` only to stop the click bubbling to a\n * clickable ancestor; they no longer decide dismissal.\n *\n * @param isOpen The single source of truth: `true` calls `showModal()`, `false` calls `close()`.\n * @param onDismiss Called on Escape and a backdrop click; receives no event and closes nothing itself.\n * @param canDismiss When `false`, Escape and backdrop clicks are swallowed; pass `!loading`. Default `true`.\n * @returns A ref to attach to a `<dialog>` that stays mounted.\n */\nexport function useModalDialog(\n isOpen: boolean,\n onDismiss: () => void,\n canDismiss = true\n): RefObject<HTMLDialogElement | null> {\n const ref = useRef<HTMLDialogElement>(null);\n\n useEffect(() => {\n const element = ref.current;\n if (!element) {\n return;\n }\n if (isOpen) {\n element.showModal();\n } else {\n element.close();\n }\n }, [isOpen]);\n\n useEffect(() => {\n const element = ref.current;\n if (!element) {\n return;\n }\n const handleCancel = (event: Event) => {\n // Keep React in control of open/closed; never let the UA close it for us.\n event.preventDefault();\n if (canDismiss) {\n onDismiss();\n }\n };\n let pressedOnBackdrop = false;\n const handleMouseDown = (event: MouseEvent) => {\n pressedOnBackdrop = event.target === element;\n };\n const handleClick = (event: MouseEvent) => {\n const releasedOnBackdrop = event.target === element;\n const isBackdropClick = pressedOnBackdrop && releasedOnBackdrop;\n pressedOnBackdrop = false;\n if (isBackdropClick && canDismiss) {\n onDismiss();\n }\n };\n element.addEventListener('cancel', handleCancel);\n element.addEventListener('mousedown', handleMouseDown);\n element.addEventListener('click', handleClick);\n return () => {\n element.removeEventListener('cancel', handleCancel);\n element.removeEventListener('mousedown', handleMouseDown);\n element.removeEventListener('click', handleClick);\n };\n }, [onDismiss, canDismiss]);\n\n return ref;\n}\n"]}
@@ -248,6 +248,8 @@ export interface Theme {
248
248
  spinner: Recipe;
249
249
  glass: Recipe;
250
250
  glassHighlight: Recipe;
251
+ /** The shaded field row (`bg.cardHeader`, `md` corners) a control sits in inside a card. */
252
+ row: Recipe;
251
253
  modal: {
252
254
  dialog: Recipe;
253
255
  header: Recipe;