@chakra-ui/counter
Advanced tools
Comparing version 1.0.9 to 1.1.0
# Change Log | ||
## 1.1.0 | ||
### Minor Changes | ||
- [`f9b1a2a9b`](https://github.com/chakra-ui/chakra-ui/commit/f9b1a2a9b82abddbfeff510afd52cf127b765818) | ||
Thanks [@segunadebayo](https://github.com/segunadebayo)! - Expose setvalue | ||
function to allow update state without onchange | ||
### Patch Changes | ||
- [`428593906`](https://github.com/chakra-ui/chakra-ui/commit/428593906ca3f3423a2e1bc25241169d1bf4de81) | ||
[#3664](https://github.com/chakra-ui/chakra-ui/pull/3664) Thanks | ||
[@segunadebayo](https://github.com/segunadebayo)! - Fix issue where onChange | ||
is called when value did not change | ||
- Updated dependencies | ||
[[`623e782e8`](https://github.com/chakra-ui/chakra-ui/commit/623e782e80124297740a109e5c6c58cddc35b2eb), | ||
[`a58b724e9`](https://github.com/chakra-ui/chakra-ui/commit/a58b724e9c8656044f866b658f378662f2a44b46), | ||
[`b724a9dd9`](https://github.com/chakra-ui/chakra-ui/commit/b724a9dd9429d02c0b2c7f7deac66d3553100bdc)]: | ||
- @chakra-ui/hooks@1.3.0 | ||
- @chakra-ui/utils@1.5.0 | ||
## 1.0.9 | ||
@@ -4,0 +26,0 @@ |
@@ -30,6 +30,9 @@ "use strict"; | ||
keepWithinRange = _props$keepWithinRang === void 0 ? true : _props$keepWithinRang; | ||
var onChangeProp = (0, _hooks.useCallbackRef)(onChange); | ||
var _useState = (0, _react.useState)(function () { | ||
var _cast; | ||
if (defaultValue == null) return ""; | ||
return cast(defaultValue, stepProp, precisionProp); | ||
return (_cast = cast(defaultValue, stepProp, precisionProp)) != null ? _cast : ""; | ||
}), | ||
@@ -51,2 +54,4 @@ valueState = _useState[0], | ||
var update = (0, _react.useCallback)(function (next) { | ||
if (next === value) return; | ||
if (!isControlled) { | ||
@@ -56,4 +61,4 @@ setValue(next.toString()); | ||
onChange == null ? void 0 : onChange(next.toString(), parse(next)); | ||
}, [onChange, isControlled]); // Function to clamp the value and round it to the precision | ||
onChangeProp == null ? void 0 : onChangeProp(next.toString(), parse(next)); | ||
}, [onChangeProp, isControlled, value]); // Function to clamp the value and round it to the precision | ||
@@ -115,10 +120,15 @@ var clamp = (0, _react.useCallback)(function (value) { | ||
} else { | ||
next = cast(defaultValue, stepProp, precisionProp); | ||
var _cast2; | ||
next = (_cast2 = cast(defaultValue, stepProp, precisionProp)) != null ? _cast2 : min; | ||
} | ||
update(next); | ||
}, [defaultValue, precisionProp, stepProp, update]); | ||
}, [defaultValue, precisionProp, stepProp, update, min]); | ||
var castValue = (0, _react.useCallback)(function (value) { | ||
update(cast(value, stepProp, precision)); | ||
}, [precision, stepProp, update]); | ||
var _cast3; | ||
var nextValue = (_cast3 = cast(value, stepProp, precision)) != null ? _cast3 : min; | ||
update(nextValue); | ||
}, [precision, stepProp, update, min]); | ||
var valueAsNumber = parse(value); | ||
@@ -144,3 +154,4 @@ /** | ||
clamp: clamp, | ||
cast: castValue | ||
cast: castValue, | ||
setValue: setValue | ||
}; | ||
@@ -158,5 +169,7 @@ } | ||
function cast(value, step, precision) { | ||
var decimalPlaces = getDecimalPlaces(parse(value), step); | ||
return (0, _utils.toPrecision)(parse(value), precision != null ? precision : decimalPlaces); | ||
var parsedValue = parse(value); | ||
if (Number.isNaN(parsedValue)) return undefined; | ||
var decimalPlaces = getDecimalPlaces(parsedValue, step); | ||
return (0, _utils.toPrecision)(parsedValue, precision != null ? precision : decimalPlaces); | ||
} | ||
//# sourceMappingURL=use-counter.js.map |
@@ -1,3 +0,3 @@ | ||
import { useControllableProp } from "@chakra-ui/hooks"; | ||
import { countDecimalPlaces, clampValue, maxSafeInteger, minSafeInteger, toPrecision } from "@chakra-ui/utils"; | ||
import { useCallbackRef, useControllableProp } from "@chakra-ui/hooks"; | ||
import { clampValue, countDecimalPlaces, maxSafeInteger, minSafeInteger, toPrecision } from "@chakra-ui/utils"; | ||
import { useCallback, useState } from "react"; | ||
@@ -19,5 +19,8 @@ export function useCounter(props) { | ||
} = props; | ||
var onChangeProp = useCallbackRef(onChange); | ||
var [valueState, setValue] = useState(() => { | ||
var _cast; | ||
if (defaultValue == null) return ""; | ||
return cast(defaultValue, stepProp, precisionProp); | ||
return (_cast = cast(defaultValue, stepProp, precisionProp)) != null ? _cast : ""; | ||
}); | ||
@@ -33,2 +36,4 @@ /** | ||
var update = useCallback(next => { | ||
if (next === value) return; | ||
if (!isControlled) { | ||
@@ -38,4 +43,4 @@ setValue(next.toString()); | ||
onChange == null ? void 0 : onChange(next.toString(), parse(next)); | ||
}, [onChange, isControlled]); // Function to clamp the value and round it to the precision | ||
onChangeProp == null ? void 0 : onChangeProp(next.toString(), parse(next)); | ||
}, [onChangeProp, isControlled, value]); // Function to clamp the value and round it to the precision | ||
@@ -97,10 +102,15 @@ var clamp = useCallback(value => { | ||
} else { | ||
next = cast(defaultValue, stepProp, precisionProp); | ||
var _cast2; | ||
next = (_cast2 = cast(defaultValue, stepProp, precisionProp)) != null ? _cast2 : min; | ||
} | ||
update(next); | ||
}, [defaultValue, precisionProp, stepProp, update]); | ||
}, [defaultValue, precisionProp, stepProp, update, min]); | ||
var castValue = useCallback(value => { | ||
update(cast(value, stepProp, precision)); | ||
}, [precision, stepProp, update]); | ||
var _cast3; | ||
var nextValue = (_cast3 = cast(value, stepProp, precision)) != null ? _cast3 : min; | ||
update(nextValue); | ||
}, [precision, stepProp, update, min]); | ||
var valueAsNumber = parse(value); | ||
@@ -126,3 +136,4 @@ /** | ||
clamp, | ||
cast: castValue | ||
cast: castValue, | ||
setValue | ||
}; | ||
@@ -140,5 +151,7 @@ } | ||
function cast(value, step, precision) { | ||
var decimalPlaces = getDecimalPlaces(parse(value), step); | ||
return toPrecision(parse(value), precision != null ? precision : decimalPlaces); | ||
var parsedValue = parse(value); | ||
if (Number.isNaN(parsedValue)) return undefined; | ||
var decimalPlaces = getDecimalPlaces(parsedValue, step); | ||
return toPrecision(parsedValue, precision != null ? precision : decimalPlaces); | ||
} | ||
//# sourceMappingURL=use-counter.js.map |
export * from "./use-counter"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -0,1 +1,2 @@ | ||
/// <reference types="react" /> | ||
import { StringOrNumber } from "@chakra-ui/utils"; | ||
@@ -59,3 +60,5 @@ export interface UseCounterProps { | ||
cast: (value: StringOrNumber) => void; | ||
setValue: import("react").Dispatch<import("react").SetStateAction<StringOrNumber>>; | ||
}; | ||
export declare type UseCounterReturn = ReturnType<typeof useCounter>; | ||
//# sourceMappingURL=use-counter.d.ts.map |
{ | ||
"name": "@chakra-ui/counter", | ||
"version": "1.0.9", | ||
"version": "1.1.0", | ||
"description": "A React hook for managing counters", | ||
@@ -58,4 +58,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@chakra-ui/hooks": "1.2.0", | ||
"@chakra-ui/utils": "1.4.0" | ||
"@chakra-ui/hooks": "1.3.0", | ||
"@chakra-ui/utils": "1.5.0" | ||
}, | ||
@@ -62,0 +62,0 @@ "peerDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44476
15
338
+ Added@chakra-ui/hooks@1.3.0(transitive)
+ Added@chakra-ui/react-utils@1.1.0(transitive)
+ Added@chakra-ui/utils@1.5.0(transitive)
+ Addedreact-dom@18.3.1(transitive)
+ Addedscheduler@0.23.2(transitive)
- Removed@chakra-ui/hooks@1.2.0(transitive)
- Removed@chakra-ui/utils@1.4.0(transitive)
- Removed@types/object-assign@4.0.30(transitive)
Updated@chakra-ui/hooks@1.3.0
Updated@chakra-ui/utils@1.5.0