Skip to content

Commit 169b28f

Browse files
committed
Allow adding labels to ipl-small-toggle through its default slot
1 parent 0651cc3 commit 169b28f

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 3.2.0
22

33
- Allow changing the background color of ipl-dialog-title
4+
- Allow adding labels to ipl-small-toggle through its default slot
45

56
# 3.1.0
67

docs/examples/SmallToggleExample.vue

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
<template>
2-
<div class="width-capped-content vertical-layout">
2+
<div class="width-capped-content vertical-layout resizable">
33
<div>Value: {{ value }}</div>
44
<!-- #region example -->
55
<ipl-small-toggle
66
v-model="value"
77
label="Small Toggle"
88
:disabled="disabled"
99
/>
10+
<ipl-small-toggle
11+
v-model="value"
12+
:disabled="disabled"
13+
>
14+
Label from slot<br>
15+
<ipl-label>Extra line of text</ipl-label>
16+
</ipl-small-toggle>
1017
<!-- #endregion example -->
1118
</div>
1219
<div class="horizontal-layout">
@@ -20,6 +27,7 @@
2027
<script setup lang="ts">
2128
import { IplSmallToggle, IplCheckbox } from '../../src';
2229
import { ref } from 'vue';
30+
import IplLabel from '../../src/components/iplLabel.vue';
2331
2432
const value = ref(false);
2533
const disabled = ref(false);
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`IplSmallToggle matches snapshot when toggle is disabled 1`] = `"<label class="ipl-small-toggle__wrapper disabled">Toggle! <input type="checkbox" role="switch" disabled=""></label>"`;
3+
exports[`IplSmallToggle matches snapshot when adding label from slots 1`] = `"<label class="ipl-small-toggle__wrapper"><span class="label">Toggle! (Label from slot)</span><input type="checkbox" role="switch"></label>"`;
44
5-
exports[`IplSmallToggle matches snapshot when toggle value is false 1`] = `"<label class="ipl-small-toggle__wrapper">Toggle! <input type="checkbox" role="switch"></label>"`;
5+
exports[`IplSmallToggle matches snapshot when toggle is disabled 1`] = `"<label class="ipl-small-toggle__wrapper disabled"><span class="label">Toggle!</span><input type="checkbox" role="switch" disabled=""></label>"`;
66
7-
exports[`IplSmallToggle matches snapshot when toggle value is true 1`] = `"<label class="ipl-small-toggle__wrapper">Toggle! <input type="checkbox" role="switch"></label>"`;
7+
exports[`IplSmallToggle matches snapshot when toggle value is false 1`] = `"<label class="ipl-small-toggle__wrapper"><span class="label">Toggle!</span><input type="checkbox" role="switch"></label>"`;
8+
9+
exports[`IplSmallToggle matches snapshot when toggle value is true 1`] = `"<label class="ipl-small-toggle__wrapper"><span class="label">Toggle!</span><input type="checkbox" role="switch"></label>"`;

src/components/__tests__/iplSmallToggle.test.ts

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@ import IplSmallToggle from '../iplSmallToggle.vue';
22
import { mount } from '@vue/test-utils';
33

44
describe('IplSmallToggle', () => {
5+
it('matches snapshot when adding label from slots', () => {
6+
const wrapper = mount(IplSmallToggle, {
7+
props: {
8+
modelValue: true
9+
},
10+
slots: {
11+
default: () => 'Toggle! (Label from slot)'
12+
}
13+
});
14+
15+
expect(wrapper.html()).toMatchSnapshot();
16+
});
17+
518
it('matches snapshot when toggle value is true', () => {
619
const wrapper = mount(IplSmallToggle, {
720
props: {

src/components/iplSmallToggle.vue

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
class="ipl-small-toggle__wrapper"
44
:class="{ disabled: disabled }"
55
>
6-
{{ label }}
6+
<span class="label">
7+
<slot>
8+
{{ label }}
9+
</slot>
10+
</span>
711
<input
812
v-model="model"
913
type="checkbox"
@@ -22,7 +26,7 @@ export default defineComponent({
2226
props: {
2327
label: {
2428
type: String,
25-
required: true
29+
default: ''
2630
},
2731
modelValue: {
2832
type: Boolean as PropType<boolean>,

0 commit comments

Comments
 (0)