revite/src/components/ui/Overline.tsx

92 lines
2 KiB
TypeScript
Raw Normal View History

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;
hover?: boolean;
2021-07-05 06:25:20 -04:00
block?: boolean;
spaced?: boolean;
noMargin?: boolean;
2021-07-05 06:25:20 -04:00
children?: Children;
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;
transition: 0.2s ease filter;
${(props) =>
props.hover &&
css`
cursor: pointer;
transition: 0.2s ease filter;
&:hover {
filter: brightness(1.2);
}
`}
${(props) =>
!props.noMargin &&
css`
margin: 0.4em 0;
`}
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
${(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 && <> &middot; </>}
{props.error && (
<Overline type="error">
<Text id={`error.${props.error}`}>{props.error}</Text>
</Overline>
)}
</OverlineBase>
);
2021-06-18 09:20:57 -04:00
}