Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move icons to ui-kit #1510

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Template: StoryFn<typeof VcIcon> = (args) => ({
template: '<VcIcon v-bind="args" />',
});

const iconList = import.meta.glob("@/assets/icons/basic/*.svg", { eager: true });
const iconList = import.meta.glob("../../../icons/*.svg", { eager: true });

const TemplateList: StoryFn<typeof VcIcon> = (args) => ({
components: { VcIcon },
Expand Down
5 changes: 2 additions & 3 deletions client-app/ui-kit/components/atoms/icon/vc-icon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
</template>

<script setup lang="ts">
import DOMPurify from "dompurify";
import { ref, computed, watch } from "vue";
import { loadIconRaw } from "@/ui-kit/utilities";

interface IProps {
name?: string;
Expand All @@ -29,8 +29,7 @@ const style = computed(() =>
const sizeClass = computed(() => (typeof props.size === "string" ? `vc-icon--size--${props.size}` : ""));

async function loadIcon(name?: string) {
const response = (await import(`@/assets/icons/basic/${name}.svg?raw`)) as { default: string };
icon.value = DOMPurify.sanitize(response.default);
icon.value = await loadIconRaw(name);
}

watch(
Expand Down
7 changes: 2 additions & 5 deletions client-app/ui-kit/components/molecules/shape/vc-shape.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<script setup lang="ts">
import { computed, ref, watch } from "vue";
import { loadIcon } from "../../../utilities";

interface IProps {
size?: number | string;
Expand All @@ -32,14 +33,10 @@ const style = computed(() => ({
maskImage: iconUrl.value ? `url("${iconUrl.value}")` : "none",
}));

function loadIcon(name?: string) {
iconUrl.value = new URL(`/client-app/assets/icons/basic/${name}.svg`, import.meta.url).href ?? "";
}

watch(
() => props.mask,
(newIconName: string) => {
loadIcon(newIconName);
iconUrl.value = loadIcon(newIconName);
},
{ immediate: true },
);
Expand Down
10 changes: 10 additions & 0 deletions client-app/ui-kit/utilities/images.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import DOMPurify from "dompurify";

export function loadIcon(name?: string): string {
return new URL(`../icons/${name}.svg`, import.meta.url).href ?? "";
}

export async function loadIconRaw(name?: string): Promise<string> {
const response = (await import(`../icons/${name}.svg?raw`)) as { default: string };
return DOMPurify.sanitize(response.default);
}
Loading
Loading