@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.
- package/CHANGELOG.md +357 -0
- package/LICENSE +201 -0
- package/README.md +169 -0
- package/dist/components/Checkbox/Checkbox.d.ts +12 -0
- package/dist/components/Checkbox/Checkbox.js +41 -0
- package/dist/components/Checkbox/index.d.ts +1 -0
- package/dist/components/Checkbox/index.js +1 -0
- package/dist/components/Checkbox/styles.module.css +86 -0
- package/dist/components/Favorite/Favorite.d.ts +10 -0
- package/dist/components/Favorite/Favorite.js +36 -0
- package/dist/components/Favorite/index.d.ts +1 -0
- package/dist/components/Favorite/index.js +1 -0
- package/dist/components/Favorite/styles.module.css +47 -0
- package/dist/components/Radio/Radio.d.ts +7 -0
- package/dist/components/Radio/Radio.js +24 -0
- package/dist/components/Radio/index.d.ts +1 -0
- package/dist/components/Radio/index.js +1 -0
- package/dist/components/Radio/styles.module.css +90 -0
- package/dist/components/Switch/Switch.d.ts +10 -0
- package/dist/components/Switch/Switch.js +27 -0
- package/dist/components/Switch/index.d.ts +1 -0
- package/dist/components/Switch/index.js +1 -0
- package/dist/components/Switch/styles.module.css +150 -0
- package/dist/components/ToggleGroup/ToggleGroup.d.ts +28 -0
- package/dist/components/ToggleGroup/ToggleGroup.js +31 -0
- package/dist/components/ToggleGroup/hooks.d.ts +9 -0
- package/dist/components/ToggleGroup/hooks.js +23 -0
- package/dist/components/ToggleGroup/index.d.ts +2 -0
- package/dist/components/ToggleGroup/index.js +2 -0
- package/dist/components/TogglePrivate/TogglePrivate.d.ts +22 -0
- package/dist/components/TogglePrivate/TogglePrivate.js +38 -0
- package/dist/components/TogglePrivate/index.d.ts +1 -0
- package/dist/components/TogglePrivate/index.js +1 -0
- package/dist/components/TogglePrivate/styles.module.css +38 -0
- package/dist/components/index.d.ts +5 -0
- package/dist/components/index.js +5 -0
- package/dist/components/styles.module.css +0 -0
- package/dist/constants.d.ts +16 -0
- package/dist/constants.js +20 -0
- package/dist/context.d.ts +10 -0
- package/dist/context.js +8 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/types.d.ts +47 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +18 -0
- package/package.json +42 -0
- package/src/components/Checkbox/Checkbox.tsx +72 -0
- package/src/components/Checkbox/index.ts +1 -0
- package/src/components/Checkbox/styles.module.scss +77 -0
- package/src/components/Favorite/Favorite.tsx +54 -0
- package/src/components/Favorite/index.ts +1 -0
- package/src/components/Favorite/styles.module.scss +36 -0
- package/src/components/Radio/Radio.tsx +30 -0
- package/src/components/Radio/index.ts +1 -0
- package/src/components/Radio/styles.module.scss +74 -0
- package/src/components/Switch/Switch.tsx +50 -0
- package/src/components/Switch/index.ts +1 -0
- package/src/components/Switch/styles.module.scss +124 -0
- package/src/components/ToggleGroup/ToggleGroup.tsx +76 -0
- package/src/components/ToggleGroup/hooks.ts +34 -0
- package/src/components/ToggleGroup/index.ts +2 -0
- package/src/components/TogglePrivate/TogglePrivate.tsx +69 -0
- package/src/components/TogglePrivate/index.ts +1 -0
- package/src/components/TogglePrivate/styles.module.scss +56 -0
- package/src/components/index.ts +5 -0
- package/src/components/styles.module.scss +24 -0
- package/src/constants.ts +19 -0
- package/src/context.ts +17 -0
- package/src/index.ts +1 -0
- package/src/types.ts +71 -0
- package/src/utils.ts +21 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
@import '@snack-uikit/figma-tokens/build/scss/components/styles-tokens-toggles';
|
|
2
|
+
@import '@snack-uikit/figma-tokens/build/scss/components/styles-tokens-element';
|
|
3
|
+
|
|
4
|
+
$sizes: 's', 'm';
|
|
5
|
+
|
|
6
|
+
$icon-sizes: (
|
|
7
|
+
's': $icon-xs,
|
|
8
|
+
'm': $icon-s,
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
.toggleLayout {
|
|
12
|
+
cursor: pointer;
|
|
13
|
+
|
|
14
|
+
position: relative;
|
|
15
|
+
|
|
16
|
+
display: inline-flex;
|
|
17
|
+
flex-direction: row;
|
|
18
|
+
flex-grow: 0;
|
|
19
|
+
flex-shrink: 0;
|
|
20
|
+
align-items: center;
|
|
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
|
+
&[data-disabled=true] {
|
|
32
|
+
cursor: not-allowed;
|
|
33
|
+
color: $sys-neutral-text-disabled;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.togglePrivate {
|
|
38
|
+
cursor: pointer;
|
|
39
|
+
|
|
40
|
+
position: absolute;
|
|
41
|
+
top: 0;
|
|
42
|
+
right: 0;
|
|
43
|
+
bottom: 0;
|
|
44
|
+
left: 0;
|
|
45
|
+
|
|
46
|
+
width: 100%;
|
|
47
|
+
height: 100%;
|
|
48
|
+
margin: 0;
|
|
49
|
+
padding: 0;
|
|
50
|
+
|
|
51
|
+
opacity: 0;
|
|
52
|
+
|
|
53
|
+
&:disabled {
|
|
54
|
+
cursor: not-allowed;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
@import '@snack-uikit/figma-tokens/build/scss/components/styles-tokens-toggles';
|
|
2
|
+
@import '@snack-uikit/figma-tokens/build/scss/components/styles-tokens-element';
|
|
3
|
+
|
|
4
|
+
$sizes: 's', 'm';
|
|
5
|
+
|
|
6
|
+
@mixin container($component) {
|
|
7
|
+
display: flex;
|
|
8
|
+
align-items: center;
|
|
9
|
+
justify-content: center;
|
|
10
|
+
box-sizing: border-box;
|
|
11
|
+
|
|
12
|
+
@each $size in $sizes {
|
|
13
|
+
&[data-size='#{$size}'] {
|
|
14
|
+
@include composite-var($toggles, $size, $component, 'container');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
&[data-focusvisible=true] {
|
|
19
|
+
@include outline-var($container-focused-s);
|
|
20
|
+
&[data-size='s'] {
|
|
21
|
+
outline-offset: simple-var($theme-variables, 'border-width', 'state-focus', 's');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export enum Mode {
|
|
2
|
+
Checkbox = 'checkbox',
|
|
3
|
+
Radio = 'radio',
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export enum Size {
|
|
7
|
+
S = 's',
|
|
8
|
+
M = 'm',
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export enum FavoriteIcon {
|
|
12
|
+
Star = 'star',
|
|
13
|
+
Heart = 'heart',
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export enum SelectionMode {
|
|
17
|
+
Single = 'single',
|
|
18
|
+
Multiple = 'multiple',
|
|
19
|
+
}
|
package/src/context.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
|
|
3
|
+
import { SelectionMode } from './constants';
|
|
4
|
+
|
|
5
|
+
type ToggleGroupContextType = {
|
|
6
|
+
value: string | undefined | string[];
|
|
7
|
+
onChange: ((id: string) => void) | undefined;
|
|
8
|
+
selectionMode: SelectionMode;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const ToggleGroupContext = createContext<ToggleGroupContextType>({
|
|
12
|
+
value: undefined,
|
|
13
|
+
onChange: undefined,
|
|
14
|
+
selectionMode: SelectionMode.Single,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export const useToggleGroupContext = () => useContext(ToggleGroupContext);
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components';
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { FocusEventHandler, MouseEventHandler, ReactNode, RefObject } from 'react';
|
|
2
|
+
|
|
3
|
+
import { WithSupportProps } from '@snack-uikit/utils';
|
|
4
|
+
|
|
5
|
+
import { Mode, Size } from './constants';
|
|
6
|
+
|
|
7
|
+
export type InputVisualState = {
|
|
8
|
+
focusVisible: boolean;
|
|
9
|
+
disabled: boolean;
|
|
10
|
+
checked: boolean;
|
|
11
|
+
hover: boolean;
|
|
12
|
+
size: Size;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type DataAttributes = Record<`data-${string}`, string | boolean>;
|
|
16
|
+
|
|
17
|
+
export type TogglePrivateProps = WithSupportProps<{
|
|
18
|
+
className?: string;
|
|
19
|
+
/** Размер */
|
|
20
|
+
size?: Size;
|
|
21
|
+
/** Колбек рендера компонента */
|
|
22
|
+
render: (visualState: InputVisualState) => ReactNode;
|
|
23
|
+
/** Режим работы */
|
|
24
|
+
mode?: Mode;
|
|
25
|
+
/** HTML-аттрибут id */
|
|
26
|
+
id?: string;
|
|
27
|
+
/** HTML-аттрибут value */
|
|
28
|
+
value?: string;
|
|
29
|
+
/** HTML-аттрибут name */
|
|
30
|
+
name?: string;
|
|
31
|
+
/** HTML-аттрибут tab-index */
|
|
32
|
+
tabIndex?: number;
|
|
33
|
+
/** HTML-аттрибут autofocus */
|
|
34
|
+
autofocus?: boolean;
|
|
35
|
+
/** HTML-аттрибут checked */
|
|
36
|
+
checked?: boolean;
|
|
37
|
+
/** HTML-аттрибут checked по-умолчанию */
|
|
38
|
+
defaultChecked?: boolean;
|
|
39
|
+
/** HTML-аттрибут disabled */
|
|
40
|
+
disabled?: boolean;
|
|
41
|
+
/** Колбек смены значения */
|
|
42
|
+
onChange?: (checked: boolean) => void;
|
|
43
|
+
/** Колбек клика */
|
|
44
|
+
onClick?: MouseEventHandler<HTMLInputElement>;
|
|
45
|
+
/** Колбек потери фокуса */
|
|
46
|
+
onBlur?: FocusEventHandler<HTMLInputElement>;
|
|
47
|
+
/** Колбек приобретения фокуса */
|
|
48
|
+
onFocus?: FocusEventHandler<HTMLInputElement>;
|
|
49
|
+
}>;
|
|
50
|
+
|
|
51
|
+
export type ToggleProps = WithSupportProps<
|
|
52
|
+
Pick<
|
|
53
|
+
TogglePrivateProps,
|
|
54
|
+
| 'id'
|
|
55
|
+
| 'name'
|
|
56
|
+
| 'value'
|
|
57
|
+
| 'tabIndex'
|
|
58
|
+
| 'autofocus'
|
|
59
|
+
| 'checked'
|
|
60
|
+
| 'defaultChecked'
|
|
61
|
+
| 'disabled'
|
|
62
|
+
| 'onChange'
|
|
63
|
+
| 'onClick'
|
|
64
|
+
| 'onBlur'
|
|
65
|
+
| 'onFocus'
|
|
66
|
+
| 'className'
|
|
67
|
+
| 'size'
|
|
68
|
+
> & {
|
|
69
|
+
inputRef?: RefObject<HTMLInputElement>;
|
|
70
|
+
}
|
|
71
|
+
>;
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Size } from './constants';
|
|
2
|
+
import { DataAttributes } from './types';
|
|
3
|
+
|
|
4
|
+
export function getVisualStateAttributes(state: Record<string, string | boolean>) {
|
|
5
|
+
return Object.entries(state).reduce<DataAttributes>(function (result, [name, value]) {
|
|
6
|
+
result[`data-${name.toLowerCase()}`] = value;
|
|
7
|
+
return result;
|
|
8
|
+
}, {});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function getIconSize(size?: Size) {
|
|
12
|
+
switch (size) {
|
|
13
|
+
case Size.S: {
|
|
14
|
+
return 16;
|
|
15
|
+
}
|
|
16
|
+
case Size.M:
|
|
17
|
+
default: {
|
|
18
|
+
return 24;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|