-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathslds-checkbox.vue
91 lines (73 loc) · 1.97 KB
/
slds-checkbox.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<template>
<slds-form-element
:help="help"
:label="inline ? undefined : label"
:required="required"
:stacked="stacked"
:tooltip="tooltip"
>
<!-- Tooltip -->
<template v-if="$slots.tooltip" #tooltip>
<slot name="tooltip"/>
</template>
<!-- Default slot -->
<template #default="slotProps">
<slds-checkbox-option
:id="slotProps['input-id']"
:value="modelValue"
:option="label"
:disabled="disabled"
:inline="inline"
@click="onClick"
/>
</template>
<!-- Inline help -->
<template #help>
<slot name="help"/>
</template>
<!-- Error messages -->
<template #error>
<slot name="error"/>
</template>
</slds-form-element>
</template>
<script lang="ts">
import SldsCheckboxOption from "./slds-checkbox-option.vue"
import SldsFormElement from "../slds-form-element/slds-form-element.vue"
import { EVENTS } from "../../constants"
import { defineComponent } from "vue"
export default defineComponent({
name: "SldsCheckbox",
components: {
SldsCheckboxOption,
SldsFormElement,
},
props: {
disabled: Boolean,
error: Boolean,
/**
* Inline help text.
* When using the help slot this prop is ignored.
*/
help: String,
inline: Boolean,
label: { type: String, required: true },
/**
* Input value.
*/
modelValue: Boolean,
required: Boolean,
/**
* Indicates whether the input is stacked among other inputs.
*/
stacked: Boolean,
tooltip: String,
},
methods: {
onClick(): void {
if (this.disabled) return
this.$emit(EVENTS.UPDATE_MODEL_VALUE, !this.modelValue)
},
},
})
</script>