mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-17 20:52:14 +01:00
add combobox to ui package
This commit is contained in:
25
resources/js/packages/ui/src/combobox/Combobox.vue
Normal file
25
resources/js/packages/ui/src/combobox/Combobox.vue
Normal file
@@ -0,0 +1,25 @@
|
||||
<script setup lang="ts">
|
||||
import type { ComboboxRootEmits, ComboboxRootProps } from 'reka-ui';
|
||||
import type { HTMLAttributes } from 'vue';
|
||||
import { reactiveOmit } from '@vueuse/core';
|
||||
import { ComboboxRoot, useForwardPropsEmits } from 'reka-ui';
|
||||
import { cn } from '../utils/cn';
|
||||
|
||||
const props = defineProps<ComboboxRootProps & { class?: HTMLAttributes['class'] }>();
|
||||
const emits = defineEmits<ComboboxRootEmits>();
|
||||
|
||||
const delegatedProps = reactiveOmit(props, 'class');
|
||||
|
||||
const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- Keep the trigger inside this root. Reka treats anything within the root
|
||||
element as "not outside", so it suppresses its own dismissal for trigger
|
||||
clicks and ComboboxInput's blur-close ignores them. Putting the trigger
|
||||
in a separate Popover instead gives two competing open states, and the
|
||||
popover then closes on mousedown and reopens on the following click. -->
|
||||
<ComboboxRoot v-slot="slotProps" v-bind="forwarded" :class="cn('min-w-0', props.class)">
|
||||
<slot v-bind="slotProps" />
|
||||
</ComboboxRoot>
|
||||
</template>
|
||||
19
resources/js/packages/ui/src/combobox/ComboboxAnchor.vue
Normal file
19
resources/js/packages/ui/src/combobox/ComboboxAnchor.vue
Normal file
@@ -0,0 +1,19 @@
|
||||
<script setup lang="ts">
|
||||
import type { ComboboxAnchorProps } from 'reka-ui';
|
||||
import type { HTMLAttributes } from 'vue';
|
||||
import { reactiveOmit } from '@vueuse/core';
|
||||
import { ComboboxAnchor, useForwardProps } from 'reka-ui';
|
||||
import { cn } from '../utils/cn';
|
||||
|
||||
const props = defineProps<ComboboxAnchorProps & { class?: HTMLAttributes['class'] }>();
|
||||
|
||||
const delegatedProps = reactiveOmit(props, 'class');
|
||||
|
||||
const forwarded = useForwardProps(delegatedProps);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ComboboxAnchor v-bind="forwarded" :class="cn('w-full', props.class)">
|
||||
<slot />
|
||||
</ComboboxAnchor>
|
||||
</template>
|
||||
35
resources/js/packages/ui/src/combobox/ComboboxInput.vue
Normal file
35
resources/js/packages/ui/src/combobox/ComboboxInput.vue
Normal file
@@ -0,0 +1,35 @@
|
||||
<script setup lang="ts">
|
||||
import type { ComboboxInputEmits, ComboboxInputProps } from 'reka-ui';
|
||||
import type { HTMLAttributes } from 'vue';
|
||||
import { reactiveOmit } from '@vueuse/core';
|
||||
import { Search } from '@lucide/vue';
|
||||
import { ComboboxInput, useForwardPropsEmits } from 'reka-ui';
|
||||
import { cn } from '../utils/cn';
|
||||
|
||||
defineOptions({
|
||||
inheritAttrs: false,
|
||||
});
|
||||
|
||||
const props = defineProps<ComboboxInputProps & { class?: HTMLAttributes['class'] }>();
|
||||
const emits = defineEmits<ComboboxInputEmits>();
|
||||
|
||||
const delegatedProps = reactiveOmit(props, 'class');
|
||||
|
||||
const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="relative items-center border-b border-card-background-separator">
|
||||
<ComboboxInput
|
||||
v-bind="{ ...$attrs, ...forwarded }"
|
||||
:class="
|
||||
cn(
|
||||
'h-10 w-full border-0 rounded-none bg-transparent pl-9 pr-3 text-sm text-text-primary placeholder:text-text-tertiary focus:outline-none focus:ring-0',
|
||||
props.class
|
||||
)
|
||||
" />
|
||||
<span class="absolute start-0 inset-y-0 flex items-center justify-center px-3">
|
||||
<Search class="size-4 text-text-tertiary" />
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
27
resources/js/packages/ui/src/combobox/ComboboxItem.vue
Normal file
27
resources/js/packages/ui/src/combobox/ComboboxItem.vue
Normal file
@@ -0,0 +1,27 @@
|
||||
<script setup lang="ts">
|
||||
import type { ComboboxItemEmits, ComboboxItemProps } from 'reka-ui';
|
||||
import type { HTMLAttributes } from 'vue';
|
||||
import { reactiveOmit } from '@vueuse/core';
|
||||
import { ComboboxItem, useForwardPropsEmits } from 'reka-ui';
|
||||
import { cn } from '../utils/cn';
|
||||
|
||||
const props = defineProps<ComboboxItemProps & { class?: HTMLAttributes['class'] }>();
|
||||
const emits = defineEmits<ComboboxItemEmits>();
|
||||
|
||||
const delegatedProps = reactiveOmit(props, 'class');
|
||||
|
||||
const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ComboboxItem
|
||||
v-bind="forwarded"
|
||||
:class="
|
||||
cn(
|
||||
'flex w-full cursor-default items-center rounded-md px-2 py-1.5 text-sm text-text-primary data-[highlighted]:bg-card-background-active',
|
||||
props.class
|
||||
)
|
||||
">
|
||||
<slot />
|
||||
</ComboboxItem>
|
||||
</template>
|
||||
41
resources/js/packages/ui/src/combobox/ComboboxList.vue
Normal file
41
resources/js/packages/ui/src/combobox/ComboboxList.vue
Normal file
@@ -0,0 +1,41 @@
|
||||
<script setup lang="ts">
|
||||
import type { ComboboxContentEmits, ComboboxContentProps } from 'reka-ui';
|
||||
import type { HTMLAttributes } from 'vue';
|
||||
import { reactiveOmit } from '@vueuse/core';
|
||||
import { ComboboxContent, ComboboxPortal, useForwardPropsEmits } from 'reka-ui';
|
||||
import { cn } from '../utils/cn';
|
||||
|
||||
defineOptions({
|
||||
inheritAttrs: false,
|
||||
});
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<ComboboxContentProps & { class?: HTMLAttributes['class'] }>(),
|
||||
{
|
||||
position: 'popper',
|
||||
align: 'start',
|
||||
sideOffset: 4,
|
||||
class: undefined,
|
||||
}
|
||||
);
|
||||
const emits = defineEmits<ComboboxContentEmits>();
|
||||
|
||||
const delegatedProps = reactiveOmit(props, 'class');
|
||||
|
||||
const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ComboboxPortal>
|
||||
<ComboboxContent
|
||||
v-bind="{ ...$attrs, ...forwarded }"
|
||||
:class="
|
||||
cn(
|
||||
'z-50 w-[--reka-popper-anchor-width] min-w-60 overflow-hidden rounded-lg border border-popover-border bg-popover text-popover-foreground shadow-dropdown outline-none origin-[var(--reka-combobox-content-transform-origin)] data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
|
||||
props.class
|
||||
)
|
||||
">
|
||||
<slot />
|
||||
</ComboboxContent>
|
||||
</ComboboxPortal>
|
||||
</template>
|
||||
19
resources/js/packages/ui/src/combobox/ComboboxSeparator.vue
Normal file
19
resources/js/packages/ui/src/combobox/ComboboxSeparator.vue
Normal file
@@ -0,0 +1,19 @@
|
||||
<script setup lang="ts">
|
||||
import type { ComboboxSeparatorProps } from 'reka-ui';
|
||||
import type { HTMLAttributes } from 'vue';
|
||||
import { reactiveOmit } from '@vueuse/core';
|
||||
import { ComboboxSeparator, useForwardProps } from 'reka-ui';
|
||||
import { cn } from '../utils/cn';
|
||||
|
||||
const props = defineProps<ComboboxSeparatorProps & { class?: HTMLAttributes['class'] }>();
|
||||
|
||||
const delegatedProps = reactiveOmit(props, 'class');
|
||||
|
||||
const forwarded = useForwardProps(delegatedProps);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ComboboxSeparator
|
||||
v-bind="forwarded"
|
||||
:class="cn('my-1 h-px bg-card-background-separator', props.class)" />
|
||||
</template>
|
||||
29
resources/js/packages/ui/src/combobox/ComboboxTrigger.vue
Normal file
29
resources/js/packages/ui/src/combobox/ComboboxTrigger.vue
Normal file
@@ -0,0 +1,29 @@
|
||||
<script setup lang="ts">
|
||||
import type { ComboboxTriggerProps } from 'reka-ui';
|
||||
import type { HTMLAttributes } from 'vue';
|
||||
import { reactiveOmit } from '@vueuse/core';
|
||||
import { ComboboxTrigger, useForwardProps } from 'reka-ui';
|
||||
import { cn } from '../utils/cn';
|
||||
|
||||
const props = defineProps<ComboboxTriggerProps & { class?: HTMLAttributes['class'] }>();
|
||||
|
||||
const delegatedProps = reactiveOmit(props, 'class');
|
||||
|
||||
const forwarded = useForwardProps(delegatedProps);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- Reka hardcodes tabindex="-1" here because it expects a ComboboxInput
|
||||
next to the trigger in the anchor to be the focusable control. Our input
|
||||
lives inside ComboboxList, so this trigger is the control and has to be
|
||||
tabbable. tabindex is a fallthrough attr, which Vue applies after Reka's
|
||||
own props and therefore wins.
|
||||
|
||||
Reka also hardcodes aria-label="Show popup", which would otherwise be
|
||||
the accessible name. Pass :aria-label on the child element (it wins
|
||||
again, because Slot merges child props over attrs) to name the trigger
|
||||
after its current value. -->
|
||||
<ComboboxTrigger v-bind="forwarded" :class="cn(props.class)" tabindex="0">
|
||||
<slot />
|
||||
</ComboboxTrigger>
|
||||
</template>
|
||||
38
resources/js/packages/ui/src/combobox/ComboboxViewport.vue
Normal file
38
resources/js/packages/ui/src/combobox/ComboboxViewport.vue
Normal file
@@ -0,0 +1,38 @@
|
||||
<script setup lang="ts">
|
||||
import type { ComboboxViewportProps } from 'reka-ui';
|
||||
import type { HTMLAttributes } from 'vue';
|
||||
import { reactiveOmit } from '@vueuse/core';
|
||||
import { ComboboxViewport, useForwardProps } from 'reka-ui';
|
||||
import { cn } from '../utils/cn';
|
||||
|
||||
const props = defineProps<ComboboxViewportProps & { class?: HTMLAttributes['class'] }>();
|
||||
|
||||
const delegatedProps = reactiveOmit(props, 'class');
|
||||
|
||||
const forwarded = useForwardProps(delegatedProps);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ComboboxViewport
|
||||
v-bind="forwarded"
|
||||
:class="cn('ui-combobox-viewport max-h-60 overflow-y-auto p-2', props.class)">
|
||||
<slot />
|
||||
</ComboboxViewport>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
/* Reka's ComboboxViewport injects a global style that hides scrollbars; the
|
||||
attribute+class selector below is more specific and restores them. */
|
||||
[data-reka-combobox-viewport].ui-combobox-viewport {
|
||||
scrollbar-width: thin;
|
||||
-ms-overflow-style: auto;
|
||||
}
|
||||
[data-reka-combobox-viewport].ui-combobox-viewport::-webkit-scrollbar {
|
||||
display: block;
|
||||
width: 8px;
|
||||
}
|
||||
[data-reka-combobox-viewport].ui-combobox-viewport::-webkit-scrollbar-thumb {
|
||||
background-color: rgb(127 127 127 / 0.4);
|
||||
border-radius: 4px;
|
||||
}
|
||||
</style>
|
||||
9
resources/js/packages/ui/src/combobox/index.ts
Normal file
9
resources/js/packages/ui/src/combobox/index.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export { default as Combobox } from './Combobox.vue';
|
||||
export { default as ComboboxAnchor } from './ComboboxAnchor.vue';
|
||||
export { default as ComboboxInput } from './ComboboxInput.vue';
|
||||
export { default as ComboboxItem } from './ComboboxItem.vue';
|
||||
export { default as ComboboxList } from './ComboboxList.vue';
|
||||
export { default as ComboboxSeparator } from './ComboboxSeparator.vue';
|
||||
export { default as ComboboxTrigger } from './ComboboxTrigger.vue';
|
||||
export { default as ComboboxViewport } from './ComboboxViewport.vue';
|
||||
export { ComboboxVirtualizer } from 'reka-ui';
|
||||
@@ -57,6 +57,16 @@ import {
|
||||
CalendarNextButton,
|
||||
CalendarPrevButton,
|
||||
} from './calendar/index';
|
||||
import {
|
||||
Combobox,
|
||||
ComboboxAnchor,
|
||||
ComboboxInput,
|
||||
ComboboxItem,
|
||||
ComboboxList,
|
||||
ComboboxSeparator,
|
||||
ComboboxTrigger,
|
||||
ComboboxViewport,
|
||||
} from './combobox/index';
|
||||
import { CommandPalette } from './CommandPalette/index';
|
||||
import {
|
||||
ContextMenu,
|
||||
@@ -176,6 +186,14 @@ export {
|
||||
CardTitle,
|
||||
Checkbox,
|
||||
color,
|
||||
Combobox,
|
||||
ComboboxAnchor,
|
||||
ComboboxInput,
|
||||
ComboboxItem,
|
||||
ComboboxList,
|
||||
ComboboxSeparator,
|
||||
ComboboxTrigger,
|
||||
ComboboxViewport,
|
||||
CommandPalette,
|
||||
ContextMenu,
|
||||
ContextMenuCheckboxItem,
|
||||
|
||||
Reference in New Issue
Block a user