Skip to content

Commit

Permalink
chore: perf icon component
Browse files Browse the repository at this point in the history
  • Loading branch information
chizukicn committed Nov 14, 2023
1 parent 69ae230 commit ec5c2dd
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions packages/core/src/icon/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { computed } from "vue";
import type { CSSProperties, PropType } from "vue";
import { defineHookComponent, defineHookProps, useSharedConfig } from "@hoci/shared";
import { unit_f } from "tslx";
import { createUnitFormat } from "tslx";

export const iconProps = defineHookProps({
src: {
Expand Down Expand Up @@ -34,20 +34,21 @@ export const useIcon = defineHookComponent({
setup(props, context) {
const sharedConfig = useSharedConfig("icon");

const sizeStyle = computed(() => {
const sizeStyle = computed<CSSProperties>(() => {
const s = props.size ?? sharedConfig.size;
const size = s ? unit_f(s, sharedConfig.sizeUnit) : undefined;
const unit = createUnitFormat(sharedConfig.sizeUnit ?? "px");
const size = s ? unit(s) : undefined;
const w = props.width ?? size;
const h = props.height ?? size;
const width = w ? unit_f(w, sharedConfig.sizeUnit) : undefined;
const height = h ? unit_f(h, sharedConfig.sizeUnit) : undefined;
const width = w ? unit(w) : undefined;
const height = h ? unit(h) : undefined;
return {
width,
height
};
});

const dynamicStyle = computed(() => {
const dynamicStyle = computed<CSSProperties>(() => {
const mask = props.mask === "auto" ? props.src.endsWith(".svg") : props.mask;
if (!mask) {
return {
Expand All @@ -64,14 +65,14 @@ export const useIcon = defineHookComponent({
};
});

const staticStyle = computed(() => {
const staticStyle = computed<CSSProperties>(() => {
return {
"--icon-url": `url('${props.src}')`
};
});


const style = computed((): CSSProperties => {
const style = computed<CSSProperties>(() => {
return {
...staticStyle.value,
...dynamicStyle.value,
Expand Down

0 comments on commit ec5c2dd

Please sign in to comment.