blob: 9c64986a98bb10b7776df50109298fa97b7678b5 [file] [log] [blame]
Einav Weiss Keidar1801b242018-08-13 16:19:46 +03001/*
2 * Copyright © 2016-2018 European Support Limited
AviZi280f8012017-06-09 02:39:56 +03003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
Einav Weiss Keidar1801b242018-08-13 16:19:46 +03008 * http://www.apache.org/licenses/LICENSE-2.0
AviZi280f8012017-06-09 02:39:56 +03009 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
AviZi280f8012017-06-09 02:39:56 +030015 */
Michael Landoefa037d2017-02-19 12:57:33 +020016/**
17 * Holds the buttons for save/reset for forms.
18 * Used by the ValidationForm that changes the state of the buttons according to its own state.
19 *
20 * properties:
21 * labledButtons - whether or not to use labeled buttons or icons only
22 */
23import React from 'react';
talig8e9c0652017-12-20 14:30:43 +020024import PropTypes from 'prop-types';
Michael Landoefa037d2017-02-19 12:57:33 +020025import i18n from 'nfvo-utils/i18n/i18n.js';
Arielka51eac02019-07-07 12:56:11 +030026import { Button, SVGIcon } from 'onap-ui-react';
Michael Landoefa037d2017-02-19 12:57:33 +020027
28class ValidationButtons extends React.Component {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020029 static propTypes = {
30 labledButtons: PropTypes.bool.isRequired,
31 isReadOnlyMode: PropTypes.bool,
32 submitButtonText: PropTypes.string,
33 cancelButtonText: PropTypes.string
34 };
Michael Landoefa037d2017-02-19 12:57:33 +020035
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020036 state = {
37 isValid: this.props.formValid
38 };
Michael Landoefa037d2017-02-19 12:57:33 +020039
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020040 render() {
41 let submitBtn = this.props.labledButtons ? (
42 this.props.submitButtonText ? (
43 this.props.submitButtonText
44 ) : (
45 i18n('Save')
46 )
47 ) : (
48 <SVGIcon className="check" name="check" />
49 );
50 let closeBtn = this.props.labledButtons ? (
51 this.props.cancelButtonText ? (
52 this.props.cancelButtonText
53 ) : (
54 i18n('Cancel')
55 )
56 ) : (
57 <SVGIcon className="close" name="close" />
58 );
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030059 let className = 'validation-buttons';
60 if (this.props.className) {
61 className += ' ' + this.props.className;
62 }
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020063 return (
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030064 <div className={className}>
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020065 {!this.props.isReadOnlyMode ? (
66 <div>
67 <Button
68 type="submit"
svishnev04783c42018-04-17 11:32:22 +030069 btnType="primary"
svishnev65533392018-04-23 10:10:51 +030070 size="default"
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020071 data-test-id="form-submit-button"
72 disabled={!this.state.isValid}>
73 {submitBtn}
74 </Button>
75 <Button
svishnev04783c42018-04-17 11:32:22 +030076 btnType="secondary"
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020077 type="reset"
78 data-test-id="form-close-button">
79 {closeBtn}
80 </Button>
81 </div>
82 ) : (
83 <Button
svishnev04783c42018-04-17 11:32:22 +030084 btnType="primary"
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020085 type="reset"
86 data-test-id="form-close-button">
87 {i18n('Close')}
88 </Button>
89 )}
90 </div>
91 );
92 }
Michael Landoefa037d2017-02-19 12:57:33 +020093}
94export default ValidationButtons;