InitStudioDocsBookmarksToolsAsk
B
Back
Oct 28, 2026

Design Component Docs

บทเรียนที่ 1

Install commands

InstallCommandsBlock แสดงชุดคำสั่งใน code block พร้อมชื่อไฟล์ ปุ่มคัดลอก และปุ่มเปิดดูโค้ดทั้งหมด ระบุประเภทด้วย filename หรือ language ไอคอนจะเปลี่ยนตามประเภท เช่น react, typescript, npm, pnpm, python, css, html, mdx ส่วนประเภทอื่นใช้ไอคอนโค้ดทั่วไป

install.sh
1npm install motion2npx skills add jakubkrehel/skills3npm install loading-dev4npm install sonner5npm install agentation -D6npx -y react-scan@latest init7npm i torph8pnpm dlx shadcn@latest init -t [framework]9pnpm add lucide-react10pnpm install cmdk11pnpm i vaul12npm install @dnd-kit/react13npm install @xyflow/react14npm install driver.js15npx shadcn@latest add @svgl/sanity16npm install @web-kits/audio17npm install cuelume

Drawing controls

ภาพเทคนิคโคมไฟตั้งโต๊ะ (concept) สลับ Expanded กับ Assembled ซูม จิ้มชิ้นส่วนเพื่อเปิดเมนู Parts ปรับสีหรือเติมสี ปรับขนาด แล้วดาวน์โหลดเป็น SVG, PNG หรือ PDF

<iframe src="/teardown" title="Desk lamp technical drawing" className="h-[640px] w-full rounded-2xl" />

Component catalog

ตัวอย่าง component ที่ยังเก็บไว้ในหน้านี้

Code

CustomPre แสดง code block พร้อมชื่อไฟล์และปุ่มคัดลอก

hello.tsx
1xprint("Hello, World!")2xprint("Hello, World!")3xprint("Hello, World!")4xprint("Hello, World!")5npm install motion
token.ts
type Token = string
theme.css
:root { color: black; }
index.html
<p>Hello</p>
note.mdx
# Note

Concentric radius

ตัวอย่าง interactive สำหรับเปรียบเทียบมุมโค้งของพื้นผิวที่ซ้อนกัน ปรับค่า inner radius และ padding เพื่อดูว่า outer radius ควรสัมพันธ์กันอย่างไร

Radius formula

แสดงความสัมพันธ์เป็น block แยก และแก้ข้อความในแต่ละส่วนได้ด้วย outerLabel, innerLabel และ paddingLabel

กรอบนอก=พื้นด้านใน+ระยะห่าง
<ConcentricRadiusFormula  outerLabel="กรอบนอก"  innerLabel="พื้นด้านใน"  paddingLabel="ระยะห่าง"/>

Interactive demo

ด้านซ้ายใช้ radius เท่ากันทั้งกรอบนอกและพื้นด้านใน ส่วนด้านขวาเพิ่ม radius ด้านนอกตามระยะ padding เปิด Show Values เพื่อดูตัวเลขประกอบ

padding: 8px
12px
12px
Same radius on both layers
12px
20px
Concentric corners
outer radius=inner radius+padding

มุมด้านนอกต้องโค้งกว้างกว่ามุมด้านในเท่ากับระยะห่างระหว่างสองชั้น เพื่อให้ขอบวิ่งขนานกัน ตอนนี้ inner radius 12px + padding 8px = outer radius 20px

ซ้ายใช้ radius เท่ากัน · ขวาคำนวณตามระยะ inset
Outer radius22px
Inner radius14px
Padding8px

Resource grid

กริดการ์ดลิงก์สองคอลัมน์ แต่ละใบมีภาพ ชื่อ และคำอธิบายสั้น ๆ ใส่ image สำหรับภาพปกแนวนอน หรือ icon สำหรับโลโก้สี่เหลี่ยมที่วางกลางกรอบ ลิงก์ภายนอกจะเปิดในแท็บใหม่ ถ้าใส่ moreHref แถวล่างจะจางลงและมีปุ่มไปยังรายการทั้งหมด

Open Graph coverInitStudio notes
Interface illustrationsInitStudio
MotionAnimation library for React
(opens in a new tab)
Animations on the WebEmil Kowalski
(opens in a new tab)
View all tools
<ResourceGrid moreHref="/interface/Tools" moreLabel="View all tools">  <ResourceCard    href="https://motion.dev"    icon="/image/tools/motion.dev.png"    title="Motion"    description="Animation library for React"  />  <ResourceCard    href="/interface/Home"    image="/image/notes/og-cover-example.png"    title="Open Graph cover"    description="InitStudio notes"  /></ResourceGrid>

Image card

การ์ดสินค้าแสดงรูป ชื่อ รหัสและราคา ปุ่มขยายกับปุ่มเลือกจะแสดงเมื่อ hover (และยังใช้ได้ด้วยคีย์บอร์ดหรือจอสัมผัส) ปุ่ม Buy Now จะเลื่อนขึ้นมาทับขอบล่างของภาพโดยไม่เปลี่ยนความสูงของการ์ด เมื่อเลือกจะแสดงกรอบสีฟ้าด้านนอก กดขยายเพื่อเปิดภาพเต็มจอ โดยทั้ง card เคลื่อนพร้อมกันด้วย shared layoutId

ภาพประกอบชุด component สีน้ำเงินของ InitStudio

InitStudio components

#846
ImageCard
<ImageCard  src="/image/cover/home-illustration.png"  alt="ภาพประกอบชุด component สีน้ำเงินของ InitStudio"  title="InitStudio components"  itemNumber="#846"  price="0.145 ETH"/>

Flowchart

แผนภาพลำดับขั้นแนวตั้ง แต่ละ FlowStep มีหัวข้อและกล่องเนื้อหา ระบบจะใส่เส้นเชื่อมระหว่างขั้นให้เอง ใส่ active เพื่อเน้นขั้นที่ต้องการ และใส่ caption เพื่อแสดงคำอธิบายใต้แผนภาพ

  1. Main Layer - CPU
    Other Elements
  2. Compositing Layer - GPU
    Element with will-change
เบราว์เซอร์แยก element ที่มี will-change ไปไว้บน compositing layer ของ GPU
<Flowchart caption="เบราว์เซอร์แยก element ที่มี will-change ไปไว้บน compositing layer ของ GPU">  <FlowStep title="Main Layer - CPU">Other Elements</FlowStep>  <FlowStep title="Compositing Layer - GPU" active>    Element with will-change  </FlowStep></Flowchart>

Ask input

ช่องพิมพ์ข้อความแบบแชต เมื่อเริ่มพิมพ์ ปุ่มกล้อง รูปภาพ และไฟล์จะยุบรวมเป็นปุ่มเพิ่มไฟล์แนบปุ่มเดียว ช่องพิมพ์จะขยายกว้างขึ้น และไอคอนเสียงจะเปลี่ยนเป็นปุ่มส่ง กด Enter เพื่อส่งได้

ลองพิมพ์ข้อความเพื่อดูการเปลี่ยนสถานะ
<AskInputDemo caption="ลองพิมพ์ข้อความเพื่อดูการเปลี่ยนสถานะ" />

Dynamic Island

เกาะสีดำที่ยืดหดตามเนื้อหาด้วย spring layout animation ที่มี bounce เล็กน้อยให้รู้สึกเป็นธรรมชาติ เนื้อหาแต่ละสถานะสลับกันด้วย opacity, scale และ blur โหมด Ring จะสลับเป็น Silent อัตโนมัติ ส่วน Timer นับถอยหลังพร้อมปุ่มหยุดชั่วคราวและปุ่มออก

Dynamic Island

The focus here will be on the spring animation, how to make it feel organic and natural.

กด Idle, Ring หรือ Timer เพื่อดูการเปลี่ยนรูปทรง
<DynamicIslandDemo caption="กด Idle, Ring หรือ Timer เพื่อดูการเปลี่ยนรูปทรง" />

Step progress

เส้นความคืบหน้าสามขั้น การ์ดจะเลื่อนไปยังขั้นที่เลือก เส้นสีจะค่อย ๆ เติมตาม และไอคอนกับสีของวงกลมจะเปลี่ยนไปพร้อมกัน ทุกอย่างใช้ easing และ duration เดียวกันจาก CSS variable ปุ่มชุดซ้ายใช้ easing แบบ linear ส่วนชุดขวาใช้ cubic-bezier(0.59, 0.02, 0.39, 1) ลองกดสลับดูว่ารู้สึกต่างกันแค่ไหน ใส่ compare={false} เพื่อแสดงปุ่มชุดเดียว

Step 1 of 3: Code
กดไอคอนด้านล่างเพื่อเปลี่ยนขั้น
<StepProgressDemo caption="กดไอคอนด้านล่างเพื่อเปลี่ยนขั้น" /><StepProgressDemo compare={false} />

whileInView

whileInView เริ่ม animate เมื่อ element เข้าหรือออกจาก viewport กำหนด viewport.root เป็น scroll container เพื่อใช้พื้นที่เลื่อนเฉพาะจุด และ amount ระบุสัดส่วนที่ต้องเห็นก่อนเริ่ม animation

Scroll inside the panel to reveal the element
Before entering view
In view
Scroll back to replay
The element animates when at least half of it enters or leaves this scroll area.
<motion.div  initial={{ filter: "blur(8px)" }}  whileInView={{ scale: 1.1, rotate: 45, filter: "blur(0px)" }}  viewport={{ root: scrollRef, amount: 0.5 }}  transition={{ type: "spring", duration: 0.6, bounce: 0 }}/>

Shared layout with AnimatePresence

ใช้ AnimatePresence เพื่อ animate เนื้อหาด้านหลัง moving element ได้ หากต้องการให้ element ที่ใช้ layoutId เคลื่อนตำแหน่งโดยไม่รับ initial และ exit animation ให้วาง element นั้นไว้นอก AnimatePresence ถ้าวางไว้ข้างใน initial และ exit จะทำงานระหว่าง layout transition ด้วย ซึ่งอาจทำให้การเคลื่อนไหวดูสะดุด โดยเฉพาะเมื่อ animate opacity

shared-layout.tsx
const getCardConfig = () => {  switch (activeTab) {    case "Design":      return {        className: "top-24 left-46 h-12 w-32",        borderRadius: "8px",      };    case "Engineering":      return { className: "top-10 right-2 h-78 w-32", borderRadius: "8px" };    case "Product":      return { className: "bottom-2 left-2 h-20 w-28", borderRadius: "8px" };    case "Marketing":      return { className: "top-17 left-49 size-16", borderRadius: "4px" };    case "Sales":      return { className: "bottom-2 right-2 size-8", borderRadius: "32px" };  }}; const cardConfig = getCardConfig(); return (  <>    <AnimatePresence>      {/* Content behind the shared layout element */}      {content}    </AnimatePresence>     <motion.div      className={cn("absolute bg-gray-1200", cardConfig.className)}      animate={{ borderRadius: cardConfig.borderRadius }}      layoutId="card"    />  </>);
PreviousNext