-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use GDS components for
List
, Link
, and Code
+ misc. fixes and i…
…mprovements (#453) * Use GDS components for `List`, `Link`, and `Code` + misc. fixes and improvements * Use released versions of `@edgeandnode/gds` and `@edgeandnode/organisms` * Comment out `NPSForm` for now * Remove outdated comment
- Loading branch information
Showing
25 changed files
with
1,010 additions
and
1,029 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,49 @@ | ||
import Highlight, { defaultProps, Language, PrismTheme } from 'prism-react-renderer' | ||
import { HTMLAttributes } from 'react' | ||
import { HTMLAttributes, ReactNode } from 'react' | ||
|
||
import { BorderRadius, FontFamily, Spacing } from '@edgeandnode/gds' | ||
import { Code, Spacing } from '@edgeandnode/gds' | ||
|
||
export type CodeBlockProps = HTMLAttributes<HTMLPreElement> | ||
export type CodeInlineProps = HTMLAttributes<HTMLElement> | ||
|
||
import theme from 'prism-react-renderer/themes/duotoneDark' | ||
export type CodeBlockProps = { | ||
children?: | ||
| ReactNode | ||
| { | ||
props: { | ||
children: string | ||
className?: string | ||
} | ||
} | ||
} & Omit<HTMLAttributes<HTMLPreElement>, 'children'> | ||
|
||
export const CodeBlock = ({ children, ...props }: CodeBlockProps) => { | ||
const data = ( | ||
children as { | ||
props: { | ||
children: string | ||
className?: string | ||
} | ||
} | ||
).props | ||
const code = data.children.trim() | ||
let language = data.className?.substring('language-'.length) | ||
const code = | ||
children && typeof children === 'object' && 'props' in children | ||
? children.props.children.trim() | ||
: (children as string) | ||
let language = | ||
children && typeof children === 'object' && 'props' in children | ||
? children.props.className?.substring('language-'.length) | ||
: null | ||
|
||
if (!language || language === 'sh') { | ||
language = 'bash' | ||
} | ||
|
||
return ( | ||
<div sx={{ my: Spacing['24px'] }}> | ||
<Highlight {...defaultProps} code={code} language={language as Language} theme={theme}> | ||
{({ className, tokens, getLineProps, getTokenProps }) => ( | ||
<pre | ||
className={className} | ||
sx={{ | ||
overflowX: 'auto', | ||
p: Spacing['16px'], | ||
borderRadius: BorderRadius.M, | ||
border: 'White4', | ||
bg: 'White4', | ||
fontFamily: FontFamily.MONOSPACE, | ||
fontSize: '16px', | ||
lineHeight: '24px', | ||
}} | ||
{...props} | ||
> | ||
{tokens.map((line, i) => ( | ||
// eslint-disable-next-line react/jsx-key | ||
<div {...getLineProps({ line, key: i })}> | ||
{line.map((token, key) => ( | ||
// eslint-disable-next-line react/jsx-key | ||
<span {...getTokenProps({ token, key })} /> | ||
))} | ||
</div> | ||
))} | ||
</pre> | ||
)} | ||
</Highlight> | ||
</div> | ||
) | ||
} | ||
|
||
export const CodeInline = ({ children, ...props }: CodeInlineProps) => { | ||
return ( | ||
<code | ||
<Code.Block | ||
language={language} | ||
sx={{ | ||
px: Spacing['4px'], | ||
py: Spacing['2px'], | ||
borderRadius: BorderRadius.S, | ||
border: 'White4', | ||
bg: 'White4', | ||
fontFamily: FontFamily.MONOSPACE, | ||
fontSize: '0.75em', | ||
my: Spacing['24px'], | ||
'/* emotion-disable-server-rendering-unsafe-selector-warning-please-do-not-use-this-the-warning-exists-for-a-reason */ &:nth-child(1 of :not(style))': | ||
{ mt: 0 }, | ||
'/* emotion-disable-server-rendering-unsafe-selector-warning-please-do-not-use-this-the-warning-exists-for-a-reason */ &:nth-last-child(1 of :not(style))': | ||
{ mb: 0 }, | ||
}} | ||
{...props} | ||
> | ||
{children} | ||
</code> | ||
{code} | ||
</Code.Block> | ||
) | ||
} | ||
|
||
export const CodeInline = ({ children, ...props }: HTMLAttributes<HTMLElement>) => { | ||
return <Code.Inline {...props}>{children as string}</Code.Inline> | ||
} |
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
Oops, something went wrong.