|
1 | | -<script lang="ts"> |
2 | | -import { defineComponent } from "vue"; |
3 | | -import { FTextField } from "@fkui/vue"; |
| 1 | +<script setup lang="ts"> |
| 2 | +import { type Ref, computed, ref, useTemplateRef } from "vue"; |
| 3 | +import { type ContextMenuItem, FContextMenu, FDatepickerField } from "@fkui/vue"; |
| 4 | +import { FTable, defineTableColumns } from "@fkui/vue-labs"; |
4 | 5 |
|
5 | | -export default defineComponent({ |
6 | | - components: { FTextField }, |
7 | | - data() { |
8 | | - return { |
9 | | - awesomeModel: "", |
10 | | - }; |
| 6 | +interface Row { |
| 7 | + id: string; |
| 8 | + text1: string; |
| 9 | + text2: string; |
| 10 | + text3: string; |
| 11 | +} |
| 12 | +
|
| 13 | +const columns = defineTableColumns<Row>([ |
| 14 | + { |
| 15 | + type: "text", |
| 16 | + header: "ID", |
| 17 | + key: "id", |
| 18 | + }, |
| 19 | + { |
| 20 | + type: "text", |
| 21 | + header: "Text 1", |
| 22 | + key: "text1", |
| 23 | + }, |
| 24 | + { |
| 25 | + header: "Åtgärd", |
| 26 | + type: "menu", |
| 27 | + text(row) { |
| 28 | + return `Visa åtgärder för rad "${row.id}"`; |
| 29 | + }, |
| 30 | + actions: [ |
| 31 | + { |
| 32 | + label: "Visa", |
| 33 | + icon: "search", |
| 34 | + onClick(row) { |
| 35 | + window.alert(`Visa detaljer för rad "${row.id}"`); |
| 36 | + }, |
| 37 | + }, |
| 38 | + { |
| 39 | + label: "Redigera", |
| 40 | + icon: "pen", |
| 41 | + onClick(row) { |
| 42 | + window.alert(`Redigera rad "${row.id}"`); |
| 43 | + }, |
| 44 | + }, |
| 45 | + { |
| 46 | + label: "Ta bort", |
| 47 | + icon: "trashcan", |
| 48 | + onClick(row) { |
| 49 | + window.alert(`Ta bort rad "${row.id}"`); |
| 50 | + }, |
| 51 | + }, |
| 52 | + ], |
| 53 | + }, |
| 54 | + { |
| 55 | + type: "text", |
| 56 | + header: "Text 2", |
| 57 | + key: "text2", |
| 58 | + }, |
| 59 | + { |
| 60 | + type: "text", |
| 61 | + header: "Text 3", |
| 62 | + key: "text3", |
11 | 63 | }, |
| 64 | +]); |
| 65 | +
|
| 66 | +const rows = [ |
| 67 | + { |
| 68 | + id: "1", |
| 69 | + text1: "Text 1", |
| 70 | + text2: "Text 2", |
| 71 | + text3: "Text 3", |
| 72 | + }, |
| 73 | + { |
| 74 | + id: "2", |
| 75 | + text1: "Text 4", |
| 76 | + text2: "Text 5", |
| 77 | + text3: "Text 6", |
| 78 | + }, |
| 79 | + { |
| 80 | + id: "3", |
| 81 | + text1: "Text 7", |
| 82 | + text2: "Text 8", |
| 83 | + text3: "Text 9", |
| 84 | + }, |
| 85 | +]; |
| 86 | +
|
| 87 | +const items: Ref<ContextMenuItem[]> = ref([ |
| 88 | + { label: "Påminnelse", key: "MENU_2", icon: "bell" }, |
| 89 | + { label: "Ändra", key: "MENU_3", icon: "pen" }, |
| 90 | + { separator: true }, |
| 91 | + { label: "Ta bort", key: "MENU_4", icon: "trashcan" }, |
| 92 | + { label: "Utan ikon", key: "MENU_5" }, |
| 93 | +]); |
| 94 | +const selected = ref(""); |
| 95 | +const isOpen = ref(false); |
| 96 | +
|
| 97 | +const anch = useTemplateRef("popupAnchor"); |
| 98 | +
|
| 99 | +const anchor = computed(() => { |
| 100 | + return anch.value as HTMLElement; |
12 | 101 | }); |
| 102 | +
|
| 103 | +function onClose(): void { |
| 104 | + isOpen.value = false; |
| 105 | +} |
| 106 | +function onClick(): void { |
| 107 | + isOpen.value = !isOpen.value; |
| 108 | +} |
| 109 | +function onSelect(value: string): void { |
| 110 | + selected.value = value; |
| 111 | +} |
13 | 112 | </script> |
14 | 113 |
|
15 | 114 | <template> |
16 | | - <div class="sandbox-root"> |
17 | | - <h1>FKUI Sandbox</h1> |
18 | | - <p> |
19 | | - Ett internt paket som innehåller en avskalad Vue-applikation. Applikationen är konsument av övriga |
20 | | - FKUI-paket och innehåller enbart ett tomt exempel. |
21 | | - </p> |
22 | | - <p> |
23 | | - <strong>Ändra och labba gärna här men glöm inte återställa innan merge!</strong> |
24 | | - </p> |
25 | | - <hr /> |
26 | | - <f-text-field |
27 | | - id="awesome-field" |
28 | | - v-model="awesomeModel" |
29 | | - v-validation.required.maxLength="{ maxLength: { length: 10 } }" |
30 | | - > |
31 | | - <template #default> Inmatningsfält. </template> |
32 | | - <template #description="{ descriptionClass }"> |
33 | | - <span :class="descriptionClass"> Lorem ipsum dolor sit amet. </span> |
34 | | - </template> |
35 | | - </f-text-field> |
| 115 | + <div class="sandbox-container"> |
| 116 | + <div class="space-box"></div> |
| 117 | + <div class="table-container"> |
| 118 | + <div class="table-container-inner"> |
| 119 | + <h2>FTable</h2> |
| 120 | + <f-table ref="table" :rows :columns striped></f-table> |
| 121 | + </div> |
| 122 | + </div> |
| 123 | + <div class="menu-container"> |
| 124 | + <h2>FContextMenu</h2> |
| 125 | + <button |
| 126 | + ref="popupAnchor" |
| 127 | + data-test="open-example-contextmenu-button" |
| 128 | + type="button" |
| 129 | + class="button button--primary" |
| 130 | + aria-haspopup="menu" |
| 131 | + @click="onClick" |
| 132 | + > |
| 133 | + Öppna |
| 134 | + </button> |
| 135 | + <pre>Selected: {{ selected }}</pre> |
| 136 | + <f-context-menu |
| 137 | + data-test="contextmenu-open" |
| 138 | + :is-open |
| 139 | + :items |
| 140 | + :anchor |
| 141 | + @close="onClose" |
| 142 | + @select="onSelect" |
| 143 | + ></f-context-menu> |
| 144 | + <h2>FDatepickerField</h2> |
| 145 | + <f-datepicker-field></f-datepicker-field> |
| 146 | + </div> |
| 147 | + <div class="space-box"></div> |
36 | 148 | </div> |
37 | 149 | </template> |
38 | 150 |
|
39 | 151 | <style> |
40 | | -.sandbox-root { |
41 | | - width: min(100% - 2rem, 80ch); |
42 | | - margin: auto; |
| 152 | +.sandbox-container { |
| 153 | + min-height: 200vh; |
| 154 | + min-width: 200vw; |
| 155 | +} |
| 156 | +
|
| 157 | +.menu-container { |
| 158 | + margin-left: 600px; |
| 159 | + width: 400px; |
| 160 | +} |
| 161 | +
|
| 162 | +.table-container { |
| 163 | + margin-left: 600px; |
| 164 | + width: 800px; |
| 165 | + overflow: scroll; |
43 | 166 | } |
44 | 167 |
|
45 | | -h1 { |
46 | | - margin-top: 2rem; |
| 168 | +.table-container-inner { |
| 169 | + width: 1200px; |
47 | 170 | } |
48 | 171 |
|
49 | | -hr { |
50 | | - margin-bottom: 2rem; |
| 172 | +.space-box { |
| 173 | + height: 400px; |
51 | 174 | } |
52 | 175 | </style> |
0 commit comments