@helsenorge/designsystem-react 5.0.0 → 5.1.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 +62 -0
- package/FormGroup.js +1 -1
- package/FormGroup.js.map +1 -1
- package/FormLayout.js +1 -1
- package/FormLayout.js.map +1 -1
- package/Input.js +1 -1
- package/Input.js.map +1 -1
- package/RadioButton.js +1 -1
- package/RadioButton.js.map +1 -1
- package/Select.js.map +1 -1
- package/Textarea.js +1 -1
- package/Textarea.js.map +1 -1
- package/components/Button/styles.module.scss +11 -0
- package/components/FormExample/FormExample.d.ts +1 -2
- package/components/FormExample/FormExample.d.ts.map +1 -1
- package/components/FormExample/componentdata.json +1 -1
- package/components/FormExample/index.js +3 -3
- package/components/FormExample/index.js.map +1 -1
- package/components/FormGroup/FormGroup.d.ts.map +1 -1
- package/components/FormGroup/index.js +1 -1
- package/components/FormLayout/FormLayout.d.ts +1 -1
- package/components/FormLayout/FormLayout.d.ts.map +1 -1
- package/components/FormLayout/componentdata.json +1 -1
- package/components/HighlightBox/styles.module.scss +5 -2
- package/components/Input/Input.d.ts +7 -1
- package/components/Input/Input.d.ts.map +1 -1
- package/components/Input/componentdata.json +1 -1
- package/components/Input/index.js +1 -1
- package/components/Input/styles.module.scss +11 -1
- package/components/Input/styles.module.scss.d.ts +12 -10
- package/components/Label/componentdata.json +1 -1
- package/components/RadioButton/RadioButton.d.ts +3 -0
- package/components/RadioButton/RadioButton.d.ts.map +1 -1
- package/components/RadioButton/componentdata.json +1 -1
- package/components/RadioButton/index.js +1 -1
- package/components/Select/Select.d.ts +1 -1
- package/components/Select/Select.d.ts.map +1 -1
- package/components/Select/componentdata.json +1 -1
- package/components/Textarea/styles.module.scss +2 -2
- package/components/Textarea/styles.module.scss.d.ts +9 -9
- package/components/Validation/index.js +1 -1
- package/index.d.ts +1 -0
- package/index.d.ts.map +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/scss/_input.scss +1 -1
- package/utils/mobile.d.ts +10 -0
- package/utils/mobile.d.ts.map +1 -0
- package/utils/mobile.js +2 -0
- package/utils/mobile.js.map +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,65 @@
|
|
|
1
|
+
## [5.1.1](https://github.com/helsenorge/designsystem/branchCompare?baseVersion=GTv5.1.0&targetVersion=GTv5.1.1) (2023-10-30)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
- input type number base inkrementering verdi
|
|
6
|
+
([6b8113e](https://github.com/helsenorge/designsystem/commit/6b8113ea73653981cfe80f7012508b7ee77279e8)), closes
|
|
7
|
+
[#312174](https://github.com/helsenorge/designsystem/issues/312174)
|
|
8
|
+
- input width fikset ([07a4c52](https://github.com/helsenorge/designsystem/commit/07a4c52cbfa04b1a19cf983227eb28968607baeb)), closes
|
|
9
|
+
[#312326](https://github.com/helsenorge/designsystem/issues/312326)
|
|
10
|
+
|
|
11
|
+
## [5.1.0](https://github.com/helsenorge/designsystem/branchCompare?baseVersion=GTv5.0.0&targetVersion=GTv5.1.0) (2023-10-26)
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
- nytt komponent datepicker ([59d3193](https://github.com/helsenorge/designsystem/commit/59d3193992d1c98b4f38a12d9aae03909f0653b0)), closes
|
|
16
|
+
[#306637](https://github.com/helsenorge/designsystem/issues/306637)
|
|
17
|
+
- select støtter onChange ([3439471](https://github.com/helsenorge/designsystem/commit/3439471cbe7481ee8a0db1b8a2aca0071a379f43)), closes
|
|
18
|
+
[#309850](https://github.com/helsenorge/designsystem/issues/309850)
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
- datepicker ux endringer etter feedback
|
|
23
|
+
([db17354](https://github.com/helsenorge/designsystem/commit/db173541a1c0c5f1dc4c9b8fe42c6df3763e13e3)), closes
|
|
24
|
+
[#306637](https://github.com/helsenorge/designsystem/issues/306637)
|
|
25
|
+
- radiobutton bigform checked styling
|
|
26
|
+
([1cf5580](https://github.com/helsenorge/designsystem/commit/1cf5580270313614719d92fbb1a01dab5881d742)), closes
|
|
27
|
+
[#305272](https://github.com/helsenorge/designsystem/issues/305272)
|
|
28
|
+
- vite bygg og dependencies ([2e45dcd](https://github.com/helsenorge/designsystem/commit/2e45dcd23494ae77341cff0b02c6517011ca4cbe)), closes
|
|
29
|
+
[#306637](https://github.com/helsenorge/designsystem/issues/306637)
|
|
30
|
+
|
|
31
|
+
## [5.0.0](https://github.com/helsenorge/designsystem/branchCompare?baseVersion=GTv4.4.0&targetVersion=GTv5.0.0) (2023-09-25)
|
|
32
|
+
|
|
33
|
+
### ⚠ BREAKING CHANGES
|
|
34
|
+
|
|
35
|
+
- role=region må settes via prop
|
|
36
|
+
- name/id settes ikke lenger default til verdien av title. Man må sette name/id selv om man trenger det.
|
|
37
|
+
- fjernet mulighet for at Tile kan være button
|
|
38
|
+
|
|
39
|
+
### Features
|
|
40
|
+
|
|
41
|
+
- formgroup har prop for fieldset name
|
|
42
|
+
([625f843](https://github.com/helsenorge/designsystem/commit/625f843aa947601f7edaa82f388f6c22cda00851)), closes
|
|
43
|
+
[#308141](https://github.com/helsenorge/designsystem/issues/308141)
|
|
44
|
+
- helppanel ([e2e8f23](https://github.com/helsenorge/designsystem/commit/e2e8f2319626be54174c129f59f83e42603dd237))
|
|
45
|
+
|
|
46
|
+
### Bug Fixes
|
|
47
|
+
|
|
48
|
+
- expanderList/LinkList (ListHeader) HtmlValidering i story
|
|
49
|
+
([72b12a3](https://github.com/helsenorge/designsystem/commit/72b12a3a5570e6f73fb69045cbe90d0572fd5da6)), closes
|
|
50
|
+
[#308137](https://github.com/helsenorge/designsystem/issues/308137)
|
|
51
|
+
- highlightbox har ikke lenger fargene kiwi/plum
|
|
52
|
+
([8852e6c](https://github.com/helsenorge/designsystem/commit/8852e6cd07abf4995518ffcea6fb2bb5b421b84e)), closes
|
|
53
|
+
[#305259](https://github.com/helsenorge/designsystem/issues/305259)
|
|
54
|
+
- html i Tile validerer ([f0a9f37](https://github.com/helsenorge/designsystem/commit/f0a9f3739f39fa33d2feb1d78812958730c09f33)), closes
|
|
55
|
+
[#308149](https://github.com/helsenorge/designsystem/issues/308149)
|
|
56
|
+
- ikke bruk aria-attributter med mindre NotificationPanel har role
|
|
57
|
+
([8f1b09b](https://github.com/helsenorge/designsystem/commit/8f1b09b48a4840c8a8ce0efb7abdbed05de62a8e)), closes
|
|
58
|
+
[#309176](https://github.com/helsenorge/designsystem/issues/309176)
|
|
59
|
+
- notificationpanel er ikke region som default
|
|
60
|
+
([00103ce](https://github.com/helsenorge/designsystem/commit/00103ce8a237f0222966f3a25f80f2222fbecf37)), closes
|
|
61
|
+
[#309176](https://github.com/helsenorge/designsystem/issues/309176)
|
|
62
|
+
|
|
1
63
|
## [4.4.0](https://github.com/helsenorge/designsystem/branchCompare?baseVersion=GTv4.3.1&targetVersion=GTv4.4.0) (2023-09-15)
|
|
2
64
|
|
|
3
65
|
### Features
|
package/FormGroup.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import r from"react";import l from"classnames";import{FormMode as
|
|
1
|
+
import r,{useState as _}from"react";import l from"classnames";import{FormMode as k,FormVariant as F,AnalyticsId as A}from"./constants.js";import{isComponent as s}from"./utils/component.js";import{u as D}from"./uuid.js";import{C as H}from"./Checkbox.js";import{E as V}from"./ErrorWrapper.js";import{F as $}from"./FormLayout.js";import{I as j}from"./Input.js";import{R as q,g as z}from"./RadioButton.js";import{S as J}from"./Select.js";import{T as K}from"./Title.js";import t from"./components/FormGroup/styles.module.scss";const u=r.forwardRef((o,G)=>{const{className:b,fieldsetClassName:w,mode:n=k.onwhite,variant:m=F.normal,error:a,name:p,htmlMarkup:c="fieldset",renderError:R=!0,errorWrapperClassName:y,errorWrapperTestId:v}=o,[T,x]=_(),[S]=_(D()),i=n===k.ondark,f=m===F.bigform,W=l(t["form-group-wrapper"],{[t["form-group-wrapper--on-dark"]]:i,[t["form-group-wrapper--invalid"]]:a},b),M=l(t["form-group-wrapper__title"],{[t["form-group-wrapper__title--on-dark"]]:i&&!a,[t["form-group-wrapper__title--bigform"]]:f}),B=l(t["form-group"]),g=l(t["field-set__legend"],{[t["field-set__legend--on-dark"]]:i&&!a,[t["field-set__legend--bigform"]]:f}),C=l(t["field-set"],w),d=(e,L)=>{if(s(e,$))return r.cloneElement(e,{variant:m,mapHelper:d});if(s(e,u))return r.cloneElement(e,{mode:n,variant:m,error:a,renderError:!1});if(s(e,H))return r.cloneElement(e,{name:p??e.props.name,mode:n,variant:m,error:!!a});if(s(e,q)){const N=typeof e.props.inputId>"u"?S+L:e.props.inputId;return r.cloneElement(e,{inputId:N,name:p??e.props.name,mode:n,onChange:I=>{x(I.target.id),e.props.onChange&&e.props.onChange(I)},variant:m,error:!!a,labelClassNames:z(N,n,f,T)})}else{if(s(e,j))return r.cloneElement(e,{name:p??e.props.name,mode:n,variant:m,error:!!a});if(s(e,J))return r.cloneElement(e,{name:p??e.props.name,mode:n,error:!!a})}return e},E=()=>r.createElement("div",{className:B},c==="div"&&r.createElement("div",{className:C},o.legend&&r.createElement("h5",{className:g},o.legend),r.Children.map(o.children,d)),c==="fieldset"&&r.createElement("fieldset",{name:o.fieldsetName,className:C},o.legend&&r.createElement("legend",{className:g},o.legend),r.Children.map(o.children,d)));return r.createElement("div",{"data-testid":o.testId,"data-analyticsid":A.FormGroup,className:W,ref:G,tabIndex:-1},o.title&&r.createElement(K,{className:M,htmlMarkup:"h4",appearance:"title4",margin:{marginTop:0,marginBottom:a?1:2}},o.title),R?r.createElement(V,{className:y,errorText:a,testId:v},E()):E())});u.displayName="FormGroup";const ne=u;export{ne as F,u as a};
|
|
2
2
|
//# sourceMappingURL=FormGroup.js.map
|
package/FormGroup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormGroup.js","sources":["../src/components/FormGroup/FormGroup.tsx"],"sourcesContent":["import React from 'react';\n\nimport classNames from 'classnames';\n\nimport { AnalyticsId, FormMode, FormVariant } from '../../constants';\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 } from '../RadioButton/RadioButton';\nimport Select, { SelectProps } from '../Select';\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 mode?: keyof typeof FormMode;\n /** Changes the visuals of the formgroup */\n variant?: keyof typeof FormVariant;\n /** Error message */\n error?: 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 mode = FormMode.onwhite,\n variant = FormVariant.normal,\n error,\n name,\n htmlMarkup = 'fieldset',\n renderError = true,\n errorWrapperClassName,\n errorWrapperTestId,\n } = props;\n const onDark = mode === FormMode.ondark;\n const bigform = variant === FormVariant.bigform;\n const formGroupWrapperClasses = classNames(\n formGroupStyles['form-group-wrapper'],\n {\n [formGroupStyles['form-group-wrapper--on-dark']]: onDark,\n [formGroupStyles['form-group-wrapper--invalid']]: error,\n },\n className\n );\n const titleClasses = classNames(formGroupStyles['form-group-wrapper__title'], {\n [formGroupStyles['form-group-wrapper__title--on-dark']]: onDark && !error,\n [formGroupStyles['form-group-wrapper__title--bigform']]: bigform,\n });\n const formGroupClasses = classNames(formGroupStyles['form-group']);\n\n const legendClasses = classNames(formGroupStyles['field-set__legend'], {\n [formGroupStyles['field-set__legend--on-dark']]: onDark && !error,\n [formGroupStyles['field-set__legend--bigform']]: bigform,\n });\n\n const fieldsetClasses = classNames(formGroupStyles['field-set'], fieldsetClassName);\n\n const mapFormComponent = (child: React.ReactNode): React.ReactNode => {\n if (isComponent<FormGroupProps>(child, FormLayout)) {\n return React.cloneElement(child as React.ReactElement<FormLayoutProps>, {\n variant,\n mapHelper: mapFormComponent,\n });\n } else if (isComponent<FormGroupProps>(child, FormGroup)) {\n return React.cloneElement(child, {\n mode,\n variant,\n error,\n renderError: false,\n });\n } else if (isComponent<CheckboxProps>(child, Checkbox)) {\n return React.cloneElement(child as React.ReactElement<CheckboxProps>, {\n name: name ?? child.props.name,\n mode,\n variant,\n error: !!error,\n });\n } else if (isComponent<RadioButtonProps>(child, RadioButton)) {\n return React.cloneElement(child as React.ReactElement<RadioButtonProps>, {\n name: name ?? child.props.name,\n mode,\n variant,\n error: !!error,\n });\n } else if (isComponent<InputProps>(child, Input)) {\n return React.cloneElement(child as React.ReactElement<InputProps>, {\n name: name ?? child.props.name,\n mode,\n variant,\n error: !!error,\n });\n } else if (isComponent<SelectProps>(child, Select)) {\n return React.cloneElement(child as React.ReactElement<SelectProps>, {\n name: name ?? child.props.name,\n mode,\n error: !!error,\n });\n }\n return child;\n };\n\n const formGroupContent = () => {\n return (\n <div className={formGroupClasses}>\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}>\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","mode","FormMode","variant","FormVariant","error","name","htmlMarkup","renderError","errorWrapperClassName","errorWrapperTestId","onDark","bigform","formGroupWrapperClasses","classNames","formGroupStyles","titleClasses","formGroupClasses","legendClasses","fieldsetClasses","mapFormComponent","child","isComponent","FormLayout","Checkbox","RadioButton","Input","Select","formGroupContent","AnalyticsId","Title","ErrorWrapper","FormGroup$1"],"mappings":"sdAmDO,MAAMA,EAAYC,EAAM,WAAW,CAACC,EAAuBC,IAA4C,CACtG,KAAA,CACJ,UAAAC,EACA,kBAAAC,EACA,KAAAC,EAAOC,EAAS,QAChB,QAAAC,EAAUC,EAAY,OACtB,MAAAC,EACA,KAAAC,EACA,WAAAC,EAAa,WACb,YAAAC,EAAc,GACd,sBAAAC,EACA,mBAAAC,CACE,EAAAb,EACEc,EAASV,IAASC,EAAS,OAC3BU,EAAUT,IAAYC,EAAY,QAClCS,EAA0BC,EAC9BC,EAAgB,oBAAoB,EACpC,CACE,CAACA,EAAgB,6BAA6B,CAAC,EAAGJ,EAClD,CAACI,EAAgB,6BAA6B,CAAC,EAAGV,CACpD,EACAN,CAAA,EAEIiB,EAAeF,EAAWC,EAAgB,2BAA2B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AAI,CAAA,UAAWqB,CACb,EAAAV,IAAe,OACbX,EAAA,cAAA,MAAA,CAAI,UAAWuB,CAAA,EACbtB,EAAM,wBAAW,KAAG,CAAA,UAAWqB,CAAgB,EAAArB,EAAM,MAAO,EAC5DD,EAAM,SAAS,IAAIC,EAAM,SAAUuB,CAAgB,CACtD,EAEDb,IAAe,YACbX,EAAA,cAAA,WAAA,CAAS,KAAMC,EAAM,aAAc,UAAWsB,CAAA,EAC5CtB,EAAM,QAAWD,EAAA,cAAA,SAAA,CAAO,UAAWsB,CAAgB,EAAArB,EAAM,MAAO,EAChED,EAAM,SAAS,IAAIC,EAAM,SAAUuB,CAAgB,CACtD,CAEJ,EAKF,OAAAxB,EAAA,cAAC,OAAI,cAAaC,EAAM,OAAQ,mBAAkBgC,EAAY,UAAW,UAAWhB,EAAyB,IAAAf,EAAU,SAAU,EAC9H,EAAAD,EAAM,OACJD,EAAA,cAAAkC,EAAA,CAAM,UAAWd,EAAc,WAAY,KAAM,WAAY,SAAU,OAAQ,CAAE,UAAW,EAAG,aAAcX,EAAQ,EAAI,CACvH,CAAA,EAAAR,EAAM,KACT,EAEDW,EACCZ,EAAA,cAACmC,GAAa,UAAWtB,EAAuB,UAAWJ,EAAO,OAAQK,GACvEkB,EAAiB,CACpB,EAEAA,EAEJ,CAAA,CAEJ,CAAC,EAEDjC,EAAU,YAAc,YAExB,MAAAqC,EAAerC"}
|
|
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, FormMode, FormVariant } from '../../constants';\nimport { isComponent } from '../../utils/component';\nimport uuid from '../../utils/uuid';\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 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 mode?: keyof typeof FormMode;\n /** Changes the visuals of the formgroup */\n variant?: keyof typeof FormVariant;\n /** Error message */\n error?: 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 mode = FormMode.onwhite,\n variant = FormVariant.normal,\n error,\n name,\n htmlMarkup = 'fieldset',\n renderError = true,\n errorWrapperClassName,\n errorWrapperTestId,\n } = props;\n const [checkedRadioId, setCheckedRadioId] = useState<string>();\n const [radioGroupId] = useState<string>(uuid());\n const onDark = mode === FormMode.ondark;\n const bigform = variant === FormVariant.bigform;\n const formGroupWrapperClasses = classNames(\n formGroupStyles['form-group-wrapper'],\n {\n [formGroupStyles['form-group-wrapper--on-dark']]: onDark,\n [formGroupStyles['form-group-wrapper--invalid']]: error,\n },\n className\n );\n const titleClasses = classNames(formGroupStyles['form-group-wrapper__title'], {\n [formGroupStyles['form-group-wrapper__title--on-dark']]: onDark && !error,\n [formGroupStyles['form-group-wrapper__title--bigform']]: bigform,\n });\n const formGroupClasses = classNames(formGroupStyles['form-group']);\n\n const legendClasses = classNames(formGroupStyles['field-set__legend'], {\n [formGroupStyles['field-set__legend--on-dark']]: onDark && !error,\n [formGroupStyles['field-set__legend--bigform']]: bigform,\n });\n\n const fieldsetClasses = classNames(formGroupStyles['field-set'], fieldsetClassName);\n\n const mapFormComponent = (child: React.ReactNode, index: number): React.ReactNode => {\n if (isComponent<FormGroupProps>(child, FormLayout)) {\n return React.cloneElement(child as React.ReactElement<FormLayoutProps>, {\n variant,\n mapHelper: mapFormComponent,\n });\n } else if (isComponent<FormGroupProps>(child, FormGroup)) {\n return React.cloneElement(child, {\n mode,\n variant,\n error,\n renderError: false,\n });\n } else if (isComponent<CheckboxProps>(child, Checkbox)) {\n return React.cloneElement(child as React.ReactElement<CheckboxProps>, {\n name: name ?? child.props.name,\n mode,\n variant,\n error: !!error,\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 as React.ReactElement<RadioButtonProps>, {\n inputId: radioId,\n name: name ?? child.props.name,\n mode,\n onChange: (event: React.ChangeEvent<HTMLInputElement>) => {\n setCheckedRadioId(event.target.id);\n child.props.onChange && child.props.onChange(event);\n },\n variant,\n error: !!error,\n labelClassNames: getRadioLabelClasses(radioId, mode as FormMode, bigform, checkedRadioId),\n });\n } else if (isComponent<InputProps>(child, Input)) {\n return React.cloneElement(child as React.ReactElement<InputProps>, {\n name: name ?? child.props.name,\n mode,\n variant,\n error: !!error,\n });\n } else if (isComponent<SelectProps>(child, Select)) {\n return React.cloneElement(child as React.ReactElement<SelectProps>, {\n name: name ?? child.props.name,\n mode,\n error: !!error,\n });\n }\n return child;\n };\n\n const formGroupContent = (): React.ReactNode => {\n return (\n <div className={formGroupClasses}>\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}>\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","mode","FormMode","variant","FormVariant","error","name","htmlMarkup","renderError","errorWrapperClassName","errorWrapperTestId","checkedRadioId","setCheckedRadioId","useState","radioGroupId","uuid","onDark","bigform","formGroupWrapperClasses","classNames","formGroupStyles","titleClasses","formGroupClasses","legendClasses","fieldsetClasses","mapFormComponent","child","index","isComponent","FormLayout","Checkbox","RadioButton","radioId","event","getRadioLabelClasses","Input","Select","formGroupContent","AnalyticsId","Title","ErrorWrapper","FormGroup$1"],"mappings":"0gBAoDO,MAAMA,EAAYC,EAAM,WAAW,CAACC,EAAuBC,IAA4C,CACtG,KAAA,CACJ,UAAAC,EACA,kBAAAC,EACA,KAAAC,EAAOC,EAAS,QAChB,QAAAC,EAAUC,EAAY,OACtB,MAAAC,EACA,KAAAC,EACA,WAAAC,EAAa,WACb,YAAAC,EAAc,GACd,sBAAAC,EACA,mBAAAC,CACE,EAAAb,EACE,CAACc,EAAgBC,CAAiB,EAAIC,EAAiB,EACvD,CAACC,CAAY,EAAID,EAAiBE,EAAM,CAAA,EACxCC,EAASf,IAASC,EAAS,OAC3Be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AAU,OAAQ,CAAE,UAAW,EAAG,aAAchB,EAAQ,EAAI,CACvH,CAAA,EAAAR,EAAM,KACT,EAEDW,EACCZ,EAAA,cAAC4C,GAAa,UAAW/B,EAAuB,UAAWJ,EAAO,OAAQK,GACvE2B,EAAiB,CACpB,EAEAA,EAEJ,CAAA,CAEJ,CAAC,EAED1C,EAAU,YAAc,YAExB,MAAA8C,GAAe9C"}
|
package/FormLayout.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import a from"react";import m from"classnames";import{FormVariant as h,AnalyticsId as v}from"./constants.js";import o from"./components/FormLayout/styles.module.scss";var p=(t=>(t.one="one",t.two="two",t.three="three",t.four="four",t.five="five",t))(p||{});const l=a.forwardRef((t,w)=>{const{maxColumns:r="one",colMinWidth:s=300,variant:f,className:c,mapHelper:e}=t,n={"--min-col-width":`${s}px`},d=m(o["form-layout-container"],{[o["form-layout-container--bigform"]]:f===h.bigform},c),u=m(o["form-layout-child"],{[o["form-layout-child--two"]]:r==="two",[o["form-layout-child--three"]]:r==="three",[o["form-layout-child--four"]]:r==="four",[o["form-layout-child--five"]]:r==="five"});return a.createElement("div",{"data-testid":t.testId,"data-analyticsid":v.FormLayout,style:n,className:d},a.Children.map(t.children,(i,y)=>a.createElement("div",{className:u},e?e(i,y):i)))});l.displayName="FormLayout";const C=l;export{C as F,p as a,l as b};
|
|
2
2
|
//# sourceMappingURL=FormLayout.js.map
|
package/FormLayout.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormLayout.js","sources":["../src/components/FormLayout/FormLayout.tsx"],"sourcesContent":["import React from 'react';\n\nimport classNames from 'classnames';\n\nimport { AnalyticsId, FormVariant } from '../../constants';\n\nimport formGroupStyles from './styles.module.scss';\n\nexport enum FormLayoutColumns {\n one = 'one',\n two = 'two',\n three = 'three',\n four = 'four',\n five = 'five',\n}\n\nexport interface FormLayoutProps {\n /** The max number of columns that will exist if space is available */\n maxColumns?: keyof typeof FormLayoutColumns;\n /** Sets the minimum width for the columns in pixels - this determines how many will fit on a row */\n colMinWidth?: number;\n /** Items in the FormLayout component */\n children?: React.ReactNode;\n /** Changes the visuals of the formgroup */\n variant?: keyof typeof FormVariant;\n /** Adds custom classes to the element. */\n className?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Function that helps map the form children */\n mapHelper?: (child: React.ReactNode) => React.ReactNode;\n}\n\nexport const FormLayout = React.forwardRef((props: FormLayoutProps, ref: React.ForwardedRef<HTMLElement>) => {\n const { maxColumns: columns = FormLayoutColumns.one, colMinWidth = 300, variant, className, mapHelper } = props;\n\n const cssVariable = { '--min-col-width': `${colMinWidth}px` } as React.CSSProperties;\n const formLayoutContainerClasses = classNames(\n formGroupStyles['form-layout-container'],\n {\n [formGroupStyles['form-layout-container--bigform']]: variant === FormVariant.bigform,\n },\n className\n );\n const formLayoutChildClasses = classNames(formGroupStyles['form-layout-child'], {\n [formGroupStyles['form-layout-child--two']]: columns === FormLayoutColumns.two,\n [formGroupStyles['form-layout-child--three']]: columns === FormLayoutColumns.three,\n [formGroupStyles['form-layout-child--four']]: columns === FormLayoutColumns.four,\n [formGroupStyles['form-layout-child--five']]: columns === FormLayoutColumns.five,\n });\n\n return (\n <div data-testid={props.testId} data-analyticsid={AnalyticsId.FormLayout} style={cssVariable} className={formLayoutContainerClasses}>\n {React.Children.map(props.children, (child: React.ReactNode) => {\n return <div className={formLayoutChildClasses}>{mapHelper ? mapHelper(child) : child}</div>;\n })}\n </div>\n );\n});\n\nexport default FormLayout;\n"],"names":["FormLayoutColumns","FormLayout","React","props","ref","columns","colMinWidth","variant","className","mapHelper","cssVariable","formLayoutContainerClasses","classNames","formGroupStyles","FormVariant","formLayoutChildClasses","AnalyticsId","child","FormLayout$1"],"mappings":"uKAQY,IAAAA,GAAAA,IACVA,EAAA,IAAM,MACNA,EAAA,IAAM,MACNA,EAAA,MAAQ,QACRA,EAAA,KAAO,OACPA,EAAA,KAAO,OALGA,IAAAA,GAAA,CAAA,CAAA,EAyBL,MAAMC,EAAaC,EAAM,WAAW,CAACC,EAAwBC,IAAyC,CACrG,KAAA,CAAE,WAAYC,EAAU,MAAuB,YAAAC,EAAc,IAAK,QAAAC,EAAS,UAAAC,EAAW,UAAAC,CAAc,EAAAN,EAEpGO,EAAc,CAAE,kBAAmB,GAAGJ,CAAW,MACjDK,EAA6BC,EACjCC,EAAgB,uBAAuB,EACvC,CACE,CAACA,EAAgB,gCAAgC,CAAC,EAAGN,IAAYO,EAAY,OAC/E,EACAN,CAAA,EAEIO,EAAyBH,EAAWC,EAAgB,mBAAmB,EAAG,CAC9E,CAACA,EAAgB,wBAAwB,CAAC,EAAGR,IAAY,MACzD,CAACQ,EAAgB,0BAA0B,CAAC,EAAGR,IAAY,QAC3D,CAACQ,EAAgB,yBAAyB,CAAC,EAAGR,IAAY,OAC1D,CAACQ,EAAgB,yBAAyB,CAAC,EAAGR,IAAY,MAAA,CAC3D,EAED,uBACG,MAAI,CAAA,cAAaF,EAAM,OAAQ,mBAAkBa,EAAY,WAAY,MAAON,EAAa,UAAWC,GACtGT,EAAM,SAAS,IAAIC,EAAM,
|
|
1
|
+
{"version":3,"file":"FormLayout.js","sources":["../src/components/FormLayout/FormLayout.tsx"],"sourcesContent":["import React from 'react';\n\nimport classNames from 'classnames';\n\nimport { AnalyticsId, FormVariant } from '../../constants';\n\nimport formGroupStyles from './styles.module.scss';\n\nexport enum FormLayoutColumns {\n one = 'one',\n two = 'two',\n three = 'three',\n four = 'four',\n five = 'five',\n}\n\nexport interface FormLayoutProps {\n /** The max number of columns that will exist if space is available */\n maxColumns?: keyof typeof FormLayoutColumns;\n /** Sets the minimum width for the columns in pixels - this determines how many will fit on a row */\n colMinWidth?: number;\n /** Items in the FormLayout component */\n children?: React.ReactNode;\n /** Changes the visuals of the formgroup */\n variant?: keyof typeof FormVariant;\n /** Adds custom classes to the element. */\n className?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Function that helps map the form children */\n mapHelper?: (child: React.ReactNode, index: number) => React.ReactNode;\n}\n\nexport const FormLayout = React.forwardRef((props: FormLayoutProps, ref: React.ForwardedRef<HTMLElement>) => {\n const { maxColumns: columns = FormLayoutColumns.one, colMinWidth = 300, variant, className, mapHelper } = props;\n\n const cssVariable = { '--min-col-width': `${colMinWidth}px` } as React.CSSProperties;\n const formLayoutContainerClasses = classNames(\n formGroupStyles['form-layout-container'],\n {\n [formGroupStyles['form-layout-container--bigform']]: variant === FormVariant.bigform,\n },\n className\n );\n const formLayoutChildClasses = classNames(formGroupStyles['form-layout-child'], {\n [formGroupStyles['form-layout-child--two']]: columns === FormLayoutColumns.two,\n [formGroupStyles['form-layout-child--three']]: columns === FormLayoutColumns.three,\n [formGroupStyles['form-layout-child--four']]: columns === FormLayoutColumns.four,\n [formGroupStyles['form-layout-child--five']]: columns === FormLayoutColumns.five,\n });\n\n return (\n <div data-testid={props.testId} data-analyticsid={AnalyticsId.FormLayout} style={cssVariable} className={formLayoutContainerClasses}>\n {React.Children.map(props.children, (child: React.ReactNode, index: number) => {\n return <div className={formLayoutChildClasses}>{mapHelper ? mapHelper(child, index) : child}</div>;\n })}\n </div>\n );\n});\n\nFormLayout.displayName = 'FormLayout';\n\nexport default FormLayout;\n"],"names":["FormLayoutColumns","FormLayout","React","props","ref","columns","colMinWidth","variant","className","mapHelper","cssVariable","formLayoutContainerClasses","classNames","formGroupStyles","FormVariant","formLayoutChildClasses","AnalyticsId","child","index","FormLayout$1"],"mappings":"uKAQY,IAAAA,GAAAA,IACVA,EAAA,IAAM,MACNA,EAAA,IAAM,MACNA,EAAA,MAAQ,QACRA,EAAA,KAAO,OACPA,EAAA,KAAO,OALGA,IAAAA,GAAA,CAAA,CAAA,EAyBL,MAAMC,EAAaC,EAAM,WAAW,CAACC,EAAwBC,IAAyC,CACrG,KAAA,CAAE,WAAYC,EAAU,MAAuB,YAAAC,EAAc,IAAK,QAAAC,EAAS,UAAAC,EAAW,UAAAC,CAAc,EAAAN,EAEpGO,EAAc,CAAE,kBAAmB,GAAGJ,CAAW,MACjDK,EAA6BC,EACjCC,EAAgB,uBAAuB,EACvC,CACE,CAACA,EAAgB,gCAAgC,CAAC,EAAGN,IAAYO,EAAY,OAC/E,EACAN,CAAA,EAEIO,EAAyBH,EAAWC,EAAgB,mBAAmB,EAAG,CAC9E,CAACA,EAAgB,wBAAwB,CAAC,EAAGR,IAAY,MACzD,CAACQ,EAAgB,0BAA0B,CAAC,EAAGR,IAAY,QAC3D,CAACQ,EAAgB,yBAAyB,CAAC,EAAGR,IAAY,OAC1D,CAACQ,EAAgB,yBAAyB,CAAC,EAAGR,IAAY,MAAA,CAC3D,EAED,uBACG,MAAI,CAAA,cAAaF,EAAM,OAAQ,mBAAkBa,EAAY,WAAY,MAAON,EAAa,UAAWC,GACtGT,EAAM,SAAS,IAAIC,EAAM,SAAU,CAACc,EAAwBC,IACpDhB,EAAA,cAAC,OAAI,UAAWa,CAAA,EAAyBN,EAAYA,EAAUQ,EAAOC,CAAK,EAAID,CAAM,CAC7F,CACH,CAEJ,CAAC,EAEDhB,EAAW,YAAc,aAEzB,MAAAkB,EAAelB"}
|
package/Input.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import r,{useRef as
|
|
1
|
+
import r,{useRef as $,useState as A}from"react";import x from"classnames";import{FormMode as l,FormVariant as he,IconSize as K,AnalyticsId as ge,AVERAGE_CHARACTER_WIDTH_PX as Ce}from"./constants.js";import{useBreakpoint as ve,Breakpoint as xe}from"./hooks/useBreakpoint.js";import{useUuid as ye}from"./hooks/useUuid.js";import{getColor as D}from"./theme/currys/color.js";import{E as ke}from"./ErrorWrapper.js";import{Icon as we}from"./components/Icons/Icon.js";import{a as Ee}from"./Label.js";import{M as _e}from"./MaxCharacters.js";import n from"./components/Input/styles.module.scss";var Ie=(e=>(e.text="text",e.number="number",e.email="email",e.password="password",e.search="search",e.tel="tel",e.url="url",e.date="date",e.time="time",e))(Ie||{});const Ne=(e,s,f)=>{const u=s?"1.5rem":"2rem",b=s?`${f}px`:"0px",d="4px";return`calc(${e*Ce}px + ${u} + ${b} + ${d})`},F=r.forwardRef((e,s)=>{const{className:f,defaultValue:u,placeholder:b,type:d="text",name:M,transparent:z=!1,icon:i,iconRight:h,inputId:B,inputWrapperRef:P,mode:o=l.onwhite,baseIncrementValue:y,variant:U,label:H,error:O,errorText:k,testId:X,disabled:c,readOnly:q,autoComplete:G,afterInputChildren:L,rightOfInput:j,width:w,required:J,onChange:E,onKeyDown:_,autoFocus:Q,maxCharacters:m,maxText:Y,...Z}=e,T=ve(),p=$(null),I=ye(B),[N,ee]=A(u||""),[te,ne]=A(void 0),g=$(!1),R=/^[0-9]$/,re=o===l.ondark,ae=o===l.onblueberry,oe=!!m&&N.toString().length>m,C=o===l.oninvalid||!!k||!!O||oe,v=U===he.bigform,ie=z&&o!==l.ondark&&!C,ce=x(n["input-wrapper"],f),le=x(n["input-container"],{[n["input-container--transparent"]]:ie,[n["input-container--on-blueberry"]]:ae,[n["input-container--on-dark"]]:re,[n["input-container--invalid"]]:C,[n["input-container--bigform"]]:v,[n["input-container--disabled"]]:c,[n["input-container--with-icon"]]:i}),se=x(n["input-container__input"],{[n["input-container__input--bigform"]]:v,[n["input-container__input--disabled"]]:c}),ue=c?D("neutral",500):D("black"),S=T===xe.xs||!v?K.XSmall:K.Small,W=()=>i!==void 0?r.createElement(we,{className:n["input-container__input__icon"],color:ue,size:S,svgIcon:i}):null,de=t=>{if(p&&p.current&&i){const a=h?0:1;p.current.children[a].focus(),e.onClick&&e.onClick(t)}},me=t=>{const a=pe(t);E&&E(t),ee(a),ne(a)},pe=t=>{if(typeof y>"u"||d!=="number")return t.target.value;const a=Number(t.target.value);return!te&&!g.current&&(a===1||a===-1)&&(t.target.value=y+""),t.target.value},fe=t=>{R.test(t.key)&&(g.current=!0),_&&_(t)},be=t=>{R.test(t.key)&&(g.current=!1)},V=w?Ne(w,!!i,S):void 0;return r.createElement(ke,{errorText:k},r.createElement("div",{"data-testid":X,"data-analyticsid":ge.Input,className:ce,ref:P},Ee(H,I,o,c),r.createElement("div",{className:n["content-wrapper"],style:{width:V}},r.createElement("div",{onClick:de,ref:p,className:le},!h&&W(),r.createElement("input",{onChange:me,onKeyDown:fe,onKeyUp:be,name:M,type:d,defaultValue:u,id:I,className:se,ref:s,"aria-labelledby":e["aria-labelledby"]??void 0,"aria-describedby":e["aria-describedby"]??void 0,"aria-invalid":!!C,disabled:c,placeholder:b,readOnly:q,autoComplete:G||"off",required:J,autoFocus:Q,...Z}),h&&W()),j),m&&r.createElement(_e,{maxCharacters:m,length:N.toString().length,maxText:Y,mode:o,maxWidth:V}),L))});F.displayName="Input";const Pe=F;export{Pe as I,Ie as a};
|
|
2
2
|
//# sourceMappingURL=Input.js.map
|
package/Input.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Input.js","sources":["../src/components/Input/Input.tsx"],"sourcesContent":["import React, { useRef, useState } from 'react';\n\nimport cn from 'classnames';\n\nimport { FormMode, FormVariant, AnalyticsId, AVERAGE_CHARACTER_WIDTH_PX } from '../../constants';\nimport { Breakpoint, useBreakpoint } from '../../hooks/useBreakpoint';\nimport { getColor } from '../../theme/currys';\nimport { uuid } from '../../utils/uuid';\nimport ErrorWrapper from '../ErrorWrapper';\nimport Icon, { IconSize, SvgIcon } from '../Icons';\nimport { renderLabel } from '../Label';\nimport MaxCharacters from '../MaxCharacters/MaxCharacters';\n\nimport styles from './styles.module.scss';\n\nexport interface InputProps\n extends 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 | 'onChange'\n | 'onKeyDown'\n | 'autoFocus'\n > {\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;\n /** Places the icon to the right */\n iconRight?: boolean;\n /** Changes the color profile of the input */\n mode?: keyof typeof FormMode;\n /** Changes the visuals of the input */\n variant?: keyof typeof FormVariant;\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 /** Sets the data-testid attribute. */\n testId?: string;\n /** Component shown after input */\n afterInputChildren?: 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 inputId = uuid(),\n name,\n transparent = false,\n icon,\n iconRight,\n mode = FormMode.onwhite,\n variant,\n label,\n error,\n errorText,\n testId,\n disabled,\n readOnly,\n autoComplete,\n afterInputChildren,\n width,\n required,\n onChange,\n onKeyDown,\n autoFocus,\n maxCharacters,\n maxText,\n ...rest\n } = props;\n const breakpoint = useBreakpoint();\n const contentWrapperRef = useRef<HTMLDivElement>(null);\n const [input, setInput] = useState(defaultValue || '');\n\n const onDark = mode === FormMode.ondark;\n const onBlueberry = mode === FormMode.onblueberry;\n const maxCharactersExceeded = !!maxCharacters && input.toString().length > maxCharacters;\n const onError = mode === FormMode.oninvalid || !!errorText || !!error || maxCharactersExceeded;\n const bigForm = variant === FormVariant.bigform;\n const isTransparent = transparent && mode !== FormMode.ondark && !onError;\n\n const inputWrapperClass = cn(styles['input-wrapper'], className);\n\n const contentWrapperClass = cn(styles['content-wrapper'], {\n [styles['content-wrapper--transparent']]: isTransparent,\n [styles['content-wrapper--on-blueberry']]: onBlueberry,\n [styles['content-wrapper--on-dark']]: onDark,\n [styles['content-wrapper--invalid']]: onError,\n [styles['content-wrapper--bigform']]: bigForm,\n [styles['content-wrapper--disabled']]: disabled,\n [styles['content-wrapper--with-icon']]: icon,\n });\n\n const inputClass = cn(styles['content-wrapper__input'], {\n [styles['content-wrapper__input--bigform']]: bigForm,\n [styles['content-wrapper__input--disabled']]: disabled,\n });\n\n const iconColor = disabled ? getColor('neutral', 500) : getColor('black');\n const iconSize = breakpoint === Breakpoint.xs || !bigForm ? IconSize.XSmall : IconSize.Small;\n\n const renderIcon = (): React.ReactNode => {\n return icon !== undefined ? <Icon color={iconColor} size={iconSize} svgIcon={icon} /> : null;\n };\n\n const handleClick = (): void => {\n if (contentWrapperRef && contentWrapperRef.current && icon) {\n const selectedChild = iconRight ? 0 : 1;\n const input = contentWrapperRef.current.children[selectedChild] as HTMLInputElement;\n input.focus();\n }\n };\n\n const handleChange = (e: React.ChangeEvent<HTMLInputElement>): void => {\n if (onChange) {\n onChange(e);\n }\n setInput(e.target.value);\n };\n\n const maxWidth = width ? getInputMaxWidth(width, !!icon, iconSize) : undefined;\n\n return (\n <ErrorWrapper errorText={errorText}>\n <div data-testid={testId} data-analyticsid={AnalyticsId.Input} className={inputWrapperClass}>\n {renderLabel(label, inputId, mode as FormMode, disabled)}\n {/* input-elementet tillater keyboard-interaksjon */}\n {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */}\n <div onClick={handleClick} ref={contentWrapperRef} className={contentWrapperClass} style={{ maxWidth }}>\n {!iconRight && renderIcon()}\n <input\n onChange={handleChange}\n onKeyDown={onKeyDown}\n name={name}\n type={type}\n defaultValue={defaultValue}\n id={inputId}\n className={inputClass}\n ref={ref}\n aria-labelledby={props['aria-labelledby'] ?? undefined}\n aria-describedby={props['aria-describedby'] ?? undefined}\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 {maxCharacters && (\n <MaxCharacters maxCharacters={maxCharacters} length={input.toString().length} maxText={maxText} mode={mode} maxWidth={maxWidth} />\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","borderWidth","AVERAGE_CHARACTER_WIDTH_PX","Input","React","props","ref","className","defaultValue","placeholder","type","inputId","uuid","name","transparent","icon","iconRight","mode","FormMode","variant","label","error","errorText","testId","disabled","readOnly","autoComplete","afterInputChildren","width","required","onChange","onKeyDown","autoFocus","maxCharacters","maxText","rest","breakpoint","useBreakpoint","contentWrapperRef","useRef","input","setInput","useState","onDark","onBlueberry","maxCharactersExceeded","onError","bigForm","FormVariant","isTransparent","inputWrapperClass","cn","styles","contentWrapperClass","inputClass","iconColor","getColor","Breakpoint","IconSize","renderIcon","Icon","handleClick","selectedChild","handleChange","e","maxWidth","ErrorWrapper","AnalyticsId","renderLabel","MaxCharacters","Input$1"],"mappings":"6jBAoEY,IAAAA,IAAAA,IACVA,EAAA,KAAO,OACPA,EAAA,OAAS,SACTA,EAAA,MAAQ,QACRA,EAAA,SAAW,WACXA,EAAA,OAAS,SACTA,EAAA,IAAM,MACNA,EAAA,IAAM,MACNA,EAAA,KAAO,OACPA,EAAA,KAAO,OATGA,IAAAA,IAAA,CAAA,CAAA,EAYZ,MAAMC,GAAmB,CAACC,EAA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lB,EACA,KAAAH,EACA,aAAAF,EACA,GAAIG,EACJ,UAAW2C,EACX,IAAAhD,EACA,kBAAiBD,EAAM,iBAAiB,GAAK,OAC7C,mBAAkBA,EAAM,kBAAkB,GAAK,OAC/C,eAAc,CAAC,CAACyC,EAChB,SAAAtB,EACA,YAAAf,EACA,SAAAgB,EACA,aAAcC,GAAgB,MAC9B,SAAAG,EAEA,UAAAG,EACC,GAAGG,CAAA,CAAA,EAELnB,GAAa2C,EAAA,CAChB,EACC1B,mBACEoC,GAAc,CAAA,cAAApC,EAA8B,OAAQO,EAAM,SAAA,EAAW,OAAQ,QAAAN,EAAkB,KAAAjB,EAAY,SAAAgD,CAAoB,CAAA,EAEjItC,CACH,CACF,CAEJ,CAAC,EAEDxB,EAAM,YAAc,QAEpB,MAAAmE,GAAenE"}
|
|
1
|
+
{"version":3,"file":"Input.js","sources":["../src/components/Input/Input.tsx"],"sourcesContent":["import React, { useRef, useState } from 'react';\n\nimport cn from 'classnames';\n\nimport { FormMode, FormVariant, AnalyticsId, AVERAGE_CHARACTER_WIDTH_PX } from '../../constants';\nimport { Breakpoint, useBreakpoint } from '../../hooks/useBreakpoint';\nimport { useUuid } from '../../hooks/useUuid';\nimport { getColor } from '../../theme/currys';\nimport ErrorWrapper from '../ErrorWrapper';\nimport Icon, { IconSize, SvgIcon } from '../Icons';\nimport { renderLabel } from '../Label';\nimport MaxCharacters from '../MaxCharacters/MaxCharacters';\n\nimport styles from './styles.module.scss';\n\nexport interface InputProps\n extends 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;\n /** Places the icon to the right */\n iconRight?: boolean;\n /** Ref that is placed on the inputWrapper */\n inputWrapperRef?: React.RefObject<HTMLDivElement>;\n /** Changes the color profile of the input */\n mode?: keyof typeof FormMode;\n /** Changes the visuals of the input */\n variant?: keyof typeof FormVariant;\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 /** 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 mode = FormMode.onwhite,\n baseIncrementValue,\n variant,\n label,\n error,\n errorText,\n testId,\n disabled,\n readOnly,\n autoComplete,\n afterInputChildren,\n rightOfInput,\n width,\n required,\n onChange,\n onKeyDown,\n autoFocus,\n maxCharacters,\n maxText,\n ...rest\n } = props;\n const breakpoint = useBreakpoint();\n const inputContainerRef = 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 numRegex = /^[0-9]$/;\n\n const onDark = mode === FormMode.ondark;\n const onBlueberry = mode === FormMode.onblueberry;\n const maxCharactersExceeded = !!maxCharacters && input.toString().length > maxCharacters;\n const onError = mode === FormMode.oninvalid || !!errorText || !!error || maxCharactersExceeded;\n const bigForm = variant === FormVariant.bigform;\n const isTransparent = transparent && mode !== FormMode.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--bigform']]: bigForm,\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--bigform']]: bigForm,\n [styles['input-container__input--disabled']]: disabled,\n });\n\n const iconColor = disabled ? getColor('neutral', 500) : getColor('black');\n const iconSize = breakpoint === Breakpoint.xs || !bigForm ? IconSize.XSmall : IconSize.Small;\n\n const renderIcon = (): React.ReactNode => {\n return icon !== undefined ? (\n <Icon className={styles['input-container__input__icon']} color={iconColor} size={iconSize} svgIcon={icon} />\n ) : null;\n };\n\n // eslint-disable-next-line\n const handleClick = (e: React.MouseEvent<any>): void => {\n if (inputContainerRef && inputContainerRef.current && icon) {\n const selectedChild = iconRight ? 0 : 1;\n const input = inputContainerRef.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 widthStyling = width ? getInputMaxWidth(width, !!icon, iconSize) : undefined;\n\n return (\n <ErrorWrapper errorText={errorText}>\n <div data-testid={testId} data-analyticsid={AnalyticsId.Input} className={inputWrapperClass} ref={inputWrapperRef}>\n {renderLabel(label, inputIdState, mode as FormMode, disabled)}\n {/* input-elementet tillater keyboard-interaksjon */}\n <div className={styles['content-wrapper']} style={{ width: widthStyling }}>\n {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */}\n <div onClick={handleClick} ref={inputContainerRef} className={inputContainer}>\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={props['aria-describedby'] ?? undefined}\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 {rightOfInput}\n </div>\n {maxCharacters && (\n <MaxCharacters\n maxCharacters={maxCharacters}\n length={input.toString().length}\n maxText={maxText}\n mode={mode}\n maxWidth={widthStyling}\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","borderWidth","AVERAGE_CHARACTER_WIDTH_PX","Input","React","props","ref","className","defaultValue","placeholder","type","name","transparent","icon","iconRight","inputId","inputWrapperRef","mode","FormMode","baseIncrementValue","variant","label","error","errorText","testId","disabled","readOnly","autoComplete","afterInputChildren","rightOfInput","width","required","onChange","onKeyDown","autoFocus","maxCharacters","maxText","rest","breakpoint","useBreakpoint","inputContainerRef","useRef","inputIdState","useUuid","input","setInput","useState","prevValue","setPrevValue","numKeyPressed","numRegex","onDark","onBlueberry","maxCharactersExceeded","onError","bigForm","FormVariant","isTransparent","inputWrapperClass","cn","styles","inputContainer","inputClass","iconColor","getColor","Breakpoint","IconSize","renderIcon","Icon","handleClick","e","selectedChild","handleChange","newValue","getIncrementValue","valueAsNumber","handleKeyDown","handleKeyUp","widthStyling","ErrorWrapper","AnalyticsId","renderLabel","MaxCharacters","Input$1"],"mappings":"0kBA6EY,IAAAA,IAAAA,IACVA,EAAA,KAAO,OACPA,EAAA,OAAS,SACTA,EAAA,MAAQ,QACRA,EAAA,SAAW,WACXA,EAAA,OAAS,SACTA,EAAA,IAAM,MACNA,EAAA,IAAM,MACNA,EAAA,KAAO,OACPA,EAAA,KAAO,OATGA,IAAAA,IAAA,CAAA,CAAA,EAYZ,MAAMC,GAAmB,CAACC,EAAoBC,EAAkBC,IAA6B,CACrF,MAAAC,EAAeF,EAAU,SAAW,OACpCG,EAAYH,EAAU,GAAGC,CAAQ,KAAO,MACxCG,EAAc,MAEb,MAAA,QAAQL,EAAaM,EAA0B,QAAQH,CAAY,MAAMC,CAAS,MAAMC,CAAW,GAC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EAAUqC,CAAC,CAAA,EAGpBO,GAAeP,GAAmD,CAClEpB,EAAS,KAAKoB,EAAE,GAAG,IACrBrB,EAAc,QAAU,GAC1B,EAGI6B,EAAehD,EAAQnC,GAAiBmC,EAAO,CAAC,CAACjB,EAAMf,CAAQ,EAAI,OAEzE,uBACGiF,GAAa,CAAA,UAAAxD,CAAA,kBACX,MAAI,CAAA,cAAaC,EAAQ,mBAAkBwD,GAAY,MAAO,UAAWtB,GAAmB,IAAK1C,CAC/F,EAAAiE,GAAY5D,EAAOqB,EAAczB,EAAkBQ,CAAQ,EAE5DrB,EAAA,cAAC,MAAI,CAAA,UAAWwD,EAAO,iBAAiB,EAAG,MAAO,CAAE,MAAOkB,EAEzD,EAAA1E,EAAA,cAAC,OAAI,QAASiE,GAAa,IAAK7B,EAAmB,UAAWqB,IAC3D,CAAC/C,GAAaqD,EACf,EAAA/D,EAAA,cAAC,QAAA,CACC,SAAUoE,GACV,UAAWI,GACX,QAASC,GACT,KAAAlE,EACA,KAAAD,EACA,aAAAF,EACA,GAAIkC,EACJ,UAAWoB,GACX,IAAAxD,EACA,kBAAiBD,EAAM,iBAAiB,GAAK,OAC7C,mBAAkBA,EAAM,kBAAkB,GAAK,OAC/C,eAAc,CAAC,CAACiD,EAChB,SAAA7B,EACA,YAAAhB,EACA,SAAAiB,EACA,aAAcC,GAAgB,MAC9B,SAAAI,EAEA,UAAAG,EACC,GAAGG,CAAA,CAAA,EAELvB,GAAaqD,GAChB,EACCtC,CACH,EACCM,GACC/B,EAAA,cAAC8E,GAAA,CACC,cAAA/C,EACA,OAAQS,EAAM,SAAA,EAAW,OACzB,QAAAR,EACA,KAAAnB,EACA,SAAU6D,CAAA,CAAA,EAGblD,CACH,CACF,CAEJ,CAAC,EAEDzB,EAAM,YAAc,QAEpB,MAAAgF,GAAehF"}
|
package/RadioButton.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import p,{useState as D}from"react";import s from"classnames";import{FormMode as d,FormVariant as V,AnalyticsId as W}from"./constants.js";import{usePseudoClasses as $}from"./hooks/usePseudoClasses.js";import{isMutableRefObject as z,mergeRefs as G}from"./utils/refs.js";import{u as H}from"./uuid.js";import{g as J,r as K}from"./Label.js";import o from"./components/RadioButton/styles.module.scss";const ro=(b,r,a,l)=>{const n=r==="oninvalid",e=b===l;return s({[o["radio-button-label__bigform--on-grey"]]:a&&r==="ongrey"&&!e,[o["radio-button-label__bigform--on-blueberry"]]:r==="onblueberry"&&!e&&a,[o["radio-button-label__bigform--selected"]]:a&&e&&!n,[o["radio-button-label__bigform--selected-invalid"]]:a&&e&&n})},h=p.forwardRef((b,r)=>{const{className:a,defaultChecked:l=!1,onChange:n,disabled:e,label:g,inputId:f=H(),mode:i=d.onwhite,name:C=f,variant:w,errorText:u,error:R=!!u,value:k=J(g),testId:B,required:N,labelClassNames:L,...x}=b,_=R||i===d.oninvalid,y=i===d.ondark,v=i===d.onblueberry,E=i===d.oninvalid,t=w===V.bigform,[F,I]=D(l),{refObject:S,isFocused:c}=$(z(r)?r:null),j=G([r,S]),A=s(o["radio-button-wrapper"],{[o["radio-button-wrapper--with-error"]]:u,[o["radio-button-wrapper__bigform"]]:t,[o["radio-button-wrapper__bigform--focused"]]:t&&c,[o["radio-button-wrapper__bigform--selected"]]:t&&F&&c,[o["radio-button-wrapper__bigform--invalid"]]:t&&E&&c,[o["radio-button-wrapper__bigform--on-blueberry"]]:t&&v&&c}),M=s(o["radio-button-label"],{[o["radio-button-label--disabled"]]:e,[o["radio-button-label--on-dark"]]:y,[o["radio-button-label--invalid"]]:_,[o["radio-button-label__bigform"]]:t,[o["radio-button-label__bigform--disabled"]]:t&&e},L),O=s(o["radio-button"],{[o["radio-button--on-dark"]]:y,[o["radio-button--disabled"]]:e,[o["radio-button--on-blueberry"]]:v,[o["radio-button--invalid"]]:_,[o["radio-button__bigform"]]:t,[o["radio-button__bigform--disabled"]]:t&&e,[o["radio-button__bigform--invalid"]]:t&&_},a),P=s(o["radio-button-errors"]),T=m=>{I(m.target.checked),n&&n(m)},q=()=>p.createElement("input",{id:f,name:C,className:O,type:"radio",disabled:e,value:k,ref:j,defaultChecked:l,"aria-describedby":b["aria-describedby"]??void 0,required:N,...x,onChange:m=>T(m)});return p.createElement("div",{"data-testid":B,"data-analyticsid":W.RadioButton,className:A},u&&p.createElement("p",{className:P},u),K(g,q(),f,i,e,M,void 0,o["radiobutton-sublabel-wrapper"],t))});h.displayName="RadioButton";const ao=h;export{ao as R,h as a,ro as g};
|
|
2
2
|
//# sourceMappingURL=RadioButton.js.map
|
package/RadioButton.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RadioButton.js","sources":["../src/components/RadioButton/RadioButton.tsx"],"sourcesContent":["import React, { useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport { AnalyticsId, FormMode, FormVariant } from '../../constants';\nimport { usePseudoClasses } from '../../hooks/usePseudoClasses';\nimport { isMutableRefObject, mergeRefs } from '../../utils/refs';\nimport { uuid } from '../../utils/uuid';\nimport { getLabelText, renderLabelAsParent } from '../Label';\n\nimport radioButtonStyles from './styles.module.scss';\n\nexport interface RadioButtonProps\n extends Pick<\n React.InputHTMLAttributes<HTMLInputElement>,\n 'aria-describedby' | 'name' | 'value' | 'disabled' | 'defaultChecked' | 'required' | 'onChange'\n > {\n /** Adds custom classes to the element. */\n className?: string;\n /** The <Label/> next to the radioButton - sublabels kan ikke kombineres med bigform variant */\n label: React.ReactNode;\n /** input id of the radioButton */\n inputId?: string;\n /** Changes the visuals of the radioButton */\n mode?: keyof typeof FormMode;\n /** Changes the visuals of the radioButton */\n variant?: keyof typeof FormVariant;\n /** Activates Error style for the radioButton - This is can be true while errorText is empty, when in a FormGroup */\n error?: boolean;\n /** Error text to show above the component */\n errorText?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport const RadioButton = React.forwardRef((props: RadioButtonProps, ref: React.Ref<HTMLInputElement>) => {\n const {\n className,\n defaultChecked = false,\n onChange,\n disabled,\n label,\n inputId = uuid(),\n mode = FormMode.onwhite,\n name = inputId,\n variant,\n errorText,\n error = !!errorText,\n value = getLabelText(label),\n testId,\n required,\n ...rest\n } = props;\n const invalid = error || mode === FormMode.oninvalid;\n const onDark = mode === FormMode.ondark;\n const onBlueberry = mode === FormMode.onblueberry;\n const
|
|
1
|
+
{"version":3,"file":"RadioButton.js","sources":["../src/components/RadioButton/RadioButton.tsx"],"sourcesContent":["import React, { useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport { AnalyticsId, FormMode, FormVariant } from '../../constants';\nimport { usePseudoClasses } from '../../hooks/usePseudoClasses';\nimport { isMutableRefObject, mergeRefs } from '../../utils/refs';\nimport { uuid } from '../../utils/uuid';\nimport { getLabelText, renderLabelAsParent } from '../Label';\n\nimport radioButtonStyles from './styles.module.scss';\n\nexport interface RadioButtonProps\n extends Pick<\n React.InputHTMLAttributes<HTMLInputElement>,\n 'aria-describedby' | 'name' | 'value' | 'disabled' | 'defaultChecked' | 'required' | 'onChange'\n > {\n /** Adds custom classes to the element. */\n className?: string;\n /** The <Label/> next to the radioButton - sublabels kan ikke kombineres med bigform variant */\n label: React.ReactNode;\n /** Adds custom classes to the label element. */\n labelClassNames?: string;\n /** input id of the radioButton */\n inputId?: string;\n /** Changes the visuals of the radioButton */\n mode?: keyof typeof FormMode;\n /** Changes the visuals of the radioButton */\n variant?: keyof typeof FormVariant;\n /** Activates Error style for the radioButton - This is can be true while errorText is empty, when in a FormGroup */\n error?: boolean;\n /** Error text to show above the component */\n errorText?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport const getRadioLabelClasses = (radioId: string, mode: FormMode, bigform: boolean, checkedRadioId?: string): string | undefined => {\n const onCherry = mode === 'oninvalid';\n const checked = radioId === checkedRadioId;\n\n return classNames({\n [radioButtonStyles['radio-button-label__bigform--on-grey']]: bigform && mode === 'ongrey' && !checked,\n [radioButtonStyles['radio-button-label__bigform--on-blueberry']]: mode === 'onblueberry' && !checked && bigform,\n [radioButtonStyles['radio-button-label__bigform--selected']]: bigform && checked && !onCherry,\n [radioButtonStyles['radio-button-label__bigform--selected-invalid']]: bigform && checked && onCherry,\n });\n};\n\nexport const RadioButton = React.forwardRef((props: RadioButtonProps, ref: React.Ref<HTMLInputElement>) => {\n const {\n className,\n defaultChecked = false,\n onChange,\n disabled,\n label,\n inputId = uuid(),\n mode = FormMode.onwhite,\n name = inputId,\n variant,\n errorText,\n error = !!errorText,\n value = getLabelText(label),\n testId,\n required,\n labelClassNames,\n ...rest\n } = props;\n const invalid = error || mode === FormMode.oninvalid;\n const onDark = mode === FormMode.ondark;\n const onBlueberry = mode === FormMode.onblueberry;\n const onCherry = mode === FormMode.oninvalid;\n const bigform = variant === FormVariant.bigform;\n const [checked, changeChecked] = useState<boolean>(defaultChecked);\n const { refObject, isFocused } = usePseudoClasses<HTMLInputElement>(isMutableRefObject(ref) ? ref : null);\n const mergedRefs = mergeRefs([ref, refObject]);\n\n const radioButtonWrapperClasses = classNames(radioButtonStyles['radio-button-wrapper'], {\n [radioButtonStyles['radio-button-wrapper--with-error']]: errorText,\n [radioButtonStyles['radio-button-wrapper__bigform']]: bigform,\n [radioButtonStyles['radio-button-wrapper__bigform--focused']]: bigform && isFocused,\n [radioButtonStyles['radio-button-wrapper__bigform--selected']]: bigform && checked && isFocused,\n [radioButtonStyles['radio-button-wrapper__bigform--invalid']]: bigform && onCherry && isFocused,\n [radioButtonStyles['radio-button-wrapper__bigform--on-blueberry']]: bigform && onBlueberry && isFocused,\n });\n const radioButtonLabelClasses = classNames(\n radioButtonStyles['radio-button-label'],\n {\n [radioButtonStyles['radio-button-label--disabled']]: disabled,\n [radioButtonStyles['radio-button-label--on-dark']]: onDark,\n [radioButtonStyles['radio-button-label--invalid']]: invalid,\n [radioButtonStyles['radio-button-label__bigform']]: bigform,\n [radioButtonStyles['radio-button-label__bigform--disabled']]: bigform && disabled,\n },\n labelClassNames\n );\n const radioButtonClasses = classNames(\n radioButtonStyles['radio-button'],\n {\n [radioButtonStyles['radio-button--on-dark']]: onDark,\n [radioButtonStyles['radio-button--disabled']]: disabled,\n [radioButtonStyles['radio-button--on-blueberry']]: onBlueberry,\n [radioButtonStyles['radio-button--invalid']]: invalid,\n [radioButtonStyles['radio-button__bigform']]: bigform,\n [radioButtonStyles['radio-button__bigform--disabled']]: bigform && disabled,\n [radioButtonStyles['radio-button__bigform--invalid']]: bigform && invalid,\n },\n className\n );\n const errorStyles = classNames(radioButtonStyles['radio-button-errors']);\n\n const change = (e: React.ChangeEvent<HTMLInputElement>): void => {\n changeChecked(e.target.checked);\n onChange && onChange(e);\n };\n\n const getLabelContent = (): React.ReactNode => (\n <input\n id={inputId}\n name={name}\n className={radioButtonClasses}\n type=\"radio\"\n disabled={disabled}\n value={value}\n ref={mergedRefs}\n defaultChecked={defaultChecked}\n aria-describedby={props['aria-describedby'] ?? undefined}\n required={required}\n {...rest}\n onChange={(e): void => change(e)}\n />\n );\n\n return (\n <div data-testid={testId} data-analyticsid={AnalyticsId.RadioButton} className={radioButtonWrapperClasses}>\n {errorText && <p className={errorStyles}>{errorText}</p>}\n {renderLabelAsParent(\n label,\n getLabelContent(),\n inputId,\n mode as FormMode,\n disabled,\n radioButtonLabelClasses,\n undefined,\n radioButtonStyles['radiobutton-sublabel-wrapper'],\n bigform\n )}\n </div>\n );\n});\n\nRadioButton.displayName = 'RadioButton';\n\nexport default RadioButton;\n"],"names":["getRadioLabelClasses","radioId","mode","bigform","checkedRadioId","onCherry","checked","classNames","radioButtonStyles","RadioButton","React","props","ref","className","defaultChecked","onChange","disabled","label","inputId","uuid","FormMode","name","variant","errorText","error","value","getLabelText","testId","required","labelClassNames","rest","invalid","onDark","onBlueberry","FormVariant","changeChecked","useState","refObject","isFocused","usePseudoClasses","isMutableRefObject","mergedRefs","mergeRefs","radioButtonWrapperClasses","radioButtonLabelClasses","radioButtonClasses","errorStyles","change","e","getLabelContent","AnalyticsId","renderLabelAsParent","RadioButton$1"],"mapp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iB,EACC,GAAGE,EACJ,SAAWkB,GAAYD,EAAOC,CAAC,CAAA,CAAA,EAInC,OACGtC,EAAA,cAAA,MAAA,CAAI,cAAaiB,EAAQ,mBAAkBuB,EAAY,YAAa,UAAWP,CAAA,EAC7EpB,GAAcb,EAAA,cAAA,IAAA,CAAE,UAAWoC,CAAA,EAAcvB,CAAU,EACnD4B,EACClC,EACAgC,EAAgB,EAChB/B,EACAhB,EACAc,EACA4B,EACA,OACApC,EAAkB,8BAA8B,EAChDL,CAAA,CAEJ,CAEJ,CAAC,EAEDM,EAAY,YAAc,cAE1B,MAAA2C,GAAe3C"}
|
package/Select.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Select.js","sources":["../src/components/Select/Select.tsx"],"sourcesContent":["import React from 'react';\n\nimport classNames from 'classnames';\n\nimport { AnalyticsId, AVERAGE_CHARACTER_WIDTH_PX, FormMode, IconSize } from '../../constants';\nimport { useUuid } from '../../hooks/useUuid';\nimport { getColor } from '../../theme/currys';\nimport ErrorWrapper from '../ErrorWrapper';\nimport Icon from '../Icons';\nimport ChevronDown from '../Icons/ChevronDown';\nimport { renderLabel } from '../Label';\n\nimport selectStyles from './styles.module.scss';\n\ntype SelectConcept = 'normal' | 'transparent';\n\nexport interface SelectProps\n extends Pick
|
|
1
|
+
{"version":3,"file":"Select.js","sources":["../src/components/Select/Select.tsx"],"sourcesContent":["import React from 'react';\n\nimport classNames from 'classnames';\n\nimport { AnalyticsId, AVERAGE_CHARACTER_WIDTH_PX, FormMode, IconSize } from '../../constants';\nimport { useUuid } from '../../hooks/useUuid';\nimport { getColor } from '../../theme/currys';\nimport ErrorWrapper from '../ErrorWrapper';\nimport Icon from '../Icons';\nimport ChevronDown from '../Icons/ChevronDown';\nimport { renderLabel } from '../Label';\n\nimport selectStyles from './styles.module.scss';\n\ntype SelectConcept = 'normal' | 'transparent';\n\nexport interface SelectProps\n extends Pick<\n React.SelectHTMLAttributes<HTMLSelectElement>,\n 'aria-describedby' | 'name' | 'disabled' | 'required' | 'value' | 'onChange'\n > {\n /** Component shown after label */\n afterLabelChildren?: React.ReactNode;\n /** Sets the content of the select element. */\n children: React.ReactNode;\n /** Adds custom classes to the element. */\n className?: string;\n /** Changes the visuals of the component */\n concept?: SelectConcept;\n /** The label text above the select */\n label?: React.ReactNode;\n /** Changes the visuals of the component */\n mode?: keyof typeof FormMode;\n /** Activates Error style for the select component - This is can be true while errorText is empty, when in a FormGroup */\n error?: boolean;\n /** Error text to show above the component */\n errorText?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** select id of the select element */\n selectId?: string;\n /** Width of select in characters (approximate) */\n width?: number;\n /** Gives defaultvalue to the comp. Preferred over selected prop on option by react */\n defaultValue?: string | number;\n}\n\nconst getSelectMaxWidth = (characters: number): string => {\n const paddingWidth = '2rem';\n\n return `calc(${characters * AVERAGE_CHARACTER_WIDTH_PX}px + ${paddingWidth})`;\n};\n\nconst getIconColor = (invalid: boolean, disabled: boolean) => {\n const iconColor = invalid ? 'cherry' : 'blueberry';\n return disabled ? getColor('neutral', 500) : getColor(iconColor, 600);\n};\n\nexport const Select = React.forwardRef(function SelectForwardedRef(props: SelectProps, ref: React.Ref<HTMLSelectElement>) {\n const {\n afterLabelChildren,\n className,\n children,\n concept = 'normal',\n disabled,\n error,\n errorText,\n label,\n selectId,\n name = selectId,\n mode = FormMode.onwhite,\n testId,\n width,\n required,\n value,\n defaultValue,\n ...rest\n } = props;\n\n const uuid = useUuid(selectId);\n const onBlueberry = mode === 'onblueberry';\n const invalid = mode === 'oninvalid' || !!errorText || !!error;\n const iconColor = getIconColor(invalid, !!disabled);\n const maxWidth = width ? getSelectMaxWidth(width) : undefined;\n\n const selectInnerWrapperClasses = classNames(\n selectStyles['select-inner-wrapper'],\n {\n [selectStyles['select-inner-wrapper--transparent']]: concept === 'transparent',\n [selectStyles['select-inner-wrapper--on-blueberry']]: onBlueberry,\n [selectStyles['select-inner-wrapper--invalid']]: invalid,\n [selectStyles['select-inner-wrapper--disabled']]: disabled,\n },\n className\n );\n\n const selectClasses = classNames(selectStyles.select, {\n [selectStyles['select--on-blueberry']]: onBlueberry,\n [selectStyles['select--invalid']]: invalid,\n });\n\n return (\n <ErrorWrapper errorText={errorText}>\n <div data-testid={testId} data-analyticsid={AnalyticsId.Select} className={selectStyles['select-wrapper']} style={{ maxWidth }}>\n {renderLabel(label, uuid, mode as FormMode, disabled)}\n <div className={selectInnerWrapperClasses}>\n <Icon className={selectStyles['select-arrow']} svgIcon={ChevronDown} color={iconColor} size={IconSize.XSmall} />\n <select\n aria-invalid={!!invalid}\n id={uuid}\n name={name}\n className={selectClasses}\n disabled={disabled}\n ref={ref}\n required={required}\n aria-describedby={props['aria-describedby'] ?? undefined}\n aria-required={!!required}\n value={value}\n defaultValue={defaultValue}\n {...rest}\n >\n {children}\n </select>\n </div>\n </div>\n </ErrorWrapper>\n );\n});\n\nexport default Select;\n"],"names":["getSelectMaxWidth","characters","paddingWidth","AVERAGE_CHARACTER_WIDTH_PX","getIconColor","invalid","disabled","getColor","Select","React","props","ref","afterLabelChildren","className","children","concept","error","errorText","label","selectId","name","mode","FormMode","testId","width","required","value","defaultValue","rest","uuid","useUuid","onBlueberry","iconColor","maxWidth","selectInnerWrapperClasses","classNames","selectStyles","selectClasses","ErrorWrapper","AnalyticsId","renderLabel","Icon","ChevronDown","IconSize","Select$1"],"mappings":"sdA+CA,MAAMA,EAAqBC,GAA+B,CACxD,MAAMC,EAAe,OAErB,MAAO,QAAQD,EAAaE,CAA0B,QAAQD,CAAY,GAC5E,EAEME,EAAe,CAACC,EAAkBC,IAE/BA,EAAWC,EAAS,UAAW,GAAG,EAAIA,EAD3BF,EAAU,SAAW,YAC0B,GAAG,EAGzDG,EAASC,EAAM,WAAW,SAA4BC,EAAoBC,EAAmC,CAClH,KAAA,CACJ,mBAAAC,EACA,UAAAC,EACA,SAAAC,EACA,QAAAC,EAAU,SACV,SAAAT,EACA,MAAAU,EACA,UAAAC,EACA,MA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C,EACA,aAAAC,EACC,GAAGC,CAAA,EAEHd,CAEL,CAAA,CACF,CACF,CAEJ,CAAC,EAED8B,EAAepC"}
|
package/Textarea.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import o,{useState as I,useRef as U,useEffect as Y}from"react";import x from"classnames";import{FormMode as d,AnalyticsId as Z,AVERAGE_CHARACTER_WIDTH_PX as ee}from"./constants.js";import{u as te}from"./uuid.js";import{E as ae}from"./ErrorWrapper.js";import{a as re}from"./Label.js";import{M as ne}from"./MaxCharacters.js";import t from"./components/Textarea/styles.module.scss";const oe=r=>{const m="2rem",n="16px",u="4px";return`calc(${r*ee}px + ${m} + ${n} + ${u})`},A=o.forwardRef((r,m)=>{const{maxCharacters:n,maxText:u,width:h,testId:M,defaultValue:f,marginBottom:N,transparent:$,mode:s=d.onwhite,label:B,textareaId:b=te(),minRows:g=3,maxRows:i=10,grow:w,errorText:C,autoFocus:k,disabled:E,name:L,autoComplete:T,placeholder:S,readOnly:D,required:F,onChange:y,...V}=r,[q,R]=I(g),[v,z]=I(f||""),c=U(null),W=e=>{const l=e.rows;e.rows=g;const a=Math.floor((e.scrollHeight-16)/28);a===l&&(e.rows=a),a>=i&&(e.rows=i,e.scrollTop=e.scrollHeight),a<i?R(a):R(i)},G=s===d.ondark,O=s===d.onblueberry,P=!!n&&v.toString().length>n,H=s===d.oninvalid||!!C||P,X=x(t.textarea,{[t["textarea--gutterBottom"]]:N}),j=x(t["input-container"],{[t["input-container--transparent"]]:$,[t["input-container--on-blueberry"]]:O,[t["input-container--on-dark"]]:G,[t["input-container--invalid"]]:H,[t["input-container--disabled"]]:r.disabled}),J=x(t["input-container__input"],{[t["input-container__input--disabled"]]:r.disabled});Y(()=>{var e,p,l;if(w&&((e=c.current)!=null&&e.children)&&((p=c.current)!=null&&p.children[0])){const a=(l=c.current)==null?void 0:l.children[0];W(a)}},[]);const K=e=>{w&&W(e.target),z(e.target.value)},Q=e=>{y&&y(e),K(e)},_=h?oe(h):void 0;return o.createElement(ae,{errorText:C},o.createElement("div",{"data-testid":M,"data-analyticsid":Z.Textarea,className:X},re(B,b,s,E),o.createElement("div",{className:j,ref:c,style:{maxWidth:_}},o.createElement("textarea",{rows:q,defaultValue:f,id:b,className:J,ref:m,"aria-describedby":r["aria-describedby"]??void 0,"aria-invalid":!!H,autoFocus:k,disabled:E,name:L,autoComplete:T||void 0,placeholder:S,readOnly:D,required:F,onChange:Q,...V})),n&&o.createElement(ne,{maxCharacters:n,length:v.toString().length,maxText:u,mode:s,maxWidth:_})))});A.displayName="Textarea";const xe=A;export{xe as T};
|
|
2
2
|
//# sourceMappingURL=Textarea.js.map
|
package/Textarea.js.map
CHANGED
|
@@ -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 { 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\ninterface 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 /** Error text to show above the component */\n errorText?: 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 errorText,\n autoFocus,\n disabled,\n name,\n autoComplete,\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\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 || maxCharactersExceeded;\n\n const textareaWrapperClass = cn(styles.textarea, {\n [styles['textarea--gutterBottom']]: gutterBottom,\n });\n\n const contentWrapperClass = cn(styles['
|
|
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 { 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\ninterface 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 /** Error text to show above the component */\n errorText?: 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 errorText,\n autoFocus,\n disabled,\n name,\n autoComplete,\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\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 || 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}>\n <div data-testid={testId} data-analyticsid={AnalyticsId.Textarea} className={textareaWrapperClass}>\n {renderLabel(label, textareaId, mode as FormMode, disabled)}\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'] ?? undefined}\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","paddingWidth","scrollbarWidth","borderWidth","AVERAGE_CHARACTER_WIDTH_PX","Textarea","React","props","ref","maxCharacters","maxText","width","testId","defaultValue","gutterBottom","transparent","mode","FormMode","label","textareaId","uuid","minRows","maxRows","grow","errorText","autoFocus","disabled","name","autoComplete","placeholder","readOnly","required","onChange","rest","rows","setRows","useState","textareaInput","setTextareaInput","referanse","useRef","resizeHeight","target","previousRows","currentRows","onDark","onBlueberry","maxCharactersExceeded","onError","textareaWrapperClass","cn","styles","contentWrapperClass","textareaClass","useEffect","_a","_b","textarea","_c","handleChange","onChangeHandler","maxWidth","ErrorWrapper","AnalyticsId","renderLabel","MaxCharacters","Textarea$1"],"mappings":"2XAsDA,MAAMA,GAAuBC,GAA+B,CAC1D,MAAMC,EAAe,OACfC,EAAiB,OACjBC,EAAc,MAEb,MAAA,QAAQ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GAA8B,OAC5C,YAAAC,EACA,SAAAC,EACA,SAAAC,EACA,SAAU6B,EACT,GAAG3B,CAAA,CAAA,CAER,EACCxB,GACCH,EAAA,cAAC2D,GAAA,CACC,cAAAxD,EACA,OAAQ4B,EAAc,SAAA,EAAW,OACjC,QAAA3B,EACA,KAAAM,EACA,SAAA6C,CAAA,CAGN,CAAA,CACF,CAEJ,CAAC,EAEDxD,EAAS,YAAc,WAEvB,MAAA6D,GAAe7D"}
|
|
@@ -99,6 +99,7 @@ $with-icons: // icon-class, size-class, padding-left, padding-right, padding-lef
|
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
/* stylelint-disable-next-line */
|
|
102
103
|
:disabled > & {
|
|
103
104
|
background-color: $dark-mode-disabled-transparrent;
|
|
104
105
|
}
|
|
@@ -185,6 +186,10 @@ $with-icons: // icon-class, size-class, padding-left, padding-right, padding-lef
|
|
|
185
186
|
&:disabled {
|
|
186
187
|
cursor: not-allowed;
|
|
187
188
|
}
|
|
189
|
+
|
|
190
|
+
&:focus-visible {
|
|
191
|
+
outline: none;
|
|
192
|
+
}
|
|
188
193
|
}
|
|
189
194
|
|
|
190
195
|
.button {
|
|
@@ -283,10 +288,12 @@ $with-icons: // icon-class, size-class, padding-left, padding-right, padding-lef
|
|
|
283
288
|
@include outline($cherry700, $cherry50);
|
|
284
289
|
}
|
|
285
290
|
|
|
291
|
+
/* stylelint-disable-next-line */
|
|
286
292
|
&--borderless:not(.button--only-icon) {
|
|
287
293
|
padding: 0 getSpacer(3xs);
|
|
288
294
|
}
|
|
289
295
|
|
|
296
|
+
/* stylelint-disable-next-line */
|
|
290
297
|
&--borderless {
|
|
291
298
|
&:hover {
|
|
292
299
|
box-shadow: none;
|
|
@@ -305,6 +312,7 @@ $with-icons: // icon-class, size-class, padding-left, padding-right, padding-lef
|
|
|
305
312
|
}
|
|
306
313
|
}
|
|
307
314
|
|
|
315
|
+
/* stylelint-disable-next-line */
|
|
308
316
|
&__text {
|
|
309
317
|
color: $white;
|
|
310
318
|
margin: 0 auto 0 0;
|
|
@@ -320,6 +328,7 @@ $with-icons: // icon-class, size-class, padding-left, padding-right, padding-lef
|
|
|
320
328
|
}
|
|
321
329
|
}
|
|
322
330
|
|
|
331
|
+
/* stylelint-disable-next-line */
|
|
323
332
|
&--outline &__text {
|
|
324
333
|
@include outline-text($blueberry600);
|
|
325
334
|
}
|
|
@@ -327,6 +336,7 @@ $with-icons: // icon-class, size-class, padding-left, padding-right, padding-lef
|
|
|
327
336
|
@include outline-text($cherry600);
|
|
328
337
|
}
|
|
329
338
|
|
|
339
|
+
/* stylelint-disable-next-line */
|
|
330
340
|
&--borderless &__text {
|
|
331
341
|
@include borderless-text($blueberry600);
|
|
332
342
|
}
|
|
@@ -334,6 +344,7 @@ $with-icons: // icon-class, size-class, padding-left, padding-right, padding-lef
|
|
|
334
344
|
@include borderless-text($cherry600);
|
|
335
345
|
}
|
|
336
346
|
|
|
347
|
+
/* stylelint-disable-next-line */
|
|
337
348
|
&--only-icon &__text {
|
|
338
349
|
@include sr-only;
|
|
339
350
|
}
|
|
@@ -10,8 +10,7 @@ export declare enum FormExampleVariants {
|
|
|
10
10
|
radiobutton = "radiobutton",
|
|
11
11
|
textarea = "textarea",
|
|
12
12
|
input = "input",
|
|
13
|
-
select = "select"
|
|
14
|
-
date = "date"
|
|
13
|
+
select = "select"
|
|
15
14
|
}
|
|
16
15
|
export declare const FormExample: (props: FormExampleProps) => JSX.Element;
|
|
17
16
|
export default FormExample;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormExample.d.ts","sourceRoot":"","sources":["../../../src/components/FormExample/FormExample.tsx"],"names":[],"mappings":";AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"FormExample.d.ts","sourceRoot":"","sources":["../../../src/components/FormExample/FormExample.tsx"],"names":[],"mappings":";AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAc9C,UAAU,gBAAgB;IACxB,WAAW,EAAE,mBAAmB,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,OAAO,WAAW,CAAC;CACpC;AAED,oBAAY,mBAAmB;IAC7B,SAAS,cAAc;IACvB,QAAQ,aAAa;IACrB,WAAW,gBAAgB;IAC3B,QAAQ,aAAa;IACrB,KAAK,UAAU;IACf,MAAM,WAAW;CAClB;AAED,eAAO,MAAM,WAAW,UAAW,gBAAgB,KAAG,WA+OrD,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"props":{"exampleType":{"defaultValue":null,"description":"","name":"exampleType","parent":{"fileName":"src/components/FormExample/FormExample.tsx","name":"FormExampleProps"},"declarations":[{"fileName":"src/components/FormExample/FormExample.tsx","name":"FormExampleProps"}],"required":true,"type":{"name":"enum","raw":"FormExampleVariants","value":[{"value":"\"formgroup\"","description":"","fullComment":"","tags":{}},{"value":"\"checkbox\"","description":"","fullComment":"","tags":{}},{"value":"\"radiobutton\"","description":"","fullComment":"","tags":{}},{"value":"\"textarea\"","description":"","fullComment":"","tags":{}},{"value":"\"input\"","description":"","fullComment":"","tags":{}},{"value":"\"select\"","description":"","fullComment":"","tags":{}}
|
|
1
|
+
{"props":{"exampleType":{"defaultValue":null,"description":"","name":"exampleType","parent":{"fileName":"src/components/FormExample/FormExample.tsx","name":"FormExampleProps"},"declarations":[{"fileName":"src/components/FormExample/FormExample.tsx","name":"FormExampleProps"}],"required":true,"type":{"name":"enum","raw":"FormExampleVariants","value":[{"value":"\"formgroup\"","description":"","fullComment":"","tags":{}},{"value":"\"checkbox\"","description":"","fullComment":"","tags":{}},{"value":"\"radiobutton\"","description":"","fullComment":"","tags":{}},{"value":"\"textarea\"","description":"","fullComment":"","tags":{}},{"value":"\"input\"","description":"","fullComment":"","tags":{}},{"value":"\"select\"","description":"","fullComment":"","tags":{}}]}},"variant":{"defaultValue":null,"description":"","name":"variant","parent":{"fileName":"src/components/FormExample/FormExample.tsx","name":"FormExampleProps"},"declarations":[{"fileName":"src/components/FormExample/FormExample.tsx","name":"FormExampleProps"}],"required":false,"type":{"name":"enum","raw":"\"normal\" | \"bigform\"","value":[{"value":"\"normal\""},{"value":"\"bigform\""}]}}}}
|