-
-
Notifications
You must be signed in to change notification settings - Fork 563
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b67599
commit c56e29d
Showing
39 changed files
with
578 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { h, toChildArray } from 'preact'; | ||
import defaultAttributes from './defaultAttributes'; | ||
import { IconNode, LucideProps } from './createLucideIcon'; | ||
|
||
interface IconComponentProps extends LucideProps { | ||
iconNode: IconNode | ||
} | ||
|
||
/** | ||
* Lucide icon component | ||
* | ||
* @component Icon | ||
* @param {object} props | ||
* @param {string} props.color - The color of the icon | ||
* @param {number} props.size - The size of the icon | ||
* @param {number} props.strokeWidth - The stroke width of the icon | ||
* @param {boolean} props.absoluteStrokeWidth - Whether to use absolute stroke width | ||
* @param {string} props.class - The class name of the icon | ||
* @param {IconNode} props.children - The children of the icon | ||
* @param {IconNode} props.iconNode - The icon node of the icon | ||
* | ||
* @returns {ForwardRefExoticComponent} LucideIcon | ||
*/ | ||
const Icon = ({ | ||
color = 'currentColor', | ||
size = 24, | ||
strokeWidth = 2, | ||
absoluteStrokeWidth, | ||
children, | ||
iconNode, | ||
class: classes = '', | ||
...rest | ||
}: IconComponentProps) => | ||
h( | ||
'svg', | ||
{ | ||
...defaultAttributes, | ||
width: String(size), | ||
height: size, | ||
stroke: color, | ||
['stroke-width' as 'strokeWidth']: absoluteStrokeWidth | ||
? (Number(strokeWidth) * 24) / Number(size) | ||
: strokeWidth, | ||
class: ['lucide', classes].join(' '), | ||
...rest, | ||
}, | ||
[ | ||
...iconNode.map(([tag, attrs]) => h(tag, attrs)), | ||
...toChildArray(children) | ||
], | ||
); | ||
|
||
export default Icon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { render } from '@testing-library/preact'; | ||
|
||
import { airVent } from './testIconNodes'; | ||
import Icon from '../src/Icon'; | ||
|
||
describe('Using Icon Component', () => { | ||
it('should render icon based on a iconNode', async () => { | ||
const { container } = render( | ||
<Icon | ||
iconNode={airVent} | ||
size={48} | ||
stroke="red" | ||
absoluteStrokeWidth | ||
/>, | ||
); | ||
|
||
expect( container.firstChild ).toBeDefined() | ||
}); | ||
|
||
it('should render icon and match snapshot', async () => { | ||
const { container } = render( | ||
<Icon | ||
iconNode={airVent} | ||
size={48} | ||
stroke="red" | ||
absoluteStrokeWidth | ||
/>, | ||
); | ||
|
||
expect( container.firstChild ).toMatchSnapshot(); | ||
}); | ||
}) |
29 changes: 29 additions & 0 deletions
29
packages/lucide-preact/tests/__snapshots__/Icon.spec.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`Using Icon Component > should render icon and match snapshot 1`] = ` | ||
<svg | ||
class="lucide " | ||
fill="none" | ||
height="48" | ||
stroke="red" | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
stroke-width="1" | ||
viewBox="0 0 24 24" | ||
width="48" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M6 12H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2" | ||
/> | ||
<path | ||
d="M6 8h12" | ||
/> | ||
<path | ||
d="M18.3 17.7a2.5 2.5 0 0 1-3.16 3.83 2.53 2.53 0 0 1-1.14-2V12" | ||
/> | ||
<path | ||
d="M6.6 15.6A2 2 0 1 0 10 17v-5" | ||
/> | ||
</svg> | ||
`; |
29 changes: 29 additions & 0 deletions
29
packages/lucide-preact/tests/__snapshots__/createLucideIcon.spec.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`Using createLucideIcon > should create a component from an iconNode 1`] = ` | ||
<svg | ||
class="lucide lucide-air-vent" | ||
fill="none" | ||
height="24" | ||
stroke="currentColor" | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
stroke-width="2" | ||
viewBox="0 0 24 24" | ||
width="24" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M6 12H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2" | ||
/> | ||
<path | ||
d="M6 8h12" | ||
/> | ||
<path | ||
d="M18.3 17.7a2.5 2.5 0 0 1-3.16 3.83 2.53 2.53 0 0 1-1.14-2V12" | ||
/> | ||
<path | ||
d="M6.6 15.6A2 2 0 1 0 10 17v-5" | ||
/> | ||
</svg> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { createLucideIcon } from '../src/lucide-preact'; | ||
import { airVent } from './testIconNodes'; | ||
import { render } from '@testing-library/preact' | ||
|
||
describe('Using createLucideIcon', () => { | ||
it('should create a component from an iconNode', () => { | ||
const AirVent = createLucideIcon('AirVent', airVent) | ||
|
||
const { container } = render( <AirVent/> ); | ||
|
||
expect( container.firstChild ).toMatchSnapshot(); | ||
expect( container.firstChild ).toBeDefined(); | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.