picocrank 1.1.1 → 1.1.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "picocrank",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "A set of zero dependency Vue components built on the Femtocrank global CSS theme.",
5
5
  "main": "vite.config.js",
6
6
  "scripts": {
@@ -1,7 +1,12 @@
1
1
  <template>
2
2
  <section class = "with-header-and-content">
3
- <div class = "section-header">
4
- <h2>{{ title }}</h2>
3
+ <div class = "section-header flex-row">
4
+ <div class = "fg1">
5
+ <h2 :title = "subtitle">{{ title }}</h2>
6
+ </div>
7
+ <div role = "toolbar">
8
+ <slot name="toolbar" />
9
+ </div>
5
10
  </div>
6
11
  <div :class = "padding ? 'section-content padding' : 'section-content'">
7
12
  <slot />
@@ -20,5 +25,9 @@ const props = defineProps({
20
25
  type: Boolean,
21
26
  default: true,
22
27
  },
28
+ subtitle: {
29
+ type: String,
30
+ default: "",
31
+ },
23
32
  });
24
33
  </script>
@@ -4,9 +4,11 @@
4
4
  <th v-for="(header, index) in visibleHeaders" :key="index" @click="toggleSort(header)" :class="{ sortable: header.sortable }">
5
5
  {{ header.label }}
6
6
 
7
- <span v-if="header.sortable && sortBy === header.key">
8
- <span v-if="sortDir === 'asc'">▲</span>
9
- <span v-else>▼</span>
7
+ <span v-if="header.sortable" style:= "width: 1.5em; display: inline-block; text-align: center;">
8
+ <span v-if="sortBy === header.key">
9
+ <span v-if="sortDir === 'asc'">▲</span>
10
+ <span v-else-if="sortDir === 'desc'">▼</span>
11
+ </span>
10
12
  </span>
11
13
  </th>
12
14
  </thead>
@@ -42,7 +44,22 @@
42
44
  const page = ref(1);
43
45
  const pageSize = ref(10);
44
46
 
45
- const items = ref([])
47
+ const props = defineProps({
48
+ headers: {
49
+ type: Array,
50
+ default: () => ['id'],
51
+ },
52
+ data: {
53
+ type: Array,
54
+ default: () => [],
55
+ },
56
+ });
57
+
58
+ const items = computed(() => {
59
+ const arr = [...props.data];
60
+
61
+ return arr;
62
+ })
46
63
 
47
64
  const sortedItems = computed(() => {
48
65
  if (!sortBy.value) return [...items.value];
@@ -89,18 +106,9 @@
89
106
  }));
90
107
  });
91
108
 
92
- const props = defineProps({
93
- headers: {
94
- type: Array,
95
- default: () => ['id'],
96
- },
97
- data: {
98
- type: Array,
99
- default: () => [],
100
- },
101
- });
102
-
103
109
  function toggleSort(header) {
110
+ if (!header.sortable) return;
111
+
104
112
  if (sortBy.value === header.key) {
105
113
  sortDir.value = sortDir.value === 'asc' ? 'desc' : 'asc';
106
114
  } else {
@@ -110,14 +118,10 @@
110
118
 
111
119
  console.log(`Sorting by ${sortBy.value} in ${sortDir.value} order`);
112
120
  }
113
-
114
- onMounted(() => {
115
- items.value = props.data;
116
- })
117
121
  </script>
118
122
 
119
123
  <style scoped>
120
- table thead th:hover {
124
+ table thead th.sortable:hover {
121
125
  cursor: pointer;
122
126
  color: #0366d6;
123
127
  }
@@ -1,18 +1,27 @@
1
1
  <template>
2
- <Section title="Table Example" :padding = "false">
2
+ <Section
3
+ title="Table Example"
4
+ subtitle="A simple table with sortable columns and pagination"
5
+ :padding = "false"
6
+ >
7
+ <template #toolbar>
8
+ <button>Add Item</button>
9
+ </template>
10
+
3
11
  <Table
4
- :data = "data"
5
- :headers = "headers"
6
- />
12
+ :data = "data"
13
+ :headers = "headers"
14
+ >
15
+ </Table>
7
16
  </Section>
8
17
  </template>
9
18
 
10
19
  <script setup>
11
- import { ref } from 'vue'
20
+ import { ref, onMounted } from 'vue'
12
21
 
13
22
  const headers = ref([
14
23
  { key: "name", label: "Name", sortable: true, hidden: true, linkFunc: getLink },
15
- { key: "age", label: "Age", sortable: true, hidden: false, linkFunc: null },
24
+ { key: "age", label: "Age", sortable: false, hidden: false, linkFunc: null },
16
25
  { key: "city", label: "City", sortable: true, hidden: false, link: null },
17
26
  ])
18
27
 
@@ -24,26 +33,30 @@
24
33
  }
25
34
  }
26
35
 
27
- const data = [
28
- { name: "Alice", age: 30, city: "New York" },
29
- { name: "Bob", age: 25, city: "Los Angeles" },
30
- { name: "Charlie", age: 35, city: "Chicago" },
31
- { name: "David", age: 28, city: "Houston" },
32
- { name: "Eve", age: 22, city: "Phoenix" },
33
- { name: "Frank", age: 40, city: "Philadelphia" },
34
- { name: "Grace", age: 29, city: "San Antonio" },
35
- { name: "Hannah", age: 32, city: "San Diego" },
36
- { name: "Ian", age: 27, city: "Dallas" },
37
- { name: "Jack", age: 31, city: "San Jose" },
38
- { name: "Kathy", age: 26, city: "Austin" },
39
- { name: "Leo", age: 33, city: "Jacksonville" },
40
- { name: "Mia", age: 24, city: "Fort Worth" },
41
- { name: "Nina", age: 38, city: "Columbus" },
42
- { name: "Oscar", age: 36, city: "Charlotte" },
43
- { name: "Paul", age: 34, city: "San Francisco" },
44
- { name: "Quinn", age: 23, city: "Indianapolis" },
45
- { name: "Rita", age: 37, city: "Seattle" },
46
- { name: "Sam", age: 39, city: "Denver" },
47
- { name: "Tina", age: 21, city: "Washington D.C." }
48
- ]
36
+ const data = ref([])
37
+
38
+ onMounted(() => {
39
+ data.value = [
40
+ { name: "Alice", age: 30, city: "New York" },
41
+ { name: "Bob", age: 25, city: "Los Angeles" },
42
+ { name: "Charlie", age: 35, city: "Chicago" },
43
+ { name: "David", age: 28, city: "Houston" },
44
+ { name: "Eve", age: 22, city: "Phoenix" },
45
+ { name: "Frank", age: 40, city: "Philadelphia" },
46
+ { name: "Grace", age: 29, city: "San Antonio" },
47
+ { name: "Hannah", age: 32, city: "San Diego" },
48
+ { name: "Ian", age: 27, city: "Dallas" },
49
+ { name: "Jack", age: 31, city: "San Jose" },
50
+ { name: "Kathy", age: 26, city: "Austin" },
51
+ { name: "Leo", age: 33, city: "Jacksonville" },
52
+ { name: "Mia", age: 24, city: "Fort Worth" },
53
+ { name: "Nina", age: 38, city: "Columbus" },
54
+ { name: "Oscar", age: 36, city: "Charlotte" },
55
+ { name: "Paul", age: 34, city: "San Francisco" },
56
+ { name: "Quinn", age: 23, city: "Indianapolis" },
57
+ { name: "Rita", age: 37, city: "Seattle" },
58
+ { name: "Sam", age: 39, city: "Denver" },
59
+ { name: "Tina", age: 21, city: "Washington D.C." }
60
+ ]
61
+ })
49
62
  </script>