diff --git a/src/components/HotspotEditorModal/HotspotTextStyleTab/HotspotTextStyleTab.jsx b/src/components/HotspotEditorModal/HotspotTextStyleTab/HotspotTextStyleTab.jsx index fcfa2bddb4..08aab8a79d 100644 --- a/src/components/HotspotEditorModal/HotspotTextStyleTab/HotspotTextStyleTab.jsx +++ b/src/components/HotspotEditorModal/HotspotTextStyleTab/HotspotTextStyleTab.jsx @@ -1,4 +1,4 @@ -import React, { useRef } from 'react'; +import React from 'react'; import PropTypes from 'prop-types'; import merge from 'lodash/merge'; import { NumberInput } from 'carbon-components-react'; @@ -20,7 +20,13 @@ const colorPropType = PropTypes.shape({ }); const propTypes = { + /** + * Specify an optional className to be applied to the container node + */ + className: PropTypes.string, + /** True if the light theme is to be used, defaults to true */ light: PropTypes.bool, + /** set of internationalized labels */ i18n: PropTypes.shape({ boldLabel: PropTypes.string, italicLabel: PropTypes.string, @@ -37,7 +43,7 @@ const propTypes = { }), /** Callback for when any of the form element's value changes */ onChange: PropTypes.func.isRequired, - /** The state values of the controlled form elements e.g. { title: 'My hotspot 1', description: 'Lorem ipsum' } */ + /** The state values of the controlled form elements, see defaults for shape */ formValues: PropTypes.objectOf( PropTypes.oneOfType([ PropTypes.string, @@ -46,47 +52,63 @@ const propTypes = { colorPropType, ]) ), + /** Array of colors to be shown for the font colors dropdown */ fontColors: PropTypes.arrayOf(colorPropType), + /** Array of colors to be shown for the background colors dropdown */ backgroundColors: PropTypes.arrayOf(colorPropType), + /** Array of colors to be shown for the border colors dropdown */ borderColors: PropTypes.arrayOf(colorPropType), + /** Minimum Font size */ + minFontSize: PropTypes.number, + /** Maximum Font size */ + maxFontSize: PropTypes.number, + /** Minimum Opacity Value */ + minOpacity: PropTypes.number, + /** Maximum Opacity Value */ + maxOpacity: PropTypes.number, + /** Minimum Border Width */ + minBorderWidth: PropTypes.number, + /** Maximum Border Width */ + maxBorderWidth: PropTypes.number, }; const defaultProps = { + className: '', light: true, i18n: { - boldLabel: 'Text Bold', - italicLabel: 'Text Italic', - underlineLabel: 'Text Underline', - fontLabel: 'Font', - fontSizeLabel: 'Font Size', - fontSizeInvalid: 'Font Size is invalid', - backgroundLabel: 'Background', - fillOpacityLabel: 'Fill Opacity', - fillOpacityInvalid: 'Fill Opacity is invalid', - borderLabel: 'Border', - borderWidthLabel: 'Border Width', - borderWidthInvalid: 'Border Width is invalid', + boldLabelText: 'Text Bold', + italicLabelText: 'Text Italic', + underlineLabelText: 'Text Underline', + fontLabelText: 'Font', + fontSizeLabelText: 'Font Size', + fontSizeInvalidText: 'Font Size is invalid', + backgroundLabelText: 'Background', + fillOpacityLabelText: 'Fill Opacity', + fillOpacityInvalidText: 'Fill Opacity is invalid', + borderLabelText: 'Border', + borderWidthLabelText: 'Border Width', + borderWidthInvalidText: 'Border Width is invalid', }, formValues: { bold: false, italic: false, underline: false, - font: { - color: undefined, - size: 12, - }, - background: { - color: undefined, - opacity: 100, - }, - border: { - color: undefined, - width: 1, - }, + fontColor: undefined, + fontSize: undefined, + backgroundColor: undefined, + backgroundOpacity: undefined, + borderColor: undefined, + borderWidth: undefined, }, fontColors: undefined, backgroundColors: undefined, borderColors: undefined, + minFontSize: 1, + maxFontSize: 50, + minOpacity: 0, + maxOpacity: 100, + minBorderWidth: 0, + maxBorderWidth: 15, }; /* this component is only used internally where props are defined and set. */ @@ -99,31 +121,39 @@ const HotspotTextStyleTab = ({ light, i18n, onChange, + minFontSize, + maxFontSize, + minOpacity, + maxOpacity, + minBorderWidth, + maxBorderWidth, }) => { const { - boldLabel, - italicLabel, - underlineLabel, - fontLabel, - fontSizeLabel, - fontSizeInvalid, - backgroundLabel, - fillOpacityLabel, - fillOpacityInvalid, - borderLabel, - borderWidthLabel, - borderWidthInvalid, + boldLabelText, + italicLabelText, + underlineLabelText, + fontLabelText, + fontSizeLabelText, + fontSizeInvalidText, + backgroundLabelText, + fillOpacityLabelText, + fillOpacityInvalidText, + borderLabelText, + borderWidthLabelText, + borderWidthInvalidText, } = merge({}, defaultProps.i18n, i18n); - const fontSizeRef = useRef(null); - const fillOpacityRef = useRef(null); - const borderWidthRef = useRef(null); - - const { bold, italic, underline, font, background, border } = merge( - {}, - defaultProps.formValues, - formValues - ); + const { + bold, + italic, + underline, + fontSize, + fontColor, + backgroundColor, + backgroundOpacity, + borderColor, + borderWidth, + } = formValues; return (