From 35f812249e52a494bd4d213a3aa567a12dbb34b3 Mon Sep 17 00:00:00 2001
From: Anass Bouassaba
Date: Wed, 20 Nov 2024 04:36:39 +0100
Subject: [PATCH] refactor: simplify bundle stories
---
src/stories/bundles/app.stories.tsx | 447 +++++++++++++++++-
src/stories/bundles/layout.stories.tsx | 208 +++++++-
src/stories/bundles/page.stories.tsx | 251 +++++++++-
src/stories/common/data.ts | 33 --
src/stories/common/layout.tsx | 156 ------
src/stories/common/list.tsx | 84 ----
src/stories/common/page.tsx | 18 -
src/stories/common/paragraphs.tsx | 32 --
src/stories/common/settings.tsx | 94 ----
src/stories/components/data-table.stories.tsx | 37 +-
src/stories/components/shell.stories.tsx | 51 +-
src/stories/components/sidenav.stories.tsx | 51 +-
12 files changed, 994 insertions(+), 468 deletions(-)
delete mode 100644 src/stories/common/data.ts
delete mode 100644 src/stories/common/layout.tsx
delete mode 100644 src/stories/common/list.tsx
delete mode 100644 src/stories/common/page.tsx
delete mode 100644 src/stories/common/paragraphs.tsx
delete mode 100644 src/stories/common/settings.tsx
diff --git a/src/stories/bundles/app.stories.tsx b/src/stories/bundles/app.stories.tsx
index bf55761..58bc897 100644
--- a/src/stories/bundles/app.stories.tsx
+++ b/src/stories/bundles/app.stories.tsx
@@ -1,19 +1,61 @@
-import { useEffect } from 'react'
+import { ReactElement, useEffect, useState } from 'react'
+import {
+ Avatar,
+ Button,
+ IconButton,
+ MenuItem,
+ Progress,
+ Switch,
+ Link as ChakraLink,
+ useDisclosure,
+ Tabs,
+ TabList,
+ Tab,
+} from '@chakra-ui/react'
+import {
+ AccountMenu,
+ AppBar,
+ AuxiliaryDrawer,
+ DataTable,
+ Form,
+ IconAdd,
+ IconAdminPanelSettings,
+ IconChat,
+ IconDelete,
+ IconEdit,
+ IconFavorite,
+ IconFlag,
+ IconGroup,
+ IconLogout,
+ IconStacks,
+ IconTune,
+ IconUpload,
+ IconWorkspaces,
+ Logo,
+ NumberTag,
+ PagePagination,
+ SearchBar,
+ Shell,
+ usePagePagination,
+} from '@koupr/ui'
import { Meta, StoryObj } from '@storybook/react'
-import { Route, Routes, useLocation, useNavigate } from 'react-router-dom'
-import { Layout } from '../common/layout'
-import { List } from '../common/list'
-import { Page } from '../common/page'
-import { ParagraphGroups, ParagraphOrganizations } from '../common/paragraphs'
-import { Settings } from '../common/settings'
-
-export const App = () => {
+import cx from 'classnames'
+import {
+ Link,
+ Outlet,
+ Route,
+ Routes,
+ useLocation,
+ useNavigate,
+} from 'react-router-dom'
+
+const App = () => {
const location = useLocation()
const navigate = useNavigate()
useEffect(() => {
if (location.pathname === '/workspace') {
- navigate('/workspace/list')
+ navigate('/workspace/data-table')
}
}, [location.pathname, navigate])
@@ -25,28 +67,403 @@ export const App = () => {
element={}
children={
<>
- } />
- } />
+ }
+ />
+ } />
>
}
/>
- } />
- } />
+
+ Commodo volutpat facilisis habitant; mattis ultrices mauris ex
+ nisi. Consequat nascetur lacus sed fames convallis pretium sit
+ justo. Gravida curabitur condimentum hac mi, ridiculus montes.
+ Eros commodo porttitor erat amet primis imperdiet. Morbi at
+ potenti volutpat litora viverra dapibus sapien. Fermentum sodales
+ nullam aliquam fusce aliquam.
+
+ }
+ />
+
+ Dis eros primis condimentum a porttitor orci curabitur. Aluctus
+ arcu blandit dui facilisi interdum pretium tristique. Cras nam
+ congue parturient posuere tempor lectus? Felis hendrerit penatibus
+ semper maximus convallis tortor. Et potenti quisque ex phasellus
+ magnis leo netus. Hac enim ante curae odio libero feugiat metus
+ conubia tincidunt.
+
+ }
+ />
)
}
+type LayoutProps = {
+ children?: ReactElement
+}
+
+const Layout = ({ children }: LayoutProps) => {
+ const location = useLocation()
+ const navigate = useNavigate()
+ const tasks = useDisclosure()
+ const uploads = useDisclosure()
+ const [query, setQuery] = useState('')
+
+ useEffect(() => {
+ if (location.pathname === '/') {
+ navigate('/workspace')
+ }
+ }, [navigate])
+
+ return (
+ }
+ topBar={
+ }
+ title="Search filters"
+ aria-label="Search filters"
+ />
+ }
+ onSearch={setQuery}
+ onClear={() => setQuery('')}
+ />
+ }
+ buttons={
+ <>
+ }
+ variant="solid"
+ colorScheme="blue"
+ >
+ New Workspace
+
+ }
+ title="Open console"
+ aria-label="Open console"
+ />
+ }
+ header="Uploads"
+ body={<>>}
+ isOpen={uploads.isOpen}
+ onClose={uploads.onClose}
+ onOpen={uploads.onOpen}
+ />
+ }
+ header="Tasks"
+ body={<>>}
+ hasBadge={true}
+ isOpen={tasks.isOpen}
+ onOpen={tasks.onOpen}
+ onClose={tasks.onClose}
+ />
+
+
+
+
+ >
+ }
+ />
+ >
+ }
+ />
+ }
+ items={[
+ {
+ href: '/workspace',
+ icon: ,
+ primaryText: 'Workspaces',
+ secondaryText: 'Isolated containers for files and folders.',
+ },
+ {
+ href: '/group',
+ icon: ,
+ primaryText: 'Groups',
+ secondaryText: 'Allows assigning permissions to a group of users.',
+ },
+ {
+ href: '/organization',
+ icon: ,
+ primaryText: 'Organizations',
+ secondaryText: 'Umbrellas for workspaces and users.',
+ },
+ ]}
+ pathnameFn={() => location.pathname}
+ navigateFn={navigate}
+ >
+ {children}
+
+ )
+}
+
+const Page = () => {
+ const navigate = useNavigate()
+ return (
+
+
+
+ navigate('/workspace/data-table')}>
+ Data Table
+
+ navigate('/workspace/form')}>Form
+
+
+
+
+ )
+}
+
const meta: Meta = {
title: 'Bundles/App',
component: App,
parameters: {
layout: 'fullscreen',
},
- excludeStories: /App/,
}
export default meta
type Story = StoryObj
export const Default: Story = {}
+
+type SampleItem = {
+ name: string
+ symbol: string
+ dateOfBirth: string
+}
+
+const SampleDataTable = () => {
+ const navigate = useNavigate()
+ const location = useLocation()
+ const { page, size, steps, setPage, setSize } = usePagePagination({
+ navigateFn: navigate,
+ searchFn: () => location.search,
+ })
+
+ return (
+
+ items={[
+ {
+ name: 'Bruce Wayne',
+ symbol: 'Batman',
+ dateOfBirth: '1915-04-07',
+ },
+ {
+ name: 'Tony Stark',
+ symbol: 'Iron Man',
+ dateOfBirth: '1970-05-29',
+ },
+ {
+ name: 'Steven Rogers',
+ symbol: 'Captain America',
+ dateOfBirth: '1918-07-04',
+ },
+ {
+ name: 'Clinton Barton',
+ symbol: 'Hawkeye',
+ dateOfBirth: '1975-01-01',
+ },
+ {
+ name: 'Natasha Romanoff',
+ symbol: 'Black Widow',
+ dateOfBirth: '1984-12-03',
+ },
+ ]}
+ columns={[
+ {
+ title: 'Name',
+ renderCell: (item) => (
+
+ ),
+ },
+ {
+ title: 'Symbol',
+ renderCell: (item) => {item.symbol},
+ },
+ {
+ title: 'Date of Birth',
+ renderCell: (item) => (
+ {new Date(item.dateOfBirth).toLocaleString()}
+ ),
+ },
+ ]}
+ actions={[
+ {
+ label: 'Mark As Favorite',
+ icon: ,
+ onClick: (item) => console.log(`Marking ${item.name} as favorite!`),
+ },
+ {
+ label: 'Start Conversation',
+ icon: ,
+ isDisabled: true,
+ onClick: (item) =>
+ console.log(`Starting a conversation with ${item.name}.`),
+ },
+ {
+ label: 'Remove From Organization',
+ icon: ,
+ isDestructive: true,
+ onClick: (item) =>
+ console.log(`Removing ${item.name} from organization...`),
+ },
+ ]}
+ pagination={
+
+ }
+ />
+ )
+}
+
+const SampleForm = () => (
+
)
@@ -33,3 +75,198 @@ export default meta
type Story = StoryObj
export const Default: Story = {}
+
+type SampleItem = {
+ name: string
+ symbol: string
+ dateOfBirth: string
+}
+
+const SampleDataTable = () => {
+ const navigate = useNavigate()
+ const location = useLocation()
+ const { page, size, steps, setPage, setSize } = usePagePagination({
+ navigateFn: navigate,
+ searchFn: () => location.search,
+ })
+
+ return (
+
+ items={[
+ {
+ name: 'Bruce Wayne',
+ symbol: 'Batman',
+ dateOfBirth: '1915-04-07',
+ },
+ {
+ name: 'Tony Stark',
+ symbol: 'Iron Man',
+ dateOfBirth: '1970-05-29',
+ },
+ {
+ name: 'Steven Rogers',
+ symbol: 'Captain America',
+ dateOfBirth: '1918-07-04',
+ },
+ {
+ name: 'Clinton Barton',
+ symbol: 'Hawkeye',
+ dateOfBirth: '1975-01-01',
+ },
+ {
+ name: 'Natasha Romanoff',
+ symbol: 'Black Widow',
+ dateOfBirth: '1984-12-03',
+ },
+ ]}
+ columns={[
+ {
+ title: 'Name',
+ renderCell: (item) => (
+
+ ),
+ },
+ {
+ title: 'Symbol',
+ renderCell: (item) => {item.symbol},
+ },
+ {
+ title: 'Date of Birth',
+ renderCell: (item) => (
+ {new Date(item.dateOfBirth).toLocaleString()}
+ ),
+ },
+ ]}
+ actions={[
+ {
+ label: 'Mark As Favorite',
+ icon: ,
+ onClick: (item) => console.log(`Marking ${item.name} as favorite!`),
+ },
+ {
+ label: 'Start Conversation',
+ icon: ,
+ isDisabled: true,
+ onClick: (item) =>
+ console.log(`Starting a conversation with ${item.name}.`),
+ },
+ {
+ label: 'Remove From Organization',
+ icon: ,
+ isDestructive: true,
+ onClick: (item) =>
+ console.log(`Removing ${item.name} from organization...`),
+ },
+ ]}
+ pagination={
+
+ }
+ />
+ )
+}
+
+const SampleForm = () => (
+