Skip to content

Commit 0afb29f

Browse files
committed
Improve anchor in title and refItem
1 parent b3fe7fe commit 0afb29f

File tree

6 files changed

+65
-19
lines changed

6 files changed

+65
-19
lines changed

themes/opentermsarchive/assets/css/components/refItem.css

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
box-shadow: inset 0 1px var(--colorBlack200);
77
}
88

9+
.refItem-name {
10+
position: relative;
11+
display: flex;
12+
align-items: center;
13+
gap: 0.5rem;
14+
color:inherit
15+
}
16+
917
.refItem-name code {
1018
font-weight: 600;
1119
overflow-y: auto;
@@ -27,6 +35,26 @@
2735
font-weight: 400;
2836
}
2937

38+
.refItem-anchor-icon {
39+
opacity: 0;
40+
color: var(--colorBlack600);
41+
text-decoration: none;
42+
transition: opacity 0.1s ease;
43+
}
44+
45+
.refItem-name:hover .refItem-anchor-icon {
46+
opacity: 1;
47+
}
48+
49+
.refItem-anchor-icon:hover {
50+
color: var(--colorBlack800);
51+
}
52+
53+
.refItem-anchor-icon {
54+
width: 1em;
55+
height: 1em;
56+
}
57+
3058
.refItem-details {
3159
display: flex;
3260
}

themes/opentermsarchive/assets/css/elements/syntax.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/* Background */ .bg { background-color: var(--colorBlack200); }
2-
/* PreWrapper */ .chroma { background-color: var(--colorBlack200); font-size: 1.4rem; }
1+
/* Background */ .bg { background-color: var(--colorBlack100); border-radius: 0.2em; }
2+
/* PreWrapper */ .chroma { background-color: var(--colorBlack100); font-size: 1.4rem; border-radius: 0.2em;}
33
/* Other */ .chroma .x { }
44
/* Error */ .chroma .err { color: var(--colorError); }
55
/* CodeLine */ .chroma .cl { }
@@ -72,11 +72,11 @@
7272
/* CommentPreproc */ .chroma .cp { color: #67707b; font-style: italic }
7373
/* CommentPreprocFile */ .chroma .cpf { color: #67707b; font-style: italic }
7474
/* Generic */ .chroma .g { }
75-
/* GenericDeleted */ .chroma .gd { }
75+
/* GenericDeleted */ .chroma .gd { background-color: rgb(255, 206, 203); }
7676
/* GenericEmph */ .chroma .ge { }
7777
/* GenericError */ .chroma .gr { }
7878
/* GenericHeading */ .chroma .gh { }
79-
/* GenericInserted */ .chroma .gi { }
79+
/* GenericInserted */ .chroma .gi { background-color: rgb(172, 238, 187); }
8080
/* GenericOutput */ .chroma .go { }
8181
/* GenericPrompt */ .chroma .gp { }
8282
/* GenericStrong */ .chroma .gs { }

themes/opentermsarchive/assets/css/elements/titles.css

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,26 @@ h6,
120120
line-height: 1.25;
121121
}
122122

123+
.title-link {
124+
color: inherit;
125+
text-decoration: none;
126+
}
127+
128+
.title-link:hover {
129+
color: inherit;
130+
}
131+
123132
.title-anchor {
124-
color: var(--colorBlack400);
125133
font-size: 0.8em;
126134
font-weight: normal;
127-
display: none;
135+
opacity: 0;
136+
transition: opacity 0.1s ease;
128137
}
129138

130139
h2, h3, h4, h5, h6 {
131-
&:hover {
132-
a.title-anchor {
133-
display: inline;
140+
.title-link:hover {
141+
.title-anchor {
142+
opacity: 1;
134143
}
135144
}
136145
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import {
22
ChevronDown,
33
X,
4-
4+
Link,
55
createIcons,
66
} from 'lucide';
77

88
createIcons({
99
icons: {
1010
X,
1111
ChevronDown,
12+
Link,
1213
},
1314
attrs: { 'aria-hidden': true },
1415
});
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<h{{ .Level }} id="{{ .Anchor }}">
2+
{{ if ne .Level 1 }}
3+
<a class="title-link" href="#{{ .Anchor }}">
4+
{{ end }}
25
{{ .Text | safeHTML }}
36
{{ if ne .Level 1 }}
4-
<a class="title-anchor" href="#{{ .Anchor }}">🔗</a>
7+
<i class="title-anchor icon" data-lucide="link"></i>
8+
</a>
59
{{ end }}
10+
11+
612
</h{{ .Level }}>

themes/opentermsarchive/layouts/shortcodes/refItem.html

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77
{{/* Get description either from attribute or nested content */}}
88
{{ $description := .Get "description" }}
99
{{ $example := .Get "example" }}
10+
{{ $anchorID := $name | lower | replaceRE "[^a-z0-9-]" "-" | replaceRE "-+" "-" | replaceRE "^-" "" | replaceRE "-$" "" }}
1011

11-
<div class="refItem">
12-
<div class="refItem-name">
13-
<code>{{ $name }}</code>
14-
<span class="refItem-type">{{ $type }}</span>
15-
{{ with $required }}
16-
<span class="refItem-required">{{ if eq . true }}required{{ else }}{{ . | markdownify }}{{ end }}</span>
17-
{{ end }}
18-
</div>
12+
<div class="refItem" id="ref-{{ $anchorID }}">
13+
<a href="#ref-{{ $anchorID }}" class="refItem-name">
14+
<code>{{ $name }}</code>
15+
<span class="refItem-type">{{ $type }}</span>
16+
{{ with $required }}
17+
<span class="refItem-required">{{ if eq . true }}required{{ else }}{{ . | markdownify }}{{ end }}</span>
18+
{{ end }}
19+
<i class="refItem-anchor-icon icon" data-lucide="link"></i>
20+
</a>
1921
<div class="refItem-description">{{ $description | markdownify | safeHTML }}</div>
2022
<div class="refItem-details refItem-details__{{ if .Inner }}full{{ end }}">
2123
{{ if $default }}

0 commit comments

Comments
 (0)