@chayns-components/core 5.0.0-beta.1187 → 5.0.0-beta.1189
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/lib/cjs/components/checkbox/Checkbox.js +26 -6
- package/lib/cjs/components/checkbox/Checkbox.js.map +1 -1
- package/lib/cjs/components/checkbox/Checkbox.styles.js +17 -21
- package/lib/cjs/components/checkbox/Checkbox.styles.js.map +1 -1
- package/lib/cjs/utils/calculate.js +13 -6
- package/lib/cjs/utils/calculate.js.map +1 -1
- package/lib/esm/components/checkbox/Checkbox.js +27 -8
- package/lib/esm/components/checkbox/Checkbox.js.map +1 -1
- package/lib/esm/components/checkbox/Checkbox.styles.js +16 -20
- package/lib/esm/components/checkbox/Checkbox.styles.js.map +1 -1
- package/lib/esm/utils/calculate.js +13 -6
- package/lib/esm/utils/calculate.js.map +1 -1
- package/lib/types/components/checkbox/Checkbox.styles.d.ts +5 -1
- package/lib/types/utils/calculate.d.ts +5 -1
- package/package.json +2 -2
- package/lib/cjs/utils/checkBox.js +0 -29
- package/lib/cjs/utils/checkBox.js.map +0 -1
- package/lib/esm/utils/checkBox.js +0 -22
- package/lib/esm/utils/checkBox.js.map +0 -1
- package/lib/types/utils/checkBox.d.ts +0 -1
|
@@ -20,6 +20,9 @@ const Checkbox = ({
|
|
|
20
20
|
shouldChangeOnLabelClick = true
|
|
21
21
|
}) => {
|
|
22
22
|
const [isActive, setIsActive] = (0, _react.useState)(isChecked ?? false);
|
|
23
|
+
const [checkboxTop, setCheckboxTop] = (0, _react.useState)(undefined);
|
|
24
|
+
const checkboxBoxRef = (0, _react.useRef)(null);
|
|
25
|
+
const checkboxRootRef = (0, _react.useRef)(null);
|
|
23
26
|
const handleChange = (0, _react.useCallback)(event => {
|
|
24
27
|
setIsActive(event.target.checked);
|
|
25
28
|
if (typeof onChange === 'function') {
|
|
@@ -27,23 +30,40 @@ const Checkbox = ({
|
|
|
27
30
|
}
|
|
28
31
|
}, [onChange]);
|
|
29
32
|
const uuid = (0, _uuid.useUuid)();
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
(0, _react.useEffect)(() => {
|
|
34
|
+
if (checkboxRootRef.current && !shouldShowCentered) {
|
|
35
|
+
var _checkboxBoxRef$curre;
|
|
36
|
+
const singleLineHeight = (0, _calculate.getHeightOfSingleTextLine)({
|
|
37
|
+
container: checkboxRootRef.current
|
|
38
|
+
});
|
|
39
|
+
const boxHeight = ((_checkboxBoxRef$curre = checkboxBoxRef.current) === null || _checkboxBoxRef$curre === void 0 ? void 0 : _checkboxBoxRef$curre.getBoundingClientRect().height) ?? 0;
|
|
40
|
+
setCheckboxTop((singleLineHeight - boxHeight) / 2);
|
|
41
|
+
}
|
|
42
|
+
}, [shouldShowCentered]);
|
|
43
|
+
return /*#__PURE__*/_react.default.createElement(_Checkbox.StyledCheckbox, {
|
|
44
|
+
ref: checkboxRootRef
|
|
45
|
+
}, /*#__PURE__*/_react.default.createElement(_Checkbox.StyledCheckboxInput, {
|
|
32
46
|
checked: isChecked,
|
|
33
47
|
disabled: isDisabled,
|
|
34
48
|
id: uuid,
|
|
35
49
|
onChange: handleChange,
|
|
36
50
|
type: "checkbox"
|
|
37
|
-
}), /*#__PURE__*/_react.default.createElement(_Checkbox.
|
|
51
|
+
}), /*#__PURE__*/_react.default.createElement(_Checkbox.StyledCheckboxBoxWrapper, {
|
|
52
|
+
style: {
|
|
53
|
+
top: shouldShowCentered ? '50%' : checkboxTop,
|
|
54
|
+
transform: shouldShowCentered ? 'translateY(-50%)' : undefined
|
|
55
|
+
}
|
|
56
|
+
}, /*#__PURE__*/_react.default.createElement(_Checkbox.StyledCheckboxBox, {
|
|
38
57
|
htmlFor: uuid,
|
|
58
|
+
ref: checkboxBoxRef,
|
|
39
59
|
$isChecked: isChecked ?? isActive,
|
|
40
60
|
$isDisabled: isDisabled,
|
|
41
|
-
$shouldShowAsSwitch: shouldShowAsSwitch
|
|
42
|
-
|
|
43
|
-
}), /*#__PURE__*/_react.default.createElement(_Checkbox.StyledCheckboxLabel, {
|
|
61
|
+
$shouldShowAsSwitch: shouldShowAsSwitch
|
|
62
|
+
})), /*#__PURE__*/_react.default.createElement(_Checkbox.StyledCheckboxLabel, {
|
|
44
63
|
className: labelClassName,
|
|
45
64
|
$isDisabled: isDisabled,
|
|
46
65
|
$shouldChangeOnLabelClick: shouldChangeOnLabelClick,
|
|
66
|
+
$shouldShowAsSwitch: shouldShowAsSwitch,
|
|
47
67
|
htmlFor: shouldChangeOnLabelClick ? uuid : undefined
|
|
48
68
|
}, children));
|
|
49
69
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.js","names":["_react","_interopRequireWildcard","require","_uuid","_calculate","_Checkbox","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","Checkbox","children","isChecked","isDisabled","labelClassName","onChange","shouldShowAsSwitch","shouldShowCentered","shouldChangeOnLabelClick","isActive","setIsActive","useState","handleChange","useCallback","event","target","checked","uuid","useUuid","
|
|
1
|
+
{"version":3,"file":"Checkbox.js","names":["_react","_interopRequireWildcard","require","_uuid","_calculate","_Checkbox","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","Checkbox","children","isChecked","isDisabled","labelClassName","onChange","shouldShowAsSwitch","shouldShowCentered","shouldChangeOnLabelClick","isActive","setIsActive","useState","checkboxTop","setCheckboxTop","undefined","checkboxBoxRef","useRef","checkboxRootRef","handleChange","useCallback","event","target","checked","uuid","useUuid","useEffect","current","_checkboxBoxRef$curre","singleLineHeight","getHeightOfSingleTextLine","container","boxHeight","getBoundingClientRect","height","createElement","StyledCheckbox","ref","StyledCheckboxInput","disabled","id","type","StyledCheckboxBoxWrapper","style","top","transform","StyledCheckboxBox","htmlFor","$isChecked","$isDisabled","$shouldShowAsSwitch","StyledCheckboxLabel","className","$shouldChangeOnLabelClick","displayName","_default","exports"],"sources":["../../../../src/components/checkbox/Checkbox.tsx"],"sourcesContent":["import React, {\n ChangeEvent,\n ChangeEventHandler,\n FC,\n ReactElement,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from 'react';\nimport { useUuid } from '../../hooks/uuid';\nimport { getHeightOfSingleTextLine } from '../../utils/calculate';\nimport {\n StyledCheckbox,\n StyledCheckboxBox,\n StyledCheckboxBoxWrapper,\n StyledCheckboxInput,\n StyledCheckboxLabel,\n} from './Checkbox.styles';\n\nexport type CheckboxProps = {\n /**\n * Text for checkbox or switch\n */\n children?: ReactElement | string;\n /**\n * Indicates whether the checkbox or switch is selected\n */\n isChecked?: boolean;\n /**\n * Disables the checkbox or switch so it cannot be toggled\n */\n isDisabled?: boolean;\n /**\n * Classname for the label\n */\n labelClassName?: string;\n /**\n * Function to be executed if the checked value changes\n */\n onChange?: ChangeEventHandler<HTMLInputElement>;\n /**\n * Whether the label should change the state of the checkbox\n */\n shouldChangeOnLabelClick?: boolean;\n /**\n * Changes the design to use switch instead of checkbox\n */\n shouldShowAsSwitch?: boolean;\n /**\n * Whether the Checkbox should be displayed centered to the label or at the top\n */\n shouldShowCentered?: boolean;\n};\n\nconst Checkbox: FC<CheckboxProps> = ({\n children,\n isChecked,\n isDisabled,\n labelClassName,\n onChange,\n shouldShowAsSwitch,\n shouldShowCentered = false,\n shouldChangeOnLabelClick = true,\n}) => {\n const [isActive, setIsActive] = useState(isChecked ?? false);\n const [checkboxTop, setCheckboxTop] = useState<number | undefined>(undefined);\n\n const checkboxBoxRef = useRef<HTMLLabelElement>(null);\n const checkboxRootRef = useRef<HTMLDivElement>(null);\n\n const handleChange = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n setIsActive(event.target.checked);\n\n if (typeof onChange === 'function') {\n onChange(event);\n }\n },\n [onChange],\n );\n\n const uuid = useUuid();\n\n useEffect(() => {\n if (checkboxRootRef.current && !shouldShowCentered) {\n const singleLineHeight = getHeightOfSingleTextLine({\n container: checkboxRootRef.current,\n });\n\n const boxHeight = checkboxBoxRef.current?.getBoundingClientRect().height ?? 0;\n\n setCheckboxTop((singleLineHeight - boxHeight) / 2);\n }\n }, [shouldShowCentered]);\n\n return (\n <StyledCheckbox ref={checkboxRootRef}>\n <StyledCheckboxInput\n checked={isChecked}\n disabled={isDisabled}\n id={uuid}\n onChange={handleChange}\n type=\"checkbox\"\n />\n <StyledCheckboxBoxWrapper\n style={{\n top: shouldShowCentered ? '50%' : checkboxTop,\n transform: shouldShowCentered ? 'translateY(-50%)' : undefined,\n }}\n >\n <StyledCheckboxBox\n htmlFor={uuid}\n ref={checkboxBoxRef}\n $isChecked={isChecked ?? isActive}\n $isDisabled={isDisabled}\n $shouldShowAsSwitch={shouldShowAsSwitch}\n />\n </StyledCheckboxBoxWrapper>\n <StyledCheckboxLabel\n className={labelClassName}\n $isDisabled={isDisabled}\n $shouldChangeOnLabelClick={shouldChangeOnLabelClick}\n $shouldShowAsSwitch={shouldShowAsSwitch}\n htmlFor={shouldChangeOnLabelClick ? uuid : undefined}\n >\n {children}\n </StyledCheckboxLabel>\n </StyledCheckbox>\n );\n};\n\nCheckbox.displayName = 'Checkbox';\n\nexport default Checkbox;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAUA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AAM2B,SAAAD,wBAAAK,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAP,uBAAA,YAAAA,CAAAK,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA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AAA,CAAA2C,aAAA,CAACtD,SAAA,CAAAiE,iBAAiB;IACdC,OAAO,EAAEvB,IAAK;IACda,GAAG,EAAErB,cAAe;IACpBgC,UAAU,EAAE7C,SAAS,IAAIO,QAAS;IAClCuC,WAAW,EAAE7C,UAAW;IACxB8C,mBAAmB,EAAE3C;EAAmB,CAC3C,CACqB,CAAC,eAC3B/B,MAAA,CAAAgB,OAAA,CAAA2C,aAAA,CAACtD,SAAA,CAAAsE,mBAAmB;IAChBC,SAAS,EAAE/C,cAAe;IAC1B4C,WAAW,EAAE7C,UAAW;IACxBiD,yBAAyB,EAAE5C,wBAAyB;IACpDyC,mBAAmB,EAAE3C,kBAAmB;IACxCwC,OAAO,EAAEtC,wBAAwB,GAAGe,IAAI,GAAGT;EAAU,GAEpDb,QACgB,CACT,CAAC;AAEzB,CAAC;AAEDD,QAAQ,CAACqD,WAAW,GAAG,UAAU;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAhE,OAAA,GAEnBS,QAAQ","ignoreList":[]}
|
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.StyledCheckboxLabel = exports.StyledCheckboxInput = exports.StyledCheckboxBox = exports.StyledCheckbox = void 0;
|
|
6
|
+
exports.StyledCheckboxLabel = exports.StyledCheckboxInput = exports.StyledCheckboxBoxWrapper = exports.StyledCheckboxBox = exports.StyledCheckbox = void 0;
|
|
7
7
|
var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
8
|
-
var _checkBox = require("../../utils/checkBox");
|
|
9
8
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
10
9
|
const StyledCheckbox = exports.StyledCheckbox = _styledComponents.default.div`
|
|
11
10
|
align-items: center;
|
|
@@ -17,6 +16,12 @@ const StyledCheckbox = exports.StyledCheckbox = _styledComponents.default.div`
|
|
|
17
16
|
const StyledCheckboxInput = exports.StyledCheckboxInput = _styledComponents.default.input`
|
|
18
17
|
display: none;
|
|
19
18
|
`;
|
|
19
|
+
const StyledCheckboxBoxWrapper = exports.StyledCheckboxBoxWrapper = _styledComponents.default.div`
|
|
20
|
+
display: flex;
|
|
21
|
+
flex-shrink: 0;
|
|
22
|
+
height: 16px;
|
|
23
|
+
position: absolute;
|
|
24
|
+
`;
|
|
20
25
|
const StyledCheckboxBox = exports.StyledCheckboxBox = _styledComponents.default.label`
|
|
21
26
|
color: ${({
|
|
22
27
|
theme
|
|
@@ -27,9 +32,7 @@ const StyledCheckboxBox = exports.StyledCheckboxBox = _styledComponents.default.
|
|
|
27
32
|
opacity: ${({
|
|
28
33
|
$isDisabled
|
|
29
34
|
}) => $isDisabled ? 0.5 : 1};
|
|
30
|
-
|
|
31
|
-
$shouldShowAsSwitch
|
|
32
|
-
}) => $shouldShowAsSwitch ? '48px' : '20px'};
|
|
35
|
+
position: relative;
|
|
33
36
|
transition: opacity 0.2s ease;
|
|
34
37
|
user-select: none;
|
|
35
38
|
height: 16px;
|
|
@@ -37,16 +40,14 @@ const StyledCheckboxBox = exports.StyledCheckboxBox = _styledComponents.default.
|
|
|
37
40
|
&:after {
|
|
38
41
|
${({
|
|
39
42
|
$isChecked,
|
|
40
|
-
$shouldShowAsSwitch
|
|
41
|
-
$lineHeight,
|
|
42
|
-
theme
|
|
43
|
+
$shouldShowAsSwitch
|
|
43
44
|
}) => $shouldShowAsSwitch ? (0, _styledComponents.css)`
|
|
44
45
|
background-color: white;
|
|
45
46
|
border-radius: 50%;
|
|
46
47
|
box-shadow: 0 1px 4px rgb(0 0 0 / 35%);
|
|
47
48
|
height: 16px;
|
|
48
49
|
left: 7px;
|
|
49
|
-
top:
|
|
50
|
+
top: 50%;
|
|
50
51
|
transform: translateX(${$isChecked ? '18px' : 0}) translateY(-50%);
|
|
51
52
|
transition: transform 0.2s ease;
|
|
52
53
|
width: 16px;
|
|
@@ -56,10 +57,10 @@ const StyledCheckboxBox = exports.StyledCheckboxBox = _styledComponents.default.
|
|
|
56
57
|
height: 10px;
|
|
57
58
|
left: 2px;
|
|
58
59
|
opacity: ${$isChecked ? 1 : 0};
|
|
59
|
-
top:
|
|
60
|
+
top: calc(50% - 2px);
|
|
60
61
|
transform: rotateZ(37deg) translateY(-50%);
|
|
61
62
|
transition: opacity 0.2s ease;
|
|
62
|
-
width:
|
|
63
|
+
width: 5px;
|
|
63
64
|
`}
|
|
64
65
|
|
|
65
66
|
content: ' ';
|
|
@@ -96,20 +97,12 @@ const StyledCheckboxBox = exports.StyledCheckboxBox = _styledComponents.default.
|
|
|
96
97
|
$shouldShowAsSwitch
|
|
97
98
|
}) => $shouldShowAsSwitch ? '10px' : 0};
|
|
98
99
|
position: absolute;
|
|
100
|
+
top: 50%;
|
|
101
|
+
transform: translateY(-50%);
|
|
99
102
|
transition: background-color 0.2s ease;
|
|
100
103
|
width: ${({
|
|
101
104
|
$shouldShowAsSwitch
|
|
102
105
|
}) => $shouldShowAsSwitch ? '28px' : '15px'};
|
|
103
|
-
${({
|
|
104
|
-
$lineHeight,
|
|
105
|
-
theme,
|
|
106
|
-
$shouldShowAsSwitch
|
|
107
|
-
}) => $lineHeight ? (0, _styledComponents.css)`
|
|
108
|
-
top: ${(0, _checkBox.getCheckBoxPosition)(Number(theme.fontSize)) ?? 5 + ($shouldShowAsSwitch ? 1 : 0)}px;
|
|
109
|
-
` : (0, _styledComponents.css)`
|
|
110
|
-
top: 50%;
|
|
111
|
-
transform: translateY(-50%);
|
|
112
|
-
`}
|
|
113
106
|
}
|
|
114
107
|
}
|
|
115
108
|
`;
|
|
@@ -123,6 +116,9 @@ const StyledCheckboxLabel = exports.StyledCheckboxLabel = _styledComponents.defa
|
|
|
123
116
|
opacity: ${({
|
|
124
117
|
$isDisabled
|
|
125
118
|
}) => $isDisabled ? 0.5 : 1};
|
|
119
|
+
padding-left: ${({
|
|
120
|
+
$shouldShowAsSwitch
|
|
121
|
+
}) => $shouldShowAsSwitch ? '48px' : '20px'};
|
|
126
122
|
transition: opacity 0.2s ease;
|
|
127
123
|
user-select: none;
|
|
128
124
|
`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.styles.js","names":["_styledComponents","_interopRequireWildcard","require","
|
|
1
|
+
{"version":3,"file":"Checkbox.styles.js","names":["_styledComponents","_interopRequireWildcard","require","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","StyledCheckbox","exports","styled","div","StyledCheckboxInput","input","StyledCheckboxBoxWrapper","StyledCheckboxBox","label","theme","text","$isDisabled","$isChecked","$shouldShowAsSwitch","css","green","red","StyledCheckboxLabel","$shouldChangeOnLabelClick"],"sources":["../../../../src/components/checkbox/Checkbox.styles.ts"],"sourcesContent":["import styled, { css } from 'styled-components';\nimport type { WithTheme } from '../color-scheme-provider/ColorSchemeProvider';\nimport type { CheckboxProps } from './Checkbox';\n\nexport const StyledCheckbox = styled.div`\n align-items: center;\n display: flex;\n position: relative;\n width: 100%;\n min-height: 20px;\n`;\n\nexport const StyledCheckboxInput = styled.input`\n display: none;\n`;\n\ntype StyledCheckboxBoxWrapperProps = WithTheme<{\n $shouldShowAsSwitch?: CheckboxProps['shouldShowAsSwitch'];\n}>;\n\nexport const StyledCheckboxBoxWrapper = styled.div<StyledCheckboxBoxWrapperProps>`\n display: flex;\n flex-shrink: 0;\n height: 16px;\n position: absolute;\n`;\n\ntype StyledCheckboxBoxProps = WithTheme<{\n $shouldShowAsSwitch?: CheckboxProps['shouldShowAsSwitch'];\n $isDisabled?: CheckboxProps['isDisabled'];\n $isChecked?: CheckboxProps['isChecked'];\n}>;\n\nexport const StyledCheckboxBox = styled.label<StyledCheckboxBoxProps>`\n color: ${({ theme }: StyledCheckboxBoxProps) => theme.text};\n cursor: ${({ $isDisabled }) => ($isDisabled ? 'default' : 'pointer')};\n opacity: ${({ $isDisabled }) => ($isDisabled ? 0.5 : 1)};\n position: relative;\n transition: opacity 0.2s ease;\n user-select: none;\n height: 16px;\n\n &:after {\n ${({ $isChecked, $shouldShowAsSwitch }: StyledCheckboxBoxProps) =>\n $shouldShowAsSwitch\n ? css`\n background-color: white;\n border-radius: 50%;\n box-shadow: 0 1px 4px rgb(0 0 0 / 35%);\n height: 16px;\n left: 7px;\n top: 50%;\n transform: translateX(${$isChecked ? '18px' : 0}) translateY(-50%);\n transition: transform 0.2s ease;\n width: 16px;\n `\n : css`\n border-right: 2px solid #fff;\n border-bottom: 2px solid #fff;\n height: 10px;\n left: 2px;\n opacity: ${$isChecked ? 1 : 0};\n top: calc(50% - 2px);\n transform: rotateZ(37deg) translateY(-50%);\n transition: opacity 0.2s ease;\n width: 5px;\n `}\n\n content: ' ';\n position: absolute;\n }\n\n &:before {\n background-color: ${({\n $isChecked,\n $shouldShowAsSwitch,\n theme,\n }: StyledCheckboxBoxProps) => {\n if ($shouldShowAsSwitch) {\n return $isChecked ? theme.green : theme.red;\n }\n\n return $isChecked ? theme['408'] : theme['403'];\n }};\n\n ${({ $shouldShowAsSwitch, theme }) =>\n !$shouldShowAsSwitch &&\n css`\n border: 1px solid rgba(${theme['409-rgb']}, 0.5);\n `}\n\n border-radius: ${({ $shouldShowAsSwitch }) => ($shouldShowAsSwitch ? '100px' : 0)};\n content: ' ';\n height: ${({ $shouldShowAsSwitch }) => ($shouldShowAsSwitch ? '13px' : '15px')};\n left: ${({ $shouldShowAsSwitch }) => ($shouldShowAsSwitch ? '10px' : 0)};\n position: absolute;\n top: 50%;\n transform: translateY(-50%);\n transition: background-color 0.2s ease;\n width: ${({ $shouldShowAsSwitch }) => ($shouldShowAsSwitch ? '28px' : '15px')};\n }\n}\n`;\n\ntype StyledCheckboxLabelProps = WithTheme<{\n $isDisabled?: CheckboxProps['isDisabled'];\n $shouldChangeOnLabelClick?: CheckboxProps['shouldChangeOnLabelClick'];\n $shouldShowAsSwitch?: CheckboxProps['shouldShowAsSwitch'];\n}>;\n\nexport const StyledCheckboxLabel = styled.label<StyledCheckboxLabelProps>`\n color: ${({ theme }: StyledCheckboxLabelProps) => theme.text};\n cursor: ${({ $shouldChangeOnLabelClick }) =>\n !$shouldChangeOnLabelClick ? 'default' : 'pointer'};\n opacity: ${({ $isDisabled }) => ($isDisabled ? 0.5 : 1)};\n padding-left: ${({ $shouldShowAsSwitch }) => ($shouldShowAsSwitch ? '48px' : '20px')};\n transition: opacity 0.2s ease;\n user-select: none;\n`;\n"],"mappings":";;;;;;AAAA,IAAAA,iBAAA,GAAAC,uBAAA,CAAAC,OAAA;AAAgD,SAAAD,wBAAAE,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAJ,uBAAA,YAAAA,CAAAE,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OA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AAC,KAAMA,mBAAmB,GAAG,MAAM,GAAG,MAAO;AACxF;AACA;AACA,CAAC","ignoreList":[]}
|
|
@@ -88,12 +88,19 @@ const calculateContentHeight = elements => {
|
|
|
88
88
|
return heights.reduce((partialSum, a) => partialSum + a, 0);
|
|
89
89
|
};
|
|
90
90
|
exports.calculateContentHeight = calculateContentHeight;
|
|
91
|
-
const getHeightOfSingleTextLine = (
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
document.
|
|
95
|
-
|
|
96
|
-
|
|
91
|
+
const getHeightOfSingleTextLine = ({
|
|
92
|
+
container
|
|
93
|
+
}) => {
|
|
94
|
+
const div = document.createElement('div');
|
|
95
|
+
div.style.visibility = 'hidden';
|
|
96
|
+
div.style.position = 'absolute';
|
|
97
|
+
div.style.whiteSpace = 'nowrap';
|
|
98
|
+
div.innerText = 'Single text line';
|
|
99
|
+
container.appendChild(div);
|
|
100
|
+
const {
|
|
101
|
+
height
|
|
102
|
+
} = div.getBoundingClientRect();
|
|
103
|
+
container.removeChild(div);
|
|
97
104
|
return height;
|
|
98
105
|
};
|
|
99
106
|
exports.getHeightOfSingleTextLine = getHeightOfSingleTextLine;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculate.js","names":["_chaynsApi","require","_react","_interopRequireDefault","_server","_ColorSchemeProvider","e","__esModule","default","calculateContentWidth","list","functions","values","length","forEach","suffixElement","text","textStyles","tagName","styles","div","document","createElement","Object","assign","style","display","gap","position","visibility","whiteSpace","width","body","appendChild","innerText","innerHTML","renderToString","ChaynsProvider","data","isModule","color","colorMode","push","offsetWidth","removeChild","Math","max","apply","exports","calculateBiggestWidth","elements","container","padding","id","element","accessKey","calculateContentHeight","heights","offsetHeight","reduce","partialSum","a","getHeightOfSingleTextLine","
|
|
1
|
+
{"version":3,"file":"calculate.js","names":["_chaynsApi","require","_react","_interopRequireDefault","_server","_ColorSchemeProvider","e","__esModule","default","calculateContentWidth","list","functions","values","length","forEach","suffixElement","text","textStyles","tagName","styles","div","document","createElement","Object","assign","style","display","gap","position","visibility","whiteSpace","width","body","appendChild","innerText","innerHTML","renderToString","ChaynsProvider","data","isModule","color","colorMode","push","offsetWidth","removeChild","Math","max","apply","exports","calculateBiggestWidth","elements","container","padding","id","element","accessKey","calculateContentHeight","heights","offsetHeight","reduce","partialSum","a","getHeightOfSingleTextLine","height","getBoundingClientRect","getMaxHeightInPixels","maxHeight","rootElement","tempElement"],"sources":["../../../src/utils/calculate.tsx"],"sourcesContent":["import { ChaynsProvider, ChaynsReactFunctions, ChaynsReactValues } from 'chayns-api';\nimport React, { type CSSProperties } from 'react';\nimport { renderToString } from 'react-dom/server';\nimport ColorSchemeProvider from '../components/color-scheme-provider/ColorSchemeProvider';\nimport type { IComboBoxItem } from '../components/combobox/ComboBox';\nimport type { SliderButtonItem } from '../types/slider-button';\n\nexport const calculateContentWidth = (\n list: IComboBoxItem[],\n functions: ChaynsReactFunctions,\n values: ChaynsReactValues,\n) => {\n const length: number[] = [];\n\n list.forEach(({ suffixElement, text, textStyles }) => {\n const tagName = textStyles?.tagName ?? 'div';\n const styles = textStyles?.styles;\n\n const div = document.createElement(tagName);\n\n if (styles) {\n Object.assign(div.style, styles);\n }\n\n div.style.display = 'flex';\n div.style.gap = '10px';\n div.style.position = 'absolute';\n div.style.visibility = 'hidden';\n div.style.whiteSpace = 'nowrap';\n div.style.width = 'auto';\n\n document.body.appendChild(div);\n\n div.innerText = text;\n\n if (suffixElement) {\n // ColorSchemeProvider is used to prevent missing scheme context error.\n // Due to the fact that the element is never rendered visible, the values are irrelevant.\n div.innerHTML += renderToString(\n <ChaynsProvider data={values} functions={functions} isModule>\n <ColorSchemeProvider color=\"#005EB8\" colorMode={0}>\n {suffixElement}\n </ColorSchemeProvider>\n </ChaynsProvider>,\n );\n }\n\n length.push(div.offsetWidth);\n\n document.body.removeChild(div);\n });\n\n return Math.max.apply(null, length);\n};\n\nexport const calculateBiggestWidth = (elements: SliderButtonItem[]) => {\n const container = document.createElement('div');\n\n container.style.visibility = 'hidden';\n container.style.position = 'absolute';\n container.style.width = 'auto';\n container.style.whiteSpace = 'nowrap';\n container.style.padding = '7px 12px';\n container.style.display = 'block';\n\n elements.forEach(({ text, id }) => {\n const element = document.createElement('div');\n\n element.accessKey = `slider-button-pseudo--${id}`;\n element.innerText = text;\n\n container.appendChild(element);\n });\n\n document.body.appendChild(container);\n\n const width = container.offsetWidth;\n\n document.body.removeChild(container);\n\n return width;\n};\n\nexport const calculateContentHeight = (elements: string[]) => {\n const heights: number[] = [];\n\n elements.forEach((element: string) => {\n const div = document.createElement('div');\n\n div.style.visibility = 'hidden';\n div.style.position = 'absolute';\n div.style.width = 'auto';\n div.style.padding = '4px 10px';\n div.style.whiteSpace = 'nowrap';\n\n document.body.appendChild(div);\n\n div.innerText = element;\n\n heights.push(div.offsetHeight);\n\n document.body.removeChild(div);\n });\n\n return heights.reduce((partialSum, a) => partialSum + a, 0);\n};\n\ninterface GetHeightOfSingleTextLineOptions {\n container: Element;\n}\n\nexport const getHeightOfSingleTextLine = ({ container }: GetHeightOfSingleTextLineOptions) => {\n const div = document.createElement('div');\n\n div.style.visibility = 'hidden';\n div.style.position = 'absolute';\n div.style.whiteSpace = 'nowrap';\n\n div.innerText = 'Single text line';\n\n container.appendChild(div);\n\n const { height } = div.getBoundingClientRect();\n\n container.removeChild(div);\n\n return height;\n};\n\nexport const getMaxHeightInPixels = (\n maxHeight: CSSProperties['maxHeight'],\n rootElement: Element,\n): number => {\n const tempElement = document.createElement('div');\n\n tempElement.style.position = 'absolute';\n tempElement.style.visibility = 'hidden';\n tempElement.style.height = '100vh';\n tempElement.style.maxHeight = maxHeight as string;\n\n rootElement.appendChild(tempElement);\n\n const { height } = tempElement.getBoundingClientRect();\n\n rootElement.removeChild(tempElement);\n\n return height;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,OAAA,GAAA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,KAAK,CAAC;EAEzCF,GAAG,CAACK,KAAK,CAACI,UAAU,GAAG,QAAQ;EAC/BT,GAAG,CAACK,KAAK,CAACG,QAAQ,GAAG,UAAU;EAC/BR,GAAG,CAACK,KAAK,CAACK,UAAU,GAAG,QAAQ;EAE/BV,GAAG,CAACc,SAAS,GAAG,kBAAkB;EAElCiB,SAAS,CAAClB,WAAW,CAACb,GAAG,CAAC;EAE1B,MAAM;IAAE2C;EAAO,CAAC,GAAG3C,GAAG,CAAC4C,qBAAqB,CAAC,CAAC;EAE9Cb,SAAS,CAACP,WAAW,CAACxB,GAAG,CAAC;EAE1B,OAAO2C,MAAM;AACjB,CAAC;AAACf,OAAA,CAAAc,yBAAA,GAAAA,yBAAA;AAEK,MAAMG,oBAAoB,GAAGA,CAChCC,SAAqC,EACrCC,WAAoB,KACX;EACT,MAAMC,WAAW,GAAG/C,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;EAEjD8C,WAAW,CAAC3C,KAAK,CAACG,QAAQ,GAAG,UAAU;EACvCwC,WAAW,CAAC3C,KAAK,CAACI,UAAU,GAAG,QAAQ;EACvCuC,WAAW,CAAC3C,KAAK,CAACsC,MAAM,GAAG,OAAO;EAClCK,WAAW,CAAC3C,KAAK,CAACyC,SAAS,GAAGA,SAAmB;EAEjDC,WAAW,CAAClC,WAAW,CAACmC,WAAW,CAAC;EAEpC,MAAM;IAAEL;EAAO,CAAC,GAAGK,WAAW,CAACJ,qBAAqB,CAAC,CAAC;EAEtDG,WAAW,CAACvB,WAAW,CAACwB,WAAW,CAAC;EAEpC,OAAOL,MAAM;AACjB,CAAC;AAACf,OAAA,CAAAiB,oBAAA,GAAAA,oBAAA","ignoreList":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import React, { useCallback,
|
|
1
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { useUuid } from '../../hooks/uuid';
|
|
3
3
|
import { getHeightOfSingleTextLine } from '../../utils/calculate';
|
|
4
|
-
import { StyledCheckbox, StyledCheckboxBox, StyledCheckboxInput, StyledCheckboxLabel } from './Checkbox.styles';
|
|
4
|
+
import { StyledCheckbox, StyledCheckboxBox, StyledCheckboxBoxWrapper, StyledCheckboxInput, StyledCheckboxLabel } from './Checkbox.styles';
|
|
5
5
|
const Checkbox = ({
|
|
6
6
|
children,
|
|
7
7
|
isChecked,
|
|
@@ -13,6 +13,9 @@ const Checkbox = ({
|
|
|
13
13
|
shouldChangeOnLabelClick = true
|
|
14
14
|
}) => {
|
|
15
15
|
const [isActive, setIsActive] = useState(isChecked ?? false);
|
|
16
|
+
const [checkboxTop, setCheckboxTop] = useState(undefined);
|
|
17
|
+
const checkboxBoxRef = useRef(null);
|
|
18
|
+
const checkboxRootRef = useRef(null);
|
|
16
19
|
const handleChange = useCallback(event => {
|
|
17
20
|
setIsActive(event.target.checked);
|
|
18
21
|
if (typeof onChange === 'function') {
|
|
@@ -20,23 +23,39 @@ const Checkbox = ({
|
|
|
20
23
|
}
|
|
21
24
|
}, [onChange]);
|
|
22
25
|
const uuid = useUuid();
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (checkboxRootRef.current && !shouldShowCentered) {
|
|
28
|
+
const singleLineHeight = getHeightOfSingleTextLine({
|
|
29
|
+
container: checkboxRootRef.current
|
|
30
|
+
});
|
|
31
|
+
const boxHeight = checkboxBoxRef.current?.getBoundingClientRect().height ?? 0;
|
|
32
|
+
setCheckboxTop((singleLineHeight - boxHeight) / 2);
|
|
33
|
+
}
|
|
34
|
+
}, [shouldShowCentered]);
|
|
35
|
+
return /*#__PURE__*/React.createElement(StyledCheckbox, {
|
|
36
|
+
ref: checkboxRootRef
|
|
37
|
+
}, /*#__PURE__*/React.createElement(StyledCheckboxInput, {
|
|
25
38
|
checked: isChecked,
|
|
26
39
|
disabled: isDisabled,
|
|
27
40
|
id: uuid,
|
|
28
41
|
onChange: handleChange,
|
|
29
42
|
type: "checkbox"
|
|
30
|
-
}), /*#__PURE__*/React.createElement(
|
|
43
|
+
}), /*#__PURE__*/React.createElement(StyledCheckboxBoxWrapper, {
|
|
44
|
+
style: {
|
|
45
|
+
top: shouldShowCentered ? '50%' : checkboxTop,
|
|
46
|
+
transform: shouldShowCentered ? 'translateY(-50%)' : undefined
|
|
47
|
+
}
|
|
48
|
+
}, /*#__PURE__*/React.createElement(StyledCheckboxBox, {
|
|
31
49
|
htmlFor: uuid,
|
|
50
|
+
ref: checkboxBoxRef,
|
|
32
51
|
$isChecked: isChecked ?? isActive,
|
|
33
52
|
$isDisabled: isDisabled,
|
|
34
|
-
$shouldShowAsSwitch: shouldShowAsSwitch
|
|
35
|
-
|
|
36
|
-
}), /*#__PURE__*/React.createElement(StyledCheckboxLabel, {
|
|
53
|
+
$shouldShowAsSwitch: shouldShowAsSwitch
|
|
54
|
+
})), /*#__PURE__*/React.createElement(StyledCheckboxLabel, {
|
|
37
55
|
className: labelClassName,
|
|
38
56
|
$isDisabled: isDisabled,
|
|
39
57
|
$shouldChangeOnLabelClick: shouldChangeOnLabelClick,
|
|
58
|
+
$shouldShowAsSwitch: shouldShowAsSwitch,
|
|
40
59
|
htmlFor: shouldChangeOnLabelClick ? uuid : undefined
|
|
41
60
|
}, children));
|
|
42
61
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.js","names":["React","useCallback","
|
|
1
|
+
{"version":3,"file":"Checkbox.js","names":["React","useCallback","useEffect","useRef","useState","useUuid","getHeightOfSingleTextLine","StyledCheckbox","StyledCheckboxBox","StyledCheckboxBoxWrapper","StyledCheckboxInput","StyledCheckboxLabel","Checkbox","children","isChecked","isDisabled","labelClassName","onChange","shouldShowAsSwitch","shouldShowCentered","shouldChangeOnLabelClick","isActive","setIsActive","checkboxTop","setCheckboxTop","undefined","checkboxBoxRef","checkboxRootRef","handleChange","event","target","checked","uuid","current","singleLineHeight","container","boxHeight","getBoundingClientRect","height","createElement","ref","disabled","id","type","style","top","transform","htmlFor","$isChecked","$isDisabled","$shouldShowAsSwitch","className","$shouldChangeOnLabelClick","displayName"],"sources":["../../../../src/components/checkbox/Checkbox.tsx"],"sourcesContent":["import React, {\n ChangeEvent,\n ChangeEventHandler,\n FC,\n ReactElement,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from 'react';\nimport { useUuid } from '../../hooks/uuid';\nimport { getHeightOfSingleTextLine } from '../../utils/calculate';\nimport {\n StyledCheckbox,\n StyledCheckboxBox,\n StyledCheckboxBoxWrapper,\n StyledCheckboxInput,\n StyledCheckboxLabel,\n} from './Checkbox.styles';\n\nexport type CheckboxProps = {\n /**\n * Text for checkbox or switch\n */\n children?: ReactElement | string;\n /**\n * Indicates whether the checkbox or switch is selected\n */\n isChecked?: boolean;\n /**\n * Disables the checkbox or switch so it cannot be toggled\n */\n isDisabled?: boolean;\n /**\n * Classname for the label\n */\n labelClassName?: string;\n /**\n * Function to be executed if the checked value changes\n */\n onChange?: ChangeEventHandler<HTMLInputElement>;\n /**\n * Whether the label should change the state of the checkbox\n */\n shouldChangeOnLabelClick?: boolean;\n /**\n * Changes the design to use switch instead of checkbox\n */\n shouldShowAsSwitch?: boolean;\n /**\n * Whether the Checkbox should be displayed centered to the label or at the top\n */\n shouldShowCentered?: boolean;\n};\n\nconst Checkbox: FC<CheckboxProps> = ({\n children,\n isChecked,\n isDisabled,\n labelClassName,\n onChange,\n shouldShowAsSwitch,\n shouldShowCentered = false,\n shouldChangeOnLabelClick = true,\n}) => {\n const [isActive, setIsActive] = useState(isChecked ?? false);\n const [checkboxTop, setCheckboxTop] = useState<number | undefined>(undefined);\n\n const checkboxBoxRef = useRef<HTMLLabelElement>(null);\n const checkboxRootRef = useRef<HTMLDivElement>(null);\n\n const handleChange = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n setIsActive(event.target.checked);\n\n if (typeof onChange === 'function') {\n onChange(event);\n }\n },\n [onChange],\n );\n\n const uuid = useUuid();\n\n useEffect(() => {\n if (checkboxRootRef.current && !shouldShowCentered) {\n const singleLineHeight = getHeightOfSingleTextLine({\n container: checkboxRootRef.current,\n });\n\n const boxHeight = checkboxBoxRef.current?.getBoundingClientRect().height ?? 0;\n\n setCheckboxTop((singleLineHeight - boxHeight) / 2);\n }\n }, [shouldShowCentered]);\n\n return (\n <StyledCheckbox ref={checkboxRootRef}>\n <StyledCheckboxInput\n checked={isChecked}\n disabled={isDisabled}\n id={uuid}\n onChange={handleChange}\n type=\"checkbox\"\n />\n <StyledCheckboxBoxWrapper\n style={{\n top: shouldShowCentered ? '50%' : checkboxTop,\n transform: shouldShowCentered ? 'translateY(-50%)' : undefined,\n }}\n >\n <StyledCheckboxBox\n htmlFor={uuid}\n ref={checkboxBoxRef}\n $isChecked={isChecked ?? isActive}\n $isDisabled={isDisabled}\n $shouldShowAsSwitch={shouldShowAsSwitch}\n />\n </StyledCheckboxBoxWrapper>\n <StyledCheckboxLabel\n className={labelClassName}\n $isDisabled={isDisabled}\n $shouldChangeOnLabelClick={shouldChangeOnLabelClick}\n $shouldShowAsSwitch={shouldShowAsSwitch}\n htmlFor={shouldChangeOnLabelClick ? uuid : undefined}\n >\n {children}\n </StyledCheckboxLabel>\n </StyledCheckbox>\n );\n};\n\nCheckbox.displayName = 'Checkbox';\n\nexport default Checkbox;\n"],"mappings":"AAAA,OAAOA,KAAK,IAKRC,WAAW,EACXC,SAAS,EACTC,MAAM,EACNC,QAAQ,QACL,OAAO;AACd,SAASC,OAAO,QAAQ,kBAAkB;AAC1C,SAASC,yBAAyB,QAAQ,uBAAuB;AACjE,SACIC,cAAc,EACdC,iBAAiB,EACjBC,wBAAwB,EACxBC,mBAAmB,EACnBC,mBAAmB,QAChB,mBAAmB;AAqC1B,MAAMC,QAA2B,GAAGA,CAAC;EACjCC,QAAQ;EACRC,SAAS;EACTC,UAAU;EACVC,cAAc;EACdC,QAAQ;EACRC,kBAAkB;EAClBC,kBAAkB,GAAG,KAAK;EAC1BC,wBAAwB,GAAG;AAC/B,CAAC,KAAK;EAC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eACF3C,KAAA,CAAAuC,aAAA,CAAC9B,wBAAwB;IACrBmC,KAAK,EAAE;MACHC,GAAG,EAAE1B,kBAAkB,GAAG,KAAK,GAAGI,WAAW;MAC7CuB,SAAS,EAAE3B,kBAAkB,GAAG,kBAAkB,GAAGM;IACzD;EAAE,gBAEFzB,KAAA,CAAAuC,aAAA,CAAC/B,iBAAiB;IACduC,OAAO,EAAEf,IAAK;IACdQ,GAAG,EAAEd,cAAe;IACpBsB,UAAU,EAAElC,SAAS,IAAIO,QAAS;IAClC4B,WAAW,EAAElC,UAAW;IACxBmC,mBAAmB,EAAEhC;EAAmB,CAC3C,CACqB,CAAC,eAC3BlB,KAAA,CAAAuC,aAAA,CAAC5B,mBAAmB;IAChBwC,SAAS,EAAEnC,cAAe;IAC1BiC,WAAW,EAAElC,UAAW;IACxBqC,yBAAyB,EAAEhC,wBAAyB;IACpD8B,mBAAmB,EAAEhC,kBAAmB;IACxC6B,OAAO,EAAE3B,wBAAwB,GAAGY,IAAI,GAAGP;EAAU,GAEpDZ,QACgB,CACT,CAAC;AAEzB,CAAC;AAEDD,QAAQ,CAACyC,WAAW,GAAG,UAAU;AAEjC,eAAezC,QAAQ","ignoreList":[]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import styled, { css } from 'styled-components';
|
|
2
|
-
import { getCheckBoxPosition } from '../../utils/checkBox';
|
|
3
2
|
export const StyledCheckbox = styled.div`
|
|
4
3
|
align-items: center;
|
|
5
4
|
display: flex;
|
|
@@ -10,6 +9,12 @@ export const StyledCheckbox = styled.div`
|
|
|
10
9
|
export const StyledCheckboxInput = styled.input`
|
|
11
10
|
display: none;
|
|
12
11
|
`;
|
|
12
|
+
export const StyledCheckboxBoxWrapper = styled.div`
|
|
13
|
+
display: flex;
|
|
14
|
+
flex-shrink: 0;
|
|
15
|
+
height: 16px;
|
|
16
|
+
position: absolute;
|
|
17
|
+
`;
|
|
13
18
|
export const StyledCheckboxBox = styled.label`
|
|
14
19
|
color: ${({
|
|
15
20
|
theme
|
|
@@ -20,9 +25,7 @@ export const StyledCheckboxBox = styled.label`
|
|
|
20
25
|
opacity: ${({
|
|
21
26
|
$isDisabled
|
|
22
27
|
}) => $isDisabled ? 0.5 : 1};
|
|
23
|
-
|
|
24
|
-
$shouldShowAsSwitch
|
|
25
|
-
}) => $shouldShowAsSwitch ? '48px' : '20px'};
|
|
28
|
+
position: relative;
|
|
26
29
|
transition: opacity 0.2s ease;
|
|
27
30
|
user-select: none;
|
|
28
31
|
height: 16px;
|
|
@@ -30,16 +33,14 @@ export const StyledCheckboxBox = styled.label`
|
|
|
30
33
|
&:after {
|
|
31
34
|
${({
|
|
32
35
|
$isChecked,
|
|
33
|
-
$shouldShowAsSwitch
|
|
34
|
-
$lineHeight,
|
|
35
|
-
theme
|
|
36
|
+
$shouldShowAsSwitch
|
|
36
37
|
}) => $shouldShowAsSwitch ? css`
|
|
37
38
|
background-color: white;
|
|
38
39
|
border-radius: 50%;
|
|
39
40
|
box-shadow: 0 1px 4px rgb(0 0 0 / 35%);
|
|
40
41
|
height: 16px;
|
|
41
42
|
left: 7px;
|
|
42
|
-
top:
|
|
43
|
+
top: 50%;
|
|
43
44
|
transform: translateX(${$isChecked ? '18px' : 0}) translateY(-50%);
|
|
44
45
|
transition: transform 0.2s ease;
|
|
45
46
|
width: 16px;
|
|
@@ -49,10 +50,10 @@ export const StyledCheckboxBox = styled.label`
|
|
|
49
50
|
height: 10px;
|
|
50
51
|
left: 2px;
|
|
51
52
|
opacity: ${$isChecked ? 1 : 0};
|
|
52
|
-
top:
|
|
53
|
+
top: calc(50% - 2px);
|
|
53
54
|
transform: rotateZ(37deg) translateY(-50%);
|
|
54
55
|
transition: opacity 0.2s ease;
|
|
55
|
-
width:
|
|
56
|
+
width: 5px;
|
|
56
57
|
`}
|
|
57
58
|
|
|
58
59
|
content: ' ';
|
|
@@ -89,20 +90,12 @@ export const StyledCheckboxBox = styled.label`
|
|
|
89
90
|
$shouldShowAsSwitch
|
|
90
91
|
}) => $shouldShowAsSwitch ? '10px' : 0};
|
|
91
92
|
position: absolute;
|
|
93
|
+
top: 50%;
|
|
94
|
+
transform: translateY(-50%);
|
|
92
95
|
transition: background-color 0.2s ease;
|
|
93
96
|
width: ${({
|
|
94
97
|
$shouldShowAsSwitch
|
|
95
98
|
}) => $shouldShowAsSwitch ? '28px' : '15px'};
|
|
96
|
-
${({
|
|
97
|
-
$lineHeight,
|
|
98
|
-
theme,
|
|
99
|
-
$shouldShowAsSwitch
|
|
100
|
-
}) => $lineHeight ? css`
|
|
101
|
-
top: ${getCheckBoxPosition(Number(theme.fontSize)) ?? 5 + ($shouldShowAsSwitch ? 1 : 0)}px;
|
|
102
|
-
` : css`
|
|
103
|
-
top: 50%;
|
|
104
|
-
transform: translateY(-50%);
|
|
105
|
-
`}
|
|
106
99
|
}
|
|
107
100
|
}
|
|
108
101
|
`;
|
|
@@ -116,6 +109,9 @@ export const StyledCheckboxLabel = styled.label`
|
|
|
116
109
|
opacity: ${({
|
|
117
110
|
$isDisabled
|
|
118
111
|
}) => $isDisabled ? 0.5 : 1};
|
|
112
|
+
padding-left: ${({
|
|
113
|
+
$shouldShowAsSwitch
|
|
114
|
+
}) => $shouldShowAsSwitch ? '48px' : '20px'};
|
|
119
115
|
transition: opacity 0.2s ease;
|
|
120
116
|
user-select: none;
|
|
121
117
|
`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.styles.js","names":["styled","css","
|
|
1
|
+
{"version":3,"file":"Checkbox.styles.js","names":["styled","css","StyledCheckbox","div","StyledCheckboxInput","input","StyledCheckboxBoxWrapper","StyledCheckboxBox","label","theme","text","$isDisabled","$isChecked","$shouldShowAsSwitch","green","red","StyledCheckboxLabel","$shouldChangeOnLabelClick"],"sources":["../../../../src/components/checkbox/Checkbox.styles.ts"],"sourcesContent":["import styled, { css } from 'styled-components';\nimport type { WithTheme } from '../color-scheme-provider/ColorSchemeProvider';\nimport type { CheckboxProps } from './Checkbox';\n\nexport const StyledCheckbox = styled.div`\n align-items: center;\n display: flex;\n position: relative;\n width: 100%;\n min-height: 20px;\n`;\n\nexport const StyledCheckboxInput = styled.input`\n display: none;\n`;\n\ntype StyledCheckboxBoxWrapperProps = WithTheme<{\n $shouldShowAsSwitch?: CheckboxProps['shouldShowAsSwitch'];\n}>;\n\nexport const StyledCheckboxBoxWrapper = styled.div<StyledCheckboxBoxWrapperProps>`\n display: flex;\n flex-shrink: 0;\n height: 16px;\n position: absolute;\n`;\n\ntype StyledCheckboxBoxProps = WithTheme<{\n $shouldShowAsSwitch?: CheckboxProps['shouldShowAsSwitch'];\n $isDisabled?: CheckboxProps['isDisabled'];\n $isChecked?: CheckboxProps['isChecked'];\n}>;\n\nexport const StyledCheckboxBox = styled.label<StyledCheckboxBoxProps>`\n color: ${({ theme }: StyledCheckboxBoxProps) => theme.text};\n cursor: ${({ $isDisabled }) => ($isDisabled ? 'default' : 'pointer')};\n opacity: ${({ $isDisabled }) => ($isDisabled ? 0.5 : 1)};\n position: relative;\n transition: opacity 0.2s ease;\n user-select: none;\n height: 16px;\n\n &:after {\n ${({ $isChecked, $shouldShowAsSwitch }: StyledCheckboxBoxProps) =>\n $shouldShowAsSwitch\n ? css`\n background-color: white;\n border-radius: 50%;\n box-shadow: 0 1px 4px rgb(0 0 0 / 35%);\n height: 16px;\n left: 7px;\n top: 50%;\n transform: translateX(${$isChecked ? '18px' : 0}) translateY(-50%);\n transition: transform 0.2s ease;\n width: 16px;\n `\n : css`\n border-right: 2px solid #fff;\n border-bottom: 2px solid #fff;\n height: 10px;\n left: 2px;\n opacity: ${$isChecked ? 1 : 0};\n top: calc(50% - 2px);\n transform: rotateZ(37deg) translateY(-50%);\n transition: opacity 0.2s ease;\n width: 5px;\n `}\n\n content: ' ';\n position: absolute;\n }\n\n &:before {\n background-color: ${({\n $isChecked,\n $shouldShowAsSwitch,\n theme,\n }: StyledCheckboxBoxProps) => {\n if ($shouldShowAsSwitch) {\n return $isChecked ? theme.green : theme.red;\n }\n\n return $isChecked ? theme['408'] : theme['403'];\n }};\n\n ${({ $shouldShowAsSwitch, theme }) =>\n !$shouldShowAsSwitch &&\n css`\n border: 1px solid rgba(${theme['409-rgb']}, 0.5);\n `}\n\n border-radius: ${({ $shouldShowAsSwitch }) => ($shouldShowAsSwitch ? '100px' : 0)};\n content: ' ';\n height: ${({ $shouldShowAsSwitch }) => ($shouldShowAsSwitch ? '13px' : '15px')};\n left: ${({ $shouldShowAsSwitch }) => ($shouldShowAsSwitch ? '10px' : 0)};\n position: absolute;\n top: 50%;\n transform: translateY(-50%);\n transition: background-color 0.2s ease;\n width: ${({ $shouldShowAsSwitch }) => ($shouldShowAsSwitch ? '28px' : '15px')};\n }\n}\n`;\n\ntype StyledCheckboxLabelProps = WithTheme<{\n $isDisabled?: CheckboxProps['isDisabled'];\n $shouldChangeOnLabelClick?: CheckboxProps['shouldChangeOnLabelClick'];\n $shouldShowAsSwitch?: CheckboxProps['shouldShowAsSwitch'];\n}>;\n\nexport const StyledCheckboxLabel = styled.label<StyledCheckboxLabelProps>`\n color: ${({ theme }: StyledCheckboxLabelProps) => theme.text};\n cursor: ${({ $shouldChangeOnLabelClick }) =>\n !$shouldChangeOnLabelClick ? 'default' : 'pointer'};\n opacity: ${({ $isDisabled }) => ($isDisabled ? 0.5 : 1)};\n padding-left: ${({ $shouldShowAsSwitch }) => ($shouldShowAsSwitch ? '48px' : '20px')};\n transition: opacity 0.2s ease;\n user-select: none;\n`;\n"],"mappings":"AAAA,OAAOA,MAAM,IAAIC,GAAG,QAAQ,mBAAmB;AAI/C,OAAO,MAAMC,cAAc,GAAGF,MAAM,CAACG,GAAG;AACxC;AACA;AACA;AACA;AACA;AACA,CAAC;AAED,OAAO,MAAMC,mBAAmB,GAAGJ,MAAM,CAACK,KAAK;AAC/C;AACA,CAAC;AAMD,OAAO,MAAMC,wBAAwB,GAAGN,MAAM,CAACG,GAAkC;AACjF;AACA;AACA;AACA;AACA,CAAC;AAQD,OAAO,MAAMI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AAMA,mBAAmB,GAAG,MAAM,GAAG,CAAE;AAC/E;AACA;AACA;AACA;AACA,iBAAiB,CAAC;EAAEA;AAAoB,CAAC,KAAMA,mBAAmB,GAAG,MAAM,GAAG,MAAO;AACrF;AACA;AACA,CAAC;AAQD,OAAO,MAAMG,mBAAmB,GAAGhB,MAAM,CAACQ,KAA+B;AACzE,aAAa,CAAC;EAAEC;AAAgC,CAAC,KAAKA,KAAK,CAACC,IAAI;AAChE,cAAc,CAAC;EAAEO;AAA0B,CAAC,KACpC,CAACA,yBAAyB,GAAG,SAAS,GAAG,SAAS;AAC1D,eAAe,CAAC;EAAEN;AAAY,CAAC,KAAMA,WAAW,GAAG,GAAG,GAAG,CAAE;AAC3D,oBAAoB,CAAC;EAAEE;AAAoB,CAAC,KAAMA,mBAAmB,GAAG,MAAM,GAAG,MAAO;AACxF;AACA;AACA,CAAC","ignoreList":[]}
|
|
@@ -78,12 +78,19 @@ export const calculateContentHeight = elements => {
|
|
|
78
78
|
});
|
|
79
79
|
return heights.reduce((partialSum, a) => partialSum + a, 0);
|
|
80
80
|
};
|
|
81
|
-
export const getHeightOfSingleTextLine = (
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
document.
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
export const getHeightOfSingleTextLine = ({
|
|
82
|
+
container
|
|
83
|
+
}) => {
|
|
84
|
+
const div = document.createElement('div');
|
|
85
|
+
div.style.visibility = 'hidden';
|
|
86
|
+
div.style.position = 'absolute';
|
|
87
|
+
div.style.whiteSpace = 'nowrap';
|
|
88
|
+
div.innerText = 'Single text line';
|
|
89
|
+
container.appendChild(div);
|
|
90
|
+
const {
|
|
91
|
+
height
|
|
92
|
+
} = div.getBoundingClientRect();
|
|
93
|
+
container.removeChild(div);
|
|
87
94
|
return height;
|
|
88
95
|
};
|
|
89
96
|
export const getMaxHeightInPixels = (maxHeight, rootElement) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculate.js","names":["ChaynsProvider","React","renderToString","ColorSchemeProvider","calculateContentWidth","list","functions","values","length","forEach","suffixElement","text","textStyles","tagName","styles","div","document","createElement","Object","assign","style","display","gap","position","visibility","whiteSpace","width","body","appendChild","innerText","innerHTML","data","isModule","color","colorMode","push","offsetWidth","removeChild","Math","max","apply","calculateBiggestWidth","elements","container","padding","id","element","accessKey","calculateContentHeight","heights","offsetHeight","reduce","partialSum","a","getHeightOfSingleTextLine","
|
|
1
|
+
{"version":3,"file":"calculate.js","names":["ChaynsProvider","React","renderToString","ColorSchemeProvider","calculateContentWidth","list","functions","values","length","forEach","suffixElement","text","textStyles","tagName","styles","div","document","createElement","Object","assign","style","display","gap","position","visibility","whiteSpace","width","body","appendChild","innerText","innerHTML","data","isModule","color","colorMode","push","offsetWidth","removeChild","Math","max","apply","calculateBiggestWidth","elements","container","padding","id","element","accessKey","calculateContentHeight","heights","offsetHeight","reduce","partialSum","a","getHeightOfSingleTextLine","height","getBoundingClientRect","getMaxHeightInPixels","maxHeight","rootElement","tempElement"],"sources":["../../../src/utils/calculate.tsx"],"sourcesContent":["import { ChaynsProvider, ChaynsReactFunctions, ChaynsReactValues } from 'chayns-api';\nimport React, { type CSSProperties } from 'react';\nimport { renderToString } from 'react-dom/server';\nimport ColorSchemeProvider from '../components/color-scheme-provider/ColorSchemeProvider';\nimport type { IComboBoxItem } from '../components/combobox/ComboBox';\nimport type { SliderButtonItem } from '../types/slider-button';\n\nexport const calculateContentWidth = (\n list: IComboBoxItem[],\n functions: ChaynsReactFunctions,\n values: ChaynsReactValues,\n) => {\n const length: number[] = [];\n\n list.forEach(({ suffixElement, text, textStyles }) => {\n const tagName = textStyles?.tagName ?? 'div';\n const styles = textStyles?.styles;\n\n const div = document.createElement(tagName);\n\n if (styles) {\n Object.assign(div.style, styles);\n }\n\n div.style.display = 'flex';\n div.style.gap = '10px';\n div.style.position = 'absolute';\n div.style.visibility = 'hidden';\n div.style.whiteSpace = 'nowrap';\n div.style.width = 'auto';\n\n document.body.appendChild(div);\n\n div.innerText = text;\n\n if (suffixElement) {\n // ColorSchemeProvider is used to prevent missing scheme context error.\n // Due to the fact that the element is never rendered visible, the values are irrelevant.\n div.innerHTML += renderToString(\n <ChaynsProvider data={values} functions={functions} isModule>\n <ColorSchemeProvider color=\"#005EB8\" colorMode={0}>\n {suffixElement}\n </ColorSchemeProvider>\n </ChaynsProvider>,\n );\n }\n\n length.push(div.offsetWidth);\n\n document.body.removeChild(div);\n });\n\n return Math.max.apply(null, length);\n};\n\nexport const calculateBiggestWidth = (elements: SliderButtonItem[]) => {\n const container = document.createElement('div');\n\n container.style.visibility = 'hidden';\n container.style.position = 'absolute';\n container.style.width = 'auto';\n container.style.whiteSpace = 'nowrap';\n container.style.padding = '7px 12px';\n container.style.display = 'block';\n\n elements.forEach(({ text, id }) => {\n const element = document.createElement('div');\n\n element.accessKey = `slider-button-pseudo--${id}`;\n element.innerText = text;\n\n container.appendChild(element);\n });\n\n document.body.appendChild(container);\n\n const width = container.offsetWidth;\n\n document.body.removeChild(container);\n\n return width;\n};\n\nexport const calculateContentHeight = (elements: string[]) => {\n const heights: number[] = [];\n\n elements.forEach((element: string) => {\n const div = document.createElement('div');\n\n div.style.visibility = 'hidden';\n div.style.position = 'absolute';\n div.style.width = 'auto';\n div.style.padding = '4px 10px';\n div.style.whiteSpace = 'nowrap';\n\n document.body.appendChild(div);\n\n div.innerText = element;\n\n heights.push(div.offsetHeight);\n\n document.body.removeChild(div);\n });\n\n return heights.reduce((partialSum, a) => partialSum + a, 0);\n};\n\ninterface GetHeightOfSingleTextLineOptions {\n container: Element;\n}\n\nexport const getHeightOfSingleTextLine = ({ container }: GetHeightOfSingleTextLineOptions) => {\n const div = document.createElement('div');\n\n div.style.visibility = 'hidden';\n div.style.position = 'absolute';\n div.style.whiteSpace = 'nowrap';\n\n div.innerText = 'Single text line';\n\n container.appendChild(div);\n\n const { height } = div.getBoundingClientRect();\n\n container.removeChild(div);\n\n return height;\n};\n\nexport const getMaxHeightInPixels = (\n maxHeight: CSSProperties['maxHeight'],\n rootElement: Element,\n): number => {\n const tempElement = document.createElement('div');\n\n tempElement.style.position = 'absolute';\n tempElement.style.visibility = 'hidden';\n tempElement.style.height = '100vh';\n tempElement.style.maxHeight = maxHeight as string;\n\n rootElement.appendChild(tempElement);\n\n const { height } = tempElement.getBoundingClientRect();\n\n rootElement.removeChild(tempElement);\n\n return height;\n};\n"],"mappings":"AAAA,SAASA,cAAc,QAAiD,YAAY;AACpF,OAAOC,KAAK,MAA8B,OAAO;AACjD,SAASC,cAAc,QAAQ,kBAAkB;AACjD,OAAOC,mBAAmB,MAAM,yDAAyD;AAIzF,OAAO,MAAMC,qBAAqB,GAAGA,CACjCC,IAAqB,EACrBC,SAA+B,EAC/BC,MAAyB,KACxB;EACD,MAAMC,MAAgB,GAAG,EAAE;EAE3BH,IAAI,CAACI,OAAO,CAAC,CAAC;IAAEC,aAAa;IAAEC,IAAI;IAAEC;EAAW,CAAC,KAAK;IAClD,MAAMC,OAAO,GAAGD,UAAU,EAAEC,OAAO,IAAI,KAAK;IAC5C,MAAMC,MAAM,GAAGF,UAAU,EAAEE,MAAM;IAEjC,MAAMC,GAAG,GAAGC,QAAQ,CAACC,aAAa,CAACJ,OAAO,CAAC;IAE3C,IAAIC,MAAM,EAAE;MACRI,MAAM,CAACC,MAAM,CAACJ,GAAG,CAACK,KAAK,EAAEN,MAAM,CAAC;IACpC;IAEAC,GAAG,CAACK,KAAK,CAACC,OAAO,GAAG,MAAM;IAC1BN,GAAG,CAACK,KAAK,CAACE,GAAG,GAAG,MAAM;IACtBP,GAAG,CAACK,KAAK,CAACG,QAAQ,GAAG,UAAU;IAC/BR,GAAG,CAACK,KAAK,CAACI,UAAU,GAAG,QAAQ;IAC/BT,GAAG,CAACK,KAAK,CAACK,UAAU,GAAG,QAAQ;IAC/BV,GAAG,CAACK,KAAK,CAACM,KAAK,GAAG,MAAM;IAExBV,QAAQ,CAACW,IAAI,CAACC,WAAW,CAACb,GAAG,CAAC;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,CAAC;EAEzCF,GAAG,CAACK,KAAK,CAACI,UAAU,GAAG,QAAQ;EAC/BT,GAAG,CAACK,KAAK,CAACG,QAAQ,GAAG,UAAU;EAC/BR,GAAG,CAACK,KAAK,CAACK,UAAU,GAAG,QAAQ;EAE/BV,GAAG,CAACc,SAAS,GAAG,kBAAkB;EAElCc,SAAS,CAACf,WAAW,CAACb,GAAG,CAAC;EAE1B,MAAM;IAAEwC;EAAO,CAAC,GAAGxC,GAAG,CAACyC,qBAAqB,CAAC,CAAC;EAE9Cb,SAAS,CAACN,WAAW,CAACtB,GAAG,CAAC;EAE1B,OAAOwC,MAAM;AACjB,CAAC;AAED,OAAO,MAAME,oBAAoB,GAAGA,CAChCC,SAAqC,EACrCC,WAAoB,KACX;EACT,MAAMC,WAAW,GAAG5C,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;EAEjD2C,WAAW,CAACxC,KAAK,CAACG,QAAQ,GAAG,UAAU;EACvCqC,WAAW,CAACxC,KAAK,CAACI,UAAU,GAAG,QAAQ;EACvCoC,WAAW,CAACxC,KAAK,CAACmC,MAAM,GAAG,OAAO;EAClCK,WAAW,CAACxC,KAAK,CAACsC,SAAS,GAAGA,SAAmB;EAEjDC,WAAW,CAAC/B,WAAW,CAACgC,WAAW,CAAC;EAEpC,MAAM;IAAEL;EAAO,CAAC,GAAGK,WAAW,CAACJ,qBAAqB,CAAC,CAAC;EAEtDG,WAAW,CAACtB,WAAW,CAACuB,WAAW,CAAC;EAEpC,OAAOL,MAAM;AACjB,CAAC","ignoreList":[]}
|
|
@@ -2,16 +2,20 @@ import type { WithTheme } from '../color-scheme-provider/ColorSchemeProvider';
|
|
|
2
2
|
import type { CheckboxProps } from './Checkbox';
|
|
3
3
|
export declare const StyledCheckbox: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
|
|
4
4
|
export declare const StyledCheckboxInput: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, never>> & string;
|
|
5
|
+
type StyledCheckboxBoxWrapperProps = WithTheme<{
|
|
6
|
+
$shouldShowAsSwitch?: CheckboxProps['shouldShowAsSwitch'];
|
|
7
|
+
}>;
|
|
8
|
+
export declare const StyledCheckboxBoxWrapper: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, StyledCheckboxBoxWrapperProps>> & string;
|
|
5
9
|
type StyledCheckboxBoxProps = WithTheme<{
|
|
6
10
|
$shouldShowAsSwitch?: CheckboxProps['shouldShowAsSwitch'];
|
|
7
11
|
$isDisabled?: CheckboxProps['isDisabled'];
|
|
8
12
|
$isChecked?: CheckboxProps['isChecked'];
|
|
9
|
-
$lineHeight?: number;
|
|
10
13
|
}>;
|
|
11
14
|
export declare const StyledCheckboxBox: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>, StyledCheckboxBoxProps>> & string;
|
|
12
15
|
type StyledCheckboxLabelProps = WithTheme<{
|
|
13
16
|
$isDisabled?: CheckboxProps['isDisabled'];
|
|
14
17
|
$shouldChangeOnLabelClick?: CheckboxProps['shouldChangeOnLabelClick'];
|
|
18
|
+
$shouldShowAsSwitch?: CheckboxProps['shouldShowAsSwitch'];
|
|
15
19
|
}>;
|
|
16
20
|
export declare const StyledCheckboxLabel: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>, StyledCheckboxLabelProps>> & string;
|
|
17
21
|
export {};
|
|
@@ -5,5 +5,9 @@ import type { SliderButtonItem } from '../types/slider-button';
|
|
|
5
5
|
export declare const calculateContentWidth: (list: IComboBoxItem[], functions: ChaynsReactFunctions, values: ChaynsReactValues) => number;
|
|
6
6
|
export declare const calculateBiggestWidth: (elements: SliderButtonItem[]) => number;
|
|
7
7
|
export declare const calculateContentHeight: (elements: string[]) => number;
|
|
8
|
-
|
|
8
|
+
interface GetHeightOfSingleTextLineOptions {
|
|
9
|
+
container: Element;
|
|
10
|
+
}
|
|
11
|
+
export declare const getHeightOfSingleTextLine: ({ container }: GetHeightOfSingleTextLineOptions) => number;
|
|
9
12
|
export declare const getMaxHeightInPixels: (maxHeight: CSSProperties["maxHeight"], rootElement: Element) => number;
|
|
13
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chayns-components/core",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.1189",
|
|
4
4
|
"description": "A set of beautiful React components for developing your own applications with chayns.",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"browserslist": [
|
|
@@ -85,5 +85,5 @@
|
|
|
85
85
|
"publishConfig": {
|
|
86
86
|
"access": "public"
|
|
87
87
|
},
|
|
88
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "4ad280bc3a76abba115c89e9d37dd71c6a484e3a"
|
|
89
89
|
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getCheckBoxPosition = void 0;
|
|
7
|
-
const getCheckBoxPosition = fontSize => {
|
|
8
|
-
const position = {
|
|
9
|
-
30: 17,
|
|
10
|
-
25.5: 14,
|
|
11
|
-
24: 12,
|
|
12
|
-
20: 8,
|
|
13
|
-
19: 8,
|
|
14
|
-
18: 6,
|
|
15
|
-
17: 7,
|
|
16
|
-
16: 5,
|
|
17
|
-
15: 4,
|
|
18
|
-
14: 4,
|
|
19
|
-
13: 3,
|
|
20
|
-
12: 1,
|
|
21
|
-
11: 1,
|
|
22
|
-
10: 0,
|
|
23
|
-
9: -1,
|
|
24
|
-
8: -1
|
|
25
|
-
};
|
|
26
|
-
return position[fontSize];
|
|
27
|
-
};
|
|
28
|
-
exports.getCheckBoxPosition = getCheckBoxPosition;
|
|
29
|
-
//# sourceMappingURL=checkBox.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"checkBox.js","names":["getCheckBoxPosition","fontSize","position","exports"],"sources":["../../../src/utils/checkBox.ts"],"sourcesContent":["export const getCheckBoxPosition = (fontSize: number) => {\n const position: { [key: number]: number } = {\n 30: 17,\n 25.5: 14,\n 24: 12,\n 20: 8,\n 19: 8,\n 18: 6,\n 17: 7,\n 16: 5,\n 15: 4,\n 14: 4,\n 13: 3,\n 12: 1,\n 11: 1,\n 10: 0,\n 9: -1,\n 8: -1,\n };\n\n return position[fontSize];\n};\n"],"mappings":";;;;;;AAAO,MAAMA,mBAAmB,GAAIC,QAAgB,IAAK;EACrD,MAAMC,QAAmC,GAAG;IACxC,EAAE,EAAE,EAAE;IACN,IAAI,EAAE,EAAE;IACR,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,CAAC;IACL,CAAC,EAAE,CAAC,CAAC;IACL,CAAC,EAAE,CAAC;EACR,CAAC;EAED,OAAOA,QAAQ,CAACD,QAAQ,CAAC;AAC7B,CAAC;AAACE,OAAA,CAAAH,mBAAA,GAAAA,mBAAA","ignoreList":[]}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export const getCheckBoxPosition = fontSize => {
|
|
2
|
-
const position = {
|
|
3
|
-
30: 17,
|
|
4
|
-
25.5: 14,
|
|
5
|
-
24: 12,
|
|
6
|
-
20: 8,
|
|
7
|
-
19: 8,
|
|
8
|
-
18: 6,
|
|
9
|
-
17: 7,
|
|
10
|
-
16: 5,
|
|
11
|
-
15: 4,
|
|
12
|
-
14: 4,
|
|
13
|
-
13: 3,
|
|
14
|
-
12: 1,
|
|
15
|
-
11: 1,
|
|
16
|
-
10: 0,
|
|
17
|
-
9: -1,
|
|
18
|
-
8: -1
|
|
19
|
-
};
|
|
20
|
-
return position[fontSize];
|
|
21
|
-
};
|
|
22
|
-
//# sourceMappingURL=checkBox.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"checkBox.js","names":["getCheckBoxPosition","fontSize","position"],"sources":["../../../src/utils/checkBox.ts"],"sourcesContent":["export const getCheckBoxPosition = (fontSize: number) => {\n const position: { [key: number]: number } = {\n 30: 17,\n 25.5: 14,\n 24: 12,\n 20: 8,\n 19: 8,\n 18: 6,\n 17: 7,\n 16: 5,\n 15: 4,\n 14: 4,\n 13: 3,\n 12: 1,\n 11: 1,\n 10: 0,\n 9: -1,\n 8: -1,\n };\n\n return position[fontSize];\n};\n"],"mappings":"AAAA,OAAO,MAAMA,mBAAmB,GAAIC,QAAgB,IAAK;EACrD,MAAMC,QAAmC,GAAG;IACxC,EAAE,EAAE,EAAE;IACN,IAAI,EAAE,EAAE;IACR,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,CAAC;IACL,CAAC,EAAE,CAAC,CAAC;IACL,CAAC,EAAE,CAAC;EACR,CAAC;EAED,OAAOA,QAAQ,CAACD,QAAQ,CAAC;AAC7B,CAAC","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const getCheckBoxPosition: (fontSize: number) => number | undefined;
|