-
Notifications
You must be signed in to change notification settings - Fork 19
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 #56 from josemarluedke/feat/modals
Create Overlay and Modal component
- Loading branch information
Showing
44 changed files
with
1,448 additions
and
57 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
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,37 @@ | ||
<Button | ||
{{on "click" this.toggleModal}} | ||
> | ||
Open Modal | ||
</Button> | ||
|
||
<div class="relative h-48 w-3xl"> | ||
<Modal | ||
@isOpen={{this.isOpen}} | ||
@onClose={{this.toggleModal}} | ||
@renderInPlace={{false}} | ||
as |m| | ||
> | ||
<m.Header>Title</m.Header> | ||
<m.Body> | ||
<p>Some contents...</p> | ||
<p>Some contents...</p> | ||
<p>Some contents...</p> | ||
</m.Body> | ||
<m.Footer> | ||
<Button | ||
@appearance="minimal" | ||
class="mr-4" | ||
{{on "click" this.toggleModal}} | ||
> | ||
Cancel | ||
</Button> | ||
<Button | ||
@intent="primary" | ||
disabled={{this.isLoading}} | ||
{{on "click" this.save}} | ||
> | ||
{{if this.isLoading "Loading..." "Save"}} | ||
</Button> | ||
</m.Footer> | ||
</Modal> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import Component from '@glimmer/component'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { action } from '@ember/object'; | ||
import { later } from '@ember/runloop'; | ||
|
||
interface DemoModalArgs {} | ||
|
||
export default class DemoModal extends Component<DemoModalArgs> { | ||
@tracked isOpen = false; | ||
@tracked isLoading = false; | ||
|
||
@action toggleModal(): void { | ||
this.isOpen = !this.isOpen; | ||
} | ||
|
||
@action save(): void { | ||
this.isLoading = true; | ||
|
||
later( | ||
this, | ||
() => { | ||
this.isLoading = false; | ||
this.isOpen = false; | ||
}, | ||
1000 | ||
); | ||
} | ||
} |
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,5 @@ | ||
# Overlays Installation | ||
|
||
```sh | ||
ember install @frontile/overlays | ||
``` |
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,3 @@ | ||
# Modal | ||
|
||
<Demo::Overlays::DemoModal /> |
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,5 @@ | ||
export function getDOM(context: unknown): null | HTMLDocument; | ||
export function getElementById( | ||
doc: HTMLElement | HTMLDocument, | ||
id: string | ||
): null | HTMLElement; |
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,61 @@ | ||
import { getOwner } from '@ember/application'; | ||
|
||
// adjusted from https://github.com/yapplabs/ember-wormhole/blob/0.5.4/addon/utils/dom.js#L45-L63 | ||
// Copied from https://github.com/ember-intl/ember-intl/blob/a66560d0af9f08af20778a3eb3003045e19fbf16/addon/-private/utils/get-dom.js | ||
// | ||
// Private Ember API usage. Get the dom implementation used by the current | ||
// renderer, be it native browser DOM or Fastboot SimpleDOM | ||
/** | ||
* @private | ||
* @hide | ||
*/ | ||
export function getDOM(context) { | ||
let { renderer } = context; | ||
if (!renderer || !renderer._dom) { | ||
// pre glimmer2 | ||
const container = getOwner ? getOwner(context) : context.container; | ||
const documentService = container.lookup('service:-document'); | ||
|
||
if (documentService) { | ||
return documentService; | ||
} | ||
|
||
renderer = container.lookup('renderer:-dom'); | ||
} | ||
|
||
if (renderer._dom && renderer._dom.document) { | ||
// pre Ember 2.6 | ||
return renderer._dom.document; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
function childNodesOfElement(element) { | ||
const children = []; | ||
let child = element.firstChild; | ||
while (child) { | ||
children.push(child); | ||
child = child.nextSibling; | ||
} | ||
return children; | ||
} | ||
|
||
export function getElementById(doc, id) { | ||
if (doc.getElementById) { | ||
return doc.getElementById(id); | ||
} | ||
|
||
let nodes = childNodesOfElement(doc); | ||
let node; | ||
|
||
while (nodes.length) { | ||
node = nodes.shift(); | ||
|
||
if (node.getAttribute && node.getAttribute('id') === id) { | ||
return node; | ||
} | ||
|
||
nodes = childNodesOfElement(node).concat(nodes); | ||
} | ||
} |
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,6 @@ | ||
<div | ||
class="modal__body" | ||
...attributes | ||
> | ||
{{yield}} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Component from '@glimmer/component'; | ||
|
||
interface ModalBodyArgs {} | ||
|
||
export default class ModalBody extends Component<ModalBodyArgs> {} |
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,6 @@ | ||
<div | ||
class="modal__footer" | ||
...attributes | ||
> | ||
{{yield}} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Component from '@glimmer/component'; | ||
|
||
interface ModalFooterArgs {} | ||
|
||
export default class ModalFooter extends Component<ModalFooterArgs> {} |
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,7 @@ | ||
<div | ||
id={{@labelledById}} | ||
class="modal__header" | ||
...attributes | ||
> | ||
{{yield}} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Component from '@glimmer/component'; | ||
|
||
interface ModalHeaderArgs { | ||
/* | ||
* The id used to reference labelledById in Modal component | ||
*/ | ||
labelledById: string; | ||
} | ||
|
||
export default class ModalHeader extends Component<ModalHeaderArgs> {} |
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,39 @@ | ||
<Overlay | ||
@isOpen={{@isOpen}} | ||
@onClose={{this.handleClose}} | ||
@renderInPlace={{@renderInPlace}} | ||
@destinationElementId={{@destinationElementId}} | ||
@transitionDuration={{@transitionDuration}} | ||
@disableBackdrop={{@disableBackdrop}} | ||
@disableTransitions={{@disableTransitions}} | ||
@disableFocusTrap={{@disableFocusTrap}} | ||
@closeOnOutsideClick={{if this.preventClosing false @closeOnOutsideClick}} | ||
@closeOnEscapeKey={{if this.preventClosing false @closeOnEscapeKey}} | ||
@backdropTransitionName={{@backdropTransitionName}} | ||
@contentTransitionName={{if @transitionName @transitionName "overlay--transition--zoom"}} | ||
> | ||
<div | ||
class="modal" | ||
tabindex="0" | ||
role="dialog" | ||
aria-labelledby={{this.headerId}} | ||
...attributes | ||
> | ||
{{#unless this.preventClosing}} | ||
<button | ||
{{on "click" this.handleClose}} | ||
type="button" | ||
class="modal__close-btn" | ||
> | ||
<span class="modal__close-btn--icon"></span> | ||
<VisuallyHidden>Close</VisuallyHidden> | ||
</button> | ||
{{/unless}} | ||
|
||
{{yield (hash | ||
Header=(component "modal/header" labelledById=this.headerId) | ||
Body=(component "modal/body") | ||
Footer=(component "modal/footer") | ||
)}} | ||
</div> | ||
</Overlay> |
Oops, something went wrong.