@createnl/grouped-checkboxes
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -15,3 +15,7 @@ "use strict"; | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -40,11 +44,11 @@ if (k2 === undefined) k2 = k; | ||
var uuid_1 = __importDefault(require("./uuid")); | ||
var AllCheckerCheckbox = react_1.forwardRef(function (props, ref) { | ||
var AllCheckerCheckbox = (0, react_1.forwardRef)(function (props, ref) { | ||
var disabled = props.disabled, onChange = props.onChange; | ||
var id = react_1.useState(uuid_1.default())[0]; | ||
var checkboxGroup = react_1.useContext(CheckboxGroupContext_1.default); | ||
var _a = react_1.useState(false), initialized = _a[0], setInitialized = _a[1]; | ||
var _b = react_1.useState(true), shouldTriggerCheckboxContextChange = _b[0], setShouldTriggerCheckboxContextChange = _b[1]; | ||
var _c = react_1.useState(checkboxGroup.defaultChecked), isChecked = _c[0], setIsChecked = _c[1]; | ||
var _d = react_1.useState(disabled !== undefined ? disabled : checkboxGroup.defaultDisabled), isDisabled = _d[0], setIsDisabled = _d[1]; | ||
react_1.useEffect(function () { | ||
var id = (0, react_1.useState)((0, uuid_1.default)())[0]; | ||
var checkboxGroup = (0, react_1.useContext)(CheckboxGroupContext_1.default); | ||
var _a = (0, react_1.useState)(false), initialized = _a[0], setInitialized = _a[1]; | ||
var _b = (0, react_1.useState)(true), shouldTriggerCheckboxContextChange = _b[0], setShouldTriggerCheckboxContextChange = _b[1]; | ||
var _c = (0, react_1.useState)(checkboxGroup.defaultChecked), isChecked = _c[0], setIsChecked = _c[1]; | ||
var _d = (0, react_1.useState)(disabled !== undefined ? disabled : checkboxGroup.defaultDisabled), isDisabled = _d[0], setIsDisabled = _d[1]; | ||
(0, react_1.useEffect)(function () { | ||
checkboxGroup.assertIdDoesNotExist(id); | ||
@@ -55,3 +59,3 @@ return function () { | ||
}, []); | ||
react_1.useEffect(function () { | ||
(0, react_1.useEffect)(function () { | ||
checkboxGroup.allCheckerCheckboxes.set(id, { | ||
@@ -58,0 +62,0 @@ isChecked: isChecked, |
@@ -15,3 +15,7 @@ "use strict"; | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -40,10 +44,10 @@ if (k2 === undefined) k2 = k; | ||
var uuid_1 = __importDefault(require("./uuid")); | ||
var Checkbox = react_1.forwardRef(function (props, ref) { | ||
var Checkbox = (0, react_1.forwardRef)(function (props, ref) { | ||
var checked = props.checked, disabled = props.disabled, onChange = props.onChange; | ||
var id = react_1.useState(uuid_1.default())[0]; | ||
var checkboxGroup = react_1.useContext(CheckboxGroupContext_1.default); | ||
var _a = react_1.useState(true), shouldTriggerCheckboxContextChange = _a[0], setShouldTriggerCheckboxContextChange = _a[1]; | ||
var _b = react_1.useState(checked !== undefined ? checked : checkboxGroup.defaultChecked), isChecked = _b[0], setIsChecked = _b[1]; | ||
var _c = react_1.useState(disabled !== undefined ? disabled : checkboxGroup.defaultDisabled), isDisabled = _c[0], setIsDisabled = _c[1]; | ||
react_1.useEffect(function () { | ||
var id = (0, react_1.useState)((0, uuid_1.default)())[0]; | ||
var checkboxGroup = (0, react_1.useContext)(CheckboxGroupContext_1.default); | ||
var _a = (0, react_1.useState)(true), shouldTriggerCheckboxContextChange = _a[0], setShouldTriggerCheckboxContextChange = _a[1]; | ||
var _b = (0, react_1.useState)(checked !== undefined ? checked : checkboxGroup.defaultChecked), isChecked = _b[0], setIsChecked = _b[1]; | ||
var _c = (0, react_1.useState)(disabled !== undefined ? disabled : checkboxGroup.defaultDisabled), isDisabled = _c[0], setIsDisabled = _c[1]; | ||
(0, react_1.useEffect)(function () { | ||
checkboxGroup.assertIdDoesNotExist(id); | ||
@@ -55,3 +59,3 @@ return function () { | ||
}, []); | ||
react_1.useEffect(function () { | ||
(0, react_1.useEffect)(function () { | ||
if (checked !== undefined) { | ||
@@ -62,3 +66,3 @@ setShouldTriggerCheckboxContextChange(true); | ||
}, [checked, setIsChecked, setShouldTriggerCheckboxContextChange]); | ||
react_1.useEffect(function () { | ||
(0, react_1.useEffect)(function () { | ||
checkboxGroup.checkboxes.set(id, { | ||
@@ -65,0 +69,0 @@ isChecked: isChecked, |
@@ -1,2 +0,2 @@ | ||
import React, { FC } from "react"; | ||
import React, { FC, PropsWithChildren } from 'react'; | ||
export interface CheckboxChange extends React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> { | ||
@@ -11,3 +11,3 @@ checked: boolean; | ||
} | ||
declare const CheckboxGroup: FC<CheckboxGroupProps>; | ||
declare const CheckboxGroup: FC<PropsWithChildren<CheckboxGroupProps>>; | ||
export default CheckboxGroup; |
@@ -15,3 +15,7 @@ "use strict"; | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -42,6 +46,6 @@ if (k2 === undefined) k2 = k; | ||
var CheckboxGroup = function (_a) { | ||
var children = _a.children, defaultChecked = _a.defaultChecked, defaultDisabled = _a.defaultDisabled, onChange = _a.onChange; | ||
var checkboxes = react_1.useState(new Map())[0]; | ||
var allCheckerCheckboxes = react_1.useState(new Map())[0]; | ||
var noneCheckerCheckboxes = react_1.useState(new Map())[0]; | ||
var defaultChecked = _a.defaultChecked, defaultDisabled = _a.defaultDisabled, onChange = _a.onChange, children = _a.children; | ||
var checkboxes = (0, react_1.useState)(new Map())[0]; | ||
var allCheckerCheckboxes = (0, react_1.useState)(new Map())[0]; | ||
var noneCheckerCheckboxes = (0, react_1.useState)(new Map())[0]; | ||
var dispatchOnChange = function () { | ||
@@ -57,3 +61,3 @@ if (onChange === undefined) { | ||
}; | ||
var debouncedOnChange = lodash_debounce_1.default(dispatchOnChange, ON_CHANGE_DEBOUNCE_TIMEOUT); | ||
var debouncedOnChange = (0, lodash_debounce_1.default)(dispatchOnChange, ON_CHANGE_DEBOUNCE_TIMEOUT); | ||
var setAllCheckboxesChecked = function (state) { | ||
@@ -119,3 +123,3 @@ allCheckerCheckboxes.forEach(function (checkbox) { return checkbox.setIsChecked(state); }); | ||
if (hasCheckbox(subject)) { | ||
throw new Error("Duplicate id " + subject + " in CheckboxGroup"); | ||
throw new Error("Duplicate id ".concat(subject, " in CheckboxGroup")); | ||
} | ||
@@ -122,0 +126,0 @@ }; |
@@ -15,3 +15,7 @@ "use strict"; | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -40,11 +44,11 @@ if (k2 === undefined) k2 = k; | ||
var uuid_1 = __importDefault(require("./uuid")); | ||
var NoneCheckerCheckbox = react_1.forwardRef(function (props, ref) { | ||
var NoneCheckerCheckbox = (0, react_1.forwardRef)(function (props, ref) { | ||
var disabled = props.disabled, onChange = props.onChange; | ||
var id = react_1.useState(uuid_1.default())[0]; | ||
var checkboxGroup = react_1.useContext(CheckboxGroupContext_1.default); | ||
var _a = react_1.useState(false), initialized = _a[0], setInitialized = _a[1]; | ||
var _b = react_1.useState(true), shouldTriggerCheckboxContextChange = _b[0], setShouldTriggerCheckboxContextChange = _b[1]; | ||
var _c = react_1.useState(checkboxGroup.defaultChecked !== undefined ? !checkboxGroup.defaultChecked : undefined), isChecked = _c[0], setIsChecked = _c[1]; | ||
var _d = react_1.useState(disabled !== undefined ? disabled : checkboxGroup.defaultDisabled), isDisabled = _d[0], setIsDisabled = _d[1]; | ||
react_1.useEffect(function () { | ||
var id = (0, react_1.useState)((0, uuid_1.default)())[0]; | ||
var checkboxGroup = (0, react_1.useContext)(CheckboxGroupContext_1.default); | ||
var _a = (0, react_1.useState)(false), initialized = _a[0], setInitialized = _a[1]; | ||
var _b = (0, react_1.useState)(true), shouldTriggerCheckboxContextChange = _b[0], setShouldTriggerCheckboxContextChange = _b[1]; | ||
var _c = (0, react_1.useState)(checkboxGroup.defaultChecked !== undefined ? !checkboxGroup.defaultChecked : undefined), isChecked = _c[0], setIsChecked = _c[1]; | ||
var _d = (0, react_1.useState)(disabled !== undefined ? disabled : checkboxGroup.defaultDisabled), isDisabled = _d[0], setIsDisabled = _d[1]; | ||
(0, react_1.useEffect)(function () { | ||
checkboxGroup.assertIdDoesNotExist(id); | ||
@@ -55,3 +59,3 @@ return function () { | ||
}, []); | ||
react_1.useEffect(function () { | ||
(0, react_1.useEffect)(function () { | ||
checkboxGroup.noneCheckerCheckboxes.set(id, { | ||
@@ -58,0 +62,0 @@ isChecked: isChecked, |
@@ -0,4 +1,5 @@ | ||
const {defaults} = require('jest-config'); | ||
module.exports = { | ||
// Jest transformations -- this adds support for TypeScript | ||
// using ts-jest | ||
moduleFileExtensions: ['ts', 'tsx', ...defaults.moduleFileExtensions], | ||
transform: { | ||
@@ -5,0 +6,0 @@ "^.+\\.tsx?$": "ts-jest" |
{ | ||
"name": "@createnl/grouped-checkboxes", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Grouped checkboxes with check-all checkboxes", | ||
@@ -24,13 +24,15 @@ "repository": { | ||
"peerDependencies": { | ||
"react": ">=16.8.0", | ||
"react-dom": ">=16.8.0" | ||
"react": "^18.1.0", | ||
"react-dom": "^18.1.0" | ||
}, | ||
"devDependencies": { | ||
"@testing-library/react": "^10.0.4", | ||
"@types/jest": "^25.2.1", | ||
"@babel/preset-env": "^7.18.2", | ||
"@babel/preset-react": "^7.17.12", | ||
"@testing-library/react": "^13.3.0", | ||
"@types/jest": "^28.1.1", | ||
"@types/lodash.debounce": "^4.0.6", | ||
"@types/react": "^17.0.11", | ||
"@types/react-dom": "^17.0.8", | ||
"@types/react-dom": "^18.0.5", | ||
"@typescript-eslint/eslint-plugin": "^2.33.0", | ||
"@typescript-eslint/parser": "^2.33.0", | ||
"babel-jest": "^28.1.1", | ||
"eslint": "^7.0.0", | ||
@@ -42,13 +44,10 @@ "eslint-config-airbnb-typescript": "^7.2.1", | ||
"eslint-plugin-react-hooks": "^4.0.1", | ||
"jest": "^26.0.1", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2", | ||
"react-test-renderer": "^17.0.2", | ||
"ts-jest": "^25.5.1", | ||
"typescript": "^4.3.4" | ||
"jest": "^28.1.1", | ||
"jest-environment-jsdom": "^28.1.1", | ||
"react": "^18.1.0", | ||
"react-dom": "^18.1.0", | ||
"react-test-renderer": "^18.1.0", | ||
"ts-jest": "^28.0.4", | ||
"typescript": "^4.7.3" | ||
}, | ||
"jest": { | ||
"coverageDirectory": "./coverage/", | ||
"collectCoverage": true | ||
}, | ||
"dependencies": { | ||
@@ -55,0 +54,0 @@ "lodash.debounce": "^4.0.8" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
148886
45
1927
22
1