Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(Tabs): Separate Tabs into Tabs and VerticalTabs #2699

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 140 additions & 0 deletions packages/nutui-taro-demo/src/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@

const subPackages = [
{
"root": "base",
"pages": [
"pages/button/index",
"pages/cell/index",
"pages/configprovider/index",
"pages/icon/index",
"pages/image/index",
"pages/overlay/index"
]
},
{
"root": "layout",
"pages": [
"pages/divider/index",
"pages/grid/index",
"pages/layout/index",
"pages/safearea/index",
"pages/space/index",
"pages/sticky/index"
]
},
{
"root": "nav",
"pages": [
"pages/backtop/index",
"pages/elevator/index",
"pages/fixednav/index",
"pages/hoverbutton/index",
"pages/navbar/index",
"pages/sidenavbar/index",
"pages/tabbar/index",
"pages/tabs/index",
"pages/verticaltabs/index"
Comment on lines +35 to +36
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

需要添加垂直标签页面的具体实现

根据验证结果,虽然在 app.config.ts 中添加了页面配置,但是在 packages/nutui-taro-demo/src/pages/verticaltabs/ 目录下尚未找到对应的页面实现文件。

建议:

  • packages/nutui-taro-demo/src/pages/verticaltabs/ 目录下创建 index.tsx 文件
  • 参考现有的 tabs demo 页面实现垂直标签的演示页面
  • 确保新页面正确引用并展示 VerticalTabs 组件
🔗 Analysis chain

新增垂直标签页面配置正确!

页面配置的位置合理,与现有的标签页面放在同一个导航子包中,保持了良好的组织结构。

请运行以下脚本验证新页面的实现:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:验证垂直标签页面的实现文件是否存在

# 测试:检查页面实现文件是否存在
fd "index\.(tsx|jsx|ts|js)$" -p "nav/pages/verticaltabs"

# 测试:检查页面是否已在演示文档中添加
rg "verticaltabs" -t md

Length of output: 190


Script:

#!/bin/bash
# 检查正确的页面路径
fd "index\.(tsx|jsx|ts|js)$" "pages/verticaltabs"

# 检查是否有相关的文档或引用
rg -g "!*.{lock,svg}" "verticaltabs"

# 检查Tabs相关组件的实现
fd "tabs" -t f "src"

Length of output: 1081


Script:

#!/bin/bash
# 检查demo目录下的页面实现
fd "index\.(tsx|jsx|ts|js)$" "packages/nutui-taro-demo"

# 检查verticaltabs的具体实现
rg -A 5 "const VerticalTabs" src/packages/verticaltabs/

Length of output: 1112

Comment on lines +35 to +36
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

需要创建垂直选项卡示例页面

在app.config.ts中添加了路由配置,但是对应的页面文件夹和组件尚未创建。请注意:

  • 需要在 packages/nutui-taro-demo/src/pages/verticaltabs/ 创建相关页面文件
  • 确保创建 index.tsxindex.config.ts 文件
  • 参考现有的Tabs示例页面实现VerticalTabs的展示
🔗 Analysis chain

页面路由配置正确添加

新增的垂直选项卡页面路由配置符合现有规范,且放置在正确的导航组件子包中。

执行以下脚本以验证页面路由的唯一性:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查是否存在重复的页面路由配置
# 预期结果:不应该有重复的页面路由

# 搜索所有可能包含页面路由配置的文件
rg "pages/verticaltabs/index" 

Length of output: 105


Script:

#!/bin/bash
# 检查垂直选项卡页面文件是否存在
fd "index\.(tsx?|jsx?)" -p packages/nutui-taro-demo/src/pages/verticaltabs/

# 检查其他配置文件中是否有相关路由
rg -g "*.config.*" "verticaltabs"

# 检查是否有相关的组件引用
rg "VerticalTabs" -A 2

Length of output: 9849


Script:

#!/bin/bash
# 检查demo页面文件是否存在
fd -p "demo" packages/nutui-taro-demo/src/pages/verticaltabs/

# 检查是否有相关的路由配置文件
fd -p "index.config" packages/nutui-taro-demo/src/pages/verticaltabs/

# 检查pages目录结构
fd -t d "pages" packages/nutui-taro-demo/src/

Length of output: 485

]
},
{
"root": "dentry",
"pages": [
"pages/address/index",
"pages/calendar/index",
"pages/calendarcard/index",
"pages/cascader/index",
"pages/checkbox/index",
"pages/datepicker/index",
"pages/form/index",
"pages/input/index",
"pages/inputnumber/index"
]
},
{
"root": "dataentry",
"pages": [
"pages/menu/index",
"pages/numberkeyboard/index",
"pages/picker/index",
"pages/radio/index",
"pages/range/index",
"pages/rate/index",
"pages/searchbar/index",
"pages/shortpassword/index",
"pages/signature/index",
"pages/switch/index",
"pages/textarea/index",
"pages/uploader/index"
]
},
{
"root": "feedback",
"pages": [
"pages/actionsheet/index",
"pages/badge/index",
"pages/dialog/index",
"pages/drag/index",
"pages/empty/index",
"pages/infiniteloading/index",
"pages/loading/index",
"pages/noticebar/index",
"pages/notify/index",
"pages/popover/index",
"pages/popup/index",
"pages/pulltorefresh/index",
"pages/resultpage/index",
"pages/skeleton/index",
"pages/swipe/index",
"pages/toast/index"
]
},
{
"root": "exhibition",
"pages": [
"pages/animate/index",
"pages/animatingnumbers/index",
"pages/avatar/index",
"pages/circleprogress/index",
"pages/collapse/index",
"pages/countdown/index",
"pages/ellipsis/index",
"pages/imagepreview/index",
"pages/indicator/index",
"pages/pagination/index",
"pages/price/index",
"pages/progress/index",
"pages/steps/index",
"pages/swiper/index",
"pages/table/index",
"pages/tag/index",
"pages/tour/index",
"pages/video/index",
"pages/virtuallist/index"
]
},
{
"root": "business",
"pages": [
"pages/avatarcropper/index",
"pages/barrage/index",
"pages/card/index",
"pages/timeselect/index",
"pages/trendarrow/index",
"pages/watermark/index"
]
}
];

export default defineAppConfig({
pages: ['pages/index/index'],
subPackages,
window: {
backgroundTextStyle: 'light',
navigationBarBackgroundColor: '#fff',
navigationBarTitleText: 'NutUI-React',
navigationBarTextStyle: 'black'
},
components: ['pages/index/index', ...(subPackages.map(subPackage => {
return subPackage.pages.map(page => `${subPackage.root}/${page}`)
}).flat())]
})
13 changes: 12 additions & 1 deletion src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,23 @@
"version": "2.0.0",
"name": "Tabs",
"type": "component",
"cName": "选项卡切换",
"cName": "水平选项卡",
"desc": "常用于平级区域大块内容的的收纳和展现,支持内嵌标签形式和渲染循环数据形式",
"sort": 12,
"show": true,
"taro": true,
"author": "oasis"
},
{
"version": "2.0.0",
"name": "VerticalTabs",
"type": "component",
"cName": "垂直选项卡",
"desc": "常用于平级区域大块内容的的收纳和展现,支持内嵌标签形式和渲染循环数据形式",
"sort": 13,
"show": true,
"taro": true,
"author": "Alex.hxy"
}
]
},
Expand Down
6 changes: 3 additions & 3 deletions src/packages/tabs/__test__/tabs.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test('base Tabs', () => {

test('base tabs props', () => {
const { container } = render(
<Tabs value="0" direction="horizontal" activeType="smile">
<Tabs value="0" activeType="smile">
<TabPane title="Tab 1" value="0">
Tab 1
</TabPane>
Expand All @@ -31,7 +31,7 @@ test('base tabs props', () => {

test('base tabs props', () => {
const { container } = render(
<Tabs value="0" direction="horizontal" activeType="card">
<Tabs value="0" activeType="card">
<TabPane title="Tab 1" value="0">
Tab 1
</TabPane>
Expand Down Expand Up @@ -144,7 +144,7 @@ test('base click', () => {
test('click tab when have many tabs', async () => {
const handleClick = vi.fn(() => {})
const { container } = render(
<Tabs value="0" onClick={handleClick} direction="vertical">
<Tabs value="0" onClick={handleClick}>
<TabPane title="Tab 1" value="0">
Tab 1
</TabPane>
Expand Down
27 changes: 2 additions & 25 deletions src/packages/tabs/demo.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ import Demo15 from './demos/taro/demo15'
import Demo16 from './demos/taro/demo16'
import Demo17 from './demos/taro/demo17'
import Demo18 from './demos/taro/demo18'
import Demo19 from './demos/taro/demo19'
import Demo20 from './demos/taro/demo20'
import Demo21 from './demos/taro/demo21'
import Demo22 from './demos/taro/demo22'
import Demo23 from './demos/taro/demo23'

const TabsDemo = () => {
const [translated] = useTranslate({
Expand All @@ -40,10 +35,6 @@ const TabsDemo = () => {
title2: '通过 value 匹配',
title3: '数据异步渲染 3s',
title4: '数量多,滚动操作',
title5: '左右布局',
title6: '左右布局-微笑曲线',
title12: '嵌套布局',
title13: '嵌套布局 2',
title14: '滑动切换',
title7: 'Title 字体尺寸:20px 12px',
title8: '自定义标签栏',
Expand All @@ -64,10 +55,6 @@ const TabsDemo = () => {
title2: 'Match By Value',
title3: 'Data Is Rendered Asynchronously For 3s',
title4: 'A Large Number Of Scrolling Operations',
title5: 'Left And Right Layout',
title6: 'Left And Right Layout - Smile Curve',
title12: 'Tabs In Tabs',
title13: 'Tabs In Tabs 2',
title14: 'Slide To Switch',
title7: 'Title FontSize: 20px 12px',
title8: 'Custom Tab Bar',
Expand Down Expand Up @@ -118,20 +105,10 @@ const TabsDemo = () => {
<Demo15 />
<View className="h2">{translated.title4}</View>
<Demo16 />
<View className="h2">{translated.title4} 2</View>
<Demo17 />
<View className="h2">{translated.title5}</View>
<Demo18 />
<View className="h2">{translated.title6}</View>
<Demo19 />
<View className="h2">{translated.title12}</View>
<Demo20 />
<View className="h2">{translated.title13}</View>
<Demo21 />
<View className="h2">{translated.title7}</View>
<Demo22 />
<Demo17 />
<View className="h2">{translated.title8}</View>
<Demo23 />
<Demo18 />
</ScrollView>
</>
)
Expand Down
27 changes: 2 additions & 25 deletions src/packages/tabs/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ import Demo15 from './demos/h5/demo15'
import Demo16 from './demos/h5/demo16'
import Demo17 from './demos/h5/demo17'
import Demo18 from './demos/h5/demo18'
import Demo19 from './demos/h5/demo19'
import Demo20 from './demos/h5/demo20'
import Demo21 from './demos/h5/demo21'
import Demo22 from './demos/h5/demo22'
import Demo23 from './demos/h5/demo23'

const TabsDemo = () => {
const [translated] = useTranslate({
Expand All @@ -36,10 +31,6 @@ const TabsDemo = () => {
title2: '通过 value 匹配',
title3: '数据异步渲染 3s',
title4: '数量多,滚动操作',
title5: '左右布局',
title6: '左右布局-微笑曲线',
title12: '嵌套布局',
title13: '嵌套布局2',
title14: '滑动切换',
title7: 'Title 字体尺寸:20px 12px',
title8: '自定义标签栏',
Expand All @@ -60,10 +51,6 @@ const TabsDemo = () => {
title2: 'Match By Value',
title3: 'Data Is Rendered Asynchronously For 3s',
title4: 'A Large Number Of Scrolling Operations',
title5: 'Left And Right Layout',
title6: 'Left And Right Layout - Smile Curve',
title12: 'Tabs In Tabs',
title13: 'Tabs In Tabs 2',
title14: 'Slide To Switch',
title7: 'Title FontSize: 20px 12px',
title8: 'Custom Tab Bar',
Expand Down Expand Up @@ -111,20 +98,10 @@ const TabsDemo = () => {
<Demo15 />
<h2>{translated.title4}</h2>
<Demo16 />
<h2>{translated.title4} 2</h2>
<Demo17 />
<h2>{translated.title5}</h2>
<Demo18 />
<h2>{translated.title6}</h2>
<Demo19 />
<h2>{translated.title12}</h2>
<Demo20 />
<h2>{translated.title13}</h2>
<Demo21 />
<h2>{translated.title7}</h2>
<Demo22 />
<Demo17 />
<h2>{translated.title8}</h2>
<Demo23 />
<Demo18 />
</div>
</>
)
Expand Down
34 changes: 21 additions & 13 deletions src/packages/tabs/demos/h5/demo17.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
import React, { useState } from 'react'
import { Tabs } from '@nutui/nutui-react'

const Demo17 = () => {
const [tab4value, setTab4value] = useState<number | string>('0')
const list4 = Array.from(new Array(10).keys())
const Demo22 = () => {
const [tab11value, setTab11value] = useState<string | number>('0')
const [tab12value, setTab12value] = useState<string | number>('0')
return (
<>
<Tabs
value={tab4value}
style={{ height: '300px' }}
value={tab11value}
onChange={(value) => {
setTab4value(value)
setTab11value(value)
}}
direction="vertical"
style={{ '--nutui-tabs-titles-font-size': '20px' }}
>
{list4.map((item) => (
<Tabs.TabPane key={item} title={`Tab ${item}`}>
Tab {item}
</Tabs.TabPane>
))}
<Tabs.TabPane title="Tab 1"> Tab 1 </Tabs.TabPane>
<Tabs.TabPane title="Tab 2"> Tab 2 </Tabs.TabPane>
<Tabs.TabPane title="Tab 3"> Tab 3 </Tabs.TabPane>
</Tabs>
<Tabs
value={tab12value}
onChange={(value) => {
setTab12value(value)
}}
style={{ '--nutui-tabs-titles-font-size': '12px' }}
>
<Tabs.TabPane title="Tab 1"> Tab 1 </Tabs.TabPane>
<Tabs.TabPane title="Tab 2"> Tab 2 </Tabs.TabPane>
<Tabs.TabPane title="Tab 3"> Tab 3 </Tabs.TabPane>
Comment on lines +20 to +29
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

建议重构重复的标签页代码

当前代码存在明显的重复,两个标签页组件的结构完全相同,仅字体大小不同。建议提取可重用的组件来减少代码重复。

建议创建一个可复用的标签页组件:

interface CustomTabsProps {
  value: string | number
  onChange: (value: string | number) => void
  fontSize: 'large' | 'small'
  label: string
}

const CustomTabs: React.FC<CustomTabsProps> = ({ value, onChange, fontSize, label }) => (
  <Tabs
    value={value}
    onChange={onChange}
    style={{ '--nutui-tabs-titles-font-size': FONT_SIZES[fontSize] }}
    role="tablist"
    aria-label={label}
  >
    <Tabs.TabPane title="Tab 1" role="tabpanel">示例内容 1</Tabs.TabPane>
    <Tabs.TabPane title="Tab 2" role="tabpanel">示例内容 2</Tabs.TabPane>
    <Tabs.TabPane title="Tab 3" role="tabpanel">示例内容 3</Tabs.TabPane>
  </Tabs>
)

Comment on lines +20 to +29
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

第二个 Tabs 组件存在重复代码

两个 Tabs 组件的结构完全相同,只是字体大小不同。建议将重复的部分抽离为可复用的组件。

建议创建一个新的组件来处理这种重复的结构:

interface CustomTabsProps {
  value: string | number
  onChange: (value: string | number) => void
  fontSize: string
}

const CustomTabs: React.FC<CustomTabsProps> = ({ value, onChange, fontSize }) => (
  <Tabs
    value={value}
    onChange={onChange}
    style={{ '--nutui-tabs-titles-font-size': fontSize }}
  >
    <Tabs.TabPane title="Tab 1">
      <div className="content">标签页内容 1</div>
    </Tabs.TabPane>
    <Tabs.TabPane title="Tab 2">
      <div className="content">标签页内容 2</div>
    </Tabs.TabPane>
    <Tabs.TabPane title="Tab 3">
      <div className="content">标签页内容 3</div>
    </Tabs.TabPane>
  </Tabs>
)

</Tabs>
</>
)
}
export default Demo17
export default Demo22
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

导出语句需要与组件名保持一致

如果采纳了之前的建议将组件改名为 Demo17,这里的导出语句也需要相应修改。

-export default Demo22
+export default Demo17
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export default Demo22
export default Demo17

Loading
Loading