-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathPrefix.tsx
53 lines (46 loc) · 1.47 KB
/
Prefix.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
import { Box } from "@twilio-paste/box";
import type { BoxProps } from "@twilio-paste/box";
import type { BackgroundColor } from "@twilio-paste/style-props";
import * as React from "react";
import type { Variants } from "./types";
export interface PrefixProps {
children: NonNullable<React.ReactNode>;
disabled?: boolean;
/*
* Requiring element here instead of extending directly from BoxProps.
* This ensures an element prop is always passed on these composite components.
*/
element: BoxProps["element"];
variant?: Variants;
}
const Prefix = React.forwardRef<HTMLDivElement, PrefixProps>(
({ children, disabled, element = "PREFIX", variant }, ref) => {
let backgroundColor = "colorBackgroundBodyElevation" as BackgroundColor;
if (disabled && variant === "inverse") {
backgroundColor = "none";
} else if (variant === "inverse") {
backgroundColor = "colorBackgroundInverseElevation";
} else if (disabled) {
backgroundColor = "none";
}
if (children == null) return null;
return (
<Box
alignItems="flex-start"
backgroundColor={backgroundColor}
borderBottomLeftRadius="borderRadius20"
borderTopLeftRadius="borderRadius20"
display="flex"
element={`${element}_PREFIX`}
lineHeight="lineHeight20"
padding="space30"
variant={variant}
ref={ref}
>
{children}
</Box>
);
},
);
Prefix.displayName = "Prefix";
export { Prefix };