Skip to content

Commit 8a0f497

Browse files
Merge pull request #459 from patternfly/US206196--modal-web-component
US206196 modal web component
2 parents 5e35a5f + a129c2c commit 8a0f497

24 files changed

+1023
-72
lines changed

elements/pfe-modal/.babelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": [["env", { "modules": false }]],
3+
"plugins": ["external-helpers"]
4+
}

elements/pfe-modal/.editorconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# EditorConfig: http://EditorConfig.org
2+
3+
# Top-most EditorConfig file
4+
root = true
5+
6+
# Rules for JavaScript files:
7+
8+
[*.{js,py,json,sh,html}]
9+
# 4 space indentation
10+
indent_style = space
11+
indent_size = 2
12+
# No trailing spaces
13+
trim_trailing_whitespace = true
14+
# Unix-style newlines
15+
end_of_line = lf
16+
# Newline ending every file
17+
insert_final_newline = true

elements/pfe-modal/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

elements/pfe-modal/.travis.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
language: node_js
2+
dist: trusty
3+
sudo: required
4+
addons:
5+
firefox: "latest"
6+
apt:
7+
sources:
8+
- google-chrome
9+
packages:
10+
- google-chrome-stable
11+
node_js: stable
12+
before_install:
13+
- npm install -g web-component-tester
14+
install:
15+
- npm install
16+
before_script:
17+
script:
18+
- xvfb-run npm run test

elements/pfe-modal/LICENSE.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright 2019 Red Hat, Inc.
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

elements/pfe-modal/README.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# PFElements Modal Element
2+
3+
## Overview
4+
5+
`pfe-modal` is a self-contained modal window that is hidden on page load and (when activated) restricts the user from interacting with content in the main window.
6+
7+
## Usage
8+
9+
### With a trigger
10+
```html
11+
<pfe-modal>
12+
<button slot="pfe-modal--trigger">Open modal</button>
13+
<h2 slot="pfe-modal--header">Modal with a header</h2>
14+
<p>Lorem ipsum dolor sit amet, <a href="#foo">consectetur adipisicing</a> elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
15+
<pfe-cta>
16+
<a href="#bar">Learn more</a>
17+
</pfe-cta>
18+
</pfe-modal>
19+
```
20+
21+
### Without a trigger
22+
```html
23+
<pfe-modal>
24+
<h2 slot="pfe-modal--header">Modal with a header</h2>
25+
<p>Lorem ipsum dolor sit amet, <a href="#foo">consectetur adipisicing</a> elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
26+
<pfe-cta>
27+
<a href="#bar">Learn more</a>
28+
</pfe-cta>
29+
</pfe-modal>
30+
```
31+
## Slots
32+
33+
### Trigger
34+
The only part visible on page load, the trigger opens the modal window. The trigger can be a button, a cta or a link. While it is part of the modal web component, it does not contain any intrinsic styles.
35+
36+
### Header
37+
The header is an optional slot that appears at the top of the modal window. It should be a header tag (h2-h6).
38+
39+
### Default slot
40+
The default slot can contain any type of content. When the header is not present this unnamed slot appear at the top of the modal window (to the left of the close button). Otherwise it will appear beneath the header.
41+
42+
## API
43+
44+
### open
45+
46+
Manually opens a modal. Return the modal that has been opened.
47+
48+
```
49+
document.querySelector("pfe-modal").open();
50+
```
51+
52+
### close
53+
54+
Manually closes a modal. Returns the modal that has been closed.
55+
56+
```
57+
document.querySelector("pfe-modal").close();
58+
```
59+
60+
### toggle
61+
62+
Manually toggles a modal. Returns the modal that has been toggled.
63+
64+
```
65+
document.querySelector("pfe-modal").toggle();
66+
```
67+
68+
## Events
69+
70+
### pfe-modal:open
71+
Fires when a user clicks on the trigger or manually opens a modal.
72+
73+
```
74+
detail: {
75+
open: true
76+
}
77+
```
78+
79+
### pfe-modal:close
80+
Fires when either a user clicks on either the close button or the overlay or manually closes a modal.
81+
82+
```
83+
detail: {
84+
open: false
85+
}
86+
```
87+
88+
## Test
89+
90+
npm run test
91+
92+
## Build
93+
94+
npm run build
95+
96+
## Demo
97+
98+
From the PFElements root directory, run:
99+
100+
npm start
101+
102+
## Code style
103+
104+
Modal (and all PFElements) use [Prettier][prettier] to auto-format JS and JSON. The style rules get applied when you commit a change. If you choose to, you can [integrate your editor][prettier-ed] with Prettier to have the style rules applied on every save.
105+
106+
[prettier]: https://github.com/prettier/prettier/
107+
[prettier-ed]: https://github.com/prettier/prettier/#editor-integration
108+
[web-component-tester]: https://github.com/Polymer/web-component-tester

elements/pfe-modal/demo/index.html

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
6+
<title>PatternFly Element | pfe-modal Demo</title>
7+
8+
<noscript>
9+
<link href="../../pfelement/pfelement-noscript.min.css" rel="stylesheet">
10+
</noscript>
11+
12+
<link href="../../pfelement/pfelement.min.css" rel="stylesheet">
13+
14+
<!-- uncomment the es5-adapter if you're using the umd version -->
15+
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.2.10/custom-elements-es5-adapter.js"></script>
16+
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.2.10/webcomponents-loader.js"></script>
17+
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.5/require.min.js"></script>
18+
<script>require(['../pfe-modal.umd.js'])</script>
19+
</head>
20+
<body unresolved>
21+
<h1>&lt;pfe-modal&gt;</h1>
22+
<section>
23+
<h2>Modal: Standard modal</h2>
24+
<pfe-modal>
25+
<button slot="pfe-modal--trigger">Open modal</button>
26+
<h2 slot="pfe-modal--header">Modal with a header</h2>
27+
<p>Lorem ipsum dolor sit amet, <a href="#foo">consectetur adipisicing</a> elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
28+
<pfe-cta>
29+
<a href="#bar">Learn more</a>
30+
</pfe-cta>
31+
</pfe-modal>
32+
</section>
33+
<section>
34+
<h2>Modal: No header region</h2>
35+
<pfe-modal>
36+
<button slot="pfe-modal--trigger">Open modal</button>
37+
<h3>This has no header region</h3>
38+
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
39+
</pfe-modal>
40+
</section>
41+
<section>
42+
<h2>Modal: No headings</h2>
43+
<pfe-modal>
44+
<button slot="pfe-modal--trigger">Open modal</button>
45+
<p>This modal doesn't have any headings. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
46+
</pfe-modal>
47+
</section>
48+
<section>
49+
<h2>Modal: External trigger</h2>
50+
<button id="custom-trigger">Custom open modal</button>
51+
<pfe-modal id="custom-modal">
52+
<h2 slot="pfe-modal--header">Custom open modal</h2>
53+
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
54+
</pfe-modal>
55+
</section>
56+
<section>
57+
<h2>Modal: a lot of content</h2>
58+
<pfe-modal>
59+
<button slot="pfe-modal--trigger">Open modal</button>
60+
<h2 slot="pfe-modal--header">Modal with a header with a super duper long title and a lot of content</h2>
61+
<p>Lorem ipsum dolor sit amet, <a href="#foo">consectetur adipisicing</a> elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
62+
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Sed posuere consectetur est at lobortis. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.</p>
63+
<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Curabitur blandit tempus porttitor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur blandit tempus porttitor. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Curabitur blandit tempus porttitor.</p>
64+
<p>Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Donec sed odio dui. Maecenas faucibus mollis interdum. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p>
65+
<pfe-cta>
66+
<a href="#bar">Learn more</a>
67+
</pfe-cta>
68+
</pfe-modal>
69+
</section>
70+
<script>
71+
document.querySelector("#custom-trigger").addEventListener("click", function (event) {
72+
document.querySelector("#custom-modal").open(event);
73+
});
74+
</script>
75+
</body>
76+
</html>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { storiesOf } from "@storybook/polymer";
2+
import * as storybookBridge from "@storybook/addon-knobs/polymer";
3+
import * as tools from "../../../.storybook/utils.js";
4+
5+
import PfeModal from "../pfe-modal";
6+
import PfeCta from "../../pfe-cta/pfe-cta";
7+
8+
const stories = storiesOf("Modal", module );
9+
10+
const defaultHeader = tools.autoHeading();
11+
const defaultContent = tools.autoContent();
12+
13+
// Define the template to be used
14+
const template = (data = {}) => {
15+
return tools.component(PfeModal.tag, data.prop, data.slots);
16+
};
17+
18+
stories.addDecorator(storybookBridge.withKnobs);
19+
20+
21+
stories.add(PfeModal.tag, () => {
22+
let config = {};
23+
const props = PfeModal.properties;
24+
25+
// Trigger the auto generation of the knobs for attributes
26+
config.prop = tools.autoPropKnobs(props, storybookBridge);
27+
28+
const slots = PfeModal.slots;
29+
30+
slots.trigger.default = "Launch modal";
31+
slots.header.default = defaultHeader;
32+
slots.body.default = defaultContent;
33+
34+
// Trigger the auto generation of the knobs for slots
35+
config.has = tools.autoContentKnobs(slots, storybookBridge);
36+
37+
// prettier-ignore
38+
config.slots = [{
39+
slot: "pfe-modal--trigger",
40+
tag: "button",
41+
content: config.has.trigger
42+
}, {
43+
slot: "pfe-modal--header",
44+
content: tools.customTag({
45+
tag: "h3",
46+
content: config.has.header
47+
})
48+
}, {
49+
content: config.has.body + tools.component(PfeCta.tag, {}, [{
50+
content: tools.customTag({
51+
tag: "a",
52+
attributes: {
53+
href: "#"
54+
},
55+
content: "Learn more"
56+
})
57+
}])
58+
}];
59+
60+
const render = template(config);
61+
return tools.preview(render);
62+
});

elements/pfe-modal/gulpfile.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const gulpFactory = require("../../scripts/gulpfile.factory.js");
2+
const pfelementPackage = require("./package.json");
3+
4+
gulpFactory(pfelementPackage);

elements/pfe-modal/package-lock.json

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)