Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(AdaptiveTabs): allow to control some properties in More control #145

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/components/AdaptiveTabs/AdaptiveTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
const b = block('adaptive-tabs');
const TAB_CLASS_NAME = b('tab');
const getSortObjectKeysByValuesFunc =
(objectToSort: Record<string, any>) => (a: string, b: string) => {

Check warning on line 24 in src/components/AdaptiveTabs/AdaptiveTabs.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type

Check warning on line 24 in src/components/AdaptiveTabs/AdaptiveTabs.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

'b' is already declared in the upper scope on line 21 column 7
if (objectToSort[a] > objectToSort[b]) {
return 1;
}
Expand Down Expand Up @@ -117,6 +117,8 @@
size?: TabsSize;
/** Allows you not to specify activeTab */
allowNotSelected?: boolean;
/** Settings to control popup with hidden tabs list */
moreControlProps?: Pick<SelectProps, 'virtualizationThreshold' | 'popupWidth'>;
}

interface AdaptiveTabsState {
Expand Down Expand Up @@ -183,7 +185,7 @@
private tabsRootNode = React.createRef<HTMLDivElement>();
private tabsListNode = React.createRef<HTMLDivElement>();

get activeTab() {

Check warning on line 188 in src/components/AdaptiveTabs/AdaptiveTabs.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

getter functions should be placed after render
const {activeTab, items, allowNotSelected} = this.props;
if (activeTab) {
return activeTab;
Expand Down Expand Up @@ -211,7 +213,7 @@

this.breakpoints = Object.keys(props.breakpointsConfig)
.map(Number)
.sort((a, b) => a - b);

Check warning on line 216 in src/components/AdaptiveTabs/AdaptiveTabs.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

'b' is already declared in the upper scope on line 21 column 7

/* save the object, where the keys are the "name" of the current container width, the values are the maximum width of the tab for
the corresponding container width (in percent of the container width) */
Expand All @@ -225,7 +227,7 @@
breakpointName = LARGE_CONTAINER_WIDTH_NAME;
}

accum[breakpointName] = props.breakpointsConfig[currentBreakpointWidth] || 100;

Check warning on line 230 in src/components/AdaptiveTabs/AdaptiveTabs.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Assignment to property of function parameter 'accum'

return accum;
},
Expand All @@ -244,9 +246,9 @@
this.setState({currentContainerWidthName: this.getCurrentContainerWidthName()});

if (this.tabsRootNode.current.clientWidth > this.breakpoints[0]) {
if ((document as any).fonts) {

Check warning on line 249 in src/components/AdaptiveTabs/AdaptiveTabs.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
(document as any).fonts.ready.then(this.initialCollectDimensions);

Check warning on line 250 in src/components/AdaptiveTabs/AdaptiveTabs.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
} else if ((document as any).readyState === READY_STATE_COMPLETE) {

Check warning on line 251 in src/components/AdaptiveTabs/AdaptiveTabs.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
setTimeout(this.initialCollectDimensions, 0);
} else {
window.addEventListener('load', this.initialCollectDimensions);
Expand Down Expand Up @@ -858,7 +860,7 @@
renderSelect() {
const activeTabID = this.activeTab;
const {firstHiddenTabIndex, tabChosenFromSelectId} = this.state;
const {items} = this.props;
const {items, moreControlProps} = this.props;

const itemsForSelect = items
.slice(firstHiddenTabIndex, items.length)
Expand All @@ -880,6 +882,7 @@
filterable={false}
renderControl={this.renderSwitcherForMoreSelect}
onOpenChange={this.handleOpenSelectChange}
{...moreControlProps}
/>
);
}
Expand Down
1 change: 1 addition & 0 deletions src/components/AdaptiveTabs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ with the caption `More'. If only one tab fits, the select is displayed instead o
| wrapTo | `wrapTo?(item: TabItemProps, node: React.ReactNode, index: number): void` | | | Allows to wrap TabItem into another component or render custom tab |
| className | `String` | | | Class name for the tabs container |
| [breakpointsConfig](#breakpointsConfig) | `Record<string, number>` | | | Breakpoints config which control the thersholds of tab size. |
| moreControlProps | `{popupWidth?: 'fit' \| number; virtualizationThreshold?: number;}` | | | Settings to control popup with hidden tabs list |

### breakpointsConfig

Expand Down
Loading