-
-
Notifications
You must be signed in to change notification settings - Fork 622
Expand file tree
/
Copy pathFieldActions.vue
More file actions
81 lines (73 loc) · 2.54 KB
/
FieldActions.vue
File metadata and controls
81 lines (73 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<template>
<div class="flex relative items-center gap-1 -top-1">
<Dropdown v-if="hasNonQuickActions">
<template #trigger>
<Button icon="dots" variant="ghost" size="xs" :aria-label="__('Open dropdown menu')" />
</template>
<DropdownMenu>
<DropdownItem
v-for="action in actions.filter((a) => !a.quick)"
:key="action.handle || action.title"
:text="action.title"
:variant="action.dangerous ? 'destructive' : 'default'"
:aria-label="action.title"
@click="action.run(action)"
/>
</DropdownMenu>
</Dropdown>
<ButtonGroup class="mr-0.75 -mt-0.5">
<!-- Keep quick actions focusable for :focus-within styles, even when disabled. -->
<Button
v-for="(action, index) in actions.filter((a) => a.quick)"
:key="index"
@click="runQuickAction(action, $event)"
v-tooltip="action.title"
size="2xs"
:aria-disabled="action.disabled ? 'true' : null"
:class="{ '!cursor-not-allowed': action.disabled }"
:icon-only="true"
:aria-label="action.title"
>
<ui-icon :name="action.icon" class="size-3.5" :class="{ '!opacity-30': action.disabled }" />
</Button>
</ButtonGroup>
</div>
</template>
<script>
import { Button, ButtonGroup, Dropdown, DropdownMenu, DropdownItem } from '@/components/ui';
export default {
components: {
Button,
ButtonGroup,
Dropdown,
DropdownMenu,
DropdownItem,
},
props: {
actions: {
type: Array,
},
},
computed: {
hasQuickActions() {
return this.actions.filter((a) => a.quick).length > 0;
},
hasNonQuickActions() {
return this.actions.filter((a) => !a.quick).length > 0;
},
},
methods: {
runQuickAction(action, event) {
const target = event?.currentTarget;
if (action.disabled) {
if (target instanceof HTMLButtonElement) {
// Re-focus after click so selection/focus styling doesn't jump to parent containers.
requestAnimationFrame(() => target.focus({ preventScroll: true }));
}
return;
}
action.run();
},
},
};
</script>