@cleartrip/ct-design-modal 4.0.0 → 5.0.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.
Files changed (78) hide show
  1. package/README.md +100 -0
  2. package/dist/Backdrop/Backdrop.d.ts +8 -4
  3. package/dist/Backdrop/Backdrop.d.ts.map +1 -1
  4. package/dist/Backdrop/style.d.ts +18 -0
  5. package/dist/Backdrop/style.d.ts.map +1 -0
  6. package/dist/Backdrop/type.d.ts +9 -8
  7. package/dist/Backdrop/type.d.ts.map +1 -1
  8. package/dist/Modal.d.ts +4 -4
  9. package/dist/Modal.d.ts.map +1 -1
  10. package/dist/Modal.native.d.ts +5 -0
  11. package/dist/Modal.native.d.ts.map +1 -0
  12. package/dist/ModalAction/ModalAction.d.ts +7 -5
  13. package/dist/ModalAction/ModalAction.d.ts.map +1 -1
  14. package/dist/ModalContainer/ModalContainer.d.ts +7 -7
  15. package/dist/ModalContainer/ModalContainer.d.ts.map +1 -1
  16. package/dist/ModalContent/ModalContent.d.ts +9 -6
  17. package/dist/ModalContent/ModalContent.d.ts.map +1 -1
  18. package/dist/ModalContext.d.ts +0 -1
  19. package/dist/ModalContext.d.ts.map +1 -1
  20. package/dist/ModalTitle/ModalTitle.d.ts +12 -5
  21. package/dist/ModalTitle/ModalTitle.d.ts.map +1 -1
  22. package/dist/ModalsUsableComponents/ModalWithCloseOverlay.d.ts +3 -2
  23. package/dist/ModalsUsableComponents/ModalWithCloseOverlay.d.ts.map +1 -1
  24. package/dist/ModalsUsableComponents/type.d.ts +10 -4
  25. package/dist/ModalsUsableComponents/type.d.ts.map +1 -1
  26. package/dist/constants.d.ts +28 -0
  27. package/dist/constants.d.ts.map +1 -0
  28. package/dist/ct-design-modal.browser.cjs.js +1 -1
  29. package/dist/ct-design-modal.browser.cjs.js.map +1 -1
  30. package/dist/ct-design-modal.browser.esm.js +1 -1
  31. package/dist/ct-design-modal.browser.esm.js.map +1 -1
  32. package/dist/ct-design-modal.cjs.js +233 -130
  33. package/dist/ct-design-modal.cjs.js.map +1 -1
  34. package/dist/ct-design-modal.esm.js +235 -132
  35. package/dist/ct-design-modal.esm.js.map +1 -1
  36. package/dist/ct-design-modal.umd.js +1882 -141
  37. package/dist/ct-design-modal.umd.js.map +1 -1
  38. package/dist/index.d.ts +4 -2
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.native.d.ts +5 -0
  41. package/dist/index.native.d.ts.map +1 -0
  42. package/dist/modalUtils.d.ts +2 -0
  43. package/dist/modalUtils.d.ts.map +1 -0
  44. package/dist/style.d.ts +18 -0
  45. package/dist/style.d.ts.map +1 -0
  46. package/dist/style.native.d.ts +29 -0
  47. package/dist/style.native.d.ts.map +1 -0
  48. package/dist/type.d.ts +38 -40
  49. package/dist/type.d.ts.map +1 -1
  50. package/package.json +38 -17
  51. package/src/Backdrop/Backdrop.tsx +39 -0
  52. package/src/Backdrop/index.ts +1 -0
  53. package/src/Backdrop/style.ts +18 -0
  54. package/src/Backdrop/type.ts +17 -0
  55. package/src/Handler.ts +78 -0
  56. package/src/Modal.native.tsx +210 -0
  57. package/src/Modal.tsx +234 -0
  58. package/src/ModalAction/ModalAction.tsx +42 -0
  59. package/src/ModalAction/index.ts +1 -0
  60. package/src/ModalContainer/ModalContainer.tsx +40 -0
  61. package/src/ModalContainer/index.ts +1 -0
  62. package/src/ModalContent/ModalContent.tsx +44 -0
  63. package/src/ModalContent/index.ts +1 -0
  64. package/src/ModalContext.ts +14 -0
  65. package/src/ModalTitle/ModalTitle.tsx +70 -0
  66. package/src/ModalTitle/index.ts +1 -0
  67. package/src/ModalsUsableComponents/ModalWithCloseOverlay.tsx +92 -0
  68. package/src/ModalsUsableComponents/index.ts +2 -0
  69. package/src/ModalsUsableComponents/type.ts +40 -0
  70. package/src/constants.ts +31 -0
  71. package/src/index.native.ts +4 -0
  72. package/src/index.ts +10 -0
  73. package/src/modalUtils.ts +1 -0
  74. package/src/style.native.ts +83 -0
  75. package/src/style.ts +44 -0
  76. package/src/type.ts +72 -0
  77. package/dist/ModalsUsableComponents/style.d.ts +0 -11
  78. package/dist/ModalsUsableComponents/style.d.ts.map +0 -1
@@ -0,0 +1,42 @@
1
+ import React, { ReactNode, useContext } from 'react';
2
+
3
+ import { Container } from '@cleartrip/ct-design-container';
4
+ import { useStyles } from '@cleartrip/ct-design-style-manager';
5
+ import type { Styles } from '@cleartrip/ct-design-types';
6
+
7
+ import ModalContext from '../ModalContext';
8
+ import { ModalProps } from '../type';
9
+
10
+ type ModalActionProps = Pick<ModalProps, 'footerAlignment'> & {
11
+ children: ReactNode;
12
+ styleConfig?: { root?: Styles[] };
13
+ };
14
+
15
+ const alignmentMap = {
16
+ start: 'flex-start',
17
+ end: 'flex-end',
18
+ center: 'center',
19
+ } as const;
20
+
21
+ const ModalAction: React.FunctionComponent<ModalActionProps> = ({ children, styleConfig }) => {
22
+ const { footerAlignment = 'end' } = useContext(ModalContext);
23
+
24
+ const rootStyles = useStyles(
25
+ (theme) => ({
26
+ root: {
27
+ display: 'flex',
28
+ justifyContent: alignmentMap[footerAlignment],
29
+ paddingTop: theme.spacing[6],
30
+ paddingBottom: theme.spacing[6],
31
+ paddingLeft: theme.spacing[4],
32
+ paddingRight: theme.spacing[4],
33
+ boxShadow: theme.elevation.topE1,
34
+ },
35
+ }),
36
+ [footerAlignment],
37
+ );
38
+
39
+ return <Container styleConfig={{ root: [rootStyles.root, ...(styleConfig?.root ?? [])] }}>{children}</Container>;
40
+ };
41
+
42
+ export default ModalAction;
@@ -0,0 +1 @@
1
+ export { default } from './ModalAction';
@@ -0,0 +1,40 @@
1
+ import React, { ReactNode, useContext } from 'react';
2
+
3
+ import { Box } from '@cleartrip/ct-design-box';
4
+ import { useStyles } from '@cleartrip/ct-design-style-manager';
5
+ import type { Styles } from '@cleartrip/ct-design-types';
6
+
7
+ import ModalContext from '../ModalContext';
8
+ import { ModalSizeTypes } from '../type';
9
+ import { ModalSize } from '../constants';
10
+
11
+ type ModalContainerProps = {
12
+ size?: ModalSizeTypes;
13
+ children: ReactNode;
14
+ styleConfig?: { root?: Styles[] };
15
+ };
16
+
17
+ const ModalContainer: React.FC<ModalContainerProps> = ({ children, styleConfig }) => {
18
+ const { size } = useContext(ModalContext);
19
+ const isFullScreen = size === ModalSize.FULL_SCREEN;
20
+
21
+ const rootStyles = useStyles(
22
+ () => ({
23
+ root: {
24
+ // Since it's a web only property, we need to cast it to a number
25
+ maxHeight: isFullScreen ? '100%' : ('calc(100vh - 128px)' as unknown as number),
26
+ overflowY: 'auto',
27
+ height: isFullScreen ? '100%' : undefined,
28
+ },
29
+ }),
30
+ [isFullScreen],
31
+ );
32
+
33
+ return (
34
+ <Box boxSize='zero' styleConfig={{ root: [rootStyles.root, ...(styleConfig?.root ?? [])] }}>
35
+ {children}
36
+ </Box>
37
+ );
38
+ };
39
+
40
+ export default ModalContainer;
@@ -0,0 +1 @@
1
+ export { default } from './ModalContainer';
@@ -0,0 +1,44 @@
1
+ import React, { ReactNode } from 'react';
2
+
3
+ import { Box } from '@cleartrip/ct-design-box';
4
+ import { useStyles } from '@cleartrip/ct-design-style-manager';
5
+ import type { Styles } from '@cleartrip/ct-design-types';
6
+
7
+ type ModalContentStyleConfig = {
8
+ root?: Styles[];
9
+ innerBox?: Styles[];
10
+ };
11
+
12
+ type ModalContentProps = {
13
+ children: ReactNode;
14
+ styleConfig?: ModalContentStyleConfig;
15
+ };
16
+
17
+ const ModalContent: React.FC<ModalContentProps> = ({ children, styleConfig }) => {
18
+ const staticStyles = useStyles(
19
+ (theme) => ({
20
+ root: {
21
+ overflowY: 'auto',
22
+ flex: 1,
23
+ },
24
+ innerBox: {
25
+ paddingTop: theme.spacing[6],
26
+ paddingBottom: theme.spacing[6],
27
+ paddingLeft: theme.spacing[4],
28
+ paddingRight: theme.spacing[4],
29
+ width: '100%',
30
+ },
31
+ }),
32
+ [],
33
+ );
34
+
35
+ return (
36
+ <Box boxSize='zero' styleConfig={{ root: [staticStyles.root, ...(styleConfig?.root ?? [])] }}>
37
+ <Box boxSize='xLarge' styleConfig={{ root: [staticStyles.innerBox, ...(styleConfig?.innerBox ?? [])] }}>
38
+ {children}
39
+ </Box>
40
+ </Box>
41
+ );
42
+ };
43
+
44
+ export default ModalContent;
@@ -0,0 +1 @@
1
+ export { default } from './ModalContent';
@@ -0,0 +1,14 @@
1
+ import { createContext } from 'react';
2
+ import { ModalProps } from './type';
3
+
4
+ type ModalContextProp = Pick<ModalProps, 'onClose' | 'size' | 'hideCrossIcon' | 'footerAlignment'>;
5
+ const ModalContext = createContext<ModalContextProp>({
6
+ footerAlignment: 'end',
7
+ hideCrossIcon: false,
8
+ onClose: () => {
9
+ return;
10
+ },
11
+ size: 'MEDIUM',
12
+ });
13
+
14
+ export default ModalContext;
@@ -0,0 +1,70 @@
1
+ import React, { ReactNode, useContext } from 'react';
2
+
3
+ import { Container } from '@cleartrip/ct-design-container';
4
+ import { Cross } from '@cleartrip/ct-design-icons';
5
+ import { useStyles } from '@cleartrip/ct-design-style-manager';
6
+ import { useTheme } from '@cleartrip/ct-design-theme';
7
+ import { Typography, TypographyStyleConfigProps } from '@cleartrip/ct-design-typography';
8
+ import type { Styles } from '@cleartrip/ct-design-types';
9
+
10
+ import ModalContext from '../ModalContext';
11
+ import { ModalProps } from '../type';
12
+ import { ModalSize } from '../constants';
13
+
14
+ type ModalTitleStyleConfig = {
15
+ root?: Styles[];
16
+ iconContainer?: Styles[];
17
+ childrenTypography?: TypographyStyleConfigProps;
18
+ crossIcon?: React.SVGProps<SVGSVGElement>;
19
+ };
20
+
21
+ type ModalTitleProps = Pick<ModalProps, 'hideCrossIcon' | 'onClose'> & {
22
+ children: ReactNode;
23
+ styleConfig?: ModalTitleStyleConfig;
24
+ };
25
+
26
+ const ModalTitle: React.FunctionComponent<ModalTitleProps> = ({ children, styleConfig }) => {
27
+ const theme = useTheme();
28
+ const { hideCrossIcon, onClose, size } = useContext(ModalContext);
29
+ const isFullScreen = size === ModalSize.FULL_SCREEN;
30
+
31
+ const rootStyles = useStyles(
32
+ (t) => ({
33
+ root: {
34
+ display: 'flex',
35
+ justifyContent: 'space-between',
36
+ paddingTop: isFullScreen ? t.spacing[5] : t.spacing[6],
37
+ paddingBottom: isFullScreen ? t.spacing[5] : t.spacing[4],
38
+ paddingLeft: isFullScreen ? t.spacing[7] : t.spacing[6],
39
+ paddingRight: isFullScreen ? t.spacing[7] : t.spacing[6],
40
+ boxShadow: t.elevation.bottomE1,
41
+ },
42
+ iconContainer: {
43
+ cursor: 'pointer',
44
+ marginTop: t.spacing[1],
45
+ marginRight: t.spacing[1],
46
+ },
47
+ }),
48
+ [isFullScreen],
49
+ );
50
+
51
+ return (
52
+ <Container styleConfig={{ root: [rootStyles.root, ...(styleConfig?.root ?? [])] }}>
53
+ <Typography variant='HM2' styleConfig={styleConfig?.childrenTypography}>
54
+ {children}
55
+ </Typography>
56
+ {!hideCrossIcon && (
57
+ <Container
58
+ onClick={onClose}
59
+ styleConfig={{
60
+ root: [rootStyles.iconContainer, ...(styleConfig?.iconContainer ?? [])],
61
+ }}
62
+ >
63
+ <Cross height={24} width={24} crossColor={theme.color.text.heading} {...styleConfig?.crossIcon} />
64
+ </Container>
65
+ )}
66
+ </Container>
67
+ );
68
+ };
69
+
70
+ export default ModalTitle;
@@ -0,0 +1 @@
1
+ export { default } from './ModalTitle';
@@ -0,0 +1,92 @@
1
+ import { forwardRef } from 'react';
2
+
3
+ import { Container, ContainerRef } from '@cleartrip/ct-design-container';
4
+ import { makeStyles, useStyles } from '@cleartrip/ct-design-style-manager';
5
+ import { Cross, ModalBack } from '@cleartrip/ct-design-icons';
6
+
7
+ import Modal from '../Modal';
8
+ import { ModalVariant } from '../constants';
9
+ import { ModalWithCloseOverlayProps } from './type';
10
+
11
+ const staticStyles = makeStyles(() => ({
12
+ root: {
13
+ position: 'relative',
14
+ },
15
+ }));
16
+
17
+ /**
18
+ * Returns the close icon for the modal — a back arrow when `isBack` is true,
19
+ * otherwise a cross whose stroke matches the modal variant.
20
+ */
21
+ const getCloseIcon = (isBack = false, variant: `${ModalVariant}` = ModalVariant.NEUTRAL) => {
22
+ if (isBack) {
23
+ return <ModalBack />;
24
+ }
25
+ return variant === ModalVariant.DARK ? (
26
+ <Cross height={24} width={24} crossColor='rgba(255, 255, 255, 1)' />
27
+ ) : (
28
+ <Cross height={24} width={24} crossColor='#1A1A1A' />
29
+ );
30
+ };
31
+
32
+ /**
33
+ * Modal variant that renders a floating close/back button above (or below) the
34
+ * modal content. Useful for dialogs where the close affordance should sit
35
+ * outside the content card.
36
+ */
37
+ const ModalWithCloseOverlay = forwardRef<ContainerRef, ModalWithCloseOverlayProps>((props, forwardedRef) => {
38
+ const {
39
+ isBack = false,
40
+ isCenter,
41
+ isTop = true,
42
+ variant = ModalVariant.NEUTRAL,
43
+ children,
44
+ styleConfig,
45
+ wrapperStyles,
46
+ ...rest
47
+ } = props || {};
48
+ const { onClose } = rest;
49
+
50
+ const closeButtonStyles = useStyles(
51
+ (theme) => ({
52
+ root: {
53
+ position: 'absolute',
54
+ right: (isCenter ? '50%' : isBack ? 'unset' : 0) as unknown as number,
55
+ transform: isCenter ? 'translateX(50%)' : 'none',
56
+ backgroundColor:
57
+ variant === ModalVariant.DARK ? theme.color.background.defaultDarkest : theme.color.background.neutral,
58
+ height: 32,
59
+ width: 32,
60
+ display: 'flex',
61
+ alignItems: 'center',
62
+ padding: theme.spacing[1],
63
+ borderRadius: 40,
64
+ cursor: 'pointer',
65
+ ...(isTop ? { top: -42 } : { bottom: -42 }),
66
+ },
67
+ }),
68
+ [isBack, variant, isCenter, isTop],
69
+ );
70
+
71
+ const CloseIcon = getCloseIcon(isBack, variant);
72
+
73
+ return (
74
+ <Modal ref={forwardedRef} blur size='NONE' insidePortal variant={variant} {...rest}>
75
+ <Container styleConfig={{ root: [staticStyles.root, ...(styleConfig?.root ?? [])] }}>
76
+ <Container styleConfig={{ root: [...(wrapperStyles ?? []), ...(styleConfig?.wrapper ?? [])] }}>
77
+ <Container
78
+ styleConfig={{ root: [closeButtonStyles.root, ...(styleConfig?.closeButton ?? [])] }}
79
+ onClick={() => onClose?.()}
80
+ >
81
+ {CloseIcon}
82
+ </Container>
83
+ </Container>
84
+ {children}
85
+ </Container>
86
+ </Modal>
87
+ );
88
+ });
89
+
90
+ ModalWithCloseOverlay.displayName = 'ModalWithCloseOverlay';
91
+
92
+ export default ModalWithCloseOverlay;
@@ -0,0 +1,2 @@
1
+ //will add all kind of modals here.
2
+ export { default as ModalWithCloseOverlay } from './ModalWithCloseOverlay';
@@ -0,0 +1,40 @@
1
+ import type { Styles } from '@cleartrip/ct-design-types';
2
+ import { ModalProps } from '../type';
3
+
4
+ export interface ModalWithCloseOverlayProps extends ModalProps {
5
+ /**
6
+ * Show the back icon (left side) instead of the close icon.
7
+ * @default false
8
+ */
9
+ isBack?: boolean;
10
+
11
+ /**
12
+ * Centers the close/back button horizontally above (or below) the modal.
13
+ */
14
+ isCenter?: boolean;
15
+
16
+ /**
17
+ * Position the close/back button above the modal (`true`) or below it (`false`).
18
+ * @default true
19
+ */
20
+ isTop?: boolean;
21
+
22
+ /**
23
+ * Callback fired when the close/back button is pressed.
24
+ */
25
+ onClose?: (event?: React.MouseEvent<HTMLDivElement> | React.KeyboardEvent<HTMLDivElement>) => void;
26
+
27
+ /**
28
+ * Style overrides for the wrapper holding the close button.
29
+ */
30
+ wrapperStyles?: Styles[];
31
+
32
+ /**
33
+ * Style overrides for the outer container that positions the modal content.
34
+ */
35
+ styleConfig?: {
36
+ root?: Styles[];
37
+ wrapper?: Styles[];
38
+ closeButton?: Styles[];
39
+ };
40
+ }
@@ -0,0 +1,31 @@
1
+ export enum ModalSize {
2
+ SMALL = 'SMALL',
3
+ MEDIUM = 'MEDIUM',
4
+ LARGE = 'LARGE',
5
+ FULL_SCREEN = 'FULL_SCREEN',
6
+ NONE = 'NONE',
7
+ REGULAR = 'REGULAR',
8
+ BIG = 'BIG',
9
+ }
10
+
11
+ export enum ModalVariant {
12
+ DARK = 'dark',
13
+ NEUTRAL = 'neutral',
14
+ }
15
+
16
+ export enum ModalPlacement {
17
+ CENTER = 'center',
18
+ BOTTOM = 'bottom',
19
+ }
20
+
21
+ export enum ActionButtonVariant {
22
+ BACK = 'back',
23
+ CLOSE = 'close',
24
+ NONE = 'none',
25
+ }
26
+
27
+ export enum ActionButtonAlignment {
28
+ CENTER = 'center',
29
+ LEFT = 'left',
30
+ RIGHT = 'right',
31
+ }
@@ -0,0 +1,4 @@
1
+ export { default as Modal } from './Modal.native';
2
+ export type * from './type';
3
+ export * from './constants';
4
+ export { MODAL_ANIMATION_DURATION } from './modalUtils';
package/src/index.ts ADDED
@@ -0,0 +1,10 @@
1
+ export { default as Modal } from './Modal';
2
+ export type * from './type';
3
+ export * from './constants';
4
+ export { default as ModalAction } from './ModalAction';
5
+ export { default as ModalContainer } from './ModalContainer';
6
+ export { default as ModalContent } from './ModalContent';
7
+ export { default as ModalTitle } from './ModalTitle';
8
+ export { default as Backdrop } from './Backdrop';
9
+ export { ModalWithCloseOverlay } from './ModalsUsableComponents';
10
+ export { MODAL_ANIMATION_DURATION } from './modalUtils';
@@ -0,0 +1 @@
1
+ export const MODAL_ANIMATION_DURATION = 350;
@@ -0,0 +1,83 @@
1
+ import type { ViewStyle } from '@cleartrip/ct-design-types';
2
+ import type { Theme } from '@cleartrip/ct-design-theme';
3
+
4
+ import { ActionButtonAlignmentType, ModalPlacementTypes, ModalSizeTypes } from './type';
5
+
6
+ import { ActionButtonAlignment, ModalSize, ModalVariant } from './constants';
7
+
8
+ const getModalSizeStyles = (
9
+ size: ModalSizeTypes,
10
+ ): { width?: number | '100%'; height?: number | '100%'; flex?: number } => {
11
+ switch (size) {
12
+ case ModalSize.SMALL:
13
+ return { width: 360 };
14
+ case ModalSize.LARGE:
15
+ return { width: 1032 };
16
+ case ModalSize.FULL_SCREEN:
17
+ return { width: '100%', height: '100%', flex: 1 };
18
+ case ModalSize.NONE:
19
+ return {};
20
+ case ModalSize.BIG:
21
+ return { width: 730 };
22
+ case ModalSize.REGULAR:
23
+ return { width: 484 };
24
+ case ModalSize.MEDIUM:
25
+ default:
26
+ return { width: 504 };
27
+ }
28
+ };
29
+
30
+ const getModalChildContainerCommonStyles = ({
31
+ theme,
32
+ size,
33
+ blur,
34
+ }: {
35
+ theme: Theme;
36
+ size: ModalSizeTypes;
37
+ blur?: boolean;
38
+ variant?: `${ModalVariant}`;
39
+ }): {
40
+ maxHeight?: number | '100%' | '90%';
41
+ shadowColor?: string;
42
+ shadowOffset?: { width: number; height: number };
43
+ shadowOpacity?: number;
44
+ borderRadius?: number;
45
+ } => ({
46
+ borderRadius: size === ModalSize.FULL_SCREEN ? 0 : theme?.spacing?.['3'],
47
+ maxHeight: size === ModalSize.FULL_SCREEN ? '100%' : '90%',
48
+ shadowColor: blur ? '#000' : 'transparent',
49
+ shadowOffset: blur ? { width: 0, height: 2 } : { width: 0, height: 0 },
50
+ shadowOpacity: blur ? 0.2 : 0,
51
+ });
52
+
53
+ export const getModalChildContainerStyle = ({
54
+ theme,
55
+ size,
56
+ blur,
57
+ }: {
58
+ theme: Theme;
59
+ size: ModalSizeTypes;
60
+ blur: boolean;
61
+ }) => ({
62
+ ...getModalChildContainerCommonStyles({ theme, size, blur }),
63
+ ...getModalSizeStyles(size),
64
+ });
65
+
66
+ export const getModalPlacement = ({ placement }: { placement: ModalPlacementTypes }): ViewStyle => ({
67
+ justifyContent: placement === 'center' ? 'center' : 'flex-end',
68
+ });
69
+
70
+ export const getActionButtonAlignment = ({
71
+ actionButtonAlignment,
72
+ }: {
73
+ actionButtonAlignment: ActionButtonAlignmentType;
74
+ }) => {
75
+ switch (actionButtonAlignment) {
76
+ case ActionButtonAlignment.CENTER:
77
+ return { marginLeft: '50%' as unknown as number };
78
+ case ActionButtonAlignment.LEFT:
79
+ return { marginLeft: 0 as unknown as number };
80
+ default:
81
+ return { marginLeft: 'auto' as unknown as number };
82
+ }
83
+ };
package/src/style.ts ADDED
@@ -0,0 +1,44 @@
1
+ import { ModalSizeTypes } from './type';
2
+ import { ModalSize } from './constants';
3
+
4
+ export const getModalSizeStyles = (size: ModalSizeTypes) => {
5
+ switch (size) {
6
+ case ModalSize.SMALL: {
7
+ return {
8
+ width: '360px',
9
+ };
10
+ }
11
+ case ModalSize.LARGE: {
12
+ return {
13
+ width: '1032px',
14
+ };
15
+ }
16
+ case ModalSize.FULL_SCREEN: {
17
+ return {
18
+ width: '100vw',
19
+ height: '100vh',
20
+ minHeight: '100vh',
21
+ minWidth: '100%',
22
+ };
23
+ }
24
+ case ModalSize.NONE: {
25
+ return {};
26
+ }
27
+ case ModalSize.BIG: {
28
+ return {
29
+ width: '730px',
30
+ };
31
+ }
32
+ case ModalSize.REGULAR: {
33
+ return {
34
+ width: '484px',
35
+ };
36
+ }
37
+ case ModalSize.MEDIUM:
38
+ default: {
39
+ return {
40
+ width: '504px',
41
+ };
42
+ }
43
+ }
44
+ };
package/src/type.ts ADDED
@@ -0,0 +1,72 @@
1
+ import type { Styles } from '@cleartrip/ct-design-types';
2
+ import { ReactNode, ReactElement } from 'react';
3
+ import type { ContainerRef } from '@cleartrip/ct-design-container';
4
+
5
+ import { ModalSize, ModalVariant, ModalPlacement, ActionButtonVariant, ActionButtonAlignment } from './constants';
6
+
7
+ export type ModalSizeTypes = `${ModalSize}`;
8
+
9
+ type OwnModalProps = {
10
+ /**
11
+ * footerAlignment will give whether to give flex end or start or start
12
+ */
13
+ footerAlignment?: 'start' | 'end' | 'center';
14
+ animationDuration?: number;
15
+ };
16
+
17
+ export type ModalProps = IModalProps;
18
+
19
+ export type ActionButtonVariantsType = `${ActionButtonVariant}`;
20
+ export type ActionButtonAlignmentType = `${ActionButtonAlignment}`;
21
+ export type ModalPlacementTypes = `${ModalPlacement}`;
22
+ export type ModalVariantTypes = `${ModalVariant}`;
23
+
24
+ export interface IChildProps {
25
+ onClose?: () => void;
26
+ }
27
+
28
+ export interface IModalProps extends OwnModalProps {
29
+ /** Alignment of the action button. */
30
+ actionButtonAlignment?: ActionButtonAlignmentType;
31
+ /** Type of the action button (back, close, none). */
32
+ actionButtonType?: ActionButtonVariantsType;
33
+ /** Whether clicking on the backdrop should close the modal. */
34
+ allowBackdropClose?: boolean;
35
+ /** Duration of the open/close animation in milliseconds. */
36
+ animationDuration?: number;
37
+ /** Custom backdrop component; replaces the default overlay. */
38
+ backDropComponent?: ReactNode;
39
+ /** Adds a blur/dim effect to the background. */
40
+ blur?: boolean;
41
+ /** Content rendered inside the modal body. */
42
+ children?: ReactElement<{ onClose?: () => void }>;
43
+ /** Whether the modal opens inside a portal. */
44
+ insidePortal?: boolean;
45
+ /** Callback fired when the modal requests to close. */
46
+ onClose?: () => void;
47
+ /** Callback fired on key down events. */
48
+ onKeyDown?: (event: React.KeyboardEvent<HTMLDivElement>) => void;
49
+ /** Controls the modal's visibility. */
50
+ open: boolean;
51
+ /** Placement of the modal (center or bottom). */
52
+ placement?: ModalPlacementTypes;
53
+ /** Bottom margin for modal placement. */
54
+ bottomMargin?: number;
55
+ /** Ref to the underlying container. */
56
+ ref?: React.Ref<ContainerRef>;
57
+ /** Size preset controlling the modal's dimensions. */
58
+ size?: ModalSizeTypes;
59
+ /** Style overrides for modal slots. */
60
+ styleConfig?: {
61
+ root?: Styles[];
62
+ backdropStyles?: Styles[];
63
+ modalContentStyles?: Styles[];
64
+ actionButtonStyles?: Styles[];
65
+ };
66
+ /** Visual variant (dark or neutral). */
67
+ variant?: ModalVariantTypes;
68
+ /**
69
+ * hide cross icon
70
+ */
71
+ hideCrossIcon?: boolean;
72
+ }
@@ -1,11 +0,0 @@
1
- import { CSSObject } from 'styled-components';
2
- import { Theme } from '@cleartrip/ct-design-theme';
3
- import { ModalVariant } from '../type';
4
- export declare const getCloseButtonStyle: ({ theme, isLeft, variant, isCenter, isTop, }: {
5
- theme: Theme;
6
- isLeft: boolean;
7
- variant?: "dark" | "neutral" | undefined;
8
- isCenter?: boolean | undefined;
9
- isTop?: boolean | undefined;
10
- }) => CSSObject;
11
- //# sourceMappingURL=style.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../../packages/components/Modal/src/ModalsUsableComponents/style.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,eAAO,MAAM,mBAAmB;WAOvB,KAAK;YACJ,OAAO;;;;MAIb,SAaF,CAAC"}