Skip to content

Commit f654c8d

Browse files
refactor(dialog): add more header flexibility (#4000)
* fix(dialog): condense t-shirt variables * feat(dialog): add container query - adds container query for fullscreen/fullscreenTakeover dialogs - increases the max-inline-size for the dialog to 864px for query - moves fullscreen/fullscreenTakeover grid layout to container query * chore(dialog): add changeset * test(dialog): render wrapper and container styles conditionally - force dialog container to be full width for testing
1 parent 8635e07 commit f654c8d

File tree

3 files changed

+78
-48
lines changed

3 files changed

+78
-48
lines changed

.changeset/polite-apes-think.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@spectrum-css/dialog": minor
3+
---
4+
5+
Increases flexibility and responsiveness of the dialog header. A container query for the `.spectrum-Dialog` was added, which now triggers the reflow of the `.spectrum-Dialog--fullscreen`/`.spectrum-Dialog--fullscreenTakeover` content grid. This is particularly useful when the component slot is utilized to add other components as additional content in fullscreen/fullscreenTakeover dialogs' header areas by allowing the content to reflow sooner.

components/dialog/index.css

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@
6363
--spectrum-takeover-dialog-block-size: var(--spectrum-takeover-dialog-height);
6464
}
6565

66+
.spectrum-Dialog--sizeS {
67+
--spectrum-standard-dialog-max-width: var(--mod-standard-dialog-max-width-small, var(--spectrum-standard-dialog-maximum-width-small));
68+
}
69+
70+
.spectrum-Dialog--sizeL {
71+
--spectrum-standard-dialog-max-width: var(--mod-standard-dialog-max-width-large, var(--spectrum-standard-dialog-maximum-width-large));
72+
}
73+
6674
.spectrum-Dialog {
6775
/* Be a flexbox to allow a full sized content area that scrolls */
6876
display: flex;
@@ -81,16 +89,6 @@
8189
overflow: hidden;
8290
}
8391

84-
.spectrum-Dialog--sizeS {
85-
--spectrum-standard-dialog-max-width: var(--spectrum-standard-dialog-maximum-width-small);
86-
inline-size: var(--mod-standard-dialog-max-width-small, var(--spectrum-standard-dialog-max-width));
87-
}
88-
89-
.spectrum-Dialog--sizeL {
90-
--spectrum-standard-dialog-max-width: var(--spectrum-standard-dialog-maximum-width-large);
91-
inline-size: var(--mod-standard-dialog-max-width-large, var(--spectrum-standard-dialog-max-width));
92-
}
93-
9492
.spectrum-Dialog-hero {
9593
grid-area: hero;
9694

@@ -271,6 +269,9 @@
271269
max-block-size: none;
272270
max-inline-size: none;
273271

272+
/* Enable container queries for fullscreen/fullscreenTakeover dialogs */
273+
container: dialog-fullscreen / inline-size;
274+
274275
.spectrum-Dialog-grid {
275276
display: grid;
276277
grid-template-columns:
@@ -344,7 +345,6 @@
344345
auto
345346
var(--mod-standard-dialog-spacing-grid-padding, var(--spectrum-standard-dialog-spacing-grid-padding));
346347

347-
/* TODO: investigate if we could refactor the grid to make the footer text/checkbox stack on top of the button group */
348348
grid-template-areas:
349349
"hero hero hero hero hero hero"
350350
". . . . . ."
@@ -394,6 +394,12 @@
394394
gap: 0;
395395
}
396396

397+
.spectrum-Dialog-heading {
398+
margin-block-end: var(--mod-standard-dialog-spacing-title-to-description, var(--spectrum-standard-dialog-spacing-title-to-description));
399+
}
400+
}
401+
402+
@container dialog-fullscreen (max-inline-size: 864px) {
397403
.spectrum-Dialog--fullscreen,
398404
.spectrum-Dialog--fullscreenTakeover {
399405
&.spectrum-Dialog .spectrum-Dialog-grid {
@@ -422,20 +428,22 @@
422428

423429
.spectrum-Dialog-header {
424430
margin-inline-end: 0;
431+
432+
/* The header element is a flexbox, so that the title and headerContentWrapper can wrap sooner. */
433+
display: flex;
434+
flex-direction: column;
435+
gap: var(--mod-takeover-dialog-spacing-header-content-gap, var(--spectrum-takeover-dialog-spacing-header-content-gap));
425436
}
426437

427438
.spectrum-Dialog-heading {
428439
margin-inline-end: 0;
440+
margin-block-end: 0;
429441
}
430442
}
431-
432-
.spectrum-Dialog-heading {
433-
margin-block-end: var(--spectrum-standard-dialog-spacing-title-to-description);
434-
}
435443
}
436444

437445
@media (forced-colors: active) {
438446
.spectrum-Dialog {
439-
border: 1px solid rgba(var(--spectrum-black-rgb), var(--spectrum-overlay-opacity));
447+
border: 1px solid rgb(var(--spectrum-black-rgb), var(--spectrum-overlay-opacity));
440448
}
441449
}

components/dialog/stories/dialog.test.js

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,39 +51,56 @@ export const DialogGroup = Variants({
5151
],
5252
});
5353

54-
export const DialogFullscreen = Variants({
55-
Template: (args, context) => {
56-
const { parameters: { showTestingGrid = false } = {} } = context;
54+
export const DialogFullscreen = (args, context) => {
55+
const { parameters: { showTestingGrid = false } = {} } = context;
5756

58-
return Template({
59-
...args,
60-
/*
61-
* Custom styles were added to make sure the VRTs catch the rounded corners
62-
*/
63-
customStyles: {
64-
margin: showTestingGrid ? "16px" : undefined,
65-
},
66-
}, context);
67-
},
68-
withSizes: false,
69-
wrapperStyles: {
70-
"background-color": "var(--spectrum-gray-50)"
71-
},
72-
testData: [
73-
{
74-
showModal: false,
75-
layout: "fullscreen",
57+
return Variants({
58+
Template: (args, context) => {
59+
return Template({
60+
...args,
61+
/*
62+
* Custom styles were added to make sure the VRTs catch the rounded corners
63+
*/
64+
customStyles: {
65+
margin: showTestingGrid ? "16px" : undefined,
66+
},
67+
}, context);
7668
},
77-
],
78-
});
69+
withSizes: false,
70+
wrapperStyles: {
71+
"background-color": "var(--spectrum-gray-50)",
72+
...(showTestingGrid && { "inline-size": "100%" }), // Applies conditional styles based on showTestingGrid- forces the data-inner-container to be full width so the container query doesn't break.
73+
},
74+
containerStyles: {
75+
...(showTestingGrid && { "inline-size": "100%" }), // forces the data-outer-container to be full width so the container query doesn't break.
76+
},
77+
testData: [
78+
{
79+
showModal: false,
80+
layout: "fullscreen",
81+
},
82+
],
83+
})(args, context);
84+
};
7985

80-
export const DialogFullscreenTakeover = Variants({
81-
Template,
82-
withSizes: false,
83-
testData: [
84-
{
85-
showModal: false,
86-
layout: "fullscreenTakeover",
86+
export const DialogFullscreenTakeover = (args, context) => {
87+
const { parameters: { showTestingGrid = false } = {} } = context;
88+
89+
return Variants({
90+
Template,
91+
withSizes: false,
92+
wrapperStyles: {
93+
...(showTestingGrid && { "inline-size": "100%" }), // Applies conditional styles based on showTestingGrid- forces the data-inner-container to be full width so the container query doesn't break.
8794
},
88-
],
89-
});
95+
// Apply conditional styles based on showTestingGrid
96+
containerStyles: {
97+
...(showTestingGrid && { "inline-size": "100%" }), // forces the data-outer-container to be full width so the container query doesn't break.
98+
},
99+
testData: [
100+
{
101+
showModal: false,
102+
layout: "fullscreenTakeover",
103+
},
104+
],
105+
})(args, context);
106+
};

0 commit comments

Comments
 (0)