Skip to content

Commit 4b2a97a

Browse files
committed
Added animation to content tabs
1 parent dffcba4 commit 4b2a97a

File tree

7 files changed

+74
-26
lines changed

7 files changed

+74
-26
lines changed

material/assets/javascripts/bundle.649a939e.min.js renamed to material/assets/javascripts/bundle.1cbe63b4.min.js

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

material/assets/javascripts/bundle.649a939e.min.js.map renamed to material/assets/javascripts/bundle.1cbe63b4.min.js.map

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

material/assets/stylesheets/main.8e8281cd.min.css renamed to material/assets/stylesheets/main.ffa0dd14.min.css

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

material/assets/stylesheets/main.8e8281cd.min.css.map renamed to material/assets/stylesheets/main.ffa0dd14.min.css.map

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

material/base.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
{% endif %}
3535
{% endblock %}
3636
{% block styles %}
37-
<link rel="stylesheet" href="{{ 'assets/stylesheets/main.8e8281cd.min.css' | url }}">
37+
<link rel="stylesheet" href="{{ 'assets/stylesheets/main.ffa0dd14.min.css' | url }}">
3838
{% if config.theme.palette %}
3939
{% set palette = config.theme.palette %}
4040
<link rel="stylesheet" href="{{ 'assets/stylesheets/palette.e6a45f82.min.css' | url }}">
@@ -213,7 +213,7 @@
213213
</script>
214214
{% endblock %}
215215
{% block scripts %}
216-
<script src="{{ 'assets/javascripts/bundle.649a939e.min.js' | url }}"></script>
216+
<script src="{{ 'assets/javascripts/bundle.1cbe63b4.min.js' | url }}"></script>
217217
{% for path in config["extra_javascript"] %}
218218
<script src="{{ path | url }}"></script>
219219
{% endfor %}

src/assets/javascripts/components/content/tabs/index.ts

+37-14
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ import {
2929
map,
3030
mapTo,
3131
merge,
32+
startWith,
3233
tap
3334
} from "rxjs"
3435

3536
import {
3637
getElement,
3738
getElementOffset,
39+
getElementSize,
3840
getElements
3941
} from "~/browser"
4042

@@ -65,15 +67,19 @@ export interface ContentTabs {
6567
export function watchContentTabs(
6668
el: HTMLElement
6769
): Observable<ContentTabs> {
68-
return merge(...getElements(":scope > input", el)
69-
.map(input => fromEvent(input, "change")
70-
.pipe(
71-
mapTo<ContentTabs>({
72-
active: getElement(`label[for=${input.id}]`)
73-
})
74-
)
70+
const inputs = getElements(":scope > input", el)
71+
return merge(...inputs.map(input => fromEvent(input, "change")
72+
.pipe(
73+
mapTo<ContentTabs>({
74+
active: getElement(`label[for=${input.id}]`)
75+
})
76+
)
77+
))
78+
.pipe(
79+
startWith({
80+
active: getElement(`label[for=${inputs[0].id}]`)
81+
} as ContentTabs)
7582
)
76-
)
7783
}
7884

7985
/**
@@ -94,12 +100,29 @@ export function mountContentTabs(
94100
const container = getElement(".tabbed-labels", el)
95101
return defer(() => {
96102
const push$ = new Subject<ContentTabs>()
97-
push$.subscribe(({ active }) => {
98-
const { x } = getElementOffset(active)
99-
container.scrollTo({
100-
behavior: "smooth",
101-
left: x
102-
})
103+
push$.subscribe({
104+
105+
/* Handle emission */
106+
next({ active }) {
107+
const offset = getElementOffset(active)
108+
const { width } = getElementSize(active)
109+
110+
/* Set tab indicator offset and width */
111+
el.style.setProperty("--md-indicator-x", `${offset.x}px`)
112+
el.style.setProperty("--md-indicator-width", `${width}px`)
113+
114+
/* Smoothly scroll container */
115+
container.scrollTo({
116+
behavior: "smooth",
117+
left: offset.x
118+
})
119+
},
120+
121+
/* Handle complete */
122+
complete() {
123+
el.style.removeProperty("--md-indicator-x")
124+
el.style.removeProperty("--md-indicator-width")
125+
}
103126
})
104127

105128
/* Create and return component */

src/assets/stylesheets/main/extensions/pymdownx/_tabbed.scss

+26-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,27 @@
8787
display: contents;
8888
}
8989

90+
// [js]: Show animated tab indicator
91+
.js & {
92+
position: relative;
93+
94+
// Tab indicator
95+
&::after {
96+
position: absolute;
97+
bottom: 0;
98+
display: block;
99+
width: var(--md-indicator-width);
100+
height: 2px;
101+
background: var(--md-accent-fg-color);
102+
transform: translateX(var(--md-indicator-x));
103+
transition:
104+
width 250ms,
105+
transform 250ms;
106+
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
107+
content: "";
108+
}
109+
}
110+
90111
// Webkit scrollbar
91112
&::-webkit-scrollbar {
92113
display: none; // Chrome, Safari
@@ -207,7 +228,11 @@
207228
// [screen]: Show active state
208229
@media screen {
209230
color: var(--md-accent-fg-color);
210-
border-color: var(--md-accent-fg-color);
231+
232+
// [no-js]: Show border (indicator is animated with JavaScript)
233+
.no-js & {
234+
border-color: var(--md-accent-fg-color);
235+
}
211236
}
212237
}
213238

0 commit comments

Comments
 (0)