@helsenorge/designsystem-react 8.6.0 → 9.0.0-beta.0

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 (87) hide show
  1. package/Button.js +7 -7
  2. package/Button.js.map +1 -1
  3. package/Checkbox.js +42 -42
  4. package/Checkbox.js.map +1 -1
  5. package/ErrorWrapper.js.map +1 -1
  6. package/FormGroup.js +30 -30
  7. package/FormGroup.js.map +1 -1
  8. package/Icon.js +21 -21
  9. package/Icon.js.map +1 -1
  10. package/Input.js +98 -88
  11. package/Input.js.map +1 -1
  12. package/Label.js +58 -62
  13. package/Label.js.map +1 -1
  14. package/MaxCharacters.js +2 -2
  15. package/MaxCharacters.js.map +1 -1
  16. package/RadioButton.js +61 -61
  17. package/RadioButton.js.map +1 -1
  18. package/Select.js +34 -33
  19. package/Select.js.map +1 -1
  20. package/StatusDot.js +15 -15
  21. package/StatusDot.js.map +1 -1
  22. package/TabList.js +88 -53
  23. package/TabList.js.map +1 -1
  24. package/TabPanel.js +7 -7
  25. package/TabPanel.js.map +1 -1
  26. package/Textarea.js +59 -58
  27. package/Textarea.js.map +1 -1
  28. package/Trigger.js +33 -33
  29. package/Trigger.js.map +1 -1
  30. package/components/Button/Button.d.ts +2 -2
  31. package/components/Checkbox/Checkbox.d.ts +4 -3
  32. package/components/Checkbox/styles.module.scss +0 -14
  33. package/components/Checkbox/styles.module.scss.d.ts +0 -1
  34. package/components/Dropdown/Dropdown.d.ts +2 -2
  35. package/components/Dropdown/index.js +25 -25
  36. package/components/Dropdown/index.js.map +1 -1
  37. package/components/ErrorWrapper/ErrorWrapper.d.ts +3 -0
  38. package/components/ExpanderList/ExpanderList.d.ts +4 -6
  39. package/components/ExpanderList/index.js +118 -126
  40. package/components/ExpanderList/index.js.map +1 -1
  41. package/components/ExpanderList/styles.module.scss +164 -53
  42. package/components/ExpanderList/styles.module.scss.d.ts +29 -5
  43. package/components/FormGroup/FormGroup.d.ts +2 -2
  44. package/components/Icon/Icon.d.ts +4 -4
  45. package/components/Icons/NoAccess.js +7 -7
  46. package/components/Icons/NoAccess.js.map +1 -1
  47. package/components/Input/Input.d.ts +4 -3
  48. package/components/Label/Label.d.ts +4 -7
  49. package/components/Label/SubLabel.d.ts +2 -2
  50. package/components/MaxCharacters/MaxCharacters.d.ts +2 -2
  51. package/components/RadioButton/RadioButton.d.ts +5 -4
  52. package/components/RadioButton/styles.module.scss +0 -15
  53. package/components/RadioButton/styles.module.scss.d.ts +0 -1
  54. package/components/Select/Select.d.ts +4 -3
  55. package/components/SharingStatus/SharingStatus.d.ts +1 -1
  56. package/components/SharingStatus/index.js +5 -5
  57. package/components/SharingStatus/index.js.map +1 -1
  58. package/components/SharingStatus/styles.module.scss +0 -16
  59. package/components/SharingStatus/styles.module.scss.d.ts +0 -4
  60. package/components/StatusDot/StatusDot.d.ts +3 -3
  61. package/components/StatusDot/index.js +3 -3
  62. package/components/Tabs/TabList/TabList.d.ts +3 -3
  63. package/components/Tabs/TabList/styles.module.scss +63 -51
  64. package/components/Tabs/TabList/styles.module.scss.d.ts +7 -3
  65. package/components/Tabs/TabPanel/TabPanel.d.ts +1 -2
  66. package/components/Tabs/TabPanel/styles.module.scss +11 -26
  67. package/components/Tabs/TabPanel/styles.module.scss.d.ts +0 -2
  68. package/components/Tabs/Tabs.d.ts +3 -3
  69. package/components/Tabs/index.js +60 -75
  70. package/components/Tabs/index.js.map +1 -1
  71. package/components/Tabs/styles.module.scss +5 -9
  72. package/components/Tabs/styles.module.scss.d.ts +0 -1
  73. package/components/Textarea/Textarea.d.ts +4 -3
  74. package/components/Toggle/index.js +1222 -1180
  75. package/components/Toggle/index.js.map +1 -1
  76. package/components/Trigger/Trigger.d.ts +2 -2
  77. package/components/Validation/index.js +38 -32
  78. package/components/Validation/index.js.map +1 -1
  79. package/constants.d.ts +1 -1
  80. package/constants.js +1 -1
  81. package/constants.js.map +1 -1
  82. package/docs/FormExample/FormExample.d.ts +2 -1
  83. package/index.js +23 -23
  84. package/package.json +4 -4
  85. package/utils/component.d.ts +1 -0
  86. package/utils/component.js +7 -3
  87. package/utils/component.js.map +1 -1
package/Button.js CHANGED
@@ -11,7 +11,7 @@ import { breakpoints as ht } from "./theme/grid.js";
11
11
  import { isTest as gt, isProd as _t } from "./utils/environment.js";
12
12
  import wt from "./components/Icons/ArrowRight.js";
13
13
  import t from "./components/Button/styles.module.scss";
14
- const It = (o, r, n, f, e, g) => g && n ? !e || o ? u("neutral", r ? 500 : 700) : u("white") : n ? !e || o ? u("neutral", 500) : `${u("white")}b3` : o && !e || !o && e ? "white" : f === "normal" ? u("blueberry", 600) : u("cherry", 500), R = (o, r) => r && o ? B.Small : o ? B.Medium : B.XSmall, yt = (o, r, n) => {
14
+ const It = (o, r, n, f, e, g) => g && n ? !e || o ? u("neutral", r ? 500 : 700) : u("white") : n ? !e || o ? u("neutral", 500) : `${u("white")}b3` : o && !e || !o && e ? "white" : f === "normal" ? u("blueberry", 600) : u("cherry", 500), R = (o, r) => r && o ? B.Small : o ? B.Medium : B.XSmall, Ct = (o, r, n) => {
15
15
  if (n && o && (r === void 0 || r === ""))
16
16
  throw new Error("Fyll inn ariaLabel prop på Button uten tekst for å opprettholde UU krav");
17
17
  }, jt = x.forwardRef(function(r, n) {
@@ -27,11 +27,11 @@ const It = (o, r, n, f, e, g) => g && n ? !e || o ? u("neutral", r ? 500 : 700)
27
27
  ellipsis: S = !1,
28
28
  fluid: w = !1,
29
29
  htmlMarkup: I = "button",
30
- mode: J = "onlight",
30
+ onColor: J = "onlight",
31
31
  onBlur: z,
32
32
  onClick: U,
33
33
  size: K = "medium",
34
- variant: y = "fill",
34
+ variant: C = "fill",
35
35
  href: Q,
36
36
  tabIndex: F,
37
37
  testId: H,
@@ -39,7 +39,7 @@ const It = (o, r, n, f, e, g) => g && n ? !e || o ? u("neutral", r ? 500 : 700)
39
39
  type: Y = "button",
40
40
  textPosition: Z = "left",
41
41
  ...j
42
- } = r, [d, b, L] = ft(x.Children.toArray(g)), { hoverRef: M, isHovered: E } = I === "button" ? $(n) : $(n), tt = dt(null), s = !!(d || b) && !L, T = d && (b || _) && !s, C = J === "ondark", h = mt() < ht.md, V = A === "destructive" && !i, ot = y === "outline", c = y === "borderless", W = It(y === "fill", c, i, A, C, h), v = _ === "icon" && !c, p = K === "large" && !V && !c, rt = _ === "accessibility-character" && !w && !d && !b && !v && c, nt = { ...j }, D = m(
42
+ } = r, [d, b, L] = ft(x.Children.toArray(g)), { hoverRef: M, isHovered: E } = I === "button" ? $(n) : $(n), tt = dt(null), s = !!(d || b) && !L, T = d && (b || _) && !s, y = J === "ondark", h = mt() < ht.md, V = A === "destructive" && !i, ot = C === "outline", c = C === "borderless", W = It(C === "fill", c, i, A, y, h), v = _ === "icon" && !c, p = K === "large" && !V && !c, rt = _ === "accessibility-character" && !w && !d && !b && !v && c, nt = { ...j }, D = m(
43
43
  t["button-wrapper"],
44
44
  { [t["button-wrapper--fluid"]]: w || S },
45
45
  q
@@ -56,17 +56,17 @@ const It = (o, r, n, f, e, g) => g && n ? !e || o ? u("neutral", r ? 500 : 700)
56
56
  [t["button--both-icons"]]: T,
57
57
  [t["button--only-icon"]]: s,
58
58
  [t["button--arrow"]]: v,
59
- [t["button--on-dark"]]: C
59
+ [t["button--on-dark"]]: y
60
60
  },
61
61
  G
62
62
  ), st = m(t.button__text, {
63
63
  [t["button__text--ellipsis"]]: S,
64
64
  [t["button__text--centered"]]: w && Z === "centered"
65
65
  }), at = m(t.diagonal, {
66
- [t["diagonal--on-dark"]]: C
66
+ [t["diagonal--on-dark"]]: y
67
67
  });
68
68
  bt(() => {
69
- yt(s, f, !gt() && !_t());
69
+ Ct(s, f, !gt() && !_t());
70
70
  }, []);
71
71
  const k = (l, ct, lt) => l ? x.cloneElement(l, {
72
72
  size: ct,
package/Button.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Button.js","sources":["../src/components/Button/Button.tsx"],"sourcesContent":["import React, { AriaAttributes, useEffect, useRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport Icon, { IconSize } from './../Icon';\nimport { HTMLButtonProps, HTMLAnchorProps, AnalyticsId } from '../../constants';\nimport { useBreakpoint } from '../../hooks/useBreakpoint';\nimport { useHover } from '../../hooks/useHover';\nimport { BaseIconElement, useIcons } from '../../hooks/useIcons';\nimport { getColor } from '../../theme/currys/color';\nimport { breakpoints } from '../../theme/grid';\nimport { isTest, isProd } from '../../utils/environment';\nimport ArrowRight from '../Icons/ArrowRight';\n\nimport buttonStyles from './styles.module.scss';\n\nexport type ButtonConcept = 'normal' | 'destructive';\nexport type ButtonVariant = 'fill' | 'outline' | 'borderless';\nexport type ButtonSize = 'medium' | 'large';\nexport type ButtonMode = 'onlight' | 'ondark';\nexport type ButtonTags = 'button' | 'a';\nexport type ButtonArrows = 'icon' | 'accessibility-character';\nexport type ButtonTextPosition = 'left' | 'centered';\n\nexport interface ButtonProps extends HTMLButtonProps, HTMLAnchorProps, AriaAttributes {\n /** Sets the aria-label of the button, use when the button only includes an icon */\n ariaLabel?: string;\n /** Gives a unique id to the button */\n id?: string;\n /** Sets the content of the button. */\n children: React.ReactNode;\n /** Adds custom classes to the wrapper element. */\n wrapperClassName?: string;\n /** Adds custom classes to the element. */\n className?: string;\n /** Enables an arrow icon to the right inside the button (Not available in borderless variant) */\n arrow?: ButtonArrows;\n /** Changes the intent of the button. Mostly changes the color profile. */\n concept?: ButtonConcept;\n /** Disables text wrapping and enables ellipsis. */\n ellipsis?: boolean;\n /** Makes the button scale to full width of its parent element. */\n fluid?: boolean;\n /** Changes the underlying element of the button. */\n htmlMarkup?: ButtonTags;\n /** Changes the button colors for different backgrounds. */\n mode?: ButtonMode;\n /** Function that is called when the Button loses focus */\n onBlur?: () => void;\n /** Function that is called when clicked */\n onClick?: (e?: React.MouseEvent<HTMLElement, MouseEvent> | React.FormEvent<{}> | React.KeyboardEvent<HTMLUListElement> | null) => void;\n /** Changes the button colors for different backgrounds. (Large not available in borderless variant) */\n size?: ButtonSize;\n /** Changes the visual representation of the button. */\n variant?: ButtonVariant;\n /** Specifies the focus order relative to the other buttons or controls on the page */\n tabIndex?: number;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Sets the position of the text in the button - only applies when button is fluid */\n textPosition?: ButtonTextPosition;\n /** Button type. Default: button */\n type?: React.ButtonHTMLAttributes<HTMLButtonElement>['type'];\n}\n\nconst getIconColor = (\n fill: boolean,\n borderless: boolean,\n disabled: boolean,\n concept: ButtonConcept,\n ondark: boolean,\n mobile: boolean\n): string => {\n if (mobile && disabled) {\n return !ondark || fill ? getColor('neutral', !borderless ? 700 : 500) : getColor('white');\n }\n if (disabled) {\n return !ondark || fill ? getColor('neutral', 500) : `${getColor('white')}b3`;\n }\n if ((fill && !ondark) || (!fill && ondark)) {\n return 'white';\n }\n\n return concept === 'normal' ? getColor('blueberry', 600) : getColor('cherry', 500);\n};\nconst getLargeIconSize = (large: boolean, mobile: boolean): IconSize => {\n if (mobile && large) return IconSize.Small;\n if (large) return IconSize.Medium;\n return IconSize.XSmall;\n};\n\nconst checkOnlyIconAria = (onlyIcon: boolean, ariaLabel: string | undefined, devEnv: boolean): void => {\n if (devEnv && onlyIcon && (ariaLabel === undefined || ariaLabel === '')) {\n throw new Error('Fyll inn ariaLabel prop på Button uten tekst for å opprettholde UU krav');\n }\n};\n\nconst Button = React.forwardRef(function ButtonForwardedRef(\n props: ButtonProps,\n ref: React.ForwardedRef<HTMLButtonElement | HTMLAnchorElement>\n) {\n const {\n ariaLabel,\n id,\n children,\n wrapperClassName,\n className,\n arrow,\n concept = 'normal',\n disabled = false,\n ellipsis = false,\n fluid = false,\n htmlMarkup = 'button',\n mode = 'onlight',\n onBlur,\n onClick,\n size = 'medium',\n variant = 'fill',\n href,\n tabIndex,\n testId,\n target,\n type = 'button',\n textPosition = 'left',\n ...restProps\n } = props;\n\n const [leftIcon, rightIcon, restChildren] = useIcons(React.Children.toArray(children));\n const { hoverRef, isHovered } =\n htmlMarkup === 'button'\n ? useHover<HTMLButtonElement>(ref as React.RefObject<HTMLButtonElement>)\n : useHover<HTMLAnchorElement>(ref as React.RefObject<HTMLAnchorElement>);\n const buttonContentRef = useRef<HTMLDivElement>(null);\n const onlyIcon = !!(leftIcon || rightIcon) && !restChildren;\n const bothIcons = leftIcon && (rightIcon || arrow) && !onlyIcon;\n const onDark = mode === 'ondark';\n const breakpoint = useBreakpoint();\n const mobile = breakpoint < breakpoints.md;\n const destructive = concept === 'destructive' && !disabled;\n const outlineVariant = variant === 'outline';\n const borderlessVariant = variant === 'borderless';\n const iconColor = getIconColor(variant === 'fill', borderlessVariant, disabled, concept, onDark, mobile);\n const hasArrow = arrow === 'icon' && !borderlessVariant;\n const large = size === 'large' && !destructive && !borderlessVariant;\n const hasUURightArrow = arrow === 'accessibility-character' && !fluid && !leftIcon && !rightIcon && !hasArrow && borderlessVariant;\n const rest = { ...restProps };\n\n const buttonWrapperClasses = classNames(\n buttonStyles['button-wrapper'],\n { [buttonStyles['button-wrapper--fluid']]: fluid || ellipsis },\n wrapperClassName\n );\n const buttonClasses = classNames(\n buttonStyles.button,\n {\n [buttonStyles['button--destructive']]: destructive,\n [buttonStyles['button--normal']]: !large,\n [buttonStyles['button--large']]: large,\n [buttonStyles['button--outline']]: outlineVariant,\n [buttonStyles['button--borderless']]: borderlessVariant,\n [buttonStyles['button--left-icon']]: leftIcon && !onlyIcon,\n [buttonStyles['button--right-icon']]: rightIcon && !onlyIcon,\n [buttonStyles['button--both-icons']]: bothIcons,\n [buttonStyles['button--only-icon']]: onlyIcon,\n [buttonStyles['button--arrow']]: hasArrow,\n [buttonStyles['button--on-dark']]: onDark,\n },\n className\n );\n const buttonTextClasses = classNames(buttonStyles['button__text'], {\n [buttonStyles['button__text--ellipsis']]: ellipsis,\n [buttonStyles['button__text--centered']]: fluid && textPosition === 'centered',\n });\n const diagonalClasses = classNames(buttonStyles['diagonal'], {\n [buttonStyles['diagonal--on-dark']]: onDark,\n });\n\n useEffect(() => {\n checkOnlyIconAria(onlyIcon, ariaLabel, !isTest() && !isProd());\n }, []);\n\n const renderIcon = (iconElement: BaseIconElement | null, iconSize: number, iconClassName?: string): BaseIconElement | null => {\n return iconElement\n ? React.cloneElement(iconElement, {\n size: iconSize,\n color: iconElement?.props.color && !disabled ? iconElement.props.color : iconColor,\n isHovered: !disabled && isHovered,\n className: iconClassName,\n })\n : null;\n };\n\n const renderButtonContent = (): JSX.Element => {\n return (\n <span className={buttonTextClasses} ref={buttonContentRef}>\n {disabled && borderlessVariant && (\n <span className={diagonalClasses}>\n <span className={buttonStyles['diagonal__line']} />\n </span>\n )}\n <span>{onlyIcon ? ariaLabel : restChildren}</span>\n </span>\n );\n };\n\n const renderbuttonContentWrapper = (): JSX.Element => (\n <span className={buttonClasses}>\n {renderIcon(leftIcon, getLargeIconSize(large, mobile), !onlyIcon ? buttonStyles['button__left-icon'] : undefined)}\n {renderButtonContent()}\n {hasArrow\n ? renderIcon(\n <Icon svgIcon={ArrowRight} />,\n getLargeIconSize(large, mobile),\n classNames(buttonStyles['button__arrow'], { [buttonStyles['button__arrow--both-icons']]: bothIcons })\n )\n : renderIcon(rightIcon, getLargeIconSize(large, mobile), buttonStyles['button__right-icon'])}\n {hasUURightArrow && (\n <span style={{ color: iconColor }} className={buttonStyles['button__right-unicode-arrow']} aria-hidden>\n {' →'}\n </span>\n )}\n </span>\n );\n\n return (\n <>\n {htmlMarkup === 'button' && (\n <button\n id={id}\n onBlur={onBlur}\n onClick={onClick}\n disabled={disabled}\n data-testid={testId}\n data-analyticsid={AnalyticsId.Button}\n className={buttonWrapperClasses}\n ref={hoverRef as React.ForwardedRef<HTMLButtonElement>}\n tabIndex={tabIndex}\n type={type}\n {...rest}\n >\n {renderbuttonContentWrapper()}\n </button>\n )}\n {htmlMarkup === 'a' && (\n <a\n id={id}\n onBlur={onBlur}\n onClick={onClick}\n data-testid={testId}\n data-analyticsid={AnalyticsId.Button}\n className={buttonWrapperClasses}\n href={href}\n target={target}\n rel={target === '_blank' ? 'noopener noreferrer' : props.rel}\n ref={hoverRef as React.ForwardedRef<HTMLAnchorElement>}\n tabIndex={tabIndex}\n {...restProps}\n >\n {renderbuttonContentWrapper()}\n </a>\n )}\n </>\n );\n});\n\nexport default Button;\n"],"names":["getIconColor","fill","borderless","disabled","concept","ondark","mobile","getColor","getLargeIconSize","large","IconSize","checkOnlyIconAria","onlyIcon","ariaLabel","devEnv","Button","React","props","ref","id","children","wrapperClassName","className","arrow","ellipsis","fluid","htmlMarkup","mode","onBlur","onClick","size","variant","href","tabIndex","testId","target","type","textPosition","restProps","leftIcon","rightIcon","restChildren","useIcons","hoverRef","isHovered","useHover","buttonContentRef","useRef","bothIcons","onDark","useBreakpoint","breakpoints","destructive","outlineVariant","borderlessVariant","iconColor","hasArrow","hasUURightArrow","rest","buttonWrapperClasses","classNames","buttonStyles","buttonClasses","buttonTextClasses","diagonalClasses","useEffect","isTest","isProd","renderIcon","iconElement","iconSize","iconClassName","renderButtonContent","jsxs","jsx","renderbuttonContentWrapper","Icon","ArrowRight","Fragment","AnalyticsId"],"mappings":";;;;;;;;;;;;;AAiEA,MAAMA,KAAe,CACnBC,GACAC,GACAC,GACAC,GACAC,GACAC,MAEIA,KAAUH,IACL,CAACE,KAAUJ,IAAOM,EAAS,WAAYL,IAAmB,MAAN,GAAS,IAAIK,EAAS,OAAO,IAEtFJ,IACK,CAACE,KAAUJ,IAAOM,EAAS,WAAW,GAAG,IAAI,GAAGA,EAAS,OAAO,CAAC,OAErEN,KAAQ,CAACI,KAAY,CAACJ,KAAQI,IAC1B,UAGFD,MAAY,WAAWG,EAAS,aAAa,GAAG,IAAIA,EAAS,UAAU,GAAG,GAE7EC,IAAmB,CAACC,GAAgBH,MACpCA,KAAUG,IAAcC,EAAS,QACjCD,IAAcC,EAAS,SACpBA,EAAS,QAGZC,KAAoB,CAACC,GAAmBC,GAA+BC,MAA0B;AACrG,MAAIA,KAAUF,MAAaC,MAAc,UAAaA,MAAc;AAC5D,UAAA,IAAI,MAAM,yEAAyE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AAAgD;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,IAAAvD;AAAA,QACA,QAAAS;AAAA,QACA,SAAAC;AAAA,QACA,UAAA1B;AAAA,QACA,eAAa+B;AAAA,QACb,oBAAkB6C,EAAY;AAAA,QAC9B,WAAWpB;AAAA,QACX,KAAKhB;AAAA,QACL,UAAAV;AAAA,QACA,MAAAG;AAAA,QACC,GAAGsB;AAAA,QAEH,UAA2BiB,EAAA;AAAA,MAAA;AAAA,IAC9B;AAAA,IAEDjD,MAAe,OACd,gBAAAgD;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,IAAAvD;AAAA,QACA,QAAAS;AAAA,QACA,SAAAC;AAAA,QACA,eAAaK;AAAA,QACb,oBAAkB6C,EAAY;AAAA,QAC9B,WAAWpB;AAAA,QACX,MAAA3B;AAAA,QACA,QAAAG;AAAA,QACA,KAAKA,MAAW,WAAW,wBAAwBlB,EAAM;AAAA,QACzD,KAAK0B;AAAA,QACL,UAAAV;AAAA,QACC,GAAGK;AAAA,QAEH,UAA2BqC,EAAA;AAAA,MAAA;AAAA,IAC9B;AAAA,EAEJ,EAAA,CAAA;AAEJ,CAAC;"}
1
+ {"version":3,"file":"Button.js","sources":["../src/components/Button/Button.tsx"],"sourcesContent":["import React, { AriaAttributes, useEffect, useRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport Icon, { IconSize } from './../Icon';\nimport { HTMLButtonProps, HTMLAnchorProps, AnalyticsId } from '../../constants';\nimport { useBreakpoint } from '../../hooks/useBreakpoint';\nimport { useHover } from '../../hooks/useHover';\nimport { BaseIconElement, useIcons } from '../../hooks/useIcons';\nimport { getColor } from '../../theme/currys/color';\nimport { breakpoints } from '../../theme/grid';\nimport { isTest, isProd } from '../../utils/environment';\nimport ArrowRight from '../Icons/ArrowRight';\n\nimport buttonStyles from './styles.module.scss';\n\nexport type ButtonConcept = 'normal' | 'destructive';\nexport type ButtonVariant = 'fill' | 'outline' | 'borderless';\nexport type ButtonSize = 'medium' | 'large';\nexport type ButtonOnColor = 'onlight' | 'ondark';\nexport type ButtonTags = 'button' | 'a';\nexport type ButtonArrows = 'icon' | 'accessibility-character';\nexport type ButtonTextPosition = 'left' | 'centered';\n\nexport interface ButtonProps extends HTMLButtonProps, HTMLAnchorProps, AriaAttributes {\n /** Sets the aria-label of the button, use when the button only includes an icon */\n ariaLabel?: string;\n /** Gives a unique id to the button */\n id?: string;\n /** Sets the content of the button. */\n children: React.ReactNode;\n /** Adds custom classes to the wrapper element. */\n wrapperClassName?: string;\n /** Adds custom classes to the element. */\n className?: string;\n /** Enables an arrow icon to the right inside the button (Not available in borderless variant) */\n arrow?: ButtonArrows;\n /** Changes the intent of the button. Mostly changes the color profile. */\n concept?: ButtonConcept;\n /** Disables text wrapping and enables ellipsis. */\n ellipsis?: boolean;\n /** Makes the button scale to full width of its parent element. */\n fluid?: boolean;\n /** Changes the underlying element of the button. */\n htmlMarkup?: ButtonTags;\n /** Changes the button colors for different backgrounds. */\n onColor?: ButtonOnColor;\n /** Function that is called when the Button loses focus */\n onBlur?: () => void;\n /** Function that is called when clicked */\n onClick?: (e?: React.MouseEvent<HTMLElement, MouseEvent> | React.FormEvent<{}> | React.KeyboardEvent<HTMLUListElement> | null) => void;\n /** Changes the button colors for different backgrounds. (Large not available in borderless variant) */\n size?: ButtonSize;\n /** Changes the visual representation of the button. */\n variant?: ButtonVariant;\n /** Specifies the focus order relative to the other buttons or controls on the page */\n tabIndex?: number;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Sets the position of the text in the button - only applies when button is fluid */\n textPosition?: ButtonTextPosition;\n /** Button type. Default: button */\n type?: React.ButtonHTMLAttributes<HTMLButtonElement>['type'];\n}\n\nconst getIconColor = (\n fill: boolean,\n borderless: boolean,\n disabled: boolean,\n concept: ButtonConcept,\n ondark: boolean,\n mobile: boolean\n): string => {\n if (mobile && disabled) {\n return !ondark || fill ? getColor('neutral', !borderless ? 700 : 500) : getColor('white');\n }\n if (disabled) {\n return !ondark || fill ? getColor('neutral', 500) : `${getColor('white')}b3`;\n }\n if ((fill && !ondark) || (!fill && ondark)) {\n return 'white';\n }\n\n return concept === 'normal' ? getColor('blueberry', 600) : getColor('cherry', 500);\n};\nconst getLargeIconSize = (large: boolean, mobile: boolean): IconSize => {\n if (mobile && large) return IconSize.Small;\n if (large) return IconSize.Medium;\n return IconSize.XSmall;\n};\n\nconst checkOnlyIconAria = (onlyIcon: boolean, ariaLabel: string | undefined, devEnv: boolean): void => {\n if (devEnv && onlyIcon && (ariaLabel === undefined || ariaLabel === '')) {\n throw new Error('Fyll inn ariaLabel prop på Button uten tekst for å opprettholde UU krav');\n }\n};\n\nconst Button = React.forwardRef(function ButtonForwardedRef(\n props: ButtonProps,\n ref: React.ForwardedRef<HTMLButtonElement | HTMLAnchorElement>\n) {\n const {\n ariaLabel,\n id,\n children,\n wrapperClassName,\n className,\n arrow,\n concept = 'normal',\n disabled = false,\n ellipsis = false,\n fluid = false,\n htmlMarkup = 'button',\n onColor = 'onlight',\n onBlur,\n onClick,\n size = 'medium',\n variant = 'fill',\n href,\n tabIndex,\n testId,\n target,\n type = 'button',\n textPosition = 'left',\n ...restProps\n } = props;\n\n const [leftIcon, rightIcon, restChildren] = useIcons(React.Children.toArray(children));\n const { hoverRef, isHovered } =\n htmlMarkup === 'button'\n ? useHover<HTMLButtonElement>(ref as React.RefObject<HTMLButtonElement>)\n : useHover<HTMLAnchorElement>(ref as React.RefObject<HTMLAnchorElement>);\n const buttonContentRef = useRef<HTMLDivElement>(null);\n const onlyIcon = !!(leftIcon || rightIcon) && !restChildren;\n const bothIcons = leftIcon && (rightIcon || arrow) && !onlyIcon;\n const onDark = onColor === 'ondark';\n const breakpoint = useBreakpoint();\n const mobile = breakpoint < breakpoints.md;\n const destructive = concept === 'destructive' && !disabled;\n const outlineVariant = variant === 'outline';\n const borderlessVariant = variant === 'borderless';\n const iconColor = getIconColor(variant === 'fill', borderlessVariant, disabled, concept, onDark, mobile);\n const hasArrow = arrow === 'icon' && !borderlessVariant;\n const large = size === 'large' && !destructive && !borderlessVariant;\n const hasUURightArrow = arrow === 'accessibility-character' && !fluid && !leftIcon && !rightIcon && !hasArrow && borderlessVariant;\n const rest = { ...restProps };\n\n const buttonWrapperClasses = classNames(\n buttonStyles['button-wrapper'],\n { [buttonStyles['button-wrapper--fluid']]: fluid || ellipsis },\n wrapperClassName\n );\n const buttonClasses = classNames(\n buttonStyles.button,\n {\n [buttonStyles['button--destructive']]: destructive,\n [buttonStyles['button--normal']]: !large,\n [buttonStyles['button--large']]: large,\n [buttonStyles['button--outline']]: outlineVariant,\n [buttonStyles['button--borderless']]: borderlessVariant,\n [buttonStyles['button--left-icon']]: leftIcon && !onlyIcon,\n [buttonStyles['button--right-icon']]: rightIcon && !onlyIcon,\n [buttonStyles['button--both-icons']]: bothIcons,\n [buttonStyles['button--only-icon']]: onlyIcon,\n [buttonStyles['button--arrow']]: hasArrow,\n [buttonStyles['button--on-dark']]: onDark,\n },\n className\n );\n const buttonTextClasses = classNames(buttonStyles['button__text'], {\n [buttonStyles['button__text--ellipsis']]: ellipsis,\n [buttonStyles['button__text--centered']]: fluid && textPosition === 'centered',\n });\n const diagonalClasses = classNames(buttonStyles['diagonal'], {\n [buttonStyles['diagonal--on-dark']]: onDark,\n });\n\n useEffect(() => {\n checkOnlyIconAria(onlyIcon, ariaLabel, !isTest() && !isProd());\n }, []);\n\n const renderIcon = (iconElement: BaseIconElement | null, iconSize: number, iconClassName?: string): BaseIconElement | null => {\n return iconElement\n ? React.cloneElement(iconElement, {\n size: iconSize,\n color: iconElement?.props.color && !disabled ? iconElement.props.color : iconColor,\n isHovered: !disabled && isHovered,\n className: iconClassName,\n })\n : null;\n };\n\n const renderButtonContent = (): JSX.Element => {\n return (\n <span className={buttonTextClasses} ref={buttonContentRef}>\n {disabled && borderlessVariant && (\n <span className={diagonalClasses}>\n <span className={buttonStyles['diagonal__line']} />\n </span>\n )}\n <span>{onlyIcon ? ariaLabel : restChildren}</span>\n </span>\n );\n };\n\n const renderbuttonContentWrapper = (): JSX.Element => (\n <span className={buttonClasses}>\n {renderIcon(leftIcon, getLargeIconSize(large, mobile), !onlyIcon ? buttonStyles['button__left-icon'] : undefined)}\n {renderButtonContent()}\n {hasArrow\n ? renderIcon(\n <Icon svgIcon={ArrowRight} />,\n getLargeIconSize(large, mobile),\n classNames(buttonStyles['button__arrow'], { [buttonStyles['button__arrow--both-icons']]: bothIcons })\n )\n : renderIcon(rightIcon, getLargeIconSize(large, mobile), buttonStyles['button__right-icon'])}\n {hasUURightArrow && (\n <span style={{ color: iconColor }} className={buttonStyles['button__right-unicode-arrow']} aria-hidden>\n {' →'}\n </span>\n )}\n </span>\n );\n\n return (\n <>\n {htmlMarkup === 'button' && (\n <button\n id={id}\n onBlur={onBlur}\n onClick={onClick}\n disabled={disabled}\n data-testid={testId}\n data-analyticsid={AnalyticsId.Button}\n className={buttonWrapperClasses}\n ref={hoverRef as React.ForwardedRef<HTMLButtonElement>}\n tabIndex={tabIndex}\n type={type}\n {...rest}\n >\n {renderbuttonContentWrapper()}\n </button>\n )}\n {htmlMarkup === 'a' && (\n <a\n id={id}\n onBlur={onBlur}\n onClick={onClick}\n data-testid={testId}\n data-analyticsid={AnalyticsId.Button}\n className={buttonWrapperClasses}\n href={href}\n target={target}\n rel={target === '_blank' ? 'noopener noreferrer' : props.rel}\n ref={hoverRef as React.ForwardedRef<HTMLAnchorElement>}\n tabIndex={tabIndex}\n {...restProps}\n >\n {renderbuttonContentWrapper()}\n </a>\n )}\n </>\n );\n});\n\nexport default Button;\n"],"names":["getIconColor","fill","borderless","disabled","concept","ondark","mobile","getColor","getLargeIconSize","large","IconSize","checkOnlyIconAria","onlyIcon","ariaLabel","devEnv","Button","React","props","ref","id","children","wrapperClassName","className","arrow","ellipsis","fluid","htmlMarkup","onColor","onBlur","onClick","size","variant","href","tabIndex","testId","target","type","textPosition","restProps","leftIcon","rightIcon","restChildren","useIcons","hoverRef","isHovered","useHover","buttonContentRef","useRef","bothIcons","onDark","useBreakpoint","breakpoints","destructive","outlineVariant","borderlessVariant","iconColor","hasArrow","hasUURightArrow","rest","buttonWrapperClasses","classNames","buttonStyles","buttonClasses","buttonTextClasses","diagonalClasses","useEffect","isTest","isProd","renderIcon","iconElement","iconSize","iconClassName","renderButtonContent","jsxs","jsx","renderbuttonContentWrapper","Icon","ArrowRight","Fragment","AnalyticsId"],"mappings":";;;;;;;;;;;;;AAiEA,MAAMA,KAAe,CACnBC,GACAC,GACAC,GACAC,GACAC,GACAC,MAEIA,KAAUH,IACL,CAACE,KAAUJ,IAAOM,EAAS,WAAYL,IAAmB,MAAN,GAAS,IAAIK,EAAS,OAAO,IAEtFJ,IACK,CAACE,KAAUJ,IAAOM,EAAS,WAAW,GAAG,IAAI,GAAGA,EAAS,OAAO,CAAC,OAErEN,KAAQ,CAACI,KAAY,CAACJ,KAAQI,IAC1B,UAGFD,MAAY,WAAWG,EAAS,aAAa,GAAG,IAAIA,EAAS,UAAU,GAAG,GAE7EC,IAAmB,CAACC,GAAgBH,MACpCA,KAAUG,IAAcC,EAAS,QACjCD,IAAcC,EAAS,SACpBA,EAAS,QAGZC,KAAoB,CAACC,GAAmBC,GAA+BC,MAA0B;AACrG,MAAIA,KAAUF,MAAaC,MAAc,UAAaA,MAAc;AAC5D,UAAA,IAAI,MAAM,yEAAyE;AAE7F,GAEME,KAASC,EAAM,WAAW,SAC9BC,GACAC,GACA;AACM,QAAA;AAAA,IACJ,WAAAL;AAAA,IACA,IAAAM;AAAA,IACA,UAAAC;AAAA,IACA,kBAAAC;AAAA,IACA,WAAAC;AAAA,IACA,OAAAC;AAAA,IACA,SAAAnB,IAAU;AAAA,IACV,UAAAD,IAAW;AAAA,IACX,UAAAqB,IAAW;AAAA,IACX,OAAAC,IAAQ;AAAA,IACR,YAAAC,IAAa;AAAA,IACb,SAAAC,IAAU;AAAA,IACV,QAAAC;AAAA,IACA,SAAAC;AAAA,IACA,MAAAC,IAAO;AAAA,IACP,SAAAC,IAAU;AAAA,IACV,M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AAA,QACA,eAAaK;AAAA,QACb,oBAAkB6C,EAAY;AAAA,QAC9B,WAAWpB;AAAA,QACX,MAAA3B;AAAA,QACA,QAAAG;AAAA,QACA,KAAKA,MAAW,WAAW,wBAAwBlB,EAAM;AAAA,QACzD,KAAK0B;AAAA,QACL,UAAAV;AAAA,QACC,GAAGK;AAAA,QAEH,UAA2BqC,EAAA;AAAA,MAAA;AAAA,IAC9B;AAAA,EAEJ,EAAA,CAAA;AAEJ,CAAC;"}
package/Checkbox.js CHANGED
@@ -1,80 +1,80 @@
1
- import { jsx as s, jsxs as G, Fragment as H } from "react/jsx-runtime";
2
- import X, { useState as J, useEffect as K } from "react";
1
+ import { jsx as s, jsxs as M, Fragment as X } from "react/jsx-runtime";
2
+ import J, { useState as K, useEffect as Q } from "react";
3
3
  import b from "classnames";
4
- import { FormMode as i, FormSize as Q, AnalyticsId as V, IconSize as Y } from "./constants.js";
5
- import { usePseudoClasses as Z } from "./hooks/usePseudoClasses.js";
6
- import { useUuid as $ } from "./hooks/useUuid.js";
4
+ import { FormOnColor as n, FormSize as V, AnalyticsId as Y, IconSize as Z } from "./constants.js";
5
+ import { usePseudoClasses as $ } from "./hooks/usePseudoClasses.js";
6
+ import { useUuid as ee } from "./hooks/useUuid.js";
7
7
  import { getColor as _ } from "./theme/currys/color.js";
8
- import { getAriaDescribedBy as ee } from "./utils/accessibility.js";
9
- import { isMutableRefObject as re, mergeRefs as ce } from "./utils/refs.js";
10
- import { u as oe } from "./uuid.js";
11
- import { E as ae } from "./ErrorWrapper.js";
12
- import { I as le } from "./Icon.js";
8
+ import { getAriaDescribedBy as re } from "./utils/accessibility.js";
9
+ import { isMutableRefObject as ce, mergeRefs as oe } from "./utils/refs.js";
10
+ import { u as ae } from "./uuid.js";
11
+ import { E as le } from "./ErrorWrapper.js";
12
+ import { I as ne } from "./Icon.js";
13
13
  import ie from "./components/Icons/Check.js";
14
- import { g as ne, r as se } from "./Label.js";
14
+ import { g as se, r as be } from "./Label.js";
15
15
  import e from "./components/Checkbox/styles.module.scss";
16
- const be = X.forwardRef((x, h) => {
16
+ const te = J.forwardRef((k, h) => {
17
17
  const {
18
18
  className: I,
19
19
  checked: d = !1,
20
20
  disabled: a,
21
- label: m,
22
- inputId: p = oe(),
23
- mode: l = i.onwhite,
21
+ label: x,
22
+ inputId: p = ae(),
23
+ onColor: l = n.onwhite,
24
24
  name: N = p,
25
25
  size: T,
26
- errorText: k,
27
- error: g = !!k,
26
+ errorText: m,
27
+ error: g = !!m,
28
28
  errorTextId: R,
29
- value: S = ne(m),
29
+ errorWrapperClassName: S,
30
+ value: W = se(x),
30
31
  testId: j,
31
32
  required: z,
32
33
  onChange: u,
33
34
  ...F
34
- } = x, [c, f] = J(d), w = $(R), C = l === i.onwhite, y = l === i.ongrey, v = l === i.onblueberry, o = g || l === i.oninvalid, n = l === i.ondark, r = T === Q.large, { refObject: L, isFocused: W } = Z(re(h) ? h : null), A = ce([h, L]), E = b({
35
- [e["checkbox-wrapper--with-error"]]: k,
35
+ } = k, [c, f] = K(d), w = ee(R), C = l === n.onwhite, y = l === n.ongrey, v = l === n.onblueberry, o = g || l === n.oninvalid, i = l === n.ondark, r = T === V.large, { refObject: L, isFocused: A } = $(ce(h) ? h : null), E = oe([h, L]), O = b({
36
36
  [e["checkbox-wrapper--large"]]: r
37
37
  }), B = b(e["checkbox-label"], {
38
38
  [e["checkbox-label--disabled"]]: a,
39
- [e["checkbox-label--on-dark"]]: n,
39
+ [e["checkbox-label--on-dark"]]: i,
40
40
  [e["checkbox-label--large"]]: r,
41
41
  [e["checkbox-label__large--checked"]]: r && c,
42
- [e["checkbox-label__large--focus"]]: r && W,
42
+ [e["checkbox-label__large--focus"]]: r && A,
43
43
  [e["checkbox-label__large--on-white"]]: r && C,
44
44
  [e["checkbox-label__large--on-grey"]]: r && y,
45
45
  [e["checkbox-label__large--on-blueberry"]]: r && v,
46
46
  [e["checkbox-label__large--on-invalid"]]: r && o,
47
47
  [e["checkbox-label__large--disabled"]]: r && a
48
- }), D = b(e.checkbox, I), M = b(e["checkbox__icon-wrapper"], {
48
+ }), D = b(e.checkbox, I), P = b(e["checkbox__icon-wrapper"], {
49
49
  [e["checkbox__icon-wrapper--on-white"]]: C,
50
50
  [e["checkbox__icon-wrapper--on-grey"]]: y,
51
51
  [e["checkbox__icon-wrapper--on-invalid"]]: o,
52
52
  [e["checkbox__icon-wrapper--disabled"]]: a,
53
53
  [e["checkbox__icon-wrapper__regular--checked"]]: !r && c,
54
54
  [e["checkbox__icon-wrapper__regular--invalid"]]: !r && c && o,
55
- [e["checkbox__icon-wrapper__regular--on-dark"]]: !r && c && n,
55
+ [e["checkbox__icon-wrapper__regular--on-dark"]]: !r && c && i,
56
56
  [e["checkbox__icon-wrapper__large--checked"]]: r && c,
57
57
  [e["checkbox__icon-wrapper__large--invalid"]]: r && o,
58
- [e["checkbox__icon-wrapper--on-dark"]]: n,
58
+ [e["checkbox__icon-wrapper--on-dark"]]: i,
59
59
  [e["checkbox__icon-wrapper--on-blueberry"]]: v,
60
60
  [e["checkbox__icon-wrapper--invalid"]]: o,
61
61
  [e["checkbox__icon-wrapper__large--invalid"]]: r && c && o,
62
62
  [e["checkbox__icon-wrapper__large--disabled"]]: a && r && c,
63
63
  [e["checkbox__icon-wrapper__large--checked--invalid"]]: r && c && o,
64
64
  [e["checkbox__icon-wrapper__large--checked--disabled"]]: a && r && c
65
- }), O = b(e["checkbox-label__text"], {
65
+ }), U = b(e["checkbox-label__text"], {
66
66
  [e["checkbox-label__text__large--checked"]]: r && c,
67
67
  [e["checkbox-label__text__large--invalid"]]: r && c && o,
68
- [e["checkbox-label__text--on-dark"]]: n,
68
+ [e["checkbox-label__text--on-dark"]]: i,
69
69
  [e["checkbox-label__text--disabled"]]: a
70
70
  });
71
71
  let t = _("white");
72
- (n || r && c) && (t = _("blueberry", 900)), o && r && c && (t = _("white")), a && (t = _("neutral", 700)), K(() => {
72
+ (i || r && c) && (t = _("blueberry", 900)), o && r && c && (t = _("white")), a && (t = _("neutral", 700)), Q(() => {
73
73
  f(d);
74
74
  }, [d]);
75
- const P = (q) => {
76
- u && u(q), f(!c);
77
- }, U = () => /* @__PURE__ */ G(H, { children: [
75
+ const q = (H) => {
76
+ u && u(H), f(!c);
77
+ }, G = () => /* @__PURE__ */ M(X, { children: [
78
78
  /* @__PURE__ */ s(
79
79
  "input",
80
80
  {
@@ -84,30 +84,30 @@ const be = X.forwardRef((x, h) => {
84
84
  type: "checkbox",
85
85
  checked: c,
86
86
  disabled: a,
87
- value: S,
88
- ref: A,
89
- "aria-describedby": ee(x, w),
87
+ value: W,
88
+ ref: E,
89
+ "aria-describedby": re(k, w),
90
90
  "aria-invalid": g,
91
91
  required: z,
92
- onChange: P,
92
+ onChange: q,
93
93
  ...F
94
94
  }
95
95
  ),
96
- /* @__PURE__ */ s("span", { className: M, children: c && /* @__PURE__ */ s(le, { color: t, className: e.checkbox__icon, svgIcon: ie, size: Y.XSmall }) })
96
+ /* @__PURE__ */ s("span", { className: P, children: c && /* @__PURE__ */ s(ne, { color: t, className: e.checkbox__icon, svgIcon: ie, size: Z.XSmall }) })
97
97
  ] });
98
- return /* @__PURE__ */ s(ae, { errorText: k, errorTextId: w, children: /* @__PURE__ */ s("div", { "data-testid": j, "data-analyticsid": V.Checkbox, className: E, children: se(
99
- m,
100
- U(),
98
+ return /* @__PURE__ */ s(le, { className: S, errorText: m, errorTextId: w, children: /* @__PURE__ */ s("div", { "data-testid": j, "data-analyticsid": Y.Checkbox, className: O, children: be(
99
+ x,
100
+ G(),
101
101
  p,
102
102
  l,
103
103
  B,
104
- O,
104
+ U,
105
105
  e["checkbox-sublabel-wrapper"],
106
106
  r
107
107
  ) }) });
108
108
  });
109
- be.displayName = "Checkbox";
109
+ te.displayName = "Checkbox";
110
110
  export {
111
- be as C
111
+ te as C
112
112
  };
113
113
  //# sourceMappingURL=Checkbox.js.map
package/Checkbox.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Checkbox.js","sources":["../src/components/Checkbox/Checkbox.tsx"],"sourcesContent":["import React, { useEffect, useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport { AnalyticsId, FormMode, FormSize, IconSize } from '../../constants';\nimport { usePseudoClasses } from '../../hooks/usePseudoClasses';\nimport { useUuid } from '../../hooks/useUuid';\nimport { getColor } from '../../theme/currys/color';\nimport { getAriaDescribedBy } from '../../utils/accessibility';\nimport { isMutableRefObject, mergeRefs } from '../../utils/refs';\nimport { uuid } from '../../utils/uuid';\nimport ErrorWrapper from '../ErrorWrapper';\nimport Icon from '../Icon';\nimport Check from '../Icons/Check';\nimport { getLabelText, renderLabelAsParent } from '../Label';\n\nimport checkboxStyles from './styles.module.scss';\n\nexport interface CheckboxProps\n extends Pick<\n React.InputHTMLAttributes<HTMLInputElement>,\n 'aria-describedby' | 'name' | 'value' | 'disabled' | 'checked' | 'required' | 'onChange'\n > {\n /** Adds custom classes to the element. */\n className?: string;\n /** The <Label/> next to the checkbox - sublabels kan ikke kombineres med large variant */\n label: React.ReactNode;\n /** input id of the checkbox */\n inputId?: string;\n /** Changes the visuals of the checkbox */\n mode?: keyof typeof FormMode;\n /** Changes the visuals of the checkbox */\n size?: keyof typeof FormSize;\n /** Activates Error style for the checkbox - This is can be true while errorText is empty, when in a FormGroup */\n error?: boolean;\n /** Error text to show above the component */\n errorText?: string;\n /** Error text id */\n errorTextId?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport const Checkbox = React.forwardRef((props: CheckboxProps, ref: React.Ref<HTMLInputElement>) => {\n const {\n className,\n checked = false,\n disabled,\n label,\n inputId = uuid(),\n mode = FormMode.onwhite,\n name = inputId,\n size,\n errorText,\n error = !!errorText,\n errorTextId,\n value = getLabelText(label),\n testId,\n required,\n onChange,\n ...rest\n } = props;\n const [isChecked, setIsChecked] = useState(checked);\n const errorTextUuid = useUuid(errorTextId);\n const onWhite = mode === FormMode.onwhite;\n const onGrey = mode === FormMode.ongrey;\n const onBlueberry = mode === FormMode.onblueberry;\n const onInvalid = error || mode === FormMode.oninvalid;\n const onDark = mode === FormMode.ondark;\n const large = size === FormSize.large;\n const { refObject, isFocused } = usePseudoClasses<HTMLInputElement>(isMutableRefObject(ref) ? ref : null);\n const mergedRefs = mergeRefs([ref, refObject]);\n\n const checkboxWrapperClasses = classNames({\n [checkboxStyles['checkbox-wrapper--with-error']]: errorText,\n [checkboxStyles['checkbox-wrapper--large']]: large,\n });\n const checkboxLabelClasses = classNames(checkboxStyles['checkbox-label'], {\n [checkboxStyles['checkbox-label--disabled']]: disabled,\n [checkboxStyles['checkbox-label--on-dark']]: onDark,\n [checkboxStyles['checkbox-label--large']]: large,\n [checkboxStyles['checkbox-label__large--checked']]: large && isChecked,\n [checkboxStyles['checkbox-label__large--focus']]: large && isFocused,\n [checkboxStyles['checkbox-label__large--on-white']]: large && onWhite,\n [checkboxStyles['checkbox-label__large--on-grey']]: large && onGrey,\n [checkboxStyles['checkbox-label__large--on-blueberry']]: large && onBlueberry,\n [checkboxStyles['checkbox-label__large--on-invalid']]: large && onInvalid,\n [checkboxStyles['checkbox-label__large--disabled']]: large && disabled,\n });\n const checkboxClasses = classNames(checkboxStyles.checkbox, className);\n const checkboxIconWrapperClasses = classNames(checkboxStyles['checkbox__icon-wrapper'], {\n [checkboxStyles['checkbox__icon-wrapper--on-white']]: onWhite,\n [checkboxStyles['checkbox__icon-wrapper--on-grey']]: onGrey,\n [checkboxStyles['checkbox__icon-wrapper--on-invalid']]: onInvalid,\n [checkboxStyles['checkbox__icon-wrapper--disabled']]: disabled,\n [checkboxStyles['checkbox__icon-wrapper__regular--checked']]: !large && isChecked,\n [checkboxStyles['checkbox__icon-wrapper__regular--invalid']]: !large && isChecked && onInvalid,\n [checkboxStyles['checkbox__icon-wrapper__regular--on-dark']]: !large && isChecked && onDark,\n [checkboxStyles['checkbox__icon-wrapper__large--checked']]: large && isChecked,\n [checkboxStyles['checkbox__icon-wrapper__large--invalid']]: large && onInvalid,\n [checkboxStyles['checkbox__icon-wrapper--on-dark']]: onDark,\n [checkboxStyles['checkbox__icon-wrapper--on-blueberry']]: onBlueberry,\n [checkboxStyles['checkbox__icon-wrapper--invalid']]: onInvalid,\n [checkboxStyles['checkbox__icon-wrapper__large--invalid']]: large && isChecked && onInvalid,\n [checkboxStyles['checkbox__icon-wrapper__large--disabled']]: disabled && large && isChecked,\n [checkboxStyles['checkbox__icon-wrapper__large--checked--invalid']]: large && isChecked && onInvalid,\n [checkboxStyles['checkbox__icon-wrapper__large--checked--disabled']]: disabled && large && isChecked,\n });\n const labelTextClasses = classNames(checkboxStyles['checkbox-label__text'], {\n [checkboxStyles['checkbox-label__text__large--checked']]: large && isChecked,\n [checkboxStyles['checkbox-label__text__large--invalid']]: large && isChecked && onInvalid,\n [checkboxStyles['checkbox-label__text--on-dark']]: onDark,\n [checkboxStyles['checkbox-label__text--disabled']]: disabled,\n });\n\n let iconColor = getColor('white');\n if (onDark || (large && isChecked)) iconColor = getColor('blueberry', 900);\n if (onInvalid && large && isChecked) iconColor = getColor('white');\n if (disabled) iconColor = getColor('neutral', 700);\n\n useEffect(() => {\n setIsChecked(checked);\n }, [checked]);\n\n const onChangeHandler = (e: React.ChangeEvent<HTMLInputElement>): void => {\n if (onChange) {\n onChange(e);\n }\n\n setIsChecked(!isChecked);\n };\n\n const getLabelContent = (): React.ReactNode => {\n return (\n <>\n <input\n id={inputId}\n name={name}\n className={checkboxClasses}\n type=\"checkbox\"\n checked={isChecked}\n disabled={disabled}\n value={value}\n ref={mergedRefs}\n aria-describedby={getAriaDescribedBy(props, errorTextUuid)}\n aria-invalid={error}\n required={required}\n onChange={onChangeHandler}\n {...rest}\n />\n <span className={checkboxIconWrapperClasses}>\n {isChecked && <Icon color={iconColor} className={checkboxStyles['checkbox__icon']} svgIcon={Check} size={IconSize.XSmall} />}\n </span>\n </>\n );\n };\n\n return (\n <ErrorWrapper errorText={errorText} errorTextId={errorTextUuid}>\n <div data-testid={testId} data-analyticsid={AnalyticsId.Checkbox} className={checkboxWrapperClasses}>\n {renderLabelAsParent(\n label,\n getLabelContent(),\n inputId,\n mode as FormMode,\n checkboxLabelClasses,\n labelTextClasses,\n checkboxStyles['checkbox-sublabel-wrapper'],\n large\n )}\n </div>\n </ErrorWrapper>\n );\n});\n\nCheckbox.displayName = 'Checkbox';\n\nexport default Checkbox;\n"],"names":["Checkbox","React","props","ref","className","checked","disabled","label","inputId","uuid","mode","FormMode","name","size","errorText","error","errorTextId","value","getLabelText","testId","required","onChange","rest","isChecked","setIsChecked","useState","errorTextUuid","useUuid","onWhite","onGrey","onBlueberry","onInvalid","onDark","large","FormSize","refObject","isFocused","usePseudoClasses","isMutableRefObject","mergedRefs","mergeRefs","checkboxWrapperClasses","classNames","checkboxStyles","checkboxLabelClasses","checkboxClasses","checkboxIconWrapperClasses","labelTextClasses","iconColor","getColor","useEffect","onChangeHandler","e","getLabelContent","jsxs","Fragment","jsx","getAriaDescribedBy","Icon","Check","IconSize","ErrorWrapper","AnalyticsId","renderLabelAsParent"],"mappings":";;;;;;;;;;;;;;;AA2CO,MAAMA,KAAWC,EAAM,WAAW,CAACC,GAAsBC,MAAqC;AAC7F,QAAA;AAAA,IACJ,WAAAC;AAAA,IACA,SAAAC,IAAU;AAAA,IACV,UAAAC;AAAA,IACA,OAAAC;AAAA,IACA,SAAAC,IAAUC,GAAK;AAAA,IACf,MAAAC,IAAOC,EAAS;AAAA,IAChB,MAAAC,IAAOJ;AAAA,IACP,MAAAK;AAAA,IACA,WAAAC;AAAA,IACA,OAAAC,IAAQ,CAAC,CAACD;AAAA,IACV,aAAAE;AAAA,IACA,OAAAC,IAAQC,GAAaX,CAAK;AAAA,IAC1B,QAAAY;AAAA,IACA,UAAAC;AAAA,IACA,UAAAC;AAAA,IACA,GAAGC;AAAA,EACD,IAAApB,GACE,CAACqB,GAAWC,CAAY,IAAIC,EAASpB,CAAO,GAC5CqB,IAAgBC,EAAQX,CAAW,GACnCY,IAAUlB,MAASC,EAAS,SAC5BkB,IAASnB,MAASC,EAAS,QAC3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CAACA,CAAO,CAAC;AAEN,QAAA8C,IAAkB,CAACC,MAAiD;AACxE,IAAI/B,KACFA,EAAS+B,CAAC,GAGZ5B,EAAa,CAACD,CAAS;AAAA,EAAA,GAGnB8B,IAAkB,MAGlB,gBAAAC,EAAAC,GAAA,EAAA,UAAA;AAAA,IAAA,gBAAAC;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,IAAIhD;AAAA,QACJ,MAAAI;AAAA,QACA,WAAWiC;AAAA,QACX,MAAK;AAAA,QACL,SAAStB;AAAA,QACT,UAAAjB;AAAA,QACA,OAAAW;AAAA,QACA,KAAKsB;AAAA,QACL,oBAAkBkB,GAAmBvD,GAAOwB,CAAa;AAAA,QACzD,gBAAcX;AAAA,QACd,UAAAK;AAAA,QACA,UAAU+B;AAAA,QACT,GAAG7B;AAAA,MAAA;AAAA,IACN;AAAA,sBACC,QAAK,EAAA,WAAWwB,GACd,UAAavB,KAAA,gBAAAiC,EAACE,MAAK,OAAOV,GAAW,WAAWL,EAAe,gBAAmB,SAASgB,IAAO,MAAMC,EAAS,OAAQ,CAAA,GAC5H;AAAA,EACF,EAAA,CAAA;AAIJ,SACG,gBAAAJ,EAAAK,IAAA,EAAa,WAAA/C,GAAsB,aAAaY,GAC/C,UAAA,gBAAA8B,EAAC,OAAI,EAAA,eAAarC,GAAQ,oBAAkB2C,EAAY,UAAU,WAAWrB,GAC1E,UAAAsB;AAAA,IACCxD;AAAA,IACA8C,EAAgB;AAAA,IAChB7C;AAAA,IACAE;AAAA,IACAkC;AAAA,IACAG;AAAA,IACAJ,EAAe,2BAA2B;AAAA,IAC1CV;AAAA,EAAA,EAEJ,CAAA,EACF,CAAA;AAEJ,CAAC;AAEDjC,GAAS,cAAc;"}
1
+ {"version":3,"file":"Checkbox.js","sources":["../src/components/Checkbox/Checkbox.tsx"],"sourcesContent":["import React, { useEffect, useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport { AnalyticsId, FormOnColor, FormSize, IconSize } from '../../constants';\nimport { usePseudoClasses } from '../../hooks/usePseudoClasses';\nimport { useUuid } from '../../hooks/useUuid';\nimport { getColor } from '../../theme/currys/color';\nimport { getAriaDescribedBy } from '../../utils/accessibility';\nimport { isMutableRefObject, mergeRefs } from '../../utils/refs';\nimport { uuid } from '../../utils/uuid';\nimport ErrorWrapper, { ErrorWrapperClassNameProps } from '../ErrorWrapper';\nimport Icon from '../Icon';\nimport Check from '../Icons/Check';\nimport { getLabelText, renderLabelAsParent } from '../Label';\n\nimport checkboxStyles from './styles.module.scss';\n\nexport interface CheckboxProps\n extends ErrorWrapperClassNameProps,\n Pick<\n React.InputHTMLAttributes<HTMLInputElement>,\n 'aria-describedby' | 'name' | 'value' | 'disabled' | 'checked' | 'required' | 'onChange'\n > {\n /** Adds custom classes to the element. */\n className?: string;\n /** The <Label/> next to the checkbox - sublabels kan ikke kombineres med large variant */\n label: React.ReactNode;\n /** input id of the checkbox */\n inputId?: string;\n /** Changes the visuals of the checkbox */\n onColor?: keyof typeof FormOnColor;\n /** Changes the visuals of the checkbox */\n size?: keyof typeof FormSize;\n /** Activates Error style for the checkbox - This is can be true while errorText is empty, when in a FormGroup */\n error?: boolean;\n /** Error text to show above the component */\n errorText?: string;\n /** Error text id */\n errorTextId?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport const Checkbox = React.forwardRef((props: CheckboxProps, ref: React.Ref<HTMLInputElement>) => {\n const {\n className,\n checked = false,\n disabled,\n label,\n inputId = uuid(),\n onColor = FormOnColor.onwhite,\n name = inputId,\n size,\n errorText,\n error = !!errorText,\n errorTextId,\n errorWrapperClassName,\n value = getLabelText(label),\n testId,\n required,\n onChange,\n ...rest\n } = props;\n const [isChecked, setIsChecked] = useState(checked);\n const errorTextUuid = useUuid(errorTextId);\n const onWhite = onColor === FormOnColor.onwhite;\n const onGrey = onColor === FormOnColor.ongrey;\n const onBlueberry = onColor === FormOnColor.onblueberry;\n const onInvalid = error || onColor === FormOnColor.oninvalid;\n const onDark = onColor === FormOnColor.ondark;\n const large = size === FormSize.large;\n const { refObject, isFocused } = usePseudoClasses<HTMLInputElement>(isMutableRefObject(ref) ? ref : null);\n const mergedRefs = mergeRefs([ref, refObject]);\n\n const checkboxWrapperClasses = classNames({\n [checkboxStyles['checkbox-wrapper--large']]: large,\n });\n const checkboxLabelClasses = classNames(checkboxStyles['checkbox-label'], {\n [checkboxStyles['checkbox-label--disabled']]: disabled,\n [checkboxStyles['checkbox-label--on-dark']]: onDark,\n [checkboxStyles['checkbox-label--large']]: large,\n [checkboxStyles['checkbox-label__large--checked']]: large && isChecked,\n [checkboxStyles['checkbox-label__large--focus']]: large && isFocused,\n [checkboxStyles['checkbox-label__large--on-white']]: large && onWhite,\n [checkboxStyles['checkbox-label__large--on-grey']]: large && onGrey,\n [checkboxStyles['checkbox-label__large--on-blueberry']]: large && onBlueberry,\n [checkboxStyles['checkbox-label__large--on-invalid']]: large && onInvalid,\n [checkboxStyles['checkbox-label__large--disabled']]: large && disabled,\n });\n const checkboxClasses = classNames(checkboxStyles.checkbox, className);\n const checkboxIconWrapperClasses = classNames(checkboxStyles['checkbox__icon-wrapper'], {\n [checkboxStyles['checkbox__icon-wrapper--on-white']]: onWhite,\n [checkboxStyles['checkbox__icon-wrapper--on-grey']]: onGrey,\n [checkboxStyles['checkbox__icon-wrapper--on-invalid']]: onInvalid,\n [checkboxStyles['checkbox__icon-wrapper--disabled']]: disabled,\n [checkboxStyles['checkbox__icon-wrapper__regular--checked']]: !large && isChecked,\n [checkboxStyles['checkbox__icon-wrapper__regular--invalid']]: !large && isChecked && onInvalid,\n [checkboxStyles['checkbox__icon-wrapper__regular--on-dark']]: !large && isChecked && onDark,\n [checkboxStyles['checkbox__icon-wrapper__large--checked']]: large && isChecked,\n [checkboxStyles['checkbox__icon-wrapper__large--invalid']]: large && onInvalid,\n [checkboxStyles['checkbox__icon-wrapper--on-dark']]: onDark,\n [checkboxStyles['checkbox__icon-wrapper--on-blueberry']]: onBlueberry,\n [checkboxStyles['checkbox__icon-wrapper--invalid']]: onInvalid,\n [checkboxStyles['checkbox__icon-wrapper__large--invalid']]: large && isChecked && onInvalid,\n [checkboxStyles['checkbox__icon-wrapper__large--disabled']]: disabled && large && isChecked,\n [checkboxStyles['checkbox__icon-wrapper__large--checked--invalid']]: large && isChecked && onInvalid,\n [checkboxStyles['checkbox__icon-wrapper__large--checked--disabled']]: disabled && large && isChecked,\n });\n const labelTextClasses = classNames(checkboxStyles['checkbox-label__text'], {\n [checkboxStyles['checkbox-label__text__large--checked']]: large && isChecked,\n [checkboxStyles['checkbox-label__text__large--invalid']]: large && isChecked && onInvalid,\n [checkboxStyles['checkbox-label__text--on-dark']]: onDark,\n [checkboxStyles['checkbox-label__text--disabled']]: disabled,\n });\n\n let iconColor = getColor('white');\n if (onDark || (large && isChecked)) iconColor = getColor('blueberry', 900);\n if (onInvalid && large && isChecked) iconColor = getColor('white');\n if (disabled) iconColor = getColor('neutral', 700);\n\n useEffect(() => {\n setIsChecked(checked);\n }, [checked]);\n\n const onChangeHandler = (e: React.ChangeEvent<HTMLInputElement>): void => {\n if (onChange) {\n onChange(e);\n }\n\n setIsChecked(!isChecked);\n };\n\n const getLabelContent = (): React.ReactNode => {\n return (\n <>\n <input\n id={inputId}\n name={name}\n className={checkboxClasses}\n type=\"checkbox\"\n checked={isChecked}\n disabled={disabled}\n value={value}\n ref={mergedRefs}\n aria-describedby={getAriaDescribedBy(props, errorTextUuid)}\n aria-invalid={error}\n required={required}\n onChange={onChangeHandler}\n {...rest}\n />\n <span className={checkboxIconWrapperClasses}>\n {isChecked && <Icon color={iconColor} className={checkboxStyles['checkbox__icon']} svgIcon={Check} size={IconSize.XSmall} />}\n </span>\n </>\n );\n };\n\n return (\n <ErrorWrapper className={errorWrapperClassName} errorText={errorText} errorTextId={errorTextUuid}>\n <div data-testid={testId} data-analyticsid={AnalyticsId.Checkbox} className={checkboxWrapperClasses}>\n {renderLabelAsParent(\n label,\n getLabelContent(),\n inputId,\n onColor as FormOnColor,\n checkboxLabelClasses,\n labelTextClasses,\n checkboxStyles['checkbox-sublabel-wrapper'],\n large\n )}\n </div>\n </ErrorWrapper>\n );\n});\n\nCheckbox.displayName = 'Checkbox';\n\nexport default Checkbox;\n"],"names":["Checkbox","React","props","ref","className","checked","disabled","label","inputId","uuid","onColor","FormOnColor","name","size","errorText","error","errorTextId","errorWrapperClassName","value","getLabelText","testId","required","onChange","rest","isChecked","setIsChecked","useState","errorTextUuid","useUuid","onWhite","onGrey","onBlueberry","onInvalid","onDark","large","FormSize","refObject","isFocused","usePseudoClasses","isMutableRefObject","mergedRefs","mergeRefs","checkboxWrapperClasses","classNames","checkboxStyles","checkboxLabelClasses","checkboxClasses","checkboxIconWrapperClasses","labelTextClasses","iconColor","getColor","useEffect","onChangeHandler","e","getLabelContent","jsxs","Fragment","jsx","getAriaDescribedBy","Icon","Check","IconSize","ErrorWrapper","AnalyticsId","renderLabelAsParent"],"mappings":";;;;;;;;;;;;;;;AA4CO,MAAMA,KAAWC,EAAM,WAAW,CAACC,GAAsBC,MAAqC;AAC7F,QAAA;AAAA,IACJ,WAAAC;AAAA,IACA,SAAAC,IAAU;AAAA,IACV,UAAAC;AAAA,IACA,OAAAC;AAAA,IACA,SAAAC,IAAUC,GAAK;AAAA,IACf,SAAAC,IAAUC,EAAY;AAAA,IACtB,MAAAC,IAAOJ;AAAA,IACP,MAAAK;AAAA,IACA,WAAAC;AAAA,IACA,OAAAC,IAAQ,CAAC,CAACD;AAAA,IACV,aAAAE;AAAA,IACA,uBAAAC;AAAA,IACA,OAAAC,IAAQC,GAAaZ,CAAK;AAAA,IAC1B,QAAAa;AAAA,IACA,UAAAC;AAAA,IACA,UAAAC;AAAA,IACA,GAAGC;AAAA,EACD,IAAArB,GACE,CAACsB,GAAWC,CAAY,IAAIC,EAASrB,CAAO,GAC5CsB,IAAgBC,GAAQZ,CAAW,GACnCa,IAAUnB,MAAYC,EAAY,SAClCmB,IAASpB,MAAYC,EAAY,QACjCoB,IAAcrB,MAAYC,EAA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FA,EAAS+B,CAAC,GAGZ5B,EAAa,CAACD,CAAS;AAAA,EAAA,GAGnB8B,IAAkB,MAGlB,gBAAAC,EAAAC,GAAA,EAAA,UAAA;AAAA,IAAA,gBAAAC;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,IAAIjD;AAAA,QACJ,MAAAI;AAAA,QACA,WAAWkC;AAAA,QACX,MAAK;AAAA,QACL,SAAStB;AAAA,QACT,UAAAlB;AAAA,QACA,OAAAY;AAAA,QACA,KAAKsB;AAAA,QACL,oBAAkBkB,GAAmBxD,GAAOyB,CAAa;AAAA,QACzD,gBAAcZ;AAAA,QACd,UAAAM;AAAA,QACA,UAAU+B;AAAA,QACT,GAAG7B;AAAA,MAAA;AAAA,IACN;AAAA,sBACC,QAAK,EAAA,WAAWwB,GACd,UAAavB,KAAA,gBAAAiC,EAACE,MAAK,OAAOV,GAAW,WAAWL,EAAe,gBAAmB,SAASgB,IAAO,MAAMC,EAAS,OAAQ,CAAA,GAC5H;AAAA,EACF,EAAA,CAAA;AAIJ,SACG,gBAAAJ,EAAAK,IAAA,EAAa,WAAW7C,GAAuB,WAAAH,GAAsB,aAAaa,GACjF,UAAC,gBAAA8B,EAAA,OAAA,EAAI,eAAarC,GAAQ,oBAAkB2C,EAAY,UAAU,WAAWrB,GAC1E,UAAAsB;AAAA,IACCzD;AAAA,IACA+C,EAAgB;AAAA,IAChB9C;AAAA,IACAE;AAAA,IACAmC;AAAA,IACAG;AAAA,IACAJ,EAAe,2BAA2B;AAAA,IAC1CV;AAAA,EAAA,EAEJ,CAAA,EACF,CAAA;AAEJ,CAAC;AAEDlC,GAAS,cAAc;"}
@@ -1 +1 @@
1
- {"version":3,"file":"ErrorWrapper.js","sources":["../src/components/ErrorWrapper/ErrorWrapper.tsx"],"sourcesContent":["import React from 'react';\n\nimport cn from 'classnames';\n\nimport styles from './styles.module.scss';\n\nexport interface ErrorWrapperProps {\n /** Form component */\n children?: React.ReactNode;\n /** Error message */\n errorText?: string;\n /** Error text id */\n errorTextId?: string;\n /** Adds custom classes to the element. */\n className?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport const ErrorWrapper: React.FC<ErrorWrapperProps> = props => {\n const errorWrapperClasses = cn(props.errorText && styles[`error-wrapper--with-error`], props.className);\n\n return (\n <div className={errorWrapperClasses} data-testid={props.testId}>\n {props.errorText && (\n <p className={styles['error-wrapper__errors']} id={props.errorTextId}>\n {props.errorText}\n </p>\n )}\n {props.children}\n </div>\n );\n};\n\nexport default ErrorWrapper;\n"],"names":["ErrorWrapper","props","errorWrapperClasses","cn","styles","jsx"],"mappings":";;;AAmBO,MAAMA,IAA4C,CAASC,MAAA;AAC1D,QAAAC,IAAsBC,EAAGF,EAAM,aAAaG,EAAO,2BAA2B,GAAGH,EAAM,SAAS;AAEtG,2BACG,OAAI,EAAA,WAAWC,GAAqB,eAAaD,EAAM,QACrD,UAAA;AAAA,IAAMA,EAAA,aACJ,gBAAAI,EAAA,KAAA,EAAE,WAAWD,EAAO,uBAAuB,GAAG,IAAIH,EAAM,aACtD,UAAAA,EAAM,UACT,CAAA;AAAA,IAEDA,EAAM;AAAA,EACT,EAAA,CAAA;AAEJ;"}
1
+ {"version":3,"file":"ErrorWrapper.js","sources":["../src/components/ErrorWrapper/ErrorWrapper.tsx"],"sourcesContent":["import React from 'react';\n\nimport cn from 'classnames';\n\nimport styles from './styles.module.scss';\n\nexport interface ErrorWrapperClassNameProps {\n errorWrapperClassName?: string;\n}\n\nexport interface ErrorWrapperProps {\n /** Form component */\n children?: React.ReactNode;\n /** Error message */\n errorText?: string;\n /** Error text id */\n errorTextId?: string;\n /** Adds custom classes to the element. */\n className?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport const ErrorWrapper: React.FC<ErrorWrapperProps> = props => {\n const errorWrapperClasses = cn(props.errorText && styles[`error-wrapper--with-error`], props.className);\n\n return (\n <div className={errorWrapperClasses} data-testid={props.testId}>\n {props.errorText && (\n <p className={styles['error-wrapper__errors']} id={props.errorTextId}>\n {props.errorText}\n </p>\n )}\n {props.children}\n </div>\n );\n};\n\nexport default ErrorWrapper;\n"],"names":["ErrorWrapper","props","errorWrapperClasses","cn","styles","jsx"],"mappings":";;;AAuBO,MAAMA,IAA4C,CAASC,MAAA;AAC1D,QAAAC,IAAsBC,EAAGF,EAAM,aAAaG,EAAO,2BAA2B,GAAGH,EAAM,SAAS;AAEtG,2BACG,OAAI,EAAA,WAAWC,GAAqB,eAAaD,EAAM,QACrD,UAAA;AAAA,IAAMA,EAAA,aACJ,gBAAAI,EAAA,KAAA,EAAE,WAAWD,EAAO,uBAAuB,GAAG,IAAIH,EAAM,aACtD,UAAAA,EAAM,UACT,CAAA;AAAA,IAEDA,EAAM;AAAA,EACT,EAAA,CAAA;AAEJ;"}
package/FormGroup.js CHANGED
@@ -1,23 +1,23 @@
1
- import { jsxs as i, jsx as p } from "react/jsx-runtime";
1
+ import { jsxs as d, jsx as p } from "react/jsx-runtime";
2
2
  import t, { useState as A } from "react";
3
3
  import f from "classnames";
4
- import { FormMode as E, FormSize as k, AnalyticsId as D } from "./constants.js";
4
+ import { FormOnColor as E, FormSize as k, AnalyticsId as D } from "./constants.js";
5
5
  import { useUuid as F } from "./hooks/useUuid.js";
6
6
  import { isComponent as s } from "./utils/component.js";
7
7
  import { C as H } from "./Checkbox.js";
8
- import { E as h } from "./ErrorWrapper.js";
9
- import { F as q } from "./FormLayout.js";
10
- import { I as J } from "./Input.js";
11
- import { R as K, g as O } from "./RadioButton.js";
8
+ import { E as O } from "./ErrorWrapper.js";
9
+ import { F as h } from "./FormLayout.js";
10
+ import { I as q } from "./Input.js";
11
+ import { R as J, g as K } from "./RadioButton.js";
12
12
  import { S as P } from "./Select.js";
13
13
  import { T as Q } from "./Textarea.js";
14
14
  import { T as V } from "./Title.js";
15
- import d from "./components/FormGroup/styles.module.scss";
15
+ import i from "./components/FormGroup/styles.module.scss";
16
16
  const G = t.forwardRef((r, R) => {
17
17
  const {
18
18
  className: y,
19
19
  fieldsetClassName: _,
20
- mode: a = E.onwhite,
20
+ onColor: a = E.onwhite,
21
21
  size: m = k.medium,
22
22
  error: o,
23
23
  errorTextId: S,
@@ -26,19 +26,19 @@ const G = t.forwardRef((r, R) => {
26
26
  renderError: b = !0,
27
27
  errorWrapperClassName: w,
28
28
  errorWrapperTestId: W
29
- } = r, [v, L] = A(), M = F(), n = F(S), I = a === E.ondark, j = m === k.large, z = f(d["form-group-wrapper"], y), B = f({
30
- [d["form-group-wrapper__title--on-dark"]]: I && !o
31
- }), g = f(d["field-set__legend"], {
32
- [d["field-set__legend--on-dark"]]: I && !o
33
- }), C = f(d["field-set"], _), u = (e, U) => {
34
- if (s(e, q))
29
+ } = r, [v, L] = A(), j = F(), n = F(S), I = a === E.ondark, z = m === k.large, B = f(i["form-group-wrapper"], y), M = f({
30
+ [i["form-group-wrapper__title--on-dark"]]: I && !o
31
+ }), g = f(i["field-set__legend"], {
32
+ [i["field-set__legend--on-dark"]]: I && !o
33
+ }), C = f(i["field-set"], _), u = (e, U) => {
34
+ if (s(e, h))
35
35
  return t.cloneElement(e, {
36
36
  size: m,
37
37
  mapHelper: u
38
38
  });
39
39
  if (s(e, G))
40
40
  return t.cloneElement(e, {
41
- mode: a,
41
+ onColor: a,
42
42
  size: m,
43
43
  error: o,
44
44
  renderError: !1,
@@ -47,30 +47,30 @@ const G = t.forwardRef((r, R) => {
47
47
  if (s(e, H))
48
48
  return t.cloneElement(e, {
49
49
  name: l ?? e.props.name,
50
- mode: a,
50
+ onColor: a,
51
51
  size: m,
52
52
  error: !!o,
53
53
  errorTextId: n
54
54
  });
55
- if (s(e, K)) {
56
- const T = typeof e.props.inputId > "u" ? M + U : e.props.inputId;
55
+ if (s(e, J)) {
56
+ const T = typeof e.props.inputId > "u" ? j + U : e.props.inputId;
57
57
  return t.cloneElement(e, {
58
58
  inputId: T,
59
59
  name: l ?? e.props.name,
60
- mode: a,
60
+ onColor: a,
61
61
  size: m,
62
62
  onChange: (N) => {
63
63
  L(N.target.id), e.props.onChange && e.props.onChange(N);
64
64
  },
65
65
  error: !!o,
66
66
  errorTextId: n,
67
- labelClassNames: O(T, a, j, v)
67
+ labelClassNames: K(T, a, z, v)
68
68
  });
69
69
  } else {
70
- if (s(e, J))
70
+ if (s(e, q))
71
71
  return t.cloneElement(e, {
72
72
  name: l ?? e.props.name,
73
- mode: a,
73
+ onColor: a,
74
74
  size: m,
75
75
  error: !!o,
76
76
  errorTextId: n
@@ -78,32 +78,32 @@ const G = t.forwardRef((r, R) => {
78
78
  if (s(e, Q))
79
79
  return t.cloneElement(e, {
80
80
  name: l ?? e.props.name,
81
- mode: a,
81
+ onColor: a,
82
82
  error: !!o,
83
83
  errorTextId: n
84
84
  });
85
85
  if (s(e, P))
86
86
  return t.cloneElement(e, {
87
87
  name: l ?? e.props.name,
88
- mode: a,
88
+ onColor: a,
89
89
  error: !!o,
90
90
  errorTextId: n
91
91
  });
92
92
  }
93
93
  return e;
94
- }, x = () => /* @__PURE__ */ i("div", { children: [
95
- c === "div" && /* @__PURE__ */ i("div", { className: C, children: [
94
+ }, x = () => /* @__PURE__ */ d("div", { children: [
95
+ c === "div" && /* @__PURE__ */ d("div", { className: C, children: [
96
96
  r.legend && /* @__PURE__ */ p("h5", { className: g, children: r.legend }),
97
97
  t.Children.map(r.children, u)
98
98
  ] }),
99
- c === "fieldset" && /* @__PURE__ */ i("fieldset", { name: r.fieldsetName, className: C, children: [
99
+ c === "fieldset" && /* @__PURE__ */ d("fieldset", { name: r.fieldsetName, className: C, children: [
100
100
  r.legend && /* @__PURE__ */ p("legend", { className: g, children: r.legend }),
101
101
  t.Children.map(r.children, u)
102
102
  ] })
103
103
  ] });
104
- return /* @__PURE__ */ i("div", { "data-testid": r.testId, "data-analyticsid": D.FormGroup, className: z, ref: R, tabIndex: -1, children: [
105
- r.title && /* @__PURE__ */ p(V, { className: B, htmlMarkup: "h4", appearance: "title4", margin: { marginTop: 0, marginBottom: o ? 1 : 2 }, children: r.title }),
106
- b ? /* @__PURE__ */ p(h, { className: w, errorText: o, testId: W, errorTextId: n, children: x() }) : x()
104
+ return /* @__PURE__ */ d("div", { "data-testid": r.testId, "data-analyticsid": D.FormGroup, className: B, ref: R, tabIndex: -1, children: [
105
+ r.title && /* @__PURE__ */ p(V, { className: M, htmlMarkup: "h4", appearance: "title4", margin: { marginTop: 0, marginBottom: o ? 1 : 2 }, children: r.title }),
106
+ b ? /* @__PURE__ */ p(O, { className: w, errorText: o, testId: W, errorTextId: n, children: x() }) : x()
107
107
  ] });
108
108
  });
109
109
  G.displayName = "FormGroup";
package/FormGroup.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"FormGroup.js","sources":["../src/components/FormGroup/FormGroup.tsx"],"sourcesContent":["import React, { useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport { AnalyticsId, FormMode, FormSize } from '../../constants';\nimport { useUuid } from '../../hooks/useUuid';\nimport { isComponent } from '../../utils/component';\nimport Checkbox, { CheckboxProps } from '../Checkbox/Checkbox';\nimport ErrorWrapper from '../ErrorWrapper';\nimport FormLayout, { FormLayoutProps } from '../FormLayout';\nimport Input, { InputProps } from '../Input/Input';\nimport RadioButton, { RadioButtonProps, getRadioLabelClasses } from '../RadioButton/RadioButton';\nimport Select, { SelectProps } from '../Select';\nimport Textarea, { TextareaProps } from '../Textarea';\nimport Title from '../Title';\n\nimport formGroupStyles from './styles.module.scss';\n\nexport type FormGroupTags = 'fieldset' | 'div';\n\nexport interface FormGroupProps {\n /** title for the the fieldset */\n title?: string;\n /** text placed in the legend tag of the fieldset */\n legend?: string;\n /** Items in the FormGroup component */\n children?: React.ReactNode;\n /** Adds custom classes to the element. */\n className?: string;\n /** Adds custom classes to the errorWrapper. */\n errorWrapperClassName?: string;\n /** Adds custom classes to the fieldset element. */\n fieldsetClassName?: string;\n /** Changes the visuals of the formgroup */\n mode?: keyof typeof FormMode;\n /** Changes the visuals of the formgroup */\n size?: keyof typeof FormSize;\n /** Error message */\n error?: string;\n /** Error text id */\n errorTextId?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Sets the data-testid attribute for the error-wrapper. */\n errorWrapperTestId?: string;\n /** Unique name for the child input element */\n name?: string;\n /** Unique name for the fieldset */\n fieldsetName?: string;\n /** Sets div instead of fieldset tag */\n htmlMarkup?: FormGroupTags;\n /** Renders the error component (Default: true) */\n renderError?: boolean;\n}\n\nexport const FormGroup = React.forwardRef((props: FormGroupProps, ref: React.ForwardedRef<HTMLDivElement>) => {\n const {\n className,\n fieldsetClassName,\n mode = FormMode.onwhite,\n size = FormSize.medium,\n error,\n errorTextId,\n name,\n htmlMarkup = 'fieldset',\n renderError = true,\n errorWrapperClassName,\n errorWrapperTestId,\n } = props;\n const [checkedRadioId, setCheckedRadioId] = useState<string>();\n const radioGroupId = useUuid();\n const errorTextUuid = useUuid(errorTextId);\n const onDark = mode === FormMode.ondark;\n const isLarge = size === FormSize.large;\n const formGroupWrapperClasses = classNames(formGroupStyles['form-group-wrapper'], className);\n const titleClasses = classNames({\n [formGroupStyles['form-group-wrapper__title--on-dark']]: onDark && !error,\n });\n\n const legendClasses = classNames(formGroupStyles['field-set__legend'], {\n [formGroupStyles['field-set__legend--on-dark']]: onDark && !error,\n });\n\n const fieldsetClasses = classNames(formGroupStyles['field-set'], fieldsetClassName);\n\n const mapFormComponent = (child: React.ReactNode, index: number): React.ReactNode => {\n if (isComponent<FormLayoutProps>(child, FormLayout)) {\n return React.cloneElement(child, {\n size,\n mapHelper: mapFormComponent,\n });\n } else if (isComponent<FormGroupProps>(child, FormGroup)) {\n return React.cloneElement(child, {\n mode,\n size,\n error,\n renderError: false,\n errorTextId: errorTextUuid,\n });\n } else if (isComponent<CheckboxProps>(child, Checkbox)) {\n return React.cloneElement(child, {\n name: name ?? child.props.name,\n mode,\n size,\n error: !!error,\n errorTextId: errorTextUuid,\n });\n } else if (isComponent<RadioButtonProps>(child, RadioButton)) {\n const radioId = typeof child.props.inputId === 'undefined' ? radioGroupId + index : child.props.inputId;\n return React.cloneElement(child, {\n inputId: radioId,\n name: name ?? child.props.name,\n mode,\n size,\n onChange: (event: React.ChangeEvent<HTMLInputElement>) => {\n setCheckedRadioId(event.target.id);\n child.props.onChange && child.props.onChange(event);\n },\n error: !!error,\n errorTextId: errorTextUuid,\n labelClassNames: getRadioLabelClasses(radioId, mode as FormMode, isLarge, checkedRadioId),\n });\n } else if (isComponent<InputProps>(child, Input)) {\n return React.cloneElement(child, {\n name: name ?? child.props.name,\n mode,\n size,\n error: !!error,\n errorTextId: errorTextUuid,\n });\n } else if (isComponent<TextareaProps>(child, Textarea)) {\n return React.cloneElement(child, {\n name: name ?? child.props.name,\n mode,\n error: !!error,\n errorTextId: errorTextUuid,\n });\n } else if (isComponent<SelectProps>(child, Select)) {\n return React.cloneElement(child, {\n name: name ?? child.props.name,\n mode,\n error: !!error,\n errorTextId: errorTextUuid,\n });\n }\n return child;\n };\n\n const formGroupContent = (): React.ReactNode => {\n return (\n <div>\n {htmlMarkup === 'div' && (\n <div className={fieldsetClasses}>\n {props.legend && <h5 className={legendClasses}>{props.legend}</h5>}\n {React.Children.map(props.children, mapFormComponent)}\n </div>\n )}\n {htmlMarkup === 'fieldset' && (\n <fieldset name={props.fieldsetName} className={fieldsetClasses}>\n {props.legend && <legend className={legendClasses}>{props.legend}</legend>}\n {React.Children.map(props.children, mapFormComponent)}\n </fieldset>\n )}\n </div>\n );\n };\n\n return (\n <div data-testid={props.testId} data-analyticsid={AnalyticsId.FormGroup} className={formGroupWrapperClasses} ref={ref} tabIndex={-1}>\n {props.title && (\n <Title className={titleClasses} htmlMarkup={'h4'} appearance={'title4'} margin={{ marginTop: 0, marginBottom: error ? 1 : 2 }}>\n {props.title}\n </Title>\n )}\n {renderError ? (\n <ErrorWrapper className={errorWrapperClassName} errorText={error} testId={errorWrapperTestId} errorTextId={errorTextUuid}>\n {formGroupContent()}\n </ErrorWrapper>\n ) : (\n formGroupContent()\n )}\n </div>\n );\n});\n\nFormGroup.displayName = 'FormGroup';\n\nexport default FormGroup;\n"],"names":["FormGroup","React","props","ref","className","fieldsetClassName","mode","FormMode","size","FormSize","error","errorTextId","name","htmlMarkup","renderError","errorWrapperClassName","errorWrapperTestId","checkedRadioId","setCheckedRadioId","useState","radioGroupId","useUuid","errorTextUuid","onDark","isLarge","formGroupWrapperClasses","classNames","formGroupStyles","titleClasses","legendClasses","fieldsetClasses","mapFormComponent","child","index","isComponent","FormLayout","Checkbox","RadioButton","radioId","event","getRadioLabelClasses","Input","Textarea","Select","formGroupContent","jsxs","jsx","AnalyticsId","Title","ErrorWrapper"],"mappings":";;;;;;;;;;;;;;;AAuDO,MAAMA,IAAYC,EAAM,WAAW,CAACC,GAAuBC,MAA4C;AACtG,QAAA;AAAA,IACJ,WAAAC;AAAA,IACA,mBAAAC;AAAA,IACA,MAAAC,IAAOC,EAAS;AAAA,IAChB,MAAAC,IAAOC,EAAS;AAAA,IAChB,OAAAC;AAAA,IACA,aAAAC;AAAA,IACA,MAAAC;AAAA,IACA,YAAAC,IAAa;AAAA,IACb,aAAAC,IAAc;AAAA,IACd,uBAAAC;AAAA,IACA,oBAAAC;AAAA,EACE,IAAAd,GACE,CAACe,GAAgBC,CAAiB,IAAIC,EAAiB,GACvDC,IAAeC,KACfC,IAAgBD,EAAQV,CAAW,GACnCY,IAASjB,MAASC,EAAS,QAC3BiB,IAAUhB,MAASC,EAAS,OAC5BgB,IAA0BC,EAAWC,EAAgB,oBAAoB,GAAGvB,CAAS,GACrFwB,IAAeF,EAAW;AAAA,IAC9B,CAACC,EAAgB,oCAAoC,CAAC,GAAGJ,KAAU,CAACb;AAAA,EAAA,CACrE,GAEKmB,IAAgBH,EAAWC,EAAgB,mBAAmB,GAAG;AAAA,IACrE,CAACA,EAAgB,4BAA4B,CAAC,GAAGJ,KAAU,CAACb;AAAA,EAAA,CAC7D,GAEKoB,IAAkBJ,EAAWC,EAAgB,WAAW,GAAGtB,CAAiB,GAE5E0B,IAAmB,CAACC,GAAwBC,MAAmC;AAC/E,QAAAC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,EAAE,WAAW,GAAG,cAAclB,IAAQ,IAAI,EAAE,GACzH,YAAM,OACT;AAAA,IAEDI,IACC,gBAAAgC,EAACG,GAAa,EAAA,WAAWlC,GAAuB,WAAWL,GAAO,QAAQM,GAAoB,aAAaM,GACxG,UAAiBsB,EAAA,EAAA,CACpB,IAEAA,EAAiB;AAAA,EAErB,EAAA,CAAA;AAEJ,CAAC;AAED5C,EAAU,cAAc;"}
1
+ {"version":3,"file":"FormGroup.js","sources":["../src/components/FormGroup/FormGroup.tsx"],"sourcesContent":["import React, { useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport { AnalyticsId, FormOnColor, FormSize } from '../../constants';\nimport { useUuid } from '../../hooks/useUuid';\nimport { isComponent } from '../../utils/component';\nimport Checkbox, { CheckboxProps } from '../Checkbox/Checkbox';\nimport ErrorWrapper from '../ErrorWrapper';\nimport FormLayout, { FormLayoutProps } from '../FormLayout';\nimport Input, { InputProps } from '../Input/Input';\nimport RadioButton, { RadioButtonProps, getRadioLabelClasses } from '../RadioButton/RadioButton';\nimport Select, { SelectProps } from '../Select';\nimport Textarea, { TextareaProps } from '../Textarea';\nimport Title from '../Title';\n\nimport formGroupStyles from './styles.module.scss';\n\nexport type FormGroupTags = 'fieldset' | 'div';\n\nexport interface FormGroupProps {\n /** title for the the fieldset */\n title?: string;\n /** text placed in the legend tag of the fieldset */\n legend?: string;\n /** Items in the FormGroup component */\n children?: React.ReactNode;\n /** Adds custom classes to the element. */\n className?: string;\n /** Adds custom classes to the errorWrapper. */\n errorWrapperClassName?: string;\n /** Adds custom classes to the fieldset element. */\n fieldsetClassName?: string;\n /** Changes the visuals of the formgroup */\n onColor?: keyof typeof FormOnColor;\n /** Changes the visuals of the formgroup */\n size?: keyof typeof FormSize;\n /** Error message */\n error?: string;\n /** Error text id */\n errorTextId?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Sets the data-testid attribute for the error-wrapper. */\n errorWrapperTestId?: string;\n /** Unique name for the child input element */\n name?: string;\n /** Unique name for the fieldset */\n fieldsetName?: string;\n /** Sets div instead of fieldset tag */\n htmlMarkup?: FormGroupTags;\n /** Renders the error component (Default: true) */\n renderError?: boolean;\n}\n\nexport const FormGroup = React.forwardRef((props: FormGroupProps, ref: React.ForwardedRef<HTMLDivElement>) => {\n const {\n className,\n fieldsetClassName,\n onColor = FormOnColor.onwhite,\n size = FormSize.medium,\n error,\n errorTextId,\n name,\n htmlMarkup = 'fieldset',\n renderError = true,\n errorWrapperClassName,\n errorWrapperTestId,\n } = props;\n const [checkedRadioId, setCheckedRadioId] = useState<string>();\n const radioGroupId = useUuid();\n const errorTextUuid = useUuid(errorTextId);\n const onDark = onColor === FormOnColor.ondark;\n const isLarge = size === FormSize.large;\n const formGroupWrapperClasses = classNames(formGroupStyles['form-group-wrapper'], className);\n const titleClasses = classNames({\n [formGroupStyles['form-group-wrapper__title--on-dark']]: onDark && !error,\n });\n\n const legendClasses = classNames(formGroupStyles['field-set__legend'], {\n [formGroupStyles['field-set__legend--on-dark']]: onDark && !error,\n });\n\n const fieldsetClasses = classNames(formGroupStyles['field-set'], fieldsetClassName);\n\n const mapFormComponent = (child: React.ReactNode, index: number): React.ReactNode => {\n if (isComponent<FormLayoutProps>(child, FormLayout)) {\n return React.cloneElement(child, {\n size,\n mapHelper: mapFormComponent,\n });\n } else if (isComponent<FormGroupProps>(child, FormGroup)) {\n return React.cloneElement(child, {\n onColor,\n size,\n error,\n renderError: false,\n errorTextId: errorTextUuid,\n });\n } else if (isComponent<CheckboxProps>(child, Checkbox)) {\n return React.cloneElement(child, {\n name: name ?? child.props.name,\n onColor,\n size,\n error: !!error,\n errorTextId: errorTextUuid,\n });\n } else if (isComponent<RadioButtonProps>(child, RadioButton)) {\n const radioId = typeof child.props.inputId === 'undefined' ? radioGroupId + index : child.props.inputId;\n return React.cloneElement(child, {\n inputId: radioId,\n name: name ?? child.props.name,\n onColor,\n size,\n onChange: (event: React.ChangeEvent<HTMLInputElement>) => {\n setCheckedRadioId(event.target.id);\n child.props.onChange && child.props.onChange(event);\n },\n error: !!error,\n errorTextId: errorTextUuid,\n labelClassNames: getRadioLabelClasses(radioId, onColor as FormOnColor, isLarge, checkedRadioId),\n });\n } else if (isComponent<InputProps>(child, Input)) {\n return React.cloneElement(child, {\n name: name ?? child.props.name,\n onColor,\n size,\n error: !!error,\n errorTextId: errorTextUuid,\n });\n } else if (isComponent<TextareaProps>(child, Textarea)) {\n return React.cloneElement(child, {\n name: name ?? child.props.name,\n onColor,\n error: !!error,\n errorTextId: errorTextUuid,\n });\n } else if (isComponent<SelectProps>(child, Select)) {\n return React.cloneElement(child, {\n name: name ?? child.props.name,\n onColor,\n error: !!error,\n errorTextId: errorTextUuid,\n });\n }\n return child;\n };\n\n const formGroupContent = (): React.ReactNode => {\n return (\n <div>\n {htmlMarkup === 'div' && (\n <div className={fieldsetClasses}>\n {props.legend && <h5 className={legendClasses}>{props.legend}</h5>}\n {React.Children.map(props.children, mapFormComponent)}\n </div>\n )}\n {htmlMarkup === 'fieldset' && (\n <fieldset name={props.fieldsetName} className={fieldsetClasses}>\n {props.legend && <legend className={legendClasses}>{props.legend}</legend>}\n {React.Children.map(props.children, mapFormComponent)}\n </fieldset>\n )}\n </div>\n );\n };\n\n return (\n <div data-testid={props.testId} data-analyticsid={AnalyticsId.FormGroup} className={formGroupWrapperClasses} ref={ref} tabIndex={-1}>\n {props.title && (\n <Title className={titleClasses} htmlMarkup={'h4'} appearance={'title4'} margin={{ marginTop: 0, marginBottom: error ? 1 : 2 }}>\n {props.title}\n </Title>\n )}\n {renderError ? (\n <ErrorWrapper className={errorWrapperClassName} errorText={error} testId={errorWrapperTestId} errorTextId={errorTextUuid}>\n {formGroupContent()}\n </ErrorWrapper>\n ) : (\n formGroupContent()\n )}\n </div>\n );\n});\n\nFormGroup.displayName = 'FormGroup';\n\nexport default FormGroup;\n"],"names":["FormGroup","React","props","ref","className","fieldsetClassName","onColor","FormOnColor","size","FormSize","error","errorTextId","name","htmlMarkup","renderError","errorWrapperClassName","errorWrapperTestId","checkedRadioId","setCheckedRadioId","useState","radioGroupId","useUuid","errorTextUuid","onDark","isLarge","formGroupWrapperClasses","classNames","formGroupStyles","titleClasses","legendClasses","fieldsetClasses","mapFormComponent","child","index","isComponent","FormLayout","Checkbox","RadioButton","radioId","event","getRadioLabelClasses","Input","Textarea","Select","formGroupContent","jsxs","jsx","AnalyticsId","Title","ErrorWrapper"],"mappings":";;;;;;;;;;;;;;;AAuDO,MAAMA,IAAYC,EAAM,WAAW,CAACC,GAAuBC,MAA4C;AACtG,QAAA;AAAA,IACJ,WAAAC;AAAA,IACA,mBAAAC;AAAA,IACA,SAAAC,IAAUC,EAAY;AAAA,IACtB,MAAAC,IAAOC,EAAS;AAAA,IAChB,OAAAC;AAAA,IACA,aAAAC;AAAA,IACA,MAAAC;AAAA,IACA,YAAAC,IAAa;AAAA,IACb,aAAAC,IAAc;AAAA,IACd,uBAAAC;AAAA,IACA,oBAAAC;AAAA,EACE,IAAAd,GACE,CAACe,GAAgBC,CAAiB,IAAIC,EAAiB,GACvDC,IAAeC,KACfC,IAAgBD,EAAQV,CAAW,GACnCY,IAASjB,MAAYC,EAAY,QACjCiB,IAAUhB,MAASC,EAAS,OAC5BgB,IAA0BC,EAAWC,EAAgB,oBAAoB,GAAGvB,CAAS,GACrFwB,IAAeF,EAAW;AAAA,IAC9B,CAACC,EAAgB,oCAAoC,CAAC,GAAGJ,KAAU,CAACb;AAAA,EAAA,CACrE,GAEKmB,IAAgBH,EAAWC,EAAgB,mBAAmB,GAAG;AAAA,IACrE,CAACA,EAAgB,4BAA4B,CAAC,GAAGJ,KAAU,CAACb;AAAA,EAAA,CAC7D,GAEKoB,IAAkBJ,EAAWC,EAAgB,WAAW,GAAGtB,CAAiB,GAE5E0B,IAAmB,CAACC,GAAwBC,MAAmC;AAC/E,QAAAC,EAA6BF,GAAOG,CAAU;AACzC,aAAAlC,EAAM,aAAa+B,GAAO;AAAA,QAC/B,MAAAxB;AAAA,QACA,WAAW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