-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* toggle buttons * docs radio/checkbox added * gen:xxx done * trigger second try
- Loading branch information
Showing
9 changed files
with
333 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<script lang="ts"> | ||
import Button from '$lib/buttons/Button.svelte'; | ||
import type { ButtonColorType, SizeType } from '$lib/types'; | ||
import { twMerge } from 'tailwind-merge'; | ||
export let group: (string | number)[] = []; | ||
export let value: string | number = 'on'; | ||
export let checked: boolean | undefined = undefined; | ||
export let inline: boolean = true; | ||
// Button properties forwarding | ||
export let pill: boolean = false; | ||
export let outline: boolean = false; | ||
export let size: SizeType | undefined = undefined; | ||
export let color: ButtonColorType | undefined = undefined; | ||
export let shadow: boolean = false; | ||
// react on external group changes | ||
function init(_: HTMLElement, _group: (string | number)[]) { | ||
if (checked === undefined) checked = _group.includes(value); | ||
onChange(); | ||
return { | ||
update(_group: (string | number)[]) { | ||
checked = _group.includes(value); | ||
} | ||
}; | ||
} | ||
function onChange() { | ||
// There's a bug in Svelte and bind:group is not working with wrapped checkbox | ||
// This workaround is taken from: | ||
// https://svelte.dev/repl/de117399559f4e7e9e14e2fc9ab243cc?version=3.12.1 | ||
const index = group.indexOf(value); | ||
if (checked === undefined) checked = index >= 0; | ||
if (checked) { | ||
if (index < 0) { | ||
group.push(value); | ||
group = group; | ||
} | ||
} else { | ||
if (index >= 0) { | ||
group.splice(index, 1); | ||
group = group; | ||
} | ||
} | ||
} | ||
let buttonClass: string; | ||
$: buttonClass = twMerge(inline ? 'inline-flex' : 'flex', $$props.class); | ||
</script> | ||
|
||
<Button tag="label" {checked} {pill} {outline} {size} {color} {shadow} class={buttonClass}> | ||
<input | ||
use:init={group} | ||
type="checkbox" | ||
bind:checked | ||
{value} | ||
{...$$restProps} | ||
class="sr-only" | ||
on:keyup | ||
on:keydown | ||
on:keypress | ||
on:focus | ||
on:blur | ||
on:click | ||
on:mouseover | ||
on:mouseenter | ||
on:mouseleave | ||
on:paste | ||
on:change={onChange} | ||
on:change /> | ||
<slot /> | ||
</Button> | ||
|
||
<!-- | ||
@component | ||
[Go to docs](https://flowbite-svelte.com/) | ||
## Props | ||
@prop export let group: (string | number)[] = []; | ||
@prop export let value: string | number = 'on'; | ||
@prop export let checked: boolean | undefined = undefined; | ||
@prop export let inline: boolean = true; | ||
@prop export let pill: boolean = false; | ||
@prop export let outline: boolean = false; | ||
@prop export let size: SizeType | undefined = undefined; | ||
@prop export let color: ButtonColorType | undefined = undefined; | ||
@prop export let shadow: boolean = false; | ||
--> |
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,54 @@ | ||
<script lang="ts"> | ||
import Button from '$lib/buttons/Button.svelte'; | ||
import type { ButtonColorType, SizeType } from '$lib/types'; | ||
import { twMerge } from 'tailwind-merge'; | ||
export let group: string | number = ''; | ||
export let value: string | number = ''; | ||
export let inline: boolean = true; | ||
// Button properties forwarding | ||
export let pill: boolean = false; | ||
export let outline: boolean = false; | ||
export let size: SizeType | undefined = undefined; | ||
export let color: ButtonColorType | undefined = undefined; | ||
export let shadow: boolean = false; | ||
let buttonClass: string; | ||
$: buttonClass = twMerge(inline ? 'inline-flex' : 'flex', $$props.class); | ||
</script> | ||
|
||
<Button tag="label" checked={value === group} {pill} {outline} {size} {color} {shadow} class={buttonClass}> | ||
<input | ||
type="radio" | ||
bind:group | ||
{value} | ||
{...$$restProps} | ||
class="sr-only" | ||
on:keyup | ||
on:keydown | ||
on:keypress | ||
on:focus | ||
on:blur | ||
on:click | ||
on:mouseover | ||
on:mouseenter | ||
on:mouseleave | ||
on:paste | ||
on:change /> | ||
<slot /> | ||
</Button> | ||
|
||
<!-- | ||
@component | ||
[Go to docs](https://flowbite-svelte.com/) | ||
## Props | ||
@prop export let group: string | number = ''; | ||
@prop export let value: string | number = ''; | ||
@prop export let inline: boolean = true; | ||
@prop export let pill: boolean = false; | ||
@prop export let outline: boolean = false; | ||
@prop export let size: SizeType | undefined = undefined; | ||
@prop export let color: ButtonColorType | undefined = undefined; | ||
@prop export let shadow: boolean = false; | ||
--> |
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 @@ | ||
{"name":"CheckboxButton","slots":[],"events":["on:keyup","on:keydown","on:keypress","on:focus","on:blur","on:click","on:mouseover","on:mouseenter","on:mouseleave","on:paste","on:change","on:change"],"props":[["group","(string | number)[]","[]"],["value","string | number","'on'"],["checked","boolean | undefined","undefined"],["inline","boolean","true"],["pill","boolean","false"],["outline","boolean","false"],["size","SizeType | undefined","undefined"],["color","ButtonColorType | undefined","undefined"],["shadow","boolean","false"]]} |
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 @@ | ||
{"name":"RadioButton","slots":[],"events":["on:keyup","on:keydown","on:keypress","on:focus","on:blur","on:click","on:mouseover","on:mouseenter","on:mouseleave","on:paste","on:change"],"props":[["group","string | number","''"],["value","string | number","''"],["inline","boolean","true"],["pill","boolean","false"],["outline","boolean","false"],["size","SizeType | undefined","undefined"],["color","ButtonColorType | undefined","undefined"],["shadow","boolean","false"]]} |
Oops, something went wrong.
fe563e6
There was a problem hiding this comment.
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:
flowbite-svelte-update – ./
flowbite-svelte-update-git-main-themesberg.vercel.app
flowbite-svelte-update-themesberg.vercel.app
flowbite-svelte-update.vercel.app
fe563e6
There was a problem hiding this comment.
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:
flowbite-svelte – ./
flowbite-svelte-git-main-themesberg.vercel.app
flowbite-svelte-themesberg.vercel.app
flowbite-svelte.com
flowbite-svelte.vercel.app
www.flowbite-svelte.com