runeforge 0.0.30 → 0.0.32
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.
|
@@ -207,6 +207,8 @@
|
|
|
207
207
|
...actions.map((action) => ({
|
|
208
208
|
label: action.label,
|
|
209
209
|
icon: action.icon,
|
|
210
|
+
toggle: action.toggle,
|
|
211
|
+
class: action.class,
|
|
210
212
|
condition: action.condition,
|
|
211
213
|
run: (item: T) => onAction?.(action, item)
|
|
212
214
|
})),
|
|
@@ -230,22 +232,39 @@
|
|
|
230
232
|
</script>
|
|
231
233
|
|
|
232
234
|
{#snippet actionsCell(item: T)}
|
|
233
|
-
<div class="flex justify-end gap-1">
|
|
235
|
+
<div class="flex justify-end items-center gap-1">
|
|
234
236
|
{#each rowActions as action (action.label)}
|
|
235
237
|
{#if action.condition?.(item) ?? true}
|
|
236
|
-
{@const
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
action.
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
238
|
+
{@const resolvedClass =
|
|
239
|
+
typeof action.class === 'function' ? action.class(item) : action.class}
|
|
240
|
+
{#if action.toggle}
|
|
241
|
+
<input
|
|
242
|
+
type="checkbox"
|
|
243
|
+
class={['toggle toggle-sm', resolvedClass]}
|
|
244
|
+
title={action.label}
|
|
245
|
+
aria-label={action.label}
|
|
246
|
+
checked={action.toggle(item)}
|
|
247
|
+
onclick={(e) => {
|
|
248
|
+
e.preventDefault();
|
|
249
|
+
e.stopPropagation();
|
|
250
|
+
action.run(item);
|
|
251
|
+
}}
|
|
252
|
+
/>
|
|
253
|
+
{:else}
|
|
254
|
+
{@const Icon = action.icon}
|
|
255
|
+
<Button
|
|
256
|
+
variant="ghost"
|
|
257
|
+
class={['btn-xs', resolvedClass]}
|
|
258
|
+
title={action.label}
|
|
259
|
+
aria-label={action.label}
|
|
260
|
+
onclick={(e) => {
|
|
261
|
+
e.stopPropagation();
|
|
262
|
+
action.run(item);
|
|
263
|
+
}}
|
|
264
|
+
>
|
|
265
|
+
<Icon class="size-4" />
|
|
266
|
+
</Button>
|
|
267
|
+
{/if}
|
|
249
268
|
{/if}
|
|
250
269
|
{/each}
|
|
251
270
|
</div>
|
package/dist/types/crud.d.ts
CHANGED
|
@@ -62,7 +62,24 @@ export interface ActionConfiguration<T extends object = Record<string, unknown>>
|
|
|
62
62
|
}
|
|
63
63
|
export interface CustomAction<T extends object = Record<string, unknown>> {
|
|
64
64
|
label: string;
|
|
65
|
-
|
|
65
|
+
/** Required unless `toggle` is set, which renders the action as a switch
|
|
66
|
+
* instead of an icon button. */
|
|
67
|
+
icon?: any;
|
|
68
|
+
/** Renders the row action as a real daisyUI toggle switch reflecting the
|
|
69
|
+
* item's current on/off state, instead of an icon button. Takes
|
|
70
|
+
* precedence over `icon` when both are set.
|
|
71
|
+
*
|
|
72
|
+
* The switch is controlled, not editable directly: clicking it never
|
|
73
|
+
* flips its own checked state, it still just calls `run` (opening `view`
|
|
74
|
+
* or navigating via `href`) like any other action. It only visually
|
|
75
|
+
* flips once the underlying item's data actually changes — e.g. after
|
|
76
|
+
* the action's modal confirms and the list reloads. */
|
|
77
|
+
toggle?: (item: T) => boolean;
|
|
78
|
+
/** Extra class(es) on the row action's button/switch — e.g. to color a
|
|
79
|
+
* `toggle` by the item's own state (`toggle-success`/`toggle-error`).
|
|
80
|
+
* Pass a function to resolve it per item; a plain string applies to
|
|
81
|
+
* every row alike. */
|
|
82
|
+
class?: string | ((item: T) => string);
|
|
66
83
|
endpoint?: string;
|
|
67
84
|
condition?: (item: T) => boolean;
|
|
68
85
|
/** Renders as a modal-like panel when the action runs. Mutually exclusive
|
|
@@ -74,8 +91,11 @@ export interface CustomAction<T extends object = Record<string, unknown>> {
|
|
|
74
91
|
}
|
|
75
92
|
export interface RowAction<T extends object = Record<string, unknown>> {
|
|
76
93
|
label: string;
|
|
77
|
-
icon
|
|
78
|
-
|
|
94
|
+
icon?: any;
|
|
95
|
+
/** See `CustomAction.toggle` — same controlled-switch rendering. */
|
|
96
|
+
toggle?: (item: T) => boolean;
|
|
97
|
+
/** See `CustomAction.class`. */
|
|
98
|
+
class?: string | ((item: T) => string);
|
|
79
99
|
condition?: (item: T) => boolean;
|
|
80
100
|
run: (item: T) => void;
|
|
81
101
|
}
|