@cloud-ru/ds-toggles 1.0.1-preview-fb311860.0 → 1.0.1-preview-cd0cd6fb.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 CHANGED
@@ -213,6 +213,9 @@ export function RadioStates() {
213
213
 
214
214
  #### Size
215
215
  `xs` — для плотных настроек и таблиц, `s` — дефолт в формах и карточках.
216
+
217
+ #### Icon (default `false`)
218
+ По умолчанию ползунок — пустой круг. `showIcon` добавляет галочку в состоянии «включено». Спиннер состояния `loading` показывается независимо от `showIcon`.
216
219
  ### Примеры использования
217
220
  #### 1. Базовый Switch
218
221
 
@@ -276,6 +279,7 @@ export function SwitchStates() {
276
279
  | `onChange` | `((checked: boolean) => void)` | — | Колбек смены значения |
277
280
  | `onClick` | `MouseEventHandler<HTMLInputElement>` | — | Колбек клика |
278
281
  | `onFocus` | `FocusEventHandler<HTMLInputElement>` | — | Колбек приобретения фокуса |
282
+ | `showIcon` | `boolean` | `false` | Показывать ли иконку внутри ползунка. Спиннер в состоянии `loading` показывается независимо |
279
283
  | `size` | `"s"` \| `"xs"` | `s` | Размер |
280
284
  | `tabIndex` | `number` | — | HTML-аттрибут tab-index |
281
285
  | `value` | `string` | — | HTML-аттрибут value |
@@ -1,3 +1,6 @@
1
1
  import { ToggleProps } from '../../types';
2
- export type SwitchProps = ToggleProps;
3
- export declare function Switch({ inputRef, checked: checkedProp, defaultChecked, onChange, onBlur, onFocus, disabled, loading, size, className, 'data-test-id': dataTestId, ...otherProps }: SwitchProps): import("react/jsx-runtime").JSX.Element;
2
+ export type SwitchProps = ToggleProps & {
3
+ /** Показывать ли иконку внутри ползунка. Спиннер в состоянии `loading` показывается независимо */
4
+ showIcon?: boolean;
5
+ };
6
+ export declare function Switch({ inputRef, checked: checkedProp, defaultChecked, onChange, onBlur, onFocus, disabled, loading, showIcon, size, className, 'data-test-id': dataTestId, ...otherProps }: SwitchProps): import("react/jsx-runtime").JSX.Element;
@@ -24,7 +24,7 @@ function Icon({ size, loading }) {
24
24
  const iconSize = (0, utils_2.getIconSize)(size);
25
25
  return (0, jsx_runtime_1.jsx)(system_1.CheckSVG, { "aria-hidden": true, className: styles_module_scss_1.default.icon, size: iconSize });
26
26
  }
27
- function Switch({ inputRef, checked: checkedProp, defaultChecked, onChange, onBlur, onFocus, disabled = false, loading = false, size = constants_1.SIZE.S, className, 'data-test-id': dataTestId, ...otherProps }) {
27
+ function Switch({ inputRef, checked: checkedProp, defaultChecked, onChange, onBlur, onFocus, disabled = false, loading = false, showIcon = false, size = constants_1.SIZE.S, className, 'data-test-id': dataTestId, ...otherProps }) {
28
28
  const [checked, setChecked] = (0, utils_1.useUncontrolledProp)(checkedProp, Boolean(defaultChecked), onChange);
29
29
  const [focusVisible, setFocusVisible] = (0, react_1.useState)(false);
30
30
  const stateDataAttributes = (0, utils_2.getVisualStateAttributes)({
@@ -32,7 +32,7 @@ function Switch({ inputRef, checked: checkedProp, defaultChecked, onChange, onBl
32
32
  disabled,
33
33
  checked,
34
34
  });
35
- return ((0, jsx_runtime_1.jsx)("span", { className: (0, classnames_1.default)(styles_module_scss_1.default.root, className), role: constants_1.MODE.Checkbox, "data-size": size, ...stateDataAttributes, "data-focusvisible": focusVisible || undefined, "data-test-id": dataTestId || undefined, children: (0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.container, children: [(0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.framing, ...stateDataAttributes, children: [(0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.backgroundStateLayer, "data-state": 'emptyDarkOnAccent' }), (0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.flag, children: (0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.surface, ...stateDataAttributes, children: (0, jsx_runtime_1.jsx)(Icon, { size: size, loading: Boolean(loading) }) }) })] }), !loading && ((0, jsx_runtime_1.jsx)("input", { ...otherProps, "data-test-id": dataTestId ? `${dataTestId}${constants_1.NATIVE_INPUT_SUFFIX}` : undefined, ref: inputRef, type: constants_1.MODE.Checkbox, className: styles_module_scss_1.default.inputPrivate, checked: checked, disabled: disabled, onChange: e => setChecked(e.target.checked), onFocus: event => {
35
+ return ((0, jsx_runtime_1.jsx)("span", { className: (0, classnames_1.default)(styles_module_scss_1.default.root, className), role: constants_1.MODE.Checkbox, "data-size": size, ...stateDataAttributes, "data-focusvisible": focusVisible || undefined, "data-test-id": dataTestId || undefined, children: (0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.container, children: [(0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.framing, ...stateDataAttributes, children: [(0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.backgroundStateLayer, "data-state": 'emptyDarkOnAccent' }), (0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.flag, children: (0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.surface, ...stateDataAttributes, children: (showIcon || loading) && (0, jsx_runtime_1.jsx)(Icon, { size: size, loading: Boolean(loading) }) }) })] }), !loading && ((0, jsx_runtime_1.jsx)("input", { ...otherProps, "data-test-id": dataTestId ? `${dataTestId}${constants_1.NATIVE_INPUT_SUFFIX}` : undefined, ref: inputRef, type: constants_1.MODE.Checkbox, className: styles_module_scss_1.default.inputPrivate, checked: checked, disabled: disabled, onChange: e => setChecked(e.target.checked), onFocus: event => {
36
36
  setFocusVisible(event.target.matches(':focus-visible'));
37
37
  onFocus?.(event);
38
38
  }, onBlur: event => {
@@ -1,3 +1,6 @@
1
1
  import { ToggleProps } from '../../types.js';
2
- export type SwitchProps = ToggleProps;
3
- export declare function Switch({ inputRef, checked: checkedProp, defaultChecked, onChange, onBlur, onFocus, disabled, loading, size, className, 'data-test-id': dataTestId, ...otherProps }: SwitchProps): import("react/jsx-runtime").JSX.Element;
2
+ export type SwitchProps = ToggleProps & {
3
+ /** Показывать ли иконку внутри ползунка. Спиннер в состоянии `loading` показывается независимо */
4
+ showIcon?: boolean;
5
+ };
6
+ export declare function Switch({ inputRef, checked: checkedProp, defaultChecked, onChange, onBlur, onFocus, disabled, loading, showIcon, size, className, 'data-test-id': dataTestId, ...otherProps }: SwitchProps): import("react/jsx-runtime").JSX.Element;
@@ -18,7 +18,7 @@ function Icon({ size, loading }) {
18
18
  const iconSize = getIconSize(size);
19
19
  return _jsx(CheckSVG, { "aria-hidden": true, className: styles.icon, size: iconSize });
20
20
  }
21
- export function Switch({ inputRef, checked: checkedProp, defaultChecked, onChange, onBlur, onFocus, disabled = false, loading = false, size = SIZE.S, className, 'data-test-id': dataTestId, ...otherProps }) {
21
+ export function Switch({ inputRef, checked: checkedProp, defaultChecked, onChange, onBlur, onFocus, disabled = false, loading = false, showIcon = false, size = SIZE.S, className, 'data-test-id': dataTestId, ...otherProps }) {
22
22
  const [checked, setChecked] = useUncontrolledProp(checkedProp, Boolean(defaultChecked), onChange);
23
23
  const [focusVisible, setFocusVisible] = useState(false);
24
24
  const stateDataAttributes = getVisualStateAttributes({
@@ -26,7 +26,7 @@ export function Switch({ inputRef, checked: checkedProp, defaultChecked, onChang
26
26
  disabled,
27
27
  checked,
28
28
  });
29
- return (_jsx("span", { className: cn(styles.root, className), role: MODE.Checkbox, "data-size": size, ...stateDataAttributes, "data-focusvisible": focusVisible || undefined, "data-test-id": dataTestId || undefined, children: _jsxs("div", { className: styles.container, children: [_jsxs("div", { className: styles.framing, ...stateDataAttributes, children: [_jsx("div", { className: styles.backgroundStateLayer, "data-state": 'emptyDarkOnAccent' }), _jsx("div", { className: styles.flag, children: _jsx("div", { className: styles.surface, ...stateDataAttributes, children: _jsx(Icon, { size: size, loading: Boolean(loading) }) }) })] }), !loading && (_jsx("input", { ...otherProps, "data-test-id": dataTestId ? `${dataTestId}${NATIVE_INPUT_SUFFIX}` : undefined, ref: inputRef, type: MODE.Checkbox, className: styles.inputPrivate, checked: checked, disabled: disabled, onChange: e => setChecked(e.target.checked), onFocus: event => {
29
+ return (_jsx("span", { className: cn(styles.root, className), role: MODE.Checkbox, "data-size": size, ...stateDataAttributes, "data-focusvisible": focusVisible || undefined, "data-test-id": dataTestId || undefined, children: _jsxs("div", { className: styles.container, children: [_jsxs("div", { className: styles.framing, ...stateDataAttributes, children: [_jsx("div", { className: styles.backgroundStateLayer, "data-state": 'emptyDarkOnAccent' }), _jsx("div", { className: styles.flag, children: _jsx("div", { className: styles.surface, ...stateDataAttributes, children: (showIcon || loading) && _jsx(Icon, { size: size, loading: Boolean(loading) }) }) })] }), !loading && (_jsx("input", { ...otherProps, "data-test-id": dataTestId ? `${dataTestId}${NATIVE_INPUT_SUFFIX}` : undefined, ref: inputRef, type: MODE.Checkbox, className: styles.inputPrivate, checked: checked, disabled: disabled, onChange: e => setChecked(e.target.checked), onFocus: event => {
30
30
  setFocusVisible(event.target.matches(':focus-visible'));
31
31
  onFocus?.(event);
32
32
  }, onBlur: event => {