@helsenorge/designsystem-react 7.0.0-beta.2 → 7.0.0-beta.5
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/CHANGELOG.md +19 -0
- package/__mocks__/usePseudoClasses.d.ts +1 -0
- package/__mocks__/usePseudoClasses.js +5 -0
- package/__mocks__/usePseudoClasses.js.map +1 -0
- package/components/AnchorLink/AnchorLink.d.ts +2 -1
- package/components/AnchorLink/AnchorLink.js.map +1 -1
- package/components/Badge/Badge.stories.d.ts +1 -1
- package/components/Button/Button.d.ts +2 -1
- package/components/Button/Button.js +88 -88
- package/components/Button/Button.js.map +1 -1
- package/components/Button/Button.stories.d.ts +1 -0
- package/components/Button/styles.module.scss +4 -0
- package/components/Button/styles.module.scss.d.ts +1 -0
- package/components/Checkbox/Checkbox.d.ts +2 -0
- package/components/Checkbox/Checkbox.js +72 -70
- package/components/Checkbox/Checkbox.js.map +1 -1
- package/components/Dropdown/Dropdown.d.ts +2 -0
- package/components/Dropdown/Dropdown.js +32 -31
- package/components/Dropdown/Dropdown.js.map +1 -1
- package/components/ErrorWrapper/ErrorWrapper.d.ts +4 -2
- package/components/ErrorWrapper/ErrorWrapper.js +7 -7
- package/components/ErrorWrapper/ErrorWrapper.js.map +1 -1
- package/components/Expander/Expander.d.ts +2 -0
- package/components/Expander/Expander.js +30 -29
- package/components/Expander/Expander.js.map +1 -1
- package/components/ExpanderHierarchy/expander.module.scss +0 -20
- package/components/ExpanderHierarchy/expander.module.scss.d.ts +0 -1
- package/components/ExpanderList/ExpanderList.d.ts +4 -0
- package/components/ExpanderList/ExpanderList.js +78 -75
- package/components/ExpanderList/ExpanderList.js.map +1 -1
- package/components/ExpanderList/ExpanderList.stories.d.ts +1 -1
- package/components/FormExample/FormExample.js +136 -216
- package/components/FormExample/FormExample.js.map +1 -1
- package/components/FormGroup/FormGroup.d.ts +2 -0
- package/components/FormGroup/FormGroup.js +62 -48
- package/components/FormGroup/FormGroup.js.map +1 -1
- package/components/FormGroup/FormGroup.stories.d.ts +1 -0
- package/components/FormLayout/styles.module.scss +1 -2
- package/components/GridExample/GridExample.js +1 -1
- package/components/GridExample/GridExample.js.map +1 -1
- package/components/HelpQuestion/styles.module.scss +3 -3
- package/components/Icon/Icon.stories.d.ts +5 -2
- package/components/Input/Input.d.ts +2 -0
- package/components/Input/Input.js +75 -74
- package/components/Input/Input.js.map +1 -1
- package/components/Input/Input.stories.d.ts +2 -2
- package/components/LinkList/LinkList.stories.d.ts +1 -1
- package/components/Loader/Loader.stories.d.ts +1 -1
- package/components/Logo/Logo.stories.d.ts +1 -1
- package/components/NotificationPanel/DetailButton/styles.module.scss +1 -1
- package/components/PopMenu/PopMenu.js +73 -61
- package/components/PopMenu/PopMenu.js.map +1 -1
- package/components/PopOver/PopOver.d.ts +2 -0
- package/components/PopOver/PopOver.js +37 -36
- package/components/PopOver/PopOver.js.map +1 -1
- package/components/RadioButton/RadioButton.d.ts +2 -0
- package/components/RadioButton/RadioButton.js +62 -60
- package/components/RadioButton/RadioButton.js.map +1 -1
- package/components/Select/Select.d.ts +2 -0
- package/components/Select/Select.js +40 -39
- package/components/Select/Select.js.map +1 -1
- package/components/SharingStatus/styles.module.scss +2 -0
- package/components/Textarea/Textarea.d.ts +4 -0
- package/components/Textarea/Textarea.js +70 -67
- package/components/Textarea/Textarea.js.map +1 -1
- package/components/Trigger/styles.module.scss +24 -4
- package/components/Validation/ErrorList.d.ts +7 -0
- package/components/Validation/ErrorList.js +8 -0
- package/components/Validation/ErrorList.js.map +1 -0
- package/components/Validation/ErrorListItem.d.ts +8 -0
- package/components/Validation/ErrorListItem.js +12 -0
- package/components/Validation/ErrorListItem.js.map +1 -0
- package/components/Validation/Validation.d.ts +9 -1
- package/components/Validation/Validation.js +15 -13
- package/components/Validation/Validation.js.map +1 -1
- package/components/Validation/ValidationSummary.d.ts +15 -0
- package/components/Validation/ValidationSummary.js +17 -0
- package/components/Validation/ValidationSummary.js.map +1 -0
- package/components/Validation/styles.module.scss +13 -5
- package/components/Validation/styles.module.scss.d.ts +4 -1
- package/components/Validation/types.d.ts +9 -0
- package/constants.d.ts +1 -0
- package/constants.js +1 -1
- package/constants.js.map +1 -1
- package/fonts/source-sans-pro-200-extralight.woff +0 -0
- package/fonts/source-sans-pro-200-extralight.woff2 +0 -0
- package/fonts/source-sans-pro-300-light.woff +0 -0
- package/fonts/source-sans-pro-300-light.woff2 +0 -0
- package/fonts/source-sans-pro-400-regular.woff +0 -0
- package/fonts/source-sans-pro-400-regular.woff2 +0 -0
- package/fonts/source-sans-pro-600-semibold.woff +0 -0
- package/fonts/source-sans-pro-600-semibold.woff2 +0 -0
- package/fonts/source-sans-pro-700-bold.woff +0 -0
- package/fonts/source-sans-pro-700-bold.woff2 +0 -0
- package/fonts/source-sans-pro-900-black.woff +0 -0
- package/fonts/source-sans-pro-900-black.woff2 +0 -0
- package/package.json +3 -3
- package/scss/_icon.scss +8 -0
- package/utils/tests/setup-test.d.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
## 7.0.0-beta.3 (2024-04-04)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
- button arrow prop endres til aa stotte accessibility-character
|
|
6
|
+
([e516b86](https://github.com/helsenorge/designsystem/commit/e516b869cd48f301b3ab0242548ef33c07c0da1c)), closes
|
|
7
|
+
[#320171](https://github.com/helsenorge/designsystem/issues/320171)
|
|
8
|
+
- skjermleser leser oppsummerende feilmelding i validation automatisk
|
|
9
|
+
([0c9fc3a](https://github.com/helsenorge/designsystem/commit/0c9fc3aa1f9dd2d245a9037b568bce58d6d7455c)), closes
|
|
10
|
+
[#316622](https://github.com/helsenorge/designsystem/issues/316622)
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
- trigger har riktig avstand til andre elementer og større klikkflate i medium størrelse
|
|
15
|
+
([c9d566f](https://github.com/helsenorge/designsystem/commit/c9d566fefe6ff0797925e7c90ebfe17e48de041e)), closes
|
|
16
|
+
[#322394](https://github.com/helsenorge/designsystem/issues/322394)
|
|
17
|
+
|
|
18
|
+
## 7.0.0-beta.2 (2024-03-07)
|
|
19
|
+
|
|
1
20
|
## 7.0.0-beta.1 (2024-03-07)
|
|
2
21
|
|
|
3
22
|
## 7.0.0-beta.0 (2024-03-07)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePseudoClasses.js","sources":["../../src/__mocks__/usePseudoClasses.ts"],"sourcesContent":["import { vi as jest } from 'vitest';\n\njest.mock('../hooks/usePseudoClasses', () => ({\n usePseudoClasses: jest.fn().mockImplementation(ref => {\n return { refObject: ref, isHovered: false, isFocused: false };\n }),\n}));\n\nexport {};\n"],"names":["jest","ref"],"mappings":";AAEAA,EAAK,KAAK,6BAA6B,OAAO;AAAA,EAC5C,kBAAkBA,EAAK,GAAG,EAAE,mBAAmB,CAAOC,OAC7C,EAAE,WAAWA,GAAK,WAAW,IAAO,WAAW,KACvD;AACH,EAAE;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
export type AnchorLinkTargets = '_self' | '_blank' | '_parent';
|
|
3
3
|
export type AnchorLinkTags = 'a' | 'button';
|
|
4
|
+
export type AnchorLinkOnClickEvent = React.MouseEvent<HTMLElement, MouseEvent> | React.FormEvent<{}> | React.KeyboardEvent<HTMLUListElement> | null;
|
|
4
5
|
export interface AnchorLinkProps {
|
|
5
6
|
/** Sets the content of the <a> tag */
|
|
6
7
|
children: React.ReactNode;
|
|
@@ -15,7 +16,7 @@ export interface AnchorLinkProps {
|
|
|
15
16
|
/** HTML markup for anchor link. Default: a */
|
|
16
17
|
htmlMarkup?: AnchorLinkTags;
|
|
17
18
|
/** Function that is called when clicked */
|
|
18
|
-
onClick?: (e?:
|
|
19
|
+
onClick?: (e?: AnchorLinkOnClickEvent) => void;
|
|
19
20
|
/** Sets the data-testid attribute. */
|
|
20
21
|
testId?: string;
|
|
21
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnchorLink.js","sources":["../../../src/components/AnchorLink/AnchorLink.tsx"],"sourcesContent":["import React from 'react';\n\nimport classNames from 'classnames';\n\nimport { AnalyticsId } from '../../constants';\nimport { useHover } from '../../hooks/useHover';\nimport { getColor } from '../../theme/currys';\nimport Icon, { IconSize } from '../Icon';\nimport ArrowUpRight from '../Icons/ArrowUpRight';\n\nimport AnchorLinkStyles from './styles.module.scss';\n\nexport type AnchorLinkTargets = '_self' | '_blank' | '_parent';\n\nexport type AnchorLinkTags = 'a' | 'button';\n\nexport interface AnchorLinkProps {\n /** Sets the content of the <a> tag */\n children: React.ReactNode;\n /** URL to link to */\n href?: string;\n /** Gives a unique id to the anchor-link :) */\n id?: string;\n /** Adds custom classes to the element. */\n className?: string;\n /** Sets the target type of the <a> tag. _blank adds an arrow icon at the end of the link */\n target?: AnchorLinkTargets;\n /** HTML markup for anchor link. Default: a */\n htmlMarkup?: AnchorLinkTags;\n /** Function that is called when clicked */\n onClick?: (e?:
|
|
1
|
+
{"version":3,"file":"AnchorLink.js","sources":["../../../src/components/AnchorLink/AnchorLink.tsx"],"sourcesContent":["import React from 'react';\n\nimport classNames from 'classnames';\n\nimport { AnalyticsId } from '../../constants';\nimport { useHover } from '../../hooks/useHover';\nimport { getColor } from '../../theme/currys';\nimport Icon, { IconSize } from '../Icon';\nimport ArrowUpRight from '../Icons/ArrowUpRight';\n\nimport AnchorLinkStyles from './styles.module.scss';\n\nexport type AnchorLinkTargets = '_self' | '_blank' | '_parent';\n\nexport type AnchorLinkTags = 'a' | 'button';\n\nexport type AnchorLinkOnClickEvent =\n | React.MouseEvent<HTMLElement, MouseEvent>\n | React.FormEvent<{}>\n | React.KeyboardEvent<HTMLUListElement>\n | null;\n\nexport interface AnchorLinkProps {\n /** Sets the content of the <a> tag */\n children: React.ReactNode;\n /** URL to link to */\n href?: string;\n /** Gives a unique id to the anchor-link :) */\n id?: string;\n /** Adds custom classes to the element. */\n className?: string;\n /** Sets the target type of the <a> tag. _blank adds an arrow icon at the end of the link */\n target?: AnchorLinkTargets;\n /** HTML markup for anchor link. Default: a */\n htmlMarkup?: AnchorLinkTags;\n /** Function that is called when clicked */\n onClick?: (e?: AnchorLinkOnClickEvent) => void;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nconst AnchorLink = React.forwardRef<HTMLAnchorElement | HTMLButtonElement, AnchorLinkProps>((props, ref) => {\n const { id, href, children, className, target = '_self', htmlMarkup = 'a', onClick, testId } = props;\n const external = target === '_blank';\n const { hoverRef, isHovered } = useHover<HTMLButtonElement | HTMLAnchorElement>(\n ref as React.RefObject<HTMLButtonElement | HTMLAnchorElement>\n );\n const anchorClasses = classNames(AnchorLinkStyles.anchorlink, className);\n\n const commonProps = {\n id,\n ['data-testid']: testId,\n ['data-analyticsid']: AnalyticsId.AnchorLink,\n onClick,\n };\n\n const renderContent = () => (\n <>\n {children}\n {external && (\n <Icon\n className={AnchorLinkStyles.anchorlink__icon}\n svgIcon={ArrowUpRight}\n color={getColor('blueberry', 600)}\n hoverColor={getColor('blueberry', 700)}\n size={IconSize.XSmall}\n isHovered={isHovered}\n />\n )}\n </>\n );\n\n return (\n <>\n {htmlMarkup === 'a' && (\n <a\n href={href}\n target={target}\n className={anchorClasses}\n rel={external ? 'noopener noreferrer' : undefined}\n ref={hoverRef as React.RefObject<HTMLAnchorElement>}\n {...commonProps}\n >\n {renderContent()}\n </a>\n )}\n {htmlMarkup === 'button' && (\n <button\n type=\"button\"\n className={AnchorLinkStyles['anchorlink-wrapper']}\n ref={hoverRef as React.RefObject<HTMLButtonElement>}\n {...commonProps}\n >\n <span className={anchorClasses}>{renderContent()}</span>\n </button>\n )}\n </>\n );\n});\n\nexport default AnchorLink;\n"],"names":["AnchorLink","React","props","ref","id","href","children","className","target","htmlMarkup","onClick","testId","external","hoverRef","isHovered","useHover","anchorClasses","classNames","AnchorLinkStyles","commonProps","AnalyticsId","renderContent","Icon","ArrowUpRight","getColor","IconSize","AnchorLink$1"],"mappings":";;;;;;;;AAyCA,MAAMA,IAAaC,EAAM,WAAmE,CAACC,GAAOC,MAAQ;AACpG,QAAA,EAAE,IAAAC,GAAI,MAAAC,GAAM,UAAAC,GAAU,WAAAC,GAAW,QAAAC,IAAS,SAAS,YAAAC,IAAa,KAAK,SAAAC,GAAS,QAAAC,EAAA,IAAWT,GACzFU,IAAWJ,MAAW,UACtB,EAAE,UAAAK,GAAU,WAAAC,EAAA,IAAcC;AAAA,IAC9BZ;AAAA,EAAA,GAEIa,IAAgBC,EAAWC,EAAiB,YAAYX,CAAS,GAEjEY,IAAc;AAAA,IAClB,IAAAf;AAAA,IACC,eAAgBO;AAAA,IAChB,oBAAqBS,EAAY;AAAA,IAClC,SAAAV;AAAA,EAAA,GAGIW,IAAgB,MAEjBpB,gBAAAA,EAAA,cAAAA,EAAA,UAAA,MAAAK,GACAM,KACCX,gBAAAA,EAAA;AAAA,IAACqB;AAAA,IAAA;AAAA,MACC,WAAWJ,EAAiB;AAAA,MAC5B,SAASK;AAAA,MACT,OAAOC,EAAS,aAAa,GAAG;AAAA,MAChC,YAAYA,EAAS,aAAa,GAAG;AAAA,MACrC,MAAMC,EAAS;AAAA,MACf,WAAAX;AAAA,IAAA;AAAA,EAAA,CAGN;AAIA,SAAAb,gBAAAA,EAAA,cAAAA,EAAA,UAAA,MACGQ,MAAe,OACdR,gBAAAA,EAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,MAAAI;AAAA,MACA,QAAAG;AAAA,MACA,WAAWQ;AAAA,MACX,KAAKJ,IAAW,wBAAwB;AAAA,MACxC,KAAKC;AAAA,MACJ,GAAGM;AAAA,IAAA;AAAA,IAEHE,EAAc;AAAA,EAAA,GAGlBZ,MAAe,YACdR,gBAAAA,EAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,MAAK;AAAA,MACL,WAAWiB,EAAiB,oBAAoB;AAAA,MAChD,KAAKL;AAAA,MACJ,GAAGM;AAAA,IAAA;AAAA,IAEHlB,gBAAAA,EAAA,cAAA,QAAA,EAAK,WAAWe,EAAA,GAAgBK,GAAgB;AAAA,EAAA,CAGvD;AAEJ,CAAC,GAEDK,IAAe1B;"}
|
|
@@ -5,6 +5,7 @@ export type ButtonVariant = 'fill' | 'outline' | 'borderless';
|
|
|
5
5
|
export type ButtonSize = 'medium' | 'large';
|
|
6
6
|
export type ButtonMode = 'onlight' | 'ondark';
|
|
7
7
|
export type ButtonTags = 'button' | 'a';
|
|
8
|
+
export type ButtonArrows = 'icon' | 'accessibility-character';
|
|
8
9
|
export interface ButtonProps extends HTMLButtonProps, HTMLAnchorProps, AriaAttributes {
|
|
9
10
|
/** Sets the aria-label of the button, use when the button only includes an icon */
|
|
10
11
|
ariaLabel?: string;
|
|
@@ -17,7 +18,7 @@ export interface ButtonProps extends HTMLButtonProps, HTMLAnchorProps, AriaAttri
|
|
|
17
18
|
/** Adds custom classes to the element. */
|
|
18
19
|
className?: string;
|
|
19
20
|
/** Enables an arrow icon to the right inside the button (Not available in borderless variant) */
|
|
20
|
-
arrow?:
|
|
21
|
+
arrow?: ButtonArrows;
|
|
21
22
|
/** Changes the intent of the button. Mostly changes the color profile. */
|
|
22
23
|
concept?: ButtonConcept;
|
|
23
24
|
/** Disables text wrapping and enables ellipsis. */
|
|
@@ -1,116 +1,116 @@
|
|
|
1
|
-
import o, { useRef as
|
|
2
|
-
import
|
|
3
|
-
import { Icon as
|
|
4
|
-
import { AnalyticsId as
|
|
5
|
-
import { useBreakpoint as
|
|
6
|
-
import { useHover as
|
|
7
|
-
import { useIcons as
|
|
8
|
-
import { getColor as
|
|
9
|
-
import { breakpoints as
|
|
10
|
-
import { isTest as
|
|
11
|
-
import
|
|
1
|
+
import o, { useRef as lt, useEffect as ct } from "react";
|
|
2
|
+
import p from "classnames";
|
|
3
|
+
import { Icon as it } from "../Icon/Icon.js";
|
|
4
|
+
import { AnalyticsId as $, IconSize as v } from "../../constants.js";
|
|
5
|
+
import { useBreakpoint as ut } from "../../hooks/useBreakpoint.js";
|
|
6
|
+
import { useHover as D } from "../../hooks/useHover.js";
|
|
7
|
+
import { useIcons as mt } from "../../hooks/useIcons.js";
|
|
8
|
+
import { getColor as i } from "../../theme/currys/color.js";
|
|
9
|
+
import { breakpoints as bt } from "../../theme/grid.js";
|
|
10
|
+
import { isTest as pt, isProd as dt } from "../../utils/environment.js";
|
|
11
|
+
import ft from "../Icons/ArrowRight.js";
|
|
12
12
|
import t from "./styles.module.scss";
|
|
13
|
-
const
|
|
13
|
+
const ht = (e, r, n, d, s, g) => g && n ? !s || e ? i("neutral", r ? 500 : 700) : i("white") : n ? !s || e ? i("neutral", 500) : `${i("white")}b3` : e && !s || !e && s ? "white" : d === "normal" ? i("blueberry", 600) : i("cherry", 500), N = (e, r) => r && e ? v.Small : e ? v.Medium : v.XSmall, gt = (e, r, n) => {
|
|
14
14
|
if (n && e && (r === void 0 || r === ""))
|
|
15
15
|
throw new Error("Fyll inn ariaLabel prop på Button uten tekst for å opprettholde UU krav");
|
|
16
|
-
},
|
|
16
|
+
}, _t = o.forwardRef(function(r, n) {
|
|
17
17
|
const {
|
|
18
|
-
ariaLabel:
|
|
18
|
+
ariaLabel: d,
|
|
19
19
|
id: s,
|
|
20
20
|
children: g,
|
|
21
|
-
wrapperClassName:
|
|
22
|
-
className:
|
|
23
|
-
arrow:
|
|
24
|
-
concept:
|
|
25
|
-
disabled:
|
|
26
|
-
ellipsis:
|
|
27
|
-
fluid:
|
|
28
|
-
htmlMarkup:
|
|
29
|
-
mode:
|
|
30
|
-
onBlur:
|
|
21
|
+
wrapperClassName: O,
|
|
22
|
+
className: X,
|
|
23
|
+
arrow: _,
|
|
24
|
+
concept: B = "normal",
|
|
25
|
+
disabled: f = !1,
|
|
26
|
+
ellipsis: R = !1,
|
|
27
|
+
fluid: A = !1,
|
|
28
|
+
htmlMarkup: w = "button",
|
|
29
|
+
mode: j = "onlight",
|
|
30
|
+
onBlur: E,
|
|
31
31
|
onClick: x,
|
|
32
|
-
size:
|
|
33
|
-
variant:
|
|
34
|
-
href:
|
|
35
|
-
tabIndex:
|
|
36
|
-
testId:
|
|
37
|
-
target:
|
|
38
|
-
type:
|
|
39
|
-
...
|
|
40
|
-
} = r, [
|
|
32
|
+
size: q = "medium",
|
|
33
|
+
variant: I = "fill",
|
|
34
|
+
href: G,
|
|
35
|
+
tabIndex: S,
|
|
36
|
+
testId: z,
|
|
37
|
+
target: U,
|
|
38
|
+
type: J = "button",
|
|
39
|
+
...F
|
|
40
|
+
} = r, [u, m, H] = mt(o.Children.toArray(g)), { hoverRef: L, isHovered: K } = w === "button" ? D(n) : D(n), Q = lt(null), a = !!(u || m) && !H, M = u && (m || _) && !a, y = j === "ondark", h = ut() < bt.md, P = B === "destructive" && !f, Y = I === "outline", l = I === "borderless", T = ht(I === "fill", l, f, B, y, h), C = _ === "icon" && !l, b = q === "large" && !P && !l, Z = _ === "accessibility-character" && !A && !u && !m && !C && l, tt = { ...F }, V = p(
|
|
41
41
|
t["button-wrapper"],
|
|
42
|
-
{ [t["button-wrapper--fluid"]]:
|
|
43
|
-
|
|
44
|
-
),
|
|
42
|
+
{ [t["button-wrapper--fluid"]]: A || R },
|
|
43
|
+
O
|
|
44
|
+
), ot = p(
|
|
45
45
|
t.button,
|
|
46
46
|
{
|
|
47
|
-
[t["button--destructive"]]:
|
|
48
|
-
[t["button--normal"]]: !
|
|
49
|
-
[t["button--large"]]:
|
|
50
|
-
[t["button--outline"]]:
|
|
51
|
-
[t["button--borderless"]]:
|
|
52
|
-
[t["button--left-icon"]]:
|
|
53
|
-
[t["button--right-icon"]]:
|
|
54
|
-
[t["button--both-icons"]]:
|
|
47
|
+
[t["button--destructive"]]: P,
|
|
48
|
+
[t["button--normal"]]: !b,
|
|
49
|
+
[t["button--large"]]: b,
|
|
50
|
+
[t["button--outline"]]: Y,
|
|
51
|
+
[t["button--borderless"]]: l,
|
|
52
|
+
[t["button--left-icon"]]: u && !a,
|
|
53
|
+
[t["button--right-icon"]]: m && !a,
|
|
54
|
+
[t["button--both-icons"]]: M,
|
|
55
55
|
[t["button--only-icon"]]: a,
|
|
56
|
-
[t["button--arrow"]]:
|
|
57
|
-
[t["button--on-dark"]]:
|
|
56
|
+
[t["button--arrow"]]: C,
|
|
57
|
+
[t["button--on-dark"]]: y
|
|
58
58
|
},
|
|
59
|
-
|
|
60
|
-
),
|
|
61
|
-
[t["button__text--ellipsis"]]:
|
|
62
|
-
}),
|
|
63
|
-
[t["diagonal--on-dark"]]:
|
|
59
|
+
X
|
|
60
|
+
), et = p(t.button__text, {
|
|
61
|
+
[t["button__text--ellipsis"]]: R
|
|
62
|
+
}), rt = p(t.diagonal, {
|
|
63
|
+
[t["diagonal--on-dark"]]: y
|
|
64
64
|
});
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
ct(() => {
|
|
66
|
+
gt(a, d, !pt() && !dt());
|
|
67
67
|
}, []);
|
|
68
|
-
const
|
|
69
|
-
size:
|
|
70
|
-
color:
|
|
71
|
-
isHovered:
|
|
72
|
-
className:
|
|
73
|
-
}) : null,
|
|
74
|
-
/* @__PURE__ */ o.createElement(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
) :
|
|
78
|
-
return /* @__PURE__ */ o.createElement(o.Fragment, null,
|
|
68
|
+
const k = (c, st, at) => c ? o.cloneElement(c, {
|
|
69
|
+
size: st,
|
|
70
|
+
color: c != null && c.props.color ? c.props.color : T,
|
|
71
|
+
isHovered: K,
|
|
72
|
+
className: at
|
|
73
|
+
}) : null, nt = () => /* @__PURE__ */ o.createElement("span", { className: et, ref: Q }, f && l && /* @__PURE__ */ o.createElement("span", { className: rt }, /* @__PURE__ */ o.createElement("span", { className: t.diagonal__line })), /* @__PURE__ */ o.createElement("span", null, a ? d : H)), W = () => /* @__PURE__ */ o.createElement("span", { className: ot }, k(u, N(b, h), a ? void 0 : t["button__left-icon"]), nt(), C ? k(
|
|
74
|
+
/* @__PURE__ */ o.createElement(it, { svgIcon: ft }),
|
|
75
|
+
N(b, h),
|
|
76
|
+
p(t.button__arrow, { [t["button__arrow--both-icons"]]: M })
|
|
77
|
+
) : k(m, N(b, h), t["button__right-icon"]), Z && /* @__PURE__ */ o.createElement("span", { style: { color: T }, className: t["button__right-unicode-arrow"] }, " →"));
|
|
78
|
+
return /* @__PURE__ */ o.createElement(o.Fragment, null, w === "button" && /* @__PURE__ */ o.createElement(
|
|
79
79
|
"button",
|
|
80
80
|
{
|
|
81
81
|
id: s,
|
|
82
|
-
onBlur:
|
|
82
|
+
onBlur: E,
|
|
83
83
|
onClick: x,
|
|
84
|
-
disabled:
|
|
85
|
-
"data-testid":
|
|
86
|
-
"data-analyticsid":
|
|
87
|
-
className:
|
|
88
|
-
ref:
|
|
89
|
-
tabIndex:
|
|
90
|
-
type:
|
|
91
|
-
...
|
|
84
|
+
disabled: f,
|
|
85
|
+
"data-testid": z,
|
|
86
|
+
"data-analyticsid": $.Button,
|
|
87
|
+
className: V,
|
|
88
|
+
ref: L,
|
|
89
|
+
tabIndex: S,
|
|
90
|
+
type: J,
|
|
91
|
+
...tt
|
|
92
92
|
},
|
|
93
|
-
|
|
94
|
-
),
|
|
93
|
+
W()
|
|
94
|
+
), w === "a" && /* @__PURE__ */ o.createElement(
|
|
95
95
|
"a",
|
|
96
96
|
{
|
|
97
97
|
id: s,
|
|
98
|
-
onBlur:
|
|
98
|
+
onBlur: E,
|
|
99
99
|
onClick: x,
|
|
100
|
-
"data-testid":
|
|
101
|
-
"data-analyticsid":
|
|
102
|
-
className:
|
|
103
|
-
href:
|
|
104
|
-
target:
|
|
105
|
-
rel:
|
|
106
|
-
ref:
|
|
107
|
-
tabIndex:
|
|
108
|
-
...
|
|
100
|
+
"data-testid": z,
|
|
101
|
+
"data-analyticsid": $.Button,
|
|
102
|
+
className: V,
|
|
103
|
+
href: G,
|
|
104
|
+
target: U,
|
|
105
|
+
rel: U === "_blank" ? "noopener noreferrer" : r.rel,
|
|
106
|
+
ref: L,
|
|
107
|
+
tabIndex: S,
|
|
108
|
+
...F
|
|
109
109
|
},
|
|
110
|
-
|
|
110
|
+
W()
|
|
111
111
|
));
|
|
112
|
-
}),
|
|
112
|
+
}), zt = _t;
|
|
113
113
|
export {
|
|
114
|
-
|
|
114
|
+
zt as default
|
|
115
115
|
};
|
|
116
116
|
//# sourceMappingURL=Button.js.map
|
|
@@ -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';\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?: boolean;\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 /** 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) => {\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 = false,\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 ...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 && !borderlessVariant;\n const large = size === 'large' && !destructive && !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 });\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 ? iconElement.props.color : iconColor,\n 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 </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","restProps","leftIcon","rightIcon","restChildren","useIcons","hoverRef","isHovered","useHover","buttonContentRef","useRef","bothIcons","onDark","useBreakpoint","breakpoints","destructive","outlineVariant","borderlessVariant","iconColor","hasArrow","rest","buttonWrapperClasses","classNames","buttonStyles","buttonClasses","buttonTextClasses","diagonalClasses","useEffect","isTest","isProd","renderIcon","iconElement","iconSize","iconClassName","renderButtonContent","renderbuttonContentWrapper","Icon","ArrowRight","AnalyticsId","Button$1"],"mappings":";;;;;;;;;;;;AA6DA,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,MAAoB;AAC/F,MAAIA,KAAUF,MAAaC,MAAc,UAAaA,MAAc;AAC5D,UAAA,IAAI,MAAM,yEAAyE;AAE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C;AAAA,MACA,eAAaK;AAAA,MACb,oBAAkBwC,EAAY;AAAA,MAC9B,WAAWjB;AAAA,MACX,MAAAzB;AAAA,MACA,QAAAG;AAAA,MACA,KAAKA,MAAW,WAAW,wBAAwBlB,EAAM;AAAA,MACzD,KAAKyB;AAAA,MACL,UAAAT;AAAA,MACC,GAAGI;AAAA,IAAA;AAAA,IAEHkC,EAA2B;AAAA,EAAA,CAGlC;AAEJ,CAAC,GAEDI,KAAe5D;"}
|
|
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';\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 /** 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 ...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 });\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 ? iconElement.props.color : iconColor,\n 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']}>\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","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","renderbuttonContentWrapper","Icon","ArrowRight","AnalyticsId","Button$1"],"mappings":";;;;;;;;;;;;AA8DA,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,GAE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AC;AAAA,IAAA;AAAA,MACC,IAAAG;AAAA,MACA,QAAAS;AAAA,MACA,SAAAC;AAAA,MACA,UAAA1B;AAAA,MACA,eAAa+B;AAAA,MACb,oBAAkByC,EAAY;AAAA,MAC9B,WAAWjB;AAAA,MACX,KAAKhB;AAAA,MACL,UAAAT;AAAA,MACA,MAAAG;AAAA,MACC,GAAGqB;AAAA,IAAA;AAAA,IAEHe,EAA2B;AAAA,EAAA,GAG/B9C,MAAe,OACdV,gBAAAA,EAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,IAAAG;AAAA,MACA,QAAAS;AAAA,MACA,SAAAC;AAAA,MACA,eAAaK;AAAA,MACb,oBAAkByC,EAAY;AAAA,MAC9B,WAAWjB;AAAA,MACX,MAAA1B;AAAA,MACA,QAAAG;AAAA,MACA,KAAKA,MAAW,WAAW,wBAAwBlB,EAAM;AAAA,MACzD,KAAKyB;AAAA,MACL,UAAAT;AAAA,MACC,GAAGI;AAAA,IAAA;AAAA,IAEHmC,EAA2B;AAAA,EAAA,CAGlC;AAEJ,CAAC,GAEDI,KAAe7D;"}
|
|
@@ -332,6 +332,10 @@ $with-icons: // icon-class, size-class, padding-left, padding-right, padding-lef
|
|
|
332
332
|
}
|
|
333
333
|
}
|
|
334
334
|
|
|
335
|
+
&__right-unicode-arrow {
|
|
336
|
+
white-space: pre;
|
|
337
|
+
}
|
|
338
|
+
|
|
335
339
|
/* stylelint-disable-next-line */
|
|
336
340
|
&--outline &__text {
|
|
337
341
|
@include outline-text($blueberry600);
|
|
@@ -15,6 +15,8 @@ export interface CheckboxProps extends Pick<React.InputHTMLAttributes<HTMLInputE
|
|
|
15
15
|
error?: boolean;
|
|
16
16
|
/** Error text to show above the component */
|
|
17
17
|
errorText?: string;
|
|
18
|
+
/** Error text id */
|
|
19
|
+
errorTextId?: string;
|
|
18
20
|
/** Sets the data-testid attribute. */
|
|
19
21
|
testId?: string;
|
|
20
22
|
}
|
|
@@ -1,107 +1,109 @@
|
|
|
1
|
-
import l, { useState as
|
|
1
|
+
import l, { useState as X, useEffect as $ } from "react";
|
|
2
2
|
import t from "classnames";
|
|
3
|
-
import { FormMode as
|
|
4
|
-
import { usePseudoClasses as
|
|
3
|
+
import { FormMode as i, FormSize as J, AnalyticsId as K, IconSize as Q } from "../../constants.js";
|
|
4
|
+
import { usePseudoClasses as V } from "../../hooks/usePseudoClasses.js";
|
|
5
|
+
import { useUuid as Y } from "../../hooks/useUuid.js";
|
|
5
6
|
import { getColor as h } from "../../theme/currys/color.js";
|
|
6
|
-
import { isMutableRefObject as
|
|
7
|
-
import { uuid as
|
|
8
|
-
import { Icon as
|
|
9
|
-
import
|
|
10
|
-
import { getLabelText as
|
|
7
|
+
import { isMutableRefObject as Z, mergeRefs as ee } from "../../utils/refs.js";
|
|
8
|
+
import { uuid as ce } from "../../utils/uuid.js";
|
|
9
|
+
import { Icon as re } from "../Icon/Icon.js";
|
|
10
|
+
import oe from "../Icons/Check.js";
|
|
11
|
+
import { getLabelText as ae, renderLabelAsParent as le } from "../Label/Label.js";
|
|
11
12
|
import e from "./styles.module.scss";
|
|
12
|
-
const
|
|
13
|
+
const I = l.forwardRef((x, d) => {
|
|
13
14
|
const {
|
|
14
|
-
className:
|
|
15
|
+
className: N,
|
|
15
16
|
checked: k = !1,
|
|
16
17
|
disabled: a,
|
|
17
18
|
label: m,
|
|
18
|
-
inputId: p =
|
|
19
|
-
mode: n =
|
|
20
|
-
name:
|
|
21
|
-
size:
|
|
19
|
+
inputId: p = ce(),
|
|
20
|
+
mode: n = i.onwhite,
|
|
21
|
+
name: E = p,
|
|
22
|
+
size: S,
|
|
22
23
|
errorText: s,
|
|
23
24
|
error: g = !!s,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
errorTextId: R,
|
|
26
|
+
value: T = ae(m),
|
|
27
|
+
testId: z,
|
|
28
|
+
required: F,
|
|
27
29
|
onChange: u,
|
|
28
|
-
...
|
|
29
|
-
} = x, [
|
|
30
|
+
...L
|
|
31
|
+
} = x, [r, w] = X(k), f = Y(R), C = n === i.onwhite, y = n === i.ongrey, v = n === i.onblueberry, o = g || n === i.oninvalid, b = n === i.ondark, c = S === J.large, { refObject: j, isFocused: W } = V(Z(d) ? d : null), A = ee([d, j]), M = t(e["checkbox-wrapper"], {
|
|
30
32
|
[e["checkbox-wrapper--with-error"]]: s,
|
|
31
33
|
[e["checkbox-wrapper--large"]]: c
|
|
32
|
-
}),
|
|
34
|
+
}), O = t(e["checkbox-label"], {
|
|
33
35
|
[e["checkbox-label--disabled"]]: a,
|
|
34
|
-
[e["checkbox-label--on-dark"]]:
|
|
36
|
+
[e["checkbox-label--on-dark"]]: b,
|
|
35
37
|
[e["checkbox-label--large"]]: c,
|
|
36
|
-
[e["checkbox-label__large--checked"]]: c &&
|
|
37
|
-
[e["checkbox-label__large--focus"]]: c &&
|
|
38
|
-
[e["checkbox-label__large--on-white"]]: c &&
|
|
39
|
-
[e["checkbox-label__large--on-grey"]]: c &&
|
|
40
|
-
[e["checkbox-label__large--on-blueberry"]]: c &&
|
|
41
|
-
[e["checkbox-label__large--on-invalid"]]: c &&
|
|
38
|
+
[e["checkbox-label__large--checked"]]: c && r,
|
|
39
|
+
[e["checkbox-label__large--focus"]]: c && W,
|
|
40
|
+
[e["checkbox-label__large--on-white"]]: c && C,
|
|
41
|
+
[e["checkbox-label__large--on-grey"]]: c && y,
|
|
42
|
+
[e["checkbox-label__large--on-blueberry"]]: c && v,
|
|
43
|
+
[e["checkbox-label__large--on-invalid"]]: c && o,
|
|
42
44
|
[e["checkbox-label__large--disabled"]]: c && a
|
|
43
|
-
}),
|
|
44
|
-
[e["checkbox__icon-wrapper--on-white"]]:
|
|
45
|
-
[e["checkbox__icon-wrapper--on-grey"]]:
|
|
46
|
-
[e["checkbox__icon-wrapper--on-invalid"]]:
|
|
45
|
+
}), P = t(e.checkbox, N), U = t(e["checkbox__icon-wrapper"], {
|
|
46
|
+
[e["checkbox__icon-wrapper--on-white"]]: C,
|
|
47
|
+
[e["checkbox__icon-wrapper--on-grey"]]: y,
|
|
48
|
+
[e["checkbox__icon-wrapper--on-invalid"]]: o,
|
|
47
49
|
[e["checkbox__icon-wrapper--disabled"]]: a,
|
|
48
|
-
[e["checkbox__icon-wrapper__regular--checked"]]: !c &&
|
|
49
|
-
[e["checkbox__icon-wrapper__regular--invalid"]]: !c &&
|
|
50
|
-
[e["checkbox__icon-wrapper__regular--on-dark"]]: !c &&
|
|
51
|
-
[e["checkbox__icon-wrapper__large--checked"]]: c &&
|
|
52
|
-
[e["checkbox__icon-wrapper__large--invalid"]]: c &&
|
|
53
|
-
[e["checkbox__icon-wrapper--on-dark"]]:
|
|
54
|
-
[e["checkbox__icon-wrapper--on-blueberry"]]:
|
|
55
|
-
[e["checkbox__icon-wrapper--invalid"]]:
|
|
56
|
-
[e["checkbox__icon-wrapper__large--invalid"]]: c &&
|
|
57
|
-
[e["checkbox__icon-wrapper__large--disabled"]]: a && c &&
|
|
58
|
-
[e["checkbox__icon-wrapper__large--checked--invalid"]]: c &&
|
|
59
|
-
[e["checkbox__icon-wrapper__large--checked--disabled"]]: a && c &&
|
|
60
|
-
}),
|
|
61
|
-
[e["checkbox-label__text__large--checked"]]: c &&
|
|
62
|
-
[e["checkbox-label__text__large--invalid"]]: c &&
|
|
63
|
-
[e["checkbox-label__text--on-dark"]]:
|
|
50
|
+
[e["checkbox__icon-wrapper__regular--checked"]]: !c && r,
|
|
51
|
+
[e["checkbox__icon-wrapper__regular--invalid"]]: !c && r && o,
|
|
52
|
+
[e["checkbox__icon-wrapper__regular--on-dark"]]: !c && r && b,
|
|
53
|
+
[e["checkbox__icon-wrapper__large--checked"]]: c && r,
|
|
54
|
+
[e["checkbox__icon-wrapper__large--invalid"]]: c && o,
|
|
55
|
+
[e["checkbox__icon-wrapper--on-dark"]]: b,
|
|
56
|
+
[e["checkbox__icon-wrapper--on-blueberry"]]: v,
|
|
57
|
+
[e["checkbox__icon-wrapper--invalid"]]: o,
|
|
58
|
+
[e["checkbox__icon-wrapper__large--invalid"]]: c && r && o,
|
|
59
|
+
[e["checkbox__icon-wrapper__large--disabled"]]: a && c && r,
|
|
60
|
+
[e["checkbox__icon-wrapper__large--checked--invalid"]]: c && r && o,
|
|
61
|
+
[e["checkbox__icon-wrapper__large--checked--disabled"]]: a && c && r
|
|
62
|
+
}), q = t(e["checkbox-label__text"], {
|
|
63
|
+
[e["checkbox-label__text__large--checked"]]: c && r,
|
|
64
|
+
[e["checkbox-label__text__large--invalid"]]: c && r && o,
|
|
65
|
+
[e["checkbox-label__text--on-dark"]]: b,
|
|
64
66
|
[e["checkbox-label__text--disabled"]]: a
|
|
65
|
-
}),
|
|
67
|
+
}), B = t(e["checkbox-errors"]);
|
|
66
68
|
let _ = h("white");
|
|
67
|
-
(
|
|
69
|
+
(b || c && r) && (_ = h("blueberry", 900)), o && c && r && (_ = h("white")), a && (_ = h("neutral", 400)), $(() => {
|
|
68
70
|
w(k);
|
|
69
71
|
}, [k]);
|
|
70
|
-
const
|
|
71
|
-
u && u(
|
|
72
|
-
},
|
|
72
|
+
const D = (H) => {
|
|
73
|
+
u && u(H), w(!r);
|
|
74
|
+
}, G = () => /* @__PURE__ */ l.createElement(l.Fragment, null, /* @__PURE__ */ l.createElement(
|
|
73
75
|
"input",
|
|
74
76
|
{
|
|
75
77
|
id: p,
|
|
76
|
-
name:
|
|
77
|
-
className:
|
|
78
|
+
name: E,
|
|
79
|
+
className: P,
|
|
78
80
|
type: "checkbox",
|
|
79
|
-
checked:
|
|
81
|
+
checked: r,
|
|
80
82
|
disabled: a,
|
|
81
|
-
value:
|
|
82
|
-
ref:
|
|
83
|
-
"aria-describedby": x["aria-describedby"]
|
|
83
|
+
value: T,
|
|
84
|
+
ref: A,
|
|
85
|
+
"aria-describedby": [x["aria-describedby"] || "", f].join(" "),
|
|
84
86
|
"aria-invalid": g,
|
|
85
|
-
required:
|
|
86
|
-
onChange:
|
|
87
|
-
...
|
|
87
|
+
required: F,
|
|
88
|
+
onChange: D,
|
|
89
|
+
...L
|
|
88
90
|
}
|
|
89
|
-
), /* @__PURE__ */ l.createElement("span", { className:
|
|
90
|
-
return /* @__PURE__ */ l.createElement("div", { "data-testid":
|
|
91
|
+
), /* @__PURE__ */ l.createElement("span", { className: U }, r && /* @__PURE__ */ l.createElement(re, { color: _, className: e.checkbox__icon, svgIcon: oe, size: Q.XSmall })));
|
|
92
|
+
return /* @__PURE__ */ l.createElement("div", { "data-testid": z, "data-analyticsid": K.Checkbox, className: M }, s && /* @__PURE__ */ l.createElement("p", { className: B, id: f }, s), le(
|
|
91
93
|
m,
|
|
92
|
-
|
|
94
|
+
G(),
|
|
93
95
|
p,
|
|
94
96
|
n,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
+
O,
|
|
98
|
+
q,
|
|
97
99
|
e["checkbox-sublabel-wrapper"],
|
|
98
100
|
c
|
|
99
101
|
));
|
|
100
102
|
});
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
+
I.displayName = "Checkbox";
|
|
104
|
+
const ge = I;
|
|
103
105
|
export {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
+
I as Checkbox,
|
|
107
|
+
ge as default
|
|
106
108
|
};
|
|
107
109
|
//# sourceMappingURL=Checkbox.js.map
|