Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Alert): add actions slot #1785

Merged
merged 9 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 7 additions & 3 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 || $slots.actions) && (actions.length || $slots.actions)" :class="ui.actions">
moshetanzer marked this conversation as resolved.
Show resolved Hide resolved
<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">
moshetanzer marked this conversation as resolved.
Show resolved Hide resolved
<UButton v-for="(action, index) of actions" :key="index" v-bind="{ ...(ui.default.actionButton || {}), ...action }" @click.stop="onAction(action)" />
<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
Loading