@autoafleveren/ui 1.6.4 → 1.8.0

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": "@autoafleveren/ui",
3
- "version": "1.6.4",
3
+ "version": "1.8.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist/*",
@@ -97,10 +97,11 @@
97
97
  class="app-context-menu fixed z-100 flex w-64 flex-col rounded-lg bg-secondary p-2 drop-shadow-card empty:hidden"
98
98
  data-test-context-menu
99
99
  >
100
- <div v-if="enableSearch && actionsWithFallback.length > 0">
100
+ <div v-if="search?.enabled && actionsWithFallback.length > 0">
101
101
  <AppInput
102
+ v-bind="search"
102
103
  :model-value="searchActionsQuery"
103
- :placeholder="searchPlaceholder ?? ''"
104
+ :placeholder="search?.placeholder ?? ''"
104
105
  class="mb-2 text-zinc-700"
105
106
  type="text"
106
107
  data-test-driver-search
@@ -93,7 +93,7 @@ describe('the AppContextMenu ShortcutItem component', () => {
93
93
  });
94
94
 
95
95
  it('should render the search input when enableSearch is true', () => {
96
- const wrapper = createWrapper(actionsMock, { enableSearch: true });
96
+ const wrapper = createWrapper(actionsMock, { search: { enabled: true } });
97
97
  const searchInput = wrapper.findComponent({ name: 'AppInput' });
98
98
 
99
99
  expect(searchInput.exists()).toBe(true);
@@ -101,8 +101,7 @@ describe('the AppContextMenu ShortcutItem component', () => {
101
101
 
102
102
  it('should use the searchPlaceholder prop as the input placeholder', () => {
103
103
  const wrapper = createWrapper(actionsMock, {
104
- enableSearch: true,
105
- searchPlaceholder: 'Search actions...',
104
+ search: { enabled: true, placeholder: 'Search actions...' },
106
105
  });
107
106
 
108
107
  const searchInput = wrapper.findComponent({ name: 'AppInput' });
@@ -111,7 +110,7 @@ describe('the AppContextMenu ShortcutItem component', () => {
111
110
  });
112
111
 
113
112
  it('should default the placeholder to an empty string when searchPlaceholder is not provided', () => {
114
- const wrapper = createWrapper(actionsMock, { enableSearch: true });
113
+ const wrapper = createWrapper(actionsMock, { search: { enabled: true } });
115
114
  const searchInput = wrapper.findComponent({ name: 'AppInput' });
116
115
 
117
116
  expect(searchInput.attributes('placeholder')).toBe('');
@@ -119,7 +118,7 @@ describe('the AppContextMenu ShortcutItem component', () => {
119
118
 
120
119
  it('should display noResultsText when searching yields no results', async () => {
121
120
  const wrapper = createWrapper(actionsMock, {
122
- enableSearch: true,
121
+ search: { enabled: true },
123
122
  noResultsText: 'No results found',
124
123
  });
125
124
 
@@ -138,7 +137,7 @@ describe('the AppContextMenu ShortcutItem component', () => {
138
137
  });
139
138
 
140
139
  it('should default noResultsText to an empty string when not provided', async () => {
141
- const wrapper = createWrapper(actionsMock, { enableSearch: true });
140
+ const wrapper = createWrapper(actionsMock, { search: { enabled: true } });
142
141
  const searchInput = wrapper.findComponent({ name: 'AppInput' });
143
142
 
144
143
  await searchInput.vm.$emit('update:modelValue', 'test_action_non_existant');
@@ -154,7 +153,7 @@ describe('the AppContextMenu ShortcutItem component', () => {
154
153
  });
155
154
 
156
155
  it('should filter actions based on search query', async () => {
157
- const wrapper = createWrapper(actionsMock, { enableSearch: true });
156
+ const wrapper = createWrapper(actionsMock, { search: { enabled: true } });
158
157
  const searchInput = wrapper.findComponent({ name: 'AppInput' });
159
158
 
160
159
  await searchInput.vm.$emit('update:modelValue', 'Action #1');
@@ -198,7 +197,7 @@ describe('the AppContextMenu ShortcutItem component', () => {
198
197
  { ...actionsMock[0], name: 'Action 5' },
199
198
  ];
200
199
 
201
- const wrapper = createWrapper(manyActions, { enableSearch: true, maxList: 2 });
200
+ const wrapper = createWrapper(manyActions, { search: { enabled: true }, maxList: 2 });
202
201
  const searchInput = wrapper.findComponent({ name: 'AppInput' });
203
202
 
204
203
  await searchInput.vm.$emit('update:modelValue', 'Action');
@@ -1,5 +1,6 @@
1
1
  import type { App } from 'vue';
2
2
  import type AppContextMenu from './AppContextMenu.vue';
3
+ import type { AppInputProps } from '~components/AppInput/index.d';
3
4
 
4
5
  export type { Action } from '~components/AppActionBar/index.d';
5
6
 
@@ -8,8 +9,10 @@ export interface Props {
8
9
  event: PointerEvent | MouseEvent;
9
10
  actions?: Action[];
10
11
  confirmed?: Action['key'];
11
- enableSearch?: boolean;
12
- searchPlaceholder?: string;
12
+ search?: Omit<AppInputProps<string>, 'modelValue'> & {
13
+ enabled?: boolean;
14
+ placeholder?: string;
15
+ };
13
16
  noResultsText?: string;
14
17
  maxList?: number;
15
18
  }
@@ -1,11 +1,12 @@
1
1
  <script lang="ts" setup>
2
- import { ref, provide } from 'vue';
2
+ /* eslint-disable vue/no-unused-properties */
3
+ import { ref, provide, computed } from 'vue';
3
4
  import { Dialog, DialogPanel, TransitionChild, TransitionRoot } from '@headlessui/vue';
4
5
  import { FontAwesomeIcon, byPrefixAndName } from '~icons';
5
6
 
6
7
  import type { DrawerProps } from './index.d';
7
8
 
8
- withDefaults(defineProps<Omit<DrawerProps, 'router' | 'unique' | 'onOpen' | 'onClose' | 'plugins' | 'forceCreate'>>(), {
9
+ const props = withDefaults(defineProps<Omit<DrawerProps, 'router' | 'unique' | 'onOpen' | 'onClose' | 'plugins' | 'forceCreate'>>(), {
9
10
  withBackdrop: true,
10
11
  withFooter: true,
11
12
  preventBackdropClose: false,
@@ -21,6 +22,13 @@
21
22
  }>();
22
23
 
23
24
  const isOpen = ref(false);
25
+ const localOptions = ref<Partial<DrawerProps>>({});
26
+
27
+ const mergedProps = computed(() => ({ ...props, ...localOptions.value }));
28
+
29
+ function setOptions(options: DrawerProps): void {
30
+ localOptions.value = { ...localOptions.value, ...options };
31
+ }
24
32
 
25
33
  async function open(): Promise<void> {
26
34
  isOpen.value = true;
@@ -35,7 +43,7 @@
35
43
  emit('close', { animation: async () => new Promise(resolve => setTimeout(resolve, 350)) });
36
44
  }
37
45
 
38
- defineExpose({ isOpen, open, close });
46
+ defineExpose({ isOpen, open, close, setOptions });
39
47
 
40
48
  provide('isDrawer', true);
41
49
  </script>
@@ -49,10 +57,10 @@
49
57
  :static="true"
50
58
  class="relative z-10 group/drawer is-drawer"
51
59
  data-test-drawer-dialog
52
- @close="() => (preventBackdropClose || !withBackdrop) ? undefined : close()"
60
+ @close="() => (mergedProps.preventBackdropClose || !mergedProps.withBackdrop) ? undefined : close()"
53
61
  >
54
62
  <TransitionChild
55
- v-if="withBackdrop"
63
+ v-if="mergedProps.withBackdrop"
56
64
  as="template"
57
65
  enter="ease-in-out duration-300"
58
66
  enter-from="opacity-0"
@@ -68,11 +76,11 @@
68
76
  </TransitionChild>
69
77
 
70
78
  <div
71
- :class="{ 'pointer-events-none': !withBackdrop }"
79
+ :class="{ 'pointer-events-none': !mergedProps.withBackdrop }"
72
80
  class="fixed inset-0 overflow-hidden"
73
81
  >
74
82
  <div
75
- :class="{ 'pointer-events-none': !withBackdrop }"
83
+ :class="{ 'pointer-events-none': !mergedProps.withBackdrop }"
76
84
  class="absolute inset-0 overflow-hidden"
77
85
  >
78
86
  <div class="pointer-events-none fixed inset-y-0 right-0 flex max-w-full pl-10">
@@ -86,7 +94,7 @@
86
94
  leave-to="translate-x-full"
87
95
  >
88
96
  <DialogPanel
89
- :class="panelClasses"
97
+ :class="mergedProps.panelClasses"
90
98
  class="@container pointer-events-auto relative w-screen max-w-xl 2xl:max-w-4xl"
91
99
  >
92
100
  <TransitionChild
@@ -110,7 +118,7 @@
110
118
  <span class="sr-only">Close panel</span>
111
119
 
112
120
  <FontAwesomeIcon
113
- :icon="closeIcon ?? byPrefixAndName.far?.['chevron-right']"
121
+ :icon="mergedProps.closeIcon ?? byPrefixAndName.far?.['chevron-right']"
114
122
  class="size-6"
115
123
  aria-hidden="true"
116
124
  />
@@ -119,22 +127,22 @@
119
127
  </TransitionChild>
120
128
 
121
129
  <div
122
- :class="modalClasses"
130
+ :class="mergedProps.modalClasses"
123
131
  class="flex h-full flex-col overflow-y-scroll rounded-l-[40px] bg-white pt-8 mb-8 shadow-[-6px_0px_6px_#20202010]"
124
132
  >
125
133
  <div
126
- :class="`relative mt-6 flex-1 px-2 sm:px-6 ${contentClasses}`"
134
+ :class="`relative mt-6 flex-1 px-2 sm:px-6 ${mergedProps.contentClasses}`"
127
135
  data-test-modal-content
128
136
  >
129
137
  <slot>
130
- <template v-if="typeof content === 'string'">
131
- {{ content }}
138
+ <template v-if="typeof mergedProps.content === 'string'">
139
+ {{ mergedProps.content }}
132
140
  </template>
133
141
 
134
142
  <Component
135
- :is="content"
143
+ :is="mergedProps.content"
136
144
  v-else
137
- v-bind="properties"
145
+ v-bind="mergedProps.properties"
138
146
  />
139
147
  </slot>
140
148
  </div>
@@ -1,4 +1,5 @@
1
1
  import { shallowRef } from 'vue';
2
+ import { useContextMenu } from '~composables';
2
3
 
3
4
  import type { Action } from '~components/AppActionBar/index.d';
4
5
  import type { OnResetSelection } from './index.d';
@@ -13,6 +14,8 @@ const state = {
13
14
  };
14
15
 
15
16
  export function useActionBar<T = number>() {
17
+ const contextMenu = useContextMenu();
18
+
16
19
  function setSelection(selection: T[]): void {
17
20
  // @ts-expect-error type mismatch, but we want to allow any type of selection
18
21
  state.selection.value = selection;
@@ -25,6 +28,8 @@ export function useActionBar<T = number>() {
25
28
  }
26
29
 
27
30
  function setActions(actions: Action[]): void {
31
+ contextMenu.setActions(undefined);
32
+
28
33
  state.actions.value = actions;
29
34
 
30
35
  open();
@@ -9,7 +9,7 @@ const state = {
9
9
  instances: ref<ModalInstance[]>([]),
10
10
  };
11
11
 
12
- function closeDrawer(modalInstance: Omit<ModalInstance, 'withRouter'>): void {
12
+ function closeDrawer(modalInstance: Omit<ModalInstance, 'withRouter' | 'unique'>): void {
13
13
  modalInstance?.instance?.unmount();
14
14
  modalInstance?.element?.remove();
15
15
 
@@ -60,6 +60,7 @@ export function useDrawer(component?: MaybeRef<Component | string>, options?: Dr
60
60
 
61
61
  if (openOptions.forceCreate !== true && instancesWithRouter.length > 0 && openOptions.router) {
62
62
  instancesWithRouter[instancesWithRouter.length - 1]?.instance?.config?.globalProperties?.$router?.push?.(openOptions.router);
63
+ instancesWithRouter[instancesWithRouter.length - 1]?.ref?.setOptions(openOptions);
63
64
 
64
65
  return;
65
66
  }
@@ -90,7 +91,7 @@ export function useDrawer(component?: MaybeRef<Component | string>, options?: Dr
90
91
  if (!hasReadyListener) {
91
92
  mountDrawer(modalInstance, modalRootElement, !!openOptions.router);
92
93
 
93
- if (openOptions.router) {
94
+ if (openOptions.router && !openOptions.unique) {
94
95
  modalInstance?.config?.globalProperties?.$router?.push?.(openOptions.router);
95
96
  }
96
97
 
@@ -130,10 +131,25 @@ export function useDrawer(component?: MaybeRef<Component | string>, options?: Dr
130
131
  return Promise.resolve();
131
132
  }
132
133
 
134
+ async function closeAll(): Promise<void> {
135
+ state.instances.value.forEach(stateInstance => {
136
+ stateInstance.ref.close();
137
+
138
+ setTimeout(() => {
139
+ if (instance.value) {
140
+ closeDrawer(stateInstance);
141
+ }
142
+ }, 300);
143
+ });
144
+
145
+ return Promise.resolve();
146
+ }
147
+
133
148
  return {
134
149
  ...state,
135
150
  instance,
136
151
  open,
137
152
  close,
153
+ closeAll,
138
154
  };
139
155
  }