-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathRemark.astro
More file actions
146 lines (122 loc) · 2.77 KB
/
Remark.astro
File metadata and controls
146 lines (122 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
---
import Icon from "./Icon.astro";
import {
faAsterisk,
faCircleDot,
faExclamation,
faNoteSticky,
faPenRuler,
faTrashCan,
faWarning,
} from "@fortawesome/free-solid-svg-icons";
const TYPES = {
note: { displayName: "Note", icon: faNoteSticky },
warning: { displayName: "Warning", icon: faWarning },
important: { displayName: "Important", icon: faExclamation },
WIP: { displayName: "WIP", icon: faPenRuler },
deprecated: { displayName: "Deprecated", icon: faTrashCan },
issue: { displayName: "Issue", icon: faCircleDot },
recommendation: { displayName: "Recommendation", icon: faAsterisk },
};
type RemarkType =
| "note"
| "warning"
| "important"
| "WIP"
| "deprecated"
| "issue"
| "recommendation";
export interface Props {
type: RemarkType;
display?: "fit" | "block" | "compact";
}
const { type, display } = Astro.props;
const remark = TYPES[type];
if (!remark) {
throw new Error("Invalid remark type: " + type);
}
const classList = [type, "remark"];
if (display) {
classList.push(display);
} else {
// If display mode is not specified, fetch the slot text content length and determine best mode.
const content = await Astro.slots.render("default");
const text = content
.replace(/<[^>]*>/g, "")
.replace(/\s+/g, " ")
.trim();
if (text.length < 115) {
classList.push("compact");
} else {
classList.push("block");
}
}
---
<div class:list={classList}>
<div>
<Icon icon={remark.icon} />
{remark.displayName}
</div>
<div class="content">
<slot />
</div>
</div>
<style lang="scss">
.remark {
padding: 0.5em 1em;
border-radius: 0.4em;
border-width: 0.3em;
border-style: outset;
margin: 1em auto;
width: fit-content;
box-shadow: var(--remark-color) 0px 0px 0.75em 0px;
border-color: var(--remark-color);
background-color: color-mix(in srgb, var(--remark-color), #071521 80%);
&.block {
width: 95%;
}
&.compact {
display: flex;
align-items: center;
gap: 0.5em;
}
&.note {
--remark-color: #0099ff;
}
&.warning {
--remark-color: #c47c00;
}
&.important {
--remark-color: #ba0000;
}
&.deprecated {
--remark-color: #9320ff;
}
&.WIP {
--remark-color: #ff20d6;
}
&.issue {
--remark-color: #2ea043;
}
&.recommendation {
--remark-color: #1aecbe;
}
& > div:first-of-type {
font-size: 1.1em;
display: flex;
gap: 0.2em;
align-items: center;
font-weight: bold;
:global(i.fa-solid) {
margin-left: -0.3em;
font-size: 1.3em;
color: color-mix(in srgb, var(--remark-color), white 60%);
}
}
& > .content {
:global(p) {
margin: 0.1em auto;
}
}
}
</style>