From 9f401f8e8b8353e14e7bdf862a46db437afa9b2e Mon Sep 17 00:00:00 2001 From: Emanuel Saramago Date: Mon, 2 Dec 2024 18:23:04 +0000 Subject: [PATCH] Documentation for Svelte (#2262) * Documentation for Svelte #2261 * fix bracket --------- Co-authored-by: esaramago --- docs/_includes/sidebar.njk | 1 + docs/pages/frameworks/svelte.md | 85 +++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 docs/pages/frameworks/svelte.md diff --git a/docs/_includes/sidebar.njk b/docs/_includes/sidebar.njk index 11745e65..df0958bb 100644 --- a/docs/_includes/sidebar.njk +++ b/docs/_includes/sidebar.njk @@ -17,6 +17,7 @@
  • React
  • Vue
  • Angular
  • +
  • Svelte
  • diff --git a/docs/pages/frameworks/svelte.md b/docs/pages/frameworks/svelte.md new file mode 100644 index 00000000..0e11967b --- /dev/null +++ b/docs/pages/frameworks/svelte.md @@ -0,0 +1,85 @@ +--- +meta: + title: Svelte + description: Tips for using Shoelace in your Svelte app. +--- + +# Svelte + +Svelte [plays nice](https://custom-elements-everywhere.com/#svelte) with custom elements, so you can use Shoelace in your Svelte apps with ease. + +## Installation + +To add Shoelace to your Svelte app, install the package from npm. + +```bash +npm install @shoelace-style/shoelace +``` + +Next, [include a theme](/getting-started/themes) and set the [base path](/getting-started/installation#setting-the-base-path) for icons and other assets. In this example, we'll import the light theme and use the CDN as a base path. + +```jsx +// main.js or main.ts +import '@shoelace-style/shoelace/dist/themes/light.css'; +import { setBasePath } from '@shoelace-style/shoelace/dist/utilities/base-path'; + +setBasePath('https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@%VERSION%/%CDNDIR%/'); +``` + +:::tip +If you'd rather not use the CDN for assets, you can create a build task that copies `node_modules/@shoelace-style/shoelace/dist/assets` into a public folder in your app. Then you can point the base path to that folder instead. +::: + +## Usage + +### QR code generator example + +```jsx +

    Live editing

    + + message = event.target.value}> + + + + {message} + + + +``` + +### Two-way Binding + +One caveat is there's currently Svelte only supports `bind:value` directive in ``, `