@snack-uikit/toggles 0.7.1-preview-104ad22c.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.
Files changed (73) hide show
  1. package/CHANGELOG.md +357 -0
  2. package/LICENSE +201 -0
  3. package/README.md +169 -0
  4. package/dist/components/Checkbox/Checkbox.d.ts +12 -0
  5. package/dist/components/Checkbox/Checkbox.js +41 -0
  6. package/dist/components/Checkbox/index.d.ts +1 -0
  7. package/dist/components/Checkbox/index.js +1 -0
  8. package/dist/components/Checkbox/styles.module.css +86 -0
  9. package/dist/components/Favorite/Favorite.d.ts +10 -0
  10. package/dist/components/Favorite/Favorite.js +36 -0
  11. package/dist/components/Favorite/index.d.ts +1 -0
  12. package/dist/components/Favorite/index.js +1 -0
  13. package/dist/components/Favorite/styles.module.css +47 -0
  14. package/dist/components/Radio/Radio.d.ts +7 -0
  15. package/dist/components/Radio/Radio.js +24 -0
  16. package/dist/components/Radio/index.d.ts +1 -0
  17. package/dist/components/Radio/index.js +1 -0
  18. package/dist/components/Radio/styles.module.css +90 -0
  19. package/dist/components/Switch/Switch.d.ts +10 -0
  20. package/dist/components/Switch/Switch.js +27 -0
  21. package/dist/components/Switch/index.d.ts +1 -0
  22. package/dist/components/Switch/index.js +1 -0
  23. package/dist/components/Switch/styles.module.css +150 -0
  24. package/dist/components/ToggleGroup/ToggleGroup.d.ts +28 -0
  25. package/dist/components/ToggleGroup/ToggleGroup.js +31 -0
  26. package/dist/components/ToggleGroup/hooks.d.ts +9 -0
  27. package/dist/components/ToggleGroup/hooks.js +23 -0
  28. package/dist/components/ToggleGroup/index.d.ts +2 -0
  29. package/dist/components/ToggleGroup/index.js +2 -0
  30. package/dist/components/TogglePrivate/TogglePrivate.d.ts +22 -0
  31. package/dist/components/TogglePrivate/TogglePrivate.js +38 -0
  32. package/dist/components/TogglePrivate/index.d.ts +1 -0
  33. package/dist/components/TogglePrivate/index.js +1 -0
  34. package/dist/components/TogglePrivate/styles.module.css +38 -0
  35. package/dist/components/index.d.ts +5 -0
  36. package/dist/components/index.js +5 -0
  37. package/dist/components/styles.module.css +0 -0
  38. package/dist/constants.d.ts +16 -0
  39. package/dist/constants.js +20 -0
  40. package/dist/context.d.ts +10 -0
  41. package/dist/context.js +8 -0
  42. package/dist/index.d.ts +1 -0
  43. package/dist/index.js +1 -0
  44. package/dist/types.d.ts +47 -0
  45. package/dist/types.js +1 -0
  46. package/dist/utils.d.ts +4 -0
  47. package/dist/utils.js +18 -0
  48. package/package.json +42 -0
  49. package/src/components/Checkbox/Checkbox.tsx +72 -0
  50. package/src/components/Checkbox/index.ts +1 -0
  51. package/src/components/Checkbox/styles.module.scss +77 -0
  52. package/src/components/Favorite/Favorite.tsx +54 -0
  53. package/src/components/Favorite/index.ts +1 -0
  54. package/src/components/Favorite/styles.module.scss +36 -0
  55. package/src/components/Radio/Radio.tsx +30 -0
  56. package/src/components/Radio/index.ts +1 -0
  57. package/src/components/Radio/styles.module.scss +74 -0
  58. package/src/components/Switch/Switch.tsx +50 -0
  59. package/src/components/Switch/index.ts +1 -0
  60. package/src/components/Switch/styles.module.scss +124 -0
  61. package/src/components/ToggleGroup/ToggleGroup.tsx +76 -0
  62. package/src/components/ToggleGroup/hooks.ts +34 -0
  63. package/src/components/ToggleGroup/index.ts +2 -0
  64. package/src/components/TogglePrivate/TogglePrivate.tsx +69 -0
  65. package/src/components/TogglePrivate/index.ts +1 -0
  66. package/src/components/TogglePrivate/styles.module.scss +56 -0
  67. package/src/components/index.ts +5 -0
  68. package/src/components/styles.module.scss +24 -0
  69. package/src/constants.ts +19 -0
  70. package/src/context.ts +17 -0
  71. package/src/index.ts +1 -0
  72. package/src/types.ts +71 -0
  73. package/src/utils.ts +21 -0
package/README.md ADDED
@@ -0,0 +1,169 @@
1
+ # Checkbox, Radio, Switch и Favorite
2
+ Компоненты, реализующие переключатели.
3
+
4
+ ## Installation
5
+ `npm i @snack-uikit/toggles`
6
+
7
+ [Changelog](../../../CHANGELOG.md)
8
+
9
+ ## хук useToggleGroup
10
+ Хук для элементов внутри группы переключателей.
11
+
12
+ ### Аргументы
13
+
14
+ #### **`value: string`**
15
+
16
+ Уникальное значение для элемента в группе
17
+
18
+ ```tsx
19
+ function ToggleCard(props: ToggleCardProps) {
20
+ const { isChecked, handleClick, multipleSelection } = useToggleGroup(props.id);
21
+
22
+ return (
23
+ <Card {...props} checked={isChecked} onClick={handleClick} multipleSelection={multipleSelection}/>
24
+ );
25
+ }
26
+ ```
27
+
28
+ ### Примеры:
29
+
30
+ #### ToggleGroup
31
+ ```typescript jsx
32
+
33
+ const [value, setValue] = useState<string | undefined>(undefined);
34
+
35
+ function ToggleCard(props: ToggleCardProps) {
36
+ const { isChecked, handleClick, multipleSelection } = useToggleGroup(id);
37
+
38
+ return (
39
+ <Card {...props} checked={isChecked} onClick={handleClick} multipleSelection={multipleSelection}/>
40
+ );
41
+ }
42
+
43
+ // ITEMS -some array with ToggleCardProps
44
+
45
+ ...
46
+
47
+ <ToggleGroup selectionMode={ToggleGroup.selectionModes.Single} value={value} onChange={setValue}>
48
+ {ITEMS.map(props => (
49
+ <ToggleCard key={props.id} {...props} />
50
+ ))}
51
+ </ToggleGroup>
52
+ ...
53
+
54
+ return (
55
+ <>
56
+ {items.map(({ checked, setChecked, data }) =>
57
+ <CustomRadioButton
58
+ // повторяет нативное поведение радиогруппы: по клику можно выбрать, но нельзя снять выбор
59
+ onClick={() => setChecked(true)}
60
+ checked={checked}
61
+ data={data}
62
+ />
63
+ )}
64
+ </>
65
+ );
66
+ ```
67
+
68
+
69
+ ```
70
+
71
+
72
+ [//]: DOCUMENTATION_SECTION_START
73
+ [//]: THIS_SECTION_IS_AUTOGENERATED_PLEASE_DONT_EDIT_IT
74
+ ## Checkbox
75
+ ### Props
76
+ | name | type | default value | description |
77
+ |------|------|---------------|-------------|
78
+ | id | `string` | - | HTML-аттрибут id |
79
+ | name | `string` | - | HTML-аттрибут name |
80
+ | value | `string` | - | HTML-аттрибут value |
81
+ | tabIndex | `number` | - | HTML-аттрибут tab-index |
82
+ | autofocus | `boolean` | - | HTML-аттрибут autofocus |
83
+ | checked | `boolean` | - | HTML-аттрибут checked |
84
+ | defaultChecked | `boolean` | - | HTML-аттрибут checked по-умолчанию |
85
+ | disabled | `boolean` | - | HTML-аттрибут disabled |
86
+ | onChange | `(checked: boolean) => void` | - | Колбек смены значения |
87
+ | onClick | `MouseEventHandler<HTMLInputElement>` | - | Колбек клика |
88
+ | onBlur | `FocusEventHandler<HTMLInputElement>` | - | Колбек потери фокуса |
89
+ | onFocus | `FocusEventHandler<HTMLInputElement>` | - | Колбек приобретения фокуса |
90
+ | className | `string` | - | CSS-класс |
91
+ | size | enum Size: `"s"`, `"m"` | Size.M | Размер |
92
+ | inputRef | `RefObject<HTMLInputElement>` | - | |
93
+ | indeterminate | `boolean` | - | Состояние частичного выбора |
94
+ | indeterminateDefault | `boolean` | - | Состояние частичного выбора по-умолчанию |
95
+ ## Switch
96
+ ### Props
97
+ | name | type | default value | description |
98
+ |------|------|---------------|-------------|
99
+ | id | `string` | - | HTML-аттрибут id |
100
+ | name | `string` | - | HTML-аттрибут name |
101
+ | value | `string` | - | HTML-аттрибут value |
102
+ | tabIndex | `number` | - | HTML-аттрибут tab-index |
103
+ | autofocus | `boolean` | - | HTML-аттрибут autofocus |
104
+ | checked | `boolean` | - | HTML-аттрибут checked |
105
+ | defaultChecked | `boolean` | - | HTML-аттрибут checked по-умолчанию |
106
+ | disabled | `boolean` | - | HTML-аттрибут disabled |
107
+ | onChange | `(checked: boolean) => void` | - | Колбек смены значения |
108
+ | onClick | `MouseEventHandler<HTMLInputElement>` | - | Колбек клика |
109
+ | onBlur | `FocusEventHandler<HTMLInputElement>` | - | Колбек потери фокуса |
110
+ | onFocus | `FocusEventHandler<HTMLInputElement>` | - | Колбек приобретения фокуса |
111
+ | className | `string` | - | CSS-класс |
112
+ | size | enum Size: `"s"`, `"m"` | Size.M | Размер |
113
+ | inputRef | `RefObject<HTMLInputElement>` | - | |
114
+ | showIcon | `boolean` | - | Показывать ли иконку в переключателе |
115
+ ## Radio
116
+ ### Props
117
+ | name | type | default value | description |
118
+ |------|------|---------------|-------------|
119
+ | id | `string` | - | HTML-аттрибут id |
120
+ | name | `string` | - | HTML-аттрибут name |
121
+ | value | `string` | - | HTML-аттрибут value |
122
+ | tabIndex | `number` | - | HTML-аттрибут tab-index |
123
+ | autofocus | `boolean` | - | HTML-аттрибут autofocus |
124
+ | checked | `boolean` | - | HTML-аттрибут checked |
125
+ | defaultChecked | `boolean` | - | HTML-аттрибут checked по-умолчанию |
126
+ | disabled | `boolean` | - | HTML-аттрибут disabled |
127
+ | onChange | `(checked: boolean) => void` | - | Колбек смены значения |
128
+ | onClick | `MouseEventHandler<HTMLInputElement>` | - | Колбек клика |
129
+ | onBlur | `FocusEventHandler<HTMLInputElement>` | - | Колбек потери фокуса |
130
+ | onFocus | `FocusEventHandler<HTMLInputElement>` | - | Колбек приобретения фокуса |
131
+ | className | `string` | - | CSS-класс |
132
+ | size | enum Size: `"s"`, `"m"` | - | Размер |
133
+ | inputRef | `RefObject<HTMLInputElement>` | - | |
134
+ ## Favorite
135
+ ### Props
136
+ | name | type | default value | description |
137
+ |------|------|---------------|-------------|
138
+ | id | `string` | - | HTML-аттрибут id |
139
+ | name | `string` | - | HTML-аттрибут name |
140
+ | value | `string` | - | HTML-аттрибут value |
141
+ | tabIndex | `number` | - | HTML-аттрибут tab-index |
142
+ | autofocus | `boolean` | - | HTML-аттрибут autofocus |
143
+ | checked | `boolean` | - | HTML-аттрибут checked |
144
+ | defaultChecked | `boolean` | - | HTML-аттрибут checked по-умолчанию |
145
+ | onChange | `(checked: boolean) => void` | - | Колбек смены значения |
146
+ | onClick | `MouseEventHandler<HTMLInputElement>` | - | Колбек клика |
147
+ | onBlur | `FocusEventHandler<HTMLInputElement>` | - | Колбек потери фокуса |
148
+ | onFocus | `FocusEventHandler<HTMLInputElement>` | - | Колбек приобретения фокуса |
149
+ | className | `string` | - | CSS-класс |
150
+ | size | enum Size: `"s"`, `"m"` | Size.M | Размер |
151
+ | inputRef | `RefObject<HTMLInputElement>` | - | |
152
+ | icon | enum FavoriteIcon: `"star"`, `"heart"` | FavoriteIcon.Heart | Иконка |
153
+ ## ToggleGroup
154
+ ### Props
155
+ | name | type | default value | description |
156
+ |------|------|---------------|-------------|
157
+ | children* | `ReactNode` | - | Вложенный контент |
158
+ | defaultValue | `string \| string[]` | - | Начальное состояние |
159
+ | value | `string \| string[]` | - | Controlled состояние |
160
+ | onChange | `((value: string) => void) \| ((value: string[]) => void)` | - | Controlled обработчик измения состояния |
161
+ | selectionMode | enum SelectionMode: `"single"`, `"multiple"` | SelectionMode.Single | Режим выбора |
162
+ ## useToggleGroup
163
+ ### Props
164
+ | name | type | default value | description |
165
+ |------|------|---------------|-------------|
166
+ | value* | `string` | - | |
167
+
168
+
169
+ [//]: DOCUMENTATION_SECTION_END
@@ -0,0 +1,12 @@
1
+ import { Size } from '../../constants';
2
+ import { ToggleProps } from '../../types';
3
+ export type CheckboxProps = ToggleProps & {
4
+ /** Состояние частичного выбора */
5
+ indeterminate?: boolean;
6
+ /** Состояние частичного выбора по-умолчанию */
7
+ indeterminateDefault?: boolean;
8
+ };
9
+ export declare function Checkbox({ inputRef, indeterminate: indeterminateProp, indeterminateDefault, onChange: onChangeProp, 'data-test-id': dataTestId, size, ...restProps }: CheckboxProps): import("react/jsx-runtime").JSX.Element;
10
+ export declare namespace Checkbox {
11
+ var sizes: typeof Size;
12
+ }
@@ -0,0 +1,41 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import mergeRefs from 'merge-refs';
14
+ import { useCallback, useEffect, useMemo, useRef } from 'react';
15
+ import { useUncontrolledProp } from 'uncontrollable';
16
+ import { CheckSVG, MinusSVG } from '@snack-uikit/icons';
17
+ import { Size } from '../../constants';
18
+ import { getIconSize, getVisualStateAttributes } from '../../utils';
19
+ import { TogglePrivate } from '../TogglePrivate';
20
+ import styles from './styles.module.css';
21
+ export function Checkbox(_a) {
22
+ var { inputRef, indeterminate: indeterminateProp, indeterminateDefault, onChange: onChangeProp, 'data-test-id': dataTestId, size = Size.M } = _a, restProps = __rest(_a, ["inputRef", "indeterminate", "indeterminateDefault", "onChange", 'data-test-id', "size"]);
23
+ const localRef = useRef(null);
24
+ const ref = mergeRefs(localRef, inputRef);
25
+ const [indeterminate, setIndeterminate] = useUncontrolledProp(indeterminateProp, indeterminateDefault);
26
+ const onChange = useCallback((checked) => {
27
+ onChangeProp === null || onChangeProp === void 0 ? void 0 : onChangeProp(checked);
28
+ setIndeterminate(false);
29
+ }, [onChangeProp, setIndeterminate]);
30
+ useEffect(() => {
31
+ if (localRef.current) {
32
+ localRef.current.indeterminate = Boolean(indeterminate);
33
+ }
34
+ }, [localRef, indeterminate]);
35
+ const iconSize = useMemo(() => getIconSize(size), [size]);
36
+ return (_jsx(TogglePrivate, Object.assign({}, restProps, { size: size, onChange: onChange, "data-test-id": dataTestId, ref: ref, render: function Checkbox(visualState) {
37
+ const data = getVisualStateAttributes(Object.assign(Object.assign({}, visualState), { indeterminate: Boolean(indeterminate) }));
38
+ return (_jsxs("div", Object.assign({ className: styles.container }, data, { children: [_jsx("div", Object.assign({ className: styles.box }, data)), _jsx("div", Object.assign({ className: styles.icon }, data, { children: indeterminate ? _jsx(MinusSVG, { size: iconSize }) : _jsx(CheckSVG, { size: iconSize }) }))] })));
39
+ } })));
40
+ }
41
+ Checkbox.sizes = Size;
@@ -0,0 +1 @@
1
+ export * from './Checkbox';
@@ -0,0 +1 @@
1
+ export * from './Checkbox';
@@ -0,0 +1,86 @@
1
+ .container{
2
+ display:flex;
3
+ align-items:center;
4
+ justify-content:center;
5
+ box-sizing:border-box;
6
+ }
7
+ .container[data-size=s]{
8
+ width:var(--size-toggles-s-container, 16px);
9
+ height:var(--size-toggles-s-container, 16px);
10
+ border-radius:var(--radius-toggles-s-box-checkbox, 6px);
11
+ border-width:var(--border-width-toggles-single, 2px);
12
+ }
13
+ .container[data-size=m]{
14
+ width:var(--size-toggles-m-container, 24px);
15
+ height:var(--size-toggles-m-container, 24px);
16
+ border-radius:var(--radius-toggles-m-box-checkbox, 8px);
17
+ border-width:var(--border-width-toggles-single, 2px);
18
+ }
19
+ .container[data-focusvisible=true]{
20
+ outline-width:var(--border-state-focus-s-border-width, 2px);
21
+ outline-style:var(--border-state-focus-s-border-style, solid);
22
+ outline-color:var(--border-state-focus-s-border-color, );
23
+ }
24
+ .container[data-focusvisible=true][data-size=s]{
25
+ outline-offset:var(--border-width-state-focus-s, 2px);
26
+ }
27
+
28
+ .box{
29
+ box-sizing:border-box;
30
+ background-color:var(--sys-neutral-background1-level, #f9f9f9);
31
+ border-color:var(--sys-neutral-decor-default, #dedede);
32
+ border-style:solid;
33
+ }
34
+ .box[data-checked=false][data-focusvisible=true], .box[data-checked=false][data-hover=true]{
35
+ background-color:var(--sys-neutral-background2-level, #fdfdfd);
36
+ border-color:var(--sys-neutral-decor-hovered, #d2d2d2);
37
+ }
38
+ .box[data-checked=false][data-disabled=true]{
39
+ background-color:var(--sys-neutral-background1-level, #f9f9f9);
40
+ border-color:var(--sys-neutral-decor-disabled, #e7e7e7);
41
+ }
42
+ .box[data-indeterminate=true], .box[data-checked=true]{
43
+ background-color:var(--sys-primary-accent-default, #794ed3);
44
+ border-color:var(--sys-primary-accent-default, #794ed3);
45
+ }
46
+ .box[data-indeterminate=true][data-focusvisible=true], .box[data-indeterminate=true][data-hover=true], .box[data-checked=true][data-focusvisible=true], .box[data-checked=true][data-hover=true]{
47
+ background-color:var(--sys-primary-accent-hovered, #6851a6);
48
+ border-color:var(--sys-primary-accent-hovered, #6851a6);
49
+ }
50
+ .box[data-indeterminate=true][data-disabled=true], .box[data-checked=true][data-disabled=true]{
51
+ background-color:var(--sys-neutral-decor-disabled, #e7e7e7);
52
+ border-color:var(--sys-neutral-decor-disabled, #e7e7e7);
53
+ }
54
+ .box[data-size=s]{
55
+ width:var(--size-toggles-s-container, 16px);
56
+ height:var(--size-toggles-s-container, 16px);
57
+ border-width:var(--border-width-toggles-single, 2px);
58
+ border-radius:var(--radius-toggles-s-box-checkbox, 6px);
59
+ }
60
+ .box[data-size=s] svg{
61
+ width:var(--dimension-2m, 16px) !important;
62
+ height:var(--dimension-2m, 16px) !important;
63
+ }
64
+ .box[data-size=m]{
65
+ width:var(--size-toggles-m-box-checkbox, 20px);
66
+ height:var(--size-toggles-m-box-checkbox, 20px);
67
+ border-width:var(--border-width-toggles-single, 2px);
68
+ border-radius:var(--radius-toggles-m-box-checkbox, 8px);
69
+ }
70
+ .box[data-size=m] svg{
71
+ width:var(--dimension-3m, 24px) !important;
72
+ height:var(--dimension-3m, 24px) !important;
73
+ }
74
+
75
+ .icon{
76
+ position:absolute;
77
+ top:0;
78
+ left:0;
79
+ display:none;
80
+ width:100%;
81
+ height:100%;
82
+ color:var(--sys-primary-on-accent, #fdfbff);
83
+ }
84
+ .icon[data-indeterminate=true], .icon[data-checked=true]{
85
+ display:block;
86
+ }
@@ -0,0 +1,10 @@
1
+ import { FavoriteIcon, Size } from '../../constants';
2
+ import { ToggleProps } from '../../types';
3
+ export type FavoriteProps = Omit<ToggleProps, 'disabled'> & {
4
+ /** Иконка */
5
+ icon?: FavoriteIcon;
6
+ };
7
+ export declare function Favorite({ inputRef, 'data-test-id': dataTestId, size, icon, ...restProps }: FavoriteProps): import("react/jsx-runtime").JSX.Element;
8
+ export declare namespace Favorite {
9
+ var sizes: typeof Size;
10
+ }
@@ -0,0 +1,36 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { useMemo } from 'react';
14
+ import { HeartFilledSVG, HeartSVG, StarFilledSVG, StarSVG } from '@snack-uikit/icons';
15
+ import { FavoriteIcon, Size } from '../../constants';
16
+ import { getIconSize, getVisualStateAttributes } from '../../utils';
17
+ import { TogglePrivate } from '../TogglePrivate';
18
+ import styles from './styles.module.css';
19
+ const CHECKED_ICONS = {
20
+ [FavoriteIcon.Star]: StarFilledSVG,
21
+ [FavoriteIcon.Heart]: HeartFilledSVG,
22
+ };
23
+ const UNCHECKED_ICONS = {
24
+ [FavoriteIcon.Star]: StarSVG,
25
+ [FavoriteIcon.Heart]: HeartSVG,
26
+ };
27
+ export function Favorite(_a) {
28
+ var { inputRef, 'data-test-id': dataTestId, size = Size.M, icon = FavoriteIcon.Heart } = _a, restProps = __rest(_a, ["inputRef", 'data-test-id', "size", "icon"]);
29
+ const iconSize = useMemo(() => getIconSize(size), [size]);
30
+ return (_jsx(TogglePrivate, Object.assign({}, restProps, { "data-test-id": dataTestId, ref: inputRef, size: size, render: function Favorite(visualState) {
31
+ const Icon = visualState.checked ? CHECKED_ICONS[icon] : UNCHECKED_ICONS[icon];
32
+ const data = getVisualStateAttributes(Object.assign(Object.assign({}, visualState), { icon }));
33
+ return (_jsx("div", Object.assign({ className: styles.container }, data, { children: _jsx(Icon, Object.assign({ className: styles.icon }, data, { size: iconSize })) })));
34
+ } })));
35
+ }
36
+ Favorite.sizes = Size;
@@ -0,0 +1 @@
1
+ export * from './Favorite';
@@ -0,0 +1 @@
1
+ export * from './Favorite';
@@ -0,0 +1,47 @@
1
+ .container{
2
+ display:flex;
3
+ align-items:center;
4
+ justify-content:center;
5
+ box-sizing:border-box;
6
+ outline-color:var(--sys-available-complementary, #131313);
7
+ }
8
+ .container[data-size=s]{
9
+ width:var(--size-toggles-s-container, 16px);
10
+ height:var(--size-toggles-s-container, 16px);
11
+ border-radius:var(--radius-toggles-s-box-checkbox, 6px);
12
+ }
13
+ .container[data-size=m]{
14
+ width:var(--size-toggles-m-container, 24px);
15
+ height:var(--size-toggles-m-container, 24px);
16
+ border-radius:var(--radius-toggles-m-box-checkbox, 8px);
17
+ }
18
+ .container[data-focusvisible=true]{
19
+ outline-width:var(--border-state-focus-s-border-width, 2px);
20
+ outline-style:var(--border-state-focus-s-border-style, solid);
21
+ outline-color:var(--border-state-focus-s-border-color, );
22
+ }
23
+ .container[data-focusvisible=true][data-size=s]{
24
+ outline-offset:var(--border-width-state-focus-s, 2px);
25
+ }
26
+ .container[data-checked=true]{
27
+ outline-color:var(--sys-available-complementary, #131313);
28
+ }
29
+
30
+ .icon{
31
+ color:var(--sys-neutral-text-light, #898989);
32
+ }
33
+ .icon[data-hover=true]{
34
+ color:var(--sys-neutral-text-support, #565656);
35
+ }
36
+ .icon[data-icon=star][data-checked=true]{
37
+ color:var(--sys-yellow-accent-default, #feb528);
38
+ }
39
+ .icon[data-icon=star][data-checked=true][data-focusvisible=true], .icon[data-icon=star][data-checked=true][data-hover=true]{
40
+ color:var(--sys-yellow-accent-hovered, #d69542);
41
+ }
42
+ .icon[data-icon=heart][data-checked=true]{
43
+ color:var(--sys-red-accent-default, #d93f2f);
44
+ }
45
+ .icon[data-icon=heart][data-checked=true][data-focusvisible=true], .icon[data-icon=heart][data-checked=true][data-hover=true]{
46
+ color:var(--sys-red-accent-hovered, #b9443a);
47
+ }
@@ -0,0 +1,7 @@
1
+ import { Size } from '../../constants';
2
+ import { ToggleProps } from '../../types';
3
+ export type RadioProps = ToggleProps;
4
+ export declare function Radio({ inputRef, 'data-test-id': dataTestId, ...restProps }: RadioProps): import("react/jsx-runtime").JSX.Element;
5
+ export declare namespace Radio {
6
+ var sizes: typeof Size;
7
+ }
@@ -0,0 +1,24 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { Mode, Size } from '../../constants';
14
+ import { getVisualStateAttributes } from '../../utils';
15
+ import { TogglePrivate } from '../TogglePrivate';
16
+ import styles from './styles.module.css';
17
+ export function Radio(_a) {
18
+ var { inputRef, 'data-test-id': dataTestId } = _a, restProps = __rest(_a, ["inputRef", 'data-test-id']);
19
+ return (_jsx(TogglePrivate, Object.assign({}, restProps, { "data-test-id": dataTestId, mode: Mode.Radio, ref: inputRef, render: function Radio(visualState) {
20
+ const data = getVisualStateAttributes(visualState);
21
+ return (_jsx("div", Object.assign({ className: styles.container }, data, { children: _jsx("div", Object.assign({ className: styles.box }, data, { children: _jsx("div", Object.assign({ className: styles.flag }, data)) })) })));
22
+ } })));
23
+ }
24
+ Radio.sizes = Size;
@@ -0,0 +1 @@
1
+ export * from './Radio';
@@ -0,0 +1 @@
1
+ export * from './Radio';
@@ -0,0 +1,90 @@
1
+ .container{
2
+ display:flex;
3
+ align-items:center;
4
+ justify-content:center;
5
+ box-sizing:border-box;
6
+ }
7
+ .container[data-size=s]{
8
+ width:var(--size-toggles-s-container, 16px);
9
+ height:var(--size-toggles-s-container, 16px);
10
+ border-radius:var(--radius-toggles-s-box-radio, 16px);
11
+ border-width:var(--border-width-toggles-single, 2px);
12
+ }
13
+ .container[data-size=m]{
14
+ width:var(--size-toggles-m-container, 24px);
15
+ height:var(--size-toggles-m-container, 24px);
16
+ border-radius:var(--radius-toggles-m-box-radio, 16px);
17
+ border-width:var(--border-width-toggles-single, 2px);
18
+ }
19
+ .container[data-focusvisible=true]{
20
+ outline-width:var(--border-state-focus-s-border-width, 2px);
21
+ outline-style:var(--border-state-focus-s-border-style, solid);
22
+ outline-color:var(--border-state-focus-s-border-color, );
23
+ }
24
+ .container[data-focusvisible=true][data-size=s]{
25
+ outline-offset:var(--border-width-state-focus-s, 2px);
26
+ }
27
+
28
+ .box{
29
+ position:relative;
30
+ box-sizing:border-box;
31
+ background-color:var(--sys-neutral-background1-level, #f9f9f9);
32
+ border-color:var(--sys-neutral-decor-default, #dedede);
33
+ border-style:solid;
34
+ }
35
+ .box[data-size=s]{
36
+ width:var(--size-toggles-s-box-radio, 16px);
37
+ height:var(--size-toggles-s-box-radio, 16px);
38
+ border-width:var(--border-width-toggles-single, 2px);
39
+ border-radius:var(--radius-toggles-s-box-radio, 16px);
40
+ }
41
+ .box[data-size=m]{
42
+ width:var(--size-toggles-m-box-radio, 20px);
43
+ height:var(--size-toggles-m-box-radio, 20px);
44
+ border-width:var(--border-width-toggles-single, 2px);
45
+ border-radius:var(--radius-toggles-m-box-radio, 16px);
46
+ }
47
+ .box[data-focusvisible=true], .box[data-hover=true]{
48
+ background-color:var(--sys-neutral-background2-level, #fdfdfd);
49
+ border-color:var(--sys-neutral-decor-hovered, #d2d2d2);
50
+ }
51
+ .box[data-disabled=true]{
52
+ background-color:var(--sys-neutral-background1-level, #f9f9f9);
53
+ border-color:var(--sys-neutral-decor-disabled, #e7e7e7);
54
+ }
55
+ .box[data-checked=true]{
56
+ border-color:var(--sys-primary-accent-default, #794ed3);
57
+ }
58
+ .box[data-checked=true][data-focusvisible=true], .box[data-checked=true][data-hover=true]{
59
+ border-color:var(--sys-primary-accent-hovered, #6851a6);
60
+ }
61
+ .box[data-checked=true][data-disabled=true]{
62
+ border-color:var(--sys-neutral-decor-disabled, #e7e7e7);
63
+ }
64
+
65
+ .flag{
66
+ position:absolute;
67
+ top:50%;
68
+ left:50%;
69
+ transform:translate(-50%, -50%);
70
+ background-color:var(--sys-primary-accent-default, #794ed3);
71
+ }
72
+ .flag[data-hover=true]{
73
+ background-color:var(--sys-primary-accent-hovered, #6851a6);
74
+ }
75
+ .flag[data-disabled=true]{
76
+ background-color:var(--sys-neutral-text-disabled, #9e9e9e);
77
+ }
78
+ .flag[data-checked=false]{
79
+ display:none;
80
+ }
81
+ .flag[data-size=s]{
82
+ border-radius:var(--radius-toggles-s-box-radio, 16px);
83
+ width:var(--size-toggles-s-flag-radio, 8px);
84
+ height:var(--size-toggles-s-flag-radio, 8px);
85
+ }
86
+ .flag[data-size=m]{
87
+ border-radius:var(--radius-toggles-m-box-radio, 16px);
88
+ width:var(--size-toggles-m-flag-radio, 12px);
89
+ height:var(--size-toggles-m-flag-radio, 12px);
90
+ }
@@ -0,0 +1,10 @@
1
+ import { Size } from '../../constants';
2
+ import { ToggleProps } from '../../types';
3
+ export type SwitchProps = ToggleProps & {
4
+ /** Показывать ли иконку в переключателе */
5
+ showIcon?: boolean;
6
+ };
7
+ export declare function Switch({ inputRef, 'data-test-id': dataTestId, showIcon, size, ...restProps }: SwitchProps): import("react/jsx-runtime").JSX.Element;
8
+ export declare namespace Switch {
9
+ var sizes: typeof Size;
10
+ }
@@ -0,0 +1,27 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { useMemo } from 'react';
14
+ import { CheckSVG, CrossSVG } from '@snack-uikit/icons';
15
+ import { Size } from '../../constants';
16
+ import { getIconSize, getVisualStateAttributes } from '../../utils';
17
+ import { TogglePrivate } from '../TogglePrivate';
18
+ import styles from './styles.module.css';
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]);
22
+ return (_jsx(TogglePrivate, Object.assign({}, restProps, { size: size, "data-test-id": dataTestId, ref: inputRef, render: function Switch(visualState) {
23
+ 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: iconSize }) })), _jsx("div", Object.assign({ className: styles.flag_icon_on }, data, { children: _jsx(CheckSVG, { size: iconSize }) }))] }))] }))] })));
25
+ } })));
26
+ }
27
+ Switch.sizes = Size;
@@ -0,0 +1 @@
1
+ export * from './Switch';
@@ -0,0 +1 @@
1
+ export * from './Switch';