New:Microsoft Teams Notifications Are Now Available in Socket.Learn more
Get Started

@isoftdata/svelte-load-item-modal

Package Overview
Dependencies
Maintainers
11
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@isoftdata/svelte-load-item-modal

```sh npm i @isoftdata/svelte-load-item-modal ```

npmnpm
Version
1.2.0
Version published
Weekly downloads
38
40.74%
Maintainers
11
Weekly downloads
 
Created
Source

Svelte LoadItemModal

Install

npm i @isoftdata/svelte-load-item-modal

Props

NameTypeDescriptionDefault Value
allowEmptySearchbooleanWhether to allow searching without a search string.false
itemTitlestringThe title of the item. Shown in the header and input placeholder.'Item'
itemIdPropkeyof TThe property name for the item ID. Used for the default slot's default contentRequired
itemDisplayPropkeyof TThe property name for the item display. Used for the default slot's default contentRequired
modalSizeComponentProps<Modal>['modalSize']The size of the modal''
doSearch(searchString: string) => Promise<Array<T>>The search functionRequired
titlestring | undefinedThe title to use instead of the default. Useful if you want to translate this component.computed based on itemTitle
inputPlaceholderstring | undefinedThe input placeholder to use instead of the default. Useful if you want to translate this component.computed based on itemTitle
noResultsTextstring | undefinedThe text to show when there are no results instead of the default. Useful if you want to translate this component.computed based on itemTitle

Slots

  • default - The inner html content of each "item" in the results list. Props item and index are available on this slot

Events

  • chooseItem - Fired when an item is clicked. detail is { item: T; index: number }
  • lookupError - Fired when doSearch throws an error. detail is {error: Error}
  • cancel - Fired when the modal is closed. detail is void

Functions

  • open(searchInput?: string) => void - Opens the modal. If a search string is provided, it will perform a search with that string.

Example

<script lang="ts">
	import LoadItemModal from '@isoftdata/svelte-load-item-modal'

	let loadItemModal: LoadItemModal<{id: number, name: string}> | undefined

	function doSearch() {
		loadItemModal?.open()
	}
</script>

<LoadItemModal
	itemDisplayProp="name"
	itemIdProp="id"
	itemTitle="Fruit"
	bind:this={loadItemModal}
	doSearch={searchString => {
		return Promise.resolve(
			[
				{ id: 1, name: 'Apple' },
				{ id: 2, name: 'Banana' },
				{ id: 3, name: 'Watermelon' },
				{ id: 4, name: 'Pineapple' },
				{ id: 5, name: 'Mango' },
				{ id: 6, name: 'Strawberry' },
				{ id: 7, name: 'Blueberry' },
				{ id: 8, name: 'Raspberry' },
				{ id: 9, name: 'Blackberry' },
				{ id: 10, name: 'Kiwi' },
			].filter(item => item.name.toLowerCase().includes(searchString.toLowerCase())),
		)
	}}
	on:chooseItem={event => {
		console.log('Item chosen:', event.detail)
	}}
	on:onLookupError={event => {
		console.error('Lookup error:', event.detail)
	}}
	on:cancel={() => {
		console.log('Cancel')
	}}
	let:item
>{item.name}</LoadItemModal>

FAQs

Package last updated on 27 Feb 2025

Related posts