diff --git a/src/demo-components/InflectionDemo.tsx b/src/demo-components/InflectionDemo.tsx index 4ede762..6b81e61 100644 --- a/src/demo-components/InflectionDemo.tsx +++ b/src/demo-components/InflectionDemo.tsx @@ -11,191 +11,239 @@ import HumanReadableInflectionPattern from "../components/src/HumanReadableInfle import leftChevron from "./chevron_left-24px.svg"; import rightChevron from "./chevron_right-24px.svg"; const chevStyle = { - height: "2rem", - width: "2rem", - color: "#ccc", + height: "2rem", + width: "2rem", + color: "#ccc", }; -const nounsAdjs = nounsAdjsUnsafe - .filter(x => tp.isNounEntry(x) || tp.isAdjectiveEntry(x)) as (T.NounEntry | T.AdjectiveEntry)[]; +const nounsAdjs = nounsAdjsUnsafe.filter( + (x) => tp.isNounEntry(x) || tp.isAdjectiveEntry(x) +) as (T.NounEntry | T.AdjectiveEntry)[]; -function InflectionDemo({ opts }: { - opts: T.TextOptions, -}) { - const [pattern, setPattern] = useState("all"); - const [word, setWord] = useState(undefined) - const patterns: { - value: T.InflectionPattern | "all", - label: JSX.Element | string, - }[] = [ - { - value: "all", - label: "all types", - }, - { - value: 0, - label: "no inflection", - }, { - value: 1, - label: "basic", - }, { - value: 2, - label: <>unstressed {{ p: "ی", f: "ey" }}, - }, { - value: 3, - label: <>stressed {{ p: "ی", f: "éy" }}, - }, { - value: 4, - label: '"Pashtoon" pattern', - }, { - value: 5, - label: "short squish", - }, { - value: 6, - label: <>fem. inan. {{ p: "ي", f: "ee" }}, - }, - ]; - const entries = (nounsAdjs as (T.NounEntry | T.AdjectiveEntry)[]).filter(tp.isPattern(pattern)) - function handlePatternChange(e: React.ChangeEvent) { - const v = e.target.value; - const value = v === "all" ? v : (Number(v) as T.InflectionPattern); - setPattern(value); - console.log({ word }); - if (word && !tp.isPattern(value)(word)) { - setWord(undefined); - } +function InflectionDemo({ opts }: { opts: T.TextOptions }) { + const [pattern, setPattern] = useState("all"); + const [word, setWord] = useState( + undefined + ); + const patterns: { + value: T.InflectionPattern | "all"; + label: JSX.Element | string; + }[] = [ + { + value: "all", + label: "all types", + }, + { + value: 0, + label: "no inflection", + }, + { + value: 1, + label: "basic", + }, + { + value: 2, + label: ( + <> + unstressed {{ p: "ی", f: "ay" }} + + ), + }, + { + value: 3, + label: ( + <> + stressed {{ p: "ی", f: "áy" }} + + ), + }, + { + value: 4, + label: '"Pashtoon" pattern', + }, + { + value: 5, + label: "short squish", + }, + { + value: 6, + label: ( + <> + fem. inan. {{ p: "ي", f: "ee" }} + + ), + }, + ]; + const entries = (nounsAdjs as (T.NounEntry | T.AdjectiveEntry)[]).filter( + tp.isPattern(pattern) + ); + function handlePatternChange(e: React.ChangeEvent) { + const v = e.target.value; + const value = v === "all" ? v : (Number(v) as T.InflectionPattern); + setPattern(value); + console.log({ word }); + if (word && !tp.isPattern(value)(word)) { + setWord(undefined); } - function wordForward() { - if (!word) { - setWord(entries[0]); - return; - } - const oldIndex = entries.findIndex(e => e.ts === word.ts); - const newIndex = entries.length === (oldIndex + 1) - ? 0 : (oldIndex + 1); - setWord(entries[newIndex]); + } + function wordForward() { + if (!word) { + setWord(entries[0]); + return; } - function wordBack() { - if (!word) { - setWord(entries[entries.length - 1]); - return; - } - const oldIndex = entries.findIndex(e => e.ts === word.ts); - const newIndex = oldIndex === 0 - ? (entries.length - 1) : (oldIndex + 1); - setWord(entries[newIndex]); + const oldIndex = entries.findIndex((e) => e.ts === word.ts); + const newIndex = entries.length === oldIndex + 1 ? 0 : oldIndex + 1; + setWord(entries[newIndex]); + } + function wordBack() { + if (!word) { + setWord(entries[entries.length - 1]); + return; } - const inf = ((): T.InflectorOutput | false => { - if (!word) return false; - try { - return inflectWord(word); - } catch (e) { - console.error("error inflecting entry", word); - return false; - } - })(); - return
-

- Produces the inflections and plural forms (Pashto and Arabic plurals where applicable) for words -

-
-
-
-
-
-
Filter words by inflection pattern:
-
- {patterns.map(({ value, label}) => ( -
- - -
- ))} -
-
-
-
-
Select word:
- -
- {"previous"} - {"next"} -
+ const oldIndex = entries.findIndex((e) => e.ts === word.ts); + const newIndex = oldIndex === 0 ? entries.length - 1 : oldIndex + 1; + setWord(entries[newIndex]); + } + const inf = ((): T.InflectorOutput | false => { + if (!word) return false; + try { + return inflectWord(word); + } catch (e) { + console.error("error inflecting entry", word); + return false; + } + })(); + return ( +
+

+ Produces the inflections and plural forms (Pashto and Arabic plurals + where applicable) for words +

+
+
+
+
+
+
+ Filter words by{" "} + + inflection pattern + + : +
+
+ {patterns.map(({ value, label }) => ( +
+ +
+ ))}
+
+
+
Select word:
+ +
+ {"previous"} + {"next"} +
+
+
- {inf ?
- {inf.inflections && word && (() => { - const pattern = getInflectionPattern(word); - return ; - })()} - {"plural" in inf && inf.plural !== undefined &&
-
Plural
- -
} - {"arabicPlural" in inf && inf.arabicPlural !== undefined &&
-
Arabic Plural
- -
} -
:
-
} -
; +
+ {inf ? ( +
+ {inf.inflections && + word && + (() => { + const pattern = getInflectionPattern(word); + return ( + + ); + })()} + {"plural" in inf && inf.plural !== undefined && ( +
+
Plural
+ +
+ )} + {"arabicPlural" in inf && inf.arabicPlural !== undefined && ( +
+
Arabic Plural
+ +
+ )} +
+ ) : ( +
+ )} +
+ ); } function inflectionSubUrl(pattern: T.InflectionPattern): string { - return pattern === 0 - ? "" - : pattern === 1 - ? "#1-basic" - : pattern === 2 - ? "#2-words-ending-in-an-unstressed-ی---ey" - : pattern === 3 - ? "#3-words-ending-in-a-stressed-ی---éy" - : pattern === 4 - ? "#4-words-with-the-pashtoon-pattern" - : pattern === 5 - ? "#5-shorter-words-that-squish" - // : pattern === 6 - : "#6-inanimate-feminine-nouns-ending-in-ي---ee" + return pattern === 0 + ? "" + : pattern === 1 + ? "#1-basic" + : pattern === 2 + ? "#2-words-ending-in-an-unstressed-ی---ey" + : pattern === 3 + ? "#3-words-ending-in-a-stressed-ی---éy" + : pattern === 4 + ? "#4-words-with-the-pashtoon-pattern" + : pattern === 5 + ? "#5-shorter-words-that-squish" + : // : pattern === 6 + "#6-inanimate-feminine-nouns-ending-in-ي---ee"; } -export default InflectionDemo; \ No newline at end of file +export default InflectionDemo;