Skip to content

Commit aef6175

Browse files
committed
Added type selection to icon and emoji search
1 parent b0c5fe6 commit aef6175

File tree

12 files changed

+112
-40
lines changed

12 files changed

+112
-40
lines changed

docs/reference/icons-emojis.md

+8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ can be added] and used in `mkdocs.yml`, documents and templates.
2121
data-mdx-component="iconsearch-query"
2222
/>
2323
<div class="mdx-iconsearch-result" data-mdx-component="iconsearch-result">
24+
<select
25+
class="mdx-iconsearch-result__select"
26+
data-mdx-component="iconsearch-select"
27+
>
28+
<option value="all" selected>All</option>
29+
<option value="icons">Icons</option>
30+
<option value="emojis">Emojis</option>
31+
</select>
2432
<div class="mdx-iconsearch-result__meta"></div>
2533
<ol class="mdx-iconsearch-result__list"></ol>
2634
</div>

material/overrides/assets/javascripts/custom.63a6dff3.min.js

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

material/overrides/assets/javascripts/custom.63a6dff3.min.js.map

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

material/overrides/assets/javascripts/custom.e2e97759.min.js

-18
This file was deleted.

material/overrides/assets/javascripts/custom.e2e97759.min.js.map

-7
This file was deleted.

material/overrides/assets/stylesheets/custom.00c04c01.min.css renamed to material/overrides/assets/stylesheets/custom.efcf58ca.min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

material/overrides/assets/stylesheets/custom.00c04c01.min.css.map renamed to material/overrides/assets/stylesheets/custom.efcf58ca.min.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

material/overrides/main.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
-#}
44
{% extends "base.html" %}
55
{% block extrahead %}
6-
<link rel="stylesheet" href="{{ 'assets/stylesheets/custom.00c04c01.min.css' | url }}">
6+
<link rel="stylesheet" href="{{ 'assets/stylesheets/custom.efcf58ca.min.css' | url }}">
77
{% endblock %}
88
{% block announce %}
99
For updates follow <strong>@squidfunk</strong> on
@@ -23,5 +23,5 @@
2323
{% endblock %}
2424
{% block scripts %}
2525
{{ super() }}
26-
<script src="{{ 'assets/javascripts/custom.e2e97759.min.js' | url }}"></script>
26+
<script src="{{ 'assets/javascripts/custom.63a6dff3.min.js' | url }}"></script>
2727
{% endblock %}

src/overrides/assets/javascripts/components/_/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export type ComponentType =
3333
| "iconsearch" /* Icon search */
3434
| "iconsearch-query" /* Icon search input */
3535
| "iconsearch-result" /* Icon search results */
36+
| "iconsearch-select" /* Icon search select */
3637
| "sponsorship" /* Sponsorship */
3738
| "sponsorship-count" /* Sponsorship count */
3839
| "sponsorship-total" /* Sponsorship total */
@@ -62,6 +63,7 @@ interface ComponentTypeMap {
6263
"iconsearch": HTMLElement /* Icon search */
6364
"iconsearch-query": HTMLInputElement /* Icon search input */
6465
"iconsearch-result": HTMLElement /* Icon search results */
66+
"iconsearch-select": HTMLSelectElement
6567
"sponsorship": HTMLElement /* Sponsorship */
6668
"sponsorship-count": HTMLElement /* Sponsorship count */
6769
"sponsorship-total": HTMLElement /* Sponsorship total */

src/overrides/assets/javascripts/components/iconsearch/_/index.ts

+25-3
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@
2020
* IN THE SOFTWARE.
2121
*/
2222

23-
import { Observable, merge } from "rxjs"
23+
import { BehaviorSubject, Observable, fromEvent, map, merge } from "rxjs"
2424

2525
import { configuration } from "~/_"
2626
import { requestJSON } from "~/browser"
2727

28-
import { Component, getComponentElement } from "../../_"
28+
import {
29+
Component,
30+
getComponentElement,
31+
getComponentElements
32+
} from "../../_"
2933
import {
3034
IconSearchQuery,
3135
mountIconSearchQuery
@@ -64,6 +68,14 @@ export type IconSearch =
6468
| IconSearchQuery
6569
| IconSearchResult
6670

71+
/**
72+
* Icon search mode
73+
*/
74+
export type IconSearchMode =
75+
| "all"
76+
| "icons"
77+
| "emojis"
78+
6779
/* ----------------------------------------------------------------------------
6880
* Functions
6981
* ------------------------------------------------------------------------- */
@@ -87,8 +99,18 @@ export function mountIconSearch(
8799
const query = getComponentElement("iconsearch-query", el)
88100
const result = getComponentElement("iconsearch-result", el)
89101

102+
/* Retrieve select component */
103+
const mode$ = new BehaviorSubject<IconSearchMode>("all")
104+
const selects = getComponentElements("iconsearch-select", el)
105+
for (const select of selects) {
106+
fromEvent(select, "change").pipe(
107+
map(ev => (ev.target as HTMLSelectElement).value as IconSearchMode)
108+
)
109+
.subscribe(mode$)
110+
}
111+
90112
/* Create and return component */
91113
const query$ = mountIconSearchQuery(query)
92-
const result$ = mountIconSearchResult(result, { index$, query$ })
114+
const result$ = mountIconSearchResult(result, { index$, query$, mode$ })
93115
return merge(query$, result$)
94116
}

src/overrides/assets/javascripts/components/iconsearch/result/index.ts

+16-8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
Subject,
2727
bufferCount,
2828
combineLatest,
29+
combineLatestWith,
2930
distinctUntilKeyChanged,
3031
filter,
3132
finalize,
@@ -47,7 +48,7 @@ import { round } from "~/utilities"
4748
import { Icon, renderIconSearchResult } from "_/templates"
4849

4950
import { Component } from "../../_"
50-
import { IconSearchIndex } from "../_"
51+
import { IconSearchIndex, IconSearchMode } from "../_"
5152
import { IconSearchQuery } from "../query"
5253

5354
/* ----------------------------------------------------------------------------
@@ -71,6 +72,7 @@ export interface IconSearchResult {
7172
interface WatchOptions {
7273
index$: Observable<IconSearchIndex> /* Search index observable */
7374
query$: Observable<IconSearchQuery> /* Search query observable */
75+
mode$: Observable<IconSearchMode> /* Search mode observable */
7476
}
7577

7678
/**
@@ -79,6 +81,7 @@ interface WatchOptions {
7981
interface MountOptions {
8082
index$: Observable<IconSearchIndex> /* Search index observable */
8183
query$: Observable<IconSearchQuery> /* Search query observable */
84+
mode$: Observable<IconSearchMode> /* Search mode observable */
8285
}
8386

8487
/* ----------------------------------------------------------------------------
@@ -94,7 +97,7 @@ interface MountOptions {
9497
* @returns Icon search result observable
9598
*/
9699
export function watchIconSearchResult(
97-
el: HTMLElement, { index$, query$ }: WatchOptions
100+
el: HTMLElement, { index$, query$, mode$ }: WatchOptions
98101
): Observable<IconSearchResult> {
99102
switch (el.getAttribute("data-mdx-mode")) {
100103

@@ -131,9 +134,14 @@ export function watchIconSearchResult(
131134
query$.pipe(distinctUntilKeyChanged("value")),
132135
index$
133136
.pipe(
134-
map(({ icons, emojis }) => [
135-
...Object.keys(icons.data),
136-
...Object.keys(emojis.data)
137+
combineLatestWith(mode$),
138+
map(([{ icons, emojis }, mode]) => [
139+
...["all", "icons"].includes(mode)
140+
? Object.keys(icons.data)
141+
: [],
142+
...["all", "emojis"].includes(mode)
143+
? Object.keys(emojis.data)
144+
: []
137145
])
138146
)
139147
])
@@ -169,7 +177,7 @@ export function watchIconSearchResult(
169177
* @returns Icon search result component observable
170178
*/
171179
export function mountIconSearchResult(
172-
el: HTMLElement, { index$, query$ }: MountOptions
180+
el: HTMLElement, { index$, query$, mode$ }: MountOptions
173181
): Observable<Component<IconSearchResult, HTMLElement>> {
174182
const push$ = new Subject<IconSearchResult>()
175183
const boundary$ = watchElementBoundary(el)
@@ -178,7 +186,7 @@ export function mountIconSearchResult(
178186
)
179187

180188
/* Update search result metadata */
181-
const meta = getElement(":scope > :first-child", el)
189+
const meta = getElement(".mdx-iconsearch-result__meta", el)
182190
push$
183191
.pipe(
184192
withLatestFrom(query$)
@@ -228,7 +236,7 @@ export function mountIconSearchResult(
228236
))
229237

230238
/* Create and return component */
231-
return watchIconSearchResult(el, { query$, index$ })
239+
return watchIconSearchResult(el, { query$, index$, mode$ })
232240
.pipe(
233241
tap(state => push$.next(state)),
234242
finalize(() => push$.complete()),

src/overrides/assets/stylesheets/custom/layout/_iconsearch.scss

+32
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,38 @@
9090
right: px2rem(12px);
9191
font-size: px2rem(12.8px);
9292
color: var(--md-default-fg-color--lighter);
93+
94+
// [mobile portrait -]: Hide meta
95+
@include break-to-device(mobile portrait) {
96+
display: none;
97+
}
98+
}
99+
100+
// Icon search result select
101+
&__select {
102+
position: absolute;
103+
top: px2rem(8px);
104+
right: px2rem(12px);
105+
padding-block: 0.15em;
106+
font-size: px2rem(12.8px);
107+
color: var(--md-default-fg-color--light);
108+
background-color: var(--md-default-fg-color--lightest);
109+
border: none;
110+
border-radius: px2rem(2px);
111+
transition: color 125ms, background-color 125ms;
112+
113+
// Focused or hovered
114+
&:focus,
115+
&:hover {
116+
color: var(--md-accent-bg-color);
117+
background-color: var(--md-accent-fg-color);
118+
outline: none;
119+
}
120+
121+
// Adjust spacing
122+
+ .mdx-iconsearch-result__meta {
123+
right: px2rem(82px);
124+
}
93125
}
94126

95127
// Icon search result list

0 commit comments

Comments
 (0)