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

feat: Add default classes to the icons #23

Merged
merged 3 commits into from
Aug 19, 2024
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
Loading