@helsenorge/designsystem-react 9.0.0 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Avatar.js +15 -14
- package/Avatar.js.map +1 -1
- package/Button.js +46 -41
- package/Button.js.map +1 -1
- package/CHANGELOG.md +50 -3
- package/Expander.js +22 -21
- package/Expander.js.map +1 -1
- package/Slider.js.map +1 -1
- package/components/Avatar/Avatar.d.ts +2 -0
- package/components/Avatar/styles.module.scss +4 -0
- package/components/Avatar/styles.module.scss.d.ts +1 -0
- package/components/Button/Button.d.ts +2 -0
- package/components/Button/styles.module.scss +28 -25
- package/components/Expander/styles.module.scss +6 -5
- package/components/Expander/styles.module.scss.d.ts +29 -0
- package/components/HelpPanel/index.js +17 -21
- package/components/HelpPanel/index.js.map +1 -1
- package/components/Slider/Slider.d.ts +1 -1
- package/components/Tabs/Tabs.d.ts +2 -0
- package/components/Tabs/index.js +40 -38
- package/components/Tabs/index.js.map +1 -1
- package/package.json +1 -1
- package/scss/layout.module.scss +14 -0
- package/scss/layout.module.scss.d.ts +9 -0
package/Avatar.js
CHANGED
|
@@ -1,34 +1,35 @@
|
|
|
1
1
|
import { jsx as m } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { AnalyticsId as
|
|
2
|
+
import v from "react";
|
|
3
|
+
import u from "classnames";
|
|
4
|
+
import { AnalyticsId as b, IconSize as x } from "./constants.js";
|
|
5
5
|
import { palette as o } from "./theme/palette.js";
|
|
6
|
-
import { I
|
|
7
|
-
import
|
|
6
|
+
import { I } from "./Icon.js";
|
|
7
|
+
import y from "./components/Icons/Check.js";
|
|
8
8
|
import a from "./components/Avatar/styles.module.scss";
|
|
9
9
|
var A = /* @__PURE__ */ ((r) => (r.xsmall = "xsmall", r.small = "small", r))(A || {});
|
|
10
|
-
const
|
|
11
|
-
const { children: t, className:
|
|
10
|
+
const j = v.forwardRef(function(c, i) {
|
|
11
|
+
const { children: t, className: n = "", selected: l = !1, variant: s = "normal", type: d = "normal", size: e = "small", testId: p } = c, f = t.charAt(0).toLocaleUpperCase() + t.substring(1, 2);
|
|
12
12
|
return /* @__PURE__ */ m(
|
|
13
13
|
"span",
|
|
14
14
|
{
|
|
15
|
-
className:
|
|
15
|
+
className: u(
|
|
16
16
|
a.avatar,
|
|
17
17
|
l && a["avatar--selected"],
|
|
18
18
|
s === "black" && a["avatar--black"],
|
|
19
|
+
d === "circle" && a["avatar--circle"],
|
|
19
20
|
e === "xsmall" && a["avatar--xsmall"],
|
|
20
21
|
e === "small" && a["avatar--small"],
|
|
21
|
-
|
|
22
|
+
n
|
|
22
23
|
),
|
|
23
|
-
ref:
|
|
24
|
-
"data-testid":
|
|
25
|
-
"data-analyticsid":
|
|
26
|
-
children: l ? /* @__PURE__ */ m(
|
|
24
|
+
ref: i,
|
|
25
|
+
"data-testid": p,
|
|
26
|
+
"data-analyticsid": b.Avatar,
|
|
27
|
+
children: l ? /* @__PURE__ */ m(I, { svgIcon: y, size: x.Small, color: s === "black" ? o.neutral900 : o.blueberry600 }) : f
|
|
27
28
|
}
|
|
28
29
|
);
|
|
29
30
|
});
|
|
30
31
|
export {
|
|
31
|
-
|
|
32
|
+
j as A,
|
|
32
33
|
A as a
|
|
33
34
|
};
|
|
34
35
|
//# sourceMappingURL=Avatar.js.map
|
package/Avatar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Avatar.js","sources":["../src/components/Avatar/Avatar.tsx"],"sourcesContent":["import React from 'react';\n\nimport cn from 'classnames';\n\nimport { AnalyticsId } from '../../constants';\nimport { palette } from '../../theme/palette';\nimport Icon, { IconSize } from '../Icon';\nimport Check from '../Icons/Check';\n\nimport styles from './styles.module.scss';\n\nexport enum AvatarSize {\n xsmall = 'xsmall',\n small = 'small',\n}\n\nexport interface AvatarProps {\n /** Name to display in the avatar. Will be truncated to the first two characters. */\n children: string;\n /** Displays a check icon to indicated the selected state. */\n selected?: boolean;\n /** background and color will be determined on variant. */\n variant?: 'normal' | 'black';\n /** Avatar size. Default: small */\n size?: keyof typeof AvatarSize;\n /** Adds custom classes to the element. */\n className?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\nexport type AvatarType = React.ForwardRefExoticComponent<AvatarProps & React.RefAttributes<HTMLElement>>;\nconst Avatar: AvatarType = React.forwardRef(function AvatarForwardedRef(props: AvatarProps, ref: React.ForwardedRef<HTMLElement>) {\n const { children, className = '', selected = false, variant = 'normal', size = AvatarSize.small, testId } = props;\n const truncatedName = children.charAt(0).toLocaleUpperCase() + children.substring(1, 2);\n return (\n <span\n className={cn(\n styles.avatar,\n selected && styles['avatar--selected'],\n variant === 'black' && styles['avatar--black'],\n size === AvatarSize.xsmall && styles['avatar--xsmall'],\n size === AvatarSize.small && styles['avatar--small'],\n className\n )}\n ref={ref}\n data-testid={testId}\n data-analyticsid={AnalyticsId.Avatar}\n >\n {selected ? (\n <Icon svgIcon={Check} size={IconSize.Small} color={variant === 'black' ? palette.neutral900 : palette.blueberry600} />\n ) : (\n truncatedName\n )}\n </span>\n );\n});\n\nexport default Avatar;\n"],"names":["AvatarSize","Avatar","React","props","ref","children","className","selected","variant","size","testId","truncatedName","jsx","cn","styles","AnalyticsId","Icon","Check","IconSize","palette"],"mappings":";;;;;;;;AAWY,IAAAA,sBAAAA,OACVA,EAAA,SAAS,UACTA,EAAA,QAAQ,SAFEA,IAAAA,KAAA,CAAA,CAAA;
|
|
1
|
+
{"version":3,"file":"Avatar.js","sources":["../src/components/Avatar/Avatar.tsx"],"sourcesContent":["import React from 'react';\n\nimport cn from 'classnames';\n\nimport { AnalyticsId } from '../../constants';\nimport { palette } from '../../theme/palette';\nimport Icon, { IconSize } from '../Icon';\nimport Check from '../Icons/Check';\n\nimport styles from './styles.module.scss';\n\nexport enum AvatarSize {\n xsmall = 'xsmall',\n small = 'small',\n}\n\nexport interface AvatarProps {\n /** Name to display in the avatar. Will be truncated to the first two characters. */\n children: string;\n /** Displays a check icon to indicated the selected state. */\n selected?: boolean;\n /** background and color will be determined on variant. */\n variant?: 'normal' | 'black';\n /** @deprecated Square or circle variant of avatar. The circle should only be used for representation of someone else. NB: This is temporary and will be renamed in v10 */\n type?: 'normal' | 'circle';\n /** Avatar size. Default: small */\n size?: keyof typeof AvatarSize;\n /** Adds custom classes to the element. */\n className?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\nexport type AvatarType = React.ForwardRefExoticComponent<AvatarProps & React.RefAttributes<HTMLElement>>;\nconst Avatar: AvatarType = React.forwardRef(function AvatarForwardedRef(props: AvatarProps, ref: React.ForwardedRef<HTMLElement>) {\n const { children, className = '', selected = false, variant = 'normal', type = 'normal', size = AvatarSize.small, testId } = props;\n const truncatedName = children.charAt(0).toLocaleUpperCase() + children.substring(1, 2);\n return (\n <span\n className={cn(\n styles.avatar,\n selected && styles['avatar--selected'],\n variant === 'black' && styles['avatar--black'],\n type === 'circle' && styles['avatar--circle'],\n size === AvatarSize.xsmall && styles['avatar--xsmall'],\n size === AvatarSize.small && styles['avatar--small'],\n className\n )}\n ref={ref}\n data-testid={testId}\n data-analyticsid={AnalyticsId.Avatar}\n >\n {selected ? (\n <Icon svgIcon={Check} size={IconSize.Small} color={variant === 'black' ? palette.neutral900 : palette.blueberry600} />\n ) : (\n truncatedName\n )}\n </span>\n );\n});\n\nexport default Avatar;\n"],"names":["AvatarSize","Avatar","React","props","ref","children","className","selected","variant","type","size","testId","truncatedName","jsx","cn","styles","AnalyticsId","Icon","Check","IconSize","palette"],"mappings":";;;;;;;;AAWY,IAAAA,sBAAAA,OACVA,EAAA,SAAS,UACTA,EAAA,QAAQ,SAFEA,IAAAA,KAAA,CAAA,CAAA;AAsBZ,MAAMC,IAAqBC,EAAM,WAAW,SAA4BC,GAAoBC,GAAsC;AAChI,QAAM,EAAE,UAAAC,GAAU,WAAAC,IAAY,IAAI,UAAAC,IAAW,IAAO,SAAAC,IAAU,UAAU,MAAAC,IAAO,UAAU,MAAAC,IAAO,SAAkB,QAAAC,MAAWR,GACvHS,IAAgBP,EAAS,OAAO,CAAC,EAAE,kBAAsB,IAAAA,EAAS,UAAU,GAAG,CAAC;AAEpF,SAAA,gBAAAQ;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAWC;AAAAA,QACTC,EAAO;AAAA,QACPR,KAAYQ,EAAO,kBAAkB;AAAA,QACrCP,MAAY,WAAWO,EAAO,eAAe;AAAA,QAC7CN,MAAS,YAAYM,EAAO,gBAAgB;AAAA,QAC5CL,MAAS,YAAqBK,EAAO,gBAAgB;AAAA,QACrDL,MAAS,WAAoBK,EAAO,eAAe;AAAA,QACnDT;AAAA,MACF;AAAA,MACA,KAAAF;AAAA,MACA,eAAaO;AAAA,MACb,oBAAkBK,EAAY;AAAA,MAE7B,UACCT,IAAA,gBAAAM,EAACI,GAAK,EAAA,SAASC,GAAO,MAAMC,EAAS,OAAO,OAAOX,MAAY,UAAUY,EAAQ,aAAaA,EAAQ,aAAc,CAAA,IAEpHR;AAAA,IAAA;AAAA,EAAA;AAIR,CAAC;"}
|
package/Button.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import x, { useRef as
|
|
1
|
+
import { jsxs as k, Fragment as dt, jsx as a } from "react/jsx-runtime";
|
|
2
|
+
import x, { useRef as bt, useEffect as pt } from "react";
|
|
3
3
|
import m from "classnames";
|
|
4
|
-
import { I as
|
|
4
|
+
import { I as mt } from "./Icon.js";
|
|
5
5
|
import { AnalyticsId as X, IconSize as B } from "./constants.js";
|
|
6
|
-
import { useBreakpoint as
|
|
6
|
+
import { useBreakpoint as ft } from "./hooks/useBreakpoint.js";
|
|
7
7
|
import { useHover as $ } from "./hooks/useHover.js";
|
|
8
|
-
import { useIcons as
|
|
8
|
+
import { useIcons as ht } from "./hooks/useIcons.js";
|
|
9
9
|
import { getColor as u } from "./theme/currys/color.js";
|
|
10
|
-
import { breakpoints as
|
|
11
|
-
import { isTest as
|
|
12
|
-
import
|
|
10
|
+
import { breakpoints as gt } from "./theme/grid.js";
|
|
11
|
+
import { isTest as _t, isProd as wt } from "./utils/environment.js";
|
|
12
|
+
import Ct 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, yt = (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
|
+
}, Lt = x.forwardRef(function(r, n) {
|
|
18
18
|
const {
|
|
19
19
|
ariaLabel: f,
|
|
20
20
|
id: e,
|
|
@@ -26,31 +26,32 @@ const It = (o, r, n, f, e, g) => g && n ? !e || o ? u("neutral", r ? 500 : 700)
|
|
|
26
26
|
disabled: i = !1,
|
|
27
27
|
ellipsis: S = !1,
|
|
28
28
|
fluid: w = !1,
|
|
29
|
-
htmlMarkup:
|
|
29
|
+
htmlMarkup: C = "button",
|
|
30
30
|
onColor: J = "onlight",
|
|
31
31
|
onBlur: z,
|
|
32
32
|
onClick: U,
|
|
33
33
|
size: K = "medium",
|
|
34
|
-
variant:
|
|
34
|
+
variant: I = "fill",
|
|
35
35
|
href: Q,
|
|
36
36
|
tabIndex: F,
|
|
37
37
|
testId: H,
|
|
38
38
|
target: P,
|
|
39
39
|
type: Y = "button",
|
|
40
|
-
|
|
40
|
+
textClassName: Z,
|
|
41
|
+
textPosition: E = "left",
|
|
41
42
|
...j
|
|
42
|
-
} = r, [d, b, L] =
|
|
43
|
+
} = r, [d, b, L] = ht(x.Children.toArray(g)), { hoverRef: M, isHovered: tt } = C === "button" ? $(n) : $(n), ot = bt(null), s = !!(d || b) && !L, T = d && (b || _) && !s, y = J === "ondark", h = ft() < gt.md, V = A === "destructive" && !i, rt = I === "outline", l = I === "borderless", W = It(I === "fill", l, i, A, y, h), v = _ === "icon" && !l, p = K === "large" && !V && !l, nt = _ === "accessibility-character" && !w && !d && !b && !v && l, et = { ...j }, D = m(
|
|
43
44
|
t["button-wrapper"],
|
|
44
45
|
{ [t["button-wrapper--fluid"]]: w || S },
|
|
45
46
|
q
|
|
46
|
-
),
|
|
47
|
+
), st = m(
|
|
47
48
|
t.button,
|
|
48
49
|
{
|
|
49
50
|
[t["button--destructive"]]: V,
|
|
50
51
|
[t["button--normal"]]: !p,
|
|
51
52
|
[t["button--large"]]: p,
|
|
52
|
-
[t["button--outline"]]:
|
|
53
|
-
[t["button--borderless"]]:
|
|
53
|
+
[t["button--outline"]]: rt,
|
|
54
|
+
[t["button--borderless"]]: l,
|
|
54
55
|
[t["button--left-icon"]]: d && !s,
|
|
55
56
|
[t["button--right-icon"]]: b && !s,
|
|
56
57
|
[t["button--both-icons"]]: T,
|
|
@@ -59,35 +60,39 @@ const It = (o, r, n, f, e, g) => g && n ? !e || o ? u("neutral", r ? 500 : 700)
|
|
|
59
60
|
[t["button--on-dark"]]: y
|
|
60
61
|
},
|
|
61
62
|
G
|
|
62
|
-
),
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
), at = m(
|
|
64
|
+
t.button__text,
|
|
65
|
+
{
|
|
66
|
+
[t["button__text--ellipsis"]]: S,
|
|
67
|
+
[t["button__text--centered"]]: w && E === "centered"
|
|
68
|
+
},
|
|
69
|
+
Z
|
|
70
|
+
), it = m(t.diagonal, {
|
|
66
71
|
[t["diagonal--on-dark"]]: y
|
|
67
72
|
});
|
|
68
|
-
|
|
69
|
-
|
|
73
|
+
pt(() => {
|
|
74
|
+
yt(s, f, !_t() && !wt());
|
|
70
75
|
}, []);
|
|
71
|
-
const
|
|
76
|
+
const N = (c, ct, ut) => c ? x.cloneElement(c, {
|
|
72
77
|
size: ct,
|
|
73
|
-
color:
|
|
74
|
-
isHovered: !i &&
|
|
75
|
-
className:
|
|
76
|
-
}) : null,
|
|
77
|
-
i &&
|
|
78
|
+
color: c != null && c.props.color && !i ? c.props.color : W,
|
|
79
|
+
isHovered: !i && tt,
|
|
80
|
+
className: ut
|
|
81
|
+
}) : null, lt = () => /* @__PURE__ */ k("span", { className: at, ref: ot, children: [
|
|
82
|
+
i && l && /* @__PURE__ */ a("span", { className: it, children: /* @__PURE__ */ a("span", { className: t.diagonal__line }) }),
|
|
78
83
|
/* @__PURE__ */ a("span", { children: s ? f : L })
|
|
79
|
-
] }), O = () => /* @__PURE__ */
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
v ?
|
|
83
|
-
/* @__PURE__ */ a(
|
|
84
|
+
] }), O = () => /* @__PURE__ */ k("span", { className: st, children: [
|
|
85
|
+
N(d, R(p, h), s ? void 0 : t["button__left-icon"]),
|
|
86
|
+
lt(),
|
|
87
|
+
v ? N(
|
|
88
|
+
/* @__PURE__ */ a(mt, { svgIcon: Ct }),
|
|
84
89
|
R(p, h),
|
|
85
90
|
m(t.button__arrow, { [t["button__arrow--both-icons"]]: T })
|
|
86
|
-
) :
|
|
87
|
-
|
|
91
|
+
) : N(b, R(p, h), t["button__right-icon"]),
|
|
92
|
+
nt && /* @__PURE__ */ a("span", { style: { color: W }, className: t["button__right-unicode-arrow"], "aria-hidden": !0, children: " →" })
|
|
88
93
|
] });
|
|
89
|
-
return /* @__PURE__ */
|
|
90
|
-
|
|
94
|
+
return /* @__PURE__ */ k(dt, { children: [
|
|
95
|
+
C === "button" && /* @__PURE__ */ a(
|
|
91
96
|
"button",
|
|
92
97
|
{
|
|
93
98
|
id: e,
|
|
@@ -100,11 +105,11 @@ const It = (o, r, n, f, e, g) => g && n ? !e || o ? u("neutral", r ? 500 : 700)
|
|
|
100
105
|
ref: M,
|
|
101
106
|
tabIndex: F,
|
|
102
107
|
type: Y,
|
|
103
|
-
...
|
|
108
|
+
...et,
|
|
104
109
|
children: O()
|
|
105
110
|
}
|
|
106
111
|
),
|
|
107
|
-
|
|
112
|
+
C === "a" && /* @__PURE__ */ a(
|
|
108
113
|
"a",
|
|
109
114
|
{
|
|
110
115
|
id: e,
|
|
@@ -125,6 +130,6 @@ const It = (o, r, n, f, e, g) => g && n ? !e || o ? u("neutral", r ? 500 : 700)
|
|
|
125
130
|
] });
|
|
126
131
|
});
|
|
127
132
|
export {
|
|
128
|
-
|
|
133
|
+
Lt as B
|
|
129
134
|
};
|
|
130
135
|
//# sourceMappingURL=Button.js.map
|
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 ButtonOnColor = 'onlight' | 'ondark';\nexport type ButtonTags = 'button' | 'a';\nexport type ButtonArrows = 'icon' | 'accessibility-character';\nexport type ButtonTextPosition = 'left' | 'centered';\n\nexport interface ButtonProps extends HTMLButtonProps, HTMLAnchorProps, AriaAttributes {\n /** Sets the aria-label of the button, use when the button only includes an icon */\n ariaLabel?: string;\n /** Gives a unique id to the button */\n id?: string;\n /** Sets the content of the button. */\n children: React.ReactNode;\n /** Adds custom classes to the wrapper element. */\n wrapperClassName?: string;\n /** Adds custom classes to the element. */\n className?: string;\n /** Enables an arrow icon to the right inside the button (Not available in borderless variant) */\n arrow?: ButtonArrows;\n /** Changes the intent of the button. Mostly changes the color profile. */\n concept?: ButtonConcept;\n /** Disables text wrapping and enables ellipsis. */\n ellipsis?: boolean;\n /** Makes the button scale to full width of its parent element. */\n fluid?: boolean;\n /** Changes the underlying element of the button. */\n htmlMarkup?: ButtonTags;\n /** Changes the button colors for different backgrounds. */\n onColor?: ButtonOnColor;\n /** Function that is called when the Button loses focus */\n onBlur?: () => void;\n /** Function that is called when clicked */\n onClick?: (e?: React.MouseEvent<HTMLElement, MouseEvent> | React.FormEvent<{}> | React.KeyboardEvent<HTMLUListElement> | null) => void;\n /** Changes the button colors for different backgrounds. (Large not available in borderless variant) */\n size?: ButtonSize;\n /** Changes the visual representation of the button. */\n variant?: ButtonVariant;\n /** Specifies the focus order relative to the other buttons or controls on the page */\n tabIndex?: number;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Sets the position of the text in the button - only applies when button is fluid */\n textPosition?: ButtonTextPosition;\n /** Button type. Default: button */\n type?: React.ButtonHTMLAttributes<HTMLButtonElement>['type'];\n}\n\nconst getIconColor = (\n fill: boolean,\n borderless: boolean,\n disabled: boolean,\n concept: ButtonConcept,\n ondark: boolean,\n mobile: boolean\n): string => {\n if (mobile && disabled) {\n return !ondark || fill ? getColor('neutral', !borderless ? 700 : 500) : getColor('white');\n }\n if (disabled) {\n return !ondark || fill ? getColor('neutral', 500) : `${getColor('white')}b3`;\n }\n if ((fill && !ondark) || (!fill && ondark)) {\n return 'white';\n }\n\n return concept === 'normal' ? getColor('blueberry', 600) : getColor('cherry', 500);\n};\nconst getLargeIconSize = (large: boolean, mobile: boolean): IconSize => {\n if (mobile && large) return IconSize.Small;\n if (large) return IconSize.Medium;\n return IconSize.XSmall;\n};\n\nconst checkOnlyIconAria = (onlyIcon: boolean, ariaLabel: string | undefined, devEnv: boolean): void => {\n if (devEnv && onlyIcon && (ariaLabel === undefined || ariaLabel === '')) {\n throw new Error('Fyll inn ariaLabel prop på Button uten tekst for å opprettholde UU krav');\n }\n};\n\nconst Button = React.forwardRef(function ButtonForwardedRef(\n props: ButtonProps,\n ref: React.ForwardedRef<HTMLButtonElement | HTMLAnchorElement>\n) {\n const {\n ariaLabel,\n id,\n children,\n wrapperClassName,\n className,\n arrow,\n concept = 'normal',\n disabled = false,\n ellipsis = false,\n fluid = false,\n htmlMarkup = 'button',\n onColor = 'onlight',\n onBlur,\n onClick,\n size = 'medium',\n variant = 'fill',\n href,\n tabIndex,\n testId,\n target,\n type = 'button',\n textPosition = 'left',\n ...restProps\n } = props;\n\n const [leftIcon, rightIcon, restChildren] = useIcons(React.Children.toArray(children));\n const { hoverRef, isHovered } =\n htmlMarkup === 'button'\n ? useHover<HTMLButtonElement>(ref as React.RefObject<HTMLButtonElement>)\n : useHover<HTMLAnchorElement>(ref as React.RefObject<HTMLAnchorElement>);\n const buttonContentRef = useRef<HTMLDivElement>(null);\n const onlyIcon = !!(leftIcon || rightIcon) && !restChildren;\n const bothIcons = leftIcon && (rightIcon || arrow) && !onlyIcon;\n const onDark = onColor === 'ondark';\n const breakpoint = useBreakpoint();\n const mobile = breakpoint < breakpoints.md;\n const destructive = concept === 'destructive' && !disabled;\n const outlineVariant = variant === 'outline';\n const borderlessVariant = variant === 'borderless';\n const iconColor = getIconColor(variant === 'fill', borderlessVariant, disabled, concept, onDark, mobile);\n const hasArrow = arrow === 'icon' && !borderlessVariant;\n const large = size === 'large' && !destructive && !borderlessVariant;\n const hasUURightArrow = arrow === 'accessibility-character' && !fluid && !leftIcon && !rightIcon && !hasArrow && borderlessVariant;\n const rest = { ...restProps };\n\n const buttonWrapperClasses = classNames(\n buttonStyles['button-wrapper'],\n { [buttonStyles['button-wrapper--fluid']]: fluid || ellipsis },\n wrapperClassName\n );\n const buttonClasses = classNames(\n buttonStyles.button,\n {\n [buttonStyles['button--destructive']]: destructive,\n [buttonStyles['button--normal']]: !large,\n [buttonStyles['button--large']]: large,\n [buttonStyles['button--outline']]: outlineVariant,\n [buttonStyles['button--borderless']]: borderlessVariant,\n [buttonStyles['button--left-icon']]: leftIcon && !onlyIcon,\n [buttonStyles['button--right-icon']]: rightIcon && !onlyIcon,\n [buttonStyles['button--both-icons']]: bothIcons,\n [buttonStyles['button--only-icon']]: onlyIcon,\n [buttonStyles['button--arrow']]: hasArrow,\n [buttonStyles['button--on-dark']]: onDark,\n },\n className\n );\n const buttonTextClasses = classNames(buttonStyles['button__text'], {\n [buttonStyles['button__text--ellipsis']]: ellipsis,\n [buttonStyles['button__text--centered']]: fluid && textPosition === 'centered',\n });\n const diagonalClasses = classNames(buttonStyles['diagonal'], {\n [buttonStyles['diagonal--on-dark']]: onDark,\n });\n\n useEffect(() => {\n checkOnlyIconAria(onlyIcon, ariaLabel, !isTest() && !isProd());\n }, []);\n\n const renderIcon = (iconElement: BaseIconElement | null, iconSize: number, iconClassName?: string): BaseIconElement | null => {\n return iconElement\n ? React.cloneElement(iconElement, {\n size: iconSize,\n color: iconElement?.props.color && !disabled ? iconElement.props.color : iconColor,\n isHovered: !disabled && isHovered,\n className: iconClassName,\n })\n : null;\n };\n\n const renderButtonContent = (): JSX.Element => {\n return (\n <span className={buttonTextClasses} ref={buttonContentRef}>\n {disabled && borderlessVariant && (\n <span className={diagonalClasses}>\n <span className={buttonStyles['diagonal__line']} />\n </span>\n )}\n <span>{onlyIcon ? ariaLabel : restChildren}</span>\n </span>\n );\n };\n\n const renderbuttonContentWrapper = (): JSX.Element => (\n <span className={buttonClasses}>\n {renderIcon(leftIcon, getLargeIconSize(large, mobile), !onlyIcon ? buttonStyles['button__left-icon'] : undefined)}\n {renderButtonContent()}\n {hasArrow\n ? renderIcon(\n <Icon svgIcon={ArrowRight} />,\n getLargeIconSize(large, mobile),\n classNames(buttonStyles['button__arrow'], { [buttonStyles['button__arrow--both-icons']]: bothIcons })\n )\n : renderIcon(rightIcon, getLargeIconSize(large, mobile), buttonStyles['button__right-icon'])}\n {hasUURightArrow && (\n <span style={{ color: iconColor }} className={buttonStyles['button__right-unicode-arrow']} aria-hidden>\n {' →'}\n </span>\n )}\n </span>\n );\n\n return (\n <>\n {htmlMarkup === 'button' && (\n <button\n id={id}\n onBlur={onBlur}\n onClick={onClick}\n disabled={disabled}\n data-testid={testId}\n data-analyticsid={AnalyticsId.Button}\n className={buttonWrapperClasses}\n ref={hoverRef as React.ForwardedRef<HTMLButtonElement>}\n tabIndex={tabIndex}\n type={type}\n {...rest}\n >\n {renderbuttonContentWrapper()}\n </button>\n )}\n {htmlMarkup === 'a' && (\n <a\n id={id}\n onBlur={onBlur}\n onClick={onClick}\n data-testid={testId}\n data-analyticsid={AnalyticsId.Button}\n className={buttonWrapperClasses}\n href={href}\n target={target}\n rel={target === '_blank' ? 'noopener noreferrer' : props.rel}\n ref={hoverRef as React.ForwardedRef<HTMLAnchorElement>}\n tabIndex={tabIndex}\n {...restProps}\n >\n {renderbuttonContentWrapper()}\n </a>\n )}\n </>\n );\n});\n\nexport default Button;\n"],"names":["getIconColor","fill","borderless","disabled","concept","ondark","mobile","getColor","getLargeIconSize","large","IconSize","checkOnlyIconAria","onlyIcon","ariaLabel","devEnv","Button","React","props","ref","id","children","wrapperClassName","className","arrow","ellipsis","fluid","htmlMarkup","onColor","onBlur","onClick","size","variant","href","tabIndex","testId","target","type","textPosition","restProps","leftIcon","rightIcon","restChildren","useIcons","hoverRef","isHovered","useHover","buttonContentRef","useRef","bothIcons","onDark","useBreakpoint","breakpoints","destructive","outlineVariant","borderlessVariant","iconColor","hasArrow","hasUURightArrow","rest","buttonWrapperClasses","classNames","buttonStyles","buttonClasses","buttonTextClasses","diagonalClasses","useEffect","isTest","isProd","renderIcon","iconElement","iconSize","iconClassName","renderButtonContent","jsxs","jsx","renderbuttonContentWrapper","Icon","ArrowRight","Fragment","AnalyticsId"],"mappings":";;;;;;;;;;;;;AAiEA,MAAMA,KAAe,CACnBC,GACAC,GACAC,GACAC,GACAC,GACAC,MAEIA,KAAUH,IACL,CAACE,KAAUJ,IAAOM,EAAS,WAAYL,IAAmB,MAAN,GAAS,IAAIK,EAAS,OAAO,IAEtFJ,IACK,CAACE,KAAUJ,IAAOM,EAAS,WAAW,GAAG,IAAI,GAAGA,EAAS,OAAO,CAAC,OAErEN,KAAQ,CAACI,KAAY,CAACJ,KAAQI,IAC1B,UAGFD,MAAY,WAAWG,EAAS,aAAa,GAAG,IAAIA,EAAS,UAAU,GAAG,GAE7EC,IAAmB,CAACC,GAAgBH,MACpCA,KAAUG,IAAcC,EAAS,QACjCD,IAAcC,EAAS,SACpBA,EAAS,QAGZC,KAAoB,CAACC,GAAmBC,GAA+BC,MAA0B;AACrG,MAAIA,KAAUF,MAAaC,MAAc,UAAaA,MAAc;AAC5D,UAAA,IAAI,MAAM,yEAAyE;AAE7F,GAEME,KAASC,EAAM,WAAW,SAC9BC,GACAC,GACA;AACM,QAAA;AAAA,IACJ,WAAAL;AAAA,IACA,IAAAM;AAAA,IACA,UAAAC;AAAA,IACA,kBAAAC;AAAA,IACA,WAAAC;AAAA,IACA,OAAAC;AAAA,IACA,SAAAnB,IAAU;AAAA,IACV,UAAAD,IAAW;AAAA,IACX,UAAAqB,IAAW;AAAA,IACX,OAAAC,IAAQ;AAAA,IACR,YAAAC,IAAa;AAAA,IACb,SAAAC,IAAU;AAAA,IACV,QAAAC;AAAA,IACA,SAAAC;AAAA,IACA,MAAAC,IAAO;AAAA,IACP,SAAAC,IAAU;AAAA,IACV,MAAAC;AAAA,IACA,UAAAC;AAAA,IACA,QAAAC;AAAA,IACA,QAAAC;AAAA,IACA,MAAAC,IAAO;AAAA,IACP,cAAAC,IAAe;AA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ACA,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 /** Adds custom classes to the text */\n textClassName?: 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 textClassName,\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(\n buttonStyles['button__text'],\n {\n [buttonStyles['button__text--ellipsis']]: ellipsis,\n [buttonStyles['button__text--centered']]: fluid && textPosition === 'centered',\n },\n textClassName\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","textClassName","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":";;;;;;;;;;;;;AAmEA,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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0&targetVersion=GTv9.0.0) (2024-11-05)
|
|
2
|
+
|
|
3
|
+
## 9.0.0-beta.3 (2024-10-29)
|
|
4
|
+
|
|
5
|
+
## 9.0.0-beta.2 (2024-10-29)
|
|
6
|
+
|
|
7
|
+
## 9.0.0-beta.1 (2024-10-25)
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
- legg til invalidFormatErrorMessage som parameter i valideringsfunksjoner
|
|
12
|
+
([2270650](https://github.com/helsenorge/designsystem/commit/22706507750a5968d9998b5430430b8de3b75683)), closes
|
|
13
|
+
[#333981](https://github.com/helsenorge/designsystem/issues/333981)
|
|
14
|
+
- **slider:** legger til validering, og ref og endre signatur til onchange
|
|
15
|
+
([5d5148a](https://github.com/helsenorge/designsystem/commit/5d5148ae5833c463f4bb7069ee704bc44d44d30f)), closes
|
|
16
|
+
[#329653](https://github.com/helsenorge/designsystem/issues/329653)
|
|
17
|
+
|
|
18
|
+
## 9.0.0-beta.0 (2024-10-17)
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
- endre fra mode til oncolor ([3491c74](https://github.com/helsenorge/designsystem/commit/3491c7438b743e4e05d78ddd130a5f3797b5b55a)), closes
|
|
23
|
+
[#331833](https://github.com/helsenorge/designsystem/issues/331833)
|
|
24
|
+
- validate gir skjema komponenter spacing
|
|
25
|
+
([c984428](https://github.com/helsenorge/designsystem/commit/c98442817d8f4a799e7c1d6a473dd215148ca7cd)), closes
|
|
26
|
+
[#331167](https://github.com/helsenorge/designsystem/issues/331167)
|
|
27
|
+
- **expanderlist:** fjern sticky mulighet
|
|
28
|
+
([c0b7df9](https://github.com/helsenorge/designsystem/commit/c0b7df9eeb186f74de16b9e7d7f11601e0e5794b)), closes
|
|
29
|
+
[#332677](https://github.com/helsenorge/designsystem/issues/332677)
|
|
30
|
+
- **expanderlist:** nytt design ([eb4d0f3](https://github.com/helsenorge/designsystem/commit/eb4d0f36d53401764033678dd571a10b481227e4)),
|
|
31
|
+
closes [#332677](https://github.com/helsenorge/designsystem/issues/332677)
|
|
32
|
+
- **sharingstatus:** fjern fargevalg blueberry og banana
|
|
33
|
+
([26db632](https://github.com/helsenorge/designsystem/commit/26db6326baeae2f7868d34b5a085c76a022e9345)), closes
|
|
34
|
+
[#328894](https://github.com/helsenorge/designsystem/issues/328894)
|
|
35
|
+
- **tabs:** designendringer for mobiltilpasning
|
|
36
|
+
([8ba1309](https://github.com/helsenorge/designsystem/commit/8ba13094a038b3077c07c870e1cb46ace0597f85)), closes
|
|
37
|
+
[#331142](https://github.com/helsenorge/designsystem/issues/331142)
|
|
38
|
+
|
|
39
|
+
### Bug Fixes
|
|
40
|
+
|
|
41
|
+
- ikke vis fadeout om siste tab er valgt
|
|
42
|
+
([f0fe5a9](https://github.com/helsenorge/designsystem/commit/f0fe5a9ee1d928a0ae093bbed0909c3bce951498)), closes
|
|
43
|
+
[#331142](https://github.com/helsenorge/designsystem/issues/331142)
|
|
44
|
+
- **dropdown:** import av feil oncolor
|
|
45
|
+
([f305cae](https://github.com/helsenorge/designsystem/commit/f305caea3c7cdcf4d312bc0f3b6af1d839a0aaca)), closes
|
|
46
|
+
[#331833](https://github.com/helsenorge/designsystem/issues/331833)
|
|
47
|
+
|
|
1
48
|
## [8.8.0](https://github.com/helsenorge/designsystem/branchCompare?baseVersion=GTv8.7.0&targetVersion=GTv8.8.0) (2024-11-04)
|
|
2
49
|
|
|
3
50
|
### Features
|
|
@@ -1815,12 +1862,12 @@ Dette er fordi vi skal kunne dynamisk importere alt som ligger i Icons, så da b
|
|
|
1815
1862
|
|
|
1816
1863
|
### Bug Fixes
|
|
1817
1864
|
|
|
1818
|
-
- økt kontrast på understreking av lenker
|
|
1819
|
-
([50b7fa4](https://github.com/helsenorge/designsystem/commit/50b7fa47fb44cb7d75fb877bd53e2309b35e1e21)), closes
|
|
1820
|
-
[#229049](https://github.com/helsenorge/designsystem/issues/229049)
|
|
1821
1865
|
- panel har avstand fra tittel til badge
|
|
1822
1866
|
([09034c4](https://github.com/helsenorge/designsystem/commit/09034c4844408c7cfe8f65d7a1a0d82a7828c2ef)), closes
|
|
1823
1867
|
[#282359](https://github.com/helsenorge/designsystem/issues/282359)
|
|
1868
|
+
- økt kontrast på understreking av lenker
|
|
1869
|
+
([50b7fa4](https://github.com/helsenorge/designsystem/commit/50b7fa47fb44cb7d75fb877bd53e2309b35e1e21)), closes
|
|
1870
|
+
[#229049](https://github.com/helsenorge/designsystem/issues/229049)
|
|
1824
1871
|
|
|
1825
1872
|
## [1.2.2](https://github.com/helsenorge/designsystem/branchCompare?baseVersion=GTv1.2.1&targetVersion=GTv1.2.2) (2022-08-31)
|
|
1826
1873
|
|
package/Expander.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { jsxs as m, jsx as t } from "react/jsx-runtime";
|
|
2
2
|
import { useRef as C } from "react";
|
|
3
|
-
import
|
|
4
|
-
import { ZIndex as O, AnalyticsId as
|
|
3
|
+
import d from "classnames";
|
|
4
|
+
import { ZIndex as O, AnalyticsId as b, IconSize as c } from "./constants.js";
|
|
5
5
|
import { useExpand as U } from "./hooks/useExpand.js";
|
|
6
6
|
import { useHover as Z } from "./hooks/useHover.js";
|
|
7
7
|
import { useSticky as q } from "./hooks/useSticky.js";
|
|
8
8
|
import { B as F } from "./Button.js";
|
|
9
9
|
import { I as x } from "./Icon.js";
|
|
10
|
-
import
|
|
11
|
-
import
|
|
10
|
+
import z from "./components/Icons/ChevronDown.js";
|
|
11
|
+
import E from "./components/Icons/ChevronUp.js";
|
|
12
12
|
import { L as G } from "./LazyIcon.js";
|
|
13
13
|
import e from "./components/Expander/styles.module.scss";
|
|
14
14
|
var J = /* @__PURE__ */ ((s) => (s.small = "small", s.large = "large", s))(J || {});
|
|
15
|
-
const
|
|
15
|
+
const de = (s) => {
|
|
16
16
|
const {
|
|
17
|
-
title:
|
|
17
|
+
title: _,
|
|
18
18
|
children: k,
|
|
19
19
|
size: n = "small",
|
|
20
|
-
color:
|
|
20
|
+
color: g,
|
|
21
21
|
contentClassNames: $,
|
|
22
22
|
svgIcon: a,
|
|
23
23
|
expanded: S = !1,
|
|
@@ -27,10 +27,10 @@ const ie = (s) => {
|
|
|
27
27
|
onExpand: W,
|
|
28
28
|
renderChildrenWhenClosed: X = !1,
|
|
29
29
|
zIndex: B = O.ExpanderTrigger
|
|
30
|
-
} = s, [r, u] = U(S, W), v = C(null),
|
|
30
|
+
} = s, [r, u] = U(S, W), v = C(null), i = C(null), { isHovered: l } = Z(i), { isOutsideWindow: H, isLeavingWindow: h, offsetHeight: y, contentWidth: I } = q(v, i), o = L && r && H, N = (p) => /* @__PURE__ */ t("span", { className: d(e.expander__icon, e[`expander__icon--${p}`]), children: /* @__PURE__ */ t(x, { svgIcon: r ? E : z, size: c.XSmall, isHovered: l }) }), R = d(
|
|
31
31
|
e.expander__trigger,
|
|
32
32
|
n === "large" && e[`expander__trigger--${n}`],
|
|
33
|
-
n === "large" && e[`expander__trigger--${
|
|
33
|
+
n === "large" && e[`expander__trigger--${g || "neutral"}`],
|
|
34
34
|
n === "large" && a && e["expander__trigger--icon"],
|
|
35
35
|
r && e["expander__trigger--expanded"],
|
|
36
36
|
o && !h && e["expander__trigger--sticky"]
|
|
@@ -44,18 +44,18 @@ const ie = (s) => {
|
|
|
44
44
|
width: o && I ? `${I}px` : void 0
|
|
45
45
|
},
|
|
46
46
|
"aria-expanded": r,
|
|
47
|
-
ref:
|
|
47
|
+
ref: i,
|
|
48
48
|
onClick: () => u(!r),
|
|
49
49
|
"data-testid": f,
|
|
50
|
-
"data-analyticsid":
|
|
50
|
+
"data-analyticsid": b.Expander,
|
|
51
51
|
children: [
|
|
52
52
|
n === "small" && N("left"),
|
|
53
|
-
a && /* @__PURE__ */ t("span", { className:
|
|
54
|
-
|
|
53
|
+
a && /* @__PURE__ */ t("span", { className: d(e.expander__icon, e["expander__icon--left"]), children: typeof a == "string" ? /* @__PURE__ */ t(G, { iconName: a, size: c.XSmall, isHovered: l }) : /* @__PURE__ */ t(x, { svgIcon: a, size: c.XSmall, isHovered: l }) }),
|
|
54
|
+
_,
|
|
55
55
|
n === "large" && N("right")
|
|
56
56
|
]
|
|
57
57
|
}
|
|
58
|
-
), j =
|
|
58
|
+
), j = d(
|
|
59
59
|
e.expander__button,
|
|
60
60
|
r && e["expander__button--expanded"],
|
|
61
61
|
o && !h && e["expander__button--sticky"]
|
|
@@ -63,24 +63,25 @@ const ie = (s) => {
|
|
|
63
63
|
F,
|
|
64
64
|
{
|
|
65
65
|
variant: "borderless",
|
|
66
|
+
textClassName: e.expander__button__text,
|
|
66
67
|
className: j,
|
|
67
68
|
"aria-expanded": r,
|
|
68
|
-
ref:
|
|
69
|
+
ref: i,
|
|
69
70
|
onClick: () => u(!r),
|
|
70
71
|
testId: f,
|
|
71
|
-
"data-analyticsid":
|
|
72
|
+
"data-analyticsid": b.Expander,
|
|
72
73
|
children: [
|
|
73
|
-
/* @__PURE__ */ t(x, { svgIcon: r ?
|
|
74
|
-
|
|
74
|
+
/* @__PURE__ */ t(x, { svgIcon: r ? E : z, size: c.XSmall }),
|
|
75
|
+
_
|
|
75
76
|
]
|
|
76
77
|
}
|
|
77
78
|
), D = () => {
|
|
78
79
|
if (!X && !r)
|
|
79
80
|
return null;
|
|
80
|
-
const p =
|
|
81
|
+
const p = d(
|
|
81
82
|
e.expander__content,
|
|
82
83
|
e[`expander__content--${n}`],
|
|
83
|
-
n === "large" && e[`expander__content--${
|
|
84
|
+
n === "large" && e[`expander__content--${g || "neutral"}`],
|
|
84
85
|
n === "large" && a && e["expander__content--icon"],
|
|
85
86
|
r && e["expander__content--expanded"],
|
|
86
87
|
n === "small" && !w && e["expander__content--nested-line"],
|
|
@@ -102,7 +103,7 @@ const ie = (s) => {
|
|
|
102
103
|
);
|
|
103
104
|
};
|
|
104
105
|
export {
|
|
105
|
-
|
|
106
|
+
de as E,
|
|
106
107
|
J as a
|
|
107
108
|
};
|
|
108
109
|
//# sourceMappingURL=Expander.js.map
|
package/Expander.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Expander.js","sources":["../src/components/Expander/Expander.tsx"],"sourcesContent":["import React, { useRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport { AnalyticsId, ZIndex } from '../../constants';\nimport { useExpand } from '../../hooks/useExpand';\nimport { useHover } from '../../hooks/useHover';\nimport { useSticky } from '../../hooks/useSticky';\nimport { PaletteNames } from '../../theme/palette';\nimport Button from '../Button';\nimport Icon, { IconSize, SvgIcon } from '../Icon';\nimport ChevronDown from '../Icons/ChevronDown';\nimport ChevronUp from '../Icons/ChevronUp';\nimport { IconName } from '../Icons/IconNames';\nimport LazyIcon from '../LazyIcon';\n\nimport styles from './styles.module.scss';\n\nexport enum ExpanderSize {\n small = 'small',\n large = 'large',\n}\n\nexport type ExpanderColors = Extract<PaletteNames, 'banana' | 'blueberry' | 'cherry' | 'kiwi' | 'neutral' | 'plum' | 'white'>;\n\nexport interface ExpanderProps {\n /** Sets the trigger title */\n title: string;\n /** Sets the expanded content */\n children?: React.ReactNode;\n /** Sets classnames on the content area */\n contentClassNames?: string;\n /** Sets the size of the expander. Default: ExpanderSize.small */\n size?: ExpanderSize;\n /** Sets the background of the expander. Requires size=ExpanderSize.large. */\n color?: ExpanderColors;\n /** Adds an icon to the expander trigger. Requires size=ExpanderSize.large. */\n svgIcon?: SvgIcon | IconName;\n /** Opens or closes the expander */\n expanded?: boolean;\n /** Removes border to the left of the content. Requires size=ExpanderSize.small. */\n noNestedLine?: boolean;\n /** Stick expander trigger to top of screen while scrolling down */\n sticky?: boolean;\n /** Called when expander is open/closed. */\n onExpand?: (isExpanded: boolean) => void;\n /** Whether to render children when closed (in which case they are hidden with CSS). Default: false */\n renderChildrenWhenClosed?: boolean;\n /** Sets the data-testid attribute on the expander button. */\n testId?: string;\n /** Overrides the default z-index of the expander header */\n zIndex?: number;\n}\n\nconst Expander: React.FC<ExpanderProps> = props => {\n const {\n title,\n children,\n size = ExpanderSize.small,\n color,\n contentClassNames,\n svgIcon: icon,\n expanded = false,\n noNestedLine = false,\n sticky = false,\n testId,\n onExpand,\n renderChildrenWhenClosed = false,\n zIndex = ZIndex.ExpanderTrigger,\n } = props;\n const [isExpanded, setIsExpanded] = useExpand(expanded, onExpand);\n const expanderRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLButtonElement>(null);\n const { isHovered } = useHover(triggerRef);\n const { isOutsideWindow, isLeavingWindow, offsetHeight, contentWidth } = useSticky(expanderRef, triggerRef);\n\n const isSticky = sticky && isExpanded && isOutsideWindow;\n\n const renderChevron = (align: 'left' | 'right'): React.ReactNode => (\n <span className={classNames(styles['expander__icon'], styles[`expander__icon--${align}`])}>\n <Icon svgIcon={isExpanded ? ChevronUp : ChevronDown} size={IconSize.XSmall} isHovered={isHovered} />\n </span>\n );\n\n const triggerClassName = classNames(\n styles['expander__trigger'],\n size === ExpanderSize.large && styles[`expander__trigger--${size}`],\n size === ExpanderSize.large && styles[`expander__trigger--${color || 'neutral'}`],\n size === ExpanderSize.large && icon && styles['expander__trigger--icon'],\n isExpanded && styles['expander__trigger--expanded'],\n isSticky && !isLeavingWindow && styles['expander__trigger--sticky']\n );\n\n const renderTrigger = (): React.ReactNode => (\n <button\n type=\"button\"\n className={triggerClassName}\n style={{\n zIndex: isHovered || isSticky ? zIndex : undefined,\n width: isSticky && contentWidth ? `${contentWidth}px` : undefined,\n }}\n aria-expanded={isExpanded}\n ref={triggerRef}\n onClick={(): void => setIsExpanded(!isExpanded)}\n data-testid={testId}\n data-analyticsid={AnalyticsId.Expander}\n >\n {size === ExpanderSize.small && renderChevron('left')}\n {icon && (\n <span className={classNames(styles['expander__icon'], styles['expander__icon--left'])}>\n {typeof icon === 'string' ? (\n <LazyIcon iconName={icon} size={IconSize.XSmall} isHovered={isHovered} />\n ) : (\n <Icon svgIcon={icon} size={IconSize.XSmall} isHovered={isHovered} />\n )}\n </span>\n )}\n {title}\n {size === ExpanderSize.large && renderChevron('right')}\n </button>\n );\n\n const buttonClassName = classNames(\n styles['expander__button'],\n isExpanded && styles['expander__button--expanded'],\n isSticky && !isLeavingWindow && styles['expander__button--sticky']\n );\n\n const renderButton = (): React.ReactNode => (\n <Button\n variant=\"borderless\"\n className={buttonClassName}\n aria-expanded={isExpanded}\n ref={triggerRef}\n onClick={(): void => setIsExpanded(!isExpanded)}\n testId={testId}\n data-analyticsid={AnalyticsId.Expander}\n >\n <Icon svgIcon={isExpanded ? ChevronUp : ChevronDown} size={IconSize.XSmall} />\n {title}\n </Button>\n );\n\n const renderContent = (): React.ReactNode => {\n if (!renderChildrenWhenClosed && !isExpanded) {\n return null;\n }\n\n const contentClassName = classNames(\n styles['expander__content'],\n styles[`expander__content--${size}`],\n size === ExpanderSize.large && styles[`expander__content--${color || 'neutral'}`],\n size === ExpanderSize.large && icon && styles['expander__content--icon'],\n isExpanded && styles['expander__content--expanded'],\n size === ExpanderSize.small && !noNestedLine && styles['expander__content--nested-line'],\n contentClassNames\n );\n\n return <div className={contentClassName}>{children}</div>;\n };\n\n return (\n <div\n className={styles['expander']}\n ref={expanderRef}\n style={{ paddingTop: isSticky && offsetHeight ? `${offsetHeight}px` : undefined }}\n >\n {size === ExpanderSize.large ? renderTrigger() : renderButton()}\n {renderContent()}\n </div>\n );\n};\n\nexport default Expander;\n"],"names":["ExpanderSize","Expander","props","title","children","size","color","contentClassNames","icon","expanded","noNestedLine","sticky","testId","onExpand","renderChildrenWhenClosed","zIndex","ZIndex","isExpanded","setIsExpanded","useExpand","expanderRef","useRef","triggerRef","isHovered","useHover","isOutsideWindow","isLeavingWindow","offsetHeight","contentWidth","useSticky","isSticky","renderChevron","align","jsx","classNames","styles","Icon","ChevronUp","ChevronDown","IconSize","triggerClassName","renderTrigger","jsxs","AnalyticsId","LazyIcon","buttonClassName","renderButton","Button","renderContent","contentClassName"],"mappings":";;;;;;;;;;;;;AAkBY,IAAAA,sBAAAA,OACVA,EAAA,QAAQ,SACRA,EAAA,QAAQ,SAFEA,IAAA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,IAAC;AAAA,IAAA;AAAA,MACC,MAAK;AAAA,MACL,WAAWF;AAAA,MACX,OAAO;AAAA,QACL,QAAQjB,KAAaO,IAAWf,IAAS;AAAA,QACzC,OAAOe,KAAYF,IAAe,GAAGA,CAAY,OAAO;AAAA,MAC1D;AAAA,MACA,iBAAeX;AAAA,MACf,KAAKK;AAAA,MACL,SAAS,MAAYJ,EAAc,CAACD,CAAU;AAAA,MAC9C,eAAaL;AAAA,MACb,oBAAkB+B,EAAY;AAAA,MAE7B,UAAA;AAAA,QAAStC,MAAA,WAAsB0B,EAAc,MAAM;AAAA,QACnDvB,KACC,gBAAAyB,EAAC,QAAK,EAAA,WAAWC,EAAWC,EAAO,gBAAmBA,EAAO,sBAAsB,CAAC,GACjF,UAAA,OAAO3B,KAAS,WACf,gBAAAyB,EAACW,GAAS,EAAA,UAAUpC,GAAM,MAAM+B,EAAS,QAAQ,WAAAhB,GAAsB,IAEvE,gBAAAU,EAACG,GAAK,EAAA,SAAS5B,GAAM,MAAM+B,EAAS,QAAQ,WAAAhB,EAAsB,CAAA,GAEtE;AAAA,QAEDpB;AAAA,QACAE,MAAS,WAAsB0B,EAAc,OAAO;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA,GAInDc,IAAkBX;AAAA,IACtBC,EAAO;AAAA,IACPlB,KAAckB,EAAO,4BAA4B;AAAA,IACjDL,KAAY,CAACJ,KAAmBS,EAAO,0BAA0B;AAAA,EAAA,GAG7DW,IAAe,MACnB,gBAAAJ;AAAA,IAACK;AAAA,IAAA;AAAA,MACC,SAAQ;AAAA,MACR,
|
|
1
|
+
{"version":3,"file":"Expander.js","sources":["../src/components/Expander/Expander.tsx"],"sourcesContent":["import React, { useRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport { AnalyticsId, ZIndex } from '../../constants';\nimport { useExpand } from '../../hooks/useExpand';\nimport { useHover } from '../../hooks/useHover';\nimport { useSticky } from '../../hooks/useSticky';\nimport { PaletteNames } from '../../theme/palette';\nimport Button from '../Button';\nimport Icon, { IconSize, SvgIcon } from '../Icon';\nimport ChevronDown from '../Icons/ChevronDown';\nimport ChevronUp from '../Icons/ChevronUp';\nimport { IconName } from '../Icons/IconNames';\nimport LazyIcon from '../LazyIcon';\n\nimport styles from './styles.module.scss';\n\nexport enum ExpanderSize {\n small = 'small',\n large = 'large',\n}\n\nexport type ExpanderColors = Extract<PaletteNames, 'banana' | 'blueberry' | 'cherry' | 'kiwi' | 'neutral' | 'plum' | 'white'>;\n\nexport interface ExpanderProps {\n /** Sets the trigger title */\n title: string;\n /** Sets the expanded content */\n children?: React.ReactNode;\n /** Sets classnames on the content area */\n contentClassNames?: string;\n /** Sets the size of the expander. Default: ExpanderSize.small */\n size?: ExpanderSize;\n /** Sets the background of the expander. Requires size=ExpanderSize.large. */\n color?: ExpanderColors;\n /** Adds an icon to the expander trigger. Requires size=ExpanderSize.large. */\n svgIcon?: SvgIcon | IconName;\n /** Opens or closes the expander */\n expanded?: boolean;\n /** Removes border to the left of the content. Requires size=ExpanderSize.small. */\n noNestedLine?: boolean;\n /** Stick expander trigger to top of screen while scrolling down */\n sticky?: boolean;\n /** Called when expander is open/closed. */\n onExpand?: (isExpanded: boolean) => void;\n /** Whether to render children when closed (in which case they are hidden with CSS). Default: false */\n renderChildrenWhenClosed?: boolean;\n /** Sets the data-testid attribute on the expander button. */\n testId?: string;\n /** Overrides the default z-index of the expander header */\n zIndex?: number;\n}\n\nconst Expander: React.FC<ExpanderProps> = props => {\n const {\n title,\n children,\n size = ExpanderSize.small,\n color,\n contentClassNames,\n svgIcon: icon,\n expanded = false,\n noNestedLine = false,\n sticky = false,\n testId,\n onExpand,\n renderChildrenWhenClosed = false,\n zIndex = ZIndex.ExpanderTrigger,\n } = props;\n const [isExpanded, setIsExpanded] = useExpand(expanded, onExpand);\n const expanderRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLButtonElement>(null);\n const { isHovered } = useHover(triggerRef);\n const { isOutsideWindow, isLeavingWindow, offsetHeight, contentWidth } = useSticky(expanderRef, triggerRef);\n\n const isSticky = sticky && isExpanded && isOutsideWindow;\n\n const renderChevron = (align: 'left' | 'right'): React.ReactNode => (\n <span className={classNames(styles['expander__icon'], styles[`expander__icon--${align}`])}>\n <Icon svgIcon={isExpanded ? ChevronUp : ChevronDown} size={IconSize.XSmall} isHovered={isHovered} />\n </span>\n );\n\n const triggerClassName = classNames(\n styles['expander__trigger'],\n size === ExpanderSize.large && styles[`expander__trigger--${size}`],\n size === ExpanderSize.large && styles[`expander__trigger--${color || 'neutral'}`],\n size === ExpanderSize.large && icon && styles['expander__trigger--icon'],\n isExpanded && styles['expander__trigger--expanded'],\n isSticky && !isLeavingWindow && styles['expander__trigger--sticky']\n );\n\n const renderTrigger = (): React.ReactNode => (\n <button\n type=\"button\"\n className={triggerClassName}\n style={{\n zIndex: isHovered || isSticky ? zIndex : undefined,\n width: isSticky && contentWidth ? `${contentWidth}px` : undefined,\n }}\n aria-expanded={isExpanded}\n ref={triggerRef}\n onClick={(): void => setIsExpanded(!isExpanded)}\n data-testid={testId}\n data-analyticsid={AnalyticsId.Expander}\n >\n {size === ExpanderSize.small && renderChevron('left')}\n {icon && (\n <span className={classNames(styles['expander__icon'], styles['expander__icon--left'])}>\n {typeof icon === 'string' ? (\n <LazyIcon iconName={icon} size={IconSize.XSmall} isHovered={isHovered} />\n ) : (\n <Icon svgIcon={icon} size={IconSize.XSmall} isHovered={isHovered} />\n )}\n </span>\n )}\n {title}\n {size === ExpanderSize.large && renderChevron('right')}\n </button>\n );\n\n const buttonClassName = classNames(\n styles['expander__button'],\n isExpanded && styles['expander__button--expanded'],\n isSticky && !isLeavingWindow && styles['expander__button--sticky']\n );\n\n const renderButton = (): React.ReactNode => (\n <Button\n variant=\"borderless\"\n textClassName={styles['expander__button__text']}\n className={buttonClassName}\n aria-expanded={isExpanded}\n ref={triggerRef}\n onClick={(): void => setIsExpanded(!isExpanded)}\n testId={testId}\n data-analyticsid={AnalyticsId.Expander}\n >\n <Icon svgIcon={isExpanded ? ChevronUp : ChevronDown} size={IconSize.XSmall} />\n {title}\n </Button>\n );\n\n const renderContent = (): React.ReactNode => {\n if (!renderChildrenWhenClosed && !isExpanded) {\n return null;\n }\n\n const contentClassName = classNames(\n styles['expander__content'],\n styles[`expander__content--${size}`],\n size === ExpanderSize.large && styles[`expander__content--${color || 'neutral'}`],\n size === ExpanderSize.large && icon && styles['expander__content--icon'],\n isExpanded && styles['expander__content--expanded'],\n size === ExpanderSize.small && !noNestedLine && styles['expander__content--nested-line'],\n contentClassNames\n );\n\n return <div className={contentClassName}>{children}</div>;\n };\n\n return (\n <div\n className={styles['expander']}\n ref={expanderRef}\n style={{ paddingTop: isSticky && offsetHeight ? `${offsetHeight}px` : undefined }}\n >\n {size === ExpanderSize.large ? renderTrigger() : renderButton()}\n {renderContent()}\n </div>\n );\n};\n\nexport default Expander;\n"],"names":["ExpanderSize","Expander","props","title","children","size","color","contentClassNames","icon","expanded","noNestedLine","sticky","testId","onExpand","renderChildrenWhenClosed","zIndex","ZIndex","isExpanded","setIsExpanded","useExpand","expanderRef","useRef","triggerRef","isHovered","useHover","isOutsideWindow","isLeavingWindow","offsetHeight","contentWidth","useSticky","isSticky","renderChevron","align","jsx","classNames","styles","Icon","ChevronUp","ChevronDown","IconSize","triggerClassName","renderTrigger","jsxs","AnalyticsId","LazyIcon","buttonClassName","renderButton","Button","renderContent","contentClassName"],"mappings":";;;;;;;;;;;;;AAkBY,IAAAA,sBAAAA,OACVA,EAAA,QAAQ,SACRA,EAAA,QAAQ,SAFEA,IAAAA,KAAA,CAAA,CAAA;AAoCZ,MAAMC,KAAoC,CAASC,MAAA;AAC3C,QAAA;AAAA,IACJ,OAAAC;AAAA,IACA,UAAAC;AAAA,IACA,MAAAC,IAAO;AAAA,IACP,OAAAC;AAAA,IACA,mBAAAC;AAAA,IACA,SAASC;AAAA,IACT,UAAAC,IAAW;AAAA,IACX,cAAAC,IAAe;AAAA,IACf,QAAAC,IAAS;AAAA,IACT,Q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EAAE;AAAA,MAChFD,MAAS,WAAsBG,KAAQ2B,EAAO,yBAAyB;AAAA,MACvElB,KAAckB,EAAO,6BAA6B;AAAA,MAClD9B,MAAS,WAAsB,CAACK,KAAgByB,EAAO,gCAAgC;AAAA,MACvF5B;AAAA,IAAA;AAGF,WAAQ,gBAAA0B,EAAA,OAAA,EAAI,WAAWgB,GAAmB,UAAA7C,EAAS,CAAA;AAAA,EAAA;AAInD,SAAA,gBAAAsC;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAWP,EAAO;AAAA,MAClB,KAAKf;AAAA,MACL,OAAO,EAAE,YAAYU,KAAYH,IAAe,GAAGA,CAAY,OAAO,OAAU;AAAA,MAE/E,UAAA;AAAA,QAAStB,MAAA,UAAqBoC,EAAc,IAAIK,EAAa;AAAA,QAC7DE,EAAc;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGrB;"}
|
package/Slider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Slider.js","sources":["../src/components/Slider/Slider.tsx"],"sourcesContent":["import React, { useEffect, useState, useRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport { AnalyticsId } from '../../constants';\nimport { usePseudoClasses } from '../../hooks/usePseudoClasses';\nimport { useSize } from '../../hooks/useSize';\nimport { useUuid } from '../../hooks/useUuid';\nimport { getAriaLabelAttributes } from '../../utils/accessibility';\nimport { isMutableRefObject, mergeRefs } from '../../utils/refs';\nimport ErrorWrapper, { ErrorWrapperClassNameProps } from '../ErrorWrapper';\nimport Title from '../Title';\n\nimport styles from './styles.module.scss';\n\nconst useSafeNumberValue = (initial: number, min: number, max: number): [number, (value: number) => void] => {\n const [value, setValue] = useState(initial);\n\n const setSafeValue = (newValue: number): void => {\n if (newValue > max) {\n setValue(max);\n } else if (newValue < min) {\n setValue(min);\n } else {\n setValue(newValue);\n }\n };\n\n useEffect(() => {\n setSafeValue(initial);\n }, [min, max]);\n\n return [value, setSafeValue];\n};\n\nexport type SliderStep = {\n label?: number | string;\n emojiUniCode?: string;\n};\n\nexport interface SliderProps\n extends ErrorWrapperClassNameProps,\n Pick<React.InputHTMLAttributes<HTMLInputElement>, 'name' | 'onChange' | 'onBlur'> {\n /** Activates Error style for the input */\n error?: boolean;\n /** Error text to show above the component */\n errorText?: string;\n /** Error text id */\n errorTextId?: string;\n /**\tSets the title of the slider. */\n title?: string;\n /** Adds the left hand label to the element. */\n labelLeft?: string;\n /** Adds the right hand label to the element. */\n labelRight?: string;\n /**\tSets aria-label of the slider. */\n ariaLabel?: string;\n /** Disables the slider element. */\n disabled?: boolean;\n /** Sets the minimum allowed value on the slider - this overrides the use of steps prop for minValue/maxValue. */\n minValue?: number;\n /** Sets the maximum allowed value on the slider - this overrides the use of steps prop for minValue/maxValue. */\n maxValue?: number;\n /** If set to false will only trigger onChange once a user interaction has been made, updates to this prop will be taken into account - true by default */\n selected?: boolean;\n /** Sets the steps data for the slider */\n steps?: SliderStep[];\n /** Sets the step to move per point in the slider */\n step?: number;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Sets the value of the slider */\n value?: number;\n}\n\nexport const Slider = React.forwardRef((props: SliderProps, ref: React.Ref<HTMLInputElement>) => {\n const {\n title,\n ariaLabel,\n error,\n errorText,\n errorTextId,\n errorWrapperClassName,\n labelLeft,\n labelRight,\n disabled = false,\n onChange,\n steps,\n step = 1,\n minValue = 0,\n maxValue = steps ? steps.length - 1 : 100,\n selected = true,\n testId,\n value,\n ...rest\n } = props;\n\n const [isMoving, setIsMoving] = useState(false);\n const [selectedState, setSelectedState] = useState(typeof value === 'undefined' ? selected : true);\n const [valueState, setValueState] = useSafeNumberValue(\n typeof value === 'undefined' ? (maxValue - minValue) / 2 + minValue : value,\n minValue,\n maxValue\n );\n\n const errorTextUuid = useUuid(errorTextId);\n const titleId = useUuid();\n const labelLeftId = useUuid();\n const labelRightId = useUuid();\n const trackRef = useRef<HTMLDivElement>(null);\n const { refObject, isFocused } = usePseudoClasses<HTMLInputElement>(isMutableRefObject(ref) ? ref : null);\n const mergedRefs = mergeRefs([ref, refObject]);\n\n const { width: trackWidth } = useSize(trackRef) || { width: 0 };\n const largeStep = maxValue / 10;\n const invalid = !!errorText || !!error;\n\n useEffect(() => {\n const handlePointerUp = (): void => {\n setIsMoving(false);\n };\n\n document.addEventListener('pointerup', handlePointerUp);\n\n return (): void => {\n document.removeEventListener('pointerup', handlePointerUp);\n };\n }, []);\n\n const getValueBasedOnMarkerPosition = (markerPosition: number): number => {\n const trackPosition = trackRef.current?.getBoundingClientRect().x ?? 0;\n\n // Calculate the normalized position (0 to 1) of the marker along the track\n const normalizedPosition = (markerPosition - trackPosition) / trackWidth;\n const valueRange = maxValue - minValue;\n // Calculate the value without considering the step\n let value = normalizedPosition * valueRange + minValue;\n // Adjust the value to account for the step increment\n const stepCount = Math.round(value / step);\n value = stepCount * step;\n value = Math.max(minValue, Math.min(maxValue, value));\n\n return value;\n };\n\n useEffect(() => {\n const handlePointerMove = (e: PointerEvent): void => {\n if (!disabled && isMoving) {\n const newValue = getValueBasedOnMarkerPosition(e.clientX);\n setValueState(newValue);\n }\n };\n\n document.addEventListener('pointermove', handlePointerMove);\n\n return (): void => {\n document.removeEventListener('pointermove', handlePointerMove);\n };\n }, [isMoving]);\n\n useEffect(() => {\n if (value !== valueState && typeof value !== 'undefined') {\n handleSelected();\n setValueState(value);\n }\n }, [value]);\n\n useEffect(() => {\n if (typeof value === 'undefined' && selected !== selectedState) {\n setSelectedState(selected);\n }\n }, [selected]);\n\n const handleSelected = (): void => {\n if (selectedState === false) {\n setSelectedState(true);\n }\n };\n\n const handleKeyDown: React.KeyboardEventHandler<HTMLDivElement> = e => {\n if (disabled) return;\n\n let flag = false;\n\n switch (e.key) {\n case 'ArrowLeft':\n case 'ArrowDown':\n setValueState(valueState - step);\n flag = true;\n break;\n case 'PageDown':\n setValueState(valueState - largeStep);\n flag = true;\n break;\n case 'ArrowRight':\n case 'ArrowUp':\n setValueState(valueState + step);\n flag = true;\n break;\n case 'PageUp':\n setValueState(valueState + largeStep);\n flag = true;\n break;\n case 'Home':\n setValueState(minValue);\n flag = true;\n break;\n case 'End':\n setValueState(maxValue);\n flag = true;\n break;\n default:\n break;\n }\n\n if (flag) {\n handleSelected();\n e.preventDefault();\n e.stopPropagation();\n }\n };\n\n const handleTrackClick: React.MouseEventHandler<HTMLDivElement> = e => {\n if (disabled) return;\n\n const newValue = getValueBasedOnMarkerPosition(e.clientX);\n setValueState(newValue);\n refObject.current?.focus();\n };\n\n const handlePointerDown: React.PointerEventHandler<HTMLDivElement> = e => {\n if (disabled) return;\n\n setIsMoving(true);\n handleSelected();\n\n e.preventDefault();\n e.stopPropagation();\n\n refObject.current?.focus();\n };\n\n const markerXPos = maxValue !== minValue ? (trackWidth / (maxValue - minValue)) * (valueState - minValue) : 0;\n\n const getAriaValueText = (): string | undefined => {\n const stepIndex = steps ? Math.round((valueState - minValue) / step) : null;\n\n if (steps && stepIndex !== null && stepIndex >= 0 && stepIndex < steps.length) {\n const step = steps[stepIndex];\n const emojiCode = step.emojiUniCode;\n const label = typeof step.label !== 'undefined' ? step.label.toString() : undefined;\n\n return emojiCode && label ? `${emojiCode} ${label}` : emojiCode || label;\n }\n\n return undefined;\n };\n\n const getAriaLabeledById = (): string | undefined => {\n if (title && labelLeft && labelRight) {\n return [titleId, labelLeftId, labelRightId].join(' ');\n }\n if (title && labelLeft) {\n return [titleId, labelLeftId].join(' ');\n }\n if (title && labelRight) {\n return [titleId, labelRightId].join(' ');\n }\n if (title) {\n return titleId;\n }\n };\n\n const ariaLabelAttributes = getAriaLabelAttributes({\n label: ariaLabel,\n id: getAriaLabeledById(),\n prefer: 'label',\n });\n\n const getXPositionStyling = (index: number, stepsLength: number): { left: string } => {\n return { left: `${(index / (stepsLength - 1)) * 100}%` };\n };\n\n useEffect(() => {\n if (selectedState && onChange) {\n onChange({\n target: {\n name: props.name,\n value: valueState,\n },\n } as unknown as React.ChangeEvent<HTMLInputElement>);\n }\n }, [valueState, selectedState]);\n\n const renderEmojies = (): React.ReactNode => {\n return (\n <div className={styles['slider__emoji-container']}>\n {steps?.map((step, index) => {\n return (\n step.emojiUniCode && (\n <div\n aria-hidden={true}\n key={'emoji' + index}\n className={styles['slider__emoji']}\n style={getXPositionStyling(index, steps.length)}\n >\n {step.emojiUniCode}\n </div>\n )\n );\n })}\n </div>\n );\n };\n\n const renderSteps = (): React.ReactNode => {\n return steps?.map((_step, index) => {\n return <div key={'step' + index} className={styles['slider__track__step']} style={getXPositionStyling(index, steps.length)} />;\n });\n };\n\n const renderStepLabels = (): React.ReactNode => {\n return (\n <div className={styles['slider__value-container']}>\n {steps?.map((step, index) => {\n return (\n typeof step.label !== 'undefined' && (\n <div\n aria-hidden={true}\n key={'label' + index}\n className={styles['slider__value']}\n style={getXPositionStyling(index, steps.length)}\n >\n {step.label}\n </div>\n )\n );\n })}\n </div>\n );\n };\n\n return (\n <ErrorWrapper className={errorWrapperClassName} errorText={errorText} errorTextId={errorTextUuid}>\n <input\n aria-valuetext={getAriaValueText()}\n className={styles['sr-only-slider']}\n disabled={disabled}\n min={minValue}\n max={maxValue}\n onChange={onChange}\n onKeyDown={handleKeyDown}\n value={valueState}\n ref={mergedRefs}\n type=\"range\"\n {...rest}\n {...ariaLabelAttributes}\n />\n <div className={styles.slider} data-testid={testId} data-analyticsid={AnalyticsId.Slider}>\n {title && (\n <Title className={styles['slider__title']} htmlMarkup={'h3'} margin={0} appearance={'title3'} id={titleId}>\n {title}\n </Title>\n )}\n <div className={styles['slider__content-container']}>\n {renderEmojies()}\n {/* Slider streken er klikkbar med mus/touch */}\n {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */}\n <div\n ref={trackRef}\n className={classNames(styles['slider__track-wrapper'], disabled && styles['slider__track-wrapper--disabled'])}\n onClick={handleTrackClick}\n onPointerDown={handlePointerDown}\n >\n <div className={classNames(styles.slider__track, disabled && styles['slider__track--disabled'])}>{renderSteps()}</div>\n <div\n className={classNames(styles.slider__marker, {\n [styles['slider__marker--disabled']]: disabled,\n [styles['slider__marker--selected']]: selectedState,\n [styles['slider__marker--invalid']]: invalid,\n [styles['slider__marker--focused']]: !disabled && isFocused,\n })}\n style={{\n left: `${markerXPos}px`,\n }}\n />\n </div>\n {renderStepLabels()}\n </div>\n {(labelLeft || labelRight) && (\n <span className={styles.slider__options}>\n <span id={labelLeftId}>{labelLeft}</span>\n <span id={labelRightId}>{labelRight}</span>\n </span>\n )}\n </div>\n </ErrorWrapper>\n );\n});\n\nSlider.displayName = 'Slider';\n\nexport default Slider;\n"],"names":["useSafeNumberValue","initial","min","max","value","setValue","useState","setSafeValue","newValue","useEffect","Slider","React","props","ref","title","ariaLabel","error","errorText","errorTextId","errorWrapperClassName","labelLeft","labelRight","disabled","onChange","steps","step","minValue","maxValue","selected","testId","rest","isMoving","setIsMoving","selectedState","setSelectedState","valueState","setValueState","errorTextUuid","useUuid","titleId","labelLeftId","labelRightId","trackRef","useRef","refObject","isFocused","usePseudoClasses","isMutableRefObject","mergedRefs","mergeRefs","trackWidth","useSize","largeStep","invalid","handlePointerUp","getValueBasedOnMarkerPosition","markerPosition","trackPosition","_a","normalizedPosition","valueRange","handlePointerMove","handleSelected","handleKeyDown","e","flag","handleTrackClick","handlePointerDown","markerXPos","getAriaValueText","stepIndex","emojiCode","label","ariaLabelAttributes","getAriaLabelAttributes","getXPositionStyling","index","stepsLength","renderEmojies","jsx","styles","renderSteps","_step","renderStepLabels","ErrorWrapper","jsxs","AnalyticsId","Title","classNames"],"mappings":";;;;;;;;;;;;AAeA,MAAMA,KAAqB,CAACC,GAAiBC,GAAaC,MAAmD;AAC3G,QAAM,CAACC,GAAOC,CAAQ,IAAIC,EAASL,CAAO,GAEpCM,IAAe,CAACC,MAA2B;AAC/C,IAAIA,IAAWL,IACbE,EAASF,CAAG,IACHK,IAAWN,IACpBG,EAASH,CAAG,IAEZG,EAASG,CAAQ;AAAA,EACnB;AAGF,SAAAC,EAAU,MAAM;AACd,IAAA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AAW8C,EAAWR,EAAO,uBAAuB,GAAG1D,KAAY0D,EAAO,iCAAiC,CAAC;AAAA,YAC5G,SAASd;AAAA,YACT,eAAeC;AAAA,YAEf,UAAA;AAAA,cAAC,gBAAAY,EAAA,OAAA,EAAI,WAAWS,EAAWR,EAAO,eAAe1D,KAAY0D,EAAO,yBAAyB,CAAC,GAAI,UAAAC,GAAc,EAAA,CAAA;AAAA,cAChH,gBAAAF;AAAA,gBAAC;AAAA,gBAAA;AAAA,kBACC,WAAWS,EAAWR,EAAO,gBAAgB;AAAA,oBAC3C,CAACA,EAAO,0BAA0B,CAAC,GAAG1D;AAAA,oBACtC,CAAC0D,EAAO,0BAA0B,CAAC,GAAG/C;AAAA,oBACtC,CAAC+C,EAAO,yBAAyB,CAAC,GAAG3B;AAAA,oBACrC,CAAC2B,EAAO,yBAAyB,CAAC,GAAG,CAAC1D,KAAYuB;AAAA,kBAAA,CACnD;AAAA,kBACD,OAAO;AAAA,oBACL,MAAM,GAAGuB,EAAU;AAAA,kBACrB;AAAA,gBAAA;AAAA,cACF;AAAA,YAAA;AAAA,UAAA;AAAA,QACF;AAAA,QACCe,GAAiB;AAAA,MAAA,GACpB;AAAA,OACE/D,KAAaC,MACb,gBAAAgE,EAAC,QAAK,EAAA,WAAWL,EAAO,iBACtB,UAAA;AAAA,QAAC,gBAAAD,EAAA,QAAA,EAAK,IAAIvC,GAAc,UAAUpB,GAAA;AAAA,QACjC,gBAAA2D,EAAA,QAAA,EAAK,IAAItC,GAAe,UAAWpB,GAAA;AAAA,MAAA,GACtC;AAAA,IAAA,GAEJ;AAAA,EACF,EAAA,CAAA;AAEJ,CAAC;AAEDX,GAAO,cAAc;"}
|
|
1
|
+
{"version":3,"file":"Slider.js","sources":["../src/components/Slider/Slider.tsx"],"sourcesContent":["import React, { useEffect, useState, useRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport { AnalyticsId } from '../../constants';\nimport { usePseudoClasses } from '../../hooks/usePseudoClasses';\nimport { useSize } from '../../hooks/useSize';\nimport { useUuid } from '../../hooks/useUuid';\nimport { getAriaLabelAttributes } from '../../utils/accessibility';\nimport { isMutableRefObject, mergeRefs } from '../../utils/refs';\nimport ErrorWrapper, { ErrorWrapperClassNameProps } from '../ErrorWrapper';\nimport Title from '../Title';\n\nimport styles from './styles.module.scss';\n\nconst useSafeNumberValue = (initial: number, min: number, max: number): [number, (value: number) => void] => {\n const [value, setValue] = useState(initial);\n\n const setSafeValue = (newValue: number): void => {\n if (newValue > max) {\n setValue(max);\n } else if (newValue < min) {\n setValue(min);\n } else {\n setValue(newValue);\n }\n };\n\n useEffect(() => {\n setSafeValue(initial);\n }, [min, max]);\n\n return [value, setSafeValue];\n};\n\nexport type SliderStep = {\n label?: number | string;\n emojiUniCode?: string;\n};\n\nexport interface SliderProps\n extends ErrorWrapperClassNameProps,\n Pick<React.InputHTMLAttributes<HTMLInputElement>, 'id' | 'name' | 'onChange' | 'onBlur'> {\n /** Activates Error style for the input */\n error?: boolean;\n /** Error text to show above the component */\n errorText?: string;\n /** Error text id */\n errorTextId?: string;\n /**\tSets the title of the slider. */\n title?: string;\n /** Adds the left hand label to the element. */\n labelLeft?: string;\n /** Adds the right hand label to the element. */\n labelRight?: string;\n /**\tSets aria-label of the slider. */\n ariaLabel?: string;\n /** Disables the slider element. */\n disabled?: boolean;\n /** Sets the minimum allowed value on the slider - this overrides the use of steps prop for minValue/maxValue. */\n minValue?: number;\n /** Sets the maximum allowed value on the slider - this overrides the use of steps prop for minValue/maxValue. */\n maxValue?: number;\n /** If set to false will only trigger onChange once a user interaction has been made, updates to this prop will be taken into account - true by default */\n selected?: boolean;\n /** Sets the steps data for the slider */\n steps?: SliderStep[];\n /** Sets the step to move per point in the slider */\n step?: number;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Sets the value of the slider */\n value?: number;\n}\n\nexport const Slider = React.forwardRef((props: SliderProps, ref: React.Ref<HTMLInputElement>) => {\n const {\n title,\n ariaLabel,\n error,\n errorText,\n errorTextId,\n errorWrapperClassName,\n labelLeft,\n labelRight,\n disabled = false,\n onChange,\n steps,\n step = 1,\n minValue = 0,\n maxValue = steps ? steps.length - 1 : 100,\n selected = true,\n testId,\n value,\n ...rest\n } = props;\n\n const [isMoving, setIsMoving] = useState(false);\n const [selectedState, setSelectedState] = useState(typeof value === 'undefined' ? selected : true);\n const [valueState, setValueState] = useSafeNumberValue(\n typeof value === 'undefined' ? (maxValue - minValue) / 2 + minValue : value,\n minValue,\n maxValue\n );\n\n const errorTextUuid = useUuid(errorTextId);\n const titleId = useUuid();\n const labelLeftId = useUuid();\n const labelRightId = useUuid();\n const trackRef = useRef<HTMLDivElement>(null);\n const { refObject, isFocused } = usePseudoClasses<HTMLInputElement>(isMutableRefObject(ref) ? ref : null);\n const mergedRefs = mergeRefs([ref, refObject]);\n\n const { width: trackWidth } = useSize(trackRef) || { width: 0 };\n const largeStep = maxValue / 10;\n const invalid = !!errorText || !!error;\n\n useEffect(() => {\n const handlePointerUp = (): void => {\n setIsMoving(false);\n };\n\n document.addEventListener('pointerup', handlePointerUp);\n\n return (): void => {\n document.removeEventListener('pointerup', handlePointerUp);\n };\n }, []);\n\n const getValueBasedOnMarkerPosition = (markerPosition: number): number => {\n const trackPosition = trackRef.current?.getBoundingClientRect().x ?? 0;\n\n // Calculate the normalized position (0 to 1) of the marker along the track\n const normalizedPosition = (markerPosition - trackPosition) / trackWidth;\n const valueRange = maxValue - minValue;\n // Calculate the value without considering the step\n let value = normalizedPosition * valueRange + minValue;\n // Adjust the value to account for the step increment\n const stepCount = Math.round(value / step);\n value = stepCount * step;\n value = Math.max(minValue, Math.min(maxValue, value));\n\n return value;\n };\n\n useEffect(() => {\n const handlePointerMove = (e: PointerEvent): void => {\n if (!disabled && isMoving) {\n const newValue = getValueBasedOnMarkerPosition(e.clientX);\n setValueState(newValue);\n }\n };\n\n document.addEventListener('pointermove', handlePointerMove);\n\n return (): void => {\n document.removeEventListener('pointermove', handlePointerMove);\n };\n }, [isMoving]);\n\n useEffect(() => {\n if (value !== valueState && typeof value !== 'undefined') {\n handleSelected();\n setValueState(value);\n }\n }, [value]);\n\n useEffect(() => {\n if (typeof value === 'undefined' && selected !== selectedState) {\n setSelectedState(selected);\n }\n }, [selected]);\n\n const handleSelected = (): void => {\n if (selectedState === false) {\n setSelectedState(true);\n }\n };\n\n const handleKeyDown: React.KeyboardEventHandler<HTMLDivElement> = e => {\n if (disabled) return;\n\n let flag = false;\n\n switch (e.key) {\n case 'ArrowLeft':\n case 'ArrowDown':\n setValueState(valueState - step);\n flag = true;\n break;\n case 'PageDown':\n setValueState(valueState - largeStep);\n flag = true;\n break;\n case 'ArrowRight':\n case 'ArrowUp':\n setValueState(valueState + step);\n flag = true;\n break;\n case 'PageUp':\n setValueState(valueState + largeStep);\n flag = true;\n break;\n case 'Home':\n setValueState(minValue);\n flag = true;\n break;\n case 'End':\n setValueState(maxValue);\n flag = true;\n break;\n default:\n break;\n }\n\n if (flag) {\n handleSelected();\n e.preventDefault();\n e.stopPropagation();\n }\n };\n\n const handleTrackClick: React.MouseEventHandler<HTMLDivElement> = e => {\n if (disabled) return;\n\n const newValue = getValueBasedOnMarkerPosition(e.clientX);\n setValueState(newValue);\n refObject.current?.focus();\n };\n\n const handlePointerDown: React.PointerEventHandler<HTMLDivElement> = e => {\n if (disabled) return;\n\n setIsMoving(true);\n handleSelected();\n\n e.preventDefault();\n e.stopPropagation();\n\n refObject.current?.focus();\n };\n\n const markerXPos = maxValue !== minValue ? (trackWidth / (maxValue - minValue)) * (valueState - minValue) : 0;\n\n const getAriaValueText = (): string | undefined => {\n const stepIndex = steps ? Math.round((valueState - minValue) / step) : null;\n\n if (steps && stepIndex !== null && stepIndex >= 0 && stepIndex < steps.length) {\n const step = steps[stepIndex];\n const emojiCode = step.emojiUniCode;\n const label = typeof step.label !== 'undefined' ? step.label.toString() : undefined;\n\n return emojiCode && label ? `${emojiCode} ${label}` : emojiCode || label;\n }\n\n return undefined;\n };\n\n const getAriaLabeledById = (): string | undefined => {\n if (title && labelLeft && labelRight) {\n return [titleId, labelLeftId, labelRightId].join(' ');\n }\n if (title && labelLeft) {\n return [titleId, labelLeftId].join(' ');\n }\n if (title && labelRight) {\n return [titleId, labelRightId].join(' ');\n }\n if (title) {\n return titleId;\n }\n };\n\n const ariaLabelAttributes = getAriaLabelAttributes({\n label: ariaLabel,\n id: getAriaLabeledById(),\n prefer: 'label',\n });\n\n const getXPositionStyling = (index: number, stepsLength: number): { left: string } => {\n return { left: `${(index / (stepsLength - 1)) * 100}%` };\n };\n\n useEffect(() => {\n if (selectedState && onChange) {\n onChange({\n target: {\n name: props.name,\n value: valueState,\n },\n } as unknown as React.ChangeEvent<HTMLInputElement>);\n }\n }, [valueState, selectedState]);\n\n const renderEmojies = (): React.ReactNode => {\n return (\n <div className={styles['slider__emoji-container']}>\n {steps?.map((step, index) => {\n return (\n step.emojiUniCode && (\n <div\n aria-hidden={true}\n key={'emoji' + index}\n className={styles['slider__emoji']}\n style={getXPositionStyling(index, steps.length)}\n >\n {step.emojiUniCode}\n </div>\n )\n );\n })}\n </div>\n );\n };\n\n const renderSteps = (): React.ReactNode => {\n return steps?.map((_step, index) => {\n return <div key={'step' + index} className={styles['slider__track__step']} style={getXPositionStyling(index, steps.length)} />;\n });\n };\n\n const renderStepLabels = (): React.ReactNode => {\n return (\n <div className={styles['slider__value-container']}>\n {steps?.map((step, index) => {\n return (\n typeof step.label !== 'undefined' && (\n <div\n aria-hidden={true}\n key={'label' + index}\n className={styles['slider__value']}\n style={getXPositionStyling(index, steps.length)}\n >\n {step.label}\n </div>\n )\n );\n })}\n </div>\n );\n };\n\n return (\n <ErrorWrapper className={errorWrapperClassName} errorText={errorText} errorTextId={errorTextUuid}>\n <input\n aria-valuetext={getAriaValueText()}\n className={styles['sr-only-slider']}\n disabled={disabled}\n min={minValue}\n max={maxValue}\n onChange={onChange}\n onKeyDown={handleKeyDown}\n value={valueState}\n ref={mergedRefs}\n type=\"range\"\n {...rest}\n {...ariaLabelAttributes}\n />\n <div className={styles.slider} data-testid={testId} data-analyticsid={AnalyticsId.Slider}>\n {title && (\n <Title className={styles['slider__title']} htmlMarkup={'h3'} margin={0} appearance={'title3'} id={titleId}>\n {title}\n </Title>\n )}\n <div className={styles['slider__content-container']}>\n {renderEmojies()}\n {/* Slider streken er klikkbar med mus/touch */}\n {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */}\n <div\n ref={trackRef}\n className={classNames(styles['slider__track-wrapper'], disabled && styles['slider__track-wrapper--disabled'])}\n onClick={handleTrackClick}\n onPointerDown={handlePointerDown}\n >\n <div className={classNames(styles.slider__track, disabled && styles['slider__track--disabled'])}>{renderSteps()}</div>\n <div\n className={classNames(styles.slider__marker, {\n [styles['slider__marker--disabled']]: disabled,\n [styles['slider__marker--selected']]: selectedState,\n [styles['slider__marker--invalid']]: invalid,\n [styles['slider__marker--focused']]: !disabled && isFocused,\n })}\n style={{\n left: `${markerXPos}px`,\n }}\n />\n </div>\n {renderStepLabels()}\n </div>\n {(labelLeft || labelRight) && (\n <span className={styles.slider__options}>\n <span id={labelLeftId}>{labelLeft}</span>\n <span id={labelRightId}>{labelRight}</span>\n </span>\n )}\n </div>\n </ErrorWrapper>\n );\n});\n\nSlider.displayName = 'Slider';\n\nexport default Slider;\n"],"names":["useSafeNumberValue","initial","min","max","value","setValue","useState","setSafeValue","newValue","useEffect","Slider","React","props","ref","title","ariaLabel","error","errorText","errorTextId","errorWrapperClassName","labelLeft","labelRight","disabled","onChange","steps","step","minValue","maxValue","selected","testId","rest","isMoving","setIsMoving","selectedState","setSelectedState","valueState","setValueState","errorTextUuid","useUuid","titleId","labelLeftId","labelRightId","trackRef","useRef","refObject","isFocused","usePseudoClasses","isMutableRefObject","mergedRefs","mergeRefs","trackWidth","useSize","largeStep","invalid","handlePointerUp","getValueBasedOnMarkerPosition","markerPosition","trackPosition","_a","normalizedPosition","valueRange","handlePointerMove","handleSelected","handleKeyDown","e","flag","handleTrackClick","handlePointerDown","markerXPos","getAriaValueText","stepIndex","emojiCode","label","ariaLabelAttributes","getAriaLabelAttributes","getXPositionStyling","index","stepsLength","renderEmojies","jsx","styles","renderSteps","_step","renderStepLabels","ErrorWrapper","jsxs","AnalyticsId","Title","classNames"],"mappings":";;;;;;;;;;;;AAeA,MAAMA,KAAqB,CAACC,GAAiBC,GAAaC,MAAmD;AAC3G,QAAM,CAACC,GAAOC,CAAQ,IAAIC,EAASL,CAAO,GAEpCM,IAAe,CAACC,MAA2B;AAC/C,IAAIA,IAAWL,IACbE,EAASF,CAAG,IACHK,IAAWN,IACpBG,EAASH,CAAG,IAEZG,EAASG,CAAQ;AAAA,EACnB;AAGF,SAAAC,EAAU,MAAM;AACd,IAAAF,EAAaN,CAAO;AAAA,EAAA,GACnB,CAACC,GAAKC,CAAG,CAAC,GAEN,CAACC,GAAOG,CAAY;AAC7B,GA0CaG,KAASC,GAAM,WAAW,CAACC,GAAoBC,MAAqC;AACzF,QAAA;AAAA,IACJ,OAAAC;AAAA,IACA,WAAAC;AAAA,IACA,OAAAC;AAAA,IACA,WAAAC;AAAA,IACA,aAAAC;AAAA,IACA,uBAAAC;AAAA,IACA,WAAAC;AAAA,IACA,YAAAC;AAAA,IACA,UAAAC,IAAW;AAAA,IACX,UAAAC;AAAA,IACA,OAAAC;AAAA,IACA,MAAAC,IAAO;AAAA,IACP,UAAAC,IAAW;AAAA,IACX,UAAAC,IAAWH,IAAQA,EAAM,SAAS,IAAI;AAAA,IACtC,UAAAI,IAAW;AAAA,IACX,QAAAC;AAAA,IACA,OAAAzB;AAAA,IACA,GAAG0B;AAAA,EACD,IAAAlB,GAEE,CAACmB,GAAUC,CAAW,IAAI1B,EAAS,EAAK,GACxC,CAAC2B,GAAeC,CAAgB,IAAI5B,EAAS,OAAOF,IAAU,MAAcwB,IAAW,EAAI,GAC3F,CAACO,GAAYC,CAAa,IAAIpC;AAAA,IAClC,OAAOI,IAAU,OAAeuB,IAAWD,KAAY,IAAIA,IAAWtB;AA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A,WAAWL,EAAO,iBACtB,UAAA;AAAA,QAAC,gBAAAD,EAAA,QAAA,EAAK,IAAIvC,GAAc,UAAUpB,GAAA;AAAA,QACjC,gBAAA2D,EAAA,QAAA,EAAK,IAAItC,GAAe,UAAWpB,GAAA;AAAA,MAAA,GACtC;AAAA,IAAA,GAEJ;AAAA,EACF,EAAA,CAAA;AAEJ,CAAC;AAEDX,GAAO,cAAc;"}
|
|
@@ -10,6 +10,8 @@ export interface AvatarProps {
|
|
|
10
10
|
selected?: boolean;
|
|
11
11
|
/** background and color will be determined on variant. */
|
|
12
12
|
variant?: 'normal' | 'black';
|
|
13
|
+
/** @deprecated Square or circle variant of avatar. The circle should only be used for representation of someone else. NB: This is temporary and will be renamed in v10 */
|
|
14
|
+
type?: 'normal' | 'circle';
|
|
13
15
|
/** Avatar size. Default: small */
|
|
14
16
|
size?: keyof typeof AvatarSize;
|
|
15
17
|
/** Adds custom classes to the element. */
|
|
@@ -42,6 +42,8 @@ export interface ButtonProps extends HTMLButtonProps, HTMLAnchorProps, AriaAttri
|
|
|
42
42
|
tabIndex?: number;
|
|
43
43
|
/** Sets the data-testid attribute. */
|
|
44
44
|
testId?: string;
|
|
45
|
+
/** Adds custom classes to the text */
|
|
46
|
+
textClassName?: string;
|
|
45
47
|
/** Sets the position of the text in the button - only applies when button is fluid */
|
|
46
48
|
textPosition?: ButtonTextPosition;
|
|
47
49
|
/** Button type. Default: button */
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
@import '../../scss/palette';
|
|
5
5
|
@import '../../scss/font-settings';
|
|
6
6
|
@import '../../scss/screen-reader';
|
|
7
|
+
@import '../../scss/supernova/styles/colors';
|
|
7
8
|
|
|
8
9
|
$dark-mode-disabled-transparrent: #ffffffb3;
|
|
9
10
|
$with-icons: // icon-class, size-class, padding-left, padding-right, padding-left desktop, padding-right desktop, svg-margin-left, svg-margin-right, svg-margin-left desktop, svg-margin-right desktop
|
|
@@ -20,6 +21,18 @@ $with-icons: // icon-class, size-class, padding-left, padding-right, padding-lef
|
|
|
20
21
|
'both-icons' 'normal' getSpacer(xs) getSpacer(xs) getSpacer(xs) getSpacer(xs) 0 0 0 0,
|
|
21
22
|
'both-icons' 'large' getSpacer(xs) getSpacer(xs) getSpacer(xs) getSpacer(xs) 0 0 0 0;
|
|
22
23
|
|
|
24
|
+
// Brukes til å aktivere hover styling uten at button hovres
|
|
25
|
+
@mixin outline-borderless-hover {
|
|
26
|
+
@include outline-borderless-background(
|
|
27
|
+
var(--color-action-background-transparent-onlight-hover),
|
|
28
|
+
var(--color-action-background-transparent-onlight-hover)
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@mixin outline-borderless-text-hover {
|
|
33
|
+
@include text-color(var(--color-action-text-onlight-hover), var(--color-action-text-onlight-hover));
|
|
34
|
+
}
|
|
35
|
+
|
|
23
36
|
@mixin focus-shadow {
|
|
24
37
|
box-shadow: 0 0 0 getSpacer(3xs) $black;
|
|
25
38
|
}
|
|
@@ -28,11 +41,11 @@ $with-icons: // icon-class, size-class, padding-left, padding-right, padding-lef
|
|
|
28
41
|
box-shadow: 0 0 0 getSpacer(3xs) $white;
|
|
29
42
|
}
|
|
30
43
|
|
|
31
|
-
@mixin outline-borderless($background-color) {
|
|
32
|
-
background-color:
|
|
44
|
+
@mixin outline-borderless-background($background-color, $hover-background-color) {
|
|
45
|
+
background-color: $background-color;
|
|
33
46
|
|
|
34
47
|
&:hover {
|
|
35
|
-
background-color: $background-color;
|
|
48
|
+
background-color: $hover-background-color;
|
|
36
49
|
}
|
|
37
50
|
|
|
38
51
|
:disabled > & {
|
|
@@ -57,9 +70,13 @@ $with-icons: // icon-class, size-class, padding-left, padding-right, padding-lef
|
|
|
57
70
|
}
|
|
58
71
|
}
|
|
59
72
|
|
|
60
|
-
@mixin
|
|
73
|
+
@mixin text-color($color, $hover-color) {
|
|
61
74
|
color: $color;
|
|
62
75
|
|
|
76
|
+
:hover > & {
|
|
77
|
+
color: $hover-color;
|
|
78
|
+
}
|
|
79
|
+
|
|
63
80
|
:disabled > & {
|
|
64
81
|
@media (min-width: map.get($grid-breakpoints, md)) {
|
|
65
82
|
color: $neutral700;
|
|
@@ -67,14 +84,6 @@ $with-icons: // icon-class, size-class, padding-left, padding-right, padding-lef
|
|
|
67
84
|
}
|
|
68
85
|
}
|
|
69
86
|
|
|
70
|
-
@mixin borderless-text($color) {
|
|
71
|
-
color: $color;
|
|
72
|
-
|
|
73
|
-
:disabled > & {
|
|
74
|
-
color: $neutral700;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
87
|
@mixin fill-on-dark($background-color) {
|
|
79
88
|
background-color: $white;
|
|
80
89
|
|
|
@@ -113,7 +122,7 @@ $with-icons: // icon-class, size-class, padding-left, padding-right, padding-lef
|
|
|
113
122
|
|
|
114
123
|
@mixin on-dark {
|
|
115
124
|
&--on-dark {
|
|
116
|
-
@include fill-on-dark(
|
|
125
|
+
@include fill-on-dark(var(--color-action-background-ondark-hover));
|
|
117
126
|
}
|
|
118
127
|
&--on-dark#{&}--destructive {
|
|
119
128
|
@include fill-on-dark($cherry50);
|
|
@@ -272,11 +281,11 @@ $with-icons: // icon-class, size-class, padding-left, padding-right, padding-lef
|
|
|
272
281
|
|
|
273
282
|
&--outline,
|
|
274
283
|
&--borderless {
|
|
275
|
-
@include outline-borderless(
|
|
284
|
+
@include outline-borderless-background(transparent, var(--color-action-background-transparent-onlight-hover));
|
|
276
285
|
}
|
|
277
286
|
&--outline#{&}--destructive,
|
|
278
287
|
&--borderless#{&}--destructive {
|
|
279
|
-
@include outline-borderless($cherry50);
|
|
288
|
+
@include outline-borderless-background(transparent, $cherry50);
|
|
280
289
|
}
|
|
281
290
|
|
|
282
291
|
&--outline {
|
|
@@ -341,19 +350,13 @@ $with-icons: // icon-class, size-class, padding-left, padding-right, padding-lef
|
|
|
341
350
|
}
|
|
342
351
|
|
|
343
352
|
/* stylelint-disable-next-line */
|
|
344
|
-
&--outline &__text
|
|
345
|
-
@include outline-text($blueberry600);
|
|
346
|
-
}
|
|
347
|
-
&--outline#{&}--destructive &__text {
|
|
348
|
-
@include outline-text($cherry600);
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
/* stylelint-disable-next-line */
|
|
353
|
+
&--outline &__text,
|
|
352
354
|
&--borderless &__text {
|
|
353
|
-
@include
|
|
355
|
+
@include text-color(var(--color-action-text-onlight), var(--color-action-text-onlight-hover));
|
|
354
356
|
}
|
|
357
|
+
&--outline#{&}--destructive &__text,
|
|
355
358
|
&--borderless#{&}--destructive &__text {
|
|
356
|
-
@include
|
|
359
|
+
@include text-color($cherry600, $cherry700);
|
|
357
360
|
}
|
|
358
361
|
|
|
359
362
|
/* stylelint-disable-next-line */
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
@import '../../scss/palette';
|
|
6
6
|
@import '../../scss/font-settings';
|
|
7
7
|
@import '../../scss/supernova/styles/colors';
|
|
8
|
+
@import '../Button/styles.module';
|
|
8
9
|
|
|
9
10
|
.expander {
|
|
10
11
|
position: initial;
|
|
@@ -37,15 +38,15 @@
|
|
|
37
38
|
padding-right: getSpacer(s);
|
|
38
39
|
text-align: left;
|
|
39
40
|
|
|
40
|
-
&:hover {
|
|
41
|
-
background-color: var(--color-action-background-transparent-onlight-hover);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
41
|
&--expanded {
|
|
45
|
-
|
|
42
|
+
@include outline-borderless-hover;
|
|
46
43
|
}
|
|
47
44
|
}
|
|
48
45
|
|
|
46
|
+
&__button &__button__text {
|
|
47
|
+
@include outline-borderless-text-hover;
|
|
48
|
+
}
|
|
49
|
+
|
|
49
50
|
&__trigger {
|
|
50
51
|
$trigger: &;
|
|
51
52
|
|
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
export type Styles = {
|
|
2
|
+
button: string;
|
|
3
|
+
button__arrow: string;
|
|
4
|
+
'button__arrow--both-icons': string;
|
|
5
|
+
'button__both-icons': string;
|
|
6
|
+
'button__left-icon': string;
|
|
7
|
+
'button__only-icon': string;
|
|
8
|
+
'button__right-icon': string;
|
|
9
|
+
'button__right-unicode-arrow': string;
|
|
10
|
+
button__text: string;
|
|
11
|
+
'button__text--centered': string;
|
|
12
|
+
'button__text--ellipsis': string;
|
|
13
|
+
'button--arrow': string;
|
|
14
|
+
'button--arrow--both-icons': string;
|
|
15
|
+
'button--borderless': string;
|
|
16
|
+
'button--both-icons': string;
|
|
17
|
+
'button--destructive': string;
|
|
18
|
+
'button--large': string;
|
|
19
|
+
'button--left-icon': string;
|
|
20
|
+
'button--normal': string;
|
|
21
|
+
'button--on-dark': string;
|
|
22
|
+
'button--only-icon': string;
|
|
23
|
+
'button--outline': string;
|
|
24
|
+
'button--right-icon': string;
|
|
25
|
+
'button-wrapper': string;
|
|
26
|
+
'button-wrapper--fluid': string;
|
|
27
|
+
diagonal: string;
|
|
28
|
+
diagonal__line: string;
|
|
29
|
+
'diagonal--on-dark': string;
|
|
2
30
|
expander: string;
|
|
3
31
|
expander__button: string;
|
|
32
|
+
expander__button__text: string;
|
|
4
33
|
'expander__button--expanded': string;
|
|
5
34
|
'expander__button--sticky': string;
|
|
6
35
|
expander__content: string;
|
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
children: o
|
|
18
|
-
}
|
|
19
|
-
);
|
|
20
|
-
};
|
|
1
|
+
import { jsx as n } from "react/jsx-runtime";
|
|
2
|
+
import { H as p } from "../../HighlightPanel.js";
|
|
3
|
+
import l from "../Icons/HandWaving.js";
|
|
4
|
+
import m from "./styles.module.scss";
|
|
5
|
+
const H = ({ className: r, testId: e, size: o, children: t, title: a }) => /* @__PURE__ */ n(
|
|
6
|
+
p,
|
|
7
|
+
{
|
|
8
|
+
className: r,
|
|
9
|
+
contentWrapperClassName: m["help-panel"],
|
|
10
|
+
testId: e,
|
|
11
|
+
size: o,
|
|
12
|
+
svgIcon: l,
|
|
13
|
+
title: a,
|
|
14
|
+
children: t
|
|
15
|
+
}
|
|
16
|
+
);
|
|
21
17
|
export {
|
|
22
|
-
|
|
18
|
+
H as default
|
|
23
19
|
};
|
|
24
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/components/HelpPanel/HelpPanel.tsx"],"sourcesContent":["import React from 'react';\n\nimport
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/components/HelpPanel/HelpPanel.tsx"],"sourcesContent":["import React from 'react';\n\nimport HighlightPanel, { HighlightPanelSize } from '../HighlightPanel';\nimport HandWaving from '../Icons/HandWaving';\n\nimport styles from './styles.module.scss';\n\nexport interface HelpPanelProps {\n /** What's in the box? */\n children: React.ReactNode;\n /** Changes the size. Default: medium */\n size?: keyof typeof HighlightPanelSize;\n /** Adds custom classes to the element. */\n className?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Sets title if needed */\n title?: string;\n}\n\nconst HelpPanel: React.FC<HelpPanelProps> = ({ className, testId, size, children, title }) => {\n return (\n <HighlightPanel\n className={className}\n contentWrapperClassName={styles['help-panel']}\n testId={testId}\n size={size}\n svgIcon={HandWaving}\n title={title}\n >\n {children}\n </HighlightPanel>\n );\n};\n\nexport default HelpPanel;\n"],"names":["HelpPanel","className","testId","size","children","title","jsx","HighlightPanel","styles","HandWaving"],"mappings":";;;;AAoBM,MAAAA,IAAsC,CAAC,EAAE,WAAAC,GAAW,QAAAC,GAAQ,MAAAC,GAAM,UAAAC,GAAU,OAAAC,QAE9E,gBAAAC;AAAA,EAACC;AAAA,EAAA;AAAA,IACC,WAAAN;AAAA,IACA,yBAAyBO,EAAO,YAAY;AAAA,IAC5C,QAAAN;AAAA,IACA,MAAAC;AAAA,IACA,SAASM;AAAA,IACT,OAAAJ;AAAA,IAEC,UAAAD;AAAA,EAAA;AAAA;"}
|
|
@@ -4,7 +4,7 @@ export type SliderStep = {
|
|
|
4
4
|
label?: number | string;
|
|
5
5
|
emojiUniCode?: string;
|
|
6
6
|
};
|
|
7
|
-
export interface SliderProps extends ErrorWrapperClassNameProps, Pick<React.InputHTMLAttributes<HTMLInputElement>, 'name' | 'onChange' | 'onBlur'> {
|
|
7
|
+
export interface SliderProps extends ErrorWrapperClassNameProps, Pick<React.InputHTMLAttributes<HTMLInputElement>, 'id' | 'name' | 'onChange' | 'onBlur'> {
|
|
8
8
|
/** Activates Error style for the input */
|
|
9
9
|
error?: boolean;
|
|
10
10
|
/** Error text to show above the component */
|
|
@@ -13,6 +13,8 @@ export interface TabsProps {
|
|
|
13
13
|
className?: string;
|
|
14
14
|
/** Sets the color of the tabs. Default: white */
|
|
15
15
|
color?: TabsColors;
|
|
16
|
+
/** Sets wether the component should use the container-breakout class. Default: true */
|
|
17
|
+
containerBreakout?: boolean;
|
|
16
18
|
/** Sets the background color of the tabs. Can only be used when the color is set to white. Default: onwhite */
|
|
17
19
|
onColor?: TabsOnColor;
|
|
18
20
|
/** Whether the tab list should be sticky */
|
package/components/Tabs/index.js
CHANGED
|
@@ -1,63 +1,65 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import b, { useState as i, useRef as v, useEffect as
|
|
3
|
-
import
|
|
4
|
-
import { a as
|
|
5
|
-
import { T as
|
|
6
|
-
import
|
|
1
|
+
import { jsxs as A, jsx as d } from "react/jsx-runtime";
|
|
2
|
+
import b, { useState as i, useRef as v, useEffect as N } from "react";
|
|
3
|
+
import w from "classnames";
|
|
4
|
+
import { a as J, T as K } from "../../TabList.js";
|
|
5
|
+
import { T as O } from "../../TabPanel.js";
|
|
6
|
+
import Q from "../../scss/layout.module.scss";
|
|
7
|
+
import { isMobileUA as V } from "../../utils/mobile.js";
|
|
7
8
|
import m from "./styles.module.scss";
|
|
8
|
-
const
|
|
9
|
-
activeTab:
|
|
9
|
+
const W = 75, Y = ({
|
|
10
|
+
activeTab: L,
|
|
10
11
|
children: c,
|
|
11
|
-
className:
|
|
12
|
+
className: S,
|
|
12
13
|
color: l = "white",
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
containerBreakout: g = !0,
|
|
15
|
+
onColor: M = "onwhite",
|
|
16
|
+
sticky: k = !0,
|
|
15
17
|
testId: D,
|
|
16
|
-
touchBehaviour:
|
|
18
|
+
touchBehaviour: X = "none"
|
|
17
19
|
}) => {
|
|
18
|
-
const
|
|
20
|
+
const y = L !== void 0, [P, U] = i(0), [u, j] = i(0), [h, F] = i(0), [I, s] = i(0), [$, f] = i(null), C = V(), n = v(null), r = v(null), q = v(null);
|
|
19
21
|
let R = "onwhite";
|
|
20
|
-
l === "white" && (R =
|
|
22
|
+
l === "white" && (R = M);
|
|
21
23
|
const p = (e, o) => {
|
|
22
|
-
|
|
23
|
-
}, q = () => {
|
|
24
|
-
C && f("right");
|
|
24
|
+
y || (U(e), e > o ? (s(0), G()) : e < o && (s(0), z()));
|
|
25
25
|
}, z = () => {
|
|
26
|
-
C && f("
|
|
26
|
+
C && f("right");
|
|
27
27
|
}, G = () => {
|
|
28
|
+
C && f("left");
|
|
29
|
+
}, H = () => {
|
|
28
30
|
f(null);
|
|
29
|
-
}, t =
|
|
30
|
-
return
|
|
31
|
+
}, t = y ? L : P;
|
|
32
|
+
return N(() => {
|
|
31
33
|
const e = (a) => {
|
|
32
34
|
j(a.touches[0].clientX);
|
|
33
35
|
}, o = (a) => {
|
|
34
|
-
|
|
36
|
+
F(a.touches[0].clientX);
|
|
35
37
|
const T = a.touches[0].clientX - u;
|
|
36
38
|
t === 0 && T > 0 || t === b.Children.count(c) - 1 && T < 0 ? s(0) : s(T);
|
|
37
39
|
}, x = () => {
|
|
38
|
-
Math.abs(h - u) >=
|
|
40
|
+
Math.abs(h - u) >= W && (h > u ? p(Math.max(0, t - 1), t) : p(Math.min(b.Children.count(c) - 1, t + 1), t)), s(0);
|
|
39
41
|
};
|
|
40
|
-
return
|
|
42
|
+
return X === "swipe" && n.current && (n.current.addEventListener("touchstart", e), n.current.addEventListener("touchmove", o), n.current.addEventListener("touchend", x)), () => {
|
|
41
43
|
n.current && (n.current.removeEventListener("touchstart", e), n.current.removeEventListener("touchmove", o), n.current.removeEventListener("touchend", x));
|
|
42
44
|
};
|
|
43
|
-
}, [
|
|
45
|
+
}, [X, u, h, t]), N(() => {
|
|
44
46
|
const e = () => {
|
|
45
|
-
|
|
47
|
+
H();
|
|
46
48
|
};
|
|
47
49
|
return r.current && r.current.addEventListener("animationend", e), () => {
|
|
48
50
|
r.current && r.current.removeEventListener("animationend", e);
|
|
49
51
|
};
|
|
50
|
-
}, []), /* @__PURE__ */
|
|
51
|
-
/* @__PURE__ */
|
|
52
|
+
}, []), /* @__PURE__ */ A("div", { className: w(S, g && Q["container-breakout"]), "data-testid": D, children: [
|
|
53
|
+
/* @__PURE__ */ A(
|
|
52
54
|
"div",
|
|
53
55
|
{
|
|
54
|
-
ref:
|
|
55
|
-
className:
|
|
56
|
-
[m["tab-list-wrapper--sticky"]]:
|
|
56
|
+
ref: q,
|
|
57
|
+
className: w(m["tab-list-wrapper"], {
|
|
58
|
+
[m["tab-list-wrapper--sticky"]]: k
|
|
57
59
|
}),
|
|
58
60
|
children: [
|
|
59
61
|
/* @__PURE__ */ d(
|
|
60
|
-
|
|
62
|
+
K,
|
|
61
63
|
{
|
|
62
64
|
onTabListClick: (e) => p(e, t),
|
|
63
65
|
selectedTab: t,
|
|
@@ -66,17 +68,17 @@ const Q = 75, V = ({
|
|
|
66
68
|
children: c
|
|
67
69
|
}
|
|
68
70
|
),
|
|
69
|
-
/* @__PURE__ */ d("div", { className:
|
|
71
|
+
/* @__PURE__ */ d("div", { className: w(m["panel-wrapper"], m[`panel-wrapper--${l}`]) })
|
|
70
72
|
]
|
|
71
73
|
}
|
|
72
74
|
),
|
|
73
|
-
/* @__PURE__ */ d("div", { ref: n, style: { marginTop: "-50px" }, children: /* @__PURE__ */ d(
|
|
75
|
+
/* @__PURE__ */ d("div", { ref: n, style: { marginTop: "-50px" }, children: /* @__PURE__ */ d(O, { ref: r, color: l, isFirst: t == 0, translateX: I, animate: $, children: b.Children.toArray(c)[t] }) })
|
|
74
76
|
] });
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
}, E = Y;
|
|
78
|
+
E.displayName = "Tabs";
|
|
79
|
+
E.Tab = J;
|
|
80
|
+
E.Tab.displayName = "Tabs.Tab";
|
|
79
81
|
export {
|
|
80
|
-
|
|
82
|
+
E as default
|
|
81
83
|
};
|
|
82
84
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/components/Tabs/Tabs.tsx"],"sourcesContent":["import React, { useState, useEffect, useRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport Tab from './Tab';\nimport TabList from './TabList';\nimport TabPanel from './TabPanel';\nimport { PaletteNames } from '../../theme/palette';\nimport { isMobileUA } from '../../utils/mobile';\n\nimport styles from './styles.module.scss';\n\nexport type { TabProps } from './Tab';\nexport type TabsColors = Extract<PaletteNames, 'blueberry' | 'neutral' | 'white'>;\nexport type TabsOnColor = 'onblueberry' | 'onneutral' | 'onwhite';\nexport type TabsTouchBehaviour = 'swipe' | 'none';\n\nexport interface TabsProps {\n children?: React.ReactNode;\n /** Controlled state for Tabs component */\n activeTab?: number;\n /** Adds custom classes to the element. */\n className?: string;\n /** Sets the color of the tabs. Default: white */\n color?: TabsColors;\n /** Sets the background color of the tabs. Can only be used when the color is set to white. Default: onwhite */\n onColor?: TabsOnColor;\n /** Whether the tab list should be sticky */\n sticky?: boolean;\n /** Determines how Tabs respons to touch events. */\n touchBehaviour?: TabsTouchBehaviour;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nconst swipeDistanceThreshold = 75;\n\nconst TabsRoot: React.FC<TabsProps> = ({\n activeTab,\n children,\n className,\n color = 'white',\n onColor = 'onwhite',\n sticky = true,\n testId,\n touchBehaviour = 'none',\n}) => {\n const isControlled = activeTab !== undefined;\n const [uncontrolledValue, setUncontrolledValue] = useState(0);\n const [touchStartX, setTouchStartX] = useState(0);\n const [touchEndX, setTouchEndX] = useState(0);\n const [translateX, setTranslateX] = useState(0);\n const [panelAnimation, setPanelAnimation] = useState<'left' | 'right' | null>(null);\n const mobile = isMobileUA();\n const tabsRef = useRef<HTMLDivElement>(null);\n const tabPanelRef = useRef<HTMLDivElement>(null);\n const tabListRef = useRef<HTMLDivElement>(null);\n\n let onColorUsed: TabsOnColor = 'onwhite';\n if (color === 'white') {\n onColorUsed = onColor;\n }\n\n const onValueChange = (newValue: number, oldValue: number): void => {\n if (!isControlled) {\n setUncontrolledValue(newValue);\n if (newValue > oldValue) {\n // make sure that the translateX is reset so the animation does not go outside the screen\n setTranslateX(0);\n onLeftSwipe();\n } else if (newValue < oldValue) {\n // make sure that the translateX is reset so the animation does not go outside the screen\n setTranslateX(0);\n onRightSwipe();\n }\n }\n };\n\n const onRightSwipe = (): void => {\n mobile && setPanelAnimation('right');\n };\n\n const onLeftSwipe = (): void => {\n mobile && setPanelAnimation('left');\n };\n\n const resetAnimation = (): void => {\n setPanelAnimation(null);\n };\n\n const activeTabIndex = isControlled ? activeTab : uncontrolledValue;\n\n useEffect(() => {\n const handleTouchStart = (event: TouchEvent): void => {\n setTouchStartX(event.touches[0].clientX);\n };\n\n const handleTouchMove = (event: TouchEvent): void => {\n setTouchEndX(event.touches[0].clientX);\n const newTranslateX = event.touches[0].clientX - touchStartX;\n\n if (activeTabIndex === 0 && newTranslateX > 0) {\n setTranslateX(0);\n } else if (activeTabIndex === React.Children.count(children) - 1 && newTranslateX < 0) {\n setTranslateX(0);\n } else {\n setTranslateX(newTranslateX);\n }\n };\n\n const handleTouchEnd = (): void => {\n const swipeDistance = Math.abs(touchEndX - touchStartX);\n if (swipeDistance >= swipeDistanceThreshold) {\n if (touchEndX > touchStartX) {\n // User swiped right\n onValueChange(Math.max(0, activeTabIndex - 1), activeTabIndex);\n } else {\n // User swiped left\n onValueChange(Math.min(React.Children.count(children) - 1, activeTabIndex + 1), activeTabIndex);\n }\n }\n setTranslateX(0);\n };\n\n if (touchBehaviour === 'swipe' && tabsRef.current) {\n tabsRef.current.addEventListener('touchstart', handleTouchStart);\n tabsRef.current.addEventListener('touchmove', handleTouchMove);\n tabsRef.current.addEventListener('touchend', handleTouchEnd);\n }\n return () => {\n if (tabsRef.current) {\n tabsRef.current.removeEventListener('touchstart', handleTouchStart);\n tabsRef.current.removeEventListener('touchmove', handleTouchMove);\n tabsRef.current.removeEventListener('touchend', handleTouchEnd);\n }\n };\n }, [touchBehaviour, touchStartX, touchEndX, activeTabIndex]);\n\n useEffect(() => {\n const handleAnimationEnd = (): void => {\n resetAnimation();\n };\n\n if (tabPanelRef.current) {\n tabPanelRef.current.addEventListener('animationend', handleAnimationEnd);\n }\n\n return () => {\n if (tabPanelRef.current) {\n tabPanelRef.current.removeEventListener('animationend', handleAnimationEnd);\n }\n };\n }, []);\n\n return (\n <div className={className} data-testid={testId}>\n <div\n ref={tabListRef}\n className={classNames(styles['tab-list-wrapper'], {\n [styles['tab-list-wrapper--sticky']]: sticky,\n })}\n >\n <TabList\n onTabListClick={(index: number) => onValueChange(index, activeTabIndex)}\n selectedTab={activeTabIndex}\n color={color}\n onColor={onColorUsed}\n >\n {children}\n </TabList>\n <div className={classNames(styles['panel-wrapper'], styles[`panel-wrapper--${color}`])}></div>\n </div>\n <div ref={tabsRef} style={{ marginTop: '-50px' }}>\n <TabPanel ref={tabPanelRef} color={color} isFirst={activeTabIndex == 0} translateX={translateX} animate={panelAnimation}>\n {React.Children.toArray(children)[activeTabIndex]}\n </TabPanel>\n </div>\n </div>\n );\n};\n\ntype TabsComponent = typeof TabsRoot & {\n Tab: typeof Tab;\n};\nconst Tabs = TabsRoot as TabsComponent;\nTabs.displayName = 'Tabs';\nTabs.Tab = Tab;\nTabs.Tab.displayName = 'Tabs.Tab';\n\nexport default Tabs;\n"],"names":["swipeDistanceThreshold","TabsRoot","activeTab","children","className","color","onColor","sticky","testId","touchBehaviour","isControlled","uncontrolledValue","setUncontrolledValue","useState","touchStartX","setTouchStartX","touchEndX","setTouchEndX","translateX","setTranslateX","panelAnimation","setPanelAnimation","mobile","isMobileUA","tabsRef","useRef","tabPanelRef","tabListRef","onColorUsed","onValueChange","newValue","oldValue","onLeftSwipe","onRightSwipe","resetAnimation","activeTabIndex","useEffect","handleTouchStart","event","handleTouchMove","newTranslateX","React","handleTouchEnd","handleAnimationEnd","jsxs","classNames","styles","jsx","TabList","index","TabPanel","Tabs","Tab"],"mappings":";;;;;;;AAmCA,MAAMA,IAAyB,IAEzBC,IAAgC,CAAC;AAAA,EACrC,WAAAC;AAAA,EACA,UAAAC;AAAA,EACA,WAAAC;AAAA,EACA,OAAAC,IAAQ;AAAA,EACR,SAAAC,IAAU;AAAA,EACV,QAAAC,IAAS;AAAA,EACT,QAAAC;AAAA,EACA,gBAAAC,IAAiB;AACnB,MAAM;AACJ,QAAMC,IAAeR,MAAc,QAC7B,CAACS,GAAmBC,CAAoB,IAAIC,EAAS,CAAC,GACtD,CAACC,GAAaC,CAAc,IAAIF,EAAS,CAAC,GAC1C,CAACG,GAAWC,CAAY,IAAIJ,EAAS,CAAC,GACtC,CAACK,GAAYC,CAAa,IAAIN,EAAS,CAAC,GACxC,CAACO,GAAgBC,CAAiB,IAAIR,EAAkC,IAAI,GAC5ES,IAASC,KACTC,IAAUC,EAAuB,IAAI,GACrCC,IAAcD,EAAuB,IAAI,GACzCE,IAAaF,EAAuB,IAAI;AAE9C,MAAIG,IAA2B;AAC/B,EAAIvB,MAAU,YACEuB,IAAAtB;AAGV,QAAAuB,IAAgB,CAACC,GAAkBC,MAA2B;AAClE,IAAKrB,MACHE,EAAqBkB,CAAQ,GACzBA,IAAWC,KAEbZ,EAAc,CAAC,GACHa,OACHF,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Ac,EAAA,CAClD,EACF,CAAA;AAAA,EACF,EAAA,CAAA;AAEJ,GAKMgB,IAAOlD;AACbkD,EAAK,cAAc;AACnBA,EAAK,MAAMC;AACXD,EAAK,IAAI,cAAc;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/components/Tabs/Tabs.tsx"],"sourcesContent":["import React, { useState, useEffect, useRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport Tab from './Tab';\nimport TabList from './TabList';\nimport TabPanel from './TabPanel';\nimport designsystemlayout from '../../scss/layout.module.scss';\nimport { PaletteNames } from '../../theme/palette';\nimport { isMobileUA } from '../../utils/mobile';\n\nimport styles from './styles.module.scss';\n\nexport type { TabProps } from './Tab';\nexport type TabsColors = Extract<PaletteNames, 'blueberry' | 'neutral' | 'white'>;\nexport type TabsOnColor = 'onblueberry' | 'onneutral' | 'onwhite';\nexport type TabsTouchBehaviour = 'swipe' | 'none';\n\nexport interface TabsProps {\n children?: React.ReactNode;\n /** Controlled state for Tabs component */\n activeTab?: number;\n /** Adds custom classes to the element. */\n className?: string;\n /** Sets the color of the tabs. Default: white */\n color?: TabsColors;\n /** Sets wether the component should use the container-breakout class. Default: true */\n containerBreakout?: boolean;\n /** Sets the background color of the tabs. Can only be used when the color is set to white. Default: onwhite */\n onColor?: TabsOnColor;\n /** Whether the tab list should be sticky */\n sticky?: boolean;\n /** Determines how Tabs respons to touch events. */\n touchBehaviour?: TabsTouchBehaviour;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nconst swipeDistanceThreshold = 75;\n\nconst TabsRoot: React.FC<TabsProps> = ({\n activeTab,\n children,\n className,\n color = 'white',\n containerBreakout = true,\n onColor = 'onwhite',\n sticky = true,\n testId,\n touchBehaviour = 'none',\n}) => {\n const isControlled = activeTab !== undefined;\n const [uncontrolledValue, setUncontrolledValue] = useState(0);\n const [touchStartX, setTouchStartX] = useState(0);\n const [touchEndX, setTouchEndX] = useState(0);\n const [translateX, setTranslateX] = useState(0);\n const [panelAnimation, setPanelAnimation] = useState<'left' | 'right' | null>(null);\n const mobile = isMobileUA();\n const tabsRef = useRef<HTMLDivElement>(null);\n const tabPanelRef = useRef<HTMLDivElement>(null);\n const tabListRef = useRef<HTMLDivElement>(null);\n\n let onColorUsed: TabsOnColor = 'onwhite';\n if (color === 'white') {\n onColorUsed = onColor;\n }\n\n const onValueChange = (newValue: number, oldValue: number): void => {\n if (!isControlled) {\n setUncontrolledValue(newValue);\n if (newValue > oldValue) {\n // make sure that the translateX is reset so the animation does not go outside the screen\n setTranslateX(0);\n onLeftSwipe();\n } else if (newValue < oldValue) {\n // make sure that the translateX is reset so the animation does not go outside the screen\n setTranslateX(0);\n onRightSwipe();\n }\n }\n };\n\n const onRightSwipe = (): void => {\n mobile && setPanelAnimation('right');\n };\n\n const onLeftSwipe = (): void => {\n mobile && setPanelAnimation('left');\n };\n\n const resetAnimation = (): void => {\n setPanelAnimation(null);\n };\n\n const activeTabIndex = isControlled ? activeTab : uncontrolledValue;\n\n useEffect(() => {\n const handleTouchStart = (event: TouchEvent): void => {\n setTouchStartX(event.touches[0].clientX);\n };\n\n const handleTouchMove = (event: TouchEvent): void => {\n setTouchEndX(event.touches[0].clientX);\n const newTranslateX = event.touches[0].clientX - touchStartX;\n\n if (activeTabIndex === 0 && newTranslateX > 0) {\n setTranslateX(0);\n } else if (activeTabIndex === React.Children.count(children) - 1 && newTranslateX < 0) {\n setTranslateX(0);\n } else {\n setTranslateX(newTranslateX);\n }\n };\n\n const handleTouchEnd = (): void => {\n const swipeDistance = Math.abs(touchEndX - touchStartX);\n if (swipeDistance >= swipeDistanceThreshold) {\n if (touchEndX > touchStartX) {\n // User swiped right\n onValueChange(Math.max(0, activeTabIndex - 1), activeTabIndex);\n } else {\n // User swiped left\n onValueChange(Math.min(React.Children.count(children) - 1, activeTabIndex + 1), activeTabIndex);\n }\n }\n setTranslateX(0);\n };\n\n if (touchBehaviour === 'swipe' && tabsRef.current) {\n tabsRef.current.addEventListener('touchstart', handleTouchStart);\n tabsRef.current.addEventListener('touchmove', handleTouchMove);\n tabsRef.current.addEventListener('touchend', handleTouchEnd);\n }\n return () => {\n if (tabsRef.current) {\n tabsRef.current.removeEventListener('touchstart', handleTouchStart);\n tabsRef.current.removeEventListener('touchmove', handleTouchMove);\n tabsRef.current.removeEventListener('touchend', handleTouchEnd);\n }\n };\n }, [touchBehaviour, touchStartX, touchEndX, activeTabIndex]);\n\n useEffect(() => {\n const handleAnimationEnd = (): void => {\n resetAnimation();\n };\n\n if (tabPanelRef.current) {\n tabPanelRef.current.addEventListener('animationend', handleAnimationEnd);\n }\n\n return () => {\n if (tabPanelRef.current) {\n tabPanelRef.current.removeEventListener('animationend', handleAnimationEnd);\n }\n };\n }, []);\n\n return (\n <div className={classNames(className, containerBreakout && designsystemlayout['container-breakout'])} data-testid={testId}>\n <div\n ref={tabListRef}\n className={classNames(styles['tab-list-wrapper'], {\n [styles['tab-list-wrapper--sticky']]: sticky,\n })}\n >\n <TabList\n onTabListClick={(index: number) => onValueChange(index, activeTabIndex)}\n selectedTab={activeTabIndex}\n color={color}\n onColor={onColorUsed}\n >\n {children}\n </TabList>\n <div className={classNames(styles['panel-wrapper'], styles[`panel-wrapper--${color}`])}></div>\n </div>\n <div ref={tabsRef} style={{ marginTop: '-50px' }}>\n <TabPanel ref={tabPanelRef} color={color} isFirst={activeTabIndex == 0} translateX={translateX} animate={panelAnimation}>\n {React.Children.toArray(children)[activeTabIndex]}\n </TabPanel>\n </div>\n </div>\n );\n};\n\ntype TabsComponent = typeof TabsRoot & {\n Tab: typeof Tab;\n};\nconst Tabs = TabsRoot as TabsComponent;\nTabs.displayName = 'Tabs';\nTabs.Tab = Tab;\nTabs.Tab.displayName = 'Tabs.Tab';\n\nexport default Tabs;\n"],"names":["swipeDistanceThreshold","TabsRoot","activeTab","children","className","color","containerBreakout","onColor","sticky","testId","touchBehaviour","isControlled","uncontrolledValue","setUncontrolledValue","useState","touchStartX","setTouchStartX","touchEndX","setTouchEndX","translateX","setTranslateX","panelAnimation","setPanelAnimation","mobile","isMobileUA","tabsRef","useRef","tabPanelRef","tabListRef","onColorUsed","onValueChange","newValue","oldValue","onLeftSwipe","onRightSwipe","resetAnimation","activeTabIndex","useEffect","handleTouchStart","event","handleTouchMove","newTranslateX","React","handleTouchEnd","handleAnimationEnd","jsxs","classNames","designsystemlayout","styles","jsx","TabList","index","TabPanel","Tabs","Tab"],"mappings":";;;;;;;;AAsCA,MAAMA,IAAyB,IAEzBC,IAAgC,CAAC;AAAA,EACrC,WAAAC;AAAA,EACA,UAAAC;AAAA,EACA,WAAAC;AAAA,EACA,OAAAC,IAAQ;AAAA,EACR,mBAAAC,IAAoB;AAAA,EACpB,SAAAC,IAAU;AAAA,EACV,QAAAC,IAAS;AAAA,EACT,QAAAC;AAAA,EACA,gBAAAC,IAAiB;AACnB,MAAM;AACJ,QAAMC,IAAeT,MAAc,QAC7B,CAACU,GAAmBC,CAAoB,IAAIC,EAAS,CAAC,GACtD,CAACC,GAAaC,CAAc,IAAIF,EAAS,CAAC,GAC1C,CAACG,GAAWC,CAAY,IAAIJ,EAAS,CAAC,GACtC,CAACK,GAAYC,CAAa,IAAIN,EAAS,CAAC,GACxC,CAACO,GAAgBC,CAAiB,IAAIR,EAAkC,IAAI,GAC5ES,IAASC,KACTC,IAAUC,EAAuB,IAAI,GACrCC,IAAcD,EAAuB,IAAI,GACzCE,IAAaF,EAAuB,IAAI;AAE9C,MAAIG,IAA2B;AAC/B,EAAIxB,MAAU,YACEwB,IAAAtB;AAGV,QAAAuB,IAAgB,CAACC,GAAkBC,MAA2B;AAClE,IAAKrB,MACHE,EAAqBkB,CAAQ,GACzBA,IAAWC,KAEbZ,EAAc,CAAC,GACHa,OACHF,IAAWC,MAEpBZ,EAAc,CAAC,GACFc;EAEjB,GAGIA,IAAe,MAAY;AAC/B,IAAAX,KAAUD,EAAkB,OAAO;AAAA,EAAA,GAG/BW,IAAc,MAAY;AAC9B,IAAAV,KAAUD,EAAkB,MAAM;AAAA,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AAI,cAAc;"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
@import './breakpoints';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
Denne filen er ment til å importeres som en css module:
|
|
5
|
+
import designsystemlayout from './scss/layout.scss'
|
|
6
|
+
<div className={designsystemlayout['container-breakout']}></div>
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
.container-breakout {
|
|
10
|
+
// This is a copy of how bootstrap's row class sets margins inside a container
|
|
11
|
+
// https://github.com/twbs/bootstrap/blob/e5643aaa89eb67327a5b4abe7db976f0ea276b70/scss/mixins/_grid.scss#L16C1-L17C30
|
|
12
|
+
margin-right: -$grid-gutter-width * 0.5;
|
|
13
|
+
margin-left: -$grid-gutter-width * 0.5;
|
|
14
|
+
}
|