mirror of
https://github.com/maputnik/editor.git
synced 2026-09-12 07:17: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>
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import React from "react";
|
|
import classnames from "classnames";
|
|
|
|
export type InputMultiInputProps = {
|
|
name?: string
|
|
value: string
|
|
options: any[]
|
|
onChange(...args: unknown[]): unknown
|
|
"aria-label"?: string
|
|
};
|
|
|
|
export class InputMultiInput extends React.Component<InputMultiInputProps> {
|
|
render() {
|
|
let options = this.props.options;
|
|
if(options.length > 0 && !Array.isArray(options[0])) {
|
|
options = options.map(v => [v, v]);
|
|
}
|
|
|
|
const selectedValue = this.props.value || options[0][0];
|
|
const radios = options.map(([val, label])=> {
|
|
return <label
|
|
key={val}
|
|
className={classnames("maputnik-button", "maputnik-radio-as-button", {"maputnik-button-selected": val === selectedValue})}
|
|
>
|
|
<input type="radio"
|
|
name={this.props.name}
|
|
onChange={_e => this.props.onChange(val)}
|
|
value={val}
|
|
checked={val === selectedValue}
|
|
/>
|
|
{label}
|
|
</label>;
|
|
});
|
|
|
|
return <fieldset className="maputnik-multibutton" aria-label={this.props["aria-label"]}>
|
|
{radios}
|
|
</fieldset>;
|
|
}
|
|
}
|