diff options
| author | Murillo Pinheiro de Oliveira <[email protected]> | 2024-02-06 23:41:43 -0300 |
|---|---|---|
| committer | Murillo Pinheiro de Oliveira <[email protected]> | 2024-02-06 23:41:43 -0300 |
| commit | a02ea8e85d789d5acca9922b61222233bbc09ec6 (patch) | |
| tree | e89f53936e861bf50e8a7503c75723778570b538 /src/lib/shadcn/utils.js | |
| parent | 7e33d06f2952f64815d8c7669f0f057cde20d280 (diff) | |
| download | coinos-ui-a02ea8e85d789d5acca9922b61222233bbc09ec6.tar.gz coinos-ui-a02ea8e85d789d5acca9922b61222233bbc09ec6.zip | |
layout fixes
Diffstat (limited to 'src/lib/shadcn/utils.js')
| -rw-r--r-- | src/lib/shadcn/utils.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/lib/shadcn/utils.js b/src/lib/shadcn/utils.js new file mode 100644 index 00000000..08747b8f --- /dev/null +++ b/src/lib/shadcn/utils.js @@ -0,0 +1,48 @@ +import { clsx } from "clsx"; +import { twMerge } from "tailwind-merge"; +import { cubicOut } from "svelte/easing"; + +export function cn(...inputs) { + return twMerge(clsx(inputs)); +} + +export const flyAndScale = ( + node, + params = { y: -8, x: 0, start: 0.95, duration: 150 } +) => { + const style = getComputedStyle(node); + const transform = style.transform === "none" ? "" : style.transform; + + const scaleConversion = (valueA, scaleA, scaleB) => { + const [minA, maxA] = scaleA; + const [minB, maxB] = scaleB; + + const percentage = (valueA - minA) / (maxA - minA); + const valueB = percentage * (maxB - minB) + minB; + + return valueB; + }; + + const styleToString = (style) => { + return Object.keys(style).reduce((str, key) => { + if (style[key] === undefined) return str; + return str + `${key}:${style[key]};`; + }, ""); + }; + + return { + duration: params.duration ?? 200, + delay: 0, + css: (t) => { + const y = scaleConversion(t, [0, 1], [params.y ?? 5, 0]); + const x = scaleConversion(t, [0, 1], [params.x ?? 0, 0]); + const scale = scaleConversion(t, [0, 1], [params.start ?? 0.95, 1]); + + return styleToString({ + transform: `${transform} translate3d(${x}px, ${y}px, 0) scale(${scale})`, + opacity: t + }); + }, + easing: cubicOut + }; +}; |
