-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use shared HorizontalScroll component for Chips and Calendar
- Loading branch information
Showing
8 changed files
with
73 additions
and
42 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 |
---|---|---|
@@ -1,25 +1,10 @@ | ||
// Copyright (C) 2017-2024 Smart code 203358507 | ||
|
||
@mask-width: 10%; | ||
|
||
.chips { | ||
position: relative; | ||
width: 100%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: flex-start; | ||
gap: 1rem; | ||
overflow-x: auto; | ||
|
||
&.left { | ||
mask-image: linear-gradient(90deg, rgba(0, 0, 0, 1) calc(100% - @mask-width), rgba(0, 0, 0, 0) 100%); | ||
} | ||
|
||
&.right { | ||
mask-image: linear-gradient(90deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 1) @mask-width); | ||
} | ||
|
||
&.center { | ||
mask-image: linear-gradient(90deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 1) @mask-width, rgba(0, 0, 0, 1) calc(100% - @mask-width), rgba(0, 0, 0, 0) 100%); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (C) 2017-2024 Smart code 203358507 | ||
|
||
@mask-width: 10%; | ||
|
||
.horizontal-scroll { | ||
position: relative; | ||
overflow-x: auto; | ||
|
||
&.left { | ||
mask-image: linear-gradient(90deg, rgba(0, 0, 0, 1) calc(100% - @mask-width), rgba(0, 0, 0, 0) 100%); | ||
} | ||
|
||
&.right { | ||
mask-image: linear-gradient(90deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 1) @mask-width); | ||
} | ||
|
||
&.center { | ||
mask-image: linear-gradient(90deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 1) @mask-width, rgba(0, 0, 0, 1) calc(100% - @mask-width), rgba(0, 0, 0, 0) 100%); | ||
} | ||
} |
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,40 @@ | ||
// Copyright (C) 2017-2024 Smart code 203358507 | ||
|
||
import React, { useRef, useEffect, useState } from 'react'; | ||
import classNames from 'classnames'; | ||
import styles from './HorizontalScroll.less'; | ||
|
||
const SCROLL_THRESHOLD = 1; | ||
|
||
type Props = { | ||
className: string, | ||
children: React.ReactNode, | ||
}; | ||
|
||
const HorizontalScroll = ({ className, children }: Props) => { | ||
const ref = useRef<HTMLDivElement>(null); | ||
const [scrollPosition, setScrollPosition] = useState('left'); | ||
|
||
useEffect(() => { | ||
const onScroll = ({ target }: Event) => { | ||
const { scrollLeft, scrollWidth, offsetWidth } = target as HTMLDivElement; | ||
|
||
setScrollPosition(() => ( | ||
(scrollLeft - SCROLL_THRESHOLD) <= 0 ? 'left' : | ||
(scrollLeft + offsetWidth + SCROLL_THRESHOLD) >= scrollWidth ? 'right' : | ||
'center' | ||
)); | ||
}; | ||
|
||
ref.current?.addEventListener('scroll', onScroll); | ||
return () => ref.current?.removeEventListener('scroll', onScroll); | ||
}, []); | ||
|
||
return ( | ||
<div ref={ref} className={classNames(styles['horizontal-scroll'], className, [styles[scrollPosition]])}> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
export default HorizontalScroll; |
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,4 @@ | ||
// Copyright (C) 2017-2024 Smart code 203358507 | ||
|
||
import HorizontalScroll from './HorizontalScroll'; | ||
export default HorizontalScroll; |
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 |
---|---|---|
|
@@ -45,7 +45,6 @@ | |
gap: 1rem; | ||
height: 0; | ||
padding: 1rem; | ||
overflow-x: scroll; | ||
|
||
.item { | ||
flex: none; | ||
|
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