11<script >
22 import { onMount } from ' svelte' ;
3- export let action_label;
4- export let color = " #00D690" ;
5- let contrastedColor = ' ' ;
3+
4+ /** @type {{ action_label: string, color?: string }} */
5+ let { action_label, color = " #00D690" } = $props ();
6+
7+ let contrastedColor = $state (' ' );
8+
9+ /**
10+ * @param {string} hex
11+ * @param {number} percent
12+ */
613 function darkenColor (hex , percent ) {
714 const num = parseInt (hex .slice (1 ), 16 ),
815 amt = Math .round (2.55 * percent),
1825 .toString (16 )
1926 .slice (1 )} ` ;
2027 }
21- let darkerColor = darkenColor (color, 7 );
28+
29+ let darkerColor = $derived (darkenColor (color, 7 ));
30+
2231 onMount (async () => {
23- const fontColorContrast = (await import (' font-color-contrast' )).default ;
24- contrastedColor = fontColorContrast (color);
25- });
32+ const fontColorContrast = (await import (' font-color-contrast' )).default ;
33+ contrastedColor = fontColorContrast (color);
34+ });
2635 </script >
2736
28- <button class ="Button min-w-[137px] h-12 px-6 py-2 rounded-3xl justify-center items-center inline-flex hover:bg-white/75 transition ease-in duration-150" style ={
29- ` background-color: ${color };
30- color: ${contrastedColor }; `
31- } onMouseOver ="this.style.backgroundColor=' {darkerColor }'" onMouseOut ="this.style.backgroundColor=' {color }'" >
32- <span class ="Button text-base font-['Albert Sans'] uppercase leading-normal font-bold" > {action_label }</span >
37+ <button
38+ class =" Button min-w-[137px] h-12 px-6 py-2 rounded-3xl justify-center items-center inline-flex hover:bg-white/75 transition ease-in duration-150"
39+ style ={` background-color: ${color }; color: ${contrastedColor }; ` }
40+ onmouseover ={(e ) => { e .currentTarget .style .backgroundColor = darkerColor ; }}
41+ onmouseout ={(e ) => { e .currentTarget .style .backgroundColor = color ; }}
42+ onfocus ={(e ) => { e .currentTarget .style .backgroundColor = darkerColor ; }}
43+ onblur ={(e ) => { e .currentTarget .style .backgroundColor = color ; }}
44+ >
45+ <span class ="Button text-base font-['Albert Sans'] uppercase leading-normal font-bold" >{action_label }</span >
3346</button >
0 commit comments