import * as React from "react"; import * as cx from "classnames"; import { PCComponent, PCStyleMixin } from "paperclip"; import { DropdownMenuOption } from "../../../../../../inputs/dropdown/controller"; import { memoize } from "tandem-common"; import { inheritItemComponentTypeChangeComplete } from "../../../../../../../actions"; import { Dispatch } from "redux"; import { BaseInheritItemProps } from "./inherit-item.pc"; export type Props = BaseInheritItemProps & { onClick: any; alt?: boolean; dispatch: Dispatch; styleMixinId: string; styleMixin: PCStyleMixin; selected?: boolean; allStyleMixins: PCStyleMixin[]; }; export default (Base: React.ComponentClass) => class InheritItemController extends React.PureComponent { onChangeComplete = value => { this.props.dispatch( inheritItemComponentTypeChangeComplete( this.props.styleMixinId, value.id ) ); }; onClick = () => { this.props.onClick(this.props.styleMixinId); }; render() { const { selected, styleMixin, allStyleMixins, alt, ...rest } = this.props; const { onClick, onChangeComplete } = this; return ( event.stopPropagation(), filterable: true, value: styleMixin, options: getStyleMixinOptions(allStyleMixins), onChangeComplete: onChangeComplete }} /> ); } }; const getStyleMixinOptions = memoize( (styleMixins: PCStyleMixin[]): DropdownMenuOption[] => { return styleMixins .map(styleMixin => { return { label: styleMixin.label, value: styleMixin }; }) .sort((a, b) => (a.label > b.label ? -1 : 1)); } );