| 1 |
import { useState } from 'react'; |
| 2 |
import { ExpandableSection, Badge, Stack, StackItem } from '@patternfly/react-core'; |
| 3 |
import RhUiCheckCircleFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-check-circle-fill-icon'; |
| 4 |
|
| 5 |
export const ExpandableSectionCustomToggle: React.FunctionComponent = () => { |
| 6 |
const [isExpanded, setIsExpanded] = useState(false); |
| 7 |
|
| 8 |
const onToggle = (_event: React.MouseEvent, isExpanded: boolean) => { |
| 9 |
setIsExpanded(isExpanded); |
| 10 |
}; |
| 11 |
|
| 12 |
return ( |
| 13 |
<Stack hasGutter> |
| 14 |
<StackItem> |
| 15 |
<h3>Custom Toggle Content</h3> |
| 16 |
<p>You can use custom content such as icons and badges in the toggle:</p> |
| 17 |
<ExpandableSection |
| 18 |
toggleContent={ |
| 19 |
<div> |
| 20 |
<span>You can also use icons </span> |
| 21 |
<RhUiCheckCircleFillIcon /> |
| 22 |
<span> or badges </span> |
| 23 |
<Badge isRead={true}>4</Badge> |
| 24 |
<span> !</span> |
| 25 |
</div> |
| 26 |
} |
| 27 |
onToggle={onToggle} |
| 28 |
isExpanded={isExpanded} |
| 29 |
> |
| 30 |
This content is visible only when the component is expanded. |
| 31 |
</ExpandableSection> |
| 32 |
</StackItem> |
| 33 |
|
| 34 |
<StackItem> |
| 35 |
<h3>Accessibility Note</h3> |
| 36 |
<p> |
| 37 |
<strong>Important:</strong> If you need the toggle text to function as a heading in the document structure, do |
| 38 |
NOT put heading elements (h1-h6) inside the <code>toggleContent</code> prop, as this creates invalid HTML |
| 39 |
structure. Instead, use the <code>toggleWrapper</code> prop. |
| 40 |
</p> |
| 41 |
</StackItem> |
| 42 |
</Stack> |
| 43 |
); |
| 44 |
}; |