Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
li-jia-nan authored Jan 2, 2024
2 parents 160221f + 7c35650 commit 69bee30
Show file tree
Hide file tree
Showing 30 changed files with 806 additions and 359 deletions.
2 changes: 1 addition & 1 deletion .dumirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ export default defineConfig({
name: 'Tabs',
},
mfsu: false,
});
});
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ es
coverage
yarn.lock
package-lock.json
pnpm-lock.yaml

# umi
.umi
Expand Down
50 changes: 27 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,51 +41,53 @@ online example: https://tabs.react-component.now.sh/

## Usage

```js
```tsx
import Tabs from 'rc-tabs';
import ReactDom from 'react-dom';

var callback = function(key) {
console.log(key);
const callback = (key) => {
console.log(key);
};

const z = [
const items = [
{
key: "1",
label: "Google",
key: '1',
label: 'Google',
children: (
<div className="text-xl">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting</p>
</div>
),
},
{
key: "2",
key: '2',
label: <p>Amazon</p>,
children:
"Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...",
disabled: true
'Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...',
disabled: true,
},
{
key: "3",
key: '3',
label: <p>Twitter</p>,
children: (
<div>
"There is no one who loves pain itself, who seeks after it and wants to
have it, simply because it is pain..."
"There is no one who loves pain itself, who seeks after it and wants to have it, simply
because it is pain..."
</div>
),
},
];

React.render(
<Tabs
tabPosition="bottom"
items={z}
defaultActiveKey="1"
className="md:w-[70%] w-full mx-auto p-2 border-0"
onChange={callback}
style={{color:"yellow"}}
/>
ReactDom.render(
<Tabs
tabPosition="bottom"
items={items}
defaultActiveKey="1"
className="md:w-[70%] w-full mx-auto p-2 border-0"
onChange={callback}
style={{ color: 'yellow' }}
/>,
root,
);
```

Expand All @@ -107,6 +109,7 @@ React.render(
| renderTabBar | (props, TabBarComponent) => ReactElement | - | How to render tab bar |
| tabBarExtraContent | ReactNode \| `{ left: ReactNode, right: ReactNode }` | - | config extra content |
| tabBarGutter | number | 0 | config tab bar gutter |
| tabBarPosition | `'left' \| 'right' \| 'top' \| 'bottom'` | `'top'` | tab nav 's position |
| tabBarStyle | style | - | tab nav style |
| tabPosition | `'left' or 'right' or 'top' or 'bottom'` | `'top'` | tab nav 's position |
| destroyInactiveTabPane | boolean | false | whether destroy inactive TabPane when change tab |
Expand Down Expand Up @@ -143,6 +146,7 @@ React.render(

| name | type | default | description |
| --- | --- | --- | --- |
| destroyInactiveTabPane | boolean | false | whether destroy inactive TabPane when change tab |
| key | string | - | corresponding to activeKey, should be unique |
| forceRender | boolean | false | forced render of content in tabs, not lazy render after clicking on tabs |
| tab | ReactNode | - | current tab's title corresponding to current tabPane |
Expand Down Expand Up @@ -176,9 +180,9 @@ rc-tabs is released under the MIT license.

## FAQ

### Resposive Tabs
### Responsive Tabs

There are 3 cases when handling resposive tabs:
There are 3 cases when handling responsive tabs:
![image](https://user-images.githubusercontent.com/27722486/156315099-7e6eda9d-ab77-4b16-9b49-1727c5ec8b26.png)

We get hidden tabs through [useVisibleRange.ts](https://github.com/react-component/tabs/blob/master/src/hooks/useVisibleRange.ts).
Expand Down
3 changes: 2 additions & 1 deletion assets/position.less
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
flex-direction: column;
min-width: 50px;

&-list, &-operations {
&-list,
&-operations {
flex: 1 0 auto; // fix safari scroll problem
flex-direction: column;
}
Expand Down
8 changes: 8 additions & 0 deletions docs/demo/dynamic-extra.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: dynamic-extra
nav:
title: Demo
path: /demo
---

<code src="../examples/dynamic-extra.tsx"></code>
8 changes: 8 additions & 0 deletions docs/demo/indicator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Indicator
nav:
title: Demo
path: /demo
---

<code src="../examples/indicator.tsx"></code>
6 changes: 5 additions & 1 deletion docs/examples/basic.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import Tabs from'../../src';
import '../../assets/index.less';
import Tabs from '../../src';

export default () => {
const [destroy, setDestroy] = React.useState(false);
Expand All @@ -9,17 +9,20 @@ export default () => {
label: 'Light',
key: 'light',
children: 'Light!',
icon: <span>🌞</span>,
},
{
label: 'Bamboo',
key: 'bamboo',
children: 'Bamboo!',
icon: <span>🎋</span>,
},
{
label: 'Cute',
key: 'cute',
children: 'Cute!',
disabled: true,
icon: <span>🐼</span>,
},
]);

Expand All @@ -38,6 +41,7 @@ export default () => {
key: 'yo',
label: 'Yo',
children: 'Yo!',
icon: <span>👋</span>,
},
]);
}}
Expand Down
38 changes: 38 additions & 0 deletions docs/examples/dynamic-extra.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react';
import Tabs from '../../src';
import type { TabsProps } from '../../src';
import '../../assets/index.less';

const items: TabsProps['items'] = [];
for (let i = 0; i < 50; i += 1) {
items.push({
key: String(i),
label: `Tab ${i}`,
children: `Content of ${i}`,
});
}
export default () => {
const [key, setKey] = React.useState('0');

const extra = React.useMemo(() => {
if (key === '0') {
return (
<div>额外内容</div>
)
}
return null
}, [key])

return (
<div style={{ maxWidth: 550 }}>
<Tabs
activeKey={key}
onChange={(curKey) => setKey(curKey)}
tabBarExtraContent={extra}
defaultActiveKey="8"
moreIcon="..."
items={items}
/>
</div>
);
};
63 changes: 63 additions & 0 deletions docs/examples/indicator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React from 'react';
import '../../assets/index.less';
import type { TabsProps } from '../../src';
import Tabs from '../../src';

const items: TabsProps['items'] = [
{
label: 'Light',
key: 'light',
children: 'Light!',
},
{
label: 'Bamboo',
key: 'bamboo',
children: 'Bamboo!',
},
{
label: 'Cute',
key: 'cute',
children: 'Cute!',
},
];

export default () => (
<>
<Tabs
tabPosition="top"
items={items}
indicatorSize={origin => origin - 20}
indicatorAlign="start"
/>
<Tabs
tabPosition="top"
items={items}
indicatorSize={origin => origin - 20}
indicatorAlign="center"
/>
<Tabs
tabPosition="top"
items={items}
indicatorSize={origin => origin - 20}
indicatorAlign="end"
/>
<Tabs
tabPosition="left"
items={items}
indicatorSize={origin => origin - 20}
indicatorAlign="start"
/>
<Tabs
tabPosition="left"
items={items}
indicatorSize={origin => origin - 20}
indicatorAlign="center"
/>
<Tabs
tabPosition="left"
items={items}
indicatorSize={origin => origin - 20}
indicatorAlign="end"
/>
</>
);
Loading

0 comments on commit 69bee30

Please sign in to comment.