-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(editor): style script run output
- Loading branch information
1 parent
23ac319
commit 372d455
Showing
11 changed files
with
259 additions
and
25 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import React, { FC } from 'react'; | ||
|
||
import { styled } from 'goober'; | ||
|
||
import { FileMessage, MimeType } from '../../model/Run'; | ||
import { CoralIcon } from '../../coral/custom-elements'; | ||
|
||
const Elm = styled('div')` | ||
background: #666; | ||
color: white; | ||
padding: 1em; | ||
white-space: pre-wrap; | ||
word-break: break-all; | ||
border: 2px solid #0002; | ||
border-radius: 12px; | ||
display: grid; | ||
gap: 6px; | ||
grid-template-areas: 'icon name . download' 'icon type . download'; | ||
grid-template-columns: max-content max-content 1fr max-content; | ||
> coral-icon { | ||
grid-area: icon; | ||
position: relative; | ||
top: 0.3em; | ||
} | ||
> .name { | ||
grid-area: name; | ||
} | ||
> .type { | ||
grid-area: type; | ||
} | ||
> a { | ||
grid-area: download; | ||
} | ||
`; | ||
|
||
function iconFor(mimeType: MimeType): CoralIcon { | ||
const [kind, ...rest] = mimeType.split('/'); | ||
let [type] = rest; | ||
[type] = type!.split(';'); | ||
let icon: CoralIcon = 'file'; | ||
if (kind === 'application') { | ||
icon = 'fileCode'; | ||
if (type === 'pdf') { | ||
icon = 'filePDF'; | ||
} | ||
if (type === 'json') { | ||
icon = 'fileJson'; | ||
} | ||
if (type === 'xhtml+xml') { | ||
icon = 'fileHTML'; | ||
} | ||
if (['zip', 'vnd.rar', 'x-compressed', 'x-gzip-compressed'].includes(type!)) { | ||
icon = 'fileZip'; | ||
} | ||
} | ||
if (kind === 'text') { | ||
icon = 'fileTxt'; | ||
if (type === 'csv') { | ||
icon = 'fileCSV'; | ||
} | ||
if (type === 'html') { | ||
icon = 'fileHTML'; | ||
} | ||
} | ||
if (kind === 'image') { | ||
icon = 'image'; | ||
} | ||
|
||
return icon; | ||
} | ||
|
||
export const FileMessageOutput: FC<{ message: FileMessage }> = ({ message }) => { | ||
const icon = iconFor(message.mime); | ||
|
||
return ( | ||
<Elm> | ||
<coral-icon icon={icon} size="L" /> | ||
<span className="name">{message.name}</span> | ||
<small className="type">{message.mime}</small> | ||
<a href={URL.createObjectURL(message.blob!)} download={message.name}> | ||
<button type="button" is="coral-button" icon="download"> | ||
Download | ||
</button> | ||
</a> | ||
</Elm> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import React, { FC } from 'react'; | ||
|
||
import { styled } from 'goober'; | ||
import { useToggle } from '@uidotdev/usehooks'; | ||
|
||
import { LogMessage } from '../../model/Run'; | ||
|
||
const Elm = styled('div')` | ||
display: grid; | ||
grid-template-columns: min-content 1fr min-content; | ||
align-items: baseline; | ||
gap: 6px; | ||
> .level { | ||
text-transform: uppercase; | ||
display: inline-block; | ||
border: 1px solid #00000022; | ||
padding: 0 0.3em; | ||
border-radius: 8px; | ||
background: #ddebf7; | ||
&.debug { | ||
background: #5b9bd5; | ||
} | ||
&.info { | ||
background: #70ad47; | ||
} | ||
&.warn { | ||
background: #ffc000; | ||
} | ||
&.error { | ||
background: #ff3300; | ||
color: white; | ||
} | ||
} | ||
> .message { | ||
word-break: break-all; | ||
} | ||
> .ex-toggle { | ||
font-size: 1.4em; | ||
font-weight: bold; | ||
background: #ff3300; | ||
color: white; | ||
display: inline-block; | ||
border: 0; | ||
aspect-ratio: 1; | ||
border-radius: 50%; | ||
padding: 0 6px; | ||
text-align: center; | ||
} | ||
&:has(.exception) > .ex-toggle { | ||
color: #ff3300; | ||
background: white; | ||
} | ||
> .exception { | ||
grid-column: span 3; | ||
white-space: pre-wrap; | ||
word-break: break-all; | ||
font-family: monospace; | ||
} | ||
`; | ||
|
||
export const LogMessageOutput: FC<{ message: LogMessage }> = ({ message }) => { | ||
const [expanded, toggleExpanded] = useToggle(false); | ||
|
||
return ( | ||
<Elm> | ||
<span className={`level ${message.level}`}>{message.level}</span> | ||
<span className="message">{message.message}</span> | ||
{message.exception ? ( | ||
<button className="ex-toggle" onClick={() => toggleExpanded()}> | ||
!! | ||
</button> | ||
) : undefined} | ||
{expanded ? <div className="exception">{message.exception}</div> : undefined} | ||
</Elm> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
import React, { FC } from 'react'; | ||
|
||
import { Message } from '../../model/Run'; | ||
import { PrintMessageOutput } from './PrintMessageOutput'; | ||
import { FileMessageOutput } from './FileMessageOutput'; | ||
import { LogMessageOutput } from './LogMessageOutput'; | ||
|
||
export const MessageOutput: FC<{ message: Message }> = ({ message }) => { | ||
return <pre>{JSON.stringify(message)}</pre>; | ||
if (typeof message === 'string') { | ||
return <PrintMessageOutput message={message} />; | ||
} | ||
if (message.type === 'file') { | ||
return <FileMessageOutput message={message} />; | ||
} | ||
return <LogMessageOutput message={message} />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React, { FC } from 'react'; | ||
|
||
import { styled } from 'goober'; | ||
|
||
import { PrintMessage } from '../../model/Run'; | ||
|
||
const Elm = styled('div')` | ||
background: #ccc; | ||
padding: 0.4em; | ||
white-space: pre-wrap; | ||
word-break: break-all; | ||
border: 2px solid #0002; | ||
border-radius: 12px; | ||
`; | ||
|
||
export const PrintMessageOutput: FC<{ message: PrintMessage }> = ({ message }) => { | ||
return <Elm>{message}</Elm>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters