Debian Codegraph @

node/@patternfly/react-core/src/components/Form/FormFieldGroupExpandable.tsx

raw
1 import { useState } from 'react';
2 import { InternalFormFieldGroup } from './InternalFormFieldGroup';
3 import { useHasAnimations } from '../../helpers';
4
5 export interface FormFieldGroupExpandableProps extends Omit<React.HTMLProps<HTMLDivElement>, 'onToggle'> {
6 /** Anything that can be rendered as form field group content. */
7 children?: React.ReactNode;
8 /** Additional classes added to the form field group. */
9 className?: string;
10 /** Form field group header */
11 header?: React.ReactNode;
12 /** Flag indicating if the form field group is initially expanded */
13 isExpanded?: boolean;
14 /** Aria-label to use on the form field group toggle button */
15 toggleAriaLabel?: string;
16 /** Flag indicating whether an expandable form field group has animations. This will always render
17 * nested field group content rather than dynamically rendering them. This prop will be removed in
18 * the next breaking change release in favor of defaulting to always-rendered items.
19 */
20 hasAnimations?: boolean;
21 }
22
23 export const FormFieldGroupExpandable: React.FunctionComponent<FormFieldGroupExpandableProps> = ({
24 children,
25 className,
26 header,
27 isExpanded = false,
28 toggleAriaLabel,
29 hasAnimations: hasAnimationsProp,
30 ...props
31 }: FormFieldGroupExpandableProps) => {
32 const [localIsExpanded, setIsExpanded] = useState(isExpanded);
33 const hasAnimations = useHasAnimations(hasAnimationsProp);
34
35 return (
36 <InternalFormFieldGroup
37 className={className}
38 header={header}
39 isExpandable
40 isExpanded={localIsExpanded}
41 toggleAriaLabel={toggleAriaLabel}
42 onToggle={() => setIsExpanded(!localIsExpanded)}
43 hasAnimations={hasAnimations}
44 {...props}
45 >
46 {children}
47 </InternalFormFieldGroup>
48 );
49 };
50 FormFieldGroupExpandable.displayName = 'FormFieldGroupExpandable';