@cocoar/vue-ui 3.1.0 → 3.2.0-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.mjs +53 -0
- package/dist/components/checkbox/CoarCheckbox.vue.d.ts +1 -1
- package/dist/components/checkbox/CoarCheckbox.vue.d.ts.map +1 -1
- package/dist/components/code-block/CoarCodeBlock.vue.d.ts +1 -1
- package/dist/components/code-block/CoarCodeBlock.vue.d.ts.map +1 -1
- package/dist/components/data-list/CoarDataList.vue.d.ts +158 -0
- package/dist/components/data-list/CoarDataList.vue.d.ts.map +1 -0
- package/dist/components/data-list/CoarDataListToolbar.vue.d.ts +30 -0
- package/dist/components/data-list/CoarDataListToolbar.vue.d.ts.map +1 -0
- package/dist/components/data-list/data-list-builder.d.ts +288 -0
- package/dist/components/data-list/data-list-builder.d.ts.map +1 -0
- package/dist/components/data-list/index.d.ts +12 -0
- package/dist/components/data-list/index.d.ts.map +1 -0
- package/dist/components/data-list/internal/compare.d.ts +14 -0
- package/dist/components/data-list/internal/compare.d.ts.map +1 -0
- package/dist/components/data-list/internal/reorder-core.d.ts +46 -0
- package/dist/components/data-list/internal/reorder-core.d.ts.map +1 -0
- package/dist/components/data-list/internal/search.d.ts +16 -0
- package/dist/components/data-list/internal/search.d.ts.map +1 -0
- package/dist/components/data-list/internal/useDataListLines.d.ts +92 -0
- package/dist/components/data-list/internal/useDataListLines.d.ts.map +1 -0
- package/dist/components/data-list/internal/useDataListReorder.d.ts +68 -0
- package/dist/components/data-list/internal/useDataListReorder.d.ts.map +1 -0
- package/dist/components/data-list/internal/useSearchHighlight.d.ts +19 -0
- package/dist/components/data-list/internal/useSearchHighlight.d.ts.map +1 -0
- package/dist/components/data-list/types.d.ts +185 -0
- package/dist/components/data-list/types.d.ts.map +1 -0
- package/dist/components/data-list/useDataListModel.d.ts +79 -0
- package/dist/components/data-list/useDataListModel.d.ts.map +1 -0
- package/dist/components/date-time/_shared/maskito-config.d.ts +7 -2
- package/dist/components/date-time/_shared/maskito-config.d.ts.map +1 -1
- package/dist/components/date-time/_shared/time-helpers.d.ts +11 -4
- package/dist/components/date-time/_shared/time-helpers.d.ts.map +1 -1
- package/dist/components/date-time/_shared/use-date-picker-base.d.ts +1 -1
- package/dist/components/date-time/plain-date-picker/CoarPlainDatePicker.vue.d.ts +1 -1
- package/dist/components/date-time/plain-date-picker/CoarPlainDatePicker.vue.d.ts.map +1 -1
- package/dist/components/date-time/plain-date-time-picker/CoarPlainDateTimePicker.vue.d.ts +1 -1
- package/dist/components/date-time/plain-date-time-picker/CoarPlainDateTimePicker.vue.d.ts.map +1 -1
- package/dist/components/date-time/zoned-date-time-picker/CoarZonedDateTimePicker.vue.d.ts +1 -1
- package/dist/components/date-time/zoned-date-time-picker/CoarZonedDateTimePicker.vue.d.ts.map +1 -1
- package/dist/components/dual-listbox/CoarDualListbox.vue.d.ts +3 -0
- package/dist/components/dual-listbox/CoarDualListbox.vue.d.ts.map +1 -1
- package/dist/components/form-field/CoarFormField.vue.d.ts +1 -1
- package/dist/components/form-field/CoarFormField.vue.d.ts.map +1 -1
- package/dist/components/icon/CoarIcon.vue.d.ts +2 -2
- package/dist/components/icon/CoarIcon.vue.d.ts.map +1 -1
- package/dist/components/listbox/CoarListbox.vue.d.ts +7 -0
- package/dist/components/listbox/CoarListbox.vue.d.ts.map +1 -1
- package/dist/components/number-input/CoarNumberInput.vue.d.ts +1 -1
- package/dist/components/number-input/CoarNumberInput.vue.d.ts.map +1 -1
- package/dist/components/otp-input/CoarOtpInput.vue.d.ts +1 -1
- package/dist/components/otp-input/CoarOtpInput.vue.d.ts.map +1 -1
- package/dist/components/password-input/CoarPasswordInput.vue.d.ts +1 -1
- package/dist/components/password-input/CoarPasswordInput.vue.d.ts.map +1 -1
- package/dist/components/switch/CoarSwitch.vue.d.ts +1 -1
- package/dist/components/switch/CoarSwitch.vue.d.ts.map +1 -1
- package/dist/components/text-input/CoarTextInput.vue.d.ts +1 -1
- package/dist/components/text-input/CoarTextInput.vue.d.ts.map +1 -1
- package/dist/composables/dragRegistry.d.ts +12 -0
- package/dist/composables/dragRegistry.d.ts.map +1 -1
- package/dist/composables/index.d.ts +2 -2
- package/dist/composables/index.d.ts.map +1 -1
- package/dist/composables/useDragDrop.d.ts +62 -6
- package/dist/composables/useDragDrop.d.ts.map +1 -1
- package/dist/composables/useVirtualList.d.ts +21 -1
- package/dist/composables/useVirtualList.d.ts.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4508 -2039
- package/package.json +9 -3
- package/skills/cocoar-vue-ui/SKILL.md +244 -0
- package/skills/cocoar-vue-ui/references/components/avatar.md +178 -0
- package/skills/cocoar-vue-ui/references/components/badge.md +290 -0
- package/skills/cocoar-vue-ui/references/components/breadcrumb.md +238 -0
- package/skills/cocoar-vue-ui/references/components/button.md +252 -0
- package/skills/cocoar-vue-ui/references/components/calendar/agenda-view.md +372 -0
- package/skills/cocoar-vue-ui/references/components/calendar/coar-calendar.md +1647 -0
- package/skills/cocoar-vue-ui/references/components/calendar/day-view.md +361 -0
- package/skills/cocoar-vue-ui/references/components/calendar/index.md +312 -0
- package/skills/cocoar-vue-ui/references/components/calendar/month-view.md +486 -0
- package/skills/cocoar-vue-ui/references/components/calendar/performance.md +186 -0
- package/skills/cocoar-vue-ui/references/components/calendar/timeline-view.md +301 -0
- package/skills/cocoar-vue-ui/references/components/calendar/week-view.md +382 -0
- package/skills/cocoar-vue-ui/references/components/calendar/work-week-view.md +145 -0
- package/skills/cocoar-vue-ui/references/components/calendar/year-view.md +63 -0
- package/skills/cocoar-vue-ui/references/components/card.md +151 -0
- package/skills/cocoar-vue-ui/references/components/checkbox-group.md +103 -0
- package/skills/cocoar-vue-ui/references/components/checkbox.md +279 -0
- package/skills/cocoar-vue-ui/references/components/code-block.md +241 -0
- package/skills/cocoar-vue-ui/references/components/context-menu.md +355 -0
- package/skills/cocoar-vue-ui/references/components/data-grid/checkbox.md +213 -0
- package/skills/cocoar-vue-ui/references/components/data-grid/date-columns.md +272 -0
- package/skills/cocoar-vue-ui/references/components/data-grid/editing.md +236 -0
- package/skills/cocoar-vue-ui/references/components/data-grid/multi-select.md +193 -0
- package/skills/cocoar-vue-ui/references/components/data-grid/number.md +147 -0
- package/skills/cocoar-vue-ui/references/components/data-grid/select.md +202 -0
- package/skills/cocoar-vue-ui/references/components/data-grid/text.md +127 -0
- package/skills/cocoar-vue-ui/references/components/data-grid.md +1225 -0
- package/skills/cocoar-vue-ui/references/components/data-list.md +2121 -0
- package/skills/cocoar-vue-ui/references/components/date-or-time-picker.md +200 -0
- package/skills/cocoar-vue-ui/references/components/date-picker.md +203 -0
- package/skills/cocoar-vue-ui/references/components/date-time-picker.md +154 -0
- package/skills/cocoar-vue-ui/references/components/date-views.md +212 -0
- package/skills/cocoar-vue-ui/references/components/dialog.md +148 -0
- package/skills/cocoar-vue-ui/references/components/divider.md +157 -0
- package/skills/cocoar-vue-ui/references/components/document-viewer/annotations.md +400 -0
- package/skills/cocoar-vue-ui/references/components/document-viewer/coar-document-viewer.md +327 -0
- package/skills/cocoar-vue-ui/references/components/document-viewer/index.md +234 -0
- package/skills/cocoar-vue-ui/references/components/document-viewer/toolbar.md +221 -0
- package/skills/cocoar-vue-ui/references/components/drag-drop.md +267 -0
- package/skills/cocoar-vue-ui/references/components/dual-listbox.md +449 -0
- package/skills/cocoar-vue-ui/references/components/file-explorer/asset-store.md +327 -0
- package/skills/cocoar-vue-ui/references/components/file-explorer/in-memory-store.md +176 -0
- package/skills/cocoar-vue-ui/references/components/file-explorer/index.md +311 -0
- package/skills/cocoar-vue-ui/references/components/file-explorer/use-file-explorer.md +300 -0
- package/skills/cocoar-vue-ui/references/components/form-field.md +1025 -0
- package/skills/cocoar-vue-ui/references/components/fragment-parser.md +298 -0
- package/skills/cocoar-vue-ui/references/components/link.md +235 -0
- package/skills/cocoar-vue-ui/references/components/listbox.md +575 -0
- package/skills/cocoar-vue-ui/references/components/map/editor.md +448 -0
- package/skills/cocoar-vue-ui/references/components/map/index.md +351 -0
- package/skills/cocoar-vue-ui/references/components/markdown-diagrams.md +210 -0
- package/skills/cocoar-vue-ui/references/components/markdown-editor.md +1478 -0
- package/skills/cocoar-vue-ui/references/components/markdown-embeds.md +387 -0
- package/skills/cocoar-vue-ui/references/components/markdown-form.md +447 -0
- package/skills/cocoar-vue-ui/references/components/markdown.md +276 -0
- package/skills/cocoar-vue-ui/references/components/menu.md +380 -0
- package/skills/cocoar-vue-ui/references/components/mermaid.md +172 -0
- package/skills/cocoar-vue-ui/references/components/navbar.md +147 -0
- package/skills/cocoar-vue-ui/references/components/note.md +96 -0
- package/skills/cocoar-vue-ui/references/components/notice.md +131 -0
- package/skills/cocoar-vue-ui/references/components/number-input.md +215 -0
- package/skills/cocoar-vue-ui/references/components/otp-input.md +324 -0
- package/skills/cocoar-vue-ui/references/components/page-builder/authoring-contract.md +271 -0
- package/skills/cocoar-vue-ui/references/components/page-builder/coar-page-builder.md +476 -0
- package/skills/cocoar-vue-ui/references/components/page-builder/coar-page-renderer.md +677 -0
- package/skills/cocoar-vue-ui/references/components/page-builder/custom-elements.md +441 -0
- package/skills/cocoar-vue-ui/references/components/page-builder/idp-integration.md +122 -0
- package/skills/cocoar-vue-ui/references/components/page-builder/index.md +573 -0
- package/skills/cocoar-vue-ui/references/components/pagination.md +150 -0
- package/skills/cocoar-vue-ui/references/components/panel-layout.md +372 -0
- package/skills/cocoar-vue-ui/references/components/password-input.md +175 -0
- package/skills/cocoar-vue-ui/references/components/popconfirm.md +186 -0
- package/skills/cocoar-vue-ui/references/components/popover.md +173 -0
- package/skills/cocoar-vue-ui/references/components/progress-bar.md +178 -0
- package/skills/cocoar-vue-ui/references/components/radio-group.md +225 -0
- package/skills/cocoar-vue-ui/references/components/script-editor.md +1271 -0
- package/skills/cocoar-vue-ui/references/components/segmented-control.md +238 -0
- package/skills/cocoar-vue-ui/references/components/select.md +463 -0
- package/skills/cocoar-vue-ui/references/components/sidebar.md +421 -0
- package/skills/cocoar-vue-ui/references/components/spinner.md +132 -0
- package/skills/cocoar-vue-ui/references/components/switch.md +195 -0
- package/skills/cocoar-vue-ui/references/components/table.md +170 -0
- package/skills/cocoar-vue-ui/references/components/tabs.md +382 -0
- package/skills/cocoar-vue-ui/references/components/tag.md +178 -0
- package/skills/cocoar-vue-ui/references/components/text-input.md +256 -0
- package/skills/cocoar-vue-ui/references/components/toast.md +160 -0
- package/skills/cocoar-vue-ui/references/components/tooltip.md +121 -0
- package/skills/cocoar-vue-ui/references/components/transitions.md +193 -0
- package/skills/cocoar-vue-ui/references/components/tree.md +2388 -0
- package/skills/cocoar-vue-ui/references/components/virtual-list.md +212 -0
- package/skills/cocoar-vue-ui/references/components/wizard.md +251 -0
- package/skills/cocoar-vue-ui/references/components/zoned-date-time-picker.md +177 -0
- package/skills/cocoar-vue-ui/references/foundations/colors.md +708 -0
- package/skills/cocoar-vue-ui/references/foundations/design-principles.md +115 -0
- package/skills/cocoar-vue-ui/references/foundations/icons.md +381 -0
- package/skills/cocoar-vue-ui/references/foundations/localization/formatting.md +530 -0
- package/skills/cocoar-vue-ui/references/foundations/localization/setup.md +86 -0
- package/skills/cocoar-vue-ui/references/foundations/localization/timezones.md +182 -0
- package/skills/cocoar-vue-ui/references/foundations/localization/translations.md +305 -0
- package/skills/cocoar-vue-ui/references/foundations/motion.md +549 -0
- package/skills/cocoar-vue-ui/references/foundations/spacing.md +330 -0
- package/skills/cocoar-vue-ui/references/foundations/theming.md +140 -0
- package/skills/cocoar-vue-ui/references/foundations/typography.md +206 -0
- package/skills/cocoar-vue-ui/references/guide/error-handling.md +162 -0
- package/skills/cocoar-vue-ui/references/guide/getting-started.md +116 -0
- package/skills/cocoar-vue-ui/references/guide/migration-page-builder-3.md +207 -0
- package/skills/cocoar-vue-ui/references/guide/migration.md +140 -0
- package/skills/cocoar-vue-ui/references/guide/theming.md +98 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
<!-- Generated from apps/docs/components/switch.md by apps/docs/scripts/sync-skill.mjs. Do not edit; edit the docs page. -->
|
|
2
|
+
|
|
3
|
+
# Switch
|
|
4
|
+
|
|
5
|
+
A toggle for boolean settings that take effect immediately -- think "Enable notifications" or "Dark mode". Unlike a [Checkbox](./checkbox.md), a switch signals instant action rather than a deferred choice that requires a submit button.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { CoarSwitch } from '@cocoar/vue-ui';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Basic Usage
|
|
12
|
+
|
|
13
|
+
Bind a boolean with `v-model` and provide a `label`. The switch flips on click or keyboard activation.
|
|
14
|
+
|
|
15
|
+
**Demo — `switch/demos/BasicSwitch.vue`**
|
|
16
|
+
|
|
17
|
+
```vue
|
|
18
|
+
<template>
|
|
19
|
+
<div style="display: flex; flex-direction: column; gap: 12px;">
|
|
20
|
+
<CoarSwitch v-model="darkMode" label="Dark mode" />
|
|
21
|
+
<span style="font-size: 13px; color: #64748b;">Value: {{ darkMode }}</span>
|
|
22
|
+
</div>
|
|
23
|
+
</template>
|
|
24
|
+
|
|
25
|
+
<script setup lang="ts">
|
|
26
|
+
import { ref } from 'vue';
|
|
27
|
+
import { CoarSwitch } from '@cocoar/vue-ui';
|
|
28
|
+
|
|
29
|
+
const darkMode = ref(false);
|
|
30
|
+
</script>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## With Hint Text
|
|
34
|
+
|
|
35
|
+
Wrap in `CoarFormField` with a `hint` prop to add a brief explanation, helping users understand the consequence of toggling.
|
|
36
|
+
|
|
37
|
+
**Demo — `switch/demos/SwitchHint.vue`**
|
|
38
|
+
|
|
39
|
+
```vue
|
|
40
|
+
<template>
|
|
41
|
+
<div style="display: flex; flex-direction: column; gap: 16px;">
|
|
42
|
+
<CoarFormField hint="Receive notifications about account activity.">
|
|
43
|
+
<CoarSwitch v-model="notifications" label="Push notifications" />
|
|
44
|
+
</CoarFormField>
|
|
45
|
+
<CoarFormField hint="Automatically save changes every 5 minutes.">
|
|
46
|
+
<CoarSwitch v-model="autoSave" label="Auto-save" />
|
|
47
|
+
</CoarFormField>
|
|
48
|
+
</div>
|
|
49
|
+
</template>
|
|
50
|
+
|
|
51
|
+
<script setup lang="ts">
|
|
52
|
+
import { ref } from 'vue';
|
|
53
|
+
import { CoarSwitch, CoarFormField } from '@cocoar/vue-ui';
|
|
54
|
+
|
|
55
|
+
const notifications = ref(true);
|
|
56
|
+
const autoSave = ref(false);
|
|
57
|
+
</script>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## States
|
|
61
|
+
|
|
62
|
+
Supports `disabled` (both on and off), `required`, and `error` states for complete form validation coverage.
|
|
63
|
+
|
|
64
|
+
**Demo — `switch/demos/SwitchStates.vue`**
|
|
65
|
+
|
|
66
|
+
```vue
|
|
67
|
+
<template>
|
|
68
|
+
<div style="display: flex; flex-direction: column; gap: 8px;">
|
|
69
|
+
<CoarSwitch :model-value="true" label="Disabled (on)" :disabled="true" />
|
|
70
|
+
<CoarSwitch :model-value="false" label="Disabled (off)" :disabled="true" />
|
|
71
|
+
<CoarSwitch :model-value="false" label="Required switch" :required="true" />
|
|
72
|
+
<CoarFormField error="This setting must be enabled">
|
|
73
|
+
<CoarSwitch :model-value="false" label="With error" />
|
|
74
|
+
</CoarFormField>
|
|
75
|
+
</div>
|
|
76
|
+
</template>
|
|
77
|
+
|
|
78
|
+
<script setup lang="ts">
|
|
79
|
+
import { CoarSwitch, CoarFormField } from '@cocoar/vue-ui';
|
|
80
|
+
</script>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Sizes
|
|
84
|
+
|
|
85
|
+
Four sizes so the switch fits naturally alongside other controls at any density.
|
|
86
|
+
|
|
87
|
+
**Demo — `switch/demos/SwitchSizes.vue`**
|
|
88
|
+
|
|
89
|
+
```vue
|
|
90
|
+
<template>
|
|
91
|
+
<div style="display: flex; flex-direction: column; gap: 8px;">
|
|
92
|
+
<CoarSwitch :model-value="true" size="xs" label="Extra-small switch" />
|
|
93
|
+
<CoarSwitch :model-value="true" size="s" label="Small switch" />
|
|
94
|
+
<CoarSwitch :model-value="true" size="m" label="Medium switch (default)" />
|
|
95
|
+
<CoarSwitch :model-value="true" size="l" label="Large switch" />
|
|
96
|
+
</div>
|
|
97
|
+
</template>
|
|
98
|
+
|
|
99
|
+
<script setup lang="ts">
|
|
100
|
+
import { CoarSwitch } from '@cocoar/vue-ui';
|
|
101
|
+
</script>
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Label Position
|
|
105
|
+
|
|
106
|
+
Place the label before or after the switch with the `labelPosition` prop. Defaults to `'after'`.
|
|
107
|
+
|
|
108
|
+
**Demo — `switch/demos/SwitchLabelPosition.vue`**
|
|
109
|
+
|
|
110
|
+
```vue
|
|
111
|
+
<template>
|
|
112
|
+
<div style="display: flex; flex-direction: column; gap: 16px;">
|
|
113
|
+
<CoarSwitch v-model="a" label="Label after (default)" label-position="after" />
|
|
114
|
+
<CoarSwitch v-model="b" label="Label before" label-position="before" />
|
|
115
|
+
</div>
|
|
116
|
+
</template>
|
|
117
|
+
|
|
118
|
+
<script setup lang="ts">
|
|
119
|
+
import { ref } from 'vue';
|
|
120
|
+
import { CoarSwitch } from '@cocoar/vue-ui';
|
|
121
|
+
|
|
122
|
+
const a = ref(true);
|
|
123
|
+
const b = ref(true);
|
|
124
|
+
</script>
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Settings Panel Example
|
|
128
|
+
|
|
129
|
+
Switches shine in settings panels where each row controls an independent feature. Here is a typical layout pattern.
|
|
130
|
+
|
|
131
|
+
**Demo — `switch/demos/SwitchSettingsPanel.vue`**
|
|
132
|
+
|
|
133
|
+
```vue
|
|
134
|
+
<template>
|
|
135
|
+
<div style="display: flex; flex-direction: column; max-width: 360px;">
|
|
136
|
+
<div v-for="(item, i) in settings" :key="item.label" :style="{
|
|
137
|
+
display: 'flex',
|
|
138
|
+
alignItems: 'center',
|
|
139
|
+
justifyContent: 'space-between',
|
|
140
|
+
padding: '10px 0',
|
|
141
|
+
borderBottom: i < settings.length - 1 ? '1px solid var(--coar-border-neutral-secondary)' : 'none'
|
|
142
|
+
}">
|
|
143
|
+
<div style="display: flex; flex-direction: column; gap: 2px;">
|
|
144
|
+
<span style="font-size: 14px; font-weight: 600;">{{ item.label }}</span>
|
|
145
|
+
<span style="font-size: 13px; color: #64748b;">{{ item.description }}</span>
|
|
146
|
+
</div>
|
|
147
|
+
<CoarSwitch :model-value="item.enabled" />
|
|
148
|
+
</div>
|
|
149
|
+
</div>
|
|
150
|
+
</template>
|
|
151
|
+
|
|
152
|
+
<script setup lang="ts">
|
|
153
|
+
import { CoarSwitch } from '@cocoar/vue-ui';
|
|
154
|
+
|
|
155
|
+
const settings = [
|
|
156
|
+
{ label: 'Email notifications', description: 'Get emails about activity', enabled: true },
|
|
157
|
+
{ label: 'Marketing emails', description: 'Promotions and updates', enabled: false },
|
|
158
|
+
{ label: 'Two-factor auth', description: 'Enhanced security', enabled: true },
|
|
159
|
+
];
|
|
160
|
+
</script>
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Accessibility
|
|
164
|
+
|
|
165
|
+
### Keyboard Navigation
|
|
166
|
+
|
|
167
|
+
| Key | Action |
|
|
168
|
+
|-----|--------|
|
|
169
|
+
| `Tab` | Move focus to switch |
|
|
170
|
+
| `Space` | Toggle on/off state |
|
|
171
|
+
| `Enter` | Toggle on/off state |
|
|
172
|
+
|
|
173
|
+
> **Info**
|
|
174
|
+
>
|
|
175
|
+
> Switches use `role="switch"` with `aria-checked` to properly communicate state to screen readers.
|
|
176
|
+
|
|
177
|
+
### Screen Reader Support
|
|
178
|
+
|
|
179
|
+
- Label text announces on focus
|
|
180
|
+
- On/off state properly communicated via `aria-checked`
|
|
181
|
+
- Hint text accessible via `aria-describedby`
|
|
182
|
+
- Error messages announced when present
|
|
183
|
+
|
|
184
|
+
## API
|
|
185
|
+
|
|
186
|
+
### Props
|
|
187
|
+
|
|
188
|
+
| Prop | Type | Default | Description |
|
|
189
|
+
|------|------|---------|-------------|
|
|
190
|
+
| `v-model` | `boolean` | `false` | Switch on/off state |
|
|
191
|
+
| `label` | `string` | `''` | Label text |
|
|
192
|
+
| `error` | `boolean` | `false` | Error state (auto-injected from `CoarFormField`) |
|
|
193
|
+
| `size` | `'xs' \| 's' \| 'm' \| 'l'` | `'m'` | Switch size |
|
|
194
|
+
| `disabled` | `boolean` | `false` | Disable the switch |
|
|
195
|
+
| `labelPosition` | `'before' \| 'after'` | `'after'` | Label position relative to the switch |
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
<!-- Generated from apps/docs/components/table.md by apps/docs/scripts/sync-skill.mjs. Do not edit; edit the docs page. -->
|
|
2
|
+
|
|
3
|
+
# Table
|
|
4
|
+
|
|
5
|
+
A lightweight table wrapper that provides consistent styling, alternating row colors, and proper alignment out of the box. Use it whenever you need to present structured data -- user lists, order histories, configuration settings, or comparison grids.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { CoarTable } from '@cocoar/vue-ui';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Basic Usage
|
|
12
|
+
|
|
13
|
+
Wrap standard `thead`, `tbody`, `tr`, `th`, and `td` elements. Alternating row colors are applied automatically to improve readability in longer datasets.
|
|
14
|
+
|
|
15
|
+
**Demo — `table/demos/TableBasic.vue`**
|
|
16
|
+
|
|
17
|
+
```vue
|
|
18
|
+
<template>
|
|
19
|
+
<CoarTable>
|
|
20
|
+
<thead>
|
|
21
|
+
<tr>
|
|
22
|
+
<th>ID</th>
|
|
23
|
+
<th>Name</th>
|
|
24
|
+
<th>Email</th>
|
|
25
|
+
<th>Role</th>
|
|
26
|
+
<th>Status</th>
|
|
27
|
+
</tr>
|
|
28
|
+
</thead>
|
|
29
|
+
<tbody>
|
|
30
|
+
<tr v-for="user in users" :key="user.id">
|
|
31
|
+
<td>{{ user.id }}</td>
|
|
32
|
+
<td>{{ user.name }}</td>
|
|
33
|
+
<td>{{ user.email }}</td>
|
|
34
|
+
<td>{{ user.role }}</td>
|
|
35
|
+
<td>
|
|
36
|
+
<CoarTag :variant="statusVariant[user.status]" size="s">{{ user.status }}</CoarTag>
|
|
37
|
+
</td>
|
|
38
|
+
</tr>
|
|
39
|
+
</tbody>
|
|
40
|
+
</CoarTable>
|
|
41
|
+
</template>
|
|
42
|
+
|
|
43
|
+
<script setup lang="ts">
|
|
44
|
+
import { CoarTable, CoarTag } from '@cocoar/vue-ui';
|
|
45
|
+
|
|
46
|
+
const users = [
|
|
47
|
+
{ id: 1, name: 'Alice Johnson', role: 'Admin', status: 'active', email: 'alice@example.com' },
|
|
48
|
+
{ id: 2, name: 'Bob Smith', role: 'Editor', status: 'active', email: 'bob@example.com' },
|
|
49
|
+
{ id: 3, name: 'Carol White', role: 'Viewer', status: 'pending', email: 'carol@example.com' },
|
|
50
|
+
{ id: 4, name: 'David Brown', role: 'Editor', status: 'inactive', email: 'david@example.com' },
|
|
51
|
+
{ id: 5, name: 'Eva Martinez', role: 'Admin', status: 'active', email: 'eva@example.com' },
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
const statusVariant: Record<string, 'success' | 'warning' | 'neutral'> = {
|
|
55
|
+
active: 'success',
|
|
56
|
+
pending: 'warning',
|
|
57
|
+
inactive: 'neutral',
|
|
58
|
+
};
|
|
59
|
+
</script>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Rich Cells
|
|
63
|
+
|
|
64
|
+
Table cells aren't limited to plain text. Embed avatars, tags, badges, and other components directly in cells to create information-dense but scannable rows.
|
|
65
|
+
|
|
66
|
+
**Demo — `table/demos/TableRichCells.vue`**
|
|
67
|
+
|
|
68
|
+
```vue
|
|
69
|
+
<template>
|
|
70
|
+
<CoarTable>
|
|
71
|
+
<thead>
|
|
72
|
+
<tr>
|
|
73
|
+
<th>User</th>
|
|
74
|
+
<th>Role</th>
|
|
75
|
+
<th>Status</th>
|
|
76
|
+
<th>Notifications</th>
|
|
77
|
+
</tr>
|
|
78
|
+
</thead>
|
|
79
|
+
<tbody>
|
|
80
|
+
<tr v-for="user in users" :key="user.id">
|
|
81
|
+
<td>
|
|
82
|
+
<div style="display: flex; align-items: center; gap: 8px;">
|
|
83
|
+
<CoarAvatar :name="user.name" size="s" />
|
|
84
|
+
<div>
|
|
85
|
+
<div style="font-size: 14px; font-weight: 600;">{{ user.name }}</div>
|
|
86
|
+
<div style="font-size: 14px; color: #64748b;">{{ user.email }}</div>
|
|
87
|
+
</div>
|
|
88
|
+
</div>
|
|
89
|
+
</td>
|
|
90
|
+
<td>{{ user.role }}</td>
|
|
91
|
+
<td><CoarTag :variant="statusVariant[user.status]" size="s">{{ user.status }}</CoarTag></td>
|
|
92
|
+
<td><CoarBadge v-if="user.status === 'active'" variant="error" size="s" :content="user.notifs" /></td>
|
|
93
|
+
</tr>
|
|
94
|
+
</tbody>
|
|
95
|
+
</CoarTable>
|
|
96
|
+
</template>
|
|
97
|
+
|
|
98
|
+
<script setup lang="ts">
|
|
99
|
+
import { CoarTable, CoarTag, CoarAvatar, CoarBadge } from '@cocoar/vue-ui';
|
|
100
|
+
|
|
101
|
+
const users = [
|
|
102
|
+
{ id: 1, name: 'Alice Johnson', role: 'Admin', status: 'active', email: 'alice@example.com', notifs: 3 },
|
|
103
|
+
{ id: 2, name: 'Bob Smith', role: 'Editor', status: 'active', email: 'bob@example.com', notifs: 7 },
|
|
104
|
+
{ id: 3, name: 'Carol White', role: 'Viewer', status: 'pending', email: 'carol@example.com', notifs: 0 },
|
|
105
|
+
{ id: 4, name: 'David Brown', role: 'Editor', status: 'inactive', email: 'david@example.com', notifs: 0 },
|
|
106
|
+
{ id: 5, name: 'Eva Martinez', role: 'Admin', status: 'active', email: 'eva@example.com', notifs: 2 },
|
|
107
|
+
];
|
|
108
|
+
|
|
109
|
+
const statusVariant: Record<string, 'success' | 'warning' | 'neutral'> = {
|
|
110
|
+
active: 'success',
|
|
111
|
+
pending: 'warning',
|
|
112
|
+
inactive: 'neutral',
|
|
113
|
+
};
|
|
114
|
+
</script>
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Variants
|
|
118
|
+
|
|
119
|
+
The default striped style works well for most tables. Switch to `plain` for a minimal look, or `bordered` when you need explicit cell boundaries -- useful for dense data or comparison tables.
|
|
120
|
+
|
|
121
|
+
**Demo — `table/demos/TableVariants.vue`**
|
|
122
|
+
|
|
123
|
+
```vue
|
|
124
|
+
<template>
|
|
125
|
+
<div style="display: flex; flex-direction: column; gap: 16px;">
|
|
126
|
+
<div>
|
|
127
|
+
<p style="margin: 0 0 4px; font-size: 13px; color: #64748b;">Default (striped)</p>
|
|
128
|
+
<CoarTable>
|
|
129
|
+
<thead><tr><th>Name</th><th>Value</th></tr></thead>
|
|
130
|
+
<tbody>
|
|
131
|
+
<tr><td>Alpha</td><td>1</td></tr>
|
|
132
|
+
<tr><td>Beta</td><td>2</td></tr>
|
|
133
|
+
<tr><td>Gamma</td><td>3</td></tr>
|
|
134
|
+
</tbody>
|
|
135
|
+
</CoarTable>
|
|
136
|
+
</div>
|
|
137
|
+
<div>
|
|
138
|
+
<p style="margin: 0 0 4px; font-size: 13px; color: #64748b;">Bordered</p>
|
|
139
|
+
<CoarTable variant="bordered">
|
|
140
|
+
<thead><tr><th>Name</th><th>Value</th></tr></thead>
|
|
141
|
+
<tbody>
|
|
142
|
+
<tr><td>Alpha</td><td>1</td></tr>
|
|
143
|
+
<tr><td>Beta</td><td>2</td></tr>
|
|
144
|
+
<tr><td>Gamma</td><td>3</td></tr>
|
|
145
|
+
</tbody>
|
|
146
|
+
</CoarTable>
|
|
147
|
+
</div>
|
|
148
|
+
</div>
|
|
149
|
+
</template>
|
|
150
|
+
|
|
151
|
+
<script setup lang="ts">
|
|
152
|
+
import { CoarTable } from '@cocoar/vue-ui';
|
|
153
|
+
</script>
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## API
|
|
157
|
+
|
|
158
|
+
### Props
|
|
159
|
+
|
|
160
|
+
| Prop | Type | Default | Description |
|
|
161
|
+
|------|------|---------|-------------|
|
|
162
|
+
| `variant` | `'default' \| 'plain' \| 'bordered'` | `'default'` | Table style variant |
|
|
163
|
+
| `compact` | `boolean` | `false` | Use compact cell padding |
|
|
164
|
+
| `hover` | `boolean` | `true` | Highlight rows on hover |
|
|
165
|
+
|
|
166
|
+
### Slots
|
|
167
|
+
|
|
168
|
+
| Slot | Description |
|
|
169
|
+
|------|-------------|
|
|
170
|
+
| `default` | Native thead/tbody/tr/th/td elements |
|