-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
96 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
import { withInstall } from "@celeris/utils/src/vue/install"; | ||
import unocssIcon from "./src/UnoCSSIcon.vue"; | ||
import icon from "./src/Icon.vue"; | ||
|
||
export const UnoCSSIcon = withInstall(unocssIcon); | ||
export const Icon = withInstall(icon); | ||
|
||
export { default as CAUnoCSSIcon } from "./src/UnoCSSIcon.vue"; | ||
export { default as CAIcon } from "./src/Icon.vue"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<script setup lang="ts"> | ||
import { NIcon, NIconWrapper } from "naive-ui"; | ||
import { Icon, type IconifyIcon, loadIcon } from "@iconify/vue"; | ||
import { computed, defineProps, ref, watchEffect } from "vue"; | ||
import { isNil } from "@celeris/utils"; | ||
interface IconOptions { | ||
name?: string; | ||
size?: number; | ||
bgSize?: number; | ||
color?: string; | ||
iconColor?: string; | ||
bgColor?: string; | ||
borderRadius?: number; | ||
depth?: 1 | 2 | 3 | 4 | 5; | ||
} | ||
const props = defineProps<Omit<IconOptions, "iconColor">>(); | ||
const shouldUseWrapper = computed(() => !!(props.bgColor || props.bgSize || props.borderRadius)); | ||
const componentToRender = computed(() => (shouldUseWrapper.value ? NIconWrapper : NIcon)); | ||
const options = computed(() => { | ||
const opt: IconOptions = {}; | ||
if (shouldUseWrapper.value) { | ||
if (!isNil(props.bgSize)) { | ||
opt.size = props.bgSize; | ||
} | ||
if (!isNil(props.bgColor)) { | ||
opt.color = props.bgColor; | ||
} | ||
if (!isNil(props.borderRadius)) { | ||
opt.borderRadius = props.borderRadius; | ||
} | ||
if (!isNil(props.color)) { | ||
opt.iconColor = props.color; | ||
} | ||
} else { | ||
if (!isNil(props.color)) { | ||
opt.color = props.color; | ||
} | ||
if (!isNil(props.depth)) { | ||
opt.depth = props.depth; | ||
} | ||
if (!isNil(props.size)) { | ||
opt.size = props.size; | ||
} | ||
} | ||
return opt; | ||
}); | ||
const loadIconByName = (name: string) => loadIcon(name).catch(() => console.error(`Failed to load icon ${name}`)); | ||
const icon = ref<void | Required<IconifyIcon>>(); | ||
function setIcon(name: string | undefined) { | ||
if (!isNil(name)) { | ||
loadIconByName(name).then(res => (icon.value = res)); | ||
} | ||
} | ||
setIcon(props.name); | ||
watchEffect(() => setIcon(props.name)); | ||
</script> | ||
|
||
<template> | ||
<component :is="componentToRender" v-bind="options"> | ||
<template v-if="$slots.default"> | ||
<slot /> | ||
</template> | ||
<template v-else> | ||
<Icon v-if="icon" :icon="icon" :width="size" :height="size" /> | ||
</template> | ||
</component> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
3f0cf58
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
celeris-web-api – ./services/admin
celeris-web-api-git-master-kirklin.vercel.app
celeris-web-api.vercel.app
celeris-web-api-kirklin.vercel.app
3f0cf58
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
celeris-web – ./apps/admin
celeris-web-kirklin.vercel.app
celeris-web-git-master-kirklin.vercel.app
celeris-web.vercel.app