runeforge 0.0.30 → 0.0.31
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,7 @@
|
|
|
207
207
|
...actions.map((action) => ({
|
|
208
208
|
label: action.label,
|
|
209
209
|
icon: action.icon,
|
|
210
|
+
toggle: action.toggle,
|
|
210
211
|
condition: action.condition,
|
|
211
212
|
run: (item: T) => onAction?.(action, item)
|
|
212
213
|
})),
|
|
@@ -230,22 +231,37 @@
|
|
|
230
231
|
</script>
|
|
231
232
|
|
|
232
233
|
{#snippet actionsCell(item: T)}
|
|
233
|
-
<div class="flex justify-end gap-1">
|
|
234
|
+
<div class="flex justify-end items-center gap-1">
|
|
234
235
|
{#each rowActions as action (action.label)}
|
|
235
236
|
{#if action.condition?.(item) ?? true}
|
|
236
|
-
{
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
e
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
237
|
+
{#if action.toggle}
|
|
238
|
+
<input
|
|
239
|
+
type="checkbox"
|
|
240
|
+
class={['toggle toggle-sm', action.class]}
|
|
241
|
+
title={action.label}
|
|
242
|
+
aria-label={action.label}
|
|
243
|
+
checked={action.toggle(item)}
|
|
244
|
+
onclick={(e) => {
|
|
245
|
+
e.preventDefault();
|
|
246
|
+
e.stopPropagation();
|
|
247
|
+
action.run(item);
|
|
248
|
+
}}
|
|
249
|
+
/>
|
|
250
|
+
{:else}
|
|
251
|
+
{@const Icon = action.icon}
|
|
252
|
+
<Button
|
|
253
|
+
variant="ghost"
|
|
254
|
+
class={['btn-xs', action.class]}
|
|
255
|
+
title={action.label}
|
|
256
|
+
aria-label={action.label}
|
|
257
|
+
onclick={(e) => {
|
|
258
|
+
e.stopPropagation();
|
|
259
|
+
action.run(item);
|
|
260
|
+
}}
|
|
261
|
+
>
|
|
262
|
+
<Icon class="size-4" />
|
|
263
|
+
</Button>
|
|
264
|
+
{/if}
|
|
249
265
|
{/if}
|
|
250
266
|
{/each}
|
|
251
267
|
</div>
|
package/dist/types/crud.d.ts
CHANGED
|
@@ -62,7 +62,19 @@ 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;
|
|
66
78
|
endpoint?: string;
|
|
67
79
|
condition?: (item: T) => boolean;
|
|
68
80
|
/** Renders as a modal-like panel when the action runs. Mutually exclusive
|
|
@@ -74,7 +86,9 @@ export interface CustomAction<T extends object = Record<string, unknown>> {
|
|
|
74
86
|
}
|
|
75
87
|
export interface RowAction<T extends object = Record<string, unknown>> {
|
|
76
88
|
label: string;
|
|
77
|
-
icon
|
|
89
|
+
icon?: any;
|
|
90
|
+
/** See `CustomAction.toggle` — same controlled-switch rendering. */
|
|
91
|
+
toggle?: (item: T) => boolean;
|
|
78
92
|
class?: string;
|
|
79
93
|
condition?: (item: T) => boolean;
|
|
80
94
|
run: (item: T) => void;
|