@helsenorge/designsystem-react 9.0.0-beta.0 → 9.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -3
- package/FormGroup.js +45 -38
- package/FormGroup.js.map +1 -1
- package/Input.js.map +1 -1
- package/Label.js +58 -54
- package/Label.js.map +1 -1
- package/Select.js +45 -36
- package/Select.js.map +1 -1
- package/Slider.js +218 -0
- package/Slider.js.map +1 -0
- package/Spacer.js.map +1 -1
- package/StatusDot.js +12 -12
- package/StatusDot.js.map +1 -1
- package/__mocks__/matchMedia.js.map +1 -1
- package/__mocks__/useHover.js +2 -3
- package/__mocks__/useHover.js.map +1 -1
- package/__mocks__/useLayoutEvent.js +2 -3
- package/__mocks__/useLayoutEvent.js.map +1 -1
- package/__mocks__/useOutsideEvent.js +2 -3
- package/__mocks__/useOutsideEvent.js.map +1 -1
- package/__mocks__/usePseudoClasses.js +2 -3
- package/__mocks__/usePseudoClasses.js.map +1 -1
- package/__mocks__/useSize.js +2 -3
- package/__mocks__/useSize.js.map +1 -1
- package/__mocks__/uuid.js +2 -3
- package/__mocks__/uuid.js.map +1 -1
- package/components/AnchorLink/AnchorLink.test.d.ts +1 -0
- package/components/Avatar/Avatar.test.d.ts +1 -0
- package/components/Badge/Badge.test.d.ts +1 -0
- package/components/Button/Button.test.d.ts +1 -0
- package/components/Checkbox/Checkbox.test.d.ts +1 -0
- package/components/Chip/Chip.test.d.ts +1 -0
- package/components/Close/Close.test.d.ts +1 -0
- package/components/DictionaryTrigger/DictionaryTrigger.test.d.ts +1 -0
- package/components/Dropdown/Dropdown.test.d.ts +1 -0
- package/components/Duolist/Duolist.test.d.ts +1 -0
- package/components/EmptyState/EmptyState.test.d.ts +1 -0
- package/components/ErrorWrapper/ErrorWrapper.test.d.ts +1 -0
- package/components/Expander/Expander.test.d.ts +1 -0
- package/components/ExpanderHierarchy/ExpanderHierarchy.test.d.ts +1 -0
- package/components/ExpanderList/ExpanderList.test.d.ts +1 -0
- package/components/ExpanderList/styles.module.scss +5 -0
- package/components/EyebrowHeader/EyebrowHeader.test.d.ts +1 -0
- package/components/FormGroup/FormGroup.test.d.ts +1 -0
- package/components/FormLayout/FormLayout.test.d.ts +1 -0
- package/components/HelpBubble/HelpBubble.test.d.ts +1 -0
- package/components/HelpPanel/HelpPanel.test.d.ts +1 -0
- package/components/HelpQuestion/HelpQuestion.test.d.ts +1 -0
- package/components/HighlightPanel/HighlightPanel.test.d.ts +1 -0
- package/components/HorizontalScroll/HorizontalScroll.test.d.ts +1 -0
- package/components/Icon/Icon.test.d.ts +1 -0
- package/components/Illustration/Illustration.test.d.ts +1 -0
- package/components/Input/Input.d.ts +1 -1
- package/components/Input/Input.test.d.ts +1 -0
- package/components/Label/Label.d.ts +5 -2
- package/components/Label/Label.test.d.ts +1 -0
- package/components/LazyIcon/LazyIcon.test.d.ts +1 -0
- package/components/LazyIllustration/LazyIllustration.test.d.ts +1 -0
- package/components/LinkList/LinkList.test.d.ts +1 -0
- package/components/List/List.test.d.ts +1 -0
- package/components/Loader/Loader.test.d.ts +1 -0
- package/components/Logo/Logo.test.d.ts +1 -0
- package/components/MaxCharacters/MaxCharacters.test.d.ts +1 -0
- package/components/Modal/Modal.test.d.ts +1 -0
- package/components/NotificationPanel/NotificationPanel.test.d.ts +1 -0
- package/components/Panel/Panel.test.d.ts +1 -0
- package/components/PanelList/PanelList.test.d.ts +1 -0
- package/components/PopMenu/PopMenu.test.d.ts +1 -0
- package/components/PopOver/PopOver.test.d.ts +1 -0
- package/components/Progressbar/Progressbar.test.d.ts +1 -0
- package/components/PromoPanel/PromoPanel.test.d.ts +1 -0
- package/components/RadioButton/RadioButton.test.d.ts +1 -0
- package/components/Select/Select.test.d.ts +1 -0
- package/components/ServiceMessage/ServiceMessage.test.d.ts +1 -0
- package/components/SharingStatus/SharingStatus.test.d.ts +1 -0
- package/components/Slider/Slider.d.ts +9 -4
- package/components/Slider/Slider.test.d.ts +1 -0
- package/components/Slider/index.js +3 -189
- package/components/Slider/index.js.map +1 -1
- package/components/Slider/styles.module.scss +19 -6
- package/components/Slider/styles.module.scss.d.ts +3 -0
- package/components/Spacer/Spacer.test.d.ts +1 -0
- package/components/StatusDot/StatusDot.test.d.ts +1 -0
- package/components/Step/Step.test.d.ts +1 -0
- package/components/StepButtons/StepButtons.test.d.ts +1 -0
- package/components/Stepper/Stepper.test.d.ts +1 -0
- package/components/Table/Table.test.d.ts +1 -0
- package/components/Tabs/Tabs.test.d.ts +1 -0
- package/components/Tag/Tag.test.d.ts +1 -0
- package/components/TagList/TagList.test.d.ts +1 -0
- package/components/Textarea/Textarea.test.d.ts +1 -0
- package/components/Tile/Tile.test.d.ts +1 -0
- package/components/Title/Title.test.d.ts +1 -0
- package/components/Toggle/Toggle.test.d.ts +1 -0
- package/components/Toggle/index.js +424 -432
- package/components/Toggle/index.js.map +1 -1
- package/components/Tooltip/Tooltip.test.d.ts +1 -0
- package/components/Trigger/Trigger.test.d.ts +1 -0
- package/components/Validation/Validation.test.d.ts +1 -0
- package/components/Validation/ValidationSummary.test.d.ts +1 -0
- package/components/Validation/index.js +15 -14
- package/components/Validation/index.js.map +1 -1
- package/docs/FormExample/FormExample.d.ts +1 -0
- package/hoc/withBreakpoint/withBreakpoint.test.d.ts +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
## [8.7.0](https://github.com/helsenorge/designsystem/branchCompare?baseVersion=GTv8.6.0&targetVersion=GTv8.7.0) (2024-10-17)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
- **datetime:** får onblur prop ([31fe602](https://github.com/helsenorge/designsystem/commit/31fe602a68f12c39e48a55b5559fcd812be97785)),
|
|
6
|
+
closes [#334254](https://github.com/helsenorge/designsystem/issues/334254)
|
|
7
|
+
|
|
8
|
+
## [8.6.0](https://github.com/helsenorge/designsystem/branchCompare?baseVersion=GTv8.5.1&targetVersion=GTv8.6.0) (2024-10-09)
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
- **datepicker:** legg til prop for å sette posisjon på datepicker popup
|
|
13
|
+
([0f392ed](https://github.com/helsenorge/designsystem/commit/0f392ed1f5fc76be0fbfdeb5262f64071cbf4dc0)), closes
|
|
14
|
+
[#326998](https://github.com/helsenorge/designsystem/issues/326998)
|
|
15
|
+
- **datetime:** value prop og defaultvalue settes riktig
|
|
16
|
+
([a3d8617](https://github.com/helsenorge/designsystem/commit/a3d86173269cd5a1dd9d8cd1f13a2512b2fb87fd)), closes
|
|
17
|
+
[#332561](https://github.com/helsenorge/designsystem/issues/332561)
|
|
18
|
+
- **label:** gi mulighet for å rendre label med andre tags
|
|
19
|
+
([9f952dd](https://github.com/helsenorge/designsystem/commit/9f952ddd0eac84e1426d070685998e950fa9e9f8)), closes
|
|
20
|
+
[#331803](https://github.com/helsenorge/designsystem/issues/331803)
|
|
21
|
+
- **tabs:** endre default touch behaviour til å være none
|
|
22
|
+
([4101ce2](https://github.com/helsenorge/designsystem/commit/4101ce2a85f84e26b9fcfd61990ca8792f72b55c)), closes
|
|
23
|
+
[#331142](https://github.com/helsenorge/designsystem/issues/331142)
|
|
24
|
+
|
|
1
25
|
## [8.5.1](https://github.com/helsenorge/designsystem/branchCompare?baseVersion=GTv8.5.0&targetVersion=GTv8.5.1) (2024-09-25)
|
|
2
26
|
|
|
3
27
|
### Bug Fixes
|
|
@@ -1781,12 +1805,12 @@ Dette er fordi vi skal kunne dynamisk importere alt som ligger i Icons, så da b
|
|
|
1781
1805
|
|
|
1782
1806
|
### Bug Fixes
|
|
1783
1807
|
|
|
1784
|
-
- panel har avstand fra tittel til badge
|
|
1785
|
-
([09034c4](https://github.com/helsenorge/designsystem/commit/09034c4844408c7cfe8f65d7a1a0d82a7828c2ef)), closes
|
|
1786
|
-
[#282359](https://github.com/helsenorge/designsystem/issues/282359)
|
|
1787
1808
|
- økt kontrast på understreking av lenker
|
|
1788
1809
|
([50b7fa4](https://github.com/helsenorge/designsystem/commit/50b7fa47fb44cb7d75fb877bd53e2309b35e1e21)), closes
|
|
1789
1810
|
[#229049](https://github.com/helsenorge/designsystem/issues/229049)
|
|
1811
|
+
- panel har avstand fra tittel til badge
|
|
1812
|
+
([09034c4](https://github.com/helsenorge/designsystem/commit/09034c4844408c7cfe8f65d7a1a0d82a7828c2ef)), closes
|
|
1813
|
+
[#282359](https://github.com/helsenorge/designsystem/issues/282359)
|
|
1790
1814
|
|
|
1791
1815
|
## [1.2.2](https://github.com/helsenorge/designsystem/branchCompare?baseVersion=GTv1.2.1&targetVersion=GTv1.2.2) (2022-08-31)
|
|
1792
1816
|
|
package/FormGroup.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsxs as
|
|
1
|
+
import { jsxs as p, jsx as d } from "react/jsx-runtime";
|
|
2
2
|
import t, { useState as A } from "react";
|
|
3
3
|
import f from "classnames";
|
|
4
4
|
import { FormOnColor as E, FormSize as k, AnalyticsId as D } from "./constants.js";
|
|
@@ -6,104 +6,111 @@ import { useUuid as F } from "./hooks/useUuid.js";
|
|
|
6
6
|
import { isComponent as s } from "./utils/component.js";
|
|
7
7
|
import { C as H } from "./Checkbox.js";
|
|
8
8
|
import { E as O } from "./ErrorWrapper.js";
|
|
9
|
-
import { F as
|
|
10
|
-
import { I as
|
|
11
|
-
import { R as
|
|
12
|
-
import { S as
|
|
13
|
-
import {
|
|
14
|
-
import { T as
|
|
9
|
+
import { F as q } from "./FormLayout.js";
|
|
10
|
+
import { I as J } from "./Input.js";
|
|
11
|
+
import { R as K, g as P } from "./RadioButton.js";
|
|
12
|
+
import { S as Q } from "./Select.js";
|
|
13
|
+
import { S as V } from "./Slider.js";
|
|
14
|
+
import { T as X } from "./Textarea.js";
|
|
15
|
+
import { T as Y } from "./Title.js";
|
|
15
16
|
import i from "./components/FormGroup/styles.module.scss";
|
|
16
17
|
const G = t.forwardRef((r, R) => {
|
|
17
18
|
const {
|
|
18
|
-
className:
|
|
19
|
-
fieldsetClassName:
|
|
20
|
-
onColor:
|
|
19
|
+
className: S,
|
|
20
|
+
fieldsetClassName: y,
|
|
21
|
+
onColor: n = E.onwhite,
|
|
21
22
|
size: m = k.medium,
|
|
22
23
|
error: o,
|
|
23
|
-
errorTextId:
|
|
24
|
+
errorTextId: _,
|
|
24
25
|
name: l,
|
|
25
26
|
htmlMarkup: c = "fieldset",
|
|
26
27
|
renderError: b = !0,
|
|
27
28
|
errorWrapperClassName: w,
|
|
28
29
|
errorWrapperTestId: W
|
|
29
|
-
} = r, [v, L] = A(), j = F(),
|
|
30
|
+
} = r, [v, L] = A(), j = F(), a = F(_), I = n === E.ondark, z = m === k.large, B = f(i["form-group-wrapper"], S), M = f({
|
|
30
31
|
[i["form-group-wrapper__title--on-dark"]]: I && !o
|
|
31
32
|
}), g = f(i["field-set__legend"], {
|
|
32
33
|
[i["field-set__legend--on-dark"]]: I && !o
|
|
33
|
-
}), C = f(i["field-set"],
|
|
34
|
-
if (s(e,
|
|
34
|
+
}), C = f(i["field-set"], y), u = (e, U) => {
|
|
35
|
+
if (s(e, q))
|
|
35
36
|
return t.cloneElement(e, {
|
|
36
37
|
size: m,
|
|
37
38
|
mapHelper: u
|
|
38
39
|
});
|
|
39
40
|
if (s(e, G))
|
|
40
41
|
return t.cloneElement(e, {
|
|
41
|
-
onColor:
|
|
42
|
+
onColor: n,
|
|
42
43
|
size: m,
|
|
43
44
|
error: o,
|
|
44
45
|
renderError: !1,
|
|
45
|
-
errorTextId:
|
|
46
|
+
errorTextId: a
|
|
46
47
|
});
|
|
47
48
|
if (s(e, H))
|
|
48
49
|
return t.cloneElement(e, {
|
|
49
50
|
name: l ?? e.props.name,
|
|
50
|
-
onColor:
|
|
51
|
+
onColor: n,
|
|
51
52
|
size: m,
|
|
52
53
|
error: !!o,
|
|
53
|
-
errorTextId:
|
|
54
|
+
errorTextId: a
|
|
54
55
|
});
|
|
55
|
-
if (s(e,
|
|
56
|
+
if (s(e, K)) {
|
|
56
57
|
const T = typeof e.props.inputId > "u" ? j + U : e.props.inputId;
|
|
57
58
|
return t.cloneElement(e, {
|
|
58
59
|
inputId: T,
|
|
59
60
|
name: l ?? e.props.name,
|
|
60
|
-
onColor:
|
|
61
|
+
onColor: n,
|
|
61
62
|
size: m,
|
|
62
63
|
onChange: (N) => {
|
|
63
64
|
L(N.target.id), e.props.onChange && e.props.onChange(N);
|
|
64
65
|
},
|
|
65
66
|
error: !!o,
|
|
66
|
-
errorTextId:
|
|
67
|
-
labelClassNames:
|
|
67
|
+
errorTextId: a,
|
|
68
|
+
labelClassNames: P(T, n, z, v)
|
|
68
69
|
});
|
|
69
70
|
} else {
|
|
70
|
-
if (s(e,
|
|
71
|
+
if (s(e, J))
|
|
71
72
|
return t.cloneElement(e, {
|
|
72
73
|
name: l ?? e.props.name,
|
|
73
|
-
onColor:
|
|
74
|
+
onColor: n,
|
|
74
75
|
size: m,
|
|
75
76
|
error: !!o,
|
|
76
|
-
errorTextId:
|
|
77
|
+
errorTextId: a
|
|
78
|
+
});
|
|
79
|
+
if (s(e, X))
|
|
80
|
+
return t.cloneElement(e, {
|
|
81
|
+
name: l ?? e.props.name,
|
|
82
|
+
onColor: n,
|
|
83
|
+
error: !!o,
|
|
84
|
+
errorTextId: a
|
|
77
85
|
});
|
|
78
86
|
if (s(e, Q))
|
|
79
87
|
return t.cloneElement(e, {
|
|
80
88
|
name: l ?? e.props.name,
|
|
81
|
-
onColor:
|
|
89
|
+
onColor: n,
|
|
82
90
|
error: !!o,
|
|
83
|
-
errorTextId:
|
|
91
|
+
errorTextId: a
|
|
84
92
|
});
|
|
85
|
-
if (s(e,
|
|
93
|
+
if (s(e, V))
|
|
86
94
|
return t.cloneElement(e, {
|
|
87
95
|
name: l ?? e.props.name,
|
|
88
|
-
onColor: a,
|
|
89
96
|
error: !!o,
|
|
90
|
-
errorTextId:
|
|
97
|
+
errorTextId: a
|
|
91
98
|
});
|
|
92
99
|
}
|
|
93
100
|
return e;
|
|
94
|
-
}, x = () => /* @__PURE__ */
|
|
95
|
-
c === "div" && /* @__PURE__ */
|
|
96
|
-
r.legend && /* @__PURE__ */
|
|
101
|
+
}, x = () => /* @__PURE__ */ p("div", { children: [
|
|
102
|
+
c === "div" && /* @__PURE__ */ p("div", { className: C, children: [
|
|
103
|
+
r.legend && /* @__PURE__ */ d("h5", { className: g, children: r.legend }),
|
|
97
104
|
t.Children.map(r.children, u)
|
|
98
105
|
] }),
|
|
99
|
-
c === "fieldset" && /* @__PURE__ */
|
|
100
|
-
r.legend && /* @__PURE__ */
|
|
106
|
+
c === "fieldset" && /* @__PURE__ */ p("fieldset", { name: r.fieldsetName, className: C, children: [
|
|
107
|
+
r.legend && /* @__PURE__ */ d("legend", { className: g, children: r.legend }),
|
|
101
108
|
t.Children.map(r.children, u)
|
|
102
109
|
] })
|
|
103
110
|
] });
|
|
104
|
-
return /* @__PURE__ */
|
|
105
|
-
r.title && /* @__PURE__ */
|
|
106
|
-
b ? /* @__PURE__ */
|
|
111
|
+
return /* @__PURE__ */ p("div", { "data-testid": r.testId, "data-analyticsid": D.FormGroup, className: B, ref: R, tabIndex: -1, children: [
|
|
112
|
+
r.title && /* @__PURE__ */ d(Y, { className: M, htmlMarkup: "h4", appearance: "title4", margin: { marginTop: 0, marginBottom: o ? 1 : 2 }, children: r.title }),
|
|
113
|
+
b ? /* @__PURE__ */ d(O, { className: w, errorText: o, testId: W, errorTextId: a, children: x() }) : x()
|
|
107
114
|
] });
|
|
108
115
|
});
|
|
109
116
|
G.displayName = "FormGroup";
|
package/FormGroup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormGroup.js","sources":["../src/components/FormGroup/FormGroup.tsx"],"sourcesContent":["import React, { useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport { AnalyticsId, FormOnColor, FormSize } from '../../constants';\nimport { useUuid } from '../../hooks/useUuid';\nimport { isComponent } from '../../utils/component';\nimport Checkbox, { CheckboxProps } from '../Checkbox/Checkbox';\nimport ErrorWrapper from '../ErrorWrapper';\nimport FormLayout, { FormLayoutProps } from '../FormLayout';\nimport Input, { InputProps } from '../Input/Input';\nimport RadioButton, { RadioButtonProps, getRadioLabelClasses } from '../RadioButton/RadioButton';\nimport Select, { SelectProps } from '../Select';\nimport Textarea, { TextareaProps } from '../Textarea';\nimport Title from '../Title';\n\nimport formGroupStyles from './styles.module.scss';\n\nexport type FormGroupTags = 'fieldset' | 'div';\n\nexport interface FormGroupProps {\n /** title for the the fieldset */\n title?: string;\n /** text placed in the legend tag of the fieldset */\n legend?: string;\n /** Items in the FormGroup component */\n children?: React.ReactNode;\n /** Adds custom classes to the element. */\n className?: string;\n /** Adds custom classes to the errorWrapper. */\n errorWrapperClassName?: string;\n /** Adds custom classes to the fieldset element. */\n fieldsetClassName?: string;\n /** Changes the visuals of the formgroup */\n onColor?: keyof typeof FormOnColor;\n /** Changes the visuals of the formgroup */\n size?: keyof typeof FormSize;\n /** Error message */\n error?: string;\n /** Error text id */\n errorTextId?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Sets the data-testid attribute for the error-wrapper. */\n errorWrapperTestId?: string;\n /** Unique name for the child input element */\n name?: string;\n /** Unique name for the fieldset */\n fieldsetName?: string;\n /** Sets div instead of fieldset tag */\n htmlMarkup?: FormGroupTags;\n /** Renders the error component (Default: true) */\n renderError?: boolean;\n}\n\nexport const FormGroup = React.forwardRef((props: FormGroupProps, ref: React.ForwardedRef<HTMLDivElement>) => {\n const {\n className,\n fieldsetClassName,\n onColor = FormOnColor.onwhite,\n size = FormSize.medium,\n error,\n errorTextId,\n name,\n htmlMarkup = 'fieldset',\n renderError = true,\n errorWrapperClassName,\n errorWrapperTestId,\n } = props;\n const [checkedRadioId, setCheckedRadioId] = useState<string>();\n const radioGroupId = useUuid();\n const errorTextUuid = useUuid(errorTextId);\n const onDark = onColor === FormOnColor.ondark;\n const isLarge = size === FormSize.large;\n const formGroupWrapperClasses = classNames(formGroupStyles['form-group-wrapper'], className);\n const titleClasses = classNames({\n [formGroupStyles['form-group-wrapper__title--on-dark']]: onDark && !error,\n });\n\n const legendClasses = classNames(formGroupStyles['field-set__legend'], {\n [formGroupStyles['field-set__legend--on-dark']]: onDark && !error,\n });\n\n const fieldsetClasses = classNames(formGroupStyles['field-set'], fieldsetClassName);\n\n const mapFormComponent = (child: React.ReactNode, index: number): React.ReactNode => {\n if (isComponent<FormLayoutProps>(child, FormLayout)) {\n return React.cloneElement(child, {\n size,\n mapHelper: mapFormComponent,\n });\n } else if (isComponent<FormGroupProps>(child, FormGroup)) {\n return React.cloneElement(child, {\n onColor,\n size,\n error,\n renderError: false,\n errorTextId: errorTextUuid,\n });\n } else if (isComponent<CheckboxProps>(child, Checkbox)) {\n return React.cloneElement(child, {\n name: name ?? child.props.name,\n onColor,\n size,\n error: !!error,\n errorTextId: errorTextUuid,\n });\n } else if (isComponent<RadioButtonProps>(child, RadioButton)) {\n const radioId = typeof child.props.inputId === 'undefined' ? radioGroupId + index : child.props.inputId;\n return React.cloneElement(child, {\n inputId: radioId,\n name: name ?? child.props.name,\n onColor,\n size,\n onChange: (event: React.ChangeEvent<HTMLInputElement>) => {\n setCheckedRadioId(event.target.id);\n child.props.onChange && child.props.onChange(event);\n },\n error: !!error,\n errorTextId: errorTextUuid,\n labelClassNames: getRadioLabelClasses(radioId, onColor as FormOnColor, isLarge, checkedRadioId),\n });\n } else if (isComponent<InputProps>(child, Input)) {\n return React.cloneElement(child, {\n name: name ?? child.props.name,\n onColor,\n size,\n error: !!error,\n errorTextId: errorTextUuid,\n });\n } else if (isComponent<TextareaProps>(child, Textarea)) {\n return React.cloneElement(child, {\n name: name ?? child.props.name,\n onColor,\n error: !!error,\n errorTextId: errorTextUuid,\n });\n } else if (isComponent<SelectProps>(child, Select)) {\n return React.cloneElement(child, {\n name: name ?? child.props.name,\n onColor,\n error: !!error,\n errorTextId: errorTextUuid,\n });\n }\n return child;\n };\n\n const formGroupContent = (): React.ReactNode => {\n return (\n <div>\n {htmlMarkup === 'div' && (\n <div className={fieldsetClasses}>\n {props.legend && <h5 className={legendClasses}>{props.legend}</h5>}\n {React.Children.map(props.children, mapFormComponent)}\n </div>\n )}\n {htmlMarkup === 'fieldset' && (\n <fieldset name={props.fieldsetName} className={fieldsetClasses}>\n {props.legend && <legend className={legendClasses}>{props.legend}</legend>}\n {React.Children.map(props.children, mapFormComponent)}\n </fieldset>\n )}\n </div>\n );\n };\n\n return (\n <div data-testid={props.testId} data-analyticsid={AnalyticsId.FormGroup} className={formGroupWrapperClasses} ref={ref} tabIndex={-1}>\n {props.title && (\n <Title className={titleClasses} htmlMarkup={'h4'} appearance={'title4'} margin={{ marginTop: 0, marginBottom: error ? 1 : 2 }}>\n {props.title}\n </Title>\n )}\n {renderError ? (\n <ErrorWrapper className={errorWrapperClassName} errorText={error} testId={errorWrapperTestId} errorTextId={errorTextUuid}>\n {formGroupContent()}\n </ErrorWrapper>\n ) : (\n formGroupContent()\n )}\n </div>\n );\n});\n\nFormGroup.displayName = 'FormGroup';\n\nexport default FormGroup;\n"],"names":["FormGroup","React","props","ref","className","fieldsetClassName","onColor","FormOnColor","size","FormSize","error","errorTextId","name","htmlMarkup","renderError","errorWrapperClassName","errorWrapperTestId","checkedRadioId","setCheckedRadioId","useState","radioGroupId","useUuid","errorTextUuid","onDark","isLarge","formGroupWrapperClasses","classNames","formGroupStyles","titleClasses","legendClasses","fieldsetClasses","mapFormComponent","child","index","isComponent","FormLayout","Checkbox","RadioButton","radioId","event","getRadioLabelClasses","Input","Textarea","Select","formGroupContent","jsxs","jsx","AnalyticsId","Title","ErrorWrapper"],"mappings":";;;;;;;;;;;;;;;AAuDO,MAAMA,IAAYC,EAAM,WAAW,CAACC,GAAuBC,MAA4C;AACtG,QAAA;AAAA,IACJ,WAAAC;AAAA,IACA,mBAAAC;AAAA,IACA,SAAAC,IAAUC,EAAY;AAAA,IACtB,MAAAC,IAAOC,EAAS;AAAA,IAChB,OAA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ACb,UAAA;AAAA,MAAA5B,EAAM,UAAW,gBAAA4C,EAAA,MAAA,EAAG,WAAWjB,GAAgB,YAAM,QAAO;AAAA,MAC5D5B,EAAM,SAAS,IAAIC,EAAM,UAAU6B,CAAgB;AAAA,IAAA,GACtD;AAAA,IAEDlB,MAAe,cACb,gBAAAgC,EAAA,YAAA,EAAS,MAAM3C,EAAM,cAAc,WAAW4B,GAC5C,UAAA;AAAA,MAAA5B,EAAM,UAAW,gBAAA4C,EAAA,UAAA,EAAO,WAAWjB,GAAgB,YAAM,QAAO;AAAA,MAChE5B,EAAM,SAAS,IAAIC,EAAM,UAAU6B,CAAgB;AAAA,IAAA,GACtD;AAAA,EAEJ,EAAA,CAAA;AAIJ,SACG,gBAAAc,EAAA,OAAA,EAAI,eAAa3C,EAAM,QAAQ,oBAAkB6C,EAAY,WAAW,WAAWtB,GAAyB,KAAAtB,GAAU,UAAU,IAC9H,UAAA;AAAA,IAAAD,EAAM,SACJ,gBAAA4C,EAAAE,GAAA,EAAM,WAAWpB,GAAc,YAAY,MAAM,YAAY,UAAU,QAAQ,EAAE,WAAW,GAAG,cAAclB,IAAQ,IAAI,EAAE,GACzH,YAAM,OACT;AAAA,IAEDI,IACC,gBAAAgC,EAACG,GAAa,EAAA,WAAWlC,GAAuB,WAAWL,GAAO,QAAQM,GAAoB,aAAaM,GACxG,UAAiBsB,EAAA,EAAA,CACpB,IAEAA,EAAiB;AAAA,EAErB,EAAA,CAAA;AAEJ,CAAC;AAED5C,EAAU,cAAc;"}
|
|
1
|
+
{"version":3,"file":"FormGroup.js","sources":["../src/components/FormGroup/FormGroup.tsx"],"sourcesContent":["import React, { useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport { AnalyticsId, FormOnColor, FormSize } from '../../constants';\nimport { useUuid } from '../../hooks/useUuid';\nimport { isComponent } from '../../utils/component';\nimport Checkbox, { CheckboxProps } from '../Checkbox/Checkbox';\nimport ErrorWrapper from '../ErrorWrapper';\nimport FormLayout, { FormLayoutProps } from '../FormLayout';\nimport Input, { InputProps } from '../Input/Input';\nimport RadioButton, { RadioButtonProps, getRadioLabelClasses } from '../RadioButton/RadioButton';\nimport Select, { SelectProps } from '../Select';\nimport Slider, { SliderProps } from '../Slider';\nimport Textarea, { TextareaProps } from '../Textarea';\nimport Title from '../Title';\n\nimport formGroupStyles from './styles.module.scss';\n\nexport type FormGroupTags = 'fieldset' | 'div';\n\nexport interface FormGroupProps {\n /** title for the the fieldset */\n title?: string;\n /** text placed in the legend tag of the fieldset */\n legend?: string;\n /** Items in the FormGroup component */\n children?: React.ReactNode;\n /** Adds custom classes to the element. */\n className?: string;\n /** Adds custom classes to the errorWrapper. */\n errorWrapperClassName?: string;\n /** Adds custom classes to the fieldset element. */\n fieldsetClassName?: string;\n /** Changes the visuals of the formgroup */\n onColor?: keyof typeof FormOnColor;\n /** Changes the visuals of the formgroup */\n size?: keyof typeof FormSize;\n /** Error message */\n error?: string;\n /** Error text id */\n errorTextId?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Sets the data-testid attribute for the error-wrapper. */\n errorWrapperTestId?: string;\n /** Unique name for the child input element */\n name?: string;\n /** Unique name for the fieldset */\n fieldsetName?: string;\n /** Sets div instead of fieldset tag */\n htmlMarkup?: FormGroupTags;\n /** Renders the error component (Default: true) */\n renderError?: boolean;\n}\n\nexport const FormGroup = React.forwardRef((props: FormGroupProps, ref: React.ForwardedRef<HTMLDivElement>) => {\n const {\n className,\n fieldsetClassName,\n onColor = FormOnColor.onwhite,\n size = FormSize.medium,\n error,\n errorTextId,\n name,\n htmlMarkup = 'fieldset',\n renderError = true,\n errorWrapperClassName,\n errorWrapperTestId,\n } = props;\n const [checkedRadioId, setCheckedRadioId] = useState<string>();\n const radioGroupId = useUuid();\n const errorTextUuid = useUuid(errorTextId);\n const onDark = onColor === FormOnColor.ondark;\n const isLarge = size === FormSize.large;\n const formGroupWrapperClasses = classNames(formGroupStyles['form-group-wrapper'], className);\n const titleClasses = classNames({\n [formGroupStyles['form-group-wrapper__title--on-dark']]: onDark && !error,\n });\n\n const legendClasses = classNames(formGroupStyles['field-set__legend'], {\n [formGroupStyles['field-set__legend--on-dark']]: onDark && !error,\n });\n\n const fieldsetClasses = classNames(formGroupStyles['field-set'], fieldsetClassName);\n\n const mapFormComponent = (child: React.ReactNode, index: number): React.ReactNode => {\n if (isComponent<FormLayoutProps>(child, FormLayout)) {\n return React.cloneElement(child, {\n size,\n mapHelper: mapFormComponent,\n });\n } else if (isComponent<FormGroupProps>(child, FormGroup)) {\n return React.cloneElement(child, {\n onColor,\n size,\n error,\n renderError: false,\n errorTextId: errorTextUuid,\n });\n } else if (isComponent<CheckboxProps>(child, Checkbox)) {\n return React.cloneElement(child, {\n name: name ?? child.props.name,\n onColor,\n size,\n error: !!error,\n errorTextId: errorTextUuid,\n });\n } else if (isComponent<RadioButtonProps>(child, RadioButton)) {\n const radioId = typeof child.props.inputId === 'undefined' ? radioGroupId + index : child.props.inputId;\n return React.cloneElement(child, {\n inputId: radioId,\n name: name ?? child.props.name,\n onColor,\n size,\n onChange: (event: React.ChangeEvent<HTMLInputElement>) => {\n setCheckedRadioId(event.target.id);\n child.props.onChange && child.props.onChange(event);\n },\n error: !!error,\n errorTextId: errorTextUuid,\n labelClassNames: getRadioLabelClasses(radioId, onColor as FormOnColor, isLarge, checkedRadioId),\n });\n } else if (isComponent<InputProps>(child, Input)) {\n return React.cloneElement(child, {\n name: name ?? child.props.name,\n onColor,\n size,\n error: !!error,\n errorTextId: errorTextUuid,\n });\n } else if (isComponent<TextareaProps>(child, Textarea)) {\n return React.cloneElement(child, {\n name: name ?? child.props.name,\n onColor,\n error: !!error,\n errorTextId: errorTextUuid,\n });\n } else if (isComponent<SelectProps>(child, Select)) {\n return React.cloneElement(child, {\n name: name ?? child.props.name,\n onColor,\n error: !!error,\n errorTextId: errorTextUuid,\n });\n } else if (isComponent<SliderProps>(child, Slider)) {\n return React.cloneElement(child, {\n name: name ?? child.props.name,\n error: !!error,\n errorTextId: errorTextUuid,\n });\n }\n return child;\n };\n\n const formGroupContent = (): React.ReactNode => {\n return (\n <div>\n {htmlMarkup === 'div' && (\n <div className={fieldsetClasses}>\n {props.legend && <h5 className={legendClasses}>{props.legend}</h5>}\n {React.Children.map(props.children, mapFormComponent)}\n </div>\n )}\n {htmlMarkup === 'fieldset' && (\n <fieldset name={props.fieldsetName} className={fieldsetClasses}>\n {props.legend && <legend className={legendClasses}>{props.legend}</legend>}\n {React.Children.map(props.children, mapFormComponent)}\n </fieldset>\n )}\n </div>\n );\n };\n\n return (\n <div data-testid={props.testId} data-analyticsid={AnalyticsId.FormGroup} className={formGroupWrapperClasses} ref={ref} tabIndex={-1}>\n {props.title && (\n <Title className={titleClasses} htmlMarkup={'h4'} appearance={'title4'} margin={{ marginTop: 0, marginBottom: error ? 1 : 2 }}>\n {props.title}\n </Title>\n )}\n {renderError ? (\n <ErrorWrapper className={errorWrapperClassName} errorText={error} testId={errorWrapperTestId} errorTextId={errorTextUuid}>\n {formGroupContent()}\n </ErrorWrapper>\n ) : (\n formGroupContent()\n )}\n </div>\n );\n});\n\nFormGroup.displayName = 'FormGroup';\n\nexport default FormGroup;\n"],"names":["FormGroup","React","props","ref","className","fieldsetClassName","onColor","FormOnColor","size","FormSize","error","errorTextId","name","htmlMarkup","renderError","errorWrapperClassName","errorWrapperTestId","checkedRadioId","setCheckedRadioId","useState","radioGroupId","useUuid","errorTextUuid","onDark","isLarge","formGroupWrapperClasses","classNames","formGroupStyles","titleClasses","legendClasses","fieldsetClasses","mapFormComponent","child","index","isComponent","FormLayout","Checkbox","RadioButton","radioId","event","getRadioLabelClasses","Input","Textarea","Select","Slider","formGroupContent","jsxs","jsx","AnalyticsId","Title","ErrorWrapper"],"mappings":";;;;;;;;;;;;;;;;AAwDO,MAAMA,IAAYC,EAAM,WAAW,CAACC,GAAuBC,MAA4C;AACtG,QAAA;AAAA,IACJ,WAAAC;AAAA,IACA,mBAAAC;AAAA,IACA,SAAAC,IAAUC,EAAY;AAAA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","sources":["../src/components/Input/Input.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react';\n\nimport cn from 'classnames';\n\nimport { FormOnColor, FormSize, AnalyticsId, AVERAGE_CHARACTER_WIDTH_PX } from '../../constants';\nimport { Breakpoint, useBreakpoint } from '../../hooks/useBreakpoint';\nimport { useUuid } from '../../hooks/useUuid';\nimport { getColor } from '../../theme/currys';\nimport { getAriaDescribedBy } from '../../utils/accessibility';\nimport { mergeRefs } from '../../utils/refs';\nimport ErrorWrapper, { ErrorWrapperClassNameProps } from '../ErrorWrapper';\nimport Icon, { IconSize, SvgIcon } from '../Icon';\nimport { IconName } from '../Icons/IconNames';\nimport { renderLabel } from '../Label';\nimport LazyIcon from '../LazyIcon';\nimport MaxCharacters from '../MaxCharacters/MaxCharacters';\n\nimport styles from './styles.module.scss';\n\nexport interface InputProps\n extends ErrorWrapperClassNameProps,\n Pick<\n React.InputHTMLAttributes<HTMLInputElement>,\n | 'disabled'\n | 'readOnly'\n | 'autoComplete'\n | 'name'\n | 'placeholder'\n | 'defaultValue'\n | 'required'\n | 'value'\n | 'min'\n | 'max'\n | 'aria-describedby'\n | 'aria-labelledby'\n | 'onBlur'\n | 'onClick'\n | 'onChange'\n | 'onFocus'\n | 'onKeyDown'\n | 'autoFocus'\n > {\n /** The number at which the input field starts when you increment or decrement it */\n baseIncrementValue?: number;\n /** Adds custom classes to the element. */\n className?: string;\n /** HMTL Input type */\n type?: keyof typeof InputTypes;\n /** input id */\n inputId?: string;\n /** Width of input field in characters (approximate) */\n width?: number;\n /** If true, the component will be transparent. */\n transparent?: boolean;\n /** Icon to be displayed next to the input field */\n icon?: SvgIcon | IconName;\n /** Places the icon to the right */\n iconRight?: boolean;\n /** Ref that is placed on the inputContainerRef */\n inputContainerRef?: React.RefObject<HTMLDivElement>;\n /** Ref that is placed on the inputWrapper */\n inputWrapperRef?: React.RefObject<HTMLDivElement>;\n /** Changes the color profile of the input */\n onColor?: keyof typeof FormOnColor;\n /** Changes the visuals of the input */\n size?: keyof typeof FormSize;\n /** Label of the input */\n label?: React.ReactNode;\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 /** Sets the data-testid attribute. */\n testId?: string;\n /** Component shown after input */\n afterInputChildren?: React.ReactNode;\n /** Component shown to the right of input */\n rightOfInput?: React.ReactNode;\n /** max character limit in input */\n maxCharacters?: number;\n /** The text is displayed in the end of the text-counter */\n maxText?: string;\n}\n\nexport enum InputTypes {\n text = 'text',\n number = 'number',\n email = 'email',\n password = 'password',\n search = 'search',\n tel = 'tel',\n url = 'url',\n date = 'date',\n time = 'time',\n}\n\nconst getInputMaxWidth = (characters: number, hasIcon: boolean, iconSize: number): string => {\n const paddingWidth = hasIcon ? '1.5rem' : '2rem';\n const iconWidth = hasIcon ? `${iconSize}px` : '0px';\n const borderWidth = '4px';\n\n return `calc(${characters * AVERAGE_CHARACTER_WIDTH_PX}px + ${paddingWidth} + ${iconWidth} + ${borderWidth})`;\n};\n\nconst Input = React.forwardRef((props: InputProps, ref: React.Ref<HTMLInputElement>) => {\n const {\n className,\n defaultValue,\n placeholder,\n type = InputTypes.text,\n name,\n transparent = false,\n icon,\n iconRight,\n inputId,\n inputWrapperRef,\n onColor = FormOnColor.onwhite,\n size,\n baseIncrementValue,\n label,\n error,\n errorText,\n errorTextId,\n errorWrapperClassName,\n testId,\n disabled,\n readOnly,\n autoComplete = 'off',\n afterInputChildren,\n rightOfInput,\n width,\n required,\n onChange,\n onKeyDown,\n autoFocus,\n maxCharacters,\n maxText,\n inputContainerRef,\n ...rest\n } = props;\n const breakpoint = useBreakpoint();\n const inputContainerRefLocal = useRef<HTMLDivElement>(null);\n const inputIdState = useUuid(inputId);\n const [input, setInput] = useState(defaultValue || '');\n const [prevValue, setPrevValue] = useState<string | number | undefined>(undefined);\n const numKeyPressed = useRef<boolean>(false);\n const errorTextUuid = useUuid(errorTextId);\n const numRegex = /^[0-9]$/;\n\n useEffect(() => {\n setInput(defaultValue || '');\n }, [defaultValue]);\n\n const onDark = onColor === FormOnColor.ondark;\n const onBlueberry = onColor === FormOnColor.onblueberry;\n const maxCharactersExceeded = !!maxCharacters && input.toString().length > maxCharacters;\n const onError = onColor === FormOnColor.oninvalid || !!errorText || !!error || maxCharactersExceeded;\n const isLarge = size === FormSize.large;\n const isTransparent = transparent && onColor !== FormOnColor.ondark && !onError;\n\n const inputWrapperClass = cn(styles['input-wrapper'], className);\n\n const inputContainer = cn(styles['input-container'], {\n [styles['input-container--transparent']]: isTransparent,\n [styles['input-container--on-blueberry']]: onBlueberry,\n [styles['input-container--on-dark']]: onDark,\n [styles['input-container--invalid']]: onError,\n [styles['input-container--large']]: isLarge,\n [styles['input-container--disabled']]: disabled,\n [styles['input-container--with-icon']]: icon,\n });\n\n const inputClass = cn(styles['input-container__input'], {\n [styles['input-container__input--large']]: isLarge,\n [styles['input-container__input--disabled']]: disabled,\n });\n\n const iconColor = disabled ? getColor('neutral', 700) : getColor('black');\n const iconSize = breakpoint === Breakpoint.xs || !isLarge ? IconSize.XSmall : IconSize.Small;\n\n const renderIcon = (): React.ReactNode => {\n if (!icon) {\n return;\n }\n\n if (typeof icon === 'string') {\n return <LazyIcon className={styles['input-container__input__icon']} color={iconColor} size={iconSize} iconName={icon} />;\n }\n\n return <Icon className={styles['input-container__input__icon']} color={iconColor} size={iconSize} svgIcon={icon} />;\n };\n\n // eslint-disable-next-line\n const handleClick = (e: React.MouseEvent<any>): void => {\n if (inputContainerRefLocal && inputContainerRefLocal.current && icon) {\n const selectedChild = iconRight ? 0 : 1;\n const input = inputContainerRefLocal.current.children[selectedChild] as HTMLInputElement;\n input.focus();\n\n props.onClick && props.onClick(e);\n }\n };\n\n const handleChange = (e: React.ChangeEvent<HTMLInputElement>): void => {\n const newValue = getIncrementValue(e);\n\n if (onChange) {\n onChange(e);\n }\n\n setInput(newValue);\n setPrevValue(newValue);\n };\n\n // Hvis bruker endrer number value med 1 og det skal startes på en annen verdi enn 0\n const getIncrementValue = (e: React.ChangeEvent<HTMLInputElement>): string => {\n if (typeof baseIncrementValue === 'undefined' || type !== 'number') return e.target.value;\n\n const valueAsNumber = Number(e.target.value);\n\n if (!prevValue && !numKeyPressed.current && (valueAsNumber === 1 || valueAsNumber === -1)) {\n e.target.value = baseIncrementValue + '';\n }\n\n return e.target.value;\n };\n\n const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>): void => {\n if (numRegex.test(e.key)) {\n numKeyPressed.current = true;\n }\n onKeyDown && onKeyDown(e);\n };\n\n const handleKeyUp = (e: React.KeyboardEvent<HTMLInputElement>): void => {\n if (numRegex.test(e.key)) {\n numKeyPressed.current = false;\n }\n };\n\n const maxWidth = width ? getInputMaxWidth(width, !!icon, iconSize) : undefined;\n\n return (\n <ErrorWrapper className={errorWrapperClassName} errorText={errorText} errorTextId={errorTextUuid}>\n <div data-testid={testId} data-analyticsid={AnalyticsId.Input} className={inputWrapperClass} ref={inputWrapperRef}>\n {renderLabel(label, inputIdState, onColor as FormOnColor)}\n {/* input-elementet tillater keyboard-interaksjon */}\n <div className={styles['content-wrapper']}>\n {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */}\n <div\n onClick={handleClick}\n ref={mergeRefs([inputContainerRefLocal, inputContainerRef])}\n className={inputContainer}\n style={{ maxWidth }}\n >\n {!iconRight && renderIcon()}\n <input\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n onKeyUp={handleKeyUp}\n name={name}\n type={type}\n defaultValue={defaultValue}\n id={inputIdState}\n className={inputClass}\n ref={ref}\n aria-labelledby={props['aria-labelledby'] ?? undefined}\n aria-describedby={getAriaDescribedBy(props, errorTextUuid)}\n aria-invalid={!!onError}\n disabled={disabled}\n placeholder={placeholder}\n readOnly={readOnly}\n autoComplete={autoComplete || 'off'}\n required={required}\n // eslint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={autoFocus}\n {...rest}\n />\n {iconRight && renderIcon()}\n </div>\n <div className={styles['content-wrapper__right-of-input']}>{rightOfInput}</div>\n </div>\n {maxCharacters && (\n <MaxCharacters\n maxCharacters={maxCharacters}\n length={input.toString().length}\n maxText={maxText}\n onColor={onColor}\n maxWidth={maxWidth}\n />\n )}\n {afterInputChildren}\n </div>\n </ErrorWrapper>\n );\n});\n\nInput.displayName = 'Input';\n\nexport default Input;\n"],"names":["InputTypes","getInputMaxWidth","characters","hasIcon","iconSize","paddingWidth","iconWidth","AVERAGE_CHARACTER_WIDTH_PX","Input","React","props","ref","className","defaultValue","placeholder","type","name","transparent","icon","iconRight","inputId","inputWrapperRef","onColor","FormOnColor","size","baseIncrementValue","label","error","errorText","errorTextId","errorWrapperClassName","testId","disabled","readOnly","autoComplete","afterInputChildren","rightOfInput","width","required","onChange","onKeyDown","autoFocus","maxCharacters","maxText","inputContainerRef","rest","breakpoint","useBreakpoint","inputContainerRefLocal","useRef","inputIdState","useUuid","input","setInput","useState","prevValue","setPrevValue","numKeyPressed","errorTextUuid","numRegex","useEffect","onDark","onBlueberry","maxCharactersExceeded","onError","isLarge","FormSize","isTransparent","inputWrapperClass","cn","styles","inputContainer","inputClass","iconColor","getColor","Breakpoint","IconSize","renderIcon","jsx","LazyIcon","Icon","handleClick","e","selectedChild","handleChange","newValue","getIncrementValue","valueAsNumber","handleKeyDown","handleKeyUp","maxWidth","ErrorWrapper","jsxs","AnalyticsId","renderLabel","mergeRefs","getAriaDescribedBy","MaxCharacters"],"mappings":";;;;;;;;;;;;;;;AAsFY,IAAAA,uBAAAA,OACVA,EAAA,OAAO,QACPA,EAAA,SAAS,UACTA,EAAA,QAAQ,SACRA,EAAA,WAAW,YACXA,EAAA,SAAS,UACTA,EAAA,MAAM,OACNA,EAAA,MAAM,OACNA,EAAA,OAAO,QACPA,EAAA,OAAO,QATGA,IAAAA,MAAA,CAAA,CAAA;AAYZ,MAAMC,KAAmB,CAACC,GAAoBC,GAAkBC,MAA6B;AACrF,QAAAC,IAAeF,IAAU,WAAW,QACpCG,IA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version":3,"file":"Input.js","sources":["../src/components/Input/Input.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react';\n\nimport cn from 'classnames';\n\nimport { FormOnColor, FormSize, AnalyticsId, AVERAGE_CHARACTER_WIDTH_PX } from '../../constants';\nimport { Breakpoint, useBreakpoint } from '../../hooks/useBreakpoint';\nimport { useUuid } from '../../hooks/useUuid';\nimport { getColor } from '../../theme/currys';\nimport { getAriaDescribedBy } from '../../utils/accessibility';\nimport { mergeRefs } from '../../utils/refs';\nimport ErrorWrapper, { ErrorWrapperClassNameProps } from '../ErrorWrapper';\nimport Icon, { IconSize, SvgIcon } from '../Icon';\nimport { IconName } from '../Icons/IconNames';\nimport { renderLabel } from '../Label';\nimport LazyIcon from '../LazyIcon';\nimport MaxCharacters from '../MaxCharacters/MaxCharacters';\n\nimport styles from './styles.module.scss';\n\nexport interface InputProps\n extends ErrorWrapperClassNameProps,\n Pick<\n React.InputHTMLAttributes<HTMLInputElement>,\n | 'disabled'\n | 'readOnly'\n | 'autoComplete'\n | 'name'\n | 'placeholder'\n | 'defaultValue'\n | 'required'\n | 'value'\n | 'min'\n | 'max'\n | 'aria-describedby'\n | 'aria-labelledby'\n | 'onBlur'\n | 'onClick'\n | 'onChange'\n | 'onFocus'\n | 'onKeyDown'\n | 'autoFocus'\n | 'inputMode'\n > {\n /** The number at which the input field starts when you increment or decrement it */\n baseIncrementValue?: number;\n /** Adds custom classes to the element. */\n className?: string;\n /** HMTL Input type */\n type?: keyof typeof InputTypes;\n /** input id */\n inputId?: string;\n /** Width of input field in characters (approximate) */\n width?: number;\n /** If true, the component will be transparent. */\n transparent?: boolean;\n /** Icon to be displayed next to the input field */\n icon?: SvgIcon | IconName;\n /** Places the icon to the right */\n iconRight?: boolean;\n /** Ref that is placed on the inputContainerRef */\n inputContainerRef?: React.RefObject<HTMLDivElement>;\n /** Ref that is placed on the inputWrapper */\n inputWrapperRef?: React.RefObject<HTMLDivElement>;\n /** Changes the color profile of the input */\n onColor?: keyof typeof FormOnColor;\n /** Changes the visuals of the input */\n size?: keyof typeof FormSize;\n /** Label of the input */\n label?: React.ReactNode;\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 /** Sets the data-testid attribute. */\n testId?: string;\n /** Component shown after input */\n afterInputChildren?: React.ReactNode;\n /** Component shown to the right of input */\n rightOfInput?: React.ReactNode;\n /** max character limit in input */\n maxCharacters?: number;\n /** The text is displayed in the end of the text-counter */\n maxText?: string;\n}\n\nexport enum InputTypes {\n text = 'text',\n number = 'number',\n email = 'email',\n password = 'password',\n search = 'search',\n tel = 'tel',\n url = 'url',\n date = 'date',\n time = 'time',\n}\n\nconst getInputMaxWidth = (characters: number, hasIcon: boolean, iconSize: number): string => {\n const paddingWidth = hasIcon ? '1.5rem' : '2rem';\n const iconWidth = hasIcon ? `${iconSize}px` : '0px';\n const borderWidth = '4px';\n\n return `calc(${characters * AVERAGE_CHARACTER_WIDTH_PX}px + ${paddingWidth} + ${iconWidth} + ${borderWidth})`;\n};\n\nconst Input = React.forwardRef((props: InputProps, ref: React.Ref<HTMLInputElement>) => {\n const {\n className,\n defaultValue,\n placeholder,\n type = InputTypes.text,\n name,\n transparent = false,\n icon,\n iconRight,\n inputId,\n inputWrapperRef,\n onColor = FormOnColor.onwhite,\n size,\n baseIncrementValue,\n label,\n error,\n errorText,\n errorTextId,\n errorWrapperClassName,\n testId,\n disabled,\n readOnly,\n autoComplete = 'off',\n afterInputChildren,\n rightOfInput,\n width,\n required,\n onChange,\n onKeyDown,\n autoFocus,\n maxCharacters,\n maxText,\n inputContainerRef,\n ...rest\n } = props;\n const breakpoint = useBreakpoint();\n const inputContainerRefLocal = useRef<HTMLDivElement>(null);\n const inputIdState = useUuid(inputId);\n const [input, setInput] = useState(defaultValue || '');\n const [prevValue, setPrevValue] = useState<string | number | undefined>(undefined);\n const numKeyPressed = useRef<boolean>(false);\n const errorTextUuid = useUuid(errorTextId);\n const numRegex = /^[0-9]$/;\n\n useEffect(() => {\n setInput(defaultValue || '');\n }, [defaultValue]);\n\n const onDark = onColor === FormOnColor.ondark;\n const onBlueberry = onColor === FormOnColor.onblueberry;\n const maxCharactersExceeded = !!maxCharacters && input.toString().length > maxCharacters;\n const onError = onColor === FormOnColor.oninvalid || !!errorText || !!error || maxCharactersExceeded;\n const isLarge = size === FormSize.large;\n const isTransparent = transparent && onColor !== FormOnColor.ondark && !onError;\n\n const inputWrapperClass = cn(styles['input-wrapper'], className);\n\n const inputContainer = cn(styles['input-container'], {\n [styles['input-container--transparent']]: isTransparent,\n [styles['input-container--on-blueberry']]: onBlueberry,\n [styles['input-container--on-dark']]: onDark,\n [styles['input-container--invalid']]: onError,\n [styles['input-container--large']]: isLarge,\n [styles['input-container--disabled']]: disabled,\n [styles['input-container--with-icon']]: icon,\n });\n\n const inputClass = cn(styles['input-container__input'], {\n [styles['input-container__input--large']]: isLarge,\n [styles['input-container__input--disabled']]: disabled,\n });\n\n const iconColor = disabled ? getColor('neutral', 700) : getColor('black');\n const iconSize = breakpoint === Breakpoint.xs || !isLarge ? IconSize.XSmall : IconSize.Small;\n\n const renderIcon = (): React.ReactNode => {\n if (!icon) {\n return;\n }\n\n if (typeof icon === 'string') {\n return <LazyIcon className={styles['input-container__input__icon']} color={iconColor} size={iconSize} iconName={icon} />;\n }\n\n return <Icon className={styles['input-container__input__icon']} color={iconColor} size={iconSize} svgIcon={icon} />;\n };\n\n // eslint-disable-next-line\n const handleClick = (e: React.MouseEvent<any>): void => {\n if (inputContainerRefLocal && inputContainerRefLocal.current && icon) {\n const selectedChild = iconRight ? 0 : 1;\n const input = inputContainerRefLocal.current.children[selectedChild] as HTMLInputElement;\n input.focus();\n\n props.onClick && props.onClick(e);\n }\n };\n\n const handleChange = (e: React.ChangeEvent<HTMLInputElement>): void => {\n const newValue = getIncrementValue(e);\n\n if (onChange) {\n onChange(e);\n }\n\n setInput(newValue);\n setPrevValue(newValue);\n };\n\n // Hvis bruker endrer number value med 1 og det skal startes på en annen verdi enn 0\n const getIncrementValue = (e: React.ChangeEvent<HTMLInputElement>): string => {\n if (typeof baseIncrementValue === 'undefined' || type !== 'number') return e.target.value;\n\n const valueAsNumber = Number(e.target.value);\n\n if (!prevValue && !numKeyPressed.current && (valueAsNumber === 1 || valueAsNumber === -1)) {\n e.target.value = baseIncrementValue + '';\n }\n\n return e.target.value;\n };\n\n const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>): void => {\n if (numRegex.test(e.key)) {\n numKeyPressed.current = true;\n }\n onKeyDown && onKeyDown(e);\n };\n\n const handleKeyUp = (e: React.KeyboardEvent<HTMLInputElement>): void => {\n if (numRegex.test(e.key)) {\n numKeyPressed.current = false;\n }\n };\n\n const maxWidth = width ? getInputMaxWidth(width, !!icon, iconSize) : undefined;\n\n return (\n <ErrorWrapper className={errorWrapperClassName} errorText={errorText} errorTextId={errorTextUuid}>\n <div data-testid={testId} data-analyticsid={AnalyticsId.Input} className={inputWrapperClass} ref={inputWrapperRef}>\n {renderLabel(label, inputIdState, onColor as FormOnColor)}\n {/* input-elementet tillater keyboard-interaksjon */}\n <div className={styles['content-wrapper']}>\n {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */}\n <div\n onClick={handleClick}\n ref={mergeRefs([inputContainerRefLocal, inputContainerRef])}\n className={inputContainer}\n style={{ maxWidth }}\n >\n {!iconRight && renderIcon()}\n <input\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n onKeyUp={handleKeyUp}\n name={name}\n type={type}\n defaultValue={defaultValue}\n id={inputIdState}\n className={inputClass}\n ref={ref}\n aria-labelledby={props['aria-labelledby'] ?? undefined}\n aria-describedby={getAriaDescribedBy(props, errorTextUuid)}\n aria-invalid={!!onError}\n disabled={disabled}\n placeholder={placeholder}\n readOnly={readOnly}\n autoComplete={autoComplete || 'off'}\n required={required}\n // eslint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={autoFocus}\n {...rest}\n />\n {iconRight && renderIcon()}\n </div>\n <div className={styles['content-wrapper__right-of-input']}>{rightOfInput}</div>\n </div>\n {maxCharacters && (\n <MaxCharacters\n maxCharacters={maxCharacters}\n length={input.toString().length}\n maxText={maxText}\n onColor={onColor}\n maxWidth={maxWidth}\n />\n )}\n {afterInputChildren}\n </div>\n </ErrorWrapper>\n );\n});\n\nInput.displayName = 'Input';\n\nexport default Input;\n"],"names":["InputTypes","getInputMaxWidth","characters","hasIcon","iconSize","paddingWidth","iconWidth","AVERAGE_CHARACTER_WIDTH_PX","Input","React","props","ref","className","defaultValue","placeholder","type","name","transparent","icon","iconRight","inputId","inputWrapperRef","onColor","FormOnColor","size","baseIncrementValue","label","error","errorText","errorTextId","errorWrapperClassName","testId","disabled","readOnly","autoComplete","afterInputChildren","rightOfInput","width","required","onChange","onKeyDown","autoFocus","maxCharacters","maxText","inputContainerRef","rest","breakpoint","useBreakpoint","inputContainerRefLocal","useRef","inputIdState","useUuid","input","setInput","useState","prevValue","setPrevValue","numKeyPressed","errorTextUuid","numRegex","useEffect","onDark","onBlueberry","maxCharactersExceeded","onError","isLarge","FormSize","isTransparent","inputWrapperClass","cn","styles","inputContainer","inputClass","iconColor","getColor","Breakpoint","IconSize","renderIcon","jsx","LazyIcon","Icon","handleClick","e","selectedChild","handleChange","newValue","getIncrementValue","valueAsNumber","handleKeyDown","handleKeyUp","maxWidth","ErrorWrapper","jsxs","AnalyticsId","renderLabel","mergeRefs","getAriaDescribedBy","MaxCharacters"],"mappings":";;;;;;;;;;;;;;;AAuFY,IAAAA,uBAAAA,OACVA,EAAA,OAAO,QACPA,EAAA,SAAS,UACTA,EAAA,QAAQ,SACRA,EAAA,WAAW,YACXA,EAAA,SAAS,UACTA,EAAA,MAAM,OACNA,EAAA,MAAM,OACNA,EAAA,OAAO,QACPA,EAAA,OAAO,QATGA,IAAAA,MAAA,CAAA,CAAA;AAYZ,MAAMC,KAAmB,CAACC,GAAoBC,GAAkBC,MAA6B;AACrF,QAAAC,IA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M,cAAc;"}
|
package/Label.js
CHANGED
|
@@ -1,38 +1,40 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { AnalyticsId as
|
|
5
|
-
import { S as
|
|
1
|
+
import { jsxs as p, Fragment as F, jsx as t } from "react/jsx-runtime";
|
|
2
|
+
import y from "react";
|
|
3
|
+
import x from "classnames";
|
|
4
|
+
import { AnalyticsId as v, FormOnColor as S } from "./constants.js";
|
|
5
|
+
import { S as g } from "./Spacer.js";
|
|
6
6
|
import a from "./components/Label/styles.module.scss";
|
|
7
|
-
import { isComponent as
|
|
7
|
+
import { isComponent as u } from "./utils/component.js";
|
|
8
8
|
import { S as z } from "./StatusDot.js";
|
|
9
|
-
const A = ({ className: e, id: r, onColor: s, sublabelTexts: n, testId:
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
[a["label--semibold"]]:
|
|
13
|
-
[a["label--on-dark"]]: s ===
|
|
9
|
+
const A = ({ className: e, id: r, onColor: s, sublabelTexts: n, testId: l }) => {
|
|
10
|
+
const o = (c) => n && n.map((m, h) => {
|
|
11
|
+
const b = x(a.label, a["label--sublabel"], {
|
|
12
|
+
[a["label--semibold"]]: m.type === "semibold",
|
|
13
|
+
[a["label--on-dark"]]: s === S.ondark
|
|
14
14
|
});
|
|
15
|
-
return
|
|
16
|
-
}), i =
|
|
17
|
-
return /* @__PURE__ */
|
|
18
|
-
/* @__PURE__ */ t(
|
|
19
|
-
i && /* @__PURE__ */ t("div", { className: e, id: r, "data-testid":
|
|
20
|
-
d && /* @__PURE__ */ t("div", { className: e, "data-testid":
|
|
15
|
+
return c === m.hideFromScreenReader && /* @__PURE__ */ t("span", { className: b, children: m.text }, h);
|
|
16
|
+
}), i = o(), d = o(!0);
|
|
17
|
+
return /* @__PURE__ */ p(F, { children: [
|
|
18
|
+
/* @__PURE__ */ t(g, { size: "3xs" }),
|
|
19
|
+
i && /* @__PURE__ */ t("div", { className: e, id: r, "data-testid": l, "data-analyticsid": v.Sublabel, children: i }),
|
|
20
|
+
d && /* @__PURE__ */ t("div", { className: e, "data-testid": l, children: d })
|
|
21
21
|
] });
|
|
22
|
-
},
|
|
22
|
+
}, J = (e) => {
|
|
23
23
|
let r = "";
|
|
24
|
-
return
|
|
24
|
+
return u(e, f) && e.props.labelTexts.forEach((s) => {
|
|
25
25
|
r += s.hideFromScreenReader ? "" : s.text;
|
|
26
26
|
}), r;
|
|
27
|
-
},
|
|
27
|
+
}, K = (e, r, s, n) => /* @__PURE__ */ t(F, { children: e && u(e, f) ? y.cloneElement(e, {
|
|
28
28
|
htmlFor: r,
|
|
29
|
+
htmlMarkup: n || "label",
|
|
29
30
|
onColor: s
|
|
30
|
-
}) : typeof e == "string" && /* @__PURE__ */ t(f, { labelTexts: [{ text: e, type: "semibold" }], htmlFor: r, onColor: s }) }),
|
|
31
|
+
}) : typeof e == "string" && /* @__PURE__ */ t(f, { labelTexts: [{ text: e, type: "semibold" }], htmlFor: r, onColor: s }) }), Q = (e, r, s, n, l, o, i, d, c) => /* @__PURE__ */ t(F, { children: e && u(e, f) ? y.cloneElement(e, {
|
|
31
32
|
htmlFor: s,
|
|
32
33
|
onColor: n,
|
|
33
34
|
children: r,
|
|
34
|
-
labelClassName:
|
|
35
|
-
labelTextClassName:
|
|
35
|
+
labelClassName: x(l, e.props.labelClassName),
|
|
36
|
+
labelTextClassName: o,
|
|
37
|
+
htmlMarkup: c || "label",
|
|
36
38
|
sublabelWrapperClassName: i,
|
|
37
39
|
sublabel: d ? void 0 : e.props.sublabel,
|
|
38
40
|
statusDot: d ? void 0 : e.props.statusDot
|
|
@@ -42,8 +44,9 @@ const A = ({ className: e, id: r, onColor: s, sublabelTexts: n, testId: o }) =>
|
|
|
42
44
|
labelTexts: [{ text: e }],
|
|
43
45
|
htmlFor: s,
|
|
44
46
|
onColor: n,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
htmlMarkup: c || "label",
|
|
48
|
+
labelClassName: l,
|
|
49
|
+
labelTextClassName: o,
|
|
47
50
|
sublabelWrapperClassName: i,
|
|
48
51
|
children: r
|
|
49
52
|
}
|
|
@@ -52,45 +55,46 @@ const A = ({ className: e, id: r, onColor: s, sublabelTexts: n, testId: o }) =>
|
|
|
52
55
|
children: r,
|
|
53
56
|
className: s,
|
|
54
57
|
htmlFor: n,
|
|
58
|
+
htmlMarkup: l = "label",
|
|
55
59
|
labelClassName: o,
|
|
56
|
-
labelTextClassName:
|
|
57
|
-
labelId:
|
|
58
|
-
labelTexts:
|
|
59
|
-
onColor:
|
|
60
|
-
statusDot:
|
|
61
|
-
sublabel:
|
|
62
|
-
sublabelWrapperClassName:
|
|
63
|
-
testId:
|
|
60
|
+
labelTextClassName: i,
|
|
61
|
+
labelId: d,
|
|
62
|
+
labelTexts: c,
|
|
63
|
+
onColor: m = S.onwhite,
|
|
64
|
+
statusDot: h,
|
|
65
|
+
sublabel: b,
|
|
66
|
+
sublabelWrapperClassName: L,
|
|
67
|
+
testId: N
|
|
64
68
|
}) => {
|
|
65
|
-
const w = r && typeof r < "u",
|
|
69
|
+
const w = r && typeof r < "u", E = x(
|
|
66
70
|
a["label-wrapper"],
|
|
67
71
|
{ [a["label-wrapper--no-bottom-margin"]]: w, [a["label-wrapper--after-label-children"]]: e },
|
|
68
72
|
s
|
|
69
|
-
),
|
|
70
|
-
const j =
|
|
73
|
+
), R = () => c.map((k, M) => {
|
|
74
|
+
const j = x(
|
|
71
75
|
a.label,
|
|
72
76
|
{
|
|
73
|
-
[a["label--semibold"]]:
|
|
74
|
-
[a["label--on-dark"]]:
|
|
77
|
+
[a["label--semibold"]]: k.type === "semibold",
|
|
78
|
+
[a["label--on-dark"]]: m === S.ondark
|
|
75
79
|
},
|
|
76
|
-
|
|
80
|
+
i
|
|
77
81
|
);
|
|
78
|
-
return /* @__PURE__ */ t("span", { "aria-hidden":
|
|
82
|
+
return /* @__PURE__ */ t("span", { "aria-hidden": k.hideFromScreenReader, className: j, children: k.text }, M);
|
|
79
83
|
});
|
|
80
|
-
return /* @__PURE__ */
|
|
81
|
-
/* @__PURE__ */
|
|
82
|
-
/* @__PURE__ */ t(
|
|
84
|
+
return /* @__PURE__ */ p("div", { className: E, children: [
|
|
85
|
+
/* @__PURE__ */ p("div", { children: [
|
|
86
|
+
/* @__PURE__ */ t(l, { className: o, id: d, htmlFor: n, "data-testid": N, "data-analyticsid": v.Label, children: /* @__PURE__ */ p("span", { className: a["label-content-wrapper"], children: [
|
|
83
87
|
r,
|
|
84
|
-
/* @__PURE__ */ t("span", { className: a.label__texts, children:
|
|
88
|
+
/* @__PURE__ */ t("span", { className: a.label__texts, children: R() })
|
|
85
89
|
] }) }),
|
|
86
|
-
/* @__PURE__ */
|
|
87
|
-
|
|
88
|
-
onColor:
|
|
90
|
+
/* @__PURE__ */ p("div", { className: L, children: [
|
|
91
|
+
b && u(b, A) && y.cloneElement(b, {
|
|
92
|
+
onColor: m
|
|
89
93
|
}),
|
|
90
|
-
|
|
91
|
-
/* @__PURE__ */ t(
|
|
92
|
-
|
|
93
|
-
onColor:
|
|
94
|
+
h && u(h, z) && /* @__PURE__ */ p(F, { children: [
|
|
95
|
+
/* @__PURE__ */ t(g, { size: "3xs" }),
|
|
96
|
+
y.cloneElement(h, {
|
|
97
|
+
onColor: m === S.ondark ? "ondark" : "onwhite"
|
|
94
98
|
})
|
|
95
99
|
] })
|
|
96
100
|
] })
|
|
@@ -101,8 +105,8 @@ const A = ({ className: e, id: r, onColor: s, sublabelTexts: n, testId: o }) =>
|
|
|
101
105
|
export {
|
|
102
106
|
f as L,
|
|
103
107
|
A as S,
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
108
|
+
K as a,
|
|
109
|
+
J as g,
|
|
110
|
+
Q as r
|
|
107
111
|
};
|
|
108
112
|
//# sourceMappingURL=Label.js.map
|
package/Label.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Label.js","sources":["../src/components/Label/SubLabel.tsx","../src/components/Label/Label.tsx"],"sourcesContent":["import React from 'react';\n\nimport cn from 'classnames';\n\nimport { LabelText } from './Label';\nimport { AnalyticsId, FormOnColor } from '../../constants';\nimport Spacer from '../Spacer';\n\nimport styles from './styles.module.scss';\n\nexport interface SublabelProps {\n /** Adds custom classes to the element. */\n className?: string;\n /** id that is placed on the wrapper */\n id: string;\n /** Array of sublabel strings. Can be of type semibold or normal */\n onColor?: FormOnColor;\n /** Array of sublabel strings. Can be of type semibold or normal */\n sublabelTexts?: LabelText[];\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport const Sublabel: React.FC<SublabelProps> = ({ className, id, onColor, sublabelTexts, testId }) => {\n const mapSublabels = (hideFromScreenReader?: boolean): React.ReactNode => {\n return (\n sublabelTexts &&\n sublabelTexts.map((sublabelText, index) => {\n const labelClasses = cn(styles.label, styles['label--sublabel'], {\n [styles['label--semibold']]: sublabelText.type === 'semibold',\n [styles['label--on-dark']]: onColor === FormOnColor.ondark,\n });\n return (\n hideFromScreenReader === sublabelText.hideFromScreenReader && (\n <span className={labelClasses} key={index}>\n {sublabelText.text}\n </span>\n )\n );\n })\n );\n };\n\n const subLabels = mapSublabels();\n const ariaHiddenSublabels = mapSublabels(true);\n\n return (\n <>\n <Spacer size={'3xs'} />\n {subLabels && (\n <div className={className} id={id} data-testid={testId} data-analyticsid={AnalyticsId.Sublabel}>\n {subLabels}\n </div>\n )}\n {ariaHiddenSublabels && (\n <div className={className} data-testid={testId}>\n {ariaHiddenSublabels}\n </div>\n )}\n </>\n );\n};\n","import React, { FunctionComponent } from 'react';\n\nimport cn from 'classnames';\n\nimport { Sublabel, SublabelProps } from './SubLabel';\nimport { AnalyticsId, FormOnColor } from '../../constants';\nimport { isComponent } from '../../utils/component';\nimport Spacer from '../Spacer';\nimport StatusDot, { StatusDotProps } from '../StatusDot';\n\nimport styles from './styles.module.scss';\n\nexport type LabelText = {\n hideFromScreenReader?: boolean;\n text: string;\n type?: 'semibold' | 'normal';\n};\n\nexport interface LabelProps {\n /** Component shown after label - discourage use of this */\n afterLabelChildren?: React.ReactNode;\n /** Adds custom classes to the element. */\n children?: React.ReactNode;\n /** Adds custom classes to the label tag. */\n labelClassName?: string;\n /** Adds custom classes to the label text. */\n labelTextClassName?: string;\n /** Adds custom classes to the element. */\n className?: string;\n /** Id that is put on the \"for\" attribute of the label */\n htmlFor?: string;\n /** Id som plasseres på <label/> */\n labelId?: string;\n /** Array of main label strings. Can be of type semibold or normal */\n labelTexts: LabelText[];\n /** Array of sublabel strings. Can be of type semibold or normal */\n onColor?: keyof typeof FormOnColor;\n /** StatusDot placed underneath the last sublabel */\n statusDot?: React.ReactNode;\n /** Sublabel component */\n sublabel?: React.ReactNode;\n /** Adds custom classes to the div wrapping the sublabels. */\n sublabelWrapperClassName?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport const getLabelText = (label: React.ReactNode): string => {\n let allLabelText = '';\n\n if (isComponent<LabelProps>(label, Label)) {\n label.props.labelTexts.forEach(labelText => {\n allLabelText += !labelText.hideFromScreenReader ? labelText.text : '';\n });\n }\n\n return allLabelText;\n};\n\nexport const renderLabel = (label: React.ReactNode, inputId: string, onColor: FormOnColor): React.ReactNode => {\n return (\n <>\n {label && isComponent<LabelProps>(label, Label)\n ? React.cloneElement(label, {\n htmlFor: inputId,\n onColor,\n })\n : typeof label === 'string' && <Label labelTexts={[{ text: label, type: 'semibold' }]} htmlFor={inputId} onColor={onColor} />}\n </>\n );\n};\n\nexport const renderLabelAsParent = (\n label: React.ReactNode,\n children: React.ReactNode,\n inputId: string,\n onColor: FormOnColor,\n labelClassName?: string,\n labelTextClassName?: string,\n sublabelWrapperClassName?: string,\n large?: boolean\n): React.ReactNode => {\n return (\n <>\n {label && isComponent<LabelProps>(label, Label)\n ? React.cloneElement(label, {\n htmlFor: inputId,\n onColor,\n children: children,\n labelClassName: cn(labelClassName, label.props.labelClassName),\n labelTextClassName: labelTextClassName,\n sublabelWrapperClassName: sublabelWrapperClassName,\n sublabel: large ? undefined : label.props.sublabel,\n statusDot: large ? undefined : label.props.statusDot,\n })\n : typeof label === 'string' && (\n <Label\n labelTexts={[{ text: label }]}\n htmlFor={inputId}\n onColor={onColor}\n labelClassName={labelClassName}\n labelTextClassName={labelTextClassName}\n sublabelWrapperClassName={sublabelWrapperClassName}\n >\n {children}\n </Label>\n )}\n </>\n );\n};\n\nconst Label: FunctionComponent<LabelProps> = ({\n afterLabelChildren,\n children,\n className,\n htmlFor,\n labelClassName,\n labelTextClassName,\n labelId,\n labelTexts,\n onColor = FormOnColor.onwhite,\n statusDot,\n sublabel,\n sublabelWrapperClassName,\n testId,\n}) => {\n const hasChildren = children && typeof children !== 'undefined';\n const labelWrapperClasses = cn(\n styles['label-wrapper'],\n { [styles['label-wrapper--no-bottom-margin']]: hasChildren, [styles['label-wrapper--after-label-children']]: afterLabelChildren },\n className\n );\n\n const mapLabels = (): React.ReactNode => {\n return labelTexts.map((labelText, index) => {\n const labelClasses = cn(\n styles.label,\n {\n [styles['label--semibold']]: labelText.type === 'semibold',\n [styles['label--on-dark']]: onColor === FormOnColor.ondark,\n },\n labelTextClassName\n );\n return (\n <span aria-hidden={labelText.hideFromScreenReader} className={labelClasses} key={index}>\n {labelText.text}\n </span>\n );\n });\n };\n\n return (\n <div className={labelWrapperClasses}>\n <div>\n <label className={labelClassName} id={labelId} htmlFor={htmlFor} data-testid={testId} data-analyticsid={AnalyticsId.Label}>\n <span className={styles['label-content-wrapper']}>\n {children}\n <span className={styles.label__texts}>{mapLabels()}</span>\n </span>\n </label>\n <div className={sublabelWrapperClassName}>\n {sublabel &&\n isComponent<SublabelProps>(sublabel, Sublabel) &&\n React.cloneElement(sublabel, {\n onColor: onColor as FormOnColor,\n })}\n {statusDot && isComponent<StatusDotProps>(statusDot, StatusDot) && (\n <>\n <Spacer size={'3xs'} />\n {React.cloneElement(statusDot, {\n onColor: onColor === FormOnColor.ondark ? 'ondark' : 'onwhite',\n })}\n </>\n )}\n </div>\n </div>\n {afterLabelChildren && <div className={styles['after-label-children']}>{afterLabelChildren}</div>}\n </div>\n );\n};\n\nexport default Label;\n"],"names":["Sublabel","className","id","onColor","sublabelTexts","testId","mapSublabels","hideFromScreenReader","sublabelText","index","labelClasses","cn","styles","FormOnColor","jsx","subLabels","ariaHiddenSublabels","jsxs","Fragment","Spacer","AnalyticsId","getLabelText","label","allLabelText","isComponent","Label","labelText","renderLabel","inputId","React","renderLabelAsParent","children","labelClassName","labelTextClassName","sublabelWrapperClassName","large","afterLabelChildren","htmlFor","labelId","labelTexts","statusDot","sublabel","hasChildren","labelWrapperClasses","mapLabels","StatusDot"],"mappings":";;;;;;;;AAuBa,MAAAA,IAAoC,CAAC,EAAE,WAAAC,GAAW,IAAAC,GAAI,SAAAC,GAAS,eAAAC,GAAe,QAAAC,QAAa;AAChG,QAAAC,IAAe,CAACC,MAElBH,KACAA,EAAc,IAAI,CAACI,GAAcC,MAAU;AACzC,UAAMC,IAAeC,EAAGC,EAAO,OAAOA,EAAO,iBAAiB,GAAG;AAAA,MAC/D,CAACA,EAAO,iBAAiB,CAAC,GAAGJ,EAAa,SAAS;AAAA,MACnD,CAACI,EAAO,gBAAgB,CAAC,GAAGT,MAAYU,EAAY;AAAA,IAAA,CACrD;AAEC,WAAAN,MAAyBC,EAAa,wBACpC,gBAAAM,EAAC,UAAK,WAAWJ,GACd,UAAaF,EAAA,KAAA,GADoBC,CAEpC;AAAA,EAAA,CAGL,GAICM,IAAYT,KACZU,IAAsBV,EAAa,EAAI;AAE7C,SAEI,gBAAAW,EAAAC,GAAA,EAAA,UAAA;AAAA,IAAC,gBAAAJ,EAAAK,GAAA,EAAO,MAAM,MAAO,CAAA;AAAA,IACpBJ,KACE,gBAAAD,EAAA,OAAA,EAAI,WAAAb,GAAsB,IAAAC,GAAQ,eAAaG,GAAQ,oBAAkBe,EAAY,UACnF,UACHL,EAAA,CAAA;AAAA,IAEDC,KACE,gBAAAF,EAAA,OAAA,EAAI,WAAAb,GAAsB,eAAaI,GACrC,UACHW,G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MAAA,EAAA,CACrD,EACF,CAAA;AAAA,MACA,gBAAAK,EAAC,OAAI,EAAA,WAAWiB,GACb,UAAA;AAAA,QAAAO,KACCjB,EAA2BiB,GAAUzC,CAAQ,KAC7C6B,EAAM,aAAaY,GAAU;AAAA,UAC3B,SAAAtC;AAAA,QAAA,CACD;AAAA,QACFqC,KAAahB,EAA4BgB,GAAWK,CAAS,KAE1D,gBAAA5B,EAAAC,GAAA,EAAA,UAAA;AAAA,UAAC,gBAAAJ,EAAAK,GAAA,EAAO,MAAM,MAAO,CAAA;AAAA,UACpBU,EAAM,aAAaW,GAAW;AAAA,YAC7B,SAASrC,MAAYU,EAAY,SAAS,WAAW;AAAA,UAAA,CACtD;AAAA,QAAA,GACH;AAAA,MAAA,GAEJ;AAAA,IAAA,GACF;AAAA,IACCuB,KAAuB,gBAAAtB,EAAA,OAAA,EAAI,WAAWF,EAAO,sBAAsB,GAAI,UAAmBwB,GAAA;AAAA,EAC7F,EAAA,CAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"Label.js","sources":["../src/components/Label/SubLabel.tsx","../src/components/Label/Label.tsx"],"sourcesContent":["import React from 'react';\n\nimport cn from 'classnames';\n\nimport { LabelText } from './Label';\nimport { AnalyticsId, FormOnColor } from '../../constants';\nimport Spacer from '../Spacer';\n\nimport styles from './styles.module.scss';\n\nexport interface SublabelProps {\n /** Adds custom classes to the element. */\n className?: string;\n /** id that is placed on the wrapper */\n id: string;\n /** Array of sublabel strings. Can be of type semibold or normal */\n onColor?: FormOnColor;\n /** Array of sublabel strings. Can be of type semibold or normal */\n sublabelTexts?: LabelText[];\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport const Sublabel: React.FC<SublabelProps> = ({ className, id, onColor, sublabelTexts, testId }) => {\n const mapSublabels = (hideFromScreenReader?: boolean): React.ReactNode => {\n return (\n sublabelTexts &&\n sublabelTexts.map((sublabelText, index) => {\n const labelClasses = cn(styles.label, styles['label--sublabel'], {\n [styles['label--semibold']]: sublabelText.type === 'semibold',\n [styles['label--on-dark']]: onColor === FormOnColor.ondark,\n });\n return (\n hideFromScreenReader === sublabelText.hideFromScreenReader && (\n <span className={labelClasses} key={index}>\n {sublabelText.text}\n </span>\n )\n );\n })\n );\n };\n\n const subLabels = mapSublabels();\n const ariaHiddenSublabels = mapSublabels(true);\n\n return (\n <>\n <Spacer size={'3xs'} />\n {subLabels && (\n <div className={className} id={id} data-testid={testId} data-analyticsid={AnalyticsId.Sublabel}>\n {subLabels}\n </div>\n )}\n {ariaHiddenSublabels && (\n <div className={className} data-testid={testId}>\n {ariaHiddenSublabels}\n </div>\n )}\n </>\n );\n};\n","import React, { FunctionComponent } from 'react';\n\nimport cn from 'classnames';\n\nimport { Sublabel, SublabelProps } from './SubLabel';\nimport { AnalyticsId, FormOnColor } from '../../constants';\nimport { isComponent } from '../../utils/component';\nimport Spacer from '../Spacer';\nimport StatusDot, { StatusDotProps } from '../StatusDot';\n\nimport styles from './styles.module.scss';\n\nexport type LabelText = {\n hideFromScreenReader?: boolean;\n text: string;\n type?: 'semibold' | 'normal';\n};\n\nexport type LabelTags = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'span' | 'label' | 'p';\n\nexport interface LabelProps {\n /** Component shown after label - discourage use of this */\n afterLabelChildren?: React.ReactNode;\n /** Adds custom classes to the element. */\n children?: React.ReactNode;\n /** Adds custom classes to the label tag. */\n labelClassName?: string;\n /** Adds custom classes to the label text. */\n labelTextClassName?: string;\n /** Adds custom classes to the element. */\n className?: string;\n /** Id that is put on the \"for\" attribute of the label */\n htmlFor?: string;\n /** Changes the underlying element of the label */\n htmlMarkup?: LabelTags;\n /** Id som plasseres på <label/> */\n labelId?: string;\n /** Array of main label strings. Can be of type semibold or normal */\n labelTexts: LabelText[];\n /** Array of sublabel strings. Can be of type semibold or normal */\n onColor?: keyof typeof FormOnColor;\n /** StatusDot placed underneath the last sublabel */\n statusDot?: React.ReactNode;\n /** Sublabel component */\n sublabel?: React.ReactNode;\n /** Adds custom classes to the div wrapping the sublabels. */\n sublabelWrapperClassName?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport const getLabelText = (label: React.ReactNode): string => {\n let allLabelText = '';\n\n if (isComponent<LabelProps>(label, Label)) {\n label.props.labelTexts.forEach(labelText => {\n allLabelText += !labelText.hideFromScreenReader ? labelText.text : '';\n });\n }\n\n return allLabelText;\n};\n\nexport const renderLabel = (label: React.ReactNode, inputId: string, onColor: FormOnColor, markup?: LabelTags): React.ReactNode => {\n return (\n <>\n {label && isComponent<LabelProps>(label, Label)\n ? React.cloneElement(label, {\n htmlFor: inputId,\n htmlMarkup: markup || 'label',\n onColor,\n })\n : typeof label === 'string' && <Label labelTexts={[{ text: label, type: 'semibold' }]} htmlFor={inputId} onColor={onColor} />}\n </>\n );\n};\n\nexport const renderLabelAsParent = (\n label: React.ReactNode,\n children: React.ReactNode,\n inputId: string,\n onColor: FormOnColor,\n labelClassName?: string,\n labelTextClassName?: string,\n sublabelWrapperClassName?: string,\n large?: boolean,\n markup?: LabelTags\n): React.ReactNode => {\n return (\n <>\n {label && isComponent<LabelProps>(label, Label)\n ? React.cloneElement(label, {\n htmlFor: inputId,\n onColor,\n children: children,\n labelClassName: cn(labelClassName, label.props.labelClassName),\n labelTextClassName: labelTextClassName,\n htmlMarkup: markup || 'label',\n sublabelWrapperClassName: sublabelWrapperClassName,\n sublabel: large ? undefined : label.props.sublabel,\n statusDot: large ? undefined : label.props.statusDot,\n })\n : typeof label === 'string' && (\n <Label\n labelTexts={[{ text: label }]}\n htmlFor={inputId}\n onColor={onColor}\n htmlMarkup={markup || 'label'}\n labelClassName={labelClassName}\n labelTextClassName={labelTextClassName}\n sublabelWrapperClassName={sublabelWrapperClassName}\n >\n {children}\n </Label>\n )}\n </>\n );\n};\n\nconst Label: FunctionComponent<LabelProps> = ({\n afterLabelChildren,\n children,\n className,\n htmlFor,\n htmlMarkup = 'label',\n labelClassName,\n labelTextClassName,\n labelId,\n labelTexts,\n onColor = FormOnColor.onwhite,\n statusDot,\n sublabel,\n sublabelWrapperClassName,\n testId,\n}) => {\n const hasChildren = children && typeof children !== 'undefined';\n const labelWrapperClasses = cn(\n styles['label-wrapper'],\n { [styles['label-wrapper--no-bottom-margin']]: hasChildren, [styles['label-wrapper--after-label-children']]: afterLabelChildren },\n className\n );\n\n const mapLabels = (): React.ReactNode => {\n return labelTexts.map((labelText, index) => {\n const labelClasses = cn(\n styles.label,\n {\n [styles['label--semibold']]: labelText.type === 'semibold',\n [styles['label--on-dark']]: onColor === FormOnColor.ondark,\n },\n labelTextClassName\n );\n return (\n <span aria-hidden={labelText.hideFromScreenReader} className={labelClasses} key={index}>\n {labelText.text}\n </span>\n );\n });\n };\n const CustomTag = htmlMarkup;\n\n return (\n <div className={labelWrapperClasses}>\n <div>\n <CustomTag className={labelClassName} id={labelId} htmlFor={htmlFor} data-testid={testId} data-analyticsid={AnalyticsId.Label}>\n <span className={styles['label-content-wrapper']}>\n {children}\n <span className={styles.label__texts}>{mapLabels()}</span>\n </span>\n </CustomTag>\n <div className={sublabelWrapperClassName}>\n {sublabel &&\n isComponent<SublabelProps>(sublabel, Sublabel) &&\n React.cloneElement(sublabel, {\n onColor: onColor as FormOnColor,\n })}\n {statusDot && isComponent<StatusDotProps>(statusDot, StatusDot) && (\n <>\n <Spacer size={'3xs'} />\n {React.cloneElement(statusDot, {\n onColor: onColor === FormOnColor.ondark ? 'ondark' : 'onwhite',\n })}\n </>\n )}\n </div>\n </div>\n {afterLabelChildren && <div className={styles['after-label-children']}>{afterLabelChildren}</div>}\n </div>\n );\n};\n\nexport default Label;\n"],"names":["Sublabel","className","id","onColor","sublabelTexts","testId","mapSublabels","hideFromScreenReader","sublabelText","index","labelClasses","cn","styles","FormOnColor","jsx","subLabels","ariaHiddenSublabels","jsxs","Fragment","Spacer","AnalyticsId","getLabelText","label","allLabelText","isComponent","Label","labelText","renderLabel","inputId","markup","React","renderLabelAsParent","children","labelClassName","labelTextClassName","sublabelWrapperClassName","large","afterLabelChildren","htmlFor","htmlMarkup","labelId","labelTexts","statusDot","sublabel","hasChildren","labelWrapperClasses","mapLabels","StatusDot"],"mappings":";;;;;;;;AAuBa,MAAAA,IAAoC,CAAC,EAAE,WAAAC,GAAW,IAAAC,GAAI,SAAAC,GAAS,eAAAC,GAAe,QAAAC,QAAa;AAChG,QAAAC,IAAe,CAACC,MAElBH,KACAA,EAAc,IAAI,CAACI,GAAcC,MAAU;AACzC,UAAMC,IAAeC,EAAGC,EAAO,OAAOA,EAAO,iBAAiB,GAAG;AAAA,MAC/D,CAACA,EAAO,iBAAiB,CAAC,GAAGJ,EAAa,SAAS;AAAA,MACnD,CAACI,EAAO,gBAAgB,CAAC,GAAGT,MAAYU,EAAY;AAAA,IAAA,CACrD;AAEC,WAAAN,MAAyBC,EAAa,wBACpC,gBAAAM,EAAC,UAAK,WAAWJ,GACd,UAAaF,EAAA,KAAA,GADoBC,CAEpC;AAAA,EAAA,CAGL,GAICM,IAAYT,KACZU,IAAsBV,EAAa,EAAI;AAE7C,SAEI,gBAAAW,EAAAC,GAAA,EAAA,UAAA;AAAA,IAAC,gBAAAJ,EAAAK,GAAA,EAAO,MAAM,MAAO,CAAA;AAAA,IACpBJ,KACE,gBAAAD,EAAA,OAAA,EAAI,WAAAb,GAAsB,IAAAC,GAAQ,eAAaG,GAAQ,oBAAkBe,EAAY,UACnF,UACHL,EAAA,CAAA;AAAA,IAEDC,KACE,gBAAAF,EAAA,OAAA,EAAI,WAAAb,GAAsB,eAAaI,GACrC,UACHW,GAAA;AAAA,EAEJ,EAAA,CAAA;AAEJ,GCVaK,IAAe,CAACC,MAAmC;AAC9D,MAAIC,IAAe;AAEf,SAAAC,EAAwBF,GAAOG,CAAK,KAChCH,EAAA,MAAM,WAAW,QAAQ,CAAaI,MAAA;AAC1C,IAAAH,KAAiBG,EAAU,uBAAwC,KAAjBA,EAAU;AAAA,EAAO,CACpE,GAGIH;AACT,GAEaI,IAAc,CAACL,GAAwBM,GAAiBzB,GA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