Skip to content

Commit 36d9abc

Browse files
committed
chore: init shadcn-svelte demo
1 parent b1304c3 commit 36d9abc

21 files changed

+1170
-22
lines changed

examples/shadcn-svelte/.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.DS_Store
2+
node_modules
3+
/build
4+
/.svelte-kit
5+
/package
6+
.env
7+
.env.*
8+
!.env.example
9+
vite.config.js.timestamp-*
10+
vite.config.ts.timestamp-*

examples/shadcn-svelte/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
engine-strict=true

examples/shadcn-svelte/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# create-svelte
2+
3+
Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/main/packages/create-svelte).
4+
5+
## Creating a project
6+
7+
If you're seeing this, you've probably already done this step. Congrats!
8+
9+
```bash
10+
# create a new project in the current directory
11+
npm create svelte@latest
12+
13+
# create a new project in my-app
14+
npm create svelte@latest my-app
15+
```
16+
17+
## Developing
18+
19+
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
20+
21+
```bash
22+
npm run dev
23+
24+
# or start the server and open the app in a new browser tab
25+
npm run dev -- --open
26+
```
27+
28+
## Building
29+
30+
To create a production version of your app:
31+
32+
```bash
33+
npm run build
34+
```
35+
36+
You can preview the production build with `npm run preview`.
37+
38+
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"$schema": "https://shadcn-svelte.com/schema.json",
3+
"style": "default",
4+
"tailwind": {
5+
"config": "tailwind.config.js",
6+
"css": "src/app.pcss",
7+
"baseColor": "neutral"
8+
},
9+
"aliases": {
10+
"components": "$lib/components",
11+
"utils": "$lib/utils"
12+
}
13+
}

examples/shadcn-svelte/package.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "shadcn-svelte",
3+
"version": "0.0.1",
4+
"private": true,
5+
"scripts": {
6+
"dev": "vite dev",
7+
"build": "vite build",
8+
"preview": "vite preview",
9+
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
10+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
11+
},
12+
"devDependencies": {
13+
"@sveltejs/adapter-auto": "^3.0.0",
14+
"@sveltejs/kit": "^2.0.0",
15+
"@sveltejs/vite-plugin-svelte": "^3.0.0",
16+
"autoprefixer": "^10.4.16",
17+
"postcss": "^8.4.32",
18+
"postcss-load-config": "^5.0.2",
19+
"svelte": "^4.2.7",
20+
"svelte-check": "^3.6.0",
21+
"tailwindcss": "^3.3.6",
22+
"tslib": "^2.4.1",
23+
"typescript": "^5.0.0",
24+
"vite": "^5.0.3"
25+
},
26+
"type": "module",
27+
"dependencies": {
28+
"bits-ui": "^0.11.8",
29+
"clsx": "^2.0.0",
30+
"lucide-svelte": "^0.299.0",
31+
"tailwind-merge": "^2.1.0",
32+
"tailwind-variants": "^0.1.19"
33+
}
34+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const tailwindcss = require("tailwindcss")
2+
const autoprefixer = require("autoprefixer")
3+
4+
const config = {
5+
plugins: [
6+
//Some plugins, like tailwindcss/nesting, need to run before Tailwind,
7+
tailwindcss(),
8+
//But others, like autoprefixer, need to run after,
9+
autoprefixer,
10+
],
11+
}
12+
13+
module.exports = config

examples/shadcn-svelte/src/app.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// See https://kit.svelte.dev/docs/types#app
2+
// for information about these interfaces
3+
declare global {
4+
namespace App {
5+
// interface Error {}
6+
// interface Locals {}
7+
// interface PageData {}
8+
// interface PageState {}
9+
// interface Platform {}
10+
}
11+
}
12+
13+
export {}

examples/shadcn-svelte/src/app.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
%sveltekit.head%
8+
</head>
9+
<body data-sveltekit-preload-data="hover">
10+
<div style="display: contents">%sveltekit.body%</div>
11+
</body>
12+
</html>

examples/shadcn-svelte/src/app.pcss

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
@tailwind base;
2+
@tailwind components;
3+
@tailwind utilities;
4+
5+
@layer base {
6+
:root {
7+
--background: 0 0% 100%;
8+
--foreground: 0 0% 3.9%;
9+
10+
--muted: 0 0% 96.1%;
11+
--muted-foreground: 0 0% 45.1%;
12+
13+
--popover: 0 0% 100%;
14+
--popover-foreground: 0 0% 3.9%;
15+
16+
--card: 0 0% 100%;
17+
--card-foreground: 0 0% 3.9%;
18+
19+
--border: 0 0% 89.8%;
20+
--input: 0 0% 89.8%;
21+
22+
--primary: 0 0% 9%;
23+
--primary-foreground: 0 0% 98%;
24+
25+
--secondary: 0 0% 96.1%;
26+
--secondary-foreground: 0 0% 9%;
27+
28+
--accent: 0 0% 96.1%;
29+
--accent-foreground: 0 0% 9%;
30+
31+
--destructive: 0 72.2% 50.6%;
32+
--destructive-foreground: 0 0% 98%;
33+
34+
--ring: 0 0% 3.9%;
35+
36+
--radius: 0.5rem;
37+
}
38+
39+
.dark {
40+
--background: 0 0% 3.9%;
41+
--foreground: 0 0% 98%;
42+
43+
--muted: 0 0% 14.9%;
44+
--muted-foreground: 0 0% 63.9%;
45+
46+
--popover: 0 0% 3.9%;
47+
--popover-foreground: 0 0% 98%;
48+
49+
--card: 0 0% 3.9%;
50+
--card-foreground: 0 0% 98%;
51+
52+
--border: 0 0% 14.9%;
53+
--input: 0 0% 14.9%;
54+
55+
--primary: 0 0% 98%;
56+
--primary-foreground: 0 0% 9%;
57+
58+
--secondary: 0 0% 14.9%;
59+
--secondary-foreground: 0 0% 98%;
60+
61+
--accent: 0 0% 14.9%;
62+
--accent-foreground: 0 0% 98%;
63+
64+
--destructive: 0 62.8% 30.6%;
65+
--destructive-foreground: 0 0% 98%;
66+
67+
--ring: 0 0% 83.1%;
68+
}
69+
}
70+
71+
@layer base {
72+
* {
73+
@apply border-border;
74+
}
75+
body {
76+
@apply bg-background text-foreground;
77+
}
78+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<script lang="ts">
2+
import { Button as ButtonPrimitive } from "bits-ui";
3+
import { cn } from "$lib/utils";
4+
import { buttonVariants, type Props, type Events } from ".";
5+
6+
type $$Props = Props;
7+
type $$Events = Events;
8+
9+
let className: $$Props["class"] = undefined;
10+
export let variant: $$Props["variant"] = "default";
11+
export let size: $$Props["size"] = "default";
12+
export let builders: $$Props["builders"] = [];
13+
export { className as class };
14+
</script>
15+
16+
<ButtonPrimitive.Root
17+
{builders}
18+
class={cn(buttonVariants({ variant, size, className }))}
19+
type="button"
20+
{...$$restProps}
21+
on:click
22+
on:keydown
23+
>
24+
<slot />
25+
</ButtonPrimitive.Root>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { tv } from "tailwind-variants"
2+
3+
import Root from "./button.svelte"
4+
5+
import type { Button as ButtonPrimitive } from "bits-ui"
6+
import type { VariantProps } from "tailwind-variants"
7+
8+
const buttonVariants = tv({
9+
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",
10+
variants: {
11+
variant: {
12+
default: "bg-primary text-primary-foreground hover:bg-primary/90",
13+
destructive:
14+
"bg-destructive text-destructive-foreground hover:bg-destructive/90",
15+
outline:
16+
"border border-input bg-background hover:bg-accent hover:text-accent-foreground",
17+
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
18+
ghost: "hover:bg-accent hover:text-accent-foreground",
19+
link: "text-primary underline-offset-4 hover:underline",
20+
},
21+
size: {
22+
default: "h-10 px-4 py-2",
23+
sm: "h-9 rounded-md px-3",
24+
lg: "h-11 rounded-md px-8",
25+
icon: "h-10 w-10",
26+
},
27+
},
28+
defaultVariants: {
29+
variant: "default",
30+
size: "default",
31+
},
32+
})
33+
34+
type Variant = VariantProps<typeof buttonVariants>["variant"]
35+
type Size = VariantProps<typeof buttonVariants>["size"]
36+
37+
type Props = ButtonPrimitive.Props & {
38+
variant?: Variant
39+
size?: Size
40+
}
41+
42+
type Events = ButtonPrimitive.Events
43+
44+
export {
45+
Root,
46+
type Props,
47+
type Events,
48+
//
49+
Root as Button,
50+
type Props as ButtonProps,
51+
type Events as ButtonEvents,
52+
buttonVariants,
53+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// place files you want to import through the `$lib` alias in this folder.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { clsx } from "clsx"
2+
import { cubicOut } from "svelte/easing"
3+
import { twMerge } from "tailwind-merge"
4+
5+
import type { ClassValue } from "clsx"
6+
import type { TransitionConfig } from "svelte/transition"
7+
8+
export function cn(...inputs: ClassValue[]) {
9+
return twMerge(clsx(inputs))
10+
}
11+
12+
type FlyAndScaleParams = {
13+
y?: number
14+
x?: number
15+
start?: number
16+
duration?: number
17+
}
18+
19+
export const flyAndScale = (
20+
node: Element,
21+
params: FlyAndScaleParams = { y: -8, x: 0, start: 0.95, duration: 150 },
22+
): TransitionConfig => {
23+
const style = getComputedStyle(node)
24+
const transform = style.transform === "none" ? "" : style.transform
25+
26+
const scaleConversion = (
27+
valueA: number,
28+
scaleA: [number, number],
29+
scaleB: [number, number],
30+
) => {
31+
const [minA, maxA] = scaleA
32+
const [minB, maxB] = scaleB
33+
34+
const percentage = (valueA - minA) / (maxA - minA)
35+
const valueB = percentage * (maxB - minB) + minB
36+
37+
return valueB
38+
}
39+
40+
const styleToString = (
41+
style: Record<string, number | string | undefined>,
42+
): string => {
43+
return Object.keys(style).reduce((str, key) => {
44+
if (style[key] === undefined) return str
45+
return str + `${key}:${style[key]};`
46+
}, "")
47+
}
48+
49+
return {
50+
duration: params.duration ?? 200,
51+
delay: 0,
52+
css: (t) => {
53+
const y = scaleConversion(t, [0, 1], [params.y ?? 5, 0])
54+
const x = scaleConversion(t, [0, 1], [params.x ?? 0, 0])
55+
const scale = scaleConversion(t, [0, 1], [params.start ?? 0.95, 1])
56+
57+
return styleToString({
58+
transform: `${transform} translate3d(${x}px, ${y}px, 0) scale(${scale})`,
59+
opacity: t,
60+
})
61+
},
62+
easing: cubicOut,
63+
}
64+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<script>import "../app.pcss";</script><slot></slot>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<script lang="ts">
2+
import { Button } from "$lib/components/ui/button";
3+
</script>
4+
<Button >Button</Button>
1.53 KB
Loading
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import adapter from "@sveltejs/adapter-auto"
2+
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte"
3+
4+
/** @type {import('@sveltejs/kit').Config} */
5+
const config = {
6+
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
7+
// for more information about preprocessors
8+
preprocess: [vitePreprocess({})],
9+
10+
kit: {
11+
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
12+
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
13+
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
14+
adapter: adapter(),
15+
},
16+
}
17+
18+
export default config

0 commit comments

Comments
 (0)