-
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
634539a
commit 1e9e54e
Showing
30 changed files
with
1,430 additions
and
1,770 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
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 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,92 @@ | ||
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, isDark?: boolean, 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 && !isDark && isThemed, | ||
}, | ||
{ | ||
"dark:hidden": secondaryColor && isDark && 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 (lightSecondaryColor && darkSecondaryColor) { | ||
return ( | ||
<> | ||
{iconSvg(lightSecondaryColor, false, !!darkSecondaryColor)} | ||
{iconSvg(darkSecondaryColor, true, true)} | ||
</> | ||
); | ||
} else if (lightSecondaryColor) { | ||
return iconSvg(lightSecondaryColor, false, !!darkSecondaryColor); | ||
} else { | ||
return iconSvg(); | ||
} | ||
}; | ||
|
||
export default Icon; |
Oops, something went wrong.