|
1 | 1 | # tabs-more-button
|
| 2 | + |
2 | 3 | Responsive Tabs with more button
|
| 4 | + |
| 5 | +Making tabs responsive by hiding overflow tabs except active tab |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +```js |
| 10 | +$ npm install tabs-more-button --save |
| 11 | +``` |
| 12 | + |
| 13 | +or |
| 14 | + |
| 15 | +```js |
| 16 | +$ yarn add tabs-more-button |
| 17 | +``` |
| 18 | + |
| 19 | +If you need to directly include script in your html, use the following links : |
| 20 | + |
| 21 | +```js |
| 22 | +<script src="https://unpkg.com/tabs-more-button@latest/dist/tabs-more-button.min.js"></script> |
| 23 | +``` |
| 24 | + |
| 25 | +## Usage |
| 26 | + |
| 27 | +html : |
| 28 | + |
| 29 | +```js |
| 30 | +<div id="container" style="display:flex;"> |
| 31 | + <ul style="display:inline-flex;"> |
| 32 | + <li style="display:inline-flex;">Tab 0</li> |
| 33 | + <li style="display:inline-flex;">Tab 1</li> |
| 34 | + <li style="display:inline-flex;">Tab 2</li> |
| 35 | + <li style="display:inline-flex;">Tab 3</li> |
| 36 | + <li style="display:inline-flex;color:red;">Active Tab 4</li> |
| 37 | + <li style="display:inline-flex;">Tab 5</li> |
| 38 | + <li style="display:inline-flex;">Tab 6</li> |
| 39 | + </ul> |
| 40 | + <button id="more-button" style="display:inline-flex;"> |
| 41 | + more |
| 42 | + </button> |
| 43 | +</div> |
| 44 | +``` |
| 45 | + |
| 46 | +js : |
| 47 | + |
| 48 | +```js |
| 49 | +import tabsMoreButton from 'tabs-more-button'; |
| 50 | + |
| 51 | +const options = { |
| 52 | + buttonElement: document.getElementById('more-button'), |
| 53 | + containerElement: document.getElementById('container'), |
| 54 | +}; |
| 55 | +const instance = new tabsMoreButton(options); |
| 56 | + |
| 57 | +let hiddenTabs = instance.resize(4 /*selectedTabIndex*/); |
| 58 | +addEventListener('resize', () => { |
| 59 | + hiddenTabs = instance.resize(4 /*selectedTabIndex*/); |
| 60 | +}); |
| 61 | +document.getElementById('more-button').addEventListener('click', () => console.table(hiddenTabs)); |
| 62 | +``` |
| 63 | + |
| 64 | +## options |
| 65 | + |
| 66 | +- buttonElement |
| 67 | + |
| 68 | + - type : `HtmlELement` |
| 69 | + - description : `view more` button (should be next sibling element of `Tablist` element) |
| 70 | + |
| 71 | +- containerElement |
| 72 | + |
| 73 | + - type : `HtmlELement` |
| 74 | + - description : the first ancestor of `buttonElement` which its `width|height` is not relative to `tab list` element but is relative to `viewport` |
| 75 | + |
| 76 | +- tabDisplay? |
| 77 | + |
| 78 | + - type : `string` |
| 79 | + - description : `display` value for each `tab` element |
| 80 | + - default value : `inline-flex` |
| 81 | + |
| 82 | +- containerDisplay? |
| 83 | + |
| 84 | + - type : `string` |
| 85 | + - description : `display` value for `containerElement` |
| 86 | + - default value : `flex` |
| 87 | + |
| 88 | +## instance methods |
| 89 | + |
| 90 | +- resize |
| 91 | + |
| 92 | + - type : `function` |
| 93 | + - description : makes tabs responsive by hiding `overflow tabs` except `active tab` |
| 94 | + - arguments : |
| 95 | + 1. selectedTabIndex : |
| 96 | + - type : `Number` |
| 97 | + - description : index of active tab element in the tablist element |
| 98 | + 2. direction? : |
| 99 | + - type : `"ltr" | "rtl"` |
| 100 | + - description : direction value of `tablist` element |
| 101 | + - default value : `"ltr"` |
| 102 | + 3. isVertical? : |
| 103 | + - type : `Boolean` |
| 104 | + - description : `true` means `tablist` element is vertical |
| 105 | + - default value : `false` |
| 106 | + - return : |
| 107 | + - type : `Array<{ el: HTMLElement, index: Number }>` |
| 108 | + - description : array of hidden tabs data |
0 commit comments