瀏覽代碼

button group

Bernt Christian Egeland 9 月之前
父節點
當前提交
e4bb7379e3
共有 2 個文件被更改,包括 111 次插入 和 25 次删除
  1. 83 0
      src/components/ui/button-group.tsx
  2. 28 25
      src/features/vehicles/Components/service-page/UnifiedServiceHeader.tsx

+ 83 - 0
src/components/ui/button-group.tsx

@@ -0,0 +1,83 @@
+import { cva, type VariantProps } from "class-variance-authority"
+import { Slot } from "radix-ui"
+
+import { cn } from "@/lib/utils"
+import { Separator } from "@/components/ui/separator"
+
+const buttonGroupVariants = cva(
+  "flex w-fit items-stretch [&>*]:focus-visible:z-10 [&>*]:focus-visible:relative [&>[data-slot=select-trigger]:not([class*='w-'])]:w-fit [&>input]:flex-1 has-[select[aria-hidden=true]:last-child]:[&>[data-slot=select-trigger]:last-of-type]:rounded-r-md has-[>[data-slot=button-group]]:gap-2",
+  {
+    variants: {
+      orientation: {
+        horizontal:
+          "[&>*:not(:first-child)]:rounded-l-none [&>*:not(:first-child)]:border-l-0 [&>*:not(:last-child)]:rounded-r-none",
+        vertical:
+          "flex-col [&>*:not(:first-child)]:rounded-t-none [&>*:not(:first-child)]:border-t-0 [&>*:not(:last-child)]:rounded-b-none",
+      },
+    },
+    defaultVariants: {
+      orientation: "horizontal",
+    },
+  }
+)
+
+function ButtonGroup({
+  className,
+  orientation,
+  ...props
+}: React.ComponentProps<"div"> & VariantProps<typeof buttonGroupVariants>) {
+  return (
+    <div
+      role="group"
+      data-slot="button-group"
+      data-orientation={orientation}
+      className={cn(buttonGroupVariants({ orientation }), className)}
+      {...props}
+    />
+  )
+}
+
+function ButtonGroupText({
+  className,
+  asChild = false,
+  ...props
+}: React.ComponentProps<"div"> & {
+  asChild?: boolean
+}) {
+  const Comp = asChild ? Slot.Root : "div"
+
+  return (
+    <Comp
+      className={cn(
+        "bg-muted flex items-center gap-2 rounded-md border px-4 text-sm font-medium shadow-xs [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4",
+        className
+      )}
+      {...props}
+    />
+  )
+}
+
+function ButtonGroupSeparator({
+  className,
+  orientation = "vertical",
+  ...props
+}: React.ComponentProps<typeof Separator>) {
+  return (
+    <Separator
+      data-slot="button-group-separator"
+      orientation={orientation}
+      className={cn(
+        "bg-input relative !m-0 self-stretch data-[orientation=vertical]:h-auto",
+        className
+      )}
+      {...props}
+    />
+  )
+}
+
+export {
+  ButtonGroup,
+  ButtonGroupSeparator,
+  ButtonGroupText,
+  buttonGroupVariants,
+}

+ 28 - 25
src/features/vehicles/Components/service-page/UnifiedServiceHeader.tsx

@@ -3,6 +3,7 @@
 import Link from 'next/link'
 import Link from 'next/link'
 import { Badge } from '@/components/ui/badge'
 import { Badge } from '@/components/ui/badge'
 import { Button } from '@/components/ui/button'
 import { Button } from '@/components/ui/button'
+import { ButtonGroup } from '@/components/ui/button-group'
 import { cn } from '@/lib/utils'
 import { cn } from '@/lib/utils'
 import {
 import {
   ArrowLeft,
   ArrowLeft,
@@ -93,31 +94,33 @@ export function UnifiedServiceHeader({
               Save
               Save
             </Button>
             </Button>
           )}
           )}
-          <Button variant="outline" size="sm" onClick={onDownloadPDF} disabled={downloading}>
-            {downloading ? (
-              <Loader2 className="mr-1 h-3.5 w-3.5 animate-spin" />
-            ) : (
-              <Download className="mr-1 h-3.5 w-3.5" />
-            )}
-            PDF
-          </Button>
-          <Button variant="outline" size="sm" onClick={onShowEmail}>
-            <Mail className="mr-1 h-3.5 w-3.5" />
-            Email
-          </Button>
-          <Button variant="outline" size="sm" onClick={onShowShare}>
-            <Globe className="mr-1 h-3.5 w-3.5" />
-            Share
-          </Button>
-          <Button
-            variant="outline"
-            size="sm"
-            className="text-destructive hover:bg-destructive/10"
-            onClick={onDelete}
-          >
-            <Trash2 className="mr-1 h-3.5 w-3.5" />
-            Delete
-          </Button>
+          <ButtonGroup>
+            <Button variant="outline" size="sm" onClick={onDownloadPDF} disabled={downloading}>
+              {downloading ? (
+                <Loader2 className="mr-1 h-3.5 w-3.5 animate-spin" />
+              ) : (
+                <Download className="mr-1 h-3.5 w-3.5" />
+              )}
+              PDF
+            </Button>
+            <Button variant="outline" size="sm" onClick={onShowEmail}>
+              <Mail className="mr-1 h-3.5 w-3.5" />
+              Email
+            </Button>
+            <Button variant="outline" size="sm" onClick={onShowShare}>
+              <Globe className="mr-1 h-3.5 w-3.5" />
+              Share
+            </Button>
+            <Button
+              variant="outline"
+              size="sm"
+              className="text-destructive hover:bg-destructive/10"
+              onClick={onDelete}
+            >
+              <Trash2 className="mr-1 h-3.5 w-3.5" />
+              Delete
+            </Button>
+          </ButtonGroup>
         </div>
         </div>
       </div>
       </div>
       <nav className="flex gap-1 border-b">
       <nav className="flex gap-1 border-b">