mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-23 02:41:39 +00:00
* Add form and validation for vector search * Add form and validation for vector search * Add unit tests and merge forms
78 lines
2.3 KiB
TypeScript
78 lines
2.3 KiB
TypeScript
import { DirectionalHint, Icon, Label, Stack, TooltipHost } from "@fluentui/react";
|
|
import * as React from "react";
|
|
import { NormalizedEventKey } from "../../../Common/Constants";
|
|
import { accordionStackTokens } from "../Settings/SettingsRenderUtils";
|
|
|
|
export interface CollapsibleSectionProps {
|
|
title: string;
|
|
isExpandedByDefault: boolean;
|
|
onExpand?: () => void;
|
|
children: JSX.Element;
|
|
tooltipContent?: string | JSX.Element | JSX.Element[];
|
|
}
|
|
|
|
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(_prevProps: CollapsibleSectionProps, prevState: CollapsibleSectionState): void {
|
|
if (!prevState.isExpanded && this.state.isExpanded && this.props.onExpand) {
|
|
this.props.onExpand();
|
|
}
|
|
}
|
|
|
|
private onKeyPress = (event: React.KeyboardEvent) => {
|
|
if (event.key === NormalizedEventKey.Space || event.key === NormalizedEventKey.Enter) {
|
|
this.toggleCollapsed();
|
|
event.stopPropagation();
|
|
}
|
|
};
|
|
|
|
public render(): JSX.Element {
|
|
return (
|
|
<>
|
|
<Stack
|
|
className={"collapsibleSection"}
|
|
horizontal
|
|
verticalAlign="center"
|
|
tokens={accordionStackTokens}
|
|
onClick={this.toggleCollapsed}
|
|
onKeyPress={this.onKeyPress}
|
|
tabIndex={0}
|
|
role="button"
|
|
aria-expanded={this.state.isExpanded}
|
|
>
|
|
<Icon iconName={this.state.isExpanded ? "ChevronDown" : "ChevronRight"} />
|
|
<Label>{this.props.title}</Label>
|
|
{this.props.tooltipContent && (
|
|
<TooltipHost
|
|
directionalHint={DirectionalHint.bottomLeftEdge}
|
|
content={this.props.tooltipContent}
|
|
styles={{
|
|
root: {
|
|
marginLeft: "0 !important",
|
|
},
|
|
}}
|
|
>
|
|
<Icon iconName="Info" className="panelInfoIcon" tabIndex={0} />
|
|
</TooltipHost>
|
|
)}
|
|
</Stack>
|
|
{this.state.isExpanded && this.props.children}
|
|
</>
|
|
);
|
|
}
|
|
}
|