-
Notifications
You must be signed in to change notification settings - Fork 26
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
949268e
commit ae16180
Showing
4 changed files
with
126 additions
and
11 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 |
---|---|---|
|
@@ -56,5 +56,5 @@ android/keystores/debug.keystore | |
/lib/ | ||
|
||
# ignore generated icon files | ||
/src/ | ||
src/* | ||
!src/lib/ |
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,68 @@ | ||
import { useContext, type ReactElement, type FC } from 'react'; | ||
import Svg from 'react-native-svg'; | ||
import { type IconProps, type IconWeight, IconContext } from '../lib'; | ||
|
||
interface IconBaseProps extends IconProps { | ||
weights: Map< | ||
IconWeight, | ||
ReactElement | FC<{ duotoneColor?: string; duotoneOpacity?: number }> | ||
>; | ||
} | ||
|
||
function IconBase({ | ||
weight, | ||
color, | ||
size, | ||
style, | ||
mirrored, | ||
duotoneColor, | ||
duotoneOpacity, | ||
title, | ||
titleId, | ||
weights, | ||
...props | ||
}: IconBaseProps) { | ||
const { | ||
color: contextColor = '#000', | ||
size: contextSize = 24, | ||
weight: contextWeight = 'regular', | ||
mirrored: contextMirrored = false, | ||
style: contextStyle, | ||
duotoneColor: contextDuotoneColor = '#000', | ||
duotoneOpacity: contextDuotoneOpacity = 0.2, | ||
} = useContext(IconContext); | ||
|
||
return ( | ||
<Svg | ||
style={[ | ||
contextStyle, | ||
style, | ||
{ | ||
...((mirrored ?? contextMirrored) && { | ||
transform: [{ scaleX: -1 }], | ||
}), | ||
}, | ||
]} | ||
className={`acorn-${weight}__svg-icon-phosphor`} | ||
testID={props.testID ?? 'phosphor-react-native-acorn-bold'} | ||
fill="currentColor" | ||
viewBox="0 0 256 256" | ||
width={size ?? contextSize} | ||
height={size ?? contextSize} | ||
color={color ?? contextColor} | ||
aria-labelledby={titleId} | ||
{...props} | ||
> | ||
{title ? <title id={titleId}>{title}</title> : null} | ||
{(weight ?? contextWeight) === 'duotone' | ||
? // @ts-expect-error not callable | ||
weights.get(weight ?? contextWeight)({ | ||
duotoneColor: duotoneColor ?? contextDuotoneColor ?? color, | ||
duotoneOpacity: duotoneOpacity ?? contextDuotoneOpacity, | ||
}) | ||
: weights.get(weight ?? contextWeight)} | ||
</Svg> | ||
); | ||
} | ||
|
||
export default IconBase; |
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,35 @@ | ||
import React, { createContext } from 'react'; | ||
import { StyleProp, ViewStyle } from 'react-native'; | ||
|
||
export type IconWeight = | ||
| 'thin' | ||
| 'light' | ||
| 'regular' | ||
| 'bold' | ||
| 'fill' | ||
| 'duotone'; | ||
|
||
export type PaintFunction = (color: string) => React.ReactNode | null; | ||
|
||
export interface IconProps { | ||
color?: string; | ||
size?: string | number; | ||
weight?: IconWeight; | ||
style?: StyleProp<ViewStyle>; | ||
mirrored?: boolean; | ||
testID?: string; | ||
duotoneColor?: string; | ||
duotoneOpacity?: number; | ||
title?: string; // SVGRProps | ||
titleId?: string; // SVGRProps | ||
} | ||
|
||
export type Icon = React.FC<IconProps>; | ||
|
||
export const IconContext = createContext<IconProps>({ | ||
color: '#000', | ||
size: 24, | ||
weight: 'regular', | ||
mirrored: false, | ||
duotoneOpacity: 0.2, | ||
}); |