-
Notifications
You must be signed in to change notification settings - Fork 381
Expand file tree
/
Copy pathToolbarContent.tsx
More file actions
137 lines (131 loc) · 4.99 KB
/
ToolbarContent.tsx
File metadata and controls
137 lines (131 loc) · 4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import { Component, createRef } from 'react';
import styles from '@patternfly/react-styles/css/components/Toolbar/toolbar';
import { css } from '@patternfly/react-styles';
import { ToolbarContentContext, ToolbarContext } from './ToolbarUtils';
import { formatBreakpointMods } from '../../helpers/util';
import { PageContext } from '../Page/PageContext';
export interface ToolbarContentProps extends React.HTMLProps<HTMLDivElement> {
/** Classes applied to root element of the data toolbar content row */
className?: string;
/** Visibility at various width breakpoints. */
visibility?: {
default?: 'hidden' | 'visible';
md?: 'hidden' | 'visible';
lg?: 'hidden' | 'visible';
xl?: 'hidden' | 'visible';
'2xl'?: 'hidden' | 'visible';
};
/** Visibility at various height breakpoints. */
visibilityAtHeight?: {
default?: 'hidden' | 'visible';
md?: 'hidden' | 'visible';
lg?: 'hidden' | 'visible';
xl?: 'hidden' | 'visible';
'2xl'?: 'hidden' | 'visible';
};
/** Value to set for content wrapping at various breakpoints */
rowWrap?: {
default?: 'wrap' | 'nowrap';
sm?: 'wrap' | 'nowrap';
md?: 'wrap' | 'nowrap';
lg?: 'wrap' | 'nowrap';
xl?: 'wrap' | 'nowrap';
'2xl'?: 'wrap' | 'nowrap';
};
/** Vertical alignment of children */
alignItems?: 'start' | 'center' | 'baseline' | 'default';
/** Content to be rendered as children of the content row */
children?: React.ReactNode;
/** Flag indicating if a data toolbar toggle group's expandable content is expanded */
isExpanded?: boolean;
/** Optional callback for clearing all filters in the toolbar */
clearAllFilters?: () => void;
/** Flag indicating that the clear all filters button should be visible */
showClearFiltersButton?: boolean;
/** Text to display in the clear all filters button */
clearFiltersButtonText?: string;
/** Id of the parent Toolbar component */
toolbarId?: string;
}
class ToolbarContent extends Component<ToolbarContentProps> {
static displayName = 'ToolbarContent';
private expandableContentRef = createRef<HTMLDivElement>();
private labelContainerRef = createRef<HTMLDivElement>();
private static currentId = 0;
static defaultProps: ToolbarContentProps = {
isExpanded: false,
showClearFiltersButton: false
};
render() {
const {
className,
children,
isExpanded,
toolbarId,
visibility,
visibilityAtHeight,
rowWrap,
alignItems,
clearAllFilters,
showClearFiltersButton,
clearFiltersButtonText,
...props
} = this.props;
return (
<PageContext.Consumer>
{({ width, getBreakpoint, height, getVerticalBreakpoint }) => (
<div
className={css(
styles.toolbarContent,
formatBreakpointMods(visibility, styles, '', getBreakpoint(width)),
formatBreakpointMods(visibilityAtHeight, styles, '', getVerticalBreakpoint(height), true),
className
)}
ref={this.expandableContentRef}
{...props}
>
<ToolbarContext.Consumer>
{({
clearAllFilters: clearAllFiltersContext,
clearFiltersButtonText: clearFiltersButtonContext,
showClearFiltersButton: showClearFiltersButtonContext,
isExpanded: isExpandedContext,
toolbarId: toolbarIdContext
}) => {
const expandableContentId = `${
toolbarId || toolbarIdContext
}-expandable-content-${ToolbarContent.currentId++}`;
return (
<ToolbarContentContext.Provider
value={{
expandableContentRef: this.expandableContentRef,
expandableContentId,
labelContainerRef: this.labelContainerRef,
isExpanded: isExpanded || isExpandedContext,
clearAllFilters: clearAllFilters || clearAllFiltersContext,
clearFiltersButtonText: clearFiltersButtonText || clearFiltersButtonContext,
showClearFiltersButton: showClearFiltersButton || showClearFiltersButtonContext
}}
>
<div
className={css(
styles.toolbarContentSection,
formatBreakpointMods(rowWrap, styles, '', getBreakpoint(width)),
alignItems === 'center' && styles.modifiers.alignItemsCenter,
alignItems === 'start' && styles.modifiers.alignItemsStart,
alignItems === 'baseline' && styles.modifiers.alignItemsBaseline
)}
>
{children}
</div>
</ToolbarContentContext.Provider>
);
}}
</ToolbarContext.Consumer>
</div>
)}
</PageContext.Consumer>
);
}
}
export { ToolbarContent };