-
Notifications
You must be signed in to change notification settings - Fork 51
/
Icon.jsx
60 lines (52 loc) · 1.46 KB
/
Icon.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
import React from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'
import { colorIconPrimary, colorIconSecondary, colorCardinal, colorWhite } from '@tds/core-colours'
import { safeRest } from '@tds/util-helpers'
import icons from './icons'
const getColour = variant => {
switch (variant) {
case 'primary':
return colorIconPrimary
case 'secondary':
return colorIconSecondary
case 'inverted':
return colorWhite
case 'error':
return colorCardinal
default:
return undefined
}
}
const iconSymbol = ({ symbol }) => ({ ...icons.default, ...icons[symbol] })
const iconVariant = ({ variant }) => ({ color: getColour(variant) })
const iconSize = ({ iSize }) => ({ fontSize: `${iSize / 16}rem` })
export const StyledIcon = styled.i(iconSymbol, iconVariant, iconSize)
const Icon = ({ symbol, variant, size, ...rest }) => (
<StyledIcon {...safeRest(rest)} symbol={symbol} variant={variant} iSize={size} />
)
Icon.propTypes = {
symbol: PropTypes.oneOf([
'caretDown',
'caretUp',
'checkmark',
'chevron',
'leftChevron',
'exclamationPointCircle',
'expander',
'hamburger',
'location',
'minus',
'plus',
'questionMarkCircle',
'spyglass',
'times',
]).isRequired,
variant: PropTypes.oneOf(['primary', 'secondary', 'inverted', 'error']),
size: PropTypes.oneOf([16, 20, 24, 32, 48]),
}
Icon.defaultProps = {
variant: undefined,
size: 24,
}
export default Icon