Skip to content

Commit dfbcaf3

Browse files
committed
Update docs
1 parent b3193e7 commit dfbcaf3

2 files changed

Lines changed: 55 additions & 5 deletions

File tree

README.md

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ Options
3636
--with-web-for-typescript, -rnwts Output code for DOM with TypeScript. If --with-native is also used, will be output as .web.tsx files
3737
--remove-fill, -rf Remove all 'fill' properties from SVGs, convenient for icons
3838
--remove-stroke, -rs Remove all 'stroke' properties from SVGs, convenient for icons
39-
--allow-override-fill, -aof Replace all 'fill' properties by a dynamic prop (fills) in SVGs, e.g. fill={fills[N]}. If fills[N] is undefined, fallback to the original value. Useful to dynamically control icon color(s).
39+
--allow-override-fill, -aof --allow-override-fill, -aof Replace all 'fill' properties by a dynamic prop (fills) in SVGs, e.g. fill={fills[N]}.
4040

4141
Example
42-
$ react-from-svg assets/svgs src/Svgs --with-native --remove-fill
43-
$ react-from-svg assets/svgs src/Svgs --with-web --allow-override-fill
42+
$ react-from-svg src/svgs src/svgs/components --with-web-for-typescript --allow-override-fill
4443
```
4544

4645
Generated components will allow you to inject all the props you could use on an `<svg>`/`<Svg>`, such as:
@@ -71,3 +70,54 @@ Need you to have:
7170
- [React Native](https://reactnative.dev) (or an alternative platform like
7271
[React Native Web](https://github.com/necolas/react-native-web))
7372
- [`react-native-svg`](https://github.com/react-native-community/react-native-svg)
73+
74+
## Options
75+
76+
### `--remove-fill`
77+
78+
Remove all `fill` properties from SVGs, convenient for icons.
79+
80+
### `--remove-stroke`
81+
82+
Remove all `stroke` properties from SVGs, convenient for icons.
83+
84+
### `--allow-override-fill`
85+
86+
Replace all `fill` properties by a dynamic prop (fills) in SVGs, e.g. fill={fills[N]}.
87+
If `fills[N]` is undefined, fallback to the original value (except if `--remove-fill` is used). Useful to dynamically control icon color(s).
88+
89+
## Examples
90+
91+
### Usage with `--allow-override-fill` and children
92+
93+
When using `--allow-override-fill`, you can pass children to the component to override the fill(s).
94+
You can for example update a black SVG path to one using a gradient.
95+
96+
Assuming you have a SVG in `src/svgs/logo.svg`, let's generate an SVG component :
97+
98+
```console
99+
react-from-svg src/svgs src/svgs/components --with-web-for-typescript
100+
```
101+
102+
You should have an SVG component in `src/svgs/components/SVGLogo.tsx`.
103+
104+
Now let's boost this SVG component to use a gradient.
105+
106+
```tsx
107+
import SVGLogo from "@/src/svgs/components/SVGLogo";
108+
import { colors } from "@/src/tokens.stylex"; // your colors could be just a simple object
109+
110+
const logoGradientId = "logo-gradient-id";
111+
export default function LogoWithGradient() {
112+
return (
113+
<SVGLogo width={149} height={32} fills={[`url(#${logoGradientId})`]}>
114+
<linearGradient x1="50%" y1="100%" x2="50%" y2="0%" id={logoGradientId}>
115+
<stop stopColor={colors.textSecondary} offset="0%"></stop>
116+
<stop stopColor={colors.textTertiary} offset="100%"></stop>
117+
</linearGradient>
118+
</SVGLogo>
119+
);
120+
}
121+
```
122+
123+
That's it. You started from a simple single color SVG path and ended up with a gradient SVG path.

src/bin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ const cli = meow(
1515
--with-web-for-typescript, -rnwts Output code for DOM with TypeScript. If --with-native is also used, will be output as .web.tsx files
1616
--remove-fill, -rf Remove all 'fill' properties from SVGs, convenient for icons
1717
--remove-stroke, -rs Remove all 'stroke' properties from SVGs, convenient for icons
18-
--allow-override-fill, -aof Replace all 'fill' properties from SVGs
18+
--allow-override-fill, -aof Replace all 'fill' properties by a dynamic prop (fills) in SVGs, e.g. fill={fills[N]}.
1919
2020
Example
21-
$ react-from-svg assets/svgs src/Svgs --with-native --remove-fill
21+
$ react-from-svg src/svgs src/svgs/components --with-web-for-typescript --allow-override-fill
2222
`,
2323
{
2424
importMeta: import.meta,

0 commit comments

Comments
 (0)