@aerogel/core 0.1.1-next.9bd06e629f34098543a54bdb87e8996767876d42 → 0.1.1-next.a5ae42367ffcf6545e59e5c2abda58718cbab59b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/aerogel-core.d.ts +371 -89
  2. package/dist/aerogel-core.js +1635 -1291
  3. package/dist/aerogel-core.js.map +1 -1
  4. package/package.json +2 -1
  5. package/src/components/AppLayout.vue +1 -1
  6. package/src/components/AppOverlays.vue +1 -1
  7. package/src/components/contracts/Button.ts +1 -1
  8. package/src/components/contracts/Combobox.ts +7 -0
  9. package/src/components/contracts/Modal.ts +2 -0
  10. package/src/components/contracts/Select.ts +89 -2
  11. package/src/components/contracts/Toast.ts +1 -1
  12. package/src/components/contracts/index.ts +1 -0
  13. package/src/components/headless/HeadlessInputInput.vue +13 -5
  14. package/src/components/headless/HeadlessModal.vue +3 -12
  15. package/src/components/headless/HeadlessModalContent.vue +1 -1
  16. package/src/components/headless/HeadlessSelect.vue +6 -91
  17. package/src/components/headless/HeadlessSelectOption.vue +1 -5
  18. package/src/components/index.ts +1 -0
  19. package/src/components/ui/AdvancedOptions.vue +4 -13
  20. package/src/components/ui/Button.vue +1 -0
  21. package/src/components/ui/Combobox.vue +56 -0
  22. package/src/components/ui/ComboboxLabel.vue +29 -0
  23. package/src/components/ui/ComboboxOption.vue +46 -0
  24. package/src/components/ui/ComboboxOptions.vue +71 -0
  25. package/src/components/ui/ComboboxTrigger.vue +63 -0
  26. package/src/components/ui/Details.vue +33 -0
  27. package/src/components/ui/Input.vue +12 -4
  28. package/src/components/ui/LoadingModal.vue +1 -2
  29. package/src/components/ui/Modal.vue +32 -13
  30. package/src/components/ui/ProgressBar.vue +16 -2
  31. package/src/components/ui/SettingsModal.vue +1 -1
  32. package/src/components/ui/Toast.vue +1 -0
  33. package/src/components/ui/index.ts +6 -0
  34. package/src/components/vue/Provide.vue +11 -0
  35. package/src/components/vue/index.ts +1 -0
  36. package/src/errors/Errors.ts +4 -0
  37. package/src/forms/FormController.ts +4 -0
  38. package/src/index.css +10 -0
  39. package/src/services/App.state.ts +1 -0
  40. package/src/services/App.ts +4 -0
  41. package/src/services/index.ts +5 -0
  42. package/src/ui/UI.ts +2 -2
  43. package/src/ui/index.ts +1 -11
  44. package/src/ui/modals.ts +36 -0
  45. package/src/utils/index.ts +1 -0
  46. package/src/utils/time.ts +2 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aerogel/core",
3
- "version": "0.1.1-next.9bd06e629f34098543a54bdb87e8996767876d42",
3
+ "version": "0.1.1-next.a5ae42367ffcf6545e59e5c2abda58718cbab59b",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "exports": {
@@ -35,6 +35,7 @@
35
35
  "clsx": "^2.1.1",
36
36
  "dompurify": "^3.2.4",
37
37
  "eruda": "^3.4.1",
38
+ "eruda-indexeddb": "^0.1.1",
38
39
  "marked": "^15.0.7",
39
40
  "pinia": "^2.1.6",
40
41
  "reka-ui": "^2.2.0",
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div class="flex min-h-full flex-col text-base leading-tight font-normal text-gray-900 antialiased">
2
+ <div class="text-primary-text flex min-h-full flex-col text-base leading-tight font-normal antialiased">
3
3
  <slot v-if="$errors.hasStartupErrors" name="startup-crash">
4
4
  <component :is="$ui.requireComponent('startup-crash')" />
5
5
  </slot>
@@ -4,7 +4,7 @@
4
4
  </template>
5
5
 
6
6
  <script setup lang="ts">
7
- import { ModalsPortal } from '@noeldemartin/vue-modals';
7
+ import { ModalsPortal } from '@aerogel/core/ui/modals';
8
8
 
9
9
  import AppToasts from './AppToasts.vue';
10
10
  </script>
@@ -1,7 +1,7 @@
1
1
  import type { PrimitiveProps } from 'reka-ui';
2
2
  import type { HTMLAttributes } from 'vue';
3
3
 
4
- export type ButtonVariant = 'default' | 'secondary' | 'danger' | 'ghost' | 'outline' | 'link';
4
+ export type ButtonVariant = 'default' | 'secondary' | 'danger' | 'warning' | 'ghost' | 'outline' | 'link';
5
5
  export type ButtonSize = 'default' | 'small' | 'large' | 'icon';
6
6
  export interface ButtonProps extends PrimitiveProps {
7
7
  class?: HTMLAttributes['class'];
@@ -0,0 +1,7 @@
1
+ import type { Ref } from 'vue';
2
+
3
+ export type ComboboxContext = {
4
+ input: Ref<string>;
5
+ preventChange: Ref<boolean>;
6
+ $group: Ref<HTMLDivElement | null>;
7
+ };
@@ -5,6 +5,8 @@ export type ModalContentInstance = Nullable<InstanceType<typeof DialogContent>>;
5
5
 
6
6
  export interface ModalProps {
7
7
  persistent?: boolean;
8
+ fullscreen?: boolean;
9
+ fullscreenOnMobile?: boolean;
8
10
  title?: string;
9
11
  titleHidden?: boolean;
10
12
  description?: string;
@@ -1,8 +1,11 @@
1
+ import { computed, inject, provide, readonly } from 'vue';
2
+ import { evaluate, toString, uuid } from '@noeldemartin/utils';
1
3
  import type { AcceptableValue, AsTag, SelectContentProps } from 'reka-ui';
2
- import type { Component, ComputedRef, HTMLAttributes } from 'vue';
4
+ import type { Component, ComputedRef, EmitFn, HTMLAttributes } from 'vue';
3
5
  import type { Nullable } from '@noeldemartin/utils';
4
6
 
5
- import type { FormFieldValue } from '@aerogel/core/forms';
7
+ import { translateWithDefault } from '@aerogel/core/lang';
8
+ import type { FormController, FormFieldValue } from '@aerogel/core/forms';
6
9
 
7
10
  import type { InputEmits, InputExpose, InputProps } from './Input';
8
11
 
@@ -38,8 +41,92 @@ export interface SelectExpose<T extends Nullable<FormFieldValue> = Nullable<Form
38
41
  optionsClass?: HTMLAttributes['class'];
39
42
  align?: SelectContentProps['align'];
40
43
  side?: SelectContentProps['side'];
44
+ renderOption: (option: T) => string;
41
45
  }
42
46
 
43
47
  export function hasSelectOptionLabel(option: unknown): option is HasSelectOptionLabel {
44
48
  return typeof option === 'object' && option !== null && 'label' in option;
45
49
  }
50
+
51
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
52
+ export function useSelect<T extends Nullable<FormFieldValue>>(props: SelectProps<T>, emit: EmitFn<SelectEmits<T>>) {
53
+ const form = inject<FormController | null>('form', null);
54
+ const renderOption = (option: T): string => {
55
+ if (option === undefined) {
56
+ return '';
57
+ }
58
+
59
+ return props.renderOption
60
+ ? props.renderOption(option)
61
+ : hasSelectOptionLabel(option)
62
+ ? evaluate(option.label as string)
63
+ : toString(option);
64
+ };
65
+ const computedValue = computed(() => {
66
+ if (form && props.name) {
67
+ return form.getFieldValue(props.name) as T;
68
+ }
69
+
70
+ return props.modelValue as T;
71
+ });
72
+ const acceptableValue = computed(() => computedValue.value as AcceptableValue);
73
+ const errors = computed(() => {
74
+ if (!form || !props.name) {
75
+ return null;
76
+ }
77
+
78
+ return form.errors[props.name] ?? null;
79
+ });
80
+ const computedOptions = computed(() => {
81
+ if (!props.options) {
82
+ return null;
83
+ }
84
+
85
+ return props.options.map((option) => ({
86
+ key: uuid(),
87
+ label: renderOption(option),
88
+ value: option as AcceptableValue,
89
+ }));
90
+ });
91
+
92
+ const expose = {
93
+ renderOption,
94
+ labelClass: props.labelClass,
95
+ optionsClass: props.optionsClass,
96
+ align: props.align,
97
+ side: props.side,
98
+ value: computedValue,
99
+ id: `select-${uuid()}`,
100
+ name: computed(() => props.name),
101
+ label: computed(() => props.label),
102
+ description: computed(() => props.description),
103
+ placeholder: computed(() => props.placeholder ?? translateWithDefault('ui.select', 'Select an option')),
104
+ options: computedOptions,
105
+ selectedOption: computed(() => computedOptions.value?.find((option) => option.value === props.modelValue)),
106
+ errors: readonly(errors),
107
+ required: computed(() => {
108
+ if (!props.name || !form) {
109
+ return;
110
+ }
111
+
112
+ return form.getFieldRules(props.name).includes('required');
113
+ }),
114
+ update(value) {
115
+ if (form && props.name) {
116
+ form.setFieldValue(props.name, value as FormFieldValue);
117
+
118
+ return;
119
+ }
120
+
121
+ emit('update:modelValue', value);
122
+ },
123
+ } satisfies SelectExpose<T>;
124
+
125
+ function update(value: AcceptableValue) {
126
+ expose.update(value as T);
127
+ }
128
+
129
+ provide('select', expose);
130
+
131
+ return { expose, acceptableValue, update, renderOption };
132
+ }
@@ -1,4 +1,4 @@
1
- export type ToastVariant = 'secondary' | 'danger';
1
+ export type ToastVariant = 'secondary' | 'warning' | 'danger';
2
2
 
3
3
  export interface ToastAction {
4
4
  label: string;
@@ -1,5 +1,6 @@
1
1
  export * from './AlertModal';
2
2
  export * from './Button';
3
+ export * from './Combobox';
3
4
  export * from './ConfirmModal';
4
5
  export * from './DropdownMenu';
5
6
  export * from './ErrorReportModal';
@@ -19,6 +19,7 @@ import { computed, inject, useTemplateRef, watchEffect } from 'vue';
19
19
 
20
20
  import { injectReactiveOrFail } from '@aerogel/core/utils/vue';
21
21
  import { onFormFocus } from '@aerogel/core/utils/composition/forms';
22
+ import { LOCAL_TIMEZONE_OFFSET } from '@aerogel/core/utils';
22
23
  import type FormController from '@aerogel/core/forms/FormController';
23
24
  import type { FormFieldValue } from '@aerogel/core/forms/FormController';
24
25
  import type { InputExpose } from '@aerogel/core/components/contracts/Input';
@@ -39,7 +40,7 @@ const renderedType = computed(() => {
39
40
  return ['text', 'email', 'number', 'tel', 'url'].includes(fieldType) ? fieldType : 'text';
40
41
  });
41
42
  const checked = computed(() => {
42
- if (type !== 'checkbox') {
43
+ if (renderedType.value !== 'checkbox') {
43
44
  return;
44
45
  }
45
46
 
@@ -59,11 +60,15 @@ function getValue(): FormFieldValue | null {
59
60
  return null;
60
61
  }
61
62
 
62
- switch (type) {
63
+ switch (renderedType.value) {
63
64
  case 'checkbox':
64
65
  return $input.value.checked;
65
66
  case 'date':
66
- return $input.value.valueAsDate;
67
+ case 'time':
68
+ case 'datetime-local':
69
+ return new Date(Math.round($input.value.valueAsNumber / 60000) * 60000 + LOCAL_TIMEZONE_OFFSET);
70
+ case 'number':
71
+ return $input.value.valueAsNumber;
67
72
  default:
68
73
  return $input.value.value;
69
74
  }
@@ -75,8 +80,11 @@ watchEffect(() => {
75
80
  return;
76
81
  }
77
82
 
78
- if (type === 'date' && value.value instanceof Date) {
79
- $input.value.valueAsDate = value.value;
83
+ if (['date', 'time', 'datetime-local'].includes(renderedType.value) && value.value instanceof Date) {
84
+ const roundedValue = Math.round(value.value.getTime() / 60000) * 60000;
85
+
86
+ $input.value.valueAsNumber = roundedValue - LOCAL_TIMEZONE_OFFSET;
87
+ input.update(new Date(roundedValue));
80
88
 
81
89
  return;
82
90
  }
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <DialogRoot :ref="forwardRef" open @update:open="persistent || close()">
2
+ <DialogRoot :ref="forwardRef" open @update:open="persistent || $event || close()">
3
3
  <DialogPortal>
4
4
  <slot :close />
5
5
  </DialogPortal>
@@ -7,18 +7,17 @@
7
7
  </template>
8
8
 
9
9
  <script setup lang="ts" generic="T = void">
10
- import { after } from '@noeldemartin/utils';
11
10
  import { DialogPortal, DialogRoot, useForwardExpose } from 'reka-ui';
12
11
  import { provide, ref } from 'vue';
13
- import { useModal } from '@noeldemartin/vue-modals';
14
12
  import type { DialogContent } from 'reka-ui';
15
13
  import type { Nullable } from '@noeldemartin/utils';
16
14
 
15
+ import { useModal } from '@aerogel/core/ui/modals';
17
16
  import type { AcceptRefs } from '@aerogel/core/utils/vue';
18
17
  import type { ModalExpose, ModalProps, ModalSlots } from '@aerogel/core/components/contracts/Modal';
19
18
 
20
19
  const $content = ref<Nullable<InstanceType<typeof DialogContent>>>(null);
21
- const modal = useModal<T>({ removeOnClose: false });
20
+ const { close } = useModal<T>();
22
21
 
23
22
  defineProps<ModalProps>();
24
23
  defineSlots<ModalSlots<T>>();
@@ -27,12 +26,4 @@ defineExpose<AcceptRefs<ModalExpose>>({ $content });
27
26
  const { forwardRef } = useForwardExpose();
28
27
 
29
28
  provide('$modalContentRef', $content);
30
-
31
- async function close(result?: T) {
32
- modal.close(result);
33
-
34
- await after(1000);
35
-
36
- modal.remove();
37
- }
38
29
  </script>
@@ -9,9 +9,9 @@
9
9
  <script setup lang="ts">
10
10
  import { useTemplateRef, watchEffect } from 'vue';
11
11
  import { DialogContent } from 'reka-ui';
12
- import { ModalComponent, useModal } from '@noeldemartin/vue-modals';
13
12
  import type { Ref } from 'vue';
14
13
 
14
+ import { ModalComponent, useModal } from '@aerogel/core/ui/modals';
15
15
  import { injectOrFail } from '@aerogel/core/utils/vue';
16
16
  import type { ModalContentInstance } from '@aerogel/core/components/contracts/Modal';
17
17
 
@@ -2,7 +2,7 @@
2
2
  <SelectRoot
3
3
  v-slot="{ open }"
4
4
  :model-value="acceptableValue"
5
- :by="compareOptions as Closure<[AcceptableValue, AcceptableValue], boolean>"
5
+ :by="compareOptions"
6
6
  @update:model-value="update($event)"
7
7
  >
8
8
  <component :is="as" v-bind="$attrs">
@@ -15,16 +15,11 @@
15
15
  </template>
16
16
 
17
17
  <script setup lang="ts" generic="T extends Nullable<FormFieldValue>">
18
- import { computed, inject, provide, readonly } from 'vue';
19
- import { value as evaluate, toString, uuid } from '@noeldemartin/utils';
20
18
  import { SelectRoot } from 'reka-ui';
21
- import type { AcceptableValue } from 'reka-ui';
22
- import type { Closure, Nullable } from '@noeldemartin/utils';
19
+ import type { Nullable } from '@noeldemartin/utils';
23
20
 
24
- import { translateWithDefault } from '@aerogel/core/lang';
25
- import { hasSelectOptionLabel } from '@aerogel/core/components/contracts/Select';
26
- import type FormController from '@aerogel/core/forms/FormController';
27
- import type { SelectEmits, SelectExpose, SelectProps } from '@aerogel/core/components/contracts/Select';
21
+ import { useSelect } from '@aerogel/core/components/contracts/Select';
22
+ import type { SelectEmits, SelectProps } from '@aerogel/core/components/contracts/Select';
28
23
  import type { FormFieldValue } from '@aerogel/core/forms/FormController';
29
24
 
30
25
  import HeadlessSelectTrigger from './HeadlessSelectTrigger.vue';
@@ -32,89 +27,9 @@ import HeadlessSelectOptions from './HeadlessSelectOptions.vue';
32
27
 
33
28
  defineOptions({ inheritAttrs: false });
34
29
 
35
- const {
36
- name,
37
- as = 'div',
38
- label,
39
- options,
40
- labelClass,
41
- optionsClass,
42
- renderOption,
43
- compareOptions = (a, b) => a === b,
44
- description,
45
- placeholder,
46
- modelValue,
47
- align,
48
- side,
49
- } = defineProps<SelectProps<T>>();
50
30
  const emit = defineEmits<SelectEmits<T>>();
51
- const form = inject<FormController | null>('form', null);
52
- const computedValue = computed(() => {
53
- if (form && name) {
54
- return form.getFieldValue(name) as T;
55
- }
31
+ const { as = 'div', compareOptions = (a, b) => a === b, ...props } = defineProps<SelectProps<T>>();
32
+ const { expose, acceptableValue, update } = useSelect({ as, compareOptions, ...props }, emit);
56
33
 
57
- return modelValue as T;
58
- });
59
- const acceptableValue = computed(() => computedValue.value as AcceptableValue);
60
- const errors = computed(() => {
61
- if (!form || !name) {
62
- return null;
63
- }
64
-
65
- return form.errors[name] ?? null;
66
- });
67
- const computedOptions = computed(() => {
68
- if (!options) {
69
- return null;
70
- }
71
-
72
- return options.map((option) => ({
73
- key: uuid(),
74
- label: renderOption
75
- ? renderOption(option)
76
- : hasSelectOptionLabel(option)
77
- ? evaluate(option.label as string)
78
- : toString(option),
79
- value: option as AcceptableValue,
80
- }));
81
- });
82
- const expose = {
83
- labelClass,
84
- optionsClass,
85
- align,
86
- side,
87
- value: computedValue,
88
- id: `select-${uuid()}`,
89
- name: computed(() => name),
90
- label: computed(() => label),
91
- description: computed(() => description),
92
- placeholder: computed(() => placeholder ?? translateWithDefault('ui.select', 'Select an option')),
93
- options: computedOptions,
94
- selectedOption: computed(() => computedOptions.value?.find((option) => option.value === modelValue)),
95
- errors: readonly(errors),
96
- required: computed(() => {
97
- if (!name || !form) {
98
- return;
99
- }
100
-
101
- return form.getFieldRules(name).includes('required');
102
- }),
103
- update(value) {
104
- if (form && name) {
105
- form.setFieldValue(name, value as FormFieldValue);
106
-
107
- return;
108
- }
109
-
110
- emit('update:modelValue', value);
111
- },
112
- } satisfies SelectExpose<T>;
113
-
114
- function update(value: AcceptableValue) {
115
- expose.update(value as T);
116
- }
117
-
118
- provide('select', expose);
119
34
  defineExpose(expose);
120
35
  </script>
@@ -25,10 +25,6 @@ const select = injectReactiveOrFail<SelectExpose>(
25
25
  const renderedLabel = computed(() => {
26
26
  const itemOption = select.options?.find((option) => option.value === value);
27
27
 
28
- if (itemOption) {
29
- return itemOption.label;
30
- }
31
-
32
- return toString(value);
28
+ return itemOption ? select.renderOption(itemOption.value) : toString(value);
33
29
  });
34
30
  </script>
@@ -5,3 +5,4 @@ export { default as AppToasts } from './AppToasts.vue';
5
5
  export * from './contracts';
6
6
  export * from './headless';
7
7
  export * from './ui';
8
+ export * from './vue';
@@ -1,18 +1,9 @@
1
1
  <template>
2
- <details class="group">
3
- <summary
4
- class="-ml-2 flex w-[max-content] items-center rounded-lg py-2 pr-3 pl-1 hover:bg-gray-100 focus-visible:outline focus-visible:outline-gray-700"
5
- >
6
- <IconCheveronRight class="size-6 transition-transform group-open:rotate-90" />
7
- <span>{{ $td('ui.advancedOptions', 'Advanced options') }}</span>
8
- </summary>
9
-
10
- <div class="pt-2 pl-4">
11
- <slot />
12
- </div>
13
- </details>
2
+ <Details :label="$td('ui.advancedOptions', 'Advanced options')">
3
+ <slot />
4
+ </Details>
14
5
  </template>
15
6
 
16
7
  <script setup lang="ts">
17
- import IconCheveronRight from '~icons/zondicons/cheveron-right';
8
+ import Details from './Details.vue';
18
9
  </script>
@@ -25,6 +25,7 @@ const renderedClasses = computed(() => variantClasses<Variants<Pick<ButtonProps,
25
25
  default: 'bg-primary-600 text-white focus-visible:outline-primary-600',
26
26
  secondary: 'bg-background text-gray-900 ring-gray-300',
27
27
  danger: 'bg-red-600 text-white focus-visible:outline-red-600',
28
+ warning: 'bg-yellow-600 text-white focus-visible:outline-yellow-600',
28
29
  ghost: 'bg-transparent',
29
30
  outline: 'bg-transparent text-primary-600 ring-primary-600',
30
31
  link: 'text-links',
@@ -0,0 +1,56 @@
1
+ <template>
2
+ <ComboboxRoot
3
+ ignore-filter
4
+ :open
5
+ :reset-search-term-on-blur="false"
6
+ :reset-search-term-on-select="false"
7
+ :model-value="acceptableValue"
8
+ :by="compareOptions"
9
+ @update:model-value="update($event)"
10
+ >
11
+ <Provide name="combobox" :value="combobox">
12
+ <ComboboxLabel />
13
+ <ComboboxTrigger @focus="open = true" @change="open = true" @blur="open = false" />
14
+ <ComboboxOptions :new-input-value @select="open = false" />
15
+ </Provide>
16
+ </ComboboxRoot>
17
+ </template>
18
+
19
+ <script setup lang="ts" generic="T extends Nullable<FormFieldValue>">
20
+ import { ComboboxRoot } from 'reka-ui';
21
+ import { ref } from 'vue';
22
+ import type { AcceptableValue } from 'reka-ui';
23
+ import type { Nullable } from '@noeldemartin/utils';
24
+
25
+ import Provide from '@aerogel/core/components/vue/Provide.vue';
26
+ import { useSelect } from '@aerogel/core/components/contracts/Select';
27
+ import type { ComboboxContext } from '@aerogel/core/components/contracts/Combobox';
28
+ import type { SelectEmits, SelectProps } from '@aerogel/core/components/contracts/Select';
29
+ import type { FormFieldValue } from '@aerogel/core/forms';
30
+
31
+ import ComboboxOptions from './ComboboxOptions.vue';
32
+ import ComboboxTrigger from './ComboboxTrigger.vue';
33
+ import ComboboxLabel from './ComboboxLabel.vue';
34
+
35
+ const emit = defineEmits<SelectEmits<T>>();
36
+ const {
37
+ as = 'div',
38
+ compareOptions = (a, b) => a === b,
39
+ ...props
40
+ } = defineProps<SelectProps<T> & { newInputValue?: (value: string) => T }>();
41
+ const { expose, acceptableValue, update: baseUpdate, renderOption } = useSelect({ as, compareOptions, ...props }, emit);
42
+ const open = ref(false);
43
+ const combobox = {
44
+ input: ref(acceptableValue.value ? renderOption(acceptableValue.value as T) : ''),
45
+ preventChange: ref(false),
46
+ $group: ref(null),
47
+ } satisfies ComboboxContext;
48
+
49
+ function update(value: AcceptableValue) {
50
+ combobox.input.value = renderOption(value as T);
51
+
52
+ baseUpdate(value);
53
+ }
54
+
55
+ defineExpose(expose);
56
+ </script>
@@ -0,0 +1,29 @@
1
+ <template>
2
+ <Label
3
+ v-if="show"
4
+ :for="select.id"
5
+ :class="renderedClasses"
6
+ v-bind="$props"
7
+ >
8
+ <slot>
9
+ {{ select.label }}
10
+ </slot>
11
+ </Label>
12
+ </template>
13
+
14
+ <script setup lang="ts">
15
+ import { computed, useSlots } from 'vue';
16
+ import { Label } from 'reka-ui';
17
+ import type { LabelProps } from 'reka-ui';
18
+
19
+ import { classes } from '@aerogel/core/utils';
20
+ import { injectReactiveOrFail } from '@aerogel/core/utils/vue';
21
+ import type { SelectExpose } from '@aerogel/core/components/contracts/Select';
22
+
23
+ defineProps<Omit<LabelProps, 'for'>>();
24
+
25
+ const select = injectReactiveOrFail<SelectExpose>('select', '<ComboboxLabel> must be a child of a <Combobox>');
26
+ const slots = useSlots();
27
+ const show = computed(() => !!(select.label || slots.default));
28
+ const renderedClasses = computed(() => classes('block text-sm leading-6 font-medium text-gray-900', select.labelClass));
29
+ </script>
@@ -0,0 +1,46 @@
1
+ <template>
2
+ <ComboboxItem v-bind="$props" class="group p-1 outline-none" @select="onSelect($event)">
3
+ <div
4
+ class="relative flex max-w-[calc(100vw-2rem)] cursor-pointer items-center gap-2 truncate rounded-md px-2 py-1 text-sm select-none *:truncate group-data-[highlighted]:bg-gray-100 group-data-[state=checked]:font-semibold group-data-[state=unchecked]:opacity-50"
5
+ >
6
+ <slot>
7
+ {{ renderedLabel }}
8
+ </slot>
9
+ </div>
10
+ </ComboboxItem>
11
+ </template>
12
+
13
+ <script setup lang="ts">
14
+ import { computed } from 'vue';
15
+ import { ComboboxItem, injectComboboxRootContext } from 'reka-ui';
16
+ import { toString } from '@noeldemartin/utils';
17
+ import type { ComboboxItemProps, SelectItemSelectEvent } from 'reka-ui';
18
+
19
+ import { injectReactiveOrFail } from '@aerogel/core/utils';
20
+ import type { ComboboxContext } from '@aerogel/core/components/contracts/Combobox';
21
+ import type { SelectExpose } from '@aerogel/core/components/contracts/Select';
22
+
23
+ const emit = defineEmits<{ select: [] }>();
24
+
25
+ const { value } = defineProps<ComboboxItemProps>();
26
+ const select = injectReactiveOrFail<SelectExpose>('select', '<ComboboxOption> must be a child of a <Combobox>');
27
+ const rootContext = injectComboboxRootContext();
28
+ const combobox = injectReactiveOrFail<ComboboxContext>('combobox');
29
+ const renderedLabel = computed(() => {
30
+ const itemOption = select.options?.find((option) => option.value === value);
31
+
32
+ return itemOption ? select.renderOption(itemOption.value) : toString(value);
33
+ });
34
+
35
+ function onSelect(event: SelectItemSelectEvent<unknown>) {
36
+ if (rootContext.multiple.value || rootContext.disabled.value) {
37
+ return;
38
+ }
39
+
40
+ event.preventDefault();
41
+ combobox.preventChange = true;
42
+ rootContext.modelValue.value = value;
43
+
44
+ emit('select');
45
+ }
46
+ </script>
@@ -0,0 +1,71 @@
1
+ <template>
2
+ <ComboboxPortal>
3
+ <ComboboxContent
4
+ position="popper"
5
+ :align="select.align"
6
+ :side="select.side"
7
+ :side-offset="4"
8
+ :class="renderedClasses"
9
+ >
10
+ <ComboboxViewport>
11
+ <ComboboxEmpty class="group p-1 outline-none">
12
+ <div
13
+ class="relative flex max-w-[calc(100vw-2rem)] items-center gap-2 truncate rounded-md px-2 py-1 text-sm select-none *:truncate"
14
+ >
15
+ {{ $td('ui.comboboxEmpty', 'No options found') }}
16
+ </div>
17
+ </ComboboxEmpty>
18
+
19
+ <ComboboxGroup ref="$group">
20
+ <ComboboxOption
21
+ v-if="showInputOption"
22
+ :value="newInputValue?.(combobox.input) ?? (combobox.input as AcceptableValue)"
23
+ @select="$emit('select')"
24
+ >
25
+ {{ combobox.input }}
26
+ </ComboboxOption>
27
+ <ComboboxOption
28
+ v-for="option in filteredOptions"
29
+ :key="option.key"
30
+ :value="option.value"
31
+ @select="$emit('select')"
32
+ />
33
+ </ComboboxGroup>
34
+ </ComboboxViewport>
35
+ </ComboboxContent>
36
+ </ComboboxPortal>
37
+ </template>
38
+
39
+ <script setup lang="ts">
40
+ import { ComboboxContent, ComboboxEmpty, ComboboxGroup, ComboboxPortal, ComboboxViewport, useFilter } from 'reka-ui';
41
+ import { computed, useTemplateRef, watch } from 'vue';
42
+ import type { Nullable } from '@noeldemartin/utils';
43
+ import type { AcceptableValue } from 'reka-ui';
44
+
45
+ import { classes, injectReactiveOrFail } from '@aerogel/core/utils';
46
+ import type { FormFieldValue } from '@aerogel/core/forms';
47
+ import type { SelectExpose } from '@aerogel/core/components/contracts/Select';
48
+ import type { ComboboxContext } from '@aerogel/core/components/contracts/Combobox';
49
+
50
+ import ComboboxOption from './ComboboxOption.vue';
51
+
52
+ defineEmits<{ select: [] }>();
53
+
54
+ const { newInputValue } = defineProps<{ newInputValue?: (value: string) => Nullable<FormFieldValue> }>();
55
+ const { contains } = useFilter({ sensitivity: 'base' });
56
+ const select = injectReactiveOrFail<SelectExpose>('select', '<ComboboxOptions> must be a child of a <Combobox>');
57
+ const combobox = injectReactiveOrFail<ComboboxContext>('combobox');
58
+ const $group = useTemplateRef('$group');
59
+ const filteredOptions = computed(
60
+ () => select.options?.filter((option) => contains(option.label, combobox.input)) ?? [],
61
+ );
62
+ const showInputOption = computed(
63
+ () => combobox.input && !filteredOptions.value.some((option) => option.label === combobox.input),
64
+ );
65
+ const renderedClasses = classes(
66
+ 'max-h-(--reka-combobox-content-available-height) min-w-(--reka-combobox-trigger-width)',
67
+ 'z-50 overflow-auto rounded-lg bg-white text-base shadow-lg ring-1 ring-black/5 focus:outline-hidden',
68
+ );
69
+
70
+ watch($group, () => (combobox.$group = $group.value?.$el ?? null));
71
+ </script>