-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ArtDirection component (#294)
* feat: add ArtDirection component * docs: clarify two image scenario
- Loading branch information
Showing
10 changed files
with
75 additions
and
1 deletion.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions
33
packages/example/src/pages/components/ArtDirection/index.mdx
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,33 @@ | ||
--- | ||
title: Art Direction | ||
--- | ||
|
||
<PageDescription> | ||
|
||
On the web, [art direction](https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images#Art_direction) refers to changing the image rendered at different display sizes. The `ArtDirection` component allows you to to provide multiple images achieve this goal. | ||
|
||
</PageDescription> | ||
|
||
## Example | ||
|
||
<ArtDirection> | ||
|
||
![Mobile image](./mobile.png) | ||
![Tablet image](./tablet.png) | ||
![Desktop image](./desktop.png) | ||
|
||
</ArtDirection> | ||
|
||
## Code | ||
|
||
You can place up to three images inside of the ArtDirection component. The first will be used for mobile, the second for tablet, and the third for desktop. If only two images are provided, the second image will be used for both tablet and desktop. | ||
|
||
```markdown path=components/ArtDirection.js src=https://github.com/carbon-design-system/gatsby-theme-carbon/tree/master/packages/gatsby-theme-carbon/src/components/ArtDirection | ||
<ArtDirection> | ||
|
||
![Mobile image](./mobile.png) | ||
![Tablet image](./tablet.png) | ||
![Desktop image](./desktop.png) | ||
|
||
</ArtDirection> | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
27 changes: 27 additions & 0 deletions
27
packages/gatsby-theme-carbon/src/components/ArtDirection.js
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,27 @@ | ||
import React from 'react'; | ||
import useMedia from 'use-media'; | ||
import { breakpoints } from '@carbon/elements'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const ArtDirection = ({ children }) => { | ||
const isMobile = useMedia({ maxWidth: breakpoints.md.width }); | ||
const isTablet = useMedia({ maxWidth: breakpoints.lg.width }); | ||
|
||
const childrenArray = React.Children.toArray(children); | ||
|
||
if (isMobile || !childrenArray[1]) { | ||
return childrenArray[0]; | ||
} | ||
|
||
if (isTablet || !childrenArray[2]) { | ||
return childrenArray[1]; | ||
} | ||
|
||
return childrenArray[2]; | ||
}; | ||
|
||
ArtDirection.propTypes = { | ||
children: PropTypes.arrayOf(PropTypes.element).isRequired, | ||
}; | ||
|
||
export default ArtDirection; |
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
78171d5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully aliased the URL https://gatsby-theme-carbon-5nsoqvmmd.now.sh to the following aliases: