1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React, { useEffect } from "react";
6 import { WithStyles, withStyles, ButtonBase, StyleRulesCallback, Theme, Popover, Card, Tooltip, IconButton } from "@material-ui/core";
7 import classnames from "classnames";
8 import { DefaultTransformOrigin } from "components/popover/helpers";
9 import debounce from "lodash/debounce";
10 import { grey } from "@material-ui/core/colors";
11 import { TCheckedList } from "components/data-table/data-table";
13 export type CssRules = "root" | "icon" | "iconButton" | "disabled" | "optionsContainer" | "option";
15 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
19 backgroundColor: grey[200],
22 color: theme.palette.text.primary,
30 color: theme.palette.text.primary,
35 color: theme.palette.text.primary,
54 backgroundColor: "rgba(0, 0, 0, 0.08)",
59 export type DataTableMultiselectOption = {
61 fn: (checkedList) => void;
64 export interface DataTableMultiselectProps {
67 options: DataTableMultiselectOption[];
68 checkedList: TCheckedList;
71 interface DataTableFMultiselectPopState {
72 anchorEl?: HTMLElement;
75 export const DataTableMultiselectPopover = withStyles(styles)(
76 class extends React.Component<DataTableMultiselectProps & WithStyles<CssRules>, DataTableFMultiselectPopState> {
77 state: DataTableFMultiselectPopState = {
80 icon = React.createRef<HTMLElement>();
83 const { classes, children, options, checkedList, disabled } = this.props;
88 title="Select Options"
91 className={classnames(classes.root)}
93 onClick={disabled ? () => {} : this.open}
99 classes={{ root: classes.iconButton }}
103 className={`${classnames(["fas fa-sort-down", classes.icon])}${disabled ? ` ${classes.disabled}` : ""}`}
104 data-fa-transform="shrink-3"
111 anchorEl={this.state.anchorEl}
112 open={!!this.state.anchorEl}
113 anchorOrigin={DefaultTransformOrigin}
114 transformOrigin={DefaultTransformOrigin}
118 <div className={classes.optionsContainer}>
120 options.map((option, i) => (
123 className={classes.option}
125 option.fn(checkedList);
140 this.setState({ anchorEl: this.icon.current || undefined });
144 this.setState(prev => ({