@snack-uikit/toggles 0.9.2 → 0.9.4
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/CHANGELOG.md +20 -0
- package/README.md +1 -0
- package/dist/components/Switch/Switch.d.ts +2 -1
- package/dist/components/Switch/Switch.js +4 -5
- package/dist/components/Switch/styles.module.css +5 -5
- package/dist/components/TogglePrivate/styles.module.css +0 -8
- package/dist/helperComponents/Spinner/Spinner.d.ts +1 -0
- package/dist/helperComponents/Spinner/Spinner.js +5 -0
- package/dist/helperComponents/Spinner/index.d.ts +1 -0
- package/dist/helperComponents/Spinner/index.js +1 -0
- package/dist/helperComponents/Spinner/styles.module.css +14 -0
- package/dist/helperComponents/index.d.ts +1 -0
- package/dist/helperComponents/index.js +1 -0
- package/package.json +3 -3
- package/src/components/Switch/Switch.tsx +14 -9
- package/src/components/Switch/styles.module.scss +3 -3
- package/src/components/TogglePrivate/styles.module.scss +0 -9
- package/src/helperComponents/Spinner/Spinner.tsx +9 -0
- package/src/helperComponents/Spinner/index.ts +1 -0
- package/src/helperComponents/Spinner/styles.module.scss +19 -0
- package/src/helperComponents/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,26 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 0.9.4 (2024-01-23)
|
|
7
|
+
|
|
8
|
+
### Only dependencies have been changed
|
|
9
|
+
* [@snack-uikit/icons@0.20.0](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/icons/CHANGELOG.md)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## 0.9.3 (2023-12-28)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* **FF-3960:** add loading state, update colors ([c7678cd](https://github.com/cloud-ru-tech/snack-uikit/commit/c7678cd99cbf2e30618b80d2991b328d234069e4))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
6
26
|
## 0.9.2 (2023-12-18)
|
|
7
27
|
|
|
8
28
|
### Only dependencies have been changed
|
package/README.md
CHANGED
|
@@ -112,6 +112,7 @@ return (
|
|
|
112
112
|
| size | enum Size: `"s"`, `"m"` | m | Размер |
|
|
113
113
|
| inputRef | `RefObject<HTMLInputElement>` | - | |
|
|
114
114
|
| showIcon | `boolean` | - | Показывать ли иконку в переключателе |
|
|
115
|
+
| loading | `boolean` | - | |
|
|
115
116
|
## Radio
|
|
116
117
|
### Props
|
|
117
118
|
| name | type | default value | description |
|
|
@@ -2,5 +2,6 @@ import { ToggleProps } from '../../types';
|
|
|
2
2
|
export type SwitchProps = ToggleProps & {
|
|
3
3
|
/** Показывать ли иконку в переключателе */
|
|
4
4
|
showIcon?: boolean;
|
|
5
|
+
loading?: boolean;
|
|
5
6
|
};
|
|
6
|
-
export declare function Switch({ inputRef, 'data-test-id': dataTestId, showIcon, size, ...restProps }: SwitchProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export declare function Switch({ inputRef, 'data-test-id': dataTestId, showIcon, loading, size, ...restProps }: SwitchProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -10,17 +10,16 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
-
import { useMemo } from 'react';
|
|
14
13
|
import { CheckSVG, CrossSVG } from '@snack-uikit/icons';
|
|
15
14
|
import { SIZE } from '../../constants';
|
|
16
|
-
import {
|
|
15
|
+
import { Spinner } from '../../helperComponents';
|
|
16
|
+
import { getVisualStateAttributes } from '../../utils';
|
|
17
17
|
import { TogglePrivate } from '../TogglePrivate';
|
|
18
18
|
import styles from './styles.module.css';
|
|
19
19
|
export function Switch(_a) {
|
|
20
|
-
var { inputRef, 'data-test-id': dataTestId, showIcon, size = SIZE.M } = _a, restProps = __rest(_a, ["inputRef", 'data-test-id', "showIcon", "size"]);
|
|
21
|
-
const iconSize = useMemo(() => getIconSize(size), [size]);
|
|
20
|
+
var { inputRef, 'data-test-id': dataTestId, showIcon, loading, size = SIZE.M } = _a, restProps = __rest(_a, ["inputRef", 'data-test-id', "showIcon", "loading", "size"]);
|
|
22
21
|
return (_jsx(TogglePrivate, Object.assign({}, restProps, { size: size, "data-test-id": dataTestId, ref: inputRef, render: function Switch(visualState) {
|
|
23
22
|
const data = getVisualStateAttributes(visualState);
|
|
24
|
-
return (_jsxs("div", Object.assign({ className: styles.container }, data, { children: [_jsx("div", Object.assign({ className: styles.box }, data)), _jsxs("div", Object.assign({ className: styles.containerFlag }, data, { children: [_jsx("div", Object.assign({ className: styles.flag }, data)), showIcon && (_jsxs(_Fragment, { children: [_jsx("div", Object.assign({ className: styles.flag_icon_off }, data, { children: _jsx(CrossSVG, { size:
|
|
23
|
+
return (_jsxs("div", Object.assign({ className: styles.container }, data, { children: [_jsx("div", Object.assign({ className: styles.box }, data)), _jsxs("div", Object.assign({ className: styles.containerFlag }, data, { children: [_jsx("div", Object.assign({ className: styles.flag }, data)), (showIcon || loading) && (_jsxs(_Fragment, { children: [_jsx("div", Object.assign({ className: styles.flag_icon_off }, data, { children: loading ? _jsx(Spinner, {}) : _jsx(CrossSVG, { size: 16 }) })), _jsx("div", Object.assign({ className: styles.flag_icon_on }, data, { children: loading ? _jsx(Spinner, {}) : _jsx(CheckSVG, { size: 16 }) }))] }))] }))] })));
|
|
25
24
|
} })));
|
|
26
25
|
}
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
|
|
26
26
|
.box{
|
|
27
27
|
position:relative;
|
|
28
|
-
background-color:var(--sys-neutral-
|
|
28
|
+
background-color:var(--sys-neutral-decor-activated, #b8b8b8);
|
|
29
29
|
}
|
|
30
30
|
.box[data-size=s]{
|
|
31
31
|
width:var(--size-toggles-s-box-switch-width, 24px);
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
left:50%;
|
|
102
102
|
transform:translate(-50%, -50%);
|
|
103
103
|
display:flex;
|
|
104
|
-
color:var(--sys-neutral-
|
|
104
|
+
color:var(--sys-neutral-text-disabled, #9e9e9e);
|
|
105
105
|
fill:transparent;
|
|
106
106
|
transition:opacity 0.1s linear;
|
|
107
107
|
opacity:1;
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
color:var(--sys-primary-accent-hovered, #6851a6);
|
|
117
117
|
}
|
|
118
118
|
.flag_icon_off[data-disabled=true]{
|
|
119
|
-
color:var(--sys-neutral-
|
|
119
|
+
color:var(--sys-neutral-on-accent, #fdfdfd);
|
|
120
120
|
}
|
|
121
121
|
.flag_icon_off[data-checked=true]{
|
|
122
122
|
opacity:0;
|
|
@@ -128,7 +128,7 @@
|
|
|
128
128
|
left:50%;
|
|
129
129
|
transform:translate(-50%, -50%);
|
|
130
130
|
display:flex;
|
|
131
|
-
color:var(--sys-neutral-
|
|
131
|
+
color:var(--sys-neutral-text-disabled, #9e9e9e);
|
|
132
132
|
fill:transparent;
|
|
133
133
|
transition:opacity 0.1s linear;
|
|
134
134
|
opacity:0;
|
|
@@ -143,7 +143,7 @@
|
|
|
143
143
|
color:var(--sys-primary-accent-hovered, #6851a6);
|
|
144
144
|
}
|
|
145
145
|
.flag_icon_on[data-disabled=true]{
|
|
146
|
-
color:var(--sys-neutral-
|
|
146
|
+
color:var(--sys-neutral-on-accent, #fdfdfd);
|
|
147
147
|
}
|
|
148
148
|
.flag_icon_on[data-checked=true]{
|
|
149
149
|
opacity:1;
|
|
@@ -7,14 +7,6 @@
|
|
|
7
7
|
flex-shrink:0;
|
|
8
8
|
align-items:center;
|
|
9
9
|
}
|
|
10
|
-
.toggleLayout[data-size=s] svg{
|
|
11
|
-
width:var(--dimension-2m, 16px) !important;
|
|
12
|
-
height:var(--dimension-2m, 16px) !important;
|
|
13
|
-
}
|
|
14
|
-
.toggleLayout[data-size=m] svg{
|
|
15
|
-
width:var(--dimension-3m, 24px) !important;
|
|
16
|
-
height:var(--dimension-3m, 24px) !important;
|
|
17
|
-
}
|
|
18
10
|
.toggleLayout[data-disabled=true]{
|
|
19
11
|
cursor:not-allowed;
|
|
20
12
|
color:var(--sys-neutral-text-disabled, #9e9e9e);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Spinner(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import styles from './styles.module.css';
|
|
3
|
+
export function Spinner() {
|
|
4
|
+
return (_jsx("svg", { viewBox: '0 0 16 16', fill: 'none', xmlns: 'http://www.w3.org/2000/svg', className: styles.spinner, children: _jsx("path", { d: 'M5 8C5 6.34315 6.34315 5 8 5', stroke: 'black', strokeWidth: '1.5', strokeLinecap: 'round' }) }));
|
|
5
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Spinner';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Spinner';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
.spinner{
|
|
2
|
+
pointer-events:none;
|
|
3
|
+
width:var(--dimension-2m, 16px);
|
|
4
|
+
height:var(--dimension-2m, 16px);
|
|
5
|
+
animation:spin 1s ease-in-out infinite;
|
|
6
|
+
}
|
|
7
|
+
.spinner > path{
|
|
8
|
+
stroke:currentColor;
|
|
9
|
+
}
|
|
10
|
+
@keyframes spin{
|
|
11
|
+
to{
|
|
12
|
+
transform:rotate(360deg);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Spinner';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Spinner';
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Toggles",
|
|
7
|
-
"version": "0.9.
|
|
7
|
+
"version": "0.9.4",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
"license": "Apache-2.0",
|
|
33
33
|
"scripts": {},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@snack-uikit/icons": "0.
|
|
35
|
+
"@snack-uikit/icons": "0.20.0",
|
|
36
36
|
"@snack-uikit/utils": "3.2.0",
|
|
37
37
|
"classnames": "2.3.2",
|
|
38
38
|
"merge-refs": "1.2.1",
|
|
39
39
|
"uncontrollable": "8.0.0"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "c292f4c45173928f57cc5c9f3cb02efb26887b64"
|
|
42
42
|
}
|
|
@@ -1,21 +1,26 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
|
|
3
1
|
import { CheckSVG, CrossSVG } from '@snack-uikit/icons';
|
|
4
2
|
|
|
5
3
|
import { SIZE } from '../../constants';
|
|
4
|
+
import { Spinner } from '../../helperComponents';
|
|
6
5
|
import { ToggleProps } from '../../types';
|
|
7
|
-
import {
|
|
6
|
+
import { getVisualStateAttributes } from '../../utils';
|
|
8
7
|
import { TogglePrivate } from '../TogglePrivate';
|
|
9
8
|
import styles from './styles.module.scss';
|
|
10
9
|
|
|
11
10
|
export type SwitchProps = ToggleProps & {
|
|
12
11
|
/** Показывать ли иконку в переключателе */
|
|
13
12
|
showIcon?: boolean;
|
|
13
|
+
loading?: boolean;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
export function Switch({
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
export function Switch({
|
|
17
|
+
inputRef,
|
|
18
|
+
'data-test-id': dataTestId,
|
|
19
|
+
showIcon,
|
|
20
|
+
loading,
|
|
21
|
+
size = SIZE.M,
|
|
22
|
+
...restProps
|
|
23
|
+
}: SwitchProps) {
|
|
19
24
|
return (
|
|
20
25
|
<TogglePrivate
|
|
21
26
|
{...restProps}
|
|
@@ -29,13 +34,13 @@ export function Switch({ inputRef, 'data-test-id': dataTestId, showIcon, size =
|
|
|
29
34
|
<div className={styles.box} {...data} />
|
|
30
35
|
<div className={styles.containerFlag} {...data}>
|
|
31
36
|
<div className={styles.flag} {...data} />
|
|
32
|
-
{showIcon && (
|
|
37
|
+
{(showIcon || loading) && (
|
|
33
38
|
<>
|
|
34
39
|
<div className={styles.flag_icon_off} {...data}>
|
|
35
|
-
<CrossSVG size={
|
|
40
|
+
{loading ? <Spinner /> : <CrossSVG size={16} />}
|
|
36
41
|
</div>
|
|
37
42
|
<div className={styles.flag_icon_on} {...data}>
|
|
38
|
-
<CheckSVG size={
|
|
43
|
+
{loading ? <Spinner /> : <CheckSVG size={16} />}
|
|
39
44
|
</div>
|
|
40
45
|
</>
|
|
41
46
|
)}
|
|
@@ -11,7 +11,7 @@ $switchAnimationDuration: .1s;
|
|
|
11
11
|
|
|
12
12
|
.box {
|
|
13
13
|
position: relative;
|
|
14
|
-
background-color: simple-var($theme-variables, 'sys', 'neutral', '
|
|
14
|
+
background-color: simple-var($theme-variables, 'sys', 'neutral', 'decor-activated');
|
|
15
15
|
|
|
16
16
|
@each $size in $sizes {
|
|
17
17
|
&[data-size='#{$size}'] {
|
|
@@ -82,7 +82,7 @@ $switchAnimationDuration: .1s;
|
|
|
82
82
|
|
|
83
83
|
display: flex;
|
|
84
84
|
|
|
85
|
-
color: simple-var($theme-variables, 'sys', 'neutral', '
|
|
85
|
+
color: simple-var($theme-variables, 'sys', 'neutral', 'text-disabled');
|
|
86
86
|
|
|
87
87
|
fill: transparent;
|
|
88
88
|
|
|
@@ -100,7 +100,7 @@ $switchAnimationDuration: .1s;
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
&[data-disabled=true] {
|
|
103
|
-
color: simple-var($theme-variables, 'sys', 'neutral', '
|
|
103
|
+
color: simple-var($theme-variables, 'sys', 'neutral', 'on-accent');
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
}
|
|
@@ -19,15 +19,6 @@ $icon-sizes: (
|
|
|
19
19
|
flex-shrink: 0;
|
|
20
20
|
align-items: center;
|
|
21
21
|
|
|
22
|
-
@each $size in $sizes {
|
|
23
|
-
&[data-size='#{$size}'] {
|
|
24
|
-
svg {
|
|
25
|
-
width: simple-var($icon-sizes, $size) !important; /* stylelint-disable-line declaration-no-important */
|
|
26
|
-
height: simple-var($icon-sizes, $size) !important; /* stylelint-disable-line declaration-no-important */
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
22
|
&[data-disabled=true] {
|
|
32
23
|
cursor: not-allowed;
|
|
33
24
|
color: $sys-neutral-text-disabled;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import styles from './styles.module.scss';
|
|
2
|
+
|
|
3
|
+
export function Spinner() {
|
|
4
|
+
return (
|
|
5
|
+
<svg viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg' className={styles.spinner}>
|
|
6
|
+
<path d='M5 8C5 6.34315 6.34315 5 8 5' stroke='black' strokeWidth='1.5' strokeLinecap='round' />
|
|
7
|
+
</svg>
|
|
8
|
+
);
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Spinner';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
@import '@snack-uikit/figma-tokens/build/scss/styles-theme-variables';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
.spinner {
|
|
5
|
+
pointer-events: none;
|
|
6
|
+
width: $dimension-2m;
|
|
7
|
+
height: $dimension-2m;
|
|
8
|
+
animation: spin 1s ease-in-out infinite;
|
|
9
|
+
|
|
10
|
+
& > path {
|
|
11
|
+
stroke: currentColor;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@keyframes spin {
|
|
15
|
+
to {
|
|
16
|
+
transform: rotate(360deg);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Spinner';
|