-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathkcheckbox.vue
166 lines (151 loc) · 4.2 KB
/
kcheckbox.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<template>
<DocsPageTemplate apiDocs>
<DocsPageSection
title="Overview"
anchor="#overview"
>
<p>The checkbox is generally used to select one of two possible values in a form.</p>
<DocsShow>
<KCheckbox
label="Some label"
:checked="checked1"
@change="checked1 = !checked1"
/>
<KCheckbox
label="Another label"
:checked="checked2"
@change="checked2 = !checked2"
/>
</DocsShow>
</DocsPageSection>
<DocsPageSection
title="Layout"
anchor="#layout"
>
<ul>
<li>Aligned with container margin</li>
<li>When used in a group, vertically stacked</li>
<li>Hierarchical nesting is avoided</li>
</ul>
</DocsPageSection>
<DocsPageSection
title="Guidelines"
anchor="#guidelines"
>
<ul>
<li>Labels should be short and concise</li>
<li>
Checkbox should not be used to make real-time changes; for this situation, use a
<DocsLibraryLink component="KSwitch" /> component instead
</li>
</ul>
</DocsPageSection>
<DocsPageSection
title="States"
anchor="#states"
>
<p>The checked state represents an affirmative value.</p>
<p>
Checkboxes can also have a "partially-checked" or "indeterminate" state used in cases where
the value is neither true nor false, such as when a subset of a topic is selected:
</p>
<DocsShow>
<KCheckbox
label="Topic is selected"
:indeterminate="indeterminate3"
:checked="checked3"
@change="handle3"
/>
</DocsShow>
<p>
A user cannot enter the indeterminate state by interacting directly with the checkbox; it
only occurs due to external interactions.
</p>
</DocsPageSection>
<DocsPageSection
title="Example: Label content"
anchor="#example-labels"
>
Label content can be passed via the <code>label</code> property:
<!-- eslint-disable -->
<!-- prettier-ignore -->
<DocsShowCode language="html">
<KCheckbox label="First lesson" />
</DocsShowCode>
<!-- eslint-enable -->
<DocsShow>
<KCheckbox
label="First lesson"
:checked="checked4"
@change="checked4 = !checked4"
/>
</DocsShow>
In more complex situations, for example when another component is responsible for rendering
the label, the default slot can be used:
<!-- eslint-disable -->
<!-- prettier-ignore -->
<DocsShowCode language="html">
<KCheckbox>
<KLabeledIcon
icon="lesson"
label="First lesson"
/>
</KCheckbox>
</DocsShowCode>
<!-- eslint-enable -->
<DocsShow>
<KCheckbox
:checked="checked5"
@change="checked5 = !checked5"
>
<KLabeledIcon
icon="lesson"
label="First lesson"
/>
</KCheckbox>
</DocsShow>
<DocsDoNot>
<template #not>
<p>Don't wrap the default slot's content in <code><label></code>:</p>
<!-- eslint-disable -->
<!-- prettier-ignore -->
<DocsShowCode language="html">
<KCheckbox>
<label>
<KLabeledIcon
icon="lesson"
label="First lesson"
></KLabeledIcon>
</label>
</KCheckbox>
</DocsShowCode>
<!-- eslint-enable -->
<p>
That would cause two nested <code><label></code> elements to be rendered as
<code>KCheckbox</code> takes care of it already.
</p>
</template>
</DocsDoNot>
</DocsPageSection>
</DocsPageTemplate>
</template>
<script>
export default {
data() {
return {
checked1: true,
checked2: false,
checked3: false,
indeterminate3: true,
checked4: false,
checked5: false,
};
},
methods: {
handle3() {
this.checked3 = !this.checked3;
this.indeterminate3 = false;
},
},
};
</script>