@s-ui/react-atom-checkbox
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -44,10 +44,25 @@ import cx from 'classnames'; | ||
}; | ||
export var getIcon = function getIcon(_ref5, _ref6) { | ||
var isNative = _ref5.isNative, | ||
checked = _ref5.checked, | ||
indeterminate = _ref5.indeterminate; | ||
var CheckedIcon = _ref6.CheckedIcon, | ||
UncheckedIcon = _ref6.UncheckedIcon, | ||
IndeterminateIcon = _ref6.IndeterminateIcon, | ||
Icon = _ref6.Icon; | ||
export var getReadOnly = function getReadOnly(_ref5) { | ||
var readOnly = _ref5.readOnly, | ||
disabled = _ref5.disabled, | ||
isNative = _ref5.isNative; | ||
if (disabled) return {};else if (readOnly && isNative) { | ||
return { | ||
readOnly: true | ||
}; | ||
} else if (!isNative) { | ||
return { | ||
readOnly: true | ||
}; | ||
} | ||
return {}; | ||
}; | ||
export var getIcon = function getIcon(_ref6, _ref7) { | ||
var isNative = _ref6.isNative, | ||
checked = _ref6.checked, | ||
indeterminate = _ref6.indeterminate; | ||
var CheckedIcon = _ref7.CheckedIcon, | ||
UncheckedIcon = _ref7.UncheckedIcon, | ||
IndeterminateIcon = _ref7.IndeterminateIcon, | ||
Icon = _ref7.Icon; | ||
@@ -70,7 +85,7 @@ if (isNative) { | ||
}; | ||
export var updateStatus = function updateStatus(element, _ref7) { | ||
var _ref7$isIndeterminate = _ref7.isIndeterminate, | ||
isIndeterminate = _ref7$isIndeterminate === void 0 ? false : _ref7$isIndeterminate, | ||
_ref7$isChecked = _ref7.isChecked, | ||
isChecked = _ref7$isChecked === void 0 ? false : _ref7$isChecked; | ||
export var updateStatus = function updateStatus(element, _ref8) { | ||
var _ref8$isIndeterminate = _ref8.isIndeterminate, | ||
isIndeterminate = _ref8$isIndeterminate === void 0 ? false : _ref8$isIndeterminate, | ||
_ref8$isChecked = _ref8.isChecked, | ||
isChecked = _ref8$isChecked === void 0 ? false : _ref8$isChecked; | ||
@@ -77,0 +92,0 @@ if (!element) { |
import _extends from "@babel/runtime/helpers/esm/extends"; | ||
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose"; | ||
var _excluded = ["defaultChecked", "checked", "checkedIcon", "uncheckedIcon", "disabled", "id", "defaultIndeterminate", "indeterminate", "indeterminateIcon", "icon", "name", "onChange", "status", "size", "value"]; | ||
var _excluded = ["defaultChecked", "checked", "checkedIcon", "uncheckedIcon", "disabled", "readOnly", "id", "defaultIndeterminate", "indeterminate", "indeterminateIcon", "icon", "name", "onChange", "status", "size", "value"]; | ||
import { forwardRef, useRef } from 'react'; | ||
@@ -10,3 +10,3 @@ import cx from 'classnames'; | ||
import CheckboxIcon from './CheckboxIcon.js'; | ||
import { BASE_CLASS, CHECKBOX_SIZES, CHECKBOX_STATUS, getIcon, getIsNative, isFunction, pressedValue, updateStatus } from './config.js'; | ||
import { BASE_CLASS, CHECKBOX_SIZES, CHECKBOX_STATUS, getIcon, getIsNative, getReadOnly, isFunction, pressedValue, updateStatus } from './config.js'; | ||
import { jsx as _jsx } from "react/jsx-runtime"; | ||
@@ -21,2 +21,3 @@ import { jsxs as _jsxs } from "react/jsx-runtime"; | ||
disabled = _ref.disabled, | ||
readOnlyProp = _ref.readOnly, | ||
id = _ref.id, | ||
@@ -64,2 +65,7 @@ _ref$defaultIndetermi = _ref.defaultIndeterminate, | ||
}); | ||
var readOnlyAttributes = getReadOnly({ | ||
readOnly: readOnlyProp, | ||
disabled: disabled, | ||
isNative: isNative | ||
}); | ||
var Icon = getIcon({ | ||
@@ -82,6 +88,18 @@ isNative: isNative, | ||
_value = _event$target.value; | ||
var newChecked = isControlled ? checked : event.target.checked; | ||
var newIndeterminate = isControlled ? indeterminate : event.target.indeterminate; | ||
setChecked(newChecked); | ||
setIndeterminate(newIndeterminate); | ||
var newChecked = isControlled ? indeterminate || !checked : event.target.checked; | ||
var newIndeterminate = false; | ||
if (!isControlled) { | ||
setChecked(newChecked); | ||
setIndeterminate(newIndeterminate); | ||
} | ||
if (readOnlyProp) { | ||
newChecked = checked; | ||
newIndeterminate = indeterminate; | ||
setChecked(checked); | ||
setIndeterminate(indeterminate); | ||
event.target.indeterminate = indeterminate; | ||
} | ||
isFunction(onChangeFromProps) && onChangeFromProps(event, { | ||
@@ -104,14 +122,23 @@ name: _name, | ||
if (!disabled) { | ||
var _event$target2 = event.target, | ||
_name2 = _event$target2.name, | ||
_value2 = _event$target2.value; | ||
var newChecked = isControlled ? checked : !checked; | ||
var newIndetermiante = isControlled ? indeterminate : false; | ||
setChecked(newChecked); | ||
setIndeterminate(false); | ||
var newChecked = indeterminate || !checked; | ||
var newIndeterminate = false; | ||
if (!isControlled) { | ||
setChecked(newChecked); | ||
setIndeterminate(newIndeterminate); | ||
} | ||
if (readOnlyProp) { | ||
newChecked = checked; | ||
newIndeterminate = indeterminate; | ||
setChecked(checked); | ||
setIndeterminate(indeterminate); | ||
event.target.indeterminate = indeterminate; | ||
} | ||
isFunction(onChangeFromProps) && onChangeFromProps(event, { | ||
name: _name2, | ||
value: _value2, | ||
name: name, | ||
value: value, | ||
checked: newChecked, | ||
indeterminate: newIndetermiante | ||
indeterminate: newIndeterminate | ||
}); | ||
@@ -131,3 +158,4 @@ ref.current.focus(); | ||
value: value, | ||
disabled: disabled, | ||
disabled: disabled | ||
}, readOnlyAttributes, { | ||
checked: checked | ||
@@ -145,4 +173,2 @@ }, Object.values(CHECKBOX_STATUS).includes(status) && { | ||
onChange: handleChange(inputRef) | ||
}, !isNative && { | ||
readOnly: true | ||
}, props)), /*#__PURE__*/_jsx(CheckboxIcon, { | ||
@@ -149,0 +175,0 @@ disabled: disabled, |
{ | ||
"name": "@s-ui/react-atom-checkbox", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
25042
298
0