import type { Meta, StoryObj } from '@storybook/vue3-vite' import type { MenuItem } from 'primevue/menuitem' import { ref } from 'vue' import CpButton from '@/components/CpButton.vue' import CpIcon from '@/components/CpIcon.vue' import CpItemActions from '@/components/CpItemActions.vue' import CpTransitionListItems from '@/components/CpTransitionListItems.vue' interface LineItem { id: string label: string } const meta = { title: 'Transitions/CpTransitionListItems', component: CpTransitionListItems, argTypes: { disableOnLoad: { control: 'boolean', description: 'Skips enter transition on first paint', }, }, } satisfies Meta export default meta type Story = StoryObj const rowStyle = ` display: flex; align-items: center; min-height: 48px; min-width: 100%; padding: 16px; margin-bottom: 12px; border: 1px solid #e5e7eb; border-radius: 12px; background: #fff; box-shadow: var(--cp-shadows-sm); ` const fabWrapperStyle = { position: 'fixed', bottom: '50px', right: '50px', zIndex: 2, display: 'flex', flexDirection: 'column', gap: '12px', alignItems: 'flex-end', } /** * Animate list insertions, removals and reorders with FLIP-based * transitions. Use the + / shuffle buttons to see the enter, leave and * move animations. */ export const Default: Story = { args: { disableOnLoad: false, }, render: (args) => ({ components: { CpTransitionListItems, CpItemActions, CpButton, CpIcon }, setup() { let idSeq = 0 const nextId = () => { idSeq += 1 return `line-${idSeq}` } const items = ref([ { id: nextId(), label: 'Line 1' }, { id: nextId(), label: 'Line 2' }, { id: nextId(), label: 'Line 3' }, ]) const removeItem = (id: string) => { items.value = items.value.filter((i) => i.id !== id) } const addLine = () => { items.value.push({ id: nextId(), label: `Line ${items.value.length + 1}`, }) } const shuffleItems = () => { const arr = [...items.value] for (let i = arr.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)) ;[arr[i], arr[j]] = [arr[j], arr[i]] } items.value = arr } const deleteActionsFor = (id: string): MenuItem[] => [ { icon: 'trash-2', label: 'Delete', isCritical: true, command: () => removeItem(id), }, ] return { args, items, addLine, shuffleItems, deleteActionsFor, rowStyle, fabWrapperStyle } }, template: `
{{ item.label }}
`, }), }