mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-25 01:06:15 -04:00
refactor(uuid generator): uuid version picker (#751)
This commit is contained in:
parent
043e4f0a08
commit
38586caab7
4 changed files with 102 additions and 18 deletions
|
@ -4,11 +4,18 @@ const optionsA = [
|
|||
{ label: 'Option B', value: 'b', tooltip: 'This is a tooltip' },
|
||||
{ label: 'Option C', value: 'c' },
|
||||
];
|
||||
|
||||
const optionB = {
|
||||
'Option A': 'a',
|
||||
'Option B': 'b',
|
||||
'Option C': 'c',
|
||||
};
|
||||
|
||||
const valueA = ref('a');
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-buttons-select v-model:value="valueA" :options="optionsA" label="Label: " />
|
||||
<c-buttons-select v-model:value="valueA" :options="optionsA" label="Label: " label-position="left" mt-2 />
|
||||
<c-buttons-select v-model:value="valueA" :options="optionsA" label="Label: " label-position="left" mt-2 />
|
||||
<c-buttons-select v-model:value="valueA" :options="optionB" label="Options object: " />
|
||||
</template>
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue