From 60f5f60cd19047741ccd594e5177e8572909c9b5 Mon Sep 17 00:00:00 2001 From: Masoud Amjadi Date: Thu, 14 Sep 2023 14:13:52 -0400 Subject: [PATCH] refactor(inputcheckbox): refactor the code and clean up (#600) --- package.json | 2 +- .../__snapshots__/index.test.tsx.snap | 8 +- .../src/core/InputCheckbox/index.stories.tsx | 41 +++++---- .../src/core/InputCheckbox/index.tsx | 86 ++++++------------- 4 files changed, 51 insertions(+), 86 deletions(-) diff --git a/package.json b/package.json index f1a17a2d7..8eec7f77a 100644 --- a/package.json +++ b/package.json @@ -111,7 +111,7 @@ "test-storybook": "test-storybook", "storybook:axe": "yarn build-storybook && yarn storybook:axeOnly", "storybook:axeOnly": "axe-storybook --build-dir docs-build", - "test": "lerna run test", + "test": "lerna run test -- --detectOpenHandles", "test:updateSnapshots": "lerna run test -- -u", "namespace-check": "lerna run namespace-check", "prepare": "husky install", diff --git a/packages/components/src/core/InputCheckbox/__snapshots__/index.test.tsx.snap b/packages/components/src/core/InputCheckbox/__snapshots__/index.test.tsx.snap index 23b35bd91..944137490 100644 --- a/packages/components/src/core/InputCheckbox/__snapshots__/index.test.tsx.snap +++ b/packages/components/src/core/InputCheckbox/__snapshots__/index.test.tsx.snap @@ -3,20 +3,16 @@ exports[` Default story renders snapshot 1`] = `
- +
@@ -144,7 +143,7 @@ const LivePreviewDemo = (): JSX.Element => { export const LivePreview = { parameters: { - controls: { exclude: ["caption", "label"] }, + controls: { exclude: ["caption", "label", "stage"] }, snapshot: { skip: true, }, @@ -174,7 +173,7 @@ const TestDemo = (): JSX.Element => { />
- +
); @@ -185,7 +184,7 @@ export const Test = { id: testId, }, parameters: { - controls: { exclude: ["caption", "label", "id"] }, + controls: { exclude: ["caption", "label", "id", "stage"] }, snapshot: { skip: true, }, diff --git a/packages/components/src/core/InputCheckbox/index.tsx b/packages/components/src/core/InputCheckbox/index.tsx index 011dd261e..bc640127a 100644 --- a/packages/components/src/core/InputCheckbox/index.tsx +++ b/packages/components/src/core/InputCheckbox/index.tsx @@ -34,60 +34,32 @@ const InputCheckbox = (props: CheckboxProps): JSX.Element => { const { caption, checkboxProps, disabled, label, stage, value, ...rest } = props; - if (label === undefined || stage !== undefined) { - let newProps: MUICheckboxProps; - switch (stage) { - case "checked": - newProps = { - ...props, - checked: true, - color: "primary", - }; - break; - case "unchecked": - newProps = { - ...props, - checked: false, - color: "default", - }; - break; - case "indeterminate": - newProps = { - ...props, - checked: true, - color: "primary", - indeterminate: true, - }; - break; - default: - newProps = props; - } - return ( - - } - icon={ - - } - indeterminateIcon={ - - } - /> - ); + let newProps: MUICheckboxProps; + switch (stage) { + case "checked": + newProps = { + ...rest, + checked: true, + color: "primary", + }; + break; + case "unchecked": + newProps = { + ...rest, + checked: false, + color: "default", + }; + break; + case "indeterminate": + newProps = { + ...rest, + checked: true, + color: "primary", + indeterminate: true, + }; + break; + default: + newProps = rest; } return ( @@ -118,14 +90,12 @@ const InputCheckbox = (props: CheckboxProps): JSX.Element => { /> } {...checkboxProps} - {...rest} + {...newProps} /> } label={label} value={value} - > -
Content
- + /> ); };