ExamplesPlaygroundReference Source

coral-spectrum/coral-component-shell/src/scripts/ShellWorkspace.js

  1. /**
  2. * Copyright 2019 Adobe. All rights reserved.
  3. * This file is licensed to you under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License. You may obtain a copy
  5. * of the License at http://www.apache.org/licenses/LICENSE-2.0
  6. *
  7. * Unless required by applicable law or agreed to in writing, software distributed under
  8. * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
  9. * OF ANY KIND, either express or implied. See the License for the specific language
  10. * governing permissions and limitations under the License.
  11. */
  12.  
  13. import {BaseComponent} from '../../../coral-base-component';
  14. import {transform} from '../../../coral-utils';
  15.  
  16. const CLASSNAME = '_coral-Shell-workspaces-workspace';
  17.  
  18. /**
  19. @class Coral.Shell.Workspace
  20. @classdesc A Shell Workspace component
  21. @htmltag coral-shell-workspace
  22. @htmlbasetag a
  23. @extends {HTMLAnchorElement}
  24. @extends {BaseComponent}
  25. */
  26. class ShellWorkspace extends BaseComponent(HTMLAnchorElement) {
  27. /** @ignore */
  28. constructor() {
  29. super();
  30.  
  31. // Events
  32. this._delegateEvents({
  33. click: '_onClick'
  34. });
  35. }
  36.  
  37. /**
  38. Whether this workspace is selected.
  39.  
  40. @type {Boolean}
  41. @default false
  42. @htmlattribute selected
  43. @htmlattributereflected
  44. */
  45. get selected() {
  46. return this._selected || false;
  47. }
  48.  
  49. set selected(value) {
  50. this._selected = transform.booleanAttr(value);
  51. this._reflectAttribute('selected', this._selected);
  52.  
  53. this.setAttribute('aria-selected', this._selected);
  54. this.classList.toggle('is-selected', this._selected);
  55.  
  56. this.trigger('coral-shell-workspace:_selectedchanged');
  57. }
  58.  
  59. /** @private */
  60. _onClick() {
  61. if (!this.selected) {
  62. this.selected = true;
  63. }
  64. }
  65.  
  66. /** @ignore */
  67. static get observedAttributes() {
  68. return super.observedAttributes.concat(['selected']);
  69. }
  70.  
  71. /** @ignore */
  72. render() {
  73. super.render();
  74.  
  75. this.classList.add(CLASSNAME);
  76. }
  77.  
  78. /**
  79. Triggered when a {@link ShellWorkspace} selection changed.
  80.  
  81. @typedef {CustomEvent} coral-shell-workspace:_selectedchanged
  82.  
  83. @private
  84. */
  85. }
  86.  
  87. export default ShellWorkspace;