Skip to content

TinyVue如何自定义设计规范

Kagol edited this page May 14, 2024 · 10 revisions

TinyVue提供了自定义设计规范的能力。

比如:我想修改Grid表格组件排序图标。

image

自定义设计规范步骤:

  1. 定义设计规范对象 design,包含name/version/components三个字段,我们要定制Grid组件的icon
  2. 给Grid组件外层包一个 ConfigProvider 组件,配置 design 属性

具体代码如下:

<script setup lang="ts">
import { ref } from 'vue'
import { Grid as TinyGrid, ConfigProvider as TinyConfigProvider } from '@opentiny/vue'
import { iconUp, iconDown } from '@opentiny/vue-icon'

const design = ref({
  name: 'element-ui', // 设计规范名称
  version: '1.0.0', // 设计规范版本号
  components: {
    Grid: {
      icons: {
        sortDefault: null,
        sortAsc: iconUp(),
        sortDesc: iconDown(),
      }
    }
  }
})
</script>

<template>
  <tiny-config-provider :design="design">
    <tiny-grid ...>
      ...
    </tiny-grid>
  </tiny-config-provider>
</template>

效果如下:

image

你可以在 Playground 代码演练场上查看效果。

Playground 代码演练场(展开并复制以下链接,粘贴到浏览器地址栏中访问) https://opentiny.design/vue-playground?mode=pc&theme=default#3.15|eyJzcmMvQXBwLnZ1ZSI6IjxzY3JpcHQgbGFuZz1cInRzeFwiPlxyXG4vLyDlvJXlhaUgQG9wZW50aW55L3Z1ZSDnu4Tku7ZcclxuaW1wb3J0IHsgQnV0dG9uLCBMaW5rIH0gZnJvbSAnQG9wZW50aW55L3Z1ZSdcclxuXHJcbmV4cG9ydCBkZWZhdWx0IHtcclxuICBjb21wb25lbnRzOiB7XHJcbiAgICBUaW55QnV0dG9uOiBCdXR0b24sXHJcbiAgICBUaW55TGluazogTGlua1xyXG4gIH0sXHJcbiAgZGF0YSgpIHtcclxuICAgIHJldHVybiB7XHJcbiAgICAgIG1zZzogJ2hlbGxvIHdvcmxkISdcclxuICAgIH1cclxuICB9XHJcbn1cclxuPC9zY3JpcHQ+XHJcblxyXG48dGVtcGxhdGU+XHJcbiAgPFRpbnlCdXR0b24+56Gu5a6aPC9UaW55QnV0dG9uPlxyXG4gIDxo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