From a8356a330f226fe094d458db435fed24181d85ee Mon Sep 17 00:00:00 2001 From: Silviu Bogan Date: Thu, 22 Oct 2020 17:33:43 +0300 Subject: [PATCH] Use react-select from separate chunk --- src/Widgets/LayoutSelectWidget.jsx | 84 ++++++++++++++++++------------ 1 file changed, 50 insertions(+), 34 deletions(-) diff --git a/src/Widgets/LayoutSelectWidget.jsx b/src/Widgets/LayoutSelectWidget.jsx index 5588238..2156f4d 100644 --- a/src/Widgets/LayoutSelectWidget.jsx +++ b/src/Widgets/LayoutSelectWidget.jsx @@ -6,7 +6,9 @@ import React, { Component } from 'react'; import { compose } from 'redux'; import { defineMessages, injectIntl } from 'react-intl'; -import Select, { components } from 'react-select'; + +import loadable from '@loadable/component'; + import { isEqual } from 'lodash'; import { variants } from '../grid'; import { FormFieldWrapper, Icon } from '@plone/volto/components'; @@ -17,6 +19,8 @@ import { } from '@plone/volto/components/manage/Widgets/SelectStyling'; import checkSVG from '@plone/volto/icons/check.svg'; +const ReactSelectLib = loadable.lib(() => import('react-select')); + const gridColsAreEqual = (gridCols1, gridCols2) => { return isEqual(gridCols1, gridCols2); }; @@ -27,21 +31,27 @@ const variantToGridCols = (v) => { export const Option = (props) => { return ( - - - gridColsAreEqual(variantToGridCols(v), props.value), - ).icon - } - size="24px" - /> -
{props.label}
- {props.isFocused && !props.isSelected && ( - - )} - {props.isSelected && } -
+ + {({ components }) => { + return ( + + + gridColsAreEqual(variantToGridCols(v), props.value), + ).icon + } + size="24px" + /> +
{props.label}
+ {props.isFocused && !props.isSelected && ( + + )} + {props.isSelected && } +
+ ); + }} +
); }; @@ -119,25 +129,31 @@ export class LayoutSelectWidget extends Component { return ( - { + return { value: x[0], label: x[1] }; + })} + styles={customSelectStyles} + theme={selectTheme} + components={{ DropdownIndicator, Option, SingleValue }} + onChange={(data) => { + this.setState({ selectedOption: data }); + return onChange?.(id, data.value); + }} + /> + ); }} - /> + ); }