@fibery/ui-kit 1.34.0 → 1.34.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/toggle.tsx +39 -31
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fibery/ui-kit",
|
|
3
|
-
"version": "1.34.
|
|
3
|
+
"version": "1.34.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"files": [
|
|
6
6
|
"src/antd/styles.ts",
|
|
@@ -110,8 +110,8 @@
|
|
|
110
110
|
"svgo": "2.8.0",
|
|
111
111
|
"typescript": "5.4.3",
|
|
112
112
|
"unist-util-reduce": "0.2.2",
|
|
113
|
-
"@fibery/
|
|
114
|
-
"@fibery/
|
|
113
|
+
"@fibery/eslint-config": "8.6.0",
|
|
114
|
+
"@fibery/babel-preset": "7.4.0"
|
|
115
115
|
},
|
|
116
116
|
"jest": {
|
|
117
117
|
"testEnvironment": "jsdom",
|
package/src/toggle.tsx
CHANGED
|
@@ -6,7 +6,10 @@ import {layout, space, textStyles, transition} from "./design-system";
|
|
|
6
6
|
import _ from "lodash";
|
|
7
7
|
import SpinnerIcon from "./icons/react/Spinner";
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const toggleIconHeightVar = "--fibery-toggle-icon-height";
|
|
10
|
+
const toggleIconWidthVar = "--fibery-toggle-icon-width";
|
|
11
|
+
|
|
12
|
+
const Input = styled.input<{outlineColor: string}>`
|
|
10
13
|
position: absolute;
|
|
11
14
|
cursor: pointer;
|
|
12
15
|
top: 0;
|
|
@@ -14,9 +17,9 @@ const Input = styled.input<{containerSize: number; containerWidth: number; outli
|
|
|
14
17
|
appearance: none;
|
|
15
18
|
margin-right: 0;
|
|
16
19
|
background-color: transparent;
|
|
17
|
-
height: ${
|
|
18
|
-
width: ${
|
|
19
|
-
border-radius: ${
|
|
20
|
+
height: var(${toggleIconHeightVar});
|
|
21
|
+
width: var(${toggleIconWidthVar});
|
|
22
|
+
border-radius: calc(var(${toggleIconHeightVar}) / 2);
|
|
20
23
|
|
|
21
24
|
&:focus {
|
|
22
25
|
outline: none;
|
|
@@ -28,7 +31,6 @@ const Input = styled.input<{containerSize: number; containerWidth: number; outli
|
|
|
28
31
|
`;
|
|
29
32
|
|
|
30
33
|
const Label = styled.div<{labelPosition: "last" | "first"; disabled?: boolean}>`
|
|
31
|
-
${textStyles.regular}
|
|
32
34
|
margin-left: ${({labelPosition}) => (labelPosition === "last" ? `${space.s8}px` : 0)};
|
|
33
35
|
margin-right: ${({labelPosition}) => (labelPosition === "first" ? `${space.s8}px` : 0)};
|
|
34
36
|
opacity: ${({disabled}) => (disabled ? 0.5 : 1)};
|
|
@@ -56,26 +58,24 @@ const getOutlineColor = _.memoize((color: string) => {
|
|
|
56
58
|
});
|
|
57
59
|
|
|
58
60
|
const CircleContainer = styled.div<{
|
|
59
|
-
containerSize: number;
|
|
60
|
-
containerWidth: number;
|
|
61
61
|
backgroundColor: string;
|
|
62
62
|
disabled?: boolean;
|
|
63
63
|
}>`
|
|
64
64
|
position: relative;
|
|
65
|
-
height: ${
|
|
66
|
-
width: ${
|
|
65
|
+
height: var(${toggleIconHeightVar});
|
|
66
|
+
width: var(${toggleIconWidthVar});
|
|
67
67
|
flex-shrink: 0;
|
|
68
|
-
border-radius: ${
|
|
68
|
+
border-radius: calc(var(${toggleIconHeightVar}) / 2);
|
|
69
69
|
background-color: ${({backgroundColor}) => backgroundColor};
|
|
70
70
|
padding: ${space.s2}px;
|
|
71
71
|
transition: background-color ${transition};
|
|
72
72
|
opacity: ${({disabled}) => (disabled ? 0.5 : 1)};
|
|
73
73
|
`;
|
|
74
74
|
|
|
75
|
-
const Circle = styled.div
|
|
76
|
-
height: ${
|
|
77
|
-
width: ${
|
|
78
|
-
border-radius: ${
|
|
75
|
+
const Circle = styled.div`
|
|
76
|
+
height: calc(var(${toggleIconHeightVar}) - ${space.s2 * 2}px);
|
|
77
|
+
width: calc(var(${toggleIconHeightVar}) - ${space.s2 * 2}px);
|
|
78
|
+
border-radius: calc(var(${toggleIconHeightVar}) / 2 - ${space.s2}px);
|
|
79
79
|
background-color: white;
|
|
80
80
|
transition: transform ${transition};
|
|
81
81
|
`;
|
|
@@ -83,11 +83,26 @@ const Circle = styled.div<{containerSize: number}>`
|
|
|
83
83
|
export type ToggleSize = "small" | "medium" | "large" | "extra-large";
|
|
84
84
|
|
|
85
85
|
const toggleSize = {
|
|
86
|
-
small:
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
small: css`
|
|
87
|
+
${textStyles.small}
|
|
88
|
+
${toggleIconHeightVar}: 14px;
|
|
89
|
+
`,
|
|
90
|
+
medium: css`
|
|
91
|
+
${textStyles.regular}
|
|
92
|
+
${toggleIconHeightVar}: 16px;
|
|
93
|
+
`,
|
|
94
|
+
large: css`
|
|
95
|
+
${textStyles.regular}
|
|
96
|
+
${toggleIconHeightVar}: 18px;
|
|
97
|
+
`,
|
|
98
|
+
"extra-large": css`
|
|
99
|
+
${textStyles.regular}
|
|
100
|
+
${toggleIconHeightVar}: 20px;
|
|
101
|
+
`,
|
|
102
|
+
};
|
|
103
|
+
const toggleSizeStyle = css`
|
|
104
|
+
${toggleIconWidthVar}: calc(var(${toggleIconHeightVar}) * 1.75)
|
|
105
|
+
`;
|
|
91
106
|
|
|
92
107
|
type ToggleProps = Omit<ComponentProps<"input">, "value" | "size"> & {
|
|
93
108
|
value?: boolean;
|
|
@@ -116,17 +131,17 @@ export const Toggle: FC<ToggleProps> = ({
|
|
|
116
131
|
wrapperClassName,
|
|
117
132
|
...rest
|
|
118
133
|
}) => {
|
|
119
|
-
const height = toggleSize[size];
|
|
120
|
-
const width = height * 1.75;
|
|
121
134
|
const outlineColor = getOutlineColor(backgroundColor);
|
|
122
135
|
|
|
123
136
|
const circleTransformStyle = {
|
|
124
|
-
transform: `translateX(${value ?
|
|
137
|
+
transform: `translateX(${value ? `calc(var(${toggleIconWidthVar}) - var(${toggleIconHeightVar}))` : 0})`,
|
|
125
138
|
};
|
|
126
139
|
|
|
127
140
|
return (
|
|
128
141
|
<label
|
|
129
142
|
className={cx(
|
|
143
|
+
toggleSize[size],
|
|
144
|
+
toggleSizeStyle,
|
|
130
145
|
wrapperClassName,
|
|
131
146
|
labelWrapperStyle,
|
|
132
147
|
disabled
|
|
@@ -148,16 +163,9 @@ export const Toggle: FC<ToggleProps> = ({
|
|
|
148
163
|
>
|
|
149
164
|
{pending && <SpinnerIcon />}
|
|
150
165
|
{!pending && (
|
|
151
|
-
<CircleContainer
|
|
152
|
-
|
|
153
|
-
containerWidth={width}
|
|
154
|
-
backgroundColor={backgroundColor}
|
|
155
|
-
disabled={disabled}
|
|
156
|
-
>
|
|
157
|
-
<Circle containerSize={height} style={circleTransformStyle} />
|
|
166
|
+
<CircleContainer backgroundColor={backgroundColor} disabled={disabled}>
|
|
167
|
+
<Circle style={circleTransformStyle} />
|
|
158
168
|
<Input
|
|
159
|
-
containerSize={height}
|
|
160
|
-
containerWidth={width}
|
|
161
169
|
outlineColor={outlineColor}
|
|
162
170
|
onChange={onChange}
|
|
163
171
|
className={className}
|