diff options
| author | Adam Soltys <[email protected]> | 2024-03-19 10:23:34 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-03-19 10:23:34 -0700 |
| commit | a4685f61e656ed0e3cd343073931867955be3281 (patch) | |
| tree | c28c446ef0f6d5cbc37a7c58f954c145bd18ef80 /src/lib | |
| parent | c6c2ac113186ba304c46580320df91c119ab5314 (diff) | |
| parent | e2bb9d704878070054fa8ef81da73b248e2c4f97 (diff) | |
| download | coinos-ui-a4685f61e656ed0e3cd343073931867955be3281.tar.gz coinos-ui-a4685f61e656ed0e3cd343073931867955be3281.zip | |
Merge remote-tracking branch 'muriwolf/swapee' into swapee
Diffstat (limited to 'src/lib')
20 files changed, 431 insertions, 1 deletions
diff --git a/src/lib/shadcn/components/ui/accordion/accordion-content.svelte b/src/lib/shadcn/components/ui/accordion/accordion-content.svelte new file mode 100644 index 00000000..14328e88 --- /dev/null +++ b/src/lib/shadcn/components/ui/accordion/accordion-content.svelte @@ -0,0 +1,22 @@ +<script> + import { Accordion as AccordionPrimitive } from "bits-ui"; + import { cn } from "$lib/shadcn/utils"; + import { slide } from "svelte/transition"; + let className = undefined; + export let transition = slide; + export let transitionConfig = { + duration: 200, + }; + export { className as class }; +</script> + +<AccordionPrimitive.Content + class={cn("overflow-hidden text-sm transition-all", className)} + {transition} + {transitionConfig} + {...$$restProps} +> + <div class="pb-4 pt-0"> + <slot /> + </div> +</AccordionPrimitive.Content> diff --git a/src/lib/shadcn/components/ui/accordion/accordion-item.svelte b/src/lib/shadcn/components/ui/accordion/accordion-item.svelte new file mode 100644 index 00000000..b0887d7e --- /dev/null +++ b/src/lib/shadcn/components/ui/accordion/accordion-item.svelte @@ -0,0 +1,11 @@ +<script> + import { Accordion as AccordionPrimitive } from "bits-ui"; + import { cn } from "$lib/shadcn/utils"; + let className = undefined; + export let value; + export { className as class }; +</script> + +<AccordionPrimitive.Item {value} class={cn("border-b", className)} {...$$restProps}> + <slot /> +</AccordionPrimitive.Item> diff --git a/src/lib/shadcn/components/ui/accordion/accordion-trigger.svelte b/src/lib/shadcn/components/ui/accordion/accordion-trigger.svelte new file mode 100644 index 00000000..8acf4675 --- /dev/null +++ b/src/lib/shadcn/components/ui/accordion/accordion-trigger.svelte @@ -0,0 +1,22 @@ +<script> + import { Accordion as AccordionPrimitive } from "bits-ui"; + import { ChevronDown } from "lucide-svelte"; + import { cn } from "$lib/shadcn/utils"; + let className = undefined; + export let level = 3; + export { className as class }; +</script> + +<AccordionPrimitive.Header {level} class="flex"> + <AccordionPrimitive.Trigger + class={cn( + "flex flex-1 items-center justify-between py-2 font-medium transition-all [&[data-state=open]>svg]:rotate-180", + className + )} + {...$$restProps} + on:click + > + <slot /> + <ChevronDown class="h-4 w-4 transition-transform duration-200" /> + </AccordionPrimitive.Trigger> +</AccordionPrimitive.Header> diff --git a/src/lib/shadcn/components/ui/accordion/index.js b/src/lib/shadcn/components/ui/accordion/index.js new file mode 100644 index 00000000..d75ea273 --- /dev/null +++ b/src/lib/shadcn/components/ui/accordion/index.js @@ -0,0 +1,16 @@ +import { Accordion as AccordionPrimitive } from "bits-ui"; +import Content from "./accordion-content.svelte"; +import Item from "./accordion-item.svelte"; +import Trigger from "./accordion-trigger.svelte"; +const Root = AccordionPrimitive.Root; +export { + Root, + Content, + Item, + Trigger, + // + Root as Accordion, + Content as AccordionContent, + Item as AccordionItem, + Trigger as AccordionTrigger, +}; diff --git a/src/lib/shadcn/components/ui/button/button.svelte b/src/lib/shadcn/components/ui/button/button.svelte new file mode 100644 index 00000000..775b9f09 --- /dev/null +++ b/src/lib/shadcn/components/ui/button/button.svelte @@ -0,0 +1,21 @@ +<script> + import { Button as ButtonPrimitive } from "bits-ui"; + import { cn } from "$lib/shadcn/utils"; + import { buttonVariants } from "."; + let className = undefined; + export let variant = "default"; + export let size = "default"; + export let builders = []; + export { className as class }; +</script> + +<ButtonPrimitive.Root + {builders} + class={cn(buttonVariants({ variant, size, className }))} + type="button" + {...$$restProps} + on:click + on:keydown +> + <slot /> +</ButtonPrimitive.Root> diff --git a/src/lib/shadcn/components/ui/button/index.js b/src/lib/shadcn/components/ui/button/index.js new file mode 100644 index 00000000..96d93665 --- /dev/null +++ b/src/lib/shadcn/components/ui/button/index.js @@ -0,0 +1,32 @@ +import Root from "./button.svelte"; +import { tv } from "tailwind-variants"; +const buttonVariants = tv({ + base: "inline-flex items-center justify-center rounded-md text-sm font-medium whitespace-nowrap ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50", + variants: { + variant: { + default: "bg-primary text-primary-foreground hover:bg-primary/90", + destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90", + outline: + "border border-input bg-background hover:bg-accent hover:text-accent-foreground", + secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80", + ghost: "hover:bg-accent hover:text-accent-foreground", + link: "text-primary underline-offset-4 hover:underline", + }, + size: { + default: "h-10 px-4 py-2", + sm: "h-9 rounded-md px-3", + lg: "h-11 rounded-md px-8", + icon: "h-10 w-10", + }, + }, + defaultVariants: { + variant: "default", + size: "default", + }, +}); +export { + Root, + // + Root as Button, + buttonVariants, +}; diff --git a/src/lib/shadcn/components/ui/separator/index.js b/src/lib/shadcn/components/ui/separator/index.js new file mode 100644 index 00000000..073c5c4c --- /dev/null +++ b/src/lib/shadcn/components/ui/separator/index.js @@ -0,0 +1,6 @@ +import Root from "./separator.svelte"; +export { + Root, + // + Root as Separator, +}; diff --git a/src/lib/shadcn/components/ui/separator/separator.svelte b/src/lib/shadcn/components/ui/separator/separator.svelte new file mode 100644 index 00000000..b07c93ea --- /dev/null +++ b/src/lib/shadcn/components/ui/separator/separator.svelte @@ -0,0 +1,19 @@ +<script> + import { Separator as SeparatorPrimitive } from "bits-ui"; + import { cn } from "$lib/shadcn/utils"; + let className = undefined; + export let orientation = "horizontal"; + export let decorative = undefined; + export { className as class }; +</script> + +<SeparatorPrimitive.Root + class={cn( + "shrink-0 bg-border", + orientation === "horizontal" ? "h-[1px] w-full" : "h-full w-[1px]", + className + )} + {orientation} + {decorative} + {...$$restProps} +/> diff --git a/src/lib/shadcn/components/ui/sheet/index.js b/src/lib/shadcn/components/ui/sheet/index.js new file mode 100644 index 00000000..c892767c --- /dev/null +++ b/src/lib/shadcn/components/ui/sheet/index.js @@ -0,0 +1,99 @@ +import { Dialog as SheetPrimitive } from "bits-ui"; +import { tv } from "tailwind-variants"; +import Portal from "./sheet-portal.svelte"; +import Overlay from "./sheet-overlay.svelte"; +import Content from "./sheet-content.svelte"; +import Header from "./sheet-header.svelte"; +import Footer from "./sheet-footer.svelte"; +import Title from "./sheet-title.svelte"; +import Description from "./sheet-description.svelte"; +const Root = SheetPrimitive.Root; +const Close = SheetPrimitive.Close; +const Trigger = SheetPrimitive.Trigger; +export { + Root, + Close, + Trigger, + Portal, + Overlay, + Content, + Header, + Footer, + Title, + Description, + // + Root as Sheet, + Close as SheetClose, + Trigger as SheetTrigger, + Portal as SheetPortal, + Overlay as SheetOverlay, + Content as SheetContent, + Header as SheetHeader, + Footer as SheetFooter, + Title as SheetTitle, + Description as SheetDescription, +}; +export const sheetVariants = tv({ + base: "fixed z-50 gap-4 bg-background p-6 shadow-lg", + variants: { + side: { + top: "inset-x-0 top-0 border-b", + bottom: "inset-x-0 bottom-0 border-t", + left: "inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm", + right: "inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm", + }, + }, + defaultVariants: { + side: "right", + }, +}); +export const sheetTransitions = { + top: { + in: { + y: "-100%", + duration: 500, + opacity: 1, + }, + out: { + y: "-100%", + duration: 300, + opacity: 1, + }, + }, + bottom: { + in: { + y: "100%", + duration: 500, + opacity: 1, + }, + out: { + y: "100%", + duration: 300, + opacity: 1, + }, + }, + left: { + in: { + x: "-100%", + duration: 500, + opacity: 1, + }, + out: { + x: "-100%", + duration: 300, + opacity: 1, + }, + }, + right: { + in: { + x: "100%", + duration: 500, + opacity: 1, + }, + out: { + x: "100%", + duration: 300, + opacity: 1, + }, + }, +}; diff --git a/src/lib/shadcn/components/ui/sheet/sheet-content.svelte b/src/lib/shadcn/components/ui/sheet/sheet-content.svelte new file mode 100644 index 00000000..8e7a0ffd --- /dev/null +++ b/src/lib/shadcn/components/ui/sheet/sheet-content.svelte @@ -0,0 +1,34 @@ +<script> + import { Dialog as SheetPrimitive } from "bits-ui"; + import X from "lucide-svelte/icons/x"; + import { SheetOverlay, SheetPortal, sheetTransitions, sheetVariants } from "."; + import { cn } from "$lib/shadcn/utils"; + import { fly } from "svelte/transition"; + let className = undefined; + export let side = "right"; + export { className as class }; + export let inTransition = fly; + export let inTransitionConfig = sheetTransitions[side ? side : "right"]["in"]; + export let outTransition = fly; + export let outTransitionConfig = sheetTransitions[side ? side : "right"]["out"]; +</script> + +<SheetPortal> + <SheetOverlay /> + <SheetPrimitive.Content + {inTransition} + {inTransitionConfig} + {outTransition} + {outTransitionConfig} + class={cn(sheetVariants({ side }), className)} + {...$$restProps} + > + <slot /> + <SheetPrimitive.Close + class="absolute right-4 top-4 rounded-sm opacity-100 ring-offset-background hover:bg-swapee-purple transition-all focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-black dark:data-[state=open]:bg-white" + > + <X class="h-8 w-8" /> + <span class="sr-only">Close</span> + </SheetPrimitive.Close> + </SheetPrimitive.Content> +</SheetPortal> diff --git a/src/lib/shadcn/components/ui/sheet/sheet-description.svelte b/src/lib/shadcn/components/ui/sheet/sheet-description.svelte new file mode 100644 index 00000000..9f75b9f4 --- /dev/null +++ b/src/lib/shadcn/components/ui/sheet/sheet-description.svelte @@ -0,0 +1,10 @@ +<script> + import { Dialog as SheetPrimitive } from "bits-ui"; + import { cn } from "$lib/shadcn/utils"; + let className = undefined; + export { className as class }; +</script> + +<SheetPrimitive.Description class={cn("text-sm text-muted-foreground", className)} {...$$restProps}> + <slot /> +</SheetPrimitive.Description> diff --git a/src/lib/shadcn/components/ui/sheet/sheet-footer.svelte b/src/lib/shadcn/components/ui/sheet/sheet-footer.svelte new file mode 100644 index 00000000..3a958ac9 --- /dev/null +++ b/src/lib/shadcn/components/ui/sheet/sheet-footer.svelte @@ -0,0 +1,12 @@ +<script> + import { cn } from "$lib/shadcn/utils"; + let className = undefined; + export { className as class }; +</script> + +<div + class={cn("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2", className)} + {...$$restProps} +> + <slot /> +</div> diff --git a/src/lib/shadcn/components/ui/sheet/sheet-header.svelte b/src/lib/shadcn/components/ui/sheet/sheet-header.svelte new file mode 100644 index 00000000..c6c098a4 --- /dev/null +++ b/src/lib/shadcn/components/ui/sheet/sheet-header.svelte @@ -0,0 +1,9 @@ +<script> + import { cn } from "$lib/shadcn/utils"; + let className = undefined; + export { className as class }; +</script> + +<div class={cn("flex flex-col space-y-2 text-center sm:text-left", className)} {...$$restProps}> + <slot /> +</div> diff --git a/src/lib/shadcn/components/ui/sheet/sheet-overlay.svelte b/src/lib/shadcn/components/ui/sheet/sheet-overlay.svelte new file mode 100644 index 00000000..8f308ce9 --- /dev/null +++ b/src/lib/shadcn/components/ui/sheet/sheet-overlay.svelte @@ -0,0 +1,18 @@ +<script> + import { Dialog as SheetPrimitive } from "bits-ui"; + import { cn } from "$lib/shadcn/utils"; + import { fade } from "svelte/transition"; + let className = undefined; + export let transition = fade; + export let transitionConfig = { + duration: 150, + }; + export { className as class }; +</script> + +<SheetPrimitive.Overlay + {transition} + {transitionConfig} + class={cn("fixed inset-0 z-50 bg-background/80 backdrop-blur-sm ", className)} + {...$$restProps} +/> diff --git a/src/lib/shadcn/components/ui/sheet/sheet-portal.svelte b/src/lib/shadcn/components/ui/sheet/sheet-portal.svelte new file mode 100644 index 00000000..c7384693 --- /dev/null +++ b/src/lib/shadcn/components/ui/sheet/sheet-portal.svelte @@ -0,0 +1,10 @@ +<script> + import { Dialog as SheetPrimitive } from "bits-ui"; + import { cn } from "$lib/shadcn/utils"; + let className = undefined; + export { className as class }; +</script> + +<SheetPrimitive.Portal class={cn(className)} {...$$restProps}> + <slot /> +</SheetPrimitive.Portal> diff --git a/src/lib/shadcn/components/ui/sheet/sheet-title.svelte b/src/lib/shadcn/components/ui/sheet/sheet-title.svelte new file mode 100644 index 00000000..1a285c75 --- /dev/null +++ b/src/lib/shadcn/components/ui/sheet/sheet-title.svelte @@ -0,0 +1,13 @@ +<script> + import { Dialog as SheetPrimitive } from "bits-ui"; + import { cn } from "$lib/shadcn/utils"; + let className = undefined; + export { className as class }; +</script> + +<SheetPrimitive.Title + class={cn("text-lg font-semibold text-foreground", className)} + {...$$restProps} +> + <slot /> +</SheetPrimitive.Title> diff --git a/src/lib/shadcn/components/ui/switch/index.js b/src/lib/shadcn/components/ui/switch/index.js new file mode 100644 index 00000000..7745ca39 --- /dev/null +++ b/src/lib/shadcn/components/ui/switch/index.js @@ -0,0 +1,6 @@ +import Root from "./switch.svelte"; +export { + Root, + // + Root as Switch, +}; diff --git a/src/lib/shadcn/components/ui/switch/switch.svelte b/src/lib/shadcn/components/ui/switch/switch.svelte new file mode 100644 index 00000000..69c08b03 --- /dev/null +++ b/src/lib/shadcn/components/ui/switch/switch.svelte @@ -0,0 +1,22 @@ +<script> + import { Switch as SwitchPrimitive } from "bits-ui"; + import { cn } from "$lib/shadcn/utils"; + let className = undefined; + export let checked = undefined; + export { className as class }; +</script> + +<SwitchPrimitive.Root + bind:checked + class={cn( + "peer inline-flex h-[24px] w-[44px] shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input", + className + )} + {...$$restProps} +> + <SwitchPrimitive.Thumb + class={cn( + "pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0" + )} + /> +</SwitchPrimitive.Root> 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 + }; +}; diff --git a/src/lib/utils.js b/src/lib/utils.js index 738413bf..434ca268 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -300,4 +300,4 @@ export let isLiquid = (text) => (text.startsWith("ert1q") && text.length === 43) || (text.startsWith("ex1q") && text.length === 42) || text.startsWith("el1qq") || - text.startsWith("lq1qq"); + text.startsWith("lq1qq");
\ No newline at end of file |
