-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: generate-icon-font to use it as bin executable and update d… (
#1754) * refactor: generate-icon-font to use it as bin executable and update documentation * chore: update package-lock.json * fix: issues with all for generate-icon-fonts * docs: added hints for using with scss and separate folder --------- Co-authored-by: Anna Schoderer <[email protected]>
- Loading branch information
Showing
12 changed files
with
735 additions
and
68 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,80 @@ | ||
# Custom Icons | ||
|
||
If you have custom icons and want to use them for foundations and/or in components, you need to generate a `woff2` file. | ||
|
||
## Generate | ||
|
||
For this run: | ||
|
||
```shell | ||
npx -p @db-ui/foundations generate-icon-fonts --src ./my-path-to/icons --fontName my-name | ||
``` | ||
|
||
We search for all `**/*.svg` files inside the `src` directory and create a new icon font with the provided name. You can preview all generated icons here: `./my-path-to/icons/fonts/all/index.html`. | ||
|
||
> **_NOTE:_** We use four different sizes for components (16, 20, 24, 32) to show more or less details. You can do the same by providing another file with a size suffix for example "icon_file_name_16.svg". | ||
For more information run: | ||
|
||
```shell | ||
npx -p @db-ui/foundations generate-icon-fonts --help | ||
``` | ||
|
||
## How to use | ||
|
||
In your app you need to include some of the generated files: | ||
|
||
```html | ||
./my-path-to/icons/fonts/my-name.woff2 ./my-path-to/icons/fonts/font-face.css | ||
``` | ||
|
||
> **_NOTE:_** In case you put the files in a separate folder of your `public` directory be aware to adopt the path in your generated `font-face.css` file: `url("/{YOUR_FOLDER}}/my-name.woff2?t=1698750286189") format("woff2");` | ||
Now you can use your icons with your `font-family: my-name`, e.g.: | ||
|
||
```html | ||
<!--example.html--> | ||
<i class="my-name">icon_file_name</i> | ||
``` | ||
|
||
### SCSS | ||
|
||
When using `scss` you can also use `@forward` to include the generated files: | ||
|
||
```scss | ||
@forward "public/font-face"; | ||
``` | ||
|
||
### data-icon | ||
|
||
If you like to use a custom icon in one of our components you can do it by overwriting the default font-family like this: | ||
|
||
```html | ||
<!--example.html--> | ||
<p class="icon-family-my-name" data-icon="icon_file_name">Test</p> | ||
|
||
<!-- or --> | ||
<p data-icon-family="my-name" data-icon="icon_file_name">Test</p> | ||
``` | ||
|
||
### CSS | ||
|
||
You can overwrite custom-icons for our components with CSS as well: | ||
|
||
```css | ||
.db-button { | ||
--db-icon-font-family: "my-name"; | ||
} | ||
``` | ||
|
||
## Foundation Developer | ||
|
||
If you update a `svg` inside `assets/icons/functional/images` you need to recreate the `woff2` file. | ||
|
||
For this you just need to run | ||
|
||
```shell | ||
npm run generate:icon-fonts | ||
``` | ||
|
||
Your new icon should be inside `assets/icons/functional/fonts/info.json` and you should see it inside `assets/icons/functional/fonts/index.html` in the browser. |
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
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
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
File renamed without changes.
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
7 changes: 7 additions & 0 deletions
7
showcases/patternhub/pages/foundations/icons/custom-icons.mdx
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 @@ | ||
import DefaultPage from "../../../components/default-page"; | ||
|
||
import CustomIcons from "../../../../../packages/foundations/docs/CustomIcons.md"; | ||
|
||
<CustomIcons /> | ||
|
||
export default ({ children }) => <DefaultPage>{children}</DefaultPage>; |