Skip to content

Commit

Permalink
add vuejs example
Browse files Browse the repository at this point in the history
  • Loading branch information
shafiqhammad5 committed Oct 29, 2024
1 parent 9881f65 commit e6ecb9b
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 14 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: 🚀 lineicons release

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
release:
name: 🚀 lineicons release
runs-on: ubuntu-latest
steps:
- name: 📚 checkout
uses: actions/checkout@v2
- name: 🟢 node
uses: actions/setup-node@v2
with:
node-version: 12
registry-url: https://registry.npmjs.org
- name: installing packages
run: npm ci
- name: 🚀 publish
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
/dist
tsconfig.tsbuildinfo
tsconfig.tsbuildinfo
node_modules
7 changes: 7 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
./node_modules
./node_modules/
assets/images/
.DS_Store

./**/images/
4 changes: 2 additions & 2 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
<line-icon name="adobe" style="width: 50px; height: 50px"></line-icon>
<line-icon
name="adobe"
style="width: 50px; height: 50px; fill: red"
style="width: 50px; height: 50px; color: red"
></line-icon>
<line-icon
name="airbnb"
style="width: 20px; height: 20px; fill: blue"
style="width: 20px; height: 20px; color: blue"
></line-icon>
</div>
</div>
Expand Down
52 changes: 52 additions & 0 deletions example/vue-example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>

<script type="importmap">
{
"imports": {
"vue": "https://unpkg.com/vue@3/dist/vue.esm-browser.js"
}
}
</script>

<!-- Import your custom line-icon script -->
<script type="module" src="../../dist/lineicons.js"></script>
</head>
<body>
<div id="app">
<line-icon
name="adobe"
type="regular"
style="width: 50px; height: 50px"
></line-icon>
<line-icon
name="amazon"
type="regular"
style="width: 50px; height: 50px"
></line-icon>
<line-icon
name="500px"
type="regular"
style="width: 50px; height: 50px"
></line-icon>
<p>{{ message }}</p>
<!-- Use the line-icon component directly in Vue template -->
</div>

<script type="module">
import { createApp } from "vue";

createApp({
data() {
return {
message: "Hello Vue!",
};
},
}).mount("#app");
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"generate-icons": "node src/scripts/generate-icons.js",
"build:webfonts": "webpack",
"build:svg": "rollup -c",
"build": " concurrently \"npm run generate-icons\" \"npm run build:webfonts\" \"npm run build:svg\""
"build": "node src/scripts/generate-icons.js && webpack && rollup -c"
},
"keywords": [
"line-icons",
Expand Down
27 changes: 17 additions & 10 deletions src/lineicons.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { LitElement, css, html } from "lit";
import { svgMap } from "./svg-map.js"; // Import your generated svgMap
import { unsafeHTML } from "lit-html/directives/unsafe-html.js";
import { svgMap } from "./svg-map.js";

class LineIcon extends LitElement {
static properties = {
name: { type: String },
type: { type: String, attribute: "type" }, // e.g., regular or sharp
variant: { type: String, attribute: "variant" }, // e.g., outlined, solid, two-tone, stroke, bulk
type: { type: String },
styleString: { type: String, attribute: "style" },
};

Expand All @@ -14,28 +14,35 @@ class LineIcon extends LitElement {
display: inline-block;
width: 24px;
height: 24px;
color: currentColor; /* Use inherited color */
}
svg {
width: 100%;
height: 100%;
fill: currentColor; /* Set default fill to currentColor */
}
`;

constructor() {
super();
this.name = ""; // The name of the icon (e.g., 'adobe')
this.type = "regular"; // Default type
this.variant = "outlined"; // Default variant
this.name = "";
this.type = "regular"; // Default type if not specified
this.styleString = "";
}

render() {
const svgContent = svgMap[this.type]?.[this.variant]?.[this.name] || "";
let svgContent = svgMap[this.type]?.[this.name];

if (!svgContent) {
console.error(`Icon "${this.name}" not found in ${this.type} type!`);
return html`<div>Icon not found</div>`;
}

// Replace any fill attributes in the SVG content with `currentColor`
svgContent = svgContent.replace(/fill="[^"]*"/g, 'fill="currentColor"');

return html`
<div style=${this.styleString}>
${svgContent ? html([svgContent]) : html`<span>Icon not found</span>`}
</div>
<div style=${this.styleString}>${unsafeHTML(svgContent)}</div>
`;
}
}
Expand Down

0 comments on commit e6ecb9b

Please sign in to comment.