mirror of
https://github.com/maputnik/editor.git
synced 2026-01-21 12:50:02 +00:00
In this PR I have changed some of the jsx files to tsx file. I'm starting off with the "leafs" so that migration of the rest will be easier, hopefully. What I'm basically doing is taking a jsx file, copy paste it into: https://mskelton.dev/ratchet And after that I'm fixing the types as needed. It's not a very long process. Hopefully more PRs will follow and this will be over soon. I don't plan to migrate the storybook as I generally don't understand why is it useful, I'll open an issue to see if anyone thinks differently.
51 lines
1.1 KiB
TypeScript
51 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 default 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}
|
|
/>
|
|
}
|
|
}
|
|
}
|
|
|