Debian Codegraph @

node/@patternfly/react-core/src/layouts/Flex/Flex.tsx

raw
1 import { css } from '@patternfly/react-styles';
2 import styles from '@patternfly/react-styles/css/layouts/Flex/flex';
3 import * as flexToken from '@patternfly/react-tokens/dist/esm/l_flex_item_Order';
4
5 import { formatBreakpointMods, setBreakpointCssVars } from '../../helpers/util';
6
7 export interface FlexProps extends React.HTMLProps<HTMLDivElement> {
8 /** content rendered inside the Flex layout */
9 children?: React.ReactNode;
10 /** additional classes added to the Flex layout */
11 className?: string;
12 /** Spacers at various breakpoints */
13 spacer?: {
14 default?:
15 | 'spacerNone'
16 | 'spacerXs'
17 | 'spacerSm'
18 | 'spacerMd'
19 | 'spacerLg'
20 | 'spacerXl'
21 | 'spacer2xl'
22 | 'spacer3xl'
23 | 'spacer4xl';
24 sm?:
25 | 'spacerNone'
26 | 'spacerXs'
27 | 'spacerSm'
28 | 'spacerMd'
29 | 'spacerLg'
30 | 'spacerXl'
31 | 'spacer2xl'
32 | 'spacer3xl'
33 | 'spacer4xl';
34 md?:
35 | 'spacerNone'
36 | 'spacerXs'
37 | 'spacerSm'
38 | 'spacerMd'
39 | 'spacerLg'
40 | 'spacerXl'
41 | 'spacer2xl'
42 | 'spacer3xl'
43 | 'spacer4xl';
44 lg?:
45 | 'spacerNone'
46 | 'spacerXs'
47 | 'spacerSm'
48 | 'spacerMd'
49 | 'spacerLg'
50 | 'spacerXl'
51 | 'spacer2xl'
52 | 'spacer3xl'
53 | 'spacer4xl';
54 xl?:
55 | 'spacerNone'
56 | 'spacerXs'
57 | 'spacerSm'
58 | 'spacerMd'
59 | 'spacerLg'
60 | 'spacerXl'
61 | 'spacer2xl'
62 | 'spacer3xl'
63 | 'spacer4xl';
64 '2xl'?:
65 | 'spacerNone'
66 | 'spacerXs'
67 | 'spacerSm'
68 | 'spacerMd'
69 | 'spacerLg'
70 | 'spacerXl'
71 | 'spacer2xl'
72 | 'spacer3xl'
73 | 'spacer4xl';
74 };
75 /** Space items at various breakpoints */
76 spaceItems?: {
77 default?:
78 | 'spaceItemsNone'
79 | 'spaceItemsXs'
80 | 'spaceItemsSm'
81 | 'spaceItemsMd'
82 | 'spaceItemsLg'
83 | 'spaceItemsXl'
84 | 'spaceItems2xl'
85 | 'spaceItems3xl'
86 | 'spaceItems4xl';
87 sm?:
88 | 'spaceItemsNone'
89 | 'spaceItemsXs'
90 | 'spaceItemsSm'
91 | 'spaceItemsMd'
92 | 'spaceItemsLg'
93 | 'spaceItemsXl'
94 | 'spaceItems2xl'
95 | 'spaceItems3xl'
96 | 'spaceItems4xl';
97 md?:
98 | 'spaceItemsNone'
99 | 'spaceItemsXs'
100 | 'spaceItemsSm'
101 | 'spaceItemsMd'
102 | 'spaceItemsLg'
103 | 'spaceItemsXl'
104 | 'spaceItems2xl'
105 | 'spaceItems3xl'
106 | 'spaceItems4xl';
107 lg?:
108 | 'spaceItemsNone'
109 | 'spaceItemsXs'
110 | 'spaceItemsSm'
111 | 'spaceItemsMd'
112 | 'spaceItemsLg'
113 | 'spaceItemsXl'
114 | 'spaceItems2xl'
115 | 'spaceItems3xl'
116 | 'spaceItems4xl';
117 xl?:
118 | 'spaceItemsNone'
119 | 'spaceItemsXs'
120 | 'spaceItemsSm'
121 | 'spaceItemsMd'
122 | 'spaceItemsLg'
123 | 'spaceItemsXl'
124 | 'spaceItems2xl'
125 | 'spaceItems3xl'
126 | 'spaceItems4xl';
127 '2xl'?:
128 | 'spaceItemsNone'
129 | 'spaceItemsXs'
130 | 'spaceItemsSm'
131 | 'spaceItemsMd'
132 | 'spaceItemsLg'
133 | 'spaceItemsXl'
134 | 'spaceItems2xl'
135 | 'spaceItems3xl'
136 | 'spaceItems4xl';
137 };
138 /** Gap between items at various breakpoints. This will override spacers for the main axis. */
139 gap?: {
140 default?: 'gap' | 'gapNone' | 'gapXs' | 'gapSm' | 'gapMd' | 'gapLg' | 'gapXl' | 'gap2xl' | 'gap3xl' | 'gap4xl';
141 sm?: 'gap' | 'gapNone' | 'gapXs' | 'gapSm' | 'gapMd' | 'gapLg' | 'gapXl' | 'gap2xl' | 'gap3xl' | 'gap4xl';
142 md?: 'gap' | 'gapNone' | 'gapXs' | 'gapSm' | 'gapMd' | 'gapLg' | 'gapXl' | 'gap2xl' | 'gap3xl' | 'gap4xl';
143 lg?: 'gap' | 'gapNone' | 'gapXs' | 'gapSm' | 'gapMd' | 'gapLg' | 'gapXl' | 'gap2xl' | 'gap3xl' | 'gap4xl';
144 xl?: 'gap' | 'gapNone' | 'gapXs' | 'gapSm' | 'gapMd' | 'gapLg' | 'gapXl' | 'gap2xl' | 'gap3xl' | 'gap4xl';
145 '2xl'?: 'gap' | 'gapNone' | 'gapXs' | 'gapSm' | 'gapMd' | 'gapLg' | 'gapXl' | 'gap2xl' | 'gap3xl' | 'gap4xl';
146 };
147 /** Gap between rows at various breakpoints. This will override spacers for the main axis. */
148 rowGap?: {
149 default?:
150 | 'rowGap'
151 | 'rowGapNone'
152 | 'rowGapXs'
153 | 'rowGapSm'
154 | 'rowGapMd'
155 | 'rowGapLg'
156 | 'rowGapXl'
157 | 'rowGap2xl'
158 | 'rowGap3xl'
159 | 'rowGap4xl';
160 sm?:
161 | 'rowGap'
162 | 'rowGapNone'
163 | 'rowGapXs'
164 | 'rowGapSm'
165 | 'rowGapMd'
166 | 'rowGapLg'
167 | 'rowGapXl'
168 | 'rowGap2xl'
169 | 'rowGap3xl'
170 | 'rowGap4xl';
171 md?:
172 | 'rowGap'
173 | 'rowGapNone'
174 | 'rowGapXs'
175 | 'rowGapSm'
176 | 'rowGapMd'
177 | 'rowGapLg'
178 | 'rowGapXl'
179 | 'rowGap2xl'
180 | 'rowGap3xl'
181 | 'rowGap4xl';
182 lg?:
183 | 'rowGap'
184 | 'rowGapNone'
185 | 'rowGapXs'
186 | 'rowGapSm'
187 | 'rowGapMd'
188 | 'rowGapLg'
189 | 'rowGapXl'
190 | 'rowGap2xl'
191 | 'rowGap3xl'
192 | 'rowGap4xl';
193 xl?:
194 | 'rowGap'
195 | 'rowGapNone'
196 | 'rowGapXs'
197 | 'rowGapSm'
198 | 'rowGapMd'
199 | 'rowGapLg'
200 | 'rowGapXl'
201 | 'rowGap2xl'
202 | 'rowGap3xl'
203 | 'rowGap4xl';
204 '2xl'?:
205 | 'rowGap'
206 | 'rowGapNone'
207 | 'rowGapXs'
208 | 'rowGapSm'
209 | 'rowGapMd'
210 | 'rowGapLg'
211 | 'rowGapXl'
212 | 'rowGap2xl'
213 | 'rowGap3xl'
214 | 'rowGap4xl';
215 };
216 /** Gap beween columns at various breakpoints. This will override spacers for the main axis. */
217 columnGap?: {
218 default?:
219 | 'columnGap'
220 | 'columnGapNone'
221 | 'columnGapXs'
222 | 'columnGapSm'
223 | 'columnGapMd'
224 | 'columnGapLg'
225 | 'columnGapXl'
226 | 'columnGap2xl'
227 | 'columnGap3xl'
228 | 'columnGap4xl';
229 sm?:
230 | 'columnGap'
231 | 'columnGapNone'
232 | 'columnGapXs'
233 | 'columnGapSm'
234 | 'columnGapMd'
235 | 'columnGapLg'
236 | 'columnGapXl'
237 | 'columnGap2xl'
238 | 'columnGap3xl'
239 | 'columnGap4xl';
240 md?:
241 | 'columnGap'
242 | 'columnGapNone'
243 | 'columnGapXs'
244 | 'columnGapSm'
245 | 'columnGapMd'
246 | 'columnGapLg'
247 | 'columnGapXl'
248 | 'columnGap2xl'
249 | 'columnGap3xl'
250 | 'columnGap4xl';
251 lg?:
252 | 'columnGap'
253 | 'columnGapNone'
254 | 'columnGapXs'
255 | 'columnGapSm'
256 | 'columnGapMd'
257 | 'columnGapLg'
258 | 'columnGapXl'
259 | 'columnGap2xl'
260 | 'columnGap3xl'
261 | 'columnGap4xl';
262 xl?:
263 | 'columnGap'
264 | 'columnGapNone'
265 | 'columnGapXs'
266 | 'columnGapSm'
267 | 'columnGapMd'
268 | 'columnGapLg'
269 | 'columnGapXl'
270 | 'columnGap2xl'
271 | 'columnGap3xl'
272 | 'columnGap4xl';
273 '2xl'?:
274 | 'columnGap'
275 | 'columnGapNone'
276 | 'columnGapXs'
277 | 'columnGapSm'
278 | 'columnGapMd'
279 | 'columnGapLg'
280 | 'columnGapXl'
281 | 'columnGap2xl'
282 | 'columnGap3xl'
283 | 'columnGap4xl';
284 };
285 /** Whether to add flex: grow at various breakpoints */
286 grow?: {
287 default?: 'grow';
288 sm?: 'grow';
289 md?: 'grow';
290 lg?: 'grow';
291 xl?: 'grow';
292 '2xl'?: 'grow';
293 };
294 /** Whether to add flex: shrink at various breakpoints */
295 shrink?: {
296 default?: 'shrink';
297 sm?: 'shrink';
298 md?: 'shrink';
299 lg?: 'shrink';
300 xl?: 'shrink';
301 '2xl'?: 'shrink';
302 };
303 /** Value to add for flex property at various breakpoints */
304 flex?: {
305 default?: 'flexDefault' | 'flexNone' | 'flex_1' | 'flex_2' | 'flex_3' | 'flex_4';
306 sm?: 'flexDefault' | 'flexNone' | 'flex_1' | 'flex_2' | 'flex_3' | 'flex_4';
307 md?: 'flexDefault' | 'flexNone' | 'flex_1' | 'flex_2' | 'flex_3' | 'flex_4';
308 lg?: 'flexDefault' | 'flexNone' | 'flex_1' | 'flex_2' | 'flex_3' | 'flex_4';
309 xl?: 'flexDefault' | 'flexNone' | 'flex_1' | 'flex_2' | 'flex_3' | 'flex_4';
310 '2xl'?: 'flexDefault' | 'flexNone' | 'flex_1' | 'flex_2' | 'flex_3' | 'flex_4';
311 };
312 /** Value to add for flex-direction property at various breakpoints */
313 direction?: {
314 default?: 'column' | 'columnReverse' | 'row' | 'rowReverse';
315 sm?: 'column' | 'columnReverse' | 'row' | 'rowReverse';
316 md?: 'column' | 'columnReverse' | 'row' | 'rowReverse';
317 lg?: 'column' | 'columnReverse' | 'row' | 'rowReverse';
318 xl?: 'column' | 'columnReverse' | 'row' | 'rowReverse';
319 '2xl'?: 'column' | 'columnReverse' | 'row' | 'rowReverse';
320 };
321 /** Value to add for align-items property at various breakpoints */
322 alignItems?: {
323 default?:
324 | 'alignItemsFlexStart'
325 | 'alignItemsFlexEnd'
326 | 'alignItemsCenter'
327 | 'alignItemsStretch'
328 | 'alignItemsBaseline';
329 sm?: 'alignItemsFlexStart' | 'alignItemsFlexEnd' | 'alignItemsCenter' | 'alignItemsStretch' | 'alignItemsBaseline';
330 md?: 'alignItemsFlexStart' | 'alignItemsFlexEnd' | 'alignItemsCenter' | 'alignItemsStretch' | 'alignItemsBaseline';
331 lg?: 'alignItemsFlexStart' | 'alignItemsFlexEnd' | 'alignItemsCenter' | 'alignItemsStretch' | 'alignItemsBaseline';
332 xl?: 'alignItemsFlexStart' | 'alignItemsFlexEnd' | 'alignItemsCenter' | 'alignItemsStretch' | 'alignItemsBaseline';
333 '2xl'?:
334 | 'alignItemsFlexStart'
335 | 'alignItemsFlexEnd'
336 | 'alignItemsCenter'
337 | 'alignItemsStretch'
338 | 'alignItemsBaseline';
339 };
340 /** Value to add for align-content property at various breakpoints */
341 alignContent?: {
342 default?:
343 | 'alignContentFlexStart'
344 | 'alignContentFlexEnd'
345 | 'alignContentCenter'
346 | 'alignContentStretch'
347 | 'alignContentSpaceBetween'
348 | 'alignContentSpaceAround';
349 sm?:
350 | 'alignContentFlexStart'
351 | 'alignContentFlexEnd'
352 | 'alignContentCenter'
353 | 'alignContentStretch'
354 | 'alignContentSpaceBetween'
355 | 'alignContentSpaceAround';
356 md?:
357 | 'alignContentFlexStart'
358 | 'alignContentFlexEnd'
359 | 'alignContentCenter'
360 | 'alignContentStretch'
361 | 'alignContentSpaceBetween'
362 | 'alignContentSpaceAround';
363 lg?:
364 | 'alignContentFlexStart'
365 | 'alignContentFlexEnd'
366 | 'alignContentCenter'
367 | 'alignContentStretch'
368 | 'alignContentSpaceBetween'
369 | 'alignContentSpaceAround';
370 xl?:
371 | 'alignContentFlexStart'
372 | 'alignContentFlexEnd'
373 | 'alignContentCenter'
374 | 'alignContentStretch'
375 | 'alignContentSpaceBetween'
376 | 'alignContentSpaceAround';
377 '2xl'?:
378 | 'alignContentFlexStart'
379 | 'alignContentFlexEnd'
380 | 'alignContentCenter'
381 | 'alignContentStretch'
382 | 'alignContentSpaceBetween'
383 | 'alignContentSpaceAround';
384 };
385 /** Value to add for align-self property at various breakpoints */
386 alignSelf?: {
387 default?: 'alignSelfFlexStart' | 'alignSelfFlexEnd' | 'alignSelfCenter' | 'alignSelfStretch' | 'alignSelfBaseline';
388 sm?: 'alignSelfFlexStart' | 'alignSelfFlexEnd' | 'alignSelfCenter' | 'alignSelfStretch' | 'alignSelfBaseline';
389 md?: 'alignSelfFlexStart' | 'alignSelfFlexEnd' | 'alignSelfCenter' | 'alignSelfStretch' | 'alignSelfBaseline';
390 lg?: 'alignSelfFlexStart' | 'alignSelfFlexEnd' | 'alignSelfCenter' | 'alignSelfStretch' | 'alignSelfBaseline';
391 xl?: 'alignSelfFlexStart' | 'alignSelfFlexEnd' | 'alignSelfCenter' | 'alignSelfStretch' | 'alignSelfBaseline';
392 '2xl'?: 'alignSelfFlexStart' | 'alignSelfFlexEnd' | 'alignSelfCenter' | 'alignSelfStretch' | 'alignSelfBaseline';
393 };
394 /** Value to use for margin: auto at various breakpoints */
395 align?: {
396 default?: 'alignLeft' | 'alignRight';
397 sm?: 'alignLeft' | 'alignRight';
398 md?: 'alignLeft' | 'alignRight';
399 lg?: 'alignLeft' | 'alignRight';
400 xl?: 'alignLeft' | 'alignRight';
401 '2xl'?: 'alignLeft' | 'alignRight';
402 };
403 /** Value to add for justify-content property at various breakpoints */
404 justifyContent?: {
405 default?:
406 | 'justifyContentFlexStart'
407 | 'justifyContentFlexEnd'
408 | 'justifyContentCenter'
409 | 'justifyContentSpaceBetween'
410 | 'justifyContentSpaceAround'
411 | 'justifyContentSpaceEvenly';
412 sm?:
413 | 'justifyContentFlexStart'
414 | 'justifyContentFlexEnd'
415 | 'justifyContentCenter'
416 | 'justifyContentSpaceBetween'
417 | 'justifyContentSpaceAround'
418 | 'justifyContentSpaceEvenly';
419 md?:
420 | 'justifyContentFlexStart'
421 | 'justifyContentFlexEnd'
422 | 'justifyContentCenter'
423 | 'justifyContentSpaceBetween'
424 | 'justifyContentSpaceAround'
425 | 'justifyContentSpaceEvenly';
426 lg?:
427 | 'justifyContentFlexStart'
428 | 'justifyContentFlexEnd'
429 | 'justifyContentCenter'
430 | 'justifyContentSpaceBetween'
431 | 'justifyContentSpaceAround'
432 | 'justifyContentSpaceEvenly';
433 xl?:
434 | 'justifyContentFlexStart'
435 | 'justifyContentFlexEnd'
436 | 'justifyContentCenter'
437 | 'justifyContentSpaceBetween'
438 | 'justifyContentSpaceAround'
439 | 'justifyContentSpaceEvenly';
440 '2xl'?:
441 | 'justifyContentFlexStart'
442 | 'justifyContentFlexEnd'
443 | 'justifyContentCenter'
444 | 'justifyContentSpaceBetween'
445 | 'justifyContentSpaceAround'
446 | 'justifyContentSpaceEvenly';
447 };
448 /** Value to set to display property at various breakpoints */
449 display?: {
450 default?: 'inlineFlex';
451 sm?: 'flex' | 'inlineFlex';
452 md?: 'flex' | 'inlineFlex';
453 lg?: 'flex' | 'inlineFlex';
454 xl?: 'flex' | 'inlineFlex';
455 '2xl'?: 'flex' | 'inlineFlex';
456 };
457 /** Whether to set width: 100% at various breakpoints */
458 fullWidth?: {
459 default?: 'fullWidth';
460 sm?: 'fullWidth';
461 md?: 'fullWidth';
462 lg?: 'fullWidth';
463 xl?: 'fullWidth';
464 '2xl'?: 'fullWidth';
465 };
466 /** Value to set for flex-wrap property at various breakpoints */
467 flexWrap?: {
468 default?: 'wrap' | 'wrapReverse' | 'nowrap';
469 sm?: 'wrap' | 'wrapReverse' | 'nowrap';
470 md?: 'wrap' | 'wrapReverse' | 'nowrap';
471 lg?: 'wrap' | 'wrapReverse' | 'nowrap';
472 xl?: 'wrap' | 'wrapReverse' | 'nowrap';
473 '2xl'?: 'wrap' | 'wrapReverse' | 'nowrap';
474 };
475 /** Modifies the flex layout element order property */
476 order?: {
477 default?: string;
478 md?: string;
479 lg?: string;
480 xl?: string;
481 '2xl'?: string;
482 };
483 /** Sets the base component to render. defaults to div */
484 component?: React.ElementType<any> | React.ComponentType<any>;
485 }
486
487 export const Flex: React.FunctionComponent<FlexProps> = ({
488 children = null,
489 className = '',
490 component = 'div',
491 spacer,
492 spaceItems,
493 gap,
494 rowGap,
495 columnGap,
496 grow,
497 shrink,
498 flex,
499 direction,
500 alignItems,
501 alignContent,
502 alignSelf,
503 align,
504 justifyContent,
505 display,
506 fullWidth,
507 flexWrap,
508 order,
509 style,
510 ...props
511 }: FlexProps) => {
512 const Component: any = component;
513
514 return (
515 <Component
516 className={css(
517 styles.flex,
518 formatBreakpointMods(spacer, styles),
519 formatBreakpointMods(spaceItems, styles),
520 formatBreakpointMods(grow, styles),
521 formatBreakpointMods(shrink, styles),
522 formatBreakpointMods(flex, styles),
523 formatBreakpointMods(direction, styles),
524 formatBreakpointMods(alignItems, styles),
525 formatBreakpointMods(alignContent, styles),
526 formatBreakpointMods(alignSelf, styles),
527 formatBreakpointMods(align, styles),
528 formatBreakpointMods(justifyContent, styles),
529 formatBreakpointMods(display, styles),
530 formatBreakpointMods(fullWidth, styles),
531 formatBreakpointMods(flexWrap, styles),
532 formatBreakpointMods(gap, styles),
533 formatBreakpointMods(rowGap, styles),
534 formatBreakpointMods(columnGap, styles),
535 className
536 )}
537 style={
538 style || order ? { ...style, ...setBreakpointCssVars(order, flexToken.l_flex_item_Order.name) } : undefined
539 }
540 {...props}
541 >
542 {children}
543 </Component>
544 );
545 };
546 Flex.displayName = 'Flex';