Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Improve product list and sidebar

Damian Legawiec30e7423003ab
diff --git a/packages/admin/src/components/ui/sidebar.tsx b/packages/admin/src/components/ui/sidebar.tsx
index 352903d1e0..39e1de11de 100644
--- a/packages/admin/src/components/ui/sidebar.tsx
+++ b/packages/admin/src/components/ui/sidebar.tsx
@@ -1,48 +1,52 @@
-import { cva, type VariantProps } from 'class-variance-authority'
-import { PanelLeftIcon } from 'lucide-react'
-import { Slot } from 'radix-ui'
-import * as React from 'react'
-import { Button } from '@/components/ui/button'
-import { Input } from '@/components/ui/input'
-import { Separator } from '@/components/ui/separator'
+import { cva, type VariantProps } from "class-variance-authority";
+import { PanelLeftIcon } from "lucide-react";
+import { Slot } from "radix-ui";
+import * as React from "react";
+import { Button } from "@/components/ui/button";
+import { Input } from "@/components/ui/input";
+import { Separator } from "@/components/ui/separator";
import {
Sheet,
SheetContent,
SheetDescription,
SheetHeader,
SheetTitle,
-} from '@/components/ui/sheet'
-import { Skeleton } from '@/components/ui/skeleton'
-import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'
-import { useIsMobile } from '@/hooks/use-mobile'
-import { cn } from '@/lib/utils'
-
-const SIDEBAR_COOKIE_NAME = 'sidebar_state'
-const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7
-const SIDEBAR_WIDTH = '220px'
-const SIDEBAR_WIDTH_MOBILE = '220px'
-const SIDEBAR_WIDTH_ICON = '59px'
-const SIDEBAR_KEYBOARD_SHORTCUT = 'b'
+} from "@/components/ui/sheet";
+import { Skeleton } from "@/components/ui/skeleton";
+import {
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+} from "@/components/ui/tooltip";
+import { useIsMobile } from "@/hooks/use-mobile";
+import { cn } from "@/lib/utils";
+
+const SIDEBAR_COOKIE_NAME = "sidebar_state";
+const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
+const SIDEBAR_WIDTH = "220px";
+const SIDEBAR_WIDTH_MOBILE = "220px";
+const SIDEBAR_WIDTH_ICON = "59px";
+const SIDEBAR_KEYBOARD_SHORTCUT = "b";
type SidebarContextProps = {
- state: 'expanded' | 'collapsed'
- open: boolean
- setOpen: (open: boolean) => void
- openMobile: boolean
- setOpenMobile: (open: boolean) => void
- isMobile: boolean
- toggleSidebar: () => void
-}
+ state: "expanded" | "collapsed";
+ open: boolean;
+ setOpen: (open: boolean) => void;
+ openMobile: boolean;
+ setOpenMobile: (open: boolean) => void;
+ isMobile: boolean;
+ toggleSidebar: () => void;
+};
-const SidebarContext = React.createContext<SidebarContextProps | null>(null)
+const SidebarContext = React.createContext<SidebarContextProps | null>(null);
function useSidebar() {
- const context = React.useContext(SidebarContext)
+ const context = React.useContext(SidebarContext);
if (!context) {
- throw new Error('useSidebar must be used within a SidebarProvider.')
+ throw new Error("useSidebar must be used within a SidebarProvider.");
}
- return context
+ return context;
}
function SidebarProvider({
@@ -53,54 +57,57 @@ function SidebarProvider({
style,
children,
...props
-}: React.ComponentProps<'div'> & {
- defaultOpen?: boolean
- open?: boolean
- onOpenChange?: (open: boolean) => void
+}: React.ComponentProps<"div"> & {
+ defaultOpen?: boolean;
+ open?: boolean;
+ onOpenChange?: (open: boolean) => void;
}) {
- const isMobile = useIsMobile()
- const [openMobile, setOpenMobile] = React.useState(false)
+ const isMobile = useIsMobile();
+ const [openMobile, setOpenMobile] = React.useState(false);
// This is the internal state of the sidebar.
// We use openProp and setOpenProp for control from outside the component.
- const [_open, _setOpen] = React.useState(defaultOpen)
- const open = openProp ?? _open
+ const [_open, _setOpen] = React.useState(defaultOpen);
+ const open = openProp ?? _open;
const setOpen = React.useCallback(
(value: boolean | ((value: boolean) => boolean)) => {
- const openState = typeof value === 'function' ? value(open) : value
+ const openState = typeof value === "function" ? value(open) : value;
if (setOpenProp) {
- setOpenProp(openState)
+ setOpenProp(openState);
} else {
- _setOpen(openState)
+ _setOpen(openState);
}
// This sets the cookie to keep the sidebar state.
- document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`
+ document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`;
},
[setOpenProp, open],
- )
+ );
// Helper to toggle the sidebar.
const toggleSidebar = React.useCallback(() => {
- return isMobile ? setOpenMobile((open) => !open) : setOpen((open) => !open)
- }, [isMobile, setOpen, setOpenMobile])
+ return isMobile ? setOpenMobile((open) => !open) : setOpen((open) => !open);
+ }, [isMobile, setOpen, setOpenMobile]);
// Adds a keyboard shortcut to toggle the sidebar.
React.useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
- if (event.key === SIDEBAR_KEYBOARD_SHORTCUT && (event.metaKey || event.ctrlKey)) {
- event.preventDefault()
- toggleSidebar()
+ if (
+ event.key === SIDEBAR_KEYBOARD_SHORTCUT &&
+ (event.metaKey || event.ctrlKey)
+ ) {
+ event.preventDefault();
+ toggleSidebar();
}
- }
+ };
- window.addEventListener('keydown', handleKeyDown)
- return () => window.removeEventListener('keydown', handleKeyDown)
- }, [toggleSidebar])
+ window.addEventListener("keydown", handleKeyDown);
+ return () => window.removeEventListener("keydown", handleKeyDown);
+ }, [toggleSidebar]);
// We add a state so that we can do data-state="expanded" or "collapsed".
// This makes it easier to style the sidebar with Tailwind classes.
- const state = open ? 'expanded' : 'collapsed'
+ const state = open ? "expanded" : "collapsed";
const contextValue = React.useMemo<SidebarContextProps>(
() => ({
@@ -113,7 +120,7 @@ function SidebarProvider({
toggleSidebar,
}),
[state, open, setOpen, isMobile, openMobile, setOpenMobile, toggleSidebar],
- )
+ );
return (
<SidebarContext.Provider value={contextValue}>
@@ -121,13 +128,13 @@ function SidebarProvider({
data-slot="sidebar-wrapper"
style={
{
- '--sidebar-width': SIDEBAR_WIDTH,
- '--sidebar-width-icon': SIDEBAR_WIDTH_ICON,
+ "--sidebar-width": SIDEBAR_WIDTH,
+ "--sidebar-width-icon": SIDEBAR_WIDTH_ICON,
...style,
} as React.CSSProperties
}
className={cn(
- 'group/sidebar-wrapper flex min-h-svh w-full has-data-[variant=inset]:bg-sidebar',
+ "group/sidebar-wrapper flex min-h-svh w-full has-data-[variant=inset]:bg-sidebar",
className,
)}
{...props}
@@ -135,37 +142,37 @@ function SidebarProvider({
{children}
</div>
</SidebarContext.Provider>
- )
+ );
}
function Sidebar({
- side = 'left',
- variant = 'sidebar',
- collapsible = 'offcanvas',
+ side = "left",
+ variant = "sidebar",
+ collapsible = "offcanvas",
className,
children,
dir,
...props
-}: React.ComponentProps<'div'> & {
- side?: 'left' | 'right'
- variant?: 'sidebar' | 'floating' | 'inset'
- collapsible?: 'offcanvas' | 'icon' | 'none'
+}: React.ComponentProps<"div"> & {
+ side?: "left" | "right";
+ variant?: "sidebar" | "floating" | "inset";
+ collapsible?: "offcanvas" | "icon" | "none";
}) {
- const { isMobile, state, openMobile, setOpenMobile } = useSidebar()
+ const { isMobile, state, openMobile, setOpenMobile } = useSidebar();
- if (collapsible === 'none') {
+ if (collapsible === "none") {
return (
<div
data-slot="sidebar"
className={cn(
- 'flex h-full w-(--sidebar-width) flex-col bg-sidebar text-sidebar-foreground',
+ "flex h-full w-(--sidebar-width) flex-col bg-sidebar text-sidebar-foreground",
className,
)}
{...props}
>
{children}
</div>
- )
+ );
}
if (isMobile) {
@@ -179,7 +186,7 @@ function Sidebar({
className="w-(--sidebar-width) bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden"
style={
{
- '--sidebar-width': SIDEBAR_WIDTH_MOBILE,
+ "--sidebar-width": SIDEBAR_WIDTH_MOBILE,
} as React.CSSProperties
}
side={side}
@@ -191,14 +198,14 @@ function Sidebar({
<div className="flex h-full w-full flex-col">{children}</div>
</SheetContent>
</Sheet>
- )
+ );
}
return (
<div
className="group peer hidden text-sidebar-foreground md:block"
data-state={state}
- data-collapsible={state === 'collapsed' ? collapsible : ''}
+ data-collapsible={state === "collapsed" ? collapsible : ""}
data-variant={variant}
data-side={side}
data-slot="sidebar"
@@ -207,23 +214,23 @@ function Sidebar({
<div
data-slot="sidebar-gap"
className={cn(
- 'relative w-(--sidebar-width) bg-transparent transition-[width] duration-200 ease-linear',
- 'group-data-[collapsible=offcanvas]:w-0',
- 'group-data-[side=right]:rotate-180',
- variant === 'floating' || variant === 'inset'
- ? 'group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]'
- : 'group-data-[collapsible=icon]:w-(--sidebar-width-icon)',
+ "relative w-(--sidebar-width) bg-transparent transition-[width] duration-200 ease-linear",
+ "group-data-[collapsible=offcanvas]:w-0",
+ "group-data-[side=right]:rotate-180",
+ variant === "floating" || variant === "inset"
+ ? "group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]"
+ : "group-data-[collapsible=icon]:w-(--sidebar-width-icon)",
)}
/>
<div
data-slot="sidebar-container"
data-side={side}
className={cn(
- 'fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear data-[side=left]:left-0 data-[side=left]:group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)] data-[side=right]:right-0 data-[side=right]:group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)] md:flex',
+ "fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear data-[side=left]:left-0 data-[side=left]:group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)] data-[side=right]:right-0 data-[side=right]:group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)] md:flex",
// Adjust the padding for floating and inset variants.
- variant === 'floating' || variant === 'inset'
- ? 'p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]'
- : 'group-data-[collapsible=icon]:w-(--sidebar-width-icon)',
+ variant === "floating" || variant === "inset"
+ ? "p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]"
+ : "group-data-[collapsible=icon]:w-(--sidebar-width-icon)",
className,
)}
{...props}
@@ -237,11 +244,15 @@ function Sidebar({
</div>
</div>
</div>
- )
+ );
}
-function SidebarTrigger({ className, onClick, ...props }: React.ComponentProps<typeof Button>) {
- const { toggleSidebar } = useSidebar()
+function SidebarTrigger({
+ className,
+ onClick,
+ ...props
+}: React.ComponentProps<typeof Button>) {
+ const { toggleSidebar } = useSidebar();
return (
<Button
@@ -251,19 +262,19 @@ function SidebarTrigger({ className, onClick, ...props }: React.ComponentProps<t
size="icon-sm"
className={cn(className)}
onClick={(event) => {
- onClick?.(event)
- toggleSidebar()
+ onClick?.(event);
+ toggleSidebar();
}}
{...props}
>
<PanelLeftIcon />
<span className="sr-only">Toggle Sidebar</span>
</Button>
- )
+ );
}
-function SidebarRail({ className, ...props }: React.ComponentProps<'button'>) {
- const { toggleSidebar } = useSidebar()
+function SidebarRail({ className, ...props }: React.ComponentProps<"button">) {
+ const { toggleSidebar } = useSidebar();
return (
<button
@@ -274,220 +285,229 @@ function SidebarRail({ className, ...props }: React.ComponentProps<'button'>) {
onClick={toggleSidebar}
title="Toggle Sidebar"
className={cn(
- 'absolute inset-y-0 z-20 hidden w-4 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:start-1/2 after:w-[2px] hover:after:bg-sidebar-border sm:flex ltr:-translate-x-1/2 rtl:-translate-x-1/2',
- 'in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize',
- '[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize',
- 'group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full hover:group-data-[collapsible=offcanvas]:bg-sidebar',
- '[[data-side=left][data-collapsible=offcanvas]_&]:-right-2',
- '[[data-side=right][data-collapsible=offcanvas]_&]:-left-2',
+ "absolute inset-y-0 z-20 hidden w-4 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:start-1/2 after:w-[2px] hover:after:bg-sidebar-border sm:flex ltr:-translate-x-1/2 rtl:-translate-x-1/2",
+ "in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize",
+ "[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize",
+ "group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full hover:group-data-[collapsible=offcanvas]:bg-sidebar",
+ "[[data-side=left][data-collapsible=offcanvas]_&]:-right-2",
+ "[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",
className,
)}
{...props}
/>
- )
+ );
}
-function SidebarInset({ className, ...props }: React.ComponentProps<'main'>) {
+function SidebarInset({ className, ...props }: React.ComponentProps<"main">) {
return (
<main
data-slot="sidebar-inset"
className={cn(
- 'relative flex w-full flex-1 flex-col bg-background md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow-sm md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2',
+ "relative flex w-full flex-1 flex-col bg-background md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow-sm md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2",
className,
)}
{...props}
/>
- )
+ );
}
-function SidebarInput({ className, ...props }: React.ComponentProps<typeof Input>) {
+function SidebarInput({
+ className,
+ ...props
+}: React.ComponentProps<typeof Input>) {
return (
<Input
data-slot="sidebar-input"
data-sidebar="input"
- className={cn('h-8 w-full bg-background shadow-none', className)}
+ className={cn("h-8 w-full bg-background shadow-none", className)}
{...props}
/>
- )
+ );
}
-function SidebarHeader({ className, ...props }: React.ComponentProps<'div'>) {
+function SidebarHeader({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="sidebar-header"
data-sidebar="header"
className={cn(
- 'flex flex-col gap-0 px-2 group-data-[collapsible=icon]:px-0 group-data-[collapsible=icon]:items-center',
+ "flex flex-col gap-0 px-2 group-data-[collapsible=icon]:px-0 group-data-[collapsible=icon]:items-center",
className,
)}
{...props}
/>
- )
+ );
}
-function SidebarFooter({ className, ...props }: React.ComponentProps<'div'>) {
+function SidebarFooter({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="sidebar-footer"
data-sidebar="footer"
className={cn(
- 'flex flex-col gap-0 p-2 mt-auto border-t border-sidebar-border group-data-[collapsible=icon]:px-0 group-data-[collapsible=icon]:items-center',
+ "flex flex-col gap-0 p-2 mt-auto border-t border-sidebar-border group-data-[collapsible=icon]:px-0 group-data-[collapsible=icon]:items-center",
className,
)}
{...props}
/>
- )
+ );
}
-function SidebarSeparator({ className, ...props }: React.ComponentProps<typeof Separator>) {
+function SidebarSeparator({
+ className,
+ ...props
+}: React.ComponentProps<typeof Separator>) {
return (
<Separator
data-slot="sidebar-separator"
data-sidebar="separator"
- className={cn('mx-2 w-auto bg-sidebar-border', className)}
+ className={cn("mx-2 w-auto bg-sidebar-border", className)}
{...props}
/>
- )
+ );
}
-function SidebarContent({ className, ...props }: React.ComponentProps<'div'>) {
+function SidebarContent({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="sidebar-content"
data-sidebar="content"
className={cn(
- 'no-scrollbar flex min-h-0 flex-1 flex-col gap-0 pt-2 overflow-auto group-data-[collapsible=icon]:overflow-visible',
+ "no-scrollbar flex min-h-0 flex-1 flex-col gap-0 pt-2 overflow-auto group-data-[collapsible=icon]:overflow-visible",
className,
)}
{...props}
/>
- )
+ );
}
-function SidebarGroup({ className, ...props }: React.ComponentProps<'div'>) {
+function SidebarGroup({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="sidebar-group"
data-sidebar="group"
className={cn(
- 'relative flex w-full min-w-0 flex-col px-3 py-0 group-data-[collapsible=icon]:px-0 group-data-[collapsible=icon]:items-center',
+ "relative flex w-full min-w-0 flex-col px-3 py-0 group-data-[collapsible=icon]:px-0 group-data-[collapsible=icon]:items-center",
className,
)}
{...props}
/>
- )
+ );
}
function SidebarGroupLabel({
className,
asChild = false,
...props
-}: React.ComponentProps<'div'> & { asChild?: boolean }) {
- const Comp = asChild ? Slot.Root : 'div'
+}: React.ComponentProps<"div"> & { asChild?: boolean }) {
+ const Comp = asChild ? Slot.Root : "div";
return (
<Comp
data-slot="sidebar-group-label"
data-sidebar="group-label"
className={cn(
- 'flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium text-sidebar-foreground/70 ring-sidebar-ring outline-hidden transition-[margin,opacity] duration-200 ease-linear group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0 focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0',
+ "flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium text-sidebar-foreground/70 ring-sidebar-ring outline-hidden transition-[margin,opacity] duration-200 ease-linear group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0 focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
className,
)}
{...props}
/>
- )
+ );
}
function SidebarGroupAction({
className,
asChild = false,
...props
-}: React.ComponentProps<'button'> & { asChild?: boolean }) {
- const Comp = asChild ? Slot.Root : 'button'
+}: React.ComponentProps<"button"> & { asChild?: boolean }) {
+ const Comp = asChild ? Slot.Root : "button";
return (
<Comp
data-slot="sidebar-group-action"
data-sidebar="group-action"
className={cn(
- 'absolute top-3.5 right-3 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground ring-sidebar-ring outline-hidden transition-transform group-data-[collapsible=icon]:hidden after:absolute after:-inset-2 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 md:after:hidden [&>svg]:size-4 [&>svg]:shrink-0',
+ "absolute top-3.5 right-3 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground ring-sidebar-ring outline-hidden transition-transform group-data-[collapsible=icon]:hidden after:absolute after:-inset-2 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 md:after:hidden [&>svg]:size-4 [&>svg]:shrink-0",
className,
)}
{...props}
/>
- )
+ );
}
-function SidebarGroupContent({ className, ...props }: React.ComponentProps<'div'>) {
+function SidebarGroupContent({
+ className,
+ ...props
+}: React.ComponentProps<"div">) {
return (
<div
data-slot="sidebar-group-content"
data-sidebar="group-content"
- className={cn('w-full text-sm', className)}
+ className={cn("w-full text-sm", className)}
{...props}
/>
- )
+ );
}
-function SidebarMenu({ className, ...props }: React.ComponentProps<'ul'>) {
+function SidebarMenu({ className, ...props }: React.ComponentProps<"ul">) {
return (
<ul
data-slot="sidebar-menu"
data-sidebar="menu"
- className={cn('flex w-full min-w-0 flex-col gap-1', className)}
+ className={cn("flex w-full min-w-0 flex-col gap-1", className)}
{...props}
/>
- )
+ );
}
-function SidebarMenuItem({ className, ...props }: React.ComponentProps<'li'>) {
+function SidebarMenuItem({ className, ...props }: React.ComponentProps<"li">) {
return (
<li
data-slot="sidebar-menu-item"
data-sidebar="menu-item"
- className={cn('group/menu-item relative', className)}
+ className={cn("group/menu-item relative", className)}
{...props}
/>
- )
+ );
}
const sidebarMenuButtonVariants = cva(
- 'peer/menu-button group/menu-button flex w-full items-center overflow-hidden rounded-xl p-1 text-left text-base text-gray-800 ring-sidebar-ring outline-hidden transition-colors duration-100 ease-in-out group-has-data-[sidebar=menu-action]/menu-item:pr-8 group-data-[collapsible=icon]:size-10! group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:overflow-visible group-data-[collapsible=icon]:p-0! group-data-[collapsible=icon]:[&>span:last-child]:hidden hover:bg-gray-200/50 hover:text-zinc-950 focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-open:hover:bg-gray-200/50 data-open:hover:text-zinc-950 data-active:bg-white data-active:text-zinc-950 data-active:font-semibold data-active:shadow-nav [&>span:last-child]:truncate',
+ "peer/menu-button group/menu-button flex gap-2 w-full items-center overflow-hidden rounded-xl p-1 text-left text-base text-gray-800 ring-sidebar-ring outline-hidden transition-colors duration-100 ease-in-out group-has-data-[sidebar=menu-action]/menu-item:pr-8 group-data-[collapsible=icon]:size-10! group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:overflow-visible group-data-[collapsible=icon]:p-0! group-data-[collapsible=icon]:[&>span:last-child]:hidden hover:bg-gray-200/50 hover:text-zinc-950 focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-open:hover:bg-gray-200/50 data-open:hover:text-zinc-950 data-active:bg-white data-active:text-zinc-950 data-active:font-semibold data-active:shadow-nav [&>span:last-child]:truncate",
{
variants: {
variant: {
- default: '',
+ default: "",
outline:
- 'bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]',
+ "bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]",
},
size: {
- default: 'h-8 text-base',
- sm: 'h-7 text-xs',
- lg: 'h-12 text-base group-data-[collapsible=icon]:p-0!',
+ default: "h-8 text-base",
+ sm: "h-7 text-xs",
+ lg: "h-12 text-base group-data-[collapsible=icon]:p-0!",
},
},
defaultVariants: {
- variant: 'default',
- size: 'default',
+ variant: "default",
+ size: "default",
},
},
-)
+);
function SidebarMenuButton({
asChild = false,
isActive = false,
- variant = 'default',
- size = 'default',
+ variant = "default",
+ size = "default",
tooltip,
className,
...props
-}: React.ComponentProps<'button'> & {
- asChild?: boolean
- isActive?: boolean
- tooltip?: string | React.ComponentProps<typeof TooltipContent>
+}: React.ComponentProps<"button"> & {
+ asChild?: boolean;
+ isActive?: boolean;
+ tooltip?: string | React.ComponentProps<typeof TooltipContent>;
} & VariantProps<typeof sidebarMenuButtonVariants>) {
- const Comp = asChild ? Slot.Root : 'button'
- const { isMobile, state } = useSidebar()
+ const Comp = asChild ? Slot.Root : "button";
+ const { isMobile, state } = useSidebar();
const button = (
<Comp
@@ -498,16 +518,16 @@ function SidebarMenuButton({
className={cn(sidebarMenuButtonVariants({ variant, size }), className)}
{...props}
/>
- )
+ );
if (!tooltip) {
- return button
+ return button;
}
- if (typeof tooltip === 'string') {
+ if (typeof tooltip === "string") {
tooltip = {
children: tooltip,
- }
+ };
}
return (
@@ -516,11 +536,11 @@ function SidebarMenuButton({
<TooltipContent
side="right"
align="center"
- hidden={state !== 'collapsed' || isMobile}
+ hidden={state !== "collapsed" || isMobile}
{...tooltip}
/>
</Tooltip>
- )
+ );
}
function SidebarMenuAction({
@@ -528,111 +548,122 @@ function SidebarMenuAction({
asChild = false,
showOnHover = false,
...props
-}: React.ComponentProps<'button'> & {
- asChild?: boolean
- showOnHover?: boolean
+}: React.ComponentProps<"button"> & {
+ asChild?: boolean;
+ showOnHover?: boolean;
}) {
- const Comp = asChild ? Slot.Root : 'button'
+ const Comp = asChild ? Slot.Root : "button";
return (
<Comp
data-slot="sidebar-menu-action"
data-sidebar="menu-action"
className={cn(
- 'absolute top-1.5 right-1 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground ring-sidebar-ring outline-hidden transition-transform group-data-[collapsible=icon]:hidden peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[size=default]/menu-button:top-1.5 peer-data-[size=lg]/menu-button:top-2.5 peer-data-[size=sm]/menu-button:top-1 after:absolute after:-inset-2 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 md:after:hidden [&>svg]:size-4 [&>svg]:shrink-0',
+ "absolute top-1.5 right-1 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground ring-sidebar-ring outline-hidden transition-transform group-data-[collapsible=icon]:hidden peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[size=default]/menu-button:top-1.5 peer-data-[size=lg]/menu-button:top-2.5 peer-data-[size=sm]/menu-button:top-1 after:absolute after:-inset-2 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 md:after:hidden [&>svg]:size-4 [&>svg]:shrink-0",
showOnHover &&
- 'group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 peer-data-active/menu-button:text-sidebar-accent-foreground aria-expanded:opacity-100 md:opacity-0',
+ "group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 peer-data-active/menu-button:text-sidebar-accent-foreground aria-expanded:opacity-100 md:opacity-0",
className,
)}
{...props}
/>
- )
+ );
}
-function SidebarMenuBadge({ className, ...props }: React.ComponentProps<'div'>) {
+function SidebarMenuBadge({
+ className,
+ ...props
+}: React.ComponentProps<"div">) {
return (
<div
data-slot="sidebar-menu-badge"
data-sidebar="menu-badge"
className={cn(
- 'pointer-events-none absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium text-sidebar-foreground tabular-nums select-none group-data-[collapsible=icon]:hidden peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[size=default]/menu-button:top-1.5 peer-data-[size=lg]/menu-button:top-2.5 peer-data-[size=sm]/menu-button:top-1 peer-data-active/menu-button:text-sidebar-accent-foreground',
+ "pointer-events-none absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium text-sidebar-foreground tabular-nums select-none group-data-[collapsible=icon]:hidden peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[size=default]/menu-button:top-1.5 peer-data-[size=lg]/menu-button:top-2.5 peer-data-[size=sm]/menu-button:top-1 peer-data-active/menu-button:text-sidebar-accent-foreground",
className,
)}
{...props}
/>
- )
+ );
}
function SidebarMenuSkeleton({
className,
showIcon = false,
...props
-}: React.ComponentProps<'div'> & {
- showIcon?: boolean
+}: React.ComponentProps<"div"> & {
+ showIcon?: boolean;
}) {
// Random width between 50 to 90%.
const [width] = React.useState(() => {
- return `${Math.floor(Math.random() * 40) + 50}%`
- })
+ return `${Math.floor(Math.random() * 40) + 50}%`;
+ });
return (
<div
data-slot="sidebar-menu-skeleton"
data-sidebar="menu-skeleton"
- className={cn('flex h-8 items-center gap-2 rounded-md px-2', className)}
+ className={cn("flex h-8 items-center gap-2 rounded-md px-2", className)}
{...props}
>
- {showIcon && <Skeleton className="size-4 rounded-md" data-sidebar="menu-skeleton-icon" />}
+ {showIcon && (
+ <Skeleton
+ className="size-4 rounded-md"
+ data-sidebar="menu-skeleton-icon"
+ />
+ )}
<Skeleton
className="h-4 max-w-(--skeleton-width) flex-1"
data-sidebar="menu-skeleton-text"
style={
{
- '--skeleton-width': width,
+ "--skeleton-width": width,
} as React.CSSProperties
}
/>
</div>
- )
+ );
}
-function SidebarMenuSub({ className, ...props }: React.ComponentProps<'ul'>) {
+function SidebarMenuSub({ className, ...props }: React.ComponentProps<"ul">) {
return (
<ul
data-slot="sidebar-menu-sub"
data-sidebar="menu-sub"
className={cn(
- 'relative ml-4 flex min-w-0 flex-col pt-1 pl-4 group-data-[collapsible=icon]:hidden before:absolute before:left-0 before:top-0 before:bottom-1 before:w-px before:bg-gray-200',
+ "relative ml-4 flex min-w-0 flex-col pt-1 pl-4 group-data-[collapsible=icon]:hidden before:absolute before:left-0 before:top-0 before:bottom-1 before:w-px before:bg-gray-200",
className,
)}
{...props}
/>
- )
+ );
}
-function SidebarMenuSubItem({ className, ...props }: React.ComponentProps<'li'>) {
+function SidebarMenuSubItem({
+ className,
+ ...props
+}: React.ComponentProps<"li">) {
return (
<li
data-slot="sidebar-menu-sub-item"
data-sidebar="menu-sub-item"
- className={cn('group/menu-sub-item relative', className)}
+ className={cn("group/menu-sub-item relative", className)}
{...props}
/>
- )
+ );
}
function SidebarMenuSubButton({
asChild = false,
- size = 'md',
+ size = "md",
isActive = false,
className,
...props
-}: React.ComponentProps<'a'> & {
- asChild?: boolean
- size?: 'sm' | 'md'
- isActive?: boolean
+}: React.ComponentProps<"a"> & {
+ asChild?: boolean;
+ size?: "sm" | "md";
+ isActive?: boolean;
}) {
- const Comp = asChild ? Slot.Root : 'a'
+ const Comp = asChild ? Slot.Root : "a";
return (
<Comp
@@ -641,12 +672,12 @@ function SidebarMenuSubButton({
data-size={size}
data-active={isActive}
className={cn(
- 'relative flex h-7 min-w-0 items-center gap-2 overflow-hidden rounded-xl p-1 text-gray-800 ring-sidebar-ring outline-hidden group-data-[collapsible=icon]:hidden hover:bg-gray-50 hover:text-zinc-950 focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[size=md]:text-base data-[size=sm]:text-xs data-active:font-semibold data-active:text-zinc-950 data-active:bg-transparent data-active:shadow-none data-active:before:absolute data-active:before:-left-4 data-active:before:top-[10%] data-active:before:h-[80%] data-active:before:w-[3px] data-active:before:rounded-sm data-active:before:bg-zinc-950 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0',
+ "relative flex h-7 min-w-0 items-center gap-2 overflow-hidden rounded-xl p-1 text-gray-800 ring-sidebar-ring outline-hidden group-data-[collapsible=icon]:hidden hover:bg-gray-50 hover:text-zinc-950 focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[size=md]:text-base data-[size=sm]:text-xs data-active:font-semibold data-active:text-zinc-950 data-active:bg-transparent data-active:shadow-none data-active:before:absolute data-active:before:-left-4 data-active:before:top-[10%] data-active:before:h-[80%] data-active:before:w-[3px] data-active:before:rounded-sm data-active:before:bg-zinc-950 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
className,
)}
{...props}
/>
- )
+ );
}
export {
@@ -674,4 +705,4 @@ export {
SidebarSeparator,
SidebarTrigger,
useSidebar,
-}
+};
diff --git a/packages/admin/src/tables/products.tsx b/packages/admin/src/tables/products.tsx
index 959e141484..56233d3fd2 100644
--- a/packages/admin/src/tables/products.tsx
+++ b/packages/admin/src/tables/products.tsx
@@ -1,20 +1,20 @@
-import { Link } from '@tanstack/react-router'
-import { PackageIcon } from 'lucide-react'
-import { StatusBadge } from '@/components/ui/badge'
-import { formatPrice, formatRelativeTime } from '@/lib/formatters'
-import { defineTable } from '@/lib/table-registry'
+import { Link } from "@tanstack/react-router";
+import { PackageIcon } from "lucide-react";
+import { StatusBadge } from "@/components/ui/badge";
+import { formatPrice, formatRelativeTime } from "@/lib/formatters";
+import { defineTable } from "@/lib/table-registry";
-defineTable('products', {
- title: 'Products',
- searchParam: 'multi_search',
- searchPlaceholder: 'Search products...',
- defaultSort: { field: 'updated_at', direction: 'desc' },
+defineTable("products", {
+ title: "Products",
+ searchParam: "multi_search",
+ searchPlaceholder: "Search products...",
+ defaultSort: { field: "updated_at", direction: "desc" },
emptyIcon: <PackageIcon className="size-8 text-muted-foreground/50" />,
- emptyMessage: 'No products found',
+ emptyMessage: "No products found",
columns: [
{
- key: 'name',
- label: 'Name',
+ key: "name",
+ label: "Name",
sortable: true,
filterable: true,
default: true,
@@ -36,89 +36,112 @@ defineTable('products', {
)}
</div>
<div className="min-w-0">
- <div className="truncate font-medium text-zinc-950">{product.name}</div>
+ <div className="truncate font-medium text-zinc-950">
+ {product.name}
+ </div>
</div>
</Link>
),
},
{
- key: 'status',
- label: 'Status',
+ key: "status",
+ label: "Status",
sortable: true,
filterable: true,
default: true,
- filterType: 'status',
+ filterType: "status",
filterOptions: [
- { value: 'draft', label: 'Draft' },
- { value: 'active', label: 'Active' },
- { value: 'archived', label: 'Archived' },
+ { value: "draft", label: "Draft" },
+ { value: "active", label: "Active" },
+ { value: "archived", label: "Archived" },
],
render: (product) => <StatusBadge status={product.status} />,
},
{
- key: 'inventory',
- label: 'Inventory',
+ key: "inventory",
+ label: "Inventory",
sortable: false,
filterable: false,
default: true,
render: (product) => {
- if (!product.in_stock && !product.backorderable) {
- return <span className="text-sm text-destructive">Out of stock</span>
- }
- if (product.backorderable && !product.in_stock) {
- return <span className="text-sm text-muted-foreground">On backorder</span>
- }
- return <span className="text-sm text-muted-foreground">In stock</span>
+ const variantCount = product.variant_count;
+
+ const inventoryStatus =
+ !product.in_stock && !product.backorderable ? (
+ <span className="text-sm text-destructive">Out of stock</span>
+ ) : product.backorderable && !product.in_stock ? (
+ <span className="text-sm text-muted-foreground">On backorder</span>
+ ) : (
+ <span className="text-sm text-muted-foreground">
+ {product.total_on_hand} in stock
+ </span>
+ );
+
+ return (
+ <span>
+ {inventoryStatus}
+ {variantCount > 1 ? (
+ <>
+ &nbsp; &#8211; &nbsp;
+ <span className="text-sm text-muted-foreground">
+ {variantCount} variants
+ </span>
+ </>
+ ) : (
+ ""
+ )}
+ </span>
+ );
},
},
{
- key: 'sku',
- label: 'SKU',
+ key: "sku",
+ label: "SKU",
sortable: false,
filterable: true,
default: false,
- ransackAttribute: 'master_sku',
- className: 'text-sm text-muted-foreground',
- render: (product) => product.sku ?? '—',
+ ransackAttribute: "master_sku",
+ className: "text-sm text-muted-foreground",
+ render: (product) => product.sku ?? "—",
},
{
- key: 'price',
- label: 'Price',
+ key: "price",
+ label: "Price",
sortable: true,
filterable: true,
default: true,
- filterType: 'number',
- ransackAttribute: 'master_price',
- className: 'text-right tabular-nums whitespace-nowrap',
- render: (product) => (product.price ? formatPrice(product.price) : '—'),
+ filterType: "number",
+ ransackAttribute: "master_price",
+ className: "text-right tabular-nums whitespace-nowrap",
+ render: (product) => (product.price ? formatPrice(product.price) : "—"),
},
{
- key: 'created_at',
- label: 'Created at',
+ key: "created_at",
+ label: "Created at",
sortable: true,
filterable: true,
default: false,
- filterType: 'date',
- className: 'text-sm text-muted-foreground whitespace-nowrap',
+ filterType: "date",
+ className: "text-sm text-muted-foreground whitespace-nowrap",
render: (product) => formatRelativeTime(product.created_at),
},
{
- key: 'updated_at',
- label: 'Updated at',
+ key: "updated_at",
+ label: "Updated at",
sortable: true,
filterable: true,
default: false,
- filterType: 'date',
- className: 'text-sm text-muted-foreground whitespace-nowrap',
+ filterType: "date",
+ className: "text-sm text-muted-foreground whitespace-nowrap",
render: (product) => formatRelativeTime(product.updated_at),
},
{
- key: 'in_stock',
- label: 'In Stock',
+ key: "in_stock",
+ label: "In Stock",
filterable: true,
- filterType: 'boolean',
+ filterType: "boolean",
displayable: false,
default: false,
},
],
-})
+});
diff --git a/packages/sdk/src/types/generated/AdminProduct.ts b/packages/sdk/src/types/generated/AdminProduct.ts
new file mode 100644
index 0000000000..05e6d398e6
--- /dev/null
+++ b/packages/sdk/src/types/generated/AdminProduct.ts
@@ -0,0 +1,48 @@
+// Typelizer digest 00c73974dea37f5056ddb23737259762
+//
+// DO NOT MODIFY: This file was automatically generated by Typelizer.
+import type {AdminPrice, AdminImage, AdminVariant, AdminOptionType, AdminTaxon, AdminMetafield, AdminShippingCategory, AdminTaxCategory} from '@/types'
+
+type AdminProduct = {
+ id: string;
+ name: string;
+ description: string | null;
+ slug: string;
+ meta_description: string | null;
+ meta_keywords: string | null;
+ variant_count: number;
+ available_on: string | null;
+ created_at: string;
+ updated_at: string;
+ purchasable: boolean;
+ in_stock: boolean;
+ backorderable: boolean;
+ available: boolean;
+ default_variant_id: string;
+ thumbnail_url: string | null;
+ tags: Array<string>;
+ price: AdminPrice;
+ original_price: AdminPrice | null;
+ images?: Array<AdminImage>;
+ variants?: Array<AdminVariant>;
+ default_variant?: AdminVariant;
+ master_variant?: AdminVariant;
+ option_types?: Array<AdminOptionType>;
+ taxons?: Array<AdminTaxon>;
+ metafields?: Array<AdminMetafield>;
+ status: string;
+ make_active_at: string | null;
+ discontinue_on: string | null;
+ meta_title: string | null;
+ promotionable: boolean;
+ total_on_hand: number | null;
+ deleted_at: string | null;
+ shipping_category_id: string | null;
+ tax_category_id: string | null;
+ cost_price: string | null;
+ cost_currency: string | null;
+ shipping_category?: AdminShippingCategory;
+ tax_category?: AdminTaxCategory;
+}
+
+export default AdminProduct;
diff --git a/packages/sdk/src/zod/generated/AdminProduct.ts b/packages/sdk/src/zod/generated/AdminProduct.ts
index 0db901b769..78a4877f54 100644
--- a/packages/sdk/src/zod/generated/AdminProduct.ts
+++ b/packages/sdk/src/zod/generated/AdminProduct.ts
@@ -41,6 +41,7 @@ export const AdminProductSchema: z.ZodObject<any> = z.object({
discontinue_on: z.string().nullable(),
meta_title: z.string().nullable(),
promotionable: z.boolean(),
+ total_on_hand: z.number().nullable(),
deleted_at: z.string().nullable(),
shipping_category_id: z.string().nullable(),
tax_category_id: z.string().nullable(),