@@ -12,6 +12,17 @@ const props = defineProps<{
1212 link? : string
1313}>()
1414
15+ const content = useTemplateRef (' content' )
16+ useScrollbar (content , {
17+ overflow: {
18+ y: ' hidden'
19+ },
20+ scrollbars: {
21+ autoHideDelay: 0 ,
22+ clickScroll: true
23+ }
24+ })
25+
1526const prismAlias: Record <string , string > = {
1627 vue: ' html'
1728}
@@ -57,6 +68,7 @@ const highlighted = computed(() => {
5768})
5869
5970const code = computed (() => props .code )
71+ const lines = computed (() => props .code .split (' \n ' ).length )
6072const copy = useCopy (code )
6173
6274function handleCopy() {
@@ -74,40 +86,55 @@ function handleClick(event: MouseEvent) {
7486<template >
7587 <section class =" tp-code" >
7688 <header class =" tp-row tp-row-justify tp-code-header" >
77- {{ title }}
89+ < h3 class = " tp-code-title " > {{ title }}</ h3 >
7890 <div class =" tp-row tp-gap" >
7991 <slot name =" actions" />
80- <IconButton variant = " secondary " title =" Copy" @click =" handleCopy" >
92+ <IconButton title =" Copy" @click =" handleCopy" >
8193 <Copy />
8294 </IconButton >
8395 </div >
8496 </header >
85- <pre class =" tp-code-content" ><code v-html =" highlighted" @click =" handleClick" /></pre >
97+ <div class =" tp-code-block" >
98+ <div class =" tp-code-line-numbers" >
99+ <div class =" tp-code-line-number" v-for =" i in lines" :key =" i" >{{ i }}</div >
100+ </div >
101+ <pre
102+ class =" tp-code-content"
103+ ref =" content"
104+ ><code v-html =" highlighted" @click =" handleClick" /></pre >
105+ </div >
86106 </section >
87107</template >
88108
89109<style scoped>
90- .tp-code {
91- border-radius : 2px ;
92- background-color : var (--color-bg-secondary );
93- }
94-
95110.tp-code-header {
96- height : 40px ;
97- padding : 4px 4px 4px 12px ;
98- font-weight : 500 ;
99- color : var (--color-text-secondary );
100- user-select : none ;
101- cursor : default ;
102- min-width : 0 ;
111+ width : 100% ;
112+ min-height : 32px ;
113+ border-radius : var (--radius-medium ) var (--radius-medium ) 0 0 ;
114+ padding : 0 ;
115+ background-color : var (--color-bg );
103116 text-overflow : ellipsis ;
104117 overflow : hidden ;
105118 white-space : nowrap ;
119+ user-select : none ;
120+ cursor : default ;
106121}
107122
108- .tp-code-content {
109- border-top : 1px solid var (--color-border , rgba (0 , 0 , 0 , 0.1 ));
110- padding : 4px 12px ;
123+ .tp-code-title {
124+ padding : 8px 0 ;
125+ font-weight : 400 ;
126+ color : var (--color-text );
127+ margin : 0 ;
128+ }
129+
130+ .tp-code-block {
131+ display : flex ;
132+ flex-direction : row ;
133+ background-color : transparent ;
134+ border-radius : var (--radius-medium , 2px );
135+ box-shadow : 0 0 0 1px var (--color-border-code-well );
136+ margin : 1px 0 ;
137+ padding : 8px 0 0 ;
111138 -webkit-font-smoothing : antialiased ;
112139 font-family :
113140 Roboto Mono,
@@ -118,9 +145,39 @@ function handleClick(event: MouseEvent) {
118145 line-height : 18px ;
119146 font-size : 11px ;
120147 letter-spacing : 0.005em ;
148+ }
149+
150+ .tp-code-line-numbers {
151+ display : flex ;
152+ flex-direction : column ;
153+ min-width : 20px ;
154+ border-radius : 2px 0 0 2px ;
155+ flex-shrink : 0 ;
156+ margin-top : -8px ;
157+ padding-top : 8px ;
158+ border-right : 1px solid var (--color-border-code-well );
159+ }
160+
161+ .tp-code-line-number {
162+ min-width : 12px ;
163+ color : var (--color-text-tertiary );
164+ display : flex ;
165+ align-items : center ;
166+ justify-content : end ;
167+ padding-right : 4px ;
168+ padding-left : 4px ;
169+ }
170+
171+ .tp-code-content {
172+ padding-left : 6px ;
173+ padding-bottom : 8px ;
121174 overflow-x : auto ;
122175}
123176
177+ .tp-code-content :has (.os-scrollbar-visible ) {
178+ padding-bottom : 16px ;
179+ }
180+
124181.tp-code-content ::selection {
125182 background-color : var (--color-texthighlight , #0d99ff );
126183}
@@ -139,7 +196,8 @@ function handleClick(event: MouseEvent) {
139196 color : var (--color-text );
140197}
141198
142- .tp-code-content .token.plain {
199+ .tp-code-content .token.plain ,
200+ .tp-code-content .token.color {
143201 color : var (--color-codevalue );
144202}
145203
0 commit comments