54 lines
1.1 KiB
JavaScript
54 lines
1.1 KiB
JavaScript
// @flow
|
|
import * as React from "react";
|
|
import styled from "styled-components";
|
|
|
|
type JustifyValues =
|
|
| "center"
|
|
| "space-around"
|
|
| "space-between"
|
|
| "flex-start"
|
|
| "flex-end";
|
|
|
|
type AlignValues =
|
|
| "stretch"
|
|
| "center"
|
|
| "baseline"
|
|
| "flex-start"
|
|
| "flex-end";
|
|
|
|
type Props = {|
|
|
column?: ?boolean,
|
|
shrink?: ?boolean,
|
|
align?: AlignValues,
|
|
justify?: JustifyValues,
|
|
auto?: ?boolean,
|
|
className?: string,
|
|
children?: React.Node,
|
|
role?: string,
|
|
gap?: number,
|
|
|};
|
|
|
|
const Flex = React.forwardRef<Props, HTMLDivElement>((props: Props, ref) => {
|
|
const { children, ...restProps } = props;
|
|
|
|
return (
|
|
<Container ref={ref} {...restProps}>
|
|
{children}
|
|
</Container>
|
|
);
|
|
});
|
|
|
|
const Container = styled.div`
|
|
display: flex;
|
|
flex: ${({ auto }) => (auto ? "1 1 auto" : "initial")};
|
|
flex-direction: ${({ column }) => (column ? "column" : "row")};
|
|
align-items: ${({ align }) => align};
|
|
justify-content: ${({ justify }) => justify};
|
|
flex-shrink: ${({ shrink }) => (shrink ? 1 : "initial")};
|
|
gap: ${({ gap }) => `${gap}px` || "initial"};
|
|
min-height: 0;
|
|
min-width: 0;
|
|
`;
|
|
|
|
export default Flex;
|