Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | 2x 2x 2x 2x 4x 2x 2x 2x 104x 104x 104x 104x 104x 104x 2x 2x 96x 96x 96x 44x 96x 70x 96x 96x 96x 96x 96x 96x 132x 132x 52x 80x 96x 96x 10x 2x 2x 2x 2x 6x 96x 96x 6x 100x 100x 100x 100x 100x 8x 108x 108x 108x 108x 108x 108x 108x 12x 12x 12x 6x 12x 12x 12x 6x 12x 12x 96x 96x 70x 880x | /**
* Copyright 2019 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import {BaseComponent} from '../../../coral-base-component';
import '../../../coral-component-button';
import base from '../templates/base';
import {commons, transform, validate, i18n} from '../../../coral-utils';
import {Decorator} from '../../../coral-decorator';
/**
Enumeration for {@link Drawer} directions.
@typedef {Object} DrawerDirectionEnum
@property {String} DOWN
A drawer with a toggle button on the bottom.
@property {String} UP
A drawer with a toggle button on top.
*/
const direction = {
DOWN: 'down',
UP: 'up'
};
// The drawer's base classname
const CLASSNAME = '_coral-Drawer';
// A string of all possible direction classnames
const ALL_DIRECTION_CLASSES = [];
for (const directionValue in direction) {
ALL_DIRECTION_CLASSES.push(`${CLASSNAME}--${direction[directionValue]}`);
}
/**
@class Coral.Drawer
@classdesc A Drawer component to display content that can be opened and closed with a sliding animation.
@htmltag coral-drawer
@extends {HTMLElement}
@extends {BaseComponent}
*/
const Drawer = Decorator(class extends BaseComponent(HTMLElement) {
/** @ignore */
constructor() {
super();
// Templates
this._elements = {
content: this.querySelector('coral-drawer-content') || document.createElement('coral-drawer-content')
};
base.call(this._elements, {commons, i18n});
// Events
this._delegateEvents({
'click ._coral-Drawer-toggleButton': '_onClick'
});
}
/**
Whether this item is disabled or not. This will stop every user interaction with the item.
@type {Boolean}
@default false
@htmlattribute disabled
@htmlattributereflected
*/
get disabled() {
return this._disabled || false;
}
set disabled(value) {
this._disabled = transform.booleanAttr(value);
this._reflectAttribute('disabled', this._disabled);
this[this._disabled ? 'setAttribute' : 'removeAttribute']('aria-disabled', this._disabled);
this._elements.toggle.hidden = this._disabled;
}
/**
The drawer's content element.
@type {DrawerContent}
@htmlttribute content
@contentzone
*/
get content() {
return this._getContentZone(this._elements.content);
}
set content(value) {
this._setContentZone('content', value, {
handle: 'content',
tagName: 'coral-drawer-content',
insert: function (content) {
this._elements.contentWrapper.appendChild(content);
}
});
}
/**
The drawer's direction. See {@link DrawerDirectionEnum}.
@type {String}
@default DrawerDirectionEnum.DOWN
@htmlattribute direction
@htmlattributereflected
*/
get direction() {
return this._direction || direction.DOWN;
}
set direction(value) {
value = transform.string(value).toLowerCase();
this._direction = validate.enumeration(direction)(value) && value || direction.DOWN;
this._reflectAttribute('direction', this._direction);
this.classList.remove(...ALL_DIRECTION_CLASSES);
this.classList.add(`${CLASSNAME}--${this._direction}`);
}
/**
Whether the Drawer is expanded or not.
@type {Boolean}
@default false
@htmlattribute open
@htmlattributereflected
*/
get open() {
return this._open || false;
}
set open(value) {
const silenced = this._silenced;
this._open = transform.booleanAttr(value);
this._reflectAttribute('open', this._open);
this._elements.toggleButton.setAttribute('aria-expanded', this._open);
// eslint-disable-next-line no-unused-vars
let offsetHeight;
// Handle slider animation
const slider = this._elements.slider;
// Don't animate on initialization
if (this._animate) {
commons.transitionEnd(slider, () => {
// Keep it silenced
this._silenced = silenced;
// Remove height as we want the drawer to naturally grow if content is added later
if (this._open) {
slider.style.height = '';
}
// Trigger once transition is finished
this.trigger(`coral-drawer:${(this._open ? 'open' : 'close')}`);
this._silenced = false;
});
if (!this._open) {
// Force height to enable transition
slider.style.height = `${slider.scrollHeight}px`;
}
// Do transition in next task as browser might batch up the height property change before painting
window.setTimeout(() => {
slider.style.height = this._open ? `${slider.scrollHeight}px` : 0;
}, 10);
} else {
// Make sure it's animated next time
this._animate = true;
// Hide it on initialization if closed
if (!this._open) {
slider.style.height = 0;
}
}
}
/** @private */
_onClick() {
this.open = !this.open;
}
get _contentZones() {
return {'coral-drawer-content': 'content'};
}
/**
Returns {@link Drawer} direction options.
@return {DrawerDirectionEnum}
*/
static get direction() {
return direction;
}
/** @ignore */
static get observedAttributes() {
return super.observedAttributes.concat([
'disabled',
'direction',
'open'
]);
}
/** @ignore */
render() {
super.render();
this.classList.add(CLASSNAME, 'coral-Well');
// Default reflected attributes
if (!this._direction) {
this.direction = direction.DOWN;
}
if (!this._open) {
this.open = false;
}
// Create a fragment
const fragment = document.createDocumentFragment();
const templateHandleNames = ['slider', 'toggle'];
// Render the template
fragment.appendChild(this._elements.slider);
fragment.appendChild(this._elements.toggle);
// Fetch or create the content content zone element
const content = this._elements.content;
// Move any remaining elements into the content sub-component
while (this.firstChild) {
const child = this.firstChild;
if (child.nodeType === Node.TEXT_NODE ||
child.nodeType === Node.ELEMENT_NODE && templateHandleNames.indexOf(child.getAttribute('handle')) === -1) {
// Add non-template elements to the label
content.appendChild(child);
} else {
// Remove anything else
this.removeChild(child);
}
}
// Add the frag to the component
this.appendChild(fragment);
// Assign the content zone
this.content = content;
}
/**
Triggered when the {@link Drawer} is opened.
@typedef {CustomEvent} coral-drawer:open
*/
/**
Triggered when the {@link Drawer} is closed.
@typedef {CustomEvent} coral-drawer:close
*/
});
export default Drawer;
|