|
1 | 1 | # React Rough Fiber
|
2 | 2 |
|
3 | 3 | 
|
| 4 | + |
| 5 | +`react-rough-fiber` -- A React renderer for rendering hand-drawn SVGs. |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +``` bash |
| 10 | +npm install react-rough-fiber react-reconciler |
| 11 | +``` |
| 12 | + |
| 13 | +> If you are using React 17, you need to install react-reconciler@0.26.2 |
| 14 | +
|
| 15 | +## Quick Start |
| 16 | + |
| 17 | +To render the SVG in a hand-drawn style, you only need to add three lines of code: |
| 18 | +``` js |
| 19 | +import { RoughSVG } from 'react-rough-fiber' |
| 20 | +export default function App() { |
| 21 | + return ( |
| 22 | + <RoughSVG> |
| 23 | + <svg viewBox="0 0 128 128" width="128" height="128"> |
| 24 | + <circle cx={64} cy={64} r={48} stroke="currentColor" fill="#82ca9d" /> |
| 25 | + </svg> |
| 26 | + </RoughSVG> |
| 27 | + ) |
| 28 | +} |
| 29 | +``` |
| 30 | + |
| 31 | +## Usage |
| 32 | + |
| 33 | +react-rough-fiber can integrate with many existing SVG-based libraries: |
| 34 | + |
| 35 | +- [Icon](https://react-rough-fiber.amind.app/examples/icon) |
| 36 | +- Chart |
| 37 | + - [recharts](https://react-rough-fiber.amind.app/examples/chart/recharts) |
| 38 | + - [vis](https://react-rough-fiber.amind.app/examples/chart/visx) |
| 39 | + - [react-d3-tree](https://react-rough-fiber.amind.app/examples/chart/react-d3-tree) |
| 40 | +- [Text](https://react-rough-fiber.amind.app/examples/text) |
| 41 | +- [SVG string](https://react-rough-fiber.amind.app/examples/svg-string) |
| 42 | +- [Remove SVG](https://react-rough-fiber.amind.app/examples/remote-svg) |
| 43 | +- [Emoji](https://react-rough-fiber.amind.app/examples/emoji) |
| 44 | + |
| 45 | +## API |
| 46 | + |
| 47 | +[Full Documentation](https://react-rough-fiber.amind.app/apis). |
| 48 | + |
| 49 | +### RoughSVG |
| 50 | + |
| 51 | +``` jsx |
| 52 | +import { RoughSVG } from "react-rough-fiber"; |
| 53 | +// ... your component code |
| 54 | +<RoughSVG containerType="div" options={options}> |
| 55 | +{/* your SVG */} |
| 56 | +</RoughSVG> |
| 57 | +``` |
| 58 | + |
| 59 | +- containerType = 'div': The type of container to use for the `RoughSVG`. Optional. |
| 60 | +- options: RoughOptions | ((shape: SVGShape, props: React.HTMLAttributes<SVGElement>) => RoughOptions = {}. It can be a `RoughOptions` for [Rough.js](https://github.com/rough-stuff/rough/wiki#options). Also support a function that returns `RoughOptions`. Optional |
| 61 | + |
| 62 | +### WCRoughSVG |
| 63 | + |
| 64 | +> `WCRoughSVG` is only compatible with React version 18.0.0 or later. |
| 65 | +
|
| 66 | +If you want to use context in `RoughSVG`, you can use `WCRoughSVG` instead of `RoughSVG`. See [FAQ](https://react-rough-fiber.amind.app/faq) for more details. |
| 67 | + |
| 68 | +All parameters of `WCRoughSVG` are identical to `RoughSVG`. |
| 69 | + |
| 70 | +## Development |
| 71 | + |
| 72 | +This library is a monorepo project. The core package can be found under `/packages/react-rough-fiber`, and the docs are under `/apps/docs` |
| 73 | + |
| 74 | +- clone this repo |
| 75 | +- run `pnpm install` to install dependencies |
| 76 | +- run `pnpm dev`, and open `localhost:3000` to view the documentation. |
| 77 | +- run `pnpm test` to run tests. |
| 78 | + |
| 79 | +PRs are welcome! |
| 80 | + |
| 81 | +## Showcases |
| 82 | + |
| 83 | +- [Add your project by creating a PR](https://github.com/Bowen7/react-rough-fiber/pulls) |
| 84 | + |
| 85 | +## Credits |
| 86 | + |
| 87 | +react-rough-fiber is powered or inspired by these open source projects: |
| 88 | + |
| 89 | +- [roughjs](https://github.com/rough-stuff/rough) |
| 90 | +- [nextra](https://github.com/shuding/nextra) |
| 91 | +- [perfect-freehand](https://github.com/steveruizok/perfect-freehand) |
| 92 | +- [react-three-fiber](https://github.com/pmndrs/react-three-fiber) |
| 93 | +- [preact](https://github.com/preactjs/preact) |
| 94 | +- [shadcn/ui](https://github.com/shadcn/ui) |
| 95 | + |
| 96 | +## License |
| 97 | + |
| 98 | +MIT |
0 commit comments