Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: using baklava in vue doc added #148

Merged
merged 4 commits into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const parameters = {
options: {
storySort: {
method: 'alphabetical',
order: ['Documentation', ['Welcome', '*'], 'Components', 'Design System'],
order: ['Documentation', ['Welcome', '*'], 'Frameworks', 'Components', 'Design System'],
locales: 'en-US',
},
},
Expand Down
96 changes: 96 additions & 0 deletions docs/using-baklava-in-vue.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { Meta } from '@storybook/addon-docs';

<Meta
title="Frameworks/Vue"
parameters={{
viewMode: 'docs',
previewTabs: {
canvas: {
hidden: true,
},
},
}}
/>

# Using Baklava in Vue

Vue is mostly [compatible](https://custom-elements-everywhere.com/#vue) with custom elements.

## Installation

To add Baklava in your app, you can either import it via CDN or npm package. But one way or another, you should tell Vue to ignore custom elements.

To make the rule more generic, easiest way is ignoring the elements start with `bl-` tag. Thanks to that, every baklava element will be ignored by the Vue.
leventozen marked this conversation as resolved.
Show resolved Hide resolved

### Via CDN

To be able to use Baklava via CDN, you should add our default.css and baklava.js at head tag in your index.html file.

> Baklava is currently in beta version. So, if you want to keep updated for new changes, you can add `@beta` tag like the example below.
However, you can simply use any version you want by adding the version number.

```html
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@trendyol-js/baklava@beta/dist/themes/default.css" />
<script type="module" src="https://cdn.jsdelivr.net/npm/@trendyol-js/baklava@beta"></script>
leventozen marked this conversation as resolved.
Show resolved Hide resolved
```

### Via NPM

To be able to use Baklava via npm, run ```npm install @trendyol-js/baklava```
leventozen marked this conversation as resolved.
Show resolved Hide resolved
then,
```js
leventozen marked this conversation as resolved.
Show resolved Hide resolved
@import "@trendyol-js/baklava/dist/themes/default.css";
import { setIconPath } from '@trendyol-js/baklava'
leventozen marked this conversation as resolved.
Show resolved Hide resolved
setIconPath('https://cdn.jsdelivr.net/npm/@trendyol-js/baklava@latest/dist/assets')
leventozen marked this conversation as resolved.
Show resolved Hide resolved
```

#### Vue2
If you use Vue2, you should add ```Vue.config.ignoredElements = [/^bl-/]``` in your main.js.
leventozen marked this conversation as resolved.
Show resolved Hide resolved

#### Vue3
leventozen marked this conversation as resolved.
Show resolved Hide resolved
If you use Vue3, you can add this
leventozen marked this conversation as resolved.
Show resolved Hide resolved
```
app.config.compilerOptions.isCustomElement = tag => tag.startsWith('bl-');
```
in your main.js before Vue mounts the app.
leventozen marked this conversation as resolved.
Show resolved Hide resolved
Also, you can add ignore rule as compiler options to your webpack or vite.

```js
isCustomElement: tag => tag.startsWith('sl-')
```
For Vite:
```
plugins: [
vue({
template: {
compilerOptions: {
isCustomElement: tag => tag.startsWith('sl-')
}
}
})
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
}

```

For Webpack with `vue-loader`:

leventozen marked this conversation as resolved.
Show resolved Hide resolved
```
leventozen marked this conversation as resolved.
Show resolved Hide resolved
{
test: /\.vue$/,
use: {
loader: "vue-loader",
options: {
compilerOptions: {
isCustomElement: tag => {
return tag === "custom";
}
}
}
}
}
```