forked from t0gre/react-datepicker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClose.tsx
More file actions
102 lines (93 loc) · 2.29 KB
/
Close.tsx
File metadata and controls
102 lines (93 loc) · 2.29 KB
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
import React, {useContext} from 'react'
import styled, {ThemeContext} from 'styled-components'
import {
color,
ColorProps,
space,
SpaceProps,
fontSize,
FontSizeProps,
fontFamily,
FontFamilyProps,
fontWeight,
FontWeightProps,
compose,
} from 'styled-system'
import CloseIcon from '../../icons/CloseIcon'
// eslint-disable-next-line import/no-unresolved
import {CloseTheme} from '../../@types/theme'
import useThemeProps from '../../hooks/useThemeProps'
import globalStyles from '../../globalStyles'
import getThemeProp from '../../utils/getThemeProp'
interface TextProps
extends ColorProps,
SpaceProps,
FontSizeProps,
FontFamilyProps,
FontWeightProps {}
const composeTextStyles = compose(space, color, fontSize, fontFamily, fontWeight)
const Text = styled('div')<TextProps>`
${composeTextStyles}
float: left;
transition: color 0.15s;
`
const Wrapper = styled('button')<ColorProps>`
display: flex;
align-items: center;
cursor: pointer;
background: transparent;
padding: 0;
border: 0;
svg {
transition: color 0.15s;
}
&:hover {
${Text} {
${color}
}
svg {
${color}
}
}
`
interface CloseProps {
onClick(): void
rtl: boolean
closeText: string
}
function Close({onClick, rtl, closeText}: CloseProps) {
const themeContext = useContext(ThemeContext)
const theme: CloseTheme = useThemeProps({
fontFamily: globalStyles.fontFamily,
closeMargin: rtl ? '1px 16px 0 0' : '1px 0 0 16px',
closeColor: getThemeProp('silverCloud', globalStyles.colors.silverCloud, themeContext),
closeHoverColor: getThemeProp('darcula', globalStyles.colors.darcula, themeContext),
closeFontSize: '12px',
closeFontWeight: 600,
})
return (
<Wrapper
onClick={onClick}
// @ts-ignore
color={theme.closeHoverColor}
data-testid="DatepickerClose"
tabIndex={-1}
aria-label="Close"
>
<CloseIcon width="15px" height="16px" color="#ADADAD" />
{closeText && (
<Text
m={theme.closeMargin}
// @ts-ignore
color={theme.closeColor}
fontSize={theme.closeFontSize}
fontFamily={theme.fontFamily}
fontWeight={theme.closeFontWeight}
>
{closeText}
</Text>
)}
</Wrapper>
)
}
export default Close