-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from Applelo/dev
Version 0.9.0
- Loading branch information
Showing
31 changed files
with
1,003 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Dropdown Demo | ||
|
||
<script setup> | ||
import './../../packages/core/dist/css/dropdown.css' | ||
import { Dropdown } from './../../packages/core' | ||
import { onMounted } from 'vue' | ||
|
||
onMounted(() => { | ||
const dropdown = new Dropdown('#dropdown', { | ||
openOn: 'hover' | ||
}) | ||
const dropdownMenu = new Dropdown('#dropdown-menu') | ||
}) | ||
</script> | ||
<style> | ||
.c-dropdown.c-dropdown, .c-dropdown.c-dropdown ul { | ||
margin: 0; | ||
list-style: none; | ||
padding: 0; | ||
gap: 10px; | ||
} | ||
.c-dropdown.c-dropdown li { | ||
margin: 0; | ||
} | ||
</style> | ||
<div class="c-dropdown" id="dropdown" style="margin-top: 2rem;"> | ||
<button class="c-dropdown-trigger" aria-controls="dropdown-container">Basic Dropdown</button> | ||
<div class="c-dropdown-container" id="dropdown-container"> | ||
Hello World | ||
</div> | ||
</div> | ||
|
||
<div class="c-dropdown" id="dropdown-menu" style="margin-top: 2rem;"> | ||
<button class="c-dropdown-trigger" aria-controls="dropdown-menu-container">Item 1 - Dropdown Menu</button> | ||
<ul class="c-dropdown-container" id="dropdown-menu-container"> | ||
<li><a href="#">Item 1</a></li> | ||
<li><a href="#">Item 2</a></li> | ||
<li><a href="#">Item 3</a></li> | ||
</ul> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
# Dropdown | ||
|
||
The dropdown component allows to create a popup menu with links or whatever you want, open by a button. | ||
|
||
```scss | ||
@import 'compotes/css/dropdown'; | ||
``` | ||
|
||
```js | ||
import { Dropdown } from 'compotes' | ||
|
||
const dropdown = new Drag('.c-dropdown') | ||
``` | ||
|
||
You can use any kind of element to trigger the dropdown, just add the `c-dropdown-trigger` class. | ||
|
||
It is recommended to put an `id` to the dropdown container. On your trigger element, add an `aria-controls` attribute refering to the `id` of the dropdown. | ||
|
||
```html | ||
<!-- Default dropdown --> | ||
<div class="c-dropdown"> | ||
<button class="c-dropdown-trigger" aria-controls="my-dropdown">Basic Dropdown</button> | ||
<div class="c-dropdown-container" id="my-dropdown"> | ||
Hello World | ||
</div> | ||
</div> | ||
``` | ||
|
||
If you are using a `ul` as a dropdown, it will use, by default, the `menu` mode adding accessibility features. You can change this by enforce the type of dropdown you want. | ||
|
||
```html | ||
<!-- Menu dropdown --> | ||
<div class="c-dropdown"> | ||
<a class="c-dropdown-trigger" aria-controls="my-dropdown">Item 1 - Dropdown Menu</a> | ||
<ul class="c-dropdown-container" id="my-dropdown"> | ||
<li><a href="#">Item 1</a></li> | ||
<li><a href="#">Item 2</a></li> | ||
<li><a href="#">Item 3</a></li> | ||
</ul> | ||
</div> | ||
``` | ||
|
||
## Accessibility | ||
|
||
To ensure accessibility feature, the component will inject `aria-expanded` to the trigger element. This allow the user to know if the collapse is expanded or not. The user also knows what element it refer thanks to the `aria-controls` attribute. | ||
|
||
If you are using the `menu` type, it will inject `role` attributes on the `<ul>`, `<li>` and `<a>` elements. | ||
|
||
## Options | ||
|
||
You can change some options from the component. | ||
|
||
```js | ||
import { Dropdown } from 'compotes' | ||
|
||
const drag = new Drag('.c-drag', { | ||
init: true, // [!code focus:4] | ||
initEvents: true, | ||
enforceType: undefined, | ||
openOn: 'click', | ||
}) | ||
``` | ||
|
||
- `init` (boolean): Init the component on creation | ||
- `initEvents` (boolean): Init events on the component | ||
- `enforceType` ('default' or 'menu'): The type of the drilldown | ||
- `openOn` ('click' or 'hover'): Open the drilldown on click/hover from the trigger element | ||
|
||
## Methods | ||
|
||
The dropdown component provides several methods to init and destroy the component and also open/toggle/close event. | ||
|
||
```js | ||
import { Dropdown } from 'compotes' | ||
|
||
const dropdown = new Drag('.c-dropdown', { | ||
init: false | ||
}) | ||
dropdown.init()// [!code focus] | ||
``` | ||
|
||
- `init()`: Init the component | ||
- `initAccessibilityAttrs()`: Init accessibility attributes | ||
- `initEvents()`: Init component events | ||
- `initAccessibilityEvents()`: Init component accessibility events | ||
- `destroyEvents()`: Destroy the component events | ||
- `destroy()`: Destroy the component | ||
- `open()`: Open the drilldown | ||
- `toggle()`: Toggle the drilldown | ||
- `close()`: Close the drilldown | ||
|
||
## Data | ||
|
||
You can access data from the component like this: | ||
|
||
```js | ||
import { Dropdown } from 'compotes' | ||
|
||
const dropdown = new Drag('.c-dropdown') | ||
console.log(dropdown.isOpen)// [!code focus] | ||
``` | ||
|
||
- `options` (options object): Get options used to init the component | ||
- `isOpen` (boolean): Tell if the dropdown is open or not | ||
- `type` ('default' or 'menu'): Tell the current type of dropdown | ||
|
||
## Events | ||
|
||
You can listen to emitted events directly on the dropdown element like this: | ||
|
||
```js | ||
import { Dropdown } from 'compotes' | ||
|
||
const dropdownEl = document.querySelector('.c-dropdown') | ||
const dropdown = new Drag(dropdownEl) | ||
|
||
dropdownEl.addEventListener('c.dropdown.init', (e) => { // [!code focus:3] | ||
console.log(e.detail)// drag object | ||
}) | ||
``` | ||
|
||
- `c.dropdown.init`: On component init | ||
- `c.dropdown.destroy`: On component destroy | ||
- `c.dropdown.opened`: On dropdown open | ||
- `c.dropdown.closed`: On dropdown close |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.