Skip to content

Commit

Permalink
fix(Toggle): added class identifiers and fixed toggle on spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
N00nDay committed Oct 5, 2023
1 parent 70cf638 commit 3f7c457
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/lib/components/toggle/ContentLeft.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
const name: string = getContext('toggle-name');
const toggleOff: () => void = getContext('toggle-off');
const defaultClass = 'mr-3 cursor-pointer';
const defaultClass = 'mr-3 cursor-pointer stwui-toggle-content-left';
$: finalClass = twMerge(defaultClass, $$props.class);
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/toggle/ContentRight.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
const name: string = getContext('toggle-name');
const toggleOn: () => void = getContext('toggle-on');
const defaultClass = 'ml-3 cursor-pointer';
const defaultClass = 'ml-3 cursor-pointer stwui-toggle-content-right';
$: finalClass = twMerge(defaultClass, $$props.class);
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/toggle/Description.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { exclude } from '../../utils/exclude';
const forwardEvents = forwardEventsBuilder(get_current_component());
const defaultClass = 'text-sm text-secondary-content';
const defaultClass = 'text-sm text-secondary-content stwui-toggle-description';
$: finalClass = twMerge(defaultClass, $$props.class);
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/toggle/Label.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { exclude } from '../../utils/exclude';
const forwardEvents = forwardEventsBuilder(get_current_component());
const defaultClass = 'text-sm font-medium text-content';
const defaultClass = 'text-sm font-medium text-content stwui-toggle-label';
$: finalClass = twMerge(defaultClass, $$props.class);
</script>

Expand Down
40 changes: 33 additions & 7 deletions src/lib/components/toggle/Toggle.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<script lang="ts">
import { setContext } from 'svelte';
import { slide } from 'svelte/transition';
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions, type ActionArray } from '../../actions';
export let use: ActionArray = [];
import { exclude } from '../../utils/exclude';
import { twMerge } from 'tailwind-merge';
const forwardEvents = forwardEventsBuilder(get_current_component());
export let name: string;
export let on = false;
Expand All @@ -26,37 +32,51 @@
on = false;
}
const defaultClass = 'stwui-toggle-wrapper flex flex-col';
$: finalClass = twMerge(defaultClass, $$props.class);
setContext('toggle-name', name);
setContext('toggle-on', toggleOn);
setContext('toggle-off', toggleOff);
</script>

<div class="flex flex-col">
<div
class={finalClass}
use:useActions={use}
use:forwardEvents
{...exclude($$props, ['use', 'class'])}
>
<div class="flex items-center">
<slot name="content-left" />
<div
class="border border-border relative inline-flex flex-shrink-0 h-[1.6rem] rounded-full cursor-pointer outline-none focus:outline-none {width}"
class="border relative inline-flex flex-shrink-0 h-[1.6rem] rounded-full cursor-pointer outline-none focus:outline-none {width}"
class:border-border={!on}
class:border-primary={on}
>
<button
aria-label="toggle"
on:click={toggle}
type="button"
class="relative inline-flex items-center justify-between flex-shrink-0 h-full w-full border-2 border-transparent rounded-full cursor-pointer ease-in-out outline-none focus:outline-none"
class="stwui-toggle relative inline-flex items-center justify-between flex-shrink-0 h-full w-full border-2 border-transparent rounded-full cursor-pointer ease-in-out outline-none focus:outline-none"
class:bg-default={!on}
class:bg-primary={on}
>
<span
aria-hidden="true"
class="relative z-10 inline-block bg-surface h-5 w-5 rounded-full shadow transform transition-transform ease-in-out duration-150 border border-border {translate}"
class="stwui-toggle-dongle relative z-10 inline-block bg-surface h-5 w-5 rounded-full shadow transform transition-transform ease-in-out duration-150 border border-border {translate}"
/>
<input type="checkbox" class="hidden" {name} id={name} checked={on} />
{#if $$slots['left-icon']}
<span class="text-sm absolute left-0.5 flex items-center justify-center h-4 w-4">
<span
class="text-sm absolute left-0.5 flex items-center justify-center h-4 w-4 stwui-toggle-left-icon-wrapper"
>
<slot name="left-icon" />
</span>
{/if}
{#if $$slots['right-icon']}
<span class="text-sm absolute right-0.5 flex items-center justify-center h-4 w-4">
<span
class="text-sm absolute right-0.5 flex items-center justify-center h-4 w-4 stwui-toggle-right-con-wrapper"
>
<slot name="right-icon" />
</span>
{/if}
Expand All @@ -65,6 +85,12 @@
<slot name="content-right" />
</div>
{#if error}
<p transition:slide|local class="!mt-2 text-sm text-danger" id="{name}-error">{error}</p>
<p
transition:slide|local
class="!mt-2 text-sm text-danger stwui-toggle-error"
id="{name}-error"
>
{error}
</p>
{/if}
</div>

1 comment on commit 3f7c457

@vercel
Copy link

@vercel vercel bot commented on 3f7c457 Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

stwui – ./

stwui-n00nday.vercel.app
stwui-git-main-n00nday.vercel.app
stwui.vercel.app

Please sign in to comment.