UNPKG

api-console-assets

Version:

This repo only exists to publish api console components to npm

161 lines (145 loc) 4.86 kB
<!-- @license Copyright 2016 The Advanced REST client authors <arc@mulesoft.com> Licensed 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 CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <link rel="import" href="../polymer/polymer.html"> <link rel="import" href="../marked-element/marked-element.html"> <link rel="import" href="../markdown-styles/markdown-styles.html"> <link rel="import" href="../iron-media-query/iron-media-query.html"> <!-- `<raml-docs-documentation-viewer>` A viewer of the documentation node of the RAML definition ### Example ``` <raml-docs-documentation-viewer documentation="[[doc]]"></raml-docs-documentation-viewer> ``` ### Styling `<raml-docs-documentation-viewer>` provides the following custom properties and mixins for styling: Custom property | Description | Default ----------------|-------------|---------- `--raml-docs-documentation-viewer` | Mixin applied to the element | `{}` `--raml-docs-documentation-viewer-code` | Mixin applied to the parsed and highlighted code container for markup. Note that this container has `markdown-styles` applied. | `{}` A `markdown-styles` element is responsible for styling parsing content. @group RAML Elements @element raml-docs-documentation-viewer @demo demo/index.html --> <dom-module id="raml-docs-documentation-viewer"> <template> <style include="markdown-styles"></style> <style> :host { display: block; margin: 24px 0; @apply(--raml-docs-documentation-viewer); } :host([hidden]) { display: none !important; } :host([narrow]) .markdown-html { max-width: calc(100vw - 32px); overflow: auto; } .markdown-html { @apply(--raml-docs-documentation-viewer-code); } </style> <iron-media-query query="(max-width: [[narrowWidth]])" query-matches="{{narrow}}"></iron-media-query> <div id="preview"> <marked-element markdown="[[documentation.content]]"> <div class="markdown-html"></div> </marked-element> </div> </template> <script> Polymer({ is: 'raml-docs-documentation-viewer', properties: { // Represent a single documentation object from RAML's documentation node. documentation: Object, /** * If true then the element will start listen for the * `raml-is-documentation-changed` and `raml-selected-object-changed` * events and sets corresponding properties when needed. It's * a replacement for the Polymer's data biding for apps that are * not Polymer powered. */ autoHide: { type: Boolean, value: false, observer: '_autoHideChanged' }, // If true then the element will be hidden ui the UI. hidden: { type: Boolean, value: false, reflectToAttribute: true }, /** * If set it will renders the view in the narrow layout. */ narrow: { type: Boolean, notify: true, reflectToAttribute: true }, // A widith below which the `narrow` property will be set to true. narrowWidth: { type: String, value: '768px' } }, attached: function() { this._eventTarget = Polymer.dom(this).host || document; if (this.autoHide) { this._attacheListeners(); } }, _autoHideChanged: function(state) { if (state) { this._attacheListeners(); } else { this._detachListeners(); } }, _attacheListeners: function() { if (!this._eventTarget) { return; } this._detachListeners(); this.listen(this._eventTarget, 'raml-is-documentation-changed', '_isDocHandler'); this.listen(this._eventTarget, 'raml-selected-object-changed', '_selectedChangeHandler'); }, _detachListeners: function() { if (!this._eventTarget) { return; } this.unlisten(this._eventTarget, 'raml-is-documentation-changed', '_isDocHandler'); this.unlisten(this._eventTarget, 'raml-selected-object-changed', '_selectedChangeHandler'); }, _isDocHandler: function(e, detail) { var state = detail.state; this.hidden = !state; }, _selectedChangeHandler: function(e, detail) { if (this.hidden) { this.documentation = undefined; return; } this.documentation = detail.selectedObject; } }); </script> </dom-module>