@bagelink/vue 0.0.346 → 0.0.350

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,23 +1,25 @@
1
1
  <template>
2
- <component :is="to ? 'router-link' : is" :to="to" @click.stop="onClick" :type="type" :role="role" :disabled="disabled"
3
- :class="{
4
- 'bgl_btn-icon': icon && !slots['default'] && !value,
5
- bgl_btn: !icon || slots['default'] || value,
6
- thin,
7
- round,
8
- 'bgl_flatBtn': flat,
9
- 'bgl_btn-border': border
10
- }">
11
- <div class="loading" v-if="loading" />
12
- <div v-else class="bgl_btn-flex">
13
- <MaterialIcon v-if="icon" :icon="icon" />
14
- <slot />
15
- <template v-if="!slots['default'] && value">
16
- {{ value }}
17
- </template>
18
- <MaterialIcon v-if="props['icon.end']" :icon="props['icon.end']" />
19
- </div>
20
- </component>
2
+ <component
3
+ :is="to ? 'router-link' : is" :to="to" @click.stop="onClick" :type="type" :role="role" :disabled="disabled"
4
+ :class="{
5
+ 'bgl_btn-icon': icon && !slots['default'] && !value,
6
+ bgl_btn: !icon || slots['default'] || value,
7
+ thin,
8
+ round,
9
+ 'bgl_flatBtn': flat,
10
+ 'bgl_btn-border': border
11
+ }"
12
+ >
13
+ <div class="loading" v-if="loading" />
14
+ <div v-else class="bgl_btn-flex">
15
+ <MaterialIcon v-if="icon" :icon="icon" />
16
+ <slot />
17
+ <template v-if="!slots['default'] && value">
18
+ {{ value }}
19
+ </template>
20
+ <MaterialIcon v-if="props['icon.end']" :icon="props['icon.end']" />
21
+ </div>
22
+ </component>
21
23
  </template>
22
24
 
23
25
  <script setup lang="ts">
@@ -28,7 +30,7 @@ import type { MaterialIcons, ThemeType } from '@bagelink/vue';
28
30
  import { MaterialIcon } from '@bagelink/vue';
29
31
 
30
32
  const props = withDefaults(
31
- defineProps<{
33
+ defineProps<{
32
34
  disabled?: boolean;
33
35
  icon?: MaterialIcons;
34
36
  'icon.end'?: MaterialIcons;
@@ -46,59 +48,60 @@ const props = withDefaults(
46
48
  is?: string;
47
49
  onClick?: (e: MouseEvent) => void;
48
50
  }>(),
49
- {
50
- onClick: () => '',
51
- loading: false,
52
- round: false,
53
- disabled: false,
54
- type: 'button',
55
- role: 'button',
56
- is: 'button',
57
- border: false,
58
- },
51
+ {
52
+ onClick: () => '',
53
+ loading: false,
54
+ round: false,
55
+ disabled: false,
56
+ type: 'button',
57
+ role: 'button',
58
+ is: 'button',
59
+ border: false,
60
+ },
59
61
  );
60
62
 
61
63
  const computedTheme = $computed(
62
- () => {
63
- if (props.disabled) return 'gray-light';
64
- return (props?.color || props?.theme);
65
- },
64
+ () => {
65
+ if (props.disabled) return 'gray-light';
66
+ return (props?.color || props?.theme);
67
+ },
66
68
  );
67
69
 
68
70
  const computedDefaultColors = $computed(
69
- () => ({
70
- backgroundColor: 'var(--bgl-primary)',
71
- color: props.flat ? 'var(--bgl-black)' : 'var(--bgl-white)',
72
- }),
71
+ () => ({
72
+ backgroundColor: 'var(--bgl-primary)',
73
+ color: props.flat ? 'var(--bgl-black)' : 'var(--bgl-white)',
74
+ }),
73
75
  );
74
76
 
75
77
  function getThemeColors(theme: Partial<typeof computedDefaultColors>): typeof computedDefaultColors {
76
- return ({
77
- ...computedDefaultColors,
78
- ...theme,
79
- color: props.flat
80
- ? theme.backgroundColor as string
81
- : theme.color as string,
82
- });
78
+ return ({
79
+ ...computedDefaultColors,
80
+ ...theme,
81
+ color: props.flat
82
+ ? theme.backgroundColor as string
83
+ : theme.color as string,
84
+ });
83
85
  }
84
86
 
85
87
  const themes: { [key in ThemeType]: typeof computedDefaultColors } = {
86
- red: getThemeColors({ backgroundColor: 'var(--bgl-red)' }),
87
- black: getThemeColors({ backgroundColor: 'var(--bgl-black)' }),
88
- green: getThemeColors({ backgroundColor: 'var(--bgl-green)', color: 'var(--bgl-white)' }),
89
- primary: getThemeColors({ backgroundColor: 'var(--bgl-primary)', color: 'var(--bgl-white)' }),
90
- gray: getThemeColors({ backgroundColor: 'var(--bgl-gray-light)', color: 'var(--bgl-black)' }),
91
- light: getThemeColors({ backgroundColor: 'var(--bgl-primary-light)', color: 'var(--bgl-primary)' }),
92
- 'gray-light': getThemeColors({ backgroundColor: 'var(--bgl-gray-light)', color: 'var(--bgl-gray)' }),
93
- blue: getThemeColors({}),
88
+ red: getThemeColors({ backgroundColor: 'var(--bgl-red)' }),
89
+ white: getThemeColors({ backgroundColor: 'var(--bgl-white)' }),
90
+ black: getThemeColors({ backgroundColor: 'var(--bgl-black)' }),
91
+ green: getThemeColors({ backgroundColor: 'var(--bgl-green)', color: 'var(--bgl-white)' }),
92
+ primary: getThemeColors({ backgroundColor: 'var(--bgl-primary)', color: 'var(--bgl-white)' }),
93
+ gray: getThemeColors({ backgroundColor: 'var(--bgl-gray-light)', color: 'var(--bgl-black)' }),
94
+ light: getThemeColors({ backgroundColor: 'var(--bgl-primary-light)', color: 'var(--bgl-primary)' }),
95
+ 'gray-light': getThemeColors({ backgroundColor: 'var(--bgl-gray-light)', color: 'var(--bgl-gray)' }),
96
+ blue: getThemeColors({}),
94
97
  };
95
98
 
96
99
  const cumputedTextColor = $computed(
97
- () => (themes?.[computedTheme as ThemeType]?.color || computedDefaultColors.color),
100
+ () => (themes?.[computedTheme as ThemeType]?.color || computedDefaultColors.color),
98
101
  );
99
102
 
100
103
  const computedBackgroundColor = $computed(
101
- () => (themes?.[computedTheme as ThemeType]?.backgroundColor || computedDefaultColors.backgroundColor),
104
+ () => (themes?.[computedTheme as ThemeType]?.backgroundColor || computedDefaultColors.backgroundColor),
102
105
  );
103
106
  </script>
104
107
 
@@ -194,7 +197,7 @@ a {
194
197
 
195
198
  .bgl_btn.bgl_flatBtn:active,
196
199
  .bgl_btn-icon.bgl_flatBtn:active {
197
- background: var(--bgl-white);
200
+ background: var(--bgl-gray);
198
201
  filter: var(--bgl-hover-filter);
199
202
  }
200
203
 
@@ -202,6 +205,10 @@ a {
202
205
  .bgl_btn-icon.bgl_flatBtn.red {
203
206
  color: var(--bgl-red);
204
207
  }
208
+ .bgl_btn.bgl_flatBtn.white,
209
+ .bgl_btn-icon.bgl_flatBtn.white {
210
+ color: var(--bgl-white);
211
+ }
205
212
 
206
213
  .bgl_btn.bgl_flatBtn.light,
207
214
  .bgl_btn-icon.bgl_flatBtn.light {
@@ -1,19 +1,28 @@
1
1
  <template>
2
- <div class="BglCarousel" :style="{ height: yHeight }" :class="{ autoHeight }">
3
- <div :class="{ dragging: isDragging, clicking: isPressed, [`slides-${items}`]: true, allowScroll }"
4
- @scrollend="scrollEnd" @mousedown="startDragging" class="bgl-slider" ref="bglSlider">
5
- <div v-if="isDragging" class="blocker" />
6
- <slot />
7
- </div>
8
- <div class="Handlers">
9
- <span @click="prev">
10
- <slot name="prev" />
11
- </span>
12
- <span @click="next">
13
- <slot name="next" />
14
- </span>
15
- </div>
16
- </div>
2
+ <div class="BglCarousel" :style="{ height: yHeight }" :class="{ autoHeight }">
3
+ <div
4
+ :class="{
5
+ dragging: isDragging,
6
+ clicking: isPressed,
7
+ [`slides-${items}`]: true,
8
+ allowScroll,
9
+ }"
10
+ @scrollend="scrollEnd"
11
+ @mousedown="startDragging"
12
+ class="bgl-slider"
13
+ ref="bglSlider">
14
+ <div v-if="isDragging" class="blocker" />
15
+ <slot />
16
+ </div>
17
+ <div class="Handlers">
18
+ <span @click="prev">
19
+ <slot name="prev" />
20
+ </span>
21
+ <span @click="next">
22
+ <slot name="next" />
23
+ </span>
24
+ </div>
25
+ </div>
17
26
  </template>
18
27
 
19
28
  <script setup lang="ts">
@@ -29,130 +38,137 @@ let isPressed = $ref(false);
29
38
  const emit = defineEmits(['update:index']);
30
39
 
31
40
  const props = defineProps({
32
- autoHeight: {
33
- type: Boolean,
34
- default: false,
35
- },
36
- allowScroll: {
37
- type: Boolean,
38
- default: true,
39
- },
40
- freeDrag: {
41
- type: Boolean,
42
- default: true,
43
- },
44
- items: {
45
- type: Number,
46
- default: 4,
47
- },
48
- index: {
49
- type: Number,
50
- default: 0,
51
- },
41
+ autoHeight: {
42
+ type: Boolean,
43
+ default: false,
44
+ },
45
+ allowScroll: {
46
+ type: Boolean,
47
+ default: true,
48
+ },
49
+ freeDrag: {
50
+ type: Boolean,
51
+ default: true,
52
+ },
53
+ items: {
54
+ type: Number,
55
+ default: 4,
56
+ },
57
+ index: {
58
+ type: Number,
59
+ default: 0,
60
+ },
52
61
  });
53
62
 
54
63
  const disableDrag = () => {
55
- bglSlider?.querySelectorAll('img').forEach((e) => e.setAttribute('draggable', 'false'));
56
-
57
- for (const e of bglSlider?.children as any[] | undefined || []) {
58
- e.setAttribute('draggable', 'false');
59
- e.addEventListener('click', (e: any) => e.preventDefault());
60
- }
64
+ bglSlider
65
+ ?.querySelectorAll('img')
66
+ .forEach((e) => e.setAttribute('draggable', 'false'));
67
+
68
+ for (const e of (bglSlider?.children as any[] | undefined) || []) {
69
+ e.setAttribute('draggable', 'false');
70
+ e.addEventListener('click', (e: any) => e.preventDefault());
71
+ }
61
72
  };
62
73
 
63
74
  let yHeight = $ref('auto');
64
75
  const evalHeight = () => {
65
- if (!props.autoHeight || !bglSlider) return;
66
- const slidChildren = bglSlider.children[activeSlideIndex].children;
67
- const height = Array.from(slidChildren).map((el) => el.clientHeight).reduce((a, b) => a + b, 0);
76
+ if (!props.autoHeight || !bglSlider) return;
77
+ const slidChildren = bglSlider.children[activeSlideIndex].children;
78
+ const height = Array.from(slidChildren)
79
+ .map((el) => el.clientHeight)
80
+ .reduce((a, b) => a + b, 0);
68
81
 
69
- yHeight = `${height}px`;
82
+ yHeight = `${height}px`;
70
83
  };
71
84
 
72
85
  const goToSlide = (index: number) => {
73
- if (!bglSlider || index < 0 || index > bglSlider.children.length - 1) return;
74
-
75
- const slider = bglSlider;
76
- const scrollX = slider.offsetWidth * index;
77
- slider.scrollTo({ left: scrollX, behavior: 'smooth' });
78
-
79
- activeSlideIndex = index;
80
- evalHeight();
86
+ if (!bglSlider || index < 0 || index > bglSlider.children.length - 1) return;
87
+ const slider = bglSlider;
88
+ const isRTL = getComputedStyle(bglSlider).direction === 'rtl';
89
+ const scrollX = slider.offsetWidth * index * (isRTL ? -1 : 1);
90
+ slider.scrollTo({ left: scrollX, behavior: 'smooth' });
91
+ activeSlideIndex = index;
92
+ evalHeight();
81
93
  };
82
94
 
83
95
  watch(() => props.index, goToSlide);
84
96
 
85
- watch(activeSlideIndex, (index) => emit('update:index', index));
97
+ watch(
98
+ () => activeSlideIndex,
99
+ (index) => emit('update:index', index)
100
+ );
86
101
 
87
102
  const scrollEnd = () => {
88
- const slider = bglSlider;
89
- if (!slider || props.items !== 1) return;
90
- const nextSlide = Math.round(slider.scrollLeft / slider.offsetWidth);
91
- goToSlide(nextSlide);
103
+ const slider = bglSlider;
104
+ if (!slider || props.items !== 1) return;
105
+ const nextSlide = Math.round(slider.scrollLeft / slider.offsetWidth);
106
+ goToSlide(nextSlide);
92
107
  };
93
108
 
94
109
  const stopDragging = (e: MouseEvent) => {
95
- isPressed = false;
96
- const slider = bglSlider;
97
- if (!slider) return;
98
- const isDragForward = startX > (e.pageX + slider.offsetLeft);
99
- if (isDragForward) activeSlideIndex = Math.ceil(slider.scrollLeft / slider.offsetWidth);
100
- else activeSlideIndex = Math.floor(slider.scrollLeft / slider.offsetWidth);
101
- if (props.items === 1) goToSlide(activeSlideIndex);
102
- startX = 0;
103
- document.removeEventListener('mousemove', move);
104
- document.removeEventListener('mouseup', stopDragging);
105
- document.removeEventListener('dragend', stopDragging);
106
- setTimeout(() => isDragging = false, 100);
110
+ isPressed = false;
111
+ const slider = bglSlider;
112
+ if (!slider) return;
113
+ const isDragForward = startX > e.pageX + slider.offsetLeft;
114
+ if (isDragForward)
115
+ activeSlideIndex = Math.ceil(slider.scrollLeft / slider.offsetWidth);
116
+ else activeSlideIndex = Math.floor(slider.scrollLeft / slider.offsetWidth);
117
+ if (props.items === 1) goToSlide(activeSlideIndex);
118
+ startX = 0;
119
+ document.removeEventListener('mousemove', move);
120
+ document.removeEventListener('mouseup', stopDragging);
121
+ document.removeEventListener('dragend', stopDragging);
122
+ setTimeout(() => (isDragging = false), 100);
107
123
  };
108
124
 
109
125
  const move = (e: MouseEvent) => {
110
- if (!bglSlider) return;
111
- const x = e.pageX - bglSlider.offsetLeft;
112
- const walk = x - startX;
113
- if (walk > 20 || walk < -20) isDragging = true;
114
- if (!isDragging) return;
115
- const scroll = x - startX;
116
- bglSlider.scrollLeft = scrollLeft - scroll;
126
+ if (!bglSlider) return;
127
+ const x = e.pageX - bglSlider.offsetLeft;
128
+ const walk = x - startX;
129
+ if (walk > 20 || walk < -20) isDragging = true;
130
+ if (!isDragging) return;
131
+ const scroll = x - startX;
132
+ bglSlider.scrollLeft = scrollLeft - scroll;
117
133
  };
118
134
 
119
135
  // eslint-disable-next-line no-unused-vars
120
136
  const startDragging = (e: MouseEvent) => {
121
- if (e.button !== 0 || !props.freeDrag || !bglSlider) return;
122
- startX = e.pageX - bglSlider.offsetLeft;
123
- scrollLeft = bglSlider.scrollLeft;
124
- isPressed = true;
125
- document.addEventListener('mousemove', move);
126
- document.addEventListener('mouseup', stopDragging);
127
- document.addEventListener('dragend', stopDragging);
137
+ if (e.button !== 0 || !props.freeDrag || !bglSlider) return;
138
+ startX = e.pageX - bglSlider.offsetLeft;
139
+ scrollLeft = bglSlider.scrollLeft;
140
+ isPressed = true;
141
+ document.addEventListener('mousemove', move);
142
+ document.addEventListener('mouseup', stopDragging);
143
+ document.addEventListener('dragend', stopDragging);
128
144
  };
129
145
 
130
146
  // eslint-disable-next-line no-unused-vars
131
147
  const next = () => {
132
- if (!bglSlider) return;
133
- const slideCount = bglSlider.children.length;
134
- const isLastSlide = activeSlideIndex >= slideCount - 1;
135
- if (isLastSlide) goToSlide(0);
136
- else goToSlide(activeSlideIndex + 1);
148
+ if (!bglSlider) return;
149
+ const slideCount = bglSlider.children.length;
150
+ const isLastSlide = activeSlideIndex >= slideCount - 1;
151
+ if (isLastSlide) goToSlide(0);
152
+ else goToSlide(activeSlideIndex + 1);
137
153
  };
138
154
 
139
155
  // eslint-disable-next-line no-unused-vars
140
156
  const prev = () => {
141
- if (!bglSlider) return;
142
- const slideCount = bglSlider.children.length;
143
- if (activeSlideIndex === 0) goToSlide(slideCount - 1);
144
- else goToSlide(activeSlideIndex - 1);
157
+ if (!bglSlider) return;
158
+ const slideCount = bglSlider.children.length;
159
+ if (activeSlideIndex === 0) goToSlide(slideCount - 1);
160
+ else goToSlide(activeSlideIndex - 1);
145
161
  };
146
162
 
147
163
  const evalWidth = () => {
148
- if (!bglSlider) return;
149
- goToSlide(activeSlideIndex);
164
+ if (!bglSlider) return;
165
+ goToSlide(activeSlideIndex);
150
166
  };
151
167
 
152
168
  onMounted(() => {
153
- window.addEventListener('resize', evalWidth);
154
- evalHeight();
155
- disableDrag();
169
+ window.addEventListener('resize', evalWidth);
170
+ evalHeight();
171
+ disableDrag();
156
172
  });
157
173
 
158
174
  onUnmounted(() => window.removeEventListener('resize', evalWidth));
@@ -160,99 +176,99 @@ onUnmounted(() => window.removeEventListener('resize', evalWidth));
160
176
 
161
177
  <style scoped>
162
178
  .blocker {
163
- position: fixed;
164
- top: 0;
165
- left: 0;
166
- width: 100%;
167
- height: 100%;
168
- z-index: 100;
179
+ position: fixed;
180
+ top: 0;
181
+ left: 0;
182
+ width: 100%;
183
+ height: 100%;
184
+ z-index: 100;
169
185
  }
170
186
 
171
187
  .bgl-slider {
172
- display: grid;
173
- position: relative;
174
- scroll-behavior: smooth;
175
- grid-auto-flow: column;
176
- grid-auto-columns: 100%;
177
- scroll-snap-type: x mandatory;
178
- overflow-x: hidden;
188
+ display: grid;
189
+ position: relative;
190
+ scroll-behavior: smooth;
191
+ grid-auto-flow: column;
192
+ grid-auto-columns: 100%;
193
+ scroll-snap-type: x mandatory;
194
+ overflow-x: hidden;
179
195
  }
180
196
 
181
197
  .autoHeight {
182
- transition: height ease 0.7s;
198
+ transition: height ease 0.7s;
183
199
  }
184
200
 
185
201
  .bgl-slider.allowScroll {
186
- overflow-x: scroll;
202
+ overflow-x: scroll;
187
203
  }
188
204
 
189
205
  .bgl-slider.slides-6 {
190
- grid-auto-columns: 15.9%;
191
- gap: 1%;
206
+ grid-auto-columns: 15.9%;
207
+ gap: 1%;
192
208
  }
193
209
 
194
210
  .bgl-slider.slides-5 {
195
- grid-auto-columns: 19.3%;
196
- gap: 1%;
211
+ grid-auto-columns: 19.3%;
212
+ gap: 1%;
197
213
  }
198
214
 
199
215
  .bgl-slider.slides-4 {
200
- grid-auto-columns: 24.3%;
201
- gap: 1%;
216
+ grid-auto-columns: 24.3%;
217
+ gap: 1%;
202
218
  }
203
219
 
204
220
  .bgl-slider.slides-3 {
205
- grid-auto-columns: 33%;
206
- gap: 1%;
221
+ grid-auto-columns: 33%;
222
+ gap: 1%;
207
223
  }
208
224
 
209
225
  .bgl-slider.slides-2 {
210
- grid-auto-columns: 50%;
211
- gap: 1%;
226
+ grid-auto-columns: 50%;
227
+ gap: 1%;
212
228
  }
213
229
 
214
230
  .bgl-slider.slides-1 {
215
- grid-auto-columns: 100%;
231
+ grid-auto-columns: 100%;
216
232
  }
217
233
 
218
234
  .bgl-slider::-webkit-scrollbar {
219
- display: none;
235
+ display: none;
220
236
  }
221
237
 
222
238
  .bgl-slider * {
223
- scroll-snap-align: start;
239
+ scroll-snap-align: start;
224
240
  }
225
241
 
226
242
  .dragging.bgl-slider {
227
- cursor: grabbing;
228
- cursor: -webkit-grabbing;
229
- scroll-snap-type: unset;
243
+ cursor: grabbing;
244
+ cursor: -webkit-grabbing;
245
+ scroll-snap-type: unset;
230
246
  }
231
247
 
232
248
  .clicking.bgl-slider {
233
- scroll-behavior: unset;
249
+ scroll-behavior: unset;
234
250
  }
235
251
 
236
252
  .dragging.bgl-slider * {
237
- scroll-snap-align: unset;
238
- user-select: none;
253
+ scroll-snap-align: unset;
254
+ user-select: none;
239
255
  }
240
256
 
241
257
  @media screen and (max-width: 1280px) {
242
- .bgl-slider.slides-4 {
243
- grid-auto-columns: 33%;
244
- }
258
+ .bgl-slider.slides-4 {
259
+ grid-auto-columns: 33%;
260
+ }
245
261
  }
246
262
 
247
263
  @media screen and (max-width: 991px) {
248
- .bgl-slider.slides-4 {
249
- grid-auto-columns: 50%;
250
- }
264
+ .bgl-slider.slides-4 {
265
+ grid-auto-columns: 50%;
266
+ }
251
267
  }
252
268
 
253
269
  @media screen and (max-width: 600px) {
254
- .bgl-slider.slides-4 {
255
- grid-auto-columns: 100%;
256
- }
270
+ .bgl-slider.slides-4 {
271
+ grid-auto-columns: 100%;
272
+ }
257
273
  }
258
274
  </style>
@@ -6,12 +6,12 @@
6
6
  mode="out-in"
7
7
  appear
8
8
  >
9
- <div class="m_overflow-hidden-x">
9
+ <div class="m_overflow-hidden-x">
10
10
  <component
11
11
  :is="Component"
12
12
  :key="route?.params.itemID"
13
13
  />
14
- </div>
14
+ </div>
15
15
  </transition>
16
16
  </router-view>
17
17
  </template>