Skip to content

Commit 918606e

Browse files
authored
Update alert styles to be more accessible and match Flutter docs (#6430)
Also contributes to #2625 as these styles will be easier to support and more accessible in a dark mode.
1 parent c492704 commit 918606e

File tree

3 files changed

+88
-72
lines changed

3 files changed

+88
-72
lines changed

src/_11ty/plugins/markdown.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,11 @@ function _registerAside(markdown: MarkdownIt, id: string, defaultTitle: string |
6262
if (tokens[index].nesting === 1) {
6363
const parsedArgs = /\s+(.*)/.exec(tokens[index].info);
6464

65-
const title = parsedArgs?.[1] ?? defaultTitle ?? '';
65+
const title = parsedArgs?.[1] ?? defaultTitle;
6666
return `<aside class="alert ${style}">
67-
<div class="alert-header">
67+
${title !== null ? `<div class="alert-header">
6868
${icon !== null ? `<span class="material-symbols" aria-hidden="true">${icon}</span>` : ''}
69-
<span>${title ?? ''}</span>
70-
</div>
69+
<span>${title}</span></div>` : ''}
7170
<div class="alert-content">
7271
`;
7372
} else {
@@ -97,7 +96,8 @@ function _registerAsides(markdown: MarkdownIt): void {
9796
'alert-info',
9897
);
9998
_registerAside(markdown, 'tip', 'Tip', 'lightbulb', 'alert-success');
100-
_registerAside(markdown, 'important', 'Important', 'error', 'alert-warning');
99+
_registerAside(markdown, 'recommend', 'Recommended', 'bolt', 'alert-success');
100+
_registerAside(markdown, 'important', 'Important', 'feedback', 'alert-important');
101101
_registerAside(
102102
markdown,
103103
'warning',

src/_sass/_site.scss

+1-67
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
@use 'core/base';
99
@use 'core/utils';
1010

11+
@use 'components/alert';
1112
@use 'components/banner';
1213
@use 'components/card';
1314
@use 'components/code';
@@ -498,73 +499,6 @@ thead:has(th:empty) {
498499
margin-block-end: 1rem;
499500
}
500501

501-
.alert {
502-
border: none;
503-
border-radius: 0;
504-
color: $site-color-body;
505-
margin-top: 1rem;
506-
padding: 1.5rem;
507-
508-
.alert-header {
509-
display: flex;
510-
align-items: center;
511-
gap: 0.5rem;
512-
font-family: $site-font-family-gsans;
513-
font-size: 1.125rem;
514-
font-weight: 500;
515-
}
516-
517-
.alert-content {
518-
margin-top: 0.5rem;
519-
}
520-
521-
span.material-symbols {
522-
font-size: 1.25em;
523-
user-select: none;
524-
}
525-
526-
pre {
527-
background-color: #00000010;
528-
}
529-
530-
p, li, ul, ol {
531-
&:last-child {
532-
margin-bottom: 0;
533-
}
534-
}
535-
536-
&.alert-success {
537-
width: auto;
538-
background-color: $alert-success-bg;
539-
}
540-
541-
&.alert-info {
542-
width: auto;
543-
background-color: $alert-info-bg;
544-
}
545-
546-
&.alert-secondary {
547-
width: auto;
548-
background-color: $flutter-color-grey-500;
549-
}
550-
551-
&.alert-warning {
552-
width: auto;
553-
background-color: $alert-warning-bg;
554-
}
555-
556-
&.alert-danger {
557-
width: auto;
558-
background-color: $alert-danger-bg;
559-
}
560-
561-
&.alert-obsolete {
562-
width: auto;
563-
background-color: $gray-dark;
564-
color: $white-base;
565-
}
566-
}
567-
568502
.material-symbols {
569503
font-family: $site-font-family-icon;
570504
font-weight: normal;

src/_sass/components/_alert.scss

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
@use '../core/variables' as *;
2+
3+
aside.alert {
4+
--alert-info-fgColor: #2058b7;
5+
--alert-tip-fgColor: #0c7927;
6+
--alert-important-fgColor: #7953bf;
7+
--alert-warning-fgColor: #955d00;
8+
--alert-error-fgColor: #c43131;
9+
// Dark mode options:
10+
//--alert-info-fgColor: #429bff;
11+
//--alert-tip-fgColor: #25c04b;
12+
//--alert-important-fgColor: #ad81ff;
13+
//--alert-warning-fgColor: #cea11f;
14+
//--alert-error-fgColor: #ff6666;
15+
16+
--alert-title-color: $site-color-body;
17+
18+
padding: 0.75rem;
19+
margin-block-start: 1rem;
20+
margin-block-end: 1rem;
21+
border-left: solid 0.25rem var(--alert-border-color, var(--alert-title-color, $site-color-light-grey));
22+
background-color: $site-color-codeblock-bg;
23+
24+
.alert-header {
25+
display: flex;
26+
align-items: center;
27+
gap: 0.5rem;
28+
margin-block-end: 0.5rem;
29+
font-family: $site-font-family-alt;
30+
font-size: 1.125rem;
31+
font-weight: 500;
32+
-webkit-font-smoothing: antialiased;
33+
color: var(--alert-title-color);
34+
35+
.material-symbols {
36+
font-size: 22px;
37+
user-select: none;
38+
}
39+
}
40+
41+
.alert-content {
42+
color: $site-color-body;
43+
44+
> p, > li, > ul, > ol {
45+
&:first-child {
46+
margin-top: 0;
47+
}
48+
49+
&:last-child {
50+
margin-bottom: 0;
51+
}
52+
}
53+
}
54+
55+
p:last-child {
56+
margin-bottom: 0;
57+
}
58+
59+
&.alert-success {
60+
--alert-title-color: var(--alert-tip-fgColor);
61+
}
62+
63+
&.alert-important {
64+
--alert-title-color: var(--alert-important-fgColor);
65+
}
66+
67+
&.alert-warning {
68+
--alert-title-color: var(--alert-warning-fgColor);
69+
}
70+
71+
&.alert-info {
72+
--alert-title-color: var(--alert-info-fgColor);
73+
}
74+
75+
&.alert-secondary {
76+
--alert-border-color: #{$site-color-light-grey};
77+
}
78+
79+
&.alert-error {
80+
--alert-title-color: var(--alert-error-fgColor);
81+
}
82+
}

0 commit comments

Comments
 (0)