@snack-uikit/segmented-control 0.1.4-preview-963c3343.0 → 0.2.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 +20 -0
- package/README.md +2 -2
- package/dist/components/SegmentedControl.d.ts +6 -6
- package/dist/types.d.ts +2 -2
- package/package.json +3 -3
- package/src/components/SegmentedControl.tsx +7 -7
- package/src/types.ts +2 -2
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.2.0 (2024-09-09)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **FF-0000:** improve segmented control value type ([e6f1d66](https://github.com/cloud-ru-tech/snack-uikit/commit/e6f1d66c132402a126d8b00a5918c1f3eb40f764))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## 0.1.4 (2024-09-06)
|
|
18
|
+
|
|
19
|
+
### Only dependencies have been changed
|
|
20
|
+
* [@snack-uikit/truncate-string@0.4.21](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/truncate-string/CHANGELOG.md)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
6
26
|
## 0.1.3 (2024-08-01)
|
|
7
27
|
|
|
8
28
|
|
package/README.md
CHANGED
|
@@ -14,10 +14,10 @@ SegmentedControl
|
|
|
14
14
|
### Props
|
|
15
15
|
| name | type | default value | description |
|
|
16
16
|
|------|------|---------------|-------------|
|
|
17
|
-
| items* | `Segment[]` | - | Набор сегментов. |
|
|
17
|
+
| items* | `Segment<Value>[]` | - | Набор сегментов. |
|
|
18
18
|
| value | `IdType` | - | Value выбранного сегмента. |
|
|
19
19
|
| defaultValue | `IdType` | - | ID выбранного по умолчанию сегмента. (в uncontrolled режиме) |
|
|
20
|
-
| onChange | `(value:
|
|
20
|
+
| onChange | `(value: Value) => void` | - | Колбек смены выбранного сегмента. |
|
|
21
21
|
| className | `string` | - | CSS-класс контейнера. |
|
|
22
22
|
| size | enum Size: `"s"`, `"m"`, `"l"` | m | Размер компонента. |
|
|
23
23
|
| outline | `boolean` | - | Обводка |
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { WithSupportProps } from '@snack-uikit/utils';
|
|
2
2
|
import { IdType, Segment as SegmentType, Size, Width } from '../types';
|
|
3
|
-
export type SegmentedControlProps = WithSupportProps<{
|
|
3
|
+
export type SegmentedControlProps<Value extends IdType = IdType> = WithSupportProps<{
|
|
4
4
|
/**
|
|
5
5
|
* Набор сегментов.
|
|
6
6
|
*/
|
|
7
|
-
items: SegmentType[];
|
|
7
|
+
items: SegmentType<Value>[];
|
|
8
8
|
/**
|
|
9
9
|
* Value выбранного сегмента.
|
|
10
10
|
*/
|
|
11
|
-
value?:
|
|
11
|
+
value?: Value;
|
|
12
12
|
/**
|
|
13
13
|
* ID выбранного по умолчанию сегмента. (в uncontrolled режиме)
|
|
14
14
|
*/
|
|
15
|
-
defaultValue?:
|
|
15
|
+
defaultValue?: Value;
|
|
16
16
|
/**
|
|
17
17
|
* Колбек смены выбранного сегмента.
|
|
18
18
|
*/
|
|
19
|
-
onChange?: (value:
|
|
19
|
+
onChange?: (value: Value) => void;
|
|
20
20
|
/**
|
|
21
21
|
* CSS-класс контейнера.
|
|
22
22
|
*/
|
|
@@ -37,4 +37,4 @@ export type SegmentedControlProps = WithSupportProps<{
|
|
|
37
37
|
/**
|
|
38
38
|
* SegmentedControl
|
|
39
39
|
*/
|
|
40
|
-
export declare function SegmentedControl({ defaultValue, size, className, onChange, items, value, outline, width, ...other }: SegmentedControlProps): import("react/jsx-runtime").JSX.Element;
|
|
40
|
+
export declare function SegmentedControl<Value extends IdType>({ defaultValue, size, className, onChange, items, value, outline, width, ...other }: SegmentedControlProps<Value>): import("react/jsx-runtime").JSX.Element;
|
package/dist/types.d.ts
CHANGED
|
@@ -4,11 +4,11 @@ import { SIZE, WIDTH } from './constants';
|
|
|
4
4
|
export type IdType = string | number;
|
|
5
5
|
export type Size = ValueOf<typeof SIZE>;
|
|
6
6
|
export type Width = ValueOf<typeof WIDTH>;
|
|
7
|
-
export type Segment = {
|
|
7
|
+
export type Segment<Value extends IdType = IdType> = {
|
|
8
8
|
/**
|
|
9
9
|
* Идентификатор сегмента.
|
|
10
10
|
*/
|
|
11
|
-
value:
|
|
11
|
+
value: Value;
|
|
12
12
|
/**
|
|
13
13
|
* Текстовый заголовок сегмента.
|
|
14
14
|
*/
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Segmented Control",
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.2.0",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
"license": "Apache-2.0",
|
|
33
33
|
"scripts": {},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@snack-uikit/truncate-string": "0.4.21
|
|
35
|
+
"@snack-uikit/truncate-string": "0.4.21",
|
|
36
36
|
"@snack-uikit/utils": "3.3.0",
|
|
37
37
|
"classnames": "2.5.1",
|
|
38
38
|
"uncontrollable": "8.0.4"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "cfd6f6352e10e2000db375500ea301dc82fafc67"
|
|
41
41
|
}
|
|
@@ -10,23 +10,23 @@ import { useFocusControl } from '../hooks';
|
|
|
10
10
|
import { IdType, Segment as SegmentType, SelectionPosition, Size, Width } from '../types';
|
|
11
11
|
import styles from './styles.module.scss';
|
|
12
12
|
|
|
13
|
-
export type SegmentedControlProps = WithSupportProps<{
|
|
13
|
+
export type SegmentedControlProps<Value extends IdType = IdType> = WithSupportProps<{
|
|
14
14
|
/**
|
|
15
15
|
* Набор сегментов.
|
|
16
16
|
*/
|
|
17
|
-
items: SegmentType[];
|
|
17
|
+
items: SegmentType<Value>[];
|
|
18
18
|
/**
|
|
19
19
|
* Value выбранного сегмента.
|
|
20
20
|
*/
|
|
21
|
-
value?:
|
|
21
|
+
value?: Value;
|
|
22
22
|
/**
|
|
23
23
|
* ID выбранного по умолчанию сегмента. (в uncontrolled режиме)
|
|
24
24
|
*/
|
|
25
|
-
defaultValue?:
|
|
25
|
+
defaultValue?: Value;
|
|
26
26
|
/**
|
|
27
27
|
* Колбек смены выбранного сегмента.
|
|
28
28
|
*/
|
|
29
|
-
onChange?: (value:
|
|
29
|
+
onChange?: (value: Value) => void;
|
|
30
30
|
/**
|
|
31
31
|
* CSS-класс контейнера.
|
|
32
32
|
*/
|
|
@@ -48,7 +48,7 @@ export type SegmentedControlProps = WithSupportProps<{
|
|
|
48
48
|
/**
|
|
49
49
|
* SegmentedControl
|
|
50
50
|
*/
|
|
51
|
-
export function SegmentedControl({
|
|
51
|
+
export function SegmentedControl<Value extends IdType>({
|
|
52
52
|
defaultValue,
|
|
53
53
|
size = 'm',
|
|
54
54
|
className,
|
|
@@ -58,7 +58,7 @@ export function SegmentedControl({
|
|
|
58
58
|
outline,
|
|
59
59
|
width = WIDTH.Auto,
|
|
60
60
|
...other
|
|
61
|
-
}: SegmentedControlProps) {
|
|
61
|
+
}: SegmentedControlProps<Value>) {
|
|
62
62
|
const [selected, setSelected] = useUncontrolledProp(value, defaultValue, onChange);
|
|
63
63
|
const { focusableSegmentValue, onGetFocusable, onKeyDown } = useFocusControl({ selected, items });
|
|
64
64
|
const containerRef = useRef<HTMLDivElement>(null);
|
package/src/types.ts
CHANGED
|
@@ -10,11 +10,11 @@ export type Size = ValueOf<typeof SIZE>;
|
|
|
10
10
|
|
|
11
11
|
export type Width = ValueOf<typeof WIDTH>;
|
|
12
12
|
|
|
13
|
-
export type Segment = {
|
|
13
|
+
export type Segment<Value extends IdType = IdType> = {
|
|
14
14
|
/**
|
|
15
15
|
* Идентификатор сегмента.
|
|
16
16
|
*/
|
|
17
|
-
value:
|
|
17
|
+
value: Value;
|
|
18
18
|
/**
|
|
19
19
|
* Текстовый заголовок сегмента.
|
|
20
20
|
*/
|