2022-01-14 13:50:58 -05:00
|
|
|
import styled, { css } from "styled-components/macro";
|
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;
|
2021-11-14 13:29:46 -05:00
|
|
|
hover?: boolean;
|
2021-07-05 06:25:20 -04:00
|
|
|
block?: boolean;
|
|
|
|
spaced?: boolean;
|
2021-08-04 11:03:38 -04:00
|
|
|
noMargin?: boolean;
|
2021-07-05 06:25:20 -04:00
|
|
|
children?: Children;
|
2021-11-14 13:29:46 -05:00
|
|
|
type?: "default" | "subtle" | "error" | "accent";
|
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;
|
2021-11-12 15:20:50 -05:00
|
|
|
transition: 0.2s ease filter;
|
|
|
|
|
|
|
|
${(props) =>
|
2021-11-14 13:29:46 -05:00
|
|
|
props.hover &&
|
2021-11-12 15:20:50 -05:00
|
|
|
css`
|
2021-11-14 13:29:46 -05:00
|
|
|
cursor: pointer;
|
|
|
|
transition: 0.2s ease filter;
|
|
|
|
|
2021-11-12 15:20:50 -05:00
|
|
|
&:hover {
|
|
|
|
filter: brightness(1.2);
|
|
|
|
}
|
|
|
|
`}
|
2021-08-04 11:03:38 -04:00
|
|
|
|
|
|
|
${(props) =>
|
|
|
|
!props.noMargin &&
|
|
|
|
css`
|
|
|
|
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-11-14 13:29:46 -05:00
|
|
|
${(props) =>
|
|
|
|
props.type === "accent" &&
|
|
|
|
css`
|
|
|
|
font-size: 12px;
|
|
|
|
font-weight: 400;
|
|
|
|
color: var(--accent);
|
|
|
|
`}
|
|
|
|
|
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
|
|
|
}
|