1 | import { __rest } from "tslib";
|
2 | import * as React from 'react';
|
3 | import styles from '@patternfly/react-styles/css/components/OverflowMenu/overflow-menu';
|
4 | import { css } from '@patternfly/react-styles';
|
5 | import { OverflowMenuContext } from './OverflowMenuContext';
|
6 | import mdBreakpoint from '@patternfly/react-tokens/dist/esm/global_breakpoint_md';
|
7 | import lgBreakpoint from '@patternfly/react-tokens/dist/esm/global_breakpoint_lg';
|
8 | import xlBreakpoint from '@patternfly/react-tokens/dist/esm/global_breakpoint_xl';
|
9 | import xl2Breakpoint from '@patternfly/react-tokens/dist/esm/global_breakpoint_2xl';
|
10 | import { debounce, canUseDOM } from '../../helpers/util';
|
11 | const breakpoints = {
|
12 | md: mdBreakpoint,
|
13 | lg: lgBreakpoint,
|
14 | xl: xlBreakpoint,
|
15 | '2xl': xl2Breakpoint
|
16 | };
|
17 | export class OverflowMenu extends React.Component {
|
18 | constructor(props) {
|
19 | super(props);
|
20 | this.handleResize = () => {
|
21 | const breakpointPx = breakpoints[this.props.breakpoint];
|
22 | if (!breakpointPx) {
|
23 |
|
24 | console.error('OverflowMenu will not be visible without a valid breakpoint.');
|
25 | return;
|
26 | }
|
27 | const breakpointWidth = Number(breakpointPx.value.replace('px', ''));
|
28 | const isBelowBreakpoint = window.innerWidth < breakpointWidth;
|
29 | this.setState({ isBelowBreakpoint });
|
30 | };
|
31 | this.state = {
|
32 | isBelowBreakpoint: false
|
33 | };
|
34 | }
|
35 | componentDidMount() {
|
36 | this.handleResize();
|
37 | if (canUseDOM) {
|
38 | window.addEventListener('resize', debounce(this.handleResize, 250));
|
39 | }
|
40 | }
|
41 | componentWillUnmount() {
|
42 | if (canUseDOM) {
|
43 | window.removeEventListener('resize', debounce(this.handleResize, 250));
|
44 | }
|
45 | }
|
46 | render() {
|
47 |
|
48 | const _a = this.props, { className, breakpoint, children } = _a, props = __rest(_a, ["className", "breakpoint", "children"]);
|
49 | return (React.createElement("div", Object.assign({}, props, { className: css(styles.overflowMenu, className) }),
|
50 | React.createElement(OverflowMenuContext.Provider, { value: { isBelowBreakpoint: this.state.isBelowBreakpoint } }, children)));
|
51 | }
|
52 | }
|
53 | OverflowMenu.displayName = 'OverflowMenu';
|
54 | OverflowMenu.contextType = OverflowMenuContext;
|
55 |
|
\ | No newline at end of file |