import React from 'react' import dynamic from 'next/dynamic' import Dropdown from '../Dropdown' import { managePopout } from '../Popout' import ThemeIcon from '../svg/Theme' import RemoveIcon from '../svg/Remove' import { COLORS } from '../../lib/constants' const ThemeCreate = dynamic(() => import('./ThemeCreate'), { loading: () => null }) const ThemeItem = ({ children, item, isSelected, remove }) => (
{children} {item.custom && !isSelected && (
{ e.stopPropagation() remove(item.id) }} >
)}
) const themeIcon = class Themes extends React.PureComponent { state = { highlights: {} } dropdown = React.createRef() componentDidUpdate(prevProps) { if (prevProps.isVisible && !this.props.isVisible) { this.setState({ highlights: {} }) } } handleThemeSelected = theme => { const { toggleVisibility, update } = this.props if (theme.id === 'create') { toggleVisibility() this.dropdown.current.closeMenu() } else { update(theme) } } updateHighlights = updates => this.setState(({ highlights }) => ({ highlights: { ...highlights, ...updates } })) create = theme => { this.props.toggleVisibility() this.props.create(theme) } itemWrapper = props => render() { const { themes, theme, isVisible, toggleVisibility } = this.props const highlights = { ...theme.highlights, ...this.state.highlights } const dropdownValue = isVisible ? { name: '' } : { id: theme.id, name: theme.name } const dropdownList = [ { id: 'create', name: 'Create +' }, ...themes ] return (
{isVisible && ( )}
) } } export default managePopout(Themes)