Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit ef822d9

Browse files
committed
feat: consume internal icons
1 parent cd5ffeb commit ef822d9

File tree

8 files changed

+83
-15
lines changed

8 files changed

+83
-15
lines changed
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
<template>
22
<div>
3-
<c-icon> HELLO ALERT </c-icon>
3+
<c-icon name="star" />
44
</div>
55
</template>
66

77
<script lang="ts">
8-
// import { CIcon } from '@chakra-ui/c-icon/src'
9-
// import { defineComponent } from 'vue'
8+
import { CIcon } from '@chakra-ui/c-icon/src'
9+
import { defineComponent } from 'vue'
1010
11-
// export default defineComponent({
12-
// components: { CIcon },
13-
// })
14-
//
11+
export default defineComponent({
12+
components: { CIcon },
13+
})
1514
</script>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<template>
2+
<div>
3+
<c-icon color="red.400" size="10" name="phone" />
4+
</div>
5+
</template>
6+
7+
<script lang="ts">
8+
import { CIcon } from '@chakra-ui/c-icon/src'
9+
import { defineComponent } from 'vue'
10+
11+
export default defineComponent({
12+
components: { CIcon },
13+
})
14+
</script>

packages/c-icon/examples/with-icon-library.vue

Whitespace-only changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<template>
2+
<div>
3+
<c-icon name="phone" />
4+
<c-icon size="6" name="email" />
5+
<c-icon size="10" name="sun" />
6+
<c-icon size="14" name="moon" />
7+
</div>
8+
</template>
9+
10+
<script lang="ts">
11+
import { CIcon } from '@chakra-ui/c-icon/src'
12+
import { defineComponent } from 'vue'
13+
14+
export default defineComponent({
15+
components: { CIcon },
16+
})
17+
</script>

packages/c-icon/src/icon.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
import { h, defineComponent, PropType } from 'vue'
2-
import { chakra, DOMElements } from '@chakra-ui/vue-system'
1+
import { h, defineComponent, PropType, computed } from 'vue'
2+
import {
3+
chakra,
4+
DOMElements,
5+
StyleAndHTMLAttibutes,
6+
} from '@chakra-ui/vue-system'
37
import { InternalIcon } from './icon.internals'
8+
import internalIcons from './icon.internals'
49

510
const fallbackIcon: InternalIcon = {
611
path: `
@@ -25,10 +30,29 @@ export const CIcon = defineComponent({
2530
props: {
2631
as: {
2732
type: [Object, String] as PropType<DOMElements>,
28-
default: 'div',
33+
default: 'svg',
34+
},
35+
name: {
36+
type: [String] as PropType<string>,
37+
},
38+
size: {
39+
type: [String] as PropType<string>,
40+
default: '1em',
2941
},
3042
},
3143
setup(props, { slots, attrs }) {
32-
return () => h(chakra(props.as), { ...attrs }, slots)
44+
const vnodeProps = computed<StyleAndHTMLAttibutes>(() => ({
45+
w: props.size,
46+
h: props.size,
47+
display: 'inline-block',
48+
lineHeight: '1em',
49+
flexShrink: 0,
50+
color: 'currentColor',
51+
innerHTML:
52+
internalIcons[props?.name as string]?.path || fallbackIcon.path,
53+
viewBox: fallbackIcon.viewBox,
54+
}))
55+
56+
return () => h(chakra(props.as), { ...vnodeProps.value, ...attrs }, slots)
3357
},
3458
})

packages/system/src/system.attrs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from '@chakra-ui/styled-system'
88
import { HTMLAttributes } from 'vue'
99

10-
type StyleAndHTMLAttibutes = StyleObjectOrFn &
10+
export type StyleAndHTMLAttibutes = StyleObjectOrFn &
1111
Record<string, string | number | boolean | unknown> &
1212
HTMLAttributes
1313

playground/src/.generated/imports.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ import Component_5 from '@chakra-ui/c-alert/examples/with-status.vue'
66
import Component_6 from '@chakra-ui/c-alert/examples/with-title.vue'
77
import Component_7 from '@chakra-ui/c-button/examples/base-button.vue'
88
import Component_8 from '@chakra-ui/c-icon/examples/base-icon.vue'
9-
import Component_9 from "../components/Home.vue";
9+
import Component_9 from '@chakra-ui/c-icon/examples/with-color.vue'
10+
import Component_10 from '@chakra-ui/c-icon/examples/with-size.vue'
11+
import Component_11 from "../components/Home.vue";
1012

1113
export default {
12-
"../components/Home.vue": Component_9,
14+
"../components/Home.vue": Component_11,
1315
"@chakra-ui/c-alert/examples/base-alert.vue": Component_2,
1416
"@chakra-ui/c-alert/examples/fix-hover.vue": Component_3,
1517
"@chakra-ui/c-alert/examples/with-accent.vue": Component_4,
1618
"@chakra-ui/c-alert/examples/with-status.vue": Component_5,
1719
"@chakra-ui/c-alert/examples/with-title.vue": Component_6,
1820
"@chakra-ui/c-button/examples/base-button.vue": Component_7,
19-
"@chakra-ui/c-icon/examples/base-icon.vue": Component_8
21+
"@chakra-ui/c-icon/examples/base-icon.vue": Component_8,
22+
"@chakra-ui/c-icon/examples/with-color.vue": Component_9,
23+
"@chakra-ui/c-icon/examples/with-size.vue": Component_10
2024
}

playground/src/.generated/routes.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@
5454
"name": "Base icon",
5555
"path": "/c-icon/base-icon",
5656
"component": "@chakra-ui/c-icon/examples/base-icon.vue"
57+
},
58+
{
59+
"name": "With color",
60+
"path": "/c-icon/with-color",
61+
"component": "@chakra-ui/c-icon/examples/with-color.vue"
62+
},
63+
{
64+
"name": "With size",
65+
"path": "/c-icon/with-size",
66+
"component": "@chakra-ui/c-icon/examples/with-size.vue"
5767
}
5868
]
5969
},

0 commit comments

Comments
 (0)