item.tsx
This file
Path
apps/web/src/components/ui/item.tsx
201 lines · 4.7 KiB · TypeScript
Last changed by
Draw text, controls, prose and code from one set of tokensoscabrielbefore adoption60f862e
History of this fileTake it
Give the web its W9 dependencies, components, project nav, line and revision helpers, and a stub for every new pageoscabrielbefore adoption254268a
lines 1–37why, one step back1import { mergeProps } from "@base-ui/react/merge-props";2import { useRender } from "@base-ui/react/use-render";3import { cva, type VariantProps } from "class-variance-authority";4import { cn } from "cn";5import * as React from "react";67import { Separator } from "@/components/ui/separator";89function ItemGroup({ className, ...props }: React.ComponentProps<"div">) {10 return (11 <div12 role="list"13 data-slot="item-group"14 className={cn(15 "group/item-group flex w-full flex-col gap-4 has-data-[size=sm]:gap-2.5 has-data-[size=xs]:gap-2",16 className17 )}18 {...props}19 />20 );21}2223function ItemSeparator({24 className,25 ...props26}: React.ComponentProps<typeof Separator>) {27 return (28 <Separator29 data-slot="item-separator"30 orientation="horizontal"31 className={cn("my-2", className)}32 {...props}33 />34 );35}3637const itemVariants = cva(Draw text, controls, prose and code from one set of tokensoscabrielbefore adoption60f862e
line 38why, one step back38 "group/item focus-visible:border-ring focus-visible:ring-ring/50 [a]:hover:bg-muted text-ui flex w-full flex-wrap items-center rounded-none border transition-colors duration-100 outline-none focus-visible:ring-[3px] [a]:transition-colors",Give the web its W9 dependencies, components, project nav, line and revision helpers, and a stub for every new pageoscabrielbefore adoption254268a
lines 39–132why, one step back39 {40 variants: {41 variant: {42 default: "border-transparent",43 outline: "border-border",44 muted: "bg-muted/50 border-transparent",45 },46 size: {47 default: "gap-2.5 px-3 py-2.5",48 sm: "gap-2.5 px-3 py-2.5",49 xs: "gap-2 px-2.5 py-2 in-data-[slot=dropdown-menu-content]:p-0",50 },51 },52 defaultVariants: {53 variant: "default",54 size: "default",55 },56 }57);5859function Item({60 className,61 variant = "default",62 size = "default",63 render,64 ...props65}: useRender.ComponentProps<"div"> & VariantProps<typeof itemVariants>) {66 return useRender({67 defaultTagName: "div",68 props: mergeProps<"div">(69 {70 className: cn(itemVariants({ variant, size, className })),71 },72 props73 ),74 render,75 state: {76 slot: "item",77 variant,78 size,79 },80 });81}8283const itemMediaVariants = cva(84 "flex shrink-0 items-center justify-center gap-2 group-has-data-[slot=item-description]/item:translate-y-0.5 group-has-data-[slot=item-description]/item:self-start [&_svg]:pointer-events-none",85 {86 variants: {87 variant: {88 default: "bg-transparent",89 icon: "[&_svg:not([class*='size-'])]:size-4",90 image:91 "size-10 overflow-hidden rounded-none group-data-[size=sm]/item:size-8 group-data-[size=xs]/item:size-6 [&_img]:size-full [&_img]:object-cover",92 },93 },94 defaultVariants: {95 variant: "default",96 },97 }98);99100function ItemMedia({101 className,102 variant = "default",103 ...props104}: React.ComponentProps<"div"> & VariantProps<typeof itemMediaVariants>) {105 return (106 <div107 data-slot="item-media"108 data-variant={variant}109 className={cn(itemMediaVariants({ variant, className }))}110 {...props}111 />112 );113}114115function ItemContent({ className, ...props }: React.ComponentProps<"div">) {116 return (117 <div118 data-slot="item-content"119 className={cn(120 "flex flex-1 flex-col gap-1 group-data-[size=xs]/item:gap-0 [&+[data-slot=item-content]]:flex-none",121 className122 )}123 {...props}124 />125 );126}127128function ItemTitle({ className, ...props }: React.ComponentProps<"div">) {129 return (130 <div131 data-slot="item-title"132 className={cn(Draw text, controls, prose and code from one set of tokensoscabrielbefore adoption60f862e
line 133why, one step back133 "text-ui line-clamp-1 flex w-fit items-center gap-2 font-medium underline-offset-4",Give the web its W9 dependencies, components, project nav, line and revision helpers, and a stub for every new pageoscabrielbefore adoption254268a
lines 134–145why, one step back134 className135 )}136 {...props}137 />138 );139}140141function ItemDescription({ className, ...props }: React.ComponentProps<"p">) {142 return (143 <p144 data-slot="item-description"145 className={cn(Draw text, controls, prose and code from one set of tokensoscabrielbefore adoption60f862e
line 146why, one step back146 "text-muted-foreground [&>a:hover]:text-primary text-ui group-data-[size=xs]/item:text-ui line-clamp-2 text-left font-normal [&>a]:underline [&>a]:underline-offset-4",Give the web its W9 dependencies, components, project nav, line and revision helpers, and a stub for every new pageoscabrielbefore adoption254268a
lines 147–201why, one step back147 className148 )}149 {...props}150 />151 );152}153154function ItemActions({ className, ...props }: React.ComponentProps<"div">) {155 return (156 <div157 data-slot="item-actions"158 className={cn("flex items-center gap-2", className)}159 {...props}160 />161 );162}163164function ItemHeader({ className, ...props }: React.ComponentProps<"div">) {165 return (166 <div167 data-slot="item-header"168 className={cn(169 "flex basis-full items-center justify-between gap-2",170 className171 )}172 {...props}173 />174 );175}176177function ItemFooter({ className, ...props }: React.ComponentProps<"div">) {178 return (179 <div180 data-slot="item-footer"181 className={cn(182 "flex basis-full items-center justify-between gap-2",183 className184 )}185 {...props}186 />187 );188}189190export {191 Item,192 ItemMedia,193 ItemContent,194 ItemActions,195 ItemGroup,196 ItemSeparator,197 ItemTitle,198 ItemDescription,199 ItemHeader,200 ItemFooter,201};