import { EditIcon, MoreVerticalIcon, TrashIcon } from '@modrinth/assets' import type { Meta, StoryObj } from '@storybook/vue3-vite' import { ref } from 'vue' import Badge from '../../components/base/Badge.vue' import ButtonStyled from '../../components/base/ButtonStyled.vue' import OverflowMenu from '../../components/base/OverflowMenu.vue' import Table from '../../components/base/Table.vue' interface User { id: string name: string email: string status: 'active' | 'inactive' | 'pending' role: string } const sampleUsers: User[] = [ { id: '1', name: 'John Doe', email: 'john@example.com', status: 'active', role: 'Admin' }, { id: '2', name: 'Jane Smith', email: 'jane@example.com', status: 'inactive', role: 'User' }, { id: '3', name: 'Bob Johnson', email: 'bob@example.com', status: 'pending', role: 'Editor' }, { id: '4', name: 'Alice Brown', email: 'alice@example.com', status: 'active', role: 'User' }, { id: '5', name: 'Charlie Wilson', email: 'charlie@example.com', status: 'active', role: 'Admin', }, ] const meta = { title: 'Base/Table', // @ts-ignore - Generic component component: Table, } satisfies Meta export default meta export const Default: StoryObj = { args: {}, render: () => ({ components: { Table }, setup() { const columns = [ { key: 'name', label: 'Name' }, { key: 'email', label: 'Email' }, { key: 'status', label: 'Status' }, { key: 'role', label: 'Role' }, ] const data = sampleUsers return { columns, data } }, template: /* html */ ` `, }), } export const WithSelection: StoryObj = { args: {}, render: () => ({ components: { Table }, setup() { const columns = [ { key: 'name', label: 'Name' }, { key: 'email', label: 'Email' }, { key: 'status', label: 'Status' }, { key: 'role', label: 'Role' }, ] const data = sampleUsers const selectedIds = ref([]) return { columns, data, selectedIds } }, template: /* html */ `

Selected IDs: {{ selectedIds.join(', ') || 'None' }}

`, }), } export const WithSorting: StoryObj = { args: {}, render: () => ({ components: { Table }, setup() { const columns = [ { key: 'name', label: 'Name', enableSorting: true }, { key: 'email', label: 'Email', enableSorting: true }, { key: 'status', label: 'Status' }, { key: 'role', label: 'Role', enableSorting: true }, ] const data = sampleUsers const sortColumn = ref('name') const sortDirection = ref<'asc' | 'desc'>('asc') function handleSort(column: string, direction: 'asc' | 'desc') { console.log(`Sorting by ${column} ${direction}`) } return { columns, data, sortColumn, sortDirection, handleSort } }, template: /* html */ `

Sort: {{ sortColumn }} ({{ sortDirection }})

`, }), } export const WithColumnAlignment: StoryObj = { args: {}, render: () => ({ components: { Table }, setup() { const columns = [ { key: 'name', label: 'Name', align: 'left' as const }, { key: 'email', label: 'Email', align: 'center' as const }, { key: 'status', label: 'Status', align: 'center' as const }, { key: 'role', label: 'Role', align: 'right' as const }, ] const data = sampleUsers return { columns, data } }, template: /* html */ `
`, }), } export const WithCustomCellSlots: StoryObj = { args: {}, render: () => ({ components: { Table, Badge }, setup() { const columns = [ { key: 'name', label: 'Name' }, { key: 'email', label: 'Email' }, { key: 'status', label: 'Status', align: 'center' as const, width: '20%' }, { key: 'role', label: 'Role', width: '10%' }, ] const data = sampleUsers const statusColor = (status: string) => { switch (status) { case 'active': return 'green' case 'inactive': return 'red' case 'pending': return 'orange' default: return 'gray' } } return { columns, data, statusColor } }, template: /* html */ `
`, }), } export const WithCustomHeaderSlots: StoryObj = { args: {}, render: () => ({ components: { Table }, setup() { const columns = [ { key: 'name', label: 'Name' }, { key: 'email', label: 'Email' }, { key: 'status', label: 'Status' }, { key: 'role', label: 'Role' }, ] const data = sampleUsers return { columns, data } }, template: /* html */ `
`, }), } export const WithActionsColumn: StoryObj = { args: {}, render: () => ({ components: { Table, ButtonStyled, EditIcon, TrashIcon }, setup() { const columns = [ { key: 'name', label: 'Name' }, { key: 'email', label: 'Email' }, { key: 'role', label: 'Role' }, { key: 'actions', label: 'Actions', align: 'right' as const }, ] const data = sampleUsers function handleEdit(row: User) { alert(`Edit user: ${row.name}`) } function handleDelete(row: User) { alert(`Delete user: ${row.name}`) } return { columns, data, handleEdit, handleDelete } }, template: /* html */ `
`, }), } export const FullFeatured: StoryObj = { args: {}, render: () => ({ components: { Table, Badge, ButtonStyled, EditIcon, TrashIcon }, setup() { const columns = [ { key: 'name', label: 'Name', enableSorting: true }, { key: 'email', label: 'Email', enableSorting: true }, { key: 'status', label: 'Status', align: 'center' as const, width: '100px' }, { key: 'role', label: 'Role', enableSorting: true }, { key: 'actions', label: 'Actions', align: 'right' as const, width: '200px' }, ] const data = sampleUsers const selectedIds = ref([]) const sortColumn = ref('name') const sortDirection = ref<'asc' | 'desc'>('asc') const statusColor = (status: string) => { switch (status) { case 'active': return 'green' case 'inactive': return 'red' case 'pending': return 'orange' default: return 'gray' } } function handleSort(column: string, direction: 'asc' | 'desc') { console.log(`Sorting by ${column} ${direction}`) } function handleEdit(row: User) { alert(`Edit user: ${row.name}`) } function handleDelete(row: User) { alert(`Delete user: ${row.name}`) } return { columns, data, selectedIds, sortColumn, sortDirection, statusColor, handleSort, handleEdit, handleDelete, } }, template: /* html */ `
Selected: {{ selectedIds.length }} items Sort: {{ sortColumn }} ({{ sortDirection }})
`, }), } export const WithOverflowMenu: StoryObj = { args: {}, render: () => ({ components: { Table, Badge, ButtonStyled, OverflowMenu, MoreVerticalIcon, EditIcon, TrashIcon }, setup() { const columns = [ { key: 'name', label: 'Name' }, { key: 'email', label: 'Email' }, { key: 'status', label: 'Status', align: 'center' as const, width: '20%' }, { key: 'role', label: 'Role' }, { key: 'actions', label: '', width: '48px' }, ] const data = sampleUsers const statusColor = (status: string) => { switch (status) { case 'active': return 'green' case 'inactive': return 'red' case 'pending': return 'orange' default: return 'gray' } } const getMenuOptions = (row: User) => [ { id: 'edit', action: () => alert(`Edit user: ${row.name}`), }, { id: 'duplicate', action: () => alert(`Duplicate user: ${row.name}`), }, { divider: true }, { id: 'delete', color: 'red' as const, hoverFilled: true, action: () => alert(`Delete user: ${row.name}`), }, ] return { columns, data, statusColor, getMenuOptions } }, template: /* html */ `
`, }), }