Skip to content

chore(card): add ability to hide radio button in example #11832

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,63 +1,81 @@
import { useState } from 'react';
import { Card, CardHeader, CardTitle, CardBody, Gallery } from '@patternfly/react-core';
import { Card, CardHeader, CardTitle, CardBody, Gallery, Checkbox } from '@patternfly/react-core';

export const SingleSelectableCard: React.FunctionComponent = () => {
const [isChecked, setIsChecked] = useState('');
const id1 = 'single-selectable-card-input-1';
const id2 = 'single-selectable-card-input-2';
const id3 = 'single-selectable-card-input-3';
const [displayRadioButton, setDisplayRadioButton] = useState<boolean>(false);

const onChange = (event: React.FormEvent<HTMLInputElement>) => {
setIsChecked(event.currentTarget.id);
};

const toggleHide = (checked: boolean) => {
setDisplayRadioButton(checked);
};

return (
<Gallery hasGutter>
<Card id="single-selectable-card-example-1" isSelectable isSelected={isChecked === id1}>
<CardHeader
selectableActions={{
selectableActionId: id1,
selectableActionAriaLabelledby: 'single-selectable-card-example-1',
name: 'single-selectable-card-example',
variant: 'single',
onChange,
hasNoOffset: true
}}
>
<CardTitle>First card</CardTitle>
</CardHeader>
<CardBody>This card is single selectable.</CardBody>
</Card>
<Card id="single-selectable-card-example-2" isSelectable isSelected={isChecked === id2}>
<CardHeader
selectableActions={{
selectableActionId: id2,
selectableActionAriaLabelledby: 'single-selectable-card-example-2',
name: 'single-selectable-card-example',
variant: 'single',
onChange,
hasNoOffset: true
}}
>
<CardTitle>Second card</CardTitle>
</CardHeader>
<CardBody>This card is single selectable.</CardBody>
</Card>
<Card id="single-selectable-card-example-3" isSelectable isDisabled isSelected={isChecked === id3}>
<CardHeader
selectableActions={{
selectableActionId: id3,
selectableActionAriaLabelledby: 'single-selectable-card-example-3',
name: 'single-selectable-card-example',
variant: 'single',
onChange,
hasNoOffset: true
}}
>
<CardTitle>Third card</CardTitle>
</CardHeader>
<CardBody>This card is single selectable but disabled.</CardBody>
</Card>
</Gallery>
<>
<Checkbox
label="Hide radio button"
isChecked={displayRadioButton}
onChange={(_event, checked) => toggleHide(checked)}
id="toggle-hide-radio-button"
name="toggle-hide"
/>
<div style={{ marginTop: '15px' }}></div>
<Gallery hasGutter>
<Card id="single-selectable-card-example-1" isSelectable isSelected={isChecked === id1}>
<CardHeader
selectableActions={{
selectableActionId: id1,
selectableActionAriaLabelledby: 'single-selectable-card-example-1',
name: 'single-selectable-card-example',
variant: 'single',
onChange,
hasNoOffset: true,
isHidden: displayRadioButton
}}
>
<CardTitle>First card</CardTitle>
</CardHeader>
<CardBody>This card is single selectable.</CardBody>
</Card>
<Card id="single-selectable-card-example-2" isSelectable isSelected={isChecked === id2}>
<CardHeader
selectableActions={{
selectableActionId: id2,
selectableActionAriaLabelledby: 'single-selectable-card-example-2',
name: 'single-selectable-card-example',
variant: 'single',
onChange,
hasNoOffset: true,
isHidden: displayRadioButton
}}
>
<CardTitle>Second card</CardTitle>
</CardHeader>
<CardBody>This card is single selectable.</CardBody>
</Card>
<Card id="single-selectable-card-example-3" isSelectable isDisabled isSelected={isChecked === id3}>
<CardHeader
selectableActions={{
selectableActionId: id3,
selectableActionAriaLabelledby: 'single-selectable-card-example-3',
name: 'single-selectable-card-example',
variant: 'single',
onChange,
hasNoOffset: true,
isHidden: displayRadioButton
}}
>
<CardTitle>Third card</CardTitle>
</CardHeader>
<CardBody>This card is single selectable but disabled.</CardBody>
</Card>
</Gallery>
</>
);
};
Loading