pashto-inflector/src/components/Phonetics.tsx

41 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-03-09 12:39:13 +00:00
/**
* Copyright (c) 2021 lingdocs.com
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import {
translatePhonetics,
} from "../lib/translate-phonetics";
import { psJSXMap } from "../lib/jsx-map";
2021-03-09 12:39:13 +00:00
import * as T from "../types";
const Phonetics = ({ opts, children: text }: {
opts: T.TextOptions,
children: T.PsJSX | T.PsString | string,
2021-03-09 12:39:13 +00:00
}) => {
if (opts.phonetics === "none") {
return null;
}
const handleText = (f: string) => (
opts.phonetics === "lingdocs"
? f
: translatePhonetics(f, {
2021-03-09 12:39:13 +00:00
dialect: opts.dialect,
// @ts-ignore - weird TS not picking up the elimination of "none herre"
2021-03-09 12:39:13 +00:00
system: opts.phonetics,
})
);
if (typeof text !== "string" && typeof text.f !== "string") {
return psJSXMap(text as T.PsJSX, "f", ({f}) => handleText(f));
}
const f = typeof text === "string" ? text : text.f as string;
return <span className="f-text">
{handleText(f)}
2021-03-09 12:39:13 +00:00
</span>
};
export default Phonetics;