File : controls/textAreaControl/TextAreaControl.js

1
/*
2
Copyright - 2017 2023 - wwwouaiebe - Contact: https://www.ouaie.be/
3
4
This  program is free software;
5
you can redistribute it and/or modify it under the terms of the
6
GNU General Public License as published by the Free Software Foundation;
7
either version 3 of the License, or any later version.
8
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
*/
18
/*
19
Changes:
20
    - v4.0.0:
21
        - created from v3.6.0
22
Doc reviewed 202208
23
 */
24
25
import theHTMLElementsFactory from '../../core/uiLib/HTMLElementsFactory.js';
26
import BaseControl from '../baseControl/BaseControl.js';
27
import { TWO } from '../../main/Constants.js';
28
29
/* ------------------------------------------------------------------------------------------------------------------------- */
30
/**
31
This class is a generic control with a header text and a text area
32
*/
33
/* ------------------------------------------------------------------------------------------------------------------------- */
34
35
class TextAreaControl extends BaseControl {
36
37
    /**
38
    The text area
39
    @type {HTMLElement}
40
    */
41
42
    #textArea;
43
44
    /**
45
    The constructor
46
    @param {Object} options An object with the  options ( placeholder, rows, datasetName, headerText )
47
    @param {Object} eventListeners A reference to the eventListeners object of the dialog
48
    */
49
50
    constructor ( options, eventListeners ) {
51
52
        super ( );
53
54
        // HTMLElements creation
55
        theHTMLElementsFactory.create (
56
            'div',
57
            {
58
                textContent : options?.headerText || '',
59
                className : 'TravelNotes-BaseDialog-FlexRow'
60
            },
61
            this.controlHTMLElement
62
        );
63
        this.#textArea = theHTMLElementsFactory.create (
64
            'textarea',
65
            {
66
                className : 'TravelNotes-TextAreaControl-TextArea',
67
                placeholder : options?.placeholder || '',
68
                rows : options.rows || TWO,
69
                dataset : { Name : options?.datasetName || 'TextAreaControl' }
70
            },
71
            theHTMLElementsFactory.create (
72
                'div',
73
                {
74
                    className : 'TravelNotes-BaseDialog-FlexRow'
75
                },
76
                this.controlHTMLElement
77
            )
78
        );
79
80
        // event listeners
81
        if ( eventListeners.controlFocus ) {
82
            this.#textArea.addEventListener ( 'focus', eventListeners.controlFocus );
83
        }
84
        if ( eventListeners.controlInput ) {
85
            this.#textArea.addEventListener ( 'input', eventListeners.controlInput );
86
        }
87
    }
88
89
    /**
90
    Remove event listeners
91
    @param {NoteDialogEventListeners} eventListeners A reference to the eventListeners object of the dialog
92
    */
93
94
    destructor ( eventListeners ) {
95
        if ( eventListeners.controlFocus ) {
96
            this.#textArea.removeEventListener ( 'focus', eventListeners.controlFocus );
97
        }
98
        if ( eventListeners.controlInput ) {
99
            this.#textArea.removeEventListener ( 'input', eventListeners.controlInput );
100
        }
101
    }
102
103
    /**
104
    The icon value in the control
105
    @type {String}
106
    */
107
108
    get value ( ) { return this.#textArea.value; }
109
110
    set value ( value ) { this.#textArea.value = value; }
111
112
}
113
114
export default TextAreaControl;
115
116
/* --- End of file --------------------------------------------------------------------------------------------------------- */
117