|
1 | 1 | <script lang="ts"> |
2 | | - import { twMerge } from 'tailwind-merge'; |
3 | 2 | import Button from './Button.svelte'; |
4 | | - import { getContext } from 'svelte'; |
5 | | - import { type GradientButtonProps as Props } from '.'; |
| 3 | + // import { getContext } from 'svelte'; |
| 4 | + import { type GradientButtonProps as Props, gradientButton } from '.'; |
6 | 5 |
|
7 | | - const group = getContext('group'); |
| 6 | + // const group = getContext('group'); |
8 | 7 |
|
9 | | - let { children, outline, pill, color = 'blue', shadow, class: className, onclick, href, target, rel, type, disabled, name, ...restProps }: Props = $props(); |
| 8 | + let { children, outline, pill, color = 'blue', shadow, class: className, href, target, rel, type, disabled, name, ...restProps }: Props = $props(); |
10 | 9 |
|
11 | | - const gradientClasses = { |
12 | | - blue: 'text-white bg-gradient-to-r from-blue-500 via-blue-600 to-blue-700 hover:bg-gradient-to-br focus:ring-blue-300 dark:focus:ring-blue-800 ', |
13 | | - green: 'text-white bg-gradient-to-r from-green-400 via-green-500 to-green-600 hover:bg-gradient-to-br focus:ring-green-300 dark:focus:ring-green-800', |
14 | | - cyan: 'text-white bg-gradient-to-r from-cyan-400 via-cyan-500 to-cyan-600 hover:bg-gradient-to-br focus:ring-cyan-300 dark:focus:ring-cyan-800', |
15 | | - teal: 'text-white bg-gradient-to-r from-teal-400 via-teal-500 to-teal-600 hover:bg-gradient-to-br focus:ring-teal-300 dark:focus:ring-teal-800', |
16 | | - lime: 'text-gray-900 bg-gradient-to-r from-lime-200 via-lime-400 to-lime-500 hover:bg-gradient-to-br focus:ring-lime-300 dark:focus:ring-lime-800', |
17 | | - red: 'text-white bg-gradient-to-r from-red-400 via-red-500 to-red-600 hover:bg-gradient-to-br focus:ring-red-300 dark:focus:ring-red-800', |
18 | | - pink: 'text-white bg-gradient-to-r from-pink-400 via-pink-500 to-pink-600 hover:bg-gradient-to-br focus:ring-pink-300 dark:focus:ring-pink-800', |
19 | | - purple: 'text-white bg-gradient-to-r from-purple-500 via-purple-600 to-purple-700 hover:bg-gradient-to-br focus:ring-purple-300 dark:focus:ring-purple-800', |
20 | | - purpleToBlue: 'text-white bg-gradient-to-br from-purple-600 to-blue-500 hover:bg-gradient-to-bl focus:ring-blue-300 dark:focus:ring-blue-800', |
21 | | - cyanToBlue: 'text-white bg-gradient-to-r from-cyan-500 to-blue-500 hover:bg-gradient-to-bl focus:ring-cyan-300 dark:focus:ring-cyan-800', |
22 | | - greenToBlue: 'text-white bg-gradient-to-br from-green-400 to-blue-600 hover:bg-gradient-to-bl focus:ring-green-200 dark:focus:ring-green-800', |
23 | | - purpleToPink: 'text-white bg-gradient-to-r from-purple-500 to-pink-500 hover:bg-gradient-to-l focus:ring-purple-200 dark:focus:ring-purple-800', |
24 | | - pinkToOrange: 'text-white bg-gradient-to-br from-pink-500 to-orange-400 hover:bg-gradient-to-bl focus:ring-pink-200 dark:focus:ring-pink-800', |
25 | | - tealToLime: 'text-gray-900 bg-gradient-to-r from-teal-200 to-lime-200 hover:bg-gradient-to-l focus:ring-lime-200 dark:focus:ring-teal-700', |
26 | | - redToYellow: 'text-gray-900 bg-gradient-to-r from-red-200 via-red-300 to-yellow-200 hover:bg-gradient-to-bl focus:ring-red-100 dark:focus:ring-red-400' |
27 | | - }; |
| 10 | + const disabledValue = disabled !== null ? disabled : undefined; |
28 | 11 |
|
29 | | - const coloredShadowClasses = { |
30 | | - blue: 'shadow-blue-500/50 dark:shadow-blue-800/80', |
31 | | - green: 'shadow-green-500/50 dark:shadow-green-800/80', |
32 | | - cyan: 'shadow-cyan-500/50 dark:shadow-cyan-800/80', |
33 | | - teal: 'shadow-teal-500/50 dark:shadow-teal-800/80 ', |
34 | | - lime: 'shadow-lime-500/50 dark:shadow-lime-800/80', |
35 | | - red: 'shadow-red-500/50 dark:shadow-red-800/80 ', |
36 | | - pink: 'shadow-pink-500/50 dark:shadow-pink-800/80', |
37 | | - purple: 'shadow-purple-500/50 dark:shadow-purple-800/80', |
38 | | - purpleToBlue: 'shadow-blue-500/50 dark:shadow-blue-800/80', |
39 | | - cyanToBlue: 'shadow-cyan-500/50 dark:shadow-cyan-800/80', |
40 | | - greenToBlue: 'shadow-green-500/50 dark:shadow-green-800/80', |
41 | | - purpleToPink: 'shadow-purple-500/50 dark:shadow-purple-800/80', |
42 | | - pinkToOrange: 'shadow-pink-500/50 dark:shadow-pink-800/80', |
43 | | - tealToLime: 'shadow-lime-500/50 dark:shadow-teal-800/80', |
44 | | - redToYellow: 'shadow-red-500/50 dark:shadow-red-800/80' |
45 | | - }; |
46 | | -
|
47 | | - let gradientOutlineClass: string = twMerge( |
48 | | - 'inline-flex items-center justify-center w-full !border-0', |
49 | | - pill ? 'rounded-full' : '!rounded-md', |
50 | | - 'bg-white !text-gray-900 dark:bg-gray-900 dark:!text-white', // this is limitation - no transparency |
51 | | - 'hover:bg-transparent hover:!text-inherit', |
52 | | - 'transition-all duration-75 ease-in group-hover:!bg-opacity-0 group-hover:!text-inherit' |
53 | | - ); |
54 | | -
|
55 | | - let divClass: string = twMerge(outline && 'p-0.5', gradientClasses[color], shadow && 'shadow-lg', shadow && coloredShadowClasses[color], group ? (pill && 'first:rounded-s-full last:rounded-e-full') || 'first:rounded-s-lg last:rounded-e-lg' : (pill && 'rounded-full') || 'rounded-lg', className); |
| 12 | + const { base, outlineWrapper } = $derived(gradientButton({ color, outline, pill, shadow, disabled: disabledValue })); |
56 | 13 | </script> |
57 | 14 |
|
58 | 15 | {#if outline} |
59 | | - <div class={divClass}> |
60 | | - <Button {...restProps} color="none" class={gradientOutlineClass} {onclick} {disabled} {name} {type} {href} {target} {rel}> |
| 16 | + <div class={base({ className })}> |
| 17 | + <Button {...restProps} color="none" class={outlineWrapper()} {disabled} {name} {type} {href} {target} {rel}> |
61 | 18 | {@render children()} |
62 | 19 | </Button> |
63 | 20 | </div> |
64 | 21 | {:else} |
65 | | - <Button {...restProps} color="none" class={divClass} {onclick} {disabled} {name} {type} {href} {target} {rel}> |
| 22 | + <Button {...restProps} color="none" class={base({ className })} {disabled} {name} {type} {href} {target} {rel}> |
66 | 23 | {@render children()} |
67 | 24 | </Button> |
68 | 25 | {/if} |
|
0 commit comments