svelte.mdx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. ---
  2. slug: /svelte
  3. ---
  4. import Tabs from '@theme/Tabs';
  5. import TabItem from '@theme/TabItem';
  6. # Svelte
  7. [Svelte][] components for the Uppy UI plugins.
  8. ## Install
  9. <Tabs>
  10. <TabItem value="npm" label="NPM" default>
  11. ```shell
  12. npm install @uppy/svelte
  13. ```
  14. </TabItem>
  15. <TabItem value="yarn" label="Yarn">
  16. ```shell
  17. yarn add @uppy/svelte
  18. ```
  19. </TabItem>
  20. </Tabs>
  21. :::note
  22. You also need to install the UI plugin you want to use. For instance,
  23. `@uppy/dashboard`.
  24. :::
  25. ## Use
  26. The following plugins are available as Svelte component wrappers:
  27. - `<Dashboard />` renders [`@uppy/dashboard`](/docs/dashboard)
  28. - `<DragDrop />` renders [`@uppy/drag-drop`](/docs/drag-drop)
  29. - `<ProgressBar />` renders [`@uppy/progress-bar`](/docs/progress-bar)
  30. - `<StatusBar />` renders [`@uppy/status-bar`](/docs/status-bar)
  31. Instead of adding a UI plugin to an Uppy instance with `.use()`, the Uppy
  32. instance can be passed into components as an `uppy` prop. Due to the way Svelte
  33. handles reactivity, you can initialize Uppy the same way you would with vanilla
  34. JavaScript.
  35. ```html
  36. <script>
  37. import { Dashboard } from '@uppy/svelte';
  38. import Uppy from '@uppy/core';
  39. import Webcam from '@uppy/webcam';
  40. // Don't forget the CSS: core and UI components + plugins you are using
  41. import '@uppy/core/dist/style.css';
  42. import '@uppy/dashboard/dist/style.css';
  43. import '@uppy/webcam/dist/style.css';
  44. const uppy = new Uppy().use(Webcam);
  45. </script>
  46. <main><Dashboard uppy={uppy} plugins={["Webcam"]} /></main>
  47. ```
  48. [svelte]: https://svelte.dev