AI-native design editor. Open-source Figma alternative.
import type { Meta, StoryObj } from '@storybook/vue3-vite'
import { TooltipProvider } from 'reka-ui'
import { expect, userEvent, within } from 'storybook/test'
import { ref } from 'vue'
import MoreIcon from '~icons/lucide/ellipsis'
import EyeIcon from '~icons/lucide/eye'
import LayoutPanelTopIcon from '~icons/lucide/layout-panel-top'
import LinkIcon from '~icons/lucide/link'
import RotateIcon from '~icons/lucide/rotate-ccw'
import SquareIcon from '~icons/lucide/square'
import AppButton from '@/components/ui/button/AppButton.vue'
import IconButton from '@/components/ui/button/IconButton.vue'
import AppInput from '@/components/ui/input/AppInput.vue'
import AppSelect from '@/components/ui/select/AppSelect.vue'
import SegmentedControl from '@/components/ui/select/SegmentedControl.vue'
import PanelFieldGroup from './PanelFieldGroup.vue'
import PanelGrid from './PanelGrid.vue'
import PanelHeader from './PanelHeader.vue'
import PanelSection from './PanelSection.vue'
const meta = {
title: 'Design System/Layout/Panel Foundation',
tags: ['autodocs'],
parameters: {
docs: {
description: {
component:
'The 24px properties-panel foundation: strict grids, field groups, action rails, and semantic field states.'
}
}
}
} satisfies Meta<typeof PanelSection>
export default meta
type Story = StoryObj<typeof meta>
export const SelectionTransition: Story = {
render: () => ({
components: { AppButton, IconButton, LayoutPanelTopIcon, PanelSection },
setup() {
const container = ref(false)
return { container }
},
template: `
<div class="w-72 bg-panel text-surface">
<AppButton @click="container = !container">Switch selection</AppButton>
<PanelSection :label="container ? 'Auto layout' : 'Layout'">
<template v-if="container" #actions>
<IconButton label="Remove auto layout" active>
<LayoutPanelTopIcon class="size-3.5" />
</IconButton>
</template>
<p class="text-xs text-muted">
{{ container ? 'Frame selection' : 'Rectangle selection' }}
</p>
</PanelSection>
</div>
`
})
}
export const StateMatrix: Story = {
render: () => ({
components: {
AppInput,
AppSelect,
EyeIcon,
IconButton,
LinkIcon,
MoreIcon,
PanelFieldGroup,
PanelGrid,
PanelHeader,
PanelSection,
RotateIcon,
SegmentedControl,
SquareIcon,
TooltipProvider
},
setup() {
const width = ref<string | number>(320)
const height = ref<string | number>(240)
const mixed = ref<string | number>('Mixed')
const bound = ref<string | number>('spacing/md')
const disabled = ref<string | number>(16)
const blendMode = ref('NORMAL')
const alignment = ref('left')
return {
width,
height,
mixed,
bound,
disabled,
blendMode,
alignment,
blendModes: [
{ value: 'NORMAL', label: 'Normal' },
{ value: 'MULTIPLY', label: 'Multiply' },
{ value: 'SCREEN', label: 'Screen' }
],
alignmentOptions: [
{ value: 'left', label: 'Left' },
{ value: 'center', label: 'Center' },
{ value: 'right', label: 'Right' }
]
}
},
template: `
<TooltipProvider>
<div class="w-80 overflow-hidden rounded-lg border border-border bg-panel shadow-xl">
<PanelHeader>
<template #icon><SquareIcon class="size-3.5" /></template>
<span role="heading" aria-level="2">Rectangle</span>
<template #actions>
<IconButton label="Selection actions"><MoreIcon class="size-3.5" /></IconButton>
</template>
</PanelHeader>
<PanelSection label="Layout">
<template #actions>
<IconButton label="Reset layout"><RotateIcon class="size-3.5" /></IconButton>
</template>
<PanelGrid :columns="2">
<PanelFieldGroup label="Width">
<AppInput v-model="width" tone="panel" size="xs" data-story-control data-state="idle" aria-label="Width" />
</PanelFieldGroup>
<PanelFieldGroup label="Height">
<AppInput v-model="height" tone="panel" size="xs" data-story-control data-state="focus" aria-label="Height" />
</PanelFieldGroup>
<template #actions>
<IconButton label="Constrain proportions" size="md"><LinkIcon class="size-3.5" /></IconButton>
</template>
</PanelGrid>
</PanelSection>
<PanelSection label="Appearance">
<PanelGrid :columns="2">
<PanelFieldGroup label="Blend mode">
<AppSelect v-model="blendMode" :options="blendModes" data-story-control label="Blend mode" />
</PanelFieldGroup>
<PanelFieldGroup label="Opacity">
<AppInput v-model="mixed" tone="panel" size="xs" state="mixed" readonly data-story-control aria-label="Mixed opacity" />
</PanelFieldGroup>
<template #actions>
<IconButton label="Toggle visibility"><EyeIcon class="size-3.5" /></IconButton>
</template>
</PanelGrid>
</PanelSection>
<PanelSection label="States">
<div class="grid grid-cols-2 gap-1.5">
<PanelFieldGroup label="Bound">
<AppInput v-model="bound" tone="panel" size="xs" state="bound" readonly data-story-control aria-label="Bound value" />
</PanelFieldGroup>
<PanelFieldGroup label="Disabled">
<AppInput v-model="disabled" tone="panel" size="xs" disabled data-story-control aria-label="Disabled value" />
</PanelFieldGroup>
<PanelFieldGroup label="Alignment" class="col-span-2">
<SegmentedControl v-model="alignment" class="w-full" :options="alignmentOptions" label="Alignment" data-story-control />
</PanelFieldGroup>
</div>
</PanelSection>
</div>
</TooltipProvider>
`
}),
play: async ({ canvasElement }) => {
const canvas = within(canvasElement)
const controls = Array.from(canvasElement.querySelectorAll<HTMLElement>('[data-story-control]'))
for (const control of controls) await expect(control).toHaveStyle({ height: '24px' })
await userEvent.click(canvas.getByLabelText('Height'))
await userEvent.hover(canvas.getByLabelText('Width'))
}
}