source: node_modules/recharts/es6/container/ClipPathProvider.js@ a762898

Last change on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 1.3 KB
Line 
1import * as React from 'react';
2import { createContext, useContext, useState } from 'react';
3import { uniqueId } from '../util/DataUtils';
4import { usePlotArea } from '../hooks';
5var ClipPathIdContext = /*#__PURE__*/createContext(undefined);
6
7/**
8 * Generates a unique clip path ID for use in SVG elements,
9 * and puts it in a context provider.
10 *
11 * To read the clip path ID, use the `useClipPathId` hook,
12 * or render `<ClipPath>` component which will automatically use the ID from this context.
13 *
14 * @param props children - React children to be wrapped by the provider
15 * @returns React Context Provider
16 */
17export var ClipPathProvider = _ref => {
18 var {
19 children
20 } = _ref;
21 var [clipPathId] = useState("".concat(uniqueId('recharts'), "-clip"));
22 var plotArea = usePlotArea();
23 if (plotArea == null) {
24 return null;
25 }
26 var {
27 x,
28 y,
29 width,
30 height
31 } = plotArea;
32 return /*#__PURE__*/React.createElement(ClipPathIdContext.Provider, {
33 value: clipPathId
34 }, /*#__PURE__*/React.createElement("defs", null, /*#__PURE__*/React.createElement("clipPath", {
35 id: clipPathId
36 }, /*#__PURE__*/React.createElement("rect", {
37 x: x,
38 y: y,
39 height: height,
40 width: width
41 }))), children);
42};
43export var useClipPathId = () => {
44 return useContext(ClipPathIdContext);
45};
Note: See TracBrowser for help on using the repository browser.