UNPKG

1.15 kBJavaScriptView Raw
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 * @typechecks
7 *
8 * Example usage:
9 * <Circle
10 * radius={10}
11 * stroke="green"
12 * strokeWidth={3}
13 * fill="blue"
14 * />
15 *
16 */
17
18'use strict';
19
20var assign = require('object-assign');
21var PropTypes = require('prop-types');
22var React = require('react');
23var ReactART = require('react-art');
24
25var createReactClass = require('create-react-class');
26
27var Path = ReactART.Path;
28var Shape = ReactART.Shape;
29
30/**
31 * Circle is a React component for drawing circles. Like other ReactART
32 * components, it must be used in a <Surface>.
33 */
34var Circle = createReactClass({
35 displayName: 'Circle',
36
37 propTypes: {
38 radius: PropTypes.number.isRequired,
39 },
40
41 render: function render() {
42 var radius = this.props.radius;
43
44 var path = Path()
45 .moveTo(0, -radius)
46 .arc(0, radius * 2, radius)
47 .arc(0, radius * -2, radius)
48 .close();
49 return React.createElement(Shape, assign({}, this.props, {d: path}));
50 },
51});
52
53module.exports = Circle;