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

@isoftdata/svelte-load-item-modal

Package Overview
Dependencies
Maintainers
10
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

## Install

npmnpm
Version
1.1.0
Version published
Weekly downloads
52
420%
Maintainers
10
Weekly downloads
 
Created
Source

Svelte LoadItemModal

Install

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

Props

NameTypeDescriptionDefault Value
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

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

Example

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

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

	function doSearch() {
		loadItemModal?.show()
	}
</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 30 Oct 2024

Related posts