2023-03-15 16:00:52 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
import Component from '@ember/component';
|
2018-06-14 18:52:00 +00:00
|
|
|
import autosize from 'autosize';
|
2019-06-21 21:05:45 +00:00
|
|
|
import layout from '../templates/components/masked-input';
|
2018-06-14 18:52:00 +00:00
|
|
|
|
2019-04-05 21:58:55 +00:00
|
|
|
/**
|
|
|
|
* @module MaskedInput
|
|
|
|
* `MaskedInput` components are textarea inputs where the input is hidden. They are used to enter sensitive information like passwords.
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* <MaskedInput
|
|
|
|
* @value={{attr.options.defaultValue}}
|
|
|
|
* @allowCopy={{true}}
|
2019-04-15 22:53:44 +00:00
|
|
|
* @onChange={{action "someAction"}}
|
2021-08-24 14:59:37 +00:00
|
|
|
* @onKeyUp={{action "onKeyUp"}}
|
2019-04-05 21:58:55 +00:00
|
|
|
* />
|
|
|
|
*
|
|
|
|
* @param [value] {String} - The value to display in the input.
|
|
|
|
* @param [allowCopy=null] {bool} - Whether or not the input should render with a copy button.
|
|
|
|
* @param [displayOnly=false] {bool} - Whether or not to display the value as a display only `pre` element or as an input.
|
2019-04-15 22:53:44 +00:00
|
|
|
* @param [onChange=Function.prototype] {Function|action} - A function to call when the value of the input changes.
|
2021-08-24 14:59:37 +00:00
|
|
|
* @param [onKeyUp=Function.prototype] {Function|action} - A function to call whenever on the dom event onkeyup. Generally passed down from higher level parent.
|
2021-04-22 14:58:37 +00:00
|
|
|
* @param [isCertificate=false] {bool} - If certificate display the label and icons differently.
|
2019-04-05 21:58:55 +00:00
|
|
|
*
|
|
|
|
*/
|
2018-09-25 16:28:26 +00:00
|
|
|
export default Component.extend({
|
2019-06-21 21:05:45 +00:00
|
|
|
layout,
|
2018-09-25 16:28:26 +00:00
|
|
|
value: null,
|
2021-04-22 14:58:37 +00:00
|
|
|
showValue: false,
|
2018-09-25 16:28:26 +00:00
|
|
|
didInsertElement() {
|
|
|
|
this._super(...arguments);
|
|
|
|
autosize(this.element.querySelector('textarea'));
|
|
|
|
},
|
|
|
|
didUpdate() {
|
|
|
|
this._super(...arguments);
|
|
|
|
autosize.update(this.element.querySelector('textarea'));
|
|
|
|
},
|
|
|
|
willDestroyElement() {
|
|
|
|
this._super(...arguments);
|
|
|
|
autosize.destroy(this.element.querySelector('textarea'));
|
|
|
|
},
|
|
|
|
displayOnly: false,
|
|
|
|
onKeyDown() {},
|
2021-08-24 14:59:37 +00:00
|
|
|
onKeyUp() {},
|
2018-09-25 16:28:26 +00:00
|
|
|
onChange() {},
|
|
|
|
actions: {
|
|
|
|
toggleMask() {
|
2021-04-22 14:58:37 +00:00
|
|
|
this.toggleProperty('showValue');
|
2018-09-25 16:28:26 +00:00
|
|
|
},
|
|
|
|
updateValue(e) {
|
2022-11-09 23:15:31 +00:00
|
|
|
const value = e.target.value;
|
2019-04-15 22:53:44 +00:00
|
|
|
this.set('value', value);
|
|
|
|
this.onChange(value);
|
2018-09-25 16:28:26 +00:00
|
|
|
},
|
2021-08-24 14:59:37 +00:00
|
|
|
handleKeyUp(name, value) {
|
2022-03-22 19:43:43 +00:00
|
|
|
if (this.onKeyUp) {
|
|
|
|
this.onKeyUp(name, value);
|
|
|
|
}
|
2021-08-24 14:59:37 +00:00
|
|
|
},
|
2018-09-25 16:28:26 +00:00
|
|
|
},
|
2018-06-14 18:52:00 +00:00
|
|
|
});
|