-
Notifications
You must be signed in to change notification settings - Fork 381
Expand file tree
/
Copy pathGallery.tsx
More file actions
73 lines (70 loc) · 2.23 KB
/
Gallery.tsx
File metadata and controls
73 lines (70 loc) · 2.23 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
import { css } from '@patternfly/react-styles';
import styles from '@patternfly/react-styles/css/layouts/Gallery/gallery';
import cssGridTemplateColumnsMin from '@patternfly/react-tokens/dist/esm/l_gallery_GridTemplateColumns_min';
import cssGridTemplateColumnsMax from '@patternfly/react-tokens/dist/esm/l_gallery_GridTemplateColumns_max';
export interface GalleryProps extends React.HTMLProps<HTMLDivElement> {
/** content rendered inside the Gallery layout */
children?: React.ReactNode;
/** additional classes added to the Gallery layout */
className?: string;
/** Adds space between children. */
hasGutter?: boolean;
/** Minimum widths at various breakpoints. */
minWidths?: {
default?: string;
sm?: string;
md?: string;
lg?: string;
xl?: string;
'2xl'?: string;
};
/** Maximum widths at various breakpoints. */
maxWidths?: {
default?: string;
sm?: string;
md?: string;
lg?: string;
xl?: string;
'2xl'?: string;
};
/** Sets the base component to render. defaults to div */
component?: React.ElementType<any> | React.ComponentType<any>;
}
export const Gallery: React.FunctionComponent<GalleryProps> = ({
children = null,
className = '',
component = 'div',
hasGutter = false,
minWidths,
maxWidths,
...props
}: GalleryProps) => {
const minWidthStyles: any = {};
const Component: any = component;
if (minWidths) {
Object.entries(minWidths || {}).map(
([breakpoint, value]) =>
(minWidthStyles[`${cssGridTemplateColumnsMin.name}${breakpoint !== 'default' ? `-on-${breakpoint}` : ''}`] =
value)
);
}
const maxWidthStyles: any = {};
if (maxWidths) {
Object.entries(maxWidths || {}).map(
([breakpoint, value]) =>
(maxWidthStyles[`${cssGridTemplateColumnsMax.name}${breakpoint !== 'default' ? `-on-${breakpoint}` : ''}`] =
value)
);
}
const widthStyles = { ...minWidthStyles, ...maxWidthStyles };
return (
<Component
className={css(styles.gallery, hasGutter && styles.modifiers.gutter, className)}
{...props}
{...((minWidths || maxWidths) && { style: { ...widthStyles, ...props.style } as React.CSSProperties })}
>
{children}
</Component>
);
};
Gallery.displayName = 'Gallery';