-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
549 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { resolve } from "node:path"; | ||
import { defineConfig, devices } from "@playwright/test"; | ||
|
||
function playwrightDir(partialPath: string) { | ||
return resolve("./tests/e2e", partialPath); | ||
} | ||
|
||
const CI = !!process.env.CI; | ||
|
||
export default defineConfig({ | ||
testDir: playwrightDir("specs"), | ||
outputDir: playwrightDir("results"), | ||
webServer: { | ||
command: "bun vite build && bun vite preview", | ||
port: 4173, | ||
}, | ||
use: { | ||
screenshot: "only-on-failure", | ||
trace: "retain-on-failure", | ||
}, | ||
testMatch: /(.+\.)?(test|spec)\.[jt]s/, | ||
reporter: CI | ||
? [["github"]] | ||
: [ | ||
[ | ||
"html", | ||
{ outputFolder: playwrightDir("./report"), open: "on-failure" }, | ||
], | ||
], | ||
projects: [ | ||
{ | ||
name: "chromium", | ||
use: { | ||
...devices["Desktop Chrome"], | ||
}, | ||
}, | ||
{ | ||
name: "firefox", | ||
use: { | ||
...devices["Desktop Firefox"], | ||
}, | ||
}, | ||
{ | ||
name: "webkit", | ||
use: { | ||
...devices["Desktop Safari"], | ||
}, | ||
}, | ||
{ | ||
name: "Mobile Chrome", | ||
use: { ...devices["Pixel 5"] }, | ||
}, | ||
{ | ||
name: "Mobile Safari", | ||
use: { ...devices["iPhone 14"] }, | ||
}, | ||
/** Test branded browsers */ | ||
{ | ||
name: "google", | ||
use: { | ||
...devices["Desktop Google Chrome"], | ||
}, | ||
}, | ||
{ | ||
name: "msedge", | ||
use: { | ||
...devices["Desktop Edge"], | ||
}, | ||
}, | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<script lang="ts"> | ||
import { page } from "$app/stores"; | ||
import { useMultiSelectFilters } from "./_hooks/multi-select"; | ||
const [q, helpers] = useMultiSelectFilters($page.url); | ||
function updateCategories(category: string) { | ||
const categories = q.categories.includes(category) | ||
? q.categories.filter((c) => c !== category) | ||
: [...q.categories, category]; | ||
helpers.update({ categories }); | ||
} | ||
</script> | ||
|
||
<ul> | ||
<li> | ||
<label> | ||
<input | ||
type="checkbox" | ||
value="books" | ||
onchange={() => updateCategories("books")} | ||
checked={q.categories.includes("books")} | ||
/> | ||
Books | ||
</label> | ||
</li> | ||
<li> | ||
<label> | ||
<input | ||
type="checkbox" | ||
value="electronics" | ||
onchange={() => updateCategories("electronics")} | ||
checked={q.categories.includes("electronics")} | ||
/> | ||
Electronics | ||
</label> | ||
</li> | ||
</ul> |
15 changes: 15 additions & 0 deletions
15
packages/core/src/routes/(test)/multiselect/_hooks/multi-select.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { sveltekit } from "$lib/adapters/sveltekit"; | ||
import { createUseQueryParams } from "$lib/create-params.svelte"; | ||
import { z } from "zod"; | ||
|
||
export type MultiSelect = z.infer<typeof MultiSelect>; | ||
const MultiSelect = z.object({ | ||
categories: z | ||
.union([z.string().array(), z.string()]) | ||
.default([]) | ||
.transform((c) => (Array.isArray(c) ? c : [c])), | ||
}); | ||
|
||
export const useMultiSelectFilters = createUseQueryParams(MultiSelect, { | ||
adapter: sveltekit(), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<script> | ||
import { page } from "$app/stores"; | ||
import { usePagination } from "./_hooks/pagination"; | ||
const [q] = usePagination($page.url); | ||
const nextPage = () => { | ||
q.page = Math.min(q.page + 1, 10); | ||
}; | ||
const prevPage = () => { | ||
q.page = Math.max(q.page - 1, 1); | ||
}; | ||
</script> | ||
|
||
<h1>Current Page: {q.page}</h1> | ||
<h2>Page Size: {q.pageSize}</h2> | ||
|
||
<button onclick={prevPage} disabled={q.page === 1}>Previous</button> | ||
<button onclick={nextPage} disabled={q.page === 10}>Next</button> |
13 changes: 13 additions & 0 deletions
13
packages/core/src/routes/(test)/pagination/_hooks/pagination.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { sveltekit } from "$lib/adapters/sveltekit"; | ||
import { createUseQueryParams } from "$lib/create-params.svelte"; | ||
import { z } from "zod"; | ||
|
||
export type Pagination = z.infer<typeof Pagination>; | ||
const Pagination = z.object({ | ||
page: z.coerce.number().default(1), | ||
pageSize: z.coerce.number().default(10), | ||
}); | ||
|
||
export const usePagination = createUseQueryParams(Pagination, { | ||
adapter: sveltekit(), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<script lang="ts"> | ||
import { page } from "$app/stores"; | ||
import { useSearchFilters } from "./_hooks/search"; | ||
const [q] = useSearchFilters($page.url); | ||
</script> | ||
|
||
<input type="text" bind:value={q.q} placeholder="Search..." role="searchbox" /> | ||
<select bind:value={q.category}> | ||
<option value="">All Categories</option> | ||
<option value="books">Books</option> | ||
<option value="electronics">Electronics</option> | ||
</select> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { sveltekit } from "$lib/adapters/sveltekit"; | ||
import { createUseQueryParams } from "$lib/create-params.svelte"; | ||
import * as v from "valibot"; | ||
|
||
export type Search = v.InferOutput<typeof Search>; | ||
const Search = v.object({ | ||
q: v.optional(v.string(), ""), | ||
category: v.optional(v.string()), | ||
}); | ||
|
||
export const useSearchFilters = createUseQueryParams(Search, { | ||
debounce: 1000, | ||
adapter: sveltekit(), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { useQueryParams } from "./params"; | ||
|
||
export function load({ url }) { | ||
const [params] = useQueryParams(url); | ||
params.count = 10; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<script lang="ts"> | ||
import { page } from "$app/stores"; | ||
import { useQueryParams } from "./params"; | ||
const [q] = useQueryParams($page.url); | ||
</script> | ||
|
||
<h1>Count: {$page.url.searchParams.get("count")}</h1> | ||
<h2>Count: {q.count}</h2> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { sveltekit } from "$lib/adapters/sveltekit"; | ||
import { createUseQueryParams } from "$lib/create-params.svelte"; | ||
import { z } from "zod"; | ||
|
||
export const useQueryParams = createUseQueryParams( | ||
{ | ||
count: z.coerce.number().optional().default(0), | ||
}, | ||
{ adapter: sveltekit() } | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<script lang="ts"> | ||
import { page } from "$app/stores"; | ||
import { useTabs } from "./_hooks/tabs"; | ||
const [q] = useTabs($page.url); | ||
const onHomeTab = $derived(q.tab === "home"); | ||
const onUserTab = $derived(q.tab === "users"); | ||
</script> | ||
|
||
<header class="tabs"> | ||
<div role="tablist" aria-label="Tabs" aria-orientation="horizontal"> | ||
<button | ||
id="home-tab" | ||
role="tab" | ||
disabled={onHomeTab} | ||
aria-selected={onHomeTab} | ||
aria-controls="home" | ||
tabindex={onHomeTab ? 0 : -1} | ||
onclick={() => (q.tab = "home")} | ||
> | ||
Home | ||
</button> | ||
<button | ||
id="users-tab" | ||
role="tab" | ||
disabled={onUserTab} | ||
aria-selected={onUserTab} | ||
aria-controls="users" | ||
tabindex={onUserTab ? 0 : -1} | ||
onclick={() => (q.tab = "users")} | ||
> | ||
Users | ||
</button> | ||
</div> | ||
</header> | ||
|
||
<section> | ||
<div | ||
id="home" | ||
role="tabpanel" | ||
aria-labelledby="home-tab" | ||
tabindex="0" | ||
hidden={!onHomeTab} | ||
> | ||
<h1 id="title">Home Page</h1> | ||
<p>You are on the home page</p> | ||
</div> | ||
<div | ||
id="users" | ||
role="tabpanel" | ||
aria-labelledby="users-tab" | ||
tabindex="0" | ||
hidden={!onUserTab} | ||
> | ||
<h1 id="title">Users Page</h1> | ||
<p>You are on the users page</p> | ||
</div> | ||
</section> | ||
|
||
<style> | ||
.tabs { | ||
padding: 1em; | ||
} | ||
[role="tablist"] { | ||
margin-bottom: -1px; | ||
} | ||
[role="tab"] { | ||
position: relative; | ||
z-index: 1; | ||
background: white; | ||
border-radius: 5px 5px 0 0; | ||
border: 1px solid grey; | ||
border-bottom: 0; | ||
padding: 0.2em; | ||
} | ||
[role="tab"][aria-selected="true"] { | ||
z-index: 3; | ||
} | ||
[role="tabpanel"] { | ||
position: relative; | ||
padding: 0 0.5em 0.5em 0.7em; | ||
border: 1px solid grey; | ||
border-radius: 0 0 5px 5px; | ||
background: white; | ||
z-index: 2; | ||
} | ||
[role="tabpanel"]:focus { | ||
border-color: orange; | ||
outline: 1px solid orange; | ||
} | ||
</style> |
Oops, something went wrong.