Skip to content

Commit

Permalink
feat: shadcn component testing
Browse files Browse the repository at this point in the history
  • Loading branch information
azaleacolburn committed Jan 20, 2025
1 parent 657fea8 commit 5235326
Show file tree
Hide file tree
Showing 10 changed files with 284 additions and 290 deletions.
Binary file modified bun.lockb
Binary file not shown.
9 changes: 3 additions & 6 deletions components.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://next.shadcn-svelte.com/schema.json",
"$schema": "https://shadcn-svelte.com/schema.json",
"style": "default",
"tailwind": {
"config": "tailwind.config.ts",
Expand All @@ -8,10 +8,7 @@
},
"aliases": {
"components": "$lib/components",
"utils": "$lib/utils",
"ui": "$lib/components/ui",
"hooks": "$lib/hooks"
"utils": "$lib/utils"
},
"typescript": true,
"registry": "https://next.shadcn-svelte.com/registry"
"typescript": true
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^4.0.0",
"autoprefixer": "^10.4.20",
"bits-ui": "next",
"bits-ui": "^0.22.0",
"clsx": "^2.1.1",
"eslint": "^9.7.0",
"eslint-config-prettier": "^9.1.0",
Expand All @@ -33,7 +33,7 @@
"svelte": "^5.0.0",
"svelte-check": "^4.0.0",
"tailwind-merge": "^2.6.0",
"tailwind-variants": "^0.3.0",
"tailwind-variants": "^0.3.1",
"tailwindcss": "^3.4.9",
"tailwindcss-animate": "^1.0.7",
"typescript": "^5.0.0",
Expand Down
227 changes: 73 additions & 154 deletions src/app.css
Original file line number Diff line number Diff line change
@@ -1,159 +1,78 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

@layer utilities {
/* Hide scrollbar for Chrome, Safari and Opera */
.no-scrollbar::-webkit-scrollbar {
display: none;
}
/* Hide scrollbar for IE, Edge and Firefox */
.no-scrollbar {
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}
}


@layer base {
@font-face {
font-family: Teko;
font-style: normal;
font-weight: 300;
src: url(/static/fonts/teko/Teko-Light.ttf) format("tff");
}
@font-face {
font-family: Teko;
font-style: normal;
font-weight: 400;
src: url(/static/fonts/teko/Teko-Regular.ttf) format("tff");
}
@font-face {
font-family: Teko;
font-style: normal;
font-weight: 500;
src: url(/static/fonts/teko/Teko-Medium.ttf) format("tff");
}
@font-face {
font-family: Teko;
font-style: normal;
font-weight: 600;
src: url(/static/fonts/teko/Teko-SemiBold.ttf) format("tff");
}
@font-face {
font-family: Teko;
font-style: normal;
font-weight: 700;
src: url(/static/fonts/teko/Teko-Bold.ttf) format("tff");
}

@font-face {
font-family: Poppins;
font-style: normal;
font-weight: 100;
src: url(/static/fonts/poppins/Poppins-Thin.ttf) format("tff");
}
@font-face {
font-family: Poppins;
font-style: italic;
font-weight: 100;
src: url(/static/fonts/poppins/Poppins-ThinItalic.ttf) format("tff");
}
@font-face {
font-family: Poppins;
font-style: normal;
font-weight: 200;
src: url(/static/fonts/poppins/Poppins-ExtraLight.ttf) format("tff");
}
@font-face {
font-family: Poppins;
font-style: italic;
font-weight: 200;
src: url(/static/fonts/poppins/Poppins-ExtraLightItalic.ttf)
format("tff");
}
@font-face {
font-family: Poppins;
font-style: normal;
font-weight: 300;
src: url(/static/fonts/poppins/Poppins-Light.ttf) format("tff");
}
@font-face {
font-family: Poppins;
font-style: italic;
font-weight: 300;
src: url(/static/fonts/poppins/Poppins-LightItalic.ttf) format("tff");
}
@font-face {
font-family: Poppins;
font-style: normal;
font-weight: 400;
src: url(/static/fonts/poppins/Poppins-Regular.ttf) format("tff");
}
@font-face {
font-family: Poppins;
font-style: italic;
font-weight: 400;
src: url(/static/fonts/poppins/Poppins-Italic.ttf) format("tff");
}
@font-face {
font-family: Poppins;
font-style: normal;
font-weight: 500;
src: url(/static/fonts/poppins/Poppins-Medium.ttf) format("tff");
}
@font-face {
font-family: Poppins;
font-style: italic;
font-weight: 500;
src: url(/static/fonts/poppins/Poppins-MediumItalic.ttf) format("tff");
}
@font-face {
font-family: Poppins;
font-style: normal;
font-weight: 600;
src: url(/static/fonts/poppins/Poppins-SemiBold.ttf) format("tff");
}
@font-face {
font-family: Poppins;
font-style: italic;
font-weight: 600;
src: url(/static/fonts/poppins/Poppins-SemiBoldItalic.ttf) format("tff");
}
@font-face {
font-family: Poppins;
font-style: normal;
font-weight: 700;
src: url(/static/fonts/poppins/Poppins-Bold.ttf) format("tff");
}
@font-face {
font-family: Poppins;
font-style: italic;
font-weight: 700;
src: url(/static/fonts/poppins/Poppins-BoldItalic.ttf) format("tff");
}
@font-face {
font-family: Poppins;
font-style: normal;
font-weight: 800;
src: url(/static/fonts/poppins/Poppins-ExtraBold.ttf) format("tff");
}
@font-face {
font-family: Poppins;
font-style: italic;
font-weight: 800;
src: url(/static/fonts/poppins/Poppins-ExtraBoldItalic.ttf)
format("tff");
}
@font-face {
font-family: Poppins;
font-style: normal;
font-weight: 900;
src: url(/static/fonts/poppins/Poppins-Black.ttf) format("tff");
}
@font-face {
font-family: Poppins;
font-style: italic;
font-weight: 900;
src: url(/static/fonts/poppins/Poppins-BlackItalic.ttf) format("tff");
}
:root {
--background: 0 0% 100%;
--foreground: 224 71.4% 4.1%;

--muted: 220 14.3% 95.9%;
--muted-foreground: 220 8.9% 46.1%;

--popover: 0 0% 100%;
--popover-foreground: 224 71.4% 4.1%;

--card: 0 0% 100%;
--card-foreground: 224 71.4% 4.1%;

--border: 220 13% 91%;
--input: 220 13% 91%;

--primary: 220.9 39.3% 11%;
--primary-foreground: 210 20% 98%;

--secondary: 220 14.3% 95.9%;
--secondary-foreground: 220.9 39.3% 11%;

--accent: 220 14.3% 95.9%;
--accent-foreground: 220.9 39.3% 11%;

--destructive: 0 72.2% 50.6%;
--destructive-foreground: 210 20% 98%;

--ring: 224 71.4% 4.1%;

--radius: 0.5rem;
}

.dark {
--background: 224 71.4% 4.1%;
--foreground: 210 20% 98%;

--muted: 215 27.9% 16.9%;
--muted-foreground: 217.9 10.6% 64.9%;

--popover: 224 71.4% 4.1%;
--popover-foreground: 210 20% 98%;

--card: 224 71.4% 4.1%;
--card-foreground: 210 20% 98%;

--border: 215 27.9% 16.9%;
--input: 215 27.9% 16.9%;

--primary: 210 20% 98%;
--primary-foreground: 220.9 39.3% 11%;

--secondary: 215 27.9% 16.9%;
--secondary-foreground: 210 20% 98%;

--accent: 215 27.9% 16.9%;
--accent-foreground: 210 20% 98%;

--destructive: 0 62.8% 30.6%;
--destructive-foreground: 210 20% 98%;

--ring: 216 12.2% 83.9%;
}
}

@layer base {
* {
@apply border-border;
}
body {
@apply bg-background text-foreground;
}
}
7 changes: 7 additions & 0 deletions src/lib/components/ui/progress/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Root from "./progress.svelte";

export {
Root,
//
Root as Progress,
};
21 changes: 21 additions & 0 deletions src/lib/components/ui/progress/progress.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<script lang="ts">
import { Progress as ProgressPrimitive } from "bits-ui";
import { cn } from "$lib/utils.js";
type $$Props = ProgressPrimitive.Props;
let className: $$Props["class"] = undefined;
export let max: $$Props["max"] = 100;
export let value: $$Props["value"] = undefined;
export { className as class };
</script>

<ProgressPrimitive.Root
class={cn("bg-secondary relative h-4 w-full overflow-hidden rounded-full", className)}
{...$$restProps}
>
<div
class="bg-primary h-full w-full flex-1 transition-all"
style={`transform: translateX(-${100 - (100 * (value ?? 0)) / (max ?? 1)}%)`}
></div>
</ProgressPrimitive.Root>
62 changes: 59 additions & 3 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,62 @@
import { type ClassValue, clsx } from "clsx"
import { twMerge } from "tailwind-merge"
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
import { cubicOut } from "svelte/easing";
import type { TransitionConfig } from "svelte/transition";

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
return twMerge(clsx(inputs));
}

type FlyAndScaleParams = {
y?: number;
x?: number;
start?: number;
duration?: number;
};

export const flyAndScale = (
node: Element,
params: FlyAndScaleParams = { y: -8, x: 0, start: 0.95, duration: 150 }
): TransitionConfig => {
const style = getComputedStyle(node);
const transform = style.transform === "none" ? "" : style.transform;

const scaleConversion = (
valueA: number,
scaleA: [number, number],
scaleB: [number, number]
) => {
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: Record<string, number | string | undefined>
): string => {
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
};
};
Loading

0 comments on commit 5235326

Please sign in to comment.