Skip to content

Commit c04b801

Browse files
committed
docs(with-vite): update example
1 parent c7dd217 commit c04b801

File tree

5 files changed

+95
-26
lines changed

5 files changed

+95
-26
lines changed

examples/with-vite/src/ReactPlock.tsx

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { Masonry } from '@local/lib';
2+
import { useState } from 'react';
3+
import { Button } from './ui/Button';
4+
5+
const items = [
6+
{ height: 600, color: '#D32F2F', id: 1 }, // Extra Tall - Darker Red
7+
{ height: 200, color: '#00796B', id: 2 }, // Short - Darker Teal
8+
{ height: 400, color: '#1976D2', id: 3 }, // Tall - Darker Blue
9+
{ height: 300, color: '#2E7D32', id: 4 }, // Medium - Darker Green
10+
{ height: 500, color: '#F57F17', id: 5 }, // Very Tall - Darker Yellow
11+
{ height: 250, color: '#C2185B', id: 6 }, // Medium-Short - Darker Pink
12+
{ height: 450, color: '#4527A0', id: 7 }, // Tall - Darker Purple
13+
{ height: 200, color: '#1565C0', id: 8 }, // Short - Darker Blue
14+
{ height: 350, color: '#D84315', id: 9 }, // Medium-Tall - Darker Orange
15+
{ height: 550, color: '#1B5E20', id: 10 }, // Very Tall - Darker Green
16+
{ height: 150, color: '#B71C1C', id: 11 }, // Very Short - Darker Red
17+
{ height: 400, color: '#311B92', id: 12 }, // Tall - Darker Purple
18+
{ height: 300, color: '#00695C', id: 13 }, // Medium - Darker Turquoise
19+
{ height: 250, color: '#E65100', id: 14 }, // Medium-Short - Darker Orange
20+
{ height: 500, color: '#880E4F', id: 15 }, // Very Tall - Darker Pink
21+
{ height: 200, color: '#0D47A1', id: 16 }, // Short - Darker Blue
22+
{ height: 450, color: '#3E2723', id: 17 }, // Tall - Darker Brown
23+
{ height: 350, color: '#4A148C', id: 18 }, // Medium-Tall - Darker Purple
24+
{ height: 500, color: '#01579B', id: 19 }, // Medium - Darker Blue
25+
{ height: 400, color: '#AD1457', id: 20 }, // Tall - Darker Pink
26+
{ height: 300, color: '#E65100', id: 21 }, // Medium-Short - Darker Orange
27+
];
28+
29+
export function ReactPlock() {
30+
const [isBalanced, setIsBalanced] = useState(false);
31+
32+
return (
33+
<div style={{ padding: '16px', fontFamily: 'system-ui' }}>
34+
<fieldset style={{ padding: 16 }}>
35+
<legend>Settings</legend>
36+
37+
<Button onClick={() => setIsBalanced(!isBalanced)}>
38+
{isBalanced ? 'Balanced Layout' : 'Default Layout'}
39+
</Button>
40+
</fieldset>
41+
42+
<div style={{ paddingTop: '16px' }} />
43+
44+
<Masonry
45+
items={items}
46+
config={{
47+
columns: [1, 2, 3],
48+
gap: [24, 12, 6],
49+
media: [640, 1024, 1280],
50+
useBalancedLayout: isBalanced,
51+
}}
52+
render={(item) => (
53+
<div
54+
style={{
55+
height: item.height,
56+
backgroundColor: item.color,
57+
width: '100%',
58+
display: 'flex',
59+
alignItems: 'center',
60+
justifyContent: 'center',
61+
color: '#FFF',
62+
fontSize: '22px',
63+
fontWeight: 'bold',
64+
}}
65+
>
66+
{`${item.height}px - #${item.id}`}
67+
</div>
68+
)}
69+
/>
70+
</div>
71+
);
72+
}

examples/with-vite/src/main.css

Lines changed: 0 additions & 4 deletions
This file was deleted.

examples/with-vite/src/main.tsx

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,11 @@
1-
import { images } from "@assets/data/images";
2-
import { Masonry } from "@local/lib";
3-
import React from "react";
4-
import ReactDOM from "react-dom/client";
5-
import "./main.css";
1+
import React from 'react';
2+
import ReactDOM from 'react-dom/client';
3+
import { ReactPlock } from './ReactPlock';
64

7-
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
5+
import './styles/index.css';
6+
7+
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
88
<React.StrictMode>
9-
<Masonry
10-
items={images}
11-
config={{
12-
columns: [1, 2, 3],
13-
gap: [24, 12, 6],
14-
media: [640, 1024, 1280],
15-
}}
16-
render={(item, idx) => (
17-
<img
18-
key={idx}
19-
src={item}
20-
loading="lazy"
21-
style={{ width: "100%", height: "auto" }}
22-
/>
23-
)}
24-
/>
9+
<ReactPlock />
2510
</React.StrictMode>
2611
);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
margin: 0;
3+
}

examples/with-vite/src/ui/Button.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { ButtonHTMLAttributes, forwardRef } from 'react';
2+
3+
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {}
4+
5+
const Button = forwardRef<HTMLButtonElement, ButtonProps>(
6+
({ className, style, ...props }, ref) => {
7+
return <button className={className} ref={ref} {...props} />;
8+
}
9+
);
10+
11+
Button.displayName = 'Button';
12+
13+
export { Button };

0 commit comments

Comments
 (0)