style(storybook): refine search and date story layout
This commit is contained in:
1 parent
8827eb2681
commit
0ea5b46f74
4 files changed
+117
-79
No files matched your search
@@ -12,10 +12,11 @@ import { StoryPage, StoryPageHeader, StorySection } from "@/components/story-pag
|
||||
const today = new Date(2026, 9, 2)
|
||||
const calendarProps = { today, startMonth: new Date(2026, 0), endMonth: new Date(2027, 11) }
|
||||
|
||||
function Field({ label, id, children }: { label: string; id: string; children: ReactNode }) {
|
||||
// Label 14/20/500 in the default text color; a Disabled field keeps the secondary color at 0.6 (same as the Form pages).
|
||||
function Field({ label, id, disabled, children }: { label: string; id: string; disabled?: boolean; children: ReactNode }) {
|
||||
return (
|
||||
<div className="grid max-w-xs gap-2">
|
||||
<label htmlFor={id} className="justify-self-start text-sm font-medium text-muted-foreground">
|
||||
<label htmlFor={id} className={`justify-self-start text-sm font-medium ${disabled ? "text-muted-foreground opacity-60" : "text-foreground"}`}>
|
||||
{label}
|
||||
</label>
|
||||
{children}
|
||||
@@ -39,16 +40,19 @@ function Selected() {
|
||||
)
|
||||
}
|
||||
|
||||
function FormatExamples() {
|
||||
function DefaultFormat() {
|
||||
return (
|
||||
<div className="grid gap-3">
|
||||
<Field label="기본 형식 · YYYY.MM.DD" id="dp-padded">
|
||||
<DatePicker id="dp-padded" defaultValue={new Date(2026, 0, 9)} calendarProps={calendarProps} />
|
||||
</Field>
|
||||
<Field label="Custom format override" id="dp-custom">
|
||||
<DatePicker id="dp-custom" defaultValue={new Date(2026, 9, 6)} format={(date) => date.toLocaleDateString("ko-KR")} calendarProps={calendarProps} />
|
||||
</Field>
|
||||
</div>
|
||||
<Field label="기본 형식 · YYYY.MM.DD" id="dp-padded">
|
||||
<DatePicker id="dp-padded" defaultValue={new Date(2026, 0, 9)} calendarProps={calendarProps} />
|
||||
</Field>
|
||||
)
|
||||
}
|
||||
|
||||
function CustomFormat() {
|
||||
return (
|
||||
<Field label="Custom format override" id="dp-custom">
|
||||
<DatePicker id="dp-custom" defaultValue={new Date(2026, 9, 6)} format={(date) => date.toLocaleDateString("ko-KR")} calendarProps={calendarProps} />
|
||||
</Field>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -86,29 +90,27 @@ function DisabledDates() {
|
||||
|
||||
function Disabled() {
|
||||
return (
|
||||
<Field label="비활성" id="dp-disabled">
|
||||
<Field label="비활성" id="dp-disabled" disabled>
|
||||
<DatePicker id="dp-disabled" disabled defaultValue={new Date(2026, 9, 15)} />
|
||||
</Field>
|
||||
)
|
||||
}
|
||||
|
||||
const sections = [
|
||||
{ id: "empty", label: "Empty", node: <Empty /> },
|
||||
{ id: "selected", label: "Selected", node: <Selected /> },
|
||||
{ id: "format", label: "Format", node: <FormatExamples /> },
|
||||
{ id: "controlled", label: "Controlled", node: <Controlled showValue={false} /> },
|
||||
{ id: "disabled-dates", label: "Disabled dates", node: <DisabledDates /> },
|
||||
{ id: "disabled", label: "Disabled", node: <Disabled /> },
|
||||
]
|
||||
// Same 3-column track as the Form pages (1 column on narrow screens). Each cell is a one-specimen StateBoard so subtitles, dividers and
|
||||
// fields line up; sections with fewer specimens leave the remaining tracks empty.
|
||||
const Grid = ({ children }: { children: ReactNode }) => (
|
||||
<div className="grid items-start gap-6 [grid-template-columns:repeat(auto-fill,minmax(min(100%,300px),1fr))] min-[1000px]:grid-cols-3">{children}</div>
|
||||
)
|
||||
const Cell = ({ id, label, children }: { id: string; label: string; children: ReactNode }) => (
|
||||
<div className="min-w-0">
|
||||
<StateBoard min={10000} states={[{ id, label, children }]} />
|
||||
</div>
|
||||
)
|
||||
|
||||
const meta = { title: "Components/Search & Date/Date Picker", component: DatePicker, parameters: { layout: "padded" } } satisfies Meta<typeof DatePicker>
|
||||
export default meta
|
||||
type Story = StoryObj<typeof meta>
|
||||
|
||||
const board = (...ids: string[]) => (
|
||||
<StateBoard min={320} states={sections.filter((s) => ids.includes(s.id)).map((s) => ({ id: s.id, label: s.label, children: s.node }))} />
|
||||
)
|
||||
|
||||
// Representative Story: the common Story page; the sections group the same specimens.
|
||||
export const All: Story = {
|
||||
name: "Date Picker",
|
||||
@@ -116,15 +118,26 @@ export const All: Story = {
|
||||
render: () => (
|
||||
<StoryPage>
|
||||
<StoryPageHeader title="Date Picker" />
|
||||
<StorySection title="Overview">{board("empty")}</StorySection>
|
||||
{/* The field label already names the size, so the Medium specimen has no separate example title. */}
|
||||
<StorySection title="Sizes">
|
||||
<div className="max-w-sm">
|
||||
<Medium />
|
||||
</div>
|
||||
<Grid>
|
||||
<Cell id="empty" label="Default"><Empty /></Cell>
|
||||
<Cell id="medium" label="Medium"><Medium /></Cell>
|
||||
</Grid>
|
||||
</StorySection>
|
||||
<StorySection title="States">
|
||||
<Grid>
|
||||
<Cell id="selected" label="Selected"><Selected /></Cell>
|
||||
<Cell id="controlled" label="Controlled"><Controlled showValue={false} /></Cell>
|
||||
<Cell id="disabled-dates" label="Disabled dates"><DisabledDates /></Cell>
|
||||
<Cell id="disabled" label="Disabled"><Disabled /></Cell>
|
||||
</Grid>
|
||||
</StorySection>
|
||||
<StorySection title="Usage">
|
||||
<Grid>
|
||||
<Cell id="format-default" label="Default format"><DefaultFormat /></Cell>
|
||||
<Cell id="format-custom" label="Custom format"><CustomFormat /></Cell>
|
||||
</Grid>
|
||||
</StorySection>
|
||||
<StorySection title="States">{board("selected", "controlled", "disabled-dates", "disabled")}</StorySection>
|
||||
<StorySection title="Usage">{board("format")}</StorySection>
|
||||
</StoryPage>
|
||||
),
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user