forked from primer/react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PointerBox.tsx
46 lines (39 loc) · 1.15 KB
/
PointerBox.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
import React from 'react'
import Box, {BoxProps} from './Box'
import Caret, {CaretProps} from './Caret'
import {SxProp} from './sx'
// FIXME: Make this work with BetterStyledSystem types
type MutatedSxProps = {
sx?: {
bg?: string
backgroundColor?: string
borderColor?: string
}
} & SxProp
export type PointerBoxProps = {
caret?: CaretProps['location']
bg?: CaretProps['bg']
borderColor?: CaretProps['borderColor']
border?: CaretProps['borderWidth']
} & BoxProps &
MutatedSxProps
function PointerBox(props: PointerBoxProps) {
// don't destructure these, just grab them
const {bg, border, borderColor, theme, sx} = props
const {caret, children, ...boxProps} = props
const caretProps = {
bg: bg || sx?.bg || sx?.backgroundColor,
borderColor: borderColor || sx?.borderColor,
borderWidth: border,
location: caret,
theme
}
const defaultBoxProps = {borderWidth: '1px', borderStyle: 'solid', borderColor: 'border.default', borderRadius: 2}
return (
<Box {...defaultBoxProps} {...boxProps} sx={{...sx, position: 'relative'}}>
{children}
<Caret {...caretProps} />
</Box>
)
}
export default PointerBox