From 963ea85ae0c04166517f63e1c5d86091d3384084 Mon Sep 17 00:00:00 2001 From: zhongyuan Date: Wed, 26 Oct 2022 16:38:39 +0800 Subject: [PATCH] docs(tabBar): update tabBar doc and demo --- src/tab-bar/_example/badge-props.jsx | 36 ++++++ src/tab-bar/_example/base.jsx | 53 +++------ src/tab-bar/_example/icon-text.jsx | 69 ----------- src/tab-bar/_example/mobile.jsx | 172 +++------------------------ src/tab-bar/_example/pure-icon.jsx | 61 +++------- src/tab-bar/_example/text-spread.jsx | 45 +++---- src/tab-bar/_example/text.jsx | 35 ++++++ 7 files changed, 131 insertions(+), 340 deletions(-) create mode 100644 src/tab-bar/_example/badge-props.jsx delete mode 100644 src/tab-bar/_example/icon-text.jsx create mode 100644 src/tab-bar/_example/text.jsx diff --git a/src/tab-bar/_example/badge-props.jsx b/src/tab-bar/_example/badge-props.jsx new file mode 100644 index 00000000..8c6fab1b --- /dev/null +++ b/src/tab-bar/_example/badge-props.jsx @@ -0,0 +1,36 @@ +import React, { useState, useEffect } from 'react'; +import { TabBar, TabBarItem } from 'tdesign-mobile-react'; +import { AppIcon } from 'tdesign-icons-react'; + +function TabBarBaseDemo() { + const list = [ + { name: 'label_1', text: '文字', icon: , badgeProps: { count: 16 } }, + { name: 'label_2', text: '文字', icon: , badgeProps: { dot: true } }, + { name: 'label_3', text: '文字', icon: , badgeProps: { count: 'New' } }, + { name: 'label_4', text: '文字', icon: , badgeProps: { count: '···' } }, + ]; + const [value, setValue] = useState('label_1'); + + const change = (changeValue) => { + setValue(changeValue); + console.log('TabBar 值改变为:', changeValue); + }; + + useEffect(() => { + console.log('当前值:', value); + }, [value]); + + return ( +
+ + {list.map((item, i) => ( + + {item.text} + + ))} + +
+ ); +} + +export default TabBarBaseDemo; diff --git a/src/tab-bar/_example/base.jsx b/src/tab-bar/_example/base.jsx index bb82a26d..a3a46da6 100644 --- a/src/tab-bar/_example/base.jsx +++ b/src/tab-bar/_example/base.jsx @@ -1,36 +1,15 @@ import React, { useState, useEffect } from 'react'; import { TabBar, TabBarItem } from 'tdesign-mobile-react'; +import { AppIcon } from 'tdesign-icons-react'; function TabBarBaseDemo() { - const list1 = [ - { - name: 'label_1', - text: '标签一', - icon: undefined, - }, - { - name: 'label_2', - text: '标签二', - icon: undefined, - }, + const list = [ + { name: 'label_1', text: '文字', icon: }, + { name: 'label_2', text: '文字', icon: }, + { name: 'label_3', text: '文字', icon: }, + { name: 'label_4', text: '文字', icon: }, ]; - const list2 = [ - ...list1, - { - name: 'label_3', - text: '标签三', - icon: undefined, - }, - ]; - const list3 = [ - ...list2, - { - name: 'label_4', - text: '标签四', - icon: undefined, - }, - ]; - const [value, setValue] = useState('label_2'); + const [value, setValue] = useState('label_1'); const change = (changeValue) => { setValue(changeValue); @@ -41,19 +20,15 @@ function TabBarBaseDemo() { console.log('当前值:', value); }, [value]); - const demoList = [list1, list2, list3]; - return (
- {demoList.map((demo, idx) => ( - - {demo.map((item, i) => ( - - {item.text} - - ))} - - ))} + + {list.map((item, i) => ( + + {item.text} + + ))} +
); } diff --git a/src/tab-bar/_example/icon-text.jsx b/src/tab-bar/_example/icon-text.jsx deleted file mode 100644 index 34261158..00000000 --- a/src/tab-bar/_example/icon-text.jsx +++ /dev/null @@ -1,69 +0,0 @@ -/* eslint-disable camelcase */ -import React, { useEffect, useState } from 'react'; -import { TabBar, TabBarItem } from 'tdesign-mobile-react'; - -import { AppIcon } from 'tdesign-icons-react'; - -export default function TabBarIconTextDemo() { - const [value, setValue] = useState(null); - const list_1 = [ - { - name: 'label_1', - text: '标签一', - }, - { - name: 'label_2', - text: '标签二', - }, - ]; - const list_2 = [ - ...list_1, - { - name: 'label_3', - text: '标签三', - }, - ]; - const list_3 = [ - ...list_2, - { - name: 'label_4', - text: '标签四', - }, - ]; - const list_4 = [ - ...list_3, - { - name: 'label_5', - text: '标签五', - }, - ]; - - const change = (changeValue) => { - setValue(changeValue); - console.log('TabBar 值改变为:', changeValue); - }; - - useEffect(() => { - console.log('当前值:', value); - }, [value]); - - const demoList = [list_1, list_2, list_3, list_4]; - - return ( -
- {demoList.map((list, idx) => ( - - }> - hello world - - {list.map((item, i) => ( - } key={item.name || i} name={item.name}> - {item.text} - - ))} - - ))} - -
- ); -} diff --git a/src/tab-bar/_example/mobile.jsx b/src/tab-bar/_example/mobile.jsx index 2787b76d..d7e63e98 100644 --- a/src/tab-bar/_example/mobile.jsx +++ b/src/tab-bar/_example/mobile.jsx @@ -1,173 +1,33 @@ -import React, { useCallback, useState } from 'react'; -import { TabBar, TabBarItem } from 'tdesign-mobile-react'; -import { AppIcon } from 'tdesign-icons-react'; - +import React from 'react'; import TDemoBlock from '../../../site/mobile/components/DemoBlock'; import TDemoHeader from '../../../site/mobile/components/DemoHeader'; -import './style/index.less'; - -const list1 = [ - { - name: 'label_1', - text: '标签一', - children: [], - badge: {}, - }, - { - name: 'label_2', - text: '标签二', - children: [], - badge: {}, - }, -]; -const list2 = [ - ...list1, - { - name: 'label_3', - text: '标签三', - children: [], - badge: {}, - }, -]; -const list3 = [ - ...list2, - { - name: 'label_4', - text: '标签四', - children: [], - badge: {}, - }, -]; -const list4 = [ - ...list3, - { - name: 'label_5', - text: '标签五', - children: [], - badge: {}, - }, -]; - -const list5 = [ - ...list1, - { - name: 'label_3', - text: '此处展开', - children: [ - { - value: 'spread_1', - label: '展开项一', - }, - { - value: 'spread_2', - label: '展开项二', - }, - { - value: 'spread_3', - label: '展开项三', - }, - ], - }, -]; - -const list6 = [ - { - name: 'label_1', - text: '标签一', - children: [], - badge: { - count: '16', - }, - }, - { - name: 'label_2', - text: '标签二', - children: [], - badge: { - dot: true, - }, - }, - { - name: 'label_3', - text: '标签三', - children: [], - badge: { - count: 'New', - }, - }, - { - name: 'label_4', - text: '标签四', - children: [], - badge: { - count: '···', - }, - }, -]; +import BaseDemo from './base'; +import BadgePropsDemo from './badge-props'; +import TextDemo from './text'; +import PureIconDemo from './pure-icon'; +import TextSpreadDemo from './text-spread'; -const demoList1 = [list1, list2, list3]; -const demoList2 = [list1, list2, list3, list4, list6]; -const demoList3 = [list1, list2, list3, list4]; - -const defaultValue = 'label_1'; +import './style/index.less'; function TabBarMobileDemo() { - const [value, setValue] = useState(1); - - const change = useCallback((changeValue) => { - setValue(changeValue); - console.log('TabBar 值改变为:', changeValue); - }, []); - return (
- - {demoList1.map((demo, index) => ( - - {demo.map((item, idx) => ( - - {item.text} - - ))} - - ))} + + + + + - - {demoList2.map((demo, index) => ( - - {demo.map((item, idx) => ( - } - value={item.name} - > - {item.text} - - ))} - - ))} + + - {demoList3.map((demo, index) => ( - - {demo.map((item, idx) => ( - } value={item.name}> - ))} - - ))} + - - {list5.map((item, idx) => ( - - {item.text} - - ))} - +
); diff --git a/src/tab-bar/_example/pure-icon.jsx b/src/tab-bar/_example/pure-icon.jsx index 68531c97..813d0479 100644 --- a/src/tab-bar/_example/pure-icon.jsx +++ b/src/tab-bar/_example/pure-icon.jsx @@ -1,60 +1,29 @@ -/* eslint-disable camelcase */ -import React, { useEffect, useState } from 'react'; +import React, { useState, useEffect } from 'react'; import { TabBar, TabBarItem } from 'tdesign-mobile-react'; import { AppIcon } from 'tdesign-icons-react'; -export default function PureIconDemo() { - const [value, setValue] = useState(null); - const list_1 = [ - { - name: 'label_1', - }, - { - name: 'label_2', - }, - ]; - const list_2 = [ - ...list_1, - { - name: 'label_3', - }, - ]; - const list_3 = [ - ...list_2, - { - name: 'label_4', - }, - ]; - const list_4 = [ - ...list_3, - { - name: 'label_5', - }, - ]; - - const demoList = [list_1, list_2, list_3, list_4]; - - useEffect( - (newValue) => { - console.log('当前值:', newValue); - }, - [value], - ); +function TabBarBaseDemo() { + const list = [{ name: 'label_1' }, { name: 'label_2' }, { name: 'label_3' }, { name: 'label_4' }]; + const [value, setValue] = useState('label_1'); const change = (changeValue) => { setValue(changeValue); console.log('TabBar 值改变为:', changeValue); }; + useEffect(() => { + console.log('当前值:', value); + }, [value]); + return (
- {demoList.map((list, index) => ( - - {list.map((item, idx) => ( - } key={item.name || idx} name={item.name || idx}> - ))} - - ))} + + {list.map((item, i) => ( + } value={item.name} /> + ))} +
); } + +export default TabBarBaseDemo; diff --git a/src/tab-bar/_example/text-spread.jsx b/src/tab-bar/_example/text-spread.jsx index b212b6dd..0b4b2883 100644 --- a/src/tab-bar/_example/text-spread.jsx +++ b/src/tab-bar/_example/text-spread.jsx @@ -1,58 +1,41 @@ -/* eslint-disable camelcase */ -import React, { useEffect, useState } from 'react'; +import React from 'react'; import { TabBar, TabBarItem } from 'tdesign-mobile-react'; -export default function TextSpreadDemo() { - const [value, setValue] = useState(null); +function TabBarBaseDemo() { const list = [ { name: 'label_1', - text: '标签一', - icon: undefined, + text: '标签栏一', }, { name: 'label_2', - text: '标签二', - icon: undefined, + text: '标签栏二', }, { name: 'label_3', text: '此处展开', - icon: undefined, children: [ { - name: 'spread_1', - text: '展开项一', - icon: undefined, + value: 'spread_3', + label: '展开项三', }, { - name: 'spread_2', - text: '展开项二', - icon: undefined, + value: 'spread_2', + label: '展开项二', }, { - name: 'spread_3', - text: '展开项三', - icon: undefined, + value: 'spread_1', + label: '展开项一', }, ], }, ]; - useEffect(() => { - console.log('当前值:', value); - }, [value]); - - const change = (changeValue) => { - setValue(changeValue); - console.log('TabBar 值改变为:', changeValue); - }; - return (
- - {list.map((item, index) => ( - + + {list.map((item, i) => ( + {item.text} ))} @@ -60,3 +43,5 @@ export default function TextSpreadDemo() {
); } + +export default TabBarBaseDemo; diff --git a/src/tab-bar/_example/text.jsx b/src/tab-bar/_example/text.jsx new file mode 100644 index 00000000..66c816bd --- /dev/null +++ b/src/tab-bar/_example/text.jsx @@ -0,0 +1,35 @@ +import React, { useState, useEffect } from 'react'; +import { TabBar, TabBarItem } from 'tdesign-mobile-react'; + +function TabBarBaseDemo() { + const list = [ + { name: 'label_1', text: '标签栏一' }, + { name: 'label_2', text: '标签栏二' }, + { name: 'label_3', text: '标签栏三' }, + { name: 'label_4', text: '标签栏四' }, + ]; + const [value, setValue] = useState('label_1'); + + const change = (changeValue) => { + setValue(changeValue); + console.log('TabBar 值改变为:', changeValue); + }; + + useEffect(() => { + console.log('当前值:', value); + }, [value]); + + return ( +
+ + {list.map((item, i) => ( + + {item.text} + + ))} + +
+ ); +} + +export default TabBarBaseDemo;