Skip to content

Commit

Permalink
feat: Add default classes to the icons (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aviortheking authored Aug 19, 2024
1 parent e21daaa commit 0e1e940
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
9 changes: 6 additions & 3 deletions src/.Layout.astro
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
---
export type { Props } from './index.d.ts'
// extract and remove the size shortcut
// extract and remove special parameters
const size = Astro.props.size
const cls = Astro.props.class
const name = Astro.props.iconName
delete Astro.props.size
delete Astro.props.class
delete Astro.props.iconName
// allow the user's props to redefine our defaults
const props = Object.assign({
Expand All @@ -17,9 +21,8 @@ const props = Object.assign({
'fill': 'none',
'viewBox': '0 0 24 24'
}, Astro.props)
---

<svg {...props}>
<svg {...props} class:list={['lucide', { [`lucide-${name}`]: name }, cls]}>
<slot />
</svg>
4 changes: 2 additions & 2 deletions src/Template.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import Layout from './.Layout.astro'
export type { Props } from './index.d.ts'
---

<Layout {...Astro.props}>
<Layout iconName="<!-- name -->" {...Astro.props}>
<!-- icon -->
</Layout>
</Layout>
19 changes: 12 additions & 7 deletions src/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ await fs.mkdir('./dist')
const template = await fs.readFile('./src/Template.astro', 'utf8')

// funciton tht fill the template with the icon SVG
function fillTemplate(icon) {
return template.replace(
'<!-- icon -->',
icon.replace(/<svg(?:.|\n)*?>((?:.|\n)*)<\/svg>/gm, '$1').replace(/ /g, '\t').trim()
)
function fillTemplate(name, icon) {
return template
.replace(
'<!-- name -->',
name
)
.replace(
'<!-- icon -->',
icon.replace(/<svg(?:.|\n)*?>((?:.|\n)*)<\/svg>/gm, '$1').replace(/ /g, '\t').trim()
)
}

// copy the base layout
Expand All @@ -41,7 +46,7 @@ try {
const filePath = `./dist/${fullName}.astro`;

// compile the icon and write it out
await fs.writeFile(filePath, fillTemplate(icon), "utf-8");
await fs.writeFile(filePath, fillTemplate(name, icon), "utf-8");

// add the icon to the index
index += `export { default as ${fullName} } from './${fullName}.astro'\n`
Expand All @@ -53,4 +58,4 @@ try {
} catch (e) {
console.error('Error building the Library', e)
process.exit(1)
}
}

0 comments on commit 0e1e940

Please sign in to comment.