diff --git a/package.json b/package.json index d688392..18e78f8 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "react-router-hash-link": "^2.4.3", "react-scripts": "4.0.3", "react-scrollspy": "^3.4.3", + "react-select": "^5.1.0", "react-smooth-collapse": "^2.1.0", "react-swipeable": "^6.2.0", "web-vitals": "^1.0.1" @@ -62,7 +63,7 @@ "@types/react": "^17.0.27", "@types/react-dom": "^17.0.9", "babel-loader": "8.1.0", - "typescript": "^4.4.3", - "node-fetch": "^2.6.1" + "node-fetch": "^2.6.1", + "typescript": "^4.4.3" } } diff --git a/src/components/equative-explorer/explorer-selectors.tsx b/src/components/equative-explorer/explorer-selectors.tsx index 93e56e1..8396ab8 100644 --- a/src/components/equative-explorer/explorer-selectors.tsx +++ b/src/components/equative-explorer/explorer-selectors.tsx @@ -10,6 +10,7 @@ import { ButtonSelect, } from "@lingdocs/pashto-inflector"; import { isPluralEntry } from "../../lib/type-predicates"; +import Select from "react-select"; export function PredicateSelector({ state, dispatch }: { state: ExplorerState, @@ -19,11 +20,15 @@ export function PredicateSelector({ state, dispatch }: { const t = e.target.value as PredicateType; dispatch({ type: "setPredicateType", payload: t }); } - function onPredicateSelect(e: React.ChangeEvent) { - const ts = parseInt(e.target.value); - dispatch({ type: "setPredicate", payload: ts }); + function onPredicateSelect({ value }: any) { + dispatch({ type: "setPredicate", payload: parseInt(value) }); } - return
+ const options = inputs[state.predicateType].map(e => ({ + value: `${e.ts}`, + label: makeOptionLabel(e), + })); + const predicate = state.predicatesSelected[state.predicateType]; + return
- + className="mb-2" + // @ts-ignore + options={options} + isSearchable + placeholder={options.find(o => o.value === predicate.ts.toString())?.label} + />
; } @@ -75,14 +79,22 @@ export function SubjectSelector({ state, dispatch }: { const t = e.target.value as SubjectType; dispatch({ type: "setSubjectType", payload: t }); } - function onSubjectSelect(e: React.ChangeEvent) { - const ts = parseInt(e.target.value); - dispatch({ type: "setSubject", payload: ts }); + function onSubjectSelect({ value }: any) { + dispatch({ type: "setSubject", payload: parseInt(value) }); } const pluralNounSelected = ( state.subjectType === "noun" && isPluralEntry(state.subjectsSelected.noun) - ) - return
+ ); + const options = state.subjectType === "pronouns" + ? [] + : inputs[state.subjectType].map(e => ({ + value: e.ts.toString(), + label: makeOptionLabel(e), + })); + const subject = state.subjectType === "pronouns" + ? undefined + : state.subjectsSelected[state.subjectType] + return
{state.subjectType !== "pronouns" && <> - + className="mb-2" + // @ts-ignore + options={options} + isSearchable + placeholder={options.find(o => o.value === subject?.ts.toString())?.label} + />