x-ui-design 0.6.98 → 0.6.99

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.
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import { SwitchProps } from '../../types/switch';
3
3
  import './index.css';
4
4
  declare const Switch: {
5
- ({ prefixCls, prefixClsV3, checked, onChange, onClick, disabled, className, style, defaultChecked, value }: SwitchProps): React.JSX.Element;
5
+ ({ prefixCls, prefixClsV3, checked, onChange, onClick, disabled, className, style, defaultChecked, value, controlled }: SwitchProps): React.JSX.Element;
6
6
  displayName: string;
7
7
  };
8
8
  export default Switch;
@@ -15,4 +15,5 @@ export type SwitchProps = DefaultProps & {
15
15
  required?: boolean;
16
16
  defaultChecked?: boolean;
17
17
  checked?: boolean;
18
+ controlled?: boolean;
18
19
  };
package/dist/index.d.ts CHANGED
@@ -101,6 +101,7 @@ type SwitchProps = DefaultProps & {
101
101
  required?: boolean;
102
102
  defaultChecked?: boolean;
103
103
  checked?: boolean;
104
+ controlled?: boolean;
104
105
  };
105
106
 
106
107
  declare const Button: react.ComponentType<__types_button.ButtonProps>;
package/dist/index.esm.js CHANGED
@@ -1632,7 +1632,8 @@ const Switch = ({
1632
1632
  className = '',
1633
1633
  style = {},
1634
1634
  defaultChecked,
1635
- value
1635
+ value,
1636
+ controlled = false
1636
1637
  }) => {
1637
1638
  const isChecked = checked !== undefined ? checked : defaultChecked || value;
1638
1639
  const [internalChecked, setInternalChecked] = useState(isChecked);
@@ -1641,8 +1642,12 @@ const Switch = ({
1641
1642
  if (disabled) {
1642
1643
  return;
1643
1644
  }
1644
- setInternalChecked(!internalChecked);
1645
- e.target.value = !internalChecked;
1645
+ if (!controlled) {
1646
+ setInternalChecked(!internalChecked);
1647
+ e.target.value = !internalChecked;
1648
+ } else {
1649
+ e.target.value = !checked;
1650
+ }
1646
1651
  onClick?.(e.target.value);
1647
1652
  onChange?.(e.target.value);
1648
1653
  };