From d5ed31be3b6c97f92be4e94b70d32d1b89932ae9 Mon Sep 17 00:00:00 2001 From: Emiliano Ciavatta Date: Wed, 30 Sep 2020 15:58:16 +0200 Subject: Complete services page --- frontend/src/components/fields/InputField.js | 3 +- .../src/components/fields/extensions/ColorField.js | 34 +++++++++++++----- .../components/fields/extensions/ColorField.scss | 42 +++++++++++++--------- 3 files changed, 53 insertions(+), 26 deletions(-) (limited to 'frontend/src/components/fields') diff --git a/frontend/src/components/fields/InputField.js b/frontend/src/components/fields/InputField.js index b790891..84c981b 100644 --- a/frontend/src/components/fields/InputField.js +++ b/frontend/src/components/fields/InputField.js @@ -55,7 +55,8 @@ class InputField extends Component { { type === "file" && } + aria-describedby={this.id} onChange={handler} {...inputProps} + readOnly={this.props.readonly} /> { type !== "file" && value !== "" &&
diff --git a/frontend/src/components/fields/extensions/ColorField.js b/frontend/src/components/fields/extensions/ColorField.js index c1c210f..96ebc49 100644 --- a/frontend/src/components/fields/extensions/ColorField.js +++ b/frontend/src/components/fields/extensions/ColorField.js @@ -2,6 +2,7 @@ import React, {Component} from 'react'; import {OverlayTrigger, Popover} from "react-bootstrap"; import './ColorField.scss'; import InputField from "../InputField"; +import validation from "../../../validation"; class ColorField extends Component { @@ -15,11 +16,24 @@ class ColorField extends Component { "#00897B", "#43A047", "#7CB342", "#9E9D24", "#F9A825", "#FB8C00", "#F4511E", "#6D4C41"]; } + componentDidUpdate(prevProps, prevState, snapshot) { + if (prevProps.value !== this.props.value) { + this.onChange(this.props.value); + } + } + + onChange = (value) => { + this.setState({invalid: value !== "" && !validation.isValidColor(value)}); + + if (typeof this.props.onChange === "function") { + this.props.onChange(value); + } + }; + render() { const colorButtons = this.colors.map((color) => { - this.setState({color: color}); if (typeof this.props.onChange === "function") { this.props.onChange(color); } @@ -43,18 +57,22 @@ class ColorField extends Component { ); let buttonStyles = {}; - if (this.state.color) { - buttonStyles["backgroundColor"] = this.state.color; + if (this.props.value) { + buttonStyles["backgroundColor"] = this.props.value; } return (
- -
- - - +
+ +
+ + + +
+ {this.props.error &&
{this.props.error}
}
); } diff --git a/frontend/src/components/fields/extensions/ColorField.scss b/frontend/src/components/fields/extensions/ColorField.scss index 1c3931f..6eabbda 100644 --- a/frontend/src/components/fields/extensions/ColorField.scss +++ b/frontend/src/components/fields/extensions/ColorField.scss @@ -1,29 +1,37 @@ @import '../../../colors.scss'; .color-field { - display: flex; - align-items: flex-end; + .color-input { + display: flex; + align-items: flex-end; - .input-field { - flex: 1; + .input-field { + flex: 1; - input { - border-bottom-right-radius: 0 !important; - border-top-right-radius: 0 !important; + input { + border-bottom-right-radius: 0 !important; + border-top-right-radius: 0 !important; + } } - } - .color-picker { - margin-bottom: 5.5px; + .color-picker { + margin-bottom: 5px; - .picker-button { - font-size: 0.8em; - padding: 8px 15px; - border-bottom-right-radius: 5px; - border-top-right-radius: 5px; - background-color: $color-primary-1; + .picker-button { + font-size: 0.8em; + padding: 8px 15px; + border-bottom-right-radius: 5px; + border-top-right-radius: 5px; + background-color: $color-primary-1; + } } } + + .color-error { + font-size: 0.8em; + color: $color-secondary-0; + margin-left: 10px; + } } .colors-container { @@ -35,4 +43,4 @@ height: 31px; cursor: pointer; } -} \ No newline at end of file +} -- cgit v1.2.3-70-g09d2