code.jsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { useMemo, useState } from 'react'
  2. const formatGroups = [
  3. { title: 'Documents', items: ['docx', 'pdf', 'ofd'] },
  4. { title: 'Drawings', items: ['dxf', 'dwg', 'dwf', 'dwfx', 'xps'] },
  5. { title: 'Code', items: ['js', 'ts', 'vue', 'json'] }
  6. ]
  7. export function PreviewPicker({ onSelect }) {
  8. const [activeGroup, setActiveGroup] = useState('Documents')
  9. const visibleItems = useMemo(() => {
  10. return formatGroups.find(group => group.title === activeGroup)?.items || []
  11. }, [activeGroup])
  12. return (
  13. <section className="preview-picker">
  14. <nav aria-label="Preview groups">
  15. {formatGroups.map(group => (
  16. <button
  17. key={group.title}
  18. className={group.title === activeGroup ? 'active' : ''}
  19. type="button"
  20. onClick={() => setActiveGroup(group.title)}
  21. >
  22. {group.title}
  23. </button>
  24. ))}
  25. </nav>
  26. <ul>
  27. {visibleItems.map(type => (
  28. <li key={type}>
  29. <button type="button" onClick={() => onSelect(type)}>
  30. <strong>{type.toUpperCase()}</strong>
  31. <span>Open sample.{type}</span>
  32. </button>
  33. </li>
  34. ))}
  35. </ul>
  36. </section>
  37. )
  38. }