generated from eea/volto-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt (WIP) to solve the issue with a new widget
- Loading branch information
1 parent
abf5158
commit 9f633d6
Showing
5 changed files
with
101 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** | ||
* LayoutSelectWidget component. | ||
* @module volto-columns-block/Widgets/LayoutSelectWidget | ||
*/ | ||
|
||
import React, { Component } from 'react'; | ||
import { compose } from 'redux'; | ||
import { defineMessages, injectIntl } from 'react-intl'; | ||
import loadable from '@loadable/component'; | ||
|
||
import { FormFieldWrapper } from '@plone/volto/components'; | ||
|
||
import { | ||
Option, | ||
DropdownIndicator, | ||
selectTheme, | ||
customSelectStyles, | ||
} from '@plone/volto/components/manage/Widgets/SelectStyling'; | ||
|
||
const Select = loadable(() => import('react-select')); | ||
|
||
/** | ||
* SelectWidget component class. | ||
* @function SelectWidget | ||
* @returns {string} Markup of the component. | ||
*/ | ||
export class LayoutSelectWidget extends Component { | ||
state = { | ||
selectedOption: null, | ||
}; | ||
|
||
componentDidMount() { | ||
this.setState({ | ||
selectedOption: { | ||
value: this.props.value, | ||
label: this.props.choices.find((x) => x[0] === this.props.value)?.[1], | ||
}, | ||
}); | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
if (prevProps.value !== this.props.value) { | ||
this.setState({ | ||
selectedOption: { | ||
value: this.props.value, | ||
label: this.props.choices.find((x) => x[0] === this.props.value)?.[1], | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* Render method. | ||
* @method render | ||
* @returns {string} Markup for the component. | ||
*/ | ||
render() { | ||
const { id, choices, value, onChange } = this.props; | ||
|
||
console.log('value', value); | ||
|
||
return ( | ||
<FormFieldWrapper {...this.props}> | ||
<Select | ||
id={`field-${id}`} | ||
key={this.props.choices} | ||
name={id} | ||
value={this.state.selectedOption} | ||
isDisabled={this.props.isDisabled} | ||
className="react-select-container" | ||
classNamePrefix="react-select" | ||
options={choices.map((x) => { | ||
return { value: x[0], label: x[1] }; | ||
})} | ||
styles={customSelectStyles} | ||
theme={selectTheme} | ||
components={{ DropdownIndicator, Option }} | ||
onChange={(data) => { | ||
this.setState({ selectedOption: data }); | ||
return onChange?.(id, data.value); | ||
}} | ||
/> | ||
</FormFieldWrapper> | ||
); | ||
} | ||
} | ||
|
||
export default compose(injectIntl)(LayoutSelectWidget); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
import ColumnsWidget from './ColumnsWidget'; | ||
export default ColumnsWidget; | ||
export ColumnsWidget from './ColumnsWidget'; | ||
export LayoutSelectWidget from './LayoutSelectWidget'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters