-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add admonitions feature to blog and docs (#3371)
- Loading branch information
Showing
4 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...ns/gatsby-theme-iterative-docs/src/components/Documentation/Markdown/Admonition/index.tsx
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,49 @@ | ||
import React from 'react' | ||
import cn from 'classnames' | ||
import * as styles from './styles.module.css' | ||
|
||
const icons = { | ||
tip: '💡', | ||
info: 'ℹ️', | ||
warn: '⚠️', | ||
fire: '🔥', | ||
exclamation: '❗', | ||
lady_beetle: '🐞', | ||
bug: '🐛' | ||
} | ||
const genericTitles = { | ||
info: 'Info', | ||
tip: 'Tip', | ||
warn: 'Warning' | ||
} | ||
const defaultType = 'info' | ||
|
||
const Admonition: React.FC<{ | ||
title?: string | ||
type?: 'info' | 'tip' | 'warn' | ||
icon?: | ||
| 'tip' | ||
| 'info' | ||
| 'warn' | ||
| 'fire' | ||
| 'exclamation' | ||
| 'lady_beetle' | ||
| 'bug' | ||
}> = ({ title, type = defaultType, children, icon = type }) => { | ||
const setType = genericTitles[type] ? type : defaultType | ||
const iconContent = icons[icon] || '' | ||
|
||
return ( | ||
<div | ||
className={cn(styles.admonition, styles[setType])} | ||
style={{ '--icon': `"${iconContent}"` } as React.CSSProperties} | ||
> | ||
<p className={cn(styles.title, !iconContent && styles.noIcon)}> | ||
{title || genericTitles[setType]} | ||
</p> | ||
<div className={styles.content}>{children}</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default Admonition |
44 changes: 44 additions & 0 deletions
44
...y-theme-iterative-docs/src/components/Documentation/Markdown/Admonition/styles.module.css
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,44 @@ | ||
.admonition { | ||
padding: 10px; | ||
border-left-style: solid; | ||
margin-bottom: 10px; | ||
border-radius: 10px; | ||
border-left-width: 10px; | ||
|
||
&.warn { | ||
border-color: var(--color-orange); | ||
background-color: rgb(227 112 70 / 20%); | ||
} | ||
|
||
&.tip { | ||
border-color: var(--color-azure); | ||
background-color: rgb(19 173 199 / 20%); | ||
} | ||
|
||
&.info { | ||
border-color: var(--color-purple); | ||
background-color: rgb(148 93 214 / 20%); | ||
} | ||
|
||
.title { | ||
font-weight: 500; | ||
margin: 0; | ||
} | ||
|
||
.title::before { | ||
margin-right: 5px; | ||
content: var(--icon); | ||
} | ||
|
||
.title.noIcon::before { | ||
margin-right: 0; | ||
} | ||
|
||
.content { | ||
padding: 10px 0 0; | ||
} | ||
|
||
.content *:last-child { | ||
margin-bottom: 0; | ||
} | ||
} |
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