/
index.tsx
76 lines (68 loc) · 1.96 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import * as React from "react";
import styled, { css } from "styled-components";
import type * as Common from "../common/types";
import type { Theme } from "../defaultTheme";
import defaultTheme from "../defaultTheme";
import getSpacingToken from "../common/getSpacingToken";
import { left, right } from "../utils/rtl";
import type { Props, Indent, Align } from "./types";
import useTheme from "../hooks/useTheme";
function capitalize(string: string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
function getIndentAmount({
theme,
$indent,
}: // StyledContainer takes more props, so this shouldn't be exact
{
theme: Theme;
$indent: Indent;
}) {
return $indent === "none" ? 0 : theme.orbit[`space${capitalize($indent)}`];
}
const StyledContainer = styled.div<{ $align: Align; $indent: Indent }>`
${({ $align }) => css`
box-sizing: border-box;
width: 100%;
padding-${right}: ${$align === "left" && getIndentAmount};
padding-${left}: ${$align === "right" && getIndentAmount};
padding: ${$align === "center" && `0 ${getIndentAmount}`};
`};
`;
export const StyledSeparator = styled.hr<{
spaceAfter?: Common.SpaceAfterSizes;
$type: Props["type"];
$color?: Props["color"];
}>`
${({ theme, $type, $color }) => css`
height: ${theme.orbit.heightSeparator};
background: ${!$color && theme.orbit.backgroundSeparator};
box-sizing: border-box;
border-style: ${$type};
border-color: ${$color};
margin-top: 0;
margin-bottom: ${getSpacingToken};
`};
`;
StyledSeparator.defaultProps = {
theme: defaultTheme,
};
const Separator = ({
align = "left",
indent = "none",
spaceAfter,
type = "none",
color,
}: Props) => {
const theme = useTheme();
return (
<StyledContainer $align={align} $indent={indent}>
<StyledSeparator
$type={type}
spaceAfter={spaceAfter}
$color={color && (theme.orbit[color] as Props["color"])}
/>
</StyledContainer>
);
};
export default Separator;