* feat ui: dashboards redesign start * more cards * fix ui: more different cards... * feat ui: finish cards, all trigger, all icons * change(ui): added missin const * feature(ui): new dashboard modal * feature(ui): new dashboard modal * change(ui): new cards * change(ui): dashboard redesign * change(ui): dashboard redesign * change(ui): dashboard redesign * change(ui): modal context and alert form * change(ui): table card show more with modal * change(ui): examples * change(ui): example categorize and other improvements * change(ui): example categorize and other improvements * change(ui): performance cards * change(ui): insights card * Various style updates in dashboards and other pages. (#2308) * Various minor style updates * Various style improvements * Update ExampleCards.tsx * change(ui): fixed an issue with card create * change(ui): fixed an issue with card create * change(ui): default filters and events order * change(ui): random data * Dashboards redesign - improvments (#2313) * Various minor style updates * Various style improvements * Update ExampleCards.tsx * various minor improvements in dashbaords. * revised dashboard widget header * change(ui): sessions by user * change(ui): funnel example * change(ui): modal height and scroll * change(ui): example cards with data * change(ui): example cards with data * change(ui): funnel bar text color * change(ui): example cards overlay click * change(ui): path analysis filter card --------- Co-authored-by: Shekar Siri <sshekarsiri@gmail.com> Co-authored-by: Sudheer Salavadi <connect.uxmaster@gmail.com>
64 lines
1.7 KiB
TypeScript
64 lines
1.7 KiB
TypeScript
import React, {createContext, useContext, useState, ReactNode} from 'react';
|
|
import {Drawer} from 'antd';
|
|
|
|
interface ModalConfig {
|
|
title?: string;
|
|
placement?: 'top' | 'right' | 'bottom' | 'left';
|
|
width?: number;
|
|
}
|
|
|
|
interface ModalContextType {
|
|
openModal: (content: ReactNode, config?: ModalConfig) => void;
|
|
closeModal: () => void;
|
|
}
|
|
|
|
const defaultConfig: ModalConfig = {
|
|
title: 'Modal Title',
|
|
placement: 'right',
|
|
width: 428
|
|
};
|
|
|
|
const ModalContext = createContext<ModalContextType>({
|
|
openModal: () => {
|
|
},
|
|
closeModal: () => {
|
|
}
|
|
});
|
|
|
|
export const useModal = () => useContext(ModalContext);
|
|
|
|
export const ModalProvider = ({children}: { children: ReactNode }) => {
|
|
const [showModal, setShowModal] = useState(false);
|
|
const [modalContent, setModalContent] = useState<ReactNode>(null);
|
|
const [modalConfig, setModalConfig] = useState<ModalConfig>(defaultConfig);
|
|
|
|
const openModal = (content: ReactNode, config: ModalConfig = defaultConfig) => {
|
|
setModalContent(content);
|
|
setModalConfig(config);
|
|
setShowModal(true);
|
|
};
|
|
|
|
const closeModal = () => {
|
|
setShowModal(false);
|
|
setTimeout(() => {
|
|
setModalContent(null);
|
|
setModalConfig(defaultConfig);
|
|
}, 200)
|
|
};
|
|
|
|
return (
|
|
<ModalContext.Provider value={{openModal, closeModal}}>
|
|
{children}
|
|
<Drawer
|
|
open={showModal}
|
|
closeIcon={null}
|
|
title={modalConfig.title}
|
|
placement={modalConfig.placement}
|
|
onClose={closeModal}
|
|
width={modalConfig.width}
|
|
>
|
|
{modalContent}
|
|
</Drawer>
|
|
</ModalContext.Provider>
|
|
);
|
|
};
|