ข้ามไปเนื้อหา
WhereUI

ค้นหาในเอกสาร

ค้นหาชื่อ component หรือหน้าเอกสาร

Resizable

จาก shadcn

แบ่งพื้นที่หน้าจอเป็นส่วน ๆ ที่ลากปรับขนาดได้ เช่น รายการคำขออยู่กับรายละเอียด เลือกแนวนอนหรือแนวตั้งได้

รายการคำขอลา
รายละเอียดคำขอของ สมหญิง

ติดตั้ง

Terminal
pnpm dlx shadcn@latest add @whereui/resizable

ต้องผูก registry และติดตั้ง @whereui/theme นำหน้าเสมอเมื่อติดตั้งครั้งแรก

การใช้งาน

import {  ResizableHandle,  ResizablePanel,  ResizablePanelGroup,} from "@/components/ui/resizable"<ResizablePanelGroup orientation="horizontal">  <ResizablePanel defaultSize={40}>รายการ</ResizablePanel>  <ResizableHandle />  <ResizablePanel defaultSize={60}>รายละเอียด</ResizablePanel></ResizablePanelGroup>

ตัวอย่างเพิ่มเติม

แนวตั้ง
รายละเอียดคำขอเบิกค่ารักษา
ประวัติการอนุมัติ

ข้อควรรู้

  • defaultSize เป็นเปอร์เซ็นต์ ผลรวมทุกแผงต้องเท่ากับ 100
  • ใส่ withHandle ที่ ResizableHandle เพื่อแสดงจุดจับตรงกลาง ช่วยให้เห็นว่าลากได้
  • ควรกำหนดความสูงให้กรอบแม่ (เช่น h-48) มิฉะนั้นแผงแนวตั้งจะไม่มีพื้นที่ยืด

ซอร์สโค้ด

components/ui/resizable.tsx
"use client"import { cn } from "cn"import * as ResizablePrimitive from "react-resizable-panels"function ResizablePanelGroup({  className,  ...props}: ResizablePrimitive.GroupProps) {  return (    <ResizablePrimitive.Group      data-slot="resizable-panel-group"      className={cn(        "flex h-full w-full aria-[orientation=vertical]:flex-col",        className      )}      {...props}    />  )}function ResizablePanel({ ...props }: ResizablePrimitive.PanelProps) {  return <ResizablePrimitive.Panel data-slot="resizable-panel" {...props} />}function ResizableHandle({  withHandle,  className,  ...props}: ResizablePrimitive.SeparatorProps & {  withHandle?: boolean}) {  return (    <ResizablePrimitive.Separator      data-slot="resizable-handle"      className={cn(        "relative flex w-px items-center justify-center bg-border ring-offset-background after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-hidden aria-[orientation=horizontal]:h-px aria-[orientation=horizontal]:w-full aria-[orientation=horizontal]:after:left-0 aria-[orientation=horizontal]:after:h-1 aria-[orientation=horizontal]:after:w-full aria-[orientation=horizontal]:after:translate-x-0 aria-[orientation=horizontal]:after:-translate-y-1/2 [&[aria-orientation=horizontal]>div]:rotate-90",        className      )}      {...props}    >      {withHandle && (        <div className="z-10 flex h-6 w-1 shrink-0 rounded-lg bg-border" />      )}    </ResizablePrimitive.Separator>  )}export { ResizableHandle, ResizablePanel, ResizablePanelGroup }