package.src.components.Toolbar.ToolbarExpandableContent.tsx Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of react-core Show documentation
Show all versions of react-core Show documentation
This library provides a set of common React components for use with the PatternFly reference implementation.
The newest version!
import * as React from 'react';
import styles from '@patternfly/react-styles/css/components/Toolbar/toolbar';
import { css } from '@patternfly/react-styles';
import { RefObject } from 'react';
import { ToolbarGroup } from './ToolbarGroup';
import { ToolbarItem } from './ToolbarItem';
import { Button } from '../Button';
import { ToolbarContext } from './ToolbarUtils';
import { PickOptional } from '../../helpers/typeUtils';
export interface ToolbarExpandableContentProps extends React.HTMLProps {
/** Classes added to the root element of the data toolbar expandable content */
className?: string;
/** Flag indicating the expandable content is expanded */
isExpanded?: boolean;
/** Expandable content reference for passing to data toolbar children */
expandableContentRef?: RefObject;
/** Chip container reference for passing to data toolbar children */
chipContainerRef?: RefObject;
/** optional callback for clearing all filters in the toolbar */
clearAllFilters?: () => void;
/** Text to display in the clear all filters button */
clearFiltersButtonText?: string;
/** Flag indicating that the clear all filters button should be visible */
showClearFiltersButton: boolean;
}
class ToolbarExpandableContent extends React.Component {
static displayName = 'ToolbarExpandableContent';
static contextType = ToolbarContext;
context!: React.ContextType;
static defaultProps: PickOptional = {
isExpanded: false,
clearFiltersButtonText: 'Clear all filters'
};
render() {
const {
children,
className,
expandableContentRef,
chipContainerRef,
isExpanded,
clearAllFilters,
clearFiltersButtonText,
showClearFiltersButton,
...props
} = this.props;
const { numberOfFilters, customChipGroupContent } = this.context;
const clearChipGroups = () => {
clearAllFilters();
};
return (
{children}
{numberOfFilters > 0 && (
{showClearFiltersButton && !customChipGroupContent && (
)}
{customChipGroupContent && customChipGroupContent}
)}
);
}
}
export { ToolbarExpandableContent };