Skip to content

Commit ab869cd

Browse files
authored
feat(Math): add background on hover (#103)
1. Fix error state 2. Change background on hover
1 parent b316f08 commit ab869cd

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

src/extensions/yfm/Math/view-and-edit.scss

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
}
1010

1111
.math-error {
12-
color: var(--yc-color-base-danger-heavy);
12+
color: var(--yc-color-text-danger);
13+
}
14+
15+
.math-block-view.math-view-error {
16+
display: flex;
17+
justify-content: center;
1318
}
1419

1520
.math-container.math-active .math-view {
@@ -29,8 +34,40 @@
2934
}
3035

3136
.math-container:not(.math-active) {
37+
--ye-math-back-color: transparent;
38+
--ye-math-hover-color: var(--yc-color-base-simple-hover);
39+
3240
position: relative;
3341

42+
&.math-container-error {
43+
--ye-math-back-color: var(--yc-color-base-danger);
44+
--ye-math-hover-color: var(--yc-color-base-danger-hover);
45+
}
46+
47+
&::before {
48+
position: absolute;
49+
z-index: -1;
50+
top: -2px;
51+
right: -2px;
52+
bottom: -2px;
53+
left: -2px;
54+
55+
content: '';
56+
57+
border-radius: var(--yc-border-radius-s);
58+
background-color: var(--ye-math-back-color);
59+
60+
transition: background-color 0.15s linear;
61+
}
62+
63+
&:hover {
64+
cursor: pointer;
65+
66+
&::before {
67+
background-color: var(--ye-math-hover-color);
68+
}
69+
}
70+
3471
.math-inline,
3572
.math-block {
3673
position: absolute;
@@ -39,6 +76,8 @@
3976
bottom: 0;
4077
left: 0;
4178

79+
overflow: hidden;
80+
4281
opacity: 0;
4382
}
4483

src/extensions/yfm/Math/view-and-edit.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,25 @@ export abstract class MathNodeView implements NodeView {
6565
protected renderKatex() {
6666
try {
6767
katex.render(this.texContent, this.mathViewDOM, {
68-
throwOnError: false,
68+
throwOnError: true,
6969
displayMode: this.isDisplayMode(),
7070
});
71+
this.updateErrorView(false);
7172
} catch (err) {
7273
const errorElem = document.createElement('span');
7374
errorElem.classList.add('math-error');
7475
errorElem.innerText = `(error) ${this.texContent}`;
7576
errorElem.title = String(err);
7677
this.mathViewDOM.appendChild(errorElem);
78+
this.updateErrorView(true);
7779
}
7880
}
7981

82+
protected updateErrorView(isError: boolean) {
83+
this.dom.classList.toggle('math-container-error', isError);
84+
this.mathViewDOM.classList.toggle('math-view-error', isError);
85+
}
86+
8087
protected getTexContent() {
8188
return this.node.textContent;
8289
}

0 commit comments

Comments
 (0)