Skip to content

Commit

Permalink
feat: add attributes in vue generators (#48)
Browse files Browse the repository at this point in the history
* feat: add attributes in vue generators

* chore: changeset
  • Loading branch information
junghyeonsu authored Jul 4, 2024
1 parent a0c2d33 commit 9f9452e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/long-eggs-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@icona/generator": patch
"@icona/types": patch
---

Add attributes in vue generators
7 changes: 6 additions & 1 deletion packages/generator/src/core/vue2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const createShimFile = async (targetPath: string) => {
export const generateVue2 = async (props: Props) => {
const { config, icons = getIconaIconsFile() } = props;
const targetPath = getTargetPath(config.path || "vue2");
const { genShimFile, genIndexFile } = config;
const { genShimFile, genIndexFile, attributes } = config;
const componentNames = [];

if (!icons) {
Expand Down Expand Up @@ -100,8 +100,13 @@ export const generateVue2 = async (props: Props) => {
const svgPath = resolve(targetPath, `${componentName}.vue`);
componentNames.push(componentName);

const attributesString = Object.entries(attributes || {})
.map(([key, value]) => `${key}="${value}"`)
.join(" ");

// SVG 파일 내용을 Vue 컴포넌트로 변환
const convertedSvg = svg
.replace(/<svg/, `<svg ${attributesString}`)
.replace(/width="([^"]+)"/, ':width="size"')
.replace(/height="([^"]+)"/, ':height="size"');

Expand Down
7 changes: 6 additions & 1 deletion packages/generator/src/core/vue3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const createShimFile = async (targetPath: string) => {
export const generateVue3 = async (props: Props) => {
const { config, icons = getIconaIconsFile() } = props;
const targetPath = getTargetPath(config.path || "vue3");
const { genShimFile, genIndexFile } = config;
const { genShimFile, genIndexFile, attributes } = config;
const componentNames = [];
if (!icons) {
throw new Error("There is no icons data");
Expand Down Expand Up @@ -103,8 +103,13 @@ export const generateVue3 = async (props: Props) => {
const svgPath = resolve(targetPath, `${componentName}.vue`);
componentNames.push(componentName);

const attributesString = Object.entries(attributes || {})
.map(([key, value]) => `${key}="${value}"`)
.join(" ");

// SVG 파일 내용을 Vue 컴포넌트로 변환
const convertedSvg = svg
.replace(/<svg/, `<svg ${attributesString}`)
.replace(/width="([^"]+)"/, ':width="size"')
.replace(/height="([^"]+)"/, ':height="size"');

Expand Down
4 changes: 4 additions & 0 deletions packages/types/src/lib.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,16 @@ export interface Vue2Config extends BaseConfig {
genShimFile?: boolean;

genIndexFile?: boolean;

attributes?: Record<string, string>;
}

export interface Vue3Config extends BaseConfig {
genShimFile?: boolean;

genIndexFile?: boolean;

attributes?: Record<string, string>;
}

export interface IconaConfig {
Expand Down

0 comments on commit 9f9452e

Please sign in to comment.