@elliemae/ds-form-toggle 3.1.5-rc.9 → 3.2.0-rc.1
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/cjs/ControlledToggle.js +40 -36
- package/dist/cjs/ControlledToggle.js.map +2 -2
- package/dist/cjs/propTypes.js +19 -2
- package/dist/cjs/propTypes.js.map +2 -2
- package/dist/cjs/styles.js +18 -17
- package/dist/cjs/styles.js.map +2 -2
- package/dist/cjs/utils/addTooltipOnReadOnly.js +3 -5
- package/dist/cjs/utils/addTooltipOnReadOnly.js.map +2 -2
- package/dist/esm/ControlledToggle.js +48 -38
- package/dist/esm/ControlledToggle.js.map +2 -2
- package/dist/esm/propTypes.js +22 -3
- package/dist/esm/propTypes.js.map +2 -2
- package/dist/esm/styles.js +19 -18
- package/dist/esm/styles.js.map +2 -2
- package/dist/esm/utils/addTooltipOnReadOnly.js +4 -6
- package/dist/esm/utils/addTooltipOnReadOnly.js.map +2 -2
- package/package.json +10 -10
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
7
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
8
|
var __getProtoOf = Object.getPrototypeOf;
|
|
@@ -18,6 +20,19 @@ var __spreadValues = (a, b) => {
|
|
|
18
20
|
}
|
|
19
21
|
return a;
|
|
20
22
|
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __objRest = (source, exclude) => {
|
|
25
|
+
var target = {};
|
|
26
|
+
for (var prop in source)
|
|
27
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
if (source != null && __getOwnPropSymbols)
|
|
30
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
31
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
32
|
+
target[prop] = source[prop];
|
|
33
|
+
}
|
|
34
|
+
return target;
|
|
35
|
+
};
|
|
21
36
|
var __export = (target, all) => {
|
|
22
37
|
for (var name in all)
|
|
23
38
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -45,25 +60,16 @@ var import_ds_utilities = require("@elliemae/ds-utilities");
|
|
|
45
60
|
var import_propTypes = require("./propTypes");
|
|
46
61
|
var import_styles = require("./styles");
|
|
47
62
|
var import_addTooltipOnReadOnly = require("./utils/addTooltipOnReadOnly");
|
|
48
|
-
const DSControlledToggle = ({
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
value,
|
|
53
|
-
checked,
|
|
54
|
-
onChange,
|
|
55
|
-
size,
|
|
56
|
-
readOnly,
|
|
57
|
-
disabled,
|
|
58
|
-
containerProps,
|
|
59
|
-
id
|
|
60
|
-
}) => {
|
|
63
|
+
const DSControlledToggle = (props) => {
|
|
64
|
+
const propsWithDefaults = (0, import_ds_utilities.useMemoMergePropsWithDefault)(props, import_propTypes.defaultProps);
|
|
65
|
+
(0, import_ds_utilities.useValidateTypescriptPropTypes)(propsWithDefaults, import_propTypes.propTypes);
|
|
66
|
+
const _a = propsWithDefaults, { labelOn, labelOff, value, checked, onChange, size, readOnly, active, disabled, containerProps, id } = _a, rest = __objRest(_a, ["labelOn", "labelOff", "value", "checked", "onChange", "size", "readOnly", "active", "disabled", "containerProps", "id"]);
|
|
61
67
|
const [isLongerTextRendering, setIsLongerTextRendering] = (0, import_react.useState)(false);
|
|
62
68
|
const [width, setWidth] = (0, import_react.useState)(0);
|
|
63
69
|
const labelTextRef = (0, import_react.useRef)(null);
|
|
64
70
|
const widthTextRef = (0, import_react.useRef)(null);
|
|
65
71
|
const longerText = (0, import_react.useMemo)(() => labelOn.length > labelOff.length ? labelOn : labelOff, [labelOff, labelOn]);
|
|
66
|
-
const instanceUID = (0, import_react.useMemo)(() => (0, import_uid.uid)(5), []);
|
|
72
|
+
const instanceUID = (0, import_react.useMemo)(() => id || (0, import_uid.uid)(5), [id]);
|
|
67
73
|
(0, import_react.useEffect)(() => {
|
|
68
74
|
if (labelTextRef.current) {
|
|
69
75
|
setIsLongerTextRendering(labelTextRef.current.innerText === longerText);
|
|
@@ -77,33 +83,30 @@ const DSControlledToggle = ({
|
|
|
77
83
|
const handleOnChange = (0, import_react.useCallback)(() => {
|
|
78
84
|
if (disabled || readOnly)
|
|
79
85
|
return;
|
|
80
|
-
onChange
|
|
81
|
-
}, [disabled, readOnly, onChange]);
|
|
82
|
-
const handleKeyDown = (0, import_react.useCallback)((e) => {
|
|
83
|
-
if (disabled || readOnly) {
|
|
84
|
-
e.preventDefault();
|
|
85
|
-
}
|
|
86
|
-
if (e.key === "Enter") {
|
|
87
|
-
e.preventDefault();
|
|
86
|
+
if (onChange)
|
|
88
87
|
onChange();
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
}, [disabled, readOnly, onChange]);
|
|
89
|
+
const globalAttrs = (0, import_ds_utilities.useGetGlobalAttributes)(rest, { onClick: handleOnChange });
|
|
90
|
+
const xStyledProps = (0, import_ds_utilities.useGetXstyledProps)(rest);
|
|
91
|
+
return /* @__PURE__ */ import_react.default.createElement(import_styles.StyledContainer, __spreadProps(__spreadValues(__spreadValues({
|
|
92
92
|
size,
|
|
93
93
|
"data-testid": "ds-controlled-toggle"
|
|
94
|
-
}, containerProps),
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
}, containerProps), xStyledProps), {
|
|
95
|
+
disabled
|
|
96
|
+
}), (0, import_addTooltipOnReadOnly.addTooltipOnReadOnly)(/* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(import_styles.StyledButton, __spreadValues({
|
|
97
|
+
role: "switch",
|
|
97
98
|
value,
|
|
98
|
-
|
|
99
|
+
type: "button",
|
|
99
100
|
"data-testid": "ds-controlled-toggle-checkbox",
|
|
100
|
-
id:
|
|
101
|
+
id: instanceUID,
|
|
102
|
+
"aria-readonly": readOnly,
|
|
101
103
|
"aria-disabled": disabled,
|
|
102
104
|
"aria-checked": checked,
|
|
103
|
-
tabIndex: 0,
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
tabIndex: disabled ? -1 : 0,
|
|
106
|
+
onClick: handleOnChange,
|
|
107
|
+
readOnly,
|
|
108
|
+
disabled
|
|
109
|
+
}, globalAttrs)), /* @__PURE__ */ import_react.default.createElement(import_styles.StyledLabel, {
|
|
107
110
|
checked,
|
|
108
111
|
size,
|
|
109
112
|
width
|
|
@@ -111,6 +114,7 @@ const DSControlledToggle = ({
|
|
|
111
114
|
checked,
|
|
112
115
|
size,
|
|
113
116
|
readOnly,
|
|
117
|
+
active,
|
|
114
118
|
disabled,
|
|
115
119
|
htmlFor: id ? void 0 : instanceUID,
|
|
116
120
|
as: id ? "p" : "label"
|
|
@@ -120,6 +124,7 @@ const DSControlledToggle = ({
|
|
|
120
124
|
readOnly,
|
|
121
125
|
disabled
|
|
122
126
|
}), /* @__PURE__ */ import_react.default.createElement(import_styles.StyledText, {
|
|
127
|
+
"aria-hidden": "true",
|
|
123
128
|
ref: labelTextRef,
|
|
124
129
|
isLongerTextRendering,
|
|
125
130
|
checked,
|
|
@@ -128,9 +133,8 @@ const DSControlledToggle = ({
|
|
|
128
133
|
}, checked ? labelOn : labelOff))), /* @__PURE__ */ import_react.default.createElement(import_styles.SetLabelWidth, {
|
|
129
134
|
size,
|
|
130
135
|
ref: widthTextRef
|
|
131
|
-
}, longerText)), readOnly);
|
|
136
|
+
}, longerText)), readOnly));
|
|
132
137
|
};
|
|
133
|
-
DSControlledToggle.defaultProps = import_propTypes.defaultProps;
|
|
134
138
|
DSControlledToggle.propTypes = import_propTypes.propTypes;
|
|
135
139
|
DSControlledToggle.displayName = "DSControlledToggle";
|
|
136
140
|
const DSControlledToggleWithSchema = (0, import_ds_utilities.describe)(DSControlledToggle);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/ControlledToggle.tsx", "../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["import React, { useState, useMemo, useRef, useEffect, useCallback } from 'react';\nimport { uid } from 'uid';\nimport {
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import React, { useState, useMemo, useRef, useEffect, useCallback } from 'react';\nimport { uid } from 'uid';\nimport {\n describe,\n useMemoMergePropsWithDefault,\n useGetGlobalAttributes,\n useValidateTypescriptPropTypes,\n useGetXstyledProps,\n} from '@elliemae/ds-utilities';\nimport { propTypes, defaultProps, type DSControlledToggleT } from './propTypes';\nimport {\n StyledContainer,\n StyledButton,\n StyledLabel,\n StyledVisibleContent,\n StyledCircle,\n StyledText,\n SetLabelWidth,\n} from './styles';\nimport { addTooltipOnReadOnly } from './utils/addTooltipOnReadOnly';\n\nconst DSControlledToggle = (props: DSControlledToggleT.Props): JSX.Element => {\n const propsWithDefaults = useMemoMergePropsWithDefault(props, defaultProps);\n useValidateTypescriptPropTypes(propsWithDefaults, propTypes);\n const { labelOn, labelOff, value, checked, onChange, size, readOnly, active, disabled, containerProps, id, ...rest } =\n propsWithDefaults;\n\n const [isLongerTextRendering, setIsLongerTextRendering] = useState<boolean>(false);\n const [width, setWidth] = useState<number>(0);\n const labelTextRef = useRef<HTMLDivElement | null>(null);\n const widthTextRef = useRef<HTMLDivElement | null>(null);\n\n const longerText = useMemo(() => (labelOn.length > labelOff.length ? labelOn : labelOff), [labelOff, labelOn]);\n\n const instanceUID = useMemo(() => id || uid(5), [id]);\n\n useEffect(() => {\n if (labelTextRef.current) {\n setIsLongerTextRendering(labelTextRef.current.innerText === longerText);\n }\n }, [labelTextRef, longerText, checked]);\n\n useEffect(() => {\n if (widthTextRef.current) {\n setWidth(widthTextRef.current.clientWidth);\n }\n }, [widthTextRef]);\n\n const handleOnChange = useCallback(() => {\n if (disabled || readOnly) return;\n if (onChange) onChange();\n }, [disabled, readOnly, onChange]);\n\n const globalAttrs = useGetGlobalAttributes(rest, { onClick: handleOnChange });\n const xStyledProps = useGetXstyledProps(rest);\n\n return (\n <StyledContainer\n size={size}\n data-testid=\"ds-controlled-toggle\"\n {...containerProps}\n {...xStyledProps}\n disabled={disabled}\n >\n {addTooltipOnReadOnly(\n <>\n <StyledButton\n role=\"switch\"\n value={value}\n type=\"button\"\n data-testid=\"ds-controlled-toggle-checkbox\"\n id={instanceUID}\n aria-readonly={readOnly}\n aria-disabled={disabled}\n aria-checked={checked}\n tabIndex={disabled ? -1 : 0}\n onClick={handleOnChange}\n readOnly={readOnly}\n disabled={disabled}\n {...globalAttrs}\n />\n <StyledLabel checked={checked} size={size} width={width}>\n <StyledVisibleContent\n checked={checked}\n size={size}\n readOnly={readOnly}\n active={active}\n disabled={disabled}\n htmlFor={id ? undefined : instanceUID}\n as={id ? 'p' : 'label'}\n >\n <StyledCircle checked={checked} size={size} readOnly={readOnly} disabled={disabled} />\n <StyledText\n aria-hidden=\"true\"\n ref={labelTextRef}\n isLongerTextRendering={isLongerTextRendering}\n checked={checked}\n size={size}\n disabled={disabled}\n >\n {checked ? labelOn : labelOff}\n </StyledText>\n </StyledVisibleContent>\n </StyledLabel>\n <SetLabelWidth size={size} ref={widthTextRef}>\n {longerText}\n </SetLabelWidth>\n </>,\n readOnly,\n )}\n </StyledContainer>\n );\n};\n\nDSControlledToggle.propTypes = propTypes;\nDSControlledToggle.displayName = 'DSControlledToggle';\nconst DSControlledToggleWithSchema = describe(DSControlledToggle);\nDSControlledToggleWithSchema.propTypes = propTypes;\n\nexport { DSControlledToggle, DSControlledToggleWithSchema };\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"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cAAc,gDAAuB,MAAM,EAAE,SAAS,eAAe,CAAC;AAC5E,QAAM,eAAe,4CAAmB,IAAI;AAE5C,SACE,mDAAC;AAAA,IACC;AAAA,IACA,eAAY;AAAA,KACR,iBACA,eAJL;AAAA,IAKC;AAAA,MAEC,sDACC,wFACE,mDAAC;AAAA,IACC,MAAK;AAAA,IACL;AAAA,IACA,MAAK;AAAA,IACL,eAAY;AAAA,IACZ,IAAI;AAAA,IACJ,iBAAe;AAAA,IACf,iBAAe;AAAA,IACf,gBAAc;AAAA,IACd,UAAU,WAAW,KAAK;AAAA,IAC1B,SAAS;AAAA,IACT;AAAA,IACA;AAAA,KACI,YACN,GACA,mDAAC;AAAA,IAAY;AAAA,IAAkB;AAAA,IAAY;AAAA,KACzC,mDAAC;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS,KAAK,SAAY;AAAA,IAC1B,IAAI,KAAK,MAAM;AAAA,KAEf,mDAAC;AAAA,IAAa;AAAA,IAAkB;AAAA,IAAY;AAAA,IAAoB;AAAA,GAAoB,GACpF,mDAAC;AAAA,IACC,eAAY;AAAA,IACZ,KAAK;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,KAEC,UAAU,UAAU,QACvB,CACF,CACF,GACA,mDAAC;AAAA,IAAc;AAAA,IAAY,KAAK;AAAA,KAC7B,UACH,CACF,GACA,QACF,CACF;AAEJ;AAEA,mBAAmB,YAAY;AAC/B,mBAAmB,cAAc;AACjC,MAAM,+BAA+B,kCAAS,kBAAkB;AAChE,6BAA6B,YAAY;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/propTypes.js
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
8
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
7
24
|
var __export = (target, all) => {
|
|
8
25
|
for (var name in all)
|
|
9
26
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -37,7 +54,7 @@ const defaultProps = {
|
|
|
37
54
|
readonly: false,
|
|
38
55
|
disabled: false
|
|
39
56
|
};
|
|
40
|
-
const propTypes = {
|
|
57
|
+
const propTypes = __spreadProps(__spreadValues(__spreadValues({}, import_ds_utilities.globalAttributesPropTypes), import_ds_utilities.xstyledPropTypes), {
|
|
41
58
|
labelOn: import_ds_utilities.PropTypes.string.description("Label when toggle is checked"),
|
|
42
59
|
labelOff: import_ds_utilities.PropTypes.string.description("Label when toggle is unchecked"),
|
|
43
60
|
value: import_ds_utilities.PropTypes.string.description("Value attribute for toggle"),
|
|
@@ -50,5 +67,5 @@ const propTypes = {
|
|
|
50
67
|
disabled: import_ds_utilities.PropTypes.bool.description("Wether the toggle is disabled or not"),
|
|
51
68
|
containerProps: import_ds_utilities.PropTypes.shape({}).description("Set of properties attached to the main container"),
|
|
52
69
|
id: import_ds_utilities.PropTypes.string.description("Unique id.")
|
|
53
|
-
};
|
|
70
|
+
});
|
|
54
71
|
//# sourceMappingURL=propTypes.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/propTypes.tsx", "../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["import { PropTypes } from '@elliemae/ds-utilities';\n\nexport declare namespace DSControlledToggleT {\n export type ToggleSize = 's' | 'm' | 'l';\n export interface Props {\n labelOn: string;\n labelOff: string;\n name: string;\n value: string;\n checked: boolean;\n onChange: () => void | null;\n size: ToggleSize;\n readOnly: boolean;\n disabled: boolean;\n containerProps: Record<string, unknown>;\n id: string;\n }\n}\nexport const defaultProps = {\n labelOn: 'ON',\n labelOff: 'OFF',\n name: '',\n value: '',\n checked: false,\n onClick: () => null,\n size: 'm',\n readonly: false,\n disabled: false,\n};\n\nexport const propTypes = {\n labelOn: PropTypes.string.description('Label when toggle is checked'),\n labelOff: PropTypes.string.description('Label when toggle is unchecked'),\n value: PropTypes.string.description('Value attribute for toggle'),\n name: PropTypes.string.description('Name attribute for toggle'),\n checked: PropTypes.bool.description('Wether the toggle is checked or not'),\n onchange: PropTypes.func.description('OnClick callback'),\n size: PropTypes.oneOf(['s', 'm', 'l']).description('Size of toggle'),\n readOnly: PropTypes.bool.description('Wether the toggle is readOnly or not'),\n active: PropTypes.bool.description('Wether the toggle has active styles or not').deprecated({ version: '3.x' }),\n disabled: PropTypes.bool.description('Wether the toggle is disabled or not'),\n containerProps: PropTypes.shape({}).description('Set of properties attached to the main container'),\n id: PropTypes.string.description('Unique id.'),\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { globalAttributesPropTypes, xstyledPropTypes, PropTypes } from '@elliemae/ds-utilities';\n\nexport declare namespace DSControlledToggleT {\n export type ToggleSize = 's' | 'm' | 'l';\n export interface Props {\n labelOn: string;\n labelOff: string;\n name: string;\n value: string;\n checked: boolean;\n onChange: () => void | null;\n size: ToggleSize;\n readOnly: boolean;\n disabled: boolean;\n containerProps: Record<string, unknown>;\n id: string;\n }\n}\nexport const defaultProps = {\n labelOn: 'ON',\n labelOff: 'OFF',\n name: '',\n value: '',\n checked: false,\n onClick: () => null,\n size: 'm',\n readonly: false,\n disabled: false,\n};\n\nexport const propTypes = {\n ...globalAttributesPropTypes,\n ...xstyledPropTypes,\n labelOn: PropTypes.string.description('Label when toggle is checked'),\n labelOff: PropTypes.string.description('Label when toggle is unchecked'),\n value: PropTypes.string.description('Value attribute for toggle'),\n name: PropTypes.string.description('Name attribute for toggle'),\n checked: PropTypes.bool.description('Wether the toggle is checked or not'),\n onchange: PropTypes.func.description('OnClick callback'),\n size: PropTypes.oneOf(['s', 'm', 'l']).description('Size of toggle'),\n readOnly: PropTypes.bool.description('Wether the toggle is readOnly or not'),\n active: PropTypes.bool.description('Wether the toggle has active styles or not').deprecated({ version: '3.x' }),\n disabled: PropTypes.bool.description('Wether the toggle is disabled or not'),\n containerProps: PropTypes.shape({}).description('Set of properties attached to the main container'),\n id: PropTypes.string.description('Unique id.'),\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,0BAAuE;AAkBhE,MAAM,eAAe;AAAA,EAC1B,SAAS;AAAA,EACT,UAAU;AAAA,EACV,MAAM;AAAA,EACN,OAAO;AAAA,EACP,SAAS;AAAA,EACT,SAAS,MAAM;AAAA,EACf,MAAM;AAAA,EACN,UAAU;AAAA,EACV,UAAU;AACZ;AAEO,MAAM,YAAY,gDACpB,gDACA,uCAFoB;AAAA,EAGvB,SAAS,8BAAU,OAAO,YAAY,8BAA8B;AAAA,EACpE,UAAU,8BAAU,OAAO,YAAY,gCAAgC;AAAA,EACvE,OAAO,8BAAU,OAAO,YAAY,4BAA4B;AAAA,EAChE,MAAM,8BAAU,OAAO,YAAY,2BAA2B;AAAA,EAC9D,SAAS,8BAAU,KAAK,YAAY,qCAAqC;AAAA,EACzE,UAAU,8BAAU,KAAK,YAAY,kBAAkB;AAAA,EACvD,MAAM,8BAAU,MAAM,CAAC,KAAK,KAAK,GAAG,CAAC,EAAE,YAAY,gBAAgB;AAAA,EACnE,UAAU,8BAAU,KAAK,YAAY,sCAAsC;AAAA,EAC3E,QAAQ,8BAAU,KAAK,YAAY,4CAA4C,EAAE,WAAW,EAAE,SAAS,MAAM,CAAC;AAAA,EAC9G,UAAU,8BAAU,KAAK,YAAY,sCAAsC;AAAA,EAC3E,gBAAgB,8BAAU,MAAM,CAAC,CAAC,EAAE,YAAY,kDAAkD;AAAA,EAClG,IAAI,8BAAU,OAAO,YAAY,YAAY;AAC/C;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/styles.js
CHANGED
|
@@ -21,9 +21,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var styles_exports = {};
|
|
22
22
|
__export(styles_exports, {
|
|
23
23
|
SetLabelWidth: () => SetLabelWidth,
|
|
24
|
+
StyledButton: () => StyledButton,
|
|
24
25
|
StyledCircle: () => StyledCircle,
|
|
25
26
|
StyledContainer: () => StyledContainer,
|
|
26
|
-
StyledInput: () => StyledInput,
|
|
27
27
|
StyledLabel: () => StyledLabel,
|
|
28
28
|
StyledText: () => StyledText,
|
|
29
29
|
StyledVisibleContent: () => StyledVisibleContent
|
|
@@ -32,16 +32,7 @@ module.exports = __toCommonJS(styles_exports);
|
|
|
32
32
|
var React = __toESM(require("react"));
|
|
33
33
|
var import_ds_system = require("@elliemae/ds-system");
|
|
34
34
|
var import_styleHelpers = require("./utils/styleHelpers");
|
|
35
|
-
const
|
|
36
|
-
display: inline-flex;
|
|
37
|
-
width: fit-content;
|
|
38
|
-
justify-content: center;
|
|
39
|
-
align-items: center;
|
|
40
|
-
height: ${({ size }) => import_styleHelpers.containerHeight[size]};
|
|
41
|
-
border-radius: ${({ size }) => import_styleHelpers.borderRadius[size]};
|
|
42
|
-
outline: none;
|
|
43
|
-
position: relative;
|
|
44
|
-
border: 2px solid transparent;
|
|
35
|
+
const focusBorders = import_ds_system.css`
|
|
45
36
|
&:hover,
|
|
46
37
|
&:focus-within {
|
|
47
38
|
border: 2px solid ${({ theme }) => theme.colors.brand[300]};
|
|
@@ -55,6 +46,18 @@ const StyledContainer = import_ds_system.styled.div`
|
|
|
55
46
|
}
|
|
56
47
|
}
|
|
57
48
|
`;
|
|
49
|
+
const StyledContainer = import_ds_system.styled.div`
|
|
50
|
+
display: inline-flex;
|
|
51
|
+
width: fit-content;
|
|
52
|
+
justify-content: center;
|
|
53
|
+
align-items: center;
|
|
54
|
+
height: ${({ size }) => import_styleHelpers.containerHeight[size]};
|
|
55
|
+
border-radius: ${({ size }) => import_styleHelpers.borderRadius[size]};
|
|
56
|
+
outline: none;
|
|
57
|
+
position: relative;
|
|
58
|
+
border: 2px solid transparent;
|
|
59
|
+
${({ disabled }) => !disabled && focusBorders};
|
|
60
|
+
`;
|
|
58
61
|
const StyledLabel = import_ds_system.styled.div`
|
|
59
62
|
width: ${({ width, size }) => `calc(${width}px + ${import_styleHelpers.margin[size]})`};
|
|
60
63
|
height: ${({ size }) => import_styleHelpers.labelHeight[size]};
|
|
@@ -75,10 +78,6 @@ const StyledVisibleContent = import_ds_system.styled.label`
|
|
|
75
78
|
`};
|
|
76
79
|
transition: background-color 0.2s;
|
|
77
80
|
background-color: ${import_styleHelpers.getInterpolatedBgDsToggleColorByProps};
|
|
78
|
-
|
|
79
|
-
&:hover {
|
|
80
|
-
cursor: ${({ disabled, readOnly }) => (0, import_styleHelpers.handleCursors)(disabled, readOnly)};
|
|
81
|
-
}
|
|
82
81
|
`;
|
|
83
82
|
const StyledCircle = import_ds_system.styled.div`
|
|
84
83
|
height: ${({ size }) => import_styleHelpers.circleValues[size]};
|
|
@@ -99,13 +98,15 @@ const StyledText = import_ds_system.styled.div`
|
|
|
99
98
|
${({ isLongerTextRendering, checked }) => isLongerTextRendering && checked ? `margin-left: 6px;` : void 0}
|
|
100
99
|
${({ isLongerTextRendering, checked }) => isLongerTextRendering && !checked ? `margin-left: 4px;` : void 0}
|
|
101
100
|
`;
|
|
102
|
-
const
|
|
101
|
+
const StyledButton = import_ds_system.styled.button`
|
|
103
102
|
position: absolute;
|
|
104
103
|
opacity: 0;
|
|
105
104
|
z-index: 20;
|
|
106
105
|
height: 100%;
|
|
107
106
|
width: 100%;
|
|
108
|
-
|
|
107
|
+
&:hover {
|
|
108
|
+
cursor: ${({ disabled, readOnly }) => (0, import_styleHelpers.handleCursors)(disabled, readOnly)};
|
|
109
|
+
}
|
|
109
110
|
`;
|
|
110
111
|
const SetLabelWidth = import_ds_system.styled.div`
|
|
111
112
|
font-size: ${({ theme, size }) => (0, import_styleHelpers.handleFontSize)(size, theme)};
|
package/dist/cjs/styles.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/styles.tsx", "../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["import { styled } from '@elliemae/ds-system';\nimport type { DSControlledToggleT } from './propTypes';\n\nimport {\n containerHeight,\n borderRadius,\n labelHeight,\n getInterpolatedBorderDsToggleColorByProps,\n getInterpolatedBgDsToggleColorByProps,\n circleValues,\n handleFontSize,\n margin,\n handleCursors,\n} from './utils/styleHelpers';\n\ninterface StyledContainerT {\n size: DSControlledToggleT.ToggleSize;\n}\ninterface StyledLabelT {\n width: number;\n size: DSControlledToggleT.ToggleSize;\n checked: boolean;\n}\ninterface StyledVisibleContentT {\n checked: boolean;\n size: DSControlledToggleT.ToggleSize;\n disabled: boolean;\n readOnly: boolean;\n as: 'p' | 'label';\n htmlFor: string;\n}\ninterface StyledCircleT {\n size: DSControlledToggleT.ToggleSize;\n readOnly: boolean;\n checked: boolean;\n disabled: boolean;\n}\ninterface StyledTextT {\n isLongerTextRendering: boolean;\n size: DSControlledToggleT.ToggleSize;\n checked: boolean;\n disabled: boolean;\n}\ninterface SetLabelWidthT {\n size: DSControlledToggleT.ToggleSize;\n}\n\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,
|
|
4
|
+
"sourcesContent": ["import { styled, css } from '@elliemae/ds-system';\nimport type { DSControlledToggleT } from './propTypes';\n\nimport {\n containerHeight,\n borderRadius,\n labelHeight,\n getInterpolatedBorderDsToggleColorByProps,\n getInterpolatedBgDsToggleColorByProps,\n circleValues,\n handleFontSize,\n margin,\n handleCursors,\n} from './utils/styleHelpers';\n\ninterface StyledContainerT {\n size: DSControlledToggleT.ToggleSize;\n}\ninterface StyledLabelT {\n width: number;\n size: DSControlledToggleT.ToggleSize;\n checked: boolean;\n}\ninterface StyledVisibleContentT {\n checked: boolean;\n size: DSControlledToggleT.ToggleSize;\n disabled: boolean;\n readOnly: boolean;\n as: 'p' | 'label';\n htmlFor: string;\n}\ninterface StyledCircleT {\n size: DSControlledToggleT.ToggleSize;\n readOnly: boolean;\n checked: boolean;\n disabled: boolean;\n}\ninterface StyledTextT {\n isLongerTextRendering: boolean;\n size: DSControlledToggleT.ToggleSize;\n checked: boolean;\n disabled: boolean;\n}\ninterface SetLabelWidthT {\n size: DSControlledToggleT.ToggleSize;\n}\n\nconst focusBorders = css`\n &:hover,\n &:focus-within {\n border: 2px solid ${({ theme }) => theme.colors.brand[300]};\n &:after {\n content: '';\n height: calc(100% + 4px);\n width: calc(100% + 4px);\n border: 1px solid ${({ theme }) => theme.colors.brand[600]};\n border-radius: 20px;\n position: absolute;\n }\n }\n`;\n\nexport const StyledContainer = styled.div<StyledContainerT>`\n display: inline-flex;\n width: fit-content;\n justify-content: center;\n align-items: center;\n height: ${({ size }) => containerHeight[size]};\n border-radius: ${({ size }) => borderRadius[size]};\n outline: none;\n position: relative;\n border: 2px solid transparent;\n ${({ disabled }) => !disabled && focusBorders};\n`;\n\nexport const StyledLabel = styled.div<StyledLabelT>`\n width: ${({ width, size }) => `calc(${width}px + ${margin[size]})`};\n height: ${({ size }) => labelHeight[size]};\n z-index: 2;\n outline: none;\n border-radius: ${({ size }) => labelHeight[size]};\n`;\n\nexport const StyledVisibleContent = styled.label<StyledVisibleContentT>`\n display: flex;\n margin: 0;\n padding: 0;\n align-items: center;\n height: 100%;\n flex-direction: ${({ checked }) => (checked ? 'row-reverse' : 'row')};\n border-radius: ${({ size }) => `calc(${labelHeight[size]} - 4px)`};\n border: ${(props) =>\n props.size === 's'\n ? `1px solid ${getInterpolatedBorderDsToggleColorByProps(props)}`\n : `\n 2px solid ${getInterpolatedBorderDsToggleColorByProps(props)}\n `};\n transition: background-color 0.2s;\n background-color: ${getInterpolatedBgDsToggleColorByProps};\n`;\n\nexport const StyledCircle = styled.div<StyledCircleT>`\n height: ${({ size }) => circleValues[size]};\n width: ${({ size }) => circleValues[size]};\n border-radius: 50%;\n background-color: ${({ theme, readOnly }) => (readOnly ? theme.colors.neutral[100] : theme.colors.neutral['000'])};\n`;\n\nexport const StyledText = styled.div<StyledTextT>`\n display: flex;\n flex-grow: 1;\n line-height: 1;\n margin-bottom: -0.12rem;\n align-items: center;\n justify-content: ${({ isLongerTextRendering }) => (isLongerTextRendering ? 'flex-start' : 'center')};\n font-size: ${({ theme, size }) => handleFontSize(size, theme)};\n font-weight: ${({ theme }) => theme.fontWeights.semibold};\n color: ${({ theme, disabled }) => (disabled ? '#5c6574' : theme.colors.neutral['000'])};\n ${({ isLongerTextRendering, checked }) => (isLongerTextRendering && checked ? `margin-left: 6px;` : undefined)}\n ${({ isLongerTextRendering, checked }) => (isLongerTextRendering && !checked ? `margin-left: 4px;` : undefined)}\n`;\n\nexport const StyledButton = styled.button`\n position: absolute;\n opacity: 0;\n z-index: 20;\n height: 100%;\n width: 100%;\n &:hover {\n cursor: ${({ disabled, readOnly }) => handleCursors(disabled, readOnly)};\n }\n`;\n\nexport const SetLabelWidth = styled.div<SetLabelWidthT>`\n font-size: ${({ theme, size }) => handleFontSize(size, theme)};\n font-weight: ${({ theme }) => theme.fontWeights.semibold};\n width: auto;\n position: absolute;\n white-space: nowrap;\n visibility: hidden;\n`;\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,uBAA4B;AAG5B,0BAUO;AAkCP,MAAM,eAAe;AAAA;AAAA;AAAA,wBAGG,CAAC,EAAE,YAAY,MAAM,OAAO,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,0BAKhC,CAAC,EAAE,YAAY,MAAM,OAAO,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAOrD,MAAM,kBAAkB,wBAAO;AAAA;AAAA;AAAA;AAAA;AAAA,YAK1B,CAAC,EAAE,WAAW,oCAAgB;AAAA,mBACvB,CAAC,EAAE,WAAW,iCAAa;AAAA;AAAA;AAAA;AAAA,IAI1C,CAAC,EAAE,eAAe,CAAC,YAAY;AAAA;AAG5B,MAAM,cAAc,wBAAO;AAAA,WACvB,CAAC,EAAE,OAAO,WAAW,QAAQ,aAAa,2BAAO;AAAA,YAChD,CAAC,EAAE,WAAW,gCAAY;AAAA;AAAA;AAAA,mBAGnB,CAAC,EAAE,WAAW,gCAAY;AAAA;AAGtC,MAAM,uBAAuB,wBAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAMvB,CAAC,EAAE,cAAe,UAAU,gBAAgB;AA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(Component, readOnly) => {
|
|
30
30
|
if (readOnly)
|
|
31
|
-
return /* @__PURE__ */ import_react.default.createElement(import_ds_tooltip.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
triggerComponent: Component
|
|
35
|
-
});
|
|
31
|
+
return /* @__PURE__ */ import_react.default.createElement(import_ds_tooltip.DSTooltipV3, {
|
|
32
|
+
text: "Read Only"
|
|
33
|
+
}, Component);
|
|
36
34
|
return Component;
|
|
37
35
|
};
|
|
38
36
|
//# sourceMappingURL=addTooltipOnReadOnly.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/utils/addTooltipOnReadOnly.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["import React from 'react';\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,mBAAkB;AAClB,wBAA4B;AAErB,MAAM,uBAAuB,CAAC,WAAwB,aAAmC;AAC9F,MAAI;AAAU,WAAO,mDAAC;AAAA,MAAY,
|
|
4
|
+
"sourcesContent": ["import React from 'react';\nimport { DSTooltipV3 } from '@elliemae/ds-tooltip';\n\nexport const addTooltipOnReadOnly = (Component: JSX.Element, readOnly: boolean): JSX.Element => {\n if (readOnly) return <DSTooltipV3 text=\"Read Only\">{Component}</DSTooltipV3>;\n return Component;\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,mBAAkB;AAClB,wBAA4B;AAErB,MAAM,uBAAuB,CAAC,WAAwB,aAAmC;AAC9F,MAAI;AAAU,WAAO,mDAAC;AAAA,MAAY,MAAK;AAAA,OAAa,SAAU;AAC9D,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
2
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
@@ -14,14 +16,33 @@ var __spreadValues = (a, b) => {
|
|
|
14
16
|
}
|
|
15
17
|
return a;
|
|
16
18
|
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
17
32
|
import * as React from "react";
|
|
18
33
|
import React2, { useState, useMemo, useRef, useEffect, useCallback } from "react";
|
|
19
34
|
import { uid } from "uid";
|
|
20
|
-
import {
|
|
35
|
+
import {
|
|
36
|
+
describe,
|
|
37
|
+
useMemoMergePropsWithDefault,
|
|
38
|
+
useGetGlobalAttributes,
|
|
39
|
+
useValidateTypescriptPropTypes,
|
|
40
|
+
useGetXstyledProps
|
|
41
|
+
} from "@elliemae/ds-utilities";
|
|
21
42
|
import { propTypes, defaultProps } from "./propTypes";
|
|
22
43
|
import {
|
|
23
44
|
StyledContainer,
|
|
24
|
-
|
|
45
|
+
StyledButton,
|
|
25
46
|
StyledLabel,
|
|
26
47
|
StyledVisibleContent,
|
|
27
48
|
StyledCircle,
|
|
@@ -29,25 +50,16 @@ import {
|
|
|
29
50
|
SetLabelWidth
|
|
30
51
|
} from "./styles";
|
|
31
52
|
import { addTooltipOnReadOnly } from "./utils/addTooltipOnReadOnly";
|
|
32
|
-
const DSControlledToggle = ({
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
value,
|
|
37
|
-
checked,
|
|
38
|
-
onChange,
|
|
39
|
-
size,
|
|
40
|
-
readOnly,
|
|
41
|
-
disabled,
|
|
42
|
-
containerProps,
|
|
43
|
-
id
|
|
44
|
-
}) => {
|
|
53
|
+
const DSControlledToggle = (props) => {
|
|
54
|
+
const propsWithDefaults = useMemoMergePropsWithDefault(props, defaultProps);
|
|
55
|
+
useValidateTypescriptPropTypes(propsWithDefaults, propTypes);
|
|
56
|
+
const _a = propsWithDefaults, { labelOn, labelOff, value, checked, onChange, size, readOnly, active, disabled, containerProps, id } = _a, rest = __objRest(_a, ["labelOn", "labelOff", "value", "checked", "onChange", "size", "readOnly", "active", "disabled", "containerProps", "id"]);
|
|
45
57
|
const [isLongerTextRendering, setIsLongerTextRendering] = useState(false);
|
|
46
58
|
const [width, setWidth] = useState(0);
|
|
47
59
|
const labelTextRef = useRef(null);
|
|
48
60
|
const widthTextRef = useRef(null);
|
|
49
61
|
const longerText = useMemo(() => labelOn.length > labelOff.length ? labelOn : labelOff, [labelOff, labelOn]);
|
|
50
|
-
const instanceUID = useMemo(() => uid(5), []);
|
|
62
|
+
const instanceUID = useMemo(() => id || uid(5), [id]);
|
|
51
63
|
useEffect(() => {
|
|
52
64
|
if (labelTextRef.current) {
|
|
53
65
|
setIsLongerTextRendering(labelTextRef.current.innerText === longerText);
|
|
@@ -61,33 +73,30 @@ const DSControlledToggle = ({
|
|
|
61
73
|
const handleOnChange = useCallback(() => {
|
|
62
74
|
if (disabled || readOnly)
|
|
63
75
|
return;
|
|
64
|
-
onChange
|
|
65
|
-
}, [disabled, readOnly, onChange]);
|
|
66
|
-
const handleKeyDown = useCallback((e) => {
|
|
67
|
-
if (disabled || readOnly) {
|
|
68
|
-
e.preventDefault();
|
|
69
|
-
}
|
|
70
|
-
if (e.key === "Enter") {
|
|
71
|
-
e.preventDefault();
|
|
76
|
+
if (onChange)
|
|
72
77
|
onChange();
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
78
|
+
}, [disabled, readOnly, onChange]);
|
|
79
|
+
const globalAttrs = useGetGlobalAttributes(rest, { onClick: handleOnChange });
|
|
80
|
+
const xStyledProps = useGetXstyledProps(rest);
|
|
81
|
+
return /* @__PURE__ */ React2.createElement(StyledContainer, __spreadProps(__spreadValues(__spreadValues({
|
|
76
82
|
size,
|
|
77
83
|
"data-testid": "ds-controlled-toggle"
|
|
78
|
-
}, containerProps),
|
|
79
|
-
|
|
80
|
-
|
|
84
|
+
}, containerProps), xStyledProps), {
|
|
85
|
+
disabled
|
|
86
|
+
}), addTooltipOnReadOnly(/* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(StyledButton, __spreadValues({
|
|
87
|
+
role: "switch",
|
|
81
88
|
value,
|
|
82
|
-
|
|
89
|
+
type: "button",
|
|
83
90
|
"data-testid": "ds-controlled-toggle-checkbox",
|
|
84
|
-
id:
|
|
91
|
+
id: instanceUID,
|
|
92
|
+
"aria-readonly": readOnly,
|
|
85
93
|
"aria-disabled": disabled,
|
|
86
94
|
"aria-checked": checked,
|
|
87
|
-
tabIndex: 0,
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
95
|
+
tabIndex: disabled ? -1 : 0,
|
|
96
|
+
onClick: handleOnChange,
|
|
97
|
+
readOnly,
|
|
98
|
+
disabled
|
|
99
|
+
}, globalAttrs)), /* @__PURE__ */ React2.createElement(StyledLabel, {
|
|
91
100
|
checked,
|
|
92
101
|
size,
|
|
93
102
|
width
|
|
@@ -95,6 +104,7 @@ const DSControlledToggle = ({
|
|
|
95
104
|
checked,
|
|
96
105
|
size,
|
|
97
106
|
readOnly,
|
|
107
|
+
active,
|
|
98
108
|
disabled,
|
|
99
109
|
htmlFor: id ? void 0 : instanceUID,
|
|
100
110
|
as: id ? "p" : "label"
|
|
@@ -104,6 +114,7 @@ const DSControlledToggle = ({
|
|
|
104
114
|
readOnly,
|
|
105
115
|
disabled
|
|
106
116
|
}), /* @__PURE__ */ React2.createElement(StyledText, {
|
|
117
|
+
"aria-hidden": "true",
|
|
107
118
|
ref: labelTextRef,
|
|
108
119
|
isLongerTextRendering,
|
|
109
120
|
checked,
|
|
@@ -112,9 +123,8 @@ const DSControlledToggle = ({
|
|
|
112
123
|
}, checked ? labelOn : labelOff))), /* @__PURE__ */ React2.createElement(SetLabelWidth, {
|
|
113
124
|
size,
|
|
114
125
|
ref: widthTextRef
|
|
115
|
-
}, longerText)), readOnly);
|
|
126
|
+
}, longerText)), readOnly));
|
|
116
127
|
};
|
|
117
|
-
DSControlledToggle.defaultProps = defaultProps;
|
|
118
128
|
DSControlledToggle.propTypes = propTypes;
|
|
119
129
|
DSControlledToggle.displayName = "DSControlledToggle";
|
|
120
130
|
const DSControlledToggleWithSchema = describe(DSControlledToggle);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../scripts/build/transpile/react-shim.js", "../../src/ControlledToggle.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useState, useMemo, useRef, useEffect, useCallback } from 'react';\nimport { uid } from 'uid';\nimport {
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useState, useMemo, useRef, useEffect, useCallback } from 'react';\nimport { uid } from 'uid';\nimport {\n describe,\n useMemoMergePropsWithDefault,\n useGetGlobalAttributes,\n useValidateTypescriptPropTypes,\n useGetXstyledProps,\n} from '@elliemae/ds-utilities';\nimport { propTypes, defaultProps, type DSControlledToggleT } from './propTypes';\nimport {\n StyledContainer,\n StyledButton,\n StyledLabel,\n StyledVisibleContent,\n StyledCircle,\n StyledText,\n SetLabelWidth,\n} from './styles';\nimport { addTooltipOnReadOnly } from './utils/addTooltipOnReadOnly';\n\nconst DSControlledToggle = (props: DSControlledToggleT.Props): JSX.Element => {\n const propsWithDefaults = useMemoMergePropsWithDefault(props, defaultProps);\n useValidateTypescriptPropTypes(propsWithDefaults, propTypes);\n const { labelOn, labelOff, value, checked, onChange, size, readOnly, active, disabled, containerProps, id, ...rest } =\n propsWithDefaults;\n\n const [isLongerTextRendering, setIsLongerTextRendering] = useState<boolean>(false);\n const [width, setWidth] = useState<number>(0);\n const labelTextRef = useRef<HTMLDivElement | null>(null);\n const widthTextRef = useRef<HTMLDivElement | null>(null);\n\n const longerText = useMemo(() => (labelOn.length > labelOff.length ? labelOn : labelOff), [labelOff, labelOn]);\n\n const instanceUID = useMemo(() => id || uid(5), [id]);\n\n useEffect(() => {\n if (labelTextRef.current) {\n setIsLongerTextRendering(labelTextRef.current.innerText === longerText);\n }\n }, [labelTextRef, longerText, checked]);\n\n useEffect(() => {\n if (widthTextRef.current) {\n setWidth(widthTextRef.current.clientWidth);\n }\n }, [widthTextRef]);\n\n const handleOnChange = useCallback(() => {\n if (disabled || readOnly) return;\n if (onChange) onChange();\n }, [disabled, readOnly, onChange]);\n\n const globalAttrs = useGetGlobalAttributes(rest, { onClick: handleOnChange });\n const xStyledProps = useGetXstyledProps(rest);\n\n return (\n <StyledContainer\n size={size}\n data-testid=\"ds-controlled-toggle\"\n {...containerProps}\n {...xStyledProps}\n disabled={disabled}\n >\n {addTooltipOnReadOnly(\n <>\n <StyledButton\n role=\"switch\"\n value={value}\n type=\"button\"\n data-testid=\"ds-controlled-toggle-checkbox\"\n id={instanceUID}\n aria-readonly={readOnly}\n aria-disabled={disabled}\n aria-checked={checked}\n tabIndex={disabled ? -1 : 0}\n onClick={handleOnChange}\n readOnly={readOnly}\n disabled={disabled}\n {...globalAttrs}\n />\n <StyledLabel checked={checked} size={size} width={width}>\n <StyledVisibleContent\n checked={checked}\n size={size}\n readOnly={readOnly}\n active={active}\n disabled={disabled}\n htmlFor={id ? undefined : instanceUID}\n as={id ? 'p' : 'label'}\n >\n <StyledCircle checked={checked} size={size} readOnly={readOnly} disabled={disabled} />\n <StyledText\n aria-hidden=\"true\"\n ref={labelTextRef}\n isLongerTextRendering={isLongerTextRendering}\n checked={checked}\n size={size}\n disabled={disabled}\n >\n {checked ? labelOn : labelOff}\n </StyledText>\n </StyledVisibleContent>\n </StyledLabel>\n <SetLabelWidth size={size} ref={widthTextRef}>\n {longerText}\n </SetLabelWidth>\n </>,\n readOnly,\n )}\n </StyledContainer>\n );\n};\n\nDSControlledToggle.propTypes = propTypes;\nDSControlledToggle.displayName = 'DSControlledToggle';\nconst DSControlledToggleWithSchema = describe(DSControlledToggle);\nDSControlledToggleWithSchema.propTypes = propTypes;\n\nexport { DSControlledToggle, DSControlledToggleWithSchema };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;ACAA;AACA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA;AAEA,MAAM,qBAAqB,CAAC,UAAkD;AAC5E,QAAM,oBAAoB,6BAA6B,OAAO,YAAY;AAC1E,iCAA+B,mBAAmB,SAAS;AAC3D,QACE,wBADM,WAAS,UAAU,OAAO,SAAS,UAAU,MAAM,UAAU,QAAQ,UAAU,gBAAgB,OACrG,IAD4G,iBAC5G,IAD4G,CAAtG,WAAS,YAAU,SAAO,WAAS,YAAU,QAAM,YAAU,UAAQ,YAAU,kBAAgB;AAGvG,QAAM,CAAC,uBAAuB,4BAA4B,SAAkB,KAAK;AACjF,QAAM,CAAC,OAAO,YAAY,SAAiB,CAAC;AAC5C,QAAM,eAAe,OAA8B,IAAI;AACvD,QAAM,eAAe,OAA8B,IAAI;AAEvD,QAAM,aAAa,QAAQ,MAAO,QAAQ,SAAS,S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AAY;AAAA,IACZ,KAAK;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,KAEC,UAAU,UAAU,QACvB,CACF,CACF,GACA,qCAAC;AAAA,IAAc;AAAA,IAAY,KAAK;AAAA,KAC7B,UACH,CACF,GACA,QACF,CACF;AAEJ;AAEA,mBAAmB,YAAY;AAC/B,mBAAmB,cAAc;AACjC,MAAM,+BAA+B,SAAS,kBAAkB;AAChE,6BAA6B,YAAY;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/propTypes.js
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
1
20
|
import * as React from "react";
|
|
2
|
-
import { PropTypes } from "@elliemae/ds-utilities";
|
|
21
|
+
import { globalAttributesPropTypes, xstyledPropTypes, PropTypes } from "@elliemae/ds-utilities";
|
|
3
22
|
const defaultProps = {
|
|
4
23
|
labelOn: "ON",
|
|
5
24
|
labelOff: "OFF",
|
|
@@ -11,7 +30,7 @@ const defaultProps = {
|
|
|
11
30
|
readonly: false,
|
|
12
31
|
disabled: false
|
|
13
32
|
};
|
|
14
|
-
const propTypes = {
|
|
33
|
+
const propTypes = __spreadProps(__spreadValues(__spreadValues({}, globalAttributesPropTypes), xstyledPropTypes), {
|
|
15
34
|
labelOn: PropTypes.string.description("Label when toggle is checked"),
|
|
16
35
|
labelOff: PropTypes.string.description("Label when toggle is unchecked"),
|
|
17
36
|
value: PropTypes.string.description("Value attribute for toggle"),
|
|
@@ -24,7 +43,7 @@ const propTypes = {
|
|
|
24
43
|
disabled: PropTypes.bool.description("Wether the toggle is disabled or not"),
|
|
25
44
|
containerProps: PropTypes.shape({}).description("Set of properties attached to the main container"),
|
|
26
45
|
id: PropTypes.string.description("Unique id.")
|
|
27
|
-
};
|
|
46
|
+
});
|
|
28
47
|
export {
|
|
29
48
|
defaultProps,
|
|
30
49
|
propTypes
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../scripts/build/transpile/react-shim.js", "../../src/propTypes.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { PropTypes } from '@elliemae/ds-utilities';\n\nexport declare namespace DSControlledToggleT {\n export type ToggleSize = 's' | 'm' | 'l';\n export interface Props {\n labelOn: string;\n labelOff: string;\n name: string;\n value: string;\n checked: boolean;\n onChange: () => void | null;\n size: ToggleSize;\n readOnly: boolean;\n disabled: boolean;\n containerProps: Record<string, unknown>;\n id: string;\n }\n}\nexport const defaultProps = {\n labelOn: 'ON',\n labelOff: 'OFF',\n name: '',\n value: '',\n checked: false,\n onClick: () => null,\n size: 'm',\n readonly: false,\n disabled: false,\n};\n\nexport const propTypes = {\n labelOn: PropTypes.string.description('Label when toggle is checked'),\n labelOff: PropTypes.string.description('Label when toggle is unchecked'),\n value: PropTypes.string.description('Value attribute for toggle'),\n name: PropTypes.string.description('Name attribute for toggle'),\n checked: PropTypes.bool.description('Wether the toggle is checked or not'),\n onchange: PropTypes.func.description('OnClick callback'),\n size: PropTypes.oneOf(['s', 'm', 'l']).description('Size of toggle'),\n readOnly: PropTypes.bool.description('Wether the toggle is readOnly or not'),\n active: PropTypes.bool.description('Wether the toggle has active styles or not').deprecated({ version: '3.x' }),\n disabled: PropTypes.bool.description('Wether the toggle is disabled or not'),\n containerProps: PropTypes.shape({}).description('Set of properties attached to the main container'),\n id: PropTypes.string.description('Unique id.'),\n};\n"],
|
|
5
|
-
"mappings": "AAAA;ACAA;AAkBO,MAAM,eAAe;AAAA,EAC1B,SAAS;AAAA,EACT,UAAU;AAAA,EACV,MAAM;AAAA,EACN,OAAO;AAAA,EACP,SAAS;AAAA,EACT,SAAS,MAAM;AAAA,EACf,MAAM;AAAA,EACN,UAAU;AAAA,EACV,UAAU;AACZ;AAEO,MAAM,YAAY;AAAA,
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { globalAttributesPropTypes, xstyledPropTypes, PropTypes } from '@elliemae/ds-utilities';\n\nexport declare namespace DSControlledToggleT {\n export type ToggleSize = 's' | 'm' | 'l';\n export interface Props {\n labelOn: string;\n labelOff: string;\n name: string;\n value: string;\n checked: boolean;\n onChange: () => void | null;\n size: ToggleSize;\n readOnly: boolean;\n disabled: boolean;\n containerProps: Record<string, unknown>;\n id: string;\n }\n}\nexport const defaultProps = {\n labelOn: 'ON',\n labelOff: 'OFF',\n name: '',\n value: '',\n checked: false,\n onClick: () => null,\n size: 'm',\n readonly: false,\n disabled: false,\n};\n\nexport const propTypes = {\n ...globalAttributesPropTypes,\n ...xstyledPropTypes,\n labelOn: PropTypes.string.description('Label when toggle is checked'),\n labelOff: PropTypes.string.description('Label when toggle is unchecked'),\n value: PropTypes.string.description('Value attribute for toggle'),\n name: PropTypes.string.description('Name attribute for toggle'),\n checked: PropTypes.bool.description('Wether the toggle is checked or not'),\n onchange: PropTypes.func.description('OnClick callback'),\n size: PropTypes.oneOf(['s', 'm', 'l']).description('Size of toggle'),\n readOnly: PropTypes.bool.description('Wether the toggle is readOnly or not'),\n active: PropTypes.bool.description('Wether the toggle has active styles or not').deprecated({ version: '3.x' }),\n disabled: PropTypes.bool.description('Wether the toggle is disabled or not'),\n containerProps: PropTypes.shape({}).description('Set of properties attached to the main container'),\n id: PropTypes.string.description('Unique id.'),\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;ACAA;AAkBO,MAAM,eAAe;AAAA,EAC1B,SAAS;AAAA,EACT,UAAU;AAAA,EACV,MAAM;AAAA,EACN,OAAO;AAAA,EACP,SAAS;AAAA,EACT,SAAS,MAAM;AAAA,EACf,MAAM;AAAA,EACN,UAAU;AAAA,EACV,UAAU;AACZ;AAEO,MAAM,YAAY,gDACpB,4BACA,mBAFoB;AAAA,EAGvB,SAAS,UAAU,OAAO,YAAY,8BAA8B;AAAA,EACpE,UAAU,UAAU,OAAO,YAAY,gCAAgC;AAAA,EACvE,OAAO,UAAU,OAAO,YAAY,4BAA4B;AAAA,EAChE,MAAM,UAAU,OAAO,YAAY,2BAA2B;AAAA,EAC9D,SAAS,UAAU,KAAK,YAAY,qCAAqC;AAAA,EACzE,UAAU,UAAU,KAAK,YAAY,kBAAkB;AAAA,EACvD,MAAM,UAAU,MAAM,CAAC,KAAK,KAAK,GAAG,CAAC,EAAE,YAAY,gBAAgB;AAAA,EACnE,UAAU,UAAU,KAAK,YAAY,sCAAsC;AAAA,EAC3E,QAAQ,UAAU,KAAK,YAAY,4CAA4C,EAAE,WAAW,EAAE,SAAS,MAAM,CAAC;AAAA,EAC9G,UAAU,UAAU,KAAK,YAAY,sCAAsC;AAAA,EAC3E,gBAAgB,UAAU,MAAM,CAAC,CAAC,EAAE,YAAY,kDAAkD;AAAA,EAClG,IAAI,UAAU,OAAO,YAAY,YAAY;AAC/C;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/styles.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { styled } from "@elliemae/ds-system";
|
|
2
|
+
import { styled, css } from "@elliemae/ds-system";
|
|
3
3
|
import {
|
|
4
4
|
containerHeight,
|
|
5
5
|
borderRadius,
|
|
@@ -11,16 +11,7 @@ import {
|
|
|
11
11
|
margin,
|
|
12
12
|
handleCursors
|
|
13
13
|
} from "./utils/styleHelpers";
|
|
14
|
-
const
|
|
15
|
-
display: inline-flex;
|
|
16
|
-
width: fit-content;
|
|
17
|
-
justify-content: center;
|
|
18
|
-
align-items: center;
|
|
19
|
-
height: ${({ size }) => containerHeight[size]};
|
|
20
|
-
border-radius: ${({ size }) => borderRadius[size]};
|
|
21
|
-
outline: none;
|
|
22
|
-
position: relative;
|
|
23
|
-
border: 2px solid transparent;
|
|
14
|
+
const focusBorders = css`
|
|
24
15
|
&:hover,
|
|
25
16
|
&:focus-within {
|
|
26
17
|
border: 2px solid ${({ theme }) => theme.colors.brand[300]};
|
|
@@ -34,6 +25,18 @@ const StyledContainer = styled.div`
|
|
|
34
25
|
}
|
|
35
26
|
}
|
|
36
27
|
`;
|
|
28
|
+
const StyledContainer = styled.div`
|
|
29
|
+
display: inline-flex;
|
|
30
|
+
width: fit-content;
|
|
31
|
+
justify-content: center;
|
|
32
|
+
align-items: center;
|
|
33
|
+
height: ${({ size }) => containerHeight[size]};
|
|
34
|
+
border-radius: ${({ size }) => borderRadius[size]};
|
|
35
|
+
outline: none;
|
|
36
|
+
position: relative;
|
|
37
|
+
border: 2px solid transparent;
|
|
38
|
+
${({ disabled }) => !disabled && focusBorders};
|
|
39
|
+
`;
|
|
37
40
|
const StyledLabel = styled.div`
|
|
38
41
|
width: ${({ width, size }) => `calc(${width}px + ${margin[size]})`};
|
|
39
42
|
height: ${({ size }) => labelHeight[size]};
|
|
@@ -54,10 +57,6 @@ const StyledVisibleContent = styled.label`
|
|
|
54
57
|
`};
|
|
55
58
|
transition: background-color 0.2s;
|
|
56
59
|
background-color: ${getInterpolatedBgDsToggleColorByProps};
|
|
57
|
-
|
|
58
|
-
&:hover {
|
|
59
|
-
cursor: ${({ disabled, readOnly }) => handleCursors(disabled, readOnly)};
|
|
60
|
-
}
|
|
61
60
|
`;
|
|
62
61
|
const StyledCircle = styled.div`
|
|
63
62
|
height: ${({ size }) => circleValues[size]};
|
|
@@ -78,13 +77,15 @@ const StyledText = styled.div`
|
|
|
78
77
|
${({ isLongerTextRendering, checked }) => isLongerTextRendering && checked ? `margin-left: 6px;` : void 0}
|
|
79
78
|
${({ isLongerTextRendering, checked }) => isLongerTextRendering && !checked ? `margin-left: 4px;` : void 0}
|
|
80
79
|
`;
|
|
81
|
-
const
|
|
80
|
+
const StyledButton = styled.button`
|
|
82
81
|
position: absolute;
|
|
83
82
|
opacity: 0;
|
|
84
83
|
z-index: 20;
|
|
85
84
|
height: 100%;
|
|
86
85
|
width: 100%;
|
|
87
|
-
|
|
86
|
+
&:hover {
|
|
87
|
+
cursor: ${({ disabled, readOnly }) => handleCursors(disabled, readOnly)};
|
|
88
|
+
}
|
|
88
89
|
`;
|
|
89
90
|
const SetLabelWidth = styled.div`
|
|
90
91
|
font-size: ${({ theme, size }) => handleFontSize(size, theme)};
|
|
@@ -96,9 +97,9 @@ const SetLabelWidth = styled.div`
|
|
|
96
97
|
`;
|
|
97
98
|
export {
|
|
98
99
|
SetLabelWidth,
|
|
100
|
+
StyledButton,
|
|
99
101
|
StyledCircle,
|
|
100
102
|
StyledContainer,
|
|
101
|
-
StyledInput,
|
|
102
103
|
StyledLabel,
|
|
103
104
|
StyledText,
|
|
104
105
|
StyledVisibleContent
|
package/dist/esm/styles.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../scripts/build/transpile/react-shim.js", "../../src/styles.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { styled } from '@elliemae/ds-system';\nimport type { DSControlledToggleT } from './propTypes';\n\nimport {\n containerHeight,\n borderRadius,\n labelHeight,\n getInterpolatedBorderDsToggleColorByProps,\n getInterpolatedBgDsToggleColorByProps,\n circleValues,\n handleFontSize,\n margin,\n handleCursors,\n} from './utils/styleHelpers';\n\ninterface StyledContainerT {\n size: DSControlledToggleT.ToggleSize;\n}\ninterface StyledLabelT {\n width: number;\n size: DSControlledToggleT.ToggleSize;\n checked: boolean;\n}\ninterface StyledVisibleContentT {\n checked: boolean;\n size: DSControlledToggleT.ToggleSize;\n disabled: boolean;\n readOnly: boolean;\n as: 'p' | 'label';\n htmlFor: string;\n}\ninterface StyledCircleT {\n size: DSControlledToggleT.ToggleSize;\n readOnly: boolean;\n checked: boolean;\n disabled: boolean;\n}\ninterface StyledTextT {\n isLongerTextRendering: boolean;\n size: DSControlledToggleT.ToggleSize;\n checked: boolean;\n disabled: boolean;\n}\ninterface SetLabelWidthT {\n size: DSControlledToggleT.ToggleSize;\n}\n\
|
|
5
|
-
"mappings": "AAAA;ACAA;AAGA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { styled, css } from '@elliemae/ds-system';\nimport type { DSControlledToggleT } from './propTypes';\n\nimport {\n containerHeight,\n borderRadius,\n labelHeight,\n getInterpolatedBorderDsToggleColorByProps,\n getInterpolatedBgDsToggleColorByProps,\n circleValues,\n handleFontSize,\n margin,\n handleCursors,\n} from './utils/styleHelpers';\n\ninterface StyledContainerT {\n size: DSControlledToggleT.ToggleSize;\n}\ninterface StyledLabelT {\n width: number;\n size: DSControlledToggleT.ToggleSize;\n checked: boolean;\n}\ninterface StyledVisibleContentT {\n checked: boolean;\n size: DSControlledToggleT.ToggleSize;\n disabled: boolean;\n readOnly: boolean;\n as: 'p' | 'label';\n htmlFor: string;\n}\ninterface StyledCircleT {\n size: DSControlledToggleT.ToggleSize;\n readOnly: boolean;\n checked: boolean;\n disabled: boolean;\n}\ninterface StyledTextT {\n isLongerTextRendering: boolean;\n size: DSControlledToggleT.ToggleSize;\n checked: boolean;\n disabled: boolean;\n}\ninterface SetLabelWidthT {\n size: DSControlledToggleT.ToggleSize;\n}\n\nconst focusBorders = css`\n &:hover,\n &:focus-within {\n border: 2px solid ${({ theme }) => theme.colors.brand[300]};\n &:after {\n content: '';\n height: calc(100% + 4px);\n width: calc(100% + 4px);\n border: 1px solid ${({ theme }) => theme.colors.brand[600]};\n border-radius: 20px;\n position: absolute;\n }\n }\n`;\n\nexport const StyledContainer = styled.div<StyledContainerT>`\n display: inline-flex;\n width: fit-content;\n justify-content: center;\n align-items: center;\n height: ${({ size }) => containerHeight[size]};\n border-radius: ${({ size }) => borderRadius[size]};\n outline: none;\n position: relative;\n border: 2px solid transparent;\n ${({ disabled }) => !disabled && focusBorders};\n`;\n\nexport const StyledLabel = styled.div<StyledLabelT>`\n width: ${({ width, size }) => `calc(${width}px + ${margin[size]})`};\n height: ${({ size }) => labelHeight[size]};\n z-index: 2;\n outline: none;\n border-radius: ${({ size }) => labelHeight[size]};\n`;\n\nexport const StyledVisibleContent = styled.label<StyledVisibleContentT>`\n display: flex;\n margin: 0;\n padding: 0;\n align-items: center;\n height: 100%;\n flex-direction: ${({ checked }) => (checked ? 'row-reverse' : 'row')};\n border-radius: ${({ size }) => `calc(${labelHeight[size]} - 4px)`};\n border: ${(props) =>\n props.size === 's'\n ? `1px solid ${getInterpolatedBorderDsToggleColorByProps(props)}`\n : `\n 2px solid ${getInterpolatedBorderDsToggleColorByProps(props)}\n `};\n transition: background-color 0.2s;\n background-color: ${getInterpolatedBgDsToggleColorByProps};\n`;\n\nexport const StyledCircle = styled.div<StyledCircleT>`\n height: ${({ size }) => circleValues[size]};\n width: ${({ size }) => circleValues[size]};\n border-radius: 50%;\n background-color: ${({ theme, readOnly }) => (readOnly ? theme.colors.neutral[100] : theme.colors.neutral['000'])};\n`;\n\nexport const StyledText = styled.div<StyledTextT>`\n display: flex;\n flex-grow: 1;\n line-height: 1;\n margin-bottom: -0.12rem;\n align-items: center;\n justify-content: ${({ isLongerTextRendering }) => (isLongerTextRendering ? 'flex-start' : 'center')};\n font-size: ${({ theme, size }) => handleFontSize(size, theme)};\n font-weight: ${({ theme }) => theme.fontWeights.semibold};\n color: ${({ theme, disabled }) => (disabled ? '#5c6574' : theme.colors.neutral['000'])};\n ${({ isLongerTextRendering, checked }) => (isLongerTextRendering && checked ? `margin-left: 6px;` : undefined)}\n ${({ isLongerTextRendering, checked }) => (isLongerTextRendering && !checked ? `margin-left: 4px;` : undefined)}\n`;\n\nexport const StyledButton = styled.button`\n position: absolute;\n opacity: 0;\n z-index: 20;\n height: 100%;\n width: 100%;\n &:hover {\n cursor: ${({ disabled, readOnly }) => handleCursors(disabled, readOnly)};\n }\n`;\n\nexport const SetLabelWidth = styled.div<SetLabelWidthT>`\n font-size: ${({ theme, size }) => handleFontSize(size, theme)};\n font-weight: ${({ theme }) => theme.fontWeights.semibold};\n width: auto;\n position: absolute;\n white-space: nowrap;\n visibility: hidden;\n`;\n"],
|
|
5
|
+
"mappings": "AAAA;ACAA;AAGA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA4CA,MAAM,eAAe;AAAA;AAAA;AAAA,wBAGG,CAAC,EAAE,YAAY,MAAM,OAAO,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,0BAKhC,CAAC,EAAE,YAAY,MAAM,OAAO,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAOrD,MAAM,kBAAkB,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA,YAK1B,CAAC,EAAE,WAAW,gBAAgB;AAAA,mBACvB,CAAC,EAAE,WAAW,aAAa;AAAA;AAAA;AAAA;AAAA,IAI1C,CAAC,EAAE,eAAe,CAAC,YAAY;AAAA;AAG5B,MAAM,cAAc,OAAO;AAAA,W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KAAK;AAAA,iBAC7C,CAAC,EAAE,YAAY,MAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import React2 from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { DSTooltipV3 } from "@elliemae/ds-tooltip";
|
|
4
4
|
const addTooltipOnReadOnly = (Component, readOnly) => {
|
|
5
5
|
if (readOnly)
|
|
6
|
-
return /* @__PURE__ */ React2.createElement(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
triggerComponent: Component
|
|
10
|
-
});
|
|
6
|
+
return /* @__PURE__ */ React2.createElement(DSTooltipV3, {
|
|
7
|
+
text: "Read Only"
|
|
8
|
+
}, Component);
|
|
11
9
|
return Component;
|
|
12
10
|
};
|
|
13
11
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/utils/addTooltipOnReadOnly.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React from 'react';\nimport {
|
|
5
|
-
"mappings": "AAAA;ACAA;AACA;AAEO,MAAM,uBAAuB,CAAC,WAAwB,aAAmC;AAC9F,MAAI;AAAU,WAAO,qCAAC;AAAA,MAAY,
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React from 'react';\nimport { DSTooltipV3 } from '@elliemae/ds-tooltip';\n\nexport const addTooltipOnReadOnly = (Component: JSX.Element, readOnly: boolean): JSX.Element => {\n if (readOnly) return <DSTooltipV3 text=\"Read Only\">{Component}</DSTooltipV3>;\n return Component;\n};\n"],
|
|
5
|
+
"mappings": "AAAA;ACAA;AACA;AAEO,MAAM,uBAAuB,CAAC,WAAwB,aAAmC;AAC9F,MAAI;AAAU,WAAO,qCAAC;AAAA,MAAY,MAAK;AAAA,OAAa,SAAU;AAC9D,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elliemae/ds-form-toggle",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0-rc.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "ICE MT - Dimsum - Controlled Form Toggle",
|
|
6
6
|
"files": [
|
|
@@ -35,25 +35,25 @@
|
|
|
35
35
|
"indent": 4
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@elliemae/ds-system": "3.
|
|
39
|
-
"@elliemae/ds-tooltip": "3.
|
|
40
|
-
"@elliemae/ds-utilities": "3.
|
|
41
|
-
"styled-components": "~5.3.
|
|
38
|
+
"@elliemae/ds-system": "3.2.0-rc.1",
|
|
39
|
+
"@elliemae/ds-tooltip": "3.2.0-rc.1",
|
|
40
|
+
"@elliemae/ds-utilities": "3.2.0-rc.1",
|
|
41
|
+
"styled-components": "~5.3.5",
|
|
42
42
|
"uid": "~2.0.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@elliemae/pui-theme": "~2.6.0",
|
|
46
|
-
"@testing-library/dom": "~8.
|
|
47
|
-
"@testing-library/jest-dom": "~5.16.
|
|
48
|
-
"@testing-library/react": "~12.1.
|
|
46
|
+
"@testing-library/dom": "~8.13.0",
|
|
47
|
+
"@testing-library/jest-dom": "~5.16.4",
|
|
48
|
+
"@testing-library/react": "~12.1.3",
|
|
49
49
|
"@testing-library/user-event": "~13.5.0",
|
|
50
|
-
"styled-components": "~5.3.
|
|
50
|
+
"styled-components": "~5.3.5"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"@elliemae/pui-theme": "~2.6.0",
|
|
54
54
|
"react": "^17.0.2",
|
|
55
55
|
"react-dom": "^17.0.2",
|
|
56
|
-
"styled-components": "^5.3.
|
|
56
|
+
"styled-components": "^5.3.5",
|
|
57
57
|
"styled-system": "^5.1.5"
|
|
58
58
|
},
|
|
59
59
|
"publishConfig": {
|