@helsenorge/designsystem-react 7.3.1 → 7.4.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.
@@ -1,41 +1,42 @@
1
- import o, { useState as A, useRef as te, useEffect as N } from "react";
1
+ import o, { useState as A, useRef as te, useEffect as B } from "react";
2
2
  import p from "classnames";
3
3
  import { FormMode as m, AnalyticsId as re, AVERAGE_CHARACTER_WIDTH_PX as ae } from "../../constants.js";
4
4
  import { useUuid as oe } from "../../hooks/useUuid.js";
5
- import { uuid as ne } from "../../utils/uuid.js";
6
- import ie from "../ErrorWrapper/ErrorWrapper.js";
7
- import { renderLabel as se } from "../Label/Label.js";
8
- import ce from "../MaxCharacters/MaxCharacters.js";
5
+ import { getAriaDescribedBy as ne } from "../../utils/accessibility.js";
6
+ import { uuid as ie } from "../../utils/uuid.js";
7
+ import se from "../ErrorWrapper/ErrorWrapper.js";
8
+ import { renderLabel as ce } from "../Label/Label.js";
9
+ import de from "../MaxCharacters/MaxCharacters.js";
9
10
  import t from "../Textarea/styles.module.scss";
10
- const de = (a) => `calc(${a * ae}px + 2rem + 16px + 4px)`, $ = o.forwardRef((a, x) => {
11
+ const le = (a) => `calc(${a * ae}px + 2rem + 16px + 4px)`, N = o.forwardRef((a, x) => {
11
12
  const {
12
13
  maxCharacters: n,
13
14
  maxText: h,
14
15
  width: f,
15
- testId: B,
16
+ testId: $,
16
17
  defaultValue: s,
17
18
  marginBottom: M,
18
19
  transparent: k,
19
20
  mode: i = m.onwhite,
20
- label: L,
21
- textareaId: b = ne(),
21
+ label: D,
22
+ textareaId: b = ie(),
22
23
  minRows: g = 3,
23
24
  maxRows: c = 10,
24
25
  grow: w,
25
- error: S,
26
+ error: L,
26
27
  errorText: C,
27
- errorTextId: D,
28
+ errorTextId: S,
28
29
  autoFocus: F,
29
30
  disabled: U,
30
31
  name: V,
31
32
  autoComplete: T = "off",
32
- placeholder: j,
33
- readOnly: q,
34
- required: z,
33
+ placeholder: q,
34
+ readOnly: z,
35
+ required: G,
35
36
  onChange: E,
36
- ...G
37
- } = a, [O, W] = A(g), [y, R] = A(s || ""), d = te(null), v = oe(D);
38
- N(() => {
37
+ ...O
38
+ } = a, [P, W] = A(g), [y, R] = A(s || ""), d = te(null), v = oe(S);
39
+ B(() => {
39
40
  R(s || "");
40
41
  }, [s]);
41
42
  const _ = (e) => {
@@ -43,18 +44,18 @@ const de = (a) => `calc(${a * ae}px + 2rem + 16px + 4px)`, $ = o.forwardRef((a,
43
44
  e.rows = g;
44
45
  const r = Math.floor((e.scrollHeight - 16) / 28);
45
46
  r === l && (e.rows = r), r >= c && (e.rows = c, e.scrollTop = e.scrollHeight), r < c ? W(r) : W(c);
46
- }, P = i === m.ondark, X = i === m.onblueberry, J = !!n && y.toString().length > n, H = i === m.oninvalid || !!C || !!S || J, K = p(t.textarea, {
47
+ }, X = i === m.ondark, j = i === m.onblueberry, J = !!n && y.toString().length > n, H = i === m.oninvalid || !!C || !!L || J, K = p(t.textarea, {
47
48
  [t["textarea--gutterBottom"]]: M
48
49
  }), Q = p(t["input-container"], {
49
50
  [t["input-container--transparent"]]: k,
50
- [t["input-container--on-blueberry"]]: X,
51
- [t["input-container--on-dark"]]: P,
51
+ [t["input-container--on-blueberry"]]: j,
52
+ [t["input-container--on-dark"]]: X,
52
53
  [t["input-container--invalid"]]: H,
53
54
  [t["input-container--disabled"]]: a.disabled
54
55
  }), Y = p(t["input-container__input"], {
55
56
  [t["input-container__input--disabled"]]: a.disabled
56
57
  });
57
- N(() => {
58
+ B(() => {
58
59
  var e, u, l;
59
60
  if (w && ((e = d.current) != null && e.children) && ((u = d.current) != null && u.children[0])) {
60
61
  const r = (l = d.current) == null ? void 0 : l.children[0];
@@ -65,29 +66,29 @@ const de = (a) => `calc(${a * ae}px + 2rem + 16px + 4px)`, $ = o.forwardRef((a,
65
66
  w && _(e.target), R(e.target.value);
66
67
  }, ee = (e) => {
67
68
  E && E(e), Z(e);
68
- }, I = f ? de(f) : void 0;
69
- return /* @__PURE__ */ o.createElement(ie, { errorText: C, errorTextId: v }, /* @__PURE__ */ o.createElement("div", { "data-testid": B, "data-analyticsid": re.Textarea, className: K }, se(L, b, i), /* @__PURE__ */ o.createElement("div", { className: Q, ref: d, style: { maxWidth: I } }, /* @__PURE__ */ o.createElement(
69
+ }, I = f ? le(f) : void 0;
70
+ return /* @__PURE__ */ o.createElement(se, { errorText: C, errorTextId: v }, /* @__PURE__ */ o.createElement("div", { "data-testid": $, "data-analyticsid": re.Textarea, className: K }, ce(D, b, i), /* @__PURE__ */ o.createElement("div", { className: Q, ref: d, style: { maxWidth: I } }, /* @__PURE__ */ o.createElement(
70
71
  "textarea",
71
72
  {
72
- rows: O,
73
+ rows: P,
73
74
  defaultValue: s,
74
75
  id: b,
75
76
  className: Y,
76
77
  ref: x,
77
- "aria-describedby": [a["aria-describedby"] || "", v].join(" "),
78
+ "aria-describedby": ne(a, v),
78
79
  "aria-invalid": !!H,
79
80
  autoFocus: F,
80
81
  disabled: U,
81
82
  name: V,
82
83
  autoComplete: T || void 0,
83
- placeholder: j,
84
- readOnly: q,
85
- required: z,
84
+ placeholder: q,
85
+ readOnly: z,
86
+ required: G,
86
87
  onChange: ee,
87
- ...G
88
+ ...O
88
89
  }
89
90
  )), n && /* @__PURE__ */ o.createElement(
90
- ce,
91
+ de,
91
92
  {
92
93
  maxCharacters: n,
93
94
  length: y.toString().length,
@@ -97,9 +98,9 @@ const de = (a) => `calc(${a * ae}px + 2rem + 16px + 4px)`, $ = o.forwardRef((a,
97
98
  }
98
99
  )));
99
100
  });
100
- $.displayName = "Textarea";
101
- const we = $;
101
+ N.displayName = "Textarea";
102
+ const Te = N;
102
103
  export {
103
- we as default
104
+ Te as default
104
105
  };
105
106
  //# sourceMappingURL=Textarea.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Textarea.js","sources":["../../../src/components/Textarea/Textarea.tsx"],"sourcesContent":["import React, { useState, useRef, useEffect } from 'react';\n\nimport cn from 'classnames';\n\nimport { AnalyticsId, AVERAGE_CHARACTER_WIDTH_PX, FormMode } from '../../constants';\nimport { useUuid } from '../../hooks/useUuid';\nimport { uuid } from '../../utils/uuid';\nimport ErrorWrapper from '../ErrorWrapper';\nimport { renderLabel } from '../Label';\nimport MaxCharacters from '../MaxCharacters/MaxCharacters';\n\nimport styles from './styles.module.scss';\n\nexport interface TextareaProps\n extends Pick<\n React.InputHTMLAttributes<HTMLTextAreaElement>,\n | 'aria-describedby'\n | 'autoFocus'\n | 'disabled'\n | 'name'\n | 'autoComplete'\n | 'placeholder'\n | 'readOnly'\n | 'required'\n | 'defaultValue'\n | 'onChange'\n > {\n /** max character limit in textarea */\n maxCharacters?: number;\n /** The text is displayed in the end of the text-counter */\n maxText?: string;\n /** Width of textarea in characters (approximate) */\n width?: number;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** If true, the component will have a bottom margin. */\n marginBottom?: boolean;\n /** If true, the component will be transparent. */\n transparent?: boolean;\n /** Changes the visuals of the textarea */\n mode?: keyof typeof FormMode;\n /** Label of the input */\n label?: React.ReactNode;\n /** id of the textarea */\n textareaId?: string;\n /** max rows */\n maxRows?: number;\n /** min rows */\n minRows?: number;\n /** auto-grows until maxRows */\n grow?: boolean;\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}\n\nconst getTextareaMaxWidth = (characters: number): string => {\n const paddingWidth = '2rem';\n const scrollbarWidth = '16px';\n const borderWidth = '4px';\n\n return `calc(${characters * AVERAGE_CHARACTER_WIDTH_PX}px + ${paddingWidth} + ${scrollbarWidth} + ${borderWidth})`;\n};\n\nconst Textarea = React.forwardRef((props: TextareaProps, ref: React.Ref<HTMLTextAreaElement>) => {\n const {\n maxCharacters,\n maxText,\n width,\n testId,\n defaultValue,\n marginBottom: gutterBottom,\n transparent,\n mode = FormMode.onwhite,\n label,\n textareaId = uuid(),\n minRows = 3,\n maxRows = 10,\n grow,\n error,\n errorText,\n errorTextId,\n autoFocus,\n disabled,\n name,\n autoComplete = 'off',\n placeholder,\n readOnly,\n required,\n onChange,\n ...rest\n } = props;\n\n const [rows, setRows] = useState(minRows);\n const [textareaInput, setTextareaInput] = useState(defaultValue || '');\n const referanse = useRef<HTMLDivElement>(null);\n const errorTextUuid = useUuid(errorTextId);\n\n useEffect(() => {\n setTextareaInput(defaultValue || '');\n }, [defaultValue]);\n\n const resizeHeight = (target: HTMLTextAreaElement): void => {\n const textareaLineHeight = 28;\n\n const previousRows = target.rows;\n target.rows = minRows; // reset number of rows in textarea\n\n const currentRows = Math.floor((target.scrollHeight - 16) / textareaLineHeight); // scrollHeight - 16px of padding to calculate the rows\n\n if (currentRows === previousRows) {\n target.rows = currentRows;\n }\n\n if (currentRows >= maxRows) {\n target.rows = maxRows;\n target.scrollTop = target.scrollHeight;\n }\n\n if (currentRows < maxRows) {\n setRows(currentRows);\n } else {\n setRows(maxRows);\n }\n };\n\n const onDark = mode === FormMode.ondark;\n const onBlueberry = mode === FormMode.onblueberry;\n const maxCharactersExceeded = !!maxCharacters && textareaInput.toString().length > maxCharacters;\n const onError = mode === FormMode.oninvalid || !!errorText || !!error || maxCharactersExceeded;\n\n const textareaWrapperClass = cn(styles.textarea, {\n [styles['textarea--gutterBottom']]: gutterBottom,\n });\n\n const contentWrapperClass = cn(styles['input-container'], {\n [styles['input-container--transparent']]: transparent,\n [styles['input-container--on-blueberry']]: onBlueberry,\n [styles['input-container--on-dark']]: onDark,\n [styles['input-container--invalid']]: onError,\n [styles['input-container--disabled']]: props.disabled,\n });\n\n const textareaClass = cn(styles['input-container__input'], {\n [styles[`input-container__input--disabled`]]: props.disabled,\n });\n\n useEffect(() => {\n if (grow && referanse.current?.children && referanse.current?.children[0]) {\n const textarea = referanse.current?.children[0] as HTMLTextAreaElement;\n resizeHeight(textarea);\n }\n }, []);\n\n const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>): void => {\n if (grow) {\n resizeHeight(e.target);\n }\n setTextareaInput(e.target.value);\n };\n\n const onChangeHandler = (e: React.ChangeEvent<HTMLTextAreaElement>): void => {\n if (onChange) {\n onChange(e);\n }\n handleChange(e);\n };\n\n const maxWidth = width ? getTextareaMaxWidth(width) : undefined;\n\n return (\n <ErrorWrapper errorText={errorText} errorTextId={errorTextUuid}>\n <div data-testid={testId} data-analyticsid={AnalyticsId.Textarea} className={textareaWrapperClass}>\n {renderLabel(label, textareaId, mode as FormMode)}\n <div className={contentWrapperClass} ref={referanse} style={{ maxWidth }}>\n <textarea\n rows={rows}\n defaultValue={defaultValue}\n id={textareaId}\n className={textareaClass}\n ref={ref}\n aria-describedby={[props['aria-describedby'] || '', errorTextUuid].join(' ')}\n aria-invalid={!!onError}\n // eslint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={autoFocus}\n disabled={disabled}\n name={name}\n autoComplete={autoComplete ? autoComplete : undefined}\n placeholder={placeholder}\n readOnly={readOnly}\n required={required}\n onChange={onChangeHandler}\n {...rest}\n />\n </div>\n {maxCharacters && (\n <MaxCharacters\n maxCharacters={maxCharacters}\n length={textareaInput.toString().length}\n maxText={maxText}\n mode={mode}\n maxWidth={maxWidth}\n />\n )}\n </div>\n </ErrorWrapper>\n );\n});\n\nTextarea.displayName = 'Textarea';\n\nexport default Textarea;\n"],"names":["getTextareaMaxWidth","characters","AVERAGE_CHARACTER_WIDTH_PX","Textarea","React","props","ref","maxCharacters","maxText","width","testId","defaultValue","gutterBottom","transparent","mode","FormMode","label","textareaId","uuid","minRows","maxRows","grow","error","errorText","errorTextId","autoFocus","disabled","name","autoComplete","placeholder","readOnly","required","onChange","rest","rows","setRows","useState","textareaInput","setTextareaInput","referanse","useRef","errorTextUuid","useUuid","useEffect","resizeHeight","target","previousRows","currentRows","onDark","onBlueberry","maxCharactersExceeded","onError","textareaWrapperClass","cn","styles","contentWrapperClass","textareaClass","_a","_b","textarea","_c","handleChange","onChangeHandler","maxWidth","ErrorWrapper","AnalyticsId","renderLabel","MaxCharacters","Textarea$1"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AQT,GAAoBS,CAAK,IAAI;AAEtD,SACGL,gBAAAA,EAAA,cAAA4D,IAAA,EAAa,WAAAzC,GAAsB,aAAakB,KAC/CrC,gBAAAA,EAAA,cAAC,OAAI,EAAA,eAAaM,GAAQ,oBAAkBuD,GAAY,UAAU,WAAWb,EAAA,GAC1Ec,GAAYlD,GAAOC,GAAYH,CAAgB,GAChDV,gBAAAA,EAAA,cAAC,OAAI,EAAA,WAAWmD,GAAqB,KAAKhB,GAAW,OAAO,EAAE,UAAAwB,EAC5D,EAAA,GAAA3D,gBAAAA,EAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,MAAA8B;AAAA,MACA,cAAAvB;AAAA,MACA,IAAIM;AAAA,MACJ,WAAWuC;AAAA,MACX,KAAAlD;AAAA,MACA,oBAAkB,CAACD,EAAM,kBAAkB,KAAK,IAAIoC,CAAa,EAAE,KAAK,GAAG;AAAA,MAC3E,gBAAc,CAAC,CAACU;AAAA,MAEhB,WAAA1B;AAAA,MACA,UAAAC;AAAA,MACA,MAAAC;AAAA,MACA,cAAcC,KAA8B;AAAA,MAC5C,aAAAC;AAAA,MACA,UAAAC;AAAA,MACA,UAAAC;AAAA,MACA,UAAU+B;AAAA,MACT,GAAG7B;AAAA,IAAA;AAAA,EAAA,CAER,GACC1B,KACCH,gBAAAA,EAAA;AAAA,IAAC+D;AAAA,IAAA;AAAA,MACC,eAAA5D;AAAA,MACA,QAAQ8B,EAAc,SAAA,EAAW;AAAA,MACjC,SAAA7B;AAAA,MACA,MAAAM;AAAA,MACA,UAAAiD;AAAA,IAAA;AAAA,EAGN,CAAA,CACF;AAEJ,CAAC;AAED5D,EAAS,cAAc;AAEvB,MAAAiE,KAAejE;"}
1
+ {"version":3,"file":"Textarea.js","sources":["../../../src/components/Textarea/Textarea.tsx"],"sourcesContent":["import React, { useState, useRef, useEffect } from 'react';\n\nimport cn from 'classnames';\n\nimport { AnalyticsId, AVERAGE_CHARACTER_WIDTH_PX, FormMode } from '../../constants';\nimport { useUuid } from '../../hooks/useUuid';\nimport { getAriaDescribedBy } from '../../utils/accessibility';\nimport { uuid } from '../../utils/uuid';\nimport ErrorWrapper from '../ErrorWrapper';\nimport { renderLabel } from '../Label';\nimport MaxCharacters from '../MaxCharacters/MaxCharacters';\n\nimport styles from './styles.module.scss';\n\nexport interface TextareaProps\n extends Pick<\n React.InputHTMLAttributes<HTMLTextAreaElement>,\n | 'aria-describedby'\n | 'autoFocus'\n | 'disabled'\n | 'name'\n | 'autoComplete'\n | 'placeholder'\n | 'readOnly'\n | 'required'\n | 'defaultValue'\n | 'onChange'\n > {\n /** max character limit in textarea */\n maxCharacters?: number;\n /** The text is displayed in the end of the text-counter */\n maxText?: string;\n /** Width of textarea in characters (approximate) */\n width?: number;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** If true, the component will have a bottom margin. */\n marginBottom?: boolean;\n /** If true, the component will be transparent. */\n transparent?: boolean;\n /** Changes the visuals of the textarea */\n mode?: keyof typeof FormMode;\n /** Label of the input */\n label?: React.ReactNode;\n /** id of the textarea */\n textareaId?: string;\n /** max rows */\n maxRows?: number;\n /** min rows */\n minRows?: number;\n /** auto-grows until maxRows */\n grow?: boolean;\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}\n\nconst getTextareaMaxWidth = (characters: number): string => {\n const paddingWidth = '2rem';\n const scrollbarWidth = '16px';\n const borderWidth = '4px';\n\n return `calc(${characters * AVERAGE_CHARACTER_WIDTH_PX}px + ${paddingWidth} + ${scrollbarWidth} + ${borderWidth})`;\n};\n\nconst Textarea = React.forwardRef((props: TextareaProps, ref: React.Ref<HTMLTextAreaElement>) => {\n const {\n maxCharacters,\n maxText,\n width,\n testId,\n defaultValue,\n marginBottom: gutterBottom,\n transparent,\n mode = FormMode.onwhite,\n label,\n textareaId = uuid(),\n minRows = 3,\n maxRows = 10,\n grow,\n error,\n errorText,\n errorTextId,\n autoFocus,\n disabled,\n name,\n autoComplete = 'off',\n placeholder,\n readOnly,\n required,\n onChange,\n ...rest\n } = props;\n\n const [rows, setRows] = useState(minRows);\n const [textareaInput, setTextareaInput] = useState(defaultValue || '');\n const referanse = useRef<HTMLDivElement>(null);\n const errorTextUuid = useUuid(errorTextId);\n\n useEffect(() => {\n setTextareaInput(defaultValue || '');\n }, [defaultValue]);\n\n const resizeHeight = (target: HTMLTextAreaElement): void => {\n const textareaLineHeight = 28;\n\n const previousRows = target.rows;\n target.rows = minRows; // reset number of rows in textarea\n\n const currentRows = Math.floor((target.scrollHeight - 16) / textareaLineHeight); // scrollHeight - 16px of padding to calculate the rows\n\n if (currentRows === previousRows) {\n target.rows = currentRows;\n }\n\n if (currentRows >= maxRows) {\n target.rows = maxRows;\n target.scrollTop = target.scrollHeight;\n }\n\n if (currentRows < maxRows) {\n setRows(currentRows);\n } else {\n setRows(maxRows);\n }\n };\n\n const onDark = mode === FormMode.ondark;\n const onBlueberry = mode === FormMode.onblueberry;\n const maxCharactersExceeded = !!maxCharacters && textareaInput.toString().length > maxCharacters;\n const onError = mode === FormMode.oninvalid || !!errorText || !!error || maxCharactersExceeded;\n\n const textareaWrapperClass = cn(styles.textarea, {\n [styles['textarea--gutterBottom']]: gutterBottom,\n });\n\n const contentWrapperClass = cn(styles['input-container'], {\n [styles['input-container--transparent']]: transparent,\n [styles['input-container--on-blueberry']]: onBlueberry,\n [styles['input-container--on-dark']]: onDark,\n [styles['input-container--invalid']]: onError,\n [styles['input-container--disabled']]: props.disabled,\n });\n\n const textareaClass = cn(styles['input-container__input'], {\n [styles[`input-container__input--disabled`]]: props.disabled,\n });\n\n useEffect(() => {\n if (grow && referanse.current?.children && referanse.current?.children[0]) {\n const textarea = referanse.current?.children[0] as HTMLTextAreaElement;\n resizeHeight(textarea);\n }\n }, []);\n\n const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>): void => {\n if (grow) {\n resizeHeight(e.target);\n }\n setTextareaInput(e.target.value);\n };\n\n const onChangeHandler = (e: React.ChangeEvent<HTMLTextAreaElement>): void => {\n if (onChange) {\n onChange(e);\n }\n handleChange(e);\n };\n\n const maxWidth = width ? getTextareaMaxWidth(width) : undefined;\n\n return (\n <ErrorWrapper errorText={errorText} errorTextId={errorTextUuid}>\n <div data-testid={testId} data-analyticsid={AnalyticsId.Textarea} className={textareaWrapperClass}>\n {renderLabel(label, textareaId, mode as FormMode)}\n <div className={contentWrapperClass} ref={referanse} style={{ maxWidth }}>\n <textarea\n rows={rows}\n defaultValue={defaultValue}\n id={textareaId}\n className={textareaClass}\n ref={ref}\n aria-describedby={getAriaDescribedBy(props, errorTextUuid)}\n aria-invalid={!!onError}\n // eslint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={autoFocus}\n disabled={disabled}\n name={name}\n autoComplete={autoComplete ? autoComplete : undefined}\n placeholder={placeholder}\n readOnly={readOnly}\n required={required}\n onChange={onChangeHandler}\n {...rest}\n />\n </div>\n {maxCharacters && (\n <MaxCharacters\n maxCharacters={maxCharacters}\n length={textareaInput.toString().length}\n maxText={maxText}\n mode={mode}\n maxWidth={maxWidth}\n />\n )}\n </div>\n </ErrorWrapper>\n );\n});\n\nTextarea.displayName = 'Textarea';\n\nexport default Textarea;\n"],"names":["getTextareaMaxWidth","characters","AVERAGE_CHARACTER_WIDTH_PX","Textarea","React","props","ref","maxCharacters","maxText","width","testId","defaultValue","gutterBottom","transparent","mode","FormMode","label","textareaId","uuid","minRows","maxRows","grow","error","errorText","errorTextId","autoFocus","disabled","name","autoComplete","placeholder","readOnly","required","onChange","rest","rows","setRows","useState","textareaInput","setTextareaInput","referanse","useRef","errorTextUuid","useUuid","useEffect","resizeHeight","target","previousRows","currentRows","onDark","onBlueberry","maxCharactersExceeded","onError","textareaWrapperClass","cn","styles","contentWrapperClass","textareaClass","_a","_b","textarea","_c","handleChange","onChangeHandler","maxWidth","ErrorWrapper","AnalyticsId","renderLabel","getAriaDescribedBy","MaxCharacters","Textarea$1"],"mappings":";;;;;;;;;;AA4DA,MAA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tD,SACGL,gBAAAA,EAAA,cAAA4D,IAAA,EAAa,WAAAzC,GAAsB,aAAakB,KAC/CrC,gBAAAA,EAAA,cAAC,OAAI,EAAA,eAAaM,GAAQ,oBAAkBuD,GAAY,UAAU,WAAWb,EAAA,GAC1Ec,GAAYlD,GAAOC,GAAYH,CAAgB,GAChDV,gBAAAA,EAAA,cAAC,OAAI,EAAA,WAAWmD,GAAqB,KAAKhB,GAAW,OAAO,EAAE,UAAAwB,EAC5D,EAAA,GAAA3D,gBAAAA,EAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,MAAA8B;AAAA,MACA,cAAAvB;AAAA,MACA,IAAIM;AAAA,MACJ,WAAWuC;AAAA,MACX,KAAAlD;AAAA,MACA,oBAAkB6D,GAAmB9D,GAAOoC,CAAa;AAAA,MACzD,gBAAc,CAAC,CAACU;AAAA,MAEhB,WAAA1B;AAAA,MACA,UAAAC;AAAA,MACA,MAAAC;AAAA,MACA,cAAcC,KAA8B;AAAA,MAC5C,aAAAC;AAAA,MACA,UAAAC;AAAA,MACA,UAAAC;AAAA,MACA,UAAU+B;AAAA,MACT,GAAG7B;AAAA,IAAA;AAAA,EAAA,CAER,GACC1B,KACCH,gBAAAA,EAAA;AAAA,IAACgE;AAAA,IAAA;AAAA,MACC,eAAA7D;AAAA,MACA,QAAQ8B,EAAc,SAAA,EAAW;AAAA,MACjC,SAAA7B;AAAA,MACA,MAAAM;AAAA,MACA,UAAAiD;AAAA,IAAA;AAAA,EAGN,CAAA,CACF;AAEJ,CAAC;AAED5D,EAAS,cAAc;AAEvB,MAAAkE,KAAelE;"}
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "url": "git+https://github.com/helsenorge/designsystem.git"
8
8
  },
9
9
  "homepage": "https://helsenorge.design",
10
- "version": "7.3.1",
10
+ "version": "7.4.0",
11
11
  "author": "Helsenorge",
12
12
  "license": "MIT",
13
13
  "peerDependencies": {
@@ -0,0 +1,3 @@
1
+ /* This file was generated by Supernova and should not be changed manually */
2
+ @import "./colors.css";
3
+ @import "./typography.css";
@@ -0,0 +1,173 @@
1
+ /* stylelint-disable color-hex-length */
2
+
3
+ /* This file was generated by Supernova and should not be changed manually */
4
+ :root {
5
+ --core-color-black: #000000;
6
+ --core-color-white: #ffffff;
7
+ --core-color-blueberry-50: #e4f7f9;
8
+ --core-color-neutral-500: #989693;
9
+ --core-color-neutral-700: #62625f;
10
+ --color-action-text-ondark: #ffffff;
11
+
12
+ /* Hoverfarge for bakgrunn på interaktive elementer - onLight */
13
+ --color-action-background-transparent-onlight-hover: #126f8721;
14
+
15
+ /* Hoverfarge for bakgrunn på interaktive elementer - onLight selected */
16
+ --color-action-background-transparent-onlight-hoverselected: #126f872b;
17
+ --color-notification-background-info: #e4f7f9;
18
+ --color-notification-background-error: #fff2ea;
19
+ --color-destructive-graphics-normal: #c83521;
20
+ --color-base-text-onlight: #000000;
21
+ --color-action-background-ondark: #ffffff;
22
+ --color-action-border-ondark: #ffffff;
23
+ --color-action-border-ondark-focus: #ffffff;
24
+ --color-action-graphics-ondark: #ffffff;
25
+ --color-base-text-ondark: #ffffff;
26
+ --color-base-background-neutral: #f5f3f3;
27
+ --color-base-background-white: #ffffff;
28
+ --color-base-graphics-ondark: #ffffff;
29
+ --color-disabled-text-ondark: #ffffff;
30
+ --color-action-border-onlight: #188097;
31
+ --color-action-border-onlight-hover: #08667c;
32
+ --color-action-border-onlight-focus: #000000;
33
+ --color-action-text-onlight: #126f87;
34
+ --color-action-text-onlight-hover: #08667c;
35
+ --color-action-graphics-onlight: #188097;
36
+ --color-action-graphics-onlight-hover: #126f87;
37
+ --color-action-graphics-ondark-hover: #e4f7f9;
38
+ --color-action-background-ondark-hover: #e4f7f9;
39
+ --color-action-background-ondark-selected: #cae7ed;
40
+ --color-action-background-ondark-hoverselected: #afdae3;
41
+ --color-action-background-onlight: #188097;
42
+ --color-action-background-onlight-hover: #08667c;
43
+ --color-notification-background-warning: #fdf8df;
44
+ --color-notification-background-success: #e6f8ee;
45
+ --color-notification-border-info: #08667c;
46
+ --color-notification-border-error: #a31f0e;
47
+ --color-notification-border-warning: #ab7c00;
48
+ --color-notification-border-success: #078141;
49
+ --color-notification-graphics-info: #08667c;
50
+ --color-notification-graphics-error: #a31f0e;
51
+ --color-notification-graphics-warning: #ab7c00;
52
+ --color-notification-graphics-success: #078141;
53
+ --color-notification-status-warning: #ebc840;
54
+ --color-notification-status-success: #099150;
55
+ --color-destructive-graphics-hover: #b62e1c;
56
+ --color-destructive-text-normal: #b62e1c;
57
+ --color-destructive-text-hover: #a31f0e;
58
+ --color-disabled-background: #d6d4d3;
59
+ --color-disabled-text: #62625f;
60
+ --color-disabled-border: #7d7c79;
61
+ --color-disabled-graphics: #62625f;
62
+ --color-disabled-border-ondark: #d6d4d3;
63
+ --color-disabled-graphics-ondark: #d6d4d3;
64
+ --color-base-background-blueberry: #e4f7f9;
65
+ --color-base-background-cherry: #fff2ea;
66
+ --color-base-background-dark-blueberry: #188097;
67
+ --color-base-background-dark-cherry: #c83521;
68
+ --color-base-graphics-onlight: #000000;
69
+ --color-base-border-ondark: #d6d4d3;
70
+ --color-base-border-onlight: #989693;
71
+ --color-base-border-onlight-emphasized: #62625f;
72
+ --color-help-background: #efe4fd;
73
+ --color-help-graphics: #5b22a6;
74
+ --color-help-border: #5b22a6;
75
+ --core-color-blueberry-100: #cae7ed;
76
+ --core-color-blueberry-200: #afdae3;
77
+ --core-color-blueberry-300: #7abecc;
78
+ --core-color-blueberry-400: #58aabb;
79
+ --core-color-blueberry-500: #188097;
80
+ --core-color-blueberry-600: #126f87;
81
+ --core-color-blueberry-700: #08667c;
82
+ --core-color-blueberry-800: #06596c;
83
+ --core-color-blueberry-900: #084350;
84
+ --core-color-neutral-50: #f5f3f3;
85
+ --core-color-neutral-100: #eae7e7;
86
+ --core-color-neutral-200: #d6d4d3;
87
+ --core-color-neutral-300: #bdbab9;
88
+ --core-color-neutral-400: #aaa8a6;
89
+ --core-color-neutral-600: #7d7c79;
90
+ --core-color-neutral-800: #474745;
91
+ --core-color-neutral-900: #2b2c2b;
92
+ --core-color-banana-50: #fdf8df;
93
+ --core-color-banana-100: #fcf2bf;
94
+ --core-color-banana-200: #f9ea9f;
95
+ --core-color-banana-300: #f5e080;
96
+ --core-color-banana-400: #ebc840;
97
+ --core-color-banana-500: #ddab06;
98
+ --core-color-banana-600: #c59302;
99
+ --core-color-banana-700: #ab7c00;
100
+ --core-color-banana-800: #916500;
101
+ --core-color-banana-900: #764f00;
102
+ --core-color-cherry-50: #fff2ea;
103
+ --core-color-cherry-100: #f7e1d2;
104
+ --core-color-cherry-200: #eec0a5;
105
+ --core-color-cherry-300: #e39376;
106
+ --core-color-cherry-400: #d56147;
107
+ --core-color-cherry-500: #c83521;
108
+ --core-color-cherry-600: #b62e1c;
109
+ --core-color-cherry-700: #a31f0e;
110
+ --core-color-cherry-800: #912112;
111
+ --core-color-cherry-900: #7e1c0e;
112
+ --core-color-kiwi-50: #e6f8ee;
113
+ --core-color-kiwi-100: #c2edd6;
114
+ --core-color-kiwi-200: #9de2bf;
115
+ --core-color-kiwi-300: #79d6aa;
116
+ --core-color-kiwi-400: #56ca96;
117
+ --core-color-kiwi-500: #33be84;
118
+ --core-color-kiwi-600: #10b172;
119
+ --core-color-kiwi-700: #0ca161;
120
+ --core-color-kiwi-800: #099150;
121
+ --core-color-kiwi-900: #078141;
122
+ --core-color-plum-50: #efe4fd;
123
+ --core-color-plum-100: #d7bdf9;
124
+ --core-color-plum-200: #bf98f3;
125
+ --core-color-plum-300: #a875eb;
126
+ --core-color-plum-400: #9153e2;
127
+ --core-color-plum-500: #7a33d7;
128
+ --core-color-plum-600: #6a2abf;
129
+ --core-color-plum-700: #5b22a6;
130
+ --core-color-plum-800: #4c1b8c;
131
+ --core-color-plum-900: #3c1471;
132
+ --color-destructive-background-emphasized: #f7e1d2;
133
+ --color-destructive-background-normal: #fff2ea;
134
+ --brandcolor-white: #ffffff;
135
+ --brandcolor-black: #000000;
136
+ --brandcolor-neutral-verylight: #f5f3f3;
137
+ --brandcolor-neutral-light: #eae7e7;
138
+ --brandcolor-neutral-mediumlight: #d6d4d3;
139
+ --brandcolor-neutral-medium: #989693;
140
+ --brandcolor-neutral-dark: #62625f;
141
+ --brandcolor-neutral-verydark: #2b2c2b;
142
+ --brandcolor-blueberry-verylight: #e4f7f9;
143
+ --brandcolor-blueberry-light: #cae7ed;
144
+ --brandcolor-blueberry-mediumlight: #afdae3;
145
+ --brandcolor-blueberry-medium: #188097;
146
+ --brandcolor-blueberry-mediumdark: #126f87;
147
+ --brandcolor-blueberry-dark: #08667c;
148
+ --brandcolor-cherry-verylight: #fff2ea;
149
+ --brandcolor-cherry-light: #f7e1d2;
150
+ --brandcolor-cherry-medium: #c83521;
151
+ --brandcolor-cherry-mediumdark: #b62e1c;
152
+ --brandcolor-cherry-dark: #a31f0e;
153
+ --color-notification-status-info: #188097;
154
+ --color-notification-status-error: #c83521;
155
+ --color-destructive-border-normal: #c83521;
156
+ --color-action-border-ondark-hover: #e4f7f9;
157
+
158
+ /* Hoverfarge for bakgrunn på interaktive elementer - onDark */
159
+ --color-action-background-transparent-ondark-hover: #00000026;
160
+
161
+ /* Hoverfarge for bakgrunn på interaktive elementer - onDark selected */
162
+ --color-action-background-transparent-ondark-hoverselected: #00000040;
163
+ --color-base-background-dark-neutral: #2b2c2b;
164
+
165
+ /* Placeholdertext in input- and textarea-controls */
166
+ --color-placeholder-text-onlight: #62625f;
167
+ --color-base-border-onlight-subtle: #d6d4d3;
168
+ --color-base-border-neutral: #d6d4d3;
169
+
170
+ /* Subtle border for Blueberry 50 background */
171
+ --color-base-border-blueberry: #afdae3;
172
+ --color-base-border-cherry: #eec0a5;
173
+ }
@@ -6,4 +6,16 @@ interface AriaLabelAttributesConfig {
6
6
  }
7
7
  export type AriaLabelAttributes = Pick<AriaAttributes, 'aria-label' | 'aria-labelledby'>;
8
8
  export declare const getAriaLabelAttributes: (config: AriaLabelAttributesConfig) => AriaLabelAttributes | undefined;
9
+ export interface ErrorAriaProps {
10
+ 'aria-describedby'?: string;
11
+ errorText?: string;
12
+ errorTextId?: string;
13
+ }
14
+ /**
15
+ * Get IDs to be used with aria-describedby in form components like <Input />
16
+ * @param props Props from form component
17
+ * @param errorTextUuid Unique ID of the form component's error text
18
+ * @returns Element IDs or undefined if there is no aria-description
19
+ */
20
+ export declare const getAriaDescribedBy: (props: ErrorAriaProps, errorTextUuid?: string) => string | undefined;
9
21
  export {};
@@ -1,19 +1,28 @@
1
- const l = (a) => {
2
- const { label: r, id: e, prefer: i = "id" } = a;
3
- if (e && i === "id")
1
+ const l = (e) => {
2
+ const { label: i, id: r, prefer: a = "id" } = e;
3
+ if (r && a === "id")
4
4
  return {
5
- "aria-labelledby": e
5
+ "aria-labelledby": r
6
6
  };
7
- if (r)
7
+ if (i)
8
8
  return {
9
- "aria-label": r
9
+ "aria-label": i
10
10
  };
11
- if (e)
11
+ if (r)
12
12
  return {
13
- "aria-labelledby": e
13
+ "aria-labelledby": r
14
14
  };
15
+ }, b = (e, i) => {
16
+ const r = e["aria-describedby"], t = !!(e.errorText || e.errorTextId) ? i : void 0;
17
+ if (r && !t)
18
+ return r;
19
+ if (!r && t)
20
+ return t;
21
+ if (r && t)
22
+ return r + " " + t;
15
23
  };
16
24
  export {
25
+ b as getAriaDescribedBy,
17
26
  l as getAriaLabelAttributes
18
27
  };
19
28
  //# sourceMappingURL=accessibility.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"accessibility.js","sources":["../../src/utils/accessibility.ts"],"sourcesContent":["import { AriaAttributes } from 'react';\n\ninterface AriaLabelAttributesConfig {\n label?: string;\n id?: string;\n prefer?: 'id' | 'label';\n}\n\nexport type AriaLabelAttributes = Pick<AriaAttributes, 'aria-label' | 'aria-labelledby'>;\n\nexport const getAriaLabelAttributes = (config: AriaLabelAttributesConfig): AriaLabelAttributes | undefined => {\n const { label, id, prefer = 'id' } = config;\n\n if (id && prefer === 'id') {\n return {\n 'aria-labelledby': id,\n };\n }\n\n if (label) {\n return {\n 'aria-label': label,\n };\n }\n\n if (id) {\n return {\n 'aria-labelledby': id,\n };\n }\n};\n"],"names":["getAriaLabelAttributes","config","label","id","prefer"],"mappings":"AAUa,MAAAA,IAAyB,CAACC,MAAuE;AAC5G,QAAM,EAAE,OAAAC,GAAO,IAAAC,GAAI,QAAAC,IAAS,SAASH;AAEjC,MAAAE,KAAMC,MAAW;AACZ,WAAA;AAAA,MACL,mBAAmBD;AAAA,IAAA;AAIvB,MAAID;AACK,WAAA;AAAA,MACL,cAAcA;AAAA,IAAA;AAIlB,MAAIC;AACK,WAAA;AAAA,MACL,mBAAmBA;AAAA,IAAA;AAGzB;"}
1
+ {"version":3,"file":"accessibility.js","sources":["../../src/utils/accessibility.ts"],"sourcesContent":["import { AriaAttributes } from 'react';\n\ninterface AriaLabelAttributesConfig {\n label?: string;\n id?: string;\n prefer?: 'id' | 'label';\n}\n\nexport type AriaLabelAttributes = Pick<AriaAttributes, 'aria-label' | 'aria-labelledby'>;\n\nexport const getAriaLabelAttributes = (config: AriaLabelAttributesConfig): AriaLabelAttributes | undefined => {\n const { label, id, prefer = 'id' } = config;\n\n if (id && prefer === 'id') {\n return {\n 'aria-labelledby': id,\n };\n }\n\n if (label) {\n return {\n 'aria-label': label,\n };\n }\n\n if (id) {\n return {\n 'aria-labelledby': id,\n };\n }\n};\n\nexport interface ErrorAriaProps {\n 'aria-describedby'?: string;\n errorText?: string;\n errorTextId?: string;\n}\n\n/**\n * Get IDs to be used with aria-describedby in form components like <Input />\n * @param props Props from form component\n * @param errorTextUuid Unique ID of the form component's error text\n * @returns Element IDs or undefined if there is no aria-description\n */\nexport const getAriaDescribedBy = (props: ErrorAriaProps, errorTextUuid?: string): string | undefined => {\n const ariaDescribedBy: string | undefined = props['aria-describedby'];\n const hasErrorText: boolean = !!(props.errorText || props.errorTextId);\n const errorTextId: string | undefined = hasErrorText ? errorTextUuid : undefined;\n\n if (ariaDescribedBy && !errorTextId) {\n return ariaDescribedBy;\n } else if (!ariaDescribedBy && errorTextId) {\n return errorTextId;\n } else if (ariaDescribedBy && errorTextId) {\n return ariaDescribedBy + ' ' + errorTextId;\n }\n};\n"],"names":["getAriaLabelAttributes","config","label","id","prefer","getAriaDescribedBy","props","errorTextUuid","ariaDescribedBy","errorTextId"],"mappings":"AAUa,MAAAA,IAAyB,CAACC,MAAuE;AAC5G,QAAM,EAAE,OAAAC,GAAO,IAAAC,GAAI,QAAAC,IAAS,SAASH;AAEjC,MAAAE,KAAMC,MAAW;AACZ,WAAA;AAAA,MACL,mBAAmBD;AAAA,IAAA;AAIvB,MAAID;AACK,WAAA;AAAA,MACL,cAAcA;AAAA,IAAA;AAIlB,MAAIC;AACK,WAAA;AAAA,MACL,mBAAmBA;AAAA,IAAA;AAGzB,GAcaE,IAAqB,CAACC,GAAuBC,MAA+C;AACjG,QAAAC,IAAsCF,EAAM,kBAAkB,GAE9DG,IADwB,CAAC,EAAEH,EAAM,aAAaA,EAAM,eACHC,IAAgB;AAEnE,MAAAC,KAAmB,CAACC;AACf,WAAAD;AACT,MAAW,CAACA,KAAmBC;AACtB,WAAAA;AACT,MAAWD,KAAmBC;AAC5B,WAAOD,IAAkB,MAAMC;AAEnC;"}