|
| 1 | +# `@green-stack/icons` - Aetherspace Plugin |
| 2 | + |
| 3 | +Prerequisites: |
| 4 | +- Fork or generate a new repository from the official or free [aetherspace/green-stack-starter](https://github.com/Aetherspace/green-stack-starter-demo#readme) github repo |
| 5 | +- Choose the "✅ Include all branches" option during the fork / generation process |
| 6 | + |
| 7 | +```shell |
| 8 | +git merge with/green-stack-icons |
| 9 | +``` |
| 10 | + |
| 11 | +```shell |
| 12 | +│── packages/ |
| 13 | +│ └── @aetherspace-mongoose/ # ➡️ importable from '@green-stack/icons' |
| 14 | +│ └── assets/ # ➡️ Input folder for .svg files |
| 15 | +│ └── icons/ # ➡️ Output folder for SVG components |
| 16 | +│ └── scripts/ # ➡️ Script to generate SVG components from .svg files at /assets/ |
| 17 | +│ └── package.json # ➡️ pkg name & dependencies, like '@nandorojo/heroicons' |
| 18 | +``` |
| 19 | + |
| 20 | +## Usage -- SVG icon libraries with `@green-stack/icons` |
| 21 | + |
| 22 | +With this package, you can use any of the following icon libraries in web or mobile, without any downsides: |
| 23 | +- `@nandorojo/iconic` ([NPM](https://github.com/nandorojo/react-native-iconic)) |
| 24 | +- `@nandorojo/heroicons` ([NPM](https://github.com/nandorojo/react-native-heroicons)) |
| 25 | + |
| 26 | +[Solito Docs: Expo + Next.js Icon recipes](https://solito.dev/recipes/icons) |
| 27 | + |
| 28 | +We'll be gathering more similar SVG icon libraries with react-native support under `/packages/@green-stack-icons`. Which functions mostly as a collection of these cross-platform enabled iconsets gathered in one place... But it also has a handy script for turning your own folder of `.svg` icons into your own custom set of React-Native SVG components: |
| 29 | + |
| 30 | +## Generating your own icon set from .svg files |
| 31 | + |
| 32 | +```bash |
| 33 | +yarn workspace @green-stack/icons regenerate |
| 34 | +``` |
| 35 | + |
| 36 | +1. Merge the `with/green-stack-icons` plugin branch, or [copy-paste](/packages/@aetherspace/core/README.md#designed-for-copy-paste) in `/packages/@green-stack-icons/` |
| 37 | +2. Drop your `.svg` files in `/packages/@green-stack-icons/assets/{your-icon-set-name}/` |
| 38 | +3. Run `yarn workspace @green-stack/icons regenerate` to create icon components from your `.svg` files |
| 39 | +4. Import your icon components from `@green-stack/icons/{your-icon-set-name}/{your-icon-name}` |
| 40 | + |
| 41 | +OR, register them for use with `<AetherIcon/>`: |
| 42 | + |
| 43 | +- [Managing Icons in GREEN stack Expo + Next.js monorepos](/packages/@aetherspace/components/AetherIcon/README.md) |
| 44 | + |
| 45 | +## Better DX with `AetherIcon` |
| 46 | + |
| 47 | +> Whichever of the 4 strategies you choose, or even when choosing multiple methods, you can improve your DX or apply the icons dynamicly using Aetherspace’s icon registry pattern and `AetherIcon` component. |
| 48 | +
|
| 49 | +This will enable: |
| 50 | + |
| 51 | +- Type hints in your editor for the `name` prop on the AetherIcon component |
| 52 | +- Each workspace to define their own icons, optimising the feature or package for copy-paste |
| 53 | +- An importable list of all registered icons for e.g. building an IconPicker component |
| 54 | + |
| 55 | +Example registration (in e.g. `feature/{workspace}/icons/registry.tsx`) |
| 56 | + |
| 57 | +```tsx |
| 58 | +import { AetherImage } from 'aetherspace/primitives' |
| 59 | +import { registerIconRenderer } from 'aetherspace/utils' |
| 60 | + |
| 61 | +export const iconRegistry = { |
| 62 | + // Make sure components have 'size' & 'fill' props |
| 63 | + 'some-icon-key': MySvgComponent, |
| 64 | + // - OR, if you don't need to change the color through props - |
| 65 | + 'some-img-icon': ({ size, ...restIconProps }) => ( |
| 66 | + <AetherImage |
| 67 | + src="/img/icon.svg" |
| 68 | + width={size} |
| 69 | + height={size} |
| 70 | + {...restIconProps} |
| 71 | + /> |
| 72 | + ) |
| 73 | + // - OR - |
| 74 | + ...registerIconRenderer( |
| 75 | + ['caret-up', 'caret-down', ...] as const, |
| 76 | + ({ name, size, fill, ...restIconProps }) => ( |
| 77 | + <ThirdPartyIconLib name={name} size={size} color={fill} {...restIconProps} /> |
| 78 | + ), |
| 79 | + ), |
| 80 | +} |
| 81 | +``` |
| 82 | + |
| 83 | +Example codegen |
| 84 | + |
| 85 | +```bash |
| 86 | +yarn ats collect-icons |
| 87 | +# or just "yarn dev" as it's part of the next.config.js automations |
| 88 | +``` |
| 89 | + |
| 90 | +```tsx |
| 91 | +----------------------------------------------------------------- |
| 92 | +-i- Successfully created icon registry at: |
| 93 | +----------------------------------------------------------------- |
| 94 | +✅ packages/@registries/icons.generated.ts |
| 95 | +``` |
| 96 | + |
| 97 | +```tsx |
| 98 | +// icons.generated.ts |
| 99 | + |
| 100 | +// -i- Auto generated with 'yarn ats collect-icons' & reused in AetherIcon |
| 101 | +import { iconRegistry as someFeatureIcons } from '../../features/some-feature/icons/registry' |
| 102 | +import { iconRegistry as somePackageIcons } from '../../packages/some-package/icons/registry' |
| 103 | + |
| 104 | +/* --- Exports --------------------------------------------------------------------------------- */ |
| 105 | + |
| 106 | +export const REGISTERED_ICONS = { |
| 107 | + ...someFeatureIcons, |
| 108 | + ...somePackageIcons, |
| 109 | +} as const // prettier-ignore |
| 110 | +``` |
| 111 | + |
| 112 | +Example usage of `AetherIcon` (which uses the generated icon registry under the hood) |
| 113 | + |
| 114 | +```tsx |
| 115 | +<AetherIcon name="some-icon-key" size={24} /> |
| 116 | +// ?^ 'some-icon-key' | 'some-img-icon' | 'caret-up' | 'caret-down' | ... |
| 117 | +``` |
| 118 | + |
| 119 | +The AetherIcon way of working is fully optional and only exists to keep your feature and packages workspaces copy-pastable between Aetherspace projects by applying some minimal codegen on top. |
| 120 | + |
| 121 | +## Roadmap - More to come |
| 122 | + |
| 123 | +`@green-stack/icons` is an Aetherspace plugin branch that's already usable, but will be expanded on in the future. Follow the maintainer on Github, Twitter or Bluesky to stay up to date on the latest developments. |
0 commit comments