Skip to content

Commit 086feca

Browse files
authored
feat: Toggle Switch (#143)
* feat: Toggle Switch * feat: Toggle Switch * fix: as per our design * fix: as per our design
1 parent 5cc627e commit 086feca

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

platforms/metagram/src/app.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
--color-grey: #f5f5f5;
4444
--color-red: #ff5255;
4545

46+
--color-gray-200: #eaecf0;
47+
4648
--color-brand-burnt-orange: #da4a11;
4749
--color-brand-burnt-orange-100: #f8dbcf;
4850
--color-brand-burnt-orange-200: #f3c3b0;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { ComponentProps } from 'svelte';
2+
import Toggle from './Toggle.svelte';
3+
4+
export default {
5+
title: 'UI/Toggle',
6+
component: Toggle,
7+
tags: ['autodocs'],
8+
render: (args: { Component: Toggle; props: ComponentProps<typeof Toggle> }) => ({
9+
Component: Toggle,
10+
props: args
11+
})
12+
};
13+
14+
export const Primary = {
15+
args: {}
16+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<script lang="ts">
2+
import { cn } from '$lib/utils';
3+
import type { HTMLAttributes } from 'svelte/elements';
4+
5+
interface IToggleProps extends HTMLAttributes<HTMLElement> {
6+
checked: boolean;
7+
}
8+
9+
let { checked = $bindable(false), ...restProps }: IToggleProps = $props();
10+
11+
let uniqueId = Math.random().toString().split('.')[1];
12+
</script>
13+
14+
<label
15+
{...restProps}
16+
for={uniqueId}
17+
class={cn(["relative",restProps.class].join(" "))}
18+
aria-label={restProps['aria-label'] || 'Toggle'}
19+
role="switch"
20+
aria-checked={checked}
21+
>
22+
<div
23+
class={`h-6 w-11 rounded-full ${checked ? 'bg-brand-burnt-orange' : 'bg-gray-200'} transition duration-300`}
24+
>
25+
<div
26+
class={`absolute top-0.5 left-0.5 h-5 w-5 rounded-full bg-white ${checked ? 'translate-x-5' : 'translate-x-0'} transition duration-300`}
27+
></div>
28+
</div>
29+
</label>
30+
31+
<input id={uniqueId} type="checkbox" bind:checked class="hidden" aria-hidden="true" />
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export { default as Button } from './Button/Button.svelte';
22
export { default as Avatar } from './Avatar/Avatar.svelte';
33
export { default as Input } from './Input/Input.svelte';
4+
export { default as Toggle } from './Toggle/Toggle.svelte';

0 commit comments

Comments
 (0)