Skip to content

Commit c27ef6f

Browse files
committed
feat: artifacts style
1 parent 51e8f04 commit c27ef6f

File tree

4 files changed

+52
-30
lines changed

4 files changed

+52
-30
lines changed

app/components/artifact.module.scss

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
11
.artifact {
2-
display: block;
2+
display: flex;
33
width: 100%;
44
height: 100%;
5-
position: relative;
5+
flex-direction: column;
6+
&-header {
7+
display: flex;
8+
align-items: center;
9+
height: 36px;
10+
padding: 20px;
11+
background: var(--second);
12+
}
13+
&-title {
14+
flex: 1;
15+
text-align: center;
16+
font-weight: bold;
17+
font-size: 24px;
18+
}
19+
&-content {
20+
flex-grow: 1;
21+
padding: 0 20px 20px 20px;
22+
background-color: var(--second);
23+
}
624
}
725

826
.artifact-iframe {

app/components/artifact.tsx

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import styles from "./artifact.module.scss";
1818
export function HTMLPreview(props: {
1919
code: string;
2020
autoHeight?: boolean;
21-
height?: number;
21+
height?: number | string;
2222
onLoad?: (title?: string) => void;
2323
}) {
2424
const ref = useRef<HTMLIFrameElement>(null);
@@ -185,7 +185,6 @@ export function Artifact() {
185185
const [code, setCode] = useState("");
186186
const [loading, setLoading] = useState(true);
187187
const [fileName, setFileName] = useState("");
188-
const { height } = useWindowSize();
189188

190189
useEffect(() => {
191190
if (id) {
@@ -205,33 +204,28 @@ export function Artifact() {
205204
}, [id]);
206205

207206
return (
208-
<div className={styles.artifact}>
209-
<div
210-
style={{
211-
height: 36,
212-
display: "flex",
213-
alignItems: "center",
214-
padding: 12,
215-
}}
216-
>
207+
<div className={styles["artifact"]}>
208+
<div className={styles["artifact-header"]}>
217209
<a href={REPO_URL} target="_blank" rel="noopener noreferrer">
218210
<IconButton bordered icon={<GithubIcon />} shadow />
219211
</a>
220-
<div style={{ flex: 1, textAlign: "center" }}>NextChat Artifact</div>
212+
<div className={styles["artifact-title"]}>NextChat Artifact</div>
221213
<ArtifactShareButton id={id} getCode={() => code} fileName={fileName} />
222214
</div>
223-
{loading && <Loading />}
224-
{code && (
225-
<HTMLPreview
226-
code={code}
227-
autoHeight={false}
228-
height={height - 36}
229-
onLoad={(title) => {
230-
setFileName(title as string);
231-
setLoading(false);
232-
}}
233-
/>
234-
)}
215+
<div className={styles["artifact-content"]}>
216+
{loading && <Loading />}
217+
{code && (
218+
<HTMLPreview
219+
code={code}
220+
autoHeight={false}
221+
height={"100%"}
222+
onLoad={(title) => {
223+
setFileName(title as string);
224+
setLoading(false);
225+
}}
226+
/>
227+
)}
228+
</div>
235229
</div>
236230
);
237231
}

app/components/chat.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,12 +641,13 @@ export function ChatActions(props: {
641641
]}
642642
onClose={() => setShowPluginSelector(false)}
643643
onSelection={(s) => {
644-
if (s.length === 0) return;
645644
const plugin = s[0];
646645
chatStore.updateCurrentSession((session) => {
647646
session.mask.plugin = s;
648647
});
649-
showToast(plugin);
648+
if (plugin) {
649+
showToast(plugin);
650+
}
650651
}}
651652
/>
652653
)}

app/components/markdown.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import React from "react";
1414
import { useDebouncedCallback } from "use-debounce";
1515
import { showImageModal, FullScreen } from "./ui-lib";
1616
import { ArtifactShareButton, HTMLPreview } from "./artifact";
17-
17+
import { Plugin } from "../constant";
18+
import { useChatStore } from "../store";
1819
export function Mermaid(props: { code: string }) {
1920
const ref = useRef<HTMLDivElement>(null);
2021
const [hasError, setHasError] = useState(false);
@@ -67,6 +68,9 @@ export function PreCode(props: { children: any }) {
6768
const [mermaidCode, setMermaidCode] = useState("");
6869
const [htmlCode, setHtmlCode] = useState("");
6970
const { height } = useWindowSize();
71+
const chatStore = useChatStore();
72+
const session = chatStore.currentSession();
73+
const plugins = session.mask?.plugin;
7074

7175
const renderArtifacts = useDebouncedCallback(() => {
7276
if (!ref.current) return;
@@ -87,6 +91,11 @@ export function PreCode(props: { children: any }) {
8791
// eslint-disable-next-line react-hooks/exhaustive-deps
8892
}, [refText]);
8993

94+
const enableArtifacts = useMemo(
95+
() => plugins?.includes(Plugin.Artifact),
96+
[plugins],
97+
);
98+
9099
return (
91100
<>
92101
<pre ref={ref}>
@@ -104,7 +113,7 @@ export function PreCode(props: { children: any }) {
104113
{mermaidCode.length > 0 && (
105114
<Mermaid code={mermaidCode} key={mermaidCode} />
106115
)}
107-
{htmlCode.length > 0 && (
116+
{htmlCode.length > 0 && enableArtifacts && (
108117
<FullScreen className="no-dark html" right={70}>
109118
<ArtifactShareButton
110119
style={{ position: "absolute", right: 20, top: 10 }}

0 commit comments

Comments
 (0)