Files
cosmos-explorer/src/Explorer/Controls/CollapsiblePanel/CollapsibleSectionComponent.tsx
Hardikkumar Nai 23223cfb23 Upgrade Fluent UI v8 (#688)
Co-authored-by: Steve Faulkner <southpolesteve@gmail.com>
2021-05-05 18:26:03 -05:00

51 lines
1.3 KiB
TypeScript

import { Icon, Label, Stack } from "@fluentui/react";
import * as React from "react";
import { accordionStackTokens } from "../Settings/SettingsRenderUtils";
export interface CollapsibleSectionProps {
title: string;
isExpandedByDefault: boolean;
onExpand?: () => void;
}
export interface CollapsibleSectionState {
isExpanded: boolean;
}
export class CollapsibleSectionComponent extends React.Component<CollapsibleSectionProps, CollapsibleSectionState> {
constructor(props: CollapsibleSectionProps) {
super(props);
this.state = {
isExpanded: this.props.isExpandedByDefault,
};
}
private toggleCollapsed = (): void => {
this.setState({ isExpanded: !this.state.isExpanded });
};
public componentDidUpdate(): void {
if (this.state.isExpanded && this.props.onExpand) {
this.props.onExpand();
}
}
public render(): JSX.Element {
return (
<>
<Stack
className="collapsibleSection"
horizontal
verticalAlign="center"
tokens={accordionStackTokens}
onClick={this.toggleCollapsed}
>
<Icon iconName={this.state.isExpanded ? "ChevronDown" : "ChevronRight"} />
<Label>{this.props.title}</Label>
</Stack>
{this.state.isExpanded && this.props.children}
</>
);
}
}