@festo-ui/react
Advanced tools
Comparing version 7.0.0-dev.368 to 7.0.0-dev.370
@@ -55,2 +55,3 @@ import classNames from 'classnames'; | ||
disabled: disabled, | ||
required: required, | ||
onChange: e => handleChange(e), | ||
@@ -57,0 +58,0 @@ ...props, |
@@ -7,3 +7,4 @@ /// <reference types="react" /> | ||
title: string; | ||
value: boolean; | ||
value?: boolean; | ||
defaultValue?: boolean; | ||
disabled?: boolean; | ||
@@ -13,3 +14,3 @@ onChange?: (value: boolean) => void; | ||
} | ||
declare function Switch({ labelPosition, large, title, value, disabled, onChange, className, id: idProps, }: SwitchProps): JSX.Element; | ||
declare function Switch({ labelPosition, large, title, value, defaultValue, disabled, onChange, className, id: idProps, }: SwitchProps): JSX.Element; | ||
export default Switch; |
@@ -1,3 +0,3 @@ | ||
import { useState, useEffect } from 'react'; | ||
import classNames from 'classnames'; | ||
import useControlled from '../../helper/useControlled'; | ||
import useId from '../../helper/useId'; | ||
@@ -12,2 +12,3 @@ import { jsx as _jsx } from "react/jsx-runtime"; | ||
value, | ||
defaultValue, | ||
disabled = false, | ||
@@ -24,6 +25,6 @@ onChange, | ||
}, className); | ||
const [currentValue, setCurrentValue] = useState(value); | ||
useEffect(() => { | ||
setCurrentValue(value); | ||
}, [value]); | ||
const [currentValue, setCurrentValue] = useControlled({ | ||
controlled: value, | ||
default: defaultValue | ||
}); | ||
const handleChange = () => { | ||
@@ -30,0 +31,0 @@ const newValue = !currentValue; |
@@ -61,2 +61,3 @@ "use strict"; | ||
disabled: disabled, | ||
required: required, | ||
onChange: e => handleChange(e), | ||
@@ -63,0 +64,0 @@ ...props, |
@@ -7,4 +7,4 @@ "use strict"; | ||
exports.default = void 0; | ||
var _react = require("react"); | ||
var _classnames = _interopRequireDefault(require("classnames")); | ||
var _useControlled = _interopRequireDefault(require("../../helper/useControlled")); | ||
var _useId = _interopRequireDefault(require("../../helper/useId")); | ||
@@ -19,2 +19,3 @@ var _jsxRuntime = require("react/jsx-runtime"); | ||
value, | ||
defaultValue, | ||
disabled = false, | ||
@@ -31,6 +32,6 @@ onChange, | ||
}, className); | ||
const [currentValue, setCurrentValue] = (0, _react.useState)(value); | ||
(0, _react.useEffect)(() => { | ||
setCurrentValue(value); | ||
}, [value]); | ||
const [currentValue, setCurrentValue] = (0, _useControlled.default)({ | ||
controlled: value, | ||
default: defaultValue | ||
}); | ||
const handleChange = () => { | ||
@@ -37,0 +38,0 @@ const newValue = !currentValue; |
{ | ||
"name": "@festo-ui/react", | ||
"version": "7.0.0-dev.368", | ||
"version": "7.0.0-dev.370", | ||
"author": "Festo UI (styleguide@festo.com)", | ||
@@ -5,0 +5,0 @@ "license": "apache-2.0", |
527943
13695