Skip to content

Commit

Permalink
Fixed Scale Controls
Browse files Browse the repository at this point in the history
  • Loading branch information
khaled-0 committed Mar 5, 2024
1 parent be40b03 commit 80450cd
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 27 deletions.
6 changes: 4 additions & 2 deletions src/lib/components/AlertBoard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
<div class="flex items-center mx-0.5 large:mx-1">
<span class="color" style="--color:{alert.color}"></span>
<div class="ms-2 flex gap-2">
<div class="text-sm font-semibold text-gray-900 dark:text-white">{alert.title}</div>
<div class="text-sm font-normal">{alert.message}</div>
<div class="text-sm large:text-xl font-semibold text-gray-900 dark:text-white">
{alert.title}
</div>
<div class="text-sm large:text-lg font-normal">{alert.message}</div>
</div>
</div>
<template slot="close-button"> {addToDismissQueue(alert)}</template>
Expand Down
6 changes: 1 addition & 5 deletions src/lib/components/Preference/PreferenceDialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@
const dispatch = createEventDispatcher<{
centerBoard: void;
scaleUpdate: number;
}>();
</script>

<Modal class="divide-none" size="sm" bind:open title="Preference">
<div>
<TogglePreference title="Board Hint" bind:checked={boardHint} />
<ScaleControl
on:centerBoard={() => dispatch('centerBoard')}
on:scaleUpdate={(event) => (boardScale = event.detail)}
/>
<ScaleControl bind:scale={boardScale} on:centerBoard={() => dispatch('centerBoard')} />
</div>
</Modal>
30 changes: 12 additions & 18 deletions src/lib/components/Preference/ScaleControl.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,17 @@
import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher<{ scaleUpdate: number; centerBoard: void }>();
let scale = 5;
const scaleMap: Record<number, number> = {
1: 0.5,
2: 0.6,
3: 0.75,
4: 0.9,
5: 1,
6: 1.1,
7: 1.2,
8: 1.3,
9: 1.5
};
$: scale && dispatch('scaleUpdate', scaleMap[scale]);
export let scale: number;
</script>

<div class="global-field p-1.5 flex items-center large:flex-row flex-col">
<P>Board Scale</P>
<div class="flex items-center">
<Button outline class="ml-2 p-0.5" on:click={() => (scale = Math.max(scale - 1, 1))}>
<Button
outline
class="ml-2 p-0.5"
on:click={() => (scale = Number(Math.max(scale - 0.1, 0.7).toFixed(1)))}
>
<svg
class="w-6 h-6"
aria-hidden="true"
Expand All @@ -41,7 +31,11 @@
</svg>
</Button>
<span class="p-4">{scale}</span>
<Button outline class="p-0.5" on:click={() => (scale = Math.min(scale + 1, 9))}>
<Button
outline
class="p-0.5"
on:click={() => (scale = Number(Math.min(scale + 0.1, 1.5).toFixed(1)))}
>
<svg
class="w-6 h-6"
aria-hidden="true"
Expand All @@ -61,7 +55,7 @@

<div class="h-6 w-0.5 ml-2 bg-gray-300 dark:bg-slate-700" />

<Button outline on:click={() => (scale = 5)} class="ml-2 p-1">
<Button outline on:click={() => (scale = 1)} class="ml-2 p-1">
<svg
class="w-6 h-6"
aria-hidden="true"
Expand Down
42 changes: 42 additions & 0 deletions src/lib/components/RangeSlider.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<script lang="ts">
import { Range, Label, Button, Card, Spinner } from 'flowbite-svelte';

Check failure on line 2 in src/lib/components/RangeSlider.svelte

View workflow job for this annotation

GitHub Actions / build

'Label' is defined but never used

Check failure on line 2 in src/lib/components/RangeSlider.svelte

View workflow job for this annotation

GitHub Actions / build

'Card' is defined but never used

Check failure on line 2 in src/lib/components/RangeSlider.svelte

View workflow job for this annotation

GitHub Actions / build

'Spinner' is defined but never used
export let size: 'sm' | 'lg' | 'md' | undefined, min: number, max: number, value: number;
</script>

<div class="flex w-full items-center gap-2">
<Button outline class="ml-2 p-0.5" on:click={() => (value = Math.max(value - 1, min))}>
<svg
class="w-6 h-6"
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
>
<path
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M5 12h14"
/>
</svg>
</Button>
<Range {size} {min} {max} bind:value />
<Button outline class="p-0.5" on:click={() => (value = Math.min(value + 1, max))}>
<svg
class="w-6 h-6"
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
>
<path
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M5 12h14m-7 7V5"
/>
</svg>
</Button>
</div>
7 changes: 5 additions & 2 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import PlayerSelection from '$lib/components/Player/PlayerSelection.svelte';
import RangeSlider from '$lib/components/RangeSlider.svelte';
import type { GameParameter } from '$lib/data/GameParameters';
import { PlayersList } from '$lib/data/Player';
import { Range, Label, Button, Card, Spinner } from 'flowbite-svelte';

Check failure on line 6 in src/routes/+page.svelte

View workflow job for this annotation

GitHub Actions / build

'Range' is defined but never used
Expand Down Expand Up @@ -29,6 +30,7 @@
if (gameParams.colors?.length) gameUrl += `&colors=${gameParams.colors.join(',')}`;
window.location.href = gameUrl;
loadingState = false;
}
</script>

Expand All @@ -40,13 +42,14 @@
<Label defaultClass="w-full mb-1"
>Board Size<span class="float-end">{gameParams.board}</span></Label
>
<Range size="lg" min="6" max="16" bind:value={gameParams.board} />
<RangeSlider size="lg" min={6} max={16} bind:value={gameParams.board} />
<div class="mb-4" />

<Label defaultClass="w-full mb-1"
>Players<span class="float-end">{gameParams.players}</span></Label
>
<Range size="lg" min="2" max="6" bind:value={gameParams.players} />
<RangeSlider size="lg" min={2} max={6} bind:value={gameParams.players} />

<div class="mb-4" />

<div class="flex flex-wrap w-full gap-1 justify-center">
Expand Down

0 comments on commit 80450cd

Please sign in to comment.