UNPKG

api-console-assets

Version:

This repo only exists to publish api console components to npm

189 lines (166 loc) 5.66 kB
<!-- @license Copyright 2017 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-input/paper-input.html"> <link rel="import" href="../paper-button/paper-button.html"> <link rel="import" href="../paper-icon-button/paper-icon-button.html"> <link rel="import" href="../iron-flex-layout/iron-flex-layout.html"> <link rel="import" href="../arc-icons/arc-icons.html"> <link rel="import" href="../paper-tooltip/paper-tooltip.html"> <link rel="import" href="../iron-collapse/iron-collapse.html"> <link rel="import" href="../marked-element/marked-element.html"> <link rel="import" href="../markdown-styles/markdown-styles.html"> <link rel="import" href="multipart-form-item-behavior.html"> <!-- A file form item. --> <dom-module id="multipart-file-form-item"> <template> <style include="markdown-styles"></style> <style> :host { display: block; @apply --layout-flex; } *[hidden] { display: none !important; } .file-row { margin: 8px 0; } .controls { @apply(--layout-horizontal); @apply(--layout-flex); @apply(--layout-center); } .controls > *:not(:last-child) { margin-right: 12px; } .file-trigger, .param-name { margin-right: 12px; } .file-trigger { color: var(--multipart-payload-editor-file-trigger-color, var(--accent-color, #FF5722)); } .param-value { @apply(--layout-flex); } .file-list-names { @apply(--layout-flex); } .files-counter-message { color: rgba(0, 0, 0, 0.74); @apply(--layout-flex); @apply(--arc-font-body1); } .files-list { @apply(--arc-font-body1); } .files-list span { margin-right: 8px; } .name-field { max-width: 360px; @apply(--layout-flex); } .error { color: #F44336; } .delete-icon { color: var(--inline-fom-action-icon-color, rgba(0, 0, 0, 0.74)); transition: color 0.2s linear; } .delete-icon:hover { color: var(--inline-fom-action-icon-color-hover, var(--accent-color, rgba(0, 0, 0, 0.74))); } </style> <div class="file-row"> <div class="controls"> <paper-input error-message="The name is required" label="Field name" required auto-validate value="{{name}}" class="name-field"></paper-input> <paper-button raised on-tap="_selectFile" class="file-trigger">Choose file</paper-button> <template is="dom-if" if="[[hasFile]]"> <span class="files-counter-message" hidden$="[[!hasFile]]">[[value.name]] ([[value.size]] bytes)</span> </template> <template is="dom-if" if="[[model.hasDescription]]"> <span> <paper-icon-button class="help-icon" suffix icon="arc:help" hidden$="[[!model.hasDescription]]" on-tap="toggleDocumentation"></paper-icon-button> <paper-tooltip position="left" offset="1" margin-top="1" animation-delay="300">Display documentation</paper-tooltip> </span> </template> </div> <template is="dom-if" if="[[model.hasDescription]]" restamp> <div class="docs"> <iron-collapse opened="[[docsOpened]]"> <marked-element markdown="[[model.description]]"> <div class="markdown-html markdown-body"></div> </marked-element> </iron-collapse> </div> </template> </div> <input type="file" hidden on-change="_fileObjectChanged" accept$="[[_computeAccept(model)]]"/> </template> <script> Polymer({ is: 'multipart-file-form-item', behaviors: [ArcBehaviors.MultipartFormItemBehavior], properties: { // Computed value, true if the control has a file. hasFile: { type: Boolean, computed: '_computeHasFile(value)' } }, _getValidity: function() { return !!(this.name && this.value instanceof Blob); }, _computeHasFile: function(value) { return !!(value && value instanceof Blob); }, /** * A handler to choose file button click. * This function will find a proper input[type="file"] and programatically click on it to open * file dialog. */ _selectFile: function() { var file = this.$$('input[type="file"]'); file.click(); }, /** * A handler to file change event for input[type="file"]. * This will update files array for corresponding `this.filesList` array object. */ _fileObjectChanged: function(e) { this.set('value', e.target.files[0]); }, /** * Computes the `accept`attribute for file input. */ _computeAccept: function(model) { if (!model) { return; } if (model.fileTypes && model.fileTypes.length && typeof model.fileTypes[0] === 'string') { return model.fileTypes.join(','); } if (model.fixedFacets) { if (model.fixedFacets.fileTypes && model.fixedFacets.fileTypes.length) { return model.fixedFacets.fileTypes.join(','); } } } }); </script> </dom-module>