mirror of
https://github.com/maputnik/editor.git
synced 2025-12-25 15:40:00 +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.
62 lines
1.3 KiB
TypeScript
62 lines
1.3 KiB
TypeScript
import React from 'react'
|
|
import InputAutocomplete from './InputAutocomplete'
|
|
|
|
export type FieldFontProps = {
|
|
name: string
|
|
value?: string[]
|
|
default?: string[]
|
|
fonts?: unknown[]
|
|
style?: object
|
|
onChange(...args: unknown[]): unknown
|
|
'aria-label'?: string
|
|
};
|
|
|
|
export default class FieldFont extends React.Component<FieldFontProps> {
|
|
static defaultProps = {
|
|
fonts: []
|
|
}
|
|
|
|
get values() {
|
|
const out = this.props.value || this.props.default || [];
|
|
|
|
// Always put a "" in the last field to you can keep adding entries
|
|
if (out[out.length-1] !== ""){
|
|
return out.concat("");
|
|
}
|
|
else {
|
|
return out;
|
|
}
|
|
}
|
|
|
|
changeFont(idx: number, newValue: string) {
|
|
const changedValues = this.values.slice(0)
|
|
changedValues[idx] = newValue
|
|
const filteredValues = changedValues
|
|
.filter(v => v !== undefined)
|
|
.filter(v => v !== "")
|
|
|
|
this.props.onChange(filteredValues);
|
|
}
|
|
|
|
render() {
|
|
const inputs = this.values.map((value, i) => {
|
|
return <li
|
|
key={i}
|
|
>
|
|
<InputAutocomplete
|
|
aria-label={this.props['aria-label'] || this.props.name}
|
|
value={value}
|
|
options={this.props.fonts?.map(f => [f, f])}
|
|
onChange={this.changeFont.bind(this, i)}
|
|
/>
|
|
</li>
|
|
})
|
|
|
|
return (
|
|
<ul className="maputnik-font">
|
|
{inputs}
|
|
</ul>
|
|
);
|
|
}
|
|
}
|