Skip to content

Commit

Permalink
Show icon for selected layout in Layout field
Browse files Browse the repository at this point in the history
  • Loading branch information
silviubogan committed Oct 12, 2020
1 parent b083c2b commit 96f6b00
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/ColumnsBlock/styles.less
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,8 @@
}
}
}

.layout-select-widget-selection-icon {
vertical-align: middle;
margin-right: 1.5rem;
}
37 changes: 34 additions & 3 deletions src/Widgets/LayoutSelectWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,39 @@ export const Option = (props) => {
);
};

const SingleValue = (props) => {
const { children, className, cx, getStyles, isDisabled, innerProps } = props;

const variant = variants.find((v) =>
gridColsAreEqual(variantToGridCols(v), props.data.value),
);

const icon = variant?.icon;

return (
<div
style={getStyles('singleValue', props)}
className={cx(
{
'single-value': true,
'single-value--is-disabled': isDisabled,
},
className,
)}
{...innerProps}
>
{icon && (
<Icon
name={icon}
size="24px"
className="layout-select-widget-selection-icon"
/>
)}
{children}
</div>
);
};

/**
* LayoutSelectWidget component class.
* @function LayoutSelectWidget
Expand Down Expand Up @@ -83,8 +116,6 @@ export class LayoutSelectWidget extends Component {
render() {
const { id, choices, value, onChange } = this.props;

console.log('value', value);

return (
<FormFieldWrapper {...this.props}>
<Select
Expand All @@ -100,7 +131,7 @@ export class LayoutSelectWidget extends Component {
})}
styles={customSelectStyles}
theme={selectTheme}
components={{ DropdownIndicator, Option }}
components={{ DropdownIndicator, Option, SingleValue }}
onChange={(data) => {
this.setState({ selectedOption: data });
return onChange?.(id, data.value);
Expand Down

0 comments on commit 96f6b00

Please sign in to comment.