sprintify-ui 0.0.148 → 0.0.150

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": "sprintify-ui",
3
- "version": "0.0.148",
3
+ "version": "0.0.150",
4
4
  "scripts": {
5
5
  "build": "rimraf dist && vue-tsc && vite build",
6
6
  "build-fast": "rimraf dist && vite build",
@@ -9,7 +9,7 @@ export default {
9
9
  const Template = (args) => ({
10
10
  components: { BaseIconPicker, ShowValue },
11
11
  setup() {
12
- const value = ref(null);
12
+ const value = ref('heroicons:user-group-solid');
13
13
  return { args, value };
14
14
  },
15
15
  template: `
@@ -4,7 +4,6 @@
4
4
  <select
5
5
  v-model="suffix"
6
6
  class="max-w-[80px] shrink-0 rounded-l border-r-0 border-slate-300 text-xs focus:border-slate-300 focus:outline-none focus:ring-0"
7
- @change="scrollTop"
8
7
  >
9
8
  <option v-for="(label, key) in suffixes" :key="key" :value="key">
10
9
  {{ label }}
@@ -24,6 +23,7 @@
24
23
  <li v-for="icon in filteredIcons" :key="icon">
25
24
  <button
26
25
  type="button"
26
+ :data-icon="icon"
27
27
  :class="[
28
28
  modelValue == icon
29
29
  ? 'bg-primary-600 text-white'
@@ -41,7 +41,7 @@
41
41
  </template>
42
42
 
43
43
  <script lang="ts" setup>
44
- import { BaseIcon, config } from '..';
44
+ import { BaseIcon } from '..';
45
45
 
46
46
  const props = withDefaults(
47
47
  defineProps<{
@@ -117,17 +117,64 @@ function fetchIcons() {
117
117
  fetch('https://api.iconify.design/collection?prefix=' + props.collection)
118
118
  .then((response) => response.json())
119
119
  .then((data) => {
120
+ // Set icons
120
121
  icons.value = data.uncategorized;
122
+
123
+ // Set suffix list
121
124
  suffixes.value = data.suffixes;
122
- suffix.value = Object.keys(suffixes.value)[0] as string;
125
+
126
+ // Set suffix
127
+ selectCurrentSuffix();
128
+
129
+ // Scroll to icon
130
+
131
+ nextTick(() => {
132
+ scrollToIcon();
133
+ });
123
134
  });
124
135
  }
125
136
 
126
- fetchIcons();
137
+ function selectCurrentSuffix() {
138
+ if (!props.modelValue) {
139
+ return;
140
+ }
127
141
 
128
- function scrollTop() {
129
- if (drawer.value) {
130
- drawer.value.scrollTop = 0;
142
+ const suffixesOrderedByLength = Object.keys(suffixes.value).sort((a, b) => {
143
+ return b.length - a.length;
144
+ });
145
+
146
+ for (let i = 0; i < suffixesOrderedByLength.length; i++) {
147
+ const s = suffixesOrderedByLength[i];
148
+
149
+ if (props.modelValue.endsWith(s)) {
150
+ suffix.value = s;
151
+
152
+ return;
153
+ }
131
154
  }
132
155
  }
156
+
157
+ function scrollToIcon() {
158
+ if (!drawer.value) {
159
+ return;
160
+ }
161
+
162
+ if (!props.modelValue) {
163
+ return;
164
+ }
165
+
166
+ const icon = drawer.value.querySelector(
167
+ 'button[data-icon="' + props.modelValue + '"]'
168
+ ) as HTMLElement | null;
169
+
170
+ if (!icon) {
171
+ return;
172
+ }
173
+
174
+ drawer.value.scrollTop = icon.offsetTop - 10;
175
+ }
176
+
177
+ onMounted(() => {
178
+ fetchIcons();
179
+ });
133
180
  </script>
@@ -233,18 +233,25 @@ function onKeydown(e: KeyboardEvent) {
233
233
  emit('keydown', e);
234
234
  }
235
235
 
236
+ const defaultValue = computed<number>(() => {
237
+ return Math.max(0, props.min ?? 0);
238
+ });
239
+
236
240
  function updateInternalValueToRealValue() {
237
241
  if (realValueInternal.value === null) {
238
242
  valueInternal.value = '';
239
243
  return;
240
244
  }
241
- valueInternal.value = round(realValueInternal.value ?? 0, precision.value);
245
+ valueInternal.value = round(
246
+ realValueInternal.value ?? defaultValue.value,
247
+ precision.value
248
+ );
242
249
  }
243
250
 
244
251
  function increment() {
245
252
  if (props.disabled) return;
246
253
  if (realValueInternal.value === null) {
247
- valueInternal.value = 0;
254
+ valueInternal.value = defaultValue.value;
248
255
  } else {
249
256
  const newValue = round(
250
257
  realValueInternal.value + props.step,
@@ -260,7 +267,7 @@ function increment() {
260
267
  function decrement() {
261
268
  if (props.disabled) return;
262
269
  if (realValueInternal.value === null) {
263
- valueInternal.value = 0;
270
+ valueInternal.value = defaultValue.value;
264
271
  } else {
265
272
  const newValue = round(
266
273
  realValueInternal.value - props.step,