Skip to content

Commit

Permalink
Badges in field preview
Browse files Browse the repository at this point in the history
  • Loading branch information
wwqrd committed Mar 26, 2019
1 parent 138402e commit 65d1c08
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 23 deletions.
30 changes: 22 additions & 8 deletions src/components/Badge.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
import React from 'react';
import PropTypes from 'prop-types';

const Badge = ({ color, children }) => (
<div
className="badge"
style={{ backgroundColor: color }}
>
{children}
</div>
);
const Badge = ({ color, children }) => {
const style = color ?
{ backgroundColor: color } :
{};

return (
<div className="badge" style={style}>
{children}
</div>
);
};

Badge.propTypes = {
color: PropTypes.string,
children: PropTypes.node,
};

Badge.defaultProps = {
color: null,
children: null,
};

export default Badge;
31 changes: 17 additions & 14 deletions src/components/sections/Form/FieldPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@ import PropTypes from 'prop-types';
import { Field } from 'redux-form';
import Preview from '../../EditableList/Preview';
import Badge from '../../Badge';
import { getColorForType, getTypeForComponent } from './inputOptions';

const getColorForType = (type) => {
switch (type) {
// return 'var(--color-mustard--dark)';
// return 'var(--color-sea-green)';
// return 'var(--color-sea-green--dark)';
default:
return 'var(--color-slate-blue--dark)';
}
const PreviewFieldComponent = ({
input: {
value,
},
}) => {
const type = getTypeForComponent(value.component);

return (
<div>
{value.prompt}
<Badge color={getColorForType(type)}>{value.component}:{type}</Badge>
</div>
);
};

const PreviewFieldComponent = ({ input: { value } }) => (
<div>
{value.prompt}
<Badge color={getColorForType()}>{value.component}</Badge>
</div>
);
PreviewFieldComponent.propTypes = {
input: PropTypes.object.isRequired,
};

class PromptPreview extends Preview {
preview() {
Expand Down
1 change: 1 addition & 0 deletions src/components/sections/Form/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Form.propTypes = {
handleChangeFields: PropTypes.func.isRequired,
form: PropTypes.string.isRequired,
disabled: PropTypes.bool,
nodeType: PropTypes.string.isRequired,
};

Form.defaultProps = {
Expand Down
16 changes: 16 additions & 0 deletions src/components/sections/Form/inputOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,28 @@ const isVariableTypeWithOptions = variableType =>

const inputOptions = values(COMPONENTS);

const getColorForType = (type) => {
switch (type) {
case 'number':
case 'text':
return 'var(--color-mustard--dark)';
case 'boolean':
return 'var(--color-sea-green)';
case 'ordinal':
case 'categorical':
return 'var(--color-sea-green--dark)';
default:
return 'var(--color-slate-blue--dark)';
}
};

export {
COMPONENTS,
VARIABLE_TYPES_WITH_OPTIONS,
inputOptions,
getTypeForComponent,
getComponentsForType,
getColorForType,
isVariableTypeWithOptions,
};

Expand Down
2 changes: 1 addition & 1 deletion src/styles/components/_badge.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.badge {
display: inline-flex;
background-color: grey;
background-color: var(--color-mid-grey);
border-radius: unit(.5);
padding: unit(.5);
margin: 0 unit(1);
Expand Down

0 comments on commit 65d1c08

Please sign in to comment.