diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-01-26 15:16:59 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-01-26 15:16:59 +0100 |
| commit | 5c3ea8b577e934237a5d03c477361763b167f57b (patch) | |
| tree | 02921d693f9a70bbeae3b911c8c54b296bacf2b4 /src | |
| parent | c18f2f8a9d189343db9740945196af46c903d2d9 (diff) | |
chore: add a Gallery component for MDX rendering
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/MDX/Gallery/Gallery.module.scss | 32 | ||||
| -rw-r--r-- | src/components/MDX/Gallery/Gallery.tsx | 22 | ||||
| -rw-r--r-- | src/components/MDX/index.tsx | 3 |
3 files changed, 56 insertions, 1 deletions
diff --git a/src/components/MDX/Gallery/Gallery.module.scss b/src/components/MDX/Gallery/Gallery.module.scss new file mode 100644 index 0000000..2654b59 --- /dev/null +++ b/src/components/MDX/Gallery/Gallery.module.scss @@ -0,0 +1,32 @@ +@use "@styles/abstracts/mixins" as mix; +@use "@styles/abstracts/placeholders"; + +.wrapper { + @extend %reset-list; + + display: grid; + grid-template-columns: minmax(0, 1fr); + gap: var(--spacing-sm); + max-width: 100%; + margin: var(--spacing-sm) 0; + + @for $i from 0 to 6 { + &--#{$i}-columns { + @include mix.media("screen") { + @include mix.dimensions("xs") { + grid-template-columns: repeat(2, minmax(0, 1fr)); + } + + @include mix.dimensions("sm") { + grid-template-columns: repeat(#{$i}, minmax(0, 1fr)); + } + } + } + } +} + +.item { + > figure { + margin: 0; + } +} diff --git a/src/components/MDX/Gallery/Gallery.tsx b/src/components/MDX/Gallery/Gallery.tsx new file mode 100644 index 0000000..561ec53 --- /dev/null +++ b/src/components/MDX/Gallery/Gallery.tsx @@ -0,0 +1,22 @@ +import { Children, ReactElement } from 'react'; +import styles from './Gallery.module.scss'; + +const Gallery = ({ + children, + columns = 2, +}: { + children: ReactElement; + columns: number; +}) => { + const columnClass = styles[`wrapper--${columns}-columns`]; + + return ( + <ul className={`${styles.wrapper} ${columnClass}`}> + {Children.map(children, (child) => { + return <li className={styles.item}>{child}</li>; + })} + </ul> + ); +}; + +export default Gallery; diff --git a/src/components/MDX/index.tsx b/src/components/MDX/index.tsx index acb885e..bc7aa35 100644 --- a/src/components/MDX/index.tsx +++ b/src/components/MDX/index.tsx @@ -1,5 +1,6 @@ import CodeBlock from './CodeBlock/CodeBlock'; +import Gallery from './Gallery/Gallery'; import Link from './Link/Link'; import ResponsiveImage from './ResponsiveImage/ResponsiveImage'; -export { CodeBlock, Link, ResponsiveImage }; +export { CodeBlock, Gallery, Link, ResponsiveImage }; |
