Skip to content

Commit 19cf05f

Browse files
jcfrancobenelan
authored andcommitted
revert: feat(alert): make component responsive (#8195)
**Related Issue:** N/A Rolls back responsiveness (#7755) in favor of upcoming alert stack UX (#2835). See #7921 (comment) for more info.
1 parent 55a174e commit 19cf05f

File tree

3 files changed

+29
-225
lines changed

3 files changed

+29
-225
lines changed

packages/calcite-components/src/components/alert/alert.scss

Lines changed: 19 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ $border-style: 1px solid var(--calcite-color-border-3);
1818
box-border
1919
fixed
2020
flex
21-
flex-wrap
2221
items-center
2322
justify-center
23+
min-w-min
2424
mx-auto
2525
my-0
2626
opacity-0
@@ -64,20 +64,15 @@ $border-style: 1px solid var(--calcite-color-border-3);
6464
}
6565
}
6666

67-
.content {
68-
@apply box-border flex flex-auto flex-col transition-default;
69-
padding-block: var(--calcite-alert-spacing-token-small);
70-
padding-inline: var(--calcite-alert-spacing-token-large) var(--calcite-alert-spacing-token-small);
71-
}
72-
7367
.icon {
74-
@apply flex flex-col items-center justify-start p-0;
75-
margin-block-end: var(--calcite-alert-spacing-token-large);
68+
@apply flex flex-col items-center justify-center p-0;
69+
margin-block: auto;
7670
margin-inline-end: auto;
71+
padding-inline-start: var(--calcite-alert-spacing-token-large);
7772
}
7873

7974
.close {
80-
@apply bg-transparent border-none cursor-pointer flex items-start justify-end outline-none self-start text-color-3;
75+
@apply bg-transparent border-none cursor-pointer flex items-center justify-end outline-none self-stretch text-color-3;
8176
-webkit-appearance: none;
8277
padding: var(--calcite-alert-spacing-token-large);
8378

@@ -97,19 +92,20 @@ $border-style: 1px solid var(--calcite-color-border-3);
9792
}
9893

9994
.queue-count {
100-
@apply text-color-2
101-
bg-foreground-1
102-
transition-default
103-
invisible
104-
flex
95+
@apply bg-foreground-1
10596
cursor-default
97+
flex
98+
font-medium
99+
invisible
106100
items-center
107101
justify-around
108-
self-stretch
102+
min-w-min
103+
opacity-0
109104
overflow-hidden
105+
self-stretch
110106
text-center
111-
font-medium
112-
opacity-0;
107+
text-color-2
108+
transition-default;
113109
border-inline: 0 solid transparent;
114110
border-start-end-radius: 0;
115111

@@ -143,23 +139,14 @@ $border-style: 1px solid var(--calcite-color-border-3);
143139
}
144140

145141
.text-container {
146-
@apply flex flex-1 min-w-0 flex-col break-words;
147-
}
148-
149-
.content-container {
150-
@apply flex flex-1;
142+
@apply box-border flex flex-auto min-w-0 flex-col break-words;
143+
padding-block: var(--calcite-alert-spacing-token-small);
144+
padding-inline: var(--calcite-alert-spacing-token-large) var(--calcite-alert-spacing-token-small);
151145
}
152146

153147
.footer {
154-
@apply flex justify-end order-1 pt-px relative w-full;
155-
block-size: var(--calcite-alert-footer-height);
156-
157-
&:before {
158-
content: "";
159-
@apply absolute top-0;
160-
inset-inline: var(--calcite-alert-footer-divider-gap);
161-
border-block-start: $border-style;
162-
}
148+
@apply flex justify-end pt-px relative self-stretch w-auto;
149+
block-size: inherit;
163150
}
164151

165152
// scale variables
@@ -319,42 +306,5 @@ $alertDurations: "fast" 6000ms, "medium" 10000ms, "slow" 14000ms;
319306
@apply absolute;
320307
}
321308

322-
@container responsive-container (min-width: #{$calcite-container-size-width-xs-max}) {
323-
.content {
324-
@apply flex-row;
325-
}
326-
327-
.close {
328-
@apply items-center self-stretch;
329-
}
330-
331-
.icon {
332-
@apply justify-center;
333-
margin-inline-end: 0;
334-
margin-block: 0;
335-
padding-inline-end: var(--calcite-alert-spacing-token-large);
336-
}
337-
}
338-
339-
@container responsive-container (min-width: #{$calcite-container-size-width-sm-max}) {
340-
.close {
341-
@apply self-stretch;
342-
}
343-
344-
.footer {
345-
@apply self-stretch w-auto;
346-
order: initial;
347-
block-size: inherit;
348-
349-
&:before {
350-
content: none;
351-
}
352-
}
353-
354-
.icon {
355-
padding-inline: var(--calcite-alert-spacing-token-large) 0;
356-
}
357-
}
358-
359309
@include base-component();
360310
@include calciteHydratedHidden();

packages/calcite-components/src/components/alert/alert.stories.ts

Lines changed: 1 addition & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { select } from "@storybook/addon-knobs";
22
import { boolean, iconNames, storyFilters } from "../../../.storybook/helpers";
3-
import { createBreakpointStories, modesDarkDefault } from "../../../.storybook/utils";
3+
import { modesDarkDefault } from "../../../.storybook/utils";
44
import { html } from "../../../support/formatting";
55
import readme from "./readme.md";
66

7-
const openAlertScreenshotDelay = 1000;
8-
97
export default {
108
title: "Components/Alert",
119
parameters: {
@@ -220,121 +218,3 @@ export const autoClosableRetainsCloseButton_TestOnly = (): string => html`
220218
<calcite-link slot="link" title="my action" role="presentation"> Take action </calcite-link>
221219
</calcite-alert>
222220
`;
223-
224-
// we use individual stories since we can't display multiple open alerts at the same time
225-
226-
const breakpointsStoryTemplate = html`
227-
<style>
228-
.breakpoint-stories-container {
229-
height: 600px;
230-
231-
/* force fixed container placement on the breakpoint-sized stories container */
232-
contain: layout;
233-
}
234-
</style>
235-
<calcite-alert icon open scale="{scale}">
236-
<div slot="title">title</div>
237-
<div slot="message">message</div>
238-
<calcite-action scale="{scale}" slot="actions-end" title="Tips" icon="lightbulb"></calcite-action>
239-
<calcite-action scale="{scale}" slot="actions-end" title="Get info" icon="attachment"></calcite-action>
240-
</calcite-alert>
241-
<calcite-alert icon scale="{scale}">
242-
<div slot="title">title</div>
243-
<div slot="message">message</div>
244-
<calcite-action scale="{scale}" slot="actions-end" title="Tips" icon="lightbulb"></calcite-action>
245-
<calcite-action scale="{scale}" slot="actions-end" title="Get info" icon="attachment"></calcite-action>
246-
</calcite-alert>
247-
<script>
248-
(async function () {
249-
await customElements.whenDefined("calcite-alert");
250-
const alert2 = document.querySelectorAll("calcite-alert")[1];
251-
await alert2.componentOnReady();
252-
253-
requestAnimationFrame(() => (alert2.open = true));
254-
})();
255-
</script>
256-
`;
257-
258-
export const breakpointsXsmallScaleS_TestOnly = (): string =>
259-
createBreakpointStories(breakpointsStoryTemplate, { breakpoint: "xsmall", scale: "s" });
260-
261-
breakpointsXsmallScaleS_TestOnly.parameters = {
262-
chromatic: { delay: openAlertScreenshotDelay },
263-
};
264-
265-
export const breakpointsSmallScaleS_TestOnly = (): string =>
266-
createBreakpointStories(breakpointsStoryTemplate, { breakpoint: "small", scale: "s" });
267-
268-
breakpointsSmallScaleS_TestOnly.parameters = {
269-
chromatic: { delay: openAlertScreenshotDelay },
270-
};
271-
272-
export const breakpointsMediumScaleS_TestOnly = (): string =>
273-
createBreakpointStories(breakpointsStoryTemplate, { breakpoint: "medium", scale: "s" });
274-
275-
breakpointsMediumScaleS_TestOnly.parameters = {
276-
chromatic: { delay: openAlertScreenshotDelay },
277-
};
278-
279-
export const breakpointsLargeScaleS_TestOnly = (): string =>
280-
createBreakpointStories(breakpointsStoryTemplate, { breakpoint: "large", scale: "s" });
281-
282-
breakpointsLargeScaleS_TestOnly.parameters = {
283-
chromatic: { delay: openAlertScreenshotDelay },
284-
};
285-
286-
export const breakpointsXsmallScaleM_TestOnly = (): string =>
287-
createBreakpointStories(breakpointsStoryTemplate, { breakpoint: "xsmall", scale: "m" });
288-
289-
breakpointsXsmallScaleM_TestOnly.parameters = {
290-
chromatic: { delay: openAlertScreenshotDelay },
291-
};
292-
293-
export const breakpointsSmallScaleM_TestOnly = (): string =>
294-
createBreakpointStories(breakpointsStoryTemplate, { breakpoint: "small", scale: "m" });
295-
296-
breakpointsSmallScaleM_TestOnly.parameters = {
297-
chromatic: { delay: openAlertScreenshotDelay },
298-
};
299-
300-
export const breakpointsMediumScaleM_TestOnly = (): string =>
301-
createBreakpointStories(breakpointsStoryTemplate, { breakpoint: "medium", scale: "m" });
302-
303-
breakpointsMediumScaleM_TestOnly.parameters = {
304-
chromatic: { delay: openAlertScreenshotDelay },
305-
};
306-
307-
export const breakpointsLargeScaleM_TestOnly = (): string =>
308-
createBreakpointStories(breakpointsStoryTemplate, { breakpoint: "large", scale: "m" });
309-
310-
breakpointsLargeScaleM_TestOnly.parameters = {
311-
chromatic: { delay: openAlertScreenshotDelay },
312-
};
313-
314-
export const breakpointsXsmallScaleL_TestOnly = (): string =>
315-
createBreakpointStories(breakpointsStoryTemplate, { breakpoint: "xsmall", scale: "l" });
316-
317-
breakpointsXsmallScaleL_TestOnly.parameters = {
318-
chromatic: { delay: openAlertScreenshotDelay },
319-
};
320-
321-
export const breakpointsSmallScaleL_TestOnly = (): string =>
322-
createBreakpointStories(breakpointsStoryTemplate, { breakpoint: "small", scale: "l" });
323-
324-
breakpointsSmallScaleL_TestOnly.parameters = {
325-
chromatic: { delay: openAlertScreenshotDelay },
326-
};
327-
328-
export const breakpointsMediumScaleL_TestOnly = (): string =>
329-
createBreakpointStories(breakpointsStoryTemplate, { breakpoint: "medium", scale: "l" });
330-
331-
breakpointsMediumScaleL_TestOnly.parameters = {
332-
chromatic: { delay: openAlertScreenshotDelay },
333-
};
334-
335-
export const breakpointsLargeScaleL_TestOnly = (): string =>
336-
createBreakpointStories(breakpointsStoryTemplate, { breakpoint: "large", scale: "l" });
337-
338-
breakpointsLargeScaleL_TestOnly.parameters = {
339-
chromatic: { delay: openAlertScreenshotDelay },
340-
};

packages/calcite-components/src/components/alert/alert.tsx

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ import { KindIcons } from "../resources";
4646
import { AlertMessages } from "./assets/alert/t9n";
4747
import { AlertDuration, Sync, Unregister } from "./interfaces";
4848
import { CSS, DURATIONS, SLOTS } from "./resources";
49-
import { createObserver } from "../../utils/observers";
50-
import { breakpoints } from "../../utils/responsive";
5149

5250
/**
5351
* Alerts are meant to provide a way to communicate urgent or important information to users, frequently as a result of an action they took in your app. Alerts are positioned
@@ -175,9 +173,6 @@ export class Alert implements OpenCloseComponent, LoadableComponent, T9nComponen
175173
if (open && !this.queued) {
176174
this.calciteInternalAlertRegister.emit();
177175
}
178-
if (this.transitionEl) {
179-
this.resizeObserver?.observe(this.transitionEl);
180-
}
181176
}
182177

183178
async componentWillLoad(): Promise<void> {
@@ -190,7 +185,6 @@ export class Alert implements OpenCloseComponent, LoadableComponent, T9nComponen
190185

191186
componentDidLoad(): void {
192187
setComponentLoaded(this);
193-
this.resizeObserver?.observe(this.transitionEl);
194188
}
195189

196190
disconnectedCallback(): void {
@@ -204,7 +198,6 @@ export class Alert implements OpenCloseComponent, LoadableComponent, T9nComponen
204198
disconnectLocalized(this);
205199
disconnectMessages(this);
206200
this.slottedInShell = false;
207-
this.resizeObserver?.disconnect();
208201
}
209202

210203
render(): VNode {
@@ -214,12 +207,8 @@ export class Alert implements OpenCloseComponent, LoadableComponent, T9nComponen
214207
signDisplay: "always",
215208
};
216209

217-
const { hasEndActions } = this;
218-
const { open, autoClose, responsiveContainerWidth, label, placement, queued } = this;
210+
const { open, autoClose, label, placement, queued } = this;
219211
const role = autoClose ? "alert" : "alertdialog";
220-
const widthBreakpoints = breakpoints.width;
221-
const lessThanSmall = responsiveContainerWidth < widthBreakpoints.small;
222-
const greaterOrEqualThanSmall = responsiveContainerWidth >= widthBreakpoints.small;
223212
const hidden = !open;
224213
const effectiveIcon = setRequestedIcon(KindIcons, this.icon, this.kind);
225214
const hasQueuedAlerts = this.queueLength > 1;
@@ -243,23 +232,15 @@ export class Alert implements OpenCloseComponent, LoadableComponent, T9nComponen
243232
// eslint-disable-next-line react/jsx-sort-props -- ref should be last so node attrs/props are in sync (see https://github.com/Esri/calcite-design-system/pull/6530)
244233
ref={this.setTransitionEl}
245234
>
246-
<div class={CSS.contentContainer}>
247-
{effectiveIcon && greaterOrEqualThanSmall ? this.renderIcon(effectiveIcon) : null}
248-
<div class={CSS.content}>
249-
{effectiveIcon && lessThanSmall ? this.renderIcon(effectiveIcon) : null}
250-
<div class={CSS.textContainer}>
251-
<slot name={SLOTS.title} />
252-
<slot name={SLOTS.message} />
253-
<slot name={SLOTS.link} />
254-
</div>
255-
</div>
256-
</div>
257-
{lessThanSmall ? this.renderCloseButton() : null}
258-
<div class={CSS.footer} hidden={!hasEndActions && !hasQueuedAlerts}>
259-
{this.renderActionsEnd()}
260-
{hasQueuedAlerts ? this.renderQueueCount() : null}
235+
{effectiveIcon && this.renderIcon(effectiveIcon)}
236+
<div class={CSS.textContainer}>
237+
<slot name={SLOTS.title} />
238+
<slot name={SLOTS.message} />
239+
<slot name={SLOTS.link} />
261240
</div>
262-
{greaterOrEqualThanSmall ? this.renderCloseButton() : null}
241+
{this.renderActionsEnd()}
242+
{hasQueuedAlerts ? this.renderQueueCount() : null}
243+
{this.renderCloseButton()}
263244
{open && !queued && autoClose ? <div class={CSS.dismissProgress} /> : null}
264245
</div>
265246
</Host>
@@ -434,8 +415,6 @@ export class Alert implements OpenCloseComponent, LoadableComponent, T9nComponen
434415
/** is the alert queued */
435416
@State() queued = false;
436417

437-
@State() responsiveContainerWidth: number;
438-
439418
private autoCloseTimeoutId: number = null;
440419

441420
private closeButton: HTMLButtonElement;
@@ -446,11 +425,6 @@ export class Alert implements OpenCloseComponent, LoadableComponent, T9nComponen
446425

447426
private queueTimeout: number;
448427

449-
private resizeObserver = createObserver(
450-
"resize",
451-
(entries) => (this.responsiveContainerWidth = entries[0].contentRect.width)
452-
);
453-
454428
private totalOpenTime = 0;
455429

456430
private totalHoverTime = 0;

0 commit comments

Comments
 (0)