@aerogel/core 0.1.1-next.c3c3c32e9b674ba4ae2d33973d4659e37c863c35 → 0.1.1-next.ce10b6d6ba4cd98145cf14595fb4f292b979e2dc
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.
- package/dist/aerogel-core.d.ts +363 -119
- package/dist/aerogel-core.js +1592 -1255
- package/dist/aerogel-core.js.map +1 -1
- package/package.json +1 -1
- package/src/bootstrap/index.ts +2 -1
- package/src/components/contracts/Combobox.ts +5 -0
- package/src/components/contracts/Select.ts +98 -4
- package/src/components/contracts/index.ts +1 -0
- package/src/components/headless/HeadlessInputInput.vue +6 -3
- package/src/components/headless/HeadlessSelect.vue +10 -91
- package/src/components/headless/HeadlessSelectOption.vue +1 -5
- package/src/components/index.ts +1 -0
- package/src/components/ui/Combobox.vue +94 -0
- package/src/components/ui/ComboboxLabel.vue +29 -0
- package/src/components/ui/ComboboxOption.vue +46 -0
- package/src/components/ui/ComboboxOptions.vue +71 -0
- package/src/components/ui/ComboboxTrigger.vue +67 -0
- package/src/components/ui/Details.vue +1 -1
- package/src/components/ui/Select.vue +2 -0
- package/src/components/ui/SelectTrigger.vue +13 -2
- package/src/components/ui/index.ts +5 -0
- package/src/components/vue/Provide.vue +11 -0
- package/src/components/vue/index.ts +1 -0
- package/src/forms/FormController.test.ts +4 -4
- package/src/forms/FormController.ts +3 -3
- package/src/forms/index.ts +11 -0
- package/src/forms/utils.ts +36 -17
- package/src/forms/validation.ts +5 -1
- package/src/jobs/Job.ts +1 -1
- package/src/services/index.ts +2 -0
- package/src/utils/time.ts +6 -1
package/package.json
CHANGED
package/src/bootstrap/index.ts
CHANGED
|
@@ -10,13 +10,14 @@ import lang from '@aerogel/core/lang';
|
|
|
10
10
|
import services from '@aerogel/core/services';
|
|
11
11
|
import testing from '@aerogel/core/testing';
|
|
12
12
|
import ui from '@aerogel/core/ui';
|
|
13
|
+
import forms from '@aerogel/core/forms';
|
|
13
14
|
import { installPlugins } from '@aerogel/core/plugins';
|
|
14
15
|
import type { AerogelOptions } from '@aerogel/core/bootstrap/options';
|
|
15
16
|
|
|
16
17
|
export type { AerogelOptions };
|
|
17
18
|
|
|
18
19
|
export async function bootstrapApplication(app: AppInstance, options: AerogelOptions = {}): Promise<void> {
|
|
19
|
-
const plugins = [testing, directives, errors, lang, services, ui, ...(options.plugins ?? [])];
|
|
20
|
+
const plugins = [testing, directives, errors, lang, services, ui, forms, ...(options.plugins ?? [])];
|
|
20
21
|
|
|
21
22
|
App.instance = app;
|
|
22
23
|
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import { computed, inject, provide, readonly } from 'vue';
|
|
2
|
+
import { evaluate, toString, uuid } from '@noeldemartin/utils';
|
|
3
|
+
import type { AcceptRefs } from '@aerogel/core/utils';
|
|
1
4
|
import type { AcceptableValue, AsTag, SelectContentProps } from 'reka-ui';
|
|
2
|
-
import type { Component, ComputedRef, HTMLAttributes } from 'vue';
|
|
5
|
+
import type { Component, ComputedRef, EmitFn, HTMLAttributes, Ref } from 'vue';
|
|
3
6
|
import type { Nullable } from '@noeldemartin/utils';
|
|
4
7
|
|
|
5
|
-
import
|
|
8
|
+
import { translateWithDefault } from '@aerogel/core/lang';
|
|
9
|
+
import type { FormController, FormFieldValue } from '@aerogel/core/forms';
|
|
6
10
|
|
|
7
11
|
import type { InputEmits, InputExpose, InputProps } from './Input';
|
|
8
12
|
|
|
@@ -34,12 +38,102 @@ export interface SelectExpose<T extends Nullable<FormFieldValue> = Nullable<Form
|
|
|
34
38
|
options: ComputedRef<Nullable<readonly SelectOptionData[]>>;
|
|
35
39
|
selectedOption: ComputedRef<Nullable<SelectOptionData>>;
|
|
36
40
|
placeholder: ComputedRef<string>;
|
|
37
|
-
labelClass
|
|
38
|
-
optionsClass
|
|
41
|
+
labelClass: ComputedRef<HTMLAttributes['class']>;
|
|
42
|
+
optionsClass: ComputedRef<HTMLAttributes['class']>;
|
|
39
43
|
align?: SelectContentProps['align'];
|
|
40
44
|
side?: SelectContentProps['side'];
|
|
45
|
+
renderOption: (option: T) => string;
|
|
41
46
|
}
|
|
42
47
|
|
|
43
48
|
export function hasSelectOptionLabel(option: unknown): option is HasSelectOptionLabel {
|
|
44
49
|
return typeof option === 'object' && option !== null && 'label' in option;
|
|
45
50
|
}
|
|
51
|
+
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
53
|
+
export function useSelect<T extends Nullable<FormFieldValue>>(
|
|
54
|
+
props: Ref<SelectProps<T>>,
|
|
55
|
+
emit: EmitFn<SelectEmits<T>>,
|
|
56
|
+
) {
|
|
57
|
+
const form = inject<FormController | null>('form', null);
|
|
58
|
+
const renderOption = (option: T): string => {
|
|
59
|
+
if (option === undefined) {
|
|
60
|
+
return '';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return props.value.renderOption
|
|
64
|
+
? props.value.renderOption(option)
|
|
65
|
+
: hasSelectOptionLabel(option)
|
|
66
|
+
? evaluate(option.label as string)
|
|
67
|
+
: toString(option);
|
|
68
|
+
};
|
|
69
|
+
const computedValue = computed(() => {
|
|
70
|
+
const { name, modelValue } = props.value;
|
|
71
|
+
|
|
72
|
+
if (form && name) {
|
|
73
|
+
return form.getFieldValue(name) as T;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return modelValue as T;
|
|
77
|
+
});
|
|
78
|
+
const acceptableValue = computed(() => computedValue.value as AcceptableValue);
|
|
79
|
+
const errors = computed(() => {
|
|
80
|
+
if (!form || !props.value.name) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return form.errors[props.value.name] ?? null;
|
|
85
|
+
});
|
|
86
|
+
const computedOptions = computed(() => {
|
|
87
|
+
if (!props.value.options) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return props.value.options.map((option) => ({
|
|
92
|
+
key: uuid(),
|
|
93
|
+
label: renderOption(option),
|
|
94
|
+
value: option as AcceptableValue,
|
|
95
|
+
}));
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const expose = {
|
|
99
|
+
renderOption,
|
|
100
|
+
labelClass: computed(() => props.value.labelClass),
|
|
101
|
+
optionsClass: computed(() => props.value.optionsClass),
|
|
102
|
+
align: computed(() => props.value.align),
|
|
103
|
+
side: computed(() => props.value.side),
|
|
104
|
+
value: computedValue,
|
|
105
|
+
id: `select-${uuid()}`,
|
|
106
|
+
name: computed(() => props.value.name),
|
|
107
|
+
label: computed(() => props.value.label),
|
|
108
|
+
description: computed(() => props.value.description),
|
|
109
|
+
placeholder: computed(() => props.value.placeholder ?? translateWithDefault('ui.select', 'Select an option')),
|
|
110
|
+
options: computedOptions,
|
|
111
|
+
selectedOption: computed(() =>
|
|
112
|
+
computedOptions.value?.find((option) => option.value === props.value.modelValue)),
|
|
113
|
+
errors: readonly(errors),
|
|
114
|
+
required: computed(() => {
|
|
115
|
+
if (!props.value.name || !form) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return form.getFieldRules(props.value.name).includes('required');
|
|
120
|
+
}),
|
|
121
|
+
update(value) {
|
|
122
|
+
if (form && props.value.name) {
|
|
123
|
+
form.setFieldValue(props.value.name, value as FormFieldValue);
|
|
124
|
+
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
emit('update:modelValue', value);
|
|
129
|
+
},
|
|
130
|
+
} satisfies AcceptRefs<SelectExpose<T>>;
|
|
131
|
+
|
|
132
|
+
function update(value: AcceptableValue) {
|
|
133
|
+
expose.update(value as T);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
provide('select', expose);
|
|
137
|
+
|
|
138
|
+
return { expose, acceptableValue, update, renderOption };
|
|
139
|
+
}
|
|
@@ -19,7 +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 {
|
|
22
|
+
import { getLocalTimezoneOffset } from '@aerogel/core/utils';
|
|
23
23
|
import type FormController from '@aerogel/core/forms/FormController';
|
|
24
24
|
import type { FormFieldValue } from '@aerogel/core/forms/FormController';
|
|
25
25
|
import type { InputExpose } from '@aerogel/core/components/contracts/Input';
|
|
@@ -66,7 +66,10 @@ function getValue(): FormFieldValue | null {
|
|
|
66
66
|
case 'date':
|
|
67
67
|
case 'time':
|
|
68
68
|
case 'datetime-local':
|
|
69
|
-
return new Date(
|
|
69
|
+
return new Date(
|
|
70
|
+
Math.round($input.value.valueAsNumber / 60000) * 60000 +
|
|
71
|
+
getLocalTimezoneOffset($input.value.valueAsDate),
|
|
72
|
+
);
|
|
70
73
|
case 'number':
|
|
71
74
|
return $input.value.valueAsNumber;
|
|
72
75
|
default:
|
|
@@ -83,7 +86,7 @@ watchEffect(() => {
|
|
|
83
86
|
if (['date', 'time', 'datetime-local'].includes(renderedType.value) && value.value instanceof Date) {
|
|
84
87
|
const roundedValue = Math.round(value.value.getTime() / 60000) * 60000;
|
|
85
88
|
|
|
86
|
-
$input.value.valueAsNumber = roundedValue -
|
|
89
|
+
$input.value.valueAsNumber = roundedValue - getLocalTimezoneOffset(value.value);
|
|
87
90
|
input.update(new Date(roundedValue));
|
|
88
91
|
|
|
89
92
|
return;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<SelectRoot
|
|
3
3
|
v-slot="{ open }"
|
|
4
4
|
:model-value="acceptableValue"
|
|
5
|
-
:by="compareOptions
|
|
5
|
+
:by="compareOptions"
|
|
6
6
|
@update:model-value="update($event)"
|
|
7
7
|
>
|
|
8
8
|
<component :is="as" v-bind="$attrs">
|
|
@@ -15,16 +15,12 @@
|
|
|
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
|
|
22
|
-
import type {
|
|
19
|
+
import { computed } from 'vue';
|
|
20
|
+
import type { Nullable } from '@noeldemartin/utils';
|
|
23
21
|
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import type FormController from '@aerogel/core/forms/FormController';
|
|
27
|
-
import type { SelectEmits, SelectExpose, SelectProps } from '@aerogel/core/components/contracts/Select';
|
|
22
|
+
import { useSelect } from '@aerogel/core/components/contracts/Select';
|
|
23
|
+
import type { SelectEmits, SelectProps } from '@aerogel/core/components/contracts/Select';
|
|
28
24
|
import type { FormFieldValue } from '@aerogel/core/forms/FormController';
|
|
29
25
|
|
|
30
26
|
import HeadlessSelectTrigger from './HeadlessSelectTrigger.vue';
|
|
@@ -32,89 +28,12 @@ import HeadlessSelectOptions from './HeadlessSelectOptions.vue';
|
|
|
32
28
|
|
|
33
29
|
defineOptions({ inheritAttrs: false });
|
|
34
30
|
|
|
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
31
|
const emit = defineEmits<SelectEmits<T>>();
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
32
|
+
const { as = 'div', compareOptions = (a, b) => a === b, ...props } = defineProps<SelectProps<T>>();
|
|
33
|
+
const { expose, acceptableValue, update } = useSelect(
|
|
34
|
+
computed(() => ({ as, compareOptions, ...props })),
|
|
35
|
+
emit,
|
|
36
|
+
);
|
|
56
37
|
|
|
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
38
|
defineExpose(expose);
|
|
120
39
|
</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
|
-
|
|
29
|
-
return itemOption.label;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return toString(value);
|
|
28
|
+
return itemOption ? select.renderOption(itemOption.value) : toString(value);
|
|
33
29
|
});
|
|
34
30
|
</script>
|
package/src/components/index.ts
CHANGED
|
@@ -0,0 +1,94 @@
|
|
|
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
|
+
<HeadlessSelectError class="mt-2 text-sm text-red-600" />
|
|
15
|
+
<ComboboxOptions :new-input-value @select="open = false" />
|
|
16
|
+
</Provide>
|
|
17
|
+
</ComboboxRoot>
|
|
18
|
+
</template>
|
|
19
|
+
|
|
20
|
+
<script setup lang="ts" generic="T extends Nullable<FormFieldValue>">
|
|
21
|
+
import { ComboboxRoot } from 'reka-ui';
|
|
22
|
+
import { computed, ref, watch } from 'vue';
|
|
23
|
+
import type { AcceptableValue } from 'reka-ui';
|
|
24
|
+
import type { Nullable } from '@noeldemartin/utils';
|
|
25
|
+
|
|
26
|
+
import Provide from '@aerogel/core/components/vue/Provide.vue';
|
|
27
|
+
import { useSelect } from '@aerogel/core/components/contracts/Select';
|
|
28
|
+
import type { AcceptRefs } from '@aerogel/core/utils';
|
|
29
|
+
import type { ComboboxContext } from '@aerogel/core/components/contracts/Combobox';
|
|
30
|
+
import type { SelectEmits, SelectProps } from '@aerogel/core/components/contracts/Select';
|
|
31
|
+
import type { FormFieldValue } from '@aerogel/core/forms';
|
|
32
|
+
|
|
33
|
+
import ComboboxOptions from './ComboboxOptions.vue';
|
|
34
|
+
import ComboboxTrigger from './ComboboxTrigger.vue';
|
|
35
|
+
import ComboboxLabel from './ComboboxLabel.vue';
|
|
36
|
+
import HeadlessSelectError from '../headless/HeadlessSelectError.vue';
|
|
37
|
+
|
|
38
|
+
const emit = defineEmits<SelectEmits<T>>();
|
|
39
|
+
const {
|
|
40
|
+
as = 'div',
|
|
41
|
+
compareOptions = (a, b) => a === b,
|
|
42
|
+
newInputValue,
|
|
43
|
+
...props
|
|
44
|
+
} = defineProps<SelectProps<T> & { newInputValue?: (value: string) => T }>();
|
|
45
|
+
const {
|
|
46
|
+
expose,
|
|
47
|
+
acceptableValue,
|
|
48
|
+
update: baseUpdate,
|
|
49
|
+
renderOption,
|
|
50
|
+
} = useSelect(
|
|
51
|
+
computed(() => ({ as, compareOptions, ...props })),
|
|
52
|
+
emit,
|
|
53
|
+
);
|
|
54
|
+
const open = ref(false);
|
|
55
|
+
const optionsByLabel = computed(() =>
|
|
56
|
+
Object.fromEntries(expose.options.value?.map((option) => [option.label, option.value]) ?? []));
|
|
57
|
+
const combobox = {
|
|
58
|
+
input: ref(acceptableValue.value ? renderOption(acceptableValue.value as T) : ''),
|
|
59
|
+
preventChange: ref(false),
|
|
60
|
+
$group: ref(null),
|
|
61
|
+
} satisfies AcceptRefs<ComboboxContext>;
|
|
62
|
+
|
|
63
|
+
function update(value: AcceptableValue) {
|
|
64
|
+
combobox.input.value = renderOption(value as T);
|
|
65
|
+
|
|
66
|
+
baseUpdate(value);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
watch(expose.value, (value) => {
|
|
70
|
+
const newOptionLabel = renderOption(value as T);
|
|
71
|
+
|
|
72
|
+
if (combobox.input.value === newOptionLabel) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
combobox.preventChange.value = true;
|
|
77
|
+
combobox.input.value = newOptionLabel;
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
watch(combobox.input, (value) => {
|
|
81
|
+
const newInputOption = newInputValue ? (newInputValue(value) as AcceptableValue) : value;
|
|
82
|
+
const newInputOptionLabel = renderOption(newInputOption as T);
|
|
83
|
+
|
|
84
|
+
if (newInputOptionLabel in optionsByLabel.value) {
|
|
85
|
+
update(optionsByLabel.value[newInputOptionLabel] as AcceptableValue);
|
|
86
|
+
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
update(newInputOption);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
defineExpose(expose);
|
|
94
|
+
</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>
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<ComboboxAnchor class="relative">
|
|
3
|
+
<ComboboxInput
|
|
4
|
+
:id="select.id"
|
|
5
|
+
v-model="combobox.input"
|
|
6
|
+
:placeholder="select.placeholder"
|
|
7
|
+
:class="renderedRootClasses"
|
|
8
|
+
:display-value="select.renderOption"
|
|
9
|
+
:name="select.name"
|
|
10
|
+
@focus="$emit('focus')"
|
|
11
|
+
@blur="onBlur()"
|
|
12
|
+
@keydown.esc="$emit('blur')"
|
|
13
|
+
/>
|
|
14
|
+
<div v-if="select?.errors" class="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3">
|
|
15
|
+
<IconExclamationSolid class="size-5 text-red-500" />
|
|
16
|
+
</div>
|
|
17
|
+
</ComboboxAnchor>
|
|
18
|
+
</template>
|
|
19
|
+
|
|
20
|
+
<script setup lang="ts">
|
|
21
|
+
import IconExclamationSolid from '~icons/zondicons/exclamation-solid';
|
|
22
|
+
|
|
23
|
+
import { ComboboxAnchor, ComboboxInput } from 'reka-ui';
|
|
24
|
+
import { computed, watch } from 'vue';
|
|
25
|
+
|
|
26
|
+
import { classes, injectReactiveOrFail } from '@aerogel/core/utils';
|
|
27
|
+
import type { SelectExpose } from '@aerogel/core/components/contracts/Select';
|
|
28
|
+
import type { ComboboxContext } from '@aerogel/core/components/contracts/Combobox';
|
|
29
|
+
|
|
30
|
+
const emit = defineEmits<{ focus: []; change: []; blur: [] }>();
|
|
31
|
+
const select = injectReactiveOrFail<SelectExpose>('select', '<ComboboxTrigger> must be a child of a <Combobox>');
|
|
32
|
+
const combobox = injectReactiveOrFail<ComboboxContext>('combobox');
|
|
33
|
+
const renderedRootClasses = computed(() =>
|
|
34
|
+
classes(
|
|
35
|
+
// eslint-disable-next-line vue/max-len
|
|
36
|
+
'block w-full rounded-md border-0 py-1.5 ring-1 ring-inset focus:ring-2 focus:ring-inset sm:text-sm sm:leading-6',
|
|
37
|
+
{
|
|
38
|
+
'mt-1': select.label,
|
|
39
|
+
'focus:ring-primary-600': !select.errors,
|
|
40
|
+
'text-gray-900 shadow-2xs ring-gray-900/10 placeholder:text-gray-400': !select.errors,
|
|
41
|
+
'pr-10 text-red-900 ring-red-900/10 placeholder:text-red-300 focus:ring-red-500': select.errors,
|
|
42
|
+
},
|
|
43
|
+
));
|
|
44
|
+
|
|
45
|
+
function onBlur() {
|
|
46
|
+
const elements = Array.from(document.querySelectorAll(':hover'));
|
|
47
|
+
|
|
48
|
+
if (elements.some((element) => combobox.$group?.contains(element))) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
emit('blur');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
watch(
|
|
56
|
+
() => combobox.input,
|
|
57
|
+
() => {
|
|
58
|
+
if (combobox.preventChange) {
|
|
59
|
+
combobox.preventChange = false;
|
|
60
|
+
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
emit('change');
|
|
65
|
+
},
|
|
66
|
+
);
|
|
67
|
+
</script>
|
|
@@ -26,7 +26,7 @@ const {
|
|
|
26
26
|
const renderedContentClasses = computed(() => classes('pt-2 pl-4', contentClass));
|
|
27
27
|
const renderedSummaryClasses = computed(() =>
|
|
28
28
|
classes(
|
|
29
|
-
'-ml-2 flex w-[max-content] items-center rounded-lg py-2 pr-3 pl-1',
|
|
29
|
+
'-ml-2 flex w-[max-content] items-center rounded-lg py-2 pr-3 pl-1 max-w-full',
|
|
30
30
|
'hover:bg-gray-100 focus-visible:outline focus-visible:outline-gray-700',
|
|
31
31
|
summaryClass,
|
|
32
32
|
));
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
<SelectLabel />
|
|
4
4
|
<slot>
|
|
5
5
|
<SelectTrigger />
|
|
6
|
+
<HeadlessSelectError class="mt-2 text-sm text-red-600" />
|
|
6
7
|
<SelectOptions />
|
|
7
8
|
</slot>
|
|
8
9
|
</HeadlessSelect>
|
|
@@ -19,6 +20,7 @@ import type { FormFieldValue } from '@aerogel/core/forms';
|
|
|
19
20
|
import SelectLabel from './SelectLabel.vue';
|
|
20
21
|
import SelectOptions from './SelectOptions.vue';
|
|
21
22
|
import SelectTrigger from './SelectTrigger.vue';
|
|
23
|
+
import HeadlessSelectError from '../headless/HeadlessSelectError.vue';
|
|
22
24
|
|
|
23
25
|
defineProps<SelectProps<T>>();
|
|
24
26
|
defineEmits<SelectEmits<T>>();
|