its_ui_vite 0.0.4 → 1.0.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/README.md CHANGED
@@ -49,6 +49,7 @@ export default {
49
49
  variant?: 'tonal' | 'outlined' | 'text' | 'nav_item',
50
50
  color?: 'green' | 'black',
51
51
  disabled?: Boolean,
52
+ loading?: Boolean,
52
53
  }
53
54
 
54
55
  slots: ['без имени']
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "its_ui_vite",
3
- "version": "0.0.4",
3
+ "version": "1.0.0",
4
4
  "main": "./src/libIndex.js",
5
5
  "module": "./src/libIndex.js",
6
6
  "files": [
@@ -19,153 +19,123 @@
19
19
  </div>
20
20
  </template>
21
21
 
22
- <script>
23
- import { getPropValidator } from '../assets/js/helpers'
22
+ <script setup lang="ts">
23
+ import {
24
+ ref,
25
+ watch,
26
+ computed,
27
+ onMounted,
28
+ onUnmounted
29
+ } from 'vue'
30
+
24
31
  import CIcon from './CIcons/index.vue'
25
32
 
26
- export default {
27
- data() {
28
- return {
29
- isLockLiveTime: false,
30
- isShow: true,
31
- isFade: false,
32
- timeFade: 5000,
33
-
34
- timers: {
35
- live: undefined,
36
- fade: undefined,
37
- },
38
-
39
- classes: {
40
- root: 'c-alert',
41
- },
42
- }
43
- },
33
+ type TProp = {
34
+ liveTime?: number,
35
+ variant?: 'notification' | 'success' | 'error',
36
+ width?: string,
37
+ text?: string,
38
+ }
39
+
40
+ const props = withDefaults(defineProps<TProp>(), {
41
+ liveTime: 10000,
42
+ variant: 'notification',
43
+ width: 'auto',
44
+ text: ''
45
+ });
46
+
47
+ onMounted(addListener)
48
+ onUnmounted(removeListener)
49
+
50
+ const iconId = computed(() => {
51
+ const iconsIds = {
52
+ notification: 'bell',
53
+ success: 'success',
54
+ error: 'error',
55
+ }
56
+
57
+ return iconsIds[props.variant]
58
+ })
59
+
60
+ let root = ref(null)
44
61
 
45
- props: {
46
- liveTime: {
47
- type: Number,
62
+ let isLockLiveTime = false,
63
+ isShow = ref(true),
64
+ isFade = ref(false)
48
65
 
49
- default: 10000,
50
- },
66
+ const timeFade = 5000
67
+ const classes = {
68
+ root: 'c-alert',
69
+ }
51
70
 
52
- variant: {
53
- type: String,
71
+ type TTimers = {
72
+ live: ReturnType<typeof setTimeout>,
73
+ fade: ReturnType<typeof setTimeout>,
74
+ }
54
75
 
55
- default: 'notification',
56
- validator: getPropValidator('CAlert', 'variant', ['notification', 'success', 'error']),
57
- },
76
+ const timers: TTimers = {
77
+ live: 0,
78
+ fade: 0,
79
+ }
58
80
 
59
- width: {
60
- type: String,
81
+ watch(props, updateLiveTime, {
82
+ deep: true,
83
+ immediate: true,
84
+ })
61
85
 
62
- default: 'auto',
63
- },
86
+ function close() {
87
+ isShow.value = false
88
+ isLockLiveTime = true
89
+ }
64
90
 
65
- text: {
66
- type: String,
91
+ function updateLiveTime() {
92
+ if (!isShow.value) return
67
93
 
68
- default: '',
69
- }
70
- },
71
-
72
- methods: {
73
- close() {
74
- this.isShow = false
75
- this.isLockLiveTime = true
76
- },
77
-
78
- updateLiveTime() {
79
- if (!this.isShow) return
80
-
81
- this.isShow = true
82
- this.isFade = false
83
-
84
- clearTimeout(this.timers.fade)
85
- clearTimeout(this.timers.live)
86
-
87
- if (this.isLockLiveTime) return
88
-
89
- this.timers.fade = setTimeout(() => {
90
- this.isFade = true
91
- }, Math.max(this.liveTime - this.timeFade, 0));
92
-
93
- this.timers.live = setTimeout(() => {
94
- this.isShow = false
95
- }, this.liveTime);
96
- },
97
-
98
- // слушатели
99
- /**
100
- * @param {MouseEvent} evt
101
- */
102
- handleMouseover(evt){
103
- const tooltipTarget = evt.target.closest(`.${this.classes.root}`)
104
-
105
- if (tooltipTarget !== this.$refs.root) return
106
-
107
- this.isLockLiveTime = true
108
- evt.stopPropagation()
109
- this.updateLiveTime()
110
- },
111
-
112
- /**
113
- * @param {MouseEvent} evt
114
- */
115
- handleMouseout(evt) {
116
- const tooltipTarget = evt.target.closest(`.${this.classes.root}`)
117
-
118
- if (tooltipTarget !== this.$refs.root) return
119
-
120
- this.isLockLiveTime = false
121
- this.updateLiveTime()
122
- },
123
-
124
- addListener() {
125
- document.body.addEventListener('mouseover', this.handleMouseover)
126
- document.body.addEventListener('mouseout', this.handleMouseout)
127
- },
128
-
129
- removeListener() {
130
- document.body.removeEventListener('mouseover', this.handleMouseover)
131
- document.body.removeEventListener('mouseout', this.handleMouseout)
132
- },
133
- },
134
-
135
- mounted() {
136
- this.addListener()
137
- },
138
-
139
- beforeDestroy() {
140
- this.removeListener()
141
- },
142
-
143
- watch: {
144
- $props: {
145
- deep: true,
146
- immediate: true,
147
-
148
- handler(newWal) {
149
- this.updateLiveTime()
150
- },
151
- },
152
- },
153
-
154
- computed: {
155
- iconId() {
156
- const iconsIds = {
157
- notification: 'bell',
158
- success: 'success',
159
- error: 'error',
160
- }
161
-
162
- return iconsIds[this.variant]
163
- },
164
- },
165
-
166
- components: {
167
- CIcon,
168
- },
94
+ isShow.value = true
95
+ isFade.value = false
96
+
97
+ clearTimeout(timers.fade)
98
+ clearTimeout(timers.live)
99
+
100
+ if (isLockLiveTime) return
101
+
102
+ timers.fade = setTimeout(() => {
103
+ isFade.value = true
104
+ }, Math.max(props.liveTime - timeFade, 0));
105
+
106
+ timers.live = setTimeout(() => {
107
+ isShow.value = false
108
+ }, props.liveTime);
109
+ }
110
+
111
+ // слушатели
112
+ function handleMouseover(evt: MouseEvent){
113
+ const tooltipTarget = (evt.target as HTMLDivElement).closest(`.${classes.root}`)
114
+
115
+ if (tooltipTarget !== root.value) return
116
+
117
+ isLockLiveTime = true
118
+ evt.stopPropagation()
119
+ updateLiveTime()
120
+ }
121
+
122
+ function handleMouseout(evt: MouseEvent) {
123
+ const tooltipTarget = (evt.target as HTMLDivElement).closest(`.${classes.root}`)
124
+
125
+ if (tooltipTarget !== root.value) return
126
+
127
+ isLockLiveTime = false
128
+ updateLiveTime()
129
+ }
130
+
131
+ function addListener() {
132
+ document.body.addEventListener('mouseover', handleMouseover)
133
+ document.body.addEventListener('mouseout', handleMouseout)
134
+ }
135
+
136
+ function removeListener() {
137
+ document.body.removeEventListener('mouseover', handleMouseover)
138
+ document.body.removeEventListener('mouseout', handleMouseout)
169
139
  }
170
140
 
171
141
  </script>
@@ -1,56 +1,50 @@
1
1
  <template>
2
- <button :class="['c-btn', size, variant, color, { active }]" :disabled="disabled">
2
+ <button :class="['c-btn', size, variant, color, { active, loading }]" :disabled="disabled">
3
3
  <div class="c-btn__container">
4
4
  <slot></slot>
5
5
  </div>
6
+ <div class="c-btn__loading">
7
+ <CIcon
8
+ iconId="loading"
9
+ :size="loadingSize[size]"
10
+ />
11
+ </div>
6
12
  </button>
7
13
  </template>
8
14
 
9
- <script>
10
- import { getPropValidator } from '../assets/js/helpers.js'
11
-
12
- export default {
13
- props: {
14
- size: {
15
- type: String,
16
-
17
- default: "lg",
18
- validator: getPropValidator('CButton', 'size', ['lg', 'md', 'sm']),
19
- },
20
-
21
- variant: {
22
- type: String,
23
-
24
- default: "tonal",
25
- validator: getPropValidator('CButton', 'variant', ['tonal', 'outlined', 'text', 'nav_item']),
26
- },
27
-
28
- color: {
29
- type: String,
30
-
31
- default: "green",
32
- validator: getPropValidator('CButton', 'color', ['green', 'black']),
33
- },
34
-
35
- active: {
36
- type: Boolean,
37
-
38
- default: false,
39
- },
40
-
41
- disabled: {
42
- type: Boolean,
15
+ <script setup lang="ts">
16
+ import CIcon from './CIcons/index.vue'
17
+
18
+ const loadingSize = {
19
+ lg: 24,
20
+ md: 20,
21
+ sm: 16,
22
+ };
23
+
24
+ type TProps = {
25
+ size?: 'lg' | 'md' | 'sm',
26
+ variant?: 'tonal' | 'outlined' | 'text' | 'nav_item',
27
+ color?: 'green' | 'black',
28
+ active?: boolean,
29
+ disabled?: boolean,
30
+ loading?: boolean,
31
+ }
43
32
 
44
- default: false,
45
- },
46
- },
47
- }
33
+ const props = withDefaults(defineProps<TProps>(), {
34
+ size: 'lg',
35
+ variant: 'tonal',
36
+ color: 'green',
37
+ active: false,
38
+ disabled: false,
39
+ loading: false
40
+ });
48
41
  </script>
49
42
 
50
43
  <style lang="scss">
51
44
  @import "../assets/scss/main.scss";
52
45
 
53
46
  .c-btn {
47
+ position: relative;
54
48
  border-radius: 30px;
55
49
 
56
50
  transition: var(--transition);
@@ -59,9 +53,26 @@ import { getPropValidator } from '../assets/js/helpers.js'
59
53
  outline: none;
60
54
  border: none;
61
55
 
56
+ // prop.disabled
62
57
  &:disabled {
63
58
  cursor: default;
64
59
  }
60
+ // ./prop.disabled
61
+
62
+ // ./prop.loading
63
+ &.loading {
64
+ pointer-events: none;
65
+
66
+ .c-btn__container {
67
+ opacity: 0;
68
+ pointer-events: none;
69
+ }
70
+
71
+ .c-btn__loading {
72
+ opacity: 1;
73
+ }
74
+ }
75
+ // ./prop.loading
65
76
 
66
77
  button,
67
78
  input,
@@ -188,5 +199,31 @@ import { getPropValidator } from '../assets/js/helpers.js'
188
199
  }
189
200
  }
190
201
  // ./prop.variant
202
+
203
+ &__loading {
204
+ position: absolute;
205
+ left: 50%;
206
+ top: 50%;
207
+ transform: translate(-50%, -50%);
208
+ display: flex;
209
+ align-items: center;
210
+ justify-content: center;
211
+ opacity: 0;
212
+ pointer-events: none;
213
+
214
+ svg {
215
+ animation: animation-rotation steps(100) 1.5s infinite;
216
+ }
217
+ }
218
+ }
219
+
220
+ @keyframes animation-rotation {
221
+ 0% {
222
+ transform: rotate(0deg);
223
+ }
224
+
225
+ 100% {
226
+ transform: rotate(360deg);
227
+ }
191
228
  }
192
229
  </style>
@@ -7,11 +7,8 @@
7
7
  :value="modelValue || value"
8
8
  :checked="isRadio ? value === modelValue : modelValue"
9
9
  :disabled="disabled"
10
- @change="$emit('update:modelValue', isRadio ? value : $event.target.checked)"
10
+ @change="({ target }) => $emit('update:modelValue', isRadio ? value : (target as HTMLInputElement).checked)"
11
11
  />
12
- <!-- @change="(evt) => $emit('change', isRadio ? (modelValue || value) : evt.target.checked)" -->
13
- <!-- @change="$emit('update:checked', $event.target.checked), $emit('update:modelValue', $event.target.value)" -->
14
-
15
12
  <div class="c-checkbox__checkmark"></div>
16
13
  <div class="c-checkbox__text">
17
14
  <slot>{{ text }}</slot>
@@ -19,66 +16,35 @@
19
16
  </label>
20
17
  </template>
21
18
 
22
- <script>
23
- import { getPropValidator } from '../assets/js/helpers.js'
24
-
25
- export default {
26
- name: 'CCheckbox',
27
-
28
- data() {
29
- return {
30
- isRadio: this.variant === 'radio',
31
- }
32
- },
33
-
34
- emits: ['update:checked', 'update:modelValue'],
35
-
36
- props: {
37
-
38
- variant: {
39
- type: String,
19
+ <script setup lang="ts">
40
20
 
41
- default: 'checkbox',
42
- validator: getPropValidator('CCheckbox', 'variant', ['checkbox', 'radio', 'toggle'])
43
- },
44
-
45
- size: {
46
- type: String,
47
-
48
- default: 'lg',
49
- // по сути sm используется только в CSelect
50
- validator: getPropValidator('CCheckbox', 'size', ['lg', 'sm'])
51
- },
52
-
53
- disabled: {
54
- type: Boolean,
21
+ type TProps = {
22
+ variant?: 'checkbox' | 'radio' | 'toggle',
23
+ size?: 'lg' | 'sm',
24
+ disabled?: boolean,
25
+ text?: string,
26
+ name?: string,
27
+ value?: any,
28
+ modelValue: any,
29
+ }
55
30
 
56
- default: false,
57
- },
31
+ const props = withDefaults(defineProps<TProps>(), {
32
+ variant: 'checkbox',
33
+ size: 'lg',
34
+ disabled: false,
35
+ text: '',
36
+ name: 'c_checkbox',
37
+ value: '',
38
+ modelValue: '',
39
+ });
58
40
 
59
- text: {
60
- type: String,
61
-
62
- default: '',
63
- },
41
+ const emits = defineEmits<{
42
+ (name: 'update:checked', value: boolean): void,
43
+ (name: 'update:modelValue', value: any): void,
44
+ }>();
64
45
 
65
- name: {
66
- type: String,
67
-
68
- default: 'c_checkbox',
69
- },
46
+ const isRadio = props.variant === 'radio'
70
47
 
71
- value: {
72
- default: '',
73
- },
74
-
75
- modelValue: {
76
- type: [Boolean, String, Number, Array],
77
-
78
- default: '',
79
- },
80
- },
81
- }
82
48
  </script>
83
49
 
84
50
  <style lang="scss">
@@ -36,6 +36,10 @@
36
36
  <path d="M12 16V16.5" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
37
37
  </svg>
38
38
 
39
+ <svg v-if="iconId === 'loading'" :width="w" :height="h" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
40
+ <path d="M10 0C8.68678 -1.489e-08 7.38642 0.258657 6.17317 0.761204C4.95991 1.26375 3.85752 2.00035 2.92893 2.92893C2.00035 3.85752 1.26375 4.95991 0.761204 6.17317C0.258657 7.38642 -1.489e-08 8.68678 0 10C-4.96335e-08 11.3132 0.258657 12.6136 0.761204 13.8268C1.26375 15.0401 2.00035 16.1425 2.92893 17.0711C3.85752 17.9997 4.95991 18.7362 6.17317 19.2388C7.38642 19.7413 8.68678 20 10 20C11.3132 20 12.6136 19.7413 13.8268 19.2388C15.0401 18.7362 16.1425 17.9997 17.0711 17.0711C17.9997 16.1425 18.7362 15.0401 19.2388 13.8268C19.7413 12.6136 20 11.3132 20 10C20 8.68678 19.7413 7.38642 19.2388 6.17317C18.7362 4.95991 17.9997 3.85752 17.0711 2.92893C16.1425 2.00035 15.0401 1.26375 13.8268 0.761204C12.6136 0.258657 11.3132 -4.96335e-08 10 0ZM10 1C11.314 1.00028 12.6119 1.28828 13.8027 1.84375L12.959 3.65625C12.0324 3.22403 11.0224 3.00003 10 3C8.97758 3.00003 7.96758 3.22403 7.04102 3.65625L6.19922 1.84961C7.38895 1.2924 8.68625 1.0024 10 1ZM10 4C10.7879 4 11.5681 4.15519 12.2961 4.45672C13.0241 4.75825 13.6855 5.20021 14.2426 5.75736C14.7998 6.31451 15.2417 6.97595 15.5433 7.7039C15.8448 8.43185 16 9.21207 16 10C16 10.7879 15.8448 11.5681 15.5433 12.2961C15.2417 13.0241 14.7998 13.6855 14.2426 14.2426C13.6855 14.7998 13.0241 15.2417 12.2961 15.5433C11.5681 15.8448 10.7879 16 10 16C8.4087 16 6.88258 15.3679 5.75736 14.2426C4.63214 13.1174 4 11.5913 4 10C4 8.4087 4.63214 6.88258 5.75736 5.75736C6.88258 4.63214 8.4087 4 10 4Z" fill="white"/>
41
+ </svg>
42
+
39
43
  </div>
40
44
  </template>
41
45
 
@@ -7,7 +7,7 @@
7
7
  :placeholder="placeholder"
8
8
  :value="modelValue"
9
9
  :disabled="disabled"
10
- @input="$emit('update:modelValue', $event.target.value)"
10
+ @input="({target}) => $emit('update:modelValue', (target as HTMLInputElement).value)"
11
11
  />
12
12
 
13
13
  <div class="c-input__icon c-input__success-icon">
@@ -28,65 +28,36 @@
28
28
  </div>
29
29
  </template>
30
30
 
31
- <script>
31
+ <script setup lang="ts">
32
+ import { InputTypeHTMLAttribute } from 'vue';
32
33
  import CIcon from './CIcons/index.vue'
33
34
 
34
- import { getPropValidator } from '../assets/js/helpers';
35
+ type TProps = {
36
+ status?: 'static' | 'focus' | 'error' | 'success',
37
+ size?: 'lg' | 'md' | 'sm',
38
+ width?: string,
39
+ disabled?: boolean,
40
+ type?: InputTypeHTMLAttribute,
41
+ name?: string,
42
+ placeholder?: string,
43
+ modelValue?: any,
44
+ }
45
+
46
+ const pops = withDefaults(defineProps<TProps>(), {
47
+ status: 'static',
48
+ size: 'lg',
49
+ width: '350px',
50
+ disabled: false,
51
+ type: 'text',
52
+ name: '',
53
+ placeholder: '',
54
+ modelValue: ''
55
+ })
56
+
57
+ const emits = defineEmits<{
58
+ (name: 'update:modelValue', value: any): void
59
+ }>()
35
60
 
36
- export default {
37
- emits: ['update:modelValue'],
38
- components: {
39
- CIcon
40
- },
41
-
42
- props: {
43
- status: {
44
- type: String,
45
-
46
- default: 'static',
47
- validator: getPropValidator('CInput', 'status', ['static', 'focus'/* it rofls */, 'error', 'success'])
48
- },
49
-
50
- size: {
51
- type: String,
52
-
53
- default: 'lg',
54
- validator: getPropValidator('CInput', 'size', ['lg', 'md', 'sm'])
55
- },
56
-
57
- width: {
58
- type: String,
59
-
60
- default: '350px'
61
- },
62
-
63
- disabled: {
64
- type: Boolean,
65
- },
66
-
67
- type: {
68
- type: String,
69
-
70
- default: 'text',
71
- },
72
-
73
- name: {
74
- type: String,
75
-
76
- default: 'c_inp',
77
- },
78
-
79
- placeholder: {
80
- type: String,
81
-
82
- default: '',
83
- },
84
-
85
- modelValue: {
86
- default: '',
87
- }
88
- },
89
- }
90
61
  </script>
91
62
 
92
63
  <style lang="scss">
@@ -13,16 +13,13 @@
13
13
  </div>
14
14
  </template>
15
15
 
16
- <script>
17
- export default {
18
- props: {
19
- isShowTitle: {
20
- type: Boolean,
21
-
22
- default: true
23
- }
24
- }
25
- }
16
+ <script setup lang="ts">
17
+ type TProp = {
18
+ isShowTitle?: boolean,
19
+ }
20
+ const props = withDefaults(defineProps<TProp>(), {
21
+ isShowTitle: true
22
+ })
26
23
  </script>
27
24
 
28
25
  <style lang="scss">