@elliemae/ds-form-toggle 3.57.0-next.3 → 3.57.0-next.33
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 +75 -73
- package/dist/cjs/ControlledToggle.js.map +2 -2
- package/dist/cjs/config/useDSControlledToggle.js +25 -2
- package/dist/cjs/config/useDSControlledToggle.js.map +2 -2
- package/dist/cjs/{parts/AddTooltipOnReadOnly.js → config/useGetButtonProps.js} +30 -10
- package/dist/cjs/config/useGetButtonProps.js.map +7 -0
- package/dist/cjs/{DSFormToggleDefinitions.js → config/useGetWidestLabelWidth.js} +40 -6
- package/dist/cjs/config/useGetWidestLabelWidth.js.map +7 -0
- package/dist/cjs/constants/index.js +16 -3
- package/dist/cjs/constants/index.js.map +2 -2
- package/dist/cjs/index.js +11 -2
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/package.json +4 -1
- package/dist/cjs/react-desc-prop-types.js +12 -17
- package/dist/cjs/react-desc-prop-types.js.map +2 -2
- package/dist/cjs/styles.js +49 -35
- package/dist/cjs/styles.js.map +2 -2
- package/dist/cjs/utils/styleHelpers.js +12 -13
- package/dist/cjs/utils/styleHelpers.js.map +2 -2
- package/dist/esm/ControlledToggle.js +81 -79
- package/dist/esm/ControlledToggle.js.map +2 -2
- package/dist/esm/config/useDSControlledToggle.js +25 -2
- package/dist/esm/config/useDSControlledToggle.js.map +2 -2
- package/dist/esm/config/useGetButtonProps.js +31 -0
- package/dist/esm/config/useGetButtonProps.js.map +7 -0
- package/dist/esm/config/useGetWidestLabelWidth.js +40 -0
- package/dist/esm/config/useGetWidestLabelWidth.js.map +7 -0
- package/dist/esm/constants/index.js +16 -3
- package/dist/esm/constants/index.js.map +2 -2
- package/dist/esm/index.js +7 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/package.json +4 -1
- package/dist/esm/react-desc-prop-types.js +12 -17
- package/dist/esm/react-desc-prop-types.js.map +2 -2
- package/dist/esm/styles.js +50 -36
- package/dist/esm/styles.js.map +2 -2
- package/dist/esm/utils/styleHelpers.js +12 -13
- package/dist/esm/utils/styleHelpers.js.map +2 -2
- package/dist/types/config/useDSControlledToggle.d.ts +16 -19
- package/dist/types/config/useGetButtonProps.d.ts +10 -0
- package/dist/types/config/useGetWidestLabelWidth.d.ts +14 -0
- package/dist/types/constants/index.d.ts +15 -2
- package/dist/types/index.d.ts +2 -1
- package/dist/types/react-desc-prop-types.d.ts +39 -13
- package/dist/types/styles.d.ts +31 -30
- package/dist/types/tests/DSControlledToggle.app-sdk-compatibility.test.d.ts +1 -0
- package/dist/types/tests/DSControlledToggle.data-testId.test.d.ts +1 -0
- package/dist/types/utils/styleHelpers.d.ts +8 -8
- package/package.json +27 -30
- package/dist/cjs/DSFormToggleDefinitions.js.map +0 -7
- package/dist/cjs/parts/AddTooltipOnReadOnly.js.map +0 -7
- package/dist/esm/DSFormToggleDefinitions.js +0 -6
- package/dist/esm/DSFormToggleDefinitions.js.map +0 -7
- package/dist/esm/parts/AddTooltipOnReadOnly.js +0 -11
- package/dist/esm/parts/AddTooltipOnReadOnly.js.map +0 -7
- package/dist/types/DSFormToggleDefinitions.d.ts +0 -1
- package/dist/types/parts/AddTooltipOnReadOnly.d.ts +0 -5
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/react-desc-prop-types.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["import type {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;
|
|
4
|
+
"sourcesContent": ["import type { DSButtonV3T } from '@elliemae/ds-button-v2';\nimport type { DSPropTypesSchema, GlobalAttributesT, ValidationMap, XstyledProps } from '@elliemae/ds-props-helpers';\nimport { PropTypes, globalAttributesPropTypes, xstyledPropTypes } from '@elliemae/ds-props-helpers';\nimport { TOGGLE_SIZES } from './constants/index.js';\n\nexport declare namespace DSControlledToggleT {\n export type ToggleSize = ObjectValues<typeof TOGGLE_SIZES>;\n\n export interface DefaultProps {\n checked: boolean;\n onChange: (e: React.MouseEvent<HTMLButtonElement> | React.KeyboardEvent<HTMLButtonElement>) => void;\n size: ToggleSize;\n readOnly: boolean;\n disabled: boolean;\n applyAriaDisabled: boolean;\n }\n\n export interface RequiredProps {}\n\n export interface OptionalProps {\n containerProps?: Record<string, unknown>;\n id?: string;\n }\n\n // this interface is the \"last chance\" for apps to keep using the deprecated props before the major release that will remove them\n // this is meant to \"break\" those using the old prop, but still allow a last chance to gradually update (requiring them to change the prop name)\n export interface PostDeprecationETAPropsFallback {\n /**\n * @deprecated a custom wcagViolationLabelOn violates the role='switch' by design and it's impossible to make it WCAG compliant.\n * Do not use it, if you need a custom label, you don't need a toggle, use a checkbox instead.\n */\n wcagViolationLabelOn?: string; // used to be \"labelOn\"\n /**\n * @deprecated a custom wcagViolationLabelOff violates the role='switch' by design and it's impossible to make it WCAG compliant.\n * Do not use it, if you need a custom label, you don't need a toggle, use a checkbox instead.\n */\n wcagViolationLabelOff?: string; // used to be \"labelOff\"\n }\n export interface PostDeprecationETAProps {\n /**\n * @deprecated a custom wcagViolationLabelOn violates the role='switch' by design and it's impossible to make it WCAG compliant.\n * Do not use it, if you need a custom label, you don't need a toggle, use a checkbox instead.\n */\n labelOn?: string; // used to be \"labelOn\"\n /**\n * @deprecated a custom wcagViolationLabelOff violates the role='switch' by design and it's impossible to make it WCAG compliant.\n * Do not use it, if you need a custom label, you don't need a toggle, use a checkbox instead.\n */\n labelOff?: string; // used to be \"labelOff\"\n }\n\n export interface ButtonV3InherithedProps extends Omit<DSButtonV3T.Props, 'size' | 'children'> {}\n\n export interface Props\n extends Partial<DefaultProps>,\n OptionalProps,\n Omit<GlobalAttributesT<HTMLButtonElement>, keyof DefaultProps | keyof OptionalProps | keyof XstyledProps>,\n XstyledProps,\n RequiredProps,\n PostDeprecationETAProps,\n PostDeprecationETAPropsFallback {}\n\n export interface InternalProps\n extends DefaultProps,\n OptionalProps,\n Omit<GlobalAttributesT<HTMLButtonElement>, keyof DefaultProps | keyof OptionalProps | keyof XstyledProps>,\n XstyledProps,\n RequiredProps,\n PostDeprecationETAProps,\n PostDeprecationETAPropsFallback {}\n}\n\nexport const defaultProps: DSControlledToggleT.DefaultProps = {\n checked: false,\n onChange: () => null,\n size: TOGGLE_SIZES.MEDIUM,\n readOnly: false,\n disabled: false,\n applyAriaDisabled: false,\n};\n\nexport const DSControlledTogglePropTypes: DSPropTypesSchema<\n Omit<DSControlledToggleT.Props, keyof DSControlledToggleT.PostDeprecationETAPropsFallback> &\n DSControlledToggleT.PostDeprecationETAProps\n> = {\n ...globalAttributesPropTypes,\n ...xstyledPropTypes,\n checked: PropTypes.bool.description('Wether the toggle is checked or not').defaultValue('false'),\n onChange: PropTypes.func.description('OnClick callback').defaultValue('() => null'),\n size: PropTypes.oneOf(['s', 'm', 'l']).description('Size of toggle').defaultValue(TOGGLE_SIZES.MEDIUM),\n disabled: PropTypes.bool.description('Wether the toggle is disabled or not').defaultValue('false'),\n applyAriaDisabled: PropTypes.bool\n .description(\n 'Whether to apply disabled styling and announce as disabled in SR. CAN STILL RECEIVE FOCUS. PREVENTS ONLY MAIN ACTION.',\n )\n .defaultValue('false'),\n readOnly: PropTypes.bool.description('Wether the toggle is readOnly or not').defaultValue('false'),\n containerProps: PropTypes.object.description('Set of properties attached to the main container'),\n id: PropTypes.string.description('Unique id.'),\n labelOn: PropTypes.string\n .description('Past deprecation ETA, this fails WCAG, switch to appropiate designs')\n .deprecated({ version: '25.3' }),\n labelOff: PropTypes.string\n .description('Past deprecation ETA, this fails WCAG, switch to appropiate designs')\n .deprecated({ version: '25.3' }),\n};\n\nexport const DSControlledTogglePropTypesSchema =\n DSControlledTogglePropTypes as unknown as ValidationMap<DSControlledToggleT.Props>;\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADEvB,8BAAuE;AACvE,uBAA6B;AAqEtB,MAAM,eAAiD;AAAA,EAC5D,SAAS;AAAA,EACT,UAAU,MAAM;AAAA,EAChB,MAAM,8BAAa;AAAA,EACnB,UAAU;AAAA,EACV,UAAU;AAAA,EACV,mBAAmB;AACrB;AAEO,MAAM,8BAGT;AAAA,EACF,GAAG;AAAA,EACH,GAAG;AAAA,EACH,SAAS,kCAAU,KAAK,YAAY,qCAAqC,EAAE,aAAa,OAAO;AAAA,EAC/F,UAAU,kCAAU,KAAK,YAAY,kBAAkB,EAAE,aAAa,YAAY;AAAA,EAClF,MAAM,kCAAU,MAAM,CAAC,KAAK,KAAK,GAAG,CAAC,EAAE,YAAY,gBAAgB,EAAE,aAAa,8BAAa,MAAM;AAAA,EACrG,UAAU,kCAAU,KAAK,YAAY,sCAAsC,EAAE,aAAa,OAAO;AAAA,EACjG,mBAAmB,kCAAU,KAC1B;AAAA,IACC;AAAA,EACF,EACC,aAAa,OAAO;AAAA,EACvB,UAAU,kCAAU,KAAK,YAAY,sCAAsC,EAAE,aAAa,OAAO;AAAA,EACjG,gBAAgB,kCAAU,OAAO,YAAY,kDAAkD;AAAA,EAC/F,IAAI,kCAAU,OAAO,YAAY,YAAY;AAAA,EAC7C,SAAS,kCAAU,OAChB,YAAY,qEAAqE,EACjF,WAAW,EAAE,SAAS,OAAO,CAAC;AAAA,EACjC,UAAU,kCAAU,OACjB,YAAY,qEAAqE,EACjF,WAAW,EAAE,SAAS,OAAO,CAAC;AACnC;AAEO,MAAM,oCACX;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/styles.js
CHANGED
|
@@ -30,16 +30,17 @@ var styles_exports = {};
|
|
|
30
30
|
__export(styles_exports, {
|
|
31
31
|
SetLabelWidth: () => SetLabelWidth,
|
|
32
32
|
StyledButton: () => StyledButton,
|
|
33
|
+
StyledButtonContentWrapper: () => StyledButtonContentWrapper,
|
|
33
34
|
StyledCircle: () => StyledCircle,
|
|
34
35
|
StyledContainer: () => StyledContainer,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
StyledVisibleContent: () => StyledVisibleContent
|
|
36
|
+
StyledRadiusShape: () => StyledRadiusShape,
|
|
37
|
+
StyledTextWrapper: () => StyledTextWrapper
|
|
38
38
|
});
|
|
39
39
|
module.exports = __toCommonJS(styles_exports);
|
|
40
40
|
var React = __toESM(require("react"));
|
|
41
41
|
var import_ds_system = require("@elliemae/ds-system");
|
|
42
42
|
var import_ds_button_v2 = require("@elliemae/ds-button-v2");
|
|
43
|
+
var import_constants = require("./constants/index.js");
|
|
43
44
|
var import_styleHelpers = require("./utils/styleHelpers.js");
|
|
44
45
|
const focusBorders = import_ds_system.css`
|
|
45
46
|
&:focus-within {
|
|
@@ -56,23 +57,26 @@ const focusBorders = import_ds_system.css`
|
|
|
56
57
|
}
|
|
57
58
|
`;
|
|
58
59
|
const hoverStyled = import_ds_system.css`
|
|
59
|
-
background-color: ${({ checked, theme }) => {
|
|
60
|
-
if (checked) return theme.colors.brand["800"];
|
|
60
|
+
background-color: ${({ $checked, theme }) => {
|
|
61
|
+
if ($checked) return theme.colors.brand["800"];
|
|
61
62
|
return theme.colors.neutral["600"];
|
|
62
63
|
}};
|
|
63
64
|
|
|
64
|
-
border-color: ${({ checked, theme }) => {
|
|
65
|
-
if (checked) return theme.colors.brand["800"];
|
|
65
|
+
border-color: ${({ $checked, theme }) => {
|
|
66
|
+
if ($checked) return theme.colors.brand["800"];
|
|
66
67
|
return theme.colors.neutral["700"];
|
|
67
68
|
}};
|
|
68
69
|
`;
|
|
69
|
-
const StyledContainer = (0, import_ds_system.styled)("div"
|
|
70
|
+
const StyledContainer = (0, import_ds_system.styled)("div", {
|
|
71
|
+
name: import_constants.DSControlledToggleName,
|
|
72
|
+
slot: import_constants.CONTROLLED_TOGGLE_SLOTS.CONTROLLED_CONTAINER
|
|
73
|
+
})`
|
|
70
74
|
display: inline-flex;
|
|
71
75
|
width: fit-content;
|
|
72
76
|
justify-content: center;
|
|
73
77
|
align-items: center;
|
|
74
|
-
height: ${({ size }) => import_styleHelpers.containerHeight[size]};
|
|
75
|
-
border-radius: ${({ size }) => import_styleHelpers.borderRadius[size]};
|
|
78
|
+
height: ${({ $size }) => import_styleHelpers.containerHeight[$size]};
|
|
79
|
+
border-radius: ${({ $size }) => import_styleHelpers.borderRadius[$size]};
|
|
76
80
|
outline: none;
|
|
77
81
|
position: relative;
|
|
78
82
|
z-index: 0;
|
|
@@ -80,57 +84,67 @@ const StyledContainer = (0, import_ds_system.styled)("div")`
|
|
|
80
84
|
${({ disabled }) => !disabled && focusBorders};
|
|
81
85
|
${import_ds_system.xStyledCommonProps}
|
|
82
86
|
`;
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
87
|
+
const StyledRadiusShape = (0, import_ds_system.styled)("div", {
|
|
88
|
+
name: import_constants.DSControlledToggleName,
|
|
89
|
+
slot: import_constants.CONTROLLED_TOGGLE_SLOTS.CONTAINER_WITH_RADIUS_SHAPE
|
|
90
|
+
})`
|
|
91
|
+
width: ${({ $width, $size }) => $width ? `calc(${$width}px + ${import_styleHelpers.margin[$size]})` : "auto"};
|
|
92
|
+
height: ${({ $size }) => import_styleHelpers.labelHeight[$size]};
|
|
86
93
|
z-index: 2;
|
|
87
94
|
outline: none;
|
|
88
|
-
border-radius: ${({ size }) => import_styleHelpers.labelHeight[size]};
|
|
95
|
+
border-radius: ${({ $size }) => import_styleHelpers.labelHeight[$size]};
|
|
89
96
|
`;
|
|
90
|
-
const
|
|
97
|
+
const StyledButtonContentWrapper = (0, import_ds_system.styled)("div", {
|
|
98
|
+
name: import_constants.DSControlledToggleName,
|
|
99
|
+
slot: import_constants.CONTROLLED_TOGGLE_SLOTS.BUTTON_CONTENT_WRAPPER
|
|
100
|
+
})`
|
|
91
101
|
display: flex;
|
|
92
102
|
margin: 0;
|
|
93
103
|
padding: 0;
|
|
94
104
|
align-items: center;
|
|
95
105
|
height: 100%;
|
|
96
|
-
flex-direction: ${({ checked }) => checked ? "row-reverse" : "row"};
|
|
97
|
-
border-radius: ${({ size }) => `calc(${import_styleHelpers.labelHeight[size]} - 4px)`};
|
|
98
|
-
border: ${(props) => props
|
|
106
|
+
flex-direction: ${({ $checked }) => $checked ? "row-reverse" : "row"};
|
|
107
|
+
border-radius: ${({ $size }) => `calc(${import_styleHelpers.labelHeight[$size]} - 4px)`};
|
|
108
|
+
border: ${(props) => props.$size === "s" ? `1px solid ${(0, import_styleHelpers.getInterpolatedBorderDsToggleColorByProps)(props)}` : `
|
|
99
109
|
2px solid ${(0, import_styleHelpers.getInterpolatedBorderDsToggleColorByProps)(props)}
|
|
100
110
|
`};
|
|
101
111
|
transition: background-color 0.2s;
|
|
102
112
|
background-color: ${import_styleHelpers.getInterpolatedBgDsToggleColorByProps};
|
|
103
113
|
&:hover {
|
|
104
|
-
cursor: ${({ disabled, applyAriaDisabled, readOnly }) => (0, import_styleHelpers.handleCursors)(disabled, applyAriaDisabled, readOnly)};
|
|
105
|
-
${({ disabled, applyAriaDisabled, readOnly }) =>
|
|
114
|
+
cursor: ${({ $disabled, $applyAriaDisabled, $readOnly }) => (0, import_styleHelpers.handleCursors)($disabled, $applyAriaDisabled, $readOnly)};
|
|
115
|
+
${({ $disabled, $applyAriaDisabled, $readOnly }) => !$disabled && !$applyAriaDisabled && !$readOnly && hoverStyled}
|
|
106
116
|
}
|
|
107
117
|
`;
|
|
108
|
-
const StyledCircle = import_ds_system.styled
|
|
109
|
-
|
|
110
|
-
|
|
118
|
+
const StyledCircle = (0, import_ds_system.styled)("div", {
|
|
119
|
+
name: import_constants.DSControlledToggleName,
|
|
120
|
+
slot: import_constants.CONTROLLED_TOGGLE_SLOTS.CIRCLE
|
|
121
|
+
})`
|
|
122
|
+
height: ${({ $size }) => import_styleHelpers.circleValues[$size]};
|
|
123
|
+
width: ${({ $size }) => import_styleHelpers.circleValues[$size]};
|
|
111
124
|
border-radius: 50%;
|
|
112
|
-
background-color: ${({ theme, readOnly }) => readOnly ? theme.colors.neutral[100] : theme.colors.neutral["000"]};
|
|
125
|
+
background-color: ${({ theme, $readOnly, $applyAriaDisabled }) => $readOnly || $applyAriaDisabled ? theme.colors.neutral[100] : theme.colors.neutral["000"]};
|
|
113
126
|
`;
|
|
114
|
-
const
|
|
115
|
-
|
|
127
|
+
const StyledTextWrapper = (0, import_ds_system.styled)("div", {
|
|
128
|
+
name: import_constants.DSControlledToggleName,
|
|
129
|
+
slot: import_constants.CONTROLLED_TOGGLE_SLOTS.TEXT_WRAPPER
|
|
130
|
+
})`
|
|
116
131
|
flex-grow: 1;
|
|
117
|
-
line-height: ${({ theme, size }) => (0, import_styleHelpers.handleFontSize)(size, theme)};
|
|
118
|
-
|
|
119
|
-
justify-content: ${({ isLongerTextRendering }) => isLongerTextRendering ? "flex-start" : "center"};
|
|
120
|
-
font-size: ${({ theme, size }) => (0, import_styleHelpers.handleFontSize)(size, theme)};
|
|
132
|
+
line-height: ${({ theme, $size }) => (0, import_styleHelpers.handleFontSize)($size, theme)};
|
|
133
|
+
font-size: ${({ theme, $size }) => (0, import_styleHelpers.handleFontSize)($size, theme)};
|
|
121
134
|
font-weight: ${({ theme }) => theme.fontWeights.semibold};
|
|
122
|
-
color: ${({ theme, disabled
|
|
123
|
-
${({ isLongerTextRendering, checked }) => isLongerTextRendering && checked ? `margin-left: 6px;` : void 0}
|
|
124
|
-
${({ isLongerTextRendering, checked }) => isLongerTextRendering && !checked ? `margin-left: 4px;` : void 0}
|
|
135
|
+
color: ${({ theme, $disabled }) => $disabled ? "#5c6574" : theme.colors.neutral["000"]};
|
|
125
136
|
`;
|
|
126
|
-
const StyledButton = (0, import_ds_system.styled)(import_ds_button_v2.
|
|
137
|
+
const StyledButton = (0, import_ds_system.styled)(import_ds_button_v2.DSButtonV3, {
|
|
138
|
+
name: import_constants.DSControlledToggleName,
|
|
139
|
+
slot: import_constants.CONTROLLED_TOGGLE_SLOTS.TOGGLE_CHECKBOX
|
|
140
|
+
})`
|
|
127
141
|
margin: 0;
|
|
128
142
|
padding: 0;
|
|
129
143
|
z-index: 20;
|
|
130
144
|
border-radius: 20px;
|
|
131
145
|
`;
|
|
132
146
|
const SetLabelWidth = import_ds_system.styled.div`
|
|
133
|
-
font-size: ${({ theme, size }) => (0, import_styleHelpers.handleFontSize)(size, theme)};
|
|
147
|
+
font-size: ${({ theme, $size }) => (0, import_styleHelpers.handleFontSize)($size, theme)};
|
|
134
148
|
font-weight: ${({ theme }) => theme.fontWeights.semibold};
|
|
135
149
|
width: auto;
|
|
136
150
|
position: absolute;
|
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, css, xStyledCommonProps } from '@elliemae/ds-system';\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,uBAAgD;AAChD,0BAA2B;AAE3B,0BAUO;
|
|
4
|
+
"sourcesContent": ["import { styled, css, xStyledCommonProps } from '@elliemae/ds-system';\nimport { DSButtonV3 } from '@elliemae/ds-button-v2';\nimport type { DSControlledToggleT } from './react-desc-prop-types.js';\nimport { DSControlledToggleName, CONTROLLED_TOGGLE_SLOTS } from './constants/index.js';\nimport {\n containerHeight,\n borderRadius,\n labelHeight,\n getInterpolatedBorderDsToggleColorByProps,\n getInterpolatedBgDsToggleColorByProps,\n circleValues,\n handleFontSize,\n margin,\n handleCursors,\n} from './utils/styleHelpers.js';\n\nconst focusBorders = css`\n &:focus-within {\n &:after {\n content: '';\n top: -3px;\n right: -3px;\n bottom: -3px;\n left: -3px;\n border: 2px solid ${({ theme }) => theme.colors.brand['700']};\n border-radius: 20px;\n position: absolute;\n }\n }\n`;\n\nconst hoverStyled = css<{ $checked: boolean }>`\n background-color: ${({ $checked, theme }) => {\n if ($checked) return theme.colors.brand['800'];\n return theme.colors.neutral['600'];\n }};\n\n border-color: ${({ $checked, theme }) => {\n if ($checked) return theme.colors.brand['800'];\n return theme.colors.neutral['700'];\n }};\n`;\n\ninterface StyledContainerT {\n $size: DSControlledToggleT.ToggleSize;\n disabled: boolean;\n}\nexport const StyledContainer = styled('div', {\n name: DSControlledToggleName,\n slot: CONTROLLED_TOGGLE_SLOTS.CONTROLLED_CONTAINER,\n})<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 z-index: 0;\n border: 2px solid transparent;\n ${({ disabled }) => !disabled && focusBorders};\n ${xStyledCommonProps}\n`;\ninterface StyledRadiusShapeT {\n $width: number;\n $size: DSControlledToggleT.ToggleSize;\n}\nexport const StyledRadiusShape = styled('div', {\n name: DSControlledToggleName,\n slot: CONTROLLED_TOGGLE_SLOTS.CONTAINER_WITH_RADIUS_SHAPE,\n})<StyledRadiusShapeT>`\n width: ${({ $width, $size }) => ($width ? `calc(${$width}px + ${margin[$size]})` : 'auto')};\n height: ${({ $size }) => labelHeight[$size]};\n z-index: 2;\n outline: none;\n border-radius: ${({ $size }) => labelHeight[$size]};\n`;\n\ninterface StyledButtonContentWrapperT {\n $checked: boolean;\n $size: DSControlledToggleT.ToggleSize;\n $disabled: boolean;\n $applyAriaDisabled: boolean;\n $readOnly: boolean;\n}\nexport const StyledButtonContentWrapper = styled('div', {\n name: DSControlledToggleName,\n slot: CONTROLLED_TOGGLE_SLOTS.BUTTON_CONTENT_WRAPPER,\n})<StyledButtonContentWrapperT>`\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 &:hover {\n cursor: ${({ $disabled, $applyAriaDisabled, $readOnly }) =>\n handleCursors($disabled, $applyAriaDisabled, $readOnly)};\n ${({ $disabled, $applyAriaDisabled, $readOnly }) => !$disabled && !$applyAriaDisabled && !$readOnly && hoverStyled}\n }\n`;\n\ninterface StyledCircleT {\n $size: DSControlledToggleT.ToggleSize;\n $readOnly: boolean;\n $applyAriaDisabled: boolean;\n}\nexport const StyledCircle = styled('div', {\n name: DSControlledToggleName,\n slot: CONTROLLED_TOGGLE_SLOTS.CIRCLE,\n})<StyledCircleT>`\n height: ${({ $size }) => circleValues[$size]};\n width: ${({ $size }) => circleValues[$size]};\n border-radius: 50%;\n background-color: ${({ theme, $readOnly, $applyAriaDisabled }) =>\n $readOnly || $applyAriaDisabled ? theme.colors.neutral[100] : theme.colors.neutral['000']};\n`;\n\ninterface StyledTextWrapperT {\n $size: DSControlledToggleT.ToggleSize;\n $disabled: boolean;\n}\nexport const StyledTextWrapper = styled('div', {\n name: DSControlledToggleName,\n slot: CONTROLLED_TOGGLE_SLOTS.TEXT_WRAPPER,\n})<StyledTextWrapperT>`\n flex-grow: 1;\n line-height: ${({ theme, $size }) => handleFontSize($size, theme)};\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`;\n\nexport const StyledButton = styled(DSButtonV3, {\n name: DSControlledToggleName,\n slot: CONTROLLED_TOGGLE_SLOTS.TOGGLE_CHECKBOX,\n})`\n margin: 0;\n padding: 0;\n z-index: 20;\n border-radius: 20px;\n`;\n\ninterface SetLabelWidthT {\n $size: DSControlledToggleT.ToggleSize;\n}\n/**\n * This should not be required, we are doing this to keep the wcagViolationLabelOn/wcagViolationLabelOff working\n * this calculates the width of the widest custom label and sets the width of both labels to that width to avoid layout shift on toggle\n *\n * ---\n *\n * this can be safely removed in favor of a sensible default min-width for the accessible ON/OFF labels when we can actually kill the wcagViolationLabelOn/wcagViolationLabelOff props\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": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -42,15 +42,15 @@ module.exports = __toCommonJS(styleHelpers_exports);
|
|
|
42
42
|
var React = __toESM(require("react"));
|
|
43
43
|
var import_ds_system = require("@elliemae/ds-system");
|
|
44
44
|
const getStyleState = ({
|
|
45
|
-
checked,
|
|
46
|
-
disabled,
|
|
47
|
-
applyAriaDisabled,
|
|
48
|
-
readOnly
|
|
45
|
+
$checked,
|
|
46
|
+
$disabled,
|
|
47
|
+
$applyAriaDisabled,
|
|
48
|
+
$readOnly
|
|
49
49
|
}) => {
|
|
50
|
-
if (disabled) return "disabled";
|
|
51
|
-
if (applyAriaDisabled) return "applyAriaDisabled";
|
|
52
|
-
if (readOnly) return "readOnly";
|
|
53
|
-
if (checked) return "checked";
|
|
50
|
+
if ($disabled) return "disabled";
|
|
51
|
+
if ($applyAriaDisabled) return "applyAriaDisabled";
|
|
52
|
+
if ($readOnly) return "readOnly";
|
|
53
|
+
if ($checked) return "checked";
|
|
54
54
|
return "unchecked";
|
|
55
55
|
};
|
|
56
56
|
const circleValues = {
|
|
@@ -82,17 +82,16 @@ const handleFontSize = (size, { fontSizes }) => {
|
|
|
82
82
|
switch (size) {
|
|
83
83
|
case "s":
|
|
84
84
|
return fontSizes.microText[200];
|
|
85
|
-
case "m":
|
|
86
|
-
return "15px";
|
|
87
85
|
case "l":
|
|
88
86
|
return "20px";
|
|
87
|
+
case "m":
|
|
89
88
|
default:
|
|
90
89
|
return "15px";
|
|
91
90
|
}
|
|
92
91
|
};
|
|
93
92
|
const bgColorsMap = {
|
|
94
93
|
disabled: "neutral-100",
|
|
95
|
-
applyAriaDisabled: "neutral-
|
|
94
|
+
applyAriaDisabled: "neutral-500",
|
|
96
95
|
readOnly: "neutral-500",
|
|
97
96
|
checked: "brand-600",
|
|
98
97
|
unchecked: "neutral-500"
|
|
@@ -101,7 +100,7 @@ const getInterpolatedBgDSToggleColor = (styleState, props) => import_ds_system.t
|
|
|
101
100
|
const getInterpolatedBgDsToggleColorByProps = (props) => getInterpolatedBgDSToggleColor(getStyleState(props), props);
|
|
102
101
|
const borderColorsMap = {
|
|
103
102
|
disabled: "neutral-300",
|
|
104
|
-
applyAriaDisabled: "neutral-
|
|
103
|
+
applyAriaDisabled: "neutral-500",
|
|
105
104
|
readOnly: "neutral-500",
|
|
106
105
|
checked: "brand-700",
|
|
107
106
|
unchecked: "neutral-600"
|
|
@@ -110,7 +109,7 @@ const getInterpolatedBorderDSToggleColor = (styleState, props) => import_ds_syst
|
|
|
110
109
|
const getInterpolatedBorderDsToggleColorByProps = (props) => getInterpolatedBorderDSToggleColor(getStyleState(props), props);
|
|
111
110
|
const handleCursors = (disabled, applyAriaDisabled, readOnly) => {
|
|
112
111
|
if (disabled) return "not-allowed";
|
|
113
|
-
if (applyAriaDisabled) return "
|
|
112
|
+
if (applyAriaDisabled) return "default";
|
|
114
113
|
if (readOnly) return "default";
|
|
115
114
|
return "pointer";
|
|
116
115
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/utils/styleHelpers.tsx", "../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["import { th, type PropsWithTheme } from '@elliemae/ds-system';\nimport type { DSControlledToggleT } from '../react-desc-prop-types.js';\n\ntype StyleStateT = 'disabled' | 'applyAriaDisabled' | 'readOnly' | 'checked' | 'unchecked';\n\nconst getStyleState = ({\n checked,\n disabled,\n applyAriaDisabled,\n readOnly,\n}: PropsWithTheme<{\n checked: boolean;\n disabled: boolean;\n applyAriaDisabled: boolean;\n readOnly: boolean;\n}>): StyleStateT => {\n if (disabled) return 'disabled';\n if (applyAriaDisabled) return 'applyAriaDisabled';\n if (readOnly) return 'readOnly';\n if (checked) return 'checked';\n return 'unchecked';\n};\n\nexport const circleValues = {\n s: '14px',\n m: '20px',\n l: '28px',\n};\n\nexport const margin = {\n s: '26px',\n m: '34px',\n l: '42px',\n};\n\nexport const containerHeight = {\n s: '20px',\n m: '28px',\n l: '36px',\n};\n\nexport const labelHeight = {\n s: '16px',\n m: '24px',\n l: '32px',\n};\n\nexport const borderRadius = {\n s: '16px',\n m: '20px',\n l: '22px',\n};\n\nexport const handleFontSize = (\n size: DSControlledToggleT.ToggleSize,\n { fontSizes }: PropsWithTheme['theme'],\n): string => {\n switch (size) {\n case 's':\n return fontSizes.microText[200];\n case '
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,uBAAwC;AAKxC,MAAM,gBAAgB,CAAC;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAKoB;AAClB,MAAI,
|
|
4
|
+
"sourcesContent": ["import { th, type PropsWithTheme } from '@elliemae/ds-system';\nimport type { DSControlledToggleT } from '../react-desc-prop-types.js';\n\ntype StyleStateT = 'disabled' | 'applyAriaDisabled' | 'readOnly' | 'checked' | 'unchecked';\n\nconst getStyleState = ({\n $checked,\n $disabled,\n $applyAriaDisabled,\n $readOnly,\n}: PropsWithTheme<{\n $checked: boolean;\n $disabled: boolean;\n $applyAriaDisabled: boolean;\n $readOnly: boolean;\n}>): StyleStateT => {\n if ($disabled) return 'disabled';\n if ($applyAriaDisabled) return 'applyAriaDisabled';\n if ($readOnly) return 'readOnly';\n if ($checked) return 'checked';\n return 'unchecked';\n};\n\nexport const circleValues = {\n s: '14px',\n m: '20px',\n l: '28px',\n};\n\nexport const margin = {\n s: '26px',\n m: '34px',\n l: '42px',\n};\n\nexport const containerHeight = {\n s: '20px',\n m: '28px',\n l: '36px',\n};\n\nexport const labelHeight = {\n s: '16px',\n m: '24px',\n l: '32px',\n};\n\nexport const borderRadius = {\n s: '16px',\n m: '20px',\n l: '22px',\n};\n\nexport const handleFontSize = (\n size: DSControlledToggleT.ToggleSize,\n { fontSizes }: PropsWithTheme['theme'],\n): string => {\n switch (size) {\n case 's':\n return fontSizes.microText[200];\n case 'l':\n return '20px';\n case 'm':\n default:\n return '15px';\n }\n};\n\nconst bgColorsMap = {\n disabled: 'neutral-100',\n applyAriaDisabled: 'neutral-500',\n readOnly: 'neutral-500',\n checked: 'brand-600',\n unchecked: 'neutral-500',\n} as const;\n\nconst getInterpolatedBgDSToggleColor = (styleState: StyleStateT, props: PropsWithTheme) =>\n th.color(bgColorsMap[styleState])(props);\n\nexport const getInterpolatedBgDsToggleColorByProps = (\n props: PropsWithTheme<{\n $checked: boolean;\n $disabled: boolean;\n $applyAriaDisabled: boolean;\n $readOnly: boolean;\n }>,\n) => getInterpolatedBgDSToggleColor(getStyleState(props), props);\n\nconst borderColorsMap = {\n disabled: 'neutral-300',\n applyAriaDisabled: 'neutral-500',\n readOnly: 'neutral-500',\n checked: 'brand-700',\n unchecked: 'neutral-600',\n} as const;\n\nconst getInterpolatedBorderDSToggleColor = (styleState: StyleStateT, props: PropsWithTheme) =>\n th.color(borderColorsMap[styleState])(props);\n\nexport const getInterpolatedBorderDsToggleColorByProps = (\n props: PropsWithTheme<{\n $checked: boolean;\n $disabled: boolean;\n $applyAriaDisabled: boolean;\n $readOnly: boolean;\n }>,\n) => getInterpolatedBorderDSToggleColor(getStyleState(props), props);\n\nexport const handleCursors = (disabled: boolean, applyAriaDisabled: boolean, readOnly: boolean): string => {\n if (disabled) return 'not-allowed';\n if (applyAriaDisabled) return 'default';\n if (readOnly) return 'default';\n return 'pointer';\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,uBAAwC;AAKxC,MAAM,gBAAgB,CAAC;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAKoB;AAClB,MAAI,UAAW,QAAO;AACtB,MAAI,mBAAoB,QAAO;AAC/B,MAAI,UAAW,QAAO;AACtB,MAAI,SAAU,QAAO;AACrB,SAAO;AACT;AAEO,MAAM,eAAe;AAAA,EAC1B,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AACL;AAEO,MAAM,SAAS;AAAA,EACpB,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AACL;AAEO,MAAM,kBAAkB;AAAA,EAC7B,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AACL;AAEO,MAAM,cAAc;AAAA,EACzB,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AACL;AAEO,MAAM,eAAe;AAAA,EAC1B,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AACL;AAEO,MAAM,iBAAiB,CAC5B,MACA,EAAE,UAAU,MACD;AACX,UAAQ,MAAM;AAAA,IACZ,KAAK;AACH,aAAO,UAAU,UAAU,GAAG;AAAA,IAChC,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AAAA,IACL;AACE,aAAO;AAAA,EACX;AACF;AAEA,MAAM,cAAc;AAAA,EAClB,UAAU;AAAA,EACV,mBAAmB;AAAA,EACnB,UAAU;AAAA,EACV,SAAS;AAAA,EACT,WAAW;AACb;AAEA,MAAM,iCAAiC,CAAC,YAAyB,UAC/D,oBAAG,MAAM,YAAY,UAAU,CAAC,EAAE,KAAK;AAElC,MAAM,wCAAwC,CACnD,UAMG,+BAA+B,cAAc,KAAK,GAAG,KAAK;AAE/D,MAAM,kBAAkB;AAAA,EACtB,UAAU;AAAA,EACV,mBAAmB;AAAA,EACnB,UAAU;AAAA,EACV,SAAS;AAAA,EACT,WAAW;AACb;AAEA,MAAM,qCAAqC,CAAC,YAAyB,UACnE,oBAAG,MAAM,gBAAgB,UAAU,CAAC,EAAE,KAAK;AAEtC,MAAM,4CAA4C,CACvD,UAMG,mCAAmC,cAAc,KAAK,GAAG,KAAK;AAE5D,MAAM,gBAAgB,CAAC,UAAmB,mBAA4B,aAA8B;AACzG,MAAI,SAAU,QAAO;AACrB,MAAI,kBAAmB,QAAO;AAC9B,MAAI,SAAU,QAAO;AACrB,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,99 +1,101 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { describe, useOwnerProps } from "@elliemae/ds-props-helpers";
|
|
4
|
+
import { useDSControlledToggle } from "./config/useDSControlledToggle.js";
|
|
5
|
+
import { CONTROLLED_TOGGLE_DATA_TESTID, DSControlledToggleName } from "./constants/index.js";
|
|
5
6
|
import { DSControlledTogglePropTypesSchema } from "./react-desc-prop-types.js";
|
|
6
7
|
import {
|
|
7
|
-
|
|
8
|
+
SetLabelWidth,
|
|
8
9
|
StyledButton,
|
|
9
|
-
|
|
10
|
-
StyledVisibleContent,
|
|
10
|
+
StyledButtonContentWrapper,
|
|
11
11
|
StyledCircle,
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
StyledContainer,
|
|
13
|
+
StyledRadiusShape,
|
|
14
|
+
StyledTextWrapper
|
|
14
15
|
} from "./styles.js";
|
|
15
|
-
import { DSFormToggleName } from "./DSFormToggleDefinitions.js";
|
|
16
|
-
import { useDSControlledToggle } from "./config/useDSControlledToggle.js";
|
|
17
|
-
import { AddTooltipOnReadOnly } from "./parts/AddTooltipOnReadOnly.js";
|
|
18
16
|
const DSControlledToggle = (props) => {
|
|
19
|
-
const { propsWithDefault,
|
|
20
|
-
const {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// check https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#value
|
|
32
|
-
value,
|
|
33
|
-
id: instanceUid,
|
|
34
|
-
"aria-readonly": readOnly,
|
|
35
|
-
"aria-disabled": disabled || applyAriaDisabled || readOnly,
|
|
36
|
-
"aria-checked": checked,
|
|
37
|
-
"aria-describedby": `${instanceUid}_feedback_message ${instanceUid}_error_message`,
|
|
38
|
-
readOnly,
|
|
39
|
-
disabled,
|
|
40
|
-
...globalProps,
|
|
41
|
-
type: "button",
|
|
42
|
-
buttonType: "raw",
|
|
43
|
-
onClick: handleOnClick
|
|
44
|
-
}),
|
|
45
|
-
[checked, disabled, globalProps, handleOnClick, instanceUid, readOnly, value, applyAriaDisabled]
|
|
46
|
-
);
|
|
47
|
-
useLayoutEffect(() => {
|
|
48
|
-
if (labelTextRef.current) {
|
|
49
|
-
setIsLongerTextRendering(labelTextRef.current.innerText === longerText);
|
|
50
|
-
}
|
|
51
|
-
}, [labelTextRef, longerText, checked]);
|
|
52
|
-
useLayoutEffect(() => {
|
|
53
|
-
if (widthTextRef.current) {
|
|
54
|
-
setWidth(widthTextRef.current.clientWidth);
|
|
55
|
-
}
|
|
56
|
-
}, [widthTextRef]);
|
|
17
|
+
const { propsWithDefault, xstyledProps, width, handleRefOnLabelWidth, handleRefOffLabelWidth, buttonProps } = useDSControlledToggle(props);
|
|
18
|
+
const {
|
|
19
|
+
wcagViolationLabelOn,
|
|
20
|
+
wcagViolationLabelOff,
|
|
21
|
+
checked,
|
|
22
|
+
size,
|
|
23
|
+
containerProps,
|
|
24
|
+
disabled,
|
|
25
|
+
applyAriaDisabled,
|
|
26
|
+
readOnly
|
|
27
|
+
} = propsWithDefault;
|
|
28
|
+
const { getOwnerProps, getOwnerPropsArguments } = useOwnerProps(propsWithDefault);
|
|
57
29
|
return /* @__PURE__ */ jsx(
|
|
58
30
|
StyledContainer,
|
|
59
31
|
{
|
|
60
|
-
size,
|
|
61
|
-
"data-testid":
|
|
32
|
+
$size: size,
|
|
33
|
+
"data-testid": CONTROLLED_TOGGLE_DATA_TESTID.CONTROLLED_CONTAINER,
|
|
62
34
|
...containerProps,
|
|
63
35
|
...xstyledProps,
|
|
64
36
|
disabled,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
37
|
+
getOwnerProps,
|
|
38
|
+
getOwnerPropsArguments,
|
|
39
|
+
children: /* @__PURE__ */ jsxs(
|
|
40
|
+
StyledButton,
|
|
41
|
+
{
|
|
42
|
+
...readOnly ? { "aria-readonly": "true" } : {},
|
|
43
|
+
...buttonProps,
|
|
44
|
+
getOwnerProps,
|
|
45
|
+
getOwnerPropsArguments,
|
|
46
|
+
children: [
|
|
47
|
+
/* @__PURE__ */ jsx(
|
|
48
|
+
StyledRadiusShape,
|
|
49
|
+
{
|
|
50
|
+
$size: size,
|
|
51
|
+
$width: width,
|
|
52
|
+
getOwnerProps,
|
|
53
|
+
getOwnerPropsArguments,
|
|
54
|
+
children: /* @__PURE__ */ jsxs(
|
|
55
|
+
StyledButtonContentWrapper,
|
|
56
|
+
{
|
|
57
|
+
$checked: checked,
|
|
58
|
+
$size: size,
|
|
59
|
+
$readOnly: readOnly,
|
|
60
|
+
$disabled: disabled,
|
|
61
|
+
$applyAriaDisabled: applyAriaDisabled,
|
|
62
|
+
getOwnerProps,
|
|
63
|
+
getOwnerPropsArguments,
|
|
64
|
+
children: [
|
|
65
|
+
/* @__PURE__ */ jsx(
|
|
66
|
+
StyledCircle,
|
|
67
|
+
{
|
|
68
|
+
$size: size,
|
|
69
|
+
$readOnly: readOnly,
|
|
70
|
+
$applyAriaDisabled: applyAriaDisabled,
|
|
71
|
+
getOwnerProps,
|
|
72
|
+
getOwnerPropsArguments
|
|
73
|
+
}
|
|
74
|
+
),
|
|
75
|
+
/* @__PURE__ */ jsx(
|
|
76
|
+
StyledTextWrapper,
|
|
77
|
+
{
|
|
78
|
+
$size: size,
|
|
79
|
+
$disabled: disabled,
|
|
80
|
+
getOwnerProps,
|
|
81
|
+
getOwnerPropsArguments,
|
|
82
|
+
children: checked ? wcagViolationLabelOn ?? "ON" : wcagViolationLabelOff ?? "OFF"
|
|
83
|
+
}
|
|
84
|
+
)
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
),
|
|
90
|
+
/* @__PURE__ */ jsx(SetLabelWidth, { $size: size, innerRef: handleRefOnLabelWidth, "aria-hidden": "true", children: wcagViolationLabelOn ?? "ON" }),
|
|
91
|
+
/* @__PURE__ */ jsx(SetLabelWidth, { $size: size, innerRef: handleRefOffLabelWidth, "aria-hidden": "true", children: wcagViolationLabelOff ?? "OFF" })
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
)
|
|
93
95
|
}
|
|
94
96
|
);
|
|
95
97
|
};
|
|
96
|
-
DSControlledToggle.displayName =
|
|
98
|
+
DSControlledToggle.displayName = DSControlledToggleName;
|
|
97
99
|
const DSControlledToggleWithSchema = describe(DSControlledToggle);
|
|
98
100
|
DSControlledToggleWithSchema.propTypes = DSControlledTogglePropTypesSchema;
|
|
99
101
|
export {
|
|
@@ -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
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { describe, useOwnerProps } from '@elliemae/ds-props-helpers';\nimport React from 'react';\nimport { useDSControlledToggle } from './config/useDSControlledToggle.js';\nimport { CONTROLLED_TOGGLE_DATA_TESTID, DSControlledToggleName } from './constants/index.js';\nimport { DSControlledTogglePropTypesSchema, type DSControlledToggleT } from './react-desc-prop-types.js';\nimport {\n SetLabelWidth,\n StyledButton,\n StyledButtonContentWrapper,\n StyledCircle,\n StyledContainer,\n StyledRadiusShape,\n StyledTextWrapper,\n} from './styles.js';\n\nconst DSControlledToggle: React.ComponentType<DSControlledToggleT.Props> = (props) => {\n const { propsWithDefault, xstyledProps, width, handleRefOnLabelWidth, handleRefOffLabelWidth, buttonProps } =\n useDSControlledToggle(props);\n const {\n wcagViolationLabelOn,\n wcagViolationLabelOff,\n checked,\n size,\n containerProps,\n disabled,\n applyAriaDisabled,\n readOnly,\n } = propsWithDefault;\n const { getOwnerProps, getOwnerPropsArguments } = useOwnerProps(propsWithDefault);\n\n return (\n <StyledContainer\n $size={size}\n data-testid={CONTROLLED_TOGGLE_DATA_TESTID.CONTROLLED_CONTAINER}\n {...containerProps}\n {...xstyledProps}\n disabled={disabled}\n getOwnerProps={getOwnerProps}\n getOwnerPropsArguments={getOwnerPropsArguments}\n >\n <StyledButton\n // as per morning meeting, juan said \"readOnly\" in toggle should receive aria-readonly, aria-readonly is valid for switch role, the html readonly attribute is not\n {...(readOnly ? { 'aria-readonly': 'true' } : {})}\n {...buttonProps}\n getOwnerProps={getOwnerProps}\n getOwnerPropsArguments={getOwnerPropsArguments}\n >\n <StyledRadiusShape\n $size={size}\n $width={width}\n getOwnerProps={getOwnerProps}\n getOwnerPropsArguments={getOwnerPropsArguments}\n >\n <StyledButtonContentWrapper\n $checked={checked}\n $size={size}\n $readOnly={readOnly}\n $disabled={disabled}\n $applyAriaDisabled={applyAriaDisabled}\n getOwnerProps={getOwnerProps}\n getOwnerPropsArguments={getOwnerPropsArguments}\n >\n <StyledCircle\n $size={size}\n $readOnly={readOnly}\n $applyAriaDisabled={applyAriaDisabled}\n getOwnerProps={getOwnerProps}\n getOwnerPropsArguments={getOwnerPropsArguments}\n />\n <StyledTextWrapper\n $size={size}\n $disabled={disabled}\n getOwnerProps={getOwnerProps}\n getOwnerPropsArguments={getOwnerPropsArguments}\n >\n {checked ? (wcagViolationLabelOn ?? 'ON') : (wcagViolationLabelOff ?? 'OFF')}\n </StyledTextWrapper>\n </StyledButtonContentWrapper>\n </StyledRadiusShape>\n <SetLabelWidth $size={size} innerRef={handleRefOnLabelWidth} aria-hidden=\"true\">\n {wcagViolationLabelOn ?? 'ON'}\n </SetLabelWidth>\n <SetLabelWidth $size={size} innerRef={handleRefOffLabelWidth} aria-hidden=\"true\">\n {wcagViolationLabelOff ?? 'OFF'}\n </SetLabelWidth>\n </StyledButton>\n </StyledContainer>\n );\n};\n\nDSControlledToggle.displayName = DSControlledToggleName;\nconst DSControlledToggleWithSchema = describe(DSControlledToggle);\nDSControlledToggleWithSchema.propTypes = DSControlledTogglePropTypesSchema;\n\nexport { DSControlledToggle, DSControlledToggleWithSchema };\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACqDb,SASE,KATF;AArDV,SAAS,UAAU,qBAAqB;AAExC,SAAS,6BAA6B;AACtC,SAAS,+BAA+B,8BAA8B;AACtE,SAAS,yCAAmE;AAC5E;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,MAAM,qBAAqE,CAAC,UAAU;AACpF,QAAM,EAAE,kBAAkB,cAAc,OAAO,uBAAuB,wBAAwB,YAAY,IACxG,sBAAsB,KAAK;AAC7B,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AACJ,QAAM,EAAE,eAAe,uBAAuB,IAAI,cAAc,gBAAgB;AAEhF,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO;AAAA,MACP,eAAa,8BAA8B;AAAA,MAC1C,GAAG;AAAA,MACH,GAAG;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MAEA;AAAA,QAAC;AAAA;AAAA,UAEE,GAAI,WAAW,EAAE,iBAAiB,OAAO,IAAI,CAAC;AAAA,UAC9C,GAAG;AAAA,UACJ;AAAA,UACA;AAAA,UAEA;AAAA;AAAA,cAAC;AAAA;AAAA,gBACC,OAAO;AAAA,gBACP,QAAQ;AAAA,gBACR;AAAA,gBACA;AAAA,gBAEA;AAAA,kBAAC;AAAA;AAAA,oBACC,UAAU;AAAA,oBACV,OAAO;AAAA,oBACP,WAAW;AAAA,oBACX,WAAW;AAAA,oBACX,oBAAoB;AAAA,oBACpB;AAAA,oBACA;AAAA,oBAEA;AAAA;AAAA,wBAAC;AAAA;AAAA,0BACC,OAAO;AAAA,0BACP,WAAW;AAAA,0BACX,oBAAoB;AAAA,0BACpB;AAAA,0BACA;AAAA;AAAA,sBACF;AAAA,sBACA;AAAA,wBAAC;AAAA;AAAA,0BACC,OAAO;AAAA,0BACP,WAAW;AAAA,0BACX;AAAA,0BACA;AAAA,0BAEC,oBAAW,wBAAwB,OAAS,yBAAyB;AAAA;AAAA,sBACxE;AAAA;AAAA;AAAA,gBACF;AAAA;AAAA,YACF;AAAA,YACA,oBAAC,iBAAc,OAAO,MAAM,UAAU,uBAAuB,eAAY,QACtE,kCAAwB,MAC3B;AAAA,YACA,oBAAC,iBAAc,OAAO,MAAM,UAAU,wBAAwB,eAAY,QACvE,mCAAyB,OAC5B;AAAA;AAAA;AAAA,MACF;AAAA;AAAA,EACF;AAEJ;AAEA,mBAAmB,cAAc;AACjC,MAAM,+BAA+B,SAAS,kBAAkB;AAChE,6BAA6B,YAAY;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import React2, { useCallback } from "react";
|
|
3
2
|
import { useGetGlobalAttributes, useGetXstyledProps, useMemoMergePropsWithDefault } from "@elliemae/ds-props-helpers";
|
|
3
|
+
import React2, { useCallback } from "react";
|
|
4
4
|
import { uid } from "uid";
|
|
5
5
|
import { DSControlledTogglePropTypes, defaultProps } from "../react-desc-prop-types.js";
|
|
6
|
+
import { useGetButtonProps } from "./useGetButtonProps.js";
|
|
7
|
+
import { useGetWidestLabelWidth } from "./useGetWidestLabelWidth.js";
|
|
6
8
|
import { useValidateProps } from "./useValidateProps.js";
|
|
7
9
|
const useDSControlledToggle = (propsFromUser) => {
|
|
8
10
|
const propsWithDefault = useMemoMergePropsWithDefault(propsFromUser, defaultProps);
|
|
@@ -23,15 +25,36 @@ const useDSControlledToggle = (propsFromUser) => {
|
|
|
23
25
|
const xstyledProps = useGetXstyledProps(propsWithDefault);
|
|
24
26
|
const { id } = propsWithDefault;
|
|
25
27
|
const instanceUid = React2.useMemo(() => id || uid(5), [id]);
|
|
28
|
+
const { width, handleRefOnLabelWidth, handleRefOffLabelWidth } = useGetWidestLabelWidth();
|
|
29
|
+
const buttonProps = useGetButtonProps({
|
|
30
|
+
handleOnClick,
|
|
31
|
+
globalProps,
|
|
32
|
+
instanceUid,
|
|
33
|
+
propsWithDefault
|
|
34
|
+
});
|
|
26
35
|
return React2.useMemo(
|
|
27
36
|
() => ({
|
|
28
37
|
propsWithDefault,
|
|
38
|
+
width,
|
|
39
|
+
handleRefOnLabelWidth,
|
|
40
|
+
handleRefOffLabelWidth,
|
|
29
41
|
globalProps,
|
|
42
|
+
buttonProps,
|
|
30
43
|
xstyledProps,
|
|
31
44
|
instanceUid,
|
|
32
45
|
handleOnClick
|
|
33
46
|
}),
|
|
34
|
-
[
|
|
47
|
+
[
|
|
48
|
+
propsWithDefault,
|
|
49
|
+
width,
|
|
50
|
+
handleRefOnLabelWidth,
|
|
51
|
+
handleRefOffLabelWidth,
|
|
52
|
+
globalProps,
|
|
53
|
+
buttonProps,
|
|
54
|
+
xstyledProps,
|
|
55
|
+
instanceUid,
|
|
56
|
+
handleOnClick
|
|
57
|
+
]
|
|
35
58
|
);
|
|
36
59
|
};
|
|
37
60
|
export {
|