revite/src/components/ui/Overline.tsx

59 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-06-18 10:57:08 -04:00
import styled, { css } from "styled-components";
import { Children } from "../../types/Preact";
2021-06-19 15:00:30 -04:00
import { Text } from 'preact-i18n';
2021-06-18 09:20:57 -04:00
type Props = Omit<JSX.HTMLAttributes<HTMLDivElement>, 'children' | 'as'> & {
2021-06-19 15:00:30 -04:00
error?: string;
2021-06-18 09:20:57 -04:00
block?: boolean;
spaced?: boolean;
2021-06-18 09:20:57 -04:00
children?: Children;
type?: "default" | "subtle" | "error";
}
2021-06-18 10:57:08 -04:00
const OverlineBase = styled.div<Omit<Props, "children" | "error">>`
2021-06-18 09:20:57 -04:00
display: inline;
margin: 0.4em 0;
${ props => props.spaced && css`
margin-top: 0.8em;
` }
2021-06-18 09:20:57 -04:00
font-size: 14px;
font-weight: 600;
color: var(--foreground);
text-transform: uppercase;
2021-06-18 10:57:08 -04:00
${(props) =>
props.type === "subtle" &&
css`
font-size: 12px;
color: var(--secondary-foreground);
`}
2021-06-18 09:20:57 -04:00
2021-06-18 10:57:08 -04:00
${(props) =>
props.type === "error" &&
css`
font-size: 12px;
font-weight: 400;
color: var(--error);
`}
2021-06-18 09:20:57 -04:00
2021-06-18 10:57:08 -04:00
${(props) =>
props.block &&
css`
display: block;
`}
2021-06-18 09:20:57 -04:00
`;
2021-06-18 10:18:10 -04:00
export default function Overline(props: Props) {
2021-06-18 09:20:57 -04:00
return (
<OverlineBase {...props}>
2021-06-18 10:57:08 -04:00
{props.children}
{props.children && props.error && <> &middot; </>}
2021-06-19 15:00:30 -04:00
{props.error && <Overline type="error">
<Text id={`error.${props.error}`}>{props.error}</Text>
</Overline>}
2021-06-18 09:20:57 -04:00
</OverlineBase>
2021-06-18 10:57:08 -04:00
);
2021-06-18 09:20:57 -04:00
}