-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Create Preformatted component to render JSON (#505)
* fix close handler for email device modal * create and reuse preformatted component * optional title * use component in another place
Showing
8 changed files
with
53 additions
and
26 deletions.
There are no files selected for viewing
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
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,31 @@ | ||
import { useMemo } from 'react' | ||
|
||
import { Any } from '..' | ||
import { Text } from '../text' | ||
|
||
export type PreformattedProps = { title?: string; content: Any } | ||
|
||
export function Preformatted({ title, content }: PreformattedProps) { | ||
const memoContent = useMemo(() => JSON.stringify(content, null, 2), [content]) | ||
|
||
const formatted = ( | ||
<div className="rounded-sm bg-background-surface p-4"> | ||
<pre className="text-xs text-foreground-subtle">{memoContent}</pre> | ||
</div> | ||
) | ||
|
||
if (!title) { | ||
return formatted | ||
} | ||
|
||
return ( | ||
<div className="flex flex-col pb-0"> | ||
<div className="flex h-10 items-center bg-background-surface px-4"> | ||
<Text size="sm" className="font-medium"> | ||
{title} | ||
</Text> | ||
</div> | ||
{formatted} | ||
</div> | ||
) | ||
} |
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 @@ | ||
export { Preformatted, type PreformattedProps } from './Preformatted' |