|
1 | 1 | <script setup lang="ts"> |
| 2 | +import { ref } from 'vue' |
| 3 | +import { ScrollArea } from '#components' |
| 4 | +
|
2 | 5 | defineProps<{ name: string }>() |
| 6 | +
|
| 7 | +const expanded = ref(false) |
3 | 8 | </script> |
4 | 9 |
|
5 | 10 | <template> |
6 | 11 | <div class="vp-Example"> |
7 | | - <div class="vp-ExampleRun"> |
8 | | - <slot></slot> |
| 12 | + <div class="vp-ExampleComponent"> |
| 13 | + <ScrollArea scrollbars="horizontal"> |
| 14 | + <slot></slot> |
| 15 | + </ScrollArea> |
9 | 16 | </div> |
10 | | - <div class="vp-ExampleSource"> |
11 | | - <slot name="source"></slot> |
| 17 | + <div class="vp-ExampleSource" :data-expanded="expanded"> |
| 18 | + <ScrollArea scrollbars="horizontal"> |
| 19 | + <slot name="source"></slot> |
| 20 | + </ScrollArea> |
12 | 21 | </div> |
| 22 | + <button class="vp-ExampleAction" @click.prevent="expanded = !expanded"> |
| 23 | + <span v-if="expanded">Hide code</span> |
| 24 | + <span v-else>Show code</span> |
| 25 | + </button> |
13 | 26 | </div> |
14 | 27 | </template> |
15 | 28 |
|
16 | 29 | <style> |
| 30 | +:root { |
| 31 | + --example-mask: linear-gradient(#fff0, #fff9); |
| 32 | +} |
| 33 | +.dark { |
| 34 | + --example-mask: linear-gradient(#0000, #0009); |
| 35 | +} |
17 | 36 | .vp-Example { |
18 | 37 | margin-top: var(--space-4); |
19 | 38 | margin-bottom: var(--space-6); |
20 | 39 | border: 1px solid var(--gray-a4); |
21 | 40 | border-radius: var(--radius-4); |
| 41 | + overflow: hidden; |
22 | 42 | } |
23 | | -.vp-ExampleRun { |
24 | | - padding: var(--space-4); |
| 43 | +.vp-ExampleComponent { |
25 | 44 | border-bottom: 1px solid var(--gray-a4); |
| 45 | + width: 100%; |
| 46 | + box-sizing: border-box; |
| 47 | +} |
| 48 | +.vp-ExampleComponent .ui-ScrollAreaViewport { |
| 49 | + padding: var(--space-3) var(--space-4); |
26 | 50 | } |
27 | 51 | .vp-ExampleSource { |
28 | 52 | --vp-code-block-bg: transparent; |
29 | 53 | --vp-code-line-height: 1.6; |
30 | 54 | --vp-code-font-size: 14px; |
31 | | - background: var(--accent-a2); |
| 55 | + position: relative; |
| 56 | + display: flex; |
| 57 | + flex-direction: column; |
| 58 | + outline: 0; |
| 59 | +} |
| 60 | +.vp-ExampleSource[data-expanded="false"]:before { |
| 61 | + position: absolute; |
| 62 | + content: ""; |
| 63 | + pointer-events: none; |
| 64 | + background: var(--example-mask); |
| 65 | + height: 7.5rem; |
| 66 | + bottom: 0; |
| 67 | + left: 0; |
| 68 | + right: 0; |
| 69 | + z-index: 10; |
32 | 70 | } |
33 | | -.vp-ExampleSource div.language-vue { |
34 | | - margin-top: 0; |
35 | | - margin-bottom: 0; |
| 71 | +.vp-ExampleSource[data-expanded="false"] .ui-ScrollAreaViewport { |
| 72 | + max-height: calc(8.75lh + .5rem); |
| 73 | + overflow: hidden; |
| 74 | +} |
| 75 | +.vp-Example .vp-ExampleSource div.language-vue { |
| 76 | + margin: 0; |
| 77 | +} |
| 78 | +.vp-Example .vp-ExampleSource pre.shiki { |
| 79 | + padding-top: var(--space-2); |
| 80 | + padding-bottom: var(--space-2); |
| 81 | +} |
| 82 | +.vp-Example .vp-ExampleSource .shiki code { |
| 83 | + padding-left: var(--space-4); |
| 84 | + padding-right: var(--space-4); |
36 | 85 | } |
37 | 86 | .vp-ExampleSource span.lang { |
38 | 87 | display: none; |
39 | 88 | } |
| 89 | +.vp-ExampleSource button.copy { |
| 90 | + width: 28px !important; |
| 91 | + height: 28px !important; |
| 92 | + background-size: 14px !important; |
| 93 | +} |
| 94 | +.vp-ExampleSource button.copy:before { |
| 95 | + height: 28px !important; |
| 96 | +} |
| 97 | +.vp-ExampleAction { |
| 98 | + width: 100%; |
| 99 | + font-size: 13px; |
| 100 | + border-top: 1px solid var(--gray-a4); |
| 101 | + background: var(--gray-2); |
| 102 | + color: var(--gray-11); |
| 103 | + padding: var(--space-1); |
| 104 | +} |
40 | 105 | </style> |
0 commit comments