@neo4j-ndl/react 4.21.2 → 4.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/lib/cjs/_common/form-control/FormFieldLabel.js +52 -0
  2. package/lib/cjs/_common/form-control/FormFieldLabel.js.map +1 -0
  3. package/lib/cjs/_common/form-control/FormFieldMessage.js +72 -0
  4. package/lib/cjs/_common/form-control/FormFieldMessage.js.map +1 -0
  5. package/lib/cjs/_common/form-control/form-control-types.js +23 -0
  6. package/lib/cjs/_common/form-control/form-control-types.js.map +1 -0
  7. package/lib/cjs/_common/form-control/index.js +39 -0
  8. package/lib/cjs/_common/form-control/index.js.map +1 -0
  9. package/lib/cjs/_common/form-control/use-form-field.js +76 -0
  10. package/lib/cjs/_common/form-control/use-form-field.js.map +1 -0
  11. package/lib/cjs/_common/form-control/use-inline-field-label.js +76 -0
  12. package/lib/cjs/_common/form-control/use-inline-field-label.js.map +1 -0
  13. package/lib/cjs/checkbox/Checkbox.js +9 -21
  14. package/lib/cjs/checkbox/Checkbox.js.map +1 -1
  15. package/lib/cjs/combobox/Combobox.js +61 -45
  16. package/lib/cjs/combobox/Combobox.js.map +1 -1
  17. package/lib/cjs/combobox/combobox-types.js.map +1 -1
  18. package/lib/cjs/date-picker/DatePicker.js.map +1 -1
  19. package/lib/cjs/dropzone/stories/dropzone-full.story.js +5 -5
  20. package/lib/cjs/dropzone/stories/dropzone-full.story.js.map +1 -1
  21. package/lib/cjs/helpers/index.js +1 -0
  22. package/lib/cjs/helpers/index.js.map +1 -1
  23. package/lib/cjs/helpers/platform.js +59 -0
  24. package/lib/cjs/helpers/platform.js.map +1 -0
  25. package/lib/cjs/kbd/kbd-utils.js +6 -22
  26. package/lib/cjs/kbd/kbd-utils.js.map +1 -1
  27. package/lib/cjs/next/tree-view/TreeView.js +384 -66
  28. package/lib/cjs/next/tree-view/TreeView.js.map +1 -1
  29. package/lib/cjs/next/tree-view/selection.js +181 -0
  30. package/lib/cjs/next/tree-view/selection.js.map +1 -0
  31. package/lib/cjs/next/tree-view/stories/index.js +13 -1
  32. package/lib/cjs/next/tree-view/stories/index.js.map +1 -1
  33. package/lib/cjs/next/tree-view/stories/tree-view-large.story.js +57 -0
  34. package/lib/cjs/next/tree-view/stories/tree-view-large.story.js.map +1 -0
  35. package/lib/cjs/next/tree-view/stories/tree-view-lazy.story.js +1 -0
  36. package/lib/cjs/next/tree-view/stories/tree-view-lazy.story.js.map +1 -1
  37. package/lib/cjs/next/tree-view/stories/tree-view-multi.story.js +16 -40
  38. package/lib/cjs/next/tree-view/stories/tree-view-multi.story.js.map +1 -1
  39. package/lib/cjs/next/tree-view/stories/tree-view-multiple-replace.story.js +38 -0
  40. package/lib/cjs/next/tree-view/stories/tree-view-multiple-replace.story.js.map +1 -0
  41. package/lib/cjs/next/tree-view/stories/tree-view-non-selectable-folders.story.js +7 -4
  42. package/lib/cjs/next/tree-view/stories/tree-view-non-selectable-folders.story.js.map +1 -1
  43. package/lib/cjs/next/tree-view/stories/tree-view-root-selection.story.js +125 -0
  44. package/lib/cjs/next/tree-view/stories/tree-view-root-selection.story.js.map +1 -0
  45. package/lib/cjs/radio/Radio.js +12 -22
  46. package/lib/cjs/radio/Radio.js.map +1 -1
  47. package/lib/cjs/select/Select.js +14 -5
  48. package/lib/cjs/select/Select.js.map +1 -1
  49. package/lib/cjs/select/types.js.map +1 -1
  50. package/lib/cjs/switch/Switch.js +9 -21
  51. package/lib/cjs/switch/Switch.js.map +1 -1
  52. package/lib/cjs/text-area/TextArea.js +8 -21
  53. package/lib/cjs/text-area/TextArea.js.map +1 -1
  54. package/lib/cjs/text-input/TextInput.js +15 -38
  55. package/lib/cjs/text-input/TextInput.js.map +1 -1
  56. package/lib/cjs/text-input/stories/text-input-sizes.story.js +1 -1
  57. package/lib/cjs/text-input/stories/text-input-sizes.story.js.map +1 -1
  58. package/lib/cjs/time-picker/TimePicker.js +13 -7
  59. package/lib/cjs/time-picker/TimePicker.js.map +1 -1
  60. package/lib/cjs/timezone-picker/TimeZonePicker.js +13 -7
  61. package/lib/cjs/timezone-picker/TimeZonePicker.js.map +1 -1
  62. package/lib/cjs/toast/ToastControlled.js +1 -1
  63. package/lib/cjs/toast/ToastControlled.js.map +1 -1
  64. package/lib/esm/_common/form-control/FormFieldLabel.js +45 -0
  65. package/lib/esm/_common/form-control/FormFieldLabel.js.map +1 -0
  66. package/lib/esm/_common/form-control/FormFieldMessage.js +65 -0
  67. package/lib/esm/_common/form-control/FormFieldMessage.js.map +1 -0
  68. package/lib/esm/_common/form-control/form-control-types.js +22 -0
  69. package/lib/esm/_common/form-control/form-control-types.js.map +1 -0
  70. package/lib/esm/_common/form-control/index.js +32 -0
  71. package/lib/esm/_common/form-control/index.js.map +1 -0
  72. package/lib/esm/_common/form-control/use-form-field.js +72 -0
  73. package/lib/esm/_common/form-control/use-form-field.js.map +1 -0
  74. package/lib/esm/_common/form-control/use-inline-field-label.js +69 -0
  75. package/lib/esm/_common/form-control/use-inline-field-label.js.map +1 -0
  76. package/lib/esm/checkbox/Checkbox.js +10 -22
  77. package/lib/esm/checkbox/Checkbox.js.map +1 -1
  78. package/lib/esm/combobox/Combobox.js +62 -46
  79. package/lib/esm/combobox/Combobox.js.map +1 -1
  80. package/lib/esm/combobox/combobox-types.js.map +1 -1
  81. package/lib/esm/date-picker/DatePicker.js.map +1 -1
  82. package/lib/esm/dropzone/stories/dropzone-full.story.js +5 -5
  83. package/lib/esm/dropzone/stories/dropzone-full.story.js.map +1 -1
  84. package/lib/esm/helpers/index.js +1 -0
  85. package/lib/esm/helpers/index.js.map +1 -1
  86. package/lib/esm/helpers/platform.js +55 -0
  87. package/lib/esm/helpers/platform.js.map +1 -0
  88. package/lib/esm/kbd/kbd-utils.js +2 -18
  89. package/lib/esm/kbd/kbd-utils.js.map +1 -1
  90. package/lib/esm/next/tree-view/TreeView.js +385 -67
  91. package/lib/esm/next/tree-view/TreeView.js.map +1 -1
  92. package/lib/esm/next/tree-view/selection.js +175 -0
  93. package/lib/esm/next/tree-view/selection.js.map +1 -0
  94. package/lib/esm/next/tree-view/stories/index.js +9 -0
  95. package/lib/esm/next/tree-view/stories/index.js.map +1 -1
  96. package/lib/esm/next/tree-view/stories/tree-view-large.story.js +55 -0
  97. package/lib/esm/next/tree-view/stories/tree-view-large.story.js.map +1 -0
  98. package/lib/esm/next/tree-view/stories/tree-view-lazy.story.js +1 -0
  99. package/lib/esm/next/tree-view/stories/tree-view-lazy.story.js.map +1 -1
  100. package/lib/esm/next/tree-view/stories/tree-view-multi.story.js +16 -40
  101. package/lib/esm/next/tree-view/stories/tree-view-multi.story.js.map +1 -1
  102. package/lib/esm/next/tree-view/stories/tree-view-multiple-replace.story.js +36 -0
  103. package/lib/esm/next/tree-view/stories/tree-view-multiple-replace.story.js.map +1 -0
  104. package/lib/esm/next/tree-view/stories/tree-view-non-selectable-folders.story.js +7 -4
  105. package/lib/esm/next/tree-view/stories/tree-view-non-selectable-folders.story.js.map +1 -1
  106. package/lib/esm/next/tree-view/stories/tree-view-root-selection.story.js +123 -0
  107. package/lib/esm/next/tree-view/stories/tree-view-root-selection.story.js.map +1 -0
  108. package/lib/esm/radio/Radio.js +12 -22
  109. package/lib/esm/radio/Radio.js.map +1 -1
  110. package/lib/esm/select/Select.js +14 -5
  111. package/lib/esm/select/Select.js.map +1 -1
  112. package/lib/esm/select/types.js.map +1 -1
  113. package/lib/esm/switch/Switch.js +10 -22
  114. package/lib/esm/switch/Switch.js.map +1 -1
  115. package/lib/esm/text-area/TextArea.js +9 -22
  116. package/lib/esm/text-area/TextArea.js.map +1 -1
  117. package/lib/esm/text-input/TextInput.js +15 -38
  118. package/lib/esm/text-input/TextInput.js.map +1 -1
  119. package/lib/esm/text-input/stories/text-input-sizes.story.js +1 -1
  120. package/lib/esm/text-input/stories/text-input-sizes.story.js.map +1 -1
  121. package/lib/esm/time-picker/TimePicker.js +13 -7
  122. package/lib/esm/time-picker/TimePicker.js.map +1 -1
  123. package/lib/esm/timezone-picker/TimeZonePicker.js +13 -7
  124. package/lib/esm/timezone-picker/TimeZonePicker.js.map +1 -1
  125. package/lib/esm/toast/ToastControlled.js +1 -1
  126. package/lib/esm/toast/ToastControlled.js.map +1 -1
  127. package/lib/types/_common/form-control/FormFieldLabel.d.ts +58 -0
  128. package/lib/types/_common/form-control/FormFieldLabel.d.ts.map +1 -0
  129. package/lib/types/_common/form-control/FormFieldMessage.d.ts +46 -0
  130. package/lib/types/_common/form-control/FormFieldMessage.d.ts.map +1 -0
  131. package/lib/types/_common/form-control/form-control-types.d.ts +92 -0
  132. package/lib/types/_common/form-control/form-control-types.d.ts.map +1 -0
  133. package/lib/types/_common/form-control/index.d.ts +33 -0
  134. package/lib/types/_common/form-control/index.d.ts.map +1 -0
  135. package/lib/types/_common/form-control/use-form-field.d.ts +53 -0
  136. package/lib/types/_common/form-control/use-form-field.d.ts.map +1 -0
  137. package/lib/types/_common/form-control/use-inline-field-label.d.ts +69 -0
  138. package/lib/types/_common/form-control/use-inline-field-label.d.ts.map +1 -0
  139. package/lib/types/checkbox/Checkbox.d.ts.map +1 -1
  140. package/lib/types/combobox/Combobox.d.ts.map +1 -1
  141. package/lib/types/combobox/combobox-types.d.ts +1 -1
  142. package/lib/types/combobox/combobox-types.d.ts.map +1 -1
  143. package/lib/types/helpers/index.d.ts +1 -0
  144. package/lib/types/helpers/index.d.ts.map +1 -1
  145. package/lib/types/helpers/platform.d.ts +29 -0
  146. package/lib/types/helpers/platform.d.ts.map +1 -0
  147. package/lib/types/kbd/kbd-utils.d.ts +2 -5
  148. package/lib/types/kbd/kbd-utils.d.ts.map +1 -1
  149. package/lib/types/next/tree-view/TreeView.d.ts +29 -5
  150. package/lib/types/next/tree-view/TreeView.d.ts.map +1 -1
  151. package/lib/types/next/tree-view/selection.d.ts +78 -0
  152. package/lib/types/next/tree-view/selection.d.ts.map +1 -0
  153. package/lib/types/next/tree-view/stories/index.d.ts +6 -0
  154. package/lib/types/next/tree-view/stories/index.d.ts.map +1 -1
  155. package/lib/types/next/tree-view/stories/tree-view-large.story.d.ts +24 -0
  156. package/lib/types/next/tree-view/stories/tree-view-large.story.d.ts.map +1 -0
  157. package/lib/types/next/tree-view/stories/tree-view-lazy.story.d.ts.map +1 -1
  158. package/lib/types/next/tree-view/stories/tree-view-multi.story.d.ts +10 -0
  159. package/lib/types/next/tree-view/stories/tree-view-multi.story.d.ts.map +1 -1
  160. package/lib/types/next/tree-view/stories/tree-view-multiple-replace.story.d.ts +29 -0
  161. package/lib/types/next/tree-view/stories/tree-view-multiple-replace.story.d.ts.map +1 -0
  162. package/lib/types/next/tree-view/stories/tree-view-non-selectable-folders.story.d.ts +5 -0
  163. package/lib/types/next/tree-view/stories/tree-view-non-selectable-folders.story.d.ts.map +1 -1
  164. package/lib/types/next/tree-view/stories/tree-view-root-selection.story.d.ts +24 -0
  165. package/lib/types/next/tree-view/stories/tree-view-root-selection.story.d.ts.map +1 -0
  166. package/lib/types/radio/Radio.d.ts.map +1 -1
  167. package/lib/types/select/Select.d.ts.map +1 -1
  168. package/lib/types/select/types.d.ts.map +1 -1
  169. package/lib/types/switch/Switch.d.ts.map +1 -1
  170. package/lib/types/text-area/TextArea.d.ts.map +1 -1
  171. package/lib/types/text-input/TextInput.d.ts.map +1 -1
  172. package/lib/types/text-input/stories/text-input-sizes.story.d.ts.map +1 -1
  173. package/lib/types/time-picker/TimePicker.d.ts +3 -1
  174. package/lib/types/time-picker/TimePicker.d.ts.map +1 -1
  175. package/lib/types/timezone-picker/TimeZonePicker.d.ts +4 -1
  176. package/lib/types/timezone-picker/TimeZonePicker.d.ts.map +1 -1
  177. package/package.json +2 -2
  178. package/skills/ndl-react/SKILL.md +1 -1
  179. package/skills/ndl-react/components/color-picker.md +32 -32
  180. package/skills/ndl-react/components/combobox.md +2 -2
  181. package/skills/ndl-react/components/dropzone.md +5 -5
  182. package/skills/ndl-react/components/next/tree-view.md +444 -104
  183. package/skills/ndl-react/components/text-input.md +6 -0
  184. package/skills/ndl-react/components/time-picker.md +1 -0
  185. package/skills/ndl-react/components/timezone-picker.md +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormFieldLabel.js","sourceRoot":"","sources":["../../../../src/_common/form-control/FormFieldLabel.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,UAAU,MAAM,YAAY,CAAC;AAGpC,OAAO,EAAE,4BAA4B,EAAE,MAAM,8DAA8D,CAAC;AAC5G,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AA+B9C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,EAC7B,KAAK,EACL,IAAI,EACJ,WAAW,GAAG,UAAU,EACxB,YAAY,EACZ,mBAAmB,EACnB,YAAY,EACZ,SAAS,EACT,IAAI,GACgB,EAAE,EAAE;IACxB,MAAM,EACJ,KAAK,EACL,OAAO,EACP,SAAS,EACT,sBAAsB,EACtB,oBAAoB,EACpB,UAAU,GACX,GAAG,KAAK,CAAC;IACV,MAAM,OAAO,GAAG,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,aAAa,CAAC;IAChE,MAAM,UAAU,GAAG,WAAW,KAAK,UAAU,CAAC;IAC9C,MAAM,sBAAsB,GAAG,UAAU,CAAC;QACxC,4BAA4B,EAAE,IAAI,KAAK,OAAO;QAC9C,4BAA4B,EAAE,IAAI,KAAK,OAAO,IAAI,IAAI,KAAK,QAAQ;KACpE,CAAC,CAAC;IAEH,MAAM,GAAG,GAAG,CACV,eACE,SAAS,EAAE,UAAU,CACnB,oBAAoB,EACpB,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,EACjD,SAAS,CACV,aAED,KAAC,UAAU,IACT,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,EACjC,OAAO,EAAE,OAAO,EAChB,SAAS,EAAC,gBAAgB,EAC1B,cAAc,EACZ,UAAU;oBACR,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE;oBAC5D,CAAC,CAAC,SAAS,YAGd,KAAK,GACK,EACZ,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAC/B,MAAC,OAAO,kBAAC,IAAI,EAAC,QAAQ,IAAK,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,IAAI,eAC3C,KAAC,OAAO,CAAC,OAAO,oBACV,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,OAAO,IACzB,SAAS,EAAE,sBAAsB,EACjC,gBAAgB,kBAEhB,cACE,QAAQ,EAAE,CAAC,EACX,IAAI,EAAC,QAAQ,gBACF,kBAAkB,iBACjB,sBAAsB,YAElC,KAAC,4BAA4B,KAAG,GAC5B,IACU,EAClB,KAAC,OAAO,CAAC,OAAO,oBAAK,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,OAAO,cACvC,mBAAmB,IACJ,KACV,CACX,EACA,oBAAoB,IAAI,CACvB,KAAC,UAAU,IAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAC,0BAA0B,YAC/D,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,GAC1B,CACd,IACG,CACP,CAAC;IAEF,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,4BAAG,IAAI,CAAC,GAAG,CAAC,GAAI,CAAC;AACrD,CAAC,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport classNames from 'classnames';\nimport type React from 'react';\n\nimport { InformationCircleIconOutline } from '../../icons/generated/heroIcons/InformationCircleIconOutline';\nimport { Tooltip } from '../../tooltip';\nimport { Typography } from '../../typography';\nimport { type TooltipObjectProps } from '../types';\nimport { type FormFieldSize, type FormFieldState } from './form-control-types';\n\ntype FormFieldLabelProps = {\n field: FormFieldState;\n size: FormFieldSize;\n /**\n * How the label is associated with its control. `explicit` renders a\n * `<label>` pointing at the control through `htmlFor`, carrying `labelId`\n * for `aria-labelledby`. `implicit` renders plain text, for components\n * whose control is wrapped by an enclosing `<label>`, where a nested label\n * element would be invalid.\n */\n association?: 'explicit' | 'implicit';\n /**\n * Click handler for an explicit label, for controls that need more than\n * the default `htmlFor` focus forwarding (the Combobox label must move\n * focus without toggling the panel).\n */\n onLabelClick?: React.MouseEventHandler<HTMLLabelElement>;\n /** Text displayed in an information tooltip next to the label */\n moreInformationText?: React.ReactNode;\n /** Props for the Tooltip component used by the information icon */\n tooltipProps?: TooltipObjectProps;\n /** Extra class names for the label row */\n className?: string;\n /** Wraps the rendered row, so a component can put it inside a Skeleton. */\n wrap?: (row: React.ReactNode) => React.ReactNode;\n};\n\n/**\n * The label row of a form field: the label itself, an optional information\n * tooltip, and the Required/Optional indicator. The indicator and the tooltip\n * are separate elements rather than label content, keeping them out of the\n * control's accessible name.\n */\nexport const FormFieldLabel = ({\n field,\n size,\n association = 'explicit',\n onLabelClick,\n moreInformationText,\n tooltipProps,\n className,\n wrap,\n}: FormFieldLabelProps) => {\n const {\n label,\n labelId,\n controlId,\n hasVisuallyHiddenLabel,\n hasRequiredIndicator,\n isRequired,\n } = field;\n const variant = size === 'large' ? 'body-large' : 'body-medium';\n const isExplicit = association === 'explicit';\n const informationIconClasses = classNames({\n 'ndl-information-icon-large': size === 'large',\n 'ndl-information-icon-small': size === 'small' || size === 'medium',\n });\n\n const row = (\n <div\n className={classNames(\n 'ndl-form-label-row',\n { 'ndl-visually-hidden': hasVisuallyHiddenLabel },\n className,\n )}\n >\n <Typography\n as={isExplicit ? 'label' : 'span'}\n variant={variant}\n className=\"ndl-form-label\"\n htmlAttributes={\n isExplicit\n ? { htmlFor: controlId, id: labelId, onClick: onLabelClick }\n : undefined\n }\n >\n {label}\n </Typography>\n {Boolean(moreInformationText) && (\n <Tooltip type=\"simple\" {...tooltipProps?.root}>\n <Tooltip.Trigger\n {...tooltipProps?.trigger}\n className={informationIconClasses}\n hasButtonWrapper\n >\n <div\n tabIndex={0}\n role=\"button\"\n aria-label=\"Information icon\"\n data-testid=\"ndl-information-icon\"\n >\n <InformationCircleIconOutline />\n </div>\n </Tooltip.Trigger>\n <Tooltip.Content {...tooltipProps?.content}>\n {moreInformationText}\n </Tooltip.Content>\n </Tooltip>\n )}\n {hasRequiredIndicator && (\n <Typography variant={variant} className=\"ndl-form-label-indicator\">\n {isRequired ? 'Required' : 'Optional'}\n </Typography>\n )}\n </div>\n );\n\n return wrap === undefined ? row : <>{wrap(row)}</>;\n};\n"]}
@@ -0,0 +1,65 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ *
4
+ * Copyright (c) "Neo4j"
5
+ * Neo4j Sweden AB [http://neo4j.com]
6
+ *
7
+ * This file is part of Neo4j.
8
+ *
9
+ * Neo4j is free software: you can redistribute it and/or modify
10
+ * it under the terms of the GNU General Public License as published by
11
+ * the Free Software Foundation, either version 3 of the License, or
12
+ * (at your option) any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ * GNU General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU General Public License
20
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
21
+ */
22
+ import classNames from 'classnames';
23
+ import { ExclamationCircleIconSolid } from '../../icons/generated/heroIcons/ExclamationCircleIconSolid';
24
+ import { Typography } from '../../typography';
25
+ /**
26
+ * How each severity presents itself. A future severity (`info`, `warning`) or
27
+ * a new way of presenting a message extends this map rather than reshaping
28
+ * the components that render messages.
29
+ */
30
+ const presentationBySeverity = {
31
+ error: { className: 'ndl-error', icon: ExclamationCircleIconSolid },
32
+ help: {},
33
+ };
34
+ /**
35
+ * The message below a form field: the help text, or the error that replaces
36
+ * it. The container is rendered whether or not there is a message, so the
37
+ * `aria-live` region exists in the document before any text arrives and a
38
+ * validation error is reliably announced. The stylesheet collapses it while
39
+ * it is empty.
40
+ *
41
+ * The region is polite rather than an assertive `role="alert"`, since
42
+ * validation that runs on blur or on change would otherwise interrupt
43
+ * whatever is being read. `aria-atomic` makes the whole message announce as
44
+ * one, matching `role="status"` without presenting plain help text as a
45
+ * status message.
46
+ */
47
+ export const FormFieldMessage = ({ field, size, className, wrap, }) => {
48
+ const { message, messageId, messageSeverity } = field;
49
+ const variant = size === 'large' ? 'body-medium' : 'body-small';
50
+ const presentation = messageSeverity === undefined
51
+ ? undefined
52
+ : presentationBySeverity[messageSeverity];
53
+ const Icon = presentation === null || presentation === void 0 ? void 0 : presentation.icon;
54
+ const content = messageSeverity === undefined ? null : (
55
+ // The icon and the text share a row of their own, so the container stays
56
+ // a plain block that anything wrapping the content, a Skeleton in
57
+ // particular, can fill the width of.
58
+ _jsxs("div", { className: "ndl-form-message-content", children: [Icon !== undefined && (_jsx("div", { className: "ndl-form-message-icon", "aria-hidden": "true", children: _jsx(Icon, {}) })), _jsx(Typography, { variant: variant, className: "ndl-form-message-text", htmlAttributes: { id: messageId }, children: message })] }));
59
+ return (_jsx("div", { className: classNames('ndl-form-message', {
60
+ 'ndl-large': size === 'large',
61
+ 'ndl-medium': size === 'medium',
62
+ 'ndl-small': size === 'small',
63
+ }, presentation === null || presentation === void 0 ? void 0 : presentation.className, className), "aria-live": "polite", "aria-atomic": "true", children: content !== null && (wrap === undefined ? content : wrap(content)) }));
64
+ };
65
+ //# sourceMappingURL=FormFieldMessage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormFieldMessage.js","sourceRoot":"","sources":["../../../../src/_common/form-control/FormFieldMessage.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,UAAU,MAAM,YAAY,CAAC;AAGpC,OAAO,EAAE,0BAA0B,EAAE,MAAM,4DAA4D,CAAC;AACxG,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAc9C;;;;GAIG;AACH,MAAM,sBAAsB,GAGxB;IACF,KAAK,EAAE,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,EAAE,0BAA0B,EAAE;IACnE,IAAI,EAAE,EAAE;CACT,CAAC;AAWF;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,EAC/B,KAAK,EACL,IAAI,EACJ,SAAS,EACT,IAAI,GACkB,EAAE,EAAE;IAC1B,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,GAAG,KAAK,CAAC;IACtD,MAAM,OAAO,GAAG,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,YAAY,CAAC;IAChE,MAAM,YAAY,GAChB,eAAe,KAAK,SAAS;QAC3B,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,sBAAsB,CAAC,eAAe,CAAC,CAAC;IAC9C,MAAM,IAAI,GAAG,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,IAAI,CAAC;IAEhC,MAAM,OAAO,GACX,eAAe,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IACrC,yEAAyE;IACzE,kEAAkE;IAClE,qCAAqC;IACrC,eAAK,SAAS,EAAC,0BAA0B,aACtC,IAAI,KAAK,SAAS,IAAI,CACrB,cAAK,SAAS,EAAC,uBAAuB,iBAAa,MAAM,YACvD,KAAC,IAAI,KAAG,GACJ,CACP,EACD,KAAC,UAAU,IACT,OAAO,EAAE,OAAO,EAChB,SAAS,EAAC,uBAAuB,EACjC,cAAc,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,YAEhC,OAAO,GACG,IACT,CACP,CAAC;IAEJ,OAAO,CACL,cACE,SAAS,EAAE,UAAU,CACnB,kBAAkB,EAClB;YACE,WAAW,EAAE,IAAI,KAAK,OAAO;YAC7B,YAAY,EAAE,IAAI,KAAK,QAAQ;YAC/B,WAAW,EAAE,IAAI,KAAK,OAAO;SAC9B,EACD,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,SAAS,EACvB,SAAS,CACV,eACS,QAAQ,iBACN,MAAM,YAEjB,OAAO,KAAK,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAC/D,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport classNames from 'classnames';\nimport type React from 'react';\n\nimport { ExclamationCircleIconSolid } from '../../icons/generated/heroIcons/ExclamationCircleIconSolid';\nimport { Typography } from '../../typography';\nimport {\n type FormFieldMessageSeverity,\n type FormFieldSize,\n type FormFieldState,\n} from './form-control-types';\n\ntype FormFieldMessagePresentation = {\n /** Icon rendered before the message text. */\n icon?: React.ComponentType;\n /** Severity modifier class on the message container. */\n className?: string;\n};\n\n/**\n * How each severity presents itself. A future severity (`info`, `warning`) or\n * a new way of presenting a message extends this map rather than reshaping\n * the components that render messages.\n */\nconst presentationBySeverity: Record<\n FormFieldMessageSeverity,\n FormFieldMessagePresentation\n> = {\n error: { className: 'ndl-error', icon: ExclamationCircleIconSolid },\n help: {},\n};\n\ntype FormFieldMessageProps = {\n field: FormFieldState;\n size: FormFieldSize;\n /** Extra class names for the message container */\n className?: string;\n /** Wraps the message content, so a component can put it inside a Skeleton. */\n wrap?: (content: React.ReactNode) => React.ReactNode;\n};\n\n/**\n * The message below a form field: the help text, or the error that replaces\n * it. The container is rendered whether or not there is a message, so the\n * `aria-live` region exists in the document before any text arrives and a\n * validation error is reliably announced. The stylesheet collapses it while\n * it is empty.\n *\n * The region is polite rather than an assertive `role=\"alert\"`, since\n * validation that runs on blur or on change would otherwise interrupt\n * whatever is being read. `aria-atomic` makes the whole message announce as\n * one, matching `role=\"status\"` without presenting plain help text as a\n * status message.\n */\nexport const FormFieldMessage = ({\n field,\n size,\n className,\n wrap,\n}: FormFieldMessageProps) => {\n const { message, messageId, messageSeverity } = field;\n const variant = size === 'large' ? 'body-medium' : 'body-small';\n const presentation =\n messageSeverity === undefined\n ? undefined\n : presentationBySeverity[messageSeverity];\n const Icon = presentation?.icon;\n\n const content =\n messageSeverity === undefined ? null : (\n // The icon and the text share a row of their own, so the container stays\n // a plain block that anything wrapping the content, a Skeleton in\n // particular, can fill the width of.\n <div className=\"ndl-form-message-content\">\n {Icon !== undefined && (\n <div className=\"ndl-form-message-icon\" aria-hidden=\"true\">\n <Icon />\n </div>\n )}\n <Typography\n variant={variant}\n className=\"ndl-form-message-text\"\n htmlAttributes={{ id: messageId }}\n >\n {message}\n </Typography>\n </div>\n );\n\n return (\n <div\n className={classNames(\n 'ndl-form-message',\n {\n 'ndl-large': size === 'large',\n 'ndl-medium': size === 'medium',\n 'ndl-small': size === 'small',\n },\n presentation?.className,\n className,\n )}\n aria-live=\"polite\"\n aria-atomic=\"true\"\n >\n {content !== null && (wrap === undefined ? content : wrap(content))}\n </div>\n );\n};\n"]}
@@ -0,0 +1,22 @@
1
+ /**
2
+ *
3
+ * Copyright (c) "Neo4j"
4
+ * Neo4j Sweden AB [http://neo4j.com]
5
+ *
6
+ * This file is part of Neo4j.
7
+ *
8
+ * Neo4j is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ */
21
+ export {};
22
+ //# sourceMappingURL=form-control-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form-control-types.js","sourceRoot":"","sources":["../../../../src/_common/form-control/form-control-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport type React from 'react';\n\n/** Sizes shared by the form field parts, matching the input sizes. */\ntype FormFieldSize = 'small' | 'medium' | 'large';\n\n/**\n * Severity of the message shown below a form control. An error replaces the\n * help text whenever both are provided.\n *\n * Deliberately a union rather than an error boolean: future severities such\n * as `info` and `warning`, or new ways of presenting a message, only extend\n * this union and the severity presentation map in `FormFieldMessage`.\n */\ntype FormFieldMessageSeverity = 'help' | 'error';\n\n/**\n * The field-related props a form input component maps onto the internal form\n * field. Components pick from these internally so wording, types and behavior\n * stay aligned, while their external prop names stay untouched (for example\n * both TextInput's `showRequiredOrOptionalLabel` and TextArea's `isOptional`\n * map onto `hasRequiredIndicator` here).\n */\ntype FormFieldProps = {\n /** The label displayed above the control */\n label?: React.ReactNode;\n\n /** Assistive text displayed below the control */\n helpText?: React.ReactNode;\n\n /** Error message displayed below the control. When provided, it overrides `helpText` and shows an error icon */\n errorText?: React.ReactNode;\n\n /** Whether the control is required */\n isRequired?: boolean;\n\n /** Whether Required or Optional is shown at the end of the label row */\n hasRequiredIndicator?: boolean;\n\n /** Whether the label is clipped out of the layout, leaving it to screen readers only */\n hasVisuallyHiddenLabel?: boolean;\n};\n\n/**\n * The resolved state of a form field: the ids that tie the label and the\n * message to the control, and which message is currently displayed. Built by\n * `useFormField` and consumed by `FormFieldLabel` and `FormFieldMessage`, so\n * a component never wires ids or picks between help and error itself.\n */\ntype FormFieldState = {\n label?: React.ReactNode;\n /** Id of the label element, for `aria-labelledby` on ARIA widgets. */\n labelId: string;\n /** Id of the control, which an explicit label points at with `htmlFor`. */\n controlId: string;\n /** Id the help text renders with, referenced while it is displayed. */\n helpTextId: string;\n /** Id the error text renders with, referenced while it is displayed. */\n errorTextId: string;\n helpText?: React.ReactNode;\n errorText?: React.ReactNode;\n /** The displayed message. The error text while there is one, else the help text. */\n message?: React.ReactNode;\n /** Id of the displayed message; `undefined` while there is no message. */\n messageId?: string;\n /** Severity of the displayed message; `undefined` while there is no message. */\n messageSeverity?: FormFieldMessageSeverity;\n hasError: boolean;\n isRequired: boolean;\n hasRequiredIndicator: boolean;\n hasVisuallyHiddenLabel: boolean;\n};\n\n// These are DOM attribute names, so the boolean naming convention cannot apply.\n/* eslint-disable @typescript-eslint/naming-convention */\n/**\n * ARIA attributes for the control the field describes. Spread onto the input\n * or the ARIA widget acting as one.\n */\ntype FormFieldControlProps = {\n 'aria-describedby': string | undefined;\n 'aria-invalid': true | undefined;\n};\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport type {\n FormFieldControlProps,\n FormFieldMessageSeverity,\n FormFieldProps,\n FormFieldSize,\n FormFieldState,\n};\n"]}
@@ -0,0 +1,32 @@
1
+ /**
2
+ *
3
+ * Copyright (c) "Neo4j"
4
+ * Neo4j Sweden AB [http://neo4j.com]
5
+ *
6
+ * This file is part of Neo4j.
7
+ *
8
+ * Neo4j is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ */
21
+ /**
22
+ * The internal form control layer (DES-1772): one implementation of the
23
+ * label, the required indicator, the help text and the error message shared
24
+ * by the form input components, plus the ARIA wiring that ties them to the
25
+ * control. Internal only - not exported from the package index - so a future
26
+ * public field API can be built on top without being constrained by it.
27
+ */
28
+ export { FormFieldLabel } from './FormFieldLabel';
29
+ export { FormFieldMessage } from './FormFieldMessage';
30
+ export { useFormField } from './use-form-field';
31
+ export { useInlineFieldLabel } from './use-inline-field-label';
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/_common/form-control/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH;;;;;;GAMG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAQtD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\n/**\n * The internal form control layer (DES-1772): one implementation of the\n * label, the required indicator, the help text and the error message shared\n * by the form input components, plus the ARIA wiring that ties them to the\n * control. Internal only - not exported from the package index - so a future\n * public field API can be built on top without being constrained by it.\n */\n\nexport { FormFieldLabel } from './FormFieldLabel';\nexport { FormFieldMessage } from './FormFieldMessage';\nexport type {\n FormFieldControlProps,\n FormFieldMessageSeverity,\n FormFieldProps,\n FormFieldSize,\n FormFieldState,\n} from './form-control-types';\nexport { useFormField } from './use-form-field';\nexport { useInlineFieldLabel } from './use-inline-field-label';\n"]}
@@ -0,0 +1,72 @@
1
+ /**
2
+ *
3
+ * Copyright (c) "Neo4j"
4
+ * Neo4j Sweden AB [http://neo4j.com]
5
+ *
6
+ * This file is part of Neo4j.
7
+ *
8
+ * Neo4j is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ */
21
+ import { useId } from 'react';
22
+ /**
23
+ * Resolves the shared form field state: id generation, which of help and
24
+ * error is displayed - an error always replaces the help text - and the ARIA
25
+ * wiring of the control. The parts are rendered by `FormFieldLabel` and
26
+ * `FormFieldMessage`.
27
+ */
28
+ export const useFormField = ({ baseId, controlId, label, helpText, errorText, isRequired = false, hasRequiredIndicator = false, hasVisuallyHiddenLabel = false, extraDescribedByIds = [], }) => {
29
+ const generatedBaseId = useId();
30
+ const base = baseId !== null && baseId !== void 0 ? baseId : generatedBaseId;
31
+ const labelId = `${base}-label`;
32
+ const helpTextId = `${base}-help-text`;
33
+ const errorTextId = `${base}-error-text`;
34
+ const resolvedControlId = controlId !== null && controlId !== void 0 ? controlId : `${base}-control`;
35
+ const hasError = Boolean(errorText);
36
+ const hasHelpText = Boolean(helpText) && !hasError;
37
+ const messageSeverity = hasError
38
+ ? 'error'
39
+ : hasHelpText
40
+ ? 'help'
41
+ : undefined;
42
+ const message = hasError ? errorText : hasHelpText ? helpText : undefined;
43
+ const messageId = hasError
44
+ ? errorTextId
45
+ : hasHelpText
46
+ ? helpTextId
47
+ : undefined;
48
+ const describedByIds = [...extraDescribedByIds, messageId].filter((id) => typeof id === 'string' && id !== '');
49
+ return {
50
+ controlProps: {
51
+ 'aria-describedby': describedByIds.length > 0 ? describedByIds.join(' ') : undefined,
52
+ 'aria-invalid': hasError ? true : undefined,
53
+ },
54
+ field: {
55
+ controlId: resolvedControlId,
56
+ errorText,
57
+ errorTextId,
58
+ hasError,
59
+ hasRequiredIndicator,
60
+ hasVisuallyHiddenLabel,
61
+ helpText,
62
+ helpTextId,
63
+ isRequired,
64
+ label,
65
+ labelId,
66
+ message,
67
+ messageId,
68
+ messageSeverity,
69
+ },
70
+ };
71
+ };
72
+ //# sourceMappingURL=use-form-field.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-form-field.js","sourceRoot":"","sources":["../../../../src/_common/form-control/use-form-field.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAkC9B;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,EAC3B,MAAM,EACN,SAAS,EACT,KAAK,EACL,QAAQ,EACR,SAAS,EACT,UAAU,GAAG,KAAK,EAClB,oBAAoB,GAAG,KAAK,EAC5B,sBAAsB,GAAG,KAAK,EAC9B,mBAAmB,GAAG,EAAE,GACJ,EAAsB,EAAE;IAC5C,MAAM,eAAe,GAAG,KAAK,EAAE,CAAC;IAChC,MAAM,IAAI,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,eAAe,CAAC;IACvC,MAAM,OAAO,GAAG,GAAG,IAAI,QAAQ,CAAC;IAChC,MAAM,UAAU,GAAG,GAAG,IAAI,YAAY,CAAC;IACvC,MAAM,WAAW,GAAG,GAAG,IAAI,aAAa,CAAC;IACzC,MAAM,iBAAiB,GAAG,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,GAAG,IAAI,UAAU,CAAC;IAEzD,MAAM,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IACpC,MAAM,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC;IACnD,MAAM,eAAe,GAAyC,QAAQ;QACpE,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,WAAW;YACX,CAAC,CAAC,MAAM;YACR,CAAC,CAAC,SAAS,CAAC;IAChB,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IAC1E,MAAM,SAAS,GAAG,QAAQ;QACxB,CAAC,CAAC,WAAW;QACb,CAAC,CAAC,WAAW;YACX,CAAC,CAAC,UAAU;YACZ,CAAC,CAAC,SAAS,CAAC;IAEhB,MAAM,cAAc,GAAG,CAAC,GAAG,mBAAmB,EAAE,SAAS,CAAC,CAAC,MAAM,CAC/D,CAAC,EAAE,EAAgB,EAAE,CAAC,OAAO,EAAE,KAAK,QAAQ,IAAI,EAAE,KAAK,EAAE,CAC1D,CAAC;IAEF,OAAO;QACL,YAAY,EAAE;YACZ,kBAAkB,EAChB,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS;YAClE,cAAc,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;SAC5C;QACD,KAAK,EAAE;YACL,SAAS,EAAE,iBAAiB;YAC5B,SAAS;YACT,WAAW;YACX,QAAQ;YACR,oBAAoB;YACpB,sBAAsB;YACtB,QAAQ;YACR,UAAU;YACV,UAAU;YACV,KAAK;YACL,OAAO;YACP,OAAO;YACP,SAAS;YACT,eAAe;SAChB;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport { useId } from 'react';\n\nimport {\n type FormFieldControlProps,\n type FormFieldMessageSeverity,\n type FormFieldProps,\n type FormFieldState,\n} from './form-control-types';\n\ntype UseFormFieldOptions = FormFieldProps & {\n /**\n * Base for the generated ids, so a component that mints sibling ids of its\n * own (like the Combobox listbox and panel ids) can share one base.\n * Defaults to a generated id.\n */\n baseId?: string;\n /**\n * Overrides the generated control id, for controls that already name their\n * id (the Combobox trigger is `${baseId}-trigger`).\n */\n controlId?: string;\n /**\n * Ids referenced by `aria-describedby` before the message id, skipping\n * falsy entries (such as the TextInput clear/loading hint).\n */\n extraDescribedByIds?: (string | false | undefined)[];\n};\n\ntype UseFormFieldResult = {\n field: FormFieldState;\n /** ARIA attributes to spread onto the control the field describes. */\n controlProps: FormFieldControlProps;\n};\n\n/**\n * Resolves the shared form field state: id generation, which of help and\n * error is displayed - an error always replaces the help text - and the ARIA\n * wiring of the control. The parts are rendered by `FormFieldLabel` and\n * `FormFieldMessage`.\n */\nexport const useFormField = ({\n baseId,\n controlId,\n label,\n helpText,\n errorText,\n isRequired = false,\n hasRequiredIndicator = false,\n hasVisuallyHiddenLabel = false,\n extraDescribedByIds = [],\n}: UseFormFieldOptions): UseFormFieldResult => {\n const generatedBaseId = useId();\n const base = baseId ?? generatedBaseId;\n const labelId = `${base}-label`;\n const helpTextId = `${base}-help-text`;\n const errorTextId = `${base}-error-text`;\n const resolvedControlId = controlId ?? `${base}-control`;\n\n const hasError = Boolean(errorText);\n const hasHelpText = Boolean(helpText) && !hasError;\n const messageSeverity: FormFieldMessageSeverity | undefined = hasError\n ? 'error'\n : hasHelpText\n ? 'help'\n : undefined;\n const message = hasError ? errorText : hasHelpText ? helpText : undefined;\n const messageId = hasError\n ? errorTextId\n : hasHelpText\n ? helpTextId\n : undefined;\n\n const describedByIds = [...extraDescribedByIds, messageId].filter(\n (id): id is string => typeof id === 'string' && id !== '',\n );\n\n return {\n controlProps: {\n 'aria-describedby':\n describedByIds.length > 0 ? describedByIds.join(' ') : undefined,\n 'aria-invalid': hasError ? true : undefined,\n },\n field: {\n controlId: resolvedControlId,\n errorText,\n errorTextId,\n hasError,\n hasRequiredIndicator,\n hasVisuallyHiddenLabel,\n helpText,\n helpTextId,\n isRequired,\n label,\n labelId,\n message,\n messageId,\n messageSeverity,\n },\n };\n};\n"]}
@@ -0,0 +1,69 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ *
4
+ * Copyright (c) "Neo4j"
5
+ * Neo4j Sweden AB [http://neo4j.com]
6
+ *
7
+ * This file is part of Neo4j.
8
+ *
9
+ * Neo4j is free software: you can redistribute it and/or modify
10
+ * it under the terms of the GNU General Public License as published by
11
+ * the Free Software Foundation, either version 3 of the License, or
12
+ * (at your option) any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ * GNU General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU General Public License
20
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
21
+ */
22
+ import classNames from 'classnames';
23
+ import { useEffect, useMemo } from 'react';
24
+ import { needleWarningMessage } from '../utils';
25
+ /**
26
+ * The inline label of a selection control (Checkbox, Radio, Switch): the
27
+ * control and its label text sit side by side inside one wrapping `<label>`.
28
+ * A string label is wrapped in a titled span so a truncated label stays
29
+ * readable through its tooltip; a custom node is rendered as given, which is
30
+ * also why it needs `ariaLabel` to name the control. Warns when neither a
31
+ * label nor an aria label is provided.
32
+ *
33
+ * Returns the classes of the wrapping label along with its content, so that
34
+ * an adopting component never names a shared class itself. Typography and
35
+ * color sit on that wrapper rather than on the span here, so that a custom
36
+ * node inherits them too.
37
+ *
38
+ * TODO v5: wrap a custom node as well, once the DOM of a custom label can
39
+ * change. This would own all label styling, and the difference between the
40
+ * full-strength inline label and the weaker label above a control could then
41
+ * become a prop here instead of living in two stylesheet classes.
42
+ */
43
+ export const useInlineFieldLabel = ({ componentName, label, ariaLabel, isDisabled = false, isFluid = false, isTruncated = false, }) => {
44
+ useEffect(() => {
45
+ if (Boolean(label) === false && Boolean(ariaLabel) === false) {
46
+ needleWarningMessage(`${componentName} needs a valid label or ariaLabel: https://dequeuniversity.com/rules/axe/4.2/label?application=axeAPI`);
47
+ }
48
+ }, [ariaLabel, componentName, label]);
49
+ const labelContent = useMemo(() => {
50
+ if (Boolean(label) === false) {
51
+ return null;
52
+ }
53
+ if (typeof label === 'string') {
54
+ return (_jsx("span", { title: label, className: classNames('ndl-form-inline-label-text', {
55
+ 'ndl-disabled': isDisabled,
56
+ 'ndl-truncated': isTruncated,
57
+ }), children: label }));
58
+ }
59
+ return label;
60
+ }, [label, isDisabled, isTruncated]);
61
+ return {
62
+ fieldClassName: classNames('ndl-form-inline-field', {
63
+ 'ndl-disabled': isDisabled,
64
+ 'ndl-fluid': isFluid,
65
+ }),
66
+ labelContent,
67
+ };
68
+ };
69
+ //# sourceMappingURL=use-inline-field-label.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-inline-field-label.js","sourceRoot":"","sources":["../../../../src/_common/form-control/use-inline-field-label.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAmChD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,EAClC,aAAa,EACb,KAAK,EACL,SAAS,EACT,UAAU,GAAG,KAAK,EAClB,OAAO,GAAG,KAAK,EACf,WAAW,GAAG,KAAK,GACQ,EAA6B,EAAE;IAC1D,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,IAAI,OAAO,CAAC,SAAS,CAAC,KAAK,KAAK,EAAE,CAAC;YAC7D,oBAAoB,CAClB,GAAG,aAAa,uGAAuG,CACxH,CAAC;QACJ,CAAC;IACH,CAAC,EAAE,CAAC,SAAS,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC,CAAC;IAEtC,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,EAAE;QAChC,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO,CACL,eACE,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,UAAU,CAAC,4BAA4B,EAAE;oBAClD,cAAc,EAAE,UAAU;oBAC1B,eAAe,EAAE,WAAW;iBAC7B,CAAC,YAED,KAAK,GACD,CACR,CAAC;QACJ,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;IAErC,OAAO;QACL,cAAc,EAAE,UAAU,CAAC,uBAAuB,EAAE;YAClD,cAAc,EAAE,UAAU;YAC1B,WAAW,EAAE,OAAO;SACrB,CAAC;QACF,YAAY;KACb,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport classNames from 'classnames';\nimport { useEffect, useMemo } from 'react';\n\nimport { needleWarningMessage } from '../utils';\n\ntype UseInlineFieldLabelOptions = {\n /** Component name used in the missing-label console warning. */\n componentName: string;\n /** The label rendered next to the control, inside its wrapping `<label>`. */\n label: React.ReactNode;\n // TODO v5: only needed while naming a selection control is split across\n // `label` and `ariaLabel`. Whenever the label alone names the control, as it\n // does on Combobox, the warning below has nothing left to check.\n /** The aria label naming the control when the label is not a string. */\n ariaLabel: string | undefined;\n /** Dims the label and the control it belongs to. */\n isDisabled?: boolean;\n /** Lets the field take the full available width of its container. */\n isFluid?: boolean;\n /**\n * Truncates an overflowing string label to one line with an ellipsis (the\n * `title` set on the span keeps the full text reachable). Radio behavior\n * today; a candidate to unify across all selection controls in v5.\n */\n isTruncated?: boolean;\n};\n\ntype UseInlineFieldLabelResult = {\n /** The label, rendered next to the control. */\n labelContent: React.ReactNode;\n /**\n * Classes for the `<label>` that wraps the control and the label, which the\n * adopting component renders. Owned here so that the shared classes stay an\n * implementation detail of this module.\n */\n fieldClassName: string;\n};\n\n/**\n * The inline label of a selection control (Checkbox, Radio, Switch): the\n * control and its label text sit side by side inside one wrapping `<label>`.\n * A string label is wrapped in a titled span so a truncated label stays\n * readable through its tooltip; a custom node is rendered as given, which is\n * also why it needs `ariaLabel` to name the control. Warns when neither a\n * label nor an aria label is provided.\n *\n * Returns the classes of the wrapping label along with its content, so that\n * an adopting component never names a shared class itself. Typography and\n * color sit on that wrapper rather than on the span here, so that a custom\n * node inherits them too.\n *\n * TODO v5: wrap a custom node as well, once the DOM of a custom label can\n * change. This would own all label styling, and the difference between the\n * full-strength inline label and the weaker label above a control could then\n * become a prop here instead of living in two stylesheet classes.\n */\nexport const useInlineFieldLabel = ({\n componentName,\n label,\n ariaLabel,\n isDisabled = false,\n isFluid = false,\n isTruncated = false,\n}: UseInlineFieldLabelOptions): UseInlineFieldLabelResult => {\n useEffect(() => {\n if (Boolean(label) === false && Boolean(ariaLabel) === false) {\n needleWarningMessage(\n `${componentName} needs a valid label or ariaLabel: https://dequeuniversity.com/rules/axe/4.2/label?application=axeAPI`,\n );\n }\n }, [ariaLabel, componentName, label]);\n\n const labelContent = useMemo(() => {\n if (Boolean(label) === false) {\n return null;\n }\n\n if (typeof label === 'string') {\n return (\n <span\n title={label}\n className={classNames('ndl-form-inline-label-text', {\n 'ndl-disabled': isDisabled,\n 'ndl-truncated': isTruncated,\n })}\n >\n {label}\n </span>\n );\n }\n\n return label;\n }, [label, isDisabled, isTruncated]);\n\n return {\n fieldClassName: classNames('ndl-form-inline-field', {\n 'ndl-disabled': isDisabled,\n 'ndl-fluid': isFluid,\n }),\n labelContent,\n };\n};\n"]}
@@ -32,9 +32,9 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
32
32
  */
33
33
  import { useMergeRefs } from '@floating-ui/react';
34
34
  import classNames from 'classnames';
35
- import { useEffect, useMemo, useRef } from 'react';
35
+ import { useEffect, useRef } from 'react';
36
+ import { useInlineFieldLabel } from '../_common/form-control';
36
37
  import { useSemiControlledInput } from '../_common/use-semi-controlled-input';
37
- import { needleWarningMessage } from '../_common/utils';
38
38
  export const Checkbox = (_a) => {
39
39
  var _b;
40
40
  var { isChecked, isDefaultChecked, isIndeterminate = false, isFluid = false, isDisabled = false, hasLeadingLabel, ariaLabel, onChange, onClick, value, label, className, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["isChecked", "isDefaultChecked", "isIndeterminate", "isFluid", "isDisabled", "hasLeadingLabel", "ariaLabel", "onChange", "onClick", "value", "label", "className", "style", "htmlAttributes", "ref"]);
@@ -46,10 +46,6 @@ export const Checkbox = (_a) => {
46
46
  onChange,
47
47
  state: (_b = isChecked !== null && isChecked !== void 0 ? isChecked : isDefaultChecked) !== null && _b !== void 0 ? _b : false,
48
48
  });
49
- const labelWrappingClasses = classNames('ndl-checkbox-label', {
50
- 'ndl-disabled': isDisabled,
51
- 'ndl-fluid': isFluid,
52
- });
53
49
  const checkboxClasses = classNames('ndl-checkbox', className, {
54
50
  'ndl-disabled': isDisabled,
55
51
  });
@@ -58,21 +54,13 @@ export const Checkbox = (_a) => {
58
54
  internalRef.current.indeterminate = isIndeterminate;
59
55
  }
60
56
  }, [isIndeterminate]);
61
- /** TODO: Label handling. We can get rid of this annoying stuff as soon as we do proper form control. */
62
- const labelContent = useMemo(() => {
63
- if (Boolean(label) === false) {
64
- return null;
65
- }
66
- if (typeof label === 'string') {
67
- return (_jsx("span", { title: label, className: "ndl-checkbox-label-text", children: label }));
68
- }
69
- return label;
70
- }, [label]);
71
- useEffect(() => {
72
- if (Boolean(label) === false && Boolean(ariaLabel) === false) {
73
- needleWarningMessage('Checkbox needs a valid label or ariaLabel: https://dequeuniversity.com/rules/axe/4.2/label?application=axeAPI');
74
- }
75
- }, [ariaLabel, label]);
76
- return (_jsxs("label", { className: labelWrappingClasses, children: [hasLeadingLabel === true && labelContent, _jsx("input", Object.assign({ ref: mergedRefs, type: "checkbox", "aria-label": ariaLabel, disabled: isDisabled, checked: isCheckedState, onClick: onClick, onChange: internalOnChange, value: value, style: style, className: checkboxClasses }, restProps, htmlAttributes)), Boolean(hasLeadingLabel) === false && labelContent] }));
57
+ const { labelContent, fieldClassName } = useInlineFieldLabel({
58
+ ariaLabel,
59
+ componentName: 'Checkbox',
60
+ isDisabled,
61
+ isFluid,
62
+ label,
63
+ });
64
+ return (_jsxs("label", { className: fieldClassName, children: [hasLeadingLabel === true && labelContent, _jsx("input", Object.assign({ ref: mergedRefs, type: "checkbox", "aria-label": ariaLabel, disabled: isDisabled, checked: isCheckedState, onClick: onClick, onChange: internalOnChange, value: value, style: style, className: checkboxClasses }, restProps, htmlAttributes)), Boolean(hasLeadingLabel) === false && labelContent] }));
77
65
  };
78
66
  //# sourceMappingURL=Checkbox.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Checkbox.js","sourceRoot":"","sources":["../../../src/checkbox/Checkbox.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAGnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAkCxD,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,EAiBa,EAAE,EAAE;;QAjBjB,EACvB,SAAS,EACT,gBAAgB,EAChB,eAAe,GAAG,KAAK,EACvB,OAAO,GAAG,KAAK,EACf,UAAU,GAAG,KAAK,EAClB,eAAe,EACf,SAAS,EACT,QAAQ,EACR,OAAO,EACP,KAAK,EACL,KAAK,EACL,SAAS,EACT,KAAK,EACL,cAAc,EACd,GAAG,OAEiC,EADjC,SAAS,cAhBW,qMAiBxB,CADa;IAEZ,MAAM,WAAW,GAAG,MAAM,CAAmB,IAAI,CAAC,CAAC;IACnD,MAAM,UAAU,GAAG,YAAY,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC;IAEpD,MAAM,CAAC,cAAc,EAAE,gBAAgB,CAAC,GAAG,sBAAsB,CAAC;QAChE,SAAS,EAAE,UAAU;QACrB,YAAY,EAAE,SAAS,KAAK,SAAS;QACrC,QAAQ;QACR,KAAK,EAAE,MAAA,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,gBAAgB,mCAAI,KAAK;KAC9C,CAAC,CAAC;IAEH,MAAM,oBAAoB,GAAG,UAAU,CAAC,oBAAoB,EAAE;QAC5D,cAAc,EAAE,UAAU;QAC1B,WAAW,EAAE,OAAO;KACrB,CAAC,CAAC;IAEH,MAAM,eAAe,GAAG,UAAU,CAAC,cAAc,EAAE,SAAS,EAAE;QAC5D,cAAc,EAAE,UAAU;KAC3B,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,WAAW,CAAC,OAAO,EAAE,CAAC;YACxB,WAAW,CAAC,OAAO,CAAC,aAAa,GAAG,eAAe,CAAC;QACtD,CAAC;IACH,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;IAEtB,wGAAwG;IACxG,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,EAAE;QAChC,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO,CACL,eAAM,KAAK,EAAE,KAAK,EAAE,SAAS,EAAC,yBAAyB,YACpD,KAAK,GACD,CACR,CAAC;QACJ,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,IAAI,OAAO,CAAC,SAAS,CAAC,KAAK,KAAK,EAAE,CAAC;YAC7D,oBAAoB,CAClB,+GAA+G,CAChH,CAAC;QACJ,CAAC;IACH,CAAC,EAAE,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;IAEvB,OAAO,CACL,iBAAO,SAAS,EAAE,oBAAoB,aACnC,eAAe,KAAK,IAAI,IAAI,YAAY,EACzC,8BACE,GAAG,EAAE,UAAU,EACf,IAAI,EAAC,UAAU,gBACH,SAAS,EACrB,QAAQ,EAAE,UAAU,EACpB,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,gBAAgB,EAC1B,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,eAAe,IACtB,SAAS,EACT,cAAc,EAClB,EACD,OAAO,CAAC,eAAe,CAAC,KAAK,KAAK,IAAI,YAAY,IAC7C,CACT,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport { useMergeRefs } from '@floating-ui/react';\nimport classNames from 'classnames';\nimport { useEffect, useMemo, useRef } from 'react';\n\nimport { type CommonProps, type HtmlAttributes } from '../_common/types';\nimport { useSemiControlledInput } from '../_common/use-semi-controlled-input';\nimport { needleWarningMessage } from '../_common/utils';\n\ntype CheckboxProps = {\n /** Whether the checkbox is checked */\n isChecked?: boolean;\n /** Checks the input by default in uncontrolled mode */\n isDefaultChecked?: boolean; // isDefaultChecked sounds weird to me?\n /** Whether the checkbox is indeterminate */\n isIndeterminate?: boolean;\n /** Whether the checkbox is disabled */\n isDisabled?: boolean;\n /** Whether the checkbox & label should take the full available width of its container */\n isFluid?: boolean;\n /** The value of the checkbox */\n value?: HtmlAttributes<'input'>['value']; // should this be required?\n /** Whether the label should be displayed before the checkbox */\n hasLeadingLabel?: boolean;\n /** The callback function triggered when the checkbox value changes */\n onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;\n /** The callback function triggered when the checkbox is clicked */\n onClick?: (event: React.MouseEvent<HTMLInputElement>) => void;\n} & (\n | {\n /** The aria label of the checkbox. Required if the label is not a string. */\n ariaLabel: string;\n /** The label of the checkbox. If not a string, supply an aria label for screen reader support. */\n label?: undefined;\n }\n | {\n ariaLabel?: string;\n label: React.ReactNode;\n }\n);\n\nexport const Checkbox = ({\n isChecked,\n isDefaultChecked,\n isIndeterminate = false,\n isFluid = false,\n isDisabled = false,\n hasLeadingLabel,\n ariaLabel,\n onChange,\n onClick,\n value,\n label,\n className,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: CommonProps<'input', CheckboxProps>) => {\n const internalRef = useRef<HTMLInputElement>(null);\n const mergedRefs = useMergeRefs([internalRef, ref]);\n\n const [isCheckedState, internalOnChange] = useSemiControlledInput({\n inputType: 'checkbox',\n isControlled: isChecked !== undefined,\n onChange,\n state: isChecked ?? isDefaultChecked ?? false,\n });\n\n const labelWrappingClasses = classNames('ndl-checkbox-label', {\n 'ndl-disabled': isDisabled,\n 'ndl-fluid': isFluid,\n });\n\n const checkboxClasses = classNames('ndl-checkbox', className, {\n 'ndl-disabled': isDisabled,\n });\n\n useEffect(() => {\n if (internalRef.current) {\n internalRef.current.indeterminate = isIndeterminate;\n }\n }, [isIndeterminate]);\n\n /** TODO: Label handling. We can get rid of this annoying stuff as soon as we do proper form control. */\n const labelContent = useMemo(() => {\n if (Boolean(label) === false) {\n return null;\n }\n\n if (typeof label === 'string') {\n return (\n <span title={label} className=\"ndl-checkbox-label-text\">\n {label}\n </span>\n );\n }\n return label;\n }, [label]);\n\n useEffect(() => {\n if (Boolean(label) === false && Boolean(ariaLabel) === false) {\n needleWarningMessage(\n 'Checkbox needs a valid label or ariaLabel: https://dequeuniversity.com/rules/axe/4.2/label?application=axeAPI',\n );\n }\n }, [ariaLabel, label]);\n\n return (\n <label className={labelWrappingClasses}>\n {hasLeadingLabel === true && labelContent}\n <input\n ref={mergedRefs}\n type=\"checkbox\"\n aria-label={ariaLabel}\n disabled={isDisabled}\n checked={isCheckedState}\n onClick={onClick}\n onChange={internalOnChange}\n value={value}\n style={style}\n className={checkboxClasses}\n {...restProps}\n {...htmlAttributes}\n />\n {Boolean(hasLeadingLabel) === false && labelContent}\n </label>\n );\n};\n"]}
1
+ {"version":3,"file":"Checkbox.js","sourceRoot":"","sources":["../../../src/checkbox/Checkbox.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAE9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAuC9E,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,EAiBa,EAAE,EAAE;;QAjBjB,EACvB,SAAS,EACT,gBAAgB,EAChB,eAAe,GAAG,KAAK,EACvB,OAAO,GAAG,KAAK,EACf,UAAU,GAAG,KAAK,EAClB,eAAe,EACf,SAAS,EACT,QAAQ,EACR,OAAO,EACP,KAAK,EACL,KAAK,EACL,SAAS,EACT,KAAK,EACL,cAAc,EACd,GAAG,OAEiC,EADjC,SAAS,cAhBW,qMAiBxB,CADa;IAEZ,MAAM,WAAW,GAAG,MAAM,CAAmB,IAAI,CAAC,CAAC;IACnD,MAAM,UAAU,GAAG,YAAY,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC;IAEpD,MAAM,CAAC,cAAc,EAAE,gBAAgB,CAAC,GAAG,sBAAsB,CAAC;QAChE,SAAS,EAAE,UAAU;QACrB,YAAY,EAAE,SAAS,KAAK,SAAS;QACrC,QAAQ;QACR,KAAK,EAAE,MAAA,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,gBAAgB,mCAAI,KAAK;KAC9C,CAAC,CAAC;IAEH,MAAM,eAAe,GAAG,UAAU,CAAC,cAAc,EAAE,SAAS,EAAE;QAC5D,cAAc,EAAE,UAAU;KAC3B,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,WAAW,CAAC,OAAO,EAAE,CAAC;YACxB,WAAW,CAAC,OAAO,CAAC,aAAa,GAAG,eAAe,CAAC;QACtD,CAAC;IACH,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;IAEtB,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,GAAG,mBAAmB,CAAC;QAC3D,SAAS;QACT,aAAa,EAAE,UAAU;QACzB,UAAU;QACV,OAAO;QACP,KAAK;KACN,CAAC,CAAC;IAEH,OAAO,CACL,iBAAO,SAAS,EAAE,cAAc,aAC7B,eAAe,KAAK,IAAI,IAAI,YAAY,EACzC,8BACE,GAAG,EAAE,UAAU,EACf,IAAI,EAAC,UAAU,gBACH,SAAS,EACrB,QAAQ,EAAE,UAAU,EACpB,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,gBAAgB,EAC1B,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,eAAe,IACtB,SAAS,EACT,cAAc,EAClB,EACD,OAAO,CAAC,eAAe,CAAC,KAAK,KAAK,IAAI,YAAY,IAC7C,CACT,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport { useMergeRefs } from '@floating-ui/react';\nimport classNames from 'classnames';\nimport { useEffect, useRef } from 'react';\n\nimport { useInlineFieldLabel } from '../_common/form-control';\nimport { type CommonProps, type HtmlAttributes } from '../_common/types';\nimport { useSemiControlledInput } from '../_common/use-semi-controlled-input';\n\ntype CheckboxProps = {\n /** Whether the checkbox is checked */\n isChecked?: boolean;\n /** Checks the input by default in uncontrolled mode */\n isDefaultChecked?: boolean; // isDefaultChecked sounds weird to me?\n /** Whether the checkbox is indeterminate */\n isIndeterminate?: boolean;\n /** Whether the checkbox is disabled */\n isDisabled?: boolean;\n /** Whether the checkbox & label should take the full available width of its container */\n isFluid?: boolean;\n /** The value of the checkbox */\n value?: HtmlAttributes<'input'>['value']; // should this be required?\n /** Whether the label should be displayed before the checkbox */\n hasLeadingLabel?: boolean;\n /** The callback function triggered when the checkbox value changes */\n onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;\n /** The callback function triggered when the checkbox is clicked */\n onClick?: (event: React.MouseEvent<HTMLInputElement>) => void;\n} & (\n | {\n /** The aria label of the checkbox. Required if the label is not a string. */\n ariaLabel: string;\n // TODO v5: inconsistent naming. Naming the checkbox takes a union of\n // `label` and `ariaLabel`, so the accessible name comes from a different\n // prop depending on what the label renders. Combobox instead requires the\n // label and clips it with `hasVisuallyHiddenLabel`, and TextInput reaches\n // for htmlAttributes['aria-label'].\n /** The label of the checkbox. If not a string, supply an aria label for screen reader support. */\n label?: undefined;\n }\n | {\n ariaLabel?: string;\n label: React.ReactNode;\n }\n);\n\nexport const Checkbox = ({\n isChecked,\n isDefaultChecked,\n isIndeterminate = false,\n isFluid = false,\n isDisabled = false,\n hasLeadingLabel,\n ariaLabel,\n onChange,\n onClick,\n value,\n label,\n className,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: CommonProps<'input', CheckboxProps>) => {\n const internalRef = useRef<HTMLInputElement>(null);\n const mergedRefs = useMergeRefs([internalRef, ref]);\n\n const [isCheckedState, internalOnChange] = useSemiControlledInput({\n inputType: 'checkbox',\n isControlled: isChecked !== undefined,\n onChange,\n state: isChecked ?? isDefaultChecked ?? false,\n });\n\n const checkboxClasses = classNames('ndl-checkbox', className, {\n 'ndl-disabled': isDisabled,\n });\n\n useEffect(() => {\n if (internalRef.current) {\n internalRef.current.indeterminate = isIndeterminate;\n }\n }, [isIndeterminate]);\n\n const { labelContent, fieldClassName } = useInlineFieldLabel({\n ariaLabel,\n componentName: 'Checkbox',\n isDisabled,\n isFluid,\n label,\n });\n\n return (\n <label className={fieldClassName}>\n {hasLeadingLabel === true && labelContent}\n <input\n ref={mergedRefs}\n type=\"checkbox\"\n aria-label={ariaLabel}\n disabled={isDisabled}\n checked={isCheckedState}\n onClick={onClick}\n onChange={internalOnChange}\n value={value}\n style={style}\n className={checkboxClasses}\n {...restProps}\n {...htmlAttributes}\n />\n {Boolean(hasLeadingLabel) === false && labelContent}\n </label>\n );\n};\n"]}
@@ -34,13 +34,14 @@ import { FloatingFocusManager, FloatingPortal, useMergeRefs, } from '@floating-u
34
34
  import { useVirtualizer } from '@tanstack/react-virtual';
35
35
  import classNames from 'classnames';
36
36
  import { Fragment, useEffect, useId, useMemo, useRef, useState } from 'react';
37
+ import { FormFieldLabel, FormFieldMessage, useFormField, } from '../_common/form-control';
37
38
  import { useSemicontrolledState } from '../_common/use-semi-controlled-state';
38
39
  import { needleWarningMessage } from '../_common/utils';
39
40
  import { Checkbox } from '../checkbox';
40
41
  import { ConditionalWrap } from '../conditional-wrap';
41
42
  import { DismissibleTag } from '../dismissible-tag';
42
43
  import { Divider } from '../divider';
43
- import { CheckIconOutline, ChevronDownIconOutline, ExclamationCircleIconSolid, MagnifyingGlassIconOutline, PlusIconOutline, XMarkIconOutline, } from '../icons/generated/heroIcons';
44
+ import { CheckIconOutline, ChevronDownIconOutline, MagnifyingGlassIconOutline, PlusIconOutline, XMarkIconOutline, } from '../icons/generated/heroIcons';
44
45
  import { LoadingSpinner } from '../loading-spinner';
45
46
  import { ReadOnlyTag } from '../read-only-tag';
46
47
  import { useNeedleTheme } from '../theme';
@@ -102,9 +103,6 @@ export const Combobox = ({ label, name, formId, autoComplete, triggerRef, hasVis
102
103
  const listboxId = `${baseId}-listbox`;
103
104
  const panelId = `${baseId}-panel`;
104
105
  const triggerId = `${baseId}-trigger`;
105
- const labelId = `${baseId}-label`;
106
- const helpTextId = `${baseId}-help-text`;
107
- const errorTextId = `${baseId}-error-text`;
108
106
  const initialValue = getInitialValue(value, defaultValue, isMulti);
109
107
  const [selectedValue, setSelectedValue, resetSelectedValue] = useSemicontrolledState({
110
108
  isControlled: value !== undefined,
@@ -462,13 +460,22 @@ export const Combobox = ({ label, name, formId, autoComplete, triggerRef, hasVis
462
460
  ? actionRows.map((row) => getOptionId(row)).join(' ')
463
461
  : undefined;
464
462
  const isDialogPanel = isSearchable;
465
- // An error replaces the help text, so only one message is ever rendered and
466
- // only that one is described.
467
- const displayedErrorText = errorText !== null && errorText !== void 0 ? errorText : nativeValidationMessage;
468
- const hasError = Boolean(displayedErrorText);
469
- const hasHelpText = Boolean(helpText) && !hasError;
470
- const messageId = hasError ? errorTextId : helpTextId;
471
- const describedById = hasError || hasHelpText ? messageId : undefined;
463
+ // The shared form field resolves the ids and which message is displayed -
464
+ // an error always replaces the help text. A native validation failure
465
+ // reported by the hidden form control acts as the error while no errorText
466
+ // is set.
467
+ const { field: formField, controlProps: fieldControlProps } = useFormField({
468
+ baseId,
469
+ controlId: triggerId,
470
+ errorText: errorText !== null && errorText !== void 0 ? errorText : nativeValidationMessage,
471
+ hasRequiredIndicator,
472
+ hasVisuallyHiddenLabel,
473
+ helpText,
474
+ isRequired,
475
+ label,
476
+ });
477
+ const hasError = formField.hasError;
478
+ const labelId = formField.labelId;
472
479
  const triggerAria = {
473
480
  'aria-activedescendant': isPanelOpen && !isSearchable ? activeOptionId : undefined,
474
481
  'aria-controls': getTriggerControlsId({
@@ -478,11 +485,11 @@ export const Combobox = ({ label, name, formId, autoComplete, triggerRef, hasVis
478
485
  listboxId,
479
486
  panelId,
480
487
  }),
481
- 'aria-describedby': describedById,
488
+ 'aria-describedby': fieldControlProps['aria-describedby'],
482
489
  'aria-disabled': isDisabled ? true : undefined,
483
490
  'aria-expanded': isPanelOpen,
484
491
  'aria-haspopup': isDialogPanel ? 'dialog' : 'listbox',
485
- 'aria-invalid': hasError ? true : undefined,
492
+ 'aria-invalid': fieldControlProps['aria-invalid'],
486
493
  'aria-required': isRequired ? true : undefined,
487
494
  // The label points at the trigger through `htmlFor`, so clicking it moves
488
495
  // focus to the trigger.
@@ -502,13 +509,13 @@ export const Combobox = ({ label, name, formId, autoComplete, triggerRef, hasVis
502
509
  // is referenced, keeping "Optional" out of the accessible name.
503
510
  'aria-labelledby': labelId, ref: builtInTriggerRef });
504
511
  const field = {
505
- errorText: displayedErrorText,
506
- errorTextId,
512
+ errorText: formField.errorText,
513
+ errorTextId: formField.errorTextId,
507
514
  hasError,
508
515
  hasRequiredIndicator,
509
516
  hasVisuallyHiddenLabel,
510
517
  helpText,
511
- helpTextId,
518
+ helpTextId: formField.helpTextId,
512
519
  isRequired,
513
520
  label,
514
521
  labelId,
@@ -595,6 +602,42 @@ const getSelectedOptions = (value) => {
595
602
  }
596
603
  return value === null ? [] : [value];
597
604
  };
605
+ /**
606
+ * The public `ComboboxFieldState` keeps its own shape - a custom trigger
607
+ * renders from it - so the built-in field parts map it onto the shared form
608
+ * field state (`_common/form-control`) instead of taking it directly.
609
+ */
610
+ const toFormFieldState = (field) => {
611
+ const hasHelpText = Boolean(field.helpText) && !field.hasError;
612
+ return {
613
+ controlId: field.triggerId,
614
+ errorText: field.errorText,
615
+ errorTextId: field.errorTextId,
616
+ hasError: field.hasError,
617
+ hasRequiredIndicator: field.hasRequiredIndicator,
618
+ hasVisuallyHiddenLabel: field.hasVisuallyHiddenLabel,
619
+ helpText: field.helpText,
620
+ helpTextId: field.helpTextId,
621
+ isRequired: field.isRequired,
622
+ label: field.label,
623
+ labelId: field.labelId,
624
+ message: field.hasError
625
+ ? field.errorText
626
+ : hasHelpText
627
+ ? field.helpText
628
+ : undefined,
629
+ messageId: field.hasError
630
+ ? field.errorTextId
631
+ : hasHelpText
632
+ ? field.helpTextId
633
+ : undefined,
634
+ messageSeverity: field.hasError
635
+ ? 'error'
636
+ : hasHelpText
637
+ ? 'help'
638
+ : undefined,
639
+ };
640
+ };
598
641
  /**
599
642
  * A native select mirrors the custom control for submission, autofill,
600
643
  * constraint validation, and reset. It is hidden from assistive technology
@@ -691,6 +734,7 @@ const Control = ({ triggerProps, state, field, placeholder, isClearable, isClean
691
734
  const { isOpen, isMulti, isDisabled, selectedOptions, clear, remove } = state;
692
735
  const { MultiValue, SingleValue } = components;
693
736
  const { ref: triggerRef } = triggerProps, triggerAria = __rest(triggerProps, ["ref"]);
737
+ const sharedField = toFormFieldState(field);
694
738
  const hasValue = selectedOptions.length > 0;
695
739
  const singleValueOption = isMulti ? undefined : selectedOptions[0];
696
740
  // Selected values are shown as tags, so the trigger renders nothing and is
@@ -800,7 +844,7 @@ const Control = ({ triggerProps, state, field, placeholder, isClearable, isClean
800
844
  return (
801
845
  // A fragment, so the label, the control, and the message are rows of the
802
846
  // combobox itself. A custom trigger replaces all three.
803
- _jsxs(_Fragment, { children: [_jsx(FieldLabel, { field: field, size: size, onLabelClick: handleLabelClick }), _jsxs("div", Object.assign({ ref: referenceRef, className: classNames('ndl-combobox-control', {
847
+ _jsxs(_Fragment, { children: [_jsx(FormFieldLabel, { field: sharedField, size: size, onLabelClick: handleLabelClick }), _jsxs("div", Object.assign({ ref: referenceRef, className: classNames('ndl-combobox-control', {
804
848
  'ndl-clean': isClean,
805
849
  'ndl-disabled': isDisabled,
806
850
  'ndl-has-error': field.hasError,
@@ -846,35 +890,7 @@ const Control = ({ triggerProps, state, field, placeholder, isClearable, isClean
846
890
  // Select.
847
891
  _jsxs("div", { className: "ndl-combobox-clear", children: [_jsx("button", { type: "button", className: "ndl-combobox-clear-button", "aria-label": "Clear selection", onKeyDown: handleAuxiliaryActionKeyDown, onClick: handleClear, children: _jsx(XMarkIconOutline, {}) }), _jsx("div", { className: "ndl-combobox-divider" })] })), _jsx("div", { className: classNames('ndl-combobox-dropdown-indicator', {
848
892
  'ndl-open': isOpen,
849
- }), children: _jsx(ChevronDownIconOutline, { "aria-hidden": "true", className: "ndl-combobox-icon" }) })] })] })), _jsx(FieldMessage, { field: field, size: size })] }));
850
- };
851
- /**
852
- * The trigger is a button with `role="combobox"`, which takes its accessible
853
- * name from the author rather than from its content, so the label is referenced
854
- * through `aria-labelledby` instead of wrapping the control in a `<label>`.
855
- * The label is still a `<label>` associated through `htmlFor`, and clicking it
856
- * moves focus to the trigger, as with a native select. It deliberately does
857
- * not open the panel, which is also what a native select label leaves alone.
858
- */
859
- const FieldLabel = ({ field, size, onLabelClick }) => {
860
- const { label, labelId, triggerId, hasVisuallyHiddenLabel, hasRequiredIndicator, isRequired, } = field;
861
- const variant = size === 'large' ? 'body-large' : 'body-medium';
862
- return (_jsxs("div", { className: classNames('ndl-combobox-label-row', {
863
- 'ndl-visually-hidden': hasVisuallyHiddenLabel,
864
- }), children: [_jsx(Typography, { as: "label", variant: variant, className: "ndl-combobox-label", htmlAttributes: {
865
- htmlFor: triggerId,
866
- id: labelId,
867
- onClick: onLabelClick,
868
- }, children: label }), hasRequiredIndicator && (_jsx(Typography, { variant: variant, className: "ndl-combobox-label-indicator", children: isRequired ? 'Required' : 'Optional' }))] }));
869
- };
870
- /**
871
- * Rendered whether or not there is a message, so the live region is in the
872
- * document before the text arrives and a validation error is announced.
873
- */
874
- const FieldMessage = ({ field, size }) => {
875
- const { errorText, hasError, helpText, helpTextId, errorTextId } = field;
876
- const variant = size === 'large' ? 'body-medium' : 'body-small';
877
- return (_jsxs("div", { className: "ndl-combobox-message", "aria-live": "polite", children: [hasError && (_jsxs(_Fragment, { children: [_jsx("div", { className: "ndl-error-icon", children: _jsx(ExclamationCircleIconSolid, {}) }), _jsx(Typography, { variant: variant, className: "ndl-error-text", htmlAttributes: { id: errorTextId }, children: errorText })] })), !hasError && Boolean(helpText) && (_jsx(Typography, { variant: variant, htmlAttributes: { id: helpTextId }, children: helpText }))] }));
893
+ }), children: _jsx(ChevronDownIconOutline, { "aria-hidden": "true", className: "ndl-combobox-icon" }) })] })] })), _jsx(FormFieldMessage, { field: sharedField, size: size })] }));
878
894
  };
879
895
  const Panel = (_a) => {
880
896
  var { children, ref, id, ariaLabel, isDialog, className, style } = _a, restProps = __rest(_a, ["children", "ref", "id", "ariaLabel", "isDialog", "className", "style"]);