Skip to content

Commit

Permalink
feat: improve svg-transform example
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomura committed Nov 14, 2024
1 parent 8cdf77c commit 71883be
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions packages/examples/vite/src/examples/svg-transform/index.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
/* eslint-disable react/no-array-index-key */

import React from 'react';
import { Document, Page, Svg, G, Rect } from '@react-pdf/renderer';

const COLORS = ['red', 'green', 'blue', 'yellow', 'purple'];

const randBetween = (min, max) =>
Math.floor(Math.random() * (max - min + 1) + min);

const SvgTransform = () => {
return (
<Document>
<Page>
<Svg width="600" height="300">
<G style={{ transform: 'translate(50, 50)' }}>
<Rect fill="red" width="200" height="50" />
</G>
<Page size={[600, 600]}>
<Svg width="600" height="600">
{Array.from({ length: 200 }).map((_, i) => (
<G
key={i}
style={{
transform: `translate(${randBetween(0, 600)}, ${randBetween(0, 600)}) rotate(${randBetween(-180, 180)}deg)`,
}}
>
<Rect fill={COLORS[i % COLORS.length]} width="200" height="50" />
</G>
))}
</Svg>
</Page>
</Document>
Expand Down

0 comments on commit 71883be

Please sign in to comment.