Skip to content

Commit d08f81f

Browse files
Merge branch 'master' into new-title
2 parents 62c8a5f + 61ae021 commit d08f81f

File tree

11 files changed

+157
-23
lines changed

11 files changed

+157
-23
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# v6.2.1
2+
3+
- Fix tablistStyle issue when when adding MoreButtonPlgin
4+
- Improve document
5+
- Fix type issue of `MoreButtonPlugin`
6+
- Update demo
7+
18
# v6.2.0
29

310
Adding new option `tablistStyle`

README.md

+40-10
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Create responsive and dynamic tabs in React. This library supports ARIA accessib
3434
- [Syntax](#syntax)
3535
- [Minimal Usage Example](#minimal-usage-example)
3636
- [Simple Manipulation Example](#simple-manipulation-example)
37+
- [ready function](#ready-function)
3738
- [Options](#options)
3839
- [tabs](#tabs)
3940
- [selectedTabID](#selectedtabid)
@@ -168,7 +169,9 @@ const initialOptions = {
168169

169170
export default () => {
170171
const [TabList, PanelList, ready] = useDynTabs(initialOptions);
172+
171173
const addTab3 = function () {
174+
// use ready function to access the instance object
172175
ready((instance) => {
173176
// open tab 3
174177
instance.open({id: '3', title: 'Tab 3', panelComponent: (props) => <p> panel 3 </p>}).then(() => {
@@ -191,21 +194,34 @@ export default () => {
191194
};
192195
```
193196

194-
**NOTE :**
197+
## ready function
195198

196-
- Use `ready` function to access the `instance` object
199+
The `ready` function in the `react-dyn-tabs` library is part of the array returned by the `useDynTabs` hook, alongside the `TabList` and `PanelList` components. This function allows developers to execute a callback when the `TabList` and `PanelList` components are fully mounted, providing access to the instance object for further manipulation.
197200

198-
```js
199-
ready((instance) => {
200-
// manipulate tabs using instance object here
201-
});
202-
```
201+
### Key Features
203202

204-
- `ready` function accepts a `callback` as its parameter and executes it as soon as Tabs get mounted.
203+
- **Multiple Calls**: Developers can invoke the `ready` function multiple times without any issues.
204+
- **Stable Identity**: The reference to the `ready` function remains stable across component re-renders, ensuring consistent behavior.
205+
- **Immediate Execution**: If the `ready` function is called after the tabs have already been mounted, the provided callback will be executed immediately.
205206

206-
- If `ready` function is called after the Tabs has been mounted, the `callback` passed in will be executed immediately.
207+
### Example Usage
207208

208-
- `ready` function can be executed multiple times and its identity is stable and won’t change on re-renders.
209+
```js
210+
const [TabList, PanelList, ready] = useDynTabs(initialOptions);
211+
212+
const addTab3 = function () {
213+
ready((instance) => {
214+
// open tab 3
215+
instance.open({id: '3', title: 'Tab 3', panelComponent: (props) => <p> panel 3 </p>}).then(() => {
216+
console.log('tab 3 is open');
217+
});
218+
// switch to tab 3
219+
instance.select('3').then(() => {
220+
console.log('tab 3 is selected');
221+
});
222+
});
223+
};
224+
```
209225

210226
## Options
211227

@@ -481,6 +497,14 @@ const [TabList, PanelList, ready] = useDynTabs({isVertical: true});
481497
useDynTabs({theme:'classic'});
482498
```
483499

500+
#### Notes
501+
502+
- If the `theme` option is not provided then all imported themes CSS will be applied to the `Tablist`.
503+
504+
- If the `theme` option is set to a empty string then imported themes CSS will not be applied to the `Tablist`.
505+
506+
- You can create your own theme CSS and set the `theme` option to your theme class name
507+
484508
### tablistStyle
485509

486510
<table>
@@ -1326,6 +1350,12 @@ useDynamicTabs(
13261350
);
13271351
```
13281352

1353+
**unpkg Link**
1354+
1355+
```js
1356+
<script src="https://unpkg.com/react-dyn-tabs@latest/dist/more-button-plugin.umd.min.js"></script>
1357+
```
1358+
13291359
## Render custom components at the end of the Tablist
13301360

13311361
- render `new tab` button example :

example/stories/change-options/README.md

+43
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,46 @@ function App() {
199199
}
200200
<App />;
201201
```
202+
203+
### change moreButtonPlugin_iconComponent
204+
205+
```jsx
206+
import React from 'react';
207+
import 'react-dyn-tabs/style/react-dyn-tabs.css';
208+
import 'react-dyn-tabs/themes/react-dyn-tabs-card.css';
209+
import useDynTabs from 'react-dyn-tabs';
210+
import MoreButtonPlugin from 'react-dyn-tabs/plugins/moreButtonPlugin';
211+
212+
const initialOptions = {
213+
tabs: Array.from({length: 20}).map((value, i) => ({
214+
id: `${i + 1}`,
215+
title: `tab ${i + 1}`,
216+
panelComponent: <p> {`panel ${i + 1}`} </p>,
217+
})),
218+
selectedTabID: '2',
219+
theme: 'card',
220+
};
221+
222+
function App() {
223+
const [TabList, PanelList, ready] = useDynTabs(initialOptions, [MoreButtonPlugin]);
224+
225+
function handler() {
226+
ready((instance) => {
227+
instance
228+
.setOption('moreButtonPlugin_iconComponent', ({instance}) => {
229+
return <span style={{padding: '0.5rem 1rem', textTransform: 'none'}}>More</span>;
230+
})
231+
.refresh();
232+
});
233+
}
234+
235+
return (
236+
<div>
237+
<button onClick={handler}>customize icon component of more button</button>
238+
<TabList></TabList>
239+
<PanelList></PanelList>
240+
</div>
241+
);
242+
}
243+
<App />;
244+
```

example/stories/minimal-usage/README.md

+36
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,39 @@ function App() {
145145
}
146146
<App />;
147147
```
148+
149+
### blank theme
150+
151+
```jsx
152+
import React from 'react';
153+
import 'react-dyn-tabs/style/react-dyn-tabs.css';
154+
import useDynTabs from 'react-dyn-tabs';
155+
156+
const initialOptions = {
157+
tabs: [
158+
{
159+
id: '1',
160+
title: 'tab 1',
161+
panelComponent: (props) => <p> panel 1 </p>,
162+
},
163+
{
164+
id: '2',
165+
title: 'tab 2',
166+
panelComponent: (props) => <p> panel 2 </p>,
167+
},
168+
],
169+
selectedTabID: '1',
170+
theme: '',
171+
};
172+
173+
function App() {
174+
const [TabList, PanelList] = useDynTabs(initialOptions);
175+
return (
176+
<div>
177+
<TabList></TabList>
178+
<PanelList></PanelList>
179+
</div>
180+
);
181+
}
182+
<App />;
183+
```

index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,5 @@ export interface Instance {
9595
}
9696
type Tablist = FC<PropsWithChildren<{}>>;
9797
type Panellist = FunctionComponent<{}>;
98-
declare const useDynTabs: (options?: Options) => [Tablist, Panellist, Ready];
98+
declare const useDynTabs: (options?: Options, plugins?: Array<(instance: any, components: any) => void>) => [Tablist, Panellist, Ready];
9999
export default useDynTabs;

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-dyn-tabs",
3-
"version": "6.2.0",
3+
"version": "6.2.1",
44
"private": false,
55
"description": "Create responsive and dynamic tabs in React. This library supports ARIA accessibility and provides complete control over tab management using hooks.",
66
"keywords": [

plugins/moreButtonPlugin/index.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* @param {any} instance - developer instance of Tabs
3+
* @param {any} components - references of all components in the library
4+
*/
5+
declare const MoreButtonPlugin: (instance: any, components: any) => void;
6+
export default MoreButtonPlugin;

plugins/moreButtonPlugin/package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
2-
"main": "../../lib/cjs/plugins/moreButtonPlugin/index.js",
3-
"module": "../../lib/esm/plugins/moreButtonPlugin/index.js",
4-
"sideEffects": false
5-
}
2+
"main": "../../lib/cjs/plugins/moreButtonPlugin/index.js",
3+
"module": "../../lib/esm/plugins/moreButtonPlugin/index.js",
4+
"types": "./index.d.ts",
5+
"sideEffects": false
6+
}

src/plugins/moreButtonPlugin/setComponents.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ export const setTablistOverflow = (setComponents.setTablistOverflow = function (
5151
export const setTablistView = (setComponents.setTablistView = function (components) {
5252
components.TablistView = components.TablistViewFactory.bind(undefined, (ins) => ({
5353
tablistViewPropsManager: () => {
54-
let {className} = components.tablistViewPropsManager(ins);
55-
className += ' rc-dyn-tabs-responsive';
56-
return {className};
54+
const attrs = components.tablistViewPropsManager(ins);
55+
attrs.className += ' rc-dyn-tabs-responsive';
56+
return attrs;
5757
},
5858
}));
5959
});

styleguide.config.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
const webpack = require('webpack');
2-
const {version} = require('./package');
2+
const {version, name} = require('./package');
33
const path = require('path');
44

55
module.exports = {
6-
title: 'react-dyn-tabs',
6+
title: name,
7+
template: {
8+
head: {
9+
meta: [
10+
{
11+
name: 'description',
12+
content:
13+
'react-dyn-tabs : create responsive and dynamic tabs, supports ARIA accessibility and provides complete control over tab management using hook.',
14+
},
15+
],
16+
},
17+
},
718
getComponentPathLine(componentPath) {
819
return ``;
920
},

0 commit comments

Comments
 (0)