Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UX-779 Add helpText prop to RadioCard.Group and CheckboxCard.Group #1069

Merged
merged 1 commit into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions libby/form/CheckboxCard.lib.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ describe('CheckboxCard', () => {
</CheckboxCard.Group>
));

add('help text', () => (
<CheckboxCard.Group label="Radio Card Group" helpText="Help Text">
<CheckboxCard id="id1" label="Check Me 1" name="group" defaultChecked>
I am help text
</CheckboxCard>
<CheckboxCard id="id2" label="Check Me 2" name="group">
I am help text
</CheckboxCard>
<CheckboxCard id="id3" label="Check Me 3" name="group">
I am help text
</CheckboxCard>
</CheckboxCard.Group>
));

add('works with system props', () => (
<CheckboxCard.Group label="Radio Card Group" my="500" mx="700">
<CheckboxCard id="id1" label="Check Me 1" name="group" defaultChecked>
Expand Down
14 changes: 14 additions & 0 deletions libby/form/RadioCard.lib.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ describe('RadioCard', () => {
</RadioCard.Group>
));

add('help text', () => (
<RadioCard.Group label="Radio Card Group" helpText="Help Text">
<RadioCard id="id1" label="Check Me 1" name="group" defaultChecked>
I am help text
</RadioCard>
<RadioCard id="id2" label="Check Me 2" name="group">
I am help text
</RadioCard>
<RadioCard id="id3" label="Check Me 3" name="group">
I am help text
</RadioCard>
</RadioCard.Group>
));

add('group with optional label', () => (
<RadioCard.Group label="Radio Card Group" optional>
<RadioCard id="id1" label="Check Me 1" name="group" defaultChecked>
Expand Down
2 changes: 1 addition & 1 deletion libby/regression/CheckboxCard.lib.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('Visual Regression', () => {
<>
<CheckboxCard id="id1" label="Check Me" data-track="true" />
{/* Disabled */}
<CheckboxCard.Group label="Radio Card Group">
<CheckboxCard.Group label="Radio Card Group" helpText="Help">
<CheckboxCard id="id1" label="Check Me 1" disabled>
This one is disabled
</CheckboxCard>
Expand Down
2 changes: 1 addition & 1 deletion libby/regression/RadioCard.lib.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('Visual Regression', () => {
<>
<RadioCard id="id1" label="Check Me" data-track="true" />
{/* Disabled */}
<RadioCard.Group label="Radio Card Group">
<RadioCard.Group label="Radio Card Group" helpText="Help">
<RadioCard id="id1" label="Check Me 1" disabled>
This one is disabled
</RadioCard>
Expand Down
8 changes: 8 additions & 0 deletions packages/matchbox/src/components/CheckboxCard/Group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Columns } from '../Columns';
import { Column } from '../Column';
import { Label } from '../Label';
import { OptionalLabel } from '../OptionalLabel';
import { HelpText } from '../HelpText';
import { Stack } from '../Stack';
import { Breakpoints } from '../../helpers/types';
import { pick } from '../../helpers/props';
Expand Down Expand Up @@ -39,6 +40,7 @@ export type CheckboxCardGroupProps = {
children?: React.ReactNode;
collapseBelow?: Breakpoints;
'data-id'?: string;
helpText?: React.ReactNode;
label: string;
labelHidden?: boolean;
optional?: boolean;
Expand All @@ -54,6 +56,7 @@ const Group = React.forwardRef<HTMLFieldSetElement, CheckboxCardGroupProps>(func
const {
children,
collapseBelow,
helpText,
id,
label,
labelHidden,
Expand All @@ -74,6 +77,11 @@ const Group = React.forwardRef<HTMLFieldSetElement, CheckboxCardGroupProps>(func
</Box>
{optional && <OptionalLabel />}
</Label>
{helpText && (
<Box mb="200">
<HelpText mt="0">{helpText}</HelpText>
</Box>
)}

{orientation === 'horizontal' && (
<Columns space="300" collapseBelow={collapseBelow}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,14 @@ describe('CheckboxCard', () => {
expect(wrapper.find('#test-id')).toExist();
expect(wrapper.find('#test-id-2')).toExist();
});

it('renders helpText', () => {
const { getByText } = render(
<CheckboxCard.Group label="label" helpText="help">
<CheckboxCard id="test-id" />
</CheckboxCard.Group>,
);
expect(getByText('help')).toBeTruthy();
});
});
});
8 changes: 8 additions & 0 deletions packages/matchbox/src/components/RadioCard/Group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Columns } from '../Columns';
import { Column } from '../Column';
import { Label } from '../Label';
import { OptionalLabel } from '../OptionalLabel';
import { HelpText } from '../HelpText';
import { Stack } from '../Stack';
import { Breakpoints } from '../../helpers/types';

Expand Down Expand Up @@ -42,6 +43,7 @@ export type RadioCardGroupProps = {
children?: React.ReactNode;
collapseBelow?: Breakpoints;
'data-id'?: string;
helpText?: React.ReactNode;
label: string;
labelHidden?: boolean;
optional?: boolean;
Expand All @@ -57,6 +59,7 @@ const Group = React.forwardRef<HTMLFieldSetElement, RadioCardGroupProps>(functio
const {
children,
collapseBelow,
helpText,
id,
label,
labelHidden,
Expand All @@ -77,6 +80,11 @@ const Group = React.forwardRef<HTMLFieldSetElement, RadioCardGroupProps>(functio
</Box>
{optional && <OptionalLabel />}
</Label>
{helpText && (
<Box mb="200">
<HelpText mt="0">{helpText}</HelpText>
</Box>
)}

{orientation === 'horizontal' && (
<Columns space="300" collapseBelow={collapseBelow}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,14 @@ describe('RadioCard', () => {
expect(wrapper.find('#test-id')).toExist();
expect(wrapper.find('#test-id-2')).toExist();
});

it('renders helpText', () => {
const { getByText } = render(
<RadioCard.Group label="label" helpText="help">
<RadioCard id="test-id" />
</RadioCard.Group>,
);
expect(getByText('help')).toBeTruthy();
});
});
});