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

Modular component scripts #320

Merged
merged 32 commits into from
Aug 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
35d87a7
refactor: share focus and transition functionality
sebnitu Aug 13, 2020
ce94fbf
refactor: add shared accessibility modules
sebnitu Aug 13, 2020
1696dfd
refactor: add shared focusTrap module
sebnitu Aug 13, 2020
414795e
refactor: convert Modal to ES6 class
sebnitu Aug 14, 2020
9913a19
refactor: convert drawer to ES6 class
sebnitu Aug 14, 2020
604d751
test: fix tests
sebnitu Aug 14, 2020
f8a249c
chore: run build
sebnitu Aug 14, 2020
b2e5b97
refactor: update how handler binds this
sebnitu Aug 14, 2020
5bde5fa
refactor: convert checkbox to ES6 class
sebnitu Aug 14, 2020
2eb8b7f
refactor: create modal defaults module
sebnitu Aug 14, 2020
e6e7396
refactor: create drawer defaults module
sebnitu Aug 15, 2020
5a1b8c6
refactor: create get and move element modules
sebnitu Aug 15, 2020
0c2db04
refactor create drawer handlers module
sebnitu Aug 15, 2020
6be5065
feat: add getDrawer and getModal methods
sebnitu Aug 15, 2020
0a307a4
refactor: create drawer state module
sebnitu Aug 15, 2020
28b82d4
refactor: improve the state module legibility and add stateClear
sebnitu Aug 15, 2020
89baa64
refactor: create drawer switchTo module
sebnitu Aug 15, 2020
5378db9
refactor: create drawer breakpoint module
sebnitu Aug 15, 2020
fdcf09a
refactor: use getModal in open and remove comment
sebnitu Aug 15, 2020
bd65754
refactor: create modal initialState module
sebnitu Aug 15, 2020
081910e
test: add tests for accessibility module
sebnitu Aug 15, 2020
75b3d81
test: add tests for getElement module
sebnitu Aug 15, 2020
13e1153
test: add tests for moveElement module
sebnitu Aug 15, 2020
db8449c
refactor: update drawer import order
sebnitu Aug 15, 2020
05883c6
refactor: remove deps from transition module
sebnitu Aug 15, 2020
866050b
test: add tests for transition module
sebnitu Aug 15, 2020
c8c8b80
fix: correctly return focus in getFocusable method
sebnitu Aug 15, 2020
1cf9886
test: add tests for focus modules
sebnitu Aug 16, 2020
bc7152d
test: add test coverage for new modules and refactored code
sebnitu Aug 16, 2020
0e59f0d
refactor: clean up checkbox component module
sebnitu Aug 16, 2020
e6e19bc
docs: add docs for checkbox component
sebnitu Aug 16, 2020
c6fa039
docs: add new api to docs
sebnitu Aug 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ If you'd like to use Vrembem for prototyping or just want to take it for a test

<!-- Instantiate the component rendered in the document -->
<script>
const modal = vrembem.Modal();
const modal = new vrembem.Modal();
modal.init();
</script>
```
Expand Down Expand Up @@ -122,8 +122,8 @@ Include the component's markup into your project. Use the [online docs](https://

```html
<button data-modal-open="[unique-id]">Modal</button>
<div class="modal" data-modal="[unique-id]">
<div class="modal__dialog">
<div data-modal="[unique-id]" class="modal">
<div data-modal-dialog class="modal__dialog">
<button data-modal-close>Close</button>
...
</div>
Expand Down
331 changes: 302 additions & 29 deletions docs/_packages/checkbox.md

Large diffs are not rendered by default.

96 changes: 96 additions & 0 deletions docs/_packages/drawer.md
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,30 @@ drawer.close('drawer-key').then((result) => {
});
```

### `drawer.getDrawer(key)`

Returns a drawer that matches the provided unique drawer key.

**Parameters**

- `key [String]` A unique key that matches the value of a drawer `data-drawer` attribute.

**Returns**

- `HTML object` The matching drawer element.


```html
<div class="drawer" data-drawer="drawer-key">...</div>
```

```js
const el = drawer.getDrawer('drawer-key');

// Returns HTML Element Object
console.log(el);
```

### `drawer.setTabindex`

Sets the `tabindex="-1"` attribute on all drawer dialogs. This makes it possible to set focus on the dialog when opened but won't allow users to focus it using the keyboard. This is ran automatically on `drawer.init()` if the `setTabindex` option is set to `true`.
Expand Down Expand Up @@ -828,3 +852,75 @@ drawer.switchToDefault('drawer-key');
<!-- Output -->
<div class="drawer" data-drawer="drawer-key">...</div>
```

### `drawer.stateSet()`

Sets the current saved state of all drawer elements based on the values set in localStorage and updates the instance `drawer.state` object.

```html
<!-- Initial HTML -->
<aside data-drawer="drawer-1" class="drawer is-opened">...</aside>
<aside data-drawer="drawer-2" class="drawer is-opened">...</aside>
```

```js
// If the current saved state in localStorage looks like this:
// {
// "drawer-1": "is-closed",
// "drawer-2": "is-closed"
// }
drawer.stateSet();
```

```html
<!-- Output -->
<aside data-drawer="drawer-1" class="drawer is-closed">...</aside>
<aside data-drawer="drawer-2" class="drawer is-closed">...</aside>
```

### `drawer.stateSave(target)`

Saves the current state of drawers to localStorage and drawer's `drawer.state` object. This is useful when state becomes out of sync or the DOM is re-rendered in a way that breaks current state.

**Parameters**

- `HTML Element [Object]` (Default: null) A specific target to save state. If nothing is passed, all drawers in the DOM will have their state saved.

```html
<!-- Initial HTML -->
<aside data-drawer="drawer-1" class="drawer is-closed">...</aside>
<aside data-drawer="drawer-2" class="drawer is-opened">...</aside>
```

```js
// If current saved state looks like:
console.log(drawer.state);
// {
// "drawer-1": "is-closed",
// "drawer-2": "is-closed"
// }
drawer.stateSave();

// Result
console.log(drawer.state);
// {
// "drawer-1": "is-closed",
// "drawer-2": "is-opened"
// }
```

### `drawer.stateClear()`

Clears the existing saved states in both localStorage and drawer's `drawer.state` object.

```js
console.log(drawer.state);
// Returns: {
// "drawer-1": "is-closed",
// "drawer-2": "is-closed"
// }
drawer.stateClear();

console.log(drawer.state);
// Returns: Object { }
```
80 changes: 52 additions & 28 deletions docs/_packages/modal.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ const modal = new Modal({
autoInit: true,
selectorInert: '[role="main"]',
moveModals: {
selector: '[role="main"]',
location: 'after'
ref: '[role="main"]',
type: 'after'
}
});
```
Expand Down Expand Up @@ -587,11 +587,11 @@ Adjusts the size of modals. This modifier provides two options, `modal_size_sm`
<td data-mobile-label="Key"><code class="code text-nowrap">moveModals</code></td>
<td data-mobile-label="Default">
<pre class="code color-secondary">{
selector: null,
location: null
ref: null,
type: null
}</pre>
</td>
<td data-mobile-label="Desc">Moves all modals to a location in the DOM relative to the passed selector on <code class="code">init()</code>. Location options include <code class="code">after</code>, <code class="code">before</code>, <code class="code">append</code> and <code class="code">prepend</code>.</td>
<td data-mobile-label="Desc">Moves all modals to a location in the DOM relative to the passed reference selector on <code class="code">init()</code>. Move type options include <code class="code">after</code>, <code class="code">before</code>, <code class="code">append</code> and <code class="code">prepend</code>.</td>
</tr>
<tr>
<td data-mobile-label="Key"><code class="code text-nowrap">setTabindex</code></td>
Expand Down Expand Up @@ -665,7 +665,7 @@ modal.open('modal-key');

// Run some code after promise resolves
modal.open('modal-key').then((result) => {
console.log(result); // result = HTML Object || null
console.log(result);
});
```

Expand Down Expand Up @@ -695,35 +695,33 @@ modal.close().then((result) => {
});
```

### `modal.setInitialState()`
### `modal.getModal(key)`

Sets the initial state of all modals. This includes removing all transitional classes, opened states and applies the closed state class. This is ran automatically on `init()` but is exposed if states need to be reset for some reason.
Returns a modal that matches the provided unique modal key.

```html
<!-- Missing a state class... -->
<div data-modal="[unique-id]" class="modal">...</div>
**Parameters**

<!-- Opened state... -->
<div data-modal="[unique-id]" class="modal is-opened">...</div>
- `key [String]` A unique key that matches the value of a modal `data-modal` attribute.

<!-- Transitioning state... -->
<div data-modal="[unique-id]" class="modal is-opening">...</div>
<div data-modal="[unique-id]" class="modal is-closing">...</div>
**Returns**

- `HTML object` The matching modal element.


```html
<div class="modal is-closed" data-modal="modal-key">...</div>
```

```js
modal.setInitialState();
```
```html
<!-- Output -->
<div data-modal="[unique-id]" class="modal is-closed"></div>
<div data-modal="[unique-id]" class="modal is-closed"></div>
<div data-modal="[unique-id]" class="modal is-closed"></div>
<div data-modal="[unique-id]" class="modal is-closed"></div>
const el = modal.getModal('modal-key');

// Returns HTML Element Object
console.log(el);
```

### `modal.setTabindex()`

Sets the `tabindex="-1"` attribute on all modal dialogs. This makes it possible to set focus on the dialog when opened but won't allow users to focus it using the keyboard. This is ran automatically on `init()` if `setTabindex` is set to `true`.
Sets the `tabindex="-1"` attribute on all modal dialogs. This makes it possible to set focus on the dialog when opened but won't allow users to focus it using the keyboard. This is ran automatically on `modal.init()` if the `setTabindex` option is set to `true`.

```html
<!-- Initial HTML -->
Expand All @@ -747,14 +745,40 @@ modal.setTabindex();
</div>
```

### `modal.moveModals(selector, location)`
### `modal.setInitialState()`

Sets the initial state of all modals. This includes removing all transitional classes, opened states and applies the closed state class. This is ran automatically on `modal.init()` but is exposed if states need to be reset for some reason.

```html
<!-- Missing a state class... -->
<div data-modal="[unique-id]" class="modal">...</div>

<!-- Opened state... -->
<div data-modal="[unique-id]" class="modal is-opened">...</div>

<!-- Transitioning state... -->
<div data-modal="[unique-id]" class="modal is-opening">...</div>
<div data-modal="[unique-id]" class="modal is-closing">...</div>
```
```js
modal.setInitialState();
```
```html
<!-- Output -->
<div data-modal="[unique-id]" class="modal is-closed"></div>
<div data-modal="[unique-id]" class="modal is-closed"></div>
<div data-modal="[unique-id]" class="modal is-closed"></div>
<div data-modal="[unique-id]" class="modal is-closed"></div>
```

### `modal.moveModals(ref, type)`

Moves all modals to a location in the DOM relative to the passed selector and location reference.

**Parameters**

- `selector [String]` The selector that modals should be moved relative to.
- `location [String]` The location to move modals relative to the selector. Options include `after`, `before`, `append` and `prepend`.
- `ref [String]` The reference selector that modals should be moved relative to.
- `type [String]` The move type to move modals relative to the reference selector. Options include `after`, `before`, `append` and `prepend`.

```html
<!-- Initial HTML -->
Expand Down
2 changes: 1 addition & 1 deletion docs/_packages/vrembem.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Include the component's markup into your project. Use the [online documentation]
```html
<div class="drawer__wrapper">
<aside data-drawer="[unique-id]" class="drawer">
<div class="drawer__item">
<div data-drawer-dialog class="drawer__dialog">
<button data-drawer-close>...</button>
</div>
</aside>
Expand Down