mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
chore: lift components folder
This commit is contained in:
parent
76df51674d
commit
2200b29b92
301 changed files with 57 additions and 76 deletions
10
src/RadioButton/RadioButton.Skeleton.svelte
Normal file
10
src/RadioButton/RadioButton.Skeleton.svelte
Normal file
|
@ -0,0 +1,10 @@
|
|||
<div
|
||||
class:bx--radio-button-wrapper={true}
|
||||
{...$$restProps}
|
||||
on:click
|
||||
on:mouseover
|
||||
on:mouseenter
|
||||
on:mouseleave>
|
||||
<div class:bx--radio-button={true} class:bx--skeleton={true} />
|
||||
<span class:bx--radio-button__label={true} class:bx--skeleton={true} />
|
||||
</div>
|
14
src/RadioButton/RadioButton.Story.svelte
Normal file
14
src/RadioButton/RadioButton.Story.svelte
Normal file
|
@ -0,0 +1,14 @@
|
|||
<script>
|
||||
export let story = undefined;
|
||||
|
||||
import RadioButton from "./RadioButton.svelte";
|
||||
import RadioButtonSkeleton from "./RadioButton.Skeleton.svelte";
|
||||
|
||||
$: checked = false;
|
||||
</script>
|
||||
|
||||
{#if story === 'skeleton'}
|
||||
<RadioButtonSkeleton />
|
||||
{:else}
|
||||
<RadioButton {...$$props} bind:checked id="radio-1" />
|
||||
{/if}
|
26
src/RadioButton/RadioButton.stories.js
Normal file
26
src/RadioButton/RadioButton.stories.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { withKnobs, text, select, boolean } from "@storybook/addon-knobs";
|
||||
import Component from "./RadioButton.Story.svelte";
|
||||
|
||||
export default { title: "RadioButton", decorators: [withKnobs] };
|
||||
|
||||
const labelPositions = {
|
||||
"Left (left)": "left",
|
||||
"Right (right)": "right",
|
||||
};
|
||||
|
||||
export const Default = () => ({
|
||||
Component,
|
||||
props: {
|
||||
name: text("Form item name (name)", "test"),
|
||||
value: text("Value (value)", "standard"),
|
||||
labelText: text("Label text (labelText)", "Standard Radio Button"),
|
||||
labelPosition: select(
|
||||
"Label position (labelPosition)",
|
||||
labelPositions,
|
||||
"right"
|
||||
),
|
||||
disabled: boolean("Disabled (disabled)", false),
|
||||
},
|
||||
});
|
||||
|
||||
export const Skeleton = () => ({ Component, props: { story: "skeleton" } });
|
48
src/RadioButton/RadioButton.svelte
Normal file
48
src/RadioButton/RadioButton.svelte
Normal file
|
@ -0,0 +1,48 @@
|
|||
<script>
|
||||
export let value = "";
|
||||
export let checked = false;
|
||||
export let disabled = false;
|
||||
export let id = "ccs-" + Math.random().toString(36);
|
||||
export let labelPosition = "right"; // "left" | "right"
|
||||
export let labelText = "";
|
||||
export let hideLabel = false;
|
||||
export let name = "";
|
||||
|
||||
import { getContext } from "svelte";
|
||||
import { writable } from "svelte/store";
|
||||
|
||||
const ctx = getContext("RadioButtonGroup");
|
||||
const selectedValue = ctx
|
||||
? ctx.selectedValue
|
||||
: writable(checked ? value : undefined);
|
||||
|
||||
if (ctx) {
|
||||
ctx.add({ id, checked, disabled, value });
|
||||
}
|
||||
|
||||
$: checked = $selectedValue === value;
|
||||
</script>
|
||||
|
||||
<div
|
||||
class:bx--radio-button-wrapper={true}
|
||||
class:bx--radio-button-wrapper--label-left={labelPosition === 'left'}
|
||||
{...$$restProps}>
|
||||
<input
|
||||
type="radio"
|
||||
{id}
|
||||
{name}
|
||||
{checked}
|
||||
{disabled}
|
||||
{value}
|
||||
class:bx--radio-button={true}
|
||||
on:change
|
||||
on:change={() => {
|
||||
if (ctx) {
|
||||
ctx.update(value);
|
||||
}
|
||||
}} />
|
||||
<label class:bx--radio-button__label={true} for={id}>
|
||||
<span class:bx--radio-button__appearance={true} />
|
||||
<span class:bx--visually-hidden={hideLabel}>{labelText}</span>
|
||||
</label>
|
||||
</div>
|
2
src/RadioButton/index.js
Normal file
2
src/RadioButton/index.js
Normal file
|
@ -0,0 +1,2 @@
|
|||
export { default as RadioButton } from "./RadioButton.svelte";
|
||||
export { default as RadioButtonSkeleton } from "./RadioButton.Skeleton.svelte";
|
Loading…
Add table
Add a link
Reference in a new issue