Skip to content

Commit 166ef6b

Browse files
committed
feat: add customized bg-color support for component UsageTable
1 parent 85cba79 commit 166ef6b

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

.vitepress/theme/components/UsageTable.vue

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ const props = defineProps<{
88
left?: string
99
right?: string
1010
}
11+
colors?:{
12+
inputBg?: string
13+
outputBg?: string
14+
}
1115
}>()
1216
1317
const md = new MarkdownIt()
@@ -19,17 +23,17 @@ const renderList = computed(() => props.list)
1923
<div class="usage-table-container">
2024
<div class="wrapper">
2125
<!-- 左侧区域 -->
22-
<div class="section-correct">
26+
<div class="section-input">
2327
<!-- 自定义左侧标题 -->
2428
<div class="title">{{ labels?.left || 'Input' }}</div>
25-
<div v-for="(item, index) in renderList" :key="index" class="correct" v-html="item[0]" />
29+
<div v-for="(item, index) in renderList" :key="index" class="input" v-html="item[0]" :style="{ backgroundColor: props.colors?.inputBg }"/>
2630
</div>
2731

2832
<!-- 右侧区域 -->
29-
<div class="section-wrong">
33+
<div class="section-output">
3034
<!-- 自定义右侧标题 -->
3135
<div class="title">{{ labels?.right || 'Output' }}</div>
32-
<div v-for="(item, index) in renderList" :key="index" class="wrong">{{ item[1] }}</div>
36+
<div v-for="(item, index) in renderList" :key="index" class="output" :style="{ backgroundColor: props.colors?.outputBg }">{{ item[1] }}</div>
3337
</div>
3438
</div>
3539
</div>
@@ -58,27 +62,27 @@ const renderList = computed(() => props.list)
5862
height: auto;
5963
}
6064
61-
.section-correct .correct:not(:last-child),
62-
.section-wrong .wrong:not(:last-child){
65+
.section-input .input:not(:last-child),
66+
.section-output .output:not(:last-child){
6367
/* margin-bottom: 0.5rem; */
6468
padding-bottom: 0.5rem;
6569
border-bottom: 3px solid var(--glb-customtable-c-border);
6670
}
6771
68-
.section-correct .title {background-color: var(--glb-customtable-title-c-bg-lv1)}
69-
.section-wrong .title {background-color: var(--glb-customtable-title-c-bg-lv2)}
72+
.section-input .title {background-color: var(--glb-customtable-title-c-bg-lv1)}
73+
.section-output .title {background-color: var(--glb-customtable-title-c-bg-lv2)}
7074
71-
.section-correct,
72-
.section-wrong{
75+
.section-input,
76+
.section-output{
7377
display: flex;
7478
flex-direction: column;
7579
flex: 1; /* 平均分配宽度 */
7680
min-height: 0; /* 允许内容溢出时正常拉伸 */
7781
overflow: auto;
7882
}
7983
80-
.correct,
81-
.wrong{
84+
.input,
85+
.output{
8286
flex: 1; /* 让内容撑开容器并保持高度一致 */
8387
display: flex;
8488
flex-direction: column;
@@ -87,7 +91,7 @@ const renderList = computed(() => props.list)
8791
overflow: auto; /* 内容溢出时显示滚动条 */
8892
}
8993
90-
.wrapper .correct {
94+
.wrapper .input {
9195
flex: 2;
9296
background-color: var(--usagetable-c-bg-correct);
9397
color: var(--vp-c-text-1);
@@ -96,7 +100,7 @@ const renderList = computed(() => props.list)
96100
white-space: pre-wrap;
97101
}
98102
99-
.wrapper .wrong {
103+
.wrapper .output {
100104
flex: 2;
101105
background-color: var(--usagetable-c-bg-wrong);
102106
color: var(--vp-c-text-1);

0 commit comments

Comments
 (0)