{"name":"svelte-select","version":"5.0.0-alpha.2","repository":{"type":"git","url":"git+https://rob-balfre@github.com/rob-balfre/svelte-select.git"},"description":"A <Select> component for Svelte apps","devDependencies":{"@sveltejs/kit":"1.0.0-next.195","autoprefixer":"^10.4.0","cross-env":"^7.0.3","find-in-files":"^0.5.0","postcss":"^8.3.11","postcss-cli":"^9.0.2","postcss-import":"^14.0.2","prettier":"~2.4.1","prettier-plugin-svelte":"^2.4.0","rollup":"^2.59.0","rollup-plugin-cleaner":"^1.0.0","rollup-plugin-css-only":"^3.1.0","rollup-plugin-node-resolve":"^5.2.0","rollup-plugin-postcss":"^4.0.1","rollup-plugin-svelte":"^7.1.0","sirv-cli":"^1.0.14","svelte":"^3.44.1","svelte-preprocess":"^4.9.8","svelte-tiny-virtual-list":"^1.1.7","svelte2tsx":"^0.4.8","tailwindcss":"^2.2.19","tape-modern":"^1.1.2","typescript":"^4.4.4"},"author":{"name":"Robert Balfré","email":"rob.balfre@gmail.com","url":"https://github.com/rob-balfre"},"license":"ISC","keywords":["svelte"],"type":"module","exports":{"./package.json":"./package.json","./.DS_Store":"./.DS_Store","./ChevronIcon.svelte":"./ChevronIcon.svelte","./ClearIcon.svelte":"./ClearIcon.svelte","./Item.svelte":"./Item.svelte","./List.svelte":"./List.svelte","./LoadingIcon.svelte":"./LoadingIcon.svelte","./Multi.svelte":"./Multi.svelte","./Select.svelte":"./Select.svelte","./Selection.svelte":"./Selection.svelte","./debounce":"./debounce.js","./default.css":"./default.css","./filter":"./filter.js","./getItems":"./getItems.js",".":"./index.js","./presets/vanilla":"./presets/vanilla.js","./tailwind.css":"./tailwind.css"},"svelte":"./index.js","readme":"<div align=\"center\">\n  <img src=\"https://raw.githubusercontent.com/rob-balfre/svelte-select/feature/v5/svelte-select.png\" alt=\"Svelte Select\" width=\"150\" />\n  <h1>Svelte Select</h1>\n</div>\n\n<div align=\"center\">\n  <a href=\"https://npmjs.org/package/svelte-select\">\n    <img src=\"https://badgen.now.sh/npm/v/svelte-select\" alt=\"version\" />\n  </a>\n  <a href=\"https://npmjs.org/package/svelte-select\">\n    <img src=\"https://badgen.now.sh/npm/dm/svelte-select\" alt=\"downloads\" />\n  </a>\n</div>\n<div align=\"center\">A select/autocomplete/typeahead Svelte component. <br />\n  Lightweight, feature-rich and modular by design.</div>\n\n## Demos\n\n🌱 [Simple demo](https://svelte.dev/repl/a859c2ba7d1744af9c95037c48989193?version=3.12.1)\n\n🌻 [Advanced demo](https://svelte.dev/repl/3e032a58c3974d07b7818c0f817a06a3?version=3.20.1)\n\n## Installation\n\n```bash\nnpm install svelte-select\n```\n\n## Usage\n\n```html\n<script>\n  import Select from 'svelte-select';\n\n  let items = [\n    {value: 'chocolate', label: 'Chocolate'},\n    {value: 'pizza', label: 'Pizza'},\n    {value: 'cake', label: 'Cake'},\n    {value: 'chips', label: 'Chips'},\n    {value: 'ice-cream', label: 'Ice Cream'},\n  ];\n\n  let value = {value: 'cake', label: 'Cake'};\n\n  function handleSelect(event) {\n    console.log('selected item', event.detail);\n    // .. do something here 🙂\n  }\n</script>\n\n<Select {items} {value} on:select={handleSelect}></Select>\n```\n\n## API\n\n- `id: String` Default: `null`. Add an id to the input field.\n- `items: Array` Default: `[]`. List of selectable items that appear in the dropdown.\n- `value: Any` Default: `null`. Selected item or items.\n- `filterText: String` Default: `''`. Text to filter `items` by.\n- `placeholder: String` Default: `'Select...'`. Placeholder text.\n- `noOptionsMessage: String` Default: `'No options'`. Message to display in list when there are no `items`.\n- `optionIdentifier: String` Default: `'value'`. Override default identifier.\n- `labelIdentifier: String` Default: `'label'`. Override default identifier.\n- `listOpen: Boolean` Default: `false`. Open/close list.\n- `hideEmptyState: Boolean` Default: `false`. Hide list and don't show `noOptionsMessage` when there are no `items`.\n- `containerClasses: String` Default: `''`. Add extra container classes, for example 'global-x local-y'.\n- `containerStyles: String` Default: `''`. Add inline styles to container.\n- `isClearable: Boolean` Default: `true`. Enable clearing of selected items.\n- `isCreatable: Boolean` Default: `false`. Can create new item(s) to be added to `value`.\n- `isDisabled: Boolean` Default: `false`. Disable select.\n- `isMulti: Boolean` Default: `false`. Enable multi-select, `value` becomes an array of selected items.\n- `isSearchable: Boolean` Default: `true`. Enable search/filtering of `items` via `filterText`.\n- `isGroupHeaderSelectable: Boolean` Default: `false`. Enable selectable group headers in `items` (see adv demo).\n- `listPlacement: String` Default: `'auto'`. When `'auto'` displays either `'top'` or `'bottom'` depending on viewport.\n- `hasError: Boolean` Default: `false`. Show/hide error styles around select input (red border by default).\n- `listAutoWidth: Boolean` Default: `true`. List width will grow wider than the Select container (depending on list item content length).\n- `showIndicator: Boolean` Default: `false`. If true, the chevron indicator is always shown.\n- `inputAttributes: Object` Default: `{}`. Pass in HTML attributes to the Select input.\n- `Item: Component` Default: `Item`. Item component.\n- `Selection: Component` Default: `Selection`. Selection component.\n- `Multi: Component` Default: `Multi`. Multi selection component.\n- `Icon: Component` Default: `Icon`. Icon component.\n- `iconProps: Object` Default: `{}`. Icon props.\n- `indicatorSvg: @html` Default: `undefined`. Override default SVG chevron indicator.\n- `ClearIcon` Default: `ClearIcon`. ClearIcon component.\n- `isVirtualList: Boolean` Default: `false`. Uses [svelte-virtual-list](https://github.com/sveltejs/svelte-virtual-list) to render list (experimental).\n- `filteredItems: Array` Default: `[]`. List of items that are filtered by `filterText`\n- `placeholderAlwaysShow: Boolean` Default: `false`. When `isMulti` then placeholder text will always still show.\n- `isWaiting: Boolean` Default: `false`. If true then loader shows. `loadOptions` will automatically set this as true until promise resolves.\n- `listOffset: Number` Default: `5`. Controls the spacing offset between the list and the input.\n\n### Items\n\n`items` can be simple arrays or collections.\n\n```html\n<script>\n  import Select from 'svelte-select';\n\n  let simple = ['one', 'two', 'three'];\n\n  let collection = [\n    { value: 1, label: 'one' },\n    { value: 2, label: 'two' },\n    { value: 3, label: 'three' },\n  ];\n</script>\n\n<Select items={simple} />\n\n<Select items={collection} />\n```\n\nThey can also be grouped and include non-selectable items.\n\n```html\n<script>\n  import Select from 'svelte-select';\n\n  const items = [\n    {value: 'chocolate', label: 'Chocolate', group: 'Sweet'},\n    {value: 'pizza', label: 'Pizza', group: 'Savory'},\n    {value: 'cake', label: 'Cake', group: 'Sweet', selectable: false},\n    {value: 'chips', label: 'Chips', group: 'Savory'},\n    {value: 'ice-cream', label: 'Ice Cream', group: 'Sweet'}\n  ];\n\n  const groupBy = (item) => item.group;\n</script>\n\n<Select {items} {groupBy} />\n\n```\n\nYou can also use custom collections.\n\n```html\n<script>\n  import Select from 'svelte-select';\n\n  const optionIdentifier = 'id';\n  const labelIdentifier = 'title';\n\n  const items = [\n    {id: 0, title: 'Foo'},\n    {id: 1, title: 'Bar'},\n  ];\n</script>\n\n<Select {optionIdentifier} {labelIdentifier} {items} />\n```\n\n### Async Items\n\nTo load items asynchronously then `loadOptions` is the simplest solution. Supply a function that returns a `Promise` that resolves with a list of items. `loadOptions` has debounce baked in and fires each time `filterText` is updated.\n\n```html\n<script>\n  import Select from 'svelte-select';\n\n  import { someApiCall } from './services';\n\n  async function examplePromise(filterText) {\n    // Put your async code here...\n    // For example call an API using filterText as your search params\n    // When your API responds resolve your Promise\n    let res = await someApiCall(filterText);\n    return res;\n  }\n</script>\n\n<Select loadOptions={examplePromise} />\n```\n\n### Exposed methods\nThese internal functions are exposed to override if needed. See the adv demo or look through the test file (test/src/index.js) for examples.\n\n```js\nexport let itemFilter = (label, filterText, option) => label.toLowerCase().includes(filterText.toLowerCase());\n```\n\n```js\nexport let groupBy = undefined;\n```\n\n```js\nexport let groupFilter = groups => groups;\n```\n\n```js\nexport let createGroupHeaderItem = groupValue => {\n  return {\n    value: groupValue,\n    label: groupValue\n  };\n};\n```\n\n```js\nexport let createItem = filterText => {\n  return {\n    value: filterText,\n    label: filterText\n  };\n};\n```\n\n```js\nexport let getOptionLabel = (option, filterText) => {\n  return option.isCreator ? `Create \\\"${filterText}\\\"` : option.label;\n};\n```\n\n```js\nexport let getSelectionLabel = option => {\n  if (option) return option.label;\n};\n```\n\n```js\nexport let getGroupHeaderLabel = option => {\n  return option.label;\n};\n```\n\n```js\nexport function handleClear() {\n  value = undefined;\n  listOpen = false;\n  dispatch(\"clear\", value);\n  handleFocus();\n}\n```\n\n```js\nexport let loadOptions = undefined; // if used must return a Promise that updates 'items'\n/* Return an object with { cancelled: true } to keep the loading state as active. */\n```\n\n```js\nexport const getFilteredItems = () => {\n  return filteredItems;\n};\n```\n\n## A11y (Accessibility)\n\nOverride these methods to change the `aria-context` and `aria-selection` text.\n\n```js\nexport let ariaValues = (values) => {\n  return `Option ${values}, selected.`;\n}\n\nexport let ariaListOpen = (label, count) => {\n  return `You are currently focused on option ${label}. There are ${count} results available.`;\n}\n\nexport let ariaFocused = () => {\n  return `Select is focused, type to refine list, press down to open the menu.`;\n}\n```\n\n## Styling\n\nYou can style a component by overriding [the available CSS variables](/docs/theming_variables.md).\n\n```html\n<script>\n  import Select from 'svelte-select';\n\n  const items = ['One', 'Two', 'Three'];\n</script>\n\n<style>\n  .themed {\n    --border: 3px solid blue;\n    --borderRadius: 10px;\n    --placeholderColor: blue;\n  }\n</style>\n\n<div class=\"themed\">\n  <h2>Theming</h2>\n  <Select {items}></Select>\n</div>\n```\n\nYou can also use the `inputStyles` prop to write in any override styles needed for the input.\n\n```html\n<script>\n  import Select from 'svelte-select';\n\n  const items = ['One', 'Two', 'Three'];\n</script>\n\n<Select {items} inputStyles=\"box-sizing: border-box;\"></Select>\n```\n\n## Events\n\n| Event Name | Callback | Description |\n|------|------|----------|\n| select | { detail } | fires when value changes\n| clear | { detail } | fires when clear all is invoked or item is removed (by user) from multi select\n| loaded | { items } | fires when `loadOptions` resolves\n| error | { type, details } | fires when error is caught\n\n```html\n<script>\n  import Select from 'svelte-select';\n\n  let items = [...];\n  function handleSelect(event) {\n    // event.detail will contain the selected value\n    ...\n  }\n  function handleClear(event) {\n    // event.detail will be null unless isMulti is true and user has removed a single item\n    ...\n  }\n</script>\n\n<Select {items} on:select={handleSelect} on:clear={handleClear}></Select>\n```\n\n## Development\n\n```bash\nyarn global add serve@8\nyarn\nyarn dev\nyarn test:browser\n```\n\nIn your favourite browser go to http://localhost:3000 and open devtools and see the console for the test output. When developing its handy to see the component on the page; comment out the `select.$destroy();` on the last test in /test/src/index.js or use the `test.only()` to target just one test.\n\nFor example:\n\n```js\ntest.only('when getSelectionLabel contains HTML then render the HTML', async (t) => {\n  const select = new Select({\n    target,\n    props: {\n      value: items[0],\n      getSelectionLabel: (option) => `<p>${option.label}</p>`,\n    }\n  });\n\n  t.ok(document.querySelector('.selection').innerHTML === '<p>Chocolate</p>');\n\n  //select.$destroy();\n});\n\n```\n\n\n## Configuring webpack\n\nIf you're using webpack with [svelte-loader](https://github.com/sveltejs/svelte-loader), make sure that you add `\"svelte\"` to [`resolve.mainFields`](https://webpack.js.org/configuration/resolve/#resolve-mainfields) in your webpack config. This ensures that webpack imports the uncompiled component — this is more efficient.\n\nIf you're using Rollup with [rollup-plugin-svelte](https://github.com/rollup/rollup-plugin-svelte), this will happen automatically.\n\n\n## License\n\n[LIL](LICENSE)\n","readmeFilename":"README.md","bugs":{"url":"https://github.com/rob-balfre/svelte-select/issues"},"homepage":"https://github.com/rob-balfre/svelte-select#readme","_id":"svelte-select@5.0.0-alpha.2","_nodeVersion":"16.2.0","_npmVersion":"7.13.0","dist":{"integrity":"sha512-umsnE+vkHQ6X2totVIhqgIbXOeygVvcp5YsvbhaFFicgOjptNj5Vf7GttE4JHf7S7G2ewO6NitKqVDjBBhtCYA==","shasum":"1be3db26d6b9267029594b06c7b4f39ec52cd0e2","tarball":"http://registry-npm.ywwl.com/svelte-select/download/svelte-select-5.0.0-alpha.2.tgz","fileCount":32,"unpackedSize":78500,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDui/kXi664vJxiUp9oXDxn8qIAzkiudd52OOycllPyWQIhALNPt1aMqXHkJQEcjOxjeruJutv37il8sv3iiSQAXpMk"}],"size":19767,"noattachment":false,"key":"/svelte-select/-/svelte-select-5.0.0-alpha.2.tgz"},"_npmUser":{"name":"rob-balfre","email":"rob.balfre@gmail.com"},"directories":{},"maintainers":[{"name":"rob-balfre","email":"rob.balfre@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/svelte-select_5.0.0-alpha.2_1636678552778_0.6571782763985858"},"_hasShrinkwrap":false,"publish_time":1636678552897,"_cnpm_publish_time":1636678552897,"dist-tags":{"alpha":"5.0.0-alpha.10","beta":"5.3.0-beta.7","latest":"6.0.0"}}