forked from chanzuckerberg/sci-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstyle.tsx
124 lines (99 loc) · 2.91 KB
/
style.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { SerializedStyles } from "@emotion/react";
import {
Tab as RawTab,
Tabs as RawTabs,
TabsProps as RawTabsProps,
} from "@mui/material";
import { styled } from "@mui/material/styles";
import { focusVisibleA11yStyle, fontBodyS, fontBodyXs } from "../styles";
import {
CommonThemeProps,
getColors,
getFontWeights,
getSpaces,
} from "../styles/common/selectors/theme";
import { SdsSize } from "./components/common";
export type TabsProps = Omit<
RawTabsProps,
"nonce" | "rev" | "rel" | "autoFocus" | "content"
> & {
underlined?: boolean;
sdsSize?: "small" | "large";
};
const TempTabs = (props: RawTabsProps) => <RawTabs {...props} />;
const TABS_DO_NOT_FORWARD_PROPS = ["underlined", "sdsSize"];
export const StyledTabs = styled(TempTabs, {
shouldForwardProp: (prop) =>
!TABS_DO_NOT_FORWARD_PROPS.includes(String(prop)),
})<TabsProps>`
box-sizing: border-box;
padding-bottom: 0px;
min-height: unset;
position: relative;
z-index: 1;
overflow: inherit;
& .MuiTabs-scroller {
overflow: inherit !important;
}
${(props) => {
const { underlined, sdsSize = "large" } = props;
const colors = getColors(props);
const spaces = getSpaces(props);
const isLarge = sdsSize === "large";
return `
margin-top: ${isLarge ? spaces?.l : spaces?.m}px;
margin-bottom: ${isLarge ? spaces?.xl : spaces?.m}px;
border-bottom: ${
underlined ? `2px solid ${props.theme.palette.divider};` : "none"
};
`;
}}
`;
const TAB_DO_NOT_FORWARD_PROPS = ["sdsSize"];
interface TabProps extends CommonThemeProps {
sdsSize: SdsSize;
}
export const StyledTab = styled(RawTab, {
shouldForwardProp: (prop) => !TAB_DO_NOT_FORWARD_PROPS.includes(String(prop)),
})<TabProps>`
min-height: unset;
padding: 0;
min-width: 32px;
opacity: 1 !important;
${tabFontMixin}
${focusVisibleA11yStyle}
${(props) => {
const colors = getColors(props);
const spaces = getSpaces(props);
const fontWeights = getFontWeights(props);
const { sdsSize } = props;
const isLarge = sdsSize === "large";
return `
font-weight: ${fontWeights?.semibold};
margin: 0 ${spaces?.xl}px ${spaces?.xxs}px 0;
// (thuang): Large Tab height is 30px, the offset is 4px
height: ${isLarge ? 26 : 22}px;
color: ${props.theme.palette.text.secondary};
&:hover, :focus {
color: ${props.theme.palette.text.primary};
}
&.Mui-selected {
color: ${props.theme.palette.text.primary};
&:hover {
color: ${props.theme.palette.text.primary};
}
}
&:active {
color: ${props.theme.palette.text.primary};
}
&:disabled {
color: ${props.theme.palette.text.disabled};
}
`;
}}
`;
function tabFontMixin(props: TabProps): SerializedStyles | null {
const { sdsSize } = props;
const isLarge = sdsSize === "large";
return isLarge ? fontBodyS(props) : fontBodyXs(props);
}