@postenbring/hedwig-react 4.1.2 → 4.2.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 (260) hide show
  1. package/dist/accordion/accordion-content.js.map +1 -1
  2. package/dist/accordion/accordion-content.mjs +3 -3
  3. package/dist/accordion/accordion.js.map +1 -1
  4. package/dist/accordion/accordion.mjs +4 -4
  5. package/dist/accordion/index.js.map +1 -1
  6. package/dist/accordion/index.mjs +4 -4
  7. package/dist/{chunk-77M2ZTP7.mjs → chunk-3V4GFS46.mjs} +11 -1
  8. package/dist/chunk-3V4GFS46.mjs.map +1 -0
  9. package/dist/chunk-5M6MEYM7.mjs +1 -0
  10. package/dist/chunk-62VLFCXX.mjs +64 -0
  11. package/dist/chunk-62VLFCXX.mjs.map +1 -0
  12. package/dist/chunk-CD4LCDK3.mjs +27 -0
  13. package/dist/chunk-CD4LCDK3.mjs.map +1 -0
  14. package/dist/chunk-CSIXGT7P.mjs +1 -0
  15. package/dist/chunk-CVE23PMJ.mjs +1 -0
  16. package/dist/chunk-CVE23PMJ.mjs.map +1 -0
  17. package/dist/chunk-D2XZT2RA.mjs +17 -0
  18. package/dist/chunk-D2XZT2RA.mjs.map +1 -0
  19. package/dist/{chunk-JFTUBOIF.mjs → chunk-DMRQEQQK.mjs} +27 -9
  20. package/dist/chunk-DMRQEQQK.mjs.map +1 -0
  21. package/dist/chunk-DNCWDWK2.mjs +113 -0
  22. package/dist/chunk-DNCWDWK2.mjs.map +1 -0
  23. package/dist/chunk-F23MNQCK.mjs +28 -0
  24. package/dist/chunk-F23MNQCK.mjs.map +1 -0
  25. package/dist/{chunk-5RXT5GLF.mjs → chunk-F6QJWZJX.mjs} +2 -2
  26. package/dist/{chunk-UYLKAPXD.mjs → chunk-GICUX46A.mjs} +2 -2
  27. package/dist/{chunk-SF6EDUHP.mjs → chunk-HOLFVKXQ.mjs} +2 -2
  28. package/dist/chunk-JGQTAIEP.mjs +67 -0
  29. package/dist/chunk-JGQTAIEP.mjs.map +1 -0
  30. package/dist/chunk-JKKH77UC.mjs +103 -0
  31. package/dist/chunk-JKKH77UC.mjs.map +1 -0
  32. package/dist/{chunk-GYI4NCUY.mjs → chunk-KPNAC2WN.mjs} +2 -2
  33. package/dist/{chunk-WNYCOHSD.mjs → chunk-NAXSP4VU.mjs} +2 -2
  34. package/dist/{chunk-R6MQFVHE.mjs → chunk-O55OTMJ5.mjs} +2 -2
  35. package/dist/chunk-OQD4GKOS.mjs +65 -0
  36. package/dist/chunk-OQD4GKOS.mjs.map +1 -0
  37. package/dist/{chunk-B4D2GO6E.mjs → chunk-QDG2QLFV.mjs} +2 -2
  38. package/dist/{chunk-B6T36QDV.mjs → chunk-QTC4ATZD.mjs} +2 -2
  39. package/dist/{chunk-Z56XN4AZ.mjs → chunk-RGZSYJFL.mjs} +14 -5
  40. package/dist/chunk-RGZSYJFL.mjs.map +1 -0
  41. package/dist/chunk-RJ763KDH.mjs +21 -0
  42. package/dist/chunk-RJ763KDH.mjs.map +1 -0
  43. package/dist/{chunk-AGIY7SFP.mjs → chunk-SO7TS4TS.mjs} +2 -2
  44. package/dist/{chunk-E6OOFTRQ.mjs → chunk-SQNGMF3D.mjs} +14 -8
  45. package/dist/chunk-SQNGMF3D.mjs.map +1 -0
  46. package/dist/{chunk-LHIG6RW7.mjs → chunk-VNH7CZJ4.mjs} +5 -13
  47. package/dist/chunk-VNH7CZJ4.mjs.map +1 -0
  48. package/dist/{chunk-HEDGKRGC.mjs → chunk-WMSOBRKN.mjs} +6 -32
  49. package/dist/chunk-WMSOBRKN.mjs.map +1 -0
  50. package/dist/{chunk-HBGFFKP3.mjs → chunk-WVCJV74B.mjs} +2 -2
  51. package/dist/{chunk-EDPWJWQO.mjs → chunk-YQT2TN3U.mjs} +2 -2
  52. package/dist/footer/footer.js.map +1 -1
  53. package/dist/footer/footer.mjs +5 -5
  54. package/dist/footer/index.js.map +1 -1
  55. package/dist/footer/index.mjs +5 -5
  56. package/dist/form/checkbox/checkbox.d.ts +10 -1
  57. package/dist/form/checkbox/checkbox.d.ts.map +1 -1
  58. package/dist/form/checkbox/checkbox.js +170 -71
  59. package/dist/form/checkbox/checkbox.js.map +1 -1
  60. package/dist/form/checkbox/checkbox.mjs +11 -4
  61. package/dist/form/checkbox/index.js +170 -71
  62. package/dist/form/checkbox/index.js.map +1 -1
  63. package/dist/form/checkbox/index.mjs +11 -4
  64. package/dist/form/date-picker/date-picker.d.ts.map +1 -1
  65. package/dist/form/date-picker/date-picker.js +75 -45
  66. package/dist/form/date-picker/date-picker.js.map +1 -1
  67. package/dist/form/date-picker/date-picker.mjs +8 -4
  68. package/dist/form/date-picker/index.js +75 -45
  69. package/dist/form/date-picker/index.js.map +1 -1
  70. package/dist/form/date-picker/index.mjs +8 -4
  71. package/dist/form/error-message/error-message.d.ts +2 -0
  72. package/dist/form/error-message/error-message.d.ts.map +1 -1
  73. package/dist/form/error-message/error-message.js +18 -8
  74. package/dist/form/error-message/error-message.js.map +1 -1
  75. package/dist/form/error-message/error-message.mjs +3 -1
  76. package/dist/form/error-message/index.js +18 -8
  77. package/dist/form/error-message/index.js.map +1 -1
  78. package/dist/form/error-message/index.mjs +3 -1
  79. package/dist/form/error-summary/error-summary.js.map +1 -1
  80. package/dist/form/error-summary/error-summary.mjs +3 -3
  81. package/dist/form/error-summary/index.js.map +1 -1
  82. package/dist/form/error-summary/index.mjs +3 -3
  83. package/dist/form/fieldset/fieldset-description.d.ts +12 -0
  84. package/dist/form/fieldset/fieldset-description.d.ts.map +1 -0
  85. package/dist/form/fieldset/fieldset-description.js +51 -0
  86. package/dist/form/fieldset/fieldset-description.js.map +1 -0
  87. package/dist/form/fieldset/fieldset-description.mjs +8 -0
  88. package/dist/form/fieldset/fieldset-description.mjs.map +1 -0
  89. package/dist/form/fieldset/fieldset-legend.d.ts +9 -0
  90. package/dist/form/fieldset/fieldset-legend.d.ts.map +1 -0
  91. package/dist/form/fieldset/fieldset-legend.js +72 -0
  92. package/dist/form/fieldset/fieldset-legend.js.map +1 -0
  93. package/dist/form/fieldset/fieldset-legend.mjs +8 -0
  94. package/dist/form/fieldset/fieldset-legend.mjs.map +1 -0
  95. package/dist/form/fieldset/fieldset.d.ts +30 -6
  96. package/dist/form/fieldset/fieldset.d.ts.map +1 -1
  97. package/dist/form/fieldset/fieldset.js +110 -35
  98. package/dist/form/fieldset/fieldset.js.map +1 -1
  99. package/dist/form/fieldset/fieldset.mjs +9 -2
  100. package/dist/form/fieldset/index.d.ts +2 -0
  101. package/dist/form/fieldset/index.d.ts.map +1 -1
  102. package/dist/form/fieldset/index.js +114 -35
  103. package/dist/form/fieldset/index.js.map +1 -1
  104. package/dist/form/fieldset/index.mjs +16 -3
  105. package/dist/form/index.d.ts +1 -0
  106. package/dist/form/index.d.ts.map +1 -1
  107. package/dist/form/index.js +460 -278
  108. package/dist/form/index.js.map +1 -1
  109. package/dist/form/index.mjs +41 -28
  110. package/dist/form/input/index.js +102 -38
  111. package/dist/form/input/index.js.map +1 -1
  112. package/dist/form/input/index.mjs +8 -3
  113. package/dist/form/input/input.d.ts.map +1 -1
  114. package/dist/form/input/input.js +102 -38
  115. package/dist/form/input/input.js.map +1 -1
  116. package/dist/form/input/input.mjs +8 -3
  117. package/dist/form/input-group/index.js +58 -22
  118. package/dist/form/input-group/index.js.map +1 -1
  119. package/dist/form/input-group/index.mjs +7 -2
  120. package/dist/form/input-group/input-group.d.ts +8 -0
  121. package/dist/form/input-group/input-group.d.ts.map +1 -1
  122. package/dist/form/input-group/input-group.js +58 -22
  123. package/dist/form/input-group/input-group.js.map +1 -1
  124. package/dist/form/input-group/input-group.mjs +7 -2
  125. package/dist/form/radio-button/index.js +139 -86
  126. package/dist/form/radio-button/index.js.map +1 -1
  127. package/dist/form/radio-button/index.mjs +12 -5
  128. package/dist/form/radio-button/radio-button.d.ts +2 -10
  129. package/dist/form/radio-button/radio-button.d.ts.map +1 -1
  130. package/dist/form/radio-button/radio-button.js +139 -86
  131. package/dist/form/radio-button/radio-button.js.map +1 -1
  132. package/dist/form/radio-button/radio-button.mjs +12 -5
  133. package/dist/form/radio-button/radio-group.d.ts +11 -13
  134. package/dist/form/radio-button/radio-group.d.ts.map +1 -1
  135. package/dist/form/radio-button/radio-group.js +123 -48
  136. package/dist/form/radio-button/radio-group.js.map +1 -1
  137. package/dist/form/radio-button/radio-group.mjs +11 -4
  138. package/dist/form/search-wrapper/index.js +6 -17
  139. package/dist/form/search-wrapper/index.js.map +1 -1
  140. package/dist/form/search-wrapper/index.mjs +1 -1
  141. package/dist/form/search-wrapper/search-wrapper.d.ts +2 -5
  142. package/dist/form/search-wrapper/search-wrapper.d.ts.map +1 -1
  143. package/dist/form/search-wrapper/search-wrapper.js +6 -17
  144. package/dist/form/search-wrapper/search-wrapper.js.map +1 -1
  145. package/dist/form/search-wrapper/search-wrapper.mjs +1 -1
  146. package/dist/form/select/index.js +104 -37
  147. package/dist/form/select/index.js.map +1 -1
  148. package/dist/form/select/index.mjs +8 -3
  149. package/dist/form/select/select.d.ts.map +1 -1
  150. package/dist/form/select/select.js +104 -37
  151. package/dist/form/select/select.js.map +1 -1
  152. package/dist/form/select/select.mjs +8 -3
  153. package/dist/form/textarea/index.js +91 -26
  154. package/dist/form/textarea/index.js.map +1 -1
  155. package/dist/form/textarea/index.mjs +8 -3
  156. package/dist/form/textarea/textarea.d.ts.map +1 -1
  157. package/dist/form/textarea/textarea.js +91 -26
  158. package/dist/form/textarea/textarea.js.map +1 -1
  159. package/dist/form/textarea/textarea.mjs +8 -3
  160. package/dist/form/validation-message/index.d.ts +3 -0
  161. package/dist/form/validation-message/index.d.ts.map +1 -0
  162. package/dist/form/validation-message/index.js +75 -0
  163. package/dist/form/validation-message/index.js.map +1 -0
  164. package/dist/form/validation-message/index.mjs +9 -0
  165. package/dist/form/validation-message/index.mjs.map +1 -0
  166. package/dist/form/validation-message/validation-message.d.ts +6 -0
  167. package/dist/form/validation-message/validation-message.d.ts.map +1 -0
  168. package/dist/form/validation-message/validation-message.js +73 -0
  169. package/dist/form/validation-message/validation-message.js.map +1 -0
  170. package/dist/form/validation-message/validation-message.mjs +8 -0
  171. package/dist/form/validation-message/validation-message.mjs.map +1 -0
  172. package/dist/index.js +669 -485
  173. package/dist/index.js.map +1 -1
  174. package/dist/index.mjs +61 -46
  175. package/dist/modal/index.js.map +1 -1
  176. package/dist/modal/index.mjs +2 -2
  177. package/dist/modal/modal.js.map +1 -1
  178. package/dist/modal/modal.mjs +2 -2
  179. package/dist/navbar/index.js.map +1 -1
  180. package/dist/navbar/index.mjs +3 -3
  181. package/dist/navbar/navbar-expandable-menu.js.map +1 -1
  182. package/dist/navbar/navbar-expandable-menu.mjs +2 -2
  183. package/dist/navbar/navbar.js.map +1 -1
  184. package/dist/navbar/navbar.mjs +3 -3
  185. package/dist/skeleton/index.js.map +1 -1
  186. package/dist/skeleton/index.mjs +3 -3
  187. package/dist/skeleton/skeleton.js.map +1 -1
  188. package/dist/skeleton/skeleton.mjs +3 -3
  189. package/dist/tabs/index.js.map +1 -1
  190. package/dist/tabs/index.mjs +3 -3
  191. package/dist/tabs/tabs-list.js.map +1 -1
  192. package/dist/tabs/tabs-list.mjs +2 -2
  193. package/dist/tabs/tabs.js.map +1 -1
  194. package/dist/tabs/tabs.mjs +3 -3
  195. package/dist/utils/auto-animate-height.js.map +1 -1
  196. package/dist/utils/auto-animate-height.mjs +2 -2
  197. package/dist/utils/index.js +11 -0
  198. package/dist/utils/index.js.map +1 -1
  199. package/dist/utils/index.mjs +4 -2
  200. package/dist/utils/utils.d.ts +4 -0
  201. package/dist/utils/utils.d.ts.map +1 -1
  202. package/dist/utils/utils.js +11 -0
  203. package/dist/utils/utils.js.map +1 -1
  204. package/dist/utils/utils.mjs +3 -1
  205. package/package.json +4 -4
  206. package/src/form/checkbox/checkbox.tsx +32 -11
  207. package/src/form/date-picker/date-picker.tsx +7 -1
  208. package/src/form/error-message/error-message.tsx +8 -14
  209. package/src/form/fieldset/fieldset-description.tsx +17 -0
  210. package/src/form/fieldset/fieldset-legend.tsx +22 -0
  211. package/src/form/fieldset/fieldset.stories.tsx +2 -1
  212. package/src/form/fieldset/fieldset.tsx +95 -26
  213. package/src/form/fieldset/index.tsx +2 -0
  214. package/src/form/index.tsx +1 -0
  215. package/src/form/input/input.tsx +23 -8
  216. package/src/form/input-group/input-group.tsx +22 -7
  217. package/src/form/radio-button/radio-button.stories.tsx +0 -1
  218. package/src/form/radio-button/radio-button.tsx +8 -34
  219. package/src/form/radio-button/radio-group.tsx +20 -19
  220. package/src/form/search-wrapper/search-wrapper.tsx +7 -22
  221. package/src/form/select/select.tsx +25 -8
  222. package/src/form/textarea/textarea.tsx +19 -2
  223. package/src/form/validation-message/index.tsx +2 -0
  224. package/src/form/validation-message/validation-message.stories.tsx +20 -0
  225. package/src/form/validation-message/validation-message.tsx +18 -0
  226. package/src/utils/utils.ts +16 -0
  227. package/dist/chunk-6BDVJ3J2.mjs +0 -37
  228. package/dist/chunk-6BDVJ3J2.mjs.map +0 -1
  229. package/dist/chunk-77M2ZTP7.mjs.map +0 -1
  230. package/dist/chunk-7T2GDVFS.mjs +0 -37
  231. package/dist/chunk-7T2GDVFS.mjs.map +0 -1
  232. package/dist/chunk-BO3EWZGA.mjs +0 -78
  233. package/dist/chunk-BO3EWZGA.mjs.map +0 -1
  234. package/dist/chunk-BOPY5K4T.mjs +0 -1
  235. package/dist/chunk-E6OOFTRQ.mjs.map +0 -1
  236. package/dist/chunk-HEDGKRGC.mjs.map +0 -1
  237. package/dist/chunk-IZFODQCF.mjs +0 -36
  238. package/dist/chunk-IZFODQCF.mjs.map +0 -1
  239. package/dist/chunk-JFTUBOIF.mjs.map +0 -1
  240. package/dist/chunk-LHIG6RW7.mjs.map +0 -1
  241. package/dist/chunk-LMF3QGSF.mjs +0 -1
  242. package/dist/chunk-Z2ZPTZ6F.mjs +0 -69
  243. package/dist/chunk-Z2ZPTZ6F.mjs.map +0 -1
  244. package/dist/chunk-Z56XN4AZ.mjs.map +0 -1
  245. package/dist/chunk-ZIVURWHY.mjs +0 -30
  246. package/dist/chunk-ZIVURWHY.mjs.map +0 -1
  247. package/src/form/error-message/error-message.stories.tsx +0 -20
  248. /package/dist/{chunk-BOPY5K4T.mjs.map → chunk-5M6MEYM7.mjs.map} +0 -0
  249. /package/dist/{chunk-LMF3QGSF.mjs.map → chunk-CSIXGT7P.mjs.map} +0 -0
  250. /package/dist/{chunk-5RXT5GLF.mjs.map → chunk-F6QJWZJX.mjs.map} +0 -0
  251. /package/dist/{chunk-UYLKAPXD.mjs.map → chunk-GICUX46A.mjs.map} +0 -0
  252. /package/dist/{chunk-SF6EDUHP.mjs.map → chunk-HOLFVKXQ.mjs.map} +0 -0
  253. /package/dist/{chunk-GYI4NCUY.mjs.map → chunk-KPNAC2WN.mjs.map} +0 -0
  254. /package/dist/{chunk-WNYCOHSD.mjs.map → chunk-NAXSP4VU.mjs.map} +0 -0
  255. /package/dist/{chunk-R6MQFVHE.mjs.map → chunk-O55OTMJ5.mjs.map} +0 -0
  256. /package/dist/{chunk-B4D2GO6E.mjs.map → chunk-QDG2QLFV.mjs.map} +0 -0
  257. /package/dist/{chunk-B6T36QDV.mjs.map → chunk-QTC4ATZD.mjs.map} +0 -0
  258. /package/dist/{chunk-AGIY7SFP.mjs.map → chunk-SO7TS4TS.mjs.map} +0 -0
  259. /package/dist/{chunk-HBGFFKP3.mjs.map → chunk-WVCJV74B.mjs.map} +0 -0
  260. /package/dist/{chunk-EDPWJWQO.mjs.map → chunk-YQT2TN3U.mjs.map} +0 -0
@@ -0,0 +1,17 @@
1
+ import { forwardRef, type HTMLAttributes } from "react";
2
+
3
+ export type FieldsetDescriptionProps = HTMLAttributes<HTMLParagraphElement>;
4
+
5
+ /**
6
+ * FieldsetDescription component, used to display a description for a fieldset.
7
+ *
8
+ * @example
9
+ * <FieldsetDescription>
10
+ * Gi en kort beskrivelse i begge feltene
11
+ * </FieldsetDescription>
12
+ */
13
+ export const FieldsetDescription = forwardRef<HTMLParagraphElement, FieldsetDescriptionProps>(
14
+ function FieldsetDescription(rest, ref) {
15
+ return <p className="hds-fieldset__description" ref={ref} {...rest} />;
16
+ },
17
+ );
@@ -0,0 +1,22 @@
1
+ import { forwardRef, type HTMLAttributes } from "react";
2
+ import { clsx } from "@postenbring/hedwig-css/typed-classname";
3
+
4
+ /**
5
+ * FieldsetLegend component, used to display a legend for a fieldset.
6
+ *
7
+ * @example
8
+ * <FieldsetLegend>Skriv inn dine svar</FieldsetLegend>
9
+ */
10
+ export const FieldsetLegend = forwardRef<HTMLLegendElement, HTMLAttributes<HTMLLegendElement>>(
11
+ function FieldsetLegend({ className, ...rest }, ref) {
12
+ return (
13
+ <legend
14
+ className={clsx("hds-fieldset__legend", className as undefined)}
15
+ ref={ref}
16
+ {...rest}
17
+ />
18
+ );
19
+ },
20
+ );
21
+
22
+ FieldsetLegend.displayName = "Fieldset.Legend";
@@ -15,11 +15,12 @@ type Story = StoryObj<typeof Fieldset>;
15
15
  export const Preview: Story = {
16
16
  tags: ["!dev"],
17
17
  args: {
18
- legend: "Default fieldset",
19
18
  errorMessage: "",
20
19
  },
21
20
  render: (props) => (
22
21
  <Fieldset {...props}>
22
+ <Fieldset.Legend>Default fieldset</Fieldset.Legend>
23
+ <Fieldset.Description>This is a description</Fieldset.Description>
23
24
  <Checkbox defaultChecked value="Hello">
24
25
  Hello
25
26
  </Checkbox>
@@ -1,68 +1,137 @@
1
- import { useId, forwardRef, createContext, useContext } from "react";
2
- import type { FieldsetHTMLAttributes, HTMLAttributes, ReactNode, CSSProperties } from "react";
1
+ import {
2
+ Children,
3
+ cloneElement,
4
+ isValidElement,
5
+ useId,
6
+ forwardRef,
7
+ createContext,
8
+ useContext,
9
+ } from "react";
10
+ import type {
11
+ FieldsetHTMLAttributes,
12
+ ReactElement,
13
+ ReactNode,
14
+ CSSProperties,
15
+ ComponentProps,
16
+ } from "react";
3
17
  import { clsx } from "@postenbring/hedwig-css/typed-classname";
4
- import { ErrorMessage, type ErrorMessageProps } from "../error-message";
18
+ import { ValidationMessage, type ValidationMessageProps } from "../validation-message";
19
+ import { type ErrorMessageProps } from "../error-message";
20
+ import { getValidationMessageValue } from "../../utils";
21
+ import { FieldsetDescription } from "./fieldset-description";
22
+ import { FieldsetLegend } from "./fieldset-legend";
23
+
24
+ type FieldsetLegendProps = ComponentProps<typeof FieldsetLegend>;
5
25
 
6
26
  export interface FieldsetProps extends FieldsetHTMLAttributes<HTMLFieldSetElement> {
7
27
  className?: string;
8
28
  style?: CSSProperties;
29
+ "data-color"?: "info" | "success" | "warning" | "error";
30
+ validationMessage?: ReactNode | { value: ReactNode };
31
+ validationMessageProps?: Partial<ValidationMessageProps>;
9
32
  /**
10
33
  * Providing an errorMessage will also give contained Checkboxes or Radio buttons
11
34
  * error styling and aria to indicate invalid state.
12
35
  *
13
36
  * For Radio buttons you are even better off using RadioGroup.
14
37
  */
38
+
39
+ /** @deprecated Use `validationMessage` instead */
15
40
  errorMessage?: ReactNode;
16
- legendProps?: HTMLAttributes<HTMLElement> & { size: "default" | "large" };
17
- legend: ReactNode;
41
+ /**
42
+ * @deprecated Pass props directly to <Fieldset.Legend> instead.
43
+ */
44
+ legendProps?: FieldsetLegendProps;
45
+ /**
46
+ * @deprecated Use <Fieldset.Legend>...</Fieldset.Legend> instead.
47
+ */
48
+ legend?: ReactNode;
49
+ size?: "small" | "";
18
50
  children: ReactNode;
51
+ /** @deprecated Use `validationMessageProps` instead */
19
52
  errorMessageProps?: Partial<ErrorMessageProps>;
20
53
  }
21
54
 
22
- const FieldsetContext = createContext<{ hasError: boolean }>({ hasError: false });
55
+ /** @deprecated Will no longer be needed */
56
+ const FieldsetContext = createContext<{ hasError: boolean; size: "small" | "" }>({
57
+ hasError: false,
58
+ size: "",
59
+ });
23
60
 
61
+ /** @deprecated Will no longer be needed */
24
62
  export const useFieldsetContext = () => useContext(FieldsetContext);
25
63
 
26
64
  export const Fieldset = forwardRef<HTMLFieldSetElement, FieldsetProps>(function Fieldset(
27
65
  {
28
66
  className,
29
67
  style,
68
+ "data-color": dataColor = undefined,
69
+ validationMessage,
70
+ validationMessageProps,
30
71
  errorMessage,
31
72
  errorMessageProps,
32
- legendProps: { size: legendSize = "default", className: legendClassName, ...legendProps } = {},
73
+ legendProps,
33
74
  legend,
75
+ size = "",
34
76
  children,
35
77
  ...rest
36
78
  },
37
79
  ref,
38
80
  ) {
39
- const errorMessageId = useId();
81
+ const validationMessageId = useId();
82
+ const validationColor = errorMessage ? "error" : dataColor;
83
+ const validationMessageValue = getValidationMessageValue(validationMessage, errorMessage);
84
+ const childArray = Children.toArray(children);
85
+ const legendChild = childArray.find(
86
+ (child): child is ReactElement<FieldsetLegendProps> =>
87
+ isValidElement<FieldsetLegendProps>(child) && child.type === FieldsetLegend,
88
+ );
89
+ const contentChildren = legendChild
90
+ ? childArray.filter((child) => child !== legendChild)
91
+ : childArray;
92
+ let renderedLegend = null;
93
+
94
+ if (legendChild) {
95
+ renderedLegend = cloneElement(legendChild, {
96
+ ...legendProps,
97
+ ...legendChild.props,
98
+ className: clsx(
99
+ legendProps?.className as undefined,
100
+ legendChild.props.className as undefined,
101
+ ),
102
+ });
103
+ } else if (legend !== undefined) {
104
+ renderedLegend = <FieldsetLegend {...legendProps}>{legend}</FieldsetLegend>;
105
+ }
40
106
 
41
107
  return (
42
108
  <fieldset
43
- aria-describedby={errorMessage ? errorMessageId : undefined}
109
+ aria-describedby={validationMessageValue ? validationMessageId : undefined}
44
110
  aria-invalid={errorMessage ? true : undefined}
45
- className={clsx("hds-fieldset", className as undefined)}
111
+ className={clsx("hds-fieldset", { [`hds-fieldset--${size}`]: size }, className as undefined)}
112
+ data-color={validationColor}
46
113
  ref={ref}
47
114
  style={style}
48
115
  {...rest}
49
116
  >
50
- <legend
51
- className={clsx(
52
- "hds-fieldset__legend",
53
- { [`hds-fieldset__legend--${legendSize}`]: legendSize },
54
- legendClassName as undefined,
55
- )}
56
- {...legendProps}
57
- >
58
- {legend}
59
- </legend>
60
- <FieldsetContext.Provider value={{ hasError: Boolean(errorMessage) }}>
61
- {children}
117
+ {renderedLegend}
118
+ <FieldsetContext.Provider value={{ hasError: Boolean(errorMessage), size }}>
119
+ {contentChildren}
62
120
  </FieldsetContext.Provider>
63
- <ErrorMessage id={errorMessageId} {...errorMessageProps}>
64
- {errorMessage}
65
- </ErrorMessage>
121
+ <ValidationMessage
122
+ id={validationMessageId}
123
+ {...(validationMessageProps ?? errorMessageProps)}
124
+ >
125
+ {validationMessageValue}
126
+ </ValidationMessage>
66
127
  </fieldset>
67
128
  );
68
- });
129
+ }) as FieldsetType;
130
+
131
+ type FieldsetType = ReturnType<typeof forwardRef<HTMLFieldSetElement, FieldsetProps>> & {
132
+ Description: typeof FieldsetDescription;
133
+ Legend: typeof FieldsetLegend;
134
+ };
135
+
136
+ Fieldset.Description = FieldsetDescription;
137
+ Fieldset.Legend = FieldsetLegend;
@@ -1,2 +1,4 @@
1
1
  export { Fieldset, useFieldsetContext } from "./fieldset";
2
2
  export type * from "./fieldset";
3
+ export { FieldsetDescription } from "./fieldset-description";
4
+ export { FieldsetLegend } from "./fieldset-legend";
@@ -8,3 +8,4 @@ export * from "./radio-button";
8
8
  export * from "./search-wrapper";
9
9
  export * from "./select";
10
10
  export * from "./textarea";
11
+ export * from "./validation-message";
@@ -16,14 +16,28 @@ export type InputProps = Omit<
16
16
  "children"
17
17
  >;
18
18
 
19
- export const Input = forwardRef<HTMLInputElement, InputProps>(function Input(
20
- { className, size, errorMessage, labelProps, label, id, style, disabled, readOnly, ...rest },
21
- ref,
22
- ) {
23
- return (
19
+ export const Input = forwardRef<HTMLInputElement, InputProps>(
20
+ (
21
+ {
22
+ className,
23
+ size,
24
+ validationMessage,
25
+ errorMessage,
26
+ labelProps,
27
+ label,
28
+ id,
29
+ style,
30
+ disabled,
31
+ readOnly,
32
+ "data-color": dataColor,
33
+ ...rest
34
+ },
35
+ ref,
36
+ ) => (
24
37
  <InputGroup
25
38
  className={clsx("hds-input", className as undefined)}
26
39
  disabled={disabled}
40
+ validationMessage={validationMessage}
27
41
  errorMessage={errorMessage}
28
42
  id={id}
29
43
  label={label}
@@ -31,10 +45,11 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(function Input(
31
45
  readOnly={readOnly}
32
46
  style={style}
33
47
  size={size}
48
+ data-color={dataColor}
34
49
  >
35
- <input {...rest} disabled={disabled} readOnly={readOnly} ref={ref} />
50
+ <input disabled={disabled} readOnly={readOnly} ref={ref} {...rest} />
36
51
  </InputGroup>
37
- );
38
- });
52
+ ),
53
+ );
39
54
 
40
55
  Input.displayName = "Input";
@@ -1,7 +1,9 @@
1
1
  import { useId, forwardRef, Children, isValidElement, cloneElement } from "react";
2
2
  import type { LabelHTMLAttributes, ReactNode, CSSProperties } from "react";
3
3
  import { clsx } from "@postenbring/hedwig-css/typed-classname";
4
- import { ErrorMessage, type ErrorMessageProps } from "../error-message";
4
+ import { ValidationMessage, type ValidationMessageProps } from "../validation-message";
5
+ import { type ErrorMessageProps } from "../error-message";
6
+ import { getValidationMessageValue } from "../../utils";
5
7
 
6
8
  interface InputProps {
7
9
  "aria-describedby"?: string;
@@ -14,8 +16,13 @@ export interface InputGroupProps {
14
16
  id?: string;
15
17
  className?: string;
16
18
  style?: CSSProperties;
19
+ "data-color"?: "info" | "success" | "warning" | "error";
17
20
  size?: "large" | "small";
21
+ validationMessage?: ReactNode | { value: ReactNode };
22
+ validationMessageProps?: Partial<ValidationMessageProps>;
23
+ /** @deprecated Use `validationMessage` instead */
18
24
  errorMessage?: ReactNode;
25
+ /** @deprecated Use `validationMessageProps` instead */
19
26
  errorMessageProps?: Partial<ErrorMessageProps>;
20
27
  labelProps?: LabelHTMLAttributes<HTMLLabelElement>;
21
28
  label?: ReactNode;
@@ -34,7 +41,10 @@ export const InputGroup = forwardRef<HTMLDivElement, InputGroupProps>(function I
34
41
  id,
35
42
  className,
36
43
  style,
44
+ "data-color": dataColor = undefined,
37
45
  size = "large",
46
+ validationMessage,
47
+ validationMessageProps,
38
48
  errorMessage,
39
49
  errorMessageProps,
40
50
  labelProps: { className: labelClassName, ...labelProps } = {},
@@ -46,12 +56,14 @@ export const InputGroup = forwardRef<HTMLDivElement, InputGroupProps>(function I
46
56
  },
47
57
  ref,
48
58
  ) {
49
- const errorMessageId = useId();
59
+ const validationMessageId = useId();
50
60
  const inputId = useId();
61
+ const validationColor = errorMessage ? "error" : dataColor;
62
+ const validationMessageValue = getValidationMessageValue(validationMessage, errorMessage);
51
63
 
52
64
  const renderInput = () => {
53
65
  const inputProps: InputProps = {
54
- "aria-describedby": errorMessage ? errorMessageId : undefined,
66
+ "aria-describedby": validationMessage ? validationMessageId : undefined,
55
67
  "aria-invalid": errorMessage ? true : undefined,
56
68
  id: id ?? inputId,
57
69
  className: clsx("hds-input-group__input"),
@@ -80,12 +92,12 @@ export const InputGroup = forwardRef<HTMLDivElement, InputGroupProps>(function I
80
92
  "hds-input-group",
81
93
  {
82
94
  [`hds-input-group--${size}`]: size,
83
- "hds-input-group--error": errorMessage,
84
95
  },
85
96
  className as undefined,
86
97
  )}
87
98
  ref={ref}
88
99
  style={style}
100
+ data-color={validationColor}
89
101
  {...rest}
90
102
  >
91
103
  {label !== null && label !== undefined && label !== false && (
@@ -104,9 +116,12 @@ export const InputGroup = forwardRef<HTMLDivElement, InputGroupProps>(function I
104
116
  >
105
117
  {renderInput()}
106
118
  </div>
107
- <ErrorMessage id={errorMessageId} {...errorMessageProps}>
108
- {errorMessage}
109
- </ErrorMessage>
119
+ <ValidationMessage
120
+ id={validationMessageId}
121
+ {...(validationMessageProps ?? errorMessageProps)}
122
+ >
123
+ {validationMessageValue}
124
+ </ValidationMessage>
110
125
  </div>
111
126
  );
112
127
  });
@@ -17,7 +17,6 @@ export const Preview: Story = {
17
17
  title: "",
18
18
  children: "Just a RadioButton",
19
19
  checked: true,
20
- hasError: false,
21
20
  variant: "plain",
22
21
  },
23
22
  argTypes: {
@@ -1,22 +1,13 @@
1
1
  import { forwardRef, type InputHTMLAttributes, type ReactNode } from "react";
2
2
  import { clsx } from "@postenbring/hedwig-css/typed-classname";
3
- import { useFieldsetContext } from "../fieldset";
4
- import { type RadioGroupProps, useRadioGroupContext } from "./radio-group";
3
+ import { useRadioGroupContext } from "./radio-group";
5
4
 
6
5
  export interface RadioButtonProps
7
- extends Omit<InputHTMLAttributes<HTMLInputElement>, "defaultValue"> {
6
+ extends Omit<InputHTMLAttributes<HTMLInputElement>, "defaultValue" | "size"> {
8
7
  children: ReactNode;
9
8
  variant?: "plain" | "bounding-box";
10
- /**
11
- * Set to `true` to add error styling. The component will take care of aria to indicate invalid state.
12
- *
13
- * Normally you don't need this, as you should wrap your Radio buttons in the RadioGroup component.
14
- * When providing an errorMessage to RadioGroup, all contained Radio buttons will get correct hasError state.
15
- *
16
- * You can use this when your Radio button is part of a non-HDS fieldset which shows an error message.
17
- */
18
- hasError?: boolean;
19
9
  title?: string;
10
+ size?: "small" | "";
20
11
  }
21
12
 
22
13
  const isChecked = ({
@@ -24,7 +15,7 @@ const isChecked = ({
24
15
  selectedValue,
25
16
  value,
26
17
  }: Pick<RadioButtonProps, "checked" | "value"> & {
27
- selectedValue: RadioGroupProps["value"];
18
+ selectedValue: RadioButtonProps["value"];
28
19
  }) => {
29
20
  if (typeof checked !== "undefined") return checked;
30
21
  if (typeof selectedValue !== "undefined") return value === selectedValue;
@@ -32,26 +23,9 @@ const isChecked = ({
32
23
  };
33
24
 
34
25
  export const RadioButton = forwardRef<HTMLInputElement, RadioButtonProps>(
35
- (
36
- {
37
- checked,
38
- value,
39
- variant = "plain",
40
- hasError: hasErrorProp,
41
- title,
42
- children,
43
- className,
44
- ...rest
45
- },
46
- ref,
47
- ) => {
48
- const {
49
- value: selectedValue,
50
- hasError: hasRadioGroupError,
51
- ...context
52
- } = useRadioGroupContext();
53
- const { hasError: hasFieldsetError } = useFieldsetContext();
54
- const hasError = hasFieldsetError || hasRadioGroupError || hasErrorProp;
26
+ ({ checked, value, variant = "plain", title, children, className, size = "", ...rest }, ref) => {
27
+ const { value: selectedValue, size: groupSize, ...context } = useRadioGroupContext();
28
+ const effectiveSize = size || groupSize;
55
29
 
56
30
  return (
57
31
  <div
@@ -59,7 +33,7 @@ export const RadioButton = forwardRef<HTMLInputElement, RadioButtonProps>(
59
33
  "hds-radio-button",
60
34
  {
61
35
  [`hds-radio-button--${variant}`]: variant === "bounding-box",
62
- "hds-radio-button--error": hasError,
36
+ [`hds-radio-button--${effectiveSize}`]: effectiveSize === "small",
63
37
  },
64
38
  className as undefined,
65
39
  )}
@@ -2,52 +2,53 @@ import {
2
2
  type ChangeEventHandler,
3
3
  createContext,
4
4
  forwardRef,
5
+ type InputHTMLAttributes,
5
6
  type ReactNode,
6
7
  useContext,
7
8
  } from "react";
9
+ import { FieldsetDescription } from "../fieldset/fieldset-description";
8
10
  import { Fieldset, type FieldsetProps } from "../fieldset";
9
- import type { RadioButtonProps } from "./radio-button";
11
+ import { FieldsetLegend } from "../fieldset/fieldset-legend";
10
12
 
11
13
  export interface RadioGroupProps extends Omit<FieldsetProps, "onChange"> {
12
14
  children: ReactNode;
13
15
  /** Will be passed to all Radio buttons within the radio group */
14
- name?: RadioButtonProps["name"];
16
+ name?: InputHTMLAttributes<HTMLInputElement>["name"];
15
17
  /** If you want the group to be controlled, you can pass the selected value here */
16
- value?: RadioButtonProps["value"];
17
- /**
18
- * Error message is passed to the internal Fieldset, and will also give contained Radio buttons
19
- * error styling and aria to indicate invalid state.
20
- */
21
- errorMessage?: ReactNode;
18
+ value?: InputHTMLAttributes<HTMLInputElement>["value"];
22
19
  /** Will be passed to all Radio buttons within the radio group */
23
20
  onChange?: ChangeEventHandler<HTMLInputElement> | undefined;
24
21
  }
25
22
 
26
- type RadioGroupContextProps = {
27
- hasError: boolean;
28
- } & Pick<RadioGroupProps, "name" | "value" | "onChange">;
23
+ type RadioGroupContextProps = Pick<RadioGroupProps, "name" | "value" | "onChange" | "size">;
29
24
 
30
25
  const RadioGroupContext = createContext<RadioGroupContextProps>({
31
26
  name: undefined,
32
- hasError: false,
33
- onChange: () => {
34
- return undefined;
35
- },
27
+ onChange: () => undefined,
28
+ size: undefined,
36
29
  });
37
30
 
38
31
  export const useRadioGroupContext = () => useContext(RadioGroupContext);
39
32
 
40
33
  export const RadioGroup = forwardRef<HTMLFieldSetElement, RadioGroupProps>(function RadioGroup(
41
- { name, value, errorMessage, onChange, children, ...rest },
34
+ { name, value, onChange, children, size, ...rest },
42
35
  ref,
43
36
  ) {
44
37
  return (
45
- <RadioGroupContext.Provider value={{ name, value, hasError: Boolean(errorMessage), onChange }}>
46
- <Fieldset errorMessage={errorMessage} {...rest} ref={ref}>
38
+ <RadioGroupContext.Provider value={{ name, value, onChange, size }}>
39
+ <Fieldset size={size} {...rest} ref={ref}>
47
40
  {children}
48
41
  </Fieldset>
49
42
  </RadioGroupContext.Provider>
50
43
  );
51
- });
44
+ }) as RadioGroupType;
45
+
46
+ type RadioGroupType = ReturnType<typeof forwardRef<HTMLFieldSetElement, RadioGroupProps>> & {
47
+ Description: typeof FieldsetDescription;
48
+ Legend: typeof FieldsetLegend;
49
+ };
50
+
51
+ RadioGroup.Description = FieldsetDescription;
52
+ RadioGroup.Legend = FieldsetLegend;
52
53
 
53
54
  RadioGroup.displayName = "RadioGroup";
@@ -1,29 +1,14 @@
1
- import { forwardRef } from "react";
2
- import type { ReactNode, CSSProperties } from "react";
1
+ import { forwardRef, type HTMLAttributes } from "react";
3
2
  import { clsx } from "@postenbring/hedwig-css/typed-classname";
4
3
 
5
- export interface SearchWrapperProps {
6
- id?: string;
4
+ export interface SearchWrapperProps extends HTMLAttributes<HTMLDivElement> {
7
5
  className?: string;
8
- style?: CSSProperties;
9
- children: ReactNode;
10
6
  }
11
7
 
12
- export const SearchWrapper = forwardRef<HTMLDivElement, SearchWrapperProps>(function SearchWrapper(
13
- { id, className, style, children, ...rest },
14
- ref,
15
- ) {
16
- return (
17
- <div
18
- id={id}
19
- className={clsx("hds-search-wrapper", className as undefined)}
20
- ref={ref}
21
- style={style}
22
- {...rest}
23
- >
24
- {children}
25
- </div>
26
- );
27
- });
8
+ export const SearchWrapper = forwardRef<HTMLDivElement, SearchWrapperProps>(
9
+ ({ className, ...rest }, ref) => (
10
+ <div className={clsx("hds-search-wrapper", className as undefined)} ref={ref} {...rest} />
11
+ ),
12
+ );
28
13
 
29
14
  SearchWrapper.displayName = "SearchWrapper";
@@ -8,26 +8,43 @@ export type SelectProps = Omit<
8
8
  "readOnly" | "children"
9
9
  > & { children: ReactNode };
10
10
 
11
- export const Select = forwardRef<HTMLSelectElement, SelectProps>(function Select(
12
- { className, size, errorMessage, labelProps, label, id, style, disabled, children, ...rest },
13
- ref,
14
- ) {
15
- return (
11
+ export const Select = forwardRef<HTMLSelectElement, SelectProps>(
12
+ (
13
+ {
14
+ className,
15
+ size,
16
+ validationMessage,
17
+ validationMessageProps,
18
+ errorMessage,
19
+ labelProps,
20
+ label,
21
+ id,
22
+ style,
23
+ disabled,
24
+ "data-color": dataColor,
25
+ children,
26
+ ...rest
27
+ },
28
+ ref,
29
+ ) => (
16
30
  <InputGroup
17
31
  className={clsx("hds-select", className as undefined)}
18
32
  disabled={disabled}
33
+ validationMessage={validationMessage}
34
+ validationMessageProps={validationMessageProps}
19
35
  errorMessage={errorMessage}
20
36
  id={id}
21
37
  label={label}
22
38
  labelProps={labelProps}
23
39
  style={style}
24
40
  size={size}
41
+ data-color={dataColor}
25
42
  >
26
- <select {...rest} disabled={disabled} ref={ref}>
43
+ <select disabled={disabled} ref={ref} {...rest}>
27
44
  {children}
28
45
  </select>
29
46
  </InputGroup>
30
- );
31
- });
47
+ ),
48
+ );
32
49
 
33
50
  Select.displayName = "Select";
@@ -10,13 +10,29 @@ export type TextareaProps = Omit<
10
10
  >;
11
11
 
12
12
  export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(function Textarea(
13
- { className, size, errorMessage, labelProps, label, id, style, disabled, readOnly, ...rest },
13
+ {
14
+ className,
15
+ size,
16
+ validationMessage,
17
+ validationMessageProps,
18
+ errorMessage,
19
+ labelProps,
20
+ label,
21
+ id,
22
+ style,
23
+ disabled,
24
+ readOnly,
25
+ "data-color": dataColor,
26
+ ...rest
27
+ },
14
28
  ref,
15
29
  ) {
16
30
  return (
17
31
  <InputGroup
18
32
  className={clsx("hds-textarea", className as undefined)}
19
33
  disabled={disabled}
34
+ validationMessage={validationMessage}
35
+ validationMessageProps={validationMessageProps}
20
36
  errorMessage={errorMessage}
21
37
  id={id}
22
38
  label={label}
@@ -24,8 +40,9 @@ export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(function
24
40
  readOnly={readOnly}
25
41
  style={style}
26
42
  size={size}
43
+ data-color={dataColor}
27
44
  >
28
- <textarea {...rest} disabled={disabled} readOnly={readOnly} ref={ref} />
45
+ <textarea disabled={disabled} readOnly={readOnly} ref={ref} {...rest} />
29
46
  </InputGroup>
30
47
  );
31
48
  });
@@ -0,0 +1,2 @@
1
+ export { ValidationMessage } from "./validation-message";
2
+ export type * from "./validation-message";
@@ -0,0 +1,20 @@
1
+ /* eslint-disable import/no-extraneous-dependencies -- storybook story */
2
+ import type { Meta, StoryObj } from "@storybook/react";
3
+ import { ValidationMessage } from ".";
4
+
5
+ const meta: Meta<typeof ValidationMessage> = {
6
+ title: "Form/Validation Message",
7
+ component: ValidationMessage,
8
+ };
9
+
10
+ export default meta;
11
+
12
+ type Story = StoryObj<typeof ValidationMessage>;
13
+
14
+ export const Preview: Story = {
15
+ tags: ["!dev"],
16
+ args: {
17
+ id: "id",
18
+ children: "This is a validation message for use with form input components",
19
+ },
20
+ };