@snack-uikit/segmented-control 0.6.10 → 0.6.11-preview-4eb2b89e.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 +0 -9
- package/dist/cjs/helperComponents/Segment/Segment.d.ts +1 -1
- package/dist/cjs/helperComponents/Segment/Segment.js +6 -0
- package/dist/cjs/types.d.ts +5 -0
- package/dist/esm/helperComponents/Segment/Segment.d.ts +1 -1
- package/dist/esm/helperComponents/Segment/Segment.js +3 -2
- package/dist/esm/types.d.ts +5 -0
- package/package.json +3 -2
- package/src/helperComponents/Segment/Segment.tsx +3 -0
- package/src/types.ts +5 -0
package/README.md
CHANGED
|
@@ -14,15 +14,6 @@ SegmentedControl
|
|
|
14
14
|
### Props
|
|
15
15
|
| name | type | default value | description |
|
|
16
16
|
|------|------|---------------|-------------|
|
|
17
|
-
| items* | `Segment<Value>[]` | - | Набор сегментов. |
|
|
18
|
-
| value | `IdType` | - | Value выбранного сегмента. |
|
|
19
|
-
| defaultValue | `IdType` | - | ID выбранного по умолчанию сегмента. (в uncontrolled режиме) |
|
|
20
|
-
| onChange | `(value: Value) => void` | - | Колбек смены выбранного сегмента. |
|
|
21
|
-
| className | `string` | - | CSS-класс контейнера. |
|
|
22
|
-
| size | enum Size: `"xs"`, `"s"`, `"m"`, `"l"` | m | Размер компонента. |
|
|
23
|
-
| outline | `boolean` | - | Обводка |
|
|
24
|
-
| width | enum Width: `"auto"`, `"full"` | auto | Управление шириной компонента. |
|
|
25
|
-
| name | `string` | - | Имя поля |
|
|
26
17
|
|
|
27
18
|
|
|
28
19
|
[//]: DOCUMENTATION_SECTION_END
|
|
@@ -7,5 +7,5 @@ type SegmentProps = SegmentType & {
|
|
|
7
7
|
onGetFocusable?: (ref: HTMLButtonElement | null) => void;
|
|
8
8
|
onSelectionUpdated: (element: HTMLButtonElement) => void;
|
|
9
9
|
};
|
|
10
|
-
export declare function Segment({ size, label, value, selected, onClick, disabled, icon, focusable, onGetFocusable, onSelectionUpdated, renderWrapSegment, }: SegmentProps): string | number | boolean | Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
|
|
10
|
+
export declare function Segment({ size, label, value, selected, onClick, disabled, icon, counter, focusable, onGetFocusable, onSelectionUpdated, renderWrapSegment, }: SegmentProps): string | number | boolean | Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
|
|
11
11
|
export {};
|
|
@@ -12,6 +12,7 @@ exports.Segment = Segment;
|
|
|
12
12
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
13
13
|
const classnames_1 = __importDefault(require("classnames"));
|
|
14
14
|
const react_1 = require("react");
|
|
15
|
+
const counter_1 = require("@snack-uikit/counter");
|
|
15
16
|
const truncate_string_1 = require("@snack-uikit/truncate-string");
|
|
16
17
|
const utils_1 = require("../../utils");
|
|
17
18
|
const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
|
|
@@ -24,6 +25,7 @@ function Segment(_ref) {
|
|
|
24
25
|
onClick,
|
|
25
26
|
disabled,
|
|
26
27
|
icon,
|
|
28
|
+
counter,
|
|
27
29
|
focusable,
|
|
28
30
|
onGetFocusable,
|
|
29
31
|
onSelectionUpdated,
|
|
@@ -61,6 +63,10 @@ function Segment(_ref) {
|
|
|
61
63
|
className: styles_module_scss_1.default.label,
|
|
62
64
|
"data-size": size,
|
|
63
65
|
text: label
|
|
66
|
+
}), counter !== undefined && (0, jsx_runtime_1.jsx)(counter_1.Counter, {
|
|
67
|
+
size: 's',
|
|
68
|
+
appearance: 'primary',
|
|
69
|
+
value: counter
|
|
64
70
|
})]
|
|
65
71
|
});
|
|
66
72
|
return renderWrapSegment ? renderWrapSegment(segment) : segment;
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
+
import { CounterProps } from '@snack-uikit/counter';
|
|
2
3
|
import { ValueOf } from '@snack-uikit/utils';
|
|
3
4
|
import { SIZE, WIDTH } from './constants';
|
|
4
5
|
export type IdType = string | number;
|
|
@@ -21,6 +22,10 @@ export type Segment<Value extends IdType = IdType> = {
|
|
|
21
22
|
* Иконка сегмента.
|
|
22
23
|
*/
|
|
23
24
|
icon?: ReactNode;
|
|
25
|
+
/**
|
|
26
|
+
* Иконка сегмента.
|
|
27
|
+
*/
|
|
28
|
+
counter?: CounterProps['value'];
|
|
24
29
|
/**
|
|
25
30
|
* Render-обертка над сегментом.
|
|
26
31
|
*/
|
|
@@ -7,5 +7,5 @@ type SegmentProps = SegmentType & {
|
|
|
7
7
|
onGetFocusable?: (ref: HTMLButtonElement | null) => void;
|
|
8
8
|
onSelectionUpdated: (element: HTMLButtonElement) => void;
|
|
9
9
|
};
|
|
10
|
-
export declare function Segment({ size, label, value, selected, onClick, disabled, icon, focusable, onGetFocusable, onSelectionUpdated, renderWrapSegment, }: SegmentProps): string | number | boolean | Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
|
|
10
|
+
export declare function Segment({ size, label, value, selected, onClick, disabled, icon, counter, focusable, onGetFocusable, onSelectionUpdated, renderWrapSegment, }: SegmentProps): string | number | boolean | Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
|
|
11
11
|
export {};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import cn from 'classnames';
|
|
3
3
|
import { useEffect, useRef } from 'react';
|
|
4
|
+
import { Counter } from '@snack-uikit/counter';
|
|
4
5
|
import { TruncateString } from '@snack-uikit/truncate-string';
|
|
5
6
|
import { getLayout } from '../../utils';
|
|
6
7
|
import styles from './styles.module.css';
|
|
7
|
-
export function Segment({ size, label, value, selected, onClick, disabled, icon, focusable, onGetFocusable, onSelectionUpdated, renderWrapSegment, }) {
|
|
8
|
+
export function Segment({ size, label, value, selected, onClick, disabled, icon, counter, focusable, onGetFocusable, onSelectionUpdated, renderWrapSegment, }) {
|
|
8
9
|
const buttonRef = useRef(null);
|
|
9
10
|
useEffect(() => {
|
|
10
11
|
if (focusable) {
|
|
@@ -16,6 +17,6 @@ export function Segment({ size, label, value, selected, onClick, disabled, icon,
|
|
|
16
17
|
onSelectionUpdated(buttonRef.current);
|
|
17
18
|
}
|
|
18
19
|
}, [selected, buttonRef, onSelectionUpdated]);
|
|
19
|
-
const segment = (_jsxs("button", { ref: buttonRef, "data-test-id": `section-${value}`, "data-active": selected || undefined, "data-disabled": disabled || undefined, "data-layout": getLayout(icon, label, size), className: cn(styles.segment), onClick: onClick, "data-size": size, disabled: disabled, tabIndex: focusable ? 0 : -1, "aria-checked": selected, role: 'radio', type: 'button', children: [size !== 'xs' && icon && _jsx("div", { className: styles.icon, children: icon }), label && _jsx(TruncateString, { className: styles.label, "data-size": size, text: label })] }));
|
|
20
|
+
const segment = (_jsxs("button", { ref: buttonRef, "data-test-id": `section-${value}`, "data-active": selected || undefined, "data-disabled": disabled || undefined, "data-layout": getLayout(icon, label, size), className: cn(styles.segment), onClick: onClick, "data-size": size, disabled: disabled, tabIndex: focusable ? 0 : -1, "aria-checked": selected, role: 'radio', type: 'button', children: [size !== 'xs' && icon && _jsx("div", { className: styles.icon, children: icon }), label && _jsx(TruncateString, { className: styles.label, "data-size": size, text: label }), counter !== undefined && _jsx(Counter, { size: 's', appearance: 'primary', value: counter })] }));
|
|
20
21
|
return renderWrapSegment ? renderWrapSegment(segment) : segment;
|
|
21
22
|
}
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
+
import { CounterProps } from '@snack-uikit/counter';
|
|
2
3
|
import { ValueOf } from '@snack-uikit/utils';
|
|
3
4
|
import { SIZE, WIDTH } from './constants';
|
|
4
5
|
export type IdType = string | number;
|
|
@@ -21,6 +22,10 @@ export type Segment<Value extends IdType = IdType> = {
|
|
|
21
22
|
* Иконка сегмента.
|
|
22
23
|
*/
|
|
23
24
|
icon?: ReactNode;
|
|
25
|
+
/**
|
|
26
|
+
* Иконка сегмента.
|
|
27
|
+
*/
|
|
28
|
+
counter?: CounterProps['value'];
|
|
24
29
|
/**
|
|
25
30
|
* Render-обертка над сегментом.
|
|
26
31
|
*/
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Segmented Control",
|
|
7
|
-
"version": "0.6.
|
|
7
|
+
"version": "0.6.11-preview-4eb2b89e.0",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -36,10 +36,11 @@
|
|
|
36
36
|
"license": "Apache-2.0",
|
|
37
37
|
"scripts": {},
|
|
38
38
|
"dependencies": {
|
|
39
|
+
"@snack-uikit/counter": "0.8.10",
|
|
39
40
|
"@snack-uikit/truncate-string": "0.7.2",
|
|
40
41
|
"@snack-uikit/utils": "4.0.0",
|
|
41
42
|
"classnames": "2.5.1",
|
|
42
43
|
"uncontrollable": "8.0.4"
|
|
43
44
|
},
|
|
44
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "d46627c950a04cca650210be851e436e9994ca6a"
|
|
45
46
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import cn from 'classnames';
|
|
2
2
|
import { useEffect, useRef } from 'react';
|
|
3
3
|
|
|
4
|
+
import { Counter } from '@snack-uikit/counter';
|
|
4
5
|
import { TruncateString } from '@snack-uikit/truncate-string';
|
|
5
6
|
|
|
6
7
|
import { Segment as SegmentType, Size } from '../../types';
|
|
@@ -24,6 +25,7 @@ export function Segment({
|
|
|
24
25
|
onClick,
|
|
25
26
|
disabled,
|
|
26
27
|
icon,
|
|
28
|
+
counter,
|
|
27
29
|
focusable,
|
|
28
30
|
onGetFocusable,
|
|
29
31
|
onSelectionUpdated,
|
|
@@ -61,6 +63,7 @@ export function Segment({
|
|
|
61
63
|
>
|
|
62
64
|
{size !== 'xs' && icon && <div className={styles.icon}>{icon}</div>}
|
|
63
65
|
{label && <TruncateString className={styles.label} data-size={size} text={label} />}
|
|
66
|
+
{counter !== undefined && <Counter size='s' appearance='primary' value={counter} />}
|
|
64
67
|
</button>
|
|
65
68
|
);
|
|
66
69
|
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
|
|
3
|
+
import { CounterProps } from '@snack-uikit/counter';
|
|
3
4
|
import { ValueOf } from '@snack-uikit/utils';
|
|
4
5
|
|
|
5
6
|
import { SIZE, WIDTH } from './constants';
|
|
@@ -27,6 +28,10 @@ export type Segment<Value extends IdType = IdType> = {
|
|
|
27
28
|
* Иконка сегмента.
|
|
28
29
|
*/
|
|
29
30
|
icon?: ReactNode;
|
|
31
|
+
/**
|
|
32
|
+
* Иконка сегмента.
|
|
33
|
+
*/
|
|
34
|
+
counter?: CounterProps['value'];
|
|
30
35
|
/**
|
|
31
36
|
* Render-обертка над сегментом.
|
|
32
37
|
*/
|