Skip to content

Commit

Permalink
add custom component example to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
smastrom committed Aug 1, 2023
1 parent 95d965a commit 8e2fb9f
Showing 1 changed file with 43 additions and 6 deletions.
49 changes: 43 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,31 @@ pnpm add notivue

<br />

## Vite / Vue CLI
## Vite

### 1. Configure

**main.js/ts**

```js
```diff
import { createApp } from 'vue'
import { notivue } from 'notivue'
+ import { notivue } from 'notivue'

import App from './App.vue'

import 'notivue/notifications.css' // Only needed if using built-in notifications
import 'notivue/animations.css' // Only needed if using built-in animations
+ import 'notivue/notifications.css' // Only needed if using built-in notifications
+ import 'notivue/animations.css' // Only needed if using built-in animations

const app = createApp(App)

app.use(notivue)
+ app.use(notivue)
app.mount('#app')
```

**App.vue**

With built-in notifications:

```vue
<script setup>
import { Notivue, Notifications } from 'notivue'
Expand All @@ -85,6 +87,41 @@ import { Notivue, Notifications } from 'notivue'
</template>
```

Or roll your own:

```vue
<template>
<Notivue v-slot="item">
<div class="rounded-full flex py-2 pl-3 bg-slate-700 text-slate-50 text-sm">
{{ item.message }}
<button
@click="item.clear"
aria-label="Dismiss"
class="pl-3 pr-2 hover:text-red-300 transition-colors"
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
class="w-5 h-5"
aria-hidden="true"
>
<path
fill-rule="evenodd"
d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.28 7.22a.75.75 0 00-1.06 1.06L8.94 10l-1.72 1.72a.75.75 0 101.06 1.06L10 11.06l1.72 1.72a.75.75 0 101.06-1.06L11.06 10l1.72-1.72a.75.75 0 00-1.06-1.06L10 8.94 8.28 7.22z"
/>
</svg>
</button>
</div>
</Notivue>
<!-- ... -->
</template>
```

Animations, repositioning, pausing, timeouts, and ARIA live regions are always handled by `<Notivue />` when using custom components, so don't worry about anything else besides building the component itself.

### 2. Push notifications from any component

```vue
Expand Down

0 comments on commit 8e2fb9f

Please sign in to comment.