@v1nt1248/3nclient-lib 0.0.26 → 0.0.28

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
@@ -2,7 +2,7 @@
2
2
  "name": "@v1nt1248/3nclient-lib",
3
3
  "license": "AGPL-3.0-or-later",
4
4
  "author": "v1nt1248",
5
- "version": "0.0.26",
5
+ "version": "0.0.28",
6
6
  "description": "Library for 3NWeb clients",
7
7
  "private": false,
8
8
  "type": "module",
@@ -25,6 +25,8 @@ import Ui3nList from './ui3n-list.vue'
25
25
  import type { Ui3nListProps, Ui3nListEmits, Ui3nListSlots } from './ui3n-list.vue'
26
26
  import Ui3nVirtualScroll from './ui3n-virtual-scroll.vue'
27
27
  import type { Ui3nVirtualScrollProps, Ui3nVirtualScrollSlots } from './ui3n-virtual-scroll.vue'
28
+ import Ui3nTabs from './ui3n-tabs.vue'
29
+ import type { Ui3nTabsProps, Ui3nTabsEmits, Ui3nTabsSlots } from './ui3n-tabs.vue'
28
30
 
29
31
  export {
30
32
  Ui3nIcon,
@@ -71,4 +73,8 @@ export {
71
73
  Ui3nVirtualScroll,
72
74
  Ui3nVirtualScrollProps,
73
75
  Ui3nVirtualScrollSlots,
76
+ Ui3nTabs,
77
+ Ui3nTabsProps,
78
+ Ui3nTabsEmits,
79
+ Ui3nTabsSlots,
74
80
  }
@@ -110,6 +110,7 @@
110
110
  line-height: var(--ui3n-button-text-height);
111
111
  font-weight: 600;
112
112
  color: var(--ui3n-button-text-color);
113
+ user-select: none;
113
114
 
114
115
  &--round {
115
116
  --ui3n-button-padding-vert: 6px;
@@ -154,6 +155,15 @@
154
155
  opacity: 0.7;
155
156
  }
156
157
 
158
+ &:not(.ui3n-button--round) {
159
+ .ui3n-button {
160
+ &__icon,
161
+ &__text {
162
+ pointer-events: none
163
+ }
164
+ }
165
+ }
166
+
157
167
  @include ripple(var(--ui3n-button-background));
158
168
  }
159
169
  </style>
@@ -0,0 +1,174 @@
1
+ <script lang="ts" setup>
2
+ import { computed, onMounted, ref, watch } from 'vue'
3
+
4
+ export interface Ui3nTabsProps {
5
+ modelValue: number;
6
+ itemDirection?: 'horizontal' | 'vertical';
7
+ activeColor?: string;
8
+ inactiveColor?: string;
9
+ indicatorColor?: string;
10
+ indicatorSize?: number | string;
11
+ indicatorPosition?: 'normal' | 'reverse';
12
+ }
13
+
14
+ export interface Ui3nTabsEmits {
15
+ (ev: 'update:modelValue', val: number): void;
16
+ }
17
+
18
+ export interface Ui3nTabsSlots {
19
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
+ default: () => any;
21
+ }
22
+
23
+ const props = withDefaults(
24
+ defineProps<Ui3nTabsProps>(),
25
+ {
26
+ modelValue: 0,
27
+ itemDirection: 'horizontal',
28
+ activeColor: 'var(--blue-main, #0090ec)',
29
+ inactiveColor: 'var(--black-90, #212121)',
30
+ indicatorColor: 'var(--blue-main, #0090ec)',
31
+ indicatorSize: 2,
32
+ indicatorPosition: 'normal',
33
+ },
34
+ )
35
+ const emits = defineEmits<Ui3nTabsEmits>()
36
+
37
+
38
+ const tabs = ref<HTMLDivElement | null>(null)
39
+ const children = ref<HTMLCollection | null>(null)
40
+
41
+ const activeColor = computed(() => props.activeColor)
42
+ const inactiveColor = computed(() => props.inactiveColor)
43
+ const indicatorColor = computed(() => props.indicatorColor)
44
+ const indicatorSize = computed(() => `${props.indicatorSize}px`)
45
+ const indicatorPosition = computed(() => props.indicatorPosition === 'reverse' ? '100%' : '0')
46
+
47
+ watch(
48
+ () => props.modelValue,
49
+ newValue => setTabsActivity(newValue),
50
+ )
51
+
52
+ onMounted(() => {
53
+ if (tabs.value) {
54
+ children.value = tabs.value.children
55
+ initialTabsActivity()
56
+ setTabsActivity(props.modelValue)
57
+ }
58
+ })
59
+
60
+ function initialTabsActivity(): void {
61
+ if (children.value) {
62
+ for (let i = 0; i < children.value.length; i++) {
63
+ // @ts-ignore
64
+ children.value[i].dataset.index = `${i}`
65
+ children.value[i].classList.add('ui3n-tabs__item')
66
+ }
67
+ }
68
+ }
69
+
70
+ function setTabsActivity(index: number): void {
71
+ if (children.value) {
72
+ for (let i = 0; i < children.value.length; i++) {
73
+ if (i === index) {
74
+ children.value[i].classList.add('ui3n-tabs__item--active')
75
+ } else {
76
+ children.value[i].classList.remove('ui3n-tabs__item--active')
77
+ }
78
+ }
79
+ }
80
+ }
81
+
82
+ const onClick = (ev: MouseEvent) => {
83
+ // @ts-ignore
84
+ const { index } = ev.target.dataset
85
+ if (index) {
86
+ emits('update:modelValue', Number(index))
87
+ }
88
+ }
89
+ </script>
90
+
91
+ <template>
92
+ <div
93
+ ref="tabs"
94
+ :class="[
95
+ 'ui3n-tabs',
96
+ props.itemDirection === 'vertical' && 'ui3n-tabs--vertical',
97
+ ]"
98
+ v-on="children ? { click: onClick } : {}"
99
+ >
100
+ <slot />
101
+ </div>
102
+ </template>
103
+
104
+ <style lang="scss" scoped>
105
+ @import "../assets/styles/mixins";
106
+
107
+ .ui3n-tabs {
108
+ --ui3n-tabs-height: 48px;
109
+
110
+ position: relative;
111
+ height: var(--ui3n-tabs-height);
112
+ display: flex;
113
+ justify-content: center;
114
+ align-items: stretch;
115
+
116
+ :deep(.ui3n-tabs__item) {
117
+ cursor: pointer;
118
+
119
+ &.ui3n-tabs__item {
120
+ position: relative;
121
+ user-select: none;
122
+ color: v-bind('inactiveColor');
123
+
124
+ &:hover {
125
+ background-color: var(--blue-main-20, #d8edfd);
126
+ }
127
+
128
+ &::after {
129
+ position: absolute;
130
+ content: '';
131
+ left: 0;
132
+ width: 100%;
133
+ bottom: v-bind('indicatorPosition');
134
+ height: v-bind('indicatorSize');
135
+ background-color: transparent;
136
+ transition: background-color 250ms ease-in-out;
137
+ }
138
+
139
+ &[disabled] {
140
+ opacity: 0.5;
141
+ cursor: default;
142
+ pointer-events: none
143
+ }
144
+
145
+ @include ripple(#d8edfd);
146
+ }
147
+
148
+ &.ui3n-tabs__item--active {
149
+ color: v-bind('activeColor');
150
+
151
+ &::after {
152
+ background-color: v-bind('indicatorColor');
153
+ transition: background-color 250ms ease-in-out;
154
+ }
155
+ }
156
+ }
157
+
158
+ &--vertical {
159
+ height: auto;
160
+ flex-direction: column;
161
+
162
+ :deep(.ui3n-tabs__item) {
163
+ &.ui3n-tabs__item {
164
+ &::after {
165
+ left: v-bind('indicatorPosition');
166
+ width: v-bind('indicatorSize');
167
+ bottom: 0;
168
+ height: 100%;
169
+ }
170
+ }
171
+ }
172
+ }
173
+ }
174
+ </style>