@helsenorge/designsystem-react 8.6.0 → 9.0.0-beta.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.
- package/Button.js +7 -7
- package/Button.js.map +1 -1
- package/CHANGELOG.md +27 -3
- package/Checkbox.js +42 -42
- package/Checkbox.js.map +1 -1
- package/ErrorWrapper.js.map +1 -1
- package/FormGroup.js +47 -40
- package/FormGroup.js.map +1 -1
- package/Icon.js +21 -21
- package/Icon.js.map +1 -1
- package/Input.js +98 -88
- package/Input.js.map +1 -1
- package/Label.js +28 -28
- package/Label.js.map +1 -1
- package/MaxCharacters.js +2 -2
- package/MaxCharacters.js.map +1 -1
- package/RadioButton.js +61 -61
- package/RadioButton.js.map +1 -1
- package/Select.js +34 -33
- package/Select.js.map +1 -1
- package/Slider.js +218 -0
- package/Slider.js.map +1 -0
- package/StatusDot.js +15 -15
- package/StatusDot.js.map +1 -1
- package/TabList.js +88 -53
- package/TabList.js.map +1 -1
- package/TabPanel.js +7 -7
- package/TabPanel.js.map +1 -1
- package/Textarea.js +59 -58
- package/Textarea.js.map +1 -1
- package/Trigger.js +33 -33
- package/Trigger.js.map +1 -1
- package/components/Button/Button.d.ts +2 -2
- package/components/Checkbox/Checkbox.d.ts +4 -3
- package/components/Checkbox/styles.module.scss +0 -14
- package/components/Checkbox/styles.module.scss.d.ts +0 -1
- package/components/Dropdown/Dropdown.d.ts +2 -2
- package/components/Dropdown/index.js +25 -25
- package/components/Dropdown/index.js.map +1 -1
- package/components/ErrorWrapper/ErrorWrapper.d.ts +3 -0
- package/components/ExpanderList/ExpanderList.d.ts +4 -6
- package/components/ExpanderList/index.js +118 -126
- package/components/ExpanderList/index.js.map +1 -1
- package/components/ExpanderList/styles.module.scss +165 -49
- package/components/ExpanderList/styles.module.scss.d.ts +29 -5
- package/components/FormGroup/FormGroup.d.ts +2 -2
- package/components/Icon/Icon.d.ts +4 -4
- package/components/Icons/NoAccess.js +7 -7
- package/components/Icons/NoAccess.js.map +1 -1
- package/components/Input/Input.d.ts +4 -3
- package/components/Label/Label.d.ts +4 -4
- package/components/Label/SubLabel.d.ts +2 -2
- package/components/MaxCharacters/MaxCharacters.d.ts +2 -2
- package/components/RadioButton/RadioButton.d.ts +5 -4
- package/components/RadioButton/styles.module.scss +0 -15
- package/components/RadioButton/styles.module.scss.d.ts +0 -1
- package/components/Select/Select.d.ts +4 -3
- package/components/SharingStatus/SharingStatus.d.ts +1 -1
- package/components/SharingStatus/index.js +5 -5
- package/components/SharingStatus/index.js.map +1 -1
- package/components/SharingStatus/styles.module.scss +0 -16
- package/components/SharingStatus/styles.module.scss.d.ts +0 -4
- package/components/Slider/Slider.d.ts +9 -4
- package/components/Slider/index.js +3 -189
- package/components/Slider/index.js.map +1 -1
- package/components/Slider/styles.module.scss +19 -6
- package/components/Slider/styles.module.scss.d.ts +3 -0
- package/components/StatusDot/StatusDot.d.ts +3 -3
- package/components/StatusDot/index.js +3 -3
- package/components/Tabs/TabList/TabList.d.ts +3 -3
- package/components/Tabs/TabList/styles.module.scss +63 -51
- package/components/Tabs/TabList/styles.module.scss.d.ts +7 -3
- package/components/Tabs/TabPanel/TabPanel.d.ts +1 -2
- package/components/Tabs/TabPanel/styles.module.scss +11 -26
- package/components/Tabs/TabPanel/styles.module.scss.d.ts +0 -2
- package/components/Tabs/Tabs.d.ts +3 -3
- package/components/Tabs/index.js +60 -75
- package/components/Tabs/index.js.map +1 -1
- package/components/Tabs/styles.module.scss +5 -9
- package/components/Tabs/styles.module.scss.d.ts +0 -1
- package/components/Textarea/Textarea.d.ts +4 -3
- package/components/Toggle/index.js +1204 -1170
- package/components/Toggle/index.js.map +1 -1
- package/components/Trigger/Trigger.d.ts +2 -2
- package/components/Validation/index.js +39 -32
- package/components/Validation/index.js.map +1 -1
- package/constants.d.ts +1 -1
- package/constants.js +1 -1
- package/constants.js.map +1 -1
- package/docs/FormExample/FormExample.d.ts +3 -1
- package/index.js +23 -23
- package/package.json +4 -4
- package/utils/component.d.ts +1 -0
- package/utils/component.js +7 -3
- 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,
|
|
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
|
-
|
|
30
|
+
onColor: J = "onlight",
|
|
31
31
|
onBlur: z,
|
|
32
32
|
onClick: U,
|
|
33
33
|
size: K = "medium",
|
|
34
|
-
variant:
|
|
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,
|
|
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"]]:
|
|
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"]]:
|
|
66
|
+
[t["diagonal--on-dark"]]: y
|
|
67
67
|
});
|
|
68
68
|
bt(() => {
|
|
69
|
-
|
|
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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,OAAA;AAAA,EAEJ,EAAA,CAAA;AAGF,SAEK,gBAAAY,EAAAK,IAAA,EAAA,UAAA;AAAA,IAAApD,MAAe,YACd,gBAAAgD;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,IAC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A,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;"}
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
## [8.7.0](https://github.com/helsenorge/designsystem/branchCompare?baseVersion=GTv8.6.0&targetVersion=GTv8.7.0) (2024-10-17)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
- **datetime:** får onblur prop ([31fe602](https://github.com/helsenorge/designsystem/commit/31fe602a68f12c39e48a55b5559fcd812be97785)),
|
|
6
|
+
closes [#334254](https://github.com/helsenorge/designsystem/issues/334254)
|
|
7
|
+
|
|
8
|
+
## [8.6.0](https://github.com/helsenorge/designsystem/branchCompare?baseVersion=GTv8.5.1&targetVersion=GTv8.6.0) (2024-10-09)
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
- **datepicker:** legg til prop for å sette posisjon på datepicker popup
|
|
13
|
+
([0f392ed](https://github.com/helsenorge/designsystem/commit/0f392ed1f5fc76be0fbfdeb5262f64071cbf4dc0)), closes
|
|
14
|
+
[#326998](https://github.com/helsenorge/designsystem/issues/326998)
|
|
15
|
+
- **datetime:** value prop og defaultvalue settes riktig
|
|
16
|
+
([a3d8617](https://github.com/helsenorge/designsystem/commit/a3d86173269cd5a1dd9d8cd1f13a2512b2fb87fd)), closes
|
|
17
|
+
[#332561](https://github.com/helsenorge/designsystem/issues/332561)
|
|
18
|
+
- **label:** gi mulighet for å rendre label med andre tags
|
|
19
|
+
([9f952dd](https://github.com/helsenorge/designsystem/commit/9f952ddd0eac84e1426d070685998e950fa9e9f8)), closes
|
|
20
|
+
[#331803](https://github.com/helsenorge/designsystem/issues/331803)
|
|
21
|
+
- **tabs:** endre default touch behaviour til å være none
|
|
22
|
+
([4101ce2](https://github.com/helsenorge/designsystem/commit/4101ce2a85f84e26b9fcfd61990ca8792f72b55c)), closes
|
|
23
|
+
[#331142](https://github.com/helsenorge/designsystem/issues/331142)
|
|
24
|
+
|
|
1
25
|
## [8.5.1](https://github.com/helsenorge/designsystem/branchCompare?baseVersion=GTv8.5.0&targetVersion=GTv8.5.1) (2024-09-25)
|
|
2
26
|
|
|
3
27
|
### Bug Fixes
|
|
@@ -1781,12 +1805,12 @@ Dette er fordi vi skal kunne dynamisk importere alt som ligger i Icons, så da b
|
|
|
1781
1805
|
|
|
1782
1806
|
### Bug Fixes
|
|
1783
1807
|
|
|
1784
|
-
- panel har avstand fra tittel til badge
|
|
1785
|
-
([09034c4](https://github.com/helsenorge/designsystem/commit/09034c4844408c7cfe8f65d7a1a0d82a7828c2ef)), closes
|
|
1786
|
-
[#282359](https://github.com/helsenorge/designsystem/issues/282359)
|
|
1787
1808
|
- økt kontrast på understreking av lenker
|
|
1788
1809
|
([50b7fa4](https://github.com/helsenorge/designsystem/commit/50b7fa47fb44cb7d75fb877bd53e2309b35e1e21)), closes
|
|
1789
1810
|
[#229049](https://github.com/helsenorge/designsystem/issues/229049)
|
|
1811
|
+
- panel har avstand fra tittel til badge
|
|
1812
|
+
([09034c4](https://github.com/helsenorge/designsystem/commit/09034c4844408c7cfe8f65d7a1a0d82a7828c2ef)), closes
|
|
1813
|
+
[#282359](https://github.com/helsenorge/designsystem/issues/282359)
|
|
1790
1814
|
|
|
1791
1815
|
## [1.2.2](https://github.com/helsenorge/designsystem/branchCompare?baseVersion=GTv1.2.1&targetVersion=GTv1.2.2) (2022-08-31)
|
|
1792
1816
|
|
package/Checkbox.js
CHANGED
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
import { jsx as s, jsxs as
|
|
2
|
-
import
|
|
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 {
|
|
5
|
-
import { usePseudoClasses as
|
|
6
|
-
import { useUuid as
|
|
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
|
|
9
|
-
import { isMutableRefObject as
|
|
10
|
-
import { u as
|
|
11
|
-
import { E as
|
|
12
|
-
import { I as
|
|
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
|
|
14
|
+
import { g as se, r as be } from "./Label.js";
|
|
15
15
|
import e from "./components/Checkbox/styles.module.scss";
|
|
16
|
-
const
|
|
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:
|
|
22
|
-
inputId: p =
|
|
23
|
-
|
|
21
|
+
label: x,
|
|
22
|
+
inputId: p = ae(),
|
|
23
|
+
onColor: l = n.onwhite,
|
|
24
24
|
name: N = p,
|
|
25
25
|
size: T,
|
|
26
|
-
errorText:
|
|
27
|
-
error: g = !!
|
|
26
|
+
errorText: m,
|
|
27
|
+
error: g = !!m,
|
|
28
28
|
errorTextId: R,
|
|
29
|
-
|
|
29
|
+
errorWrapperClassName: S,
|
|
30
|
+
value: W = se(x),
|
|
30
31
|
testId: j,
|
|
31
32
|
required: z,
|
|
32
33
|
onChange: u,
|
|
33
34
|
...F
|
|
34
|
-
} =
|
|
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"]]:
|
|
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 &&
|
|
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),
|
|
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 &&
|
|
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"]]:
|
|
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
|
-
}),
|
|
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"]]:
|
|
68
|
+
[e["checkbox-label__text--on-dark"]]: i,
|
|
69
69
|
[e["checkbox-label__text--disabled"]]: a
|
|
70
70
|
});
|
|
71
71
|
let t = _("white");
|
|
72
|
-
(
|
|
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
|
|
76
|
-
u && u(
|
|
77
|
-
},
|
|
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:
|
|
88
|
-
ref:
|
|
89
|
-
"aria-describedby":
|
|
87
|
+
value: W,
|
|
88
|
+
ref: E,
|
|
89
|
+
"aria-describedby": re(k, w),
|
|
90
90
|
"aria-invalid": g,
|
|
91
91
|
required: z,
|
|
92
|
-
onChange:
|
|
92
|
+
onChange: q,
|
|
93
93
|
...F
|
|
94
94
|
}
|
|
95
95
|
),
|
|
96
|
-
/* @__PURE__ */ s("span", { className:
|
|
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(
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
104
|
+
U,
|
|
105
105
|
e["checkbox-sublabel-wrapper"],
|
|
106
106
|
r
|
|
107
107
|
) }) });
|
|
108
108
|
});
|
|
109
|
-
|
|
109
|
+
te.displayName = "Checkbox";
|
|
110
110
|
export {
|
|
111
|
-
|
|
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,QAC3BmB,IAAcpB,MAASC,EAAS,aA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A8C,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,EAAY,aACtCqB,IAAYjB,K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GZ5B,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;"}
|
package/ErrorWrapper.js.map
CHANGED
|
@@ -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":";;;
|
|
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,36 +1,37 @@
|
|
|
1
|
-
import { jsxs as
|
|
1
|
+
import { jsxs as p, jsx as d } from "react/jsx-runtime";
|
|
2
2
|
import t, { useState as A } from "react";
|
|
3
3
|
import f from "classnames";
|
|
4
|
-
import {
|
|
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
|
|
8
|
+
import { E as O } from "./ErrorWrapper.js";
|
|
9
9
|
import { F as q } from "./FormLayout.js";
|
|
10
10
|
import { I as J } from "./Input.js";
|
|
11
|
-
import { R as K, g as
|
|
12
|
-
import { S as
|
|
13
|
-
import {
|
|
14
|
-
import { T as
|
|
15
|
-
import
|
|
11
|
+
import { R as K, g as P } from "./RadioButton.js";
|
|
12
|
+
import { S as Q } from "./Select.js";
|
|
13
|
+
import { S as V } from "./Slider.js";
|
|
14
|
+
import { T as X } from "./Textarea.js";
|
|
15
|
+
import { T as Y } from "./Title.js";
|
|
16
|
+
import i from "./components/FormGroup/styles.module.scss";
|
|
16
17
|
const G = t.forwardRef((r, R) => {
|
|
17
18
|
const {
|
|
18
|
-
className:
|
|
19
|
-
fieldsetClassName:
|
|
20
|
-
|
|
19
|
+
className: S,
|
|
20
|
+
fieldsetClassName: y,
|
|
21
|
+
onColor: n = E.onwhite,
|
|
21
22
|
size: m = k.medium,
|
|
22
23
|
error: o,
|
|
23
|
-
errorTextId:
|
|
24
|
+
errorTextId: _,
|
|
24
25
|
name: l,
|
|
25
26
|
htmlMarkup: c = "fieldset",
|
|
26
27
|
renderError: b = !0,
|
|
27
28
|
errorWrapperClassName: w,
|
|
28
29
|
errorWrapperTestId: W
|
|
29
|
-
} = r, [v, L] = A(),
|
|
30
|
-
[
|
|
31
|
-
}), g = f(
|
|
32
|
-
[
|
|
33
|
-
}), C = f(
|
|
30
|
+
} = r, [v, L] = A(), j = F(), a = F(_), I = n === E.ondark, z = m === k.large, B = f(i["form-group-wrapper"], S), M = f({
|
|
31
|
+
[i["form-group-wrapper__title--on-dark"]]: I && !o
|
|
32
|
+
}), g = f(i["field-set__legend"], {
|
|
33
|
+
[i["field-set__legend--on-dark"]]: I && !o
|
|
34
|
+
}), C = f(i["field-set"], y), u = (e, U) => {
|
|
34
35
|
if (s(e, q))
|
|
35
36
|
return t.cloneElement(e, {
|
|
36
37
|
size: m,
|
|
@@ -38,72 +39,78 @@ const G = t.forwardRef((r, R) => {
|
|
|
38
39
|
});
|
|
39
40
|
if (s(e, G))
|
|
40
41
|
return t.cloneElement(e, {
|
|
41
|
-
|
|
42
|
+
onColor: n,
|
|
42
43
|
size: m,
|
|
43
44
|
error: o,
|
|
44
45
|
renderError: !1,
|
|
45
|
-
errorTextId:
|
|
46
|
+
errorTextId: a
|
|
46
47
|
});
|
|
47
48
|
if (s(e, H))
|
|
48
49
|
return t.cloneElement(e, {
|
|
49
50
|
name: l ?? e.props.name,
|
|
50
|
-
|
|
51
|
+
onColor: n,
|
|
51
52
|
size: m,
|
|
52
53
|
error: !!o,
|
|
53
|
-
errorTextId:
|
|
54
|
+
errorTextId: a
|
|
54
55
|
});
|
|
55
56
|
if (s(e, K)) {
|
|
56
|
-
const T = typeof e.props.inputId > "u" ?
|
|
57
|
+
const T = typeof e.props.inputId > "u" ? j + U : e.props.inputId;
|
|
57
58
|
return t.cloneElement(e, {
|
|
58
59
|
inputId: T,
|
|
59
60
|
name: l ?? e.props.name,
|
|
60
|
-
|
|
61
|
+
onColor: n,
|
|
61
62
|
size: m,
|
|
62
63
|
onChange: (N) => {
|
|
63
64
|
L(N.target.id), e.props.onChange && e.props.onChange(N);
|
|
64
65
|
},
|
|
65
66
|
error: !!o,
|
|
66
|
-
errorTextId:
|
|
67
|
-
labelClassNames:
|
|
67
|
+
errorTextId: a,
|
|
68
|
+
labelClassNames: P(T, n, z, v)
|
|
68
69
|
});
|
|
69
70
|
} else {
|
|
70
71
|
if (s(e, J))
|
|
71
72
|
return t.cloneElement(e, {
|
|
72
73
|
name: l ?? e.props.name,
|
|
73
|
-
|
|
74
|
+
onColor: n,
|
|
74
75
|
size: m,
|
|
75
76
|
error: !!o,
|
|
76
|
-
errorTextId:
|
|
77
|
+
errorTextId: a
|
|
78
|
+
});
|
|
79
|
+
if (s(e, X))
|
|
80
|
+
return t.cloneElement(e, {
|
|
81
|
+
name: l ?? e.props.name,
|
|
82
|
+
onColor: n,
|
|
83
|
+
error: !!o,
|
|
84
|
+
errorTextId: a
|
|
77
85
|
});
|
|
78
86
|
if (s(e, Q))
|
|
79
87
|
return t.cloneElement(e, {
|
|
80
88
|
name: l ?? e.props.name,
|
|
81
|
-
|
|
89
|
+
onColor: n,
|
|
82
90
|
error: !!o,
|
|
83
|
-
errorTextId:
|
|
91
|
+
errorTextId: a
|
|
84
92
|
});
|
|
85
|
-
if (s(e,
|
|
93
|
+
if (s(e, V))
|
|
86
94
|
return t.cloneElement(e, {
|
|
87
95
|
name: l ?? e.props.name,
|
|
88
|
-
mode: a,
|
|
89
96
|
error: !!o,
|
|
90
|
-
errorTextId:
|
|
97
|
+
errorTextId: a
|
|
91
98
|
});
|
|
92
99
|
}
|
|
93
100
|
return e;
|
|
94
|
-
}, x = () => /* @__PURE__ */
|
|
95
|
-
c === "div" && /* @__PURE__ */
|
|
96
|
-
r.legend && /* @__PURE__ */
|
|
101
|
+
}, x = () => /* @__PURE__ */ p("div", { children: [
|
|
102
|
+
c === "div" && /* @__PURE__ */ p("div", { className: C, children: [
|
|
103
|
+
r.legend && /* @__PURE__ */ d("h5", { className: g, children: r.legend }),
|
|
97
104
|
t.Children.map(r.children, u)
|
|
98
105
|
] }),
|
|
99
|
-
c === "fieldset" && /* @__PURE__ */
|
|
100
|
-
r.legend && /* @__PURE__ */
|
|
106
|
+
c === "fieldset" && /* @__PURE__ */ p("fieldset", { name: r.fieldsetName, className: C, children: [
|
|
107
|
+
r.legend && /* @__PURE__ */ d("legend", { className: g, children: r.legend }),
|
|
101
108
|
t.Children.map(r.children, u)
|
|
102
109
|
] })
|
|
103
110
|
] });
|
|
104
|
-
return /* @__PURE__ */
|
|
105
|
-
r.title && /* @__PURE__ */
|
|
106
|
-
b ? /* @__PURE__ */
|
|
111
|
+
return /* @__PURE__ */ p("div", { "data-testid": r.testId, "data-analyticsid": D.FormGroup, className: B, ref: R, tabIndex: -1, children: [
|
|
112
|
+
r.title && /* @__PURE__ */ d(Y, { className: M, htmlMarkup: "h4", appearance: "title4", margin: { marginTop: 0, marginBottom: o ? 1 : 2 }, children: r.title }),
|
|
113
|
+
b ? /* @__PURE__ */ d(O, { className: w, errorText: o, testId: W, errorTextId: a, children: x() }) : x()
|
|
107
114
|
] });
|
|
108
115
|
});
|
|
109
116
|
G.displayName = "FormGroup";
|