From 38586caab78c3ae18fefe04886ee1195feb2b236 Mon Sep 17 00:00:00 2001
From: Corentin THOMASSET <corentin.thomasset74@gmail.com>
Date: Mon, 13 Nov 2023 22:38:01 +0100
Subject: refactor(uuid generator): uuid version picker (#751)

---
 src/ui/c-buttons-select/c-buttons-select.vue | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

(limited to 'src/ui/c-buttons-select/c-buttons-select.vue')

diff --git a/src/ui/c-buttons-select/c-buttons-select.vue b/src/ui/c-buttons-select/c-buttons-select.vue
index 38fff66..a1ffa42 100644
--- a/src/ui/c-buttons-select/c-buttons-select.vue
+++ b/src/ui/c-buttons-select/c-buttons-select.vue
@@ -1,10 +1,11 @@
 <script setup lang="ts" generic="T extends unknown">
+import _ from 'lodash';
 import type { CLabelProps } from '../c-label/c-label.types';
 import type { CButtonSelectOption } from './c-buttons-select.types';
 
 const props = withDefaults(
   defineProps<{
-    options?: CButtonSelectOption<T>[] | string[]
+    options?: CButtonSelectOption<T>[] | string[] | Record<string, T>
     value?: T
     size?: 'small' | 'medium' | 'large'
   } & CLabelProps >(),
@@ -20,14 +21,18 @@ const emits = defineEmits(['update:value']);
 
 const { options: rawOptions, size } = toRefs(props);
 
-const options = computed(() => {
-  return rawOptions.value.map((option: string | CButtonSelectOption<T>) => {
-    if (typeof option === 'string') {
-      return { label: option, value: option };
-    }
+const options = computed<CButtonSelectOption<T>[]>(() => {
+  if (_.isArray(rawOptions.value)) {
+    return rawOptions.value.map((option: string | CButtonSelectOption<T>) => {
+      if (typeof option === 'string') {
+        return { label: option, value: option };
+      }
 
-    return option;
-  });
+      return option;
+    }) as CButtonSelectOption<T>[];
+  }
+
+  return _.map(rawOptions.value, (value, label) => ({ label, value })) as CButtonSelectOption<T>[];
 });
 
 const value = useVModel(props, 'value', emits);
-- 
cgit v1.2.3

