Skip to content

Commit 7ad700f

Browse files
committed
[B] Fix up new dialog modal styles
1 parent 0046311 commit 7ad700f

File tree

7 files changed

+126
-40
lines changed

7 files changed

+126
-40
lines changed

client/src/global/components/Annotation/Annotation/UserContent/Flag/Modal.js

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import IconComposer from "global/components/utility/IconComposer";
88
import { FormContext } from "helpers/contexts";
99
import { useApiCallback, useFromStore } from "hooks";
1010
import { annotationsAPI, commentsAPI } from "api";
11+
import Modal from "global/components/dialog/Modal";
1112
import * as Styled from "./styles";
1213

1314
export default function FlagAnnotationModal({
1415
id,
1516
annotationId,
1617
type,
17-
dialog
18+
dialog,
19+
dialogId
1820
}) {
1921
const { t } = useTranslation();
2022

@@ -53,21 +55,8 @@ export default function FlagAnnotationModal({
5355
const colorScheme = useFromStore("ui.persistent.reader.colors.colorScheme");
5456
const styleType = colorScheme === "dark" ? "secondary" : "primary";
5557

56-
const handleEsc = e => {
57-
if (e.key === "Escape") {
58-
// prevent also exiting full screen in FF
59-
e.preventDefault();
60-
dialog.onCloseClick();
61-
}
62-
};
63-
6458
return (
65-
<Styled.Dialog
66-
className="dialog"
67-
ref={dialog.dialogRef}
68-
inert={!dialog.open ? "" : undefined}
69-
onKeyDown={handleEsc}
70-
>
59+
<Modal id={dialogId} dialog={dialog} maxWidth={600}>
7160
<header className="dialog__header">
7261
<Styled.Heading>
7362
{t("reader.report_annotation.header", {
@@ -110,6 +99,7 @@ export default function FlagAnnotationModal({
11099
{t("actions.report")}
111100
</button>
112101
<button
102+
type="button"
113103
className={classNames(
114104
buttonClasses,
115105
"button-icon-secondary--dull"
@@ -126,7 +116,7 @@ export default function FlagAnnotationModal({
126116
</Styled.ButtonGroup>
127117
</Styled.Form>
128118
</FormContext.Provider>
129-
</Styled.Dialog>
119+
</Modal>
130120
);
131121
}
132122

@@ -135,6 +125,7 @@ FlagAnnotationModal.displayName = "Annotation.Annotation.UserContent.FlagModal";
135125
FlagAnnotationModal.propTypes = {
136126
id: PropTypes.string.isRequired,
137127
type: PropTypes.string.isRequired,
128+
dialogId: PropTypes.string.isRequired,
138129
dialog: PropTypes.object.isRequired,
139130
annotationId: PropTypes.string
140131
};

client/src/global/components/Annotation/Annotation/UserContent/Flag/Toggle.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import useDialog from "@castiron/hooks/useDialog";
55
import { annotationsAPI, commentsAPI } from "api";
66
import Modal from "./Modal";
77
import * as Styled from "../styles";
8+
import { useUID } from "react-uid";
89

910
export default function FlagModalToggle({ record, annotationId }) {
1011
const { t } = useTranslation();
@@ -17,6 +18,8 @@ export default function FlagModalToggle({ record, annotationId }) {
1718
const handleUnflag =
1819
record.type === "annotations" ? unflagAnnotation : unflagComment;
1920

21+
const uid = useUID();
22+
2023
return (
2124
<>
2225
{record?.attributes?.flagged ? (
@@ -27,12 +30,14 @@ export default function FlagModalToggle({ record, annotationId }) {
2730
<Styled.SecondaryButton
2831
ref={dialog.toggleRef}
2932
onClick={dialog.onToggleClick}
33+
aria-controls={uid}
3034
>
3135
{t("actions.report")}
3236
</Styled.SecondaryButton>
3337
)}
3438
<Modal
3539
id={record.id}
40+
modalId={uid}
3641
annotationId={annotationId}
3742
type={record.type}
3843
dialog={dialog}
Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import styled from "@emotion/styled";
2-
import {
3-
respond,
4-
defaultFocusStyle,
5-
transparentize
6-
} from "theme/styles/mixins";
2+
import { respond } from "theme/styles/mixins";
73

84
export const Form = styled.form`
95
--TextArea-border-color: var(--color);
@@ -35,22 +31,3 @@ export const ButtonGroup = styled.div`
3531
export const Heading = styled.h2`
3632
color: ${$dark => ($dark ? `var(--strong-color)` : `var(--box-color)`)};
3733
`;
38-
39-
export const Dialog = styled.dialog`
40-
position: fixed;
41-
top: 50%;
42-
transform: translate(0, -50%);
43-
max-height: 60dvh;
44-
width: min(90vw, 600px);
45-
border-radius: 20px;
46-
border: none;
47-
&:focus-visible {
48-
${defaultFocusStyle}
49-
}
50-
&::backdrop {
51-
background-color: ${transparentize("neutralBlack", 0.3)};
52-
}
53-
.reader.scheme-dark & {
54-
background: var(--color-base-neutral90);
55-
}
56-
`;
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import PropTypes from "prop-types";
2+
import IconComposer from "global/components/utility/IconComposer";
3+
import * as Styled from "./styles";
4+
import { useTranslation } from "react-i18next";
5+
6+
/**
7+
* Uses the same styles as the existing dialog, but with native HTML.
8+
* Eventually this component should fully replace dialog/Wrapper.
9+
*/
10+
export default function Modal({
11+
id,
12+
dialog,
13+
children,
14+
showCloseButton,
15+
maxWidth
16+
}) {
17+
const { t } = useTranslation();
18+
19+
const handleEsc = e => {
20+
if (e.key === "Escape") {
21+
// prevent also exiting full screen in FF
22+
e.stopPropagation();
23+
}
24+
};
25+
26+
const style = {
27+
...(maxWidth ? { maxWidth } : {})
28+
};
29+
30+
return (
31+
<Styled.Dialog
32+
id={id}
33+
ref={dialog.dialogRef}
34+
onKeyDown={handleEsc}
35+
{...(!dialog.open ? { inert: "" } : {})}
36+
>
37+
<Styled.Wrapper>
38+
<div className="dialog" style={style}>
39+
{showCloseButton ? (
40+
<button
41+
onClick={dialog.onCloseClick}
42+
className="dialog__close"
43+
aria-controls={id}
44+
>
45+
<IconComposer icon="close16" size={24} />
46+
<span className="screen-reader-text">{t("modals.close")}</span>
47+
</button>
48+
) : null}
49+
{children}
50+
</div>
51+
</Styled.Wrapper>
52+
</Styled.Dialog>
53+
);
54+
}
55+
56+
Modal.displayName = "Dialog.Modal";
57+
58+
Modal.propTypes = {
59+
id: PropTypes.string.isRequired,
60+
dialog: PropTypes.object.isRequired,
61+
children: PropTypes.node.isRequired,
62+
showCloseButton: PropTypes.bool,
63+
maxWidth: PropTypes.number
64+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from "./Modal";
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import styled from "@emotion/styled";
2+
import { transparentize, defaultTransitionProps } from "theme/styles/mixins";
3+
4+
export const Dialog = styled.dialog`
5+
background-color: transparent;
6+
margin: 0px;
7+
padding: 0px;
8+
border: 0px;
9+
max-inline-size: 100dvw;
10+
max-block-size: 100dvh;
11+
inline-size: 100%;
12+
block-size: 100%;
13+
overflow-y: scroll;
14+
transition: opacity ${defaultTransitionProps}, display ${defaultTransitionProps};
15+
opacity: 1;
16+
17+
@starting-style {
18+
opacity: 0;
19+
}
20+
21+
&::backdrop {
22+
.backend & {
23+
background-color: ${transparentize("neutralBlack", 0.35)};
24+
}
25+
26+
.browse & {
27+
background-color: ${transparentize("neutralWhite", 0.1)};
28+
}
29+
30+
.reader & {
31+
background-color: ${transparentize("neutralBlack", 0.7)};
32+
}
33+
}
34+
}
35+
`;
36+
37+
export const Wrapper = styled.div`
38+
position: relative;
39+
display: flex;
40+
flex-direction: column;
41+
justify-content: center;
42+
block-size: auto;
43+
min-block-size: 100%;
44+
padding-block: 30px;
45+
padding-inline: var(--container-padding-inline-responsive);
46+
`;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import Wrapper from "./Wrapper";
2+
import Modal from "./Modal";
23
import Confirm from "./Confirm";
34
import ResetPassword from "./ResetPassword";
45

56
export default {
67
Wrapper,
8+
Modal,
79
Confirm,
810
ResetPassword
911
};

0 commit comments

Comments
 (0)