Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add modals from Tobira #5

Merged
merged 19 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions src/confirmationModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,25 @@ import { currentRef } from "./utilFunc";

type ConfirmationModalProps = Omit<ModalProps, "closable" | "title"> & {
title?: string;
/** What to display in the confirm button. A string can be enough. */
buttonContent: ReactNode;
onSubmit?: () => void;
/** Strings that will be displayed in the UI */
text: {
/** Text on the button to close the modal */
cancel: string,
/** Text on the button to close the modal */
Arnei marked this conversation as resolved.
Show resolved Hide resolved
close: string,
/** Text asking the question that should be confirmed or cancelled. */
areYouSure: string,
},
};

/**
* A component that sits in the middle of the screen, darkens the rest of the
* screen and traps user focus. Also asks for confirmation, and closing can
* be delayed if a time intensive action was triggered.
*/
export type ConfirmationModalHandle = ModalHandle & {
done: () => void;
reportError: (error: JSX.Element) => void;
Expand Down
10 changes: 10 additions & 0 deletions src/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ import {

export type ModalProps = {
title: string;
/** Whether the user can close the modal. If false, the application
* will have to close the modal eventually. */
closable?: boolean;
className?: string;
closeOnOutsideClick?: boolean;
open?: boolean;
/** If true, the first element in the modal automatically be focused. If false,
* no element is initially focused */
initialFocus?: false;
/** Strings that will be displayed in the UI */
text: {
/** Text on the button to close the modal */
close: string,
},
};
Expand All @@ -30,6 +36,10 @@ export type ModalHandle = {
isOpen?: () => boolean;
};

/**
* A component that sits in the middle of the screen, darkens the rest of the
* screen and traps user focus.
*/
export const Modal = forwardRef<ModalHandle, PropsWithChildren<ModalProps>>(({
Arnei marked this conversation as resolved.
Show resolved Hide resolved
title,
closable = true,
Expand Down
4 changes: 4 additions & 0 deletions src/styledButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
),
);

Arnei marked this conversation as resolved.
Show resolved Hide resolved
/**
* Returns css for different types of buttons.
* Comes in the kinds "normal", "danger" and "happy".
*/
const css = (kind: Kind, extraCss: Interpolation<Theme> = {}): Interpolation<Theme> => {
const config = useAppkitConfig();
Arnei marked this conversation as resolved.
Show resolved Hide resolved

Expand Down