Skip to content

Commit 94093d5

Browse files
authored
refactor: rename indicatorLength with indicatorSize (#672)
* refactor: rename indicatorLength with indicatorSize * chore: code clean
1 parent b96be82 commit 94093d5

File tree

5 files changed

+23
-22
lines changed

5 files changed

+23
-22
lines changed

docs/examples/indicator.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default () => {
2929

3030
return (
3131
<React.StrictMode>
32-
<Tabs tabBarExtraContent="extra" items={items} getIndicatorLength={(origin) => origin - 16} />
32+
<Tabs tabBarExtraContent="extra" items={items} indicatorSize={(origin) => origin - 16} />
3333
</React.StrictMode>
3434
);
3535
};

src/TabNavList/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import ExtraContent from './ExtraContent';
2727
import OperationNode from './OperationNode';
2828
import TabNode from './TabNode';
2929
import useIndicator from '../hooks/useIndicator';
30-
import type { GetIndicatorLength } from '../hooks/useIndicator';
30+
import type { GetIndicatorSize } from '../hooks/useIndicator';
3131

3232
export interface TabNavListProps {
3333
id: string;
@@ -50,7 +50,7 @@ export interface TabNavListProps {
5050
children?: (node: React.ReactElement) => React.ReactElement;
5151
getPopupContainer?: (node: HTMLElement) => HTMLElement;
5252
popupClassName?: string;
53-
indicatorLength?: GetIndicatorLength;
53+
indicatorSize?: GetIndicatorSize;
5454
}
5555

5656
const getSize = (refObj: React.RefObject<HTMLElement>): SizeInfo => {
@@ -82,7 +82,7 @@ function TabNavList(props: TabNavListProps, ref: React.Ref<HTMLDivElement>) {
8282
children,
8383
onTabClick,
8484
onTabScroll,
85-
indicatorLength,
85+
indicatorSize,
8686
} = props;
8787
const containerRef = useRef<HTMLDivElement>();
8888
const extraLeftRef = useRef<HTMLDivElement>();
@@ -369,7 +369,7 @@ function TabNavList(props: TabNavListProps, ref: React.Ref<HTMLDivElement>) {
369369
activeTabOffset,
370370
horizontal: tabPositionTopOrBottom,
371371
rtl,
372-
indicatorLength,
372+
indicatorSize,
373373
})
374374

375375
// ========================= Effect ========================

src/Tabs.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import type {
1818
import TabContext from './TabContext';
1919
import TabNavListWrapper from './TabNavList/Wrapper';
2020
import useAnimateConfig from './hooks/useAnimateConfig';
21-
import type { GetIndicatorLength } from './hooks/useIndicator';
21+
import type { GetIndicatorSize } from './hooks/useIndicator';
2222

2323
/**
2424
* Should added antd:
@@ -71,7 +71,7 @@ export interface TabsProps
7171
popupClassName?: string;
7272

7373
// Indicator
74-
indicatorLength?: GetIndicatorLength;
74+
indicatorSize?: GetIndicatorSize;
7575
}
7676

7777
function Tabs(
@@ -99,7 +99,7 @@ function Tabs(
9999
onTabScroll,
100100
getPopupContainer,
101101
popupClassName,
102-
indicatorLength,
102+
indicatorSize,
103103
...restProps
104104
}: TabsProps,
105105
ref: React.Ref<HTMLDivElement>,
@@ -185,7 +185,7 @@ function Tabs(
185185
panes: null,
186186
getPopupContainer,
187187
popupClassName,
188-
indicatorLength,
188+
indicatorSize,
189189
};
190190

191191
return (

src/hooks/useIndicator.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import React, { useEffect, useRef, useState } from 'react';
1+
import type React from 'react';
2+
import { useEffect, useRef, useState } from 'react';
23
import raf from 'rc-util/lib/raf';
3-
import { TabOffset } from '../interface';
4+
import type { TabOffset } from '../interface';
45

5-
export type GetIndicatorLength = number | ((origin: number) => number);
6+
export type GetIndicatorSize = number | ((origin: number) => number);
67

78
export type UseIndicator = (options: {
89
activeTabOffset: TabOffset,
910
horizontal: boolean;
1011
rtl: boolean;
11-
indicatorLength: GetIndicatorLength;
12+
indicatorSize: GetIndicatorSize;
1213
}) => {
1314
style: React.CSSProperties;
1415
}
@@ -17,17 +18,17 @@ const useIndicator: UseIndicator = ({
1718
activeTabOffset,
1819
horizontal,
1920
rtl,
20-
indicatorLength,
21+
indicatorSize,
2122
}) => {
2223
const [inkStyle, setInkStyle] = useState<React.CSSProperties>();
2324
const inkBarRafRef = useRef<number>();
2425

2526
const getLength = (origin: number) => {
26-
if (typeof indicatorLength === 'function') {
27-
return indicatorLength(origin);
27+
if (typeof indicatorSize === 'function') {
28+
return indicatorSize(origin);
2829
}
29-
if (typeof indicatorLength === 'number') {
30-
return indicatorLength;
30+
if (typeof indicatorSize === 'number') {
31+
return indicatorSize;
3132
}
3233
return origin;
3334
}
@@ -63,7 +64,7 @@ const useIndicator: UseIndicator = ({
6364
});
6465

6566
return cleanInkBarRaf;
66-
}, [activeTabOffset, horizontal, rtl, indicatorLength]);
67+
}, [activeTabOffset, horizontal, rtl, indicatorSize]);
6768

6869
return {
6970
style: inkStyle,

tests/index.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -584,12 +584,12 @@ describe('Tabs.Basic', () => {
584584
render(<Tabs items={[{key: 1 as any, label: 'test'}]} />)
585585
})
586586

587-
it('support getIndicatorLength', async () => {
588-
const { container, rerender } = render(getTabs({ indicatorLength: 10 }));
587+
it('support indicatorSize', async () => {
588+
const { container, rerender } = render(getTabs({ indicatorSize: 10 }));
589589
await waitFakeTimer();
590590
expect(container.querySelector('.rc-tabs-ink-bar')).toHaveStyle({ width: '10px' });
591591

592-
rerender(getTabs({ indicatorLength: (origin) => origin - 2 }));
592+
rerender(getTabs({ indicatorSize: (origin) => origin - 2 }));
593593
await waitFakeTimer();
594594
expect(container.querySelector('.rc-tabs-ink-bar')).toHaveStyle({ width: '18px' });
595595
})

0 commit comments

Comments
 (0)