|
| 1 | +import { useState } from 'react' |
| 2 | +import { Tab } from '@headlessui/react' |
| 3 | + |
| 4 | +function classNames(...classes) { |
| 5 | + return classes.filter(Boolean).join(' ') |
| 6 | +} |
| 7 | + |
| 8 | +export default function Example() { |
| 9 | + let [categories] = useState({ |
| 10 | + Recent: [ |
| 11 | + { |
| 12 | + id: 1, |
| 13 | + title: 'Does drinking coffee make you smarter?', |
| 14 | + date: '5h ago', |
| 15 | + commentCount: 5, |
| 16 | + shareCount: 2, |
| 17 | + }, |
| 18 | + { |
| 19 | + id: 2, |
| 20 | + title: "So you've bought coffee... now what?", |
| 21 | + date: '2h ago', |
| 22 | + commentCount: 3, |
| 23 | + shareCount: 2, |
| 24 | + }, |
| 25 | + ], |
| 26 | + Popular: [ |
| 27 | + { |
| 28 | + id: 1, |
| 29 | + title: 'Is tech making coffee better or worse?', |
| 30 | + date: 'Jan 7', |
| 31 | + commentCount: 29, |
| 32 | + shareCount: 16, |
| 33 | + }, |
| 34 | + { |
| 35 | + id: 2, |
| 36 | + title: 'The most innovative things happening in coffee', |
| 37 | + date: 'Mar 19', |
| 38 | + commentCount: 24, |
| 39 | + shareCount: 12, |
| 40 | + }, |
| 41 | + ], |
| 42 | + Trending: [ |
| 43 | + { |
| 44 | + id: 1, |
| 45 | + title: 'Ask Me Anything: 10 answers to your questions about coffee', |
| 46 | + date: '2d ago', |
| 47 | + commentCount: 9, |
| 48 | + shareCount: 5, |
| 49 | + }, |
| 50 | + { |
| 51 | + id: 2, |
| 52 | + title: "The worst advice we've ever heard about coffee", |
| 53 | + date: '4d ago', |
| 54 | + commentCount: 1, |
| 55 | + shareCount: 2, |
| 56 | + }, |
| 57 | + ], |
| 58 | + }) |
| 59 | + |
| 60 | + return ( |
| 61 | + <div className="my-8 rounded-lg bg-gradient-to-r from-sky-400 to-blue-600 h-[360px]"> |
| 62 | + <div className="mx-auto w-full max-w-md px-2 py-16 sm:px-0"> |
| 63 | + <Tab.Group> |
| 64 | + <Tab.List className="flex p-1 space-x-1 bg-blue-900/20 rounded-xl"> |
| 65 | + {Object.keys(categories).map((category) => ( |
| 66 | + <Tab |
| 67 | + key={category} |
| 68 | + className={({ selected }) => |
| 69 | + classNames( |
| 70 | + 'w-full py-2.5 text-sm leading-5 font-medium text-blue-700 rounded-lg', |
| 71 | + 'focus:outline-none focus:ring-2 ring-offset-2 ring-offset-blue-400 ring-white ring-opacity-60', |
| 72 | + selected |
| 73 | + ? 'bg-white shadow' |
| 74 | + : 'text-blue-100 hover:bg-white/[0.12] hover:text-white' |
| 75 | + ) |
| 76 | + } |
| 77 | + > |
| 78 | + {category} |
| 79 | + </Tab> |
| 80 | + ))} |
| 81 | + </Tab.List> |
| 82 | + <Tab.Panels className="mt-2"> |
| 83 | + {Object.values(categories).map((posts, idx) => ( |
| 84 | + <Tab.Panel |
| 85 | + key={idx} |
| 86 | + className={classNames( |
| 87 | + 'bg-white rounded-xl p-3', |
| 88 | + 'focus:outline-none focus:ring-2 ring-offset-2 ring-offset-blue-400 ring-white ring-opacity-60' |
| 89 | + )} |
| 90 | + > |
| 91 | + <ul> |
| 92 | + {posts.map((post) => ( |
| 93 | + <li |
| 94 | + key={post.id} |
| 95 | + className="relative p-3 rounded-md hover:bg-gray-100" |
| 96 | + > |
| 97 | + <h3 className="text-sm font-medium leading-5"> |
| 98 | + {post.title} |
| 99 | + </h3> |
| 100 | + |
| 101 | + <ul className="flex mt-1 space-x-1 text-xs font-normal leading-4 text-gray-500"> |
| 102 | + <li>{post.date}</li> |
| 103 | + <li>·</li> |
| 104 | + <li>{post.commentCount} comments</li> |
| 105 | + <li>·</li> |
| 106 | + <li>{post.shareCount} shares</li> |
| 107 | + </ul> |
| 108 | + |
| 109 | + <a |
| 110 | + href="#" |
| 111 | + className={classNames( |
| 112 | + 'absolute inset-0 rounded-md', |
| 113 | + 'focus:z-10 focus:outline-none focus:ring-2 ring-blue-400' |
| 114 | + )} |
| 115 | + /> |
| 116 | + </li> |
| 117 | + ))} |
| 118 | + </ul> |
| 119 | + </Tab.Panel> |
| 120 | + ))} |
| 121 | + </Tab.Panels> |
| 122 | + </Tab.Group> |
| 123 | + </div> |
| 124 | + </div> |
| 125 | + ) |
| 126 | +} |
0 commit comments