@aerogel/core 0.0.0-next.7f6ed5a1f91688a86bf5ede2adc465e4fd6cfdea → 0.0.0-next.824cf5311c4335d119158f507dad094ed4f4f0b6

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 (120) hide show
  1. package/dist/aerogel-core.cjs.js +1 -1
  2. package/dist/aerogel-core.cjs.js.map +1 -1
  3. package/dist/aerogel-core.d.ts +1630 -204
  4. package/dist/aerogel-core.esm.js +1 -1
  5. package/dist/aerogel-core.esm.js.map +1 -1
  6. package/histoire.config.ts +7 -0
  7. package/noeldemartin.config.js +4 -1
  8. package/package.json +15 -8
  9. package/postcss.config.js +6 -0
  10. package/src/assets/histoire.css +3 -0
  11. package/src/bootstrap/bootstrap.test.ts +4 -59
  12. package/src/bootstrap/index.ts +31 -28
  13. package/src/bootstrap/options.ts +8 -1
  14. package/src/components/AGAppLayout.vue +7 -2
  15. package/src/components/AGAppModals.vue +15 -0
  16. package/src/components/AGAppOverlays.vue +10 -8
  17. package/src/components/AGAppSnackbars.vue +13 -0
  18. package/src/components/constants.ts +8 -0
  19. package/src/components/forms/AGButton.vue +36 -3
  20. package/src/components/forms/AGCheckbox.vue +41 -0
  21. package/src/components/forms/AGInput.vue +15 -9
  22. package/src/components/forms/AGSelect.story.vue +46 -0
  23. package/src/components/forms/AGSelect.vue +60 -0
  24. package/src/components/forms/index.ts +5 -5
  25. package/src/components/headless/forms/AGHeadlessButton.vue +7 -7
  26. package/src/components/headless/forms/AGHeadlessInput.ts +23 -3
  27. package/src/components/headless/forms/AGHeadlessInput.vue +13 -10
  28. package/src/components/headless/forms/AGHeadlessInputError.vue +9 -5
  29. package/src/components/headless/forms/AGHeadlessInputInput.vue +20 -4
  30. package/src/components/headless/forms/AGHeadlessInputLabel.vue +22 -0
  31. package/src/components/headless/forms/AGHeadlessSelect.ts +42 -0
  32. package/src/components/headless/forms/AGHeadlessSelect.vue +77 -0
  33. package/src/components/headless/forms/AGHeadlessSelectButton.vue +24 -0
  34. package/src/components/headless/forms/AGHeadlessSelectError.vue +26 -0
  35. package/src/components/headless/forms/AGHeadlessSelectLabel.vue +24 -0
  36. package/src/components/headless/forms/AGHeadlessSelectOption.ts +4 -0
  37. package/src/components/headless/forms/AGHeadlessSelectOption.vue +39 -0
  38. package/src/components/headless/forms/AGHeadlessSelectOptions.ts +3 -0
  39. package/src/components/headless/forms/index.ts +14 -4
  40. package/src/components/headless/index.ts +1 -0
  41. package/src/components/headless/modals/AGHeadlessModal.ts +27 -0
  42. package/src/components/headless/modals/AGHeadlessModal.vue +8 -6
  43. package/src/components/headless/modals/AGHeadlessModalPanel.vue +10 -2
  44. package/src/components/headless/modals/index.ts +4 -6
  45. package/src/components/headless/snackbars/AGHeadlessSnackbar.vue +10 -0
  46. package/src/components/headless/snackbars/index.ts +40 -0
  47. package/src/components/index.ts +5 -2
  48. package/src/components/lib/AGErrorMessage.vue +16 -0
  49. package/src/components/lib/AGLink.vue +9 -0
  50. package/src/components/lib/AGMarkdown.vue +36 -0
  51. package/src/components/lib/AGMeasured.vue +15 -0
  52. package/src/components/lib/AGStartupCrash.vue +31 -0
  53. package/src/components/lib/index.ts +5 -0
  54. package/src/components/modals/AGAlertModal.ts +15 -0
  55. package/src/components/modals/AGAlertModal.vue +4 -5
  56. package/src/components/modals/AGConfirmModal.ts +27 -0
  57. package/src/components/modals/AGConfirmModal.vue +26 -0
  58. package/src/components/modals/AGErrorReportModal.ts +46 -0
  59. package/src/components/modals/AGErrorReportModal.vue +54 -0
  60. package/src/components/modals/AGErrorReportModalButtons.vue +111 -0
  61. package/src/components/modals/AGErrorReportModalTitle.vue +25 -0
  62. package/src/components/modals/AGLoadingModal.ts +23 -0
  63. package/src/components/modals/AGLoadingModal.vue +15 -0
  64. package/src/components/modals/AGModal.ts +5 -1
  65. package/src/components/modals/AGModal.vue +26 -5
  66. package/src/components/modals/AGModalTitle.vue +9 -0
  67. package/src/components/modals/AGPromptModal.ts +30 -0
  68. package/src/components/modals/AGPromptModal.vue +34 -0
  69. package/src/components/modals/index.ts +16 -4
  70. package/src/components/snackbars/AGSnackbar.vue +36 -0
  71. package/src/components/snackbars/index.ts +3 -0
  72. package/src/components/utils.ts +10 -0
  73. package/src/directives/index.ts +21 -4
  74. package/src/directives/measure.ts +12 -0
  75. package/src/errors/Errors.state.ts +31 -0
  76. package/src/errors/Errors.ts +192 -0
  77. package/src/errors/index.ts +45 -0
  78. package/src/forms/Form.test.ts +21 -0
  79. package/src/forms/Form.ts +48 -17
  80. package/src/forms/utils.ts +17 -0
  81. package/src/jobs/Job.ts +5 -0
  82. package/src/jobs/index.ts +7 -0
  83. package/src/lang/Lang.ts +48 -9
  84. package/src/lang/index.ts +17 -76
  85. package/src/lang/utils.ts +4 -0
  86. package/src/main.histoire.ts +1 -0
  87. package/src/main.ts +3 -0
  88. package/src/plugins/Plugin.ts +8 -0
  89. package/src/plugins/index.ts +26 -0
  90. package/src/services/App.state.ts +17 -0
  91. package/src/services/App.ts +47 -0
  92. package/src/services/Events.test.ts +39 -0
  93. package/src/services/Events.ts +88 -30
  94. package/src/services/Service.ts +195 -33
  95. package/src/services/index.ts +33 -7
  96. package/src/services/store.ts +30 -0
  97. package/src/types/vite.d.ts +0 -2
  98. package/src/ui/UI.state.ts +12 -6
  99. package/src/ui/UI.ts +177 -12
  100. package/src/ui/index.ts +31 -16
  101. package/src/utils/composition/events.ts +1 -0
  102. package/src/utils/composition/forms.ts +11 -0
  103. package/src/utils/composition/hooks.ts +9 -0
  104. package/src/utils/index.ts +4 -0
  105. package/src/utils/markdown.ts +11 -2
  106. package/src/utils/tailwindcss.test.ts +26 -0
  107. package/src/utils/tailwindcss.ts +7 -0
  108. package/src/utils/vue.ts +15 -4
  109. package/tailwind.config.js +4 -0
  110. package/tsconfig.json +2 -10
  111. package/vite.config.ts +3 -6
  112. package/.eslintrc.js +0 -3
  113. package/src/bootstrap/hooks.ts +0 -19
  114. package/src/components/basic/AGMarkdown.vue +0 -20
  115. package/src/components/basic/index.ts +0 -3
  116. package/src/lang/helpers.ts +0 -5
  117. package/src/models/index.ts +0 -18
  118. package/src/routing/index.ts +0 -33
  119. package/src/testing/stubs/lang/en.yaml +0 -1
  120. package/src/testing/stubs/models/User.ts +0 -3
@@ -1,2 +1,5 @@
1
1
  /** @type {import('@noeldemartin/scripts').Config} */
2
- module.exports = { vue: true };
2
+ module.exports = {
3
+ vue: true,
4
+ icons: true,
5
+ };
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.7f6ed5a1f91688a86bf5ede2adc465e4fd6cfdea",
4
+ "version": "0.0.0-next.824cf5311c4335d119158f507dad094ed4f4f0b6",
5
5
  "main": "dist/aerogel-core.cjs.js",
6
6
  "module": "dist/aerogel-core.esm.js",
7
7
  "types": "dist/aerogel-core.d.ts",
@@ -10,9 +10,11 @@
10
10
  "build": "rm dist -rf && npm run build:js && npm run build:types",
11
11
  "build:js": "noeldemartin-build-javascript",
12
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,17 +35,22 @@
33
35
  },
34
36
  "dependencies": {
35
37
  "@headlessui/vue": "^1.7.14",
36
- "@noeldemartin/utils": "0.4.0-next.65c07a35cd02a0aa1ed9e742f72036354eba5fa8",
38
+ "@noeldemartin/utils": "0.5.1-next.49cc6c9b4a20930cbf922a949135981791acc5c3",
37
39
  "dompurify": "^3.0.3",
38
40
  "marked": "^5.0.4",
39
- "soukai": "^0.5.1",
40
- "vue": "^3.3.0",
41
- "vue-i18n": "9.3.0-beta.19",
42
- "vue-router": "^4.2.1"
41
+ "pinia": "^2.1.6",
42
+ "vue": "^3.3.0"
43
43
  },
44
44
  "devDependencies": {
45
+ "@aerogel/vite": "*",
46
+ "@histoire/plugin-vue": "^0.17.6",
45
47
  "@types/dompurify": "^3.0.2",
46
48
  "@types/marked": "^5.0.0",
47
- "@vitejs/plugin-vue": "^4.2.3"
49
+ "tailwindcss": "^3.3.5"
50
+ },
51
+ "eslintConfig": {
52
+ "extends": [
53
+ "@noeldemartin/eslint-config-vue"
54
+ ]
48
55
  }
49
56
  }
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ plugins: {
3
+ tailwindcss: {},
4
+ autoprefixer: {},
5
+ },
6
+ };
@@ -0,0 +1,3 @@
1
+ @tailwind base;
2
+ @tailwind components;
3
+ @tailwind utilities;
@@ -1,19 +1,17 @@
1
1
  import { beforeEach, describe, expect, it, vi } from 'vitest';
2
2
  import { createApp } from 'vue';
3
- import { createI18n } from 'vue-i18n';
4
- import { IndexedDBEngine, requireBootedModel, requireEngine } from 'soukai';
5
3
  import { mock } from '@noeldemartin/utils';
6
4
  import type { Component } from 'vue';
7
5
 
8
6
  import Events from '@/services/Events';
9
7
  import initialFocus from '@/directives/initial-focus';
10
- import User from '@/testing/stubs/models/User';
11
8
 
12
- import { bootstrapApplication } from './index';
9
+ import { bootstrap } from './index';
13
10
 
14
11
  describe('Aerogel', () => {
15
12
 
16
13
  beforeEach(() => {
14
+ vi.stubGlobal('document', { getElementById: () => null });
17
15
  vi.mock('vue', async () => {
18
16
  const vue = (await vi.importActual('vue')) as Object;
19
17
 
@@ -29,65 +27,12 @@ describe('Aerogel', () => {
29
27
  });
30
28
  });
31
29
 
32
- it('Initializes Soukai', async () => {
33
- // Arrange
34
- const rootComponent = mock<Component>();
35
-
36
- // Act
37
- await bootstrapApplication(rootComponent, {
38
- models: import.meta.glob('@/testing/stubs/models/*', { eager: true }),
39
- });
40
-
41
- // Assert
42
- expect(requireBootedModel('User')).toEqual(User);
43
- expect(requireEngine()).toBeInstanceOf(IndexedDBEngine);
44
- });
45
-
46
- it('Initializes routes', async () => {
47
- // Arrange
48
- vi.mock('vue-router', () => ({
49
- createRouter: vi.fn(() => ({ routerMock: true })),
50
- createWebHistory: vi.fn(),
51
- }));
52
-
53
- const rootComponent = mock<Component>();
54
-
55
- // Act
56
- await bootstrapApplication(rootComponent, {
57
- routes: [],
58
- });
59
-
60
- // Assert
61
- expect(vi.mocked(createApp).mock.results[0]?.value.use).toHaveBeenCalledWith({ routerMock: true });
62
- });
63
-
64
- it('Initializes lang', async () => {
65
- // Arrange
66
- vi.mock('vue-i18n', () => ({ createI18n: vi.fn(() => ({ i18nMock: true })) }));
67
-
68
- const rootComponent = mock<Component>();
69
-
70
- // Act
71
- await bootstrapApplication(rootComponent, {
72
- langMessages: import.meta.glob('@/testing/stubs/lang/*'),
73
- });
74
-
75
- // Assert
76
- const mockedCreateI18n = vi.mocked(createI18n);
77
- const mockedCreateApp = vi.mocked(createApp);
78
-
79
- expect(mockedCreateI18n).toHaveBeenCalled();
80
- expect(mockedCreateI18n.mock.calls[0]?.[0].messages).key('en').to.exist;
81
- expect(mockedCreateI18n.mock.calls[0]?.[0].messages?.['en']).key('foo').to.exist;
82
- expect(mockedCreateApp.mock.results[0]?.value.use).toHaveBeenCalledWith({ i18nMock: true });
83
- });
84
-
85
30
  it('Boots services', async () => {
86
31
  // Arrange
87
32
  const rootComponent = mock<Component>();
88
33
 
89
34
  // Act
90
- await bootstrapApplication(rootComponent);
35
+ await bootstrap(rootComponent);
91
36
 
92
37
  // Assert
93
38
  const globals = vi.mocked(createApp).mock.results[0]?.value.config.globalProperties;
@@ -101,7 +46,7 @@ describe('Aerogel', () => {
101
46
  const rootComponent = mock<Component>();
102
47
 
103
48
  // Act
104
- await bootstrapApplication(rootComponent);
49
+ await bootstrap(rootComponent);
105
50
 
106
51
  // Assert
107
52
  expect(vi.mocked(createApp).mock.results[0]?.value.directive).toHaveBeenCalledWith(
@@ -1,36 +1,39 @@
1
- import { createApp, h } from 'vue';
2
- import type { Component } from 'vue';
1
+ import { createApp } from 'vue';
2
+ import type { App, Component } from 'vue';
3
3
 
4
4
  import directives from '@/directives';
5
+ import errors from '@/errors';
6
+ import Events from '@/services/Events';
5
7
  import lang from '@/lang';
6
- import models from '@/models';
7
- import routing from '@/routing';
8
8
  import services from '@/services';
9
9
  import ui from '@/ui';
10
- import { runAppMountedHooks } from '@/bootstrap/hooks';
11
- import type { BootstrapOptions } from '@/bootstrap/options';
12
-
13
- export async function bootstrapApplication(rootComponent: Component, options: BootstrapOptions = {}): Promise<void> {
14
- const hooks = [directives, lang, models, routing, services, ui];
15
- const app = createApp({
16
- data: () => ({
17
- ready: false,
18
- }),
19
- mounted() {
20
- runAppMountedHooks();
21
-
22
- this.ready = true;
23
- },
24
- render() {
25
- if (!this.ready) {
26
- return null;
27
- }
28
-
29
- return h(rootComponent);
30
- },
31
- });
32
-
33
- await Promise.all(hooks.map((hook) => hook(app, options)));
10
+ import { installPlugins } from '@/plugins';
11
+ import type { AerogelOptions } from '@/bootstrap/options';
12
+
13
+ export { AerogelOptions };
14
+
15
+ export async function bootstrapApplication(app: App, options: AerogelOptions = {}): Promise<void> {
16
+ const plugins = [directives, errors, lang, services, ui, ...(options.plugins ?? [])];
17
+
18
+ await installPlugins(plugins, app, options);
19
+ await options.install?.(app);
20
+ await Events.emit('application-ready');
21
+ }
22
+
23
+ export async function bootstrap(rootComponent: Component, options: AerogelOptions = {}): Promise<void> {
24
+ const app = createApp(rootComponent);
25
+
26
+ await bootstrapApplication(app, options);
34
27
 
35
28
  app.mount('#app');
29
+ app._container?.classList.remove('loading');
30
+
31
+ await Events.emit('application-mounted');
32
+ }
33
+
34
+ declare module '@/services/Events' {
35
+ export interface EventsPayload {
36
+ 'application-ready': void;
37
+ 'application-mounted': void;
38
+ }
36
39
  }
@@ -1 +1,8 @@
1
- export interface BootstrapOptions {}
1
+ import type { App } from 'vue';
2
+
3
+ import type { Plugin } from '@/plugins';
4
+
5
+ export interface AerogelOptions {
6
+ plugins?: Plugin[];
7
+ install?(app: App): void | Promise<void>;
8
+ }
@@ -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>
@@ -0,0 +1,15 @@
1
+ <template>
2
+ <aside v-if="modal">
3
+ <AGModalContext :child-index="1" :modal="modal" />
4
+ </aside>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ import { computed } from 'vue';
9
+
10
+ import UI from '@/ui/UI';
11
+
12
+ import AGModalContext from './modals/AGModalContext.vue';
13
+
14
+ const modal = computed(() => UI.modals[0] ?? null);
15
+ </script>
@@ -1,21 +1,23 @@
1
1
  <template>
2
- <div ref="$backdrop" class="pointer-events-none fixed inset-0 z-50 bg-black/30 opacity-0" />
3
- <aside v-if="modal">
4
- <AGModalContext :child-index="1" :modal="modal" />
5
- </aside>
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
+ />
7
+ <AGAppModals />
8
+ <AGAppSnackbars />
6
9
  </template>
7
10
 
8
11
  <script setup lang="ts">
9
- import { computed, ref } from 'vue';
12
+ import { ref } from 'vue';
10
13
 
11
- import UI from '@/ui/UI';
12
14
  import { useEvent } from '@/utils/composition/events';
13
15
 
14
- import AGModalContext from './modals/AGModalContext.vue';
16
+ import AGAppModals from './AGAppModals.vue';
17
+ import AGAppSnackbars from './AGAppSnackbars.vue';
15
18
 
16
19
  const $backdrop = ref<HTMLElement | null>(null);
17
20
  const backdropHidden = ref(true);
18
- const modal = computed(() => UI.modals[0] ?? null);
19
21
 
20
22
  useEvent('show-overlays-backdrop', async () => {
21
23
  if (!$backdrop.value || !backdropHidden.value) {
@@ -0,0 +1,13 @@
1
+ <template>
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-end space-y-4">
4
+ <component
5
+ :is="snackbar.component"
6
+ v-for="snackbar of $ui.snackbars"
7
+ :id="snackbar.id"
8
+ :key="snackbar.id"
9
+ v-bind="snackbar.properties"
10
+ />
11
+ </div>
12
+ </div>
13
+ </template>
@@ -0,0 +1,8 @@
1
+ export const Colors = {
2
+ Primary: 'primary',
3
+ Secondary: 'secondary',
4
+ Danger: 'danger',
5
+ Clear: 'clear',
6
+ } as const;
7
+
8
+ export type Color = (typeof Colors)[keyof typeof Colors];
@@ -1,11 +1,44 @@
1
1
  <template>
2
- <AGHeadlessButton
3
- class="bg-indigo-600 px-2.5 py-1.5 text-white hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
4
- >
2
+ <AGHeadlessButton class="px-2.5 py-1.5 focus-visible:outline focus-visible:outline-2" :class="colorClasses">
5
3
  <slot />
6
4
  </AGHeadlessButton>
7
5
  </template>
8
6
 
9
7
  <script setup lang="ts">
8
+ import { computed } from 'vue';
9
+
10
+ import { enumProp } from '@/utils/vue';
11
+ import { Colors } from '@/components/constants';
12
+
10
13
  import AGHeadlessButton from '../headless/forms/AGHeadlessButton.vue';
14
+
15
+ const props = defineProps({
16
+ color: enumProp(Colors, Colors.Primary),
17
+ });
18
+
19
+ const colorClasses = computed(() => {
20
+ switch (props.color) {
21
+ case Colors.Secondary:
22
+ return [
23
+ 'text-white bg-gray-600',
24
+ 'hover:bg-gray-500',
25
+ 'focus-visible:outline-offset-2 focus-visible:outline-gray-600',
26
+ ].join(' ');
27
+ case Colors.Clear:
28
+ return 'hover:bg-gray-500/20 focus-visible:outline-gray-500/60';
29
+ case Colors.Danger:
30
+ return [
31
+ 'text-white bg-red-600',
32
+ 'hover:bg-red-500',
33
+ 'focus-visible:outline-offset-2 focus-visible:outline-red-600',
34
+ ].join(' ');
35
+ case Colors.Primary:
36
+ default:
37
+ return [
38
+ 'text-white bg-indigo-600',
39
+ 'hover:bg-indigo-500',
40
+ 'focus-visible:outline-offset-2 focus-visible:outline-indigo-600',
41
+ ].join(' ');
42
+ }
43
+ });
11
44
  </script>
@@ -0,0 +1,41 @@
1
+ <template>
2
+ <AGHeadlessInput
3
+ ref="$input"
4
+ :name="name"
5
+ class="flex"
6
+ @update:model-value="$emit('update:modelValue', $event)"
7
+ >
8
+ <AGHeadlessInputInput
9
+ v-bind="$attrs"
10
+ type="checkbox"
11
+ :class="{
12
+ 'text-indigo-600 focus:ring-indigo-600': !$input?.errors,
13
+ 'border-red-200 text-red-600 focus:ring-red-600': $input?.errors,
14
+ }"
15
+ />
16
+
17
+ <div class="ml-2">
18
+ <AGHeadlessInputLabel v-if="$slots.default">
19
+ <slot />
20
+ </AGHeadlessInputLabel>
21
+ <AGHeadlessInputError class="text-sm text-red-600" />
22
+ </div>
23
+ </AGHeadlessInput>
24
+ </template>
25
+
26
+ <script setup lang="ts">
27
+ import { componentRef, stringProp } from '@/utils/vue';
28
+
29
+ import type { IAGHeadlessInput } from '@/components/headless/forms/AGHeadlessInput';
30
+
31
+ import AGHeadlessInput from '../headless/forms/AGHeadlessInput.vue';
32
+ import AGHeadlessInputError from '../headless/forms/AGHeadlessInputError.vue';
33
+ import AGHeadlessInputInput from '../headless/forms/AGHeadlessInputInput.vue';
34
+ import AGHeadlessInputLabel from '../headless/forms/AGHeadlessInputLabel.vue';
35
+
36
+ defineProps({ name: stringProp() });
37
+ defineOptions({ inheritAttrs: false });
38
+ defineEmits(['update:modelValue']);
39
+
40
+ const $input = componentRef<IAGHeadlessInput>();
41
+ </script>
@@ -1,32 +1,38 @@
1
1
  <template>
2
2
  <AGHeadlessInput
3
3
  ref="$input"
4
- as="div"
5
- class="flex flex-col items-center"
6
- :name="name"
4
+ class="relative flex flex-col items-center"
5
+ :class="className"
6
+ v-bind="props"
7
7
  >
8
+ <AGHeadlessInputLabel class="sr-only" />
8
9
  <AGHeadlessInputInput
9
- v-bind="$attrs"
10
+ v-bind="attrs"
10
11
  class="block w-full border-0 py-1.5 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600"
11
12
  :class="{
12
13
  'ring-1 ring-red-500': $input?.errors,
13
14
  }"
14
15
  />
15
- <AGHeadlessInputError class="mt-1 text-sm text-red-500" />
16
+ <div class="absolute bottom-0 left-0 translate-y-full">
17
+ <AGHeadlessInputError class="mt-1 text-sm text-red-500" />
18
+ </div>
16
19
  </AGHeadlessInput>
17
20
  </template>
18
21
 
19
22
  <script setup lang="ts">
20
- import { componentRef, stringProp } from '@/utils/vue';
21
-
23
+ import { componentRef } from '@/utils/vue';
24
+ import { useInputAttrs } from '@/utils/composition/forms';
25
+ import { useInputProps } from '@/components/headless/forms/AGHeadlessInput';
22
26
  import type { IAGHeadlessInput } from '@/components/headless/forms/AGHeadlessInput';
23
27
 
24
28
  import AGHeadlessInput from '../headless/forms/AGHeadlessInput.vue';
25
- import AGHeadlessInputInput from '../headless/forms/AGHeadlessInputInput.vue';
26
29
  import AGHeadlessInputError from '../headless/forms/AGHeadlessInputError.vue';
30
+ import AGHeadlessInputInput from '../headless/forms/AGHeadlessInputInput.vue';
31
+ import AGHeadlessInputLabel from '../headless/forms/AGHeadlessInputLabel.vue';
27
32
 
28
- defineProps({ name: stringProp() });
29
33
  defineOptions({ inheritAttrs: false });
30
34
 
35
+ const props = defineProps(useInputProps());
31
36
  const $input = componentRef<IAGHeadlessInput>();
37
+ const [attrs, className] = useInputAttrs();
32
38
  </script>
@@ -0,0 +1,46 @@
1
+ <template>
2
+ <Story>
3
+ <div class="h-96">
4
+ <AGSelect v-model="bestMugiwara" :label="bestMugiwaraLabel" :options="bestMugiwaraOptions" />
5
+ <AGSelect
6
+ v-model="bestFood"
7
+ :label="bestFoodLabel"
8
+ :options="bestFoodOptions"
9
+ options-text="name"
10
+ />
11
+ </div>
12
+ </Story>
13
+ </template>
14
+
15
+ <script setup lang="ts">
16
+ import { ref } from 'vue';
17
+
18
+ import AGSelect from './AGSelect.vue';
19
+
20
+ const bestMugiwara = ref(null);
21
+ const bestFood = ref(null);
22
+ const bestMugiwaraLabel = 'Who\'s the best Mugiwara?';
23
+ const bestFoodLabel = 'What\'s the best food?';
24
+ const bestMugiwaraOptions = [
25
+ 'Monkey D. Luffy',
26
+ 'Roronoa Zoro',
27
+ 'Nami',
28
+ 'Usopp',
29
+ 'Sanji',
30
+ 'Tony Tony Chopper',
31
+ 'Nico Robin',
32
+ 'Franky',
33
+ 'Brook',
34
+ 'Jinbe',
35
+ ];
36
+ const bestFoodOptions = [
37
+ {
38
+ id: 'ramen',
39
+ name: 'Ramen',
40
+ },
41
+ {
42
+ id: 'pizza',
43
+ name: 'Pizza',
44
+ },
45
+ ];
46
+ </script>
@@ -0,0 +1,60 @@
1
+ <template>
2
+ <AGHeadlessSelect
3
+ v-bind="props"
4
+ ref="$select"
5
+ as="div"
6
+ @update:model-value="$emit('update:modelValue', $event)"
7
+ >
8
+ <AGHeadlessSelectLabel class="block text-sm font-medium leading-6 text-gray-900" />
9
+ <div class="relative" :class="{ 'mt-2': $select?.label }">
10
+ <AGHeadlessSelectButton
11
+ 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"
12
+ text-class="block truncate"
13
+ :class="{
14
+ 'ring-1 ring-red-500': $select?.errors,
15
+ }"
16
+ >
17
+ <template #icon>
18
+ <span class="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2">
19
+ <IconCheveronDown class="h-5 w-5 text-gray-400" />
20
+ </span>
21
+ </template>
22
+ </AGHeadlessSelectButton>
23
+ <AGHeadlessSelectOptions
24
+ 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"
25
+ >
26
+ <AGHeadlessSelectOption
27
+ v-for="(option, index) in $select?.options ?? []"
28
+ :key="index"
29
+ :value="option"
30
+ class="relative block cursor-default select-none truncate py-2 pl-3 pr-9"
31
+ selected-class="font-semibold"
32
+ unselected-class="font-normal"
33
+ active-class="bg-indigo-600 text-white"
34
+ inactive-class="text-gray-900"
35
+ />
36
+ </AGHeadlessSelectOptions>
37
+ </div>
38
+ <AGHeadlessSelectError class="mt-2 text-sm text-red-600" />
39
+ </AGHeadlessSelect>
40
+ </template>
41
+
42
+ <script setup lang="ts">
43
+ import IconCheveronDown from '~icons/zondicons/cheveron-down';
44
+
45
+ import { componentRef } from '@/utils/vue';
46
+ import { useSelectEmits, useSelectProps } from '@/components/headless/forms/AGHeadlessSelect';
47
+ import type { IAGHeadlessSelect } from '@/components/headless/forms/AGHeadlessSelect';
48
+
49
+ import AGHeadlessSelect from '../headless/forms/AGHeadlessSelect.vue';
50
+ import AGHeadlessSelectButton from '../headless/forms/AGHeadlessSelectButton.vue';
51
+ import AGHeadlessSelectError from '../headless/forms/AGHeadlessSelectError.vue';
52
+ import AGHeadlessSelectLabel from '../headless/forms/AGHeadlessSelectLabel.vue';
53
+ import AGHeadlessSelectOption from '../headless/forms/AGHeadlessSelectOption.vue';
54
+ import AGHeadlessSelectOptions from '../headless/forms/AGHeadlessSelectOptions';
55
+
56
+ defineEmits(useSelectEmits());
57
+
58
+ const props = defineProps(useSelectProps());
59
+ const $select = componentRef<IAGHeadlessSelect>();
60
+ </script>
@@ -1,5 +1,5 @@
1
- import AGButton from './AGButton.vue';
2
- import AGForm from './AGForm.vue';
3
- import AGInput from './AGInput.vue';
4
-
5
- export { AGButton, 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';
@@ -7,15 +7,15 @@
7
7
  <script setup lang="ts">
8
8
  import { computed } from 'vue';
9
9
  import { objectWithoutEmpty } from '@noeldemartin/utils';
10
- import type { LocationQuery, RouteLocation, RouteParams } from 'vue-router';
11
10
 
12
11
  import { booleanProp, objectProp, stringProp } from '@/utils/vue';
13
12
 
14
- const { url, route, routeParams, routeQuery, submit } = defineProps({
13
+ const { href, url, route, routeParams, routeQuery, submit } = defineProps({
14
+ href: stringProp(),
15
15
  url: stringProp(),
16
16
  route: stringProp(),
17
- routeParams: objectProp<RouteParams>(() => ({})),
18
- routeQuery: objectProp<LocationQuery>(() => ({})),
17
+ routeParams: objectProp(() => ({})),
18
+ routeQuery: objectProp(() => ({})),
19
19
  submit: booleanProp(),
20
20
  });
21
21
 
@@ -24,7 +24,7 @@ const component = computed(() => {
24
24
  return {
25
25
  tag: 'router-link',
26
26
  props: {
27
- to: objectWithoutEmpty<Partial<RouteLocation>>({
27
+ to: objectWithoutEmpty({
28
28
  name: route,
29
29
  params: routeParams,
30
30
  query: routeQuery,
@@ -33,12 +33,12 @@ const component = computed(() => {
33
33
  };
34
34
  }
35
35
 
36
- if (url) {
36
+ if (href || url) {
37
37
  return {
38
38
  tag: 'a',
39
39
  props: {
40
40
  target: '_blank',
41
- href: url,
41
+ href: href || url,
42
42
  },
43
43
  };
44
44
  }