@aerogel/core 0.1.1-next.bad775a386a94fedbee1d575ee1f4fb99d1f5bab → 0.1.1-next.d3af81f1f7f69a65742c4d298e0c77c6c3977d2b

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aerogel/core",
3
- "version": "0.1.1-next.bad775a386a94fedbee1d575ee1f4fb99d1f5bab",
3
+ "version": "0.1.1-next.d3af81f1f7f69a65742c4d298e0c77c6c3977d2b",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "exports": {
@@ -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>
@@ -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
+ }
@@ -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';
@@ -0,0 +1,41 @@
1
+ <template>
2
+ <ComboboxRoot
3
+ open-on-focus
4
+ ignore-filter
5
+ :model-value="acceptableValue"
6
+ :by="compareOptions"
7
+ @update:model-value="update($event)"
8
+ >
9
+ <ProvideRef v-model="input" name="combobox-input">
10
+ <ComboboxLabel />
11
+ <ComboboxTrigger />
12
+ <ComboboxOptions :new-input-value />
13
+ </ProvideRef>
14
+ </ComboboxRoot>
15
+ </template>
16
+
17
+ <script setup lang="ts" generic="T extends Nullable<FormFieldValue>">
18
+ import { ComboboxRoot } from 'reka-ui';
19
+ import { ref } from 'vue';
20
+ import type { Nullable } from '@noeldemartin/utils';
21
+
22
+ import ProvideRef from '@aerogel/core/components/vue/ProvideRef.vue';
23
+ import { useSelect } from '@aerogel/core/components/contracts/Select';
24
+ import type { SelectEmits, SelectProps } from '@aerogel/core/components/contracts/Select';
25
+ import type { FormFieldValue } from '@aerogel/core/forms';
26
+
27
+ import ComboboxOptions from './ComboboxOptions.vue';
28
+ import ComboboxTrigger from './ComboboxTrigger.vue';
29
+ import ComboboxLabel from './ComboboxLabel.vue';
30
+
31
+ const emit = defineEmits<SelectEmits<T>>();
32
+ const {
33
+ as = 'div',
34
+ compareOptions = (a, b) => a === b,
35
+ ...props
36
+ } = defineProps<SelectProps<T> & { newInputValue?: (value: string) => T }>();
37
+ const { expose, acceptableValue, update, renderOption } = useSelect({ as, compareOptions, ...props }, emit);
38
+ const input = ref(acceptableValue.value ? renderOption(acceptableValue.value as T) : '');
39
+
40
+ defineExpose(expose);
41
+ </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,28 @@
1
+ <template>
2
+ <ComboboxItem v-bind="$props" class="group p-1 outline-none">
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, type ComboboxItemProps } from 'reka-ui';
16
+ import { toString } from '@noeldemartin/utils';
17
+
18
+ import { injectReactiveOrFail } from '@aerogel/core/utils';
19
+ import type { SelectExpose } from '@aerogel/core/components/contracts/Select';
20
+
21
+ const { value } = defineProps<ComboboxItemProps>();
22
+ const select = injectReactiveOrFail<SelectExpose>('select', '<ComboboxOption> must be a child of a <Combobox>');
23
+ const renderedLabel = computed(() => {
24
+ const itemOption = select.options?.find((option) => option.value === value);
25
+
26
+ return itemOption ? select.renderOption(itemOption.value) : toString(value);
27
+ });
28
+ </script>
@@ -0,0 +1,58 @@
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>
20
+ <ComboboxOption
21
+ v-if="showInputOption"
22
+ :value="newInputValue?.(input) ?? (input as AcceptableValue)"
23
+ >
24
+ {{ input }}
25
+ </ComboboxOption>
26
+ <ComboboxOption v-for="option in filteredOptions" :key="option.key" :value="option.value" />
27
+ </ComboboxGroup>
28
+ </ComboboxViewport>
29
+ </ComboboxContent>
30
+ </ComboboxPortal>
31
+ </template>
32
+
33
+ <script setup lang="ts">
34
+ import { ComboboxContent, ComboboxEmpty, ComboboxGroup, ComboboxPortal, ComboboxViewport, useFilter } from 'reka-ui';
35
+ import { computed } from 'vue';
36
+ import type { Ref } from 'vue';
37
+ import type { Nullable } from '@noeldemartin/utils';
38
+ import type { AcceptableValue } from 'reka-ui';
39
+
40
+ import { classes, injectOrFail, injectReactiveOrFail } from '@aerogel/core/utils';
41
+ import type { FormFieldValue } from '@aerogel/core/forms';
42
+ import type { SelectExpose } from '@aerogel/core/components/contracts/Select';
43
+
44
+ import ComboboxOption from './ComboboxOption.vue';
45
+
46
+ const { contains } = useFilter({ sensitivity: 'base' });
47
+ const { newInputValue } = defineProps<{ newInputValue?: (value: string) => Nullable<FormFieldValue> }>();
48
+ const select = injectReactiveOrFail<SelectExpose>('select', '<ComboboxOptions> must be a child of a <Combobox>');
49
+ const input = injectOrFail<Ref<string>>('combobox-input');
50
+ const filteredOptions = computed(() => select.options?.filter((option) => contains(option.label, input.value)) ?? []);
51
+ const showInputOption = computed(
52
+ () => input.value && !filteredOptions.value.some((option) => option.label === input.value),
53
+ );
54
+ const renderedClasses = classes(
55
+ 'max-h-(--reka-combobox-content-available-height) min-w-(--reka-combobox-trigger-width)',
56
+ 'z-50 overflow-auto rounded-lg bg-white text-base shadow-lg ring-1 ring-black/5 focus:outline-hidden',
57
+ );
58
+ </script>
@@ -0,0 +1,35 @@
1
+ <template>
2
+ <ComboboxAnchor>
3
+ <ComboboxInput
4
+ :id="select.id"
5
+ v-model="input"
6
+ :placeholder="select.placeholder"
7
+ :class="renderedRootClasses"
8
+ :display-value="select.renderOption"
9
+ :name="select.name"
10
+ />
11
+ </ComboboxAnchor>
12
+ </template>
13
+
14
+ <script setup lang="ts">
15
+ import { ComboboxAnchor, ComboboxInput } from 'reka-ui';
16
+ import { computed } from 'vue';
17
+ import type { Ref } from 'vue';
18
+
19
+ import { classes, injectOrFail, injectReactiveOrFail } from '@aerogel/core/utils';
20
+ import type { SelectExpose } from '@aerogel/core/components/contracts/Select';
21
+
22
+ const select = injectReactiveOrFail<SelectExpose>('select', '<ComboboxTrigger> must be a child of a <Combobox>');
23
+ const input = injectOrFail<Ref<string>>('combobox-input');
24
+ const renderedRootClasses = computed(() =>
25
+ classes(
26
+ // eslint-disable-next-line vue/max-len
27
+ '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',
28
+ {
29
+ 'mt-1': select.label,
30
+ 'focus:ring-primary-600': !select.errors,
31
+ 'text-gray-900 shadow-2xs ring-gray-900/10 placeholder:text-gray-400': !select.errors,
32
+ 'pr-10 text-red-900 ring-red-900/10 placeholder:text-red-300 focus:ring-red-500': select.errors,
33
+ },
34
+ ));
35
+ </script>
@@ -1,10 +1,10 @@
1
1
  <template>
2
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
- >
3
+ <summary :class="renderedSummaryClasses">
6
4
  <IconCheveronRight class="size-6 transition-transform group-open:rotate-90" />
7
- <span>{{ label }}</span>
5
+ <slot name="label">
6
+ <span>{{ label ?? $td('ui.details', 'Details') }}</span>
7
+ </slot>
8
8
  </summary>
9
9
 
10
10
  <div :class="renderedContentClasses">
@@ -14,10 +14,20 @@
14
14
  </template>
15
15
 
16
16
  <script setup lang="ts">
17
+ import IconCheveronRight from '~icons/zondicons/cheveron-right';
17
18
  import { classes } from '@aerogel/core/utils';
18
19
  import { type HTMLAttributes, computed } from 'vue';
19
- import IconCheveronRight from '~icons/zondicons/cheveron-right';
20
20
 
21
- const { label, contentClass } = defineProps<{ label: string; contentClass?: HTMLAttributes['class'] }>();
21
+ const {
22
+ label = undefined,
23
+ contentClass,
24
+ summaryClass,
25
+ } = defineProps<{ label?: string; contentClass?: HTMLAttributes['class']; summaryClass?: HTMLAttributes['class'] }>();
22
26
  const renderedContentClasses = computed(() => classes('pt-2 pl-4', contentClass));
27
+ const renderedSummaryClasses = computed(() =>
28
+ classes(
29
+ '-ml-2 flex w-[max-content] items-center rounded-lg py-2 pr-3 pl-1 max-w-full',
30
+ 'hover:bg-gray-100 focus-visible:outline focus-visible:outline-gray-700',
31
+ summaryClass,
32
+ ));
23
33
  </script>
@@ -36,7 +36,7 @@ const filledClasses = computed(() =>
36
36
  classes('size-full transition-transform duration-500 rounded-r-full ease-linear bg-primary-600', filledClass));
37
37
  const overflowClasses = computed(() =>
38
38
  classes(
39
- 'absolute inset-y-0 right-0 size-full rounded-r-full border-l-3 border-gray-200',
39
+ 'absolute inset-y-0 right-0 size-full rounded-r-full',
40
40
  'bg-primary-900 transition-[width] duration-500 ease-linear',
41
41
  overflowClass,
42
42
  ));
@@ -2,6 +2,11 @@ export { default as AdvancedOptions } from './AdvancedOptions.vue';
2
2
  export { default as AlertModal } from './AlertModal.vue';
3
3
  export { default as Button } from './Button.vue';
4
4
  export { default as Checkbox } from './Checkbox.vue';
5
+ export { default as Combobox } from './Combobox.vue';
6
+ export { default as ComboboxLabel } from './ComboboxLabel.vue';
7
+ export { default as ComboboxOption } from './ComboboxOption.vue';
8
+ export { default as ComboboxOptions } from './ComboboxOptions.vue';
9
+ export { default as ComboboxTrigger } from './ComboboxTrigger.vue';
5
10
  export { default as ConfirmModal } from './ConfirmModal.vue';
6
11
  export { default as Details } from './Details.vue';
7
12
  export { default as DropdownMenu } from './DropdownMenu.vue';
@@ -0,0 +1,12 @@
1
+ <template>
2
+ <slot />
3
+ </template>
4
+
5
+ <script setup lang="ts">
6
+ import { provide } from 'vue';
7
+
8
+ const { name } = defineProps<{ name: string }>();
9
+ const model = defineModel<unknown>();
10
+
11
+ provide(name, model);
12
+ </script>
@@ -0,0 +1 @@
1
+ export { default as ProvideRef } from './ProvideRef.vue';
package/src/index.css CHANGED
@@ -20,6 +20,7 @@
20
20
  --color-primary-950: color-mix(in oklab, var(--color-primary-600) 50%, black);
21
21
 
22
22
  --color-background: oklch(1 0 0);
23
+ --color-primary-text: var(--color-gray-900);
23
24
  --color-links: var(--color-primary);
24
25
 
25
26
  --breakpoint-content: var(--breakpoint-md);