sprintify-ui 0.8.27 → 0.8.29

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.
@@ -1,5 +1,5 @@
1
- module.exports = function (theme) {
2
- return {
1
+ module.exports = function ({ addComponents, theme }) {
2
+ addComponents({
3
3
  // Button
4
4
  '.btn': {
5
5
  position: 'relative',
@@ -257,5 +257,5 @@ module.exports = function (theme) {
257
257
  '--tw-ring-color': theme('colors.slate.200'),
258
258
  },
259
259
  },
260
- }
260
+ });
261
261
  }
@@ -4,19 +4,18 @@ const theme = require('./theme');
4
4
  const button = require('./button');
5
5
  const overlay = require('./overlay');
6
6
  const input = require('./input');
7
+ const table = require('./table');
7
8
 
8
9
  const config = {
9
10
  theme: theme
10
11
  }
11
12
 
12
13
  module.exports = plugin(
13
- function ({ addComponents, theme }) {
14
- addComponents(
15
- Object.assign({},
16
- button(theme),
17
- overlay(theme),
18
- input(theme),
19
- ));
14
+ function (ctx) {
15
+ button(ctx);
16
+ overlay(ctx);
17
+ input(ctx);
18
+ table(ctx);
20
19
  },
21
20
  config
22
21
  );
@@ -1,11 +1,11 @@
1
1
  const { parseColor } = require("tailwindcss/lib/util/color");
2
2
 
3
- module.exports = function (theme) {
3
+ module.exports = function ({ addComponents, theme }) {
4
4
 
5
5
  const blueColor = parseColor(theme('colors.blue.600')).color.join(", ");
6
6
  const redColor = parseColor(theme('colors.red.600')).color.join(", ");
7
7
 
8
- return {
8
+ addComponents({
9
9
  '.input-focus': {
10
10
  'border-color': `rgba(${(blueColor)}, 0.6)`,
11
11
  'zIndex': 1,
@@ -19,5 +19,5 @@ module.exports = function (theme) {
19
19
  '.input-rounded': {
20
20
  'border-radius': theme('borderRadius.md'),
21
21
  }
22
- }
22
+ });
23
23
  }
@@ -1,5 +1,5 @@
1
- module.exports = function (theme) {
2
- return {
1
+ module.exports = function ({ addComponents }) {
2
+ addComponents({
3
3
  '.overlay': {
4
4
  position: 'absolute',
5
5
  top: 0,
@@ -9,5 +9,5 @@ module.exports = function (theme) {
9
9
  width: '100%',
10
10
  height: '100%',
11
11
  },
12
- }
12
+ });
13
13
  }
@@ -0,0 +1,92 @@
1
+ module.exports = function ({ addVariant, addComponents, e, theme }) {
2
+
3
+ // Variants
4
+
5
+ addVariant('tr', ({ modifySelectors, separator }) => {
6
+ modifySelectors(({ className }) => {
7
+ return `.${e(`tr${separator}${className}`)} tr`
8
+ })
9
+ });
10
+
11
+ addVariant('th', ({ modifySelectors, separator }) => {
12
+ modifySelectors(({ className }) => {
13
+ return `.${e(`th${separator}${className}`)} th`
14
+ })
15
+ });
16
+
17
+ addVariant('td', ({ modifySelectors, separator }) => {
18
+ modifySelectors(({ className }) => {
19
+ return `.${e(`td${separator}${className}`)} td`
20
+ })
21
+ });
22
+
23
+ // Components
24
+
25
+ const borderWidth = theme('borderWidth.DEFAULT');
26
+ const borderStyle = theme('borderStyle.solid');
27
+ const borderColor = theme('colors.slate.200');
28
+
29
+ addComponents({
30
+ '.tabulation': {
31
+ 'border-collapse': 'collapse',
32
+ 'border-bottom-width': borderWidth,
33
+ 'border-bottom-style': borderStyle,
34
+ 'border-bottom-color': borderColor,
35
+ 'border-radius': theme('borderRadius.md'),
36
+ 'table-layout': 'fixed',
37
+ },
38
+ '.tabulation thead': {
39
+ 'background-color': theme('colors.slate.100'),
40
+ },
41
+ '.tabulation th, .tabulation td': {
42
+ 'padding': theme('spacing.3') + ' ' + theme('spacing.2'),
43
+ 'text-align': 'left',
44
+ 'border-bottom-width': borderWidth,
45
+ 'border-bottom-style': borderStyle,
46
+ 'border-bottom-color': borderColor,
47
+ },
48
+ '.tabulation th': {
49
+ 'font-weight': theme('fontWeight.bold'),
50
+ },
51
+ '.tabulation.tabulation-nowrap td, .tabulation.tabulation-nowrap th': {
52
+ 'white-space': 'nowrap',
53
+ },
54
+ '.tabulation.tabulation-flush td:first-child, .tabulation.tabulation-flush th:first-child': {
55
+ 'padding-left': '0',
56
+ },
57
+ '.tabulation.tabulation-flush td:last-child, .tabulation.tabulation-flush th:last-child': {
58
+ 'padding-right': '0',
59
+ },
60
+ // Sizes
61
+ '.tabulation-xs th, .tabulation-xs td': {
62
+ 'padding': theme('spacing.1') + ' ' + theme('spacing.2'),
63
+ 'font-size': theme('fontSize.xs'),
64
+ },
65
+ '.tabulation-sm th, .tabulation-sm td': {
66
+ 'padding': theme('spacing.1') + ' ' + theme('spacing.2'),
67
+ 'font-size': theme('fontSize.sm'),
68
+ },
69
+ '.tabulation-md th, .tabulation-md td': {
70
+ 'padding': theme('spacing.2') + ' ' + theme('spacing.3'),
71
+ 'font-size': theme('fontSize.sm'),
72
+ },
73
+ '.tabulation-lg th, .tabulation-lg td': {
74
+ 'padding': theme('spacing.3') + ' ' + theme('spacing.4'),
75
+ 'font-size': theme('fontSize.base'),
76
+ },
77
+ '.tabulation-xl th, .tabulation-xl td': {
78
+ 'padding': theme('spacing.4') + ' ' + theme('spacing.5'),
79
+ 'font-size': theme('fontSize.lg'),
80
+ },
81
+ // Striped
82
+ '.tabulation.tabulation-striped tr:nth-child(even)': {
83
+ 'background-color': theme('colors.slate.100'),
84
+ },
85
+ // Grid
86
+ '.tabulation.tabulation-grid th, .tabulation.tabulation-grid td': {
87
+ 'border-width': borderWidth,
88
+ 'border-style': borderStyle,
89
+ 'border-color': borderColor,
90
+ },
91
+ });
92
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sprintify-ui",
3
- "version": "0.8.27",
3
+ "version": "0.8.29",
4
4
  "scripts": {
5
5
  "build": "rimraf dist && vue-tsc && vite build",
6
6
  "build-fast": "rimraf dist && vite build",
@@ -68,6 +68,38 @@ const Template = (args) => ({
68
68
  return { args, optionsLarge };
69
69
  },
70
70
  template: `
71
+
72
+ <table class="tabulation tabulation-grid tabulation-sm tabulation-striped w-full bg-white border mb-5">
73
+ <thead>
74
+ <tr>
75
+ <th>Label</th>
76
+ <th>ID</th>
77
+ <th>Type</th>
78
+ <th>Description</th>
79
+ </tr>
80
+ </thead>
81
+ <tbody>
82
+ <tr>
83
+ <td>Label</td>
84
+ <td>ID</td>
85
+ <td>Type</td>
86
+ <td>Description</td>
87
+ </tr>
88
+ <tr>
89
+ <td>Label</td>
90
+ <td>ID</td>
91
+ <td>Type</td>
92
+ <td>Description</td>
93
+ </tr>
94
+ <tr>
95
+ <td>Label</td>
96
+ <td>ID</td>
97
+ <td>Type</td>
98
+ <td>Description</td>
99
+ </tr>
100
+ </tbody>
101
+ </table>
102
+
71
103
  <div class="border">
72
104
  <BaseTable class="w-full" v-bind="args">
73
105
  ${headTemplate}
@@ -21,10 +21,10 @@
21
21
  <script lang="ts" setup>
22
22
  import { ClassNameValue, twMerge } from 'tailwind-merge';
23
23
  import { RouteLocationRaw } from 'vue-router';
24
- import { useIntersectionObserver } from '@vueuse/core';
25
24
  import { cellClasses } from '../services/table/classes';
26
25
  import { CellConfig, TableProps } from '../services/table/types';
27
26
  import { ComputedRef, Ref } from 'vue';
27
+ import { debounce } from 'lodash';
28
28
 
29
29
  defineOptions({
30
30
  inheritAttrs: false,
@@ -40,13 +40,66 @@ const isHead = computed(() => baseTableHead !== undefined);
40
40
 
41
41
  // Virtual scrolling
42
42
 
43
+ const trRef = ref<HTMLTableRowElement | null>(null);
44
+ const inViewport = ref(false);
45
+ const trRenderedHeight = ref(undefined) as Ref<number | undefined>;
46
+
43
47
  const baseTableVirtualScrollingDefaultRowHeight = inject('table:virtualScrollingDefaultRowHeight', undefined) as ComputedRef<number> | undefined;
44
48
  const setVirtualScrollingDefaultRowHeight = inject('table:setVirtualScrollingDefaultRowHeight', undefined) as ((height: number) => void) | undefined;
45
49
 
46
- const inViewport = ref(false);
47
- const trRef = ref<HTMLTableRowElement | null>(null);
50
+ const onScrollDebounce = debounce(onScroll, 10);
48
51
 
49
- const trRenderedHeight = ref(undefined) as Ref<number | undefined>;
52
+ window.addEventListener('scroll', onScrollDebounce);
53
+
54
+ onUnmounted(() => {
55
+ window.removeEventListener('scroll', onScrollDebounce);
56
+ });
57
+
58
+ onMounted(() => {
59
+ onScroll();
60
+ });
61
+
62
+
63
+ function onScroll() {
64
+
65
+ if (isHead.value) {
66
+ return;
67
+ }
68
+
69
+ if (!baseTable?.value?.virtualScrolling) {
70
+ return;
71
+ }
72
+
73
+ const isInViewport = isElementInViewport();
74
+
75
+ inViewport.value = isInViewport;
76
+
77
+ if (isInViewport) {
78
+ nextTick(() => {
79
+ trRenderedHeight.value = trRef.value?.offsetHeight;
80
+
81
+ if (trRenderedHeight.value && setVirtualScrollingDefaultRowHeight) {
82
+ setVirtualScrollingDefaultRowHeight(trRenderedHeight.value);
83
+ }
84
+ });
85
+ }
86
+ }
87
+
88
+ function isElementInViewport() {
89
+
90
+ if (!trRef.value) {
91
+ return false;
92
+ }
93
+
94
+ const rect = trRef.value.getBoundingClientRect();
95
+
96
+ const offsetY = 500;
97
+
98
+ return (
99
+ rect.top >= -offsetY &&
100
+ rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) + offsetY
101
+ );
102
+ }
50
103
 
51
104
  const height = computed(() => {
52
105
  if (isHead.value) {
@@ -84,31 +137,7 @@ const cellClass = computed(() => {
84
137
  return cellClasses(cellConfig.value) + ' text-white border-t border-gray-200';
85
138
  });
86
139
 
87
- if (!isHead.value && baseTable.value.virtualScrolling) {
88
-
89
- const margin = '300px';
90
-
91
- useIntersectionObserver(
92
- trRef,
93
- ([{ isIntersecting }]) => {
94
-
95
- inViewport.value = isIntersecting;
96
-
97
- if (isIntersecting) {
98
- nextTick(() => {
99
- trRenderedHeight.value = trRef.value?.offsetHeight;
100
-
101
- if (trRenderedHeight.value && setVirtualScrollingDefaultRowHeight) {
102
- setVirtualScrollingDefaultRowHeight(trRenderedHeight.value);
103
- }
104
- });
105
- }
106
- },
107
- {
108
- rootMargin: margin,
109
- }
110
- );
111
- }
140
+ // Emit
112
141
 
113
142
  const emit = defineEmits(['click', 'mouseenter', 'mouseleave']);
114
143