-
Notifications
You must be signed in to change notification settings - Fork 282
feat(sidebar): develop new component #2868
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
9de3122
chore: save my content
Miles-hxy 6317e51
chore: save my content
Miles-hxy daff164
chore: save my content
Miles-hxy 8010707
fix: adopt some AI adivice
Miles-hxy bec5d79
chore: add unit test rate
Miles-hxy 4354a63
chore: add unit test rate
Miles-hxy 4539dc5
feat: v15 style adaption
Miles-hxy fc0bdbd
feat: migrate doc update
Miles-hxy 96129ff
Merge branch 'feat_v3.x' into feat_sidebar
xiaoyatong 77f595c
Merge branch 'feat_v3.x' into feat_sidebar
xiaoyatong 25fce1e
Merge branch 'feat_v3.x' into feat_sidebar
xiaoyatong c7f1018
Merge branch 'feat_v3.x' into feat_sidebar
Miles-hxy a6c6a7a
fix: review
Miles-hxy e737a7c
fix: support word wrap
Miles-hxy 928c72a
fix: support word wrap
Miles-hxy c765272
Merge branch 'feat_v3.x' into feat_sidebar
Miles-hxy 8c77a94
fix: disabled
Miles-hxy e30d95f
fix: make css easier
Miles-hxy d1f0093
Merge branch 'feat_v3.x' into feat_sidebar
Miles-hxy 846e4c7
fix: adjust some doc details
Miles-hxy 1977729
Merge branch 'feat_v3.x' into feat_sidebar
Miles-hxy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import * as React from 'react' | ||
import { fireEvent, render } from '@testing-library/react' | ||
import '@testing-library/jest-dom' | ||
import { SideBar } from '../sidebar' | ||
|
||
const list = Array.from(new Array(3).keys()) | ||
|
||
test('should render defaultValue correctly', async () => { | ||
const { container } = render( | ||
<SideBar style={{ height: 300 }} value="0"> | ||
{list.map((item) => ( | ||
<SideBar.Item key={item} title={`Opt ${item + 1}`}> | ||
Content {item + 1} | ||
</SideBar.Item> | ||
))} | ||
</SideBar> | ||
) | ||
const item = container.querySelectorAll('.nut-sidebar-titles-item')[0] | ||
expect(item).toHaveClass('nut-sidebar-titles-item-active') | ||
}) | ||
Miles-hxy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
test('should choose and scroll to the right option', async () => { | ||
const onChange = vi.fn() | ||
const { container } = render( | ||
<SideBar style={{ height: 300 }} value="0" onChange={onChange}> | ||
{list.map((item) => ( | ||
<SideBar.Item key={item} title={`Opt ${item + 1}`}> | ||
Content {item + 1} | ||
</SideBar.Item> | ||
))} | ||
</SideBar> | ||
) | ||
const items = container.querySelectorAll('.nut-sidebar-titles-item') | ||
fireEvent.click(items[1]) | ||
expect(onChange).toHaveBeenCalledWith(1) | ||
}) | ||
Miles-hxy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
test('disabled option', async () => { | ||
const onChange = vi.fn() | ||
const { container } = render( | ||
<SideBar style={{ height: 300 }} value="0" onChange={onChange}> | ||
{list.map((item) => ( | ||
<SideBar.Item key={item} title={`Opt ${item + 1}`} disabled> | ||
Content {item + 1} | ||
</SideBar.Item> | ||
))} | ||
</SideBar> | ||
) | ||
const items = container.querySelectorAll('.nut-sidebar-titles-item') | ||
fireEvent.click(items[1]) | ||
expect(onChange).not.toHaveBeenCalled() | ||
}) | ||
Miles-hxy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
test('matchByValue', async () => { | ||
const list1 = [ | ||
{ value: 'a', title: 'Opt a Opt a Opt a Opt a' }, | ||
{ value: 'b', title: 'Opt b' }, | ||
{ value: 'c', title: 'Opt c' }, | ||
] | ||
const onChange = vi.fn() | ||
const { container } = render( | ||
<SideBar style={{ height: 300 }} value="b" onChange={onChange}> | ||
{list1.map((item) => ( | ||
<SideBar.Item key={item.value} title={item.title} value={item.value}> | ||
Content {item.value} | ||
</SideBar.Item> | ||
))} | ||
</SideBar> | ||
) | ||
const items = container.querySelectorAll('.nut-sidebar-titles-item') | ||
expect(items[1]).toHaveClass('nut-sidebar-titles-item-active') | ||
}) | ||
Miles-hxy marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React from 'react' | ||
import Taro from '@tarojs/taro' | ||
import { ScrollView, View } from '@tarojs/components' | ||
import { useTranslate } from '@/sites/assets/locale/taro' | ||
import Header from '@/sites/components/header' | ||
import Demo1 from './demos/taro/demo1' | ||
import Demo2 from './demos/taro/demo2' | ||
import Demo3 from './demos/taro/demo3' | ||
import Demo4 from './demos/taro/demo4' | ||
import Demo5 from './demos/taro/demo5' | ||
import Demo6 from './demos/taro/demo6' | ||
|
||
const TabsDemo = () => { | ||
const [translated] = useTranslate({ | ||
'zh-CN': { | ||
basic: '基础用法', | ||
disabled: '禁用选项', | ||
matchByValue: '根据value匹配', | ||
multiTitle: '多个标题', | ||
setDuration: '设置滚动动画时长', | ||
padding: '内容区域留白边距', | ||
}, | ||
'en-US': { | ||
basic: 'Basic Usage', | ||
disabled: 'Disabled', | ||
matchByValue: 'Match By Value', | ||
multiTitle: 'Multiple Titles', | ||
setDuration: 'Set Scroll Animation Duration', | ||
padding: 'Set Content Padding', | ||
}, | ||
}) | ||
|
||
return ( | ||
<> | ||
<Header /> | ||
<ScrollView | ||
className={`demo ${Taro.getEnv() === 'WEB' ? 'web full' : ''}`} | ||
> | ||
<View className="h2">{translated.basic}</View> | ||
<Demo1 /> | ||
<View className="h2">{translated.disabled}</View> | ||
<Demo2 /> | ||
<View className="h2">{translated.matchByValue}</View> | ||
<Demo3 /> | ||
<View className="h2">{translated.multiTitle}</View> | ||
<Demo4 /> | ||
<View className="h2">{translated.setDuration}</View> | ||
<Demo5 /> | ||
<View className="h2">{translated.padding}</View> | ||
<Demo6 /> | ||
</ScrollView> | ||
</> | ||
) | ||
} | ||
|
||
export default TabsDemo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React from 'react' | ||
import { useTranslate } from '@/sites/assets/locale' | ||
import Demo1 from './demos/h5/demo1' | ||
import Demo2 from './demos/h5/demo2' | ||
import Demo3 from './demos/h5/demo3' | ||
import Demo4 from './demos/h5/demo4' | ||
import Demo5 from './demos/h5/demo5' | ||
Miles-hxy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import Demo6 from './demos/h5/demo6' | ||
|
||
const SideNavBarDemo = () => { | ||
const [translated] = useTranslate({ | ||
'zh-CN': { | ||
basic: '基础用法', | ||
disabled: '禁用选项', | ||
matchByValue: '根据value匹配', | ||
multiTitle: '多个标题', | ||
setDuration: '设置滚动动画时长', | ||
padding: '内容区域留白边距', | ||
}, | ||
'en-US': { | ||
basic: 'Basic Usage', | ||
disabled: 'Disabled', | ||
matchByValue: 'Match By Value', | ||
multiTitle: 'Multiple Titles', | ||
setDuration: 'Set Scroll Animation Duration', | ||
padding: 'Set Content Padding', | ||
}, | ||
}) | ||
|
||
return ( | ||
<> | ||
<div className="demo"> | ||
<h2>{translated.basic}</h2> | ||
<Demo1 /> | ||
<h2>{translated.disabled}</h2> | ||
<Demo2 /> | ||
<h2>{translated.matchByValue}</h2> | ||
<Demo3 /> | ||
<h2>{translated.multiTitle}</h2> | ||
<Demo4 /> | ||
<h2>{translated.setDuration}</h2> | ||
<Demo5 /> | ||
<h2>{translated.padding}</h2> | ||
<Demo6 /> | ||
</div> | ||
</> | ||
) | ||
} | ||
|
||
export default SideNavBarDemo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React, { useState } from 'react' | ||
import { SideBar } from '@nutui/nutui-react' | ||
|
||
const Demo1 = () => { | ||
const [value, setValue] = useState<number | string>('0') | ||
const list = Array.from(new Array(3).keys()) | ||
return ( | ||
<> | ||
<SideBar | ||
style={{ height: 300 }} | ||
value={value} | ||
onChange={(value) => { | ||
setValue(value) | ||
}} | ||
> | ||
{list.map((item) => ( | ||
<SideBar.Item key={item} title={`Opt ${item + 1}`}> | ||
Content {item + 1} | ||
</SideBar.Item> | ||
))} | ||
</SideBar> | ||
</> | ||
) | ||
} | ||
export default Demo1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React, { useState } from 'react' | ||
import { SideBar } from '@nutui/nutui-react' | ||
|
||
const Demo2 = () => { | ||
const [value, setValue] = useState<number | string>('0') | ||
return ( | ||
<> | ||
<SideBar | ||
style={{ height: 300 }} | ||
value={value} | ||
onChange={(value) => { | ||
setValue(value) | ||
}} | ||
> | ||
<SideBar.Item title="Opt 1">Content 1</SideBar.Item> | ||
<SideBar.Item title="Opt 2">Content 2</SideBar.Item> | ||
<SideBar.Item title="Opt 3" disabled /> | ||
</SideBar> | ||
</> | ||
) | ||
} | ||
export default Demo2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React, { useState } from 'react' | ||
import { SideBar } from '@nutui/nutui-react' | ||
|
||
const Demo3 = () => { | ||
const [value, setValue] = useState<number | string>('b') | ||
return ( | ||
<> | ||
<SideBar | ||
style={{ height: 300 }} | ||
value={value} | ||
onChange={(value) => { | ||
setValue(value) | ||
}} | ||
> | ||
<SideBar.Item title="Opt 1" value="a"> | ||
Content 1 | ||
</SideBar.Item> | ||
<SideBar.Item title="Opt 2" value="b"> | ||
Content 2 | ||
</SideBar.Item> | ||
<SideBar.Item title="Opt 3" value="c"> | ||
Content 3 | ||
</SideBar.Item> | ||
</SideBar> | ||
</> | ||
) | ||
} | ||
export default Demo3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React, { useState } from 'react' | ||
import { SideBar } from '@nutui/nutui-react' | ||
|
||
const Demo4 = () => { | ||
const [value, setValue] = useState<number | string>('0') | ||
const list = Array.from(new Array(20).keys()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 建议优化大列表渲染性能 当列表项较多时,建议使用虚拟列表来优化性能。可以考虑使用 另外,建议将列表数据抽离到组件外部: +const SIDEBAR_ITEMS = Array.from(new Array(20).keys()).map((item) => ({
+ key: item,
+ title: `Opt ${item + 1}`,
+ content: `Content ${item + 1}`,
+}))
const Demo4 = () => {
const [value, setValue] = useState<string>('0')
- const list = Array.from(new Array(20).keys()) Also applies to: 16-20 |
||
return ( | ||
<> | ||
<SideBar | ||
style={{ height: 300 }} | ||
value={value} | ||
onChange={(value) => { | ||
setValue(value) | ||
}} | ||
> | ||
{list.map((item) => ( | ||
<SideBar.Item key={item} title={`Opt ${item + 1}`}> | ||
Content {item + 1} | ||
</SideBar.Item> | ||
))} | ||
</SideBar> | ||
</> | ||
) | ||
} | ||
export default Demo4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React, { useState } from 'react' | ||
import { SideBar } from '@nutui/nutui-react' | ||
|
||
const Demo5 = () => { | ||
const [value, setValue] = useState<number | string>('0') | ||
const list = Array.from(new Array(20).keys()) | ||
return ( | ||
<> | ||
<SideBar | ||
style={{ height: 300 }} | ||
value={value} | ||
contentDuration={500} | ||
sidebarDuration={300} | ||
onChange={(value) => { | ||
setValue(value) | ||
}} | ||
> | ||
{list.map((item) => ( | ||
<SideBar.Item key={item} title={`Opt ${item + 1}`}> | ||
Content {item + 1} | ||
</SideBar.Item> | ||
))} | ||
</SideBar> | ||
</> | ||
) | ||
} | ||
export default Demo5 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.