no-frills-ui 0.0.14-rc.1 → 0.0.14-rc.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/dist/index.js +365 -169
- package/dist/index.js.map +1 -1
- package/lib-esm/components/Chip/Chip.js +2 -2
- package/lib-esm/components/ChipInput/ChipInput.js +12 -5
- package/lib-esm/components/ChipInput/ChipInput.js.map +1 -1
- package/lib-esm/components/DragAndDrop/DragAndDrop.js +2 -2
- package/lib-esm/components/DragAndDrop/DragItem.js +2 -2
- package/lib-esm/components/Drawer/Drawer.d.ts +1 -1
- package/lib-esm/components/Drawer/Drawer.js +2 -3
- package/lib-esm/components/Drawer/Drawer.js.map +1 -1
- package/lib-esm/components/Groups/Group.js +3 -3
- package/lib-esm/components/Groups/Group.js.map +1 -1
- package/lib-esm/components/Input/Checkbox.d.ts +2 -0
- package/lib-esm/components/Input/Checkbox.js +54 -23
- package/lib-esm/components/Input/Checkbox.js.map +1 -1
- package/lib-esm/components/Input/Dropdown.d.ts +2 -0
- package/lib-esm/components/Input/Dropdown.js +123 -59
- package/lib-esm/components/Input/Dropdown.js.map +1 -1
- package/lib-esm/components/Input/Input.js +17 -8
- package/lib-esm/components/Input/Input.js.map +1 -1
- package/lib-esm/components/Input/Radio.d.ts +2 -0
- package/lib-esm/components/Input/Radio.js +22 -10
- package/lib-esm/components/Input/Radio.js.map +1 -1
- package/lib-esm/components/Input/RadioButton.d.ts +2 -0
- package/lib-esm/components/Input/RadioButton.js +21 -9
- package/lib-esm/components/Input/RadioButton.js.map +1 -1
- package/lib-esm/components/Input/Select.js +21 -11
- package/lib-esm/components/Input/Select.js.map +1 -1
- package/lib-esm/components/Input/TextArea.js +17 -8
- package/lib-esm/components/Input/TextArea.js.map +1 -1
- package/lib-esm/components/Input/Toggle.d.ts +2 -0
- package/lib-esm/components/Input/Toggle.js +45 -15
- package/lib-esm/components/Input/Toggle.js.map +1 -1
- package/lib-esm/components/Input/index.d.ts +1 -0
- package/lib-esm/components/Menu/MenuItem.d.ts +1 -1
- package/lib-esm/components/Menu/MenuItem.js +1 -1
- package/lib-esm/components/Menu/MenuItem.js.map +1 -1
- package/lib-esm/components/Modal/Modal.d.ts +1 -1
- package/lib-esm/components/Modal/Modal.js +1 -2
- package/lib-esm/components/Modal/Modal.js.map +1 -1
- package/lib-esm/components/Popover/Popover.d.ts +1 -1
- package/lib-esm/components/Popover/Popover.js +3 -3
- package/lib-esm/components/Popover/Popover.js.map +1 -1
- package/lib-esm/components/Stepper/Stepper.js +14 -5
- package/lib-esm/components/Stepper/Stepper.js.map +1 -1
- package/lib-esm/index.js +1 -1
- package/lib-esm/shared/LayerManager.js +2 -2
- package/lib-esm/shared/styles.d.ts +4 -0
- package/lib-esm/shared/styles.js +10 -6
- package/lib-esm/shared/styles.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { jsxs, jsx } from '@emotion/react/jsx-runtime';
|
|
2
|
-
import React, { useState, useId, useRef, useEffect } from 'react';
|
|
2
|
+
import React, { useState, useId, useRef, useImperativeHandle, useEffect } from 'react';
|
|
3
3
|
import styled from '@emotion/styled';
|
|
4
4
|
import ExpandMore from '../../icons/ExpandMore.js';
|
|
5
5
|
import { getThemeValue, THEME_NAME } from '../../shared/constants.js';
|
|
6
6
|
|
|
7
7
|
const Label$3 = /*#__PURE__*/ styled("label", {
|
|
8
|
-
target: "
|
|
8
|
+
target: "e1trg58l0",
|
|
9
9
|
label: "Label"
|
|
10
10
|
})("display:inline-flex;flex-direction:column;position:relative;margin:10px 5px;pointer-events:none;max-width:268px;& svg{fill:currentColor;}");
|
|
11
11
|
const SelectField = /*#__PURE__*/ styled("select", {
|
|
12
|
-
target: "
|
|
12
|
+
target: "e1trg58l1",
|
|
13
13
|
label: "SelectField"
|
|
14
14
|
})("border:none;color:inherit;padding:0 8px;line-height:30px;min-height:32px;width:268px;border-radius:3px;border:1px solid ", getThemeValue(THEME_NAME.BORDER_COLOR), ";display:inline-block;background-color:", getThemeValue(THEME_NAME.BACKGROUND), ";pointer-events:auto;appearance:none;&:focus,&:active{border-color:", getThemeValue(THEME_NAME.PRIMARY), ";box-shadow:0 0 0 4px ", getThemeValue(THEME_NAME.PRIMARY_LIGHT), ";}&:focus ~ span,&:active ~ span{color:", getThemeValue(THEME_NAME.PRIMARY), ";}&:disabled{border-color:", getThemeValue(THEME_NAME.DISABLED_BORDER), ";background-color:", getThemeValue(THEME_NAME.DISABLED_BACKGROUND), ";}&:disabled ~ span{color:", getThemeValue(THEME_NAME.DISABLED), ";}&:focus:invalid{border-color:", getThemeValue(THEME_NAME.ERROR), ";box-shadow:0 0 0 4px ", getThemeValue(THEME_NAME.ERROR_LIGHT), ";}", (props)=>props.touched ? `
|
|
15
15
|
&:invalid {
|
|
@@ -33,31 +33,41 @@ const SelectField = /*#__PURE__*/ styled("select", {
|
|
|
33
33
|
line-height: 14px;
|
|
34
34
|
}
|
|
35
35
|
` : '', " &:focus + span,&:placeholder-shown + span{top:-8px;background:", getThemeValue(THEME_NAME.BACKGROUND), ";font-size:12px;line-height:14px;}");
|
|
36
|
-
const ErrorContainer$
|
|
37
|
-
target: "
|
|
36
|
+
const ErrorContainer$3 = /*#__PURE__*/ styled("div", {
|
|
37
|
+
target: "e1trg58l2",
|
|
38
38
|
label: "ErrorContainer"
|
|
39
39
|
})("color:", getThemeValue(THEME_NAME.ERROR), ";padding-top:3px;font-size:12px;line-height:14px;margin-left:3px;");
|
|
40
40
|
const ArrowContainer$1 = /*#__PURE__*/ styled("span", {
|
|
41
|
-
target: "
|
|
41
|
+
target: "e1trg58l3",
|
|
42
42
|
label: "ArrowContainer"
|
|
43
43
|
})("position:absolute;right:8px;top:8px;");
|
|
44
44
|
/**
|
|
45
45
|
* Select Component
|
|
46
46
|
* @param props - Component props
|
|
47
47
|
* @param ref - Ref forwarded to the underlying HTMLSelectElement
|
|
48
|
-
*/ function SelectComponent(props,
|
|
48
|
+
*/ function SelectComponent(props, forwardedRef) {
|
|
49
49
|
const [touched, setTouched] = useState(false);
|
|
50
50
|
const [value, setValue] = useState(props.value || '');
|
|
51
51
|
const errorId = useId();
|
|
52
52
|
const prevValueRef = useRef(undefined);
|
|
53
|
+
const internalRef = useRef(null);
|
|
54
|
+
useImperativeHandle(forwardedRef, ()=>internalRef.current);
|
|
55
|
+
// Sync prop value with state
|
|
53
56
|
useEffect(()=>{
|
|
54
|
-
if (props.value !==
|
|
55
|
-
setValue(props.value);
|
|
57
|
+
if (props.value !== prevValueRef.current) {
|
|
58
|
+
setValue(props.value || '');
|
|
56
59
|
prevValueRef.current = props.value;
|
|
57
60
|
}
|
|
58
61
|
}, [
|
|
59
62
|
props.value
|
|
60
63
|
]);
|
|
64
|
+
useEffect(()=>{
|
|
65
|
+
if (internalRef.current) {
|
|
66
|
+
internalRef.current.setCustomValidity(props.errorText || '');
|
|
67
|
+
}
|
|
68
|
+
}, [
|
|
69
|
+
props.errorText
|
|
70
|
+
]);
|
|
61
71
|
const handleFocus = (e)=>{
|
|
62
72
|
setTouched(true);
|
|
63
73
|
if (props.onFocus) {
|
|
@@ -76,7 +86,7 @@ const ArrowContainer$1 = /*#__PURE__*/ styled("span", {
|
|
|
76
86
|
children: [
|
|
77
87
|
/*#__PURE__*/ jsxs(SelectField, {
|
|
78
88
|
...props,
|
|
79
|
-
ref:
|
|
89
|
+
ref: internalRef,
|
|
80
90
|
multiple: false,
|
|
81
91
|
value: value,
|
|
82
92
|
onChange: onChangeHandler,
|
|
@@ -97,7 +107,7 @@ const ArrowContainer$1 = /*#__PURE__*/ styled("span", {
|
|
|
97
107
|
"aria-hidden": "true",
|
|
98
108
|
children: /*#__PURE__*/ jsx(ExpandMore, {})
|
|
99
109
|
}),
|
|
100
|
-
props.errorText && /*#__PURE__*/ jsx(ErrorContainer$
|
|
110
|
+
props.errorText && /*#__PURE__*/ jsx(ErrorContainer$3, {
|
|
101
111
|
id: errorId,
|
|
102
112
|
children: props.errorText
|
|
103
113
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Select.js","sources":["../../../src/components/Input/Select.tsx"],"sourcesContent":["import React, { useState, useEffect, useId, useRef } from 'react';\nimport styled from '@emotion/styled';\nimport ExpandMore from '../../icons/ExpandMore';\nimport { getThemeValue, THEME_NAME } from '../../shared/constants';\n\ntype SelectProps = {\n /** Label for the field */\n label?: string;\n /** Error text to be shown below the field */\n errorText?: string;\n} & React.InputHTMLAttributes<HTMLSelectElement>;\n\ntype SelectInternalProps = SelectProps & {\n touched: boolean;\n};\n\nconst Label = styled.label`\n display: inline-flex;\n flex-direction: column;\n position: relative;\n margin: 10px 5px;\n pointer-events: none;\n max-width: 268px;\n\n & svg {\n fill: currentColor;\n }\n`;\n\nconst SelectField = styled.select<SelectInternalProps>`\n border: none;\n color: inherit;\n padding: 0 8px;\n line-height: 30px;\n min-height: 32px;\n width: 268px;\n border-radius: 3px;\n border: 1px solid ${getThemeValue(THEME_NAME.BORDER_COLOR)};\n display: inline-block;\n background-color: ${getThemeValue(THEME_NAME.BACKGROUND)};\n pointer-events: auto;\n appearance: none;\n\n /** Focused */\n &:focus,\n &:active {\n border-color: ${getThemeValue(THEME_NAME.PRIMARY)};\n box-shadow: 0 0 0 4px ${getThemeValue(THEME_NAME.PRIMARY_LIGHT)};\n }\n\n &:focus ~ span,\n &:active ~ span {\n color: ${getThemeValue(THEME_NAME.PRIMARY)};\n }\n\n /** Disabled */\n &:disabled {\n border-color: ${getThemeValue(THEME_NAME.DISABLED_BORDER)};\n background-color: ${getThemeValue(THEME_NAME.DISABLED_BACKGROUND)};\n }\n\n &:disabled ~ span {\n color: ${getThemeValue(THEME_NAME.DISABLED)};\n }\n\n /** Invalid */\n &:focus:invalid {\n border-color: ${getThemeValue(THEME_NAME.ERROR)};\n box-shadow: 0 0 0 4px ${getThemeValue(THEME_NAME.ERROR_LIGHT)};\n }\n\n ${(props) =>\n props.touched\n ? `\n &:invalid {\n border-color: ${getThemeValue(THEME_NAME.ERROR)};\n }\n\n &:invalid ~ span {\n color: ${getThemeValue(THEME_NAME.ERROR)};\n }\n `\n : ''}\n\n /** Error */\n ${(props) =>\n props.errorText\n ? `\n border-color: ${getThemeValue(THEME_NAME.ERROR)};\n\n & ~ span {\n color: ${getThemeValue(THEME_NAME.ERROR)};\n }\n `\n : ''}\n\n /** Required */\n &:required + span:after {\n content: '*';\n margin-left: 2px;\n color: ${getThemeValue(THEME_NAME.ERROR)};\n }\n\n /** Label Animation */\n & + span {\n position: absolute;\n padding: 0 5px;\n top: 0px;\n left: 4px;\n font-size: 14px;\n line-height: 32px;\n transition: all 300ms ease;\n }\n\n ${(props) =>\n props.value !== ''\n ? `\n & + span {\n top: -8px;\n background: ${getThemeValue(THEME_NAME.BACKGROUND)};\n font-size: 12px;\n line-height: 14px;\n }\n `\n : ''}\n\n &:focus + span, &:placeholder-shown + span {\n top: -8px;\n background: ${getThemeValue(THEME_NAME.BACKGROUND)};\n font-size: 12px;\n line-height: 14px;\n }\n`;\n\nconst ErrorContainer = styled.div`\n color: ${getThemeValue(THEME_NAME.ERROR)};\n padding-top: 3px;\n font-size: 12px;\n line-height: 14px;\n margin-left: 3px;\n`;\n\nconst ArrowContainer = styled.span`\n position: absolute;\n right: 8px;\n top: 8px;\n`;\n\n/**\n * Select Component\n * @param props - Component props\n * @param ref - Ref forwarded to the underlying HTMLSelectElement\n */\nfunction SelectComponent(props: SelectProps, ref: React.Ref<HTMLSelectElement>) {\n const [touched, setTouched] = useState(false);\n const [value, setValue] = useState(props.value || '');\n const errorId = useId();\n const prevValueRef = useRef<string>(undefined);\n\n useEffect(() => {\n if (props.value !== undefined && props.value !== prevValueRef.current) {\n setValue(props.value);\n prevValueRef.current = props.value as string;\n }\n }, [props.value]);\n\n const handleFocus = (e: React.FocusEvent<HTMLSelectElement>) => {\n setTouched(true);\n if (props.onFocus) {\n props.onFocus(e);\n }\n };\n\n const onChangeHandler = (e: React.ChangeEvent<HTMLSelectElement>) => {\n if (props.onChange) {\n setValue(e.target.value);\n props.onChange(e);\n } else {\n setValue(e.target.value);\n }\n };\n\n return (\n <Label>\n <SelectField\n {...props}\n ref={ref}\n multiple={false}\n value={value}\n onChange={onChangeHandler}\n onFocus={handleFocus}\n touched={touched}\n aria-invalid={!!props.errorText}\n aria-required={props.required}\n aria-describedby={props.errorText ? errorId : undefined}\n >\n <option />\n {props.children}\n </SelectField>\n <span>{props.label}</span>\n <ArrowContainer aria-hidden=\"true\">\n <ExpandMore />\n </ArrowContainer>\n {props.errorText && <ErrorContainer id={errorId}>{props.errorText}</ErrorContainer>}\n </Label>\n );\n}\n\nconst Select = React.forwardRef(SelectComponent);\nexport default Select;\n"],"names":["Label","styled","SelectField","getThemeValue","THEME_NAME","BORDER_COLOR","BACKGROUND","PRIMARY","PRIMARY_LIGHT","DISABLED_BORDER","DISABLED_BACKGROUND","DISABLED","ERROR","ERROR_LIGHT","props","touched","errorText","value","ErrorContainer","ArrowContainer","SelectComponent","ref","setTouched","useState","setValue","errorId","useId","prevValueRef","useRef","undefined","useEffect","current","handleFocus","e","onFocus","onChangeHandler","onChange","target","_jsxs","multiple","aria-invalid","aria-required","required","aria-describedby","_jsx","option","children","span","label","aria-hidden","ExpandMore","id","Select","React","forwardRef"],"mappings":";;;;;;AAgBA,MAAMA,OAAAA,iBAAQC,MAAAA,CAAAA,OAAAA,EAAAA;;;;AAad,MAAMC,WAAAA,iBAAcD,MAAAA,CAAAA,QAAAA,EAAAA;;;+HAQIE,aAAAA,CAAcC,UAAAA,CAAWC,YAAY,CAAA,EAAA,yCAAA,EAErCF,aAAAA,CAAcC,WAAWE,UAAU,CAAA,EAAA,qEAAA,EAOnCH,cAAcC,UAAAA,CAAWG,OAAO,6BACxBJ,aAAAA,CAAcC,UAAAA,CAAWI,aAAa,CAAA,EAAA,yCAAA,EAKrDL,aAAAA,CAAcC,WAAWG,OAAO,CAAA,EAAA,4BAAA,EAKzBJ,cAAcC,UAAAA,CAAWK,eAAe,yBACpCN,aAAAA,CAAcC,UA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KAAK;gBACTO,GAAAA,EAAKA,GAAAA;gBACLkB,QAAAA,EAAU,KAAA;gBACVtB,KAAAA,EAAOA,KAAAA;gBACPmB,QAAAA,EAAUD,eAAAA;gBACVD,OAAAA,EAASF,WAAAA;gBACTjB,OAAAA,EAASA,OAAAA;gBACTyB,cAAAA,EAAc,CAAC,CAAC1B,KAAAA,CAAME,SAAS;AAC/ByB,gBAAAA,eAAAA,EAAe3B,MAAM4B,QAAQ;gBAC7BC,kBAAAA,EAAkB7B,KAAAA,CAAME,SAAS,GAAGS,OAAAA,GAAUI,SAAAA;;kCAE9Ce,GAAA,CAACC,QAAAA,EAAAA,EAAAA,CAAAA;AACA/B,oBAAAA,KAAAA,CAAMgC;;;0BAEXF,GAAA,CAACG,MAAAA,EAAAA;AAAMjC,gBAAAA,QAAAA,EAAAA,KAAAA,CAAMkC;;0BACbJ,GAAA,CAACzB,gBAAAA,EAAAA;gBAAe8B,aAAAA,EAAY,MAAA;AACxB,gBAAA,QAAA,gBAAAL,GAAA,CAACM,UAAAA,EAAAA,EAAAA;;YAEJpC,KAAAA,CAAME,SAAS,kBAAI4B,GAAA,CAAC1B,gBAAAA,EAAAA;gBAAeiC,EAAAA,EAAI1B,OAAAA;AAAUX,gBAAAA,QAAAA,EAAAA,KAAAA,CAAME;;;;AAGpE;AAEA,MAAMoC,MAAAA,iBAASC,KAAAA,CAAMC,UAAU,CAAClC,eAAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"Select.js","sources":["../../../src/components/Input/Select.tsx"],"sourcesContent":["import React, { useState, useEffect, useId, useRef, useImperativeHandle } from 'react';\nimport styled from '@emotion/styled';\nimport ExpandMore from '../../icons/ExpandMore';\nimport { getThemeValue, THEME_NAME } from '../../shared/constants';\n\ntype SelectProps = {\n /** Label for the field */\n label?: string;\n /** Error text to be shown below the field */\n errorText?: string;\n} & React.InputHTMLAttributes<HTMLSelectElement>;\n\ntype SelectInternalProps = SelectProps & {\n touched: boolean;\n};\n\nconst Label = styled.label`\n display: inline-flex;\n flex-direction: column;\n position: relative;\n margin: 10px 5px;\n pointer-events: none;\n max-width: 268px;\n\n & svg {\n fill: currentColor;\n }\n`;\n\nconst SelectField = styled.select<SelectInternalProps>`\n border: none;\n color: inherit;\n padding: 0 8px;\n line-height: 30px;\n min-height: 32px;\n width: 268px;\n border-radius: 3px;\n border: 1px solid ${getThemeValue(THEME_NAME.BORDER_COLOR)};\n display: inline-block;\n background-color: ${getThemeValue(THEME_NAME.BACKGROUND)};\n pointer-events: auto;\n appearance: none;\n\n /** Focused */\n &:focus,\n &:active {\n border-color: ${getThemeValue(THEME_NAME.PRIMARY)};\n box-shadow: 0 0 0 4px ${getThemeValue(THEME_NAME.PRIMARY_LIGHT)};\n }\n\n &:focus ~ span,\n &:active ~ span {\n color: ${getThemeValue(THEME_NAME.PRIMARY)};\n }\n\n /** Disabled */\n &:disabled {\n border-color: ${getThemeValue(THEME_NAME.DISABLED_BORDER)};\n background-color: ${getThemeValue(THEME_NAME.DISABLED_BACKGROUND)};\n }\n\n &:disabled ~ span {\n color: ${getThemeValue(THEME_NAME.DISABLED)};\n }\n\n /** Invalid */\n &:focus:invalid {\n border-color: ${getThemeValue(THEME_NAME.ERROR)};\n box-shadow: 0 0 0 4px ${getThemeValue(THEME_NAME.ERROR_LIGHT)};\n }\n\n ${(props) =>\n props.touched\n ? `\n &:invalid {\n border-color: ${getThemeValue(THEME_NAME.ERROR)};\n }\n\n &:invalid ~ span {\n color: ${getThemeValue(THEME_NAME.ERROR)};\n }\n `\n : ''}\n\n /** Error */\n ${(props) =>\n props.errorText\n ? `\n border-color: ${getThemeValue(THEME_NAME.ERROR)};\n\n & ~ span {\n color: ${getThemeValue(THEME_NAME.ERROR)};\n }\n `\n : ''}\n\n /** Required */\n &:required + span:after {\n content: '*';\n margin-left: 2px;\n color: ${getThemeValue(THEME_NAME.ERROR)};\n }\n\n /** Label Animation */\n & + span {\n position: absolute;\n padding: 0 5px;\n top: 0px;\n left: 4px;\n font-size: 14px;\n line-height: 32px;\n transition: all 300ms ease;\n }\n\n ${(props) =>\n props.value !== ''\n ? `\n & + span {\n top: -8px;\n background: ${getThemeValue(THEME_NAME.BACKGROUND)};\n font-size: 12px;\n line-height: 14px;\n }\n `\n : ''}\n\n &:focus + span, &:placeholder-shown + span {\n top: -8px;\n background: ${getThemeValue(THEME_NAME.BACKGROUND)};\n font-size: 12px;\n line-height: 14px;\n }\n`;\n\nconst ErrorContainer = styled.div`\n color: ${getThemeValue(THEME_NAME.ERROR)};\n padding-top: 3px;\n font-size: 12px;\n line-height: 14px;\n margin-left: 3px;\n`;\n\nconst ArrowContainer = styled.span`\n position: absolute;\n right: 8px;\n top: 8px;\n`;\n\n/**\n * Select Component\n * @param props - Component props\n * @param ref - Ref forwarded to the underlying HTMLSelectElement\n */\nfunction SelectComponent(props: SelectProps, forwardedRef: React.Ref<HTMLSelectElement>) {\n const [touched, setTouched] = useState(false);\n const [value, setValue] = useState(props.value || '');\n const errorId = useId();\n const prevValueRef = useRef<string>(undefined);\n const internalRef = useRef<HTMLSelectElement>(null);\n\n useImperativeHandle(forwardedRef, () => internalRef.current as HTMLSelectElement);\n\n // Sync prop value with state\n useEffect(() => {\n if (props.value !== prevValueRef.current) {\n setValue(props.value || '');\n prevValueRef.current = props.value as string;\n }\n }, [props.value]);\n\n useEffect(() => {\n if (internalRef.current) {\n internalRef.current.setCustomValidity(props.errorText || '');\n }\n }, [props.errorText]);\n\n const handleFocus = (e: React.FocusEvent<HTMLSelectElement>) => {\n setTouched(true);\n if (props.onFocus) {\n props.onFocus(e);\n }\n };\n\n const onChangeHandler = (e: React.ChangeEvent<HTMLSelectElement>) => {\n if (props.onChange) {\n setValue(e.target.value);\n props.onChange(e);\n } else {\n setValue(e.target.value);\n }\n };\n\n return (\n <Label>\n <SelectField\n {...props}\n ref={internalRef}\n multiple={false}\n value={value}\n onChange={onChangeHandler}\n onFocus={handleFocus}\n touched={touched}\n aria-invalid={!!props.errorText}\n aria-required={props.required}\n aria-describedby={props.errorText ? errorId : undefined}\n >\n <option />\n {props.children}\n </SelectField>\n <span>{props.label}</span>\n <ArrowContainer aria-hidden=\"true\">\n <ExpandMore />\n </ArrowContainer>\n {props.errorText && <ErrorContainer id={errorId}>{props.errorText}</ErrorContainer>}\n </Label>\n );\n}\n\nconst Select = React.forwardRef(SelectComponent);\nexport default Select;\n"],"names":["Label","styled","SelectField","getThemeValue","THEME_NAME","BORDER_COLOR","BACKGROUND","PRIMARY","PRIMARY_LIGHT","DISABLED_BORDER","DISABLED_BACKGROUND","DISABLED","ERROR","ERROR_LIGHT","props","touched","errorText","value","ErrorContainer","ArrowContainer","SelectComponent","forwardedRef","setTouched","useState","setValue","errorId","useId","prevValueRef","useRef","undefined","internalRef","useImperativeHandle","current","useEffect","setCustomValidity","handleFocus","e","onFocus","onChangeHandler","onChange","target","_jsxs","ref","multiple","aria-invalid","aria-required","required","aria-describedby","_jsx","option","children","span","label","aria-hidden","ExpandMore","id","Select","React","forwardRef"],"mappings":";;;;;;AAgBA,MAAMA,OAAAA,iBAAQC,MAAAA,CAAAA,OAAAA,EAAAA;;;;AAad,MAAMC,WAAAA,iBAAcD,MAAAA,CAAAA,QAAAA,EAAAA;;;+HAQIE,aAAAA,CAAcC,UAAAA,CAAWC,YAAY,CAAA,EAAA,yCAAA,EAErCF,aAAAA,CAAcC,WAAWE,UAAU,CAAA,EAAA,qEAAA,EAOnCH,cAAcC,UAAAA,CAAWG,OAAO,6BACxBJ,aAAAA,CAAcC,UAAAA,CAAWI,aAAa,CAAA,EAAA,yCAAA,EAKrDL,aAAAA,CAAcC,WAAWG,OAAO,CAAA,EAAA,4BAAA,EAKzBJ,cAAcC,UAAAA,CAAWK,eAAe,yBACpCN,aAAAA,CAAcC,UAAAA,CAAWM,mBAAmB,CAAA,EAAA,4BAAA,EAIvDP,aAAAA,CAAcC,WAAWO,QAAQ,CAAA,EAAA,iCAAA,EAK1BR,cAAcC,UAAAA,CAAWQ,KAAK,6BACtBT,aAAAA,CAAcC,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QAAAA,CAASY,CAAAA,CAAEI,MAAM,CAACvB,KAAK,CAAA;AAC3B,QAAA;AACJ,IAAA,CAAA;AAEA,IAAA,qBACIwB,IAAA,CAACzC,OAAAA,EAAAA;;0BACGyC,IAAA,CAACvC,WAAAA,EAAAA;AACI,gBAAA,GAAGY,KAAK;gBACT4B,GAAAA,EAAKZ,WAAAA;gBACLa,QAAAA,EAAU,KAAA;gBACV1B,KAAAA,EAAOA,KAAAA;gBACPsB,QAAAA,EAAUD,eAAAA;gBACVD,OAAAA,EAASF,WAAAA;gBACTpB,OAAAA,EAASA,OAAAA;gBACT6B,cAAAA,EAAc,CAAC,CAAC9B,KAAAA,CAAME,SAAS;AAC/B6B,gBAAAA,eAAAA,EAAe/B,MAAMgC,QAAQ;gBAC7BC,kBAAAA,EAAkBjC,KAAAA,CAAME,SAAS,GAAGS,OAAAA,GAAUI,SAAAA;;kCAE9CmB,GAAA,CAACC,QAAAA,EAAAA,EAAAA,CAAAA;AACAnC,oBAAAA,KAAAA,CAAMoC;;;0BAEXF,GAAA,CAACG,MAAAA,EAAAA;AAAMrC,gBAAAA,QAAAA,EAAAA,KAAAA,CAAMsC;;0BACbJ,GAAA,CAAC7B,gBAAAA,EAAAA;gBAAekC,aAAAA,EAAY,MAAA;AACxB,gBAAA,QAAA,gBAAAL,GAAA,CAACM,UAAAA,EAAAA,EAAAA;;YAEJxC,KAAAA,CAAME,SAAS,kBAAIgC,GAAA,CAAC9B,gBAAAA,EAAAA;gBAAeqC,EAAAA,EAAI9B,OAAAA;AAAUX,gBAAAA,QAAAA,EAAAA,KAAAA,CAAME;;;;AAGpE;AAEA,MAAMwC,MAAAA,iBAASC,KAAAA,CAAMC,UAAU,CAACtC,eAAAA;;;;"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { jsxs, jsx } from '@emotion/react/jsx-runtime';
|
|
2
|
-
import React, { useState, useId, useRef, useEffect } from 'react';
|
|
2
|
+
import React, { useState, useId, useRef, useImperativeHandle, useEffect } from 'react';
|
|
3
3
|
import styled from '@emotion/styled';
|
|
4
4
|
import { getThemeValue, THEME_NAME } from '../../shared/constants.js';
|
|
5
5
|
|
|
6
6
|
const Label$4 = /*#__PURE__*/ styled("label", {
|
|
7
|
-
target: "
|
|
7
|
+
target: "e1towgf50",
|
|
8
8
|
label: "Label"
|
|
9
9
|
})("display:inline-flex;flex-direction:column;position:relative;margin:10px 5px;");
|
|
10
10
|
const TextField = /*#__PURE__*/ styled("textarea", {
|
|
11
|
-
target: "
|
|
11
|
+
target: "e1towgf51",
|
|
12
12
|
label: "TextField"
|
|
13
13
|
})("border:none;color:inherit;padding:8px;min-height:150px;min-width:250px;border-radius:3px;border:1px solid ", getThemeValue(THEME_NAME.BORDER_COLOR), ";display:inline-block;background-color:", getThemeValue(THEME_NAME.BACKGROUND), ";&:focus,&:active{border-color:", getThemeValue(THEME_NAME.PRIMARY), ";box-shadow:0 0 0 4px ", getThemeValue(THEME_NAME.PRIMARY_LIGHT), ";}&:focus + span,&:active + span{color:", getThemeValue(THEME_NAME.PRIMARY), ";}&:disabled{border-color:", getThemeValue(THEME_NAME.DISABLED_BORDER), ";background-color:", getThemeValue(THEME_NAME.DISABLED_BACKGROUND), ";}&:disabled + span{color:", getThemeValue(THEME_NAME.DISABLED), ";}&:focus:invalid{border-color:", getThemeValue(THEME_NAME.ERROR), ";box-shadow:0 0 0 4px ", getThemeValue(THEME_NAME.ERROR_LIGHT), ";}", (props)=>props.touched ? `
|
|
14
14
|
&:invalid {
|
|
@@ -32,20 +32,22 @@ const TextField = /*#__PURE__*/ styled("textarea", {
|
|
|
32
32
|
line-height: 14px;
|
|
33
33
|
}
|
|
34
34
|
` : '', " &:focus + span,&:placeholder-shown + span{top:-8px;background:", getThemeValue(THEME_NAME.BACKGROUND), ";font-size:12px;line-height:14px;}");
|
|
35
|
-
const ErrorContainer$
|
|
36
|
-
target: "
|
|
35
|
+
const ErrorContainer$4 = /*#__PURE__*/ styled("div", {
|
|
36
|
+
target: "e1towgf52",
|
|
37
37
|
label: "ErrorContainer"
|
|
38
38
|
})("color:", getThemeValue(THEME_NAME.ERROR), ";padding-top:3px;font-size:12px;line-height:14px;margin-left:3px;");
|
|
39
39
|
/**
|
|
40
40
|
* TextArea Component
|
|
41
41
|
* @param props - Component props
|
|
42
42
|
* @param ref - Ref forwarded to the underlying HTMLTextAreaElement
|
|
43
|
-
*/ function TextAreaComponent(props,
|
|
43
|
+
*/ function TextAreaComponent(props, forwardedRef) {
|
|
44
44
|
const { label, errorText, value: propsValue, required, ...rest } = props;
|
|
45
45
|
const [touched, setTouched] = useState(false);
|
|
46
46
|
const [value, setValue] = useState(propsValue || '');
|
|
47
47
|
const errorId = useId();
|
|
48
48
|
const prevValueRef = useRef(undefined);
|
|
49
|
+
const internalRef = useRef(null);
|
|
50
|
+
useImperativeHandle(forwardedRef, ()=>internalRef.current);
|
|
49
51
|
useEffect(()=>{
|
|
50
52
|
if (propsValue !== undefined && propsValue !== prevValueRef.current) {
|
|
51
53
|
setValue(propsValue);
|
|
@@ -54,6 +56,13 @@ const ErrorContainer$2 = /*#__PURE__*/ styled("div", {
|
|
|
54
56
|
}, [
|
|
55
57
|
propsValue
|
|
56
58
|
]);
|
|
59
|
+
useEffect(()=>{
|
|
60
|
+
if (internalRef.current) {
|
|
61
|
+
internalRef.current.setCustomValidity(errorText || '');
|
|
62
|
+
}
|
|
63
|
+
}, [
|
|
64
|
+
errorText
|
|
65
|
+
]);
|
|
57
66
|
const handleFocus = (e)=>{
|
|
58
67
|
setTouched(true);
|
|
59
68
|
if (props.onFocus) {
|
|
@@ -72,7 +81,7 @@ const ErrorContainer$2 = /*#__PURE__*/ styled("div", {
|
|
|
72
81
|
children: [
|
|
73
82
|
/*#__PURE__*/ jsx(TextField, {
|
|
74
83
|
...rest,
|
|
75
|
-
ref:
|
|
84
|
+
ref: internalRef,
|
|
76
85
|
value: value,
|
|
77
86
|
onChange: onChangeHandler,
|
|
78
87
|
onFocus: handleFocus,
|
|
@@ -85,7 +94,7 @@ const ErrorContainer$2 = /*#__PURE__*/ styled("div", {
|
|
|
85
94
|
/*#__PURE__*/ jsx("span", {
|
|
86
95
|
children: label
|
|
87
96
|
}),
|
|
88
|
-
errorText && /*#__PURE__*/ jsx(ErrorContainer$
|
|
97
|
+
errorText && /*#__PURE__*/ jsx(ErrorContainer$4, {
|
|
89
98
|
id: errorId,
|
|
90
99
|
children: errorText
|
|
91
100
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextArea.js","sources":["../../../src/components/Input/TextArea.tsx"],"sourcesContent":["import React, { useState, useEffect, useId, useRef } from 'react';\nimport styled from '@emotion/styled';\nimport { getThemeValue, THEME_NAME } from '../../shared/constants';\n\ntype TextAreaProps = {\n /** Label for the field */\n label: string;\n /** Error text to be shown below the field */\n errorText?: string;\n} & React.InputHTMLAttributes<HTMLTextAreaElement>;\n\ntype TextAreaInternalProps = {\n touched: boolean;\n errorText?: string;\n};\n\nconst Label = styled.label`\n display: inline-flex;\n flex-direction: column;\n position: relative;\n margin: 10px 5px;\n`;\n\nconst TextField = styled.textarea<TextAreaInternalProps>`\n border: none;\n color: inherit;\n padding: 8px;\n min-height: 150px;\n min-width: 250px;\n border-radius: 3px;\n border: 1px solid ${getThemeValue(THEME_NAME.BORDER_COLOR)};\n display: inline-block;\n background-color: ${getThemeValue(THEME_NAME.BACKGROUND)};\n\n /** Focused */\n &:focus,\n &:active {\n border-color: ${getThemeValue(THEME_NAME.PRIMARY)};\n box-shadow: 0 0 0 4px ${getThemeValue(THEME_NAME.PRIMARY_LIGHT)};\n }\n\n &:focus + span,\n &:active + span {\n color: ${getThemeValue(THEME_NAME.PRIMARY)};\n }\n\n /** Disabled */\n &:disabled {\n border-color: ${getThemeValue(THEME_NAME.DISABLED_BORDER)};\n background-color: ${getThemeValue(THEME_NAME.DISABLED_BACKGROUND)};\n }\n\n &:disabled + span {\n color: ${getThemeValue(THEME_NAME.DISABLED)};\n }\n\n /** Invalid */\n &:focus:invalid {\n border-color: ${getThemeValue(THEME_NAME.ERROR)};\n box-shadow: 0 0 0 4px ${getThemeValue(THEME_NAME.ERROR_LIGHT)};\n }\n\n ${(props) =>\n props.touched\n ? `\n &:invalid {\n border-color: ${getThemeValue(THEME_NAME.ERROR)};\n }\n\n &:invalid + span {\n color: ${getThemeValue(THEME_NAME.ERROR)};\n }\n `\n : ''}\n\n /** Error */\n ${(props) =>\n props.errorText\n ? `\n border-color: ${getThemeValue(THEME_NAME.ERROR)};\n\n & + span {\n color: ${getThemeValue(THEME_NAME.ERROR)};\n }\n `\n : ''}\n\n /** Required */\n &:required + span:after {\n content: '*';\n margin-left: 2px;\n color: ${getThemeValue(THEME_NAME.ERROR)};\n }\n\n /** Label Animation */\n & + span {\n position: absolute;\n padding: 0 5px;\n top: 0px;\n left: 4px;\n font-size: 14px;\n line-height: 32px;\n transition: all 300ms ease;\n }\n\n ${(props) =>\n props.value !== ''\n ? `\n & + span {\n top: -8px;\n background: ${getThemeValue(THEME_NAME.BACKGROUND)};\n font-size: 12px;\n line-height: 14px;\n }\n `\n : ''}\n\n &:focus + span, &:placeholder-shown + span {\n top: -8px;\n background: ${getThemeValue(THEME_NAME.BACKGROUND)};\n font-size: 12px;\n line-height: 14px;\n }\n`;\n\nconst ErrorContainer = styled.div`\n color: ${getThemeValue(THEME_NAME.ERROR)};\n padding-top: 3px;\n font-size: 12px;\n line-height: 14px;\n margin-left: 3px;\n`;\n\n/**\n * TextArea Component\n * @param props - Component props\n * @param ref - Ref forwarded to the underlying HTMLTextAreaElement\n */\nfunction TextAreaComponent(props: TextAreaProps,
|
|
1
|
+
{"version":3,"file":"TextArea.js","sources":["../../../src/components/Input/TextArea.tsx"],"sourcesContent":["import React, { useState, useEffect, useId, useRef, useImperativeHandle } from 'react';\nimport styled from '@emotion/styled';\nimport { getThemeValue, THEME_NAME } from '../../shared/constants';\n\ntype TextAreaProps = {\n /** Label for the field */\n label: string;\n /** Error text to be shown below the field */\n errorText?: string;\n} & React.InputHTMLAttributes<HTMLTextAreaElement>;\n\ntype TextAreaInternalProps = {\n touched: boolean;\n errorText?: string;\n};\n\nconst Label = styled.label`\n display: inline-flex;\n flex-direction: column;\n position: relative;\n margin: 10px 5px;\n`;\n\nconst TextField = styled.textarea<TextAreaInternalProps>`\n border: none;\n color: inherit;\n padding: 8px;\n min-height: 150px;\n min-width: 250px;\n border-radius: 3px;\n border: 1px solid ${getThemeValue(THEME_NAME.BORDER_COLOR)};\n display: inline-block;\n background-color: ${getThemeValue(THEME_NAME.BACKGROUND)};\n\n /** Focused */\n &:focus,\n &:active {\n border-color: ${getThemeValue(THEME_NAME.PRIMARY)};\n box-shadow: 0 0 0 4px ${getThemeValue(THEME_NAME.PRIMARY_LIGHT)};\n }\n\n &:focus + span,\n &:active + span {\n color: ${getThemeValue(THEME_NAME.PRIMARY)};\n }\n\n /** Disabled */\n &:disabled {\n border-color: ${getThemeValue(THEME_NAME.DISABLED_BORDER)};\n background-color: ${getThemeValue(THEME_NAME.DISABLED_BACKGROUND)};\n }\n\n &:disabled + span {\n color: ${getThemeValue(THEME_NAME.DISABLED)};\n }\n\n /** Invalid */\n &:focus:invalid {\n border-color: ${getThemeValue(THEME_NAME.ERROR)};\n box-shadow: 0 0 0 4px ${getThemeValue(THEME_NAME.ERROR_LIGHT)};\n }\n\n ${(props) =>\n props.touched\n ? `\n &:invalid {\n border-color: ${getThemeValue(THEME_NAME.ERROR)};\n }\n\n &:invalid + span {\n color: ${getThemeValue(THEME_NAME.ERROR)};\n }\n `\n : ''}\n\n /** Error */\n ${(props) =>\n props.errorText\n ? `\n border-color: ${getThemeValue(THEME_NAME.ERROR)};\n\n & + span {\n color: ${getThemeValue(THEME_NAME.ERROR)};\n }\n `\n : ''}\n\n /** Required */\n &:required + span:after {\n content: '*';\n margin-left: 2px;\n color: ${getThemeValue(THEME_NAME.ERROR)};\n }\n\n /** Label Animation */\n & + span {\n position: absolute;\n padding: 0 5px;\n top: 0px;\n left: 4px;\n font-size: 14px;\n line-height: 32px;\n transition: all 300ms ease;\n }\n\n ${(props) =>\n props.value !== ''\n ? `\n & + span {\n top: -8px;\n background: ${getThemeValue(THEME_NAME.BACKGROUND)};\n font-size: 12px;\n line-height: 14px;\n }\n `\n : ''}\n\n &:focus + span, &:placeholder-shown + span {\n top: -8px;\n background: ${getThemeValue(THEME_NAME.BACKGROUND)};\n font-size: 12px;\n line-height: 14px;\n }\n`;\n\nconst ErrorContainer = styled.div`\n color: ${getThemeValue(THEME_NAME.ERROR)};\n padding-top: 3px;\n font-size: 12px;\n line-height: 14px;\n margin-left: 3px;\n`;\n\n/**\n * TextArea Component\n * @param props - Component props\n * @param ref - Ref forwarded to the underlying HTMLTextAreaElement\n */\nfunction TextAreaComponent(props: TextAreaProps, forwardedRef: React.Ref<HTMLTextAreaElement>) {\n const { label, errorText, value: propsValue, required, ...rest } = props;\n const [touched, setTouched] = useState(false);\n const [value, setValue] = useState(propsValue || '');\n const errorId = useId();\n const prevValueRef = useRef<string>(undefined);\n const internalRef = useRef<HTMLTextAreaElement>(null);\n\n useImperativeHandle(forwardedRef, () => internalRef.current as HTMLTextAreaElement);\n\n useEffect(() => {\n if (propsValue !== undefined && propsValue !== prevValueRef.current) {\n setValue(propsValue);\n prevValueRef.current = propsValue as string;\n }\n }, [propsValue]);\n\n useEffect(() => {\n if (internalRef.current) {\n internalRef.current.setCustomValidity(errorText || '');\n }\n }, [errorText]);\n\n const handleFocus = (e: React.FocusEvent<HTMLTextAreaElement>) => {\n setTouched(true);\n if (props.onFocus) {\n props.onFocus(e);\n }\n };\n\n const onChangeHandler = (e: React.ChangeEvent<HTMLTextAreaElement>) => {\n if (props.onChange) {\n setValue(e.target.value);\n props.onChange(e);\n } else {\n setValue(e.target.value);\n }\n };\n\n return (\n <Label>\n <TextField\n {...rest}\n ref={internalRef}\n value={value}\n onChange={onChangeHandler}\n onFocus={handleFocus}\n touched={touched}\n required={required}\n aria-invalid={!!errorText}\n aria-required={required}\n aria-describedby={errorText ? errorId : undefined}\n />\n <span>{label}</span>\n {errorText && <ErrorContainer id={errorId}>{errorText}</ErrorContainer>}\n </Label>\n );\n}\n\nconst TextArea = React.forwardRef(TextAreaComponent);\nexport default TextArea;\n"],"names":["Label","styled","TextField","getThemeValue","THEME_NAME","BORDER_COLOR","BACKGROUND","PRIMARY","PRIMARY_LIGHT","DISABLED_BORDER","DISABLED_BACKGROUND","DISABLED","ERROR","ERROR_LIGHT","props","touched","errorText","value","ErrorContainer","TextAreaComponent","forwardedRef","label","propsValue","required","rest","setTouched","useState","setValue","errorId","useId","prevValueRef","useRef","undefined","internalRef","useImperativeHandle","current","useEffect","setCustomValidity","handleFocus","e","onFocus","onChangeHandler","onChange","target","_jsxs","_jsx","ref","aria-invalid","aria-required","aria-describedby","span","id","TextArea","React","forwardRef"],"mappings":";;;;;AAgBA,MAAMA,OAAAA,iBAAQC,MAAAA,CAAAA,OAAAA,EAAAA;;;;AAOd,MAAMC,SAAAA,iBAAYD,MAAAA,CAAAA,UAAAA,EAAAA;;;iHAOME,aAAAA,CAAcC,UAAAA,CAAWC,YAAY,CAAA,EAAA,yCAAA,EAErCF,aAAAA,CAAcC,WAAWE,UAAU,CAAA,EAAA,iCAAA,EAKnCH,cAAcC,UAAAA,CAAWG,OAAO,6BACxBJ,aAAAA,CAAcC,UAAAA,CAAWI,aAAa,CAAA,EAAA,yCAAA,EAKrDL,aAAAA,CAAcC,WAAWG,OAAO,CAAA,EAAA,4BAAA,EAKzBJ,cAAcC,UAAAA,CAAWK,eAAe,yBACpCN,aAAAA,CAAcC,UAAAA,CAAWM,mBAAmB,CAAA,EAAA,4BAAA,EAIvDP,aAAAA,CAAcC,WAAWO,QAAQ,CAAA,EAAA,iCAAA,EAK1BR,cAAcC,UAAAA,CAAWQ,KAAK,6BACtBT,aAAAA,CAAcC,UAAAA,CAAWS,WAAW,CAAA,EAAA,IAAA,EAG9D,CAACC,QACCA,KAAAA,CAAMC,OAAO,GACP;;sBAEQ,EAAEZ,aAAAA,CAAcC,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;;0BACG6C,GAAA,CAAC3C,SAAAA,EAAAA;AACI,gBAAA,GAAGsB,IAAI;gBACRsB,GAAAA,EAAKb,WAAAA;gBACLhB,KAAAA,EAAOA,KAAAA;gBACPyB,QAAAA,EAAUD,eAAAA;gBACVD,OAAAA,EAASF,WAAAA;gBACTvB,OAAAA,EAASA,OAAAA;gBACTQ,QAAAA,EAAUA,QAAAA;AACVwB,gBAAAA,cAAAA,EAAc,CAAC,CAAC/B,SAAAA;gBAChBgC,eAAAA,EAAezB,QAAAA;AACf0B,gBAAAA,kBAAAA,EAAkBjC,YAAYY,OAAAA,GAAUI;;0BAE5Ca,GAAA,CAACK,MAAAA,EAAAA;AAAM7B,gBAAAA,QAAAA,EAAAA;;AACNL,YAAAA,SAAAA,kBAAa6B,GAAA,CAAC3B,gBAAAA,EAAAA;gBAAeiC,EAAAA,EAAIvB,OAAAA;AAAUZ,gBAAAA,QAAAA,EAAAA;;;;AAGxD;AAEA,MAAMoC,QAAAA,iBAAWC,KAAAA,CAAMC,UAAU,CAACnC,iBAAAA;;;;"}
|
|
@@ -2,5 +2,7 @@ import React from 'react';
|
|
|
2
2
|
declare const Toggle: React.ForwardRefExoticComponent<{
|
|
3
3
|
/** Label for the field */
|
|
4
4
|
label?: string;
|
|
5
|
+
/** Error text to be shown below the field */
|
|
6
|
+
errorText?: string;
|
|
5
7
|
} & React.InputHTMLAttributes<HTMLInputElement> & React.RefAttributes<HTMLInputElement>>;
|
|
6
8
|
export default Toggle;
|
|
@@ -1,33 +1,63 @@
|
|
|
1
1
|
import { jsxs, jsx } from '@emotion/react/jsx-runtime';
|
|
2
|
-
import React from 'react';
|
|
2
|
+
import React, { useRef, useId, useImperativeHandle, useEffect } from 'react';
|
|
3
3
|
import styled from '@emotion/styled';
|
|
4
4
|
import { getThemeValue, THEME_NAME } from '../../shared/constants.js';
|
|
5
5
|
|
|
6
6
|
const Switch = /*#__PURE__*/ styled("label", {
|
|
7
|
-
target: "
|
|
7
|
+
target: "ecxpw850",
|
|
8
8
|
label: "Switch"
|
|
9
9
|
})("position:relative;display:inline-flex;margin:5px 0;");
|
|
10
10
|
const Input$1 = /*#__PURE__*/ styled("input", {
|
|
11
|
-
target: "
|
|
11
|
+
target: "ecxpw851",
|
|
12
12
|
label: "Input"
|
|
13
13
|
})("position:absolute;width:0;height:0;appearance:none;margin:0;& + span{position:relative;cursor:pointer;width:30px;height:18px;background-color:", getThemeValue(THEME_NAME.LIGHT_GREY), ";transition:0.4s;border-radius:10px;padding:0 3px;margin:0 10px 0 5px;}& + span:before{position:absolute;content:'';height:14px;width:14px;left:1px;top:1px;border:1px solid ", getThemeValue(THEME_NAME.DISABLED_BORDER), ";border-radius:50%;background-color:", getThemeValue(THEME_NAME.BACKGROUND), ";transition:0.4s;}&:checked + span{background-color:", getThemeValue(THEME_NAME.PRIMARY_LIGHT), ";}&:checked + span:before{transform:translateX(18px);border-color:", getThemeValue(THEME_NAME.PRIMARY), ";}&:enabled:focus + span:before{box-shadow:0 0 0 3px ", getThemeValue(THEME_NAME.PRIMARY_LIGHT), ";border-color:", getThemeValue(THEME_NAME.PRIMARY), ";}&:enabled:hover ~ span{cursor:pointer;color:", getThemeValue(THEME_NAME.PRIMARY), ";}&:disabled ~ span{color:", getThemeValue(THEME_NAME.DISABLED_BORDER), ";}&:disabled + span{background-color:", getThemeValue(THEME_NAME.LIGHT_GREY), ";cursor:not-allowed;}&:disabled + span:before{background-color:", getThemeValue(THEME_NAME.BORDER_LIGHT_COLOR), ";border-color:", getThemeValue(THEME_NAME.DISABLED_BORDER), ";}");
|
|
14
|
+
const ErrorContainer$1 = /*#__PURE__*/ styled("div", {
|
|
15
|
+
target: "ecxpw852",
|
|
16
|
+
label: "ErrorContainer"
|
|
17
|
+
})("color:", getThemeValue(THEME_NAME.ERROR), ";padding-top:3px;font-size:12px;line-height:14px;");
|
|
18
|
+
const Container$5 = /*#__PURE__*/ styled("div", {
|
|
19
|
+
target: "ecxpw853",
|
|
20
|
+
label: "Container"
|
|
21
|
+
})("display:inline-flex;flex-direction:column;");
|
|
14
22
|
/**
|
|
15
23
|
* Toggle Component
|
|
16
24
|
* @param props - Component props
|
|
17
|
-
* @param
|
|
18
|
-
*/ function ToggleComponent(props,
|
|
19
|
-
|
|
25
|
+
* @param forwardedRef - Ref forwarded to the underlying HTMLInputElement
|
|
26
|
+
*/ function ToggleComponent(props, forwardedRef) {
|
|
27
|
+
const { label, errorText, ...rest } = props;
|
|
28
|
+
const internalRef = useRef(null);
|
|
29
|
+
const errorId = useId();
|
|
30
|
+
useImperativeHandle(forwardedRef, ()=>internalRef.current);
|
|
31
|
+
useEffect(()=>{
|
|
32
|
+
if (internalRef.current) {
|
|
33
|
+
internalRef.current.setCustomValidity(errorText || '');
|
|
34
|
+
}
|
|
35
|
+
}, [
|
|
36
|
+
errorText
|
|
37
|
+
]);
|
|
38
|
+
return /*#__PURE__*/ jsxs(Container$5, {
|
|
20
39
|
children: [
|
|
21
|
-
/*#__PURE__*/
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
40
|
+
/*#__PURE__*/ jsxs(Switch, {
|
|
41
|
+
children: [
|
|
42
|
+
/*#__PURE__*/ jsx(Input$1, {
|
|
43
|
+
...rest,
|
|
44
|
+
ref: internalRef,
|
|
45
|
+
type: "checkbox",
|
|
46
|
+
role: "switch",
|
|
47
|
+
"aria-checked": props.checked,
|
|
48
|
+
"aria-invalid": !!errorText,
|
|
49
|
+
"aria-label": label,
|
|
50
|
+
"aria-describedby": errorText ? errorId : undefined
|
|
51
|
+
}),
|
|
52
|
+
/*#__PURE__*/ jsx("span", {}),
|
|
53
|
+
/*#__PURE__*/ jsx("span", {
|
|
54
|
+
children: label
|
|
55
|
+
})
|
|
56
|
+
]
|
|
27
57
|
}),
|
|
28
|
-
/*#__PURE__*/ jsx(
|
|
29
|
-
|
|
30
|
-
children:
|
|
58
|
+
errorText && /*#__PURE__*/ jsx(ErrorContainer$1, {
|
|
59
|
+
id: errorId,
|
|
60
|
+
children: errorText
|
|
31
61
|
})
|
|
32
62
|
]
|
|
33
63
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toggle.js","sources":["../../../src/components/Input/Toggle.tsx"],"sourcesContent":["import React from 'react';\nimport styled from '@emotion/styled';\nimport { getThemeValue, THEME_NAME } from '../../shared/constants';\n\nconst Switch = styled.label`\n position: relative;\n display: inline-flex;\n margin: 5px 0;\n`;\n\nconst Input = styled.input`\n position: absolute;\n width: 0;\n height: 0;\n appearance: none;\n margin: 0;\n\n & + span {\n position: relative;\n cursor: pointer;\n width: 30px;\n height: 18px;\n background-color: ${getThemeValue(THEME_NAME.LIGHT_GREY)};\n transition: 0.4s;\n border-radius: 10px;\n padding: 0 3px;\n margin: 0 10px 0 5px;\n }\n & + span:before {\n position: absolute;\n content: '';\n height: 14px;\n width: 14px;\n left: 1px;\n top: 1px;\n border: 1px solid ${getThemeValue(THEME_NAME.DISABLED_BORDER)};\n border-radius: 50%;\n background-color: ${getThemeValue(THEME_NAME.BACKGROUND)};\n transition: 0.4s;\n }\n\n /* checked */\n &:checked + span {\n background-color: ${getThemeValue(THEME_NAME.PRIMARY_LIGHT)};\n }\n\n &:checked + span:before {\n transform: translateX(18px);\n border-color: ${getThemeValue(THEME_NAME.PRIMARY)};\n }\n\n /* focus */\n &:enabled:focus + span:before {\n box-shadow: 0 0 0 3px ${getThemeValue(THEME_NAME.PRIMARY_LIGHT)};\n border-color: ${getThemeValue(THEME_NAME.PRIMARY)};\n }\n\n /* hover */\n &:enabled:hover ~ span {\n cursor: pointer;\n color: ${getThemeValue(THEME_NAME.PRIMARY)};\n }\n\n /* disabled */\n &:disabled ~ span {\n color: ${getThemeValue(THEME_NAME.DISABLED_BORDER)};\n }\n\n &:disabled + span {\n background-color: ${getThemeValue(THEME_NAME.LIGHT_GREY)};\n cursor: not-allowed;\n }\n\n &:disabled + span:before {\n background-color: ${getThemeValue(THEME_NAME.BORDER_LIGHT_COLOR)};\n border-color: ${getThemeValue(THEME_NAME.DISABLED_BORDER)};\n }\n`;\n\ntype ToggleProps = {\n /** Label for the field */\n label?: string;\n} & React.InputHTMLAttributes<HTMLInputElement>;\n\n/**\n * Toggle Component\n * @param props - Component props\n * @param
|
|
1
|
+
{"version":3,"file":"Toggle.js","sources":["../../../src/components/Input/Toggle.tsx"],"sourcesContent":["import React, { useEffect, useId, useRef, useImperativeHandle } from 'react';\nimport styled from '@emotion/styled';\nimport { getThemeValue, THEME_NAME } from '../../shared/constants';\n\nconst Switch = styled.label`\n position: relative;\n display: inline-flex;\n margin: 5px 0;\n`;\n\nconst Input = styled.input`\n position: absolute;\n width: 0;\n height: 0;\n appearance: none;\n margin: 0;\n\n & + span {\n position: relative;\n cursor: pointer;\n width: 30px;\n height: 18px;\n background-color: ${getThemeValue(THEME_NAME.LIGHT_GREY)};\n transition: 0.4s;\n border-radius: 10px;\n padding: 0 3px;\n margin: 0 10px 0 5px;\n }\n & + span:before {\n position: absolute;\n content: '';\n height: 14px;\n width: 14px;\n left: 1px;\n top: 1px;\n border: 1px solid ${getThemeValue(THEME_NAME.DISABLED_BORDER)};\n border-radius: 50%;\n background-color: ${getThemeValue(THEME_NAME.BACKGROUND)};\n transition: 0.4s;\n }\n\n /* checked */\n &:checked + span {\n background-color: ${getThemeValue(THEME_NAME.PRIMARY_LIGHT)};\n }\n\n &:checked + span:before {\n transform: translateX(18px);\n border-color: ${getThemeValue(THEME_NAME.PRIMARY)};\n }\n\n /* focus */\n &:enabled:focus + span:before {\n box-shadow: 0 0 0 3px ${getThemeValue(THEME_NAME.PRIMARY_LIGHT)};\n border-color: ${getThemeValue(THEME_NAME.PRIMARY)};\n }\n\n /* hover */\n &:enabled:hover ~ span {\n cursor: pointer;\n color: ${getThemeValue(THEME_NAME.PRIMARY)};\n }\n\n /* disabled */\n &:disabled ~ span {\n color: ${getThemeValue(THEME_NAME.DISABLED_BORDER)};\n }\n\n &:disabled + span {\n background-color: ${getThemeValue(THEME_NAME.LIGHT_GREY)};\n cursor: not-allowed;\n }\n\n &:disabled + span:before {\n background-color: ${getThemeValue(THEME_NAME.BORDER_LIGHT_COLOR)};\n border-color: ${getThemeValue(THEME_NAME.DISABLED_BORDER)};\n }\n`;\n\nconst ErrorContainer = styled.div`\n color: ${getThemeValue(THEME_NAME.ERROR)};\n padding-top: 3px;\n font-size: 12px;\n line-height: 14px;\n`;\n\nconst Container = styled.div`\n display: inline-flex;\n flex-direction: column;\n`;\n\ntype ToggleProps = {\n /** Label for the field */\n label?: string;\n /** Error text to be shown below the field */\n errorText?: string;\n} & React.InputHTMLAttributes<HTMLInputElement>;\n\n/**\n * Toggle Component\n * @param props - Component props\n * @param forwardedRef - Ref forwarded to the underlying HTMLInputElement\n */\nfunction ToggleComponent(props: ToggleProps, forwardedRef: React.Ref<HTMLInputElement>) {\n const { label, errorText, ...rest } = props;\n const internalRef = useRef<HTMLInputElement>(null);\n const errorId = useId();\n\n useImperativeHandle(forwardedRef, () => internalRef.current as HTMLInputElement);\n\n useEffect(() => {\n if (internalRef.current) {\n internalRef.current.setCustomValidity(errorText || '');\n }\n }, [errorText]);\n\n return (\n <Container>\n <Switch>\n <Input\n {...rest}\n ref={internalRef}\n type=\"checkbox\"\n role=\"switch\"\n aria-checked={props.checked}\n aria-invalid={!!errorText}\n aria-label={label}\n aria-describedby={errorText ? errorId : undefined}\n />\n <span></span>\n <span>{label}</span>\n </Switch>\n {errorText && <ErrorContainer id={errorId}>{errorText}</ErrorContainer>}\n </Container>\n );\n}\n\nconst Toggle = React.forwardRef(ToggleComponent);\nexport default Toggle;\n"],"names":["Switch","styled","Input","getThemeValue","THEME_NAME","LIGHT_GREY","DISABLED_BORDER","BACKGROUND","PRIMARY_LIGHT","PRIMARY","BORDER_LIGHT_COLOR","ErrorContainer","ERROR","Container","ToggleComponent","props","forwardedRef","label","errorText","rest","internalRef","useRef","errorId","useId","useImperativeHandle","current","useEffect","setCustomValidity","_jsxs","_jsx","ref","type","role","aria-checked","checked","aria-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|
|
9
|
-
target: "
|
|
9
|
+
target: "e1u7wt750",
|
|
10
10
|
label: "Container"
|
|
11
11
|
})("font-weight:", (props)=>props.selected ? 'bold' : 'normal', ";padding:8px;border:none;border-left:4px solid\n ", (props)=>props.selected && !props.multiselect ? getThemeValue(THEME_NAME.TEXT_COLOR_DARK) : 'transparent', ";background-color:transparent;font-size:16px;border-bottom:1px solid ", getThemeValue(THEME_NAME.BORDER_LIGHT_COLOR), ";min-height:41px;display:flex;align-items:center;cursor:pointer;position:relative;color:", getThemeValue(THEME_NAME.TEXT_COLOR_DARK), ";&:hover,&:focus,&:focus-within{background-color:", getThemeValue(THEME_NAME.BORDER_LIGHT_COLOR), ";}& > label{margin:0 4px 0 0;}");
|
|
12
12
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MenuItem.js","sources":["../../../src/components/Menu/MenuItem.tsx"],"sourcesContent":["import React, { SyntheticEvent, useContext } from 'react';\nimport styled from '@emotion/styled';\nimport { getThemeValue, THEME_NAME } from '../../shared/constants';\nimport Checkbox from '../Input/Checkbox';\nimport MenuContext, { MenuContextType } from './MenuContext';\n\
|
|
1
|
+
{"version":3,"file":"MenuItem.js","sources":["../../../src/components/Menu/MenuItem.tsx"],"sourcesContent":["import React, { SyntheticEvent, useContext } from 'react';\nimport styled from '@emotion/styled';\nimport { getThemeValue, THEME_NAME } from '../../shared/constants';\nimport Checkbox from '../Input/Checkbox';\nimport MenuContext, { MenuContextType } from './MenuContext';\n\nexport type MenuItemProps<T> = {\n /** Value of the element */\n value: T;\n} & Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'value'>;\n\nconst Container = styled.button<{ selected: boolean; multiselect?: boolean }>`\n font-weight: ${(props) => (props.selected ? 'bold' : 'normal')};\n padding: 8px;\n border: none;\n border-left: 4px solid\n ${(props) =>\n props.selected && !props.multiselect\n ? getThemeValue(THEME_NAME.TEXT_COLOR_DARK)\n : 'transparent'};\n background-color: transparent;\n font-size: 16px;\n border-bottom: 1px solid ${getThemeValue(THEME_NAME.BORDER_LIGHT_COLOR)};\n min-height: 41px;\n display: flex;\n align-items: center;\n cursor: pointer;\n position: relative;\n color: ${getThemeValue(THEME_NAME.TEXT_COLOR_DARK)};\n\n &:hover,\n &:focus,\n &:focus-within {\n background-color: ${getThemeValue(THEME_NAME.BORDER_LIGHT_COLOR)};\n }\n\n & > label {\n margin: 0 4px 0 0;\n }\n`;\n\n/**\n * MenuItem Component\n * @template T - The type of value in the menu item.\n * @param props - Component props\n * @param ref - Ref forwarded to the underlying HTMLButtonElement\n */\nconst MenuItemInner = <T,>(props: MenuItemProps<T>, ref: React.Ref<HTMLButtonElement>) => {\n const context = useContext(MenuContext) as MenuContextType<T> | undefined;\n if (!context) {\n throw new Error('`MenuItem` must be used within a `Menu` provider');\n }\n const { value, children, ...rest } = props;\n const clickHandler = (e: SyntheticEvent) => {\n e.stopPropagation();\n context.updateValue(value as T);\n };\n\n let selected = false;\n if (context.multiSelect) {\n const arr = context.value as unknown as T[] | undefined;\n selected = Array.isArray(arr) && arr.includes(value as unknown as T);\n } else {\n selected = (context.value as unknown as T) === value;\n }\n\n return (\n <Container\n {...rest}\n ref={ref}\n type=\"button\"\n role=\"option\"\n aria-selected={selected}\n selected={selected}\n onClick={clickHandler}\n multiselect={context.multiSelect ? true : undefined}\n >\n {context.multiSelect && (\n <Checkbox\n checked={selected}\n readOnly\n tabIndex={-1}\n onClick={(e) => e.stopPropagation()}\n />\n )}\n {children}\n </Container>\n );\n};\n\nconst MenuItem = React.forwardRef(MenuItemInner) as <T>(\n props: MenuItemProps<T> & { ref?: React.Ref<HTMLButtonElement> },\n) => ReturnType<typeof MenuItemInner>;\nexport default MenuItem;\n"],"names":["Container","styled","props","selected","multiselect","getThemeValue","THEME_NAME","TEXT_COLOR_DARK","BORDER_LIGHT_COLOR","MenuItemInner","ref","context","useContext","MenuContext","Error","value","children","rest","clickHandler","e","stopPropagation","updateValue","multiSelect","arr","Array","isArray","includes","_jsxs","type","role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CAACF,GAAAA,CAAAA,IAAQA,GAAAA,CAAIG,QAAQ,CAACX,KAAAA,CAAAA;IAClD,CAAA,MAAO;QACHZ,QAAAA,GAAYQ,OAAAA,CAAQI,KAAK,KAAsBA,KAAAA;AACnD,IAAA;AAEA,IAAA,qBACIY,IAAA,CAAC3B,WAAAA,EAAAA;AACI,QAAA,GAAGiB,IAAI;QACRP,GAAAA,EAAKA,GAAAA;QACLkB,IAAAA,EAAK,QAAA;QACLC,IAAAA,EAAK,QAAA;QACLC,eAAAA,EAAe3B,QAAAA;QACfA,QAAAA,EAAUA,QAAAA;QACV4B,OAAAA,EAASb,YAAAA;QACTd,WAAAA,EAAaO,OAAAA,CAAQW,WAAW,GAAG,IAAA,GAAOU,SAAAA;;YAEzCrB,OAAAA,CAAQW,WAAW,kBAChBW,GAAA,CAACC,QAAAA,EAAAA;gBACGC,OAAAA,EAAShC,QAAAA;gBACTiC,QAAQ,EAAA,IAAA;AACRC,gBAAAA,QAAAA,EAAU,EAAC;gBACXN,OAAAA,EAAS,CAACZ,CAAAA,GAAMA,CAAAA,CAAEC,eAAe;;AAGxCJ,YAAAA;;;AAGb,CAAA;AAEA,MAAMsB,QAAAA,iBAAWC,KAAAA,CAAMC,UAAU,CAAC/B,aAAAA;;;;"}
|
|
@@ -89,7 +89,7 @@ export default class Modal extends React.Component<React.PropsWithChildren<Modal
|
|
|
89
89
|
* Lifecycle method to handle Modal updates.
|
|
90
90
|
* Manages opening/closing logic via LayerManager and focus preservation.
|
|
91
91
|
*/
|
|
92
|
-
|
|
92
|
+
componentDidUpdate(prevProps: ModalProps): void;
|
|
93
93
|
/**
|
|
94
94
|
* Renders the Modal component via the LayerManager portal.
|
|
95
95
|
*/
|
|
@@ -39,7 +39,7 @@ class Modal extends React.Component {
|
|
|
39
39
|
/**
|
|
40
40
|
* Lifecycle method to handle Modal updates.
|
|
41
41
|
* Manages opening/closing logic via LayerManager and focus preservation.
|
|
42
|
-
*/
|
|
42
|
+
*/ componentDidUpdate(prevProps) {
|
|
43
43
|
const { open } = this.props;
|
|
44
44
|
if (prevProps.open && !open) {
|
|
45
45
|
this.closeCallback?.();
|
|
@@ -50,7 +50,6 @@ class Modal extends React.Component {
|
|
|
50
50
|
this.lastFocusedElement = document.activeElement;
|
|
51
51
|
this.handleOpen();
|
|
52
52
|
}
|
|
53
|
-
return null;
|
|
54
53
|
}
|
|
55
54
|
/**
|
|
56
55
|
* Renders the Modal component via the LayerManager portal.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Modal.js","sources":["../../../src/components/Modal/Modal.tsx"],"sourcesContent":["import React from 'react';\nimport LayerManager, { LAYER_POSITION } from '../../shared/LayerManager';\nexport {\n Header as ModalHeader,\n Body as ModalBody,\n Footer as ModalFooter,\n} from '../../shared/styles';\nimport { DialogContainer as ModalContainer } from '../Dialog/Dialog';\n\ntype ModalProps = {\n /** Opens the modal */\n open: boolean;\n /** Closes the modal on esc */\n closeOnEsc?: boolean;\n /** Closes the modal on overlay click */\n closeOnOverlayClick?: boolean;\n /** Call back function called when the modal closes. */\n onClose?: () => void;\n /** Ref forwarded to the underlying HTMLDivElement of the modal container */\n forwardRef?: React.Ref<HTMLDivElement>;\n} & React.HTMLAttributes<HTMLDivElement>;\n\ninterface ModalState {\n open: boolean;\n}\n\n/**\n * Modal component\n *\n * A dialog window that sits on top of the main application content.\n * It disrupts the user's workflow to demand attention for a critical task or decision.\n *\n * Accessibility:\n * - Implements ARIA `role=\"dialog\"` and `aria-modal=\"true\"`.\n * - Traps focus effectively within the modal while open.\n * - Restores focus to the triggering element upon closure.\n * - Supports closing via ESC key and overlay click.\n */\nexport default class Modal extends React.Component<\n React.PropsWithChildren<ModalProps>,\n ModalState\n> {\n state = {\n open: false,\n };\n\n static defaultProps = {\n closeOnEsc: true,\n closeOnOverlayClick: true,\n };\n\n /**\n * Syncs state with props.\n */\n static getDerivedStateFromProps(props: ModalProps) {\n if (props.open) {\n return {\n open: true,\n };\n }\n return null;\n }\n\n private layer?: ReturnType<typeof LayerManager.renderLayer>;\n\n private closeCallback?: (resp?: unknown) => void;\n\n /**\n * Internal close handler.\n * Restores focus and calls the external onClose callback.\n */\n private onClose = () => {\n this.restoreFocus();\n this.setState({\n open: false,\n });\n this.props.onClose?.();\n this.closeCallback = undefined;\n this.layer = undefined;\n };\n\n private lastFocusedElement: HTMLElement | null = null;\n private modalRef = React.createRef<HTMLDivElement>();\n\n /**\n * Retrieves all focusable elements within the modal.\n */\n private getFocusableElements = (): HTMLElement[] => {\n if (!this.modalRef.current) return [];\n return Array.from(\n this.modalRef.current.querySelectorAll(\n 'button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])',\n ),\n ) as HTMLElement[];\n };\n\n /**\n * Handles keydown events to implement the focus trap.\n * Traps Tab and Shift+Tab within the modal.\n */\n private handleKeyDown = (e: React.KeyboardEvent) => {\n if (e.key === 'Tab') {\n const focusableElements = this.getFocusableElements();\n if (focusableElements.length === 0) return;\n\n const firstElement = focusableElements[0];\n const lastElement = focusableElements[focusableElements.length - 1];\n\n if (e.shiftKey) {\n if (document.activeElement === firstElement) {\n lastElement.focus();\n e.preventDefault();\n }\n } else {\n if (document.activeElement === lastElement) {\n firstElement.focus();\n e.preventDefault();\n }\n }\n }\n };\n\n /**\n * Lifecycle method to save the currently focused element when the modal mounts while open.\n */\n componentDidMount() {\n if (this.props.open) {\n this.lastFocusedElement = document.activeElement as HTMLElement;\n // Handle initial open state\n this.handleOpen();\n }\n }\n\n /**\n * Handles opening the modal by creating the layer.\n */\n private handleOpen = () => {\n const { closeOnEsc, closeOnOverlayClick, children, ...rest } = this.props;\n\n this.layer = LayerManager.renderLayer({\n overlay: true,\n exitDelay: 300,\n position: LAYER_POSITION.DIALOG,\n closeCallback: this.onClose,\n closeOnEsc: closeOnEsc,\n closeOnOverlayClick: closeOnOverlayClick,\n component: (\n <ModalContainer\n {...rest}\n ref={this.setModalRef}\n role=\"dialog\"\n aria-modal=\"true\"\n tabIndex={-1}\n onKeyDown={this.handleKeyDown}\n onClick={(e) => e.stopPropagation()}\n elevated\n >\n {children}\n </ModalContainer>\n ),\n });\n this.closeCallback = this.layer[1];\n this.forceUpdate();\n };\n\n /**\n * Lifecycle method to restore focus when the modal unmounts.\n */\n componentWillUnmount() {\n if (this.props.open) {\n this.restoreFocus();\n }\n // Clean up layer references\n if (this.closeCallback) {\n this.closeCallback();\n this.closeCallback = undefined;\n }\n this.layer = undefined;\n }\n\n /**\n * Restores focus to the element that was focused before the modal opened.\n */\n private restoreFocus = () => {\n if (this.lastFocusedElement) {\n // Check if the element is still in the document\n const elementToBeFocused = this.lastFocusedElement;\n this.lastFocusedElement = null;\n setTimeout(() => {\n if (document.body.contains(elementToBeFocused)) {\n elementToBeFocused.focus();\n }\n }, 100);\n }\n };\n\n /**\n * Callback ref to capture the Modal DOM element.\n * Triggers initial focus setting when the element mounts.\n */\n private setModalRef = (node: HTMLDivElement | null) => {\n // Update ref\n (this.modalRef as React.MutableRefObject<HTMLDivElement | null>).current = node;\n\n if (node) {\n // Set initial focus when the node is mounted\n this.setInitialFocus(node);\n }\n\n if (this.props.forwardRef) {\n (this.props.forwardRef as React.MutableRefObject<HTMLDivElement | null>).current = node;\n }\n };\n\n /**\n * Sets initial focus within the modal.\n * Tries to focus the header (first child) first, then the first interactive element, or falls back to the container.\n */\n private setInitialFocus = (root: HTMLElement) => {\n // Try to find the header (assumed to be the first child)\n const firstChild = root.firstElementChild as HTMLElement;\n if (firstChild) {\n // Ensure it's focusable\n if (firstChild.getAttribute('tabindex') === null) {\n firstChild.setAttribute('tabindex', '-1');\n }\n firstChild.focus();\n return;\n }\n\n // Fallback to focusable elements\n const focusableElements = this.getFocusableElements();\n if (focusableElements.length > 0) {\n focusableElements[0].focus();\n } else {\n // Fallback to container\n root.focus();\n }\n };\n\n /**\n * Lifecycle method to handle Modal updates.\n * Manages opening/closing logic via LayerManager and focus preservation.\n */\n getSnapshotBeforeUpdate(prevProps: ModalProps) {\n const { open } = this.props;\n\n if (prevProps.open && !open) {\n this.closeCallback?.();\n this.restoreFocus();\n }\n\n if (!prevProps.open && open) {\n // Save current focus\n this.lastFocusedElement = document.activeElement as HTMLElement;\n this.handleOpen();\n }\n\n return null;\n }\n\n /**\n * Renders the Modal component via the LayerManager portal.\n */\n render() {\n if (this.state.open && this.layer) {\n const [Component] = this.layer;\n return <Component />;\n }\n\n return null;\n }\n}\n"],"names":["Modal","React","Component","getDerivedStateFromProps","props","open","componentDidMount","lastFocusedElement","document","activeElement","handleOpen","componentWillUnmount","restoreFocus","closeCallback","undefined","layer","getSnapshotBeforeUpdate","prevProps","render","state","_jsx","onClose","setState","modalRef","createRef","getFocusableElements","current","Array","from","querySelectorAll","handleKeyDown","e","key","focusableElements","length","firstElement","lastElement","shiftKey","focus","preventDefault","closeOnEsc","closeOnOverlayClick","children","rest","LayerManager","renderLayer","overlay","exitDelay","position","LAYER_POSITION","DIALOG","component","ModalContainer","ref","setModalRef","role","aria-modal","tabIndex","onKeyDown","onClick","stopPropagation","elevated","forceUpdate","elementToBeFocused","setTimeout","body","contains","node","setInitialFocus","forwardRef","root","firstChild","firstElementChild","getAttribute","setAttribute","defaultProps"],"mappings":";;;;;AAsCe,MAAMA,KAAAA,SAAcC,MAAMC,SAAS,CAAA;AAa9C;;QAGA,OAAOC,wBAAAA,CAAyBC,KAAiB,EAAE;QAC/C,IAAIA,KAAAA,CAAMC,IAAI,EAAE;YACZ,OAAO;gBACHA,IAAAA,EAAM;AACV,aAAA;AACJ,QAAA;QACA,OAAO,IAAA;AACX,IAAA;AA6DA;;AAEC,QACDC,iBAAAA,GAAoB;AAChB,QAAA,IAAI,IAAI,CAACF,KAAK,CAACC,IAAI,EAAE;AACjB,YAAA,IAAI,CAACE,kBAAkB,GAAGC,QAAAA,CAASC,aAAa;;AAEhD,YAAA,IAAI,CAACC,UAAU,EAAA;AACnB,QAAA;AACJ,IAAA;AAkCA;;AAEC,QACDC,oBAAAA,GAAuB;AACnB,QAAA,IAAI,IAAI,CAACP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mBAAAA,EAAqB;AACzB,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"Modal.js","sources":["../../../src/components/Modal/Modal.tsx"],"sourcesContent":["import React from 'react';\nimport LayerManager, { LAYER_POSITION } from '../../shared/LayerManager';\nexport {\n Header as ModalHeader,\n Body as ModalBody,\n Footer as ModalFooter,\n} from '../../shared/styles';\nimport { DialogContainer as ModalContainer } from '../Dialog/Dialog';\n\ntype ModalProps = {\n /** Opens the modal */\n open: boolean;\n /** Closes the modal on esc */\n closeOnEsc?: boolean;\n /** Closes the modal on overlay click */\n closeOnOverlayClick?: boolean;\n /** Call back function called when the modal closes. */\n onClose?: () => void;\n /** Ref forwarded to the underlying HTMLDivElement of the modal container */\n forwardRef?: React.Ref<HTMLDivElement>;\n} & React.HTMLAttributes<HTMLDivElement>;\n\ninterface ModalState {\n open: boolean;\n}\n\n/**\n * Modal component\n *\n * A dialog window that sits on top of the main application content.\n * It disrupts the user's workflow to demand attention for a critical task or decision.\n *\n * Accessibility:\n * - Implements ARIA `role=\"dialog\"` and `aria-modal=\"true\"`.\n * - Traps focus effectively within the modal while open.\n * - Restores focus to the triggering element upon closure.\n * - Supports closing via ESC key and overlay click.\n */\nexport default class Modal extends React.Component<\n React.PropsWithChildren<ModalProps>,\n ModalState\n> {\n state = {\n open: false,\n };\n\n static defaultProps = {\n closeOnEsc: true,\n closeOnOverlayClick: true,\n };\n\n /**\n * Syncs state with props.\n */\n static getDerivedStateFromProps(props: ModalProps) {\n if (props.open) {\n return {\n open: true,\n };\n }\n return null;\n }\n\n private layer?: ReturnType<typeof LayerManager.renderLayer>;\n\n private closeCallback?: (resp?: unknown) => void;\n\n /**\n * Internal close handler.\n * Restores focus and calls the external onClose callback.\n */\n private onClose = () => {\n this.restoreFocus();\n this.setState({\n open: false,\n });\n this.props.onClose?.();\n this.closeCallback = undefined;\n this.layer = undefined;\n };\n\n private lastFocusedElement: HTMLElement | null = null;\n private modalRef = React.createRef<HTMLDivElement>();\n\n /**\n * Retrieves all focusable elements within the modal.\n */\n private getFocusableElements = (): HTMLElement[] => {\n if (!this.modalRef.current) return [];\n return Array.from(\n this.modalRef.current.querySelectorAll(\n 'button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])',\n ),\n ) as HTMLElement[];\n };\n\n /**\n * Handles keydown events to implement the focus trap.\n * Traps Tab and Shift+Tab within the modal.\n */\n private handleKeyDown = (e: React.KeyboardEvent) => {\n if (e.key === 'Tab') {\n const focusableElements = this.getFocusableElements();\n if (focusableElements.length === 0) return;\n\n const firstElement = focusableElements[0];\n const lastElement = focusableElements[focusableElements.length - 1];\n\n if (e.shiftKey) {\n if (document.activeElement === firstElement) {\n lastElement.focus();\n e.preventDefault();\n }\n } else {\n if (document.activeElement === lastElement) {\n firstElement.focus();\n e.preventDefault();\n }\n }\n }\n };\n\n /**\n * Lifecycle method to save the currently focused element when the modal mounts while open.\n */\n componentDidMount() {\n if (this.props.open) {\n this.lastFocusedElement = document.activeElement as HTMLElement;\n // Handle initial open state\n this.handleOpen();\n }\n }\n\n /**\n * Handles opening the modal by creating the layer.\n */\n private handleOpen = () => {\n const { closeOnEsc, closeOnOverlayClick, children, ...rest } = this.props;\n\n this.layer = LayerManager.renderLayer({\n overlay: true,\n exitDelay: 300,\n position: LAYER_POSITION.DIALOG,\n closeCallback: this.onClose,\n closeOnEsc: closeOnEsc,\n closeOnOverlayClick: closeOnOverlayClick,\n component: (\n <ModalContainer\n {...rest}\n ref={this.setModalRef}\n role=\"dialog\"\n aria-modal=\"true\"\n tabIndex={-1}\n onKeyDown={this.handleKeyDown}\n onClick={(e) => e.stopPropagation()}\n elevated\n >\n {children}\n </ModalContainer>\n ),\n });\n this.closeCallback = this.layer[1];\n this.forceUpdate();\n };\n\n /**\n * Lifecycle method to restore focus when the modal unmounts.\n */\n componentWillUnmount() {\n if (this.props.open) {\n this.restoreFocus();\n }\n // Clean up layer references\n if (this.closeCallback) {\n this.closeCallback();\n this.closeCallback = undefined;\n }\n this.layer = undefined;\n }\n\n /**\n * Restores focus to the element that was focused before the modal opened.\n */\n private restoreFocus = () => {\n if (this.lastFocusedElement) {\n // Check if the element is still in the document\n const elementToBeFocused = this.lastFocusedElement;\n this.lastFocusedElement = null;\n setTimeout(() => {\n if (document.body.contains(elementToBeFocused)) {\n elementToBeFocused.focus();\n }\n }, 100);\n }\n };\n\n /**\n * Callback ref to capture the Modal DOM element.\n * Triggers initial focus setting when the element mounts.\n */\n private setModalRef = (node: HTMLDivElement | null) => {\n // Update ref\n (this.modalRef as React.MutableRefObject<HTMLDivElement | null>).current = node;\n\n if (node) {\n // Set initial focus when the node is mounted\n this.setInitialFocus(node);\n }\n\n if (this.props.forwardRef) {\n (this.props.forwardRef as React.MutableRefObject<HTMLDivElement | null>).current = node;\n }\n };\n\n /**\n * Sets initial focus within the modal.\n * Tries to focus the header (first child) first, then the first interactive element, or falls back to the container.\n */\n private setInitialFocus = (root: HTMLElement) => {\n // Try to find the header (assumed to be the first child)\n const firstChild = root.firstElementChild as HTMLElement;\n if (firstChild) {\n // Ensure it's focusable\n if (firstChild.getAttribute('tabindex') === null) {\n firstChild.setAttribute('tabindex', '-1');\n }\n firstChild.focus();\n return;\n }\n\n // Fallback to focusable elements\n const focusableElements = this.getFocusableElements();\n if (focusableElements.length > 0) {\n focusableElements[0].focus();\n } else {\n // Fallback to container\n root.focus();\n }\n };\n\n /**\n * Lifecycle method to handle Modal updates.\n * Manages opening/closing logic via LayerManager and focus preservation.\n */\n componentDidUpdate(prevProps: ModalProps) {\n const { open } = this.props;\n\n if (prevProps.open && !open) {\n this.closeCallback?.();\n this.restoreFocus();\n }\n\n if (!prevProps.open && open) {\n // Save current focus\n this.lastFocusedElement = document.activeElement as HTMLElement;\n this.handleOpen();\n }\n }\n\n /**\n * Renders the Modal component via the LayerManager portal.\n */\n render() {\n if (this.state.open && this.layer) {\n const [Component] = this.layer;\n return <Component />;\n }\n\n return null;\n }\n}\n"],"names":["Modal","React","Component","getDerivedStateFromProps","props","open","componentDidMount","lastFocusedElement","document","activeElement","handleOpen","componentWillUnmount","restoreFocus","closeCallback","undefined","layer","componentDidUpdate","prevProps","render","state","_jsx","onClose","setState","modalRef","createRef","getFocusableElements","current","Array","from","querySelectorAll","handleKeyDown","e","key","focusableElements","length","firstElement","lastElement","shiftKey","focus","preventDefault","closeOnEsc","closeOnOverlayClick","children","rest","LayerManager","renderLayer","overlay","exitDelay","position","LAYER_POSITION","DIALOG","component","ModalContainer","ref","setModalRef","role","aria-modal","tabIndex","onKeyDown","onClick","stopPropagation","elevated","forceUpdate","elementToBeFocused","setTimeout","body","contains","node","setInitialFocus","forwardRef","root","firstChild","firstElementChild","getAttribute","setAttribute","defaultProps"],"mappings":";;;;;AAsCe,MAAMA,KAAAA,SAAcC,MAAMC,SAAS,CAAA;AAa9C;;QAGA,OAAOC,wBAAAA,CAAyBC,KAAiB,EAAE;QAC/C,IAAIA,KAAAA,CAAMC,IAAI,EAAE;YACZ,OAAO;gBACHA,IAAAA,EAAM;AACV,aAAA;AACJ,QAAA;QACA,OAAO,IAAA;AACX,IAAA;AA6DA;;AAEC,QACDC,iBAAAA,GAAoB;AAChB,QAAA,IAAI,IAAI,CAACF,KAAK,CAACC,IAAI,EAAE;AACjB,YAAA,IAAI,CAACE,kBAAkB,GAAGC,QAAAA,CAASC,aAAa;;AAEhD,YAAA,IAAI,CAACC,UAAU,EAAA;AACnB,QAAA;AACJ,IAAA;AAkCA;;AAEC,QACDC,oBAAAA,GAAuB;AACnB,QAAA,IAAI,IAAI,CAACP,KAAK,CAACC,IAAI,EAAE;AACjB,YAAA,IAAI,CAACO,YAAY,EAAA;AACrB,QAAA;;QAEA,IAAI,IAAI,CAACC,aAAa,EAAE;AACpB,YAAA,IAAI,CAACA,aAAa,EAAA;YAClB,IAAI,CAACA,aAAa,GAAGC,SAAAA;AACzB,QAAA;QACA,IAAI,CAACC,KAAK,GAAGD,SAAAA;AACjB,IAAA;AA8DA;;;QAIAE,kBAAAA,CAAmBC,SAAqB,EAAE;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,EAAM;;gBAEN,IAAI,CAACC,eAAe,CAACD,IAAAA,CAAAA;AACzB,YAAA;AAEA,YAAA,IAAI,IAAI,CAAC/D,KAAK,CAACiE,UAAU,EAAE;AACtB,gBAAA,IAAI,CAACjE,KAAK,CAACiE,UAAU,CAAmD3C,OAAO,GAAGyC,IAAAA;AACvF,YAAA;QACJ,CAAA;;;AAKC,QAAA,IAAA,CACOC,kBAAkB,CAACE,IAAAA,GAAAA;;YAEvB,MAAMC,UAAAA,GAAaD,KAAKE,iBAAiB;AACzC,YAAA,IAAID,UAAAA,EAAY;;AAEZ,gBAAA,IAAIA,UAAAA,CAAWE,YAAY,CAAC,UAAA,CAAA,KAAgB,IAAA,EAAM;oBAC9CF,UAAAA,CAAWG,YAAY,CAAC,UAAA,EAAY,IAAA,CAAA;AACxC,gBAAA;AACAH,gBAAAA,UAAAA,CAAWjC,KAAK,EAAA;AAChB,gBAAA;AACJ,YAAA;;YAGA,MAAML,iBAAAA,GAAoB,IAAI,CAACR,oBAAoB,EAAA;YACnD,IAAIQ,iBAAAA,CAAkBC,MAAM,GAAG,CAAA,EAAG;gBAC9BD,iBAAiB,CAAC,CAAA,CAAE,CAACK,KAAK,EAAA;YAC9B,CAAA,MAAO;;AAEHgC,gBAAAA,IAAAA,CAAKhC,KAAK,EAAA;AACd,YAAA;AACJ,QAAA,CAAA;;AAgCJ;AAxOqBtC,KAAAA,CAQV2E,YAAAA,GAAe;IAClBnC,UAAAA,EAAY,IAAA;IACZC,mBAAAA,EAAqB;AACzB,CAAA;;;;"}
|
|
@@ -9,7 +9,7 @@ type PopoverProps = {
|
|
|
9
9
|
/** Opens the popover */
|
|
10
10
|
open: boolean;
|
|
11
11
|
/** Anchor element for the popover */
|
|
12
|
-
element: React.
|
|
12
|
+
element: React.ReactElement;
|
|
13
13
|
/**
|
|
14
14
|
* Position of the popover around anchor element
|
|
15
15
|
* @default POPOVER_POSITION.BOTTOM_LEFT
|
|
@@ -29,11 +29,11 @@ const positionMap$2 = {
|
|
|
29
29
|
`
|
|
30
30
|
};
|
|
31
31
|
const PopoverDiv = /*#__PURE__*/ styled("div", {
|
|
32
|
-
target: "
|
|
32
|
+
target: "e13swao70",
|
|
33
33
|
label: "PopoverDiv"
|
|
34
34
|
})("position:relative;display:inline-flex;");
|
|
35
35
|
const Popper = /*#__PURE__*/ styled(Card, {
|
|
36
|
-
target: "
|
|
36
|
+
target: "e13swao71",
|
|
37
37
|
label: "Popper"
|
|
38
38
|
})("position:absolute;width:100%;min-width:200px;overflow:auto;animation:enter 0.3s linear;border-radius:3px;z-index:1;transform:translate(", (props)=>props.translateX, "px,", (props)=>props.translateY, "px);", (props)=>positionMap$2[props.position], " &.closing{animation:exit 0.3s linear;}@keyframes enter{from{max-height:0px;opacity:1;overflow:hidden;}to{max-height:300px;opacity:1;overflow:hidden;}}@keyframes exit{to{max-height:0px;opacity:1;overflow:hidden;}from{max-height:300px;opacity:1;overflow:hidden;}}");
|
|
39
39
|
const KEY_CODES = {
|
|
@@ -212,7 +212,7 @@ const KEY_CODES = {
|
|
|
212
212
|
ref: forwardRef,
|
|
213
213
|
...rest,
|
|
214
214
|
children: [
|
|
215
|
-
/*#__PURE__*/ React.
|
|
215
|
+
/*#__PURE__*/ React.cloneElement(element, {
|
|
216
216
|
ref: triggerRef,
|
|
217
217
|
id: triggerId,
|
|
218
218
|
'aria-expanded': open,
|