weeee💃

This commit is contained in:
Mohamad 2025-01-02 14:51:37 +01:00
commit 23a1debeb7
34 changed files with 5685 additions and 0 deletions

21
.gitignore vendored Normal file
View File

@ -0,0 +1,21 @@
node_modules
# Output
.output
.vercel
/.svelte-kit
/build
# OS
.DS_Store
Thumbs.db
# Env
.env
.env.*
!.env.example
!.env.test
# Vite
vite.config.js.timestamp-*
vite.config.ts.timestamp-*

1
.npmrc Normal file
View File

@ -0,0 +1 @@
engine-strict=true

4
.prettierignore Normal file
View File

@ -0,0 +1,4 @@
# Package Managers
package-lock.json
pnpm-lock.yaml
yarn.lock

15
.prettierrc Normal file
View File

@ -0,0 +1,15 @@
{
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
"printWidth": 100,
"plugins": ["prettier-plugin-svelte", "prettier-plugin-tailwindcss"],
"overrides": [
{
"files": "*.svelte",
"options": {
"parser": "svelte"
}
}
]
}

38
README.md Normal file
View File

@ -0,0 +1,38 @@
# create-svelte
Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/main/packages/create-svelte).
## Creating a project
If you're seeing this, you've probably already done this step. Congrats!
```bash
# create a new project in the current directory
npm create svelte@latest
# create a new project in my-app
npm create svelte@latest my-app
```
## Developing
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
```bash
npm run dev
# or start the server and open the app in a new browser tab
npm run dev -- --open
```
## Building
To create a production version of your app:
```bash
npm run build
```
You can preview the production build with `npm run preview`.
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.

14
components.json Normal file
View File

@ -0,0 +1,14 @@
{
"$schema": "https://shadcn-svelte.com/schema.json",
"style": "default",
"tailwind": {
"config": "tailwind.config.ts",
"css": "src\\app.css",
"baseColor": "slate"
},
"aliases": {
"components": "$lib/components",
"utils": "$lib/utils"
},
"typescript": true
}

33
eslint.config.js Normal file
View File

@ -0,0 +1,33 @@
import js from '@eslint/js';
import ts from 'typescript-eslint';
import svelte from 'eslint-plugin-svelte';
import prettier from 'eslint-config-prettier';
import globals from 'globals';
/** @type {import('eslint').Linter.Config[]} */
export default [
js.configs.recommended,
...ts.configs.recommended,
...svelte.configs['flat/recommended'],
prettier,
...svelte.configs['flat/prettier'],
{
languageOptions: {
globals: {
...globals.browser,
...globals.node
}
}
},
{
files: ['**/*.svelte'],
languageOptions: {
parserOptions: {
parser: ts.parser
}
}
},
{
ignores: ['build/', '.svelte-kit/', 'dist/']
}
];

5144
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

46
package.json Normal file
View File

@ -0,0 +1,46 @@
{
"name": "webshop",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"test": "npm run test:integration && npm run test:unit",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --check . && eslint .",
"format": "prettier --write .",
"test:integration": "playwright test",
"test:unit": "vitest"
},
"devDependencies": {
"@playwright/test": "^1.28.1",
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/kit": "^2.5.27",
"@sveltejs/vite-plugin-svelte": "^4.0.0",
"@tailwindcss/typography": "^0.5.14",
"@types/eslint": "^9.6.0",
"autoprefixer": "^10.4.20",
"eslint": "^9.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.45.1",
"globals": "^15.0.0",
"prettier": "^3.1.1",
"prettier-plugin-svelte": "^3.2.6",
"prettier-plugin-tailwindcss": "^0.6.5",
"svelte": "^5.0.0",
"svelte-check": "^4.0.0",
"tailwindcss": "^3.4.9",
"typescript": "^5.5.0",
"typescript-eslint": "^8.0.0",
"vite": "^5.4.4",
"vitest": "^2.0.0"
},
"type": "module",
"dependencies": {
"flowbite": "^2.5.1",
"flowbite-svelte": "^0.46.16",
"flowbite-svelte-icons": "^1.6.1"
}
}

12
playwright.config.ts Normal file
View File

@ -0,0 +1,12 @@
import type { PlaywrightTestConfig } from '@playwright/test';
const config: PlaywrightTestConfig = {
webServer: {
command: 'npm run build && npm run preview',
port: 4173
},
testDir: 'tests',
testMatch: /(.+\.)?(test|spec)\.[jt]s/
};
export default config;

6
postcss.config.js Normal file
View File

@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {}
}
};

3
src/app.css Normal file
View File

@ -0,0 +1,3 @@
@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';

13
src/app.d.ts vendored Normal file
View File

@ -0,0 +1,13 @@
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
declare global {
namespace App {
// interface Error {}
// interface Locals {}
// interface PageData {}
// interface PageState {}
// interface Platform {}
}
}
export {};

12
src/app.html Normal file
View File

@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
</html>

View File

@ -0,0 +1,6 @@
<script>
import { Button } from "flowbite-svelte";
</script>
<Button></Button>

View File

@ -0,0 +1,42 @@
<script>
import {
Navbar,
NavBrand,
NavLi,
NavUl,
NavHamburger,
Button,
Input,
Avatar
} from 'flowbite-svelte';
import { CartOutline, SearchOutline } from 'flowbite-svelte-icons';
</script>
<Navbar>
<NavBrand href="/">
<img
src="https://images.unsplash.com/photo-1520763185298-1b434c919102?q=80&w=1932&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D"
class="me-3 h-6 sm:h-9"
alt="Flowbite Logo"
/>
<span class="self-center whitespace-nowrap text-xl font-semibold dark:text-white">Webshop</span>
</NavBrand>
<div class="relative hidden md:block">
<div class="pointer-events-none absolute inset-y-0 start-0 flex items-center ps-3">
<SearchOutline class="h-4 w-4" />
</div>
<Input id="search-navbar" class="ps-10" placeholder="Search..." />
</div>
<div class="flex">
<Avatar
href="/profile"
src="https://images.unsplash.com/photo-1520763185298-1b434c919102?q=80&w=1932&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D"
class="m-1 me-4"
/>
<Button>
<CartOutline size="lg"></CartOutline>
</Button>
</div>
</Navbar>

7
src/index.test.ts Normal file
View File

@ -0,0 +1,7 @@
import { describe, it, expect } from 'vitest';
describe('sum test', () => {
it('adds 1 + 2 to equal 3', () => {
expect(1 + 2).toBe(3);
});
});

1
src/lib/index.ts Normal file
View File

@ -0,0 +1 @@
// place files you want to import through the `$lib` alias in this folder.

28
src/lib/session.svelte.ts Normal file
View File

@ -0,0 +1,28 @@
import type { User } from './types';
const key = 'user';
const key2 = 'username';
function login(user: User) {
localStorage.setItem(key, btoa(`${user.username}:${user.password}`));
localStorage.setItem(key2, user.username);
}
function logout() {
localStorage.removeItem(key);
localStorage.removeItem(key2);
}
function loggedIn() {
return localStorage.getItem(key) !== null;
}
function name() {
return localStorage.getItem(key2) ?? '';
}
function auth() {
return localStorage.getItem(key);
}
export default { login, logout, loggedIn, name, auth };

4
src/lib/types.ts Normal file
View File

@ -0,0 +1,4 @@
export interface User {
username: string;
password: string;
}

View File

@ -0,0 +1,9 @@
<script>
import Navbar from '../../components/navbar.svelte';
let { children } = $props();
</script>
<Navbar></Navbar>
{@render children?.()}

View File

@ -0,0 +1,38 @@
<script>
import { Card, Button } from 'flowbite-svelte';
import { CartPlusOutline, StarOutline } from 'flowbite-svelte-icons';
// Create an array to loop over
let cards = Array(9).fill({
title: 'Tulpe',
description: 'Lorem ipsum dolor sit, amet consectetur adipisicing elit.',
imageUrl:
'https://images.unsplash.com/photo-1520763185298-1b434c919102?q=80&w=1932&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D'
});
</script>
<div class="mx-auto my-6 grid w-fit grid-cols-3 gap-10">
{#each cards as card}
<Card img={card.imageUrl} class="">
<div class="holder flex">
<div class="left w-fit">
<h5 class="mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white">
{card.title}
</h5>
<p class="mb-3 font-normal leading-tight text-gray-700 dark:text-gray-400">
{card.description}
</p>
</div>
<div class="right grid min-w-fit gap-4">
<Button>
<CartPlusOutline class="h-6 w-6 text-white" />
</Button>
<Button>
<StarOutline class=" h-6 w-6 text-white" />
</Button>
</div>
</div>
</Card>
{/each}
</div>

View File

@ -0,0 +1,23 @@
<script>
import { Button, Card, Input } from 'flowbite-svelte';
</script>
<div class="flex h-[90svh] flex-wrap content-center">
<Card class="mx-auto max-h-fit">
<form action="">
<div class="formItem">
<label for="">Company Name:</label>
<Input type="text"></Input>
</div>
<div class="formItem">
<label for="">Email:</label>
<Input type="email"></Input>
</div>
<div class="formItem">
<label for="">GLN:</label>
<Input type="number"></Input>
</div>
<Button>Submit</Button>
</form>
</Card>
</div>

View File

@ -0,0 +1,6 @@
<script>
import '../app.css';
let { children } = $props();
</script>
{@render children?.()}

1
src/routes/+layout.ts Normal file
View File

@ -0,0 +1 @@
export const ssr = false;

7
src/routes/+page.ts Normal file
View File

@ -0,0 +1,7 @@
import session from '$lib/session.svelte';
import { redirect } from '@sveltejs/kit';
export async function load() {
const page = session.loggedIn() ? '/main' : '/login';
redirect(307, page);
}

View File

@ -0,0 +1,59 @@
<script lang="ts">
import { Card, Button, Label, Input, Checkbox } from 'flowbite-svelte';
import { goto } from '$app/navigation';
let username: string = '';
let password: string = '';
let success: boolean = true;
let loading: boolean = false;
async function login() {
if (!username || !password) {
return;
}
loading = true;
// success = await API.login({ username, password });
loading = false;
if (success) {
goto('/');
}
}
</script>
<div class="flex h-[100svh] flex-wrap content-center">
<Card class="mx-auto max-h-fit">
<form class="flex flex-col space-y-6" action="/">
<h3 class="text-xl font-medium text-gray-900 dark:text-white">Sign in to our platform</h3>
<Label class="space-y-2">
<span>Email</span>
<Input
type="email"
name="email"
placeholder="name@company.com"
required
bind:value={username}
/>
</Label>
<Label class="space-y-2">
<span>Your password</span>
<Input type="password" name="password" placeholder="•••••" required bind:value={password} />
</Label>
<div class="flex items-start">
<Checkbox>Remember me</Checkbox>
<a href="/" class="ms-auto text-sm text-primary-700 hover:underline dark:text-primary-500">
Lost password?
</a>
</div>
<Button type="submit" class="w-full" on:click={login}>Login to your account</Button>
<span class="self-center text-red-500" class:invisible={success}>Login failed</span>
<div class="text-sm font-medium text-gray-500 dark:text-gray-300">
Not registered? <a href="/" class="text-primary-700 hover:underline dark:text-primary-500">
Create account
</a>
</div>
</form>
</Card>
</div>

View File

@ -0,0 +1,8 @@
import session from '$lib/session.svelte';
import { redirect } from '@sveltejs/kit';
export async function load() {
if (session.loggedIn()) {
redirect(307, '/');
}
}

BIN
static/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

18
svelte.config.js Normal file
View File

@ -0,0 +1,18 @@
import adapter from '@sveltejs/adapter-auto';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
// for more information about preprocessors
preprocess: vitePreprocess(),
kit: {
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
adapter: adapter()
}
};
export default config;

32
tailwind.config.ts Normal file
View File

@ -0,0 +1,32 @@
import flowbitePlugin from 'flowbite/plugin';
import type { Config } from 'tailwindcss';
export default {
content: [
'./src/**/*.{html,js,svelte,ts}',
'./node_modules/flowbite-svelte/**/*.{html,js,svelte,ts}'
],
darkMode: 'selector',
theme: {
extend: {
colors: {
// flowbite-svelte
primary: {
50: '#FFF5F2',
100: '#FFF1EE',
200: '#FFE4DE',
300: '#FFD5CC',
400: '#FFBCAD',
500: '#FE795D',
600: '#EF562F',
700: '#EB4F27',
800: '#CC4522',
900: '#A5371B'
}
}
}
},
plugins: [flowbitePlugin]
} as Config;

6
tests/test.ts Normal file
View File

@ -0,0 +1,6 @@
import { expect, test } from '@playwright/test';
test('home page has expected h1', async ({ page }) => {
await page.goto('/');
await expect(page.locator('h1')).toBeVisible();
});

19
tsconfig.json Normal file
View File

@ -0,0 +1,19 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"moduleResolution": "bundler"
}
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
// except $lib which is handled by https://kit.svelte.dev/docs/configuration#files
//
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
// from the referenced tsconfig.json - TypeScript does not merge them in
}

9
vite.config.ts Normal file
View File

@ -0,0 +1,9 @@
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vitest/config';
export default defineConfig({
plugins: [sveltekit()],
test: {
include: ['src/**/*.{test,spec}.{js,ts}']
}
});