Skip to content

Commit

Permalink
feat(Alert): add actions slot (#1785)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
  • Loading branch information
moshetanzer and benjamincanac authored May 28, 2024
1 parent 4f0d00f commit c8dd71c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 6 additions & 0 deletions docs/content/2.components/alert.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ Use the `#avatar` slot to customize the displayable avatar.

:component-example{component="alert-example-avatar"}

### `actions` :u-badge{label="New" class="align-middle ml-2 !rounded-full" variant="subtle"}

Use the `#actions` slot to add custom user interaction elements.

:component-example{component="alert-example-actions"}

## Props

:component-props
Expand Down
12 changes: 8 additions & 4 deletions src/runtime/components/elements/Alert.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@
</slot>
</p>

<div v-if="(description || $slots.description) && actions.length" :class="ui.actions">
<UButton v-for="(action, index) of actions" :key="index" v-bind="{ ...(ui.default.actionButton || {}), ...action }" @click.stop="onAction(action)" />
<div v-if="(description || $slots.description) && (actions.length || $slots.actions)" :class="ui.actions">
<slot name="actions">
<UButton v-for="(action, index) of actions" :key="index" v-bind="{ ...(ui.default.actionButton || {}), ...action }" @click.stop="onAction(action)" />
</slot>
</div>
</div>
<div v-if="closeButton || (!description && !$slots.description && actions.length)" :class="twMerge(ui.actions, 'mt-0')">
<template v-if="!description && !$slots.description && actions.length">
<UButton v-for="(action, index) of actions" :key="index" v-bind="{ ...(ui.default.actionButton || {}), ...action }" @click.stop="onAction(action)" />
<template v-if="!description && !$slots.description && (actions.length || $slots.actions)">
<slot name="actions">
<UButton v-for="(action, index) of actions" :key="index" v-bind="{ ...(ui.default.actionButton || {}), ...action }" @click.stop="onAction(action)" />
</slot>
</template>

<UButton v-if="closeButton" aria-label="Close" v-bind="{ ...(ui.default.closeButton || {}), ...closeButton }" @click.stop="$emit('close')" />
Expand Down

0 comments on commit c8dd71c

Please sign in to comment.