@snack-uikit/toggles 0.12.0 → 0.12.1-preview-d1a63029.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/README.md +2 -1
- package/dist/cjs/components/Favorite/Favorite.d.ts +4 -1
- package/dist/cjs/components/Favorite/Favorite.js +8 -4
- package/dist/cjs/components/Favorite/styles.module.css +6 -0
- package/dist/cjs/components/TogglePrivate/TogglePrivate.d.ts +1 -0
- package/dist/cjs/components/TogglePrivate/TogglePrivate.js +5 -2
- package/dist/cjs/constants.d.ts +1 -0
- package/dist/cjs/constants.js +2 -1
- package/dist/cjs/types.d.ts +3 -1
- package/dist/esm/components/Favorite/Favorite.d.ts +4 -1
- package/dist/esm/components/Favorite/Favorite.js +5 -3
- package/dist/esm/components/Favorite/styles.module.css +6 -0
- package/dist/esm/components/TogglePrivate/TogglePrivate.d.ts +1 -0
- package/dist/esm/components/TogglePrivate/TogglePrivate.js +2 -2
- package/dist/esm/constants.d.ts +1 -0
- package/dist/esm/constants.js +1 -0
- package/dist/esm/types.d.ts +3 -1
- package/package.json +2 -2
- package/src/components/Favorite/Favorite.tsx +8 -2
- package/src/components/Favorite/styles.module.scss +1 -0
- package/src/components/TogglePrivate/TogglePrivate.tsx +3 -0
- package/src/constants.ts +1 -0
- package/src/types.ts +3 -1
package/README.md
CHANGED
|
@@ -151,7 +151,8 @@ return (
|
|
|
151
151
|
| className | `string` | - | CSS-класс |
|
|
152
152
|
| size | enum Size: `"s"`, `"m"` | m | Размер |
|
|
153
153
|
| inputRef | `RefObject<HTMLInputElement>` | - | |
|
|
154
|
-
| icon | enum FavoriteIcon: `"star"`, `"heart"` | heart | Иконка |
|
|
154
|
+
| icon | enum FavoriteIcon: `"star"`, `"heart"`, `"pin"` | heart | Иконка |
|
|
155
|
+
| onKeyDown | `KeyboardEventHandler<HTMLDivElement>` | - | Колбек нажатия клавиши клавиатуры |
|
|
155
156
|
## ToggleGroup
|
|
156
157
|
### Props
|
|
157
158
|
| name | type | default value | description |
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { KeyboardEventHandler } from 'react';
|
|
1
2
|
import { FavoriteIcon, ToggleProps } from '../../types';
|
|
2
3
|
export type FavoriteProps = ToggleProps & {
|
|
3
4
|
/** Иконка */
|
|
4
5
|
icon?: FavoriteIcon;
|
|
6
|
+
/** Колбек нажатия клавиши клавиатуры */
|
|
7
|
+
onKeyDown?: KeyboardEventHandler<HTMLDivElement>;
|
|
5
8
|
};
|
|
6
|
-
export declare function Favorite({ inputRef, 'data-test-id': dataTestId, size, icon, ...restProps }: FavoriteProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export declare function Favorite({ inputRef, 'data-test-id': dataTestId, size, icon, onKeyDown, ...restProps }: FavoriteProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -26,25 +26,29 @@ const TogglePrivate_1 = require("../TogglePrivate");
|
|
|
26
26
|
const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
|
|
27
27
|
const CHECKED_ICONS = {
|
|
28
28
|
[constants_1.FAVORITE_ICON.Star]: icons_1.StarFilledSVG,
|
|
29
|
-
[constants_1.FAVORITE_ICON.Heart]: icons_1.HeartFilledSVG
|
|
29
|
+
[constants_1.FAVORITE_ICON.Heart]: icons_1.HeartFilledSVG,
|
|
30
|
+
[constants_1.FAVORITE_ICON.Pin]: icons_1.PinnedSVG
|
|
30
31
|
};
|
|
31
32
|
const UNCHECKED_ICONS = {
|
|
32
33
|
[constants_1.FAVORITE_ICON.Star]: icons_1.StarSVG,
|
|
33
|
-
[constants_1.FAVORITE_ICON.Heart]: icons_1.HeartSVG
|
|
34
|
+
[constants_1.FAVORITE_ICON.Heart]: icons_1.HeartSVG,
|
|
35
|
+
[constants_1.FAVORITE_ICON.Pin]: icons_1.UnPinnedSVG
|
|
34
36
|
};
|
|
35
37
|
function Favorite(_a) {
|
|
36
38
|
var {
|
|
37
39
|
inputRef,
|
|
38
40
|
'data-test-id': dataTestId,
|
|
39
41
|
size = constants_1.SIZE.M,
|
|
40
|
-
icon = constants_1.FAVORITE_ICON.Heart
|
|
42
|
+
icon = constants_1.FAVORITE_ICON.Heart,
|
|
43
|
+
onKeyDown
|
|
41
44
|
} = _a,
|
|
42
|
-
restProps = __rest(_a, ["inputRef", 'data-test-id', "size", "icon"]);
|
|
45
|
+
restProps = __rest(_a, ["inputRef", 'data-test-id', "size", "icon", "onKeyDown"]);
|
|
43
46
|
const iconSize = (0, react_1.useMemo)(() => (0, utils_1.getIconSize)(size), [size]);
|
|
44
47
|
return (0, jsx_runtime_1.jsx)(TogglePrivate_1.TogglePrivate, Object.assign({}, restProps, {
|
|
45
48
|
"data-test-id": dataTestId,
|
|
46
49
|
ref: inputRef,
|
|
47
50
|
size: size,
|
|
51
|
+
onKeyDown: onKeyDown,
|
|
48
52
|
render: function Favorite(visualState) {
|
|
49
53
|
const Icon = visualState.checked ? CHECKED_ICONS[icon] : UNCHECKED_ICONS[icon];
|
|
50
54
|
const data = (0, utils_1.getVisualStateAttributes)(Object.assign(Object.assign({}, visualState), {
|
|
@@ -45,6 +45,12 @@
|
|
|
45
45
|
.icon:not([data-disabled=true])[data-icon=heart][data-checked=true][data-focusvisible=true], .icon:not([data-disabled=true])[data-icon=heart][data-checked=true][data-hover=true]{
|
|
46
46
|
color:var(--sys-red-accent-hovered, #bd4844);
|
|
47
47
|
}
|
|
48
|
+
.icon:not([data-disabled=true])[data-icon=pin][data-checked=true]{
|
|
49
|
+
color:var(--sys-primary-accent-default, #794ed3);
|
|
50
|
+
}
|
|
51
|
+
.icon:not([data-disabled=true])[data-icon=pin][data-checked=true][data-focusvisible=true], .icon:not([data-disabled=true])[data-icon=pin][data-checked=true][data-hover=true]{
|
|
52
|
+
color:var(--sys-primary-accent-hovered, #6851a6);
|
|
53
|
+
}
|
|
48
54
|
.icon[data-disabled=true]{
|
|
49
55
|
color:var(--sys-neutral-text-disabled, #aaaebd);
|
|
50
56
|
}
|
|
@@ -17,4 +17,5 @@ export declare const TogglePrivate: import("react").ForwardRefExoticComponent<{
|
|
|
17
17
|
onClick?: import("react").MouseEventHandler<HTMLInputElement>;
|
|
18
18
|
onBlur?: import("react").FocusEventHandler<HTMLInputElement>;
|
|
19
19
|
onFocus?: import("react").FocusEventHandler<HTMLInputElement>;
|
|
20
|
+
onKeyDown?: import("react").KeyboardEventHandler<HTMLDivElement>;
|
|
20
21
|
} & import("react").RefAttributes<HTMLInputElement>>;
|
|
@@ -36,9 +36,10 @@ exports.TogglePrivate = (0, react_1.forwardRef)(function TogglePrivate(_a, ref)
|
|
|
36
36
|
className,
|
|
37
37
|
size = constants_1.SIZE.M,
|
|
38
38
|
mode = constants_1.MODE.Checkbox,
|
|
39
|
+
onKeyDown,
|
|
39
40
|
'data-test-id': testId
|
|
40
41
|
} = _a,
|
|
41
|
-
otherProps = __rest(_a, ["render", "checked", "defaultChecked", "onChange", "onBlur", "onFocus", "disabled", "className", "size", "mode", 'data-test-id']);
|
|
42
|
+
otherProps = __rest(_a, ["render", "checked", "defaultChecked", "onChange", "onBlur", "onFocus", "disabled", "className", "size", "mode", "onKeyDown", 'data-test-id']);
|
|
42
43
|
const [checked, setChecked] = (0, uncontrollable_1.useUncontrolledProp)(checkedProp, Boolean(defaultChecked), onChange);
|
|
43
44
|
const [focusVisible, setFocusVisible] = (0, react_1.useState)(false);
|
|
44
45
|
const [hover, setHover] = (0, react_1.useState)(false);
|
|
@@ -50,11 +51,13 @@ exports.TogglePrivate = (0, react_1.forwardRef)(function TogglePrivate(_a, ref)
|
|
|
50
51
|
size
|
|
51
52
|
};
|
|
52
53
|
return (0, jsx_runtime_1.jsxs)("span", Object.assign({
|
|
54
|
+
role: mode,
|
|
53
55
|
className: (0, classnames_1.default)(className, styles_module_scss_1.default.toggleLayout),
|
|
54
56
|
"data-size": size,
|
|
55
57
|
"data-test-id": testId,
|
|
56
58
|
onMouseEnter: () => setHover(true),
|
|
57
|
-
onMouseLeave: () => setHover(false)
|
|
59
|
+
onMouseLeave: () => setHover(false),
|
|
60
|
+
onKeyDown: onKeyDown
|
|
58
61
|
}, (0, utils_1.getVisualStateAttributes)(visualState), {
|
|
59
62
|
children: [render(visualState), (0, jsx_runtime_1.jsx)("input", Object.assign({}, otherProps, {
|
|
60
63
|
"data-test-id": `${testId}-native-input`,
|
package/dist/cjs/constants.d.ts
CHANGED
package/dist/cjs/constants.js
CHANGED
package/dist/cjs/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FocusEventHandler, MouseEventHandler, ReactNode, RefObject } from 'react';
|
|
1
|
+
import { FocusEventHandler, KeyboardEventHandler, MouseEventHandler, ReactNode, RefObject } from 'react';
|
|
2
2
|
import { ValueOf, WithSupportProps } from '@snack-uikit/utils';
|
|
3
3
|
import { FAVORITE_ICON, MODE, SELECTION_MODE, SIZE } from './constants';
|
|
4
4
|
export type Size = ValueOf<typeof SIZE>;
|
|
@@ -45,6 +45,8 @@ export type TogglePrivateProps = WithSupportProps<{
|
|
|
45
45
|
onBlur?: FocusEventHandler<HTMLInputElement>;
|
|
46
46
|
/** Колбек приобретения фокуса */
|
|
47
47
|
onFocus?: FocusEventHandler<HTMLInputElement>;
|
|
48
|
+
/** Колбек нажатия клавиши клавиатуры */
|
|
49
|
+
onKeyDown?: KeyboardEventHandler<HTMLDivElement>;
|
|
48
50
|
}>;
|
|
49
51
|
export type ToggleProps = WithSupportProps<Pick<TogglePrivateProps, 'id' | 'name' | 'value' | 'tabIndex' | 'autofocus' | 'checked' | 'defaultChecked' | 'disabled' | 'onChange' | 'onClick' | 'onBlur' | 'onFocus' | 'className' | 'size'> & {
|
|
50
52
|
inputRef?: RefObject<HTMLInputElement>;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { KeyboardEventHandler } from 'react';
|
|
1
2
|
import { FavoriteIcon, ToggleProps } from '../../types';
|
|
2
3
|
export type FavoriteProps = ToggleProps & {
|
|
3
4
|
/** Иконка */
|
|
4
5
|
icon?: FavoriteIcon;
|
|
6
|
+
/** Колбек нажатия клавиши клавиатуры */
|
|
7
|
+
onKeyDown?: KeyboardEventHandler<HTMLDivElement>;
|
|
5
8
|
};
|
|
6
|
-
export declare function Favorite({ inputRef, 'data-test-id': dataTestId, size, icon, ...restProps }: FavoriteProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export declare function Favorite({ inputRef, 'data-test-id': dataTestId, size, icon, onKeyDown, ...restProps }: FavoriteProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -11,7 +11,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
13
|
import { useMemo } from 'react';
|
|
14
|
-
import { HeartFilledSVG, HeartSVG, StarFilledSVG, StarSVG } from '@snack-uikit/icons';
|
|
14
|
+
import { HeartFilledSVG, HeartSVG, PinnedSVG, StarFilledSVG, StarSVG, UnPinnedSVG } from '@snack-uikit/icons';
|
|
15
15
|
import { FAVORITE_ICON, SIZE } from '../../constants';
|
|
16
16
|
import { getIconSize, getVisualStateAttributes } from '../../utils';
|
|
17
17
|
import { TogglePrivate } from '../TogglePrivate';
|
|
@@ -19,15 +19,17 @@ import styles from './styles.module.css';
|
|
|
19
19
|
const CHECKED_ICONS = {
|
|
20
20
|
[FAVORITE_ICON.Star]: StarFilledSVG,
|
|
21
21
|
[FAVORITE_ICON.Heart]: HeartFilledSVG,
|
|
22
|
+
[FAVORITE_ICON.Pin]: PinnedSVG,
|
|
22
23
|
};
|
|
23
24
|
const UNCHECKED_ICONS = {
|
|
24
25
|
[FAVORITE_ICON.Star]: StarSVG,
|
|
25
26
|
[FAVORITE_ICON.Heart]: HeartSVG,
|
|
27
|
+
[FAVORITE_ICON.Pin]: UnPinnedSVG,
|
|
26
28
|
};
|
|
27
29
|
export function Favorite(_a) {
|
|
28
|
-
var { inputRef, 'data-test-id': dataTestId, size = SIZE.M, icon = FAVORITE_ICON.Heart } = _a, restProps = __rest(_a, ["inputRef", 'data-test-id', "size", "icon"]);
|
|
30
|
+
var { inputRef, 'data-test-id': dataTestId, size = SIZE.M, icon = FAVORITE_ICON.Heart, onKeyDown } = _a, restProps = __rest(_a, ["inputRef", 'data-test-id', "size", "icon", "onKeyDown"]);
|
|
29
31
|
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) {
|
|
32
|
+
return (_jsx(TogglePrivate, Object.assign({}, restProps, { "data-test-id": dataTestId, ref: inputRef, size: size, onKeyDown: onKeyDown, render: function Favorite(visualState) {
|
|
31
33
|
const Icon = visualState.checked ? CHECKED_ICONS[icon] : UNCHECKED_ICONS[icon];
|
|
32
34
|
const data = getVisualStateAttributes(Object.assign(Object.assign({}, visualState), { icon }));
|
|
33
35
|
return (_jsx("div", Object.assign({ className: styles.container }, data, { children: _jsx(Icon, Object.assign({ className: styles.icon }, data, { size: iconSize })) })));
|
|
@@ -45,6 +45,12 @@
|
|
|
45
45
|
.icon:not([data-disabled=true])[data-icon=heart][data-checked=true][data-focusvisible=true], .icon:not([data-disabled=true])[data-icon=heart][data-checked=true][data-hover=true]{
|
|
46
46
|
color:var(--sys-red-accent-hovered, #bd4844);
|
|
47
47
|
}
|
|
48
|
+
.icon:not([data-disabled=true])[data-icon=pin][data-checked=true]{
|
|
49
|
+
color:var(--sys-primary-accent-default, #794ed3);
|
|
50
|
+
}
|
|
51
|
+
.icon:not([data-disabled=true])[data-icon=pin][data-checked=true][data-focusvisible=true], .icon:not([data-disabled=true])[data-icon=pin][data-checked=true][data-hover=true]{
|
|
52
|
+
color:var(--sys-primary-accent-hovered, #6851a6);
|
|
53
|
+
}
|
|
48
54
|
.icon[data-disabled=true]{
|
|
49
55
|
color:var(--sys-neutral-text-disabled, #aaaebd);
|
|
50
56
|
}
|
|
@@ -17,4 +17,5 @@ export declare const TogglePrivate: import("react").ForwardRefExoticComponent<{
|
|
|
17
17
|
onClick?: import("react").MouseEventHandler<HTMLInputElement>;
|
|
18
18
|
onBlur?: import("react").FocusEventHandler<HTMLInputElement>;
|
|
19
19
|
onFocus?: import("react").FocusEventHandler<HTMLInputElement>;
|
|
20
|
+
onKeyDown?: import("react").KeyboardEventHandler<HTMLDivElement>;
|
|
20
21
|
} & import("react").RefAttributes<HTMLInputElement>>;
|
|
@@ -17,7 +17,7 @@ import { MODE, SIZE } from '../../constants';
|
|
|
17
17
|
import { getVisualStateAttributes } from '../../utils';
|
|
18
18
|
import styles from './styles.module.css';
|
|
19
19
|
export const TogglePrivate = forwardRef(function TogglePrivate(_a, ref) {
|
|
20
|
-
var { render, checked: checkedProp, defaultChecked, onChange, onBlur, onFocus, disabled, className, size = SIZE.M, mode = MODE.Checkbox, 'data-test-id': testId } = _a, otherProps = __rest(_a, ["render", "checked", "defaultChecked", "onChange", "onBlur", "onFocus", "disabled", "className", "size", "mode", 'data-test-id']);
|
|
20
|
+
var { render, checked: checkedProp, defaultChecked, onChange, onBlur, onFocus, disabled, className, size = SIZE.M, mode = MODE.Checkbox, onKeyDown, 'data-test-id': testId } = _a, otherProps = __rest(_a, ["render", "checked", "defaultChecked", "onChange", "onBlur", "onFocus", "disabled", "className", "size", "mode", "onKeyDown", 'data-test-id']);
|
|
21
21
|
const [checked, setChecked] = useUncontrolledProp(checkedProp, Boolean(defaultChecked), onChange);
|
|
22
22
|
const [focusVisible, setFocusVisible] = useState(false);
|
|
23
23
|
const [hover, setHover] = useState(false);
|
|
@@ -28,7 +28,7 @@ export const TogglePrivate = forwardRef(function TogglePrivate(_a, ref) {
|
|
|
28
28
|
hover,
|
|
29
29
|
size,
|
|
30
30
|
};
|
|
31
|
-
return (_jsxs("span", Object.assign({ className: cn(className, styles.toggleLayout), "data-size": size, "data-test-id": testId, onMouseEnter: () => setHover(true), onMouseLeave: () => setHover(false) }, getVisualStateAttributes(visualState), { children: [render(visualState), _jsx("input", Object.assign({}, otherProps, { "data-test-id": `${testId}-native-input`, ref: ref, type: mode, className: styles.togglePrivate, checked: checked, disabled: disabled, onChange: e => setChecked(e.target.checked), onFocus: event => {
|
|
31
|
+
return (_jsxs("span", Object.assign({ role: mode, className: cn(className, styles.toggleLayout), "data-size": size, "data-test-id": testId, onMouseEnter: () => setHover(true), onMouseLeave: () => setHover(false), onKeyDown: onKeyDown }, getVisualStateAttributes(visualState), { children: [render(visualState), _jsx("input", Object.assign({}, otherProps, { "data-test-id": `${testId}-native-input`, ref: ref, type: mode, className: styles.togglePrivate, checked: checked, disabled: disabled, onChange: e => setChecked(e.target.checked), onFocus: event => {
|
|
32
32
|
setFocusVisible(event.target.matches(':focus-visible'));
|
|
33
33
|
onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
|
|
34
34
|
}, onBlur: event => {
|
package/dist/esm/constants.d.ts
CHANGED
package/dist/esm/constants.js
CHANGED
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FocusEventHandler, MouseEventHandler, ReactNode, RefObject } from 'react';
|
|
1
|
+
import { FocusEventHandler, KeyboardEventHandler, MouseEventHandler, ReactNode, RefObject } from 'react';
|
|
2
2
|
import { ValueOf, WithSupportProps } from '@snack-uikit/utils';
|
|
3
3
|
import { FAVORITE_ICON, MODE, SELECTION_MODE, SIZE } from './constants';
|
|
4
4
|
export type Size = ValueOf<typeof SIZE>;
|
|
@@ -45,6 +45,8 @@ export type TogglePrivateProps = WithSupportProps<{
|
|
|
45
45
|
onBlur?: FocusEventHandler<HTMLInputElement>;
|
|
46
46
|
/** Колбек приобретения фокуса */
|
|
47
47
|
onFocus?: FocusEventHandler<HTMLInputElement>;
|
|
48
|
+
/** Колбек нажатия клавиши клавиатуры */
|
|
49
|
+
onKeyDown?: KeyboardEventHandler<HTMLDivElement>;
|
|
48
50
|
}>;
|
|
49
51
|
export type ToggleProps = WithSupportProps<Pick<TogglePrivateProps, 'id' | 'name' | 'value' | 'tabIndex' | 'autofocus' | 'checked' | 'defaultChecked' | 'disabled' | 'onChange' | 'onClick' | 'onBlur' | 'onFocus' | 'className' | 'size'> & {
|
|
50
52
|
inputRef?: RefObject<HTMLInputElement>;
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Toggles",
|
|
7
|
-
"version": "0.12.0",
|
|
7
|
+
"version": "0.12.1-preview-d1a63029.0",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"merge-refs": "1.2.1",
|
|
43
43
|
"uncontrollable": "8.0.0"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "167f0c505b9958dc320111f7ee9e8ed2ebc58796"
|
|
46
46
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
1
|
+
import { KeyboardEventHandler, useMemo } from 'react';
|
|
2
2
|
|
|
3
|
-
import { HeartFilledSVG, HeartSVG, StarFilledSVG, StarSVG } from '@snack-uikit/icons';
|
|
3
|
+
import { HeartFilledSVG, HeartSVG, PinnedSVG, StarFilledSVG, StarSVG, UnPinnedSVG } from '@snack-uikit/icons';
|
|
4
4
|
|
|
5
5
|
import { FAVORITE_ICON, SIZE } from '../../constants';
|
|
6
6
|
import { FavoriteIcon, ToggleProps } from '../../types';
|
|
@@ -11,16 +11,20 @@ import styles from './styles.module.scss';
|
|
|
11
11
|
const CHECKED_ICONS = {
|
|
12
12
|
[FAVORITE_ICON.Star]: StarFilledSVG,
|
|
13
13
|
[FAVORITE_ICON.Heart]: HeartFilledSVG,
|
|
14
|
+
[FAVORITE_ICON.Pin]: PinnedSVG,
|
|
14
15
|
};
|
|
15
16
|
|
|
16
17
|
const UNCHECKED_ICONS = {
|
|
17
18
|
[FAVORITE_ICON.Star]: StarSVG,
|
|
18
19
|
[FAVORITE_ICON.Heart]: HeartSVG,
|
|
20
|
+
[FAVORITE_ICON.Pin]: UnPinnedSVG,
|
|
19
21
|
};
|
|
20
22
|
|
|
21
23
|
export type FavoriteProps = ToggleProps & {
|
|
22
24
|
/** Иконка */
|
|
23
25
|
icon?: FavoriteIcon;
|
|
26
|
+
/** Колбек нажатия клавиши клавиатуры */
|
|
27
|
+
onKeyDown?: KeyboardEventHandler<HTMLDivElement>;
|
|
24
28
|
};
|
|
25
29
|
|
|
26
30
|
export function Favorite({
|
|
@@ -28,6 +32,7 @@ export function Favorite({
|
|
|
28
32
|
'data-test-id': dataTestId,
|
|
29
33
|
size = SIZE.M,
|
|
30
34
|
icon = FAVORITE_ICON.Heart,
|
|
35
|
+
onKeyDown,
|
|
31
36
|
...restProps
|
|
32
37
|
}: FavoriteProps) {
|
|
33
38
|
const iconSize = useMemo(() => getIconSize(size), [size]);
|
|
@@ -38,6 +43,7 @@ export function Favorite({
|
|
|
38
43
|
data-test-id={dataTestId}
|
|
39
44
|
ref={inputRef}
|
|
40
45
|
size={size}
|
|
46
|
+
onKeyDown={onKeyDown}
|
|
41
47
|
render={function Favorite(visualState) {
|
|
42
48
|
const Icon = visualState.checked ? CHECKED_ICONS[icon] : UNCHECKED_ICONS[icon];
|
|
43
49
|
const data = getVisualStateAttributes({ ...visualState, icon });
|
|
@@ -19,6 +19,7 @@ export const TogglePrivate = forwardRef<HTMLInputElement, TogglePrivateProps>(fu
|
|
|
19
19
|
className,
|
|
20
20
|
size = SIZE.M,
|
|
21
21
|
mode = MODE.Checkbox,
|
|
22
|
+
onKeyDown,
|
|
22
23
|
'data-test-id': testId,
|
|
23
24
|
...otherProps
|
|
24
25
|
},
|
|
@@ -38,11 +39,13 @@ export const TogglePrivate = forwardRef<HTMLInputElement, TogglePrivateProps>(fu
|
|
|
38
39
|
|
|
39
40
|
return (
|
|
40
41
|
<span
|
|
42
|
+
role={mode}
|
|
41
43
|
className={cn(className, styles.toggleLayout)}
|
|
42
44
|
data-size={size}
|
|
43
45
|
data-test-id={testId}
|
|
44
46
|
onMouseEnter={() => setHover(true)}
|
|
45
47
|
onMouseLeave={() => setHover(false)}
|
|
48
|
+
onKeyDown={onKeyDown}
|
|
46
49
|
{...getVisualStateAttributes(visualState)}
|
|
47
50
|
>
|
|
48
51
|
{render(visualState)}
|
package/src/constants.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FocusEventHandler, MouseEventHandler, ReactNode, RefObject } from 'react';
|
|
1
|
+
import { FocusEventHandler, KeyboardEventHandler, MouseEventHandler, ReactNode, RefObject } from 'react';
|
|
2
2
|
|
|
3
3
|
import { ValueOf, WithSupportProps } from '@snack-uikit/utils';
|
|
4
4
|
|
|
@@ -51,6 +51,8 @@ export type TogglePrivateProps = WithSupportProps<{
|
|
|
51
51
|
onBlur?: FocusEventHandler<HTMLInputElement>;
|
|
52
52
|
/** Колбек приобретения фокуса */
|
|
53
53
|
onFocus?: FocusEventHandler<HTMLInputElement>;
|
|
54
|
+
/** Колбек нажатия клавиши клавиатуры */
|
|
55
|
+
onKeyDown?: KeyboardEventHandler<HTMLDivElement>;
|
|
54
56
|
}>;
|
|
55
57
|
|
|
56
58
|
export type ToggleProps = WithSupportProps<
|