Hexagon Grid
shadcn-extras/hexagon-gridFreeComponent
An interlocking hexagon grid gallery.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/NayanDevLab/shadcn-extras/dev/public/c/hexagon-grid.jsonSource
1'use client';23import * as React from 'react';4import { cn } from '@/lib/utils';5import './hexagon-grid.css';67export interface HexGridProps extends React.HTMLAttributes<HTMLDivElement> {8 size?: number; // Size in pixels9 gap?: number; // Gap in pixels10}1112export const HexGrid = React.forwardRef<HTMLDivElement, HexGridProps>(13 ({ className, size = 220, gap = 16, children, ...props }, ref) => {14 return (15 <div className={cn('hex-grid-container', className)} ref={ref} {...props}>16 <div17 className='hex-grid'18 style={19 {20 '--hex-width': `${size}px`,21 '--hex-gap': `${gap}px`,22 '--sqrt3': '1.73205',23 '--hex-height': `calc(var(--hex-width) * 2 / var(--sqrt3))`,24 '--hex-margin-x': `calc(var(--hex-gap) / 2)`,25 '--hex-margin-y': `calc((var(--sqrt3) / 4 * var(--hex-gap)) - (0.125 * var(--hex-height)))`,26 } as React.CSSProperties27 }28 >29 {children}30 </div>31 </div>32 );33 }34);35HexGrid.displayName = 'HexGrid';3637export interface HexagonProps extends Omit<38 React.HTMLAttributes<HTMLDivElement>,39 'title'40> {41 imageSrc: string;42 imageAlt?: string;43 title?: React.ReactNode;44 subtitle?: React.ReactNode;45}4647export const Hexagon = React.forwardRef<HTMLDivElement, HexagonProps>(48 (49 {50 className,51 imageSrc,52 imageAlt = 'Hexagon image',53 title,54 subtitle,55 ...props56 },57 ref58 ) => {59 return (60 <div61 ref={ref}62 className={cn('hex', className)}63 tabIndex={0}64 role='button'65 {...props}66 >67 <div className='hex-shape'>68 {/* eslint-disable-next-line @next/next/no-img-element */}69 <img src={imageSrc} alt={imageAlt} />70 {(title || subtitle) && (71 <div className='hex-caption'>72 {title && <h3>{title}</h3>}73 {subtitle && <p>{subtitle}</p>}74 </div>75 )}76 </div>77 </div>78 );79 }80);81Hexagon.displayName = 'Hexagon';
Files it writes
More from shadcn-extras
All 33 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Image Gridanimated-image-grid | shadcn-extras | Components | Free | no deps · 3 files | |
| Blog Card Fourblog-card-four | shadcn-extras | Components | Free | 1 dep | |
| Blog Card Oneblog-card-one | shadcn-extras | Components | Free | no deps | |
| Blog Card Threeblog-card-three | shadcn-extras | Components | Free | 1 dep | |
| Blog Card Twoblog-card-two | shadcn-extras | Components | Free | 1 dep | |
| Bulb Iconbulb-icon | shadcn-extras | Components | Free | 2 deps | |
| Chevron Stepschevron-steps | shadcn-extras | Components | Free | no deps | |
| Circular Gallerycircular-gallery | shadcn-extras | Components | Free | no deps · 3 files |
