Skip to content

Commit 75a768a

Browse files
authored
fix(Layout Shift Fix) - Resolved Layout Issues on DarkMode Toggle Button and Full-Screen Modal (accordproject#125)
* layout fix Signed-off-by: nitro56565 <nitro56565@gmail.com> * updated buttons inside preview output and added extra step for start tour Signed-off-by: nitro56565 <nitro56565@gmail.com> * modal buttons preview fixed using props Signed-off-by: nitro56565 <nitro56565@gmail.com> * fixed the layout Signed-off-by: nitro56565 <nitro56565@gmail.com> * start tour classname fixed Signed-off-by: nitro56565 <nitro56565@gmail.com> * test case fixed and start tour preview window fix Signed-off-by: nitro56565 <nitro56565@gmail.com> --------- Signed-off-by: nitro56565 <nitro56565@gmail.com>
1 parent 4abc864 commit 75a768a

File tree

9 files changed

+106
-30
lines changed

9 files changed

+106
-30
lines changed

package-lock.json

Lines changed: 32 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"core-js": "^3.37.1",
2929
"highlight.js": "^11.10.0",
3030
"immer": "^10.1.1",
31+
"jest-canvas-mock": "^2.5.2",
3132
"lz-string": "^1.5.0",
3233
"monaco-editor": "^0.50.0",
3334
"node-stdlib-browser": "^1.2.0",

src/AgreementHtml.tsx

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
import { LoadingOutlined } from "@ant-design/icons";
22
import { Spin } from "antd";
33
import useAppStore from "./store/store";
4+
import FullScreenModal from "./components/FullScreenModal";
45

5-
function AgreementHtml({ loading }: { loading: any }) {
6+
function AgreementHtml({
7+
loading,
8+
isModal,
9+
}: {
10+
loading: any;
11+
isModal?: boolean;
12+
}) {
613
const agreementHtml = useAppStore((state) => state.agreementHtml);
714
const backgroundColor = useAppStore((state) => state.backgroundColor);
815
const textColor = useAppStore((state) => state.textColor);
916

1017
return (
1118
<div
12-
className="column"
19+
className="column preview-component"
1320
style={{
1421
border: "1px solid #d9d9d9",
1522
borderRadius: "8px",
@@ -20,13 +27,30 @@ function AgreementHtml({ loading }: { loading: any }) {
2027
flexDirection: "column",
2128
}}
2229
>
23-
<div style={{ textAlign: "center", color: textColor }}>
24-
<h2>Preview Output</h2>
25-
<p>
26-
The result of merging the JSON data with the template. This is
27-
AgreementMark converted to HTML.
28-
</p>
30+
<div
31+
style={{
32+
width: "100%",
33+
display: "flex",
34+
textAlign: "center",
35+
color: textColor,
36+
}}
37+
>
38+
<h2
39+
style={{
40+
flexGrow: 1,
41+
textAlign: "center",
42+
paddingLeft: "34px",
43+
color: textColor,
44+
}}
45+
>
46+
Preview Output
47+
</h2>
48+
{!isModal && <FullScreenModal />}
2949
</div>
50+
<p style={{ textAlign: "center", color: textColor }}>
51+
The result of merging the JSON data with the template. This is
52+
AgreementMark converted to HTML.
53+
</p>
3054
{loading ? (
3155
<div
3256
style={{
@@ -49,7 +73,11 @@ function AgreementHtml({ loading }: { loading: any }) {
4973
<div
5074
className="agreement"
5175
dangerouslySetInnerHTML={{ __html: agreementHtml }}
52-
style={{ flex: 1, color: textColor, backgroundColor: backgroundColor }}
76+
style={{
77+
flex: 1,
78+
color: textColor,
79+
backgroundColor: backgroundColor,
80+
}}
5381
/>
5482
)}
5583
</div>

src/App.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ import TemplateMarkdown from "./editors/editorsContainer/TemplateMarkdown";
1212
import TemplateModel from "./editors/editorsContainer/TemplateModel";
1313
import useAppStore from "./store/store";
1414
import SampleDropdown from "./components/SampleDropdown";
15-
import FullScreenModal from "./components/FullScreenModal";
1615
import UseShare from "./components/UseShare";
1716
import LearnContent from "./components/Content";
18-
import ToggleDarkMode from "./components/ToggleDarkMode";
1917

2018
const { Content } = Layout;
2119
const { useBreakpoint } = Grid;
@@ -157,12 +155,8 @@ const App = () => {
157155
marginBottom: "10px",
158156
}}
159157
>
160-
<div style={{ display: "flex" }}>
161-
<ToggleDarkMode />
162-
<FullScreenModal />
163-
</div>
164158
</div>
165-
<AgreementHtml loading={loading} />
159+
<AgreementHtml loading={loading} isModal={false} />
166160
</Col>
167161
</Row>
168162
</div>

src/components/FullScreenModal.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ const FullScreenModal: React.FC = () => {
3131
}, [textColor, backgroundColor]);
3232

3333
return (
34-
<div style={{ textAlign: "right", display: "flex", alignItems: "center", justifyContent: "flex-end", width: "100%", color: textColor, }} className="preview-element">
34+
<div style={{ textAlign: "right", display: "flex", alignItems: "center", justifyContent: "flex-end", color: textColor, }} className="preview-element">
3535
<FullscreenOutlined
36-
style={{ fontSize: "24px", cursor: "pointer", marginRight: "10px" }}
36+
style={{ fontSize: "24px", cursor: "pointer", margin: "5px" }}
3737
onClick={() => setOpen(true)}
3838
/>
3939
<Modal
@@ -44,7 +44,7 @@ const FullScreenModal: React.FC = () => {
4444
onCancel={() => setOpen(false)}
4545
width={1000}
4646
>
47-
<AgreementHtml loading={false} />
47+
<AgreementHtml loading={false} isModal={true} />
4848
</Modal>
4949
</div>
5050
);

src/components/Navbar.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
BookOutlined,
1111
CaretDownFilled,
1212
} from "@ant-design/icons";
13+
import ToggleDarkMode from "./ToggleDarkMode";
1314

1415
const { useBreakpoint } = Grid;
1516

@@ -184,6 +185,9 @@ function Navbar({ scrollToExplore }: { scrollToExplore: any }) {
184185
height: "65px",
185186
}}
186187
>
188+
<div>
189+
<ToggleDarkMode />
190+
</div>
187191
{!isLearnPage && (
188192
<div
189193
style={{

src/components/Tour.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,22 @@ tour.addStep({
6363
id: "preview",
6464
text: "This section shows the live preview of your template. View the results of your edits and see how your template renders.",
6565
attachTo: {
66-
element: ".preview-element",
66+
element: ".preview-component",
67+
on: "bottom",
68+
},
69+
buttons: [
70+
{
71+
text: "Next",
72+
action: tour.next,
73+
},
74+
],
75+
});
76+
77+
tour.addStep({
78+
id: "darkmode",
79+
text: "Toggle between light and dark mode for a comfortable viewing experience. Switch themes to suit your preference while working on your template.",
80+
attachTo: {
81+
element: ".dark-mode-toggle",
6782
on: "bottom",
6883
},
6984
buttons: [

src/styles/components/ToggleDarkMode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import styled from "styled-components";
22

33
export const ToggleDarkModeContainer = styled.div`
44
.dark-mode-toggle {
5-
overflow: visible !important;
5+
overflow: hidden !important;
66
display: flex;
77
padding-left: 10px !important;
88
}

src/tests/components/Navbar.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import { render, screen } from "@testing-library/react";
22
import "@testing-library/jest-dom";
33
import Navbar from "../../components/Navbar";
44
import { MemoryRouter } from "react-router-dom";
5+
import { vi } from "vitest";
6+
7+
vi.mock("../../components/ToggleDarkMode", () => ({
8+
default: () => <div data-testid="toggle-dark-mode">Dark Mode Toggle</div>,
9+
}));
510

611
const renderNavbar = () => {
712
render(
@@ -40,4 +45,10 @@ describe("Navbar", () => {
4045
backgroundColor: "rgba(255, 255, 255, 0.1)",
4146
});
4247
});
48+
49+
it("renders Dark Mode Toggle button", () => {
50+
renderNavbar();
51+
const toggleDarkMode = screen.getByTestId("toggle-dark-mode");
52+
expect(toggleDarkMode).toBeInTheDocument();
53+
});
4354
});

0 commit comments

Comments
 (0)