@a2simcode/ui 0.0.59 → 0.0.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -212,11 +212,6 @@ export default {
212
212
  {
213
213
  "name": "TableColumnConfig",
214
214
  "properties": [
215
- {
216
- "name": "label",
217
- "type": "string",
218
- "description": "列的标题"
219
- },
220
215
  {
221
216
  "name": "width",
222
217
  "type": "number",
@@ -319,7 +314,7 @@ export default {
319
314
  },
320
315
  {
321
316
  "name": "config",
322
- "type": "TableColumnConfig & BaseCompConfig",
317
+ "type": "TableColumnCompConfig & {\n /**\n * @zh 列的标题\n */\n label: string\n }",
323
318
  "description": "列配置"
324
319
  },
325
320
  {
@@ -29,6 +29,20 @@
29
29
  </template>
30
30
  </Demo>
31
31
 
32
+ ## Icon 图标
33
+
34
+ 通过列类型 `j-icon` 可以渲染 SVG 图标。支持传入 SVG 字符串或 Iconify 图标名称。
35
+
36
+ <Demo :source-code="tableIconCode">
37
+ <template #source>
38
+ <table-icon />
39
+ </template>
40
+ <template #description>
41
+ 在 `columns` 中设置 `type: 'j-icon'`。数据可以是 SVG 字符串,也可以是 Iconify 图标名称(如 `mdi:home`)。
42
+ 可以通过 `config.size` 设置图标大小,`config.color` 设置图标颜色。
43
+ </template>
44
+ </Demo>
45
+
32
46
  ## 冻结列
33
47
 
34
48
  通过 `columns` 中的 `config.frozen` 属性设置列的冻结方式,支持 `left`(左侧冻结)和 `right`(右侧冻结)。
@@ -189,6 +203,7 @@
189
203
  <script setup>
190
204
  import TableBasic from '../examples/table/basic.vue'
191
205
  import TableTag from '../examples/table/tag.vue'
206
+ import TableIcon from '../examples/table/icon.vue'
192
207
  import TableFrozenColumn from '../examples/table/frozen-column.vue'
193
208
  import TableHeightMode from '../examples/table/height-mode.vue'
194
209
  import TableTreeColumn from '../examples/table/tree-column.vue'
@@ -204,6 +219,7 @@ import tableApi from './meta/table'
204
219
 
205
220
  import tableBasicCode from '../examples/table/basic.vue?raw'
206
221
  import tableTagCode from '../examples/table/tag.vue?raw'
222
+ import tableIconCode from '../examples/table/icon.vue?raw'
207
223
  import tableFrozenColumnCode from '../examples/table/frozen-column.vue?raw'
208
224
  import tableHeightModeCode from '../examples/table/height-mode.vue?raw'
209
225
  import tableTreeColumnCode from '../examples/table/tree-column.vue?raw'
@@ -0,0 +1,85 @@
1
+ <template>
2
+ <div style="position: relative; width: 100%; height: 300px">
3
+ <j-table v-if="iconsReady" :columns="columns" :records="records" />
4
+ </div>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ import { getIcon, iconLoaded, loadIcon } from '@iconify/vue'
9
+ import { onBeforeMount, ref } from 'vue'
10
+
11
+ const iconsReady = ref(false)
12
+
13
+ const browsers = [
14
+ { name: 'Chrome', icon: 'logos:chrome' },
15
+ { name: 'Firefox', icon: 'logos:firefox' },
16
+ { name: 'Safari', icon: 'logos:safari' },
17
+ { name: 'Edge', icon: 'logos:microsoft-edge' },
18
+ ]
19
+
20
+ const toSvg = (iconName: string) => {
21
+ const iconData = getIcon(iconName)
22
+ if (!iconData) return ''
23
+ return `<svg viewBox="0 0 ${iconData.width} ${iconData.height}">${iconData.body}</svg>`
24
+ }
25
+
26
+ const records = ref<Record<string, any>[]>([])
27
+
28
+ onBeforeMount(async () => {
29
+ // @ts-ignore
30
+ if (import.meta.env.SSR) {
31
+ iconsReady.value = true
32
+ return
33
+ }
34
+
35
+ const icons = browsers.map((item) => item.icon)
36
+
37
+ await Promise.all(
38
+ icons.map(async (icon) => {
39
+ if (!iconLoaded(icon)) {
40
+ await loadIcon(icon)
41
+ }
42
+ })
43
+ )
44
+
45
+ records.value = browsers.map((item) => {
46
+ return {
47
+ ...item,
48
+ svg: toSvg(item.icon),
49
+ }
50
+ })
51
+
52
+ iconsReady.value = true
53
+ })
54
+
55
+ const columns = ref([
56
+ {
57
+ id: 'name',
58
+ config: {
59
+ label: '浏览器',
60
+ width: 150,
61
+ align: 'left',
62
+ },
63
+ },
64
+ {
65
+ id: 'icon',
66
+ type: 'j-icon',
67
+ config: {
68
+ label: '图标(Iconify)',
69
+ width: 120,
70
+ align: 'center',
71
+ size: 24,
72
+ },
73
+ },
74
+ {
75
+ id: 'svg',
76
+ type: 'j-icon',
77
+ config: {
78
+ label: '图标(SVG)',
79
+ width: 120,
80
+ align: 'center',
81
+ size: 24,
82
+ },
83
+ },
84
+ ])
85
+ </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a2simcode/ui",
3
- "version": "0.0.59",
3
+ "version": "0.0.61",
4
4
  "description": "A Vue 3 UI Component Library",
5
5
  "type": "module",
6
6
  "main": "./dist/simcode-ui.umd.js",