init
This commit is contained in:
21 files changed
+12224
No files matched your search
@@ -0,0 +1,154 @@
|
||||
.nova-row-actions {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.4rem;
|
||||
direction: inherit;
|
||||
}
|
||||
|
||||
.nova-row-actions__button {
|
||||
--row-action-color: rgb(107 114 128);
|
||||
--row-action-soft: rgb(243 244 246);
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
min-width: 2.25rem;
|
||||
height: 2.25rem;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.35rem;
|
||||
padding-inline: 0.5rem;
|
||||
border: 1px solid rgb(209 213 219);
|
||||
border-radius: 0.5rem;
|
||||
background: transparent;
|
||||
color: var(--row-action-color);
|
||||
line-height: 1;
|
||||
transition: background-color 150ms, border-color 150ms, color 150ms,
|
||||
transform 150ms;
|
||||
}
|
||||
|
||||
.nova-row-actions__button--primary {
|
||||
--row-action-color: rgb(14 165 233);
|
||||
--row-action-soft: rgb(240 249 255);
|
||||
}
|
||||
|
||||
.nova-row-actions__button--success {
|
||||
--row-action-color: rgb(22 163 74);
|
||||
--row-action-soft: rgb(240 253 244);
|
||||
}
|
||||
|
||||
.nova-row-actions__button--danger {
|
||||
--row-action-color: rgb(220 38 38);
|
||||
--row-action-soft: rgb(254 242 242);
|
||||
}
|
||||
|
||||
.nova-row-actions__button--warning {
|
||||
--row-action-color: rgb(217 119 6);
|
||||
--row-action-soft: rgb(255 251 235);
|
||||
}
|
||||
|
||||
.nova-row-actions__button--info {
|
||||
--row-action-color: rgb(8 145 178);
|
||||
--row-action-soft: rgb(236 254 255);
|
||||
}
|
||||
|
||||
.nova-row-actions__button--outline:not(:disabled):hover,
|
||||
.nova-row-actions__button--outline.nova-row-actions__button--active {
|
||||
border-color: var(--row-action-color);
|
||||
background: var(--row-action-soft);
|
||||
}
|
||||
|
||||
.nova-row-actions__button--solid {
|
||||
border-color: var(--row-action-color);
|
||||
background: var(--row-action-color);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.nova-row-actions__button--ghost {
|
||||
border-color: transparent;
|
||||
}
|
||||
|
||||
.nova-row-actions__button--ghost:not(:disabled):hover,
|
||||
.nova-row-actions__button--ghost.nova-row-actions__button--active {
|
||||
background: var(--row-action-soft);
|
||||
}
|
||||
|
||||
.nova-row-actions__button:not(:disabled):hover {
|
||||
transform: scale(1.04);
|
||||
}
|
||||
|
||||
.nova-row-actions__button:focus-visible {
|
||||
outline: 2px solid var(--row-action-color);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.nova-row-actions__button:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.55;
|
||||
}
|
||||
|
||||
.nova-row-actions__button--working:disabled {
|
||||
cursor: wait;
|
||||
}
|
||||
|
||||
.dark .nova-row-actions__button {
|
||||
--row-action-soft: rgb(55 65 81 / 0.55);
|
||||
border-color: rgb(75 85 99);
|
||||
}
|
||||
|
||||
.dark .nova-row-actions__button--solid {
|
||||
border-color: var(--row-action-color);
|
||||
}
|
||||
|
||||
.nova-row-actions__icon {
|
||||
width: 1.2rem;
|
||||
height: 1.2rem;
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.nova-row-actions__label {
|
||||
white-space: nowrap;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.nova-row-actions__button--working > :not(.nova-row-actions__spinner) {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.nova-row-actions__spinner {
|
||||
position: absolute;
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
border: 2px solid currentColor;
|
||||
border-inline-end-color: transparent;
|
||||
border-radius: 9999px;
|
||||
animation: nova-row-actions-spin 650ms linear infinite;
|
||||
}
|
||||
|
||||
.nova-row-actions__sr-only {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
padding: 0;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.nova-row-actions__button {
|
||||
transition: none;
|
||||
}
|
||||
|
||||
.nova-row-actions__spinner {
|
||||
animation-duration: 1.5s;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes nova-row-actions-spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
export function resolveActionContext(props, search = '') {
|
||||
const query = new URLSearchParams(search)
|
||||
|
||||
return {
|
||||
viaResource:
|
||||
props.viaResource || query.get('viaResource') || undefined,
|
||||
viaResourceId:
|
||||
props.viaResourceId ?? query.get('viaResourceId') ?? undefined,
|
||||
viaRelationship: query.get('viaRelationship') || undefined,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
<template>
|
||||
<div
|
||||
class="nova-row-actions"
|
||||
role="group"
|
||||
:aria-label="field.name"
|
||||
@click.stop
|
||||
>
|
||||
<button
|
||||
v-for="button in buttons"
|
||||
:key="button.key"
|
||||
type="button"
|
||||
class="nova-row-actions__button"
|
||||
:class="buttonClasses(button)"
|
||||
:disabled="working || button.disabled"
|
||||
:aria-label="button.label"
|
||||
:aria-pressed="button.active"
|
||||
:aria-busy="isWorking(button)"
|
||||
:title="button.tooltip"
|
||||
v-tooltip="button.tooltip"
|
||||
@click.stop="run(button)"
|
||||
>
|
||||
<Icon
|
||||
:name="button.icon"
|
||||
class="nova-row-actions__icon"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
|
||||
<span v-if="button.showLabel" class="nova-row-actions__label">
|
||||
{{ button.label }}
|
||||
</span>
|
||||
|
||||
<span v-else class="nova-row-actions__sr-only">
|
||||
{{ button.label }}
|
||||
</span>
|
||||
|
||||
<span
|
||||
v-if="isWorking(button)"
|
||||
class="nova-row-actions__spinner"
|
||||
role="status"
|
||||
:aria-label="__('Running Action')"
|
||||
/>
|
||||
</button>
|
||||
|
||||
<component
|
||||
v-if="actionModalVisible"
|
||||
:is="selectedAction?.component"
|
||||
class="text-left"
|
||||
:show="actionModalVisible"
|
||||
:working="working"
|
||||
:selected-resources="selectedResources"
|
||||
:resource-name="resourceName"
|
||||
:action="selectedAction"
|
||||
:errors="errors"
|
||||
@confirm="executeAction"
|
||||
@close="closeConfirmationModal"
|
||||
/>
|
||||
|
||||
<component
|
||||
v-if="responseModalVisible"
|
||||
:is="actionModalReponseData?.component"
|
||||
:show="responseModalVisible"
|
||||
:data="actionModalReponseData?.payload ?? {}"
|
||||
@confirm="closeResponseModalAndRefresh"
|
||||
@close="closeResponseModalAndRefresh"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, getCurrentInstance } from 'vue'
|
||||
import { useActions } from '@/composables/useActions'
|
||||
import { resolveActionContext } from '../actionContext.mjs'
|
||||
|
||||
const emit = defineEmits(['actionExecuted'])
|
||||
|
||||
const props = defineProps({
|
||||
resource: { type: Object, required: true },
|
||||
resourceName: { type: String, required: true },
|
||||
field: { type: Object, required: true },
|
||||
viaResource: { type: String, default: null },
|
||||
viaResourceId: { type: [String, Number], default: null },
|
||||
})
|
||||
|
||||
const instance = getCurrentInstance()
|
||||
const actionContext = resolveActionContext(props, window.location.search)
|
||||
|
||||
const buttons = computed(() => props.field.actions || [])
|
||||
const actions = computed(() => buttons.value.map(button => button.action))
|
||||
const selectedResources = computed(() => [props.resource.id.value])
|
||||
|
||||
const runnerProps = {
|
||||
get actions() {
|
||||
return actions.value
|
||||
},
|
||||
get selectedResources() {
|
||||
return selectedResources.value
|
||||
},
|
||||
get resourceName() {
|
||||
return props.resourceName
|
||||
},
|
||||
get viaResource() {
|
||||
return actionContext.viaResource
|
||||
},
|
||||
get viaResourceId() {
|
||||
return actionContext.viaResourceId
|
||||
},
|
||||
get viaRelationship() {
|
||||
return actionContext.viaRelationship
|
||||
},
|
||||
pivotActions: { actions: [] },
|
||||
endpoint: null,
|
||||
}
|
||||
|
||||
const relayActionExecuted = event => {
|
||||
emit(event)
|
||||
|
||||
// Nova does not forward custom field events from the field cell. Relay the
|
||||
// native event through ResourceTableRow, whose listener refreshes the table.
|
||||
if (event === 'actionExecuted') {
|
||||
instance?.proxy?.$parent?.$emit('actionExecuted')
|
||||
}
|
||||
}
|
||||
|
||||
const {
|
||||
errors,
|
||||
working,
|
||||
actionModalVisible,
|
||||
responseModalVisible,
|
||||
selectedActionKey,
|
||||
selectedAction,
|
||||
closeConfirmationModal,
|
||||
closeResponseModal,
|
||||
handleActionClick,
|
||||
executeAction,
|
||||
actionModalReponseData,
|
||||
} = useActions(runnerProps, relayActionExecuted, instance.proxy.$store)
|
||||
|
||||
const run = button => {
|
||||
if (!working.value && !button.disabled) {
|
||||
handleActionClick(button.action.uriKey)
|
||||
}
|
||||
}
|
||||
|
||||
const isWorking = button =>
|
||||
working.value && selectedActionKey.value === button.action.uriKey
|
||||
|
||||
const buttonClasses = button => [
|
||||
`nova-row-actions__button--${button.color}`,
|
||||
`nova-row-actions__button--${button.variant}`,
|
||||
{
|
||||
'nova-row-actions__button--active': button.active,
|
||||
'nova-row-actions__button--working': isWorking(button),
|
||||
},
|
||||
]
|
||||
|
||||
const closeResponseModalAndRefresh = () => {
|
||||
closeResponseModal()
|
||||
relayActionExecuted('actionExecuted')
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,5 @@
|
||||
import IndexField from './components/IndexField'
|
||||
|
||||
Nova.booting((app, store) => {
|
||||
app.component('index-row-actions', IndexField)
|
||||
})
|
||||
Reference in new issue
Block a user