Skip to content

Commit

Permalink
fix: updated docs for v4
Browse files Browse the repository at this point in the history
  • Loading branch information
kouts committed Jun 4, 2023
1 parent b449a79 commit d0f2047
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 66 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# vue-modal <a href="https://npm.im/@kouts/vue-modal"><img src="https://badgen.net/npm/v/@kouts/vue-modal/next"></a> ![](https://img.badgesize.io/kouts/vue-modal/next/dist/vue-modal.umd.js.svg) ![](https://img.badgesize.io/kouts/vue-modal/next/dist/vue-modal.umd.js.svg?compression=gzip) ![](coverage/badge.svg)

A customizable, stackable, and lightweight modal component for Vue.js 3.

---
Expand All @@ -12,30 +13,28 @@ If you're looking for a Vue.js 2 compatible version of vue-modal, [please check
> to the accessibility best practices set in the [WAI-ARIA Dialog (Modal)](https://www.w3.org/TR/wai-aria-practices/#dialog_modal) section
> of W3C.

## Features at a glance

- Lightweight, minified gzipped version is < **4kb**
- Opens and closes with a data variable using ```v-model```
- Opens and closes with a data variable using `v-model` **or** with a `name` prop and `show`/`hide` functions
- Includes sensible default styling but it's also highly customizable via user CSS classes and styles
- Override modal title and content via slots
- Modal intro and outro effects using CSS animation classes
- Exposes Component events - before-open, opening, after-open, before-close, closing, after-close, update:modelValue (close)
- Scrollable when it's contents exceed screen height
- Closeable by clicking on the upper right "x", the overlay or the ```esc``` key
- Closeable by clicking on the upper right "x", the overlay or the `esc` key
- **Stackable** - Multiple modal windows on top of each other
- Ability to set initial focus on an element when the modal window opens, just set the **autofocus** attribute on an element inside the modal
- **Focus management** traps keyboard focus - tabbed navigation inside the modal window
- Ability to have unclosable modal windows
- Render on demand or stay always in DOM with "live" mode
- Modals appended to ```<body>``` by default, ability to append to a custom element
- Modals appended to `<body>` by default, ability to append to a custom element

## Browsers support

| [<img src="https://github.com/raw/alrra/browser-logos/master/src/edge/edge_48x48.png" alt="Edge" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br/>Edge | [<img src="https://github.com/raw/alrra/browser-logos/master/src/firefox/firefox_48x48.png" alt="Firefox" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br/>Firefox | [<img src="https://github.com/raw/alrra/browser-logos/master/src/chrome/chrome_48x48.png" alt="Chrome" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br/>Chrome | [<img src="https://github.com/raw/alrra/browser-logos/master/src/safari/safari_48x48.png" alt="Safari" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br/>Safari | [<img src="https://github.com/raw/alrra/browser-logos/master/src/opera/opera_48x48.png" alt="Opera" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br/>Opera |
| --------- | --------- | --------- | --------- | --------- |
| Edge| last 2 versions| last 2 versions| last 2 versions| last 2 versions

| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Edge | last 2 versions | last 2 versions | last 2 versions | last 2 versions |

Click here for documentation and examples
https://next--vue-modal-demo.netlify.app/
Expand Down
5 changes: 4 additions & 1 deletion docs/.vuepress/client.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import Example1 from './components/Example1.vue'
import Example2 from './components/Example2.vue'
import Intro from './components/Intro.vue'
import Modal from '@/Modal.vue'
import { Modal, modalPlugin } from '@/index'
import { defineClientConfig } from '@vuepress/client'
import './styles/styles.scss'

export default defineClientConfig({
enhance({ app, router, siteData }) {
app.use(modalPlugin)
app.component('Modal', Modal)
app.component('Example1', Example1)
app.component('Example2', Example2)
app.component('Intro', Intro)
},
setup() {
Expand Down
15 changes: 15 additions & 0 deletions docs/.vuepress/components/Example2.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<template>
<div class="mt-3">
<div class="row mb-3">
<div class="col">
<button type="button" class="btn btn-primary" @click="$modal.show('myModal')">Open a modal</button>
</div>
</div>

<ClientOnly>
<Modal name="myModal" title="My first modal">
<p>Modal content goes here...</p>
</Modal>
</ClientOnly>
</div>
</template>
6 changes: 6 additions & 0 deletions docs/.vuepress/styles/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,9 @@ h1#vue-modal + p + p {
code {
font-family: inherit;
}

/* Fix h2 spacing */
.theme-container .theme-default-content:not(.custom) h2 {
margin-bottom: 1.3rem;
padding-bottom: 1.3rem;
}
15 changes: 8 additions & 7 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,27 @@ A customizable, stackable, and lightweight modal component for Vue.js 3.
<Intro />

## Features at a glance
<p class="mb-n3">&nbsp;</p>
## Features at a glance

<p class="mb-n3">&nbsp;</p>

- Lightweight, minified gzipped version is < **4kb**
- Opens and closes with a data variable using ```v-model```
- Opens and closes with a data variable using `v-model` **or** with a `name` prop and `show`/`hide` functions
- Includes sensible default styling but it's also highly customizable via user CSS classes and styles
- Override modal title and content via slots
- Modal intro and outro effects using CSS animation classes
- Exposes Component events - before-open, opening, after-open, before-close, closing, after-close, update:modelValue (close)
- Scrollable when it's contents exceed screen height
- Closeable by clicking on the upper right "x", the overlay or the ```esc``` key
- Closeable by clicking on the upper right "x", the overlay or the `esc` key
- **Stackable** - Multiple modal windows on top of each other
- Ability to set initial focus on an element when the modal window opens, just set the **autofocus** attribute on an element inside the modal
- **Focus management** traps keyboard focus - tabbed navigation inside the modal window
- Ability to have unclosable modal windows
- Render on demand or stay always in DOM with "live" mode
- Modals appended to ```<body>``` by default, ability to append to a custom element
- Modals appended to `<body>` by default, ability to append to a custom element

## Browsers support

| [<img src="https://github.com/raw/alrra/browser-logos/master/src/edge/edge_48x48.png" alt="Edge" />](http://godban.github.io/browsers-support-badges/)<br/>Edge | [<img src="https://github.com/raw/alrra/browser-logos/master/src/firefox/firefox_48x48.png" alt="Firefox" />](http://godban.github.io/browsers-support-badges/)<br/>Firefox | [<img src="https://github.com/raw/alrra/browser-logos/master/src/chrome/chrome_48x48.png" alt="Chrome" />](http://godban.github.io/browsers-support-badges/)<br/>Chrome | [<img src="https://github.com/raw/alrra/browser-logos/master/src/safari/safari_48x48.png" alt="Safari" />](http://godban.github.io/browsers-support-badges/)<br/>Safari | [<img src="https://github.com/raw/alrra/browser-logos/master/src/opera/opera_48x48.png" alt="Opera" />](http://godban.github.io/browsers-support-badges/)<br/>Opera |
| --------- | --------- | --------- | --------- | --------- |
| Edge| last 2 versions| last 2 versions| last 2 versions| last 2 versions
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Edge | last 2 versions | last 2 versions | last 2 versions | last 2 versions |
26 changes: 18 additions & 8 deletions docs/installation/index.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
## Basic

Download the repo, extract ```vue-modal.umd.js``` and ```vue-modal.css``` out of the ```dist``` folder
Download the repo, extract `vue-modal.umd.js` and `vue-modal.css` out of the `dist` folder
and insert them in your page.

``` html
```html
<script type="text/javascript" src="vue-modal.umd.js"></script>
```

``` html
<link rel="stylesheet" href="vue-modal.css">
```html
<link rel="stylesheet" href="vue-modal.css" />
```

## Module System

Install it via npm

```
npm i @kouts/vue-modal@next --save
```
Use the ```import``` statement to include it into your js
``` js
import VueModal from '@kouts/vue-modal'

Use the `import` statement to include it into your `main.js` file.
You may also choose to register `vue-modal` globally, so that you don't need to import it in every component.

```js
import { createApp } from 'vue'
import { Modal } from '@kouts/vue-modal'
import '@kouts/vue-modal/dist/vue-modal.css'
```

const app = Vue.createApp({...})

// This is optional
app.component('Modal', Modal)
```
23 changes: 21 additions & 2 deletions docs/options/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
## v-model

Pass a Boolean value to the `v-model` directive to open and close the modal window.
Pass a `Boolean` value to the `v-model` directive to show and hide the modal window.

## Plugin API

The Plugin API can be called within any component through:

- `useModal` in Composition API
- `this.$modal` in Options API

and exposes 3 functions:

- **`show(name)`** - Shows the modal with the given name
- **`hide(name)`** - Hides the modal with the given name
- **`hideAll()`** - Hides all modals

## Props

Expand All @@ -14,6 +27,12 @@ Pass a Boolean value to the `v-model` directive to open and close the modal wind
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>The name of the modal to use with the show / hide functions.</td>
<td>String</td>
<td><em>Empty</em></td>
</tr>
<tr>
<td>title</td>
<td>The title of the modal element</td>
Expand Down Expand Up @@ -93,7 +112,7 @@ Pass a Boolean value to the `v-model` directive to open and close the modal wind
<td>true</td>
</tr>
<tr>
<td>basedOn</td>
<td>modelValue</td>
<td>Opens and closes the modal window, this is used by <code>v-model</code> internally.</td>
<td>Boolean</td>
<td>false</td>
Expand Down
3 changes: 0 additions & 3 deletions docs/package.json

This file was deleted.

126 changes: 89 additions & 37 deletions docs/usage/index.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,105 @@
## Register
Register ```vue-modal``` in your application globbaly
``` js
const app = Vue.createApp({...})
# Usage

There are two ways in which you can control `vue-modal`'s visibility:

1. With `v-model` directive
2. Using a `name` prop and `show`/`hide` functions

## Usage with `v-model` directive

To control the visibility of the modal with `v-model`, you need to pass a `Boolean` value to the `v-model` directive.

```vue
<template>
<!-- Setting `showModal` to true, displays the modal -->
<button type="button" @click="showModal = true">Open a modal</button>
<Modal v-model="showModal" title="My first modal">
<p>Modal content goes here...</p>
</Modal>
</template>
<script>
// You can skip the import if you've registered the component globally
import { Modal } from '@kouts/vue-modal'
app.component('Modal', VueModal)
```
or locally
``` js
export default {
components: {
'Modal': VueModal
Modal
},
data() {
return {
showModal: false
}
}
}
</script>
```
## Use
### Template
with `v-model`
``` vue
<button type="button" class="btn btn-primary" @click="showModal=true">
Open a modal
</button>
<Modal v-model="showModal" title="My first modal">
<p>Modal content goes here...</p>
</Modal>

**Example:**

<Example1 />

## Usage with `name` prop and `show`/`hide` functions

`vue-modal` comes with a `modalPlugin` that you need to import and register,
in order to be able to use `vue-modal` with a `name` prop.

```js
import { createApp } from 'vue'
import { modalPlugin } from '@kouts/vue-modal'

const app = Vue.createApp({...})

app.use(modalPlugin)
```
or
with `modelValue` value and `update:modelValue` event
``` vue
<Modal :model-value="showModal" title="My first modal" @update:modelValue="showModal = false">
<p>Modal content goes here...</p>
</Modal>

To control the visibility of the modal with the mane `prop` you use the and `show`/`hide` functions.

**Composition API**

```vue
<template>
<!-- Use the `show` function to display the modal -->
<button type="button" @click="show('myModal')">Open a modal</button>
<Modal name="myModal" title="My first modal">
<p>Modal content goes here...</p>
</Modal>
</template>
<script setup>
// You can skip the import if you've registered the component globally
import { Modal, useModal } from '@kouts/vue-modal'
const { show } = useModal()
</script>
```

**Options API**

### Script
``` js
import VueModal from '@kouts/vue-modal'
```vue
<template>
<!-- Use the `$modal.show` function to display the modal -->
<button type="button" @click="$modal.show('myModal')">Open a modal</button>
<Modal name="myModal" title="My first modal">
<p>Modal content goes here...</p>
</Modal>
</template>
<script>
// You can skip the import if you've registered the component globally
import { Modal } from '@kouts/vue-modal'
export default {
components: {
'Modal': VueModal
},
data() {
return {
showModal: false
}
Modal
}
}
</script>
```
### Result
<Example1 />

**Example:**

<Example2 />
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"main": "./dist/vue-modal.umd.js",
"module": "./dist/vue-modal.es.js",
"unpkg": "dist/vue-modal.umd.js",
"sideEffects": false,
"scripts": {
"dev": "vite",
"serve": "vite preview",
Expand Down

0 comments on commit d0f2047

Please sign in to comment.