@bagelink/vue 1.9.81 → 1.9.83

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/vue",
3
3
  "type": "module",
4
- "version": "1.9.81",
4
+ "version": "1.9.83",
5
5
  "description": "Bagel core sdk packages",
6
6
  "author": {
7
7
  "name": "Bagel Studio",
@@ -96,7 +96,6 @@ const svgCircumference = computed(() => Math.PI * 2 * svgRadius.value)
96
96
  .lds-bar {
97
97
  height: var(--thickness, 4px);
98
98
  width: 100%;
99
- max-width: 130px;
100
99
  --c: no-repeat linear-gradient(currentColor 0 0);
101
100
  background: var(--c), var(--c), #ddd;
102
101
  background-size: 60% 100%;
@@ -1,8 +1,9 @@
1
1
  <script setup lang="ts" generic="ContextObjType extends { [key: string]: any }">
2
+ import type { Option } from '@bagelink/vue'
2
3
  import { Btn } from '@bagelink/vue'
3
4
  import { computed, ref, watch } from 'vue'
4
5
 
5
- export interface RadioOption<T> {
6
+ export interface RadioOption<T = any> {
6
7
  imgAlt?: string
7
8
  imgSrc?: string
8
9
  subLabel?: string
@@ -12,7 +13,9 @@ export interface RadioOption<T> {
12
13
  value: any
13
14
  }
14
15
 
15
- type RadioOptionsSource<T> = RadioOption<T>[] | (() => Promise<RadioOption<T>[]>)
16
+ type NormalizedRadioOption<T> = Required<Pick<RadioOption<T>, 'value'>> & Omit<RadioOption<T>, 'value'>
17
+
18
+ type RadioOptionsSource<T> = (Option | RadioOption<T>)[] | (() => Promise<(Option | RadioOption<T>)[]>)
16
19
 
17
20
  const props = withDefaults(
18
21
  defineProps<{
@@ -41,6 +44,13 @@ const props = withDefaults(
41
44
 
42
45
  const emit = defineEmits(['delete', 'focus', 'blur', 'change'])
43
46
 
47
+ function normalizeOption<T>(opt: Option | RadioOption<T>): NormalizedRadioOption<T> {
48
+ if (typeof opt === 'string') { return { label: opt, value: opt } }
49
+ if (typeof opt === 'number') { return { label: `${opt}`, value: opt } }
50
+ if (typeof opt === 'boolean') { return { label: `${opt}`, value: opt } }
51
+ return opt as NormalizedRadioOption<T>
52
+ }
53
+
44
54
  const name = computed(
45
55
  () => (
46
56
  props.groupName
@@ -49,8 +59,11 @@ const name = computed(
49
59
  )
50
60
  )
51
61
  const selectedOption = defineModel('modelValue')
52
- const loadedOptions = ref<any[]>([])
53
- const visibleOptions = computed(() => Array.isArray(props.options) ? (props.options as any[]) : (loadedOptions.value as any[]))
62
+ const loadedOptions = ref<(Option | RadioOption<ContextObjType>)[]>([])
63
+ const visibleOptions = computed<NormalizedRadioOption<ContextObjType>[]>(() => {
64
+ const raw = Array.isArray(props.options) ? props.options : loadedOptions.value
65
+ return raw.map(opt => normalizeOption<ContextObjType>(opt))
66
+ })
54
67
 
55
68
  async function loadOptionsIfNeeded() {
56
69
  if (typeof props.options === 'function') {
@@ -93,8 +106,7 @@ function handleChange() {
93
106
  <div :class="containerClasses">
94
107
  <label
95
108
  v-for="(opt, index) in visibleOptions" :key="opt.id || `${name}-${index}`"
96
- class="border rounded flex active-list-item hover"
97
- :for="opt.id || `${name}-${index}`"
109
+ class="border rounded flex active-list-item hover" :for="opt.id || `${name}-${index}`"
98
110
  :class="{ 'p-05 gap-025': thin, 'py-1 gap-075': !thin, 'ps-05': !hideRadio, 'bg-gray-light': !bgColor && !flat, 'align-items-start': align === 'start' || align === 'top', 'align-items-center': align === 'center', 'align-items-end': align === 'end' || align === 'bottom', invertedActive }"
99
111
  :style="{ backgroundColor: bgColor, borderColor }"
100
112
  >
@@ -104,9 +116,7 @@ function handleChange() {
104
116
  'mt-025': align === 'start' || align === 'top',
105
117
  'mb-025': align === 'end' || align === 'bottom',
106
118
  'hideRadio': hideRadio,
107
- }" @focus="handleFocus"
108
- @blur="handleBlur"
109
- @change="handleChange"
119
+ }" @focus="handleFocus" @blur="handleBlur" @change="handleChange"
110
120
  >
111
121
  <div
112
122
  class="flex w-100 gap-1 flex-wrap m_gap-05 m_gap-row-025"
@@ -114,8 +124,8 @@ function handleChange() {
114
124
  :style="{ color: textColor }"
115
125
  >
116
126
  <img
117
- v-if="opt.imgSrc" class="bg-popup shadow-light py-025 radius-05 m_w40" height="40" :src="opt.imgSrc"
118
- :alt="opt.imgAlt"
127
+ v-if="opt.imgSrc" class="py-025 radius-05 m_w40 object-fit" height="40" width="40"
128
+ :src="opt.imgSrc" :alt="opt.imgAlt"
119
129
  >
120
130
  <div class="">
121
131
  <div v-if="opt.label" class="m-0 m_txt-14 line-height-14" v-html="opt.label" />
@@ -132,11 +142,12 @@ function handleChange() {
132
142
  .hideRadio.radio-input-list {
133
143
  display: none !important;
134
144
  }
145
+
135
146
  .radio-input-list {
136
147
  width: auto;
137
148
  transform: scale(1.2);
138
- margin-inline-end: 0.5rem;
139
- margin-top: 0;
149
+ margin-inline-end: 0.5rem;
150
+ margin-top: 0;
140
151
  }
141
152
 
142
153
  .radio-input-list.hidden {