1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 04:46:40 +07:00
vault-frontend/src/components/containers/Grid/index.tsx
2019-07-29 19:13:16 +07:00

53 lines
1.1 KiB
TypeScript

import React, { FC } from 'react';
import classNames from 'classnames';
import * as styles from './styles.scss';
type IProps = React.HTMLAttributes<HTMLDivElement> & {
horizontal?: boolean;
vertical?: boolean;
columns?: string;
rows?: string;
size?: string;
square?: boolean;
gap?: number;
};
const Grid: FC<IProps> = ({
children,
className = '',
horizontal = false,
vertical = false,
square = false,
size = 'auto',
style = {},
columns = 'auto',
rows = 'auto',
gap = 10,
...props
}) => (
<div
className={classNames(
styles.grid,
className,
{
[styles.horizontal]: horizontal,
[styles.vertical]: !horizontal,
[styles.square]: square,
},
)}
style={{
...style,
gridTemplateColumns: square ? `repeat(auto-fill, ${(columns !== 'auto' && columns) || size})` : columns,
gridTemplateRows: square ? `repeat(auto-fill, ${(rows !== 'auto' && rows) || size})` : rows,
gridAutoRows: rows,
gridAutoColumns: columns,
gridRowGap: gap,
gridColumnGap: gap,
}}
{...props}
>
{children}
</div>
);
export { Grid };