Skip to content

Commit 23f4abf

Browse files
authored
Add searchable glossary (#12608)
Add a searchable glossary at `/resources/glossary` with two initial terms that we can add to over time. For now, don't add the new page to the sidenav until we add a few more important terms.
1 parent 300a2ea commit 23f4abf

File tree

14 files changed

+673
-11
lines changed

14 files changed

+673
-11
lines changed

firebase.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
{ "source": "/flutter-for-:platform*", "destination": "/get-started/flutter-for/:platform*-devs", "type": 301 },
5959
{ "source": "/formatting", "destination": "/tools/formatting", "type": 301 },
6060
{ "source": "/gestures", "destination": "/ui/advanced/gestures", "type": 301 },
61+
{ "source": "/glossary", "destination": "/resources/glossary", "type": 301 },
62+
{ "source": "/glossary/:entry", "destination": "/resources/glossary#:entry", "type": 301 },
6163
{ "source": "/hot-reload", "destination": "/tools/hot-reload", "type": 301 },
6264
{ "source": "/ide-setup", "destination": "/tools/editors", "type": 301 },
6365
{ "source": "/images/catalog-widget-placeholder.png", "destination": "/assets/images/docs/catalog-widget-placeholder.png", "type": 301 },

site/lib/_sass/_site.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
@use 'components/cookie-notice';
2323
@use 'components/dropdown';
2424
@use 'components/expansion-list';
25+
@use 'components/filter-search';
2526
@use 'components/footer';
2627
@use 'components/header';
2728
@use 'components/icons';
@@ -38,6 +39,7 @@
3839
@use 'components/trailing';
3940

4041
// Styles for specific pages, alphabetically ordered.
42+
@use 'pages/glossary';
4143
@use 'pages/learning-resources-index';
4244
@use 'pages/not-found';
4345
@use 'pages/search';

site/lib/_sass/components/_button.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ button {
3535
font-weight: 500;
3636
font-family: var(--site-ui-fontFamily);
3737
gap: 0.3rem;
38-
padding: 0.5rem 1rem;
38+
padding: 0.4rem 0.9rem;
3939
text-decoration: none;
4040
cursor: pointer;
4141
}
@@ -46,6 +46,11 @@ button {
4646
outline-offset: 2px;
4747
user-select: none;
4848

49+
span.material-symbols {
50+
font-variation-settings: 'FILL' 1;
51+
font-size: 20px;
52+
}
53+
4954
&:hover {
5055
@include mixins.interaction-style(8%);
5156
}

site/lib/_sass/components/_card.scss

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
@use '../base/mixins';
22

3+
.card-list {
4+
display: flex;
5+
flex-direction: column;
6+
gap: var(--card-grid-gap, 1rem);
7+
margin: 0;
8+
justify-content: center;
9+
}
10+
311
.card-grid {
412
display: grid;
513
grid-template-columns: repeat(auto-fit, minmax(min(100%, var(--card-min-width, 15rem)), 1fr));
@@ -30,7 +38,9 @@
3038
--card-min-width: 10rem;
3139
grid-auto-rows: 1fr;
3240
}
41+
}
3342

43+
.card-grid, .card-list {
3444
.card {
3545
display: flex;
3646
flex-direction: column;
@@ -101,7 +111,7 @@
101111
}
102112
}
103113

104-
.card-content {
114+
&:not(.glossary-card) .card-content {
105115
display: flex;
106116
align-items: center;
107117
gap: 0.75rem;
@@ -225,7 +235,6 @@
225235
}
226236
}
227237

228-
229238
.card-image-holder-material-3 {
230239
position: relative;
231240
align-items: center;

site/lib/_sass/components/_content.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#page-content {
1+
main {
22
display: flex;
33
flex-direction: column;
44
justify-content: center;
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#filter-and-search {
2+
display: flex;
3+
flex-direction: column;
4+
flex-wrap: wrap;
5+
justify-content: center;
6+
gap: 0.75rem;
7+
margin-block-start: 1rem;
8+
margin-block-end: 1rem;
9+
10+
&.hidden {
11+
display: none;
12+
}
13+
14+
.search-row {
15+
display: flex;
16+
flex-direction: row;
17+
align-items: center;
18+
width: 100%;
19+
gap: 0.5rem;
20+
21+
.search-wrapper {
22+
display: flex;
23+
align-items: center;
24+
width: 100%;
25+
26+
border: 1px solid var(--site-outline);
27+
border-radius: 1rem;
28+
height: 3rem;
29+
padding: 0 .5rem;
30+
31+
&:has(:focus-visible) {
32+
outline: 2px solid var(--site-primary-color);
33+
border-color: transparent;
34+
}
35+
36+
.leading-icon {
37+
padding-left: 0.25rem;
38+
user-select: none;
39+
}
40+
41+
input {
42+
background: none;
43+
width: 100%;
44+
font-size: 1rem;
45+
cursor: text;
46+
47+
&:focus {
48+
outline: none;
49+
}
50+
51+
&::-webkit-search-cancel-button {
52+
display: none;
53+
}
54+
}
55+
}
56+
}
57+
58+
+ section.content-search-results {
59+
margin-block-start: 0.5rem;
60+
margin-block-end: 1rem;
61+
}
62+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
@use '../base/mixins';
2+
3+
body.glossary-page main {
4+
.glossary-card {
5+
height: auto;
6+
padding: 0.75rem;
7+
8+
.expandable-content {
9+
border-top: 0.05rem solid var(--site-inset-borderColor);
10+
padding-top: 0.5rem;
11+
}
12+
13+
&.collapsed {
14+
min-height: 8rem;
15+
16+
.initial-content {
17+
// Only show the first paragraph if collapsed.
18+
> :not(:first-child) {
19+
display: none;
20+
}
21+
}
22+
23+
.expandable-content {
24+
display: none;
25+
}
26+
27+
.expand-button {
28+
transform: rotate(180deg);
29+
}
30+
}
31+
32+
.expand-button {
33+
&:hover, &:focus-within {
34+
transition: transform .25s ease-out;
35+
}
36+
}
37+
38+
.card-header {
39+
display: flex;
40+
flex-direction: row;
41+
justify-content: space-between;
42+
align-items: center;
43+
}
44+
}
45+
46+
.details-header {
47+
font-weight: 500;
48+
margin-bottom: 0.5rem;
49+
margin-top: 0.5rem;
50+
font-size: 1rem;
51+
}
52+
53+
.resources-list {
54+
list-style: none;
55+
padding: 0.5rem;
56+
margin: 0;
57+
58+
display: flex;
59+
flex-direction: row;
60+
flex-wrap: wrap;
61+
gap: 0.5rem;
62+
63+
li {
64+
display: flex;
65+
66+
.filled-button {
67+
text-wrap: pretty;
68+
padding: 0.25rem 0.75rem;
69+
}
70+
}
71+
}
72+
73+
.initial-content, .expandable-content {
74+
> :first-child {
75+
margin-top: 0;
76+
}
77+
78+
> :last-child {
79+
margin-bottom: 0;
80+
}
81+
}
82+
83+
.card-header-buttons {
84+
display: flex;
85+
flex-direction: row;
86+
align-items: center;
87+
gap: 0.25rem;
88+
89+
.icon-button {
90+
border-radius: 1.5rem;
91+
92+
> span {
93+
font-size: 1.5rem;
94+
}
95+
}
96+
}
97+
}

site/lib/jaspr_options.dart

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ import 'package:docs_flutter_dev_site/src/components/layout/theme_switcher.dart'
2929
as prefix10;
3030
import 'package:docs_flutter_dev_site/src/components/pages/archive_table.dart'
3131
as prefix11;
32-
import 'package:docs_flutter_dev_site/src/components/pages/learning_resource_filters.dart'
32+
import 'package:docs_flutter_dev_site/src/components/pages/glossary_search_section.dart'
3333
as prefix12;
34-
import 'package:docs_flutter_dev_site/src/components/pages/learning_resource_filters_sidebar.dart'
34+
import 'package:docs_flutter_dev_site/src/components/pages/learning_resource_filters.dart'
3535
as prefix13;
36+
import 'package:docs_flutter_dev_site/src/components/pages/learning_resource_filters_sidebar.dart'
37+
as prefix14;
3638

3739
/// Default [JasprOptions] for use with your jaspr project.
3840
///
@@ -105,13 +107,18 @@ JasprOptions get defaultJasprOptions => JasprOptions(
105107
params: _prefix11ArchiveTable,
106108
),
107109

108-
prefix12.LearningResourceFilters:
109-
ClientTarget<prefix12.LearningResourceFilters>(
110+
prefix12.GlossarySearchSection:
111+
ClientTarget<prefix12.GlossarySearchSection>(
112+
'src/components/pages/glossary_search_section',
113+
),
114+
115+
prefix13.LearningResourceFilters:
116+
ClientTarget<prefix13.LearningResourceFilters>(
110117
'src/components/pages/learning_resource_filters',
111118
),
112119

113-
prefix13.LearningResourceFiltersSidebar:
114-
ClientTarget<prefix13.LearningResourceFiltersSidebar>(
120+
prefix14.LearningResourceFiltersSidebar:
121+
ClientTarget<prefix14.LearningResourceFiltersSidebar>(
115122
'src/components/pages/learning_resource_filters_sidebar',
116123
),
117124
},

site/lib/src/client/global_scripts.dart

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ void _setUpSite() {
4141
_setUpSearchKeybindings();
4242
_setUpTabs();
4343
_setUpCollapsibleElements();
44+
_setUpExpandableCards();
4445
_setUpPlatformKeys();
4546
_setUpToc();
4647
}
@@ -255,6 +256,48 @@ void _setUpCollapsibleElements() {
255256
}
256257
}
257258

259+
void _setUpExpandableCards() {
260+
var currentFragment = web.window.location.hash.trim().toLowerCase();
261+
if (currentFragment.startsWith('#')) {
262+
// Remove the leading '#' from the fragment.
263+
currentFragment = currentFragment.substring(1);
264+
}
265+
final expandableCards = web.document.querySelectorAll('.expandable-card');
266+
web.Element? targetCard;
267+
268+
for (var i = 0; i < expandableCards.length; i++) {
269+
final card = expandableCards.item(i) as web.Element;
270+
final expandButton = card.querySelector('.expand-button');
271+
if (expandButton == null) continue;
272+
273+
expandButton.addEventListener(
274+
'click',
275+
((web.Event e) {
276+
if (card.classList.contains('collapsed')) {
277+
card.classList.remove('collapsed');
278+
expandButton.ariaExpanded = 'true';
279+
} else {
280+
card.classList.add('collapsed');
281+
expandButton.ariaExpanded = 'false';
282+
}
283+
e.preventDefault();
284+
}).toJS,
285+
);
286+
287+
if (card.id != currentFragment) {
288+
card.classList.add('collapsed');
289+
expandButton.ariaExpanded = 'false';
290+
} else {
291+
targetCard = card;
292+
}
293+
}
294+
295+
if (targetCard != null) {
296+
// Scroll the expanded card into view.
297+
targetCard.scrollIntoView();
298+
}
299+
}
300+
258301
void _setUpPlatformKeys() {
259302
final os = getOS();
260303
// Use Command key for macOS, Control key for other OS.

0 commit comments

Comments
 (0)