From 2e1564b4f5d6fdd694e3e4b3d45ac536ac1e26d5 Mon Sep 17 00:00:00 2001 From: cha0s Date: Thu, 11 Feb 2021 15:24:07 -0600 Subject: [PATCH] feat: condition++ --- .../src/behavior-components/condition.jsx | 97 ++++++++++++++----- .../src/behavior-components/condition.scss | 45 +++++++++ 2 files changed, 120 insertions(+), 22 deletions(-) diff --git a/packages/entity/src/behavior-components/condition.jsx b/packages/entity/src/behavior-components/condition.jsx index a1b62fc..4466d25 100644 --- a/packages/entity/src/behavior-components/condition.jsx +++ b/packages/entity/src/behavior-components/condition.jsx @@ -2,6 +2,7 @@ import {join} from 'path'; import {PropTypes, React} from '@latus/react'; import {useJsonPatcher} from '@persea/json'; +import classnames from 'classnames'; import Variant from './help/variant'; @@ -25,29 +26,81 @@ const Condition = ({context, path, value}) => { /> ); }); + const operator = ( + + ); + const renderables = []; + switch (value.operator) { + case 'or': + case 'and': + renderables.push(operator); + renderables.push(...operands.map((operand, i) => ( +
+ {operand} + +
+ ))); + renderables.push( + , + ); + break; + default: + renderables.push(operands.shift()); + renderables.push(operator); + renderables.push(...operands); + } return ( -
- {operands.shift()} - - {operands} +
+ {renderables}
); }; diff --git a/packages/entity/src/behavior-components/condition.scss b/packages/entity/src/behavior-components/condition.scss index 6413651..69e0734 100644 --- a/packages/entity/src/behavior-components/condition.scss +++ b/packages/entity/src/behavior-components/condition.scss @@ -1,4 +1,49 @@ .condition { align-items: center; display: flex; + &.condition--vertical { + align-items: flex-start; + flex-direction: column; + } +} + +.condition--vertical { + + > select { + margin-bottom: 1em; + } + > .expression, + > .key, + > .literal { + margin-left: 1em; + } + > .expression { + margin-bottom: 0.5em; + &:last-child { + margin-bottom: 0; + } + } +} + +.condition .condition--vertical { + padding-top: 0.5em; +} + +.operand__wrapper { + align-items: center; + display: flex; + padding-left: 0.5em; + width: 100%; + &:nth-of-type(2n+1) { + background-color: rgba(255, 255, 255, 0.05); + } + > button { + background-color: transparent; + border: none; + font-size: 0.8em; + margin-left: auto; + margin-right: 0.5em; + padding: 1em; + pointer-events: auto; + } }