Skip to content

Commit 21ef9a4

Browse files
committed
feat: artifacts style
1 parent 7c1bc1f commit 21ef9a4

6 files changed

Lines changed: 58 additions & 25 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,5 @@ dev
4444

4545
*.key
4646
*.key.pub
47+
48+
masks.json
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.artifact {
2+
display: block;
3+
width: 100%;
4+
height: 100%;
5+
position: relative;
6+
}
7+
8+
.artifact-iframe {
9+
width: 100%;
10+
border: var(--border-in-light);
11+
border-radius: 6px;
12+
}

app/components/artifact.tsx

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { Modal, showToast } from "./ui-lib";
1313
import { copyToClipboard, downloadAs } from "../utils";
1414
import { Path, ApiPath, REPO_URL } from "@/app/constant";
1515
import { Loading } from "./home";
16+
import styles from "./artifact.module.scss";
1617

1718
export function HTMLPreview(props: {
1819
code: string;
@@ -61,17 +62,22 @@ export function HTMLPreview(props: {
6162
return props.code + script;
6263
}, [props.code]);
6364

65+
const handleOnLoad = () => {
66+
if (props?.onLoad) {
67+
props.onLoad(title);
68+
}
69+
};
70+
6471
return (
6572
<iframe
73+
className={styles["artifact-iframe"]}
6674
id={frameId.current}
6775
ref={ref}
68-
frameBorder={0}
6976
sandbox="allow-forms allow-modals allow-scripts"
70-
style={{ width: "100%", height }}
71-
// src={`data:text/html,${encodeURIComponent(srcDoc)}`}
77+
style={{ height }}
7278
srcDoc={srcDoc}
73-
onLoad={(e) => props?.onLoad && props?.onLoad(title)}
74-
></iframe>
79+
onLoad={handleOnLoad}
80+
/>
7581
);
7682
}
7783

@@ -186,14 +192,7 @@ export function Artifact() {
186192
}, [id]);
187193

188194
return (
189-
<div
190-
style={{
191-
display: "block",
192-
width: "100%",
193-
height: "100%",
194-
position: "relative",
195-
}}
196-
>
195+
<div className={styles.artifact}>
197196
<div
198197
style={{
199198
height: 36,

app/components/markdown.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ export function PreCode(props: { children: any }) {
105105
<Mermaid code={mermaidCode} key={mermaidCode} />
106106
)}
107107
{htmlCode.length > 0 && (
108-
<FullScreen className="no-dark html" right={60}>
108+
<FullScreen className="no-dark html" right={70}>
109109
<ArtifactShareButton
110-
style={{ position: "absolute", right: 10, top: 10 }}
110+
style={{ position: "absolute", right: 20, top: 10 }}
111111
getCode={() => htmlCode}
112112
/>
113113
<HTMLPreview

app/components/ui-lib.module.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@
292292
z-index: 999;
293293

294294
&-content {
295+
min-width: 300px;
295296
.list {
296297
max-height: 90vh;
297298
overflow-x: hidden;

app/components/ui-lib.tsx

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export function ListItem(props: {
5353
children?: JSX.Element | JSX.Element[];
5454
icon?: JSX.Element;
5555
className?: string;
56-
onClick?: () => void;
56+
onClick?: (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
5757
}) {
5858
return (
5959
<div
@@ -454,25 +454,45 @@ export function Selector<T>(props: {
454454
onClose?: () => void;
455455
multiple?: boolean;
456456
}) {
457+
const [selectedValues, setSelectedValues] = useState<T[]>(
458+
Array.isArray(props.defaultSelectedValue)
459+
? props.defaultSelectedValue
460+
: props.defaultSelectedValue !== undefined
461+
? [props.defaultSelectedValue]
462+
: [],
463+
);
464+
465+
const handleSelection = (
466+
e: React.MouseEvent<HTMLDivElement, MouseEvent>,
467+
value: T,
468+
) => {
469+
if (props.multiple) {
470+
e.stopPropagation();
471+
const newSelectedValues = selectedValues.includes(value)
472+
? selectedValues.filter((v) => v !== value)
473+
: [...selectedValues, value];
474+
setSelectedValues(newSelectedValues);
475+
props.onSelection?.(newSelectedValues);
476+
} else {
477+
setSelectedValues([value]);
478+
props.onSelection?.([value]);
479+
props.onClose?.();
480+
}
481+
};
482+
457483
return (
458484
<div className={styles["selector"]} onClick={() => props.onClose?.()}>
459485
<div className={styles["selector-content"]}>
460486
<List>
461487
{props.items.map((item, i) => {
462-
const selected = props.multiple
463-
? // @ts-ignore
464-
props.defaultSelectedValue?.includes(item.value)
465-
: props.defaultSelectedValue === item.value;
488+
const selected = selectedValues.includes(item.value);
466489
return (
467490
<ListItem
468491
className={styles["selector-item"]}
469492
key={i}
470493
title={item.title}
471494
subTitle={item.subTitle}
472-
onClick={() => {
473-
props.onSelection?.([item.value]);
474-
props.onClose?.();
475-
}}
495+
onClick={(e) => handleSelection(e, item.value)}
476496
>
477497
{selected ? (
478498
<div
@@ -494,7 +514,6 @@ export function Selector<T>(props: {
494514
</div>
495515
);
496516
}
497-
498517
export function FullScreen(props: any) {
499518
const { children, right = 10, top = 10, ...rest } = props;
500519
const ref = useRef<HTMLDivElement>();

0 commit comments

Comments
 (0)