@aerogel/core 0.0.0-next.d824b40e5d06757cd9f47c9f771d916185df4f05 → 0.0.0-next.f1f5a990033d966dc0bb12d251110fbc9350dcc7
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.cjs.js +1 -1
- package/dist/aerogel-core.cjs.js.map +1 -1
- package/dist/aerogel-core.d.ts +641 -110
- package/dist/aerogel-core.esm.js +1 -1
- package/dist/aerogel-core.esm.js.map +1 -1
- package/histoire.config.ts +7 -0
- package/package.json +14 -5
- package/postcss.config.js +6 -0
- package/src/assets/histoire.css +3 -0
- package/src/bootstrap/bootstrap.test.ts +4 -3
- package/src/bootstrap/index.ts +18 -3
- package/src/components/AGAppLayout.vue +7 -2
- package/src/components/AGAppOverlays.vue +5 -1
- package/src/components/AGAppSnackbars.vue +1 -1
- package/src/components/forms/AGSelect.story.vue +28 -0
- package/src/components/forms/AGSelect.vue +53 -0
- package/src/components/forms/index.ts +5 -6
- package/src/components/headless/forms/AGHeadlessInput.ts +21 -1
- package/src/components/headless/forms/AGHeadlessInput.vue +8 -5
- package/src/components/headless/forms/AGHeadlessInputLabel.vue +8 -2
- package/src/components/headless/forms/AGHeadlessSelect.ts +39 -0
- package/src/components/headless/forms/AGHeadlessSelect.vue +76 -0
- package/src/components/headless/forms/AGHeadlessSelectButton.vue +24 -0
- package/src/components/headless/forms/AGHeadlessSelectError.vue +26 -0
- package/src/components/headless/forms/AGHeadlessSelectLabel.vue +24 -0
- package/src/components/headless/forms/AGHeadlessSelectOption.ts +4 -0
- package/src/components/headless/forms/AGHeadlessSelectOption.vue +39 -0
- package/src/components/headless/forms/AGHeadlessSelectOptions.ts +3 -0
- package/src/components/headless/forms/index.ts +9 -1
- package/src/components/headless/modals/AGHeadlessModal.ts +27 -0
- package/src/components/headless/modals/AGHeadlessModal.vue +3 -5
- package/src/components/headless/modals/index.ts +4 -6
- package/src/components/headless/snackbars/index.ts +23 -8
- package/src/components/index.ts +1 -1
- package/src/components/lib/AGMeasured.vue +15 -0
- package/src/components/lib/AGStartupCrash.vue +31 -0
- package/src/components/lib/index.ts +5 -0
- package/src/components/modals/AGAlertModal.ts +15 -0
- package/src/components/modals/AGAlertModal.vue +4 -15
- package/src/components/modals/AGConfirmModal.ts +27 -0
- package/src/components/modals/AGConfirmModal.vue +7 -11
- package/src/components/modals/AGErrorReportModal.ts +27 -1
- package/src/components/modals/AGErrorReportModal.vue +8 -16
- package/src/components/modals/AGErrorReportModalButtons.vue +4 -2
- package/src/components/modals/AGErrorReportModalTitle.vue +1 -1
- package/src/components/modals/AGLoadingModal.ts +23 -0
- package/src/components/modals/AGLoadingModal.vue +4 -8
- package/src/components/modals/AGModal.ts +1 -1
- package/src/components/modals/AGModal.vue +14 -12
- package/src/components/modals/index.ts +3 -0
- package/src/components/snackbars/AGSnackbar.vue +3 -9
- package/src/components/utils.ts +10 -0
- package/src/directives/index.ts +3 -1
- package/src/directives/measure.ts +12 -0
- package/src/errors/Errors.ts +10 -5
- package/src/errors/index.ts +9 -13
- package/src/forms/Form.ts +11 -3
- package/src/main.histoire.ts +1 -0
- package/src/services/App.state.ts +3 -3
- package/src/services/App.ts +10 -1
- package/src/services/Service.ts +8 -4
- package/src/services/index.ts +1 -1
- package/src/ui/UI.ts +77 -14
- package/src/ui/index.ts +6 -3
- package/src/utils/composition/events.ts +1 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/tailwindcss.test.ts +26 -0
- package/src/utils/tailwindcss.ts +7 -0
- package/src/utils/vue.ts +13 -4
- package/tailwind.config.js +4 -0
- package/tsconfig.json +1 -1
- package/.eslintrc.js +0 -3
- package/dist/virtual.d.ts +0 -11
- package/src/components/basic/index.ts +0 -5
- package/src/types/virtual.d.ts +0 -11
- /package/src/components/{basic → lib}/AGErrorMessage.vue +0 -0
- /package/src/components/{basic → lib}/AGLink.vue +0 -0
- /package/src/components/{basic → lib}/AGMarkdown.vue +0 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aerogel/core",
|
|
3
3
|
"description": "The Lightest Solid",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.f1f5a990033d966dc0bb12d251110fbc9350dcc7",
|
|
5
5
|
"main": "dist/aerogel-core.cjs.js",
|
|
6
6
|
"module": "dist/aerogel-core.esm.js",
|
|
7
7
|
"types": "dist/aerogel-core.d.ts",
|
|
@@ -9,10 +9,12 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "rm dist -rf && npm run build:js && npm run build:types",
|
|
11
11
|
"build:js": "noeldemartin-build-javascript",
|
|
12
|
-
"build:types": "noeldemartin-build-types
|
|
12
|
+
"build:types": "noeldemartin-build-types",
|
|
13
|
+
"histoire": "histoire dev",
|
|
13
14
|
"lint": "noeldemartin-lint src",
|
|
14
15
|
"publish-next": "noeldemartin-publish-next",
|
|
15
|
-
"test": "vitest --run"
|
|
16
|
+
"test": "vitest --run",
|
|
17
|
+
"test:ci": "vitest --run --reporter verbose"
|
|
16
18
|
},
|
|
17
19
|
"engines": {
|
|
18
20
|
"node": ">=18.x"
|
|
@@ -33,7 +35,7 @@
|
|
|
33
35
|
},
|
|
34
36
|
"dependencies": {
|
|
35
37
|
"@headlessui/vue": "^1.7.14",
|
|
36
|
-
"@noeldemartin/utils": "0.
|
|
38
|
+
"@noeldemartin/utils": "0.5.0-next.dce7f1ca99862fde01601bb39d71d0eaaed3abe5",
|
|
37
39
|
"dompurify": "^3.0.3",
|
|
38
40
|
"marked": "^5.0.4",
|
|
39
41
|
"pinia": "^2.1.6",
|
|
@@ -41,7 +43,14 @@
|
|
|
41
43
|
},
|
|
42
44
|
"devDependencies": {
|
|
43
45
|
"@aerogel/vite": "*",
|
|
46
|
+
"@histoire/plugin-vue": "^0.17.6",
|
|
44
47
|
"@types/dompurify": "^3.0.2",
|
|
45
|
-
"@types/marked": "^5.0.0"
|
|
48
|
+
"@types/marked": "^5.0.0",
|
|
49
|
+
"tailwindcss": "^3.3.5"
|
|
50
|
+
},
|
|
51
|
+
"eslintConfig": {
|
|
52
|
+
"extends": [
|
|
53
|
+
"@noeldemartin/eslint-config-vue"
|
|
54
|
+
]
|
|
46
55
|
}
|
|
47
56
|
}
|
|
@@ -6,11 +6,12 @@ import type { Component } from 'vue';
|
|
|
6
6
|
import Events from '@/services/Events';
|
|
7
7
|
import initialFocus from '@/directives/initial-focus';
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { bootstrap } from './index';
|
|
10
10
|
|
|
11
11
|
describe('Aerogel', () => {
|
|
12
12
|
|
|
13
13
|
beforeEach(() => {
|
|
14
|
+
vi.stubGlobal('document', { getElementById: () => null });
|
|
14
15
|
vi.mock('vue', async () => {
|
|
15
16
|
const vue = (await vi.importActual('vue')) as Object;
|
|
16
17
|
|
|
@@ -31,7 +32,7 @@ describe('Aerogel', () => {
|
|
|
31
32
|
const rootComponent = mock<Component>();
|
|
32
33
|
|
|
33
34
|
// Act
|
|
34
|
-
await
|
|
35
|
+
await bootstrap(rootComponent);
|
|
35
36
|
|
|
36
37
|
// Assert
|
|
37
38
|
const globals = vi.mocked(createApp).mock.results[0]?.value.config.globalProperties;
|
|
@@ -45,7 +46,7 @@ describe('Aerogel', () => {
|
|
|
45
46
|
const rootComponent = mock<Component>();
|
|
46
47
|
|
|
47
48
|
// Act
|
|
48
|
-
await
|
|
49
|
+
await bootstrap(rootComponent);
|
|
49
50
|
|
|
50
51
|
// Assert
|
|
51
52
|
expect(vi.mocked(createApp).mock.results[0]?.value.directive).toHaveBeenCalledWith(
|
package/src/bootstrap/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createApp } from 'vue';
|
|
2
|
-
import type { Component } from 'vue';
|
|
2
|
+
import type { App, Component } from 'vue';
|
|
3
3
|
|
|
4
4
|
import directives from '@/directives';
|
|
5
5
|
import errors from '@/errors';
|
|
@@ -10,12 +10,27 @@ import ui from '@/ui';
|
|
|
10
10
|
import { installPlugins } from '@/plugins';
|
|
11
11
|
import type { AerogelOptions } from '@/bootstrap/options';
|
|
12
12
|
|
|
13
|
-
export
|
|
13
|
+
export { AerogelOptions };
|
|
14
|
+
|
|
15
|
+
export async function bootstrapApplication(app: App, options: AerogelOptions = {}): Promise<void> {
|
|
14
16
|
const plugins = [directives, errors, lang, services, ui, ...(options.plugins ?? [])];
|
|
15
|
-
const app = createApp(rootComponent);
|
|
16
17
|
|
|
17
18
|
await installPlugins(plugins, app, options);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function bootstrap(rootComponent: Component, options: AerogelOptions = {}): Promise<void> {
|
|
22
|
+
const app = createApp(rootComponent);
|
|
23
|
+
|
|
24
|
+
await bootstrapApplication(app, options);
|
|
18
25
|
|
|
19
26
|
app.mount('#app');
|
|
27
|
+
app._container?.classList.remove('loading');
|
|
28
|
+
|
|
20
29
|
Events.emit('application-mounted');
|
|
21
30
|
}
|
|
31
|
+
|
|
32
|
+
declare module '@/services/Events' {
|
|
33
|
+
export interface EventsPayload {
|
|
34
|
+
'application-mounted': void;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div class="flex h-full flex-col text-base font-normal leading-tight text-gray-900 antialiased">
|
|
3
|
-
<slot
|
|
2
|
+
<div class="flex min-h-full flex-col text-base font-normal leading-tight text-gray-900 antialiased">
|
|
3
|
+
<slot v-if="$errors.hasStartupErrors" name="startup-crash">
|
|
4
|
+
<component :is="$ui.requireComponent(UIComponents.StartupCrash)" />
|
|
5
|
+
</slot>
|
|
6
|
+
<slot v-else />
|
|
4
7
|
|
|
5
8
|
<AGAppOverlays />
|
|
6
9
|
</div>
|
|
7
10
|
</template>
|
|
8
11
|
|
|
9
12
|
<script setup lang="ts">
|
|
13
|
+
import { UIComponents } from '@/ui/UI';
|
|
14
|
+
|
|
10
15
|
import AGAppOverlays from './AGAppOverlays.vue';
|
|
11
16
|
</script>
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div
|
|
2
|
+
<div
|
|
3
|
+
id="aerogel-overlays-backdrop"
|
|
4
|
+
ref="$backdrop"
|
|
5
|
+
class="pointer-events-none fixed inset-0 z-50 bg-black/30 opacity-0"
|
|
6
|
+
/>
|
|
3
7
|
<AGAppModals />
|
|
4
8
|
<AGAppSnackbars />
|
|
5
9
|
</template>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div aria-live="assertive" class="z-60 pointer-events-none fixed inset-0 flex items-end px-4 py-6 sm:p-6">
|
|
3
|
-
<div class="flex w-full flex-col items-
|
|
3
|
+
<div class="flex w-full flex-col items-end space-y-4">
|
|
4
4
|
<component
|
|
5
5
|
:is="snackbar.component"
|
|
6
6
|
v-for="snackbar of $ui.snackbars"
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<Story>
|
|
3
|
+
<div class="h-96">
|
|
4
|
+
<AGSelect v-model="bestMugiwara" :label="label" :options="options" />
|
|
5
|
+
</div>
|
|
6
|
+
</Story>
|
|
7
|
+
</template>
|
|
8
|
+
|
|
9
|
+
<script setup lang="ts">
|
|
10
|
+
import { ref } from 'vue';
|
|
11
|
+
|
|
12
|
+
import AGSelect from './AGSelect.vue';
|
|
13
|
+
|
|
14
|
+
const bestMugiwara = ref(null);
|
|
15
|
+
const label = 'Who\'s the best Mugiwara?';
|
|
16
|
+
const options = [
|
|
17
|
+
'Monkey D. Luffy',
|
|
18
|
+
'Roronoa Zoro',
|
|
19
|
+
'Nami',
|
|
20
|
+
'Usopp',
|
|
21
|
+
'Sanji',
|
|
22
|
+
'Tony Tony Chopper',
|
|
23
|
+
'Nico Robin',
|
|
24
|
+
'Franky',
|
|
25
|
+
'Brook',
|
|
26
|
+
'Jinbe',
|
|
27
|
+
];
|
|
28
|
+
</script>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<AGHeadlessSelect v-bind="props" ref="$select" as="div">
|
|
3
|
+
<AGHeadlessSelectLabel class="block text-sm font-medium leading-6 text-gray-900" />
|
|
4
|
+
<div class="relative" :class="{ 'mt-2': $select?.label }">
|
|
5
|
+
<AGHeadlessSelectButton
|
|
6
|
+
class="relative w-full cursor-default bg-white py-1.5 pl-3 pr-10 text-left text-gray-900 ring-1 ring-inset ring-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-600"
|
|
7
|
+
text-class="block truncate"
|
|
8
|
+
:class="{
|
|
9
|
+
'ring-1 ring-red-500': $select?.errors,
|
|
10
|
+
}"
|
|
11
|
+
>
|
|
12
|
+
<template #icon>
|
|
13
|
+
<span class="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2">
|
|
14
|
+
<IconCheveronDown class="h-5 w-5 text-gray-400" />
|
|
15
|
+
</span>
|
|
16
|
+
</template>
|
|
17
|
+
</AGHeadlessSelectButton>
|
|
18
|
+
<AGHeadlessSelectOptions
|
|
19
|
+
class="absolute z-10 mt-1 max-h-60 w-full overflow-auto border bg-white py-1 text-base ring-1 ring-black ring-opacity-5 focus:outline-none"
|
|
20
|
+
>
|
|
21
|
+
<AGHeadlessSelectOption
|
|
22
|
+
v-for="(option, index) in $select?.options ?? []"
|
|
23
|
+
:key="index"
|
|
24
|
+
:value="option.value"
|
|
25
|
+
class="relative block cursor-default select-none truncate py-2 pl-3 pr-9"
|
|
26
|
+
selected-class="font-semibold"
|
|
27
|
+
unselected-class="font-normal"
|
|
28
|
+
active-class="bg-indigo-600 text-white"
|
|
29
|
+
inactive-class="text-gray-900"
|
|
30
|
+
/>
|
|
31
|
+
</AGHeadlessSelectOptions>
|
|
32
|
+
</div>
|
|
33
|
+
<AGHeadlessSelectError class="mt-2 text-sm text-red-600" />
|
|
34
|
+
</AGHeadlessSelect>
|
|
35
|
+
</template>
|
|
36
|
+
|
|
37
|
+
<script setup lang="ts">
|
|
38
|
+
import IconCheveronDown from '~icons/zondicons/cheveron-down';
|
|
39
|
+
|
|
40
|
+
import { componentRef } from '@/utils/vue';
|
|
41
|
+
import { useSelectProps } from '@/components/headless/forms/AGHeadlessSelect';
|
|
42
|
+
import type { IAGHeadlessSelect } from '@/components/headless/forms/AGHeadlessSelect';
|
|
43
|
+
|
|
44
|
+
import AGHeadlessSelect from '../headless/forms/AGHeadlessSelect.vue';
|
|
45
|
+
import AGHeadlessSelectButton from '../headless/forms/AGHeadlessSelectButton.vue';
|
|
46
|
+
import AGHeadlessSelectError from '../headless/forms/AGHeadlessSelectError.vue';
|
|
47
|
+
import AGHeadlessSelectLabel from '../headless/forms/AGHeadlessSelectLabel.vue';
|
|
48
|
+
import AGHeadlessSelectOption from '../headless/forms/AGHeadlessSelectOption.vue';
|
|
49
|
+
import AGHeadlessSelectOptions from '../headless/forms/AGHeadlessSelectOptions';
|
|
50
|
+
|
|
51
|
+
const props = defineProps(useSelectProps());
|
|
52
|
+
const $select = componentRef<IAGHeadlessSelect>();
|
|
53
|
+
</script>
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export { AGButton, AGCheckbox, AGForm, AGInput };
|
|
1
|
+
export { default as AGButton } from './AGButton.vue';
|
|
2
|
+
export { default as AGCheckbox } from './AGCheckbox.vue';
|
|
3
|
+
export { default as AGForm } from './AGForm.vue';
|
|
4
|
+
export { default as AGInput } from './AGInput.vue';
|
|
5
|
+
export { default as AGSelect } from './AGSelect.vue';
|
|
@@ -1,8 +1,28 @@
|
|
|
1
|
-
import type { ComputedRef, DeepReadonly, Ref } from 'vue';
|
|
1
|
+
import type { ComputedRef, DeepReadonly, ExtractPropTypes, Ref } from 'vue';
|
|
2
|
+
|
|
3
|
+
import { stringProp } from '@/utils';
|
|
4
|
+
import { extractComponentProps } from '@/components/utils';
|
|
2
5
|
|
|
3
6
|
export interface IAGHeadlessInput {
|
|
4
7
|
id: string;
|
|
8
|
+
name: ComputedRef<string | null>;
|
|
9
|
+
label: ComputedRef<string | null>;
|
|
5
10
|
value: ComputedRef<string | number | boolean | null>;
|
|
6
11
|
errors: DeepReadonly<Ref<string[] | null>>;
|
|
7
12
|
update(value: string | number | boolean | null): void;
|
|
8
13
|
}
|
|
14
|
+
|
|
15
|
+
export const inputProps = {
|
|
16
|
+
name: stringProp(),
|
|
17
|
+
label: stringProp(),
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export function useInputProps(): typeof inputProps {
|
|
21
|
+
return inputProps;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function extractInputProps<T extends ExtractPropTypes<typeof inputProps>>(
|
|
25
|
+
props: T,
|
|
26
|
+
): Pick<T, keyof typeof inputProps> {
|
|
27
|
+
return extractComponentProps(props, inputProps);
|
|
28
|
+
}
|
|
@@ -12,13 +12,14 @@ import { uuid } from '@noeldemartin/utils';
|
|
|
12
12
|
import { mixedProp, stringProp } from '@/utils/vue';
|
|
13
13
|
import type Form from '@/forms/Form';
|
|
14
14
|
|
|
15
|
+
import { useInputProps } from './AGHeadlessInput';
|
|
15
16
|
import type { IAGHeadlessInput } from './AGHeadlessInput';
|
|
16
17
|
|
|
17
18
|
const emit = defineEmits(['update:modelValue']);
|
|
18
19
|
const props = defineProps({
|
|
19
20
|
as: stringProp('div'),
|
|
20
|
-
name: stringProp(),
|
|
21
21
|
modelValue: mixedProp<string | number | boolean>([String, Number, Boolean]),
|
|
22
|
+
...useInputProps(),
|
|
22
23
|
});
|
|
23
24
|
const errors = computed(() => {
|
|
24
25
|
if (!form || !props.name) {
|
|
@@ -28,11 +29,13 @@ const errors = computed(() => {
|
|
|
28
29
|
return form.errors[props.name] ?? null;
|
|
29
30
|
});
|
|
30
31
|
const form = inject<Form | null>('form', null);
|
|
31
|
-
const
|
|
32
|
+
const api: IAGHeadlessInput = {
|
|
32
33
|
id: `input-${uuid()}`,
|
|
34
|
+
name: computed(() => props.name),
|
|
35
|
+
label: computed(() => props.label),
|
|
33
36
|
value: computed(() => {
|
|
34
37
|
if (form && props.name) {
|
|
35
|
-
return form.getFieldValue(props.name);
|
|
38
|
+
return form.getFieldValue(props.name) as string | number | boolean | null;
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
return props.modelValue;
|
|
@@ -49,6 +52,6 @@ const publicApi: IAGHeadlessInput = {
|
|
|
49
52
|
},
|
|
50
53
|
};
|
|
51
54
|
|
|
52
|
-
provide<IAGHeadlessInput>('input',
|
|
53
|
-
defineExpose<IAGHeadlessInput>(
|
|
55
|
+
provide<IAGHeadlessInput>('input', api);
|
|
56
|
+
defineExpose<IAGHeadlessInput>(api);
|
|
54
57
|
</script>
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<label :for="input.id">
|
|
3
|
-
<slot
|
|
2
|
+
<label v-if="show" :for="input.id">
|
|
3
|
+
<slot>
|
|
4
|
+
{{ input.label }}
|
|
5
|
+
</slot>
|
|
4
6
|
</label>
|
|
5
7
|
</template>
|
|
6
8
|
|
|
7
9
|
<script setup lang="ts">
|
|
10
|
+
import { computed, useSlots } from 'vue';
|
|
11
|
+
|
|
8
12
|
import { injectReactiveOrFail } from '@/utils/vue';
|
|
9
13
|
|
|
10
14
|
import type { IAGHeadlessInput } from './AGHeadlessInput';
|
|
@@ -13,4 +17,6 @@ const input = injectReactiveOrFail<IAGHeadlessInput>(
|
|
|
13
17
|
'input',
|
|
14
18
|
'<AGHeadlessInputLabel> must be a child of a <AGHeadlessInput>',
|
|
15
19
|
);
|
|
20
|
+
const slots = useSlots();
|
|
21
|
+
const show = computed(() => !!(input.label || slots.default));
|
|
16
22
|
</script>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ComputedRef, DeepReadonly, ExtractPropTypes, Ref } from 'vue';
|
|
2
|
+
|
|
3
|
+
import { requiredArrayProp, stringProp } from '@/utils/vue';
|
|
4
|
+
import { extractComponentProps } from '@/components/utils';
|
|
5
|
+
|
|
6
|
+
export interface IAGSelectOption {
|
|
7
|
+
value: string | number | boolean | object | null;
|
|
8
|
+
text: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type IAGSelectOptionValue = string | number | boolean | object | null;
|
|
12
|
+
|
|
13
|
+
export interface IAGHeadlessSelect {
|
|
14
|
+
id: string;
|
|
15
|
+
label: ComputedRef<string | null>;
|
|
16
|
+
noSelectionText: ComputedRef<string>;
|
|
17
|
+
buttonText: ComputedRef<string>;
|
|
18
|
+
selectedOption: ComputedRef<IAGSelectOption | undefined>;
|
|
19
|
+
options: ComputedRef<IAGSelectOption[]>;
|
|
20
|
+
errors: DeepReadonly<Ref<string[] | null>>;
|
|
21
|
+
update(value: IAGSelectOptionValue): void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const selectProps = {
|
|
25
|
+
name: stringProp(),
|
|
26
|
+
label: stringProp(),
|
|
27
|
+
options: requiredArrayProp<IAGSelectOptionValue>(),
|
|
28
|
+
noSelectionText: stringProp(),
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export function useSelectProps(): typeof selectProps {
|
|
32
|
+
return selectProps;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function extractSelectProps<T extends ExtractPropTypes<typeof selectProps>>(
|
|
36
|
+
props: T,
|
|
37
|
+
): Pick<T, keyof typeof selectProps> {
|
|
38
|
+
return extractComponentProps(props, selectProps);
|
|
39
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<Listbox
|
|
3
|
+
v-slot="{ value, open, disabled }: ComponentProps"
|
|
4
|
+
:model-value="selectedOption?.value"
|
|
5
|
+
@update:model-value="update($event)"
|
|
6
|
+
>
|
|
7
|
+
<slot :value="value" :open="open" :disabled="disabled" />
|
|
8
|
+
</Listbox>
|
|
9
|
+
</template>
|
|
10
|
+
|
|
11
|
+
<script setup lang="ts">
|
|
12
|
+
import { computed, inject, provide } from 'vue';
|
|
13
|
+
import { isObject, toString, uuid } from '@noeldemartin/utils';
|
|
14
|
+
import { Listbox } from '@headlessui/vue';
|
|
15
|
+
|
|
16
|
+
import { mixedProp } from '@/utils/vue';
|
|
17
|
+
import { translateWithDefault } from '@/lang/utils';
|
|
18
|
+
import type Form from '@/forms/Form';
|
|
19
|
+
import type { ComponentProps } from '@/utils/vue';
|
|
20
|
+
|
|
21
|
+
import { useSelectProps } from './AGHeadlessSelect';
|
|
22
|
+
import type { IAGHeadlessSelect, IAGSelectOption, IAGSelectOptionValue } from './AGHeadlessSelect';
|
|
23
|
+
|
|
24
|
+
const emit = defineEmits(['update:modelValue']);
|
|
25
|
+
const props = defineProps({
|
|
26
|
+
modelValue: mixedProp<IAGSelectOptionValue>(),
|
|
27
|
+
...useSelectProps(),
|
|
28
|
+
});
|
|
29
|
+
const form = inject<Form | null>('form', null);
|
|
30
|
+
const noSelectionText = computed(() => props.noSelectionText ?? translateWithDefault('select.noSelection', '-'));
|
|
31
|
+
const options = computed(() =>
|
|
32
|
+
props.options.map((value) => {
|
|
33
|
+
const option: IAGSelectOption = {
|
|
34
|
+
value,
|
|
35
|
+
text: toString(isObject(value) && 'text' in value ? value.text : value),
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
return option;
|
|
39
|
+
}));
|
|
40
|
+
const selectedOption = computed(() => {
|
|
41
|
+
const selectedOptionValue = form && props.name ? form.getFieldValue(props.name) : props.modelValue;
|
|
42
|
+
|
|
43
|
+
return options.value.find((option) => option.value === selectedOptionValue);
|
|
44
|
+
});
|
|
45
|
+
const errors = computed(() => {
|
|
46
|
+
if (!form || !props.name) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return form.errors[props.name] ?? null;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
function update(value: IAGSelectOptionValue) {
|
|
54
|
+
if (form && props.name) {
|
|
55
|
+
form.setFieldValue(props.name, value);
|
|
56
|
+
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
emit('update:modelValue', value);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const api: IAGHeadlessSelect = {
|
|
64
|
+
id: `select-${uuid()}`,
|
|
65
|
+
options,
|
|
66
|
+
noSelectionText,
|
|
67
|
+
selectedOption,
|
|
68
|
+
errors,
|
|
69
|
+
label: computed(() => props.label),
|
|
70
|
+
buttonText: computed(() => selectedOption.value?.text ?? noSelectionText.value),
|
|
71
|
+
update,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
provide<IAGHeadlessSelect>('select', api);
|
|
75
|
+
defineExpose<IAGHeadlessSelect>(api);
|
|
76
|
+
</script>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<ListboxButton v-slot="{ value, open, disabled }: ComponentProps">
|
|
3
|
+
<slot :value="value" :open="open" :disabled="disabled">
|
|
4
|
+
<span :class="textClass">{{ select?.buttonText }}</span>
|
|
5
|
+
</slot>
|
|
6
|
+
<slot name="icon" />
|
|
7
|
+
</ListboxButton>
|
|
8
|
+
</template>
|
|
9
|
+
|
|
10
|
+
<script setup lang="ts">
|
|
11
|
+
import { ListboxButton } from '@headlessui/vue';
|
|
12
|
+
|
|
13
|
+
import { injectReactiveOrFail, stringProp } from '@/utils/vue';
|
|
14
|
+
import type { ComponentProps } from '@/utils/vue';
|
|
15
|
+
|
|
16
|
+
import type { IAGHeadlessSelect } from './AGHeadlessSelect';
|
|
17
|
+
|
|
18
|
+
defineProps({ textClass: stringProp() });
|
|
19
|
+
|
|
20
|
+
const select = injectReactiveOrFail<IAGHeadlessSelect>(
|
|
21
|
+
'select',
|
|
22
|
+
'<AGHeadlessSelectButton> must be a child of a <AGHeadlessSelect>',
|
|
23
|
+
);
|
|
24
|
+
</script>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<p v-if="errorMessage" :id="`${select.id}-error`">
|
|
3
|
+
{{ errorMessage }}
|
|
4
|
+
</p>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script setup lang="ts">
|
|
8
|
+
import { computed } from 'vue';
|
|
9
|
+
|
|
10
|
+
import { injectReactiveOrFail } from '@/utils/vue';
|
|
11
|
+
import { translateWithDefault } from '@/lang/utils';
|
|
12
|
+
|
|
13
|
+
import type { IAGHeadlessSelect } from './AGHeadlessSelect';
|
|
14
|
+
|
|
15
|
+
const select = injectReactiveOrFail<IAGHeadlessSelect>(
|
|
16
|
+
'select',
|
|
17
|
+
'<AGHeadlessSelectError> must be a child of a <AGHeadlessSelect>',
|
|
18
|
+
);
|
|
19
|
+
const errorMessage = computed(() => {
|
|
20
|
+
if (!select.errors) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return translateWithDefault(`errors.${select.errors[0]}`, `Error: ${select.errors[0]}`);
|
|
25
|
+
});
|
|
26
|
+
</script>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<ListboxLabel v-if="show" v-slot="{ open, disabled }: ComponentProps">
|
|
3
|
+
<slot :open="open" :disabled="disabled">
|
|
4
|
+
{{ select.label }}
|
|
5
|
+
</slot>
|
|
6
|
+
</ListboxLabel>
|
|
7
|
+
</template>
|
|
8
|
+
|
|
9
|
+
<script setup lang="ts">
|
|
10
|
+
import { computed, useSlots } from 'vue';
|
|
11
|
+
import { ListboxLabel } from '@headlessui/vue';
|
|
12
|
+
|
|
13
|
+
import { injectReactiveOrFail } from '@/utils/vue';
|
|
14
|
+
import type { ComponentProps } from '@/utils/vue';
|
|
15
|
+
|
|
16
|
+
import type { IAGHeadlessSelect } from './AGHeadlessSelect';
|
|
17
|
+
|
|
18
|
+
const select = injectReactiveOrFail<IAGHeadlessSelect>(
|
|
19
|
+
'select',
|
|
20
|
+
'<AGHeadlessSelectLabel> must be a child of a <AGHeadlessSelect>',
|
|
21
|
+
);
|
|
22
|
+
const slots = useSlots();
|
|
23
|
+
const show = computed(() => !!(select.label || slots.default));
|
|
24
|
+
</script>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<ListboxOption v-slot="{ active, selected, disabled }: ComponentProps" :value="value" as="template">
|
|
3
|
+
<slot :active="active" :selected="selected" :disabled="disabled">
|
|
4
|
+
<li
|
|
5
|
+
:class="{
|
|
6
|
+
[activeClass ?? 'active']: active,
|
|
7
|
+
[inactiveClass ?? 'inactive']: !active,
|
|
8
|
+
[selectedClass ?? 'selected']: selected,
|
|
9
|
+
[unselectedClass ?? 'unselected']: !selected,
|
|
10
|
+
}"
|
|
11
|
+
>
|
|
12
|
+
{{ option?.text }}
|
|
13
|
+
</li>
|
|
14
|
+
</slot>
|
|
15
|
+
</ListboxOption>
|
|
16
|
+
</template>
|
|
17
|
+
|
|
18
|
+
<script setup lang="ts">
|
|
19
|
+
import { computed } from 'vue';
|
|
20
|
+
import { ListboxOption } from '@headlessui/vue';
|
|
21
|
+
|
|
22
|
+
import { injectReactiveOrFail, requiredMixedProp, stringProp } from '@/utils/vue';
|
|
23
|
+
import type { ComponentProps } from '@/utils/vue';
|
|
24
|
+
|
|
25
|
+
import type { IAGHeadlessSelect, IAGSelectOptionValue } from './AGHeadlessSelect';
|
|
26
|
+
|
|
27
|
+
const props = defineProps({
|
|
28
|
+
value: requiredMixedProp<IAGSelectOptionValue>(),
|
|
29
|
+
selectedClass: stringProp(),
|
|
30
|
+
unselectedClass: stringProp(),
|
|
31
|
+
activeClass: stringProp(),
|
|
32
|
+
inactiveClass: stringProp(),
|
|
33
|
+
});
|
|
34
|
+
const select = injectReactiveOrFail<IAGHeadlessSelect>(
|
|
35
|
+
'select',
|
|
36
|
+
'<AGHeadlessSelectOption> must be a child of a <AGHeadlessSelect>',
|
|
37
|
+
);
|
|
38
|
+
const option = computed(() => select.options.find((selectOption) => selectOption.value === props.value));
|
|
39
|
+
</script>
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './AGHeadlessInput';
|
|
2
|
+
export * from './AGHeadlessSelect';
|
|
3
|
+
export * from './AGHeadlessSelectOption';
|
|
2
4
|
export { default as AGHeadlessButton } from './AGHeadlessButton.vue';
|
|
3
5
|
export { default as AGHeadlessInput } from './AGHeadlessInput.vue';
|
|
4
6
|
export { default as AGHeadlessInputError } from './AGHeadlessInputError.vue';
|
|
5
7
|
export { default as AGHeadlessInputInput } from './AGHeadlessInputInput.vue';
|
|
6
8
|
export { default as AGHeadlessInputLabel } from './AGHeadlessInputLabel.vue';
|
|
9
|
+
export { default as AGHeadlessSelect } from './AGHeadlessSelect.vue';
|
|
10
|
+
export { default as AGHeadlessSelectButton } from './AGHeadlessSelectButton.vue';
|
|
11
|
+
export { default as AGHeadlessSelectError } from './AGHeadlessSelectError.vue';
|
|
12
|
+
export { default as AGHeadlessSelectLabel } from './AGHeadlessSelectLabel.vue';
|
|
13
|
+
export { default as AGHeadlessSelectOption } from './AGHeadlessSelectOption.vue';
|
|
14
|
+
export { default as AGHeadlessSelectOptions } from './AGHeadlessSelectOptions';
|