@alfalab/core-components-switch 4.2.6 → 4.3.0
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.js +1 -1
- package/esm/Component.js +1 -1
- package/esm/index.css +28 -28
- package/index.css +28 -28
- package/modern/Component.js +1 -1
- package/modern/index.css +28 -28
- package/moderncssm/Component.d.ts +115 -0
- package/moderncssm/Component.js +36 -0
- package/moderncssm/index.d.ts +1 -0
- package/moderncssm/index.js +1 -0
- package/moderncssm/index.module.css +189 -0
- package/package.json +3 -3
- package/src/index.module.css +1 -1
package/Component.js
CHANGED
|
@@ -15,7 +15,7 @@ var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
|
15
15
|
var mergeRefs__default = /*#__PURE__*/_interopDefaultCompat(mergeRefs);
|
|
16
16
|
var cn__default = /*#__PURE__*/_interopDefaultCompat(cn);
|
|
17
17
|
|
|
18
|
-
var styles = {"component":"
|
|
18
|
+
var styles = {"component":"switch__component_13p1i","start":"switch__start_13p1i","center":"switch__center_13p1i","addons":"switch__addons_13p1i","block":"switch__block_13p1i","switch":"switch__switch_13p1i","content":"switch__content_13p1i","label":"switch__label_13p1i","errorMessage":"switch__errorMessage_13p1i","hint":"switch__hint_13p1i","reversed":"switch__reversed_13p1i","checked":"switch__checked_13p1i","disabled":"switch__disabled_13p1i","focused":"switch__focused_13p1i"};
|
|
19
19
|
require('./index.css')
|
|
20
20
|
|
|
21
21
|
var Switch = React.forwardRef(function (_a, ref) {
|
package/esm/Component.js
CHANGED
|
@@ -5,7 +5,7 @@ import cn from 'classnames';
|
|
|
5
5
|
import { dom } from '@alfalab/core-components-shared/esm';
|
|
6
6
|
import { useFocus } from '@alfalab/hooks';
|
|
7
7
|
|
|
8
|
-
var styles = {"component":"
|
|
8
|
+
var styles = {"component":"switch__component_13p1i","start":"switch__start_13p1i","center":"switch__center_13p1i","addons":"switch__addons_13p1i","block":"switch__block_13p1i","switch":"switch__switch_13p1i","content":"switch__content_13p1i","label":"switch__label_13p1i","errorMessage":"switch__errorMessage_13p1i","hint":"switch__hint_13p1i","reversed":"switch__reversed_13p1i","checked":"switch__checked_13p1i","disabled":"switch__disabled_13p1i","focused":"switch__focused_13p1i"};
|
|
9
9
|
require('./index.css')
|
|
10
10
|
|
|
11
11
|
var Switch = forwardRef(function (_a, ref) {
|
package/esm/index.css
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* hash:
|
|
1
|
+
/* hash: b1g6i */
|
|
2
2
|
:root { /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */
|
|
3
3
|
} /* deprecated */ :root {
|
|
4
4
|
--color-light-neutral-translucent-200: rgba(30, 43, 68, 0.08);
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
/* icon */
|
|
66
66
|
--switch-icon-color: var(--color-static-neutral-0);
|
|
67
67
|
--switch-icon-disabled-color: var(--color-light-neutral-translucent-500);
|
|
68
|
-
} .
|
|
68
|
+
} .switch__component_13p1i {
|
|
69
69
|
display: inline-flex;
|
|
70
70
|
align-items: flex-start;
|
|
71
71
|
margin: 0;
|
|
@@ -73,20 +73,20 @@
|
|
|
73
73
|
border: 0;
|
|
74
74
|
cursor: pointer;
|
|
75
75
|
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
|
|
76
|
-
} .
|
|
76
|
+
} .switch__component_13p1i input {
|
|
77
77
|
opacity: 0;
|
|
78
78
|
position: absolute;
|
|
79
|
-
} .
|
|
79
|
+
} .switch__start_13p1i {
|
|
80
80
|
align-items: flex-start;
|
|
81
|
-
} .
|
|
81
|
+
} .switch__center_13p1i {
|
|
82
82
|
align-items: center;
|
|
83
|
-
} .
|
|
83
|
+
} .switch__addons_13p1i {
|
|
84
84
|
margin-left: auto;
|
|
85
85
|
padding-left: var(--gap-16);
|
|
86
86
|
line-height: 24px;
|
|
87
|
-
} .
|
|
87
|
+
} .switch__block_13p1i {
|
|
88
88
|
width: 100%;
|
|
89
|
-
} .
|
|
89
|
+
} .switch__switch_13p1i {
|
|
90
90
|
position: relative;
|
|
91
91
|
border-radius: var(--border-radius-xl);
|
|
92
92
|
width: 36px;
|
|
@@ -97,9 +97,9 @@
|
|
|
97
97
|
border: 2px solid var(--switch-border-color);
|
|
98
98
|
transition: background-color 0.2s ease, border-color 0.2s ease;
|
|
99
99
|
box-sizing: border-box
|
|
100
|
-
} .
|
|
100
|
+
} .switch__switch_13p1i:hover {
|
|
101
101
|
background-color: var(--switch-hover-bg-color);
|
|
102
|
-
} .
|
|
102
|
+
} .switch__switch_13p1i:before {
|
|
103
103
|
content: '';
|
|
104
104
|
position: absolute;
|
|
105
105
|
top: 0;
|
|
@@ -111,58 +111,58 @@
|
|
|
111
111
|
background-color: var(--switch-icon-color);
|
|
112
112
|
box-sizing: border-box;
|
|
113
113
|
transition: transform 0.2s ease;
|
|
114
|
-
} .
|
|
114
|
+
} .switch__content_13p1i {
|
|
115
115
|
margin-left: var(--gap-12);
|
|
116
116
|
flex-grow: 1;
|
|
117
|
-
} .
|
|
117
|
+
} .switch__label_13p1i {
|
|
118
118
|
font-size: 16px;
|
|
119
119
|
line-height: 24px;
|
|
120
120
|
font-weight: 400;
|
|
121
121
|
display: block;
|
|
122
122
|
color: var(--switch-label-color);
|
|
123
|
-
} .
|
|
123
|
+
} .switch__label_13p1i:not(:only-child) {
|
|
124
124
|
margin-bottom: var(--gap-4);
|
|
125
|
-
} .
|
|
125
|
+
} .switch__errorMessage_13p1i {
|
|
126
126
|
font-size: 14px;
|
|
127
127
|
line-height: 18px;
|
|
128
128
|
font-weight: 400;
|
|
129
129
|
color: var(--switch-error-color);
|
|
130
|
-
} .
|
|
130
|
+
} .switch__hint_13p1i {
|
|
131
131
|
font-size: 14px;
|
|
132
132
|
line-height: 18px;
|
|
133
133
|
font-weight: 400;
|
|
134
134
|
display: block;
|
|
135
135
|
color: var(--switch-hint-color);
|
|
136
|
-
} /* Reversed state */ .
|
|
136
|
+
} /* Reversed state */ .switch__component_13p1i.switch__reversed_13p1i {
|
|
137
137
|
flex-direction: row-reverse;
|
|
138
|
-
} .
|
|
138
|
+
} .switch__reversed_13p1i .switch__content_13p1i {
|
|
139
139
|
margin-right: var(--gap-16);
|
|
140
140
|
margin-left: 0;
|
|
141
|
-
} .
|
|
141
|
+
} .switch__reversed_13p1i .switch__addons_13p1i {
|
|
142
142
|
margin-left: 0;
|
|
143
143
|
padding-left: 0;
|
|
144
144
|
margin-right: auto;
|
|
145
145
|
padding-right: var(--gap-16);
|
|
146
|
-
} /* Checked state */ .
|
|
146
|
+
} /* Checked state */ .switch__checked_13p1i .switch__switch_13p1i {
|
|
147
147
|
background-color: var(--switch-checked-bg-color)
|
|
148
|
-
} .
|
|
148
|
+
} .switch__checked_13p1i .switch__switch_13p1i:hover {
|
|
149
149
|
background-color: var(--switch-checked-hover-bg-color);
|
|
150
|
-
} .
|
|
150
|
+
} .switch__checked_13p1i .switch__switch_13p1i:before {
|
|
151
151
|
/* ширина компонента(36px + 2*2px) - отступы(2 * 2px) - размер кружка(20px) */
|
|
152
152
|
transform: translateX(16px);
|
|
153
|
-
} /* Disabled state */ .
|
|
153
|
+
} /* Disabled state */ .switch__disabled_13p1i {
|
|
154
154
|
cursor: var(--disabled-cursor);
|
|
155
|
-
} .
|
|
155
|
+
} .switch__disabled_13p1i .switch__switch_13p1i {
|
|
156
156
|
background-color: var(--switch-disabled-bg-color)
|
|
157
|
-
} .
|
|
157
|
+
} .switch__disabled_13p1i .switch__switch_13p1i:before {
|
|
158
158
|
background-color: var(--switch-icon-disabled-color);
|
|
159
|
-
} .
|
|
159
|
+
} .switch__disabled_13p1i.switch__checked_13p1i .switch__switch_13p1i {
|
|
160
160
|
background-color: var(--switch-disabled-checked-bg-color);
|
|
161
|
-
} .
|
|
161
|
+
} .switch__disabled_13p1i .switch__label_13p1i {
|
|
162
162
|
color: var(--switch-disabled-color);
|
|
163
|
-
} .
|
|
163
|
+
} .switch__disabled_13p1i .switch__hint_13p1i {
|
|
164
164
|
color: var(--switch-disabled-color);
|
|
165
|
-
} /* Focused state */ .
|
|
165
|
+
} /* Focused state */ .switch__focused_13p1i .switch__switch_13p1i {
|
|
166
166
|
outline: 2px solid var(--focus-color);
|
|
167
167
|
outline-offset: 2px;
|
|
168
168
|
}
|
package/index.css
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* hash:
|
|
1
|
+
/* hash: b1g6i */
|
|
2
2
|
:root { /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */
|
|
3
3
|
} /* deprecated */ :root {
|
|
4
4
|
--color-light-neutral-translucent-200: rgba(30, 43, 68, 0.08);
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
/* icon */
|
|
66
66
|
--switch-icon-color: var(--color-static-neutral-0);
|
|
67
67
|
--switch-icon-disabled-color: var(--color-light-neutral-translucent-500);
|
|
68
|
-
} .
|
|
68
|
+
} .switch__component_13p1i {
|
|
69
69
|
display: inline-flex;
|
|
70
70
|
align-items: flex-start;
|
|
71
71
|
margin: 0;
|
|
@@ -73,20 +73,20 @@
|
|
|
73
73
|
border: 0;
|
|
74
74
|
cursor: pointer;
|
|
75
75
|
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
|
|
76
|
-
} .
|
|
76
|
+
} .switch__component_13p1i input {
|
|
77
77
|
opacity: 0;
|
|
78
78
|
position: absolute;
|
|
79
|
-
} .
|
|
79
|
+
} .switch__start_13p1i {
|
|
80
80
|
align-items: flex-start;
|
|
81
|
-
} .
|
|
81
|
+
} .switch__center_13p1i {
|
|
82
82
|
align-items: center;
|
|
83
|
-
} .
|
|
83
|
+
} .switch__addons_13p1i {
|
|
84
84
|
margin-left: auto;
|
|
85
85
|
padding-left: var(--gap-16);
|
|
86
86
|
line-height: 24px;
|
|
87
|
-
} .
|
|
87
|
+
} .switch__block_13p1i {
|
|
88
88
|
width: 100%;
|
|
89
|
-
} .
|
|
89
|
+
} .switch__switch_13p1i {
|
|
90
90
|
position: relative;
|
|
91
91
|
border-radius: var(--border-radius-xl);
|
|
92
92
|
width: 36px;
|
|
@@ -97,9 +97,9 @@
|
|
|
97
97
|
border: 2px solid var(--switch-border-color);
|
|
98
98
|
transition: background-color 0.2s ease, border-color 0.2s ease;
|
|
99
99
|
box-sizing: border-box
|
|
100
|
-
} .
|
|
100
|
+
} .switch__switch_13p1i:hover {
|
|
101
101
|
background-color: var(--switch-hover-bg-color);
|
|
102
|
-
} .
|
|
102
|
+
} .switch__switch_13p1i:before {
|
|
103
103
|
content: '';
|
|
104
104
|
position: absolute;
|
|
105
105
|
top: 0;
|
|
@@ -111,58 +111,58 @@
|
|
|
111
111
|
background-color: var(--switch-icon-color);
|
|
112
112
|
box-sizing: border-box;
|
|
113
113
|
transition: transform 0.2s ease;
|
|
114
|
-
} .
|
|
114
|
+
} .switch__content_13p1i {
|
|
115
115
|
margin-left: var(--gap-12);
|
|
116
116
|
flex-grow: 1;
|
|
117
|
-
} .
|
|
117
|
+
} .switch__label_13p1i {
|
|
118
118
|
font-size: 16px;
|
|
119
119
|
line-height: 24px;
|
|
120
120
|
font-weight: 400;
|
|
121
121
|
display: block;
|
|
122
122
|
color: var(--switch-label-color);
|
|
123
|
-
} .
|
|
123
|
+
} .switch__label_13p1i:not(:only-child) {
|
|
124
124
|
margin-bottom: var(--gap-4);
|
|
125
|
-
} .
|
|
125
|
+
} .switch__errorMessage_13p1i {
|
|
126
126
|
font-size: 14px;
|
|
127
127
|
line-height: 18px;
|
|
128
128
|
font-weight: 400;
|
|
129
129
|
color: var(--switch-error-color);
|
|
130
|
-
} .
|
|
130
|
+
} .switch__hint_13p1i {
|
|
131
131
|
font-size: 14px;
|
|
132
132
|
line-height: 18px;
|
|
133
133
|
font-weight: 400;
|
|
134
134
|
display: block;
|
|
135
135
|
color: var(--switch-hint-color);
|
|
136
|
-
} /* Reversed state */ .
|
|
136
|
+
} /* Reversed state */ .switch__component_13p1i.switch__reversed_13p1i {
|
|
137
137
|
flex-direction: row-reverse;
|
|
138
|
-
} .
|
|
138
|
+
} .switch__reversed_13p1i .switch__content_13p1i {
|
|
139
139
|
margin-right: var(--gap-16);
|
|
140
140
|
margin-left: 0;
|
|
141
|
-
} .
|
|
141
|
+
} .switch__reversed_13p1i .switch__addons_13p1i {
|
|
142
142
|
margin-left: 0;
|
|
143
143
|
padding-left: 0;
|
|
144
144
|
margin-right: auto;
|
|
145
145
|
padding-right: var(--gap-16);
|
|
146
|
-
} /* Checked state */ .
|
|
146
|
+
} /* Checked state */ .switch__checked_13p1i .switch__switch_13p1i {
|
|
147
147
|
background-color: var(--switch-checked-bg-color)
|
|
148
|
-
} .
|
|
148
|
+
} .switch__checked_13p1i .switch__switch_13p1i:hover {
|
|
149
149
|
background-color: var(--switch-checked-hover-bg-color);
|
|
150
|
-
} .
|
|
150
|
+
} .switch__checked_13p1i .switch__switch_13p1i:before {
|
|
151
151
|
/* ширина компонента(36px + 2*2px) - отступы(2 * 2px) - размер кружка(20px) */
|
|
152
152
|
transform: translateX(16px);
|
|
153
|
-
} /* Disabled state */ .
|
|
153
|
+
} /* Disabled state */ .switch__disabled_13p1i {
|
|
154
154
|
cursor: var(--disabled-cursor);
|
|
155
|
-
} .
|
|
155
|
+
} .switch__disabled_13p1i .switch__switch_13p1i {
|
|
156
156
|
background-color: var(--switch-disabled-bg-color)
|
|
157
|
-
} .
|
|
157
|
+
} .switch__disabled_13p1i .switch__switch_13p1i:before {
|
|
158
158
|
background-color: var(--switch-icon-disabled-color);
|
|
159
|
-
} .
|
|
159
|
+
} .switch__disabled_13p1i.switch__checked_13p1i .switch__switch_13p1i {
|
|
160
160
|
background-color: var(--switch-disabled-checked-bg-color);
|
|
161
|
-
} .
|
|
161
|
+
} .switch__disabled_13p1i .switch__label_13p1i {
|
|
162
162
|
color: var(--switch-disabled-color);
|
|
163
|
-
} .
|
|
163
|
+
} .switch__disabled_13p1i .switch__hint_13p1i {
|
|
164
164
|
color: var(--switch-disabled-color);
|
|
165
|
-
} /* Focused state */ .
|
|
165
|
+
} /* Focused state */ .switch__focused_13p1i .switch__switch_13p1i {
|
|
166
166
|
outline: 2px solid var(--focus-color);
|
|
167
167
|
outline-offset: 2px;
|
|
168
168
|
}
|
package/modern/Component.js
CHANGED
|
@@ -4,7 +4,7 @@ import cn from 'classnames';
|
|
|
4
4
|
import { dom } from '@alfalab/core-components-shared/modern';
|
|
5
5
|
import { useFocus } from '@alfalab/hooks';
|
|
6
6
|
|
|
7
|
-
const styles = {"component":"
|
|
7
|
+
const styles = {"component":"switch__component_13p1i","start":"switch__start_13p1i","center":"switch__center_13p1i","addons":"switch__addons_13p1i","block":"switch__block_13p1i","switch":"switch__switch_13p1i","content":"switch__content_13p1i","label":"switch__label_13p1i","errorMessage":"switch__errorMessage_13p1i","hint":"switch__hint_13p1i","reversed":"switch__reversed_13p1i","checked":"switch__checked_13p1i","disabled":"switch__disabled_13p1i","focused":"switch__focused_13p1i"};
|
|
8
8
|
require('./index.css')
|
|
9
9
|
|
|
10
10
|
const Switch = forwardRef(({ reversed = false, checked = false, align = 'start', addons, block, disabled, inactive, error, label, hint, name, value, className, onChange, dataTestId, ...restProps }, ref) => {
|
package/modern/index.css
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* hash:
|
|
1
|
+
/* hash: b1g6i */
|
|
2
2
|
:root { /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */
|
|
3
3
|
} /* deprecated */ :root {
|
|
4
4
|
--color-light-neutral-translucent-200: rgba(30, 43, 68, 0.08);
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
/* icon */
|
|
66
66
|
--switch-icon-color: var(--color-static-neutral-0);
|
|
67
67
|
--switch-icon-disabled-color: var(--color-light-neutral-translucent-500);
|
|
68
|
-
} .
|
|
68
|
+
} .switch__component_13p1i {
|
|
69
69
|
display: inline-flex;
|
|
70
70
|
align-items: flex-start;
|
|
71
71
|
margin: 0;
|
|
@@ -73,20 +73,20 @@
|
|
|
73
73
|
border: 0;
|
|
74
74
|
cursor: pointer;
|
|
75
75
|
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
|
|
76
|
-
} .
|
|
76
|
+
} .switch__component_13p1i input {
|
|
77
77
|
opacity: 0;
|
|
78
78
|
position: absolute;
|
|
79
|
-
} .
|
|
79
|
+
} .switch__start_13p1i {
|
|
80
80
|
align-items: flex-start;
|
|
81
|
-
} .
|
|
81
|
+
} .switch__center_13p1i {
|
|
82
82
|
align-items: center;
|
|
83
|
-
} .
|
|
83
|
+
} .switch__addons_13p1i {
|
|
84
84
|
margin-left: auto;
|
|
85
85
|
padding-left: var(--gap-16);
|
|
86
86
|
line-height: 24px;
|
|
87
|
-
} .
|
|
87
|
+
} .switch__block_13p1i {
|
|
88
88
|
width: 100%;
|
|
89
|
-
} .
|
|
89
|
+
} .switch__switch_13p1i {
|
|
90
90
|
position: relative;
|
|
91
91
|
border-radius: var(--border-radius-xl);
|
|
92
92
|
width: 36px;
|
|
@@ -97,9 +97,9 @@
|
|
|
97
97
|
border: 2px solid var(--switch-border-color);
|
|
98
98
|
transition: background-color 0.2s ease, border-color 0.2s ease;
|
|
99
99
|
box-sizing: border-box
|
|
100
|
-
} .
|
|
100
|
+
} .switch__switch_13p1i:hover {
|
|
101
101
|
background-color: var(--switch-hover-bg-color);
|
|
102
|
-
} .
|
|
102
|
+
} .switch__switch_13p1i:before {
|
|
103
103
|
content: '';
|
|
104
104
|
position: absolute;
|
|
105
105
|
top: 0;
|
|
@@ -111,58 +111,58 @@
|
|
|
111
111
|
background-color: var(--switch-icon-color);
|
|
112
112
|
box-sizing: border-box;
|
|
113
113
|
transition: transform 0.2s ease;
|
|
114
|
-
} .
|
|
114
|
+
} .switch__content_13p1i {
|
|
115
115
|
margin-left: var(--gap-12);
|
|
116
116
|
flex-grow: 1;
|
|
117
|
-
} .
|
|
117
|
+
} .switch__label_13p1i {
|
|
118
118
|
font-size: 16px;
|
|
119
119
|
line-height: 24px;
|
|
120
120
|
font-weight: 400;
|
|
121
121
|
display: block;
|
|
122
122
|
color: var(--switch-label-color);
|
|
123
|
-
} .
|
|
123
|
+
} .switch__label_13p1i:not(:only-child) {
|
|
124
124
|
margin-bottom: var(--gap-4);
|
|
125
|
-
} .
|
|
125
|
+
} .switch__errorMessage_13p1i {
|
|
126
126
|
font-size: 14px;
|
|
127
127
|
line-height: 18px;
|
|
128
128
|
font-weight: 400;
|
|
129
129
|
color: var(--switch-error-color);
|
|
130
|
-
} .
|
|
130
|
+
} .switch__hint_13p1i {
|
|
131
131
|
font-size: 14px;
|
|
132
132
|
line-height: 18px;
|
|
133
133
|
font-weight: 400;
|
|
134
134
|
display: block;
|
|
135
135
|
color: var(--switch-hint-color);
|
|
136
|
-
} /* Reversed state */ .
|
|
136
|
+
} /* Reversed state */ .switch__component_13p1i.switch__reversed_13p1i {
|
|
137
137
|
flex-direction: row-reverse;
|
|
138
|
-
} .
|
|
138
|
+
} .switch__reversed_13p1i .switch__content_13p1i {
|
|
139
139
|
margin-right: var(--gap-16);
|
|
140
140
|
margin-left: 0;
|
|
141
|
-
} .
|
|
141
|
+
} .switch__reversed_13p1i .switch__addons_13p1i {
|
|
142
142
|
margin-left: 0;
|
|
143
143
|
padding-left: 0;
|
|
144
144
|
margin-right: auto;
|
|
145
145
|
padding-right: var(--gap-16);
|
|
146
|
-
} /* Checked state */ .
|
|
146
|
+
} /* Checked state */ .switch__checked_13p1i .switch__switch_13p1i {
|
|
147
147
|
background-color: var(--switch-checked-bg-color)
|
|
148
|
-
} .
|
|
148
|
+
} .switch__checked_13p1i .switch__switch_13p1i:hover {
|
|
149
149
|
background-color: var(--switch-checked-hover-bg-color);
|
|
150
|
-
} .
|
|
150
|
+
} .switch__checked_13p1i .switch__switch_13p1i:before {
|
|
151
151
|
/* ширина компонента(36px + 2*2px) - отступы(2 * 2px) - размер кружка(20px) */
|
|
152
152
|
transform: translateX(16px);
|
|
153
|
-
} /* Disabled state */ .
|
|
153
|
+
} /* Disabled state */ .switch__disabled_13p1i {
|
|
154
154
|
cursor: var(--disabled-cursor);
|
|
155
|
-
} .
|
|
155
|
+
} .switch__disabled_13p1i .switch__switch_13p1i {
|
|
156
156
|
background-color: var(--switch-disabled-bg-color)
|
|
157
|
-
} .
|
|
157
|
+
} .switch__disabled_13p1i .switch__switch_13p1i:before {
|
|
158
158
|
background-color: var(--switch-icon-disabled-color);
|
|
159
|
-
} .
|
|
159
|
+
} .switch__disabled_13p1i.switch__checked_13p1i .switch__switch_13p1i {
|
|
160
160
|
background-color: var(--switch-disabled-checked-bg-color);
|
|
161
|
-
} .
|
|
161
|
+
} .switch__disabled_13p1i .switch__label_13p1i {
|
|
162
162
|
color: var(--switch-disabled-color);
|
|
163
|
-
} .
|
|
163
|
+
} .switch__disabled_13p1i .switch__hint_13p1i {
|
|
164
164
|
color: var(--switch-disabled-color);
|
|
165
|
-
} /* Focused state */ .
|
|
165
|
+
} /* Focused state */ .switch__focused_13p1i .switch__switch_13p1i {
|
|
166
166
|
outline: 2px solid var(--focus-color);
|
|
167
167
|
outline-offset: 2px;
|
|
168
168
|
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ChangeEvent, InputHTMLAttributes, ReactNode } from "react";
|
|
4
|
+
type Align = 'start' | 'center';
|
|
5
|
+
type SwitchProps = Omit<InputHTMLAttributes<HTMLInputElement>, 'type' | 'hint' | 'onChange' | 'disabled' | 'enterKeyHint'> & {
|
|
6
|
+
/**
|
|
7
|
+
* Управление состоянием вкл/выкл компонента
|
|
8
|
+
*/
|
|
9
|
+
checked?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Текст подписи к переключателю
|
|
12
|
+
*/
|
|
13
|
+
label?: ReactNode;
|
|
14
|
+
/**
|
|
15
|
+
* Текст подсказки снизу
|
|
16
|
+
*/
|
|
17
|
+
hint?: ReactNode;
|
|
18
|
+
/**
|
|
19
|
+
* Переключатель будет отрисован справа от контента
|
|
20
|
+
*/
|
|
21
|
+
reversed?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Выравнивание
|
|
24
|
+
*/
|
|
25
|
+
align?: Align;
|
|
26
|
+
/**
|
|
27
|
+
* Дополнительный слот
|
|
28
|
+
*/
|
|
29
|
+
addons?: React.ReactNode;
|
|
30
|
+
/**
|
|
31
|
+
* Растягивать ли компонент на всю ширину
|
|
32
|
+
*/
|
|
33
|
+
block?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Управление состоянием включен / выключен
|
|
36
|
+
*/
|
|
37
|
+
disabled?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* @deprecated данный проп больше не используется, временно оставлен для обратной совместимости
|
|
40
|
+
* Используйте props disabled
|
|
41
|
+
* Управление состоянием активен / неактивен
|
|
42
|
+
*/
|
|
43
|
+
inactive?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Отображение ошибки
|
|
46
|
+
*/
|
|
47
|
+
error?: ReactNode | boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Обработчик переключения компонента
|
|
50
|
+
*/
|
|
51
|
+
onChange?: (event: ChangeEvent<HTMLInputElement>, payload: {
|
|
52
|
+
checked: boolean;
|
|
53
|
+
name: InputHTMLAttributes<HTMLInputElement>['name'];
|
|
54
|
+
}) => void;
|
|
55
|
+
/**
|
|
56
|
+
* Идентификатор для систем автоматизированного тестирования
|
|
57
|
+
*/
|
|
58
|
+
dataTestId?: string;
|
|
59
|
+
};
|
|
60
|
+
declare const Switch: React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "type" | "hint" | "onChange" | "disabled" | "enterKeyHint"> & {
|
|
61
|
+
/**
|
|
62
|
+
* Управление состоянием вкл/выкл компонента
|
|
63
|
+
*/
|
|
64
|
+
checked?: boolean | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Текст подписи к переключателю
|
|
67
|
+
*/
|
|
68
|
+
label?: ReactNode;
|
|
69
|
+
/**
|
|
70
|
+
* Текст подсказки снизу
|
|
71
|
+
*/
|
|
72
|
+
hint?: ReactNode;
|
|
73
|
+
/**
|
|
74
|
+
* Переключатель будет отрисован справа от контента
|
|
75
|
+
*/
|
|
76
|
+
reversed?: boolean | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Выравнивание
|
|
79
|
+
*/
|
|
80
|
+
align?: Align | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* Дополнительный слот
|
|
83
|
+
*/
|
|
84
|
+
addons?: React.ReactNode;
|
|
85
|
+
/**
|
|
86
|
+
* Растягивать ли компонент на всю ширину
|
|
87
|
+
*/
|
|
88
|
+
block?: boolean | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* Управление состоянием включен / выключен
|
|
91
|
+
*/
|
|
92
|
+
disabled?: boolean | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* @deprecated данный проп больше не используется, временно оставлен для обратной совместимости
|
|
95
|
+
* Используйте props disabled
|
|
96
|
+
* Управление состоянием активен / неактивен
|
|
97
|
+
*/
|
|
98
|
+
inactive?: boolean | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* Отображение ошибки
|
|
101
|
+
*/
|
|
102
|
+
error?: ReactNode | boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Обработчик переключения компонента
|
|
105
|
+
*/
|
|
106
|
+
onChange?: ((event: ChangeEvent<HTMLInputElement>, payload: {
|
|
107
|
+
checked: boolean;
|
|
108
|
+
name: InputHTMLAttributes<HTMLInputElement>['name'];
|
|
109
|
+
}) => void) | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* Идентификатор для систем автоматизированного тестирования
|
|
112
|
+
*/
|
|
113
|
+
dataTestId?: string | undefined;
|
|
114
|
+
} & React.RefAttributes<HTMLLabelElement>>;
|
|
115
|
+
export { SwitchProps, Switch };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React, { forwardRef, useRef } from 'react';
|
|
2
|
+
import mergeRefs from 'react-merge-refs';
|
|
3
|
+
import cn from 'classnames';
|
|
4
|
+
import { dom } from '@alfalab/core-components-shared/moderncssm';
|
|
5
|
+
import { useFocus } from '@alfalab/hooks';
|
|
6
|
+
import styles from './index.module.css';
|
|
7
|
+
|
|
8
|
+
const Switch = forwardRef(({ reversed = false, checked = false, align = 'start', addons, block, disabled, inactive, error, label, hint, name, value, className, onChange, dataTestId, ...restProps }, ref) => {
|
|
9
|
+
const labelRef = useRef(null);
|
|
10
|
+
const [focused] = useFocus(labelRef, 'keyboard');
|
|
11
|
+
const handleChange = (e) => {
|
|
12
|
+
if (onChange) {
|
|
13
|
+
onChange(e, { checked: e.target.checked, name });
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const errorMessage = typeof error === 'boolean' ? '' : error;
|
|
17
|
+
return (React.createElement("label", { className: cn(styles.component, styles[align], className, {
|
|
18
|
+
[styles.disabled]: disabled || inactive,
|
|
19
|
+
[styles.checked]: checked,
|
|
20
|
+
[styles.reversed]: reversed,
|
|
21
|
+
[styles.focused]: focused,
|
|
22
|
+
[styles.block]: block,
|
|
23
|
+
}), ref: mergeRefs([labelRef, ref]) },
|
|
24
|
+
React.createElement("input", { type: 'checkbox', onChange: handleChange, disabled: disabled || inactive, checked: checked, name: name, value: value, "data-test-id": dataTestId, ...restProps }),
|
|
25
|
+
React.createElement("span", { className: styles.switch }),
|
|
26
|
+
(label || hint || errorMessage) && (React.createElement("span", { className: styles.content },
|
|
27
|
+
label && React.createElement("span", { className: styles.label }, label),
|
|
28
|
+
hint && !errorMessage && React.createElement("span", { className: styles.hint }, hint),
|
|
29
|
+
errorMessage && (React.createElement("span", { className: styles.errorMessage, role: 'alert' }, errorMessage)))),
|
|
30
|
+
addons && (
|
|
31
|
+
// eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions
|
|
32
|
+
React.createElement("span", { className: styles.addons, onClick: dom.preventDefault }, addons))));
|
|
33
|
+
});
|
|
34
|
+
Switch.displayName = 'Switch';
|
|
35
|
+
|
|
36
|
+
export { Switch };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Component";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Switch } from './Component.js';
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/* */
|
|
2
|
+
|
|
3
|
+
:root {
|
|
4
|
+
--switch-label-color: var(--color-light-text-primary);
|
|
5
|
+
--switch-hint-color: var(--color-light-text-secondary);
|
|
6
|
+
--switch-bg-color: var(--color-light-neutral-translucent-700);
|
|
7
|
+
--switch-border-color: transparent;
|
|
8
|
+
--switch-error-color: var(--color-light-text-negative);
|
|
9
|
+
|
|
10
|
+
/* hover */
|
|
11
|
+
--switch-hover-bg-color: var(--color-light-neutral-translucent-700-hover);
|
|
12
|
+
|
|
13
|
+
/* checked */
|
|
14
|
+
--switch-checked-bg-color: var(--color-light-status-positive);
|
|
15
|
+
--switch-checked-hover-bg-color: var(--color-light-status-positive-hover);
|
|
16
|
+
|
|
17
|
+
/* disabled */
|
|
18
|
+
--switch-disabled-color: var(--color-light-text-secondary);
|
|
19
|
+
--switch-disabled-bg-color: var(--color-light-neutral-translucent-200);
|
|
20
|
+
|
|
21
|
+
/* disabled checked */
|
|
22
|
+
--switch-disabled-checked-bg-color: var(--switch-disabled-bg-color);
|
|
23
|
+
|
|
24
|
+
/* icon */
|
|
25
|
+
--switch-icon-color: var(--color-static-neutral-0);
|
|
26
|
+
--switch-icon-disabled-color: var(--color-light-neutral-translucent-500);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.component {
|
|
30
|
+
display: inline-flex;
|
|
31
|
+
align-items: flex-start;
|
|
32
|
+
margin: 0;
|
|
33
|
+
padding: 0;
|
|
34
|
+
border: 0;
|
|
35
|
+
cursor: pointer;
|
|
36
|
+
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.component input {
|
|
40
|
+
opacity: 0;
|
|
41
|
+
position: absolute;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.start {
|
|
45
|
+
align-items: flex-start;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.center {
|
|
49
|
+
align-items: center;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.addons {
|
|
53
|
+
margin-left: auto;
|
|
54
|
+
padding-left: var(--gap-16);
|
|
55
|
+
line-height: 24px;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.block {
|
|
59
|
+
width: 100%;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.switch {
|
|
63
|
+
position: relative;
|
|
64
|
+
border-radius: var(--border-radius-xl);
|
|
65
|
+
width: 36px;
|
|
66
|
+
height: 20px;
|
|
67
|
+
margin: var(--gap-2);
|
|
68
|
+
flex-shrink: 0;
|
|
69
|
+
background-color: var(--switch-bg-color);
|
|
70
|
+
border: 2px solid var(--switch-border-color);
|
|
71
|
+
transition: background-color 0.2s ease, border-color 0.2s ease;
|
|
72
|
+
box-sizing: border-box
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.switch:hover {
|
|
76
|
+
background-color: var(--switch-hover-bg-color);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.switch:before {
|
|
80
|
+
content: '';
|
|
81
|
+
position: absolute;
|
|
82
|
+
top: 0;
|
|
83
|
+
left: 0;
|
|
84
|
+
bottom: 0;
|
|
85
|
+
right: 16px;
|
|
86
|
+
display: block;
|
|
87
|
+
border-radius: var(--border-radius-circle);
|
|
88
|
+
background-color: var(--switch-icon-color);
|
|
89
|
+
box-sizing: border-box;
|
|
90
|
+
transition: transform 0.2s ease;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.content {
|
|
94
|
+
margin-left: var(--gap-12);
|
|
95
|
+
flex-grow: 1;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.label {
|
|
99
|
+
font-size: 16px;
|
|
100
|
+
line-height: 24px;
|
|
101
|
+
font-weight: 400;
|
|
102
|
+
display: block;
|
|
103
|
+
color: var(--switch-label-color);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.label:not(:only-child) {
|
|
107
|
+
margin-bottom: var(--gap-4);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.errorMessage {
|
|
111
|
+
font-size: 14px;
|
|
112
|
+
line-height: 18px;
|
|
113
|
+
font-weight: 400;
|
|
114
|
+
color: var(--switch-error-color);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.hint {
|
|
118
|
+
font-size: 14px;
|
|
119
|
+
line-height: 18px;
|
|
120
|
+
font-weight: 400;
|
|
121
|
+
display: block;
|
|
122
|
+
color: var(--switch-hint-color);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/* Reversed state */
|
|
126
|
+
|
|
127
|
+
.component.reversed {
|
|
128
|
+
flex-direction: row-reverse;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.reversed .content {
|
|
132
|
+
margin-right: var(--gap-16);
|
|
133
|
+
margin-left: 0;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.reversed .addons {
|
|
137
|
+
margin-left: 0;
|
|
138
|
+
padding-left: 0;
|
|
139
|
+
margin-right: auto;
|
|
140
|
+
padding-right: var(--gap-16);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/* Checked state */
|
|
144
|
+
|
|
145
|
+
.checked .switch {
|
|
146
|
+
background-color: var(--switch-checked-bg-color)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.checked .switch:hover {
|
|
150
|
+
background-color: var(--switch-checked-hover-bg-color);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.checked .switch:before {
|
|
154
|
+
/* ширина компонента(36px + 2*2px) - отступы(2 * 2px) - размер кружка(20px) */
|
|
155
|
+
transform: translateX(16px);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/* Disabled state */
|
|
159
|
+
|
|
160
|
+
.disabled {
|
|
161
|
+
cursor: var(--disabled-cursor);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.disabled .switch {
|
|
165
|
+
background-color: var(--switch-disabled-bg-color)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.disabled .switch:before {
|
|
169
|
+
background-color: var(--switch-icon-disabled-color);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.disabled.checked .switch {
|
|
173
|
+
background-color: var(--switch-disabled-checked-bg-color);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.disabled .label {
|
|
177
|
+
color: var(--switch-disabled-color);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
.disabled .hint {
|
|
181
|
+
color: var(--switch-disabled-color);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/* Focused state */
|
|
185
|
+
|
|
186
|
+
.focused .switch {
|
|
187
|
+
outline: 2px solid var(--focus-color);
|
|
188
|
+
outline-offset: 2px;
|
|
189
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alfalab/core-components-switch",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"gitHead": "f054fef20200664c65e2501ef1f916c555cdf05d",
|
|
6
6
|
"keywords": [],
|
|
@@ -21,6 +21,6 @@
|
|
|
21
21
|
"react-merge-refs": "^1.1.0",
|
|
22
22
|
"tslib": "^2.4.0"
|
|
23
23
|
},
|
|
24
|
-
"themesVersion": "13.0
|
|
25
|
-
"varsVersion": "9.
|
|
24
|
+
"themesVersion": "13.1.0",
|
|
25
|
+
"varsVersion": "9.12.0"
|
|
26
26
|
}
|
package/src/index.module.css
CHANGED