Skip to content

Commit

Permalink
feat: pro table (#15)
Browse files Browse the repository at this point in the history
* feat: pro table

* refactor: splitting components

* chore: use workspace typescript

* feat(proTable): add storybook

* fix(storybook): preview width

* feat(storybook): light and dark mode

* fix: height

* style: pagination style

* feat: support search

* feat(ProTable): search form filed

* feat(ProTable): column pinning sticky

* feat(ProTable): pinned TypeScript

* chore: remove function

* fix: vitepress build

* feat(proTable stories): reorganize ProTable stories for better clarity

- Split stories into individual feature demonstrations
- Add basic table example with simplified data structure
- Add separate stories for pagination, loading, empty state
- Add stories for search, custom toolbar, pinned columns
- Add stories for custom column sizes and visibility
- Add stories for refresh functionality and custom cells
- Improve code organization and readability
- Fix linting issues with console statements and spacing

* feat(proTable): split table body

* feat(proTable): split stories

* chore: upgrade storybook

* feat: split ProTable into dataTable

* feat: fetch data

* feat(data table):  option

* fix(data table): search options

* chore: rename data-table-search

* chore: remove TeamSwitcher

* fix: preset value

* chore: api

* fix: pagination

* feat(data table): when change page size, reset page index to 0

* chore: cSpell

* feat: avatars
  • Loading branch information
TinsFox authored Nov 15, 2024
1 parent 4c97674 commit 7c13833
Show file tree
Hide file tree
Showing 67 changed files with 2,735 additions and 2,229 deletions.
43 changes: 43 additions & 0 deletions .storybook/ThemeChanger.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { addons } from "@storybook/manager-api"
import { Moon, Sun } from "lucide-react"
import * as React from "react"

import { useTheme } from "../src/components/theme/theme-provider"
import { Button } from "../src/components/ui/button"
import { darkTheme, lightTheme } from "./theme"

export function ThemeChanger() {
const { theme, setTheme } = useTheme()

React.useEffect(() => {
// 初始化时设置 Storybook 主题
addons.setConfig({
theme: theme === "dark" ? darkTheme : lightTheme,
})
}, [])

const toggleTheme = React.useCallback(() => {
const newTheme = theme === "dark" ? "light" : "dark"
setTheme(newTheme)

// 更新 Storybook 管理界面主题
addons.setConfig({
theme: newTheme === "dark" ? darkTheme : lightTheme,
})
}, [theme, setTheme])

return (
<Button
variant="outline"
size="icon"
className="fixed right-4 top-4 z-50"
onClick={toggleTheme}
>
{theme === "dark" ? (
<Sun className="size-5" />
) : (
<Moon className="size-5" />
)}
</Button>
)
}
3 changes: 3 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ const config: StorybookConfig = {
"@storybook/addon-essentials",
"@chromatic-com/storybook",
"@storybook/addon-interactions",
"storybook-dark-mode",
],
framework: {
name: "@storybook/react-vite",
options: {},
},
docs: {},
}

export default config
5 changes: 4 additions & 1 deletion .storybook/manager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { addons } from "@storybook/manager-api"
import { themes } from "@storybook/theming"

// 获取系统主题偏好
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches

addons.setConfig({
theme: themes.dark,
theme: prefersDark ? themes.dark : themes.light,
})
42 changes: 35 additions & 7 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import "../src/styles/index.css"

import type { Preview } from "@storybook/react"
import { themes } from "@storybook/theming"
import * as React from "react"

import { ThemeProvider } from "../src/components/theme/theme-provider"
import { ThemeSwitcher } from "../src/components/theme/theme-switcher"
import { RootProviders } from "../src/providers/root-providers"

const preview: Preview = {
Expand All @@ -13,15 +16,40 @@ const preview: Preview = {
date: /Date$/i,
},
},
backgrounds: {
disable: true,
grid: {
disable: true,
},
},
layout: "padded",
darkMode: {
current: "light",
dark: { ...themes.dark },
light: { ...themes.light },
darkClass: "dark",
lightClass: "light",
classTarget: "html",
stylePreview: true,
},
},
decorators: [
(Story) => (
<div style={{ margin: "0" }}>
<RootProviders>
<Story />
</RootProviders>
</div>
),
(Story) => {
return (
<ThemeProvider defaultTheme="system">
<div className="min-h-screen w-[1200px] max-w-full bg-background text-foreground">
<RootProviders>
<div className="fixed right-4 top-4 z-50">
<ThemeSwitcher />
</div>
<div className="w-full p-4">
<Story />
</div>
</RootProviders>
</div>
</ThemeProvider>
)
},
],
}

Expand Down
63 changes: 63 additions & 0 deletions .storybook/theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { create } from "@storybook/theming/create"

export const lightTheme = create({
base: "light",
brandTitle: "My Storybook",
brandUrl: "/",

// Colors
colorPrimary: "#0099FF",
colorSecondary: "#0099FF",

// UI
appBg: "#F6F9FC",
appContentBg: "#FFFFFF",
appBorderColor: "rgba(0,0,0,.1)",
appBorderRadius: 4,

// Text colors
textColor: "#333333",
textInverseColor: "#FFFFFF",

// Toolbar default and active colors
barTextColor: "#999999",
barSelectedColor: "#0099FF",
barBg: "#FFFFFF",

// Form colors
inputBg: "#FFFFFF",
inputBorder: "rgba(0,0,0,.1)",
inputTextColor: "#333333",
inputBorderRadius: 4,
})

export const darkTheme = create({
base: "dark",
brandTitle: "My Storybook",
brandUrl: "/",

// Colors
colorPrimary: "#0099FF",
colorSecondary: "#0099FF",

// UI
appBg: "#1b1b1b",
appContentBg: "#262626",
appBorderColor: "rgba(255,255,255,.1)",
appBorderRadius: 4,

// Text colors
textColor: "#FFFFFF",
textInverseColor: "#333333",

// Toolbar default and active colors
barTextColor: "#999999",
barSelectedColor: "#0099FF",
barBg: "#1b1b1b",

// Form colors
inputBg: "#333333",
inputBorder: "rgba(255,255,255,.1)",
inputTextColor: "#FFFFFF",
inputBorderRadius: 4,
})
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,7 @@
"i18n-ally.namespace": true,
"i18n-ally.keystyle": "nested",
"i18n-ally.localesPaths": "locales",
"i18n-ally.displayLanguage": "zh-CN"
"i18n-ally.displayLanguage": "zh-CN",
"typescript.tsdk": "node_modules/typescript/lib",
"cSpell.words": ["autodocs", "hookform", "lucide", "ofetch", "tanstack"]
}
3 changes: 2 additions & 1 deletion locales/en/navigation.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
"basic_form": "Basic Form",
"step_form": "Step Form",
"advanced_form": "Advanced Form",
"basic_list": "Basic List",
"data_table": "Data Table",
"table_list": "Table List",
"pro_table": "Pro Table",
"card_list": "Card List",
"area_chart": "Area Chart",
"bar_chart": "Bar Chart",
Expand Down
3 changes: 2 additions & 1 deletion locales/zh-CN/navigation.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
"basic_form": "基本表单",
"step_form": "步骤表单",
"advanced_form": "高级表单",
"basic_list": "基本列表",
"data_table": "数据表格",
"table_list": "表格列表",
"pro_table": "高级表格",
"card_list": "卡片列表",
"area_chart": "面积图",
"bar_chart": "柱状图",
Expand Down
27 changes: 14 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,26 +91,27 @@
"rehype-raw": "^7.0.0",
"remark-gfm": "^4.0.0",
"sonner": "^1.6.1",
"storybook-dark-mode": "^4.0.2",
"tailwind-merge": "^2.5.4",
"tailwindcss-animate": "^1.0.7",
"vaul": "^0.9.9",
"zod": "^3.23.8"
},
"devDependencies": {
"@chromatic-com/storybook": "^1.9.0",
"@chromatic-com/storybook": "^3.2.2",
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"@faker-js/faker": "^8.4.1",
"@storybook/addon-essentials": "^8.4.1",
"@storybook/addon-interactions": "^8.4.1",
"@storybook/addon-links": "^8.4.1",
"@storybook/addon-onboarding": "^8.4.1",
"@storybook/blocks": "^8.4.1",
"@storybook/manager-api": "^8.4.1",
"@storybook/react": "^8.4.1",
"@storybook/react-vite": "^8.4.1",
"@storybook/test": "^8.4.1",
"@storybook/theming": "^8.4.1",
"@storybook/addon-essentials": "^8.4.2",
"@storybook/addon-interactions": "^8.4.2",
"@storybook/addon-links": "^8.4.2",
"@storybook/addon-onboarding": "^8.4.2",
"@storybook/blocks": "^8.4.2",
"@storybook/manager-api": "^8.4.2",
"@storybook/react": "^8.4.2",
"@storybook/react-vite": "^8.4.2",
"@storybook/test": "^8.4.2",
"@storybook/theming": "^8.4.2",
"@t3-oss/env-core": "^0.11.1",
"@tailwindcss/typography": "^0.5.15",
"@tanstack/react-query-devtools": "^5.59.17",
Expand All @@ -128,14 +129,14 @@
"click-to-react-component": "^1.1.0",
"eslint": "^9.14.0",
"eslint-config-hyoban": "^3.1.12",
"eslint-plugin-storybook": "^0.8.0",
"eslint-plugin-storybook": "^0.11.0",
"jsdom": "^25.0.1",
"lint-staged": "^15.2.10",
"postcss": "^8.4.47",
"release-it": "^17.10.0",
"release-it-pnpm": "^4.6.3",
"simple-git-hooks": "^2.11.1",
"storybook": "^8.4.1",
"storybook": "^8.4.2",
"tailwindcss": "^3.4.14",
"turbo": "^2.2.3",
"typescript": "^5.6.3",
Expand Down
Loading

0 comments on commit 7c13833

Please sign in to comment.