Skip to content

Commit 7beca91

Browse files
committed
Dialog: Add typings
1 parent 89be74c commit 7beca91

File tree

14 files changed

+319
-74
lines changed

14 files changed

+319
-74
lines changed

docs/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,14 @@ <h2 class="odo-component__title">
175175
<div class="odo-component__content">
176176
<h2 class="odo-component__title">
177177
<span class="odo-component__title-text">Dialog</span>
178-
<span class="odo-component__badge">v1.0.0</span>
178+
<span class="odo-component__badge">v1.1.0</span>
179179
</h2>
180180

181181

182182
<p class="odo-component__meta">
183-
<img height="20" src="https://img.shields.io/badge/coverage-100%25-brightgreen.svg" title="Statements: 100% (223 / 223)
184-
Branches: 100% (77 / 77)
185-
Functions: 100% (46 / 46)" alt="coverage">
183+
<img height="20" src="https://img.shields.io/badge/coverage-100%25-brightgreen.svg" title="Statements: 100% (232 / 232)
184+
Branches: 100% (80 / 80)
185+
Functions: 100% (47 / 47)" alt="coverage">
186186
<img height="20" src="https://img.shields.io/badge/tag-ui-blue.svg" alt="tag: ui">
187187
</p>
188188

docs/odo-dialog/dist/odo-dialog.js

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

docs/odo-dialog/dist/odo-dialog.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/odo-dialog/dist/odo-dialog.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/odo-dialog/dist/odo-dialog.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/odo-dialog/index.html

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ <h2 class="tombstoned-content__title">A shoreline in Vancouver, Canada</h2>
8989

9090
</div>
9191

92-
<br/>
93-
9492
<pre><code class="language-markup">&lt;button data-odo-dialog-open="default"&gt;Open the default dialog&lt;/button&gt;
9593

9694
&lt;!-- Could be elsewhere in your markup -->
@@ -105,25 +103,45 @@ <h2 class="tombstoned-content__title">A shoreline in Vancouver, Canada</h2>
105103
&lt;/div&gt;
106104
&lt;/div&gt;</code></pre>
107105

108-
<pre><code class="language-javascript" data-language="javascript">const defaultDialog = new OdoDialog(document.getElementById('default'));</code></pre><br/>
106+
<pre><code class="language-javascript" data-language="javascript">const defaultDialog = new OdoDialog(document.getElementById('default'));</code></pre>
109107

110108
<h3>Public Events</h3>
111-
<p>The opened event is triggered when the content has finished its transition in, while the closed event triggers once the dialog has completely transitioned out.</p>
109+
<p>The opened event is triggered when the content has finished its transition in, while the closed event triggers once the dialog has completely transitioned out. In case you need to retrieve some information from the button which triggered the dialog to open, you can subscribe to the <code>TRIGGER_CLICKED</code> event.</p>
112110
<pre><code class="language-javascript">defaultDialog.on(OdoDialog.EventType.OPENED, function () {
113111
console.log('default dialog opened');
114112
});
115113

116114
defaultDialog.on(OdoDialog.EventType.CLOSED, function () {
117115
console.log('default dialog closed');
118-
});</code></pre>
116+
});
119117

120-
<br/>
118+
defaultDialog.on(OdoDialog.EventType.TRIGGER_CLICKED, function (triggerElement) {
119+
console.log('dialog about to open because you clicked:', triggerElement);
120+
});</code></pre>
121121

122122
<h3>Public Methods</h3>
123-
<pre><code class="language-javascript">defaultDialog.open();
124-
defaultDialog.close();
125-
defaultDialog.dispose();
126-
defaultDialog.getByClass(className);</code></pre>
123+
<pre><code class="language-javascript">defaultDialog.open() // Open the dialog
124+
defaultDialog.close() // Close the dialog
125+
defaultDialog.dispose() // Close the dialog, remove event listeners and element references
126+
defaultDialog.getByClass(className) // Find a single element by class inside the dialog</code></pre>
127+
128+
<h3>Public Properties</h3>
129+
<pre><code class="language-javascript">defaultDialog.element // Base element
130+
defaultDialog.options // options object
131+
defaultDialog.id // Unique id for the dialog. Same as the id attribute of the base element
132+
defaultDialog.isOpen // Whether the dialog is currently open</code></pre>
133+
134+
<h3>Protected Methods &amp; Properties</h3>
135+
<p>If you create a subclass of OdoDialog, you will have access to these as well<sup>*</sup>.</p>
136+
137+
<pre><code class="language-javascript">defaultDialog.onClick(evt) // Delegated click handler on the dialog.
138+
defaultDialog.onKeyPress(evt) // Listens for the ESC key and traps the TAB key.
139+
defaultDialog.onResize(viewportHeight) // Sets the height of the dialog on viewport resize.
140+
defaultDialog.content // Dialog content (role=document)
141+
defaultDialog.backdrop // The background behind the dialog
142+
defaultDialog.isAnimating // Whether the dialog is currently animating (opening/closing)
143+
</code></pre>
144+
<p><sup>*</sup><small>Because this is JavaScript, you have access to them already.</small></p>
127145

128146
<h2>Changing Transitions</h2>
129147
<p>In addition to the default fade/scale transition, <code>OdoDialog</code> comes with two other transitions: <code>odo-dialog--fade</code> and <code>odo-dialog--zoom-in</code>. The other options in the <code>&lt;select&gt;</code> below are custom transitions added to this page. See the next section for details.</p>
@@ -150,8 +168,6 @@ <h2 class="no-margin-top" id="animation-changer-title">Cat Ipsum</h2>
150168
</select>
151169
</div>
152170

153-
<br/>
154-
155171
<h2>Add Custom Transitions</h2>
156172
<p>You can add your own transitions too.</p>
157173
<p><code>OdoDialog</code> follows a similar transition sequence to <a href="https://vuejs.org/v2/guide/transitions.html">Vue.js transition effects</a>.</p>

docs/odo-dialog/scripts/demo.js

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ defaultDialog.on(OdoDialog.EventType.CLOSED, function () {
6161
console.log('default dialog closed');
6262
});
6363

64+
defaultDialog.on(OdoDialog.EventType.TRIGGER_CLICKED, function (triggerElement) {
65+
console.log('dialog about to open because you clicked:', triggerElement);
66+
});
67+
6468
var styledDialog = new OdoDialog(document.getElementById('styled'));
6569

6670
var animationChanger = new OdoDialog(document.getElementById('animation-changer'));
@@ -110,40 +114,56 @@ var ScrollToCloseDialog = function (_OdoDialog) {
110114

111115
var _this = possibleConstructorReturn(this, _OdoDialog.call(this, element, options));
112116

113-
_this.onScroll = _this.onScroll.bind(_this);
114-
_this.on(OdoDialog.EventType.OPENED, _this._onOpened.bind(_this));
115-
_this.on(OdoDialog.EventType.CLOSED, _this._onClosed.bind(_this));
117+
_this._onScroll = _this._onScroll.bind(_this);
118+
_this._onOpened = _this._onOpened.bind(_this);
119+
_this._onClosed = _this._onClosed.bind(_this);
120+
_this._saveCloseOffset = _this._saveCloseOffset.bind(_this);
121+
_this.on(OdoDialog.EventType.OPENED, _this._onOpened);
122+
_this.on(OdoDialog.EventType.CLOSED, _this._onClosed);
116123
return _this;
117124
}
118125

119-
ScrollToCloseDialog.prototype._onOpened = function _onOpened() {
126+
ScrollToCloseDialog.prototype._saveCloseOffset = function _saveCloseOffset() {
120127
var viewportHeight = window.innerHeight;
121128

122129
// The extra margin is on the inner element, so it's included in the height
123130
// of the content element.
124131
var contentHeight = this.element.scrollHeight - viewportHeight;
125132

126-
// Require the user to scroll the content + 7/8 of the extra space.
127-
this.closeOffset = contentHeight - Math.round(viewportHeight / 8);
133+
this.closeOffset = contentHeight - Math.round(viewportHeight / ScrollToCloseDialog.VIEWPORT_DIVISOR);
134+
};
128135

129-
// Listen for scrolls.
130-
this.element.addEventListener('scroll', this.onScroll);
136+
ScrollToCloseDialog.prototype._onOpened = function _onOpened() {
137+
this._saveCloseOffset();
138+
this.element.addEventListener('scroll', this._onScroll);
139+
window.addEventListener('resize', this._saveCloseOffset);
131140
};
132141

133142
ScrollToCloseDialog.prototype._onClosed = function _onClosed() {
134-
this.element.removeEventListener('scroll', this.onScroll);
143+
this.element.removeEventListener('scroll', this._onScroll);
144+
window.removeEventListener('resize', this._saveCloseOffset);
135145
};
136146

137-
ScrollToCloseDialog.prototype.onScroll = function onScroll() {
138-
var scrollTop = this.element.scrollTop;
139-
if (scrollTop > this.closeOffset) {
147+
ScrollToCloseDialog.prototype._onScroll = function _onScroll() {
148+
if (this.element.scrollTop > this.closeOffset) {
140149
this.close();
141150
}
142151
};
143152

153+
ScrollToCloseDialog.prototype.dispose = function dispose() {
154+
this.off(OdoDialog.EventType.OPENED, this._onOpened);
155+
this.off(OdoDialog.EventType.CLOSED, this._onClosed);
156+
_OdoDialog.prototype.dispose.call(this);
157+
};
158+
144159
return ScrollToCloseDialog;
145160
}(OdoDialog);
146161

162+
// Require the user to scroll the content + x-1/x of the extra space.
163+
164+
165+
ScrollToCloseDialog.VIEWPORT_DIVISOR = 6;
166+
147167
var scrollToClose = new ScrollToCloseDialog(document.getElementById('scroll-to-close'));
148168

149169
window.scrollToClose = scrollToClose;

packages/odo-dialog/coverage.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"lines":{"total":222,"covered":222},"statements":{"total":225,"covered":225},"functions":{"total":46,"covered":46},"branches":{"total":79,"covered":79},"coverage":100}
1+
{"lines":{"total":229,"covered":229},"statements":{"total":232,"covered":232},"functions":{"total":47,"covered":47},"branches":{"total":80,"covered":80},"coverage":100}

packages/odo-dialog/dist/odo-dialog.js

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

packages/odo-dialog/dist/odo-dialog.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/odo-dialog/dist/odo-dialog.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)