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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃摉 Document media query attributes #32789

Merged
merged 7 commits into from
Feb 23, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 1 addition & 14 deletions extensions/amp-base-carousel/0.1/amp-base-carousel.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,7 @@ arrow buttons.
### Media Queries

The attributes for `<amp-base-carousel>` can be configured to use different
options based on a media query. You can also use a value without any media
queries. The format looks like:

```html
<amp-base-carousel
attr-name="(min-width: 1000px) valueOne, (min-width: 600px) valueTwo, defaultValue"
></amp-base-carousel>
```

The media queries are evaluated from left to right, with the first matching
media query being used. A default value (without a media query) is required. In
this case, if the page has a screen width of 1000px or more, `valueOne` is used.
If the width is between 999px and 600px, `valueTwo` is used. When it is 599px or
smaller, `defaultValue` is used.
options based on a [media query](./../../../spec/amp-html-responsive-attributes.md).

### Configuration Options

Expand Down
15 changes: 1 addition & 14 deletions extensions/amp-base-carousel/amp-base-carousel.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,20 +247,7 @@ addition, when changing `visible-slides`, you likely want to change
### Media Queries

The attributes for `<amp-base-carousel>` can be configured to use different
options based on a media query. You can also use a value without any media
queries. The format looks like:

```html
<amp-base-carousel
attr-name="(min-width: 1000px) valueOne, (min-width: 600px) valueTwo, defaultValue"
></amp-base-carousel>
```

The media queries are evaluated from left to right, with the first matching
media query being used. A default value (without a media query) is required. In
this case, if the page has a screen width of 1000px or more, `valueOne` is used.
If the width is between 999px and 600px, `valueTwo` is used. When it is 599px or
smaller, `defaultValue` is used.
options based on a [media query](./../../spec/amp-html-responsive-attributes.md).
Copy link
Contributor

Choose a reason for hiding this comment

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

Do all attributes allow media queries in this component and all others? Or should we come up with some sort of flag per-attribute. E.g. "visible-count (media allowed)"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All the ones that are eligible currently are that way for all of their attributes. Hence there is this one section which says so at the top of the ## Attributes section. It may not be this way going forward for new components that adopt this, but that pattern you recommended is a good one in that case.


### Configuration Options

Expand Down
7 changes: 6 additions & 1 deletion extensions/amp-inline-gallery/0.1/amp-inline-gallery.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ The `<amp-inline-gallery-pagination>` component determines how a pagination idic

The pagination indicator renders as dots when there are eight or fewer slides in the `amp-base-carousel`. For nine or more slides, the pagination indicator renders the current slide number and total number of slides, aligned to the right.

The pagination indicator location defaults to underneath the carousel. Adding the inset attribute to the `<amp-inline-gallery-pagination>` tag will overlay the pagination indicator on the carousel. To use different styles for different screen sizes, use the media attribute:
The pagination indicator location defaults to underneath the carousel. Adding the inset attribute to the `<amp-inline-gallery-pagination>` tag will overlay the pagination indicator on the carousel. To use different styles for different screen sizes, use the [media attribute](./../../../spec/amp-html-responsive-attributes.md):

```html
<amp-inline-gallery layout="container">
Expand Down Expand Up @@ -237,6 +237,11 @@ The example below demonstrates a gallery with thumbnails visible at larger resol

#### `amp-inline-gallery-thumbnails` attributes

##### Media Queries

The attributes for `<amp-inline-gallery-thumbnails>` can be configured to use different
options based on a [media query](./../../../spec/amp-html-responsive-attributes.md).

##### `aspect-ratio-height` (optional)

Specifies the aspect ratio when used with `aspect-ratio-width`. The aspect radio defaults to match the slides in `<amp-base-carousel>`.
Expand Down
7 changes: 6 additions & 1 deletion extensions/amp-inline-gallery/amp-inline-gallery.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ The `<amp-inline-gallery-pagination>` component determines how a pagination idic

The pagination indicator renders as dots when there are eight or fewer slides in the `amp-base-carousel`. For nine or more slides, the pagination indicator renders the current slide number and total number of slides, aligned to the right.

The pagination indicator location defaults to underneath the carousel. Adding the inset attribute to the `<amp-inline-gallery-pagination>` tag will overlay the pagination indicator on the carousel. To use different styles for different screen sizes, use the media attribute:
The pagination indicator location defaults to underneath the carousel. Adding the inset attribute to the `<amp-inline-gallery-pagination>` tag will overlay the pagination indicator on the carousel. To use different styles for different screen sizes, use the [media attribute](./../../spec/amp-html-responsive-attributes.md):

```html
<amp-inline-gallery layout="container">
Expand Down Expand Up @@ -384,6 +384,11 @@ The example below demonstrates a gallery with thumbnails visible at larger resol

#### `amp-inline-gallery-thumbnails` attributes

##### Media Queries

The attributes for `<amp-inline-gallery-thumbnails>` can be configured to use different
options based on a [media query](./../../spec/amp-html-responsive-attributes.md).

##### `aspect-ratio` (optional)

Specifies the aspect ratio expressed as `width / height`. The aspect radio defaults to match the slides in `<amp-base-carousel>`.
Expand Down
15 changes: 1 addition & 14 deletions extensions/amp-stream-gallery/amp-stream-gallery.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,20 +254,7 @@ wrapping element, and use that to center the content.
### Media Queries

The attributes for `<amp-stream-gallery>` can be configured to use different
options based on a media query. You can also use a value without any media
queries. The format looks like:

```html
<amp-stream-gallery
attr-name="(min-width: 1000px) valueOne, (min-width: 600px) valueTwo, defaultValue"
></amp-stream-gallery>
```

The media queries are evaluated from left to right, with the first matching
media query being used. A default value (without a media query) is required. In
this case, if the page has a screen width of 1000px or more, `valueOne` is used.
If the width is between 999px and 600px, `valueTwo` is used. When it is 599px or
smaller, `defaultValue` is used.
options based on a [media query](./../../spec/amp-html-responsive-attributes.md).

### Behavior

Expand Down
65 changes: 65 additions & 0 deletions spec/amp-html-responsive-attributes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!---
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks good. But to confirm: this doc file we'll end up on amp.dev, right? Or do we need to do something to make sure it does.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it is automatic, I would expect it to go to https://amp.dev/documentation/guides-and-tutorials/learn/amp-html-responsive-attributes based on where AMP's Layout system and AMP Action and events are located (also in this spec/ directory). @CrystalOnScript @sebastianbenz can one of you confirm?

Copy link
Contributor

Choose a reason for hiding this comment

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

I've opened a PR that should add it to the imported documents for amp.dev here:
ampproject/amp.dev#5422

Copyright 2021 The AMP HTML Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS-IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

# AMP HTML Responsive Attributes

You can apply or remove certain attributes based on screen size. These are responsive attributes, or media attributes. On eligible components, these attributes are applied or removed based on media queries. You can also use a value without any media queries. Media queries evaluate from from left to right, applying the first matching media query. You must include a default value with no media query.

[tip type="note"]

Responsive attributes do not require media queries. You may apply media query eligible attributes the same as regular attributes: `attr-name="attr-value"`.

[/tip]

To apply this behavior to an attribute, use the following format:

```html
<amp-component
attr-name="(min-width: 1000px) valueOne, (min-width: 600px) valueTwo, defaultValue"
></amp-component>
```

In the example above, if the page has a screen of `1000px` or more, it applies `valueOne`. If the width is between `999px` and `600px`, it applies `valueTwo`. When the screen is `599px` or smaller, it applies the `defaultValue`.

The following `amp-base-carousel` will show `3` slides at a time when width is greater than or equal to `800px`, and `2` otherwise.

[example preview="top-frame" playground="true" imports="amp-base-carousel:1.0"]

```html
<amp-base-carousel
width="900" height="200"
layout="responsive"
visible-count="(min-width: 800px) 3, 2">
<amp-img src="./img/redgradient.png" layout="flex-item"></amp-img>
<amp-img src="./img/greengradient.png" layout="flex-item"></amp-img>
<amp-img src="./img/bluegradient.png" layout="flex-item"></amp-img>
<amp-img src="./img/orangegradient.png" layout="flex-item"></amp-img>
<amp-img src="./img/tealgradient.png" layout="flex-item"></amp-img>
<amp-img src="./img/lemonyellowgradient.png" layout="flex-item"></amp-img>
<amp-img src="./img/lilacgradient.png" layout="flex-item"></amp-img>
</amp-base-carousel>
```

[/example]

## Eligible components

You may apply responsive attribute values to the following components:

- [amp-base-carousel](./../extensions/amp-base-carousel/amp-base-carousel.md)
- [amp-inline-gallery-pagination](./../extensions/amp-inline-gallery/amp-inline-gallery.md#include-pagination-indicators)
- [amp-inline-gallery-thumbnails](./../extensions/amp-inline-gallery/amp-inline-gallery.md#include-pagination-thumbnails)
- [amp-stream-gallery](./../extensions/amp-stream-gallery/amp-stream-gallery.md)
Binary file added spec/img/bluegradient.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added spec/img/greengradient.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added spec/img/lemonyellowgradient.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added spec/img/lilacgradient.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added spec/img/orangegradient.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added spec/img/redgradient.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added spec/img/tealgradient.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.