import classNames from "classnames"; import * as React from "react"; import * as Classes from "../../common/classes"; import { Elevation } from "../../common/elevation"; import { DISPLAYNAME_PREFIX, HTMLDivProps, IProps } from "../../common/props"; export interface IPanelProps extends IProps, HTMLDivProps { /** * Controls the intensity of the drop shadow beneath the panel: the higher * the elevation, the higher the drop shadow. At elevation `0`, no drop * shadow is applied. * * @default 0 */ elevation?: Elevation; /** * Whether the panel should respond to user interactions. If set to `true`, * hovering over the panel will increase the panel's elevation * and change the mouse cursor to a pointer. * * Recommended when `onClick` is also defined. * * @default false */ interactive?: boolean; /** * Header props */ headerProps?: IProps & HTMLDivProps; /** * Header element */ header?: React.ReactNode; /** * Callback invoked when the panel is clicked. * Recommended when `interactive` is `true`. */ onClick?: (e: React.MouseEvent) => void; } export class Panel extends React.PureComponent { public static displayName = `${DISPLAYNAME_PREFIX}.Panel`; public static defaultProps: IPanelProps = { elevation: Elevation.ZERO, interactive: false, }; public render() { const { className, elevation, interactive, children, header, headerProps, ...htmlProps } = this.props; const { className: headerClassName, ...htmHeaderProps } = headerProps || { className: null }; const classes = classNames( Classes.PANEL, { [Classes.INTERACTIVE]: interactive }, Classes.elevationClass(elevation), className, ); const classesHeader = classNames( Classes.PANEL_HEADER, headerClassName, ); return (
{header &&
{header}
} {children}
); } }