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