@dolanske/vui 1.0.4 → 1.1.0

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.
Files changed (195) hide show
  1. package/LICENSE +673 -673
  2. package/README.md +42 -42
  3. package/dist/components/Accordion/Accordion.vue.d.ts +3 -2
  4. package/dist/components/Accordion/AccordionGroup.vue.d.ts +5 -2
  5. package/dist/components/Alert/Alert.vue.d.ts +3 -2
  6. package/dist/components/Avatar/Avatar.vue.d.ts +3 -2
  7. package/dist/components/Badge/Badge.vue.d.ts +3 -2
  8. package/dist/components/Breadcrumbs/BreadcrumbItem.vue.d.ts +3 -2
  9. package/dist/components/Breadcrumbs/Breadcrumbs.vue.d.ts +3 -2
  10. package/dist/components/Button/Button.vue.d.ts +3 -2
  11. package/dist/components/ButtonGroup/ButtonGroup.vue.d.ts +3 -2
  12. package/dist/components/Calendar/Calendar.vue.d.ts +6 -6
  13. package/dist/components/Card/Card.vue.d.ts +4 -3
  14. package/dist/components/Checkbox/Checkbox.vue.d.ts +7 -6
  15. package/dist/components/CopyClipboard/CopyClipboard.vue.d.ts +2 -1
  16. package/dist/components/Divider/Divider.vue.d.ts +3 -2
  17. package/dist/components/Drawer/Drawer.vue.d.ts +10 -9
  18. package/dist/components/Dropdown/Dropdown.vue.d.ts +66 -3
  19. package/dist/components/Dropdown/DropdownItem.vue.d.ts +3 -2
  20. package/dist/components/Dropdown/DropdownTitle.vue.d.ts +6 -6
  21. package/dist/components/Flex/Flex.vue.d.ts +13 -12
  22. package/dist/components/Grid/Grid.vue.d.ts +7 -6
  23. package/dist/components/Input/Color.vue.d.ts +5 -5
  24. package/dist/components/Input/Counter.vue.d.ts +5 -5
  25. package/dist/components/Input/Dropzone.vue.d.ts +95 -10
  26. package/dist/components/Input/File.vue.d.ts +4 -3
  27. package/dist/components/Input/Input.vue.d.ts +7 -6
  28. package/dist/components/Input/Password.vue.d.ts +1 -1
  29. package/dist/components/Input/Textarea.vue.d.ts +7 -6
  30. package/dist/components/Kbd/Kbd.vue.d.ts +1 -1
  31. package/dist/components/Kbd/KbdGroup.vue.d.ts +2 -1
  32. package/dist/components/Modal/Confirm.vue.d.ts +7 -9
  33. package/dist/components/Modal/Modal.vue.d.ts +16 -13
  34. package/dist/components/OTP/OTP.vue.d.ts +7 -6
  35. package/dist/components/OTP/OTPItem.vue.d.ts +1 -1
  36. package/dist/components/Pagination/Pagination.vue.d.ts +3 -2
  37. package/dist/components/Popout/Popout.vue.d.ts +3 -2
  38. package/dist/components/Progress/Progress.vue.d.ts +5 -5
  39. package/dist/components/Radio/Radio.vue.d.ts +7 -6
  40. package/dist/components/Radio/RadioGroup.vue.d.ts +7 -6
  41. package/dist/components/Select/Select.vue.d.ts +4 -8
  42. package/dist/components/Sheet/Sheet.vue.d.ts +22 -13
  43. package/dist/components/Sidebar/Sidebar.vue.d.ts +7 -6
  44. package/dist/components/Skeleton/Skeleton.vue.d.ts +1 -1
  45. package/dist/components/Spinner/Spinner.vue.d.ts +1 -1
  46. package/dist/components/Switch/Switch.vue.d.ts +7 -6
  47. package/dist/components/Table/Cell.vue.d.ts +5 -2
  48. package/dist/components/Table/Head.vue.d.ts +3 -2
  49. package/dist/components/Table/Root.vue.d.ts +3 -2
  50. package/dist/components/Table/table.d.ts +2 -2
  51. package/dist/components/Tabs/Tab.vue.d.ts +3 -2
  52. package/dist/components/Tabs/Tabs.vue.d.ts +7 -6
  53. package/dist/components/Toast/toast.d.ts +6 -6
  54. package/dist/components/Tooltip/Tooltip.vue.d.ts +2 -1
  55. package/dist/internal/Backdrop/Backdrop.vue.d.ts +3 -2
  56. package/dist/vui.css +1 -0
  57. package/dist/vui.js +8090 -7884
  58. package/package.json +73 -72
  59. package/src/App.vue +95 -95
  60. package/src/components/Accordion/Accordion.vue +91 -91
  61. package/src/components/Accordion/AccordionGroup.vue +43 -43
  62. package/src/components/Accordion/accordion.scss +82 -82
  63. package/src/components/Alert/Alert.vue +59 -59
  64. package/src/components/Alert/alert.scss +161 -161
  65. package/src/components/Avatar/Avatar.vue +53 -53
  66. package/src/components/Avatar/avatar.scss +52 -52
  67. package/src/components/Badge/Badge.vue +21 -21
  68. package/src/components/Badge/badge.scss +210 -206
  69. package/src/components/Breadcrumbs/BreadcrumbItem.vue +26 -26
  70. package/src/components/Breadcrumbs/Breadcrumbs.vue +30 -30
  71. package/src/components/Breadcrumbs/breadcrumbs.scss +31 -31
  72. package/src/components/Button/Button.vue +85 -85
  73. package/src/components/Button/button.scss +279 -279
  74. package/src/components/ButtonGroup/ButtonGroup.vue +28 -28
  75. package/src/components/ButtonGroup/button-group.scss +51 -51
  76. package/src/components/Calendar/Calendar.vue +66 -66
  77. package/src/components/Calendar/calendar.scss +83 -83
  78. package/src/components/Card/Card.vue +48 -48
  79. package/src/components/Card/card.scss +53 -53
  80. package/src/components/Checkbox/Checkbox.vue +54 -54
  81. package/src/components/Checkbox/checkbox.scss +80 -80
  82. package/src/components/CopyClipboard/CopyClipboard.vue +91 -91
  83. package/src/components/CopyClipboard/copy-clipboard.scss +25 -25
  84. package/src/components/Divider/Divider.vue +44 -44
  85. package/src/components/Divider/divider.scss +35 -35
  86. package/src/components/Drawer/Drawer.vue +102 -97
  87. package/src/components/Drawer/drawer.scss +37 -37
  88. package/src/components/Dropdown/Dropdown.vue +135 -135
  89. package/src/components/Dropdown/DropdownItem.vue +33 -33
  90. package/src/components/Dropdown/DropdownTitle.vue +14 -14
  91. package/src/components/Dropdown/dropdown-item.scss +84 -84
  92. package/src/components/Dropdown/dropdown.scss +53 -53
  93. package/src/components/Flex/Flex.vue +113 -113
  94. package/src/components/Grid/Grid.vue +79 -80
  95. package/src/components/Input/Color.vue +26 -26
  96. package/src/components/Input/Counter.vue +66 -66
  97. package/src/components/Input/Dropzone.vue +65 -65
  98. package/src/components/Input/File.vue +15 -15
  99. package/src/components/Input/Input.vue +123 -123
  100. package/src/components/Input/Password.vue +35 -35
  101. package/src/components/Input/Textarea.vue +78 -78
  102. package/src/components/Input/input.scss +302 -302
  103. package/src/components/Kbd/Kbd.vue +48 -48
  104. package/src/components/Kbd/KbdGroup.vue +27 -27
  105. package/src/components/Kbd/kbd.scss +19 -19
  106. package/src/components/Modal/Confirm.vue +56 -56
  107. package/src/components/Modal/Modal.vue +103 -99
  108. package/src/components/Modal/modal.scss +54 -54
  109. package/src/components/OTP/OTP.vue +133 -133
  110. package/src/components/OTP/OTPItem.vue +37 -37
  111. package/src/components/OTP/otp.scss +84 -84
  112. package/src/components/Pagination/Pagination.vue +77 -77
  113. package/src/components/Pagination/pagination.ts +78 -78
  114. package/src/components/Popout/Popout.vue +52 -52
  115. package/src/components/Popout/popout.scss +15 -15
  116. package/src/components/Progress/Progress.vue +103 -103
  117. package/src/components/Progress/progress.scss +47 -47
  118. package/src/components/Radio/Radio.vue +38 -38
  119. package/src/components/Radio/RadioGroup.vue +40 -40
  120. package/src/components/Radio/radio.scss +78 -78
  121. package/src/components/Select/Select.vue +211 -211
  122. package/src/components/Select/select.scss +77 -77
  123. package/src/components/Sheet/Sheet.vue +108 -98
  124. package/src/components/Sheet/sheet.scss +69 -69
  125. package/src/components/Sidebar/Sidebar.vue +115 -115
  126. package/src/components/Sidebar/sidebar.scss +124 -124
  127. package/src/components/Skeleton/Skeleton.vue +43 -43
  128. package/src/components/Skeleton/skeleton.scss +14 -14
  129. package/src/components/Spinner/Spinner.vue +42 -42
  130. package/src/components/Spinner/spinner.scss +47 -47
  131. package/src/components/Switch/Switch.vue +31 -31
  132. package/src/components/Switch/switch.scss +93 -93
  133. package/src/components/Table/Cell.vue +23 -23
  134. package/src/components/Table/Head.vue +59 -59
  135. package/src/components/Table/Root.vue +66 -66
  136. package/src/components/Table/SelectAll.vue +23 -23
  137. package/src/components/Table/SelectRow.vue +30 -30
  138. package/src/components/Table/index.ts +7 -7
  139. package/src/components/Table/table.scss +154 -154
  140. package/src/components/Table/table.ts +248 -248
  141. package/src/components/Tabs/Tab.vue +25 -25
  142. package/src/components/Tabs/Tabs.vue +90 -90
  143. package/src/components/Tabs/tabs.scss +87 -87
  144. package/src/components/Toast/Toasts.vue +52 -52
  145. package/src/components/Toast/toast.scss +45 -45
  146. package/src/components/Toast/toast.ts +75 -75
  147. package/src/components/Tooltip/Tooltip.vue +86 -86
  148. package/src/components/Tooltip/tooltip.scss +8 -8
  149. package/src/examples/ExampleAccordions.vue +58 -58
  150. package/src/examples/ExampleAlerts.vue +78 -78
  151. package/src/examples/ExampleAvatars.vue +44 -44
  152. package/src/examples/ExampleBadges.vue +48 -48
  153. package/src/examples/ExampleBreadcrumbs.vue +46 -46
  154. package/src/examples/ExampleButtons.vue +140 -140
  155. package/src/examples/ExampleCalendars.vue +40 -40
  156. package/src/examples/ExampleCards.vue +94 -94
  157. package/src/examples/ExampleCheckboxes.vue +123 -123
  158. package/src/examples/ExampleCopyClipboard.vue +47 -47
  159. package/src/examples/ExampleDividers.vue +39 -39
  160. package/src/examples/ExampleDrawers.vue +67 -67
  161. package/src/examples/ExampleDropdowns.vue +114 -114
  162. package/src/examples/ExampleFlexGrid.vue +124 -122
  163. package/src/examples/ExampleInputs.vue +234 -234
  164. package/src/examples/ExampleKBD.vue +65 -65
  165. package/src/examples/ExampleModals.vue +143 -143
  166. package/src/examples/ExamplePalette.vue +159 -159
  167. package/src/examples/ExamplePopouts.vue +41 -41
  168. package/src/examples/ExampleSheets.vue +77 -77
  169. package/src/examples/ExampleSidebars.vue +270 -270
  170. package/src/examples/ExampleSkeletons.vue +26 -26
  171. package/src/examples/ExampleSpinners.vue +80 -78
  172. package/src/examples/ExampleTables.vue +195 -195
  173. package/src/examples/ExampleTabs.vue +119 -119
  174. package/src/examples/ExampleToasts.vue +96 -96
  175. package/src/examples/ExampleTooltips.vue +70 -70
  176. package/src/examples/shared/ExampleColor.vue +28 -28
  177. package/src/index.ts +116 -116
  178. package/src/internal/Backdrop/Backdrop.vue +22 -22
  179. package/src/internal/Backdrop/backdrop.scss +34 -34
  180. package/src/main.ts +5 -5
  181. package/src/shared/helpers.ts +117 -117
  182. package/src/shared/theme.ts +22 -22
  183. package/src/shared/types.ts +29 -29
  184. package/src/style/animation.scss +22 -22
  185. package/src/style/core.scss +119 -125
  186. package/src/style/layout.scss +207 -233
  187. package/src/style/media-query.scss +29 -29
  188. package/src/style/reset.scss +135 -135
  189. package/src/style/text.scss +137 -124
  190. package/src/style/theme.scss +195 -195
  191. package/src/style/tooltip.scss +146 -146
  192. package/src/style/typography.scss +415 -415
  193. package/src/style/utils.scss +36 -36
  194. package/src/style.scss +1 -1
  195. package/dist/style.css +0 -1
@@ -1,78 +1,80 @@
1
- <script setup lang='ts'>
2
- import { ref, watch } from 'vue'
3
- import Button from '../components/Button/Button.vue'
4
- import Checkbox from '../components/Checkbox/Checkbox.vue'
5
- import Flex from '../components/Flex/Flex.vue'
6
- import Progress from '../components/Progress/Progress.vue'
7
- import Spinner from '../components/Spinner/Spinner.vue'
8
-
9
- const paused = ref(true)
10
- const progress = ref(25)
11
-
12
- const fakeProgress = ref(15)
13
- const showFixed = ref(false)
14
- const variants = ['s', 'm', 'l'] as const
15
-
16
- watch(paused, () => fakeProgress.value = 0)
17
- </script>
18
-
19
- <template>
20
- <div class="mb-xxl">
21
- <h3 class="mb-l flex g-m y-center">
22
- Loading
23
- <Button square :icon="paused ? 'ph:play' : 'ph:pause'" size="s" plain @click="paused = !paused" />
24
- </h3>
25
- <table>
26
- <tbody>
27
- <tr>
28
- <th>Spinners</th>
29
- <td>
30
- <Flex
31
- gap="l" :style="{
32
- 'animation-play-state': 'paused',
33
- }"
34
- >
35
- <Spinner
36
- v-for="size in variants" :key="size" :size :style="{
37
- 'animation-play-state': paused ? 'paused' : 'running',
38
- }"
39
- />
40
- </Flex>
41
- </td>
42
- </tr>
43
- <tr>
44
- <th>Progress bar</th>
45
- <td class="w-80">
46
- <Flex gap="s" align-center>
47
- <Button square icon="ph:minus" size="s" @click="progress -= 5" />
48
- <Progress v-model="progress" class="w-full" />
49
- <Button square icon="ph:plus" size="s" @click="progress += 5" />
50
- </Flex>
51
- </td>
52
- </tr>
53
- <tr>
54
- <th>Progress bar tall</th>
55
- <td class="w-80">
56
- <Flex gap="s" align-center>
57
- <Progress v-model="progress" :height="8" class="w-full" />
58
- </Flex>
59
- </td>
60
- </tr>
61
- <tr>
62
- <th>Fake</th>
63
- <td>
64
- <Progress v-model="fakeProgress" :fake="!paused" />
65
- </td>
66
- </tr>
67
- <tr>
68
- <th>Fixed</th>
69
- <td>
70
- <Checkbox v-model="showFixed" label="Show fixed progress bar (look up)" />
71
-
72
- <Progress v-if="showFixed" v-model="fakeProgress" :fake="!paused" fixed />
73
- </td>
74
- </tr>
75
- </tbody>
76
- </table>
77
- </div>
78
- </template>
1
+ <script setup lang='ts'>
2
+ import { ref, watch } from 'vue'
3
+ import Button from '../components/Button/Button.vue'
4
+ import Checkbox from '../components/Checkbox/Checkbox.vue'
5
+ import Flex from '../components/Flex/Flex.vue'
6
+ import Progress from '../components/Progress/Progress.vue'
7
+ import Spinner from '../components/Spinner/Spinner.vue'
8
+
9
+ const paused = ref(true)
10
+ const progress = ref(25)
11
+
12
+ const fakeProgress = ref(15)
13
+ const showFixed = ref(false)
14
+ const variants = ['s', 'm', 'l'] as const
15
+
16
+ watch(paused, () => fakeProgress.value = 0)
17
+ </script>
18
+
19
+ <template>
20
+ <div class="mb-xxl">
21
+ <h3 class="mb-l">
22
+ <Flex y-center gap="m">
23
+ Loading
24
+ <Button square :icon="paused ? 'ph:play' : 'ph:pause'" size="s" plain @click="paused = !paused" />
25
+ </Flex>
26
+ </h3>
27
+ <table>
28
+ <tbody>
29
+ <tr>
30
+ <th>Spinners</th>
31
+ <td>
32
+ <Flex
33
+ gap="l" :style="{
34
+ 'animation-play-state': 'paused',
35
+ }"
36
+ >
37
+ <Spinner
38
+ v-for="size in variants" :key="size" :size :style="{
39
+ 'animation-play-state': paused ? 'paused' : 'running',
40
+ }"
41
+ />
42
+ </Flex>
43
+ </td>
44
+ </tr>
45
+ <tr>
46
+ <th>Progress bar</th>
47
+ <td class="w-80">
48
+ <Flex gap="s" y-center>
49
+ <Button square icon="ph:minus" size="s" @click="progress -= 5" />
50
+ <Progress v-model="progress" class="w-full" />
51
+ <Button square icon="ph:plus" size="s" @click="progress += 5" />
52
+ </Flex>
53
+ </td>
54
+ </tr>
55
+ <tr>
56
+ <th>Progress bar tall</th>
57
+ <td class="w-80">
58
+ <Flex gap="s" y-center>
59
+ <Progress v-model="progress" :height="8" class="w-full" />
60
+ </Flex>
61
+ </td>
62
+ </tr>
63
+ <tr>
64
+ <th>Fake</th>
65
+ <td>
66
+ <Progress v-model="fakeProgress" :fake="!paused" />
67
+ </td>
68
+ </tr>
69
+ <tr>
70
+ <th>Fixed</th>
71
+ <td>
72
+ <Checkbox v-model="showFixed" label="Show fixed progress bar (look up)" />
73
+
74
+ <Progress v-if="showFixed" v-model="fakeProgress" :fake="!paused" fixed />
75
+ </td>
76
+ </tr>
77
+ </tbody>
78
+ </table>
79
+ </div>
80
+ </template>
@@ -1,195 +1,195 @@
1
- <script setup lang="ts">
2
- import { computed, onBeforeMount, ref } from 'vue'
3
- import Accordion from '../components/Accordion/Accordion.vue'
4
- import Divider from '../components/Divider/Divider.vue'
5
- import { paginate } from '../components/Pagination/pagination'
6
- import Pagination from '../components/Pagination/Pagination.vue'
7
- import * as Table from '../components/Table/index'
8
- import { defineTable } from '../components/Table/table'
9
-
10
- interface Item {
11
- 'ID Nation': string
12
- 'ID Year': number
13
- 'Nation': string
14
- 'Population': number
15
- 'Slug Nation': string
16
- 'Year': string
17
- }
18
-
19
- interface StrippedItem {
20
- Nation: string
21
- Population: number
22
- Year: string
23
- }
24
-
25
- const data = ref<StrippedItem[]>([])
26
-
27
- onBeforeMount(async () => {
28
- data.value = await fetch('https://datausa.io/api/data?drilldowns=Nation&measures=Population')
29
- .then(response => response.json())
30
- .then(({ data }: { data: Item[] }) => {
31
- return data.map(row => ({
32
- Nation: row.Nation,
33
- Population: row.Population,
34
- Year: row.Year,
35
- }))
36
- })
37
- })
38
-
39
- const {
40
- rows,
41
- headers,
42
- pagination,
43
- allRows,
44
- setPage,
45
- selectedRows,
46
- } = defineTable(data, {
47
- pagination: {
48
- enabled: true,
49
- perPage: 3,
50
- },
51
- select: true,
52
- })
53
-
54
- // Example
55
- //
56
- const testData = ['Jan', 'Andrew', 'Kasper', 'Anton', 'Felix', 'Daniel', 'Gabriel', 'Ayalga', 'Floris']
57
- const page = ref(1)
58
- const paginationExample = computed(() => paginate(testData.length, page.value, 2))
59
- const exampleToRender = computed(() => testData.slice(paginationExample.value.startIndex, paginationExample.value.endIndex + 1))
60
- </script>
61
-
62
- <template>
63
- <div class="mb-xxl">
64
- <h3 class="mb-l">
65
- Tables
66
- </h3>
67
-
68
- <p class="mb-l">
69
- This library has two way to define tables. By default, you can use the classic <code>table</code> element and compose simple tables. <br> Or you can go overkill with the <code>{{ `<Table />` }}</code> component, which comes with its own composable function
70
- </p>
71
-
72
- <strong class="mb-s block">Simple vertical table</strong>
73
-
74
- <table class="mb-l">
75
- <thead>
76
- <tr>
77
- <th>One</th>
78
- <th>Two</th>
79
- <th>Three</th>
80
- </tr>
81
- </thead>
82
- <tbody>
83
- <tr>
84
- <td>First </td>
85
- <td>Second</td>
86
- <td>Third</td>
87
- </tr>
88
- </tbody>
89
- </table>
90
-
91
- <strong class="mb-s block">Simple horizontal table</strong>
92
-
93
- <table class="mb-xxl">
94
- <tbody>
95
- <tr>
96
- <th>One</th>
97
- <td>First</td>
98
- </tr>
99
- <tr>
100
- <th>Two</th>
101
- <td>Second</td>
102
- </tr>
103
- <tr>
104
- <th>Three</th>
105
- <td>Third</td>
106
- </tr>
107
- </tbody>
108
- </table>
109
-
110
- <h5 class="mb-s">
111
- Data table
112
- </h5>
113
-
114
- <p class="mb-s">
115
- This example demonstrates the full capability of the table component. Including column sorting, pagination and row selection.
116
- </p>
117
-
118
- <Table.Root separate-cells class="mb-l">
119
- <template #header>
120
- <Table.SelectAll />
121
- <Table.Head v-for="header in headers" :key="header.label" :header sort />
122
- </template>
123
- <template #body>
124
- <tr v-for="row in rows" :key="row.Year">
125
- <Table.SelectRow :row />
126
- <Table.Cell>{{ row.Nation }}</Table.Cell>
127
- <Table.Cell>{{ row.Population }}</Table.Cell>
128
- <Table.Cell>{{ row.Year }}</Table.Cell>
129
- </tr>
130
- </template>
131
- <template #pagination>
132
- <Pagination :pagination :first-last="false" @change="setPage" />
133
- </template>
134
- </Table.Root>
135
-
136
- <Accordion :label="`Selected rows (${selectedRows.size})`" class="mb-xl">
137
- <pre>
138
- {{ selectedRows }}
139
- </pre>
140
- </Accordion>
141
-
142
- <h5 class="mb-s">
143
- Variations
144
- </h5>
145
-
146
- <div class="typeset mb-xl">
147
- <ul>
148
- <li><p><code>separate-rows</code> Adds a border between rows (default: <code>true</code>)</p></li>
149
- <li><p><code>separate-cells</code> Adds a border between cells (default: <code>false</code>)</p></li>
150
- <li><p><code>outer-border</code> Adds a border around the entire table component (default: <code>true</code>)</p></li>
151
- <li><p><code>nowrap</code> Adds ellipsis to text which overflows to keep row size consistent (default: <code>false</code>)</p></li>
152
- <li><p><code>fixed</code> Keeps all the columns the same size (default: <code>false</code>)</p></li>
153
- </ul>
154
- </div>
155
-
156
- <div class="container container-s mb-xxl ml-0">
157
- <Table.Root :outer-border="false" :separate-cells="true" nowrap fixed>
158
- <template #body>
159
- <tr v-for="row in allRows" :key="row.Year">
160
- <Table.Cell>{{ `${row.Nation} ${row.Nation}` }}</Table.Cell>
161
- <Table.Cell>{{ row.Population }}</Table.Cell>
162
- <Table.Cell>{{ row.Year }}</Table.Cell>
163
- </tr>
164
- </template>
165
- </Table.Root>
166
- </div>
167
-
168
- <h5 class="mb-s">
169
- Pagination
170
- </h5>
171
-
172
- <p class="mb-m">
173
- Pagination does not need to be used with table only. The calculation of pages is done via an external function and the pagination component accepts all the necesary props to implement it for any kind of dataset and UI
174
- </p>
175
-
176
- <p class="mb-m">
177
- Here we have a list of names and we're gonna paginate through them:<br><br> {{ testData.join(', ') }}
178
- </p>
179
- <Pagination :pagination="paginationExample" @change="(num) => page = num" />
180
- <div class="typeset">
181
- <ul>
182
- <li
183
- v-for="name in exampleToRender"
184
- :key="name"
185
- >
186
- {{ name }}
187
- </li>
188
- </ul>
189
- </div>
190
-
191
- <Divider :size="40" class="w-40" />
192
-
193
- <p>The <code>defineTable</code> hook can also be used with other UI components. Not just tables. That's why all the table interactivity is not within the component, but in a hook. It's very flexible and allows custom functionality.</p>
194
- </div>
195
- </template>
1
+ <script setup lang="ts">
2
+ import { computed, onBeforeMount, ref } from 'vue'
3
+ import Accordion from '../components/Accordion/Accordion.vue'
4
+ import Divider from '../components/Divider/Divider.vue'
5
+ import { paginate } from '../components/Pagination/pagination'
6
+ import Pagination from '../components/Pagination/Pagination.vue'
7
+ import * as Table from '../components/Table/index'
8
+ import { defineTable } from '../components/Table/table'
9
+
10
+ interface Item {
11
+ 'ID Nation': string
12
+ 'ID Year': number
13
+ 'Nation': string
14
+ 'Population': number
15
+ 'Slug Nation': string
16
+ 'Year': string
17
+ }
18
+
19
+ interface StrippedItem {
20
+ Nation: string
21
+ Population: number
22
+ Year: string
23
+ }
24
+
25
+ const data = ref<StrippedItem[]>([])
26
+
27
+ onBeforeMount(async () => {
28
+ data.value = await fetch('https://datausa.io/api/data?drilldowns=Nation&measures=Population')
29
+ .then(response => response.json())
30
+ .then(({ data }: { data: Item[] }) => {
31
+ return data.map(row => ({
32
+ Nation: row.Nation,
33
+ Population: row.Population,
34
+ Year: row.Year,
35
+ }))
36
+ })
37
+ })
38
+
39
+ const {
40
+ rows,
41
+ headers,
42
+ pagination,
43
+ allRows,
44
+ setPage,
45
+ selectedRows,
46
+ } = defineTable(data, {
47
+ pagination: {
48
+ enabled: true,
49
+ perPage: 3,
50
+ },
51
+ select: true,
52
+ })
53
+
54
+ // Example
55
+ //
56
+ const testData = ['Jan', 'Andrew', 'Kasper', 'Anton', 'Felix', 'Daniel', 'Gabriel', 'Ayalga', 'Floris']
57
+ const page = ref(1)
58
+ const paginationExample = computed(() => paginate(testData.length, page.value, 2))
59
+ const exampleToRender = computed(() => testData.slice(paginationExample.value.startIndex, paginationExample.value.endIndex + 1))
60
+ </script>
61
+
62
+ <template>
63
+ <div class="mb-xxl">
64
+ <h3 class="mb-l">
65
+ Tables
66
+ </h3>
67
+
68
+ <p class="mb-l">
69
+ This library has two way to define tables. By default, you can use the classic <code>table</code> element and compose simple tables. <br> Or you can go overkill with the <code>{{ `<Table />` }}</code> component, which comes with its own composable function
70
+ </p>
71
+
72
+ <strong class="mb-s block">Simple vertical table</strong>
73
+
74
+ <table class="mb-l">
75
+ <thead>
76
+ <tr>
77
+ <th>One</th>
78
+ <th>Two</th>
79
+ <th>Three</th>
80
+ </tr>
81
+ </thead>
82
+ <tbody>
83
+ <tr>
84
+ <td>First </td>
85
+ <td>Second</td>
86
+ <td>Third</td>
87
+ </tr>
88
+ </tbody>
89
+ </table>
90
+
91
+ <strong class="mb-s block">Simple horizontal table</strong>
92
+
93
+ <table class="mb-xxl">
94
+ <tbody>
95
+ <tr>
96
+ <th>One</th>
97
+ <td>First</td>
98
+ </tr>
99
+ <tr>
100
+ <th>Two</th>
101
+ <td>Second</td>
102
+ </tr>
103
+ <tr>
104
+ <th>Three</th>
105
+ <td>Third</td>
106
+ </tr>
107
+ </tbody>
108
+ </table>
109
+
110
+ <h5 class="mb-s">
111
+ Data table
112
+ </h5>
113
+
114
+ <p class="mb-s">
115
+ This example demonstrates the full capability of the table component. Including column sorting, pagination and row selection.
116
+ </p>
117
+
118
+ <Table.Root separate-cells class="mb-l">
119
+ <template #header>
120
+ <Table.SelectAll />
121
+ <Table.Head v-for="header in headers" :key="header.label" :header sort />
122
+ </template>
123
+ <template #body>
124
+ <tr v-for="row in rows" :key="row.Year">
125
+ <Table.SelectRow :row />
126
+ <Table.Cell>{{ row.Nation }}</Table.Cell>
127
+ <Table.Cell>{{ row.Population }}</Table.Cell>
128
+ <Table.Cell>{{ row.Year }}</Table.Cell>
129
+ </tr>
130
+ </template>
131
+ <template #pagination>
132
+ <Pagination :pagination :first-last="false" @change="setPage" />
133
+ </template>
134
+ </Table.Root>
135
+
136
+ <Accordion :label="`Selected rows (${selectedRows.size})`" class="mb-xl">
137
+ <pre>
138
+ {{ selectedRows }}
139
+ </pre>
140
+ </Accordion>
141
+
142
+ <h5 class="mb-s">
143
+ Variations
144
+ </h5>
145
+
146
+ <div class="typeset mb-xl">
147
+ <ul>
148
+ <li><p><code>separate-rows</code> Adds a border between rows (default: <code>true</code>)</p></li>
149
+ <li><p><code>separate-cells</code> Adds a border between cells (default: <code>false</code>)</p></li>
150
+ <li><p><code>outer-border</code> Adds a border around the entire table component (default: <code>true</code>)</p></li>
151
+ <li><p><code>nowrap</code> Adds ellipsis to text which overflows to keep row size consistent (default: <code>false</code>)</p></li>
152
+ <li><p><code>fixed</code> Keeps all the columns the same size (default: <code>false</code>)</p></li>
153
+ </ul>
154
+ </div>
155
+
156
+ <div class="container container-s mb-xxl ml-0">
157
+ <Table.Root :outer-border="false" :separate-cells="true" nowrap fixed>
158
+ <template #body>
159
+ <tr v-for="row in allRows" :key="row.Year">
160
+ <Table.Cell>{{ `${row.Nation} ${row.Nation}` }}</Table.Cell>
161
+ <Table.Cell>{{ row.Population }}</Table.Cell>
162
+ <Table.Cell>{{ row.Year }}</Table.Cell>
163
+ </tr>
164
+ </template>
165
+ </Table.Root>
166
+ </div>
167
+
168
+ <h5 class="mb-s">
169
+ Pagination
170
+ </h5>
171
+
172
+ <p class="mb-m">
173
+ Pagination does not need to be used with table only. The calculation of pages is done via an external function and the pagination component accepts all the necesary props to implement it for any kind of dataset and UI
174
+ </p>
175
+
176
+ <p class="mb-m">
177
+ Here we have a list of names and we're gonna paginate through them:<br><br> {{ testData.join(', ') }}
178
+ </p>
179
+ <Pagination :pagination="paginationExample" @change="(num) => page = num" />
180
+ <div class="typeset">
181
+ <ul>
182
+ <li
183
+ v-for="name in exampleToRender"
184
+ :key="name"
185
+ >
186
+ {{ name }}
187
+ </li>
188
+ </ul>
189
+ </div>
190
+
191
+ <Divider :size="40" class="w-40" />
192
+
193
+ <p>The <code>defineTable</code> hook can also be used with other UI components. Not just tables. That's why all the table interactivity is not within the component, but in a hook. It's very flexible and allows custom functionality.</p>
194
+ </div>
195
+ </template>