浏览代码

chore: doc

DaiQiangReal 1 年之前
父节点
当前提交
c1f8fc7faa

+ 50 - 33
content/navigation/tabs/index-en-US.md

@@ -378,33 +378,34 @@ class App extends React.Component {
 
 **Modify the scrolling rendering overflow item indicator**
 
-`renderOverflowItem` modifies the overflow item indicator, with the input parameters being the overflowed items and position
+`renderArrow` modifies the overflow item indicator, with the input parameters being the overflowed items and position
 
 ```jsx live=true dir="column"
 import React from 'react';
 import { Tabs, TabPane } from '@douyinfe/semi-ui';
 
 ()=>{
-    const [activeKey,setActiveKey] = useState("item-1")
-    return  <Tabs style={{ width: '50%', margin: '20px' }} activeKey={activeKey}  type="card" collapsible renderOverflowItem={(items,pos)=>{
-      return <Dropdown render={
-        <Dropdown.Menu>
-          {items.map(item=>{
-            return  <Dropdown.Item onClick={()=>setActiveKey(item.itemKey)}>{item.itemKey}</Dropdown.Item>
-          })}
-        </Dropdown.Menu>
-      }>
-        <Button>
-          {pos}
-        </Button>
-      </Dropdown>
-    }}>
-      {[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(i => (
-              <TabPane tab={`Tab-${i}`} itemKey={`Tab-${i}`} key={i}>
-                Content of card tab {i}
-              </TabPane>
-      ))}
-    </Tabs>
+  const [activeKey,setActiveKey] = useState("Tab-0")
+  const renderArrow = (items,pos,handleArrowClick)=>{
+    const style = {width:32,height:32,display:"flex",justifyContent:'center',alignItems:'center',borderRadius:"100%",background:"#d7d7d7",color:"black",cursor:"pointer"}
+    return <Dropdown render={
+      <Dropdown.Menu>
+        {items.map(item=>{
+          return  <Dropdown.Item onClick={()=>setActiveKey(item.itemKey)}>{item.itemKey}</Dropdown.Item>
+        })}
+      </Dropdown.Menu>
+    }>
+      {pos==="start" ? <div style={style} onClick={handleArrowClick}>←</div>:<div style={style} onClick={handleArrowClick}>→</div>}
+    </Dropdown>
+  }
+
+  return  <Tabs renderArrow={renderArrow} style={{ width: '50%', margin: '20px' }} activeKey={activeKey}  type="card" collapsible onChange={k=>setActiveKey(k)}>
+    {[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(i => (
+            <TabPane tab={`Tab-${i}`} itemKey={`Tab-${i}`} key={i}>
+              Content of card tab {i}
+            </TabPane>
+    ))}
+  </Tabs>
 }
 ```
 
@@ -414,24 +415,40 @@ import { Tabs, TabPane } from '@douyinfe/semi-ui';
 
 **Modify overflow item indicator rendering position**
 
-Use `overflowItemRenderPosition` to modify the overflow indicator position, optional left both right
+Use `arrowRenderPosition` to modify the overflow indicator position, optional start both end
 
 ```jsx live=true dir=column
 import React from 'react';
 import { Tabs, TabPane } from '@douyinfe/semi-ui';
 
 class App extends React.Component {
-    render() {
-        return (
-            <Tabs style={{ width: '60%', margin: '20px' }} type="card" collapsible overflowItemRenderPosition={"end"} >
+  render() {
+    return (
+            <>
+              <Tabs style={{ width: '60%', margin: '20px' }} type="card" collapsible arrowRenderPosition={"start"} >
                 {[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(i => (
-                    <TabPane tab={`Tab-${i}`} itemKey={`Tab-${i}`} key={i}>
-                        Content of card tab {i}
-                    </TabPane>
+                        <TabPane tab={`Tab-${i}`} itemKey={`Tab-${i}`} key={i}>
+                          Content of card tab {i}
+                        </TabPane>
                 ))}
-            </Tabs>
-        );
-    }
+              </Tabs>
+              <Tabs style={{ width: '60%', margin: '20px' }} type="card" collapsible arrowRenderPosition={"both"} >
+                {[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(i => (
+                        <TabPane tab={`Tab-${i}`} itemKey={`Tab-${i}`} key={i}>
+                          Content of card tab {i}
+                        </TabPane>
+                ))}
+              </Tabs>
+              <Tabs style={{ width: '60%', margin: '20px' }} type="card" collapsible arrowRenderPosition={"end"} >
+                {[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(i => (
+                        <TabPane tab={`Tab-${i}`} itemKey={`Tab-${i}`} key={i}>
+                          Content of card tab {i}
+                        </TabPane>
+                ))}
+              </Tabs>
+            </>
+    );
+  }
 }
 ```
 
@@ -658,7 +675,7 @@ keepDOM | Whether to render the DOM structure of the hidden panel when using Tab
 lazyRender | Lazy rendering, only when the panel is activated will it be rendered in the DOM tree, **>=1.0.0**                                                                                             | boolean                                                                   | false         |
 more | Render a portion of the Tab into a drop-down menu ** >= 2.59.0**                                                                                                                              | number \| {count:number,render:()=>ReactNode,dropdownProps:DropDownProps} | -             |    
 renderTabBar | Used for secondary packaging tab bar                                                                                                                                                          | (tabBarProps: object, defaultTabBar: React.ComponentType) => ReactNode    | None          |
-renderOverflowItem | Customize how overflow items indicator are rendered externally. By default, the overflow items are expanded when the arrow button is hovered.                 **>=2.61.0**                    | (items: OverflowItem[],pos:"start"\|"end")=> ReactNode                    | None             
+renderArrow | Customize how overflow items indicator are rendered externally. By default, the overflow items are expanded when the arrow button is hovered.                 **>=2.61.0**                    | (items: OverflowItem[],pos:"start"\|"end")=> ReactNode                    | None             
 preventScroll | Indicates whether the browser should scroll the document to display the newly focused element, acting on the focus method inside the component, excluding the component passed in by the user | boolean                                                                   |               |  |
 size | Size, providing three types of `large`, `medium`, and `small`, **>=1.11.0, currently only supports linear Tabs**                                                                              | string                                                                    | `large`       |
 style | style object                                                                                                                                                                                  | CSSProperties                                                             | None          |
@@ -670,7 +687,7 @@ type | The style of the label bar, optional `line`, `card`, `button`
 onChange | Callback function when switching tab pages                                                                                                                                                    | function(activeKey: string)                                               | None          |
 onTabClick | Click event                                                                                                                                                                                   | function(key: string, e: Event)                                           | None          |
 onTabClose | executed when tab closed by user, **>=2.1.0**                                                                                                                                                 | function(tabKey: string)                                                  | None          
-overflowItemRenderPosition| Overflow item indicator rendering position **>=2.61.0**                                                                                                                                       | "start" "end" "both"                                                      | 无             
+arrowRenderPosition| Overflow item indicator rendering position **>=2.61.0**                                                                                                                                       | "start" "end" "both"                                                      | 无             
 overflowVisibleStateChange| Overflow item switching change callback  **>=2.61.0**                                                                                                                                         | (visibleState:Record\<string,bool\>)=>void                                | None
 
 ### TabPane

+ 41 - 24
content/navigation/tabs/index.md

@@ -405,27 +405,28 @@ class App extends React.Component {
 
 **修改滚动渲染溢出项指示器**
 
-`renderOverflowItem` 修改溢出项指示器,入参为溢出的 items 和 位置
+通过 renderArrow 修改滚动折叠模式下,左右切换箭头的渲染,入参为溢出的 items 和 位置
 
 ```jsx live=true dir="column"
 import React from 'react';
 import { Tabs, TabPane } from '@douyinfe/semi-ui';
 
 ()=>{
-    const [activeKey,setActiveKey] = useState("item-1")
-    return  <Tabs style={{ width: '50%', margin: '20px' }} activeKey={activeKey}  type="card" collapsible renderOverflowItem={(items,pos)=>{
-      return <Dropdown render={
-        <Dropdown.Menu>
-          {items.map(item=>{
-            return  <Dropdown.Item onClick={()=>setActiveKey(item.itemKey)}>{item.itemKey}</Dropdown.Item>
-          })}
-        </Dropdown.Menu>
+    const [activeKey,setActiveKey] = useState("Tab-0")
+    const renderArrow = (items,pos,handleArrowClick)=>{
+        const style = {width:32,height:32,display:"flex",justifyContent:'center',alignItems:'center',borderRadius:"100%",background:"#d7d7d7",color:"black",cursor:"pointer"}
+        return <Dropdown render={
+                    <Dropdown.Menu>
+                        {items.map(item=>{
+                            return  <Dropdown.Item onClick={()=>setActiveKey(item.itemKey)}>{item.itemKey}</Dropdown.Item>
+                        })}
+                    </Dropdown.Menu>
       }>
-        <Button>
-          {pos}
-        </Button>
+        {pos==="start" ? <div style={style} onClick={handleArrowClick}>←</div>:<div style={style} onClick={handleArrowClick}>→</div>}
       </Dropdown>
-    }}>
+    }
+  
+    return  <Tabs renderArrow={renderArrow} style={{ width: '50%', margin: '20px' }} activeKey={activeKey}  type="card" collapsible onChange={k=>setActiveKey(k)}>
       {[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(i => (
               <TabPane tab={`Tab-${i}`} itemKey={`Tab-${i}`} key={i}>
                 Content of card tab {i}
@@ -439,9 +440,9 @@ import { Tabs, TabPane } from '@douyinfe/semi-ui';
 
 
 
-**修改溢出项指示器渲染位置**
+**修改切换箭头的渲染位置**
 
-通过 `overflowItemRenderPosition` 来修改溢出指示器的位置,可选 left both right
+通过 `arrowRenderPosition` 来修改溢出指示器的位置,可选 start both end
 
 ```jsx live=true dir=column
 import React from 'react';
@@ -450,13 +451,29 @@ import { Tabs, TabPane } from '@douyinfe/semi-ui';
 class App extends React.Component {
     render() {
         return (
-            <Tabs style={{ width: '60%', margin: '20px' }} type="card" collapsible overflowItemRenderPosition={"end"} >
-                {[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(i => (
-                    <TabPane tab={`Tab-${i}`} itemKey={`Tab-${i}`} key={i}>
-                        Content of card tab {i}
-                    </TabPane>
-                ))}
-            </Tabs>
+            <>
+                <Tabs style={{ width: '60%', margin: '20px' }} type="card" collapsible arrowRenderPosition={"start"} >
+                    {[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(i => (
+                        <TabPane tab={`Tab-${i}`} itemKey={`Tab-${i}`} key={i}>
+                            Content of card tab {i}
+                        </TabPane>
+                    ))}
+                </Tabs>
+                <Tabs style={{ width: '60%', margin: '20px' }} type="card" collapsible arrowRenderPosition={"both"} >
+                    {[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(i => (
+                            <TabPane tab={`Tab-${i}`} itemKey={`Tab-${i}`} key={i}>
+                              Content of card tab {i}
+                            </TabPane>
+                    ))}
+                </Tabs>
+                <Tabs style={{ width: '60%', margin: '20px' }} type="card" collapsible arrowRenderPosition={"end"} >
+                    {[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(i => (
+                            <TabPane tab={`Tab-${i}`} itemKey={`Tab-${i}`} key={i}>
+                              Content of card tab {i}
+                            </TabPane>
+                    ))}
+                  </Tabs>
+              </>
         );
     }
 }
@@ -678,7 +695,7 @@ keepDOM | 使用 TabPane 写法时是否渲染隐藏面板的 DOM 结构,**>=1
 lazyRender | 懒渲染,仅当面板激活过才被渲染在 DOM 树中, **>=1.0.0**                              | boolean                                                                   | false |
 more | 将一部分 Tab 渲染到下拉菜单中 ** >= 2.59.0**                                  | number \| {count:number,render:()=>ReactNode,dropdownProps:DropDownProps} | -    |                                                              
 renderTabBar | 用于二次封装标签栏                                                         | (tabBarProps: object, defaultTabBar: React.ComponentType) => ReactNode    | 无    |
-renderOverflowItem | 自定义溢出项指示器在外部如何渲染,默认为箭头按钮 hover 时展开溢出项                **>=2.61.0** | (items: OverflowItem[],pos:"start"\|"end")=> ReactNode                    | 无    
+renderArrow | 自定义溢出项指示器在外部如何渲染,默认为箭头按钮 hover 时展开溢出项                **>=2.61.0** | (items: OverflowItem[],pos:"start"\|"end")=> ReactNode                    | 无    
 preventScroll | 指示浏览器是否应滚动文档以显示新聚焦的元素,作用于组件内的 focus 方法                            | boolean                                                                   |      |  |
 size | 大小,提供 `large`、`medium`、`small` 三种类型,**>=1.11.0,目前仅支持线性 Tabs**     | string                                                                    | `large` |
 style | 样式对象                                                              | CSSProperties                                                             | 无    |
@@ -690,7 +707,7 @@ type | 标签栏的样式,可选`line`、 `card`、 `button`
 onChange | 切换 tab 页时的回调函数                                                    | function(activeKey: string)                                               | 无    |
 onTabClick | 单击事件                                                              | function(key: string, e: Event)                                           | 无    |
 onTabClose | 关闭 tab 页时的回调函数 **>=2.1.0**                                        | function(tabKey: string)                                                  | 无    
-overflowItemRenderPosition| 溢出项指示器渲染位置 **>=2.61.0**                                           | "start" "end" "both"                                                      | 无    
+arrowRenderPosition| 溢出项指示器渲染位置 **>=2.61.0**                                           | "start" "end" "both"                                                      | 无    
 overflowVisibleStateChange| 溢出项切换变化回调                                                         | (visibleState:Record\<string,bool\>)=>void                                | 无
 
 ### TabPane

+ 0 - 1
content/show/overflowlist/index-en-US.md

@@ -240,7 +240,6 @@ import { IconAlarm, IconBookmark, IconCamera, IconDuration, IconEdit, IconFolder
 | items | All items to display in the list. **Key is required.** | Record<string, any>[] | `true` | - |
 | onIntersect | Callback invoked when the overflowed items change. | ({[key: string]: [IntersectionObserverEntry](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserverEntry)}) => void | - | 1.1.0 |
 | overflowRenderer | Callback invoked to render the overflowed items. | (overflowItems: Record<string, any>[]) => React.ReactNode[] | - | 1.1.0 |
-| overflowRenderDirection | Overflow item overall rendering position | "both" "start" 'end' | "both" | 2.61.0 |
 | threshold | At what percentage of the target's visibility the observer's callback should be executed. | number | 0.75 | 1.1.0 |
 | visibleItemRenderer | allback invoked to render each visible item. | (item: Record<string, any>, index: number) => React.ReactElement | - | 1.1.0 |
 | wrapperClassName | Scroll wrapper classname. | string | - | 1.1.0 |

+ 0 - 1
content/show/overflowlist/index.md

@@ -239,7 +239,6 @@ import { IconAlarm, IconBookmark, IconCamera, IconDuration, IconEdit, IconFolder
 | items | 渲染项目,**要求必含 key 项** | Record<string, any>[]                                                                                                              | - | 1.1.0 |
 | onIntersect | 溢出回调 | ({[key: string]: [IntersectionObserverEntry](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserverEntry)}) => void | - | 1.1.0 |
 | overflowRenderer | 溢出项的自定义渲染函数 | (overflowItems: Record<string, any>[]) => React.ReactNode[]                                                                        | - | 1.1.0 |
-| overflowRenderDirection | 溢出项整体渲染位置 | "both" "start" 'end' | "both" | 2.61.0 |
 | threshold | 触发溢出回调的阈值 | number                                                                                                                             | 0.75 | 1.1.0 |
 | visibleItemRenderer | 展示项的自定义渲染函数 | (item: Record<string, any>, index: number) => React.ReactElement                                                                   | - | 1.1.0 |
 | wrapperClassName | 滚动 wrapper 的类名 | string                                                                                                                             | - | 1.1.0 |

+ 1 - 1
packages/semi-ui/overflowList/index.tsx

@@ -36,7 +36,7 @@ export interface OverflowListProps {
     wrapperStyle?: CSSProperties;
     itemKey?: Key | ((item: OverflowItem) => Key);
     onVisibleStateChange?: (visibleState: Map<string, boolean>) => void;
-    overflowRenderDirection?: "both"|"start"|'end'
+    overflowRenderDirection?: "both"|"start"|'end' // used in tabs, not exposed to user
 }
 
 export interface OverflowListState {

+ 3 - 3
packages/semi-ui/tabs/TabBar.tsx

@@ -212,8 +212,8 @@ class TabBar extends React.Component<TabBarProps, TabBarState> {
 
     renderOverflow = (items: any[]): Array<ReactNode> => items.map((item, index) => {
         const pos = index === 0 ? 'start' : 'end';
-        if (this.props.renderOverflowItem) {
-            return this.props.renderOverflowItem(item, pos);
+        if (this.props.renderArrow) {
+            return this.props.renderArrow(item, pos, ()=>this.handleArrowClick(item, pos));
         }
         const icon = index === 0 ? <IconChevronLeft/> : <IconChevronRight/>;
         return this.renderCollapse(item, icon, pos);
@@ -229,7 +229,7 @@ class TabBar extends React.Component<TabBarProps, TabBarState> {
         return (
             <OverflowList
                 items={renderedList}
-                overflowRenderDirection={this.props.overflowItemRenderPosition}
+                overflowRenderDirection={this.props.arrowRenderPosition}
                 wrapperStyle={this.props.collapsibleWrapperStyle}
                 overflowRenderer={this.renderOverflow}
                 renderMode="scroll"

+ 7 - 4
packages/semi-ui/tabs/index.tsx

@@ -53,6 +53,8 @@ class Tabs extends BaseComponent<TabsProps, TabsState> {
         onTabClose: PropTypes.func,
         preventScroll: PropTypes.bool,
         more: PropTypes.oneOfType([PropTypes.number, PropTypes.object]),
+        arrowRenderPosition: PropTypes.string,
+        renderArrow: PropTypes.func,
     };
     static __SemiComponentName__ = "Tabs";
     static defaultProps: TabsProps = getDefaultPropsFromGlobalConfig(Tabs.__SemiComponentName__, {
@@ -66,6 +68,7 @@ class Tabs extends BaseComponent<TabsProps, TabsState> {
         tabPaneMotion: true,
         tabPosition: 'top',
         type: 'line',
+        arrowRenderPosition: "both",
         onTabClose: () => undefined
     });
 
@@ -257,8 +260,8 @@ class Tabs extends BaseComponent<TabsProps, TabsState> {
             more,
             overflowVisibleStateChange,
             collapsibleWrapperStyle,
-            overflowItemRenderPosition,
-            renderOverflowItem,
+            arrowRenderPosition,
+            renderArrow,
             ...restProps
         } = this.props;
         const { panes, activeKey } = this.state;
@@ -288,8 +291,8 @@ class Tabs extends BaseComponent<TabsProps, TabsState> {
             more,
             overflowVisibleStateChange,
             collapsibleWrapperStyle,
-            overflowItemRenderPosition,
-            renderOverflowItem
+            arrowRenderPosition,
+            renderArrow
         } as TabBarProps;
 
         const tabBar = renderTabBar ? renderTabBar(tabBarProps, TabBar) : <TabBar {...tabBarProps} />;

+ 4 - 4
packages/semi-ui/tabs/interface.ts

@@ -43,8 +43,8 @@ export interface TabsProps {
     more?: number | { count: number; render?: () => ReactNode; dropdownProps?: DropdownProps };
     overflowVisibleStateChange?: TabBarProps["overflowVisibleStateChange"];
     collapsibleWrapperStyle?: TabBarProps['collapsibleWrapperStyle'];
-    overflowItemRenderPosition?: TabBarProps['overflowItemRenderPosition'];
-    renderOverflowItem?: TabBarProps['renderOverflowItem']
+    arrowRenderPosition?: TabBarProps['arrowRenderPosition'];
+    renderArrow?: TabBarProps['renderArrow']
 }
 
 export interface TabBarProps {
@@ -66,8 +66,8 @@ export interface TabBarProps {
     more?: TabsProps['more'];
     overflowVisibleStateChange?: (visibleState: Map<string, boolean>) => void;
     collapsibleWrapperStyle?: CSSProperties;
-    overflowItemRenderPosition?: OverflowListProps['overflowRenderDirection'];
-    renderOverflowItem?: (items: OverflowItem[], pos: "start"|"end") => ReactNode
+    arrowRenderPosition?: OverflowListProps['overflowRenderDirection'];
+    renderArrow?: (items: OverflowItem[], pos: "start"|"end", handleArrowClick: () => void) => ReactNode
 
 }