-
Notifications
You must be signed in to change notification settings - Fork 368
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this will depend on Erin's response to my general review comment above, but if we do want to update the "Selectable" example as well to include this "hide input" logic, I think we could remove these empty divs and instead either apply a margin to the checkbox or gallery, or try wrapping everything in a Flex layout and utilizing gap. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RE "do you think we should also update the "Selectable" example to match with a checkbox that can hide the Card inputs?" yes, I do! Would be good to match, I actually thought it was already there 😅 |
||
<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> | ||
</> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit verbose, but just to ensure it's unique