-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(TabBar): TabBar组件对齐 mobile-vue (#482)
* fix: 更新样式文件 * feat(Demo): 升级TabBar示例 * fix(TabBar-type): 修复TabBar类型错误 * fix(TabBar-type): 同步新类型 * feat(TabBarItem): 增加tab-bar-item/样式 * feat(Demo): 升级TabBar示例 * feat(Demo): 组件TabBar自定义示例升级 * feat(TabBar-type): 增加TabBarContext类型 * feat(TabBar): 完成TabBar逻辑迁移 * feat(TabBar): 加上parseTNode * chore: 更新snap * feat(TabBar-API): 同步TabBar的API文档 * chore: update common * chore(TabBar): update snap * chore(TabBar): sync common file * chore: 变更common分支 * chore(TabBar): update tdesign-api * fix: 去掉旧的默认值定义 * refactor(TabBar): 改用usePrefixClass、useDefaultProps * chore(TabBar): update api * chore: 更改common到develop * refactor(TabBar): 简化逻辑 --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
b346021
commit 8a52e88
Showing
22 changed files
with
2,235 additions
and
177 deletions.
There are no files selected for viewing
This file contains 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
Submodule _common
updated
2 files
+25 −0 | docs/mobile/api/side-bar.en-US.md | |
+25 −0 | docs/mobile/api/side-bar.md |
This file contains 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 |
---|---|---|
@@ -1,47 +1,59 @@ | ||
import React, { forwardRef, memo, useMemo, useRef } from 'react'; | ||
import cls from 'classnames'; | ||
import useConfig from '../_util/useConfig'; | ||
import useDefault from '../_util/useDefault'; | ||
import type { StyledProps } from '../common'; | ||
import type { TdTabBarProps } from './type'; | ||
import { TabBarProvider } from './TabBarContext'; | ||
import parseTNode from '../_util/parseTNode'; | ||
import useDefaultProps from '../hooks/useDefaultProps'; | ||
import { usePrefixClass } from '../hooks/useClass'; | ||
import { tabBarDefaultProps } from './defaultProps'; | ||
|
||
export interface TabBarProps extends TdTabBarProps, StyledProps {} | ||
|
||
const TabBar = forwardRef<HTMLDivElement, TabBarProps>((props, ref) => { | ||
const { bordered, fixed, onChange, value, defaultValue } = props; | ||
const { classPrefix } = useConfig(); | ||
const name = `${classPrefix}-tab-bar`; | ||
const TabBar = forwardRef<HTMLDivElement, TabBarProps>((originProps, ref) => { | ||
const props = useDefaultProps(originProps, tabBarDefaultProps); | ||
const { bordered, fixed, onChange, value, defaultValue, safeAreaInsetBottom, shape, split, theme, children } = props; | ||
|
||
const tabBarClass = usePrefixClass('tab-bar'); | ||
const [activeValue, onToggleActiveValue] = useDefault(value, defaultValue, onChange); | ||
|
||
const defaultIndex = useRef(-1); | ||
|
||
const updateChild = onToggleActiveValue; | ||
|
||
const tabBarClass = cls(name, { | ||
[`${name}--bordered`]: bordered, | ||
[`${name}--fixed`]: fixed, | ||
}); | ||
const itemCount = React.Children.count(parseTNode(children)); | ||
|
||
const memoProviderValues = useMemo( | ||
() => ({ | ||
defaultIndex, | ||
activeValue, | ||
updateChild, | ||
shape, | ||
split, | ||
theme, | ||
itemCount, | ||
}), | ||
[defaultIndex, activeValue, updateChild], | ||
[defaultIndex, activeValue, updateChild, shape, split, theme, itemCount], | ||
); | ||
|
||
return ( | ||
<div className={tabBarClass} ref={ref}> | ||
<TabBarProvider value={memoProviderValues}>{props.children}</TabBarProvider> | ||
<div | ||
className={cls( | ||
tabBarClass, | ||
{ | ||
[`${tabBarClass}--bordered`]: bordered, | ||
[`${tabBarClass}--fixed`]: fixed, | ||
[`${tabBarClass}--safe`]: safeAreaInsetBottom, | ||
}, | ||
`${tabBarClass}--${props.shape}`, | ||
)} | ||
ref={ref} | ||
role="tablist" | ||
> | ||
<TabBarProvider value={memoProviderValues}>{parseTNode(children)}</TabBarProvider> | ||
</div> | ||
); | ||
}); | ||
|
||
TabBar.defaultProps = { | ||
bordered: true, | ||
fixed: true, | ||
}; | ||
|
||
export default memo(TabBar); |
This file contains 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 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 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,41 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { TabBar, TabBarItem } from 'tdesign-mobile-react'; | ||
import { Icon } from 'tdesign-icons-react'; | ||
|
||
function TabBarBaseDemo() { | ||
const list = [ | ||
{ name: 'label_1', text: '首页', icon: 'home', badgeProps: { count: 16 }, ariaLabel: '首页,有16条消息' }, | ||
{ name: 'label_2', text: '软件', icon: 'app', badgeProps: { dot: true }, ariaLabel: '软件,有新的消息' }, | ||
{ name: 'label_3', text: '聊天', icon: 'chat', badgeProps: { count: 'New' }, ariaLabel: '聊天,New' }, | ||
{ name: 'label_4', text: '我的', icon: 'user', badgeProps: { count: '···' }, ariaLabel: '我的,有很多消息' }, | ||
]; | ||
const [value, setValue] = useState('label_1'); | ||
|
||
const change = (changeValue) => { | ||
setValue(changeValue); | ||
console.log('TabBar 值改变为:', changeValue); | ||
}; | ||
|
||
useEffect(() => { | ||
console.log('当前值:', value); | ||
}, [value]); | ||
|
||
return ( | ||
<div className="demo-tab-bar"> | ||
<TabBar value={value} onChange={change} split={false}> | ||
{list.map((item, i) => ( | ||
<TabBarItem | ||
key={item.name || i} | ||
icon={<Icon name={item.icon} />} | ||
value={item.name} | ||
badgeProps={item.badgeProps} | ||
> | ||
{item.text} | ||
</TabBarItem> | ||
))} | ||
</TabBar> | ||
</div> | ||
); | ||
} | ||
|
||
export default TabBarBaseDemo; |
This file contains 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
Oops, something went wrong.