@@ -13,6 +13,8 @@ import { Tooltip, TooltipContent, TooltipTrigger } from "~/components/tooltip";
1313import type { RootLoader } from "~/root" ;
1414import { cn } from "~/utils/cn" ;
1515
16+ const FALLBACK_TO_COLOR_IF_NO_CUSTOM_IMAGE_DEFINED = true ;
17+
1618export let variants = cva (
1719 "border border-line hover:border-body cursor-pointer" ,
1820 {
@@ -151,15 +153,26 @@ export function VariantOption(props: VariantOptionProps) {
151153 let swatchImage = imagesSwatches . find (
152154 ( i ) => i . name . toLowerCase ( ) === value . toLowerCase ( ) ,
153155 ) ;
154- let imageToRender = swatchImage ?. value || image ;
156+ let swatchColor = colorsSwatches . find (
157+ ( c ) => c . name . toLowerCase ( ) === value . toLowerCase ( ) ,
158+ ) ;
159+ let imageToRender = swatchImage ?. value ;
160+ if (
161+ ! imageToRender &&
162+ ! FALLBACK_TO_COLOR_IF_NO_CUSTOM_IMAGE_DEFINED
163+ ) {
164+ // @ts -expect-error
165+ imageToRender = image ;
166+ }
155167 let aspectRatio = "1/1" ;
156- if ( image && shape !== "circle" ) {
168+ if ( imageToRender && shape !== "circle" ) {
157169 aspectRatio = `${ image . width } /${ image . height } ` ;
158170 }
159171 return (
160172 < div
161173 key = { value }
162174 className = { clsx (
175+ "flex" ,
163176 variants ( {
164177 imageSize : size ,
165178 shape,
@@ -192,7 +205,7 @@ export function VariantOption(props: VariantOptionProps) {
192205 "w-full h-full inline-block" ,
193206 variants ( { shape } ) ,
194207 ) }
195- style = { { backgroundColor : value } }
208+ style = { { backgroundColor : swatchColor ?. value || value } }
196209 />
197210 ) }
198211 </ div >
0 commit comments