Skip to content

fix(tray): full width at portrait orientation #2547

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

Merged
merged 4 commits into from
Feb 20, 2024
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
32 changes: 16 additions & 16 deletions components/tray/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ governing permissions and limitations under the License.
--spectrum-tray-background-color: var(--spectrum-background-layer-2-color);
}

@media (forced-colors: active) {
.spectrum-Tray {
--highcontrast-tray-background-color: Background;
}
}

.spectrum-Tray-wrapper {
inset-inline-start: 0;
/* Positioned at the bottom of the window */
Expand All @@ -45,20 +39,19 @@ governing permissions and limitations under the License.
}

.spectrum-Tray {
/* Default to full width when the viewport is in portrait orientation
* (height is greater than width)
*/
/* Default to full width when the viewport is in portrait orientation */
inline-size: 100%;
--mod-modal-max-width: 100%;
max-inline-size: 100%;

max-block-size: calc(100vh - var(--mod-tray-spacing-edge-to-tray-safe-zone, var(--spectrum-tray-spacing-edge-to-tray-safe-zone)));
margin-block-start: var(--mod-tray-spacing-edge-to-tray-safe-zone, var(--spectrum-tray-spacing-edge-to-tray-safe-zone));
padding-block-start: var(--mod-tray-top-to-content-area, var(--spectrum-tray-top-to-content-area));
padding-block-end: var(--mod-tray-bottom-to-content-area, var(--spectrum-tray-top-to-content-area));
box-sizing: border-box;
overflow: auto;
outline: none;

/* Unset spectrum-Modal border-radius */
border-radius: unset;
border-radius: var(--mod-tray-corner-radius-portrait, 0) var(--mod-tray-corner-radius-portrait, 0) 0 0;

/* Start offset by the animation distance */
transform: translateY(100%);
Expand Down Expand Up @@ -91,14 +84,21 @@ governing permissions and limitations under the License.
}
}

/* https://developer.mozilla.org/en-US/docs/Web/CSS/@media/orientation
* Limit Tray width to 375px and round corners when the viewport is in landscape orientation
* (width is greater than height)
*/
@media screen and (orientation: landscape) {
.spectrum-Tray {
border-start-start-radius: var(--mod-tray-corner-radius, var(--spectrum-tray-corner-radius));
border-start-end-radius: var(--mod-tray-corner-radius, var(--spectrum-tray-corner-radius));
max-inline-size: var(--mod-tray-max-inline-size, var(--spectrum-tray-max-inline-size));
}
}

@media (forced-colors: active) {
.spectrum-Tray {
--highcontrast-tray-background-color: Canvas;

border: solid;
& .spectrum-Dialog {
border: none;
}
}
}
1 change: 1 addition & 0 deletions components/tray/metadata/mods.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
| `--mod-tray-background-color` |
| `--mod-tray-bottom-to-content-area` |
| `--mod-tray-corner-radius` |
| `--mod-tray-corner-radius-portrait` |
| `--mod-tray-entry-animation-delay` |
| `--mod-tray-entry-animation-duration` |
| `--mod-tray-exit-animation-delay` |
Expand Down
9 changes: 5 additions & 4 deletions components/tray/metadata/tray.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
name: Tray
description: |
Tray Dialogs are typically used to portray information on mobile device or
smaller screens.
The Tray component is typically used to portray information on mobile devices or smaller screens.

sections:
- name: Custom Properties API
description: |
This component can be modified via its `--mod-*` prefixed custom properties. A list of those prefixed custom properties can be found <a class="spectrum-Link" href="https://github.com/adobe/spectrum-css/tree/main/components/tray/metadata/mods.md">here</a>.
SpectrumSiteSlug: https://spectrum.adobe.com/page/trays/
SpectrumSiteSlug: https://spectrum.adobe.com/page/tray/
examples:
- id: tray
name: Tray
name: Standard
description: The following example displays differently depending on the orientation of the viewport, using the `orientation` CSS media feature. In portrait orientation, a Tray is displayed at the bottom of the screen and takes up the full width of the view. In landscape orientation, it keeps its portrait width, is centered horizontally, and has rounded upper corners.
markup: |
<div class="spectrum-Tray-wrapper spectrum-CSSExample-dialog" style="background: rgba(0,0,0,0.4);">
<div class="spectrum-Modal spectrum-Tray is-open">
Expand Down
3 changes: 1 addition & 2 deletions components/tray/stories/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { classMap } from "lit/directives/class-map.js";
import { ifDefined } from "lit/directives/if-defined.js";
import { styleMap } from "lit/directives/style-map.js";

import { Template as Modal } from "@spectrum-css/modal/stories/template.js";

import "@spectrum-css/modal/index.css";
import "../index.css";

export const Template = ({
Expand Down
8 changes: 4 additions & 4 deletions components/tray/stories/tray.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default {
rootClass: "spectrum-Tray",
customClasses: ["spectrum-Modal"],
isOpen: true,
heading: "New Messages",
},
parameters: {
actions: {
Expand All @@ -43,15 +44,16 @@ export default {
};

export const Default = ({
heading,
...args
}) => {
return html`
<div>
${Template({
heading: "Tray Dialog",
...args,
content: [
() => Dialog({
heading: "New Messages",
heading,
content: ["You have 5 new messages!"],
isDismissable: false,
})
Expand All @@ -62,7 +64,6 @@ export const Default = ({
window.isChromatic() ?
Template({
...args,
heading: "Tray Dialog",
content: [
() => Dialog({
heading: "You have new messages waiting in your inbox",
Expand All @@ -79,4 +80,3 @@ export const Default = ({
</div>
`;
};
Default.args = {};