-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use Tailwind theming prefixes over custom approach
- Loading branch information
1 parent
76c079b
commit 289f73f
Showing
28 changed files
with
1,360 additions
and
1,746 deletions.
There are no files selected for viewing
This file was deleted.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,96 @@ | ||
import React, { CSSProperties } from "react"; | ||
import React, { CSSProperties, useCallback } from "react"; | ||
import clsx from "clsx"; | ||
|
||
import { defaultIconSecondaryColor } from "./Icon/secondary-colors"; | ||
import { IconName, IconSize } from "./Icon/types"; | ||
import { ColorClass } from "./styles/colors/types"; | ||
import { ColorClass, ColorThemeSet } from "./styles/colors/types"; | ||
import { convertTailwindClassToVar } from "./styles/colors/utils"; | ||
|
||
export type IconProps = { | ||
name: IconName; | ||
size?: IconSize; | ||
color?: ColorClass; | ||
secondaryColor?: ColorClass; | ||
color?: ColorClass | ColorThemeSet; | ||
secondaryColor?: ColorClass | ColorThemeSet; | ||
additionalCSS?: string; | ||
}; | ||
|
||
const Icon = ({ | ||
name, | ||
size = "0.75rem", | ||
color, | ||
secondaryColor = defaultIconSecondaryColor(name), | ||
secondaryColor, | ||
additionalCSS = "", | ||
...additionalAttributes | ||
}: IconProps) => ( | ||
<svg | ||
className={`${color ?? ""} ${additionalCSS}`} | ||
style={ | ||
{ | ||
width: size, | ||
height: size, | ||
...(secondaryColor && { | ||
"--ui-icon-secondary-color": | ||
convertTailwindClassToVar(secondaryColor), | ||
}), | ||
} as CSSProperties | ||
} | ||
{...additionalAttributes} | ||
> | ||
<use xlinkHref={`#sprite-${name}`} /> | ||
</svg> | ||
); | ||
}: IconProps) => { | ||
const [lightSecondaryColor, darkSecondaryColor] = ( | ||
secondaryColor ?? "" | ||
).split(" dark:") as [ColorClass, ColorClass | undefined]; | ||
|
||
const iconSvg = useCallback( | ||
(secondaryColor?: ColorClass, isThemed?: boolean) => { | ||
let secondaryColorValue; | ||
if (secondaryColor) { | ||
secondaryColorValue = convertTailwindClassToVar(secondaryColor); | ||
} else if (defaultIconSecondaryColor(name)) { | ||
secondaryColorValue = convertTailwindClassToVar( | ||
defaultIconSecondaryColor(name), | ||
); | ||
} | ||
|
||
return ( | ||
<svg | ||
className={clsx( | ||
{ [`${color}`]: color }, | ||
{ [`${additionalCSS}`]: additionalCSS }, | ||
{ | ||
"hidden dark:block": | ||
secondaryColor && | ||
secondaryColor === darkSecondaryColor && | ||
isThemed, | ||
}, | ||
{ | ||
"dark:hidden": | ||
secondaryColor && | ||
secondaryColor === lightSecondaryColor && | ||
isThemed, | ||
}, | ||
)} | ||
style={ | ||
{ | ||
width: size, | ||
height: size, | ||
...(secondaryColorValue && { | ||
"--ui-icon-secondary-color": secondaryColorValue, | ||
}), | ||
} as CSSProperties | ||
} | ||
{...additionalAttributes} | ||
> | ||
<use xlinkHref={`#sprite-${name}`} /> | ||
</svg> | ||
); | ||
}, | ||
[ | ||
name, | ||
size, | ||
color, | ||
additionalCSS, | ||
additionalAttributes, | ||
lightSecondaryColor, | ||
darkSecondaryColor, | ||
], | ||
); | ||
|
||
if (secondaryColor) { | ||
return ( | ||
<> | ||
{iconSvg(lightSecondaryColor, !!darkSecondaryColor)} | ||
{darkSecondaryColor ? iconSvg(darkSecondaryColor) : null} | ||
</> | ||
); | ||
} else { | ||
return iconSvg(); | ||
} | ||
}; | ||
|
||
export default 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
Oops, something went wrong.