-
-
Notifications
You must be signed in to change notification settings - Fork 549
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lucide-react, lucide-preact, lucide-react-native, lucide-solid, …
…lucide-vue-next): Adjustable icon naming imports (#2328) * Add override alias import entry files lucide-react * Make it work * Setup files for packages * Revert icon changes * Remove solid support and add docs * Adjust docs * format files * Fix lucide-vue-next build * Fix builds * Fix lucide-svelte * Add vscode settings option
- Loading branch information
1 parent
d30698c
commit b177743
Showing
39 changed files
with
959 additions
and
259 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
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,93 @@ | ||
# Aliased Names | ||
|
||
Icons can have multiple names for the same icon. This is because we choose to rename some icons to make them more consistent with the rest of the icon set, or the name was not generic. For example, the `edit-2` icon is renamed to `pen` to make the name more generic, since it is just a pen icon. | ||
|
||
Beside aliases names lucide also includes prefixed and suffixed names to use within your project. This is to prevent import name collisions with other libraries or your own code. | ||
|
||
```tsx | ||
// These are all the same icon | ||
import { | ||
Home, | ||
HomeIcon, | ||
LucideHome, | ||
} from "lucide-react"; | ||
``` | ||
|
||
## Choosing import name style | ||
|
||
To be consistent in your imports or want to change the autocompletion of Lucide icons in your IDE there an option to able the choose the import name style you want. | ||
|
||
This can be done by creating a custom module declaration file to override the lucide imports and turning off the autocomplete in your IDE. | ||
|
||
### Turn off autocomplete in your IDE | ||
|
||
```json [.vscode/settings.json] | ||
{ | ||
"typescript.preferences.autoImportFileExcludePatterns": [ | ||
"lucide-react", // or | ||
"lucide-preact", // or | ||
"lucide-react-native", // or | ||
"lucide-vue-next", | ||
] | ||
} | ||
``` | ||
|
||
### Create a custom module declaration file | ||
|
||
Only available for `lucide-react`, `lucide-preact`, `lucide-react-native`, `lucide-vue-next` package. | ||
This will enable you to choose the import name style you want to use in your project. | ||
|
||
::: code-group | ||
|
||
```ts [React] | ||
declare module "lucide-react" { | ||
// Prefixed import names | ||
export * from "lucide-react/dist/lucide-react.prefixed"; | ||
// or | ||
// Suffixed import names | ||
export * from "lucide-react/dist/lucide-react.suffixed"; | ||
} | ||
``` | ||
|
||
```ts [Vue] | ||
declare module "lucide-vue-next" { | ||
// Prefixed import names | ||
export * from "lucide-vue-next/dist/lucide-vue-next.prefixed"; | ||
// or | ||
// Suffixed import names | ||
export * from "lucide-vue-next/dist/lucide-vue-next.suffixed"; | ||
} | ||
``` | ||
|
||
```ts [Preact] | ||
declare module "lucide-preact" { | ||
// Prefixed import names | ||
export * from "lucide-preact/dist/lucide-preact.prefixed"; | ||
// or | ||
// Suffixed import names | ||
export * from "lucide-preact/dist/lucide-preact.suffixed"; | ||
} | ||
``` | ||
|
||
```ts [React Native] | ||
declare module "lucide-react-native" { | ||
// Prefixed import names | ||
export * from "lucide-react-native/dist/lucide-react-native.prefixed"; | ||
// or | ||
// Suffixed import names | ||
export * from "lucide-react-native/dist/lucide-react-native.suffixed"; | ||
} | ||
``` | ||
|
||
::: | ||
|
||
Place this in your project root or in a folder where your tsconfig.json is located, or locate it in your defined type directory. | ||
Easiest way is to create a `@types` folder in your project root and name the file `[package-name].d.ts`. | ||
|
||
### Import name styles | ||
|
||
| Import Style | Available imports | Declaration file import | | ||
| ------------- | --------------------------- | ----------------------- | | ||
| Default | Home, HomeIcon, LucideHome | | | ||
| Prefixed | LucideHome | [package].prefixed | | ||
| Suffixed | HomeIcon | [package].suffixed | |
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 |
---|---|---|
|
@@ -29,5 +29,8 @@ | |
"design", | ||
"shapes", | ||
"maths" | ||
], | ||
"aliases": [ | ||
"grid-2-x-2-plus" | ||
] | ||
} |
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 @@ | ||
export * from './aliases'; |
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,3 @@ | ||
export * from './aliases'; | ||
export * from './prefixed'; | ||
export * from './suffixed'; |
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,7 @@ | ||
export * from './icons'; | ||
export * as icons from './icons'; | ||
export * from './aliases/prefixed'; | ||
export * from './types'; | ||
|
||
export { default as createLucideIcon } from './createLucideIcon'; | ||
export { default as Icon } from './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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export * from './icons'; | ||
export * as icons from './icons'; | ||
export * from './aliases/suffixed'; | ||
export * from './types'; | ||
|
||
export { default as createLucideIcon } from './createLucideIcon'; | ||
export { default as Icon } from './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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './aliases'; | ||
export * from './prefixed'; | ||
export * from './suffixed'; |
7 changes: 7 additions & 0 deletions
7
packages/lucide-react-native/src/lucide-react-native.prefixed.ts
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,7 @@ | ||
export * from './icons'; | ||
export * as icons from './icons'; | ||
export * from './aliases/prefixed'; | ||
export * from './types'; | ||
|
||
export { default as createLucideIcon } from './createLucideIcon'; | ||
export { default as Icon } from './Icon'; |
7 changes: 7 additions & 0 deletions
7
packages/lucide-react-native/src/lucide-react-native.suffixed.ts
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,7 @@ | ||
export * from './icons'; | ||
export * as icons from './icons'; | ||
export * from './aliases/suffixed'; | ||
export * from './types'; | ||
|
||
export { default as createLucideIcon } from './createLucideIcon'; | ||
export { default as Icon } from './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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './aliases'; | ||
export * from './prefixed'; | ||
export * from './suffixed'; |
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,6 @@ | ||
export * as icons from './icons'; | ||
export * from './aliases/prefixed'; | ||
export * from './types'; | ||
|
||
export { default as createLucideIcon } from './createLucideIcon'; | ||
export { default as Icon } from './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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export * as icons from './icons'; | ||
export * from './aliases/suffixed'; | ||
export * from './types'; | ||
|
||
export { default as createLucideIcon } from './createLucideIcon'; | ||
export { default as Icon } from './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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './aliases'; | ||
export * from './prefixed'; | ||
export * from './suffixed'; |
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 @@ | ||
export * from './aliases'; |
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,3 @@ | ||
export * from './aliases'; | ||
export * from './prefixed'; | ||
export * from './suffixed'; |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export * from './icons/index.js'; | ||
export * as icons from './icons/index.js'; | ||
export * from './aliases.js'; | ||
export { default as defaultAttributes } from './defaultAttributes.js'; | ||
export * from './types.js'; | ||
export * from './icons/index'; | ||
export * as icons from './icons/index'; | ||
export * from './aliases'; | ||
export { default as defaultAttributes } from './defaultAttributes'; | ||
export * from './types'; | ||
export { default as Icon } from './Icon.svelte'; |
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,3 @@ | ||
export * from './aliases'; | ||
export * from './prefixed'; | ||
export * from './suffixed'; |
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,6 @@ | ||
export * as icons from './icons'; | ||
export * from './aliases/prefixed'; | ||
export * from './types'; | ||
|
||
export { default as createLucideIcon } from './createLucideIcon'; | ||
export { default as Icon } from './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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export * as icons from './icons'; | ||
export * from './aliases/suffixed'; | ||
export * from './types'; | ||
|
||
export { default as createLucideIcon } from './createLucideIcon'; | ||
export { default as Icon } from './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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './aliases'; |
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 @@ | ||
export * from './aliases'; |
Oops, something went wrong.