@cleartrip/ct-design-horizontal-scroll 4.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -0
- package/dist/HorizontalScroll.d.ts +3 -3
- package/dist/HorizontalScroll.d.ts.map +1 -1
- package/dist/HorizontalScroll.native.d.ts +5 -0
- package/dist/HorizontalScroll.native.d.ts.map +1 -0
- package/dist/constants.d.ts +10 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/ct-design-horizontal-scroll.browser.cjs.js +14 -1
- package/dist/ct-design-horizontal-scroll.browser.cjs.js.map +1 -1
- package/dist/ct-design-horizontal-scroll.browser.esm.js +14 -1
- package/dist/ct-design-horizontal-scroll.browser.esm.js.map +1 -1
- package/dist/ct-design-horizontal-scroll.cjs.js +43 -127
- package/dist/ct-design-horizontal-scroll.cjs.js.map +1 -1
- package/dist/ct-design-horizontal-scroll.esm.js +43 -126
- package/dist/ct-design-horizontal-scroll.esm.js.map +1 -1
- package/dist/ct-design-horizontal-scroll.umd.js +1686 -181
- package/dist/ct-design-horizontal-scroll.umd.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.native.d.ts +4 -0
- package/dist/index.native.d.ts.map +1 -0
- package/dist/style.d.ts +40 -0
- package/dist/style.d.ts.map +1 -0
- package/dist/type.d.ts +21 -27
- package/dist/type.d.ts.map +1 -1
- package/package.json +31 -11
- package/src/HorizontalScroll.native.tsx +80 -0
- package/src/HorizontalScroll.tsx +62 -0
- package/src/constants.ts +10 -0
- package/src/index.native.ts +3 -0
- package/src/index.ts +3 -0
- package/src/style.ts +86 -0
- package/src/type.ts +67 -0
- package/dist/StyledHorizontalScroll/StyledHorizontalScroll.d.ts +0 -6
- package/dist/StyledHorizontalScroll/StyledHorizontalScroll.d.ts.map +0 -1
- package/dist/StyledHorizontalScroll/index.d.ts +0 -2
- package/dist/StyledHorizontalScroll/index.d.ts.map +0 -1
- package/dist/StyledLeftShadow/StyledLeftShadow.d.ts +0 -11
- package/dist/StyledLeftShadow/StyledLeftShadow.d.ts.map +0 -1
- package/dist/StyledLeftShadow/index.d.ts +0 -2
- package/dist/StyledLeftShadow/index.d.ts.map +0 -1
- package/dist/StyledRightShadow/StyledRightShadow.d.ts +0 -11
- package/dist/StyledRightShadow/StyledRightShadow.d.ts.map +0 -1
- package/dist/StyledRightShadow/index.d.ts +0 -2
- package/dist/StyledRightShadow/index.d.ts.map +0 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { forwardRef, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
import { css } from '@emotion/css';
|
|
4
|
+
import { Container } from '@cleartrip/ct-design-container';
|
|
5
|
+
import { IHorizontalScroll } from './type';
|
|
6
|
+
import useMergeRefs from '@cleartrip/ct-design-use-merge-refs';
|
|
7
|
+
import { useWebMergeStyles } from '@cleartrip/ct-design-style-manager';
|
|
8
|
+
import { ScrollContainerRef } from '@cleartrip/ct-design-scroll-container';
|
|
9
|
+
|
|
10
|
+
// todo @raghav to revisit this
|
|
11
|
+
|
|
12
|
+
const horizontalScrollStyles = css`
|
|
13
|
+
display: flex;
|
|
14
|
+
white-space: no-wrap;
|
|
15
|
+
overflow-x: auto;
|
|
16
|
+
scroll-behavior: smooth;
|
|
17
|
+
-webkit-tap-highlight-color: transparent;
|
|
18
|
+
scrollbar-width: none; /* Firefox */
|
|
19
|
+
-ms-overflow-style: none; /* Internet Explorer 10+ */
|
|
20
|
+
|
|
21
|
+
&::-webkit-scrollbar {
|
|
22
|
+
/* WebKit */
|
|
23
|
+
display: none;
|
|
24
|
+
}
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
const HorizontalScroll = forwardRef<ScrollContainerRef, IHorizontalScroll>(
|
|
28
|
+
({ children, styleConfig = {}, onScroll }, forwardRef) => {
|
|
29
|
+
const { root, childContainer } = styleConfig;
|
|
30
|
+
|
|
31
|
+
const horizontalScrollRef = useRef<HTMLDivElement>(null);
|
|
32
|
+
const parentContainerRef = useRef<HTMLDivElement>(null);
|
|
33
|
+
const childContainerRef = useRef<HTMLElement>(null);
|
|
34
|
+
const combinedParentContainerRef = useMergeRefs(parentContainerRef, forwardRef);
|
|
35
|
+
const combinedParenAndChildContainerRef = useMergeRefs(parentContainerRef, childContainerRef);
|
|
36
|
+
|
|
37
|
+
const rootStyles = useWebMergeStyles([...(root || []), horizontalScrollStyles], [root]);
|
|
38
|
+
|
|
39
|
+
const handleScroll = (event: React.UIEvent<HTMLDivElement>) => {
|
|
40
|
+
onScroll?.({
|
|
41
|
+
nativeEvent: {
|
|
42
|
+
contentOffset: { x: event.currentTarget.scrollLeft, y: event.currentTarget.scrollTop },
|
|
43
|
+
layoutMeasurement: { height: event.currentTarget.clientHeight, width: event.currentTarget.clientWidth },
|
|
44
|
+
contentSize: { height: event.currentTarget.scrollHeight, width: event.currentTarget.scrollWidth },
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<div ref={horizontalScrollRef} onScroll={handleScroll}>
|
|
51
|
+
<div ref={combinedParentContainerRef} className={rootStyles}>
|
|
52
|
+
<Container styleConfig={{ root: childContainer }} ref={combinedParenAndChildContainerRef}>
|
|
53
|
+
{children}
|
|
54
|
+
</Container>
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
57
|
+
);
|
|
58
|
+
},
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
HorizontalScroll.displayName = 'HorizontalScroll';
|
|
62
|
+
export default HorizontalScroll;
|
package/src/constants.ts
ADDED
package/src/index.ts
ADDED
package/src/style.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { makeStyles } from '@cleartrip/ct-design-style-manager';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Default fade-out gradient for the left edge shadow when the caller
|
|
5
|
+
* hasn't supplied `shadowGradientStyle.left`.
|
|
6
|
+
* @web
|
|
7
|
+
*/
|
|
8
|
+
export const DEFAULT_LEFT_SHADOW_GRADIENT = 'linear-gradient(90deg, #FFFFFF 0%, rgba(255, 255, 255, 0) 100%)';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Default fade-out gradient for the right edge shadow when the caller
|
|
12
|
+
* hasn't supplied `shadowGradientStyle.right`.
|
|
13
|
+
* @web
|
|
14
|
+
*/
|
|
15
|
+
export const DEFAULT_RIGHT_SHADOW_GRADIENT = 'linear-gradient(270deg, #ffffff 0%, rgba(255, 255, 255, 0) 100%)';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Default horizontal extent of the shadow overlays on either side.
|
|
19
|
+
* @web
|
|
20
|
+
*/
|
|
21
|
+
export const DEFAULT_SHADOW_WIDTH = '64px';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Static, theme-independent styles shared by the HorizontalScroll
|
|
25
|
+
* web and native implementations. The keys prefixed `native*` are
|
|
26
|
+
* only consumed by `HorizontalScroll.native.tsx`; `web*` keys and
|
|
27
|
+
* the shared layout keys are consumed by `HorizontalScroll.tsx` via
|
|
28
|
+
* `useWebMergeStyles`.
|
|
29
|
+
*/
|
|
30
|
+
const staticHorizontalScrollStyles = makeStyles((theme) => ({
|
|
31
|
+
/**
|
|
32
|
+
* Native content-container default: horizontal row with
|
|
33
|
+
* theme-driven gap so siblings fall into a horizontal flow.
|
|
34
|
+
*/
|
|
35
|
+
nativeContent: {
|
|
36
|
+
display: 'flex',
|
|
37
|
+
flexDirection: 'row',
|
|
38
|
+
gap: theme?.spacing[3],
|
|
39
|
+
},
|
|
40
|
+
/**
|
|
41
|
+
* Web scroll viewport. Hides the native scrollbar across all
|
|
42
|
+
* engines and enables smooth horizontal scroll. Nested selector
|
|
43
|
+
* is processed by emotion under the hood.
|
|
44
|
+
*/
|
|
45
|
+
webScrollWrapper: {
|
|
46
|
+
display: 'flex',
|
|
47
|
+
whiteSpace: 'nowrap',
|
|
48
|
+
overflowX: 'auto',
|
|
49
|
+
scrollBehavior: 'smooth',
|
|
50
|
+
WebkitTapHighlightColor: 'transparent',
|
|
51
|
+
scrollbarWidth: 'none',
|
|
52
|
+
msOverflowStyle: 'none',
|
|
53
|
+
'&::-webkit-scrollbar': {
|
|
54
|
+
display: 'none',
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
/**
|
|
58
|
+
* Shared layout for the edge shadow overlays on web. Dynamic
|
|
59
|
+
* width + gradient are applied on top via useStyles in the
|
|
60
|
+
* component.
|
|
61
|
+
*/
|
|
62
|
+
webShadowBase: {
|
|
63
|
+
position: 'absolute',
|
|
64
|
+
top: 0,
|
|
65
|
+
height: '100%',
|
|
66
|
+
display: 'flex',
|
|
67
|
+
alignItems: 'center',
|
|
68
|
+
zIndex: 10,
|
|
69
|
+
},
|
|
70
|
+
/**
|
|
71
|
+
* Left-shadow-specific overrides layered over `webShadowBase`.
|
|
72
|
+
*/
|
|
73
|
+
webLeftShadow: {
|
|
74
|
+
left: 0,
|
|
75
|
+
justifyContent: 'flex-start',
|
|
76
|
+
},
|
|
77
|
+
/**
|
|
78
|
+
* Right-shadow-specific overrides layered over `webShadowBase`.
|
|
79
|
+
*/
|
|
80
|
+
webRightShadow: {
|
|
81
|
+
right: 0,
|
|
82
|
+
justifyContent: 'flex-end',
|
|
83
|
+
},
|
|
84
|
+
}));
|
|
85
|
+
|
|
86
|
+
export default staticHorizontalScrollStyles;
|
package/src/type.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Styles, ViewStyle } from '@cleartrip/ct-design-types';
|
|
2
|
+
import { IScrollContainer } from '@cleartrip/ct-design-scroll-container';
|
|
3
|
+
import { ARROW_SIZE } from './constants';
|
|
4
|
+
|
|
5
|
+
export interface IHorizontalScroll extends IScrollContainer {
|
|
6
|
+
children?: React.ReactNode;
|
|
7
|
+
/**
|
|
8
|
+
* Style configuration for Horizontal Scroll component
|
|
9
|
+
*/
|
|
10
|
+
styleConfig?: {
|
|
11
|
+
/**
|
|
12
|
+
* Style configuration for root container for Horizonatal Scroll
|
|
13
|
+
* !NOTE: This works only in case of web
|
|
14
|
+
*/
|
|
15
|
+
root?: Styles[];
|
|
16
|
+
/**
|
|
17
|
+
* Style configuration for child container for Horizonatal Scroll
|
|
18
|
+
*/
|
|
19
|
+
childContainer?: Styles[];
|
|
20
|
+
};
|
|
21
|
+
width?: number; // Fixed width of each child container
|
|
22
|
+
/**
|
|
23
|
+
* @description Triggers when index changes
|
|
24
|
+
*/
|
|
25
|
+
onIndexChange?: (index: number) => void; // Triggers when index changes
|
|
26
|
+
/**
|
|
27
|
+
* @description Current active index
|
|
28
|
+
*/
|
|
29
|
+
currentActiveIndex?: number;
|
|
30
|
+
/**
|
|
31
|
+
* @description Paging enabled
|
|
32
|
+
*/
|
|
33
|
+
pagingEnabled?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* @description Snap to offsets
|
|
36
|
+
*/
|
|
37
|
+
snapToOffsets?: number[];
|
|
38
|
+
/**
|
|
39
|
+
* @description Deceleration rate
|
|
40
|
+
*/
|
|
41
|
+
decelerationRate?: number;
|
|
42
|
+
/**
|
|
43
|
+
* @description Total items length
|
|
44
|
+
*/
|
|
45
|
+
totalItemsLength?: number;
|
|
46
|
+
/**
|
|
47
|
+
* @description Custom content container style
|
|
48
|
+
*/
|
|
49
|
+
customContentContainerStyle?: ViewStyle;
|
|
50
|
+
/**
|
|
51
|
+
* @description Wrap intersection observer
|
|
52
|
+
*/
|
|
53
|
+
wrapIntersectionObserver?: boolean;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @description Arrow size
|
|
57
|
+
*/
|
|
58
|
+
arrowSize?: `${ARROW_SIZE}`;
|
|
59
|
+
/**
|
|
60
|
+
* @description Shadow gradient style
|
|
61
|
+
*/
|
|
62
|
+
shadowGradientStyle?: IShadowGradient;
|
|
63
|
+
}
|
|
64
|
+
export interface IShadowGradient {
|
|
65
|
+
left: string;
|
|
66
|
+
right: string;
|
|
67
|
+
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { CSSProperties } from 'styled-components';
|
|
2
|
-
declare const StyledHorizontalScroll: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {
|
|
3
|
-
css?: CSSProperties | undefined;
|
|
4
|
-
}, never>;
|
|
5
|
-
export default StyledHorizontalScroll;
|
|
6
|
-
//# sourceMappingURL=StyledHorizontalScroll.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"StyledHorizontalScroll.d.ts","sourceRoot":"","sources":["../../packages/components/HorizontalScroll/src/StyledHorizontalScroll/StyledHorizontalScroll.tsx"],"names":[],"mappings":"AAAA,OAAe,EAAc,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEtE,QAAA,MAAM,sBAAsB;;SAkB3B,CAAC;AAEF,eAAe,sBAAsB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/components/HorizontalScroll/src/StyledHorizontalScroll/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { CSSProperties } from "styled-components";
|
|
2
|
-
import { IShadowGradientStyle } from '../type';
|
|
3
|
-
export interface StyledLeftShadowProps {
|
|
4
|
-
width?: string;
|
|
5
|
-
shadowGradientStyle?: IShadowGradientStyle;
|
|
6
|
-
}
|
|
7
|
-
declare const StyledLeftShadow: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, StyledLeftShadowProps & {
|
|
8
|
-
css?: CSSProperties | undefined;
|
|
9
|
-
}, never>;
|
|
10
|
-
export default StyledLeftShadow;
|
|
11
|
-
//# sourceMappingURL=StyledLeftShadow.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"StyledLeftShadow.d.ts","sourceRoot":"","sources":["../../packages/components/HorizontalScroll/src/StyledLeftShadow/StyledLeftShadow.tsx"],"names":[],"mappings":"AAAA,OAAe,EAAc,aAAa,EAAE,MAAO,mBAAmB,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAG/C,MAAM,WAAW,qBAAqB;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IAClB,mBAAmB,CAAC,EAAE,oBAAoB,CAAC;CAC3C;AAED,QAAA,MAAM,gBAAgB;;SAiBrB,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/components/HorizontalScroll/src/StyledLeftShadow/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { CSSProperties } from 'styled-components';
|
|
2
|
-
import { IShadowGradientStyle } from '../type';
|
|
3
|
-
export interface StyledRightShadowProps {
|
|
4
|
-
width?: string;
|
|
5
|
-
shadowGradientStyle?: IShadowGradientStyle;
|
|
6
|
-
}
|
|
7
|
-
declare const StyledRightShadow: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, StyledRightShadowProps & {
|
|
8
|
-
css?: CSSProperties | undefined;
|
|
9
|
-
}, never>;
|
|
10
|
-
export default StyledRightShadow;
|
|
11
|
-
//# sourceMappingURL=StyledRightShadow.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"StyledRightShadow.d.ts","sourceRoot":"","sources":["../../packages/components/HorizontalScroll/src/StyledRightShadow/StyledRightShadow.tsx"],"names":[],"mappings":"AAAA,OAAe,EAAe,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAE/C,MAAM,WAAW,sBAAsB;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mBAAmB,CAAC,EAAE,oBAAoB,CAAC;CAC3C;AAED,QAAA,MAAM,iBAAiB;;SAiBtB,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/components/HorizontalScroll/src/StyledRightShadow/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qBAAqB,CAAC"}
|