Created
November 3, 2024 11:56
-
-
Save erikvullings/aa531ff3255dad0b0b207df4ff6c04e4 to your computer and use it in GitHub Desktop.
Plugin for mithril-ui-form of the SearchSelect component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { registerPlugin } from 'mithril-ui-form'; | |
import { searchSelectPlugin } from './search-select-plugin'; | |
// Register plugin under the name `search_select` or any other name of your choosing. | |
registerPlugin('search_select', searchSelectPlugin); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import m from 'mithril'; | |
import { PluginType } from 'mithril-ui-form'; | |
import { SearchSelect, Option } from 'mithril-materialized'; | |
export const searchSelectPlugin: PluginType<string[], Option<string>[]> = () => { | |
let options: Option<string>[] = []; | |
let className: string | undefined; | |
return { | |
oninit: ({ attrs: { field } }) => { | |
const { options: o, className: c } = field; | |
className = c; | |
if (o && typeof o !== 'string') { | |
options = o; | |
} | |
}, | |
view: ({ attrs: { iv, onchange, label } }) => { | |
return m( | |
'.multi-select', | |
{ className }, | |
m(SearchSelect<string>, { | |
label, | |
initialValue: iv, | |
options, | |
onchange, | |
}) | |
); | |
}, | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment