mirror of
https://github.com/maputnik/editor.git
synced 2026-09-11 14:57:26 +00:00
9c1499b805
## Launch Checklist See title, Also removed some "_" from some file names. This is a pure refactoring, no logic changes. - [x] Briefly describe the changes in this PR. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
import React from "react";
|
|
import { InputSelect } from "./InputSelect";
|
|
import { InputMultiInput } from "./InputMultiInput";
|
|
|
|
|
|
function optionsLabelLength(options: any[]) {
|
|
let sum = 0;
|
|
options.forEach(([_, label]) => {
|
|
sum += label.length;
|
|
});
|
|
return sum;
|
|
}
|
|
|
|
|
|
export type InputEnumProps = {
|
|
"data-wd-key"?: string
|
|
value?: string
|
|
style?: object
|
|
default?: string
|
|
name?: string
|
|
onChange(...args: unknown[]): unknown
|
|
options: any[]
|
|
"aria-label"?: string
|
|
label?: string
|
|
};
|
|
|
|
|
|
export class InputEnum extends React.Component<InputEnumProps> {
|
|
render() {
|
|
const {options, value, onChange, name, label} = this.props;
|
|
|
|
if(options.length <= 3 && optionsLabelLength(options) <= 20) {
|
|
return <InputMultiInput
|
|
name={name}
|
|
options={options}
|
|
value={(value || this.props.default)!}
|
|
onChange={onChange}
|
|
aria-label={this.props["aria-label"] || label}
|
|
/>;
|
|
} else {
|
|
return <InputSelect
|
|
options={options}
|
|
value={(value || this.props.default)!}
|
|
onChange={onChange}
|
|
aria-label={this.props["aria-label"] || label}
|
|
/>;
|
|
}
|
|
}
|
|
}
|