Skip to content

Commit

Permalink
fix(ui-contract-editor): render conditional switch
Browse files Browse the repository at this point in the history
Signed-off-by: irmerk <[email protected]>
  • Loading branch information
jolanglinais authored and jeromesimeon committed Aug 4, 2020
1 parent bc50621 commit c8a8476
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import React from 'react';
import PropTypes from 'prop-types';

/* Actions */
import { childReducer } from '../actions';

/* Styling */
import { ClauseConditionalTooltip } from '../styles';

Expand All @@ -18,18 +21,22 @@ const ConditionalSwitch = (props) => {
caretLeft: 2,
tooltipHeight: 1.85,
};
const tooltipText = props.isTrue ? props.whenFalse : props.whenTrue;
const tooltipInstructions = props.isContentShowing
? 'Hide text'
: `Change to: "${tooltipText}"`;
const trueHasLength = childReducer(props.whenTrue).length;
const falseHasLength = childReducer(props.whenFalse).length;
const tooltipText = props.isTrue ? childReducer(props.whenFalse) : childReducer(props.whenTrue);
const tooltipInstructions = (text) => {
if (trueHasLength && falseHasLength) return `Change to: "${text}"`;
if (props.isContentShowing) return 'Hide text';
return `Change to: "${text}"`;
};

return (
<>
<ClauseConditionalTooltip
contentEditable={false}
{...conditionalTooltip}
>
{tooltipInstructions}
{tooltipInstructions(tooltipText)}
</ClauseConditionalTooltip>
</>
);
Expand Down

0 comments on commit c8a8476

Please sign in to comment.