-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tabs): added controls to scrollable container
- Loading branch information
Showing
30 changed files
with
752 additions
and
563 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 @@ | ||
--- | ||
'@alfalab/core-components-tabs': minor | ||
--- | ||
|
||
Добавлены контролы в scrollable контейнер десктопных табов |
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,10 +1,2 @@ | ||
export { | ||
TabsCollapsibleResponsive as TabsCollapsible, | ||
TabsCollapsibleResponsiveProps as TabsCollapsibleProps, | ||
} from './components/tabs/Component.collapsible.responsive'; | ||
export * from './components/tabs/Component.collabsible.desktop'; | ||
export * from './components/tabs/Component.collapsible.mobile'; | ||
export * from './components/primary-tablist/Component.collapsible.responsive'; | ||
export * from './components/primary-tablist/Component.collapsible.desktop'; | ||
export * from './components/primary-tablist/Component.collapsible.mobile'; | ||
export { TabsCollapsible, TabsCollapsibleProps } from './components/tabs/Component.collapsible'; | ||
export * from './components/tab'; |
11 changes: 0 additions & 11 deletions
11
packages/tabs/src/components/primary-tablist/Component.collapsible.desktop.tsx
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
packages/tabs/src/components/primary-tablist/Component.collapsible.mobile.tsx
This file was deleted.
Oops, something went wrong.
34 changes: 0 additions & 34 deletions
34
packages/tabs/src/components/primary-tablist/Component.collapsible.responsive.tsx
This file was deleted.
Oops, something went wrong.
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
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
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
74 changes: 74 additions & 0 deletions
74
packages/tabs/src/components/scroll-controls/Component.tsx
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,74 @@ | ||
import React, { forwardRef, RefObject, useEffect, useState } from 'react'; | ||
import cn from 'classnames'; | ||
import _debounce from 'lodash.debounce'; | ||
|
||
import { IconButton } from '@alfalab/core-components-icon-button'; | ||
import { ChevronLeftMIcon } from '@alfalab/icons-glyph/ChevronLeftMIcon'; | ||
import { ChevronRightMIcon } from '@alfalab/icons-glyph/ChevronRightMIcon'; | ||
|
||
import { TabsProps } from '../../typings'; | ||
|
||
import { getDisabledState, scrollIntoFirstTab, scrollIntoLastTab } from './utils'; | ||
|
||
import styles from './index.module.css'; | ||
|
||
type ScrollControlsProps = { | ||
view: Exclude<TabsProps['view'], undefined>; | ||
size: TabsProps['size']; | ||
containerRef: RefObject<HTMLDivElement>; | ||
}; | ||
|
||
export const ScrollControls = forwardRef<HTMLDivElement, ScrollControlsProps>( | ||
({ containerRef, view, size: sizeProp }, ref) => { | ||
const container = containerRef.current; | ||
const [disabledState, updateDisabledState] = useState(() => getDisabledState(container)); | ||
|
||
useEffect(() => { | ||
const handleScroll = _debounce(() => { | ||
updateDisabledState(getDisabledState(container)); | ||
}, 150); | ||
|
||
container?.addEventListener('scroll', handleScroll); | ||
|
||
return () => container?.removeEventListener('scroll', handleScroll); | ||
}, [container]); | ||
|
||
const getSize = () => { | ||
if (view === 'primary') { | ||
return sizeProp === 'xl' ? 'xs' : 'xxs'; | ||
} | ||
|
||
return sizeProp && ['s', 'm', 'l', 'xl'].includes(sizeProp) ? 's' : 'xs'; | ||
}; | ||
|
||
const handleScrollLeft = () => scrollIntoFirstTab(container); | ||
|
||
const handleScrollRight = () => scrollIntoLastTab(container); | ||
|
||
const commonButtonProps = { | ||
className: styles.button, | ||
size: getSize(), | ||
view: 'secondary', | ||
} as const; | ||
|
||
return ( | ||
<div | ||
ref={ref} | ||
className={cn(styles.component, styles[view], sizeProp && styles[sizeProp])} | ||
> | ||
<IconButton | ||
{...commonButtonProps} | ||
icon={ChevronLeftMIcon} | ||
disabled={disabledState.toLeft} | ||
onClick={handleScrollLeft} | ||
/> | ||
<IconButton | ||
{...commonButtonProps} | ||
icon={ChevronRightMIcon} | ||
disabled={disabledState.toRight} | ||
onClick={handleScrollRight} | ||
/> | ||
</div> | ||
); | ||
}, | ||
); |
45 changes: 45 additions & 0 deletions
45
packages/tabs/src/components/scroll-controls/index.module.css
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,45 @@ | ||
@import '../../../../themes/src/default.css'; | ||
@import '../../vars.css'; | ||
|
||
.component { | ||
display: flex; | ||
flex-shrink: 0; | ||
} | ||
|
||
.primary { | ||
position: relative; | ||
width: 72px; | ||
align-items: flex-start; | ||
justify-content: flex-end; | ||
|
||
&:before { | ||
content: ''; | ||
display: block; | ||
position: absolute; | ||
bottom: 1px; | ||
height: 1px; | ||
width: 100%; | ||
background-color: var(--primary-tablist-bottom-border-color); | ||
} | ||
|
||
.button:first-child { | ||
margin-right: var(--gap-xs); | ||
} | ||
|
||
&.xl .button:first-child { | ||
margin-right: var(--gap-2xs); | ||
} | ||
} | ||
|
||
.secondary { | ||
align-items: center; | ||
justify-content: center; | ||
|
||
&.xs { | ||
width: 76px; | ||
|
||
.button:first-child { | ||
margin-right: var(--gap-2xs); | ||
} | ||
} | ||
} |
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 @@ | ||
export { ScrollControls } from './Component'; |
Oops, something went wrong.