Skip to content

Commit

Permalink
add vue types
Browse files Browse the repository at this point in the history
  • Loading branch information
break-stuff committed Dec 26, 2023
1 parent 7891dbe commit 43c045b
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 27 deletions.
7 changes: 7 additions & 0 deletions custom-elements-manifest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as path from 'path';
import { customElementJetBrainsPlugin } from 'custom-element-jet-brains-integration';
import { customElementVsCodePlugin } from 'custom-element-vs-code-integration';
import { customElementVuejsPlugin } from "custom-element-vuejs-integration";
import { parse } from 'comment-parser';
import { pascalCase } from 'pascal-case';
import commandLineArgs from 'command-line-args';
Expand Down Expand Up @@ -218,6 +219,12 @@ export default {
url: `https://shoelace.style/components/${tag.replace('sl-', '')}`
};
}
}),

customElementVuejsPlugin({
outdir: './dist/types/vue',
fileName: 'index.d.ts',
componentTypePath: (_, tag) => `../../components/${tag.replace('sl-', '')}/${tag.replace('sl-', '')}.component.js`,
})
]
};
41 changes: 14 additions & 27 deletions docs/pages/frameworks/vue.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,22 @@ If you'd rather not use the CDN for assets, you can create a build task that cop

## Configuration

You'll need to tell Vue to ignore Shoelace components. This is pretty easy because they all start with `sl-`.

```js
import { fileURLToPath, URL } from 'url';

import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';

// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue({
template: {
compilerOptions: {
isCustomElement: tag => tag.startsWith('sl-')
}
}
})
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
}
});
```
If you haven't configured your Vue.js project to work with custom elements/web components, follow [the instructions here](https://vuejs.org/guide/extras/web-components.html#using-custom-elements-in-vue) based on your project type to ensure your project will not throw an error when it encounters a custom element.

Now you can start using Shoelace components in your app!

## Types

Once you have configured you application for custom elements, you should be able to use Shoelace in your application without it causing any errors. Unfortunately, this doesn't register the custom elements to behave like components built using Vue. To provide autocomplete information and type-safety for your components, you can import the Shoelace Vue types into your `tsconfig.json` to get better integration in your standard Vue and JSX templates.

```json
{
"compilerOptions": {
"types": ["@shoelace-style/shoelace/dist/types/vue"],
},
}
```

## Usage

### QR code generator example
Expand Down Expand Up @@ -126,7 +113,7 @@ Are you using Shoelace with Vue? [Help us improve this page!](https://github.com

### Slots

To use Shoelace components with slots, follow the Vue documentation on using [slots with custom elements](https://vuejs.org/guide/extras/web-components.html#building-custom-elements-with-vue).
Slots in Shoelace/web components are functionally the same as basic slots in Vue. Slots can be assigned to elements using the `slot` attribute followed by the name of the slot it is being assigned to.

Here is an example:

Expand Down
42 changes: 42 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"cspell": "^6.18.1",
"custom-element-jet-brains-integration": "^1.4.0",
"custom-element-vs-code-integration": "^1.2.1",
"custom-element-vuejs-integration": "^1.0.0",
"del": "^7.1.0",
"download": "^8.0.0",
"esbuild": "^0.19.4",
Expand Down

0 comments on commit 43c045b

Please sign in to comment.