-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial rebranding and added pagination for tabs component (#2061)
This PR will conclude the initial rebranding update for the tabs component. New features of this component: - Pagination/scroll feature on overflow. - Optional onClose handler. all other changes are styling related and are based on the new designs made for the rebranding.
- Loading branch information
Showing
15 changed files
with
650 additions
and
151 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
--- | ||
"@kadena/react-ui": patch | ||
--- | ||
|
||
Add new tabs component style and added the pagination option |
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,32 +1,74 @@ | ||
import { MonoClose } from '@kadena/react-icons/system'; | ||
import classNames from 'classnames'; | ||
import type { ReactNode } from 'react'; | ||
import React, { useRef } from 'react'; | ||
import type { AriaTabProps } from 'react-aria'; | ||
import { useTab } from 'react-aria'; | ||
import { mergeProps, useHover, useTab } from 'react-aria'; | ||
import type { Node, TabListState } from 'react-stately'; | ||
import { tabItemClass } from './Tabs.css'; | ||
import { Button } from '../Button'; | ||
import { closeButtonClass, tabItemClass } from './Tabs.css'; | ||
|
||
interface ITabProps extends AriaTabProps { | ||
item: Node<object>; | ||
state: TabListState<object>; | ||
inverse?: boolean; | ||
className?: string; | ||
borderPosition: 'top' | 'bottom'; | ||
onClose?: (item: Node<object>) => void; | ||
isCompact?: boolean; | ||
} | ||
|
||
/** | ||
* @internal this should not be used, check the Tabs.stories | ||
*/ | ||
export const Tab = ({ item, state }: ITabProps): ReactNode => { | ||
export const Tab = ({ | ||
item, | ||
state, | ||
className, | ||
inverse = false, | ||
borderPosition = 'bottom', | ||
isCompact = false, | ||
onClose, | ||
}: ITabProps): ReactNode => { | ||
const { key, rendered } = item; | ||
const ref = useRef(null); | ||
const { tabProps } = useTab({ key }, state, ref); | ||
const { hoverProps, isHovered } = useHover({ ...item, ...state }); | ||
|
||
return ( | ||
<div | ||
className={tabItemClass} | ||
{...tabProps} | ||
className={classNames( | ||
className, | ||
tabItemClass({ | ||
inverse, | ||
borderPosition, | ||
size: isCompact ? 'compact' : 'default', | ||
}), | ||
{ | ||
closeable: typeof onClose === 'function', | ||
}, | ||
)} | ||
{...mergeProps(tabProps, hoverProps)} | ||
ref={ref} | ||
role="tab" | ||
data-selected={state.selectedKey === key} | ||
data-hovered={isHovered || undefined} | ||
> | ||
{rendered} | ||
{typeof onClose === 'function' && ( | ||
<Button | ||
className={closeButtonClass} | ||
type="button" | ||
onPress={() => onClose(item)} | ||
aria-label="Close" | ||
variant="transparent" | ||
isCompact | ||
data-parent-selected={state.selectedKey === key || undefined} | ||
data-parent-hovered={isHovered || undefined} | ||
> | ||
<MonoClose aria-hidden="true" /> | ||
</Button> | ||
)} | ||
</div> | ||
); | ||
}; |
This file contains 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
Oops, something went wrong.