-
Notifications
You must be signed in to change notification settings - Fork 65
Open
Description
Hi, I've been using this package and it has been great. I just wanted to provide a simple svelte and react examples in case you wanted to add more generic examples to the recipe documentation.
Svelte
https://svelte.dev/repl/61514fb55a1b40be84cd731028435498?version=4.2.19
<script>
import { defineHex, Grid, rectangle } from 'honeycomb-grid'
const Hex = defineHex({ dimensions: 30, origin: 'topLeft' })
const grid = new Grid(Hex, rectangle({ width: 8, height: 5 }))
</script>
<svg viewBox="-1 0 500 500">
{#each grid as hex}
<polygon
points={hex.corners.map(({ x, y }) => `${x},${y}`)}
stroke-width="1"
stroke="#000"
fill="none"
/>
{/each}
</svg>
React
https://stackblitz.com/edit/vitejs-vite-evbazp?file=src%2FApp.tsx
import { defineHex, Grid, rectangle } from 'honeycomb-grid';
const Hex = defineHex({ dimensions: 30, origin: 'topLeft' });
const grid = new Grid(Hex, rectangle({ width: 8, height: 5 }));
function App() {
return (
<>
<svg viewBox="-1 0 500 500">
{grid.toArray().map((hex, index) => {
return (
<polygon
key={index}
points={hex.corners.map(({ x, y }) => `${x},${y}`).join(' ')}
strokeWidth="1"
stroke="#000"
fill="none"
/>
);
})}
</svg>
</>
);
}
export default App;Metadata
Metadata
Assignees
Labels
No labels