-
-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(footer): add footer markdown render
- Loading branch information
1 parent
84ba4a8
commit ff572f6
Showing
49 changed files
with
234 additions
and
178 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { marked } from 'marked' | ||
import { forwardRef } from 'react' | ||
import { Sx, TypographyStylesProvider, createStyles } from '@mantine/core' | ||
import { useIsMobile } from '@Utils/ThemeOverride' | ||
|
||
interface MarkdownProps extends React.ComponentPropsWithoutRef<'div'> { | ||
source: string | ||
sx?: Sx | (Sx | undefined)[] | ||
} | ||
|
||
const useFooterStyles = createStyles((theme) => { | ||
const sc = (dark: any, light: any) => (theme.colorScheme === 'dark' ? dark : light) | ||
const cs = theme.colors | ||
|
||
return { | ||
root: { | ||
overflowX: 'auto', | ||
textAlign: 'center', | ||
fontSize: theme.fontSizes.sm, | ||
color: theme.fn.dimmed(), | ||
|
||
'& p': { | ||
wordBreak: 'break-word', | ||
wordWrap: 'break-word', | ||
overflow: 'hidden', | ||
marginBottom: theme.spacing.xs, | ||
}, | ||
|
||
'& :not(pre) > code': { | ||
color: theme.fn.dimmed(), | ||
whiteSpace: 'normal', | ||
fontSize: '0.95em', | ||
backgroundColor: 'transparent', | ||
padding: `1px calc(${theme.spacing.xs} / 2)`, | ||
border: 'none', | ||
}, | ||
|
||
'& strong': { | ||
color: cs.brand[sc(6, 7)], | ||
}, | ||
|
||
'& a': { | ||
color: theme.fn.dimmed(), | ||
textDecoration: 'none', | ||
transition: 'all 0.2s ease-in-out', | ||
}, | ||
|
||
'& a:hover': { | ||
textDecoration: 'none', | ||
}, | ||
}, | ||
} | ||
}) | ||
|
||
export const FooterRender = forwardRef<HTMLDivElement, MarkdownProps>((props, ref) => { | ||
const { classes, cx } = useFooterStyles() | ||
const { source, ...others } = props | ||
|
||
const isMobile = useIsMobile() | ||
|
||
// replace `<mbr/>` with `<br />` for mobile | ||
const mdSource = source.replace(/<mbr\/>/g, isMobile ? '<br />' : '') | ||
|
||
return ( | ||
<TypographyStylesProvider | ||
ref={ref} | ||
className={others.className ? cx(classes.root, others.className) : classes.root} | ||
{...others} | ||
> | ||
<div | ||
dangerouslySetInnerHTML={{ | ||
__html: marked(mdSource, { | ||
silent: true, | ||
}), | ||
}} | ||
/> | ||
</TypographyStylesProvider> | ||
) | ||
}) | ||
|
||
export default FooterRender |
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
Oops, something went wrong.