diff --git a/core/components/atoms/selectionCard/SelectionCard.tsx b/core/components/atoms/selectionCard/SelectionCard.tsx index 3228cb3e99..a1fb7b469a 100644 --- a/core/components/atoms/selectionCard/SelectionCard.tsx +++ b/core/components/atoms/selectionCard/SelectionCard.tsx @@ -42,19 +42,23 @@ export const SelectionCard = (props: SelectionCardProps) => { const classes = classNames( { ['Selection-card']: true, - ['Selection-card--selected']: selected, - ['Selection-card--disabled']: disabled && !selected, + ['Selection-card--default']: !disabled, + ['Selection-card--selected']: selected && !disabled, + ['Selection-card--disabled']: disabled, + ['Selection-card--default-disabled']: disabled && !selected, ['Selection-card--selected-disabled']: disabled && selected, }, className ); const onClickHandler = (event: ClickEventType) => { - onClick && onClick(event, id, cardValue); + if (!disabled && onClick) { + onClick(event, id, cardValue); + } }; const onKeyDownHandler = (event: React.KeyboardEvent) => { - if (event.key === 'Enter') { + if (event.key === 'Enter' && !disabled) { onClickHandler(event); } }; @@ -63,7 +67,7 @@ export const SelectionCard = (props: SelectionCardProps) => {
onClickHandler(event)} className={classes} diff --git a/core/components/atoms/selectionCard/__stories__/index.story.jsx b/core/components/atoms/selectionCard/__stories__/index.story.jsx index 85e1ef0f8a..45632e5f7d 100644 --- a/core/components/atoms/selectionCard/__stories__/index.story.jsx +++ b/core/components/atoms/selectionCard/__stories__/index.story.jsx @@ -39,7 +39,7 @@ export const all = () => { @@ -47,7 +47,9 @@ export const all = () => {
{title}
- {description} + + {description} +
@@ -93,7 +95,7 @@ const customCode = `() => { @@ -101,7 +103,7 @@ const customCode = `() => {
{title}
- {description} + {description}
diff --git a/core/components/atoms/selectionCard/__stories__/layout.story.jsx b/core/components/atoms/selectionCard/__stories__/layout.story.jsx index 9accce6791..020c9b6ce2 100644 --- a/core/components/atoms/selectionCard/__stories__/layout.story.jsx +++ b/core/components/atoms/selectionCard/__stories__/layout.story.jsx @@ -6,12 +6,14 @@ export const layout = () => { return (
Left Content Alignment: - +
Manual drop on SFTP disk
- Give access to a separate SFTP disk image + + Give access to a separate SFTP disk image +
diff --git a/core/components/atoms/selectionCard/__stories__/multiSelect.story.jsx b/core/components/atoms/selectionCard/__stories__/multiSelect.story.jsx index c56e45327d..dd6c9a82bc 100644 --- a/core/components/atoms/selectionCard/__stories__/multiSelect.story.jsx +++ b/core/components/atoms/selectionCard/__stories__/multiSelect.story.jsx @@ -51,7 +51,7 @@ export const multiSelect = () => { @@ -59,7 +59,9 @@ export const multiSelect = () => {
{title}
- {description} + + {description} +
@@ -117,7 +119,7 @@ const customCode = `() => { @@ -125,7 +127,7 @@ const customCode = `() => {
{title}
- {description} + {description}
diff --git a/core/components/atoms/selectionCard/__stories__/singleSelect.story.jsx b/core/components/atoms/selectionCard/__stories__/singleSelect.story.jsx index 37c9e45f1e..336194ee93 100644 --- a/core/components/atoms/selectionCard/__stories__/singleSelect.story.jsx +++ b/core/components/atoms/selectionCard/__stories__/singleSelect.story.jsx @@ -51,7 +51,7 @@ export const singleSelect = () => { @@ -59,7 +59,9 @@ export const singleSelect = () => {
{title}
- {description} + + {description} +
@@ -117,7 +119,7 @@ const customCode = `() => { @@ -125,7 +127,7 @@ const customCode = `() => {
{title}
- {description} + {description}
diff --git a/core/components/atoms/selectionCard/__stories__/state.story.jsx b/core/components/atoms/selectionCard/__stories__/state.story.jsx new file mode 100644 index 0000000000..3c8d9a2d87 --- /dev/null +++ b/core/components/atoms/selectionCard/__stories__/state.story.jsx @@ -0,0 +1,76 @@ +import * as React from 'react'; +import { SelectionCard, Row, Column, Icon, Text } from '@/index'; + +// CSF format story + +export const state = () => { + const cardConfigs = [ + { label: 'Default:', props: {} }, + { label: 'Disabled:', props: { disabled: true } }, + { label: 'Selected:', props: { selected: true } }, + { label: 'Selected and disabled:', props: { disabled: true, selected: true } }, + ]; + + return ( + + {cardConfigs.map((config, index) => ( + + {config.label} + + +
+ Manual drop on SFTP disk +
+ + Give access to a separate SFTP disk image + +
+
+
+ ))} +
+ ); +}; + +const customCode = `() => { + const cardConfigs = [ + { label: 'Default:', props: {} }, + { label: 'Disabled:', props: { disabled: true } }, + { label: 'Selected:', props: { selected: true } }, + { label: 'Selected and disabled:', props: { disabled: true, selected: true } }, + ]; + + return ( + + {cardConfigs.map((config, index) => ( + + {config.label} + + +
+ Manual drop on SFTP disk +
+ + Give access to a separate SFTP disk image + +
+
+
+ ))} +
+ ); +}`; + +export default { + title: 'Components/Interactive Card/Selection Card/State', + component: SelectionCard, + parameters: { + docs: { + docPage: { + title: 'SelectionCard', + propDescription: `Note: All the valid properties of HTML DIV elements are acceptable as a prop`, + customCode, + }, + }, + }, +}; diff --git a/core/components/atoms/selectionCard/__tests__/SelectionCard.test.tsx b/core/components/atoms/selectionCard/__tests__/SelectionCard.test.tsx index ef1b341292..68d3735b97 100644 --- a/core/components/atoms/selectionCard/__tests__/SelectionCard.test.tsx +++ b/core/components/atoms/selectionCard/__tests__/SelectionCard.test.tsx @@ -31,6 +31,16 @@ const SingleSelect = () => { > Single Selection Item 2
+ + updateCardSelection('item3')} + selected={isCardSelected('item3')} + > + Single Selection Item 3 +
); }; @@ -49,6 +59,7 @@ const MultiSelect = () => { > Multi Selection + { > Multi Selection + + updateCardSelection('item3')} + selected={isCardSelected('item3')} + > + Single Selection Item 3 +
); }; @@ -88,6 +109,7 @@ describe('selection card component tests', () => { const element = getByTestId('DesignSystem-SelectionCard'); expect(element).toBeInTheDocument(); expect(element).toHaveClass('Selection-card'); + expect(element).toHaveClass('Selection-card--default'); expect(element).toHaveTextContent(StringValue); }); }); @@ -120,6 +142,7 @@ describe('selection card disabled item component tests', () => { ); const element = getByTestId('DesignSystem-SelectionCard'); expect(element).toHaveClass('Selection-card--disabled'); + expect(element).toHaveClass('Selection-card--default-disabled'); }); it('check for disabled class for selected item', () => { @@ -129,8 +152,20 @@ describe('selection card disabled item component tests', () => { ); const element = getByTestId('DesignSystem-SelectionCard'); + expect(element).toHaveClass('Selection-card--disabled'); expect(element).toHaveClass('Selection-card--selected-disabled'); }); + + it('check for onClick event for disabled item', () => { + const { getByTestId } = render( + + {StringValue} + + ); + const element = getByTestId('DesignSystem-SelectionCard'); + fireEvent.click(element); + expect(FunctionValue).not.toHaveBeenCalled(); + }); }); describe('selection card component classes', () => { @@ -181,6 +216,12 @@ describe('selection card component hooks test', () => { fireEvent.click(element2); expect(element2).not.toHaveClass('Selection-card--selected'); + const element3 = getByTestId('Selection-card-3'); + fireEvent.click(element2); + + fireEvent.click(element3); + expect(element3).not.toHaveClass('Selection-card--selected'); + expect(element2).toHaveClass('Selection-card--selected'); }); it('test for multi select hook', () => { @@ -195,5 +236,11 @@ describe('selection card component hooks test', () => { fireEvent.click(element1); expect(element1).not.toHaveClass('Selection-card--selected'); + + const element3 = getByTestId('Selection-card-3'); + fireEvent.click(element3); + expect(element3).not.toHaveClass('Selection-card--selected'); + + expect(element2).toHaveClass('Selection-card--selected'); }); }); diff --git a/core/components/atoms/selectionCard/__tests__/__snapshots__/SelectionCard.test.tsx.snap b/core/components/atoms/selectionCard/__tests__/__snapshots__/SelectionCard.test.tsx.snap index 65117bda4d..81a51035b4 100644 --- a/core/components/atoms/selectionCard/__tests__/__snapshots__/SelectionCard.test.tsx.snap +++ b/core/components/atoms/selectionCard/__tests__/__snapshots__/SelectionCard.test.tsx.snap @@ -6,7 +6,7 @@ exports[`selection card item component snapshot