-
Notifications
You must be signed in to change notification settings - Fork 48
Add reusable tabs #1462
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
Open
jpggvilaca
wants to merge
13
commits into
main
Choose a base branch
from
jvilaca/add-reusable-tabs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add reusable tabs #1462
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
15c2aa8
Remove unused scss file
jpggvilaca 3e05cbe
Add ManagedTabs
jpggvilaca 144d708
Remove shared styles from custom-tab
jpggvilaca 066eb67
Use new component on workspaces-tabs
jpggvilaca 9c429f5
Use new component on dataset tabs
jpggvilaca 75d73af
Use new component on users toolbar
jpggvilaca 3be8518
Copilot
jpggvilaca ba323d9
Replace iife for just vars
jpggvilaca 51e5bff
Rename var; Make addButton ReactNode
jpggvilaca b0959d2
Remove collapsed-items-picker
jpggvilaca 056b5fc
Update managed tabs
jpggvilaca 659a7e0
Update consumers
jpggvilaca 8607e4e
Export component
jpggvilaca File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
web_ui/packages/ui/src/managed-tabs/managed-tabs.component.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| // Copyright (C) 2022-2025 Intel Corporation | ||
| // LIMITED EDGE SOFTWARE DISTRIBUTION LICENSE | ||
|
|
||
| import { Key, ReactNode } from 'react'; | ||
|
|
||
| import { Flex, Item, Picker, TabList, TabPanels, Tabs } from '@adobe/react-spectrum'; | ||
|
|
||
| import classes from './managed-tabs.module.scss'; | ||
|
|
||
| interface TabItem { | ||
| id: string; | ||
| key: string; | ||
| name: ReactNode; | ||
| children: ReactNode; | ||
| } | ||
|
|
||
| interface OverflowConfig { | ||
| maxVisibleTabs: number; | ||
| pickerAriaLabel: string; | ||
| onCollapsedItemSelect: (key: string) => void; | ||
| } | ||
|
|
||
| interface ManagedTabsProps<T extends { id: string; name: string }> { | ||
| id?: string; | ||
| items: T[]; | ||
| selectedKey: string; | ||
| onSelectionChange: (key: Key) => void; | ||
| renderTabItem: (item: T) => ReactNode; | ||
| children?: ReactNode; | ||
| addButton?: ReactNode; | ||
| overflow?: OverflowConfig; | ||
| orientation?: 'horizontal' | 'vertical'; | ||
| wrapperClassName?: string; | ||
| tabListClassName?: string; | ||
| ariaLabel: string; | ||
| } | ||
|
|
||
| export const ManagedTabs = <T extends { id: string; name: string }>({ | ||
| id, | ||
| items, | ||
| selectedKey, | ||
| onSelectionChange, | ||
| renderTabItem, | ||
| children, | ||
| addButton, | ||
| overflow, | ||
| orientation = 'vertical', | ||
| wrapperClassName, | ||
| tabListClassName, | ||
| ariaLabel, | ||
| }: ManagedTabsProps<T>) => { | ||
| const hasOverflow = overflow && items.length > overflow.maxVisibleTabs; | ||
|
|
||
| const visibleItems = hasOverflow ? items.slice(0, overflow.maxVisibleTabs) : items; | ||
| const collapsedItems = hasOverflow ? items.slice(overflow.maxVisibleTabs) : []; | ||
| const hasSelectedCollapsedItem = collapsedItems.some((item) => item.id === selectedKey); | ||
|
|
||
| const tabItems = visibleItems.map((item) => ({ | ||
| id: item.id, | ||
| key: item.id, | ||
| name: item.name, | ||
| originalItem: item, | ||
| })); | ||
|
|
||
| const collapsedPickerItems = collapsedItems.map((item) => ({ id: item.id, name: item.name })); | ||
|
|
||
| return ( | ||
| <Flex | ||
| id={id} | ||
| direction={orientation === 'vertical' ? 'row' : 'column'} | ||
| height='100%' | ||
| width='100%' | ||
| UNSAFE_className={`${classes.componentWrapper} ${wrapperClassName || ''}`} | ||
| > | ||
| <Tabs | ||
| orientation={orientation} | ||
| selectedKey={selectedKey} | ||
| items={tabItems} | ||
| aria-label={ariaLabel} | ||
| height='100%' | ||
| width='100%' | ||
| onSelectionChange={onSelectionChange} | ||
| > | ||
| <Flex | ||
| alignItems='center' | ||
| width='100%' | ||
| position='relative' | ||
| gap='size-200' | ||
| UNSAFE_className={classes.tabWrapper} | ||
| > | ||
| <div className={classes.tabListScrollContainer}> | ||
| <TabList UNSAFE_className={tabListClassName || classes.tabList}> | ||
| {(item: TabItem & { originalItem: T }) => ( | ||
| <Item textValue={String(item.name)} key={item.key}> | ||
| {renderTabItem(item.originalItem)} | ||
| </Item> | ||
| )} | ||
| </TabList> | ||
|
|
||
| {overflow && collapsedItems.length > 0 && ( | ||
| <Picker | ||
| isQuiet | ||
| items={collapsedPickerItems} | ||
| aria-label={overflow.pickerAriaLabel} | ||
| onSelectionChange={(key) => overflow.onCollapsedItemSelect(String(key))} | ||
| placeholder={`${collapsedItems.length} more`} | ||
| UNSAFE_className={[ | ||
| classes.collapsedItemsPicker, | ||
| !hasSelectedCollapsedItem ? classes.selected : '', | ||
| ].join(' ')} | ||
| > | ||
| {(item) => <Item>{item.name}</Item>} | ||
| </Picker> | ||
| )} | ||
| </div> | ||
|
|
||
| {addButton && addButton} | ||
| </Flex> | ||
|
|
||
| <TabPanels>{(item: TabItem) => <Item key={item.key}>{children}</Item>}</TabPanels> | ||
| </Tabs> | ||
| </Flex> | ||
| ); | ||
| }; | ||
107 changes: 107 additions & 0 deletions
107
web_ui/packages/ui/src/managed-tabs/managed-tabs.module.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| /* | ||
| Overriding vertical tabs is necessary because if the user's monitor display settings | ||
| are higher than 100%, then spectrum's tabs collapses to a Picker. This doesn't happen on | ||
| vertical tabs. So we decided to use the vertical tabs logic with horizontal tabs layout. | ||
|
|
||
| https://react-spectrum.adobe.com/react-spectrum/Tabs.html#collapse-overflow-behavior | ||
| */ | ||
| .componentWrapper { | ||
| div[class*='spectrum-Tabs--vertical'] { | ||
| border-left: 0 !important; | ||
| flex-direction: row !important; | ||
| padding-right: var(--spectrum-global-dimension-size-100) !important; | ||
|
|
||
| > div[class*='Tabs-item'] { | ||
| margin-bottom: 0 !important; | ||
| margin-left: 0 !important; | ||
| box-sizing: border-box !important; | ||
| display: flex; | ||
| align-items: center; | ||
|
|
||
| &:first-child { | ||
| padding-left: 0 !important; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| div[class*='TabsPanel--vertical'] { | ||
| flex-direction: column !important; | ||
| padding: 0 !important; | ||
| } | ||
| } | ||
|
|
||
| .tabList { | ||
| span[class*='spectrum-Tabs-itemLabel'] { | ||
| font-size: var(--spectrum-global-dimension-font-size-200); | ||
| } | ||
|
|
||
| div[class*='is-selected']::after { | ||
| transition: background-color 0.15s ease-in-out; | ||
| content: ''; | ||
| height: var(--spectrum-global-dimension-size-25); | ||
| background-color: transparent; | ||
| position: absolute; | ||
| left: 0; | ||
| right: 0; | ||
| bottom: 0; | ||
| } | ||
|
|
||
| div[class*='is-selected'] { | ||
| position: relative; | ||
|
|
||
| &:after { | ||
| background-color: var(--energy-blue); | ||
| } | ||
| } | ||
|
|
||
| div[class*='spectrum-Tabs-selectionIndicator'] { | ||
| display: none; | ||
| } | ||
|
|
||
| &.emptySelection { | ||
| div[class*='is-selected'] { | ||
| color: var(--spectrum-tabs-text-color, var(--spectrum-alias-label-text-color)); | ||
| } | ||
| } | ||
|
|
||
| > div { | ||
| border-bottom-width: 0; | ||
| } | ||
| } | ||
|
|
||
| .tabWrapper { | ||
| border-bottom: var(--spectrum-global-dimension-size-10) solid | ||
| var(--spectrum-tabs-rule-color, var(--spectrum-global-color-gray-200)) !important; | ||
| box-sizing: border-box !important; | ||
| display: flex; | ||
| align-items: center; | ||
| } | ||
|
|
||
| .tabListScrollContainer { | ||
| flex: 1 1 auto; | ||
| min-width: 0; | ||
| overflow: auto hidden; | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 0; | ||
| } | ||
|
|
||
| .collapsedItemsPicker { | ||
| position: relative; | ||
| flex-shrink: 0; | ||
|
|
||
| &.selected::after { | ||
| content: ''; | ||
| position: absolute; | ||
| height: var(--spectrum-global-dimension-size-25); | ||
| left: 0; | ||
| bottom: -15px; | ||
| right: var(--spectrum-global-dimension-size-400); | ||
| background-color: var(--energy-blue); | ||
| } | ||
|
|
||
| span[class*='spectrum-Dropdown-label'] { | ||
| font-size: var(--spectrum-global-dimension-font-size-100) !important; | ||
| font-style: normal !important; | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.