Skip to content

Commit bab3fec

Browse files
committed
feat: added ability to remove switch icons
1 parent 943795f commit bab3fec

File tree

4 files changed

+55
-17
lines changed

4 files changed

+55
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<div>
2+
<FormField>
3+
<Switch bind:checked={checked1} icons={false} />
4+
<span slot="label">Fields of grain.</span>
5+
</FormField>
6+
</div>
7+
8+
<pre class="status">Checked: {checked1}</pre>
9+
10+
<div style="margin-top: 1em;">
11+
<FormField>
12+
<Switch bind:checked={checked2} color="secondary" icons={false} />
13+
<span slot="label">Fields of grain.</span>
14+
</FormField>
15+
</div>
16+
17+
<pre class="status">Checked: {checked2}</pre>
18+
19+
<script lang="ts">
20+
import Switch from '@smui/switch';
21+
import FormField from '@smui/form-field';
22+
23+
let checked1 = false;
24+
let checked2 = false;
25+
</script>

packages/site/src/routes/demo/switch/index.svelte

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
</Demo>
1515

1616
<Demo component={Group} file="switch/_Group.svelte">Group switch</Demo>
17+
18+
<Demo component={NoIcons} file="switch/_NoIcons.svelte">No icons</Demo>
1719
</section>
1820

1921
<script lang="ts">
@@ -22,4 +24,5 @@
2224
import Simple from './_Simple.svelte';
2325
import SecondaryColor from './_SecondaryColor.svelte';
2426
import Group from './_Group.svelte';
27+
import NoIcons from './_NoIcons.svelte';
2528
</script>

packages/switch/Switch.svelte

+26-17
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,31 @@
3636
<div class="mdc-elevation-overlay" />
3737
</div>
3838
<div class="mdc-switch__ripple" bind:this={rippleElement} />
39-
<div
40-
use:useActions={icons$use}
41-
class={classMap({
42-
[icons$class]: true,
43-
'mdc-switch__icons': true,
44-
})}
45-
{...prefixFilter($$restProps, 'icons$')}
46-
>
47-
<svg class="mdc-switch__icon mdc-switch__icon--on" viewBox="0 0 24 24">
48-
<path
49-
d="M19.69,5.23L8.96,15.96l-4.23-4.23L2.96,13.5l6,6L21.46,7L19.69,5.23z"
50-
/>
51-
</svg>
52-
<svg class="mdc-switch__icon mdc-switch__icon--off" viewBox="0 0 24 24">
53-
<path d="M20 13H4v-2h16v2z" />
54-
</svg>
55-
</div>
39+
{#if icons}
40+
<div
41+
use:useActions={icons$use}
42+
class={classMap({
43+
[icons$class]: true,
44+
'mdc-switch__icons': true,
45+
})}
46+
{...prefixFilter($$restProps, 'icons$')}
47+
>
48+
<svg
49+
class="mdc-switch__icon mdc-switch__icon--on"
50+
viewBox="0 0 24 24"
51+
>
52+
<path
53+
d="M19.69,5.23L8.96,15.96l-4.23-4.23L2.96,13.5l6,6L21.46,7L19.69,5.23z"
54+
/>
55+
</svg>
56+
<svg
57+
class="mdc-switch__icon mdc-switch__icon--off"
58+
viewBox="0 0 24 24"
59+
>
60+
<path d="M20 13H4v-2h16v2z" />
61+
</svg>
62+
</div>
63+
{/if}
5664
</div>
5765
</div>
5866
</button>
@@ -95,6 +103,7 @@
95103
export let value: any = null;
96104
/** This currently does nothing. */
97105
export let processing = false;
106+
export let icons = true;
98107
export let icons$use: ActionArray = [];
99108
export let icons$class = '';
100109

packages/switch/Switch.types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export declare class SwitchComponentDev extends Component {
1717
| 'checked'
1818
| 'value'
1919
| 'processing'
20+
| 'icons'
2021
> & {
2122
[k in keyof Partial<
2223
svelte.JSX.HTMLAttributes<HTMLDivElement>

0 commit comments

Comments
 (0)