Skip to content

Commit

Permalink
Start styling switch button
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnw committed Dec 11, 2024
1 parent 0619a74 commit 6b88aa5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/lib/components/colors/SwitchButton.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script lang="ts">
import Icon from '$lib/components/util/Icon.svelte';
import { switchColors } from '$lib/stores';
</script>

<button type="button" onclick={switchColors} data-btn="icon">
<Icon name="switch" />
<span class="sr-only">Click to swap colors</span></button
>
6 changes: 4 additions & 2 deletions src/lib/components/colors/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import Header from '$lib/components/colors/Header.svelte';
import Sliders from '$lib/components/colors/Sliders.svelte';
import SupportWarning from '$lib/components/colors/SupportWarning.svelte';
import { bg, fg, format, switchColors } from '$lib/stores';
import { bg, fg, format } from '$lib/stores';
import SwitchButton from './SwitchButton.svelte';
</script>

<h2 class="sr-only">Check the contrast ratio between two colors</h2>
Expand All @@ -13,7 +15,7 @@
<form data-form="contrast-checker" data-layout="color-form">
<Header type="bg" color={bg} format={$format} />
<Sliders type="bg" color={bg} format={$format} />
<button type="button" on:click={switchColors}>Switch colors</button>
<SwitchButton />
<Header type="fg" color={fg} format={$format} />
<Sliders type="fg" color={fg} format={$format} />
</form>
Expand Down
2 changes: 2 additions & 0 deletions src/lib/components/util/Icon.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import OddBird from '$lib/icons/OddBird.svelte';
import Twitter from '$lib/icons/Twitter.svelte';
import Warning from '$lib/icons/Warning.svelte';
import Switch from '$src/lib/icons/Switch.svelte';
const icons: Record<string, Component> = {
check: Check,
Expand All @@ -25,6 +26,7 @@
oddbird: OddBird,
linkedin: LinkedIn,
mastodon: Mastodon,
switch: Switch,
};
interface Props {
Expand Down
17 changes: 17 additions & 0 deletions src/lib/icons/Switch.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<script lang="ts">
let props = $props();
</script>

<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 512 512"
width="26"
height="26"
{...props}
>
<path
id="switch"
data-name="switch"
d="M406.6 374.6l96-96c12.5-12.5 12.5-32.8 0-45.3l-96-96c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L402.7 224l-293.5 0 41.4-41.4c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-96 96c-12.5 12.5-12.5 32.8 0 45.3l96 96c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L109.3 288l293.5 0-41.4 41.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0z"
/>
</svg>
4 changes: 2 additions & 2 deletions src/sass/initial/_layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ body {
@include config.above('sm-page-break') {
display: grid;
grid-template:
'bginput fginput' auto
'bgslide fgslide' auto / 1fr 1fr;
'bginput switch fginput' auto
'bgslide . fgslide' auto / 1fr min-content 1fr;
}
}

Expand Down

0 comments on commit 6b88aa5

Please sign in to comment.