{"name":"svelte-select","version":"4.2.8-beta.0","repository":{"type":"git","url":"git+https://rob-balfre@github.com/rob-balfre/svelte-select.git"},"description":"A <Select> component for Svelte apps","svelte":"src/index.js","module":"dist/index.mjs","main":"dist/index.js","types":"./src/index.d.ts","scripts":{"build":"rollup -c","dev":"rollup -cw","prepublishOnly":"npm run build","test":"node test/runner.js","test:browser":"npm run build && serve test/public","test:playwright":"playwright test","gen:docs":"node docs/generate_theming_variables_md.js","pretest":"npm run build"},"devDependencies":{"@babel/polyfill":"7.12.1","@playwright/test":"1.12.3","find-in-files":"^0.5.0","playwright-chromium":"1.12.3","port-authority":"^1.0.5","puppeteer":"^1.9.0","rollup":"^2.41.2","rollup-plugin-cleaner":"^1.0.0","rollup-plugin-css-only":"^3.1.0","rollup-plugin-node-resolve":"^5.2.0","rollup-plugin-serve":"1.1.0","rollup-plugin-svelte":"^7.1.0","rollup-plugin-terser":"^7.0.2","sirv":"^0.2.2","svelte":"^3.38.3","tap-diff":"^0.1.1","tap-dot":"^2.0.0","tape-modern":"^1.1.1"},"author":{"name":"rob-balfre"},"license":"LIL","keywords":["svelte"],"readme":"# svelte-select\n\nA select/autocomplete component for Svelte apps.  With support for grouping, filtering, async and more.\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\nyarn add svelte-select\n```\n\n**Note:** Install as a dev dependency (yarn add svelte-select --dev) if using [Sapper](https://sapper.svelte.dev/) to avoid a SSR error.\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\n## API\n\n- `items: Array` Default: `[]`. List of selectable items that appear in the dropdown.\n- `value: Any` Default: `undefined`. 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: `{}`. Useful for passing in HTML attributes like `'id'` to the Select input.\n- `Item: Component` Default: `Item`. Item component.\n- `Selection: Component` Default: `Selection`. Selection component.\n- `MultiSelection: Component` Default: `MultiSelection`. 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### Exposed methods\nIf you really want to get your hands dirty these internal functions are exposed as props 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; // see adv demo for example\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## 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","gitHead":"aaa44213ffb6d56acc337e33f08bbf18b08b9c88","bugs":{"url":"https://github.com/rob-balfre/svelte-select/issues"},"homepage":"https://github.com/rob-balfre/svelte-select#readme","_id":"svelte-select@4.2.8-beta.0","_nodeVersion":"16.2.0","_npmVersion":"7.13.0","dist":{"integrity":"sha512-HjOGRTivPT3gmUzqKdeWNn8NHVZrDRjpSnx+eNo3Gf2xPkyicvhI9iPAoQbiLLOtewHoLShAY7L2bWDBuAanYg==","shasum":"55cdb061e4888335e305ec2d0be31a1bf4669d90","tarball":"http://registry-npm.ywwl.com/svelte-select/download/svelte-select-4.2.8-beta.0.tgz","fileCount":17,"unpackedSize":158954,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhAekkCRA9TVsSAnZWagAAhtcP/1RPaoSwO3gZ8/+P6tAe\n7pI/z2YW6B+IYBZaSsn5uHcVRhVO0WdhE8XkcZowdJmh8PIbX2FC10j2BZBm\ntbUTb5EKW5x8upW+6jMYEgVRO3CZekztPco/z4F1RnoeLsVEm3XmgegKKwBe\nBGiHonZsyazhs2aQpzuED/j9fkfpGkKJE8AwZ9mU7ulKCJjCu472Bp+WApzU\nxVJxwOkjCeZlJ6EvNwN8b6EJ1iYMn2GWs3odnIbp8UI/y3ebAE+nym0IruNw\nkPjpwSvZQkLjtK6pyZ773qi2ICkvExBxA6AnzwNJc3DVH4leyAUXCU2TQGVH\nVOQwc0eW7c3C4W4FTv1nLEDLUVA+z655zpBT8t/ep98E6/NFXafJrwfZifKI\nbKvJkr062aXpU0vETxcKYOdHeJzXBPZXPgNhDbIdEckoWLwyWngZrHJRuB3P\njdqolZCo/zCEadXOwOsZ03TPkKXDes/uvFiRCLU6ZUE04UtVHYXSQUzbJClQ\nLxsAnOoxTrE9Unu7SZFJox6rF9Z3RzpXkfkHX9yC1617GghCa4OdAei77Ggt\n+2YuZ8IORle1YK2xNmx1YJ1Z06m/Udk8eb6t9xp7XfoE1x0iGUwpVA56rqO7\nxgHaQfCwMOikKAfVEN4lrVGYkowcgCAuUp6xhjn2rw52cA1xzJOMGMw/704E\nAsso\r\n=cLne\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGswbxsUwMATUQqLT1iRKTVdX81sdPyELzSY2aS9HHAmAiEA1l2gWOQ8LZ4qbdvgCsagMPQLxIjjyH1Q1LwKsIhX2Xk="}],"size":46686,"noattachment":false,"key":"/svelte-select/-/svelte-select-4.2.8-beta.0.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_4.2.8-beta.0_1627515172365_0.4448705644801667"},"_hasShrinkwrap":false,"publish_time":1627515172508,"_cnpm_publish_time":1627515172508,"dist-tags":{"alpha":"5.0.0-alpha.10","beta":"5.3.0-beta.7","latest":"6.0.0"}}