sprintify-ui 0.7.11 → 0.8.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 (44) hide show
  1. package/dist/sprintify-ui.es.js +10481 -10348
  2. package/dist/style.css +1 -1
  3. package/dist/types/components/BaseDataIterator.vue.d.ts +50 -4
  4. package/dist/types/components/BaseDataIteratorSectionColumns.vue.d.ts +156 -68
  5. package/dist/types/components/BaseDataTable.vue.d.ts +86 -6
  6. package/dist/types/components/BaseDataTableTemplate.vue.d.ts +44 -28
  7. package/dist/types/components/BaseTable.vue.d.ts +30 -7
  8. package/dist/types/components/BaseTableCell.vue.d.ts +19 -1
  9. package/dist/types/components/BaseTableColumn.vue.d.ts +50 -3
  10. package/dist/types/components/BaseTableHead.vue.d.ts +6 -5
  11. package/dist/types/components/BaseTableHeader.vue.d.ts +12 -2
  12. package/dist/types/components/BaseTableRow.vue.d.ts +5 -0
  13. package/dist/types/composables/isFirstColumn.d.ts +4 -0
  14. package/dist/types/composables/isLastColumn.d.ts +4 -0
  15. package/dist/types/composables/paginatedData.d.ts +5 -5
  16. package/dist/types/services/table/types.d.ts +6 -5
  17. package/dist/types/types/index.d.ts +7 -2
  18. package/dist/types/utils/getApiData.d.ts +1 -1
  19. package/package.json +2 -1
  20. package/src/assets/main.css +0 -1
  21. package/src/components/BaseAvatar.vue +1 -0
  22. package/src/components/BaseDataIterator.stories.js +96 -1
  23. package/src/components/BaseDataIterator.vue +135 -11
  24. package/src/components/BaseDataIteratorSectionColumns.vue +2 -2
  25. package/src/components/BaseDataTable.stories.js +140 -50
  26. package/src/components/BaseDataTable.vue +82 -48
  27. package/src/components/BaseDataTableTemplate.vue +207 -372
  28. package/src/components/BaseTable.stories.js +57 -15
  29. package/src/components/BaseTable.vue +71 -9
  30. package/src/components/BaseTableBody.vue +1 -1
  31. package/src/components/BaseTableCell.vue +94 -36
  32. package/src/components/BaseTableColumn.vue +25 -2
  33. package/src/components/BaseTableHead.vue +17 -5
  34. package/src/components/BaseTableHeader.vue +39 -10
  35. package/src/components/BaseTableRow.vue +27 -6
  36. package/src/composables/isFirstColumn.ts +31 -0
  37. package/src/composables/isLastColumn.ts +31 -0
  38. package/src/composables/paginatedData.ts +22 -10
  39. package/src/services/table/classes.ts +13 -9
  40. package/src/services/table/types.ts +6 -5
  41. package/src/stories/List.stories.js +5 -1
  42. package/src/types/index.ts +7 -2
  43. package/src/utils/getApiData.ts +1 -1
  44. package/src/assets/base-table.css +0 -17
@@ -1,9 +1,8 @@
1
1
  <template>
2
2
  <tr
3
3
  :class="classes"
4
- @click="emit('click')"
5
- @mouseenter="emit('mouseenter')"
6
- @mouseleave="emit('mouseleave')"
4
+ @mouseenter="onMouseEnter"
5
+ @mouseleave="onMouseLeave"
7
6
  >
8
7
  <slot />
9
8
  </tr>
@@ -17,7 +16,7 @@ defineOptions({
17
16
  inheritAttrs: false,
18
17
  });
19
18
 
20
- const baseTable = inject('BaseTable');
19
+ const baseTable = inject('table:props');
21
20
 
22
21
  if (!baseTable) {
23
22
  throw new Error('baseTable must be used within a BaseTable.');
@@ -31,16 +30,16 @@ const props = withDefaults(defineProps<{
31
30
  target?: '_blank' | '_self' | '_parent' | '_top',
32
31
  title?: string,
33
32
  class?: ClassNameValue,
33
+ onClick?: (e: MouseEvent) => void,
34
34
  }>(), {
35
35
  href: undefined,
36
36
  to: undefined,
37
37
  target: undefined,
38
38
  title: undefined,
39
39
  class: undefined,
40
+ onClick: undefined,
40
41
  });
41
42
 
42
- provide('BaseTableRow', computed(() => props));
43
-
44
43
  const classes = computed(() => {
45
44
  const base = 'group/row';
46
45
 
@@ -50,4 +49,26 @@ const classes = computed(() => {
50
49
  );
51
50
  });
52
51
 
52
+ const hover = ref(false);
53
+ const hoverForFullRow = ref(false);
54
+
55
+ function setHoverForFullRow(active: boolean) {
56
+ hoverForFullRow.value = active;
57
+ }
58
+
59
+ function onMouseEnter() {
60
+ emit('mouseenter');
61
+ hover.value = true;
62
+ }
63
+
64
+ function onMouseLeave() {
65
+ emit('mouseleave');
66
+ hover.value = false;
67
+ }
68
+
69
+ provide('tableRow:props', computed(() => props));
70
+ provide('tableRow:hover', computed(() => hover.value));
71
+ provide('tableRow:setHoverForFullRow', setHoverForFullRow);
72
+ provide('tableRow:hoverForFullRow', computed(() => hoverForFullRow.value));
73
+
53
74
  </script>
@@ -0,0 +1,31 @@
1
+ import { MaybeRef } from "vue";
2
+
3
+ export function useIsFirstColumn(tdOrTh: MaybeRef<HTMLTableCellElement | null>) {
4
+
5
+ const leftCol = ref<HTMLTableCellElement | null>();
6
+
7
+ onMounted(() => {
8
+ leftCol.value = unref(tdOrTh)?.previousElementSibling as HTMLTableCellElement | null;
9
+ });
10
+
11
+ const isFirstColumn = computed(() => {
12
+
13
+ if (!leftCol.value) {
14
+ return true;
15
+ }
16
+
17
+ if (leftCol.value.tagName.toLowerCase() === 'th') {
18
+ return false;
19
+ }
20
+
21
+ if (leftCol.value.tagName.toLowerCase() === 'td') {
22
+ return false;
23
+ }
24
+
25
+ return true;
26
+ });
27
+
28
+ return {
29
+ isFirstColumn,
30
+ };
31
+ }
@@ -0,0 +1,31 @@
1
+ import { MaybeRef } from "vue";
2
+
3
+ export function useIsLastColumn(tdOrTh: MaybeRef<HTMLTableCellElement | null>) {
4
+
5
+ const rightCol = ref<HTMLTableCellElement | null>();
6
+
7
+ onMounted(() => {
8
+ rightCol.value = unref(tdOrTh)?.nextElementSibling as HTMLTableCellElement | null;
9
+ });
10
+
11
+ const isLastColumn = computed(() => {
12
+
13
+ if (!rightCol.value) {
14
+ return true;
15
+ }
16
+
17
+ if (rightCol.value.tagName.toLowerCase() === 'th') {
18
+ return false;
19
+ }
20
+
21
+ if (rightCol.value.tagName.toLowerCase() === 'td') {
22
+ return false;
23
+ }
24
+
25
+ return true;
26
+ });
27
+
28
+ return {
29
+ isLastColumn,
30
+ };
31
+ }
@@ -1,4 +1,4 @@
1
- import { Ref } from 'vue';
1
+ import { ComputedRef, Ref } from 'vue';
2
2
  import {
3
3
  Collection,
4
4
  PaginatedCollection,
@@ -9,26 +9,38 @@ import { isArray } from 'lodash';
9
9
  import { getItems } from '@/utils/getApiData';
10
10
 
11
11
  export function useHasPaginatedData(
12
- data: Ref<Collection | PaginatedCollection | ResourceCollection | null>
12
+ data: Ref<Collection | PaginatedCollection | ResourceCollection | null | undefined>,
13
+ page?: ComputedRef<number>,
14
+ perPage?: ComputedRef<number>,
13
15
  ) {
14
16
  const items = computed(() => {
15
17
  return getItems(data.value);
16
18
  });
17
19
 
18
20
  const paginationMetadata = computed<PaginationMetadata | null>(() => {
19
- const defaultMeta = {
20
- current_page: 1,
21
- last_page: 1,
22
- per_page: 1,
23
- total: 0,
24
- };
25
21
 
26
22
  if (!data.value) {
27
- return defaultMeta;
23
+ return null;
28
24
  }
25
+
29
26
  if (isArray(data.value)) {
30
- return defaultMeta;
27
+
28
+ const perPageUnref = unref(perPage);
29
+ const pageUnref = unref(page);
30
+
31
+ const total = data.value.length;
32
+ const perPageArr = perPageUnref ? perPageUnref : total;
33
+ const pageArr = pageUnref ? pageUnref : 1;
34
+ const lastPage = Math.ceil(total / perPageArr);
35
+
36
+ return {
37
+ current_page: pageArr,
38
+ last_page: lastPage,
39
+ per_page: perPageArr,
40
+ total: total,
41
+ };
31
42
  }
43
+
32
44
  if ('meta' in data.value) {
33
45
  return data.value.meta;
34
46
  }
@@ -1,24 +1,28 @@
1
1
  import { twMerge } from "tailwind-merge";
2
- import { CellConfig, CellSpacing } from "./types";
2
+ import { CellConfig, CellSize } from "./types";
3
3
 
4
4
  export function cellClasses(config: CellConfig): string {
5
- const base = 'block';
6
- const space = spacing(config.spacing ?? 'md');
7
- const flush = config.flush ? 'px-0' : '';
5
+ const base = '';
6
+ const space = size(config.size ?? 'md');
8
7
 
9
- return twMerge([base, space, flush]);
8
+ return twMerge([base, space]);
10
9
  }
11
10
 
12
- function spacing(spacing: CellSpacing): string {
13
- if (spacing == 'sm') {
11
+ function size(size: CellSize): string {
12
+
13
+ if (size == 'xs') {
14
14
  return 'px-1 py-0.5';
15
15
  }
16
16
 
17
- if (spacing == 'md') {
17
+ if (size == 'sm') {
18
+ return 'px-2 py-1';
19
+ }
20
+
21
+ if (size == 'md') {
18
22
  return 'px-2 py-2';
19
23
  }
20
24
 
21
- if (spacing == 'lg') {
25
+ if (size == 'lg') {
22
26
  return 'px-4 py-3';
23
27
  }
24
28
 
@@ -1,19 +1,20 @@
1
1
  import { RouteLocationRaw } from "vue-router";
2
2
 
3
- export type CellSpacing = 'none' | 'sm' | 'md' | 'lg';
3
+ export type CellSize = 'none' | 'xs' | 'sm' | 'md' | 'lg';
4
4
 
5
5
  export interface TableProps {
6
- spacing?: CellSpacing;
6
+ size?: CellSize;
7
7
  flush?: boolean;
8
+ fixedHeader?: boolean;
9
+ fixedColumn?: boolean;
8
10
  }
9
11
 
10
- export type CellConfig = {
11
- flush?: boolean;
12
- } & TableProps;
12
+ export type CellConfig = TableProps;
13
13
 
14
14
  export interface CellProps {
15
15
  title?: string;
16
16
  href?: string;
17
17
  to?: RouteLocationRaw;
18
18
  target?: string;
19
+ onClick?: (e: MouseEvent) => void;
19
20
  }
@@ -125,7 +125,11 @@ const Template = (args) => ({
125
125
  alert('Cell click: ' + row.id);
126
126
  }
127
127
 
128
- return { args, onCellClick, DateTime };
128
+ function onRowClick(row) {
129
+ alert('Row click: ' + row.id);
130
+ }
131
+
132
+ return { args, onCellClick, onRowClick, DateTime };
129
133
  },
130
134
  });
131
135
 
@@ -103,15 +103,20 @@ export interface BaseTableColumnData {
103
103
  field: string;
104
104
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
105
105
  meta: undefined | Record<string, any>;
106
- newKey: number;
106
+ newKey: string;
107
107
  numeric: boolean;
108
108
  position: 'left' | 'right';
109
109
  searchable: boolean;
110
110
  sortable: boolean;
111
- clickable: boolean;
111
+ ignoreRowInteractions: boolean;
112
112
  toggle: boolean;
113
113
  toggleDefault: boolean;
114
114
  width: number;
115
+ class?: string | string[];
116
+ to?: (row: Row) => RouteLocationRaw;
117
+ href?: (row: Row) => string;
118
+ target?: '_blank' | '_self' | '_parent' | '_top';
119
+ onClick?: (row: Row, index: number, column: BaseTableColumnData, colIndex: number, event: MouseEvent) => void;
115
120
  style: {
116
121
  width: undefined | number;
117
122
  };
@@ -1,7 +1,7 @@
1
1
  import { Collection, PaginatedCollection, ResourceCollection } from "@/types";
2
2
  import { isArray } from "lodash";
3
3
 
4
- export function getItems(data: Collection | PaginatedCollection | ResourceCollection | null) {
4
+ export function getItems(data: Collection | PaginatedCollection | ResourceCollection | null | undefined) {
5
5
  if (!data) {
6
6
  return [];
7
7
  }
@@ -1,17 +0,0 @@
1
- .base-table {
2
- .th {
3
- @apply relative z-[2];
4
- @apply bg-slate-50;
5
- @apply border-b border-slate-300;
6
- }
7
-
8
- .base-table--has-max-height .th {
9
- @apply sticky;
10
- @apply top-0;
11
- @apply bg-opacity-75 backdrop-blur backdrop-filter;
12
- }
13
-
14
- tbody tr.item-row:hover td {
15
- @apply bg-slate-50;
16
- }
17
- }