api-console-assets
Version:
This repo only exists to publish api console components to npm
195 lines (178 loc) • 7.44 kB
HTML
<!--
@license
Copyright 2016 The Advanced REST client authors
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="docs-parameters-behavior.html">
<link rel="import" href="docs-parameters-table-shared-styles.html">
<link rel="import" href="docs-parameters-table-row.html">
<!--
`<docs-parameters-table>` A query and URI parameters list and description table for the RAML documentation view
This element renders a table of paramteres with the doccumentation. It can be used to display
URL parameters.
For headers documentation table pleae, use `<docs-headers-table>` element.
For types documentation table pleae, use `<docs-body-parameters-table>` element.
### Example
```
<docs-parameters-table
uri-parameters="[[uriParameters]]"
query-parameters="[[queryParameters]]"></docs-parameters-table>
```
### Object properties
An object in both arrays can contain any property that URI and query parameters can contain.
Currently following properties are supported:
- name (required) - name of the property, in case of UIR parameter it should be the parameter itself
- type - the type of the parameter, any RAML allowed value will be accepted
- description - description of the parameter
- required - mark that the property is a required property
- pattern - validation pattern to be applied to the parameter value
- example - example value of the parameter
- min - minimum value of the parametre when the type is numeric
- max - maximum value of the parametre when the type is numeric
- enum - List of possible values.
### Styling
`<docs-parameters-table>` provides the following custom properties and mixins for styling:
Custom property | Description | Default
----------------|-------------|----------
`--docs-parameters-table` | Mixin applied to all parameter table elements | `{}`
`--docs-parameters-url-table` | Mixin applied to this elements | `{}`
`--params-table-header-background-color` | Background color of table header | `#00A1DF`
`--params-table-header-color` | Font color of table header | `rgba(255, 255, 255, 0.87)`
`--params-table-subheader-background-color` | Background color of table subheader | `rgba(0, 161, 223, 0.24)`
`--params-table-subheader-color` | Font color of table subheader | `rgba(0, 0, 0, 0.87)`
`--params-table-row-border-color` | Border color of table's each row | `#00A1DF`
`--params-table-row-background-color` | Background color of table's each row | `#fff`
`--params-table-row-color` | Font color of table's each row | `#fff`
`--docs-parameters-table-cell` | Mixin applied to each cell | `{}`
`--docs-parameters-table-meta` | Mixin applied to property's metadata (example, pattern, etc) | `{}`
@group RAML Elements
@element docs-parameters-table
@demo demo/docs-parameters-table.html
@hero hero.svg
-->
<dom-module id="docs-parameters-table">
<template>
<style include="docs-parameters-table-shared-styles"></style>
<div class="params-table">
<div class="thead params-table-header">
<section class="tr">
<span class="th">Parameter</span>
<span class="th">Type</span>
<span class="th">Description</span>
</section>
</div>
<h5 class="narrow-title">Properties</h5>
<div class="tbody">
<template is="dom-if" if="[[hasUriParameteres]]">
<section class="tr params-table-header subheader path">
<div class="td subheader fullrow">Path parameters</div>
<div class="td subheader subheader-empty-cell"></div>
<div class="td subheader subheader-empty-cell"></div>
</section>
<template is="dom-repeat" items="[[displayUriParameters]]">
<docs-parameters-table-row class="tr uri-parameter" item="[[item]]"></docs-parameters-table-row>
</template>
</template>
<template is="dom-if" if="[[hasQueryParameteres]]">
<section class="tr params-table-header subheader query">
<div class="td subheader">Query parameters</div>
<div class="td subheader subheader-empty-cell"></div>
<div class="td subheader subheader-empty-cell"></div>
</section>
<template is="dom-repeat" items="[[displayQueryParameters]]">
<docs-parameters-table-row class="tr query-param" item="[[item]]"></docs-parameters-table-row>
</template>
</template>
</div>
</div>
</template>
<script>
Polymer({
is: 'docs-parameters-table',
behaviors: [RamlBehaviors.DocsParametersBehavior],
properties: {
/**
* The RAML's URI parameters object.
* See overview for object details.
*/
uriParameters: Object,
/**
* The RAML's query parameters object.
* See overview for object details.
*/
queryParameters: Object,
// True when `uriParameters` are present
hasUriParameteres: {
type: Boolean,
computed: '_computeHasUriParameteres(uriParameters.*)',
value: false,
notify: true
},
// True when `queryParameters` are present
hasQueryParameteres: {
type: Boolean,
computed: '_computeHasQueryParameteres(queryParameters.*)',
value: false,
notify: true
},
// True if it has either `uriParameteres` or `queryParameteres`
hasParameters: {
type: Boolean,
computed: '_computeHasParameteres(hasQueryParameteres, hasUriParameteres)',
value: false,
notify: true
},
// If set automatically hides the element which doesn't have parameteres set
autoHide: {
type: Boolean,
value: false
},
// Computed uriParameters array
displayUriParameters: {
type: Array,
computed: '_computeProperty(uriParameters)'
},
// Computed uriParameters array
displayQueryParameters: {
type: Array,
computed: '_computeProperty(queryParameters)'
}
},
observers: [
'_autoHide(autoHide, hasQueryParameteres, hasUriParameteres)'
],
_computeHasUriParameteres: function() {
return !!(this.uriParameters && Object.keys(this.uriParameters).length);
},
_computeHasQueryParameteres: function() {
return !!(this.queryParameters && Object.keys(this.queryParameters).length);
},
_autoHide: function(autoHide, hasQueryParameteres, hasUriParameteres) {
if (!autoHide) {
return;
}
var state = !(hasQueryParameteres || hasUriParameteres);
this.toggleAttribute('hidden', state);
},
_computeProperty: function(value) {
if (!value) {
return value;
}
return this.readProperties(value);
},
// Computes if any of arguments is trully
_computeHasParameteres: function(hasQueryParameteres, hasUriParameteres) {
return !!(hasQueryParameteres || hasUriParameteres);
}
});
</script>
</dom-module>