Datasets:
Download tasks/c12/repo/src/components/ProjectSection.jsx from Roy-DOU/Webdev-Bench: direct link, hf CLI and curl.
- Browser
- Download file 3.2 kB
-
https://huggingface.co/datasets/Roy-DOU/Webdev-Bench/resolve/main/tasks/c12/repo/src/components/ProjectSection.jsx
- Command line
-
hf download hf://datasets/Roy-DOU/Webdev-Bench/tasks/c12/repo/src/components/ProjectSection.jsx
-
curl -L -o ProjectSection.jsx https://huggingface.co/datasets/Roy-DOU/Webdev-Bench/resolve/main/tasks/c12/repo/src/components/ProjectSection.jsx
3.2 kB
| import { useState } from 'react' | |
| const noop = (event) => event.preventDefault() | |
| function ViewGlyph({ kind }) { | |
| if (kind === 'two') { | |
| return ( | |
| <svg viewBox="0 0 14 14" width="14" height="14" aria-hidden="true"> | |
| <rect x="0" y="0" width="6" height="14" /> | |
| <rect x="8" y="0" width="6" height="14" /> | |
| </svg> | |
| ) | |
| } | |
| if (kind === 'four') { | |
| return ( | |
| <svg viewBox="0 0 14 14" width="14" height="14" aria-hidden="true"> | |
| {[0, 8].map((x) => | |
| [0, 8].map((y) => <rect key={`${x}-${y}`} x={x} y={y} width="6" height="6" />), | |
| )} | |
| </svg> | |
| ) | |
| } | |
| return ( | |
| <svg viewBox="0 0 14 14" width="14" height="14" aria-hidden="true"> | |
| {[0, 5, 10].map((x) => | |
| [0, 5, 10].map((y) => <rect key={`${x}-${y}`} x={x} y={y} width="4" height="4" />), | |
| )} | |
| </svg> | |
| ) | |
| } | |
| const VIEWS = [ | |
| { cols: 2, kind: 'two', label: '2 columns' }, | |
| { cols: 3, kind: 'four', label: '3 columns' }, | |
| { cols: 4, kind: 'nine', label: '4 columns' }, | |
| ] | |
| function Cell({ cell, projectName, index }) { | |
| const style = { aspectRatio: `928.5 / ${cell.h}` } | |
| if (cell.off) style.marginTop = `${cell.off / 2}px` | |
| return ( | |
| <a | |
| className="cell" | |
| href="#" | |
| onClick={noop} | |
| style={style} | |
| aria-label={`${projectName} — visual ${index + 1}`} | |
| > | |
| {cell.type === 'img' ? ( | |
| <img src={cell.src} alt={`${projectName} case visual ${index + 1}`} /> | |
| ) : ( | |
| <span className="hatch" aria-hidden="true" /> | |
| )} | |
| </a> | |
| ) | |
| } | |
| export default function ProjectSection({ project }) { | |
| const [cols, setCols] = useState(4) | |
| const [pressedCols, setPressedCols] = useState(4) | |
| const cells = project.rows.flat() | |
| return ( | |
| <section className="project" id={project.id}> | |
| <div className="project-head"> | |
| <h2 className="project-title"> | |
| <a className="project-name" href="#" onClick={noop}> | |
| {project.name} | |
| </a> | |
| <span className="project-meta"> | |
| , {project.tags.join(', ')}, {project.year} | |
| </span> | |
| </h2> | |
| <button className="plus" type="button" aria-label={`Expand ${project.name}`}> | |
| <svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"> | |
| <path d="M8 1v14M1 8h14" stroke="currentColor" strokeWidth="1.2" fill="none" /> | |
| </svg> | |
| </button> | |
| <div className="views" role="group" aria-label={`${project.name} grid density`}> | |
| {VIEWS.map((view) => ( | |
| <button | |
| key={view.cols} | |
| type="button" | |
| className={`view-btn${pressedCols === view.cols ? ' active' : ''}`} | |
| aria-pressed={pressedCols === view.cols} | |
| aria-label={view.label} | |
| onClick={() => { | |
| setCols(view.cols) | |
| setPressedCols(cols) | |
| }} | |
| > | |
| <ViewGlyph kind={view.kind} /> | |
| </button> | |
| ))} | |
| </div> | |
| </div> | |
| <div className="grid" style={{ '--cols': cols }}> | |
| {cells.map((cell, i) => ( | |
| <Cell key={i} cell={cell} projectName={project.name} index={i} /> | |
| ))} | |
| </div> | |
| </section> | |
| ) | |
| } | |