UNPKG

api-console-assets

Version:

This repo only exists to publish api console components to npm

197 lines (180 loc) 7.55 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="../paper-styles/paper-styles.html"> <link rel="import" href="../iron-flex-layout/iron-flex-layout.html"> <link rel="import" href="../paper-item/paper-item.html"> <link rel="import" href="../paper-menu/paper-menu.html"> <link rel="import" href="../marked-element/marked-element.html"> <link rel="import" href="../markdown-styles/markdown-styles.html"> <link rel="import" href="../docs-parameters-table/docs-body-parameters-table.html"> <link rel="import" href="../docs-parameters-table/docs-headers-table.html"> <link rel="import" href="raml-docs-response-status-selector.html"> <!-- `<raml-docs-response-panel>` Element that displays response documentation for RAML This element is used in `<raml-docs-method-viewer>` element. See it's demo for demo. ### Example ``` <raml-docs-response-panel responses="[[raml.responses]]"></raml-docs-response-panel> ``` The `raml.responses` is a list of responses for current method. It can be obtained using a `raml-path-to-object` element or by passing method Definition from RAML's JSON structure. Note, you have to use ARC's `<raml-js-parser>` since it is also responsoble for transformind parser JSON output to internal data structure. ## Element's width and overflow The code blocks generated by the element can be wide. This is why this element has the CSS `overflow` property set to `auto` by default. In this case you can set the `max-width` or `width` propety on this element (or any parent element) and it will be respected. ### Styling `<raml-docs-response-panel>` provides the following custom properties and mixins for styling: Custom property | Description | Default ----------------|-------------|---------- `--raml-docs-response-panel` | Mixin applied to the element | `{}` `--arc-status-code-color-200` | Color of the 200 status code (ARC theme option) | `rgba(56, 142, 60, 1)` | `--arc-status-code-color-300` | Color of the 300 status code (ARC theme option) | `rgba(48, 63, 159, 1)` | `--arc-status-code-color-400` | Color of the 400 status code (ARC theme option) | `rgba(245, 124, 0, 1)` | `--arc-status-code-color-500` | Color of the 500 status code (ARC theme option) | `rgba(211, 47, 47, 1)` | `--arc-status-code-bgcolor-200` | Background color of the 200 status code | `rgba(56, 142, 60, 0.12)` | `--arc-status-code-bgcolor-300` | Background color of the 300 status code | `rgba(48, 63, 159, 0.12)` | `--arc-status-code-bgcolor-400` | Background color of the 400 status code | `rgba(245, 124, 0, 0.12)` | `--arc-status-code-bgcolor-500` | Background color of the 500 status code | `rgba(211, 47, 47, 0.12)` | `--raml-docs-response-panel-codes-border-color` | Border color of the response codes column | `rgba(0, 161, 223, 0.24)` `--no-info-message` | A mixin applied to the "missing type" paragraph. | `{}` | `--raml-docs-response-panel-container` | A mixin applied to the element's main container | `{}` `--raml-docs-response-panel-codes-content` | A mixin applied to the element's status codes container | `{}` `--raml-docs-response-panel-docs-content` | A mixin applied to the element's documentation content container | `{}` @group RAML Elements @element raml-docs-response-panel @demo demo/index.html --> <dom-module id="raml-docs-response-panel"> <template> <style include="markdown-styles"></style> <style> :host { display: block; @apply(--raml-docs-response-panel); } h4 { @apply(--raml-docs-response-panel-headers-title); } .container { @apply(--layout-horizontal); @apply(--raml-docs-response-panel-container); } .docs { @apply(--layout-flex); @apply(--paper-font-body1); margin-left: 16px; overflow: auto; @apply(--raml-docs-response-panel-docs-content); } .no-data-info { @apply(--no-info-message); } </style> <div class="container"> <raml-docs-response-status-selector responses="[[responses]]" selected-response="{{selectedResponse}}" selected="{{selected}}"></raml-docs-response-status-selector> <div class="docs"> <section> <template is="dom-if" if="[[selectedResponse.description]]"> <marked-element markdown="[[selectedResponse.description]]"> <div class="markdown-html"></div> </marked-element> </template> <p class="no-data-info" hidden$="[[hasProperties]]">No description provided.</p> <template is="dom-if" if="[[_hasProperty(selectedResponse, 'headers')]]"> <h4 class="sub-title">Response headers</h4> <docs-headers-table headers="[[selectedResponse.headers]]"></docs-headers-table> </template> <template is="dom-if" if="[[_hasProperty(selectedResponse, 'body')]]"> <docs-body-parameters-table body="[[selectedResponse.body]]"></docs-body-parameters-table> </template> </section> </div> </div> </template> <script> Polymer({ is: 'raml-docs-response-panel', properties: { // List of responses - RAML definition (JSON) responses: Array, // Computed value if currently panel has anything to display hasResponses: { type: Boolean, notify: true, readOnly: true, value: false, computed: '_computeHasResponses(responses)' }, /** * Computed value, true if selected response has description or * body declaration. * It is used to display empty data message if none of this properties * are set. */ hasProperties: { type: Boolean, computed: '_computeHasProperties(selectedResponse)' }, /** * Selected response's index. * This will be set to default (0, zero) value when `responses` * array change. */ selected: Number }, // Computes `hasResponses` property. _computeHasResponses: function(responses) { // var responses = record && record.base; return !!(responses && responses.length); }, /** * Checks if given `obj` has a `property`. * * @param {Object} obj Object to check * @param {String} property Property name of the object * @return {Boolean} True if the `obj` contains a `property`. */ _hasProperty: function(obj, property) { if (!obj) { return false; } return property in obj; }, /** * Computes `hasProperties` value. * * @param {Object} response Currently selected response. * @return {Boolean} True if the response has description or body. */ _computeHasProperties: function(response) { if (!response) { return false; } if (response.description) { return true; } if (response.body && response.body.length) { return true; } return false; } }); </script> </dom-module>