Skip to content

useGenerate ​

Generates Vuetify button props from an action definition, with Inertia-aware href handling and responsive icon-only collapse on mobile.

File: vue/src/js/hooks/utils/useGenerate.js


Usage ​

js
import useGenerate from '@/hooks/utils/useGenerate'

const { generateButtonProps, generatedButtonProps } = useGenerate(props, context)
html
<!-- Spread onto any v-btn -->
<v-btn v-bind="generateButtonProps(action)">{{ action.label }}</v-btn>

<!-- Or use the reactive computed version (reads from props directly) -->
<v-btn v-bind="generatedButtonProps">{{ props.label }}</v-btn>

Returns ​

NameTypeDescription
generateButtonProps(action: Object) => ObjectGenerate button props from an action definition object
generatedButtonPropsComputedRef<Object>Reactive button props computed from props (used when the component itself is an action)

Generated Props ​

generateButtonProps(action) returns:

PropSourceDescription
iconaction.icon (when !forceLabel)Icon to display
textaction.label (when forceLabel)Text label
coloraction.colorButton color
variantaction.variantVuetify variant
densityaction.densityDefault 'comfortable'
sizeaction.sizeDefault 'default'
disabledaction.disabledDisabled state
roundedtrue (icon), null (label)Rounded style
onClickInertia-aware handlerSet when action.href is provided

Inertia Href Handling ​

When action.href is set, the generated onClick handler:

  1. Calls e.preventDefault() on the click event
  2. If shouldUseInertia is true and the URL is on the same origin → router.visit(href)
  3. If target is not '_blank' → router.visit(href, { target })
  4. Otherwise → window.open(href, target)

Responsive Behavior ​

generatedButtonProps collapses to icon-only on xs screens (Vuetify's smAndUp breakpoint is false):

  • Sets icon to the resolved icon value
  • Switches density to 'compact'
  • Sets rounded: true

See Also ​