forked from wulkano/Kap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvg.js
117 lines (103 loc) · 2.55 KB
/
svg.js
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
import React from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import {handleKeyboardActivation} from '../utils/inputs';
class Svg extends React.Component {
static defaultProps = {
fill: 'var(--icon-color)',
activeFill: 'var(--kap)',
hoverFill: 'var(--icon-hover-color)',
size: '24px',
active: false,
viewBox: '0 0 24 24',
tabIndex: -1
}
onClick = () => {
const {onClick} = this.props;
if (onClick) {
onClick();
}
}
stopPropagation = event => {
event.stopPropagation();
}
render() {
const {
fill,
size,
activeFill,
hoverFill,
active,
onClick,
children,
viewBox,
shadow,
tabIndex,
isMenu
} = this.props;
const className = classNames({active, shadow, focusable: tabIndex >= 0});
return (
<div tabIndex={tabIndex} onKeyDown={tabIndex >= 0 ? handleKeyboardActivation(onClick, {isMenu}) : undefined}>
<svg
viewBox={viewBox}
className={className}
onClick={onClick}
onMouseDown={this.stopPropagation}
>
{ children }
</svg>
<style jsx>{`
svg {
fill: ${fill};
width: ${size};
height: ${size};
}
svg:hover,
div:focus svg {
fill: ${hoverFill};
}
div {
position: relative;
width: ${size};
height: ${size};
outline: none;
}
div.focusable:focus::before {
content: '';
position: absolute;
left: 0;
right: 0;
width: 100%;
height: 100%;
transform: scale(${1 / 0.75});
background: var(--icon-focus-background-color);
z-index: -1;
border-radius: 2px;
}
.shadow {
filter: drop-shadow(0 1px 2px rgba(0,0,0,.1));
}
.active,
.active:hover,
div.focusable:focus svg {
fill: ${activeFill};
}
`}</style>
</div>
);
}
}
Svg.propTypes = {
fill: PropTypes.string,
size: PropTypes.string,
activeFill: PropTypes.string,
hoverFill: PropTypes.string,
active: PropTypes.bool,
children: PropTypes.any,
viewBox: PropTypes.string,
onClick: PropTypes.elementType,
shadow: PropTypes.bool,
tabIndex: PropTypes.number,
isMenu: PropTypes.bool
};
export default Svg;