mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-14 18:01:06 +00:00
* docs: update number of available Carbon icons * docs: add svelte:head example for loading CDN styles * chore(deps-dev): upgrade svelte to 3.40.1 * fix(a11y): disable a11y-mouse-events-have-key-events warning #760 * fix(deps): upgrade carbon-icons-svelte to v10.36.0 to avoid a11y warnings #760 * refactor(overflow-menu): remove formatStyle utility * docs: links in paragraphs should be inline * docs: add note on using all styles for dynamic theming
96 lines
2.1 KiB
Svelte
96 lines
2.1 KiB
Svelte
<script>
|
|
/**
|
|
* @event {boolean} check
|
|
*/
|
|
|
|
/** Specify whether the checkbox is checked */
|
|
export let checked = false;
|
|
|
|
/** Specify whether the checkbox is indeterminate */
|
|
export let indeterminate = false;
|
|
|
|
/** Set to `true` to display the skeleton state */
|
|
export let skeleton = false;
|
|
|
|
/** Set to `true` for the checkbox to be read-only */
|
|
export let readonly = false;
|
|
|
|
/** Set to `true` to disable the checkbox */
|
|
export let disabled = false;
|
|
|
|
/** Specify the label text */
|
|
export let labelText = "";
|
|
|
|
/** Set to `true` to visually hide the label text */
|
|
export let hideLabel = false;
|
|
|
|
/** Set a name for the input element */
|
|
export let name = "";
|
|
|
|
/**
|
|
* Specify the title attribute for the label element
|
|
* @type {string}
|
|
*/
|
|
export let title = undefined;
|
|
|
|
/** Set an id for the input label */
|
|
export let id = "ccs-" + Math.random().toString(36);
|
|
|
|
/** Obtain a reference to the input HTML element */
|
|
export let ref = null;
|
|
|
|
import { createEventDispatcher } from "svelte";
|
|
import CheckboxSkeleton from "./CheckboxSkeleton.svelte";
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
$: dispatch("check", checked);
|
|
</script>
|
|
|
|
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
|
|
{#if skeleton}
|
|
<CheckboxSkeleton
|
|
{...$$restProps}
|
|
on:click
|
|
on:mouseover
|
|
on:mouseenter
|
|
on:mouseleave
|
|
/>
|
|
{:else}
|
|
<div
|
|
class:bx--form-item="{true}"
|
|
class:bx--checkbox-wrapper="{true}"
|
|
{...$$restProps}
|
|
on:click
|
|
on:mouseover
|
|
on:mouseenter
|
|
on:mouseleave
|
|
>
|
|
<input
|
|
bind:this="{ref}"
|
|
type="checkbox"
|
|
checked="{checked}"
|
|
disabled="{disabled}"
|
|
id="{id}"
|
|
indeterminate="{indeterminate}"
|
|
name="{name}"
|
|
readonly="{readonly}"
|
|
class:bx--checkbox="{true}"
|
|
on:change
|
|
on:change="{() => {
|
|
checked = !checked;
|
|
}}"
|
|
on:blur
|
|
/>
|
|
<label for="{id}" title="{title}" class:bx--checkbox-label="{true}">
|
|
<span
|
|
class:bx--checkbox-label-text="{true}"
|
|
class:bx--visually-hidden="{hideLabel}"
|
|
>
|
|
<slot name="labelText">
|
|
{labelText}
|
|
</slot>
|
|
</span>
|
|
</label>
|
|
</div>
|
|
{/if}
|