All files / src/views/demo index.vue

0% Statements 0/24
0% Branches 0/7
0% Functions 0/10
0% Lines 0/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
<script setup>
import { ref, computed } from 'vue'
 
defineOptions({ name: 'Demo' })
import { Check, Moon, Sun } from '@lucide/vue'
import { useAppStore } from '@/stores/app'
import { PRESETS } from '@/theme/presets'
import Button from '@/components/ui/button/button.vue'
import ButtonDemo from '@/components/ui/demo/button.vue'
import ButtonGroupDemo from '@/components/ui/demo/button-group.vue'
import TabsDemo from '@/components/ui/demo/tabs.vue'
import PaginationDemo from '@/components/ui/demo/pagination.vue'
import InputDemo from '@/components/ui/demo/input.vue'
import CheckboxDemo from '@/components/ui/demo/checkbox.vue'
import RadioDemo from '@/components/ui/demo/radio.vue'
import SwitchDemo from '@/components/ui/demo/switch.vue'
import SelectDemo from '@/components/ui/demo/select.vue'
import DateDemo from '@/components/ui/demo/date.vue'
import FormDemo from '@/components/ui/demo/form.vue'
import PopoverDemo from '@/components/ui/demo/popover.vue'
import TooltipDemo from '@/components/ui/demo/tooltip.vue'
import MessageDemo from '@/components/ui/demo/message.vue'
import NotificationDemo from '@/components/ui/demo/notification.vue'
import ModalDemo from '@/components/ui/demo/modal.vue'
import DrawerDemo from '@/components/ui/demo/drawer.vue'
import SpinDemo from '@/components/ui/demo/spin.vue'
import GridDemo from '@/components/ui/demo/grid.vue'
import SplitterDemo from '@/components/ui/demo/splitter.vue'
import DropdownDemo from '@/components/ui/demo/dropdown.vue'
import TagDemo from '@/components/ui/demo/tag.vue'
import TreeDemo from '@/components/ui/demo/tree.vue'
 
/* ---------- 导航分类 ---------- */
const appStore = useAppStore()
const isDark = computed(() => appStore.darkMode)
function toggleDark() {
  appStore.toggleDark()
}
 
/* 主色选择:原 ColorThemePicker 组件逻辑内联 */
const activeColor = computed(() => appStore.primaryColor)
function pickColor(color) {
  appStore.setPrimary(color)
}
 
const activeKey = ref('button')
 
const categories = [
  {
    label: '通用',
    items: [
      { key: 'button', label: 'Button 按钮' },
      { key: 'button-group', label: 'ButtonGroup 按钮组' },
      { key: 'tabs', label: 'Tabs 标签页' },
      { key: 'pagination', label: 'Pagination 分页' },
    ],
  },
  {
    label: '数据录入',
    items: [
      { key: 'input', label: 'Input 输入框' },
      { key: 'checkbox', label: 'Checkbox 复选框' },
      { key: 'radio', label: 'Radio 单选框' },
      { key: 'switch', label: 'Switch 开关' },
      { key: 'select', label: 'Select 下拉选择' },
      { key: 'date', label: 'DatePicker 日期选择' },
      { key: 'form', label: 'Form 表单' },
    ],
  },
  {
    label: '数据展示',
    items: [
      { key: 'splitter', label: 'Splitter 分割面板' },
      { key: 'dropdown', label: 'Dropdown 下拉菜单' },
      { key: 'grid', label: 'Grid 栅格' },
      { key: 'tag', label: 'Tag 标签' },
      { key: 'tree', label: 'Tree 树形' },
    ],
  },
  {
    label: '反馈',
    items: [
      { key: 'popover', label: 'Popover 气泡卡片' },
      { key: 'tooltip', label: 'Tooltip 文字提示' },
      { key: 'message', label: 'Message 轻提示' },
      { key: 'notification', label: 'Notification 通知' },
      { key: 'modal', label: 'Modal 模态框' },
      { key: 'drawer', label: 'Drawer 抽屉' },
      { key: 'spin', label: 'Spin 加载中' },
    ],
  },
]
 
// key -> demo 组件映射,页面只做按需切换渲染
const demoMap = {
  button: ButtonDemo,
  'button-group': ButtonGroupDemo,
  tabs: TabsDemo,
  pagination: PaginationDemo,
  input: InputDemo,
  checkbox: CheckboxDemo,
  radio: RadioDemo,
  switch: SwitchDemo,
  select: SelectDemo,
  date: DateDemo,
  form: FormDemo,
  popover: PopoverDemo,
  tooltip: TooltipDemo,
  message: MessageDemo,
  notification: NotificationDemo,
  modal: ModalDemo,
  drawer: DrawerDemo,
  spin: SpinDemo,
  grid: GridDemo,
  splitter: SplitterDemo,
  dropdown: DropdownDemo,
  tag: TagDemo,
  tree: TreeDemo,
}
</script>
 
<template>
  <main class="app-shell">
    <header class="app-header">
      <div class="brand">
        <p class="eyebrow">FMS UI</p>
        <h1>基础组件</h1>
      </div>
 
      <div class="theme-controls">
        <div class="color-picker" role="group" aria-label="主题色">
          <button
            v-for="preset in PRESETS"
            :key="preset.color"
            class="swatch"
            type="button"
            :style="{ background: preset.color }"
            :aria-label="preset.name"
            :title="preset.name"
            :aria-pressed="activeColor === preset.color"
            @click="pickColor(preset.color)"
          >
            <Check v-if="activeColor === preset.color" class="check" />
          </button>
        </div>
        <Button
          type="ghost"
          class="theme-toggle-btn"
          :title="isDark ? '浅色模式' : '深色模式'"
          @click="toggleDark"
        >
          <component :is="isDark ? Moon : Sun" />
        </Button>
      </div>
    </header>
 
    <div class="app-body">
      <aside class="app-sidebar">
        <nav>
          <div v-for="cat in categories" :key="cat.label" class="nav-group">
            <p class="nav-group-title">{{ cat.label }}</p>
            <button
              v-for="item in cat.items"
              :key="item.key"
              type="button"
              class="nav-item"
              :class="{ 'nav-item-active': activeKey === item.key }"
              @click="activeKey = item.key"
            >
              {{ item.label }}
            </button>
          </div>
        </nav>
      </aside>
 
      <div class="app-content">
        <component :is="demoMap[activeKey]" :key="activeKey" />
      </div>
    </div>
  </main>
</template>
 
<style scoped>
.app-shell {
  min-height: 100vh;
  background: var(--fms-background);
  color: var(--fms-text);
  transition:
    background-color 200ms ease,
    color 200ms ease;
}
 
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 64px;
  padding: 0 32px;
  background: var(--fms-card);
  border-bottom: 1px solid var(--fms-border);
}
 
.brand h1 {
  margin: 2px 0 0;
  font-size: 24px;
  font-weight: 600;
}
 
.theme-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}
 
.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: var(--fms-control-radius);
  background: transparent;
  color: var(--fms-text);
  cursor: pointer;
  transition: background-color 150ms ease;
}
 
.theme-toggle-btn:hover {
  background: var(--fms-secondary-hover);
}
 
.theme-toggle-btn:focus-visible {
  outline: 2px solid var(--fms-primary);
  outline-offset: 2px;
}
 
.theme-toggle-btn svg {
  width: 16px;
  height: 16px;
}
 
/* 色板(原 ColorThemePicker 组件内联) */
.color-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
 
.swatch {
  position: relative;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  outline: 2px solid transparent;
  outline-offset: 1px;
  transition:
    outline-color 120ms ease,
    transform 120ms ease;
 
  &:hover {
    transform: scale(1.1);
  }
 
  &:focus-visible {
    outline-color: var(--fms-primary);
  }
}
 
.check {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 14px;
  height: 14px;
  color: #fff;
}
 
.app-body {
  display: flex;
  align-items: flex-start;
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
}
 
.app-sidebar {
  position: sticky;
  top: 64px;
  flex-shrink: 0;
  width: 200px;
  padding: 20px 12px 24px 16px;
}
 
.nav-group + .nav-group {
  margin-top: 20px;
}
 
.nav-group-title {
  margin: 0 0 8px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fms-text-secondary);
}
 
.nav-item {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border: none;
  border-radius: var(--fms-control-radius);
  background: transparent;
  color: var(--fms-text);
  font-size: 14px;
  line-height: var(--fms-line-height);
  text-align: left;
  cursor: pointer;
  transition:
    background-color 150ms ease,
    color 150ms ease;
}
 
.nav-item:hover {
  background: var(--fms-secondary-hover);
}
 
.nav-item-active {
  background: var(--fms-primary);
  color: var(--fms-primary-text);
}
 
.nav-item:focus-visible {
  outline: 2px solid var(--fms-primary);
  outline-offset: 2px;
}
 
.app-content {
  flex: 1;
  min-width: 0;
  padding: 32px;
}
 
@media (max-width: 768px) {
  .app-header {
    height: auto;
    min-height: 64px;
    flex-wrap: wrap;
    padding: 12px 16px;
  }
 
  .theme-controls {
    flex-wrap: wrap;
  }
 
  .app-body {
    flex-direction: column;
  }
 
  .app-sidebar {
    position: static;
    width: 100%;
    padding: 12px 16px;
    border-bottom: 1px solid var(--fms-border);
  }
 
  .app-content {
    padding: 24px 16px;
  }
}
 
@media (prefers-reduced-motion: reduce) {
  .app-shell,
  .nav-item {
    transition: none;
  }
}
</style>