This repository was archived by the owner on Aug 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathIcon.jsx
More file actions
160 lines (151 loc) · 3.56 KB
/
Icon.jsx
File metadata and controls
160 lines (151 loc) · 3.56 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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import React from 'react'
import PropTypes from 'prop-types'
import getValidProps from '@helpscout/react-utils/dist/getValidProps'
import VisuallyHidden from '../VisuallyHidden'
import classNames from 'classnames'
import { IconUI } from './Icon.css'
import { svgSet } from './Icon.utils'
const Icon = props => {
const {
center,
className,
clickable,
faint,
ignoreClick,
isWithHiddenTitle,
inline,
muted,
onClick,
offsetLeft,
offsetRight,
name,
shade,
size,
state,
subtle,
title,
withCaret,
...rest
} = props
const componentClassName = classNames(
'c-Icon',
center && 'is-center',
clickable && 'is-clickable',
!clickable && ignoreClick && 'is-noInteract',
faint && 'is-faint',
inline && 'is-inline',
name && `is-iconName-${name}`,
offsetLeft && 'is-offsetLeft',
offsetRight && 'is-offsetRight',
muted && 'is-muted',
shade && `is-${shade}`,
state && `is-${state}`,
subtle && 'is-subtle',
size && `is-${size}`,
withCaret && 'withCaret',
className
)
const IconComponent = svgSet[name]
const CaretComponent = svgSet['caret-down']
const iconTitle = title || name
const caretMarkup = withCaret ? (
<span className="c-Icon__icon is-caret" title="Caret">
{CaretComponent && <CaretComponent />}
</span>
) : null
return (
<IconUI
aria-hidden
role="img"
{...getValidProps(rest)}
className={componentClassName}
onClick={onClick}
data-icon-name={name}
title={iconTitle}
>
<span className="c-Icon__icon">{IconComponent && <IconComponent />}</span>
{caretMarkup}
{isWithHiddenTitle ? <VisuallyHidden>{iconTitle}</VisuallyHidden> : null}
</IconUI>
)
}
function noop() {}
Icon.defaultProps = {
center: false,
clickable: false,
'data-cy': 'Icon',
ignoreClick: true,
isWithHiddenTitle: true,
muted: false,
name: 'emoji',
onClick: noop,
offsetLeft: false,
offsetRight: false,
size: '20',
withCaret: false,
}
Icon.propTypes = {
/** Center aligns component. */
center: PropTypes.bool,
/** Custom class names to be added to the component. */
className: PropTypes.string,
/** Enables the component to be clickable. */
clickable: PropTypes.bool,
/** Ignores click events. Bubbles click event to parent component. */
ignoreClick: PropTypes.bool,
/** Displays the component as `inline-block`. */
inline: PropTypes.bool,
/** Applies muted styles. */
muted: PropTypes.bool,
/** Determines the SVG image. Required. */
name: PropTypes.string,
/** Callback function when component is clicked. */
onClick: PropTypes.func,
/** Changes icon color to represent a state. */
state: PropTypes.oneOf(['error', 'success', 'warning']),
/** Changes icon color shade. */
shade: PropTypes.oneOf(['subtle', 'muted', 'faint', 'extraMuted']),
/** Adjusts the size of the component. */
size: PropTypes.oneOf([
8,
10,
12,
13,
14,
15,
16,
18,
20,
24,
32,
48,
52,
72,
'8',
'10',
'12',
'13',
'14',
'15',
'16',
'18',
'20',
'24',
'32',
'48',
'52',
'72',
]),
/** Provides a name for the component. */
title: PropTypes.string,
/** Renders a caret icon, next to the component's SVG icon. */
withCaret: PropTypes.bool,
faint: PropTypes.bool,
isWithHiddenTitle: PropTypes.bool,
offsetLeft: PropTypes.bool,
offsetRight: PropTypes.bool,
subtle: PropTypes.bool,
/** Data attr for Cypress tests. */
'data-cy': PropTypes.string,
}
export default Icon