forked from Faithlife/styled-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
styled.jsx
139 lines (125 loc) · 3.92 KB
/
styled.jsx
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import styled from 'styled-components';
import { colors } from '../shared-styles';
const arrowWidth = '10px';
const maxWidth = '1000px';
const maxHeight = '1000px';
export const margins = {
top: { marginBottom: arrowWidth },
right: { marginLeft: arrowWidth },
left: { marginRight: arrowWidth },
bottom: { marginTop: arrowWidth },
};
export const getPlacement = placement => {
if (!placement) {
return 'top';
}
return placement.split('-')[0];
};
export const PopoverBase = styled.div`
background: ${({ styleOverrides }) =>
styleOverrides.background
? styleOverrides.background
: `${({ theme }) => theme.backgroundColor}`};
background-color: ${({ theme }) => theme.backgroundColor};
border: ${({ styleOverrides }) => (styleOverrides.border ? styleOverrides.border : 'none')};
border-radius: ${({ styleOverrides }) =>
styleOverrides.borderRadius ? styleOverrides.borderRadius : '0px'};
box-shadow: ${({ styleOverrides }) => (styleOverrides.hideShadow ? 'none' : colors.boxShadow)};
color: ${({ theme }) => theme.textColor};
font-size: ${({ styleOverrides }) =>
styleOverrides.fontSize ? styleOverrides.fontSize : 'medium'};
font-weight: ${({ styleOverrides }) =>
styleOverrides.fontWeight ? styleOverrides.fontWeight : 'normal'};
height: ${({ styleOverrides }) => (styleOverrides.height ? styleOverrides.height : 'auto')};
line-height: ${({ styleOverrides }) =>
styleOverrides.lineHeight ? styleOverrides.lineHeight : 'normal'};
margin: ${({ styleOverrides }) => (styleOverrides.margin ? styleOverrides.margin : '0px')};
max-height: ${({ styleOverrides }) =>
styleOverrides.maxHeight
? typeof styleOverrides.maxHeight === 'number'
? `${styleOverrides.maxHeight}px`
: styleOverrides.maxHeight
: maxHeight};
max-width: ${({ styleOverrides }) =>
styleOverrides.maxWidth
? typeof styleOverrides.maxWidth === 'number'
? `${styleOverrides.maxWidth}px`
: styleOverrides.maxWidth
: maxWidth};
min-height: ${({ styleOverrides }) =>
styleOverrides.minHeight
? typeof styleOverrides.minHeight === 'number'
? `${styleOverrides.maxWidth}px`
: styleOverrides.maxWidth
: ''};
min-width: ${({ styleOverrides }) =>
styleOverrides.minWidth
? typeof styleOverrides.minWidth === 'number'
? `${styleOverrides.maxWidth}px`
: styleOverrides.maxWidth
: ''};
outline: ${({ styleOverrides }) => (styleOverrides.outline ? styleOverrides.outline : '')};
padding: ${({ styleOverrides }) => (styleOverrides.padding ? styleOverrides.padding : '0px')};
position: absolute;
text-align: ${({ styleOverrides }) =>
styleOverrides.textAlign ? styleOverrides.textAlign : 'center'};
white-space: normal;
width: ${({ styleOverrides }) => (styleOverrides.width ? styleOverrides.width : 'auto')};
z-index: ${({ styleOverrides }) => (styleOverrides.zIndex ? styleOverrides.zIndex : '10')};
`;
export const Arrow = styled.div`
width: 25px;
height: 25px;
position: absolute;
overflow: hidden;
pointer-events: none;
&::after {
content: '';
border: ${({ styleOverrides }) => (styleOverrides.border ? styleOverrides.border : 'none')};
position: absolute;
width: ${arrowWidth};
height: ${arrowWidth};
background: ${({ theme }) => theme.backgroundColor};
transform: translateX(-50%) translateY(-50%) rotate(45deg);
box-shadow: ${({ styleOverrides }) => (styleOverrides.hideShadow ? 'none' : colors.boxShadow)};
}
${({ placement }) => (placement ? arrowStyles[getPlacement(placement)] : arrowStyles.top)};
`;
const arrowStyles = {
top: `
top: 100%;
&::after {
top: 0;
}
`,
right: `
right: 100%;
&::after {
top: 50%;
left: 100%;
}
`,
left: `
left: 100%;
&::after {
top: 50%;
left: 0;
}
`,
bottom: `
bottom: 100%;
&::after {
top: 100%;
}
`,
};
export const ReferenceContainer = styled.div`
display: inline-block;
`;
export const FocusCatcher = styled.div.attrs(_ => ({ tabIndex: '-1' }))`
display: inline-block;
&:focus {
outline: none;
box-shadow: none;
}
`;