diff --git a/package.json b/package.json index 3b894d2..1f5d7ba 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lingdocs/pashto-inflector", - "version": "2.5.5", + "version": "2.5.6", "author": "lingdocs.com", "description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations", "homepage": "https://verbs.lingdocs.com", @@ -76,7 +76,10 @@ "extends": [ "react-app", "react-app/jest" - ] + ], + "rules": { + "no-warning-comments": [1, {"terms": ["fixme", "xxx"], "location": "anywhere"}] + } }, "browserslist": { "production": [ diff --git a/src/components/EntrySelect.tsx b/src/components/EntrySelect.tsx index 6a4f044..5717923 100644 --- a/src/components/EntrySelect.tsx +++ b/src/components/EntrySelect.tsx @@ -111,4 +111,69 @@ function EntrySelect(props: { } +export function SandwichSelect(props: { + sandwiches: E[], + value: E | undefined, + onChange: (value: E | undefined) => void, + name: string | undefined, + opts: T.TextOptions, + style?: StyleHTMLAttributes, +}) { + const divStyle = props.style || { width: "13rem" }; + const placeholder = "Select Sandwich…"; + const value = props.value ? makeSandwichOption(props.value) : undefined; + const options = props.sandwiches + // .sort((a, b) => { + // if ("entry" in a) { + // return a.before.p.localeCompare("p" in b ? b.p : b.entry.p, "af-PS") + // } + // return a.p.localeCompare("p" in b ? b.p : b.entry.p, "af-PS"); + // }) + .map(makeSandwichOption); + const onChange = (v: { label: string | JSX.Element, value: string } | null) => { + if (!v) { + props.onChange(undefined); + return; + } + const s = props.sandwiches.find(e => { + const sValue = JSON.parse(v.value) as T.Sandwich; + if (sValue.type !== "sandwich") throw new Error("error converting selected sandwich value to a sandwich"); + return sandwichSideEq(e.before, sValue.before) + && sandwichSideEq(e.after, sValue.after) + && (e.e === sValue.e); + }); + if (!s) return; + props.onChange(s); + } + return
+