组件
全局配置 Config Provider
ConfigProvider:提供设计令牌层 `[data-density]` 选择器定义的四个密度档位。密度只压缩留白和控件高度,不牺牲可读性。
#基础用法
Outside — the page's own density and ink
Brush, ink, paper, and the inkstone — the same furniture.
Inside — compact controls under the qinghua accent
Density and pigment are fixed in here — mode, scene and paper still ride the page around them.
<script setup lang="ts">
import { Button, Card, ConfigProvider } from "@bysages/vue";
</script>
<template>
<div class="grid gap-4 justify-items-start">
<Card.Root class="w-104">
<Card.Header>
<Card.Title>Outside — the page's own density and ink</Card.Title>
<Card.Description>
Brush, ink, paper, and the inkstone — the same furniture.
</Card.Description>
</Card.Header>
<Card.Content class="flex flex-wrap gap-[var(--bs-gap-sm)]">
<Button>Primary</Button>
<Button variant="ghost">Secondary</Button>
</Card.Content>
</Card.Root>
<ConfigProvider density="compact" accent="qinghua">
<Card.Root class="w-104">
<Card.Header>
<Card.Title>Inside — compact controls under the qinghua accent</Card.Title>
<Card.Description>
Density and pigment are fixed in here — mode, scene and paper still ride the page around
them.
</Card.Description>
</Card.Header>
<Card.Content class="flex flex-wrap gap-[var(--bs-gap-sm)]">
<Button>Primary</Button>
<Button variant="ghost">Secondary</Button>
</Card.Content>
</Card.Root>
</ConfigProvider>
</div>
</template>
Comfortable — the outer provider's tier
Local to this host element and its descendants.
Compact — the inner provider, its own scope only
The outer scope stays where it was.
<script setup lang="ts">
import { Button, Card, ConfigProvider } from "@bysages/vue";
const contentStyle = { display: "flex", flexWrap: "wrap", gap: "var(--bs-gap-sm)" };
const cardStyle = { inlineSize: "26rem" };
</script>
<template>
<ConfigProvider density="comfortable">
<div class="grid gap-4 justify-items-start">
<Card.Root :style="cardStyle">
<Card.Header>
<Card.Title>Comfortable — the outer provider's tier</Card.Title>
<Card.Description>Local to this host element and its descendants.</Card.Description>
</Card.Header>
<Card.Content :style="contentStyle">
<Button>Primary</Button>
<Button variant="ghost">Secondary</Button>
</Card.Content>
</Card.Root>
<ConfigProvider density="compact">
<Card.Root :style="cardStyle">
<Card.Header>
<Card.Title>Compact — the inner provider, its own scope only</Card.Title>
<Card.Description>The outer scope stays where it was.</Card.Description>
</Card.Header>
<Card.Content :style="contentStyle">
<Button>Primary</Button>
<Button variant="ghost">Secondary</Button>
</Card.Content>
</Card.Root>
</ConfigProvider>
</div>
</ConfigProvider>
</template>
#属性
#ConfigProvider
全局配置的声明式宿主。这个元素既承载设计令牌层属性([data-density] 与 [data-accent] 可放在任意元素上),又通过 useConfig 把同一组值提供给后代,使交互行为(格式化、消息)和视觉主题共用一个配置来源。
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
density | String as PropType<ConfigDensity> | undefined | — |
scene | String as PropType<ConfigScene> | undefined | — |
accent | String | undefined | — |
dir | String as PropType<"ltr" | "rtl"> | undefined | — |
locale | String | undefined | — |