MCPcopy Create free account
hub / github.com/dailydotdev/apps / Modal

Function Modal

packages/shared/src/components/modals/common/Modal.tsx:88–235  ·  view source on GitHub ↗
({
  defaultView,
  className,
  overlayClassName,
  children,
  kind = ModalKind.FlexibleCenter,
  size = ModalSize.Medium,
  onViewChange,
  onLogNext,
  onLogPrev,
  onRequestClose,
  tabs,
  steps,
  isDrawerOnMobile,
  drawerProps,
  shouldCloseOnOverlayClick,
  formProps,
  ...props
}: ModalProps)

Source from the content-addressed store, hash-verified

86let openModalCount = 0;
87
88export function Modal({
89 defaultView,
90 className,
91 overlayClassName,
92 children,
93 kind = ModalKind.FlexibleCenter,
94 size = ModalSize.Medium,
95 onViewChange,
96 onLogNext,
97 onLogPrev,
98 onRequestClose,
99 tabs,
100 steps,
101 isDrawerOnMobile,
102 drawerProps,
103 shouldCloseOnOverlayClick,
104 formProps,
105 ...props
106}: ModalProps): ReactElement | null {
107 if (!isExtension) {
108 initReactModal({
109 modalObject: ReactModal,
110 appElement: '#__next',
111 });
112 }
113
114 const stepTitle = steps ? steps?.[0].key : undefined;
115 const tabTitle = tabs ? modalTabTitle(tabs[0]) : undefined;
116 const isMobile = useViewSize(ViewSize.MobileL);
117 const isDrawerOpen = isDrawerOnMobile && isMobile;
118 const isForm = formProps && isMobile;
119 const [activeView, setView] = useState<string | undefined>(
120 isMobile && tabs ? defaultView : (defaultView ?? stepTitle ?? tabTitle),
121 );
122 const opensOverModal = useMemo(
123 () => props.isOpen && openModalCount > 0,
124 [props.isOpen],
125 );
126
127 useEffect(() => {
128 if (!props.isOpen) {
129 return undefined;
130 }
131
132 openModalCount += 1;
133 return () => {
134 openModalCount -= 1;
135 };
136 }, [props.isOpen]);
137
138 const setActiveView = (view?: string) => {
139 if (onViewChange && view) {
140 onViewChange(view);
141 }
142 setView(view);
143 };
144
145 const content = (

Callers

nothing calls this directly

Calls 4

initReactModalFunction · 0.90
modalTabTitleFunction · 0.90
useViewSizeFunction · 0.90
onRequestCloseFunction · 0.50

Tested by

no test coverage detected