@festo-ui/react 7.0.0-dev.368 → 7.0.0-dev.371
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.
|
@@ -4,10 +4,11 @@ export interface SwitchProps extends ClassNameProps {
|
|
|
4
4
|
labelPosition?: 'before' | 'after' | 'below';
|
|
5
5
|
large?: boolean;
|
|
6
6
|
title: string;
|
|
7
|
-
value
|
|
7
|
+
value?: boolean;
|
|
8
|
+
defaultValue?: boolean;
|
|
8
9
|
disabled?: boolean;
|
|
9
10
|
onChange?: (value: boolean) => void;
|
|
10
11
|
id?: string;
|
|
11
12
|
}
|
|
12
|
-
declare function Switch({ labelPosition, large, title, value, disabled, onChange, className, id: idProps, }: SwitchProps): JSX.Element;
|
|
13
|
+
declare function Switch({ labelPosition, large, title, value, defaultValue, disabled, onChange, className, id: idProps, }: SwitchProps): JSX.Element;
|
|
13
14
|
export default Switch;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useState, useEffect } from 'react';
|
|
2
1
|
import classNames from 'classnames';
|
|
2
|
+
import useControlled from '../../helper/useControlled';
|
|
3
3
|
import useId from '../../helper/useId';
|
|
4
4
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
5
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -9,6 +9,7 @@ function Switch(_ref) {
|
|
|
9
9
|
large = false,
|
|
10
10
|
title,
|
|
11
11
|
value,
|
|
12
|
+
defaultValue,
|
|
12
13
|
disabled = false,
|
|
13
14
|
onChange,
|
|
14
15
|
className,
|
|
@@ -20,10 +21,10 @@ function Switch(_ref) {
|
|
|
20
21
|
}, {
|
|
21
22
|
'fwe-switch-lg': large
|
|
22
23
|
}, className);
|
|
23
|
-
const [currentValue, setCurrentValue] =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
24
|
+
const [currentValue, setCurrentValue] = useControlled({
|
|
25
|
+
controlled: value,
|
|
26
|
+
default: defaultValue
|
|
27
|
+
});
|
|
27
28
|
const handleChange = () => {
|
|
28
29
|
const newValue = !currentValue;
|
|
29
30
|
setCurrentValue(newValue);
|
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _react = require("react");
|
|
8
7
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
8
|
+
var _useControlled = _interopRequireDefault(require("../../helper/useControlled"));
|
|
9
9
|
var _useId = _interopRequireDefault(require("../../helper/useId"));
|
|
10
10
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -15,6 +15,7 @@ function Switch(_ref) {
|
|
|
15
15
|
large = false,
|
|
16
16
|
title,
|
|
17
17
|
value,
|
|
18
|
+
defaultValue,
|
|
18
19
|
disabled = false,
|
|
19
20
|
onChange,
|
|
20
21
|
className,
|
|
@@ -26,10 +27,10 @@ function Switch(_ref) {
|
|
|
26
27
|
}, {
|
|
27
28
|
'fwe-switch-lg': large
|
|
28
29
|
}, className);
|
|
29
|
-
const [currentValue, setCurrentValue] = (0,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
30
|
+
const [currentValue, setCurrentValue] = (0, _useControlled.default)({
|
|
31
|
+
controlled: value,
|
|
32
|
+
default: defaultValue
|
|
33
|
+
});
|
|
33
34
|
const handleChange = () => {
|
|
34
35
|
const newValue = !currentValue;
|
|
35
36
|
setCurrentValue(newValue);
|