@snack-uikit/segmented-control 0.4.19 → 0.4.20-preview-2b94e286.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 +1 -0
- package/dist/cjs/components/SegmentedControl.d.ts +5 -1
- package/dist/cjs/components/SegmentedControl.js +8 -3
- package/dist/esm/components/SegmentedControl.d.ts +5 -1
- package/dist/esm/components/SegmentedControl.js +2 -2
- package/package.json +2 -2
- package/src/components/SegmentedControl.tsx +6 -0
package/README.md
CHANGED
|
@@ -22,6 +22,7 @@ SegmentedControl
|
|
|
22
22
|
| size | enum Size: `"s"`, `"m"`, `"l"` | m | Размер компонента. |
|
|
23
23
|
| outline | `boolean` | - | Обводка |
|
|
24
24
|
| width | enum Width: `"auto"`, `"full"` | auto | Управление шириной компонента. |
|
|
25
|
+
| name | `string` | - | Имя поля |
|
|
25
26
|
|
|
26
27
|
|
|
27
28
|
[//]: DOCUMENTATION_SECTION_END
|
|
@@ -33,8 +33,12 @@ export type SegmentedControlProps<Value extends IdType = IdType> = WithSupportPr
|
|
|
33
33
|
* Управление шириной компонента.
|
|
34
34
|
*/
|
|
35
35
|
width?: Width;
|
|
36
|
+
/**
|
|
37
|
+
* Имя поля
|
|
38
|
+
*/
|
|
39
|
+
name?: string;
|
|
36
40
|
}>;
|
|
37
41
|
/**
|
|
38
42
|
* SegmentedControl
|
|
39
43
|
*/
|
|
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;
|
|
44
|
+
export declare function SegmentedControl<Value extends IdType>({ defaultValue, size, className, onChange, items, value, outline, width, name, ...other }: SegmentedControlProps<Value>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -38,9 +38,10 @@ function SegmentedControl(_a) {
|
|
|
38
38
|
items,
|
|
39
39
|
value,
|
|
40
40
|
outline,
|
|
41
|
-
width = constants_1.WIDTH.Auto
|
|
41
|
+
width = constants_1.WIDTH.Auto,
|
|
42
|
+
name
|
|
42
43
|
} = _a,
|
|
43
|
-
other = __rest(_a, ["defaultValue", "size", "className", "onChange", "items", "value", "outline", "width"]);
|
|
44
|
+
other = __rest(_a, ["defaultValue", "size", "className", "onChange", "items", "value", "outline", "width", "name"]);
|
|
44
45
|
const [selected, setSelected] = (0, uncontrollable_1.useUncontrolledProp)(value, defaultValue, onChange);
|
|
45
46
|
const {
|
|
46
47
|
focusableSegmentValue,
|
|
@@ -106,7 +107,11 @@ function SegmentedControl(_a) {
|
|
|
106
107
|
"data-outline": outline || undefined,
|
|
107
108
|
"data-width": width
|
|
108
109
|
}, (0, utils_1.extractDataTestProps)(other), (0, utils_1.extractSupportProps)(other), {
|
|
109
|
-
children: [(0, jsx_runtime_1.jsx)("
|
|
110
|
+
children: [name && (0, jsx_runtime_1.jsx)("input", {
|
|
111
|
+
type: 'hidden',
|
|
112
|
+
value: selected,
|
|
113
|
+
name: name
|
|
114
|
+
}), (0, jsx_runtime_1.jsx)("div", {
|
|
110
115
|
"data-size": size,
|
|
111
116
|
style: selectionPosition,
|
|
112
117
|
className: styles_module_scss_1.default.selection,
|
|
@@ -33,8 +33,12 @@ export type SegmentedControlProps<Value extends IdType = IdType> = WithSupportPr
|
|
|
33
33
|
* Управление шириной компонента.
|
|
34
34
|
*/
|
|
35
35
|
width?: Width;
|
|
36
|
+
/**
|
|
37
|
+
* Имя поля
|
|
38
|
+
*/
|
|
39
|
+
name?: string;
|
|
36
40
|
}>;
|
|
37
41
|
/**
|
|
38
42
|
* SegmentedControl
|
|
39
43
|
*/
|
|
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;
|
|
44
|
+
export declare function SegmentedControl<Value extends IdType>({ defaultValue, size, className, onChange, items, value, outline, width, name, ...other }: SegmentedControlProps<Value>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -22,7 +22,7 @@ import styles from './styles.module.css';
|
|
|
22
22
|
* SegmentedControl
|
|
23
23
|
*/
|
|
24
24
|
export function SegmentedControl(_a) {
|
|
25
|
-
var { defaultValue, size = 'm', className, onChange, items, value, outline, width = WIDTH.Auto } = _a, other = __rest(_a, ["defaultValue", "size", "className", "onChange", "items", "value", "outline", "width"]);
|
|
25
|
+
var { defaultValue, size = 'm', className, onChange, items, value, outline, width = WIDTH.Auto, name } = _a, other = __rest(_a, ["defaultValue", "size", "className", "onChange", "items", "value", "outline", "width", "name"]);
|
|
26
26
|
const [selected, setSelected] = useUncontrolledProp(value, defaultValue, onChange);
|
|
27
27
|
const { focusableSegmentValue, onGetFocusable, onKeyDown } = useFocusControl({ selected, items });
|
|
28
28
|
const containerRef = useRef(null);
|
|
@@ -60,5 +60,5 @@ export function SegmentedControl(_a) {
|
|
|
60
60
|
const itemsJSX = useMemo(() => items.map(props => (_jsx("div", { className: styles.segmentHolder, "data-width": width, children: _jsx(Segment, Object.assign({}, props, { size: size, onGetFocusable: onGetFocusable, selected: selected === props.value, onClick: () => setSelected(props.value), focusable: focusableSegmentValue === props.value, onSelectionUpdated: updateSelectionPosition })) }, props.value))), [items, width, size, onGetFocusable, selected, focusableSegmentValue, updateSelectionPosition, setSelected]);
|
|
61
61
|
return (
|
|
62
62
|
// eslint-disable-next-line jsx-a11y/interactive-supports-focus
|
|
63
|
-
_jsxs("div", Object.assign({ ref: containerRef, "data-size": size, onKeyDown: onKeyDown, className: cn(styles.container, className), role: 'radiogroup', "data-outline": outline || undefined, "data-width": width }, extractDataTestProps(other), extractSupportProps(other), { children: [_jsx("div", { "data-size": size, style: selectionPosition, className: styles.selection, "aria-hidden": true }), itemsJSX] })));
|
|
63
|
+
_jsxs("div", Object.assign({ ref: containerRef, "data-size": size, onKeyDown: onKeyDown, className: cn(styles.container, className), role: 'radiogroup', "data-outline": outline || undefined, "data-width": width }, extractDataTestProps(other), extractSupportProps(other), { children: [name && _jsx("input", { type: 'hidden', value: selected, name: name }), _jsx("div", { "data-size": size, style: selectionPosition, className: styles.selection, "aria-hidden": true }), itemsJSX] })));
|
|
64
64
|
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Segmented Control",
|
|
7
|
-
"version": "0.4.
|
|
7
|
+
"version": "0.4.20-preview-2b94e286.0",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"classnames": "2.5.1",
|
|
42
42
|
"uncontrollable": "8.0.4"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "c4c169513a2393af7ce64c9bdbca39a5d284faf4"
|
|
45
45
|
}
|
|
@@ -43,6 +43,10 @@ export type SegmentedControlProps<Value extends IdType = IdType> = WithSupportPr
|
|
|
43
43
|
* Управление шириной компонента.
|
|
44
44
|
*/
|
|
45
45
|
width?: Width;
|
|
46
|
+
/**
|
|
47
|
+
* Имя поля
|
|
48
|
+
*/
|
|
49
|
+
name?: string;
|
|
46
50
|
}>;
|
|
47
51
|
|
|
48
52
|
/**
|
|
@@ -57,6 +61,7 @@ export function SegmentedControl<Value extends IdType>({
|
|
|
57
61
|
value,
|
|
58
62
|
outline,
|
|
59
63
|
width = WIDTH.Auto,
|
|
64
|
+
name,
|
|
60
65
|
...other
|
|
61
66
|
}: SegmentedControlProps<Value>) {
|
|
62
67
|
const [selected, setSelected] = useUncontrolledProp(value, defaultValue, onChange);
|
|
@@ -129,6 +134,7 @@ export function SegmentedControl<Value extends IdType>({
|
|
|
129
134
|
{...extractDataTestProps(other)}
|
|
130
135
|
{...extractSupportProps(other)}
|
|
131
136
|
>
|
|
137
|
+
{name && <input type='hidden' value={selected} name={name} />}
|
|
132
138
|
<div data-size={size} style={selectionPosition} className={styles.selection} aria-hidden={true} />
|
|
133
139
|
{itemsJSX}
|
|
134
140
|
</div>
|