Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add additional aspect ratios for do dont #1216

Merged
merged 2 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 79 additions & 10 deletions packages/example/src/pages/components/DoDontExample.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ and `<Column>` components to align them to the grid at the correct size.

<Title>Text</Title>

<DoDontExample type="dont" aspectRatio="1:1" color="dark" captionTitle="Caption title" caption="Caption" text="This is some text" />
<DoDontExample
type="dont"
aspectRatio="1:1"
color="dark"
captionTitle="Caption title"
caption="Caption"
text="This is some text"
/>

</Column>
</Row>
<Row>
Expand All @@ -43,6 +51,55 @@ and `<Column>` components to align them to the grid at the correct size.
</Column>
</Row>

<Title>Aspect ratios</Title>

<Row>

<Column colMd={4} colLg={4}>

<DoDontExample aspectRatio="4:3" text="4:3" />

</Column>
<Column colMd={4} colLg={4}>

<DoDontExample aspectRatio="16:9" text="16:9" />

</Column>
<Column colMd={4} colLg={4}>

<DoDontExample aspectRatio="2:1" text="2:1" />

</Column>
</Row>

<Row>
<Column colMd={4} colLg={4}>

<DoDontExample aspectRatio="9:16" text="9:16" />

</Column>

<Column colMd={4} colLg={4}>

<DoDontExample aspectRatio="1:2" text="1:2" />

</Column>

<Column colMd={4} colLg={4}>

<DoDontExample aspectRatio="3:4" text="3:4" />

</Column>
</Row>

<Row>
<Column colMd={4} colLg={4}>

<DoDontExample aspectRatio="1:1" text="1:1" />

</Column>
</Row>

## Code

<Title>Image</Title>
Expand Down Expand Up @@ -76,14 +133,26 @@ and `<Column>` components to align them to the grid at the correct size.
</DoDontExample>
```

<Title>Aspect ratios</Title>

```mdx path=components/DoDontExample/DoDontExample.js src=https://github.com/carbon-design-system/gatsby-theme-carbon/tree/main/packages/gatsby-theme-carbon/src/components/DoDontExample
<DoDontExample aspectRatio="4:3" text="4:3" />
<DoDontExample aspectRatio="16:9" text="16:9" />
<DoDontExample aspectRatio="2:1" text="2:1" />
<DoDontExample aspectRatio="9:16" text="9:16" />
<DoDontExample aspectRatio="1:2" text="1:2" />
<DoDontExample aspectRatio="3:4" text="3:4" />
<DoDontExample aspectRatio="1:1" text="1:1" />
```

### Props

| property | propType | required | default | description |
| ------------ | -------- | -------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| children | node | | | child node, expects a markdown image or `<Video>` component |
| text | string | | | text to display inside the component instead of an image or video |
| caption | string | | | caption |
| captionTitle | string | | | caption title |
| type | string | | dont | set to `do` to show green check, otherwise shows pink X |
| color | string | | light | set to `dark` for dark background card |
| aspectRatio | string | | | set to `1:1` to force square example <br/>_(We welcome [contributions](https://github.com/carbon-design-system/gatsby-theme-carbon/tree/main/packages/gatsby-theme-carbon/src/components/DoDontExample) to add additional aspect ratio options)_ |
| property | propType | required | default | description |
| ------------ | -------- | -------- | ------- | ----------------------------------------------------------------- |
| children | node | | | child node, expects a markdown image or `<Video>` component |
| text | string | | | text to display inside the component instead of an image or video |
| caption | string | | | caption |
| captionTitle | string | | | caption title |
| type | string | | dont | set to `do` to show green check, otherwise shows pink X |
| color | string | | light | set to `dark` for dark background card |
| aspectRatio | string | | | `1:1`,`1:2`,`2:1`,`3:4`,`4:3`,`16:9`,`9:16` |
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,25 @@ export default class DoDontExample extends React.Component {
};

render() {
const {
children,
caption,
captionTitle,
text,
aspectRatio,
color,
type,
} = this.props;
const { children, caption, captionTitle, text, aspectRatio, color, type } =
this.props;

const wrapperClassNames = cx(`${prefix}--example`, {
[`${prefix}--example--square`]: aspectRatio === '1:1',
[`${prefix}--example--ratio`]:
aspectRatio === '1:1' ||
aspectRatio === '2:1' ||
aspectRatio === '1:2' ||
aspectRatio === '4:3' ||
aspectRatio === '3:4' ||
aspectRatio === '9:16' ||
aspectRatio === '16:9',
[`${prefix}--example--1x1`]: aspectRatio === '1:1',
[`${prefix}--example--2x1`]: aspectRatio === '2:1',
[`${prefix}--example--1x2`]: aspectRatio === '1:2',
[`${prefix}--example--4x3`]: aspectRatio === '4:3',
[`${prefix}--example--3x4`]: aspectRatio === '3:4',
[`${prefix}--example--9x16`]: aspectRatio === '9:16',
[`${prefix}--example--16x9`]: aspectRatio === '16:9',
[`${prefix}--example--correct`]: type === 'do',
[`${prefix}--example--incorrect`]: type !== 'do',
[`${prefix}--example--dark`]: color === 'dark',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,37 @@
position: relative;
}

.#{$prefix}--example--square .#{$prefix}--example-card {
// Aspect Ratio

.#{$prefix}--example--1x1 .#{$prefix}--example-card {
padding-top: 100%;
}

.#{$prefix}--example--square .#{$prefix}--example-card__content {
.#{$prefix}--example--4x3 .#{$prefix}--example-card {
padding-top: 75%;
}

.#{$prefix}--example--3x4 .#{$prefix}--example-card {
padding-top: 133.3333333333%;
}

.#{$prefix}--example--2x1 .#{$prefix}--example-card {
padding-top: 50%;
}

.#{$prefix}--example--1x2 .#{$prefix}--example-card {
padding-top: 150%;
}

.#{$prefix}--example--9x16 .#{$prefix}--example-card {
padding-top: 177.7777777778%;
}

.#{$prefix}--example--16x9 .#{$prefix}--example-card {
padding-top: 56.25%;
}

.#{$prefix}--example--ratio .#{$prefix}--example-card__content {
position: absolute;
top: 0;
left: 0;
Expand Down