|
| 1 | +<script setup lang="ts"> |
| 2 | +import { ref } from "vue"; |
| 3 | +import VueSelect from "../../src/Select.vue"; |
| 4 | +
|
| 5 | +const options = [ |
| 6 | + { label: "France", value: "FR" }, |
| 7 | + { label: "Germany", value: "DE" }, |
| 8 | + { label: "Spain", value: "ES" }, |
| 9 | + { label: "Italy", value: "IT" }, |
| 10 | + { label: "Portugal", value: "PT" }, |
| 11 | +]; |
| 12 | +
|
| 13 | +const selected = ref<string | null>(null); |
| 14 | +</script> |
| 15 | + |
| 16 | +<template> |
| 17 | + <div class="demo-container"> |
| 18 | + <h2>Menu Positioning with data-state-position</h2> |
| 19 | + <p> |
| 20 | + The dropdown menu includes a <code>data-state-position</code> attribute that reflects |
| 21 | + its current position. This demo shows how the attribute changes based on available space. |
| 22 | + </p> |
| 23 | + |
| 24 | + <div class="demo-section"> |
| 25 | + <h3>Normal Position (bottom-start)</h3> |
| 26 | + <p>Scroll down to see the menu flip to the top when there's no space below.</p> |
| 27 | + <VueSelect |
| 28 | + v-model="selected" |
| 29 | + :options="options" |
| 30 | + placeholder="Select a country" |
| 31 | + class="custom-position-demo" |
| 32 | + /> |
| 33 | + </div> |
| 34 | + |
| 35 | + <div style="height: 100vh; display: flex; align-items: center;"> |
| 36 | + <div class="demo-section"> |
| 37 | + <h3>Middle of Page</h3> |
| 38 | + <p>The menu should open downward here.</p> |
| 39 | + <VueSelect |
| 40 | + v-model="selected" |
| 41 | + :options="options" |
| 42 | + placeholder="Select a country" |
| 43 | + class="custom-position-demo" |
| 44 | + /> |
| 45 | + </div> |
| 46 | + </div> |
| 47 | + |
| 48 | + <div style="height: 100vh; display: flex; align-items: flex-end; padding-bottom: 50px;"> |
| 49 | + <div class="demo-section"> |
| 50 | + <h3>Bottom of Page (menu flips to top-start)</h3> |
| 51 | + <p>The menu should open upward here with different styling.</p> |
| 52 | + <VueSelect |
| 53 | + v-model="selected" |
| 54 | + :options="options" |
| 55 | + placeholder="Select a country" |
| 56 | + class="custom-position-demo" |
| 57 | + /> |
| 58 | + </div> |
| 59 | + </div> |
| 60 | + </div> |
| 61 | +</template> |
| 62 | + |
| 63 | +<style scoped> |
| 64 | +.demo-container { |
| 65 | + padding: 20px; |
| 66 | + max-width: 600px; |
| 67 | +} |
| 68 | +
|
| 69 | +.demo-section { |
| 70 | + margin-bottom: 30px; |
| 71 | + width: 100%; |
| 72 | +} |
| 73 | +
|
| 74 | +h2 { |
| 75 | + margin-bottom: 10px; |
| 76 | +} |
| 77 | +
|
| 78 | +h3 { |
| 79 | + margin-top: 20px; |
| 80 | + margin-bottom: 10px; |
| 81 | + font-size: 18px; |
| 82 | +} |
| 83 | +
|
| 84 | +p { |
| 85 | + margin-bottom: 15px; |
| 86 | + color: #666; |
| 87 | +} |
| 88 | +
|
| 89 | +code { |
| 90 | + background-color: #f4f4f5; |
| 91 | + padding: 2px 6px; |
| 92 | + border-radius: 3px; |
| 93 | + font-family: monospace; |
| 94 | + font-size: 14px; |
| 95 | +} |
| 96 | +
|
| 97 | +:deep(.custom-position-demo) { |
| 98 | + --vs-border-radius: 8px; |
| 99 | +} |
| 100 | +
|
| 101 | +/* Style menu differently based on position */ |
| 102 | +:deep(.menu[data-state-position^="top"]) { |
| 103 | + border-bottom-left-radius: 0; |
| 104 | + border-bottom-right-radius: 0; |
| 105 | + border-top-left-radius: 8px; |
| 106 | + border-top-right-radius: 8px; |
| 107 | + box-shadow: 0 -4px 6px -1px rgb(0 0 0 / 0.1); |
| 108 | +} |
| 109 | +
|
| 110 | +:deep(.menu[data-state-position^="bottom"]) { |
| 111 | + border-top-left-radius: 0; |
| 112 | + border-top-right-radius: 0; |
| 113 | + border-bottom-left-radius: 8px; |
| 114 | + border-bottom-right-radius: 8px; |
| 115 | + box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1); |
| 116 | +} |
| 117 | +
|
| 118 | +/* Add visual indicator for position */ |
| 119 | +:deep(.menu[data-state-position="bottom-start"]::before) { |
| 120 | + content: "↓ bottom-start"; |
| 121 | + position: absolute; |
| 122 | + top: 4px; |
| 123 | + right: 8px; |
| 124 | + font-size: 10px; |
| 125 | + color: #999; |
| 126 | + font-weight: 500; |
| 127 | + text-transform: uppercase; |
| 128 | + letter-spacing: 0.5px; |
| 129 | +} |
| 130 | +
|
| 131 | +:deep(.menu[data-state-position="top-start"]::before) { |
| 132 | + content: "↑ top-start"; |
| 133 | + position: absolute; |
| 134 | + bottom: 4px; |
| 135 | + right: 8px; |
| 136 | + font-size: 10px; |
| 137 | + color: #999; |
| 138 | + font-weight: 500; |
| 139 | + text-transform: uppercase; |
| 140 | + letter-spacing: 0.5px; |
| 141 | +} |
| 142 | +</style> |
0 commit comments