Skip to content

Commit a760427

Browse files
committed
fix(switch): add inline
1 parent 3f6845a commit a760427

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

packages/switch/src/lib/switch.svelte

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
/** @type {String, Number} */
2525
export let tabindex;
2626
export let beforeChange = null;
27+
export let width = null;
2728
$: size = size || getContext('svel-size');
2829
$: isControlled = value !== false;
2930
$: actualValue = value;
@@ -81,6 +82,8 @@
8182
function handleInputKeydown({ key }) {
8283
console.log(key);
8384
}
85+
86+
$: coreStyle = a2st([[`width`, width ? `${width}px` : null]]);
8487
</script>
8588

8689
<div class={switchKls} on:click={switchValue} {style}>
@@ -109,13 +112,13 @@
109112
{/if}
110113
</span>
111114
{/if}
112-
<span class="svel-switch__core">
115+
<span class="svel-switch__core" style={coreStyle}>
113116
{#if inlinePrompt}
114117
<div class="svel-switch__inner">
115118
{#if activeIcon || inactiveIcon}
116119
<SvelIcon />
117120
{:else if activeText || inactiveText}
118-
<span class="is-text" aria-hidden="!checked">{checked ? activeText : inactiveText}</span>
121+
<span class="is-text" aria-hidden={!checked}>{checked ? activeText : inactiveText}</span>
119122
{/if}
120123
</div>
121124
{/if}

packages/switch/src/routes/+page.svelte

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,9 @@
1919
<div />
2020
<SvelSwitch activeText="Pay by month" inactiveText="Pay by year" />
2121
<SvelSwitch activeText="Y" inactiveText="N" inlinePrompt />
22+
<div />
23+
<SvelSwitch activeText="超出省略" inactiveText="超出省略" inlinePrompt width="60" />
24+
<div />
25+
<SvelSwitch activeText="完整展示多个内容" inactiveText="多个内容" inlinePrompt />
2226

2327
<div />

0 commit comments

Comments
 (0)