-
Notifications
You must be signed in to change notification settings - Fork 21
Feat/bulk action component #323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Changes from all commits
e850dee
c83ee3b
e65f705
a5defaf
c95b1b6
b9a4d32
41eea76
28d3d04
afe97c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -263,4 +263,63 @@ bulkActions: [ | |
| }, | ||
| } | ||
| ], | ||
| ``` | ||
|
|
||
| ## Custom Component | ||
|
|
||
| If you want to style an action's button/icon without changing its behavior, attach a custom UI wrapper via `customComponent`. | ||
| The file points to your SFC in the custom folder (alias `@@/`), and `meta` lets you pass lightweight styling options (e.g., border color, radius). | ||
|
|
||
| ```ts title="./resources/apartments.ts" | ||
| { | ||
| resourceId: 'aparts', | ||
| options: { | ||
| actions: [ | ||
| { | ||
| name: 'Auto submit', | ||
| icon: 'flowbite:play-solid', | ||
| // UI wrapper for the built-in action button | ||
| //diff-add | ||
| customComponent: { | ||
| //diff-add | ||
| file: '@@/ActionBorder.vue', // SFC path in your custom folder | ||
| //diff-add | ||
| meta: { color: '#94a3b8', radius: 10 } // free-form styling params | ||
| //diff-add | ||
| }, | ||
| showIn: { list: true, showButton: true, showThreeDotsMenu: true }, | ||
| action: async ({ recordId, adminUser }) => { | ||
| return { ok: true, successMessage: 'Auto submitted' }; | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Use this minimal wrapper component to add a border/rounding around the default action UI while keeping the action logic intact. | ||
| Keep the `<slot />` (that's where AdminForth renders the default button) and emit `callAction` to trigger the handler when the wrapper is clicked. | ||
|
|
||
| ```ts title="./custom/ActionBorder.vue" | ||
| <template> | ||
| <!-- Keep the slot: AdminForth renders the default action button/icon here --> | ||
| <!-- Emit `callAction` to trigger the action when the wrapper is clicked --> | ||
| <div :style="styleObj" @click="emit('callAction')"> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @NoOne7135 for verbosity can we use |
||
| <slot /> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import { computed } from 'vue'; | ||
|
|
||
| const props = defineProps<{ meta?: { color?: string; radius?: number; padding?: number } }>(); | ||
| const emit = defineEmits<{ (e: 'callAction', payload?: unknown): void }>(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @NoOne7135 payload any here? |
||
|
|
||
| const styleObj = computed(() => ({ | ||
| display: 'inline-block', | ||
| border: `1px solid ${props.meta?.color ?? '#e5e7eb'}`, | ||
| borderRadius: (props.meta?.radius ?? 8) + 'px', | ||
| padding: (props.meta?.padding ?? 2) + 'px', | ||
| })); | ||
| </script> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @NoOne7135 lets add one more example which demonstrates how to pass dynamic value from frontend to backend. @click="emit('callAction', {asListed: true})" @click="emit('callAction', {asListed: false})" and how to access it on backend in handler - using extra |
||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <template> | ||
| <div @click="onClick"> | ||
| <slot /> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| const props = defineProps<{ disabled?: boolean, extra?: any }>(); | ||
| const emit = defineEmits<{ (e: 'callAction', extra?: any ): void }>(); | ||
|
|
||
| function onClick() { | ||
| if (props.disabled) return; | ||
| emit('callAction', props.extra); | ||
| } | ||
| </script> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <span> TEST CUSTOM COMPONENT </span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NoOne7135 lets use mark as listed example as base (with link to original mark as listed action)