Skip to content

Commit 62ab93e

Browse files
committed
docs: aside,tabs
1 parent ff26b48 commit 62ab93e

13 files changed

Lines changed: 296 additions & 17 deletions

File tree

docs/components/aside/index.mdx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Aside
2+
3+
常用于侧边栏导航
4+
5+
## Playground
6+
7+
<code src="./playground.tsx" />
8+
9+
## API
10+
11+
### Aside
12+
13+
| Property | Description | Type | Default Value |
14+
| -------------- | ------------------------ | ----------------------------------------------------------------------------------- | ------------- |
15+
| defaultList`*` | 侧边栏菜单列表 | `AsideListItem[]` | - |
16+
| activeKey`*` | 选中的菜单 | `string` | - |
17+
| className | 类名 | `string` | - |
18+
| title | 顶部模块 | `ReactNode` | - |
19+
| footer | 底部模块 | `ReactNode` | - |
20+
| onNav | 点击菜单后触发的回掉函数 | `(value: { title: string;url?: string; icon?: LucideIcon; key?: string; }) => void` | - |
21+
22+
### AsideProvider
23+
24+
无输入参数
25+
26+
### useAside
27+
28+
#### 输出
29+
30+
| Property | Description | Type | Default Value |
31+
| -------- | -------------- | ------------ | ------------- |
32+
| open | 是否打开面板 | `boolean` | `false` |
33+
| toggle | 折叠当前侧边栏 | `() => void` | - |
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { AsideProvider, Aside, AsidebarTrigger, Button } from '@shilong/react'
2+
import { Calendar, Group, Home, KeyRound, Search, User } from 'lucide-react'
3+
import { useState } from 'react'
4+
5+
const items = [
6+
{
7+
groupTitle: 'User',
8+
menusList: [
9+
{
10+
title: 'Home',
11+
url: '/',
12+
icon: Home,
13+
key: 'home',
14+
},
15+
{
16+
title: 'User',
17+
url: '/user',
18+
icon: User,
19+
key: 'user',
20+
},
21+
{
22+
title: 'Group',
23+
icon: Group,
24+
children: [
25+
{
26+
title: 'Item1',
27+
url: '/item1',
28+
icon: Calendar,
29+
key: 'item1',
30+
},
31+
{
32+
title: 'Item2',
33+
url: '/item2',
34+
icon: Search,
35+
key: 'item2',
36+
},
37+
],
38+
},
39+
{
40+
title: 'Role',
41+
url: '/role',
42+
icon: KeyRound,
43+
key: 'role',
44+
},
45+
],
46+
},
47+
]
48+
49+
function App() {
50+
const [routeKey, setRouteKey] = useState('item1')
51+
52+
return (
53+
<AsideProvider>
54+
<div
55+
style={{
56+
display: 'flex',
57+
}}
58+
>
59+
<Aside
60+
activeKey={routeKey}
61+
defaultList={items}
62+
onNav={(v) => {
63+
v.key && setRouteKey(v.key)
64+
}}
65+
/>
66+
<div>
67+
<div>
68+
<AsidebarTrigger
69+
render={(val) => (
70+
<Button variant="outline" onClick={() => val.toggle()}>
71+
Toggle
72+
</Button>
73+
)}
74+
/>
75+
</div>
76+
<div>main</div>
77+
</div>
78+
</div>
79+
</AsideProvider>
80+
)
81+
}
82+
83+
export default App

docs/components/tabs/index.mdx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Tabs
2+
3+
常用于选择某一个标签值
4+
5+
## Playground
6+
7+
<code src="./playground.tsx" />
8+
9+
## API
10+
11+
### Tabs
12+
13+
| Property | Description | Type | Default Value |
14+
| -------- | ---------------------- | --------------------------------------------------------- | ------------- |
15+
| list`*` | 标签列表 | `{ label: string; value: string; disabled?: boolean; }[]` | - |
16+
| value | 选中的标签值 | `string` | - |
17+
| onChange | 选中或者关闭的回掉函数 | `(action: 'select' \| 'close', value: Item) => void` | - |
18+
| closable | 是否可以关闭标签 | `boolean` | - |
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Tabs } from '@shilong/react'
2+
3+
function App() {
4+
return (
5+
<Tabs
6+
list={[
7+
{
8+
label: '1111',
9+
value: '222',
10+
},
11+
{
12+
label: '222',
13+
value: '33',
14+
},
15+
]}
16+
onChange={(_, v) => {
17+
console.log(v)
18+
}}
19+
/>
20+
)
21+
}
22+
23+
export default App

playground/src/App.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Calendar, Group, Home, KeyRound, Search, User } from 'lucide-react'
22
import { Aside, AsidebarTrigger, useAside } from '../../src/components/aside'
33
import { AsideProvider } from '../../src/components/aside/context'
4+
import { Tabs } from '../../src/components/tabs/Tabs'
45

56
import { useState } from 'react'
67

@@ -70,6 +71,25 @@ export default function App() {
7071
render={(val) => <span onClick={() => val.toggle()}>nihao</span>}
7172
/>
7273
</div>
74+
<div>
75+
<Tabs
76+
list={[
77+
{
78+
label: '1111',
79+
value: '222',
80+
},
81+
{
82+
label: '222',
83+
value: '33',
84+
// disabled: true,
85+
},
86+
]}
87+
closable
88+
onChange={(a) => {
89+
console.log(a)
90+
}}
91+
/>
92+
</div>
7393
</div>
7494
</AsideProvider>
7595
</div>

rspress.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ const componentsList = [
4747
text: 'Skeleton',
4848
link: '/components/skeleton',
4949
},
50+
{
51+
text: 'Aside',
52+
link: '/components/aside',
53+
},
54+
{
55+
text: 'Tabs',
56+
link: '/components/tabs',
57+
},
5058
// {
5159
// text: 'DataTable',
5260
// link: '/components/data-table',
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { clsx } from '@shilong/utils'
2+
import type { ComponentProps } from 'react'
3+
import { base } from './styles.css'
4+
5+
export const ResetButton = (props: ComponentProps<'button'>) => {
6+
const { className, ...reset } = props
7+
8+
return <button className={clsx(base, className)} {...reset} />
9+
}

src/components/index.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/components/tabs/Tabs.tsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { clsx } from '@shilong/utils'
2+
import { ResetButton } from '../button/ResetButton'
3+
import * as styles from './styles.css'
4+
import { useState } from 'react'
5+
import { X } from 'lucide-react'
6+
import type { TabsProps } from './type'
7+
8+
const Tabs = (props: TabsProps) => {
9+
const { list, value, onChange, closable = false } = props
10+
11+
const [ownValue, setOwnValue] = useState(list[0].value)
12+
13+
const finalValue = value ?? ownValue
14+
15+
return (
16+
<div className={styles.container}>
17+
{list.map((tab) => (
18+
<ResetButton
19+
key={tab.value}
20+
className={clsx(
21+
styles.button,
22+
finalValue === tab.value && styles.buttonActive,
23+
)}
24+
disabled={tab.disabled}
25+
onClick={() => {
26+
setOwnValue(tab.value)
27+
onChange?.('select', tab)
28+
}}
29+
>
30+
{tab.label}
31+
{closable && (
32+
<X
33+
className={styles.icon}
34+
onClick={(e) => {
35+
e.stopPropagation()
36+
onChange?.('close', tab)
37+
}}
38+
/>
39+
)}
40+
</ResetButton>
41+
))}
42+
</div>
43+
)
44+
}
45+
46+
export { Tabs }

src/components/tabs/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './Tabs'

0 commit comments

Comments
 (0)