-
Notifications
You must be signed in to change notification settings - Fork 11
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 #13 from ccinelli/feature/cc/portal
Adding portal
- Loading branch information
Showing
9 changed files
with
34,586 additions
and
8,858 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,9 @@ | ||
# Change Log | ||
|
||
All notable changes to this project will be documented in this file. | ||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. | ||
|
||
|
||
### Features | ||
|
||
* **portal:** Adding portal component ([b27e61a](https://github.com/marko-js/tags/commit/b27e61a)) |
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,57 @@ | ||
<h1 align="center"> | ||
<!-- Logo --> | ||
<br/> | ||
@marko-tags/portal | ||
<br/> | ||
|
||
<!-- Stability --> | ||
<a href="https://nodejs.org/api/documentation.html#documentation_stability_index"> | ||
<img src="https://img.shields.io/badge/stability-stable-green.svg" alt="API Stability"/> | ||
</a> | ||
<!-- NPM Version --> | ||
<a href="https://npmjs.org/package/@marko-tags/portal"> | ||
<img src="https://img.shields.io/npm/v/@marko-tags/portal.svg" alt="NPM Version"/> | ||
</a> | ||
<!-- Downloads --> | ||
<a href="https://npmjs.org/package/@marko-tags/portal"> | ||
<img src="https://img.shields.io/npm/dm/@marko-tags/portal.svg" alt="Downloads"/> | ||
</a> | ||
</h1> | ||
|
||
A Portal Component for Marko.js | ||
|
||
Portals provide a way to render children into a DOM node that exists outside the DOM hierarchy of the parent component. | ||
|
||
A typical use case for portals is when a parent component has an `overflow: hidden` or `z-index` style, but you need the child to visually “break out” of its container. For example, dialogs and tooltips. | ||
|
||
# Installation | ||
|
||
```console | ||
npm install @marko-tags/portal | ||
``` | ||
|
||
# Example | ||
|
||
By default, the portal renders into `document.body`: | ||
|
||
```marko | ||
<portal> | ||
...content here... | ||
</portal> | ||
``` | ||
|
||
You can set a custom target container using a DOM id: | ||
|
||
```marko | ||
<portal target="some-id"> | ||
...content here... | ||
</portal> | ||
``` | ||
|
||
Or by passing a DOM Node: | ||
|
||
```marko | ||
<portal target=someNode> | ||
...content here... | ||
</portal> | ||
``` |
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 @@ | ||
import targetTemplate from './target' | ||
|
||
class { | ||
onMount() { | ||
this.target = this.getTarget(this.input.target); | ||
this.component = targetTemplate | ||
.renderSync(this.input) | ||
.appendTo(this.target) | ||
.getComponent(); | ||
} | ||
onInput(newInput) { | ||
let component = this.component; | ||
if (component) { | ||
let target = this.getTarget(newInput.target); | ||
if (target !== this.target) { | ||
component.els.forEach(el => target.appendChild(el)); | ||
this.target = target; | ||
} | ||
component.input = newInput; | ||
} | ||
} | ||
getTarget(target) { | ||
if (typeof target === "string") { | ||
target = document.getElementById(target); | ||
} | ||
return target || document.body; | ||
} | ||
onDestroy() { | ||
this.component.destroy(); | ||
} | ||
} | ||
|
||
<span style={ | ||
display: "none" | ||
}/> |
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,8 @@ | ||
{ | ||
"<portal>": { | ||
"template": "./index.marko", | ||
"attributes": { | ||
"target": "expression" | ||
} | ||
} | ||
} |
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,29 @@ | ||
{ | ||
"name": "@marko-tags/portal", | ||
"description": "A Portal Component for Marko.js. A typical use case for portals is in dialogs, 'hovercards', and tooltips.", | ||
"version": "1.0.0", | ||
"bugs": "https://github.com/marko-js/tags/issues/new?template=Bug_report.md", | ||
"files": [ | ||
"index.marko", | ||
"target.marko", | ||
"marko.json" | ||
], | ||
"homepage": "https://github.com/marko-js/tags/tree/master/tags/portal", | ||
"keywords": [ | ||
"marko", | ||
"markojs", | ||
"portal", | ||
"dialog", | ||
"body", | ||
"overflow", | ||
"z-index" | ||
], | ||
"license": "MIT", | ||
"peerDependencies": { | ||
"marko": "^4" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/marko-js/tags" | ||
} | ||
} |
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 @@ | ||
<include(input.renderBody)/> |
Oops, something went wrong.