@weni/unnnic-system 3.34.2 → 3.35.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weni/unnnic-system",
3
- "version": "3.34.2",
3
+ "version": "3.35.0",
4
4
  "type": "commonjs",
5
5
  "files": [
6
6
  "dist",
@@ -1,17 +1,38 @@
1
1
  <script setup lang="ts">
2
- import type { HTMLAttributes } from 'vue';
2
+ import type { HTMLAttributes, VNode } from 'vue';
3
+ import { Comment, Fragment, Text, computed, useSlots } from 'vue';
3
4
  import { cn } from '@/lib/utils';
4
5
 
5
6
  const props = withDefaults(
6
7
  defineProps<{
8
+ align?: 'center' | 'left' | 'right';
7
9
  class?: HTMLAttributes['class'];
8
10
  ellipsis?: boolean;
9
11
  width?: string;
10
12
  }>(),
11
13
  {
12
- ellipsis: false,
14
+ align: 'left',
15
+ ellipsis: true,
13
16
  },
14
17
  );
18
+
19
+ const slots = useSlots();
20
+
21
+ const isTextOnlySlot = (vnodes: VNode[] | undefined): boolean => {
22
+ if (!vnodes?.length) return true;
23
+
24
+ return vnodes.every((vnode) => {
25
+ if (vnode.type === Comment) return true;
26
+ if (vnode.type === Text) return true;
27
+ if (vnode.type === Fragment) {
28
+ return isTextOnlySlot(vnode.children as VNode[]);
29
+ }
30
+
31
+ return false;
32
+ });
33
+ };
34
+
35
+ const hasComponentContent = computed(() => !isTextOnlySlot(slots.default?.()));
15
36
  </script>
16
37
 
17
38
  <template>
@@ -19,32 +40,77 @@ const props = withDefaults(
19
40
  :class="
20
41
  cn(
21
42
  'unnnic-table-cell',
22
- { 'unnnic-table-cell--ellipsis': props.ellipsis },
43
+ `unnnic-table-cell--align-${props.align}`,
44
+ {
45
+ 'unnnic-table-cell--ellipsis': props.ellipsis,
46
+ 'unnnic-table-cell--has-component': hasComponentContent,
47
+ },
23
48
  props.class,
24
49
  )
25
50
  "
26
51
  :style="{ width: props.width }"
27
52
  >
28
- <slot />
53
+ <div class="unnnic-table-cell__inner">
54
+ <slot />
55
+ </div>
29
56
  </td>
30
57
  </template>
31
58
 
32
59
  <style lang="scss" scoped>
33
60
  @use '@/assets/scss/unnnic' as *;
34
61
 
62
+ $row-min-height: 61px;
63
+
35
64
  .unnnic-table-cell {
65
+ @include unnnic-font-body;
66
+ color: $unnnic-color-fg-emphasized;
36
67
  vertical-align: middle;
68
+ padding: 0;
69
+
70
+ &__inner {
71
+ box-sizing: border-box;
72
+ display: flex;
73
+ align-items: center;
74
+ min-width: 0;
75
+ max-width: 100%;
76
+ min-height: $row-min-height;
77
+ padding: $unnnic-space-3 $unnnic-space-4;
78
+ }
79
+
80
+ &--has-component &__inner {
81
+ padding-block: $unnnic-space-2;
82
+ }
83
+
84
+ &--align-left {
85
+ text-align: left;
86
+
87
+ .unnnic-table-cell__inner {
88
+ justify-content: flex-start;
89
+ }
90
+ }
91
+
92
+ &--align-center {
93
+ text-align: center;
94
+
95
+ .unnnic-table-cell__inner {
96
+ justify-content: center;
97
+ }
98
+ }
37
99
 
38
- padding: $unnnic-space-4 0;
100
+ &--align-right {
101
+ text-align: right;
39
102
 
40
- &:not(:last-child) {
41
- padding-right: $unnnic-space-4;
103
+ .unnnic-table-cell__inner {
104
+ justify-content: flex-end;
105
+ }
42
106
  }
43
107
 
44
- &--ellipsis {
108
+ &--ellipsis:not(&--has-component) &__inner {
109
+ display: block;
45
110
  overflow: hidden;
46
111
  text-overflow: ellipsis;
47
112
  white-space: nowrap;
113
+ align-content: center;
48
114
  }
49
115
  }
50
116
  </style>
@@ -4,11 +4,13 @@ import { cn } from '@/lib/utils';
4
4
 
5
5
  const props = withDefaults(
6
6
  defineProps<{
7
+ align?: 'center' | 'left' | 'right';
7
8
  class?: HTMLAttributes['class'];
8
9
  ellipsis?: boolean;
9
10
  width?: string;
10
11
  }>(),
11
12
  {
13
+ align: 'left',
12
14
  ellipsis: false,
13
15
  },
14
16
  );
@@ -19,6 +21,7 @@ const props = withDefaults(
19
21
  :class="
20
22
  cn(
21
23
  'unnnic-table-head',
24
+ `unnnic-table-head--align-${props.align}`,
22
25
  { 'unnnic-table-head--ellipsis': props.ellipsis },
23
26
  props.class,
24
27
  )
@@ -35,10 +38,19 @@ const props = withDefaults(
35
38
  .unnnic-table-head {
36
39
  @include unnnic-font-caption-1;
37
40
  color: $unnnic-color-fg-base;
38
- text-align: left;
39
- align-items: center;
41
+ vertical-align: middle;
40
42
 
41
- pointer-events: none;
43
+ &--align-left {
44
+ text-align: left;
45
+ }
46
+
47
+ &--align-center {
48
+ text-align: center;
49
+ }
50
+
51
+ &--align-right {
52
+ text-align: right;
53
+ }
42
54
 
43
55
  &--ellipsis {
44
56
  overflow: hidden;
@@ -18,7 +18,11 @@ const props = defineProps<{
18
18
 
19
19
  .unnnic-table-header {
20
20
  * {
21
- padding-bottom: $unnnic-space-2;
21
+ padding: $unnnic-space-3 $unnnic-space-4;
22
+ }
23
+
24
+ &:hover {
25
+ background-color: $unnnic-color-bg-soft;
22
26
  }
23
27
  }
24
28
  </style>
@@ -1,9 +1,9 @@
1
1
  <script setup lang="ts">
2
2
  import type { HTMLAttributes } from 'vue';
3
- import { computed, useAttrs } from 'vue';
3
+ import { computed, getCurrentInstance } from 'vue';
4
4
  import { cn } from '@/lib/utils';
5
5
 
6
- defineEmits<{
6
+ const emit = defineEmits<{
7
7
  (e: 'click', event: KeyboardEvent | MouseEvent): void;
8
8
  }>();
9
9
 
@@ -11,9 +11,13 @@ const props = defineProps<{
11
11
  class?: HTMLAttributes['class'];
12
12
  }>();
13
13
 
14
- const attrs = useAttrs();
14
+ const instance = getCurrentInstance();
15
+ const isClickable = computed(() => Boolean(instance?.vnode.props?.onClick));
15
16
 
16
- const isClickable = computed(() => Boolean(attrs.onClick));
17
+ function handleClick(event: KeyboardEvent | MouseEvent) {
18
+ if (!isClickable.value) return;
19
+ emit('click', event);
20
+ }
17
21
  </script>
18
22
 
19
23
  <template>
@@ -27,8 +31,9 @@ const isClickable = computed(() => Boolean(attrs.onClick));
27
31
  props.class,
28
32
  )
29
33
  "
30
- @keydown.enter="isClickable && $emit('click', $event)"
31
- @keydown.space.prevent="isClickable && $emit('click', $event)"
34
+ @click="handleClick"
35
+ @keydown.enter="handleClick"
36
+ @keydown.space.prevent="handleClick"
32
37
  >
33
38
  <slot />
34
39
  </tr>
@@ -38,14 +43,6 @@ const isClickable = computed(() => Boolean(attrs.onClick));
38
43
  @use '@/assets/scss/unnnic' as *;
39
44
 
40
45
  .unnnic-table-row {
41
- & > :first-child {
42
- padding-left: $unnnic-space-3;
43
- }
44
-
45
- & > :last-child {
46
- padding-right: $unnnic-space-3;
47
- }
48
-
49
46
  border-bottom: 1px solid $unnnic-color-border-base;
50
47
 
51
48
  &:hover {