|
| 1 | +<!-- .vitepress/theme/components/SearchBox.vue --> |
| 2 | +<template> |
| 3 | + <div class="custom-search"> |
| 4 | + <button |
| 5 | + ref="searchButton" |
| 6 | + class="search-button" |
| 7 | + @click="openSearch" |
| 8 | + aria-label="搜索文档" |
| 9 | + > |
| 10 | + <svg |
| 11 | + xmlns="http://www.w3.org/2000/svg" |
| 12 | + viewBox="0 0 24 24" |
| 13 | + fill="none" |
| 14 | + stroke="currentColor" |
| 15 | + stroke-width="2" |
| 16 | + > |
| 17 | + <circle cx="11" cy="11" r="8"></circle> |
| 18 | + <path d="M21 21l-4.35-4.35"></path> |
| 19 | + </svg> |
| 20 | + <span class="DocSearch-Button-Placeholder">搜索文档...</span> |
| 21 | + </button> |
| 22 | + </div> |
| 23 | +</template> |
| 24 | + |
| 25 | +<script setup> |
| 26 | +const openSearch = async () => { |
| 27 | + const ele = document.getElementById("local-search").querySelector("button"); |
| 28 | + console.log("search", ele); |
| 29 | + ele.click(); |
| 30 | +}; |
| 31 | +</script> |
| 32 | + |
| 33 | +<style scoped> |
| 34 | +.custom-search { |
| 35 | + max-width: 580px; |
| 36 | + width: 100%; |
| 37 | + margin: 0 auto 32px; |
| 38 | + padding: 0 24px; |
| 39 | +} |
| 40 | +
|
| 41 | +.search-button { |
| 42 | + display: flex; |
| 43 | + align-items: center; |
| 44 | + width: 100%; |
| 45 | + padding: 10px 16px; |
| 46 | + background: var(--vp-c-bg-alt); |
| 47 | + border: 1px solid var(--vp-c-divider); |
| 48 | + border-radius: 8px; |
| 49 | + cursor: pointer; |
| 50 | + transition: all 0.25s ease; |
| 51 | + box-shadow: var(--vp-shadow-1); |
| 52 | + text-align: left; |
| 53 | +} |
| 54 | +
|
| 55 | +.search-button:hover { |
| 56 | + background: var(--vp-c-bg-soft); |
| 57 | + border-color: var(--vp-c-brand); |
| 58 | + box-shadow: var(--vp-shadow-2); |
| 59 | +} |
| 60 | +
|
| 61 | +.search-button:active { |
| 62 | + transform: translateY(1px); |
| 63 | +} |
| 64 | +
|
| 65 | +.search-button svg { |
| 66 | + width: 18px; |
| 67 | + height: 18px; |
| 68 | + margin-right: 12px; |
| 69 | + color: var(--vp-c-text-2); |
| 70 | + transition: color 0.25s ease; |
| 71 | +} |
| 72 | +
|
| 73 | +.search-button:hover svg { |
| 74 | + color: var(--vp-c-brand); |
| 75 | +} |
| 76 | +
|
| 77 | +.search-button span { |
| 78 | + font-size: 15px; |
| 79 | + color: var(--vp-c-text-2); |
| 80 | + transition: color 0.25s ease; |
| 81 | +} |
| 82 | +
|
| 83 | +.search-button:hover span { |
| 84 | + color: var(--vp-c-text-1); |
| 85 | +} |
| 86 | +
|
| 87 | +/* 在首页的特殊样式 */ |
| 88 | +.VPHero.has-image .custom-search { |
| 89 | + margin-top: 24px; |
| 90 | + margin-bottom: 48px; |
| 91 | +} |
| 92 | +
|
| 93 | +/* 响应式调整 */ |
| 94 | +@media (max-width: 768px) { |
| 95 | + .custom-search { |
| 96 | + padding: 0 16px; |
| 97 | + margin-bottom: 24px; |
| 98 | + } |
| 99 | +
|
| 100 | + .search-button { |
| 101 | + padding: 8px 14px; |
| 102 | + } |
| 103 | +
|
| 104 | + .search-button span { |
| 105 | + font-size: 14px; |
| 106 | + } |
| 107 | +} |
| 108 | +</style> |
0 commit comments