Skip to content

Commit

Permalink
docs(HorizontalScroll): add spacing values for example playground
Browse files Browse the repository at this point in the history
  • Loading branch information
sarkaaa committed Nov 29, 2024
1 parent 1abebe5 commit fed7e3c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
15 changes: 14 additions & 1 deletion docs/src/__examples__/HorizontalScroll/default.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,20 @@ export default {
{
name: "spacing",
type: "select",
options: ["none", "50", "100", "200", "300", "400", "600", "800", "1000"],
options: [
"none",
"50",
"100",
"150",
"200",
"300",
"400",
"600",
"800",
"1000",
"1200",
"1600",
],
defaultValue: "none",
},
],
Expand Down
10 changes: 7 additions & 3 deletions packages/orbit-components/src/HorizontalScroll/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const getSnap = (scrollSnap: ScrollSnap) => {
return scrollSnap;
};

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const getTriggerOffset = (spacing: string) => {
const spacingValues = {
[SPACINGS.NONE]: 0,
Expand Down Expand Up @@ -104,7 +105,9 @@ const HorizontalScroll = React.forwardRef<HTMLDivElement, Props>(
const theme = useTheme();
const scrollEl = scrollWrapperRef.current;

const TRIGGER_OFFSET = getTriggerOffset(spacing);
// const TRIGGER_OFFSET = getTriggerOffset(spacing);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const TRIGGER_OFFSET = 20;

const handleOverflow = React.useCallback(() => {
if (scrollWrapperRef.current?.scrollWidth && containerRef.current?.offsetWidth) {
Expand Down Expand Up @@ -136,13 +139,14 @@ const HorizontalScroll = React.forwardRef<HTMLDivElement, Props>(
if (scrollEl) {
const scrollWidth = scrollEl.scrollWidth - scrollEl.clientWidth;
const { scrollLeft } = scrollEl;
if (scrollLeft - TRIGGER_OFFSET <= 0) {

if (scrollLeft === 0) {
setReachedStart(true);
} else {
setReachedStart(false);
}

if (scrollLeft + TRIGGER_OFFSET >= scrollWidth) {
if (scrollLeft >= scrollWidth) {
setReachedEnd(true);
} else {
setReachedEnd(false);
Expand Down

0 comments on commit fed7e3c

Please sign in to comment.