Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Modal add #13

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/shared/Modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { createSignal, Component, Show } from "solid-js";
// Component Properties
interface Props {
messageHeader: string;
message: string;
confirmText: string;
declineText: string;
onConfirm: () => void;
}

const Modal: Component<Props> = (props) => {
const [show, setShow] = createSignal(true);

const handleClose = () => {
setShow(false);
};
// Make sure you set an onConfirm function on the page or it will simply close the modal without performing a task!!
const handleConfirm = () => {
props.onConfirm();
setShow(false);
};

return (
<Show when={show()}>
<div class="fixed inset-x-0 bottom-0 px-4 pb-4 sm:inset-0 sm:flex sm:items-center sm:justify-center">
<div class="fixed inset-0 transition-opacity">
<div class="absolute inset-0 bg-gray-500 opacity-75" />
</div>
Comment on lines +26 to +28
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to have a different z-index? On my machine, the background actually shows in front of the modal and stops me from interacting with it:

Screen Shot 2023-02-18 at 18 54 40

<div class="overflow-hidden rounded-lg bg-black px-4 pt-5 pb-4 shadow-xl transition-all sm:w-full sm:max-w-lg">
<div>
<div class="black mb-4 text-lg font-bold">
{props.messageHeader}
</div>
<div class="black mb-4 text-lg">{props.message}</div>
<div class="flex items-center justify-end">
<button

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could there be a case where we may need more or less buttons than two? For example, a modal with information that doesn't need a confirm/deny action.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I can also foresee situations where e.g. the button(s) should be disabled until a certain condition is met, and things of the sort.

I think the best interface for that will likely imply breaking the Modal component apart into Modal.Header, Modal.Body and Modal.Footer so we have fine-grained control of the contents in each through the children prop, but I think that can be left as a future PR if necessary.

class="text-red-500 hover:text-red-700"
onClick={handleClose}
>
{props.declineText}
</button>
<button
class="ml-3 rounded bg-purple-600 py-2 px-4 font-bold text-white hover:bg-purple-500"
onClick={handleConfirm}
>
{props.confirmText}
</button>
</div>
</div>
</div>
</div>
</Show>
);
};

export default Modal;