Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 2ea1377

Browse files
committed
Render manual SVG "octicons"
1 parent 9ae31dd commit 2ea1377

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

lib/atom/octicon.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,32 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import cx from 'classnames';
44

5+
/* eslint-disable max-len */
6+
const SVG = {
7+
unlock: {
8+
viewBox: '0 0 24 16',
9+
element: (
10+
<path
11+
fillRule="evenodd"
12+
d="m 13.4,13 h -1 v -1 h 1 z m 6,-7 h 1 c 0.55,0 1,0.45 1,1 v 7 c 0,0.55 -0.45,1 -1,1 h -10 c -0.55,0 -1,-0.45 -1,-1 V 7 c 0,-0.55 0.45,-1 1,-1 h 1 V 4.085901 C 11.4,2.1862908 9.8780193,2.4095693 8.904902,2.4143325 8.0404588,2.4185637 6.3689542,2.1882296 6.3689542,4.085901 V 7.4918301 L 4.2521568,7.4509801 4.2930068,4.045051 C 4.3176792,1.987953 5.080245,-0.02206145 8.792353,-0.03403364 13.536238,-0.0493335 13.21,3.1688541 13.21,4.085901 V 6 h -0.01 4.41 m 2.79,1 h -9 v 7 h 9 z m -7,1 h -1 v 1 h 1 z m 0,2 h -1 v 1 h 1 z"
13+
/>
14+
),
15+
},
16+
};
17+
/* eslint-enable max-len */
18+
519
export default function Octicon({icon, ...others}) {
620
const classes = cx('icon', `icon-${icon}`, others.className);
21+
22+
const svgContent = SVG[icon];
23+
if (svgContent) {
24+
return (
25+
<svg {...others} viewBox={svgContent.viewBox} xmlns="http://www.w3.org/2000/svg" className={classes}>
26+
{svgContent.element}
27+
</svg>
28+
);
29+
}
30+
731
return <span {...others} className={classes} />;
832
}
933

test/atom/octicon.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react';
2+
import {shallow} from 'enzyme';
3+
4+
import Octicon from '../../lib/atom/octicon';
5+
6+
describe('Octicon', function() {
7+
it('defaults to rendering an octicon span', function() {
8+
const wrapper = shallow(<Octicon icon="octoface" />);
9+
assert.isTrue(wrapper.exists('span.icon.icon-octoface'));
10+
});
11+
12+
it('renders SVG overrides', function() {
13+
const wrapper = shallow(<Octicon icon="unlock" />);
14+
15+
assert.strictEqual(wrapper.find('svg').prop('viewBox'), '0 0 24 16');
16+
});
17+
});

0 commit comments

Comments
 (0)