UNPKG

6.28 kBTypeScriptView Raw
1import * as StyledSystem from "styled-system";
2// import * as Emotion from "@emotion/styled";
3import * as React from "react";
4import { Omit } from "../common-types";
5
6type CSS = React.CSSProperties;
7
8type borderRadius = StyledSystem.BorderRadiusProps["borderRadius"];
9type borderColor = StyledSystem.BorderColorProps["borderColor"];
10
11interface ICustomConfig {
12 // Custom borderRadius alias
13 rounded?: borderRadius;
14 roundedTop?: borderRadius;
15 roundedBottom?: borderRadius;
16 roundedLeft?: borderRadius;
17 roundedRight?: borderRadius;
18 roundedTopRight?: borderRadius;
19 roundedTopLeft?: borderRadius;
20 roundedBottomRight?: borderRadius;
21 roundedBottomLeft?: borderRadius;
22
23 // Custom borderColor alias
24 borderBottomColor?: borderColor;
25 borderTopColor?: borderColor;
26 borderRightColor?: borderColor;
27 borderLeftColor?: borderColor;
28
29 // Custom width alias
30 w?: StyledSystem.WidthProps["width"];
31 minW?: StyledSystem.MinWidthProps["minWidth"];
32 maxW?: StyledSystem.MaxWidthProps["maxWidth"];
33
34 // Custom height alias
35 h?: StyledSystem.HeightProps["height"];
36 minH?: StyledSystem.MinHeightProps["minHeight"];
37 maxH?: StyledSystem.MaxHeightProps["maxHeight"];
38
39 // Custom display alias
40 d?: StyledSystem.DisplayProps["display"];
41
42 // Custom background alias
43 backgroundAttachment?: StyledSystem.ResponsiveValue<
44 CSS["backgroundAttachment"]
45 >;
46 bgImg?: StyledSystem.BackgroundImageProps["backgroundImage"];
47 bgImage?: StyledSystem.BackgroundImageProps["backgroundImage"];
48 bgSize?: StyledSystem.BackgroundSizeProps["backgroundSize"];
49 bgPos?: StyledSystem.BackgroundPositionProps["backgroundPosition"];
50 pos?: StyledSystem.PositionProps["position"];
51 flexDir?: StyledSystem.FlexDirectionProps["flexDirection"];
52
53 // CSS properties
54 textDecoration?: StyledSystem.ResponsiveValue<CSS["textDecoration"]>;
55 textDecor?: StyledSystem.ResponsiveValue<CSS["textDecoration"]>;
56 textTransform?: StyledSystem.ResponsiveValue<CSS["textTransform"]>;
57 overflowX?: StyledSystem.OverflowProps["overflow"];
58 overflowY?: StyledSystem.OverflowProps["overflow"];
59 appearance?: StyledSystem.ResponsiveValue<CSS["appearance"]>;
60 transform?: StyledSystem.ResponsiveValue<CSS["transform"]>;
61 transformOrigin?: StyledSystem.ResponsiveValue<CSS["transformOrigin"]>;
62 animation?: StyledSystem.ResponsiveValue<CSS["animation"]>;
63 userSelect?: StyledSystem.ResponsiveValue<CSS["userSelect"]>;
64 pointerEvents?: StyledSystem.ResponsiveValue<CSS["pointerEvents"]>;
65 boxSizing?: StyledSystem.ResponsiveValue<CSS["boxSizing"]>;
66 cursor?: StyledSystem.ResponsiveValue<CSS["cursor"]>;
67 resize?: StyledSystem.ResponsiveValue<CSS["resize"]>;
68 transition?: StyledSystem.ResponsiveValue<CSS["transition"]>;
69 objectFit?: StyledSystem.ResponsiveValue<CSS["objectFit"]>;
70 objectPosition?: StyledSystem.ResponsiveValue<CSS["objectPosition"]>;
71 visibility?: StyledSystem.ResponsiveValue<CSS["visibility"]>;
72
73 // Ellipsis alias
74 wordBreak?: StyledSystem.ResponsiveValue<CSS["wordBreak"]>;
75 overflowWrap?: StyledSystem.ResponsiveValue<CSS["overflowWrap"]>;
76 whiteSpace?: StyledSystem.ResponsiveValue<CSS["whiteSpace"]>;
77
78 // SVG color properties
79 fill?: StyledSystem.ColorProps["color"];
80 stroke?: StyledSystem.ColorProps["color"];
81
82 bgAttachment?: StyledSystem.ResponsiveValue<CSS["backgroundAttachment"]>;
83 shadow?: StyledSystem.BoxShadowProps["boxShadow"];
84
85 // List properties
86 listStyleType?: StyledSystem.ResponsiveValue<CSS["listStyleType"]>;
87 listStylePosition?: StyledSystem.ResponsiveValue<CSS["listStylePosition"]>;
88 listStyleImage?: StyledSystem.ResponsiveValue<CSS["listStyleImage"]>;
89 listStyleImg?: StyledSystem.ResponsiveValue<CSS["listStyleImage"]>;
90 listStylePos?: StyledSystem.ResponsiveValue<CSS["listStylePosition"]>;
91
92 // Outline prop
93 outline?: StyledSystem.ResponsiveValue<CSS["outline"]>;
94 float?: StyledSystem.ResponsiveValue<CSS["float"]>;
95 willChange?: StyledSystem.ResponsiveValue<CSS["willChange"]>;
96
97 // Border Width props
98 borderTopWidth?: StyledSystem.ResponsiveValue<CSS["borderTopWidth"]>;
99 borderBottomWidth?: StyledSystem.ResponsiveValue<CSS["borderBottomWidth"]>;
100 borderLeftWidth?: StyledSystem.ResponsiveValue<CSS["borderLeftWidth"]>;
101 borderRightWidth?: StyledSystem.ResponsiveValue<CSS["borderRightWidth"]>;
102}
103
104type FontSize =
105 | "xs"
106 | "sm"
107 | "base"
108 | "lg"
109 | "xl"
110 | "2xl"
111 | "3xl"
112 | "4xl"
113 | "5xl"
114 | "6xl";
115
116interface IFontSize {
117 fontSize?:
118 | StyledSystem.ResponsiveValue<FontSize>
119 | StyledSystem.FontSizeProps["fontSize"];
120}
121
122type FontWeight =
123 | "hairline"
124 | "thin"
125 | "light"
126 | "normal"
127 | "medium"
128 | "semibold"
129 | "bold"
130 | "extrabold"
131 | "black";
132
133interface IFontWeight {
134 fontWeight?:
135 | StyledSystem.ResponsiveValue<FontWeight>
136 | StyledSystem.FontWeightProps["fontWeight"];
137}
138
139type LineHeight = "none" | "shorter" | "short" | "normal" | "tall" | "taller";
140
141interface ILineHeight {
142 lineHeight?:
143 | StyledSystem.ResponsiveValue<LineHeight>
144 | StyledSystem.LineHeightProps["lineHeight"];
145}
146
147type LetterSpacing =
148 | "tighter"
149 | "tight"
150 | "normal"
151 | "wide"
152 | "wider"
153 | "widest";
154
155interface ILetterSpacing {
156 letterSpacing?:
157 | StyledSystem.ResponsiveValue<LetterSpacing>
158 | StyledSystem.LetterSpacingProps["letterSpacing"];
159}
160
161interface As {
162 as?: React.ElementType;
163}
164
165type TypographyProps = Omit<
166 StyledSystem.TypographyProps,
167 "fontWeight" | "lineHeight" | "fontSize" | "letterSpacing"
168>;
169
170interface Truncated {
171 /**
172 * If `true`, the text will be truncated
173 */
174 isTruncated?: boolean;
175}
176
177type StyledSystemProps = StyledSystem.LayoutProps &
178 StyledSystem.ColorProps &
179 StyledSystem.SpaceProps &
180 StyledSystem.BordersProps &
181 StyledSystem.BackgroundProps &
182 StyledSystem.PositionProps &
183 StyledSystem.FlexboxProps &
184 StyledSystem.ShadowProps &
185 StyledSystem.GridProps &
186 StyledSystem.OpacityProps &
187 StyledSystem.OverflowProps;
188
189type ModifiedStyledSystemProps = TypographyProps &
190 IFontSize &
191 ILetterSpacing &
192 IFontWeight &
193 ILineHeight &
194 ICustomConfig;
195
196type BoxHTMLProps = React.RefAttributes<any> & React.HTMLAttributes<any>;
197
198export type BoxProps = BoxHTMLProps &
199 StyledSystemProps &
200 ModifiedStyledSystemProps &
201 As &
202 Truncated;
203
204declare const Box: React.FC<BoxProps>;
205
206export default Box;