@@ -8,6 +8,7 @@ const TYPES = {
88 WIP: { displayName: " WIP" , icon: " pen-ruler" },
99 deprecated: { displayName: " Deprecated" , icon: " trash-can" },
1010 issue: { displayName: " Issue" , icon: " circle-dot" },
11+ recommendation: {displayName: " Recommendation" , icon: " asterisk" }
1112};
1213
1314type RemarkType =
@@ -16,7 +17,8 @@ type RemarkType =
1617 | " important"
1718 | " WIP"
1819 | " deprecated"
19- | " issue" ;
20+ | " issue"
21+ | " recommendation"
2022
2123export interface Props {
2224 type: RemarkType ;
@@ -31,15 +33,31 @@ if (!remark) {
3133 throw new Error (" Invalid remark type: " + type );
3234}
3335
34- const classList = [type , " remark" , display ?? " block" ];
36+ const classList = [type , " remark" ];
37+
38+ if (display ) {
39+ classList .push (display );
40+ } else {
41+ // If display mode is not specified, fetch the slot text content length and determine best mode.
42+ const content = await Astro .slots .render (" default" );
43+ const text = content .replace (/ <[^ >] * >/ g , " " ).replace (/ \s + / g , ' ' ).trim ();
44+
45+ if (text .length < 115 ) {
46+ classList .push (" compact" );
47+ } else {
48+ classList .push (" block" );
49+ }
50+ }
3551---
3652
3753<div class:list ={ classList } >
3854 <div >
3955 <Icon name ={ remark .icon } group =" solid" />
4056 { remark .displayName }
4157 </div >
42- <slot />
58+ <div class =" content" >
59+ <slot />
60+ </div >
4361</div >
4462
4563<style lang =" scss" >
@@ -55,17 +73,13 @@ const classList = [type, "remark", display ?? "block"];
5573 background-color: color-mix(in srgb, var(--remark-color), #071521 80%);
5674
5775 &.block {
58- width: 90 %;
76+ width: 95 %;
5977 }
6078
6179 &.compact {
6280 display: flex;
6381 align-items: center;
6482 gap: 0.5em;
65-
66- & > :global(*) {
67- margin: 0px;
68- }
6983 }
7084
7185 &.note {
@@ -92,21 +106,28 @@ const classList = [type, "remark", display ?? "block"];
92106 --remark-color: #2ea043;
93107 }
94108
95- & > div {
109+ &.recommendation {
110+ --remark-color: #1aecbe;
111+ }
112+
113+ & > div:first-of-type {
96114 font-size: 1.1em;
97115 display: flex;
98- gap: 0.5em ;
116+ gap: 0.2em ;
99117 align-items: center;
100118 font-weight: bold;
101- }
102119
103- :global(i.fa-solid) {
104- font-size: 1.3em;
105- color: color-mix(in srgb, var(--remark-color), white 60%);
120+ :global(i.fa-solid) {
121+ margin-left: -0.3em;
122+ font-size: 1.3em;
123+ color: color-mix(in srgb, var(--remark-color), white 60%);
124+ }
106125 }
107126
108- & > :global(p) {
109- margin: 0.5em auto 0.2em auto;
127+ & > .content {
128+ :global(p) {
129+ margin: 0.1em auto;
130+ }
110131 }
111132 }
112133</style >
0 commit comments