@alfalab/core-components-switch 3.0.1 → 3.0.3
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/Component.d.ts +9 -9
- package/Component.js +18 -58
- package/cssm/Component.d.ts +9 -9
- package/cssm/Component.js +24 -64
- package/cssm/index.js +2 -3
- package/cssm/index.module.css +37 -68
- package/esm/Component.d.ts +9 -9
- package/esm/Component.js +6 -44
- package/esm/index.css +38 -69
- package/esm/index.js +2 -1
- package/index.css +38 -69
- package/index.js +2 -3
- package/modern/Component.d.ts +9 -9
- package/modern/Component.js +6 -6
- package/modern/index.css +38 -69
- package/modern/index.js +2 -2
- package/package.json +3 -2
- package/send-stats.js +1 -1
package/modern/Component.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import React, { forwardRef, useRef
|
|
2
|
-
import cn from 'classnames';
|
|
1
|
+
import React, { forwardRef, useRef } from 'react';
|
|
3
2
|
import mergeRefs from 'react-merge-refs';
|
|
3
|
+
import cn from 'classnames';
|
|
4
4
|
import { useFocus } from '@alfalab/hooks';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
const styles = {"component":"switch__component_1pggx","start":"switch__start_1pggx","center":"switch__center_1pggx","addons":"switch__addons_1pggx","block":"switch__block_1pggx","switch":"switch__switch_1pggx","content":"switch__content_1pggx","label":"switch__label_1pggx","hint":"switch__hint_1pggx","reversed":"switch__reversed_1pggx","checked":"switch__checked_1pggx","disabled":"switch__disabled_1pggx","inactive":"switch__inactive_1pggx","focused":"switch__focused_1pggx"};
|
|
7
7
|
require('./index.css')
|
|
8
8
|
|
|
9
9
|
const Switch = forwardRef(({ reversed = false, checked = false, align = 'start', addons, block, disabled, inactive, label, hint, name, value, className, onChange, dataTestId, ...restProps }, ref) => {
|
|
10
10
|
const labelRef = useRef(null);
|
|
11
11
|
const [focused] = useFocus(labelRef, 'keyboard');
|
|
12
|
-
const handleChange =
|
|
12
|
+
const handleChange = (e) => {
|
|
13
13
|
if (onChange) {
|
|
14
14
|
onChange(e, { checked: e.target.checked, name });
|
|
15
15
|
}
|
|
16
|
-
}
|
|
16
|
+
};
|
|
17
17
|
return (
|
|
18
18
|
// eslint-disable-next-line jsx-a11y/label-has-associated-control
|
|
19
19
|
React.createElement("label", { className: cn(styles.component, styles[align], className, {
|
|
@@ -24,7 +24,7 @@ const Switch = forwardRef(({ reversed = false, checked = false, align = 'start',
|
|
|
24
24
|
[styles.focused]: focused,
|
|
25
25
|
[styles.block]: block,
|
|
26
26
|
}), ref: mergeRefs([labelRef, ref]) },
|
|
27
|
-
React.createElement("input",
|
|
27
|
+
React.createElement("input", { type: 'checkbox', onChange: handleChange, disabled: disabled || inactive, checked: checked, name: name, value: value, "data-test-id": dataTestId, ...restProps }),
|
|
28
28
|
React.createElement("span", { className: styles.switch }),
|
|
29
29
|
(label || hint) && (React.createElement("span", { className: styles.content },
|
|
30
30
|
label && React.createElement("span", { className: styles.label }, label),
|
package/modern/index.css
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
/* hash:
|
|
1
|
+
/* hash: 1p577 */
|
|
2
2
|
:root {
|
|
3
|
+
} /* deprecated */ :root {
|
|
3
4
|
--color-light-border-link: #007aff;
|
|
4
5
|
--color-light-border-underline: #b6bcc3;
|
|
5
6
|
--color-light-graphic-accent: #ef3124;
|
|
@@ -7,31 +8,29 @@
|
|
|
7
8
|
--color-light-graphic-quaternary: #dbdee1;
|
|
8
9
|
--color-light-graphic-secondary: #6d7986;
|
|
9
10
|
--color-light-text-primary: #0b1f35;
|
|
10
|
-
--color-light-text-secondary:
|
|
11
|
-
}
|
|
12
|
-
:root {
|
|
11
|
+
--color-light-text-secondary: rgba(11, 31, 53, 0.7);
|
|
12
|
+
} :root {
|
|
13
|
+
} :root {
|
|
14
|
+
} :root {
|
|
13
15
|
|
|
14
16
|
/* Hard */
|
|
15
17
|
|
|
16
18
|
/* Up */
|
|
17
19
|
|
|
18
20
|
/* Hard up */
|
|
19
|
-
}
|
|
20
|
-
:
|
|
21
|
+
} :root {
|
|
22
|
+
--border-radius-xl: 16px;
|
|
23
|
+
--border-radius-circle: 50%;
|
|
24
|
+
} :root {
|
|
21
25
|
--gap-3xs: 2px;
|
|
22
26
|
--gap-2xs: 4px;
|
|
23
27
|
--gap-s: 12px;
|
|
24
28
|
--gap-m: 16px;
|
|
25
|
-
}
|
|
26
|
-
:root {
|
|
27
|
-
--border-radius-xl: 16px;
|
|
28
|
-
--border-radius-circle: 50%;
|
|
29
|
-
}
|
|
30
|
-
:root {
|
|
29
|
+
} :root {
|
|
30
|
+
} :root {
|
|
31
31
|
--focus-color: var(--color-light-border-link);
|
|
32
32
|
--disabled-cursor: not-allowed;
|
|
33
|
-
}
|
|
34
|
-
:root {
|
|
33
|
+
} :root {
|
|
35
34
|
--switch-label-color: var(--color-light-text-primary);
|
|
36
35
|
--switch-hint-color: var(--color-light-text-secondary);
|
|
37
36
|
--switch-bg-color: var(--color-light-graphic-secondary);
|
|
@@ -48,8 +47,7 @@
|
|
|
48
47
|
|
|
49
48
|
/* inactive */
|
|
50
49
|
--switch-inactive-color: var(--color-light-border-underline);
|
|
51
|
-
}
|
|
52
|
-
.switch__component_s25if {
|
|
50
|
+
} .switch__component_1pggx {
|
|
53
51
|
display: inline-flex;
|
|
54
52
|
align-items: flex-start;
|
|
55
53
|
margin: 0;
|
|
@@ -57,26 +55,20 @@
|
|
|
57
55
|
border: 0;
|
|
58
56
|
cursor: pointer;
|
|
59
57
|
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
|
|
60
|
-
}
|
|
61
|
-
.switch__component_s25if input {
|
|
58
|
+
} .switch__component_1pggx input {
|
|
62
59
|
opacity: 0;
|
|
63
60
|
position: absolute;
|
|
64
|
-
}
|
|
65
|
-
.switch__start_s25if {
|
|
61
|
+
} .switch__start_1pggx {
|
|
66
62
|
align-items: flex-start;
|
|
67
|
-
}
|
|
68
|
-
.switch__center_s25if {
|
|
63
|
+
} .switch__center_1pggx {
|
|
69
64
|
align-items: center;
|
|
70
|
-
}
|
|
71
|
-
.switch__addons_s25if {
|
|
65
|
+
} .switch__addons_1pggx {
|
|
72
66
|
margin-left: auto;
|
|
73
67
|
padding-left: var(--gap-m);
|
|
74
68
|
line-height: 24px;
|
|
75
|
-
}
|
|
76
|
-
.switch__block_s25if {
|
|
69
|
+
} .switch__block_1pggx {
|
|
77
70
|
width: 100%;
|
|
78
|
-
}
|
|
79
|
-
.switch__switch_s25if {
|
|
71
|
+
} .switch__switch_1pggx {
|
|
80
72
|
position: relative;
|
|
81
73
|
border-radius: var(--border-radius-xl);
|
|
82
74
|
width: 36px;
|
|
@@ -87,8 +79,7 @@
|
|
|
87
79
|
border: 2px solid var(--switch-border-color);
|
|
88
80
|
transition: background-color 0.2s ease, border-color 0.2s ease;
|
|
89
81
|
box-sizing: border-box;
|
|
90
|
-
}
|
|
91
|
-
.switch__switch_s25if:before {
|
|
82
|
+
} .switch__switch_1pggx:before {
|
|
92
83
|
content: '';
|
|
93
84
|
position: absolute;
|
|
94
85
|
top: 0;
|
|
@@ -100,78 +91,56 @@
|
|
|
100
91
|
background-color: var(--color-light-graphic-primary-inverted);
|
|
101
92
|
box-sizing: border-box;
|
|
102
93
|
transition: transform 0.2s ease;
|
|
103
|
-
}
|
|
104
|
-
.switch__content_s25if {
|
|
94
|
+
} .switch__content_1pggx {
|
|
105
95
|
margin-left: var(--gap-s);
|
|
106
96
|
flex-grow: 1;
|
|
107
|
-
}
|
|
108
|
-
.switch__label_s25if {
|
|
97
|
+
} .switch__label_1pggx {
|
|
109
98
|
font-size: 16px;
|
|
110
99
|
line-height: 24px;
|
|
111
100
|
font-weight: 400;
|
|
112
101
|
display: block;
|
|
113
102
|
color: var(--switch-label-color);
|
|
114
|
-
}
|
|
115
|
-
.switch__label_s25if:not(:only-child) {
|
|
103
|
+
} .switch__label_1pggx:not(:only-child) {
|
|
116
104
|
margin-bottom: var(--gap-2xs);
|
|
117
|
-
}
|
|
118
|
-
.switch__hint_s25if {
|
|
105
|
+
} .switch__hint_1pggx {
|
|
119
106
|
font-size: 14px;
|
|
120
107
|
line-height: 18px;
|
|
121
108
|
font-weight: 400;
|
|
122
109
|
display: block;
|
|
123
110
|
color: var(--switch-hint-color);
|
|
124
|
-
}
|
|
125
|
-
/* Reversed state */
|
|
126
|
-
.switch__component_s25if.switch__reversed_s25if {
|
|
111
|
+
} /* Reversed state */ .switch__component_1pggx.switch__reversed_1pggx {
|
|
127
112
|
flex-direction: row-reverse;
|
|
128
|
-
}
|
|
129
|
-
.switch__reversed_s25if .switch__content_s25if {
|
|
113
|
+
} .switch__reversed_1pggx .switch__content_1pggx {
|
|
130
114
|
margin-right: var(--gap-m);
|
|
131
115
|
margin-left: 0;
|
|
132
|
-
}
|
|
133
|
-
.switch__reversed_s25if .switch__addons_s25if {
|
|
116
|
+
} .switch__reversed_1pggx .switch__addons_1pggx {
|
|
134
117
|
margin-left: 0;
|
|
135
118
|
padding-left: 0;
|
|
136
119
|
margin-right: auto;
|
|
137
120
|
padding-right: var(--gap-m);
|
|
138
|
-
}
|
|
139
|
-
/* Checked state */
|
|
140
|
-
.switch__checked_s25if .switch__switch_s25if {
|
|
121
|
+
} /* Checked state */ .switch__checked_1pggx .switch__switch_1pggx {
|
|
141
122
|
background-color: var(--switch-checked-bg-color);
|
|
142
123
|
border-color: var(--switch-checked-border-color);
|
|
143
|
-
}
|
|
144
|
-
.switch__checked_s25if .switch__switch_s25if:before {
|
|
124
|
+
} .switch__checked_1pggx .switch__switch_1pggx:before {
|
|
145
125
|
/* ширина компонента(36px + 2*2px) - отступы(2 * 2px) - размер кружка(20px) */
|
|
146
126
|
transform: translateX(16px);
|
|
147
|
-
}
|
|
148
|
-
/* Disabled state */
|
|
149
|
-
.switch__disabled_s25if {
|
|
127
|
+
} /* Disabled state */ .switch__disabled_1pggx {
|
|
150
128
|
cursor: var(--disabled-cursor);
|
|
151
|
-
}
|
|
152
|
-
.switch__disabled_s25if .switch__switch_s25if {
|
|
129
|
+
} .switch__disabled_1pggx .switch__switch_1pggx {
|
|
153
130
|
background-color: var(--switch-disabled-bg-color);
|
|
154
131
|
border-color: var(--switch-disabled-border-color);
|
|
155
|
-
}
|
|
156
|
-
.switch__disabled_s25if .switch__label_s25if {
|
|
132
|
+
} .switch__disabled_1pggx .switch__label_1pggx {
|
|
157
133
|
color: var(--switch-disabled-color);
|
|
158
|
-
}
|
|
159
|
-
.switch__disabled_s25if .switch__hint_s25if {
|
|
134
|
+
} .switch__disabled_1pggx .switch__hint_1pggx {
|
|
160
135
|
color: var(--switch-disabled-color);
|
|
161
|
-
}
|
|
162
|
-
/* Inactive */
|
|
163
|
-
.switch__inactive_s25if {
|
|
136
|
+
} /* Inactive */ .switch__inactive_1pggx {
|
|
164
137
|
cursor: var(--disabled-cursor);
|
|
165
|
-
}
|
|
166
|
-
.switch__inactive_s25if .switch__switch_s25if {
|
|
138
|
+
} .switch__inactive_1pggx .switch__switch_1pggx {
|
|
167
139
|
background-color: var(--switch-disabled-bg-color);
|
|
168
140
|
border-color: var(--switch-disabled-border-color)
|
|
169
|
-
}
|
|
170
|
-
.switch__inactive_s25if .switch__switch_s25if:before {
|
|
141
|
+
} .switch__inactive_1pggx .switch__switch_1pggx:before {
|
|
171
142
|
background-color: var(--switch-inactive-color);
|
|
172
|
-
}
|
|
173
|
-
/* Focused state */
|
|
174
|
-
.switch__focused_s25if .switch__switch_s25if {
|
|
143
|
+
} /* Focused state */ .switch__focused_1pggx .switch__switch_1pggx {
|
|
175
144
|
outline: 2px solid var(--focus-color);
|
|
176
145
|
outline-offset: 2px;
|
|
177
146
|
}
|
package/modern/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alfalab/core-components-switch",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"gitHead": "f054fef20200664c65e2501ef1f916c555cdf05d",
|
|
6
6
|
"keywords": [],
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@alfalab/hooks": "^1.4.1",
|
|
22
22
|
"classnames": "^2.3.1",
|
|
23
|
-
"react-merge-refs": "^1.1.0"
|
|
23
|
+
"react-merge-refs": "^1.1.0",
|
|
24
|
+
"tslib": "^2.4.0"
|
|
24
25
|
}
|
|
25
26
|
}
|