Skip to content

Commit

Permalink
wip: dialog lcp
Browse files Browse the repository at this point in the history
  • Loading branch information
panaC committed Oct 27, 2023
1 parent 1f0deca commit 402ff0a
Show file tree
Hide file tree
Showing 12 changed files with 870 additions and 143 deletions.
448 changes: 447 additions & 1 deletion package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
}
},
"dependencies": {
"@radix-ui/react-alert-dialog": "^1.0.5",
"@xmldom/xmldom": "^0.8.10",
"classnames": "^2.3.2",
"commonmark": "^0.30.0",
Expand Down
118 changes: 118 additions & 0 deletions src/renderer/assets/styles/components/alert.modals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@

.AlertDialogOverlay {
background-color: rgba(0, 0, 0, 0.5);
position: fixed;
inset: 0;
animation: overlayShow 150ms cubic-bezier(0.16, 1, 0.3, 1);
z-index: 110;
}

.AlertDialogContent {
background-color: white;
border-radius: 6px;
box-shadow: hsl(206deg 22% 7% / 35%) 0 10px 38px -10px, hsl(206deg 22% 7% / 20%) 0 10px 20px -15px;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 90vw;
max-width: 500px;
max-height: 85vh;
padding: 25px;
animation: contentShow 150ms cubic-bezier(0.16, 1, 0.3, 1);
z-index: 110;
}

.AlertDialogContent:focus {
outline: none;
}

.AlertDialogTitle {
margin: 0;
color: var(--color-primary);
font-size: 17px;
font-weight: 600;
}

.AlertDialogDescription {
margin-bottom: 20px;
color: var(--color-primary);
font-size: 15px;
line-height: 1.5;
}

.AlertDialogButton {
display: inline-flex;
align-items: center;
justify-content: center;
border-radius: 4px;
padding: 0 15px;
font-size: 15px;
line-height: 1;
font-weight: 500;
height: 35px;
}

.AlertDialogButton.violet {
background-color: white;
color: var(--violet-11);
box-shadow: 0 2px 10px var(--color-primary);
}

.AlertDialogButton.violet:hover {
background-color: var(--color-accent);
}

.AlertDialogButton.violet:focus {
box-shadow: 0 0 0 2px black;
}

.AlertDialogButton.delete {
color: var(--red-11);
border: 2px solid var(--color-alert-red);
transition: 200ms;
}

.AlertDialogButton.delete:hover {
background-color: var(--color-alert-red);
border: 2px solid var(--color-alert-red);
}

.AlertDialogButton.delete:focus {
background-color: var(--color-alert-red);
border: 2px solid var(--color-alert-red);
}

.AlertDialogButton.abort {
color: var(--mauve-11);
border: 2px solid var(--color-medium-grey);
}

.AlertDialogButton.abort:hover {
border: 2px solid var(--color-abort);
}

.AlertDialogButton.abort:focus {
border: 2px solid var(--color-abort);
}

/* @keyframes overlayShow {
from {
opacity: 0;
}
to {
opacity: 1;
}
} */

/* @keyframes contentShow {
from {
opacity: 0;
transform: translate(-50%, -48%) scale(0.96);
}
to {
opacity: 1;
transform: translate(-50%, -50%) scale(1);
}
}
*/
14 changes: 14 additions & 0 deletions src/renderer/assets/styles/components/alert.modals.css.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
declare const styles: {
readonly "AlertDialogOverlay": string;
readonly "overlayShow": string;
readonly "AlertDialogContent": string;
readonly "contentShow": string;
readonly "AlertDialogTitle": string;
readonly "AlertDialogDescription": string;
readonly "AlertDialogButton": string;
readonly "violet": string;
readonly "delete": string;
readonly "abort": string;
};
export = styles;

2 changes: 1 addition & 1 deletion src/renderer/assets/styles/components/blocks.css.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
declare const styles: {
readonly "block_line": string;
readonly "block_line_inactive": string;
readonly "description_see_more": string;
readonly "block_line_edit": string;
readonly "block_line_inactive": string;
readonly "block_full": string;
readonly "block_full_wrapper": string;
readonly "block_full_close": string;
Expand Down
33 changes: 27 additions & 6 deletions src/renderer/assets/styles/components/modals.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@
}

.modal_dialog {
margin: 30px;
min-height: 400px;
min-width: 700px;
max-width: calc(100vw - 60px);
max-height: calc(100vh - 60px);
transform: translate(-50%, -50%);
left: 50%;
top: 50%;
min-height: 570px;
min-width: 800px;
width: 960px;
max-width: 960px;
max-height: calc(100vh - 200px);
border-radius: 10px;
z-index: 102;
display: flex;
Expand All @@ -52,9 +55,13 @@
overflow-x: hidden;
align-content: flex-start;
color: #3b3b3b;
position: relative;
position: absolute;
box-sizing: border-box;

@media screen and (width <= 960px) {
width: 100vw;
}

&.modal_dialog_full {
width: calc(100vw - 60px);
height: calc(100vh - 60px);
Expand Down Expand Up @@ -110,6 +117,10 @@
.modal_dialog_footer {
justify-content: end;
border-top: 1px solid var(--color-medium-grey);
position: sticky;
bottom: 0;
right: 0;
background-color: var(--color-secondary);

& [type="submit"] {
min-width: 100px;
Expand Down Expand Up @@ -171,3 +182,13 @@
.___DEBUG___COMPONENTS_MODALS_CSS {
display: none;
}


.modal_dialog-collapsed {
min-height: 0;
}

.modal_dialog_body-collapsed {
height: 0;
display: none;
}
3 changes: 2 additions & 1 deletion src/renderer/assets/styles/components/modals.css.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ declare const styles: {
readonly "modal_dialog_overlay_hidden": string;
readonly "modal_dialog": string;
readonly "modal_dialog_full": string;
readonly "modal_dialog_form_wrapper": string;
readonly "modal_dialog_body": string;
readonly "modal_dialog_body_centered": string;
readonly "modal_dialog_header": string;
Expand All @@ -14,6 +13,8 @@ declare const styles: {
readonly "field": string;
readonly "add_dialog": string;
readonly "___DEBUG___COMPONENTS_MODALS_CSS": string;
readonly "modal_dialog-collapsed": string;
readonly "modal_dialog_body-collapsed": string;
};
export = styles;

136 changes: 136 additions & 0 deletions src/renderer/common/components/dialog/DialogWithRadix.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
// ==LICENSE-BEGIN==
// Copyright 2017 European Digital Reading Lab. All rights reserved.
// Licensed to the Readium Foundation under one or more contributor license agreements.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file exposed on Github (readium) in the project repository.
// ==LICENSE-END==

import * as React from "react";
import * as Dialog from "@radix-ui/react-dialog";
import { useTranslator } from "readium-desktop/renderer/common/hooks/useTranslator";
import * as QuitIcon from "readium-desktop/renderer/assets/icons/baseline-close-24px.svg";
import SVG from "readium-desktop/renderer/common/components/SVG";
import { useSelector } from "readium-desktop/renderer/common/hooks/useSelector";
import * as stylesModals from "readium-desktop/renderer/assets/styles/components/modals.css";
import * as stylesButtons from "readium-desktop/renderer/assets/styles/components/buttons.css";
import * as chevronDownIcon from "readium-desktop/renderer/assets/icons/chevron-down.svg";
import classNames from "classnames";
import { IRendererCommonRootState } from "readium-desktop/common/redux/states/rendererCommonRootState";

export const DialogWithRadix: React.FC<React.PropsWithChildren<{ defaultOpen?: boolean | undefined }>> = (props) => {
const [open, setOpen] = React.useState(false);

const openFromState = useSelector((state: IRendererCommonRootState) => state.dialog.open);
React.useMemo(() => {
if (!openFromState) {
setOpen(false);
}
}, [openFromState]);

return (
<Dialog.Root
defaultOpen={props.defaultOpen}
open={open}
onOpenChange={
(open) => {
if (open) {
setOpen(true);
} else {
setOpen(false);
}
}}
>
{props.children}
</Dialog.Root>
);
};

export const DialogWithRadixTrigger = Dialog.Trigger;
DialogWithRadixTrigger.displayName = Dialog.Trigger.displayName;

const DialogContext = React.createContext<{
collapse: {
toggleCollapse: () => void;
isCollapsed: boolean;
};
}>(undefined);

export const DialogWithRadixContent: React.FC<React.PropsWithChildren<{}>> = (props) => {
const appOverlayElement = React.useMemo(() => document.getElementById("app-overlay"), []);
const [__] = useTranslator();
const [isCollapsed, setCollapse] = React.useState(false);

const toggleCollapse = () => {
setCollapse(!isCollapsed);
};

const dialogContextValue = { collapse: { toggleCollapse, isCollapsed } };

return (
<Dialog.Portal container={appOverlayElement}>
<div className={stylesModals.modal_dialog_overlay}></div>
<Dialog.Content className={classNames(stylesModals.modal_dialog, isCollapsed ? stylesModals["modal_dialog-collapsed"] : undefined)}
style={{
backgroundColor: "white",
zIndex: "10000",
}}
id="modalContainer">
<DialogContext.Provider value={dialogContextValue}>
{props.children}
</DialogContext.Provider>
</Dialog.Content>
</Dialog.Portal>
);
};
DialogWithRadixContent.displayName = "DialogWithRadixContent";

export const DialogTitle = Dialog.Title;
DialogTitle.displayName = "DialogTitle";


export const DialogHeader: React.FC<React.PropsWithChildren<{}>> = (props) => {
return (
<div className={stylesModals.modal_dialog_header}>
{props.children}

</div>
);
};

export const DialogCollapseButton: React.FC<{}> = () => {
const {collapse: {toggleCollapse}} = React.useContext(DialogContext);
return (
<button style={{width: "20px", height: "20px"}} id="chevronButton" onClick={() => toggleCollapse()}>
<SVG ariaHidden={true} svg={chevronDownIcon} />
</button>
);
};

export const DialogCloseButton: React.FC<{}> = () => {
return (
<Dialog.Close asChild>
<button className={stylesButtons.button_transparency_icon} aria-label="Close">
<SVG ariaHidden={true} svg={QuitIcon} />
</button>
</Dialog.Close>
);
};

export const DialogContent : React.FC<React.PropsWithChildren<{}>> = (props) => {
const {collapse: {isCollapsed}} = React.useContext(DialogContext);
return (
<div className={classNames(stylesModals.modal_dialog_body, isCollapsed ? stylesModals["modal_dialog_body-collapsed"]: undefined)}>
{props.children}
</div>
);
};

export const DialogFooter: React.FC<React.PropsWithChildren<{}>> = (props) => {
return (
<div className={stylesModals.modal_dialog_footer}>
{props.children}
</div>
);
};

export const DialogClose = Dialog.Close;
2 changes: 0 additions & 2 deletions src/renderer/library/components/dialog/DialogManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import FileImport from "./FileImport";
import LcpAuthentication from "./LcpAuthentication";
import OpdsFeedAddForm from "./OpdsFeedAddForm";
import OpdsFeedUpdateForm from "./OpdsFeedUpdateForm";
import RenewLsdConfirm from "./RenewLsdConfirm";
import ReturnLsdConfirm from "./ReturnLsdConfirm";

// eslint-disable-next-line @typescript-eslint/no-empty-interface
Expand Down Expand Up @@ -53,7 +52,6 @@ class DialogManager extends React.Component<IProps, undefined> {
<DeletePublicationConfirm></DeletePublicationConfirm>
<DeleteOpdsFeedConfirm></DeleteOpdsFeedConfirm>
<LcpAuthentication></LcpAuthentication>
<RenewLsdConfirm></RenewLsdConfirm>
<ReturnLsdConfirm></ReturnLsdConfirm>
<PublicationInfo></PublicationInfo>
</>
Expand Down
Loading

0 comments on commit 402ff0a

Please sign in to comment.