mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-25 01:06:15 -04:00
feat(new tool): ULID generator (#623)
This commit is contained in:
parent
557b30426f
commit
5c4d775e2d
11 changed files with 174 additions and 1 deletions
14
src/ui/c-buttons-select/c-buttons-select.demo.vue
Normal file
14
src/ui/c-buttons-select/c-buttons-select.demo.vue
Normal file
|
@ -0,0 +1,14 @@
|
|||
<script setup lang="ts">
|
||||
const optionsA = [
|
||||
{ label: 'Option A', value: 'a' },
|
||||
{ label: 'Option B', value: 'b', tooltip: 'This is a tooltip' },
|
||||
{ label: 'Option C', value: '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 />
|
||||
</template>
|
5
src/ui/c-buttons-select/c-buttons-select.types.ts
Normal file
5
src/ui/c-buttons-select/c-buttons-select.types.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
import type { CSelectOption } from '../c-select/c-select.types';
|
||||
|
||||
export type CButtonSelectOption<T> = CSelectOption<T> & {
|
||||
tooltip?: string
|
||||
};
|
59
src/ui/c-buttons-select/c-buttons-select.vue
Normal file
59
src/ui/c-buttons-select/c-buttons-select.vue
Normal file
|
@ -0,0 +1,59 @@
|
|||
<script setup lang="ts" generic="T extends unknown">
|
||||
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[]
|
||||
value?: T
|
||||
size?: 'small' | 'medium' | 'large'
|
||||
} & CLabelProps >(),
|
||||
{
|
||||
options: () => [],
|
||||
value: undefined,
|
||||
labelPosition: 'left',
|
||||
size: 'medium',
|
||||
},
|
||||
);
|
||||
|
||||
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 };
|
||||
}
|
||||
|
||||
return option;
|
||||
});
|
||||
});
|
||||
|
||||
const value = useVModel(props, 'value', emits);
|
||||
|
||||
function selectOption(option: CButtonSelectOption<T>) {
|
||||
// @ts-expect-error vue template generic is a bit flacky thanks to withDefaults
|
||||
value.value = option.value;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-label v-bind="props">
|
||||
<div class="flex gap-2">
|
||||
<c-tooltip
|
||||
v-for="option in options" :key="option.value"
|
||||
:tooltip="option.tooltip"
|
||||
>
|
||||
<c-button
|
||||
:test-id="option.value"
|
||||
:size="size"
|
||||
:type="option.value === value ? 'primary' : 'default'"
|
||||
@click="selectOption(option)"
|
||||
>
|
||||
{{ option.label }}
|
||||
</c-button>
|
||||
</c-tooltip>
|
||||
</div>
|
||||
</c-label>
|
||||
</template>
|
|
@ -13,6 +13,7 @@ const isTargetHovered = useElementHover(targetRef);
|
|||
</div>
|
||||
|
||||
<div
|
||||
v-if="tooltip || $slots.tooltip"
|
||||
class="absolute bottom-100% left-50% z-10 mb-5px whitespace-nowrap rounded bg-black px-12px py-6px text-sm text-white shadow-lg transition transition transition-duration-0.2s -translate-x-1/2"
|
||||
:class="{
|
||||
'op-0 scale-0': isTargetHovered === false,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue