Commit b12dd411 by Vladislav Lagunov

Необязательный printItem в MultiSelect

parent aa441891
......@@ -17,7 +17,7 @@ export type Props<A> = StandardProps<React.HTMLProps<HTMLDivElement>, string, 'v
textFieldProps?: Partial<TextFieldProps>;
renderSuggestion?(a: A): React.ReactNode;
placeholder?: string;
printItem(a: A): string;
printItem?(a: A): string;
id?: string; // Используется для установки `key` пропсов
isEqual?(a: A, b: A): boolean;
}
......@@ -26,6 +26,10 @@ export type Props<A> = StandardProps<React.HTMLProps<HTMLDivElement>, string, 'v
// @ts-ignore Component
@withStyles(styles)
export default class MultiSelect<A> extends React.Component<Props<A>> {
static defaultProps = {
printItem: String,
};
handleDelete = memoize((idx: number) => (e?: React.MouseEvent<HTMLDivElement>) => {
const { value, onValueChange, disabled } = this.props; if (disabled) return;
const nextValue = value!.slice();
......@@ -67,7 +71,7 @@ export default class MultiSelect<A> extends React.Component<Props<A>> {
const chipClassName = classNames({ [classes!.disabled!]: disabled });
return !value.length ? null : <div><span className={classes!.chips}>
{value!.map((ch, i) => (
<Chip key={ch[id]} className={chipClassName} label={printItem(ch)} onClick={this.handleDelete(i)} onDelete={this.handleDelete(i)}/>
<Chip key={ch[id]} className={chipClassName} label={printItem!(ch)} onClick={this.handleDelete(i)} onDelete={this.handleDelete(i)}/>
))}
</span></div>;
});
......
......@@ -2,6 +2,7 @@ import * as React from 'react';
import { AuthCtx as Ctx } from '~/context';
import { I18nString } from '@bitmaster/utils/gettext';
import { ObjectPath } from '~/utils';
import * as gettext from '~/gettext';
const hoistNonReactStatics = require('hoist-non-react-statics');
......@@ -71,4 +72,4 @@ export type Disabled = boolean|DisabledRecord;
export interface ErrorRecord {
[K: string]: Error;
}
export type Error = boolean|I18nString|string|ErrorRecord;
export type Error = boolean|I18nString|string|ErrorRecord|gettext.I18nString;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment