74 lines
1.5 KiB
Vue
74 lines
1.5 KiB
Vue
<script setup lang="ts" generic="T extends string">
|
|
defineProps<{
|
|
options: Array<{ value: T; label: string; icon?: 'grid' | 'list' }>;
|
|
}>();
|
|
|
|
const model = defineModel<T>({ required: true });
|
|
</script>
|
|
|
|
<template>
|
|
<div class="ui-seg" role="group">
|
|
<button
|
|
v-for="opt in options"
|
|
:key="opt.value"
|
|
type="button"
|
|
class="seg"
|
|
:class="{ on: model === opt.value }"
|
|
:aria-pressed="model === opt.value"
|
|
@click="model = opt.value"
|
|
>
|
|
<slot name="icon" :option="opt" />
|
|
<span class="seg-label">{{ opt.label }}</span>
|
|
</button>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.ui-seg {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
min-height: var(--control-h);
|
|
padding: 3px;
|
|
gap: 2px;
|
|
background: #e8eef1;
|
|
border-radius: var(--radius);
|
|
max-width: 100%;
|
|
overflow-x: auto;
|
|
scrollbar-width: none;
|
|
}
|
|
|
|
.ui-seg::-webkit-scrollbar {
|
|
display: none;
|
|
}
|
|
|
|
.seg {
|
|
flex: 0 0 auto;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 0.35rem;
|
|
min-height: calc(var(--control-h) - 6px);
|
|
padding: 0 0.75rem;
|
|
border: 0;
|
|
border-radius: calc(var(--radius) - 2px);
|
|
background: transparent;
|
|
color: #7b8794;
|
|
font: inherit;
|
|
font-weight: 700;
|
|
font-size: 0.82rem;
|
|
cursor: pointer;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.seg.on {
|
|
background: #fff;
|
|
color: var(--accent-deep);
|
|
box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
|
|
}
|
|
|
|
.seg:focus-visible {
|
|
outline: 2px solid var(--accent);
|
|
outline-offset: 1px;
|
|
}
|
|
</style>
|