Files
editor/src/components/InputFont.tsx
T
Harel M 9c1499b805 Replace default export with named exports (#1998)
## 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>
2026-07-12 14:07:28 +03:00

62 lines
1.4 KiB
TypeScript

import React from "react";
import { InputAutocomplete } from "./InputAutocomplete";
export type InputFontProps = {
name: string
value?: string[]
default?: string[]
fonts?: unknown[]
style?: object
onChange(...args: unknown[]): unknown
"aria-label"?: string
};
export class InputFont extends React.Component<InputFontProps> {
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>
);
}
}