mirror of
https://github.com/lukevella/rallly.git
synced 2025-08-02 16:09:08 +02:00
Add option to delete poll (#174)
This commit is contained in:
parent
2c4157ea24
commit
c170e03b6a
25 changed files with 271 additions and 104 deletions
|
@ -8,9 +8,15 @@ export interface ModalProviderProps {
|
|||
children?: React.ReactNode;
|
||||
}
|
||||
|
||||
type ModalContentProps = { close: () => void };
|
||||
|
||||
interface ModalConfig extends ModalProps {
|
||||
content?: React.ReactNode | ((props: ModalContentProps) => React.ReactNode);
|
||||
}
|
||||
|
||||
const ModalContext =
|
||||
React.createContext<{
|
||||
render: (el: ModalProps) => void;
|
||||
render: (el: ModalConfig) => void;
|
||||
} | null>(null);
|
||||
|
||||
ModalContext.displayName = "<ModalProvider />";
|
||||
|
@ -22,7 +28,7 @@ export const useModalContext = () => {
|
|||
const ModalProvider: React.VoidFunctionComponent<ModalProviderProps> = ({
|
||||
children,
|
||||
}) => {
|
||||
const [modals, { push, removeAt, updateAt }] = useList<ModalProps>([]);
|
||||
const [modals, { push, removeAt, updateAt }] = useList<ModalConfig>([]);
|
||||
|
||||
const removeModalAt = (index: number) => {
|
||||
updateAt(index, { ...modals[index], visible: false });
|
||||
|
@ -44,6 +50,11 @@ const ModalProvider: React.VoidFunctionComponent<ModalProviderProps> = ({
|
|||
key={i}
|
||||
visible={true}
|
||||
{...props}
|
||||
content={
|
||||
typeof props.content === "function"
|
||||
? props.content({ close: () => removeModalAt(i) })
|
||||
: props.content
|
||||
}
|
||||
onOk={() => {
|
||||
props.onOk?.();
|
||||
removeModalAt(i);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue