Skip to content

Commit

Permalink
Merge pull request #214 from primer/image-container-component
Browse files Browse the repository at this point in the history
Create ImageContainer component
  • Loading branch information
colebemis committed Jan 12, 2021
2 parents d814f7d + b07f669 commit a5db911
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/hungry-scissors-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/gatsby-theme-doctocat": minor
---

Add ImageContainer component
22 changes: 22 additions & 0 deletions docs/content/components/image-container.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
title: ImageContainer
status: New
source: https://github.com/primer/doctocat/blob/master/theme/src/components/image-container.js
---

Use the `ImageContainer` component to contain images in documentation pages.

## Usage

`ImageContainer` is a [shortcode](https://mdxjs.com/blog/shortcodes), meaning it's globally available in all `.md` and `.mdx` files. So you can use the `ImageContainer` component in any `.md` or `.mdx` file without importing it.

```jsx live
<ImageContainer>
<img
width="290"
src="https://user-images.githubusercontent.com/4608155/104243682-cc166c00-5415-11eb-889b-9abe9997481a.png"
alt="Star and Unstar buttons"
/>
</ImageContainer>
<Caption>Star and Unstar buttons</Caption>
```
7 changes: 4 additions & 3 deletions docs/content/usage/using-images.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import DemoImage from '../images/demo-image.png'

4. Then use that image name as the `src` value in an img tag:


```
<img src={DemoImage} alt="a description of your image"/>
````
<ImageContainer>
<img src={DemoImage} alt="a description of your image"/>
</ImageContainer>
```

Make sure to use the `alt` attribute to describe your image for assistive technology, or use the [`Caption` component](/components/caption)

Expand Down
2 changes: 2 additions & 0 deletions docs/src/@primer/gatsby-theme-doctocat/nav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
url: /components/caption
- title: Do/Don't
url: /components/do-dont
- title: ImageContainer
url: /components/image-container
- title: Note
url: /components/note
- title: Contributing
Expand Down
1 change: 1 addition & 0 deletions theme/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export {default as HeroLayout} from './src/components/hero-layout'
export {default as Sidebar} from './src/components/sidebar'
export {default as SourceLink} from './src/components/source-link'
export {default as StatusLabel} from './src/components/status-label'
export {default as ImageContainer} from './src/components/image-container'
14 changes: 14 additions & 0 deletions theme/src/components/image-container.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {BorderBox, Flex} from '@primer/components'
import React from 'react'

function ImageContainer({children}) {
return (
<BorderBox p={6} bg="gray.1">
<Flex justifyContent="center" sx={{img: {maxWidth: '100%'}}}>
{children}
</Flex>
</BorderBox>
)
}

export default ImageContainer
2 changes: 2 additions & 0 deletions theme/src/components/wrap-root-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {Do, DoDontContainer, Dont} from './do-dont'
import {H1, H2, H3, H4, H5, H6} from './heading'
import HorizontalRule from './horizontal-rule'
import Image from './image'
import ImageContainer from './image-container'
import InlineCode from './inline-code'
import List from './list'
import Note from './note'
Expand Down Expand Up @@ -42,6 +43,7 @@ const components = {
Dont,
DoDontContainer,
Caption,
ImageContainer,
}

function wrapRootElement({element}) {
Expand Down

2 comments on commit a5db911

@vercel
Copy link

@vercel vercel bot commented on a5db911 Jan 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on a5db911 Jan 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.