bigbuffet-rw/app/soapbox/components/ui/stack/stack.tsx

56 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-03-21 11:09:01 -07:00
import classNames from 'classnames';
import React from 'react';
2022-04-12 06:50:17 -07:00
type SIZES = 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 10
2022-03-21 11:09:01 -07:00
const spaces = {
'0.5': 'space-y-0.5',
1: 'space-y-1',
'1.5': 'space-y-1.5',
2: 'space-y-2',
3: 'space-y-3',
4: 'space-y-4',
5: 'space-y-5',
2022-04-12 06:50:17 -07:00
10: 'space-y-10',
2022-03-21 11:09:01 -07:00
};
const justifyContentOptions = {
center: 'justify-center',
};
const alignItemsOptions = {
center: 'items-center',
};
interface IStack extends React.HTMLAttributes<HTMLDivElement> {
/** Size of the gap between elements. */
2022-03-21 11:09:01 -07:00
space?: SIZES,
/** Horizontal alignment of children. */
2022-03-21 11:09:01 -07:00
alignItems?: 'center',
/** Vertical alignment of children. */
2022-03-21 11:09:01 -07:00
justifyContent?: 'center',
/** Extra class names on the <div> element. */
2022-03-21 11:09:01 -07:00
className?: string,
}
/** Vertical stack of child elements. */
2022-03-21 11:09:01 -07:00
const Stack: React.FC<IStack> = (props) => {
const { space, alignItems, justifyContent, className, ...filteredProps } = props;
return (
<div
{...filteredProps}
className={classNames('flex flex-col', {
// @ts-ignore
2022-03-21 11:09:01 -07:00
[spaces[space]]: typeof space !== 'undefined',
// @ts-ignore
2022-03-21 11:09:01 -07:00
[alignItemsOptions[alignItems]]: typeof alignItems !== 'undefined',
// @ts-ignore
2022-03-21 11:09:01 -07:00
[justifyContentOptions[justifyContent]]: typeof justifyContent !== 'undefined',
}, className)}
2022-03-21 11:09:01 -07:00
/>
);
};
export default Stack;