Skip to content

Commit 997f2b2

Browse files
committed
docs: update docs for v2.0.0
1 parent 534d7b7 commit 997f2b2

File tree

6 files changed

+194
-74
lines changed

6 files changed

+194
-74
lines changed

README.md

+97-26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# @blokwise/dynamic
22

3-
Read the official [docs](https://dynamic.blokwise.io)
3+
Let Nuxt auto-import your dynamic components with a breeze - automagically.
4+
5+
- Extends nuxt/component
6+
- Auto-importing of dynamic components
7+
- Easily hydrate your dynamic components on the fly
8+
9+
Starting with `v2.0.0`, this module only works with `nuxt v3`. To use this module with `nuxt v2` and [`@nuxt/components`](https://www.npmjs.com/package/@nuxt/components) use `v1.5.0` (or lower).
10+
11+
Read the official [docs](https://dynamic.blokwise.io).
412

513
## Installation
614

@@ -24,52 +32,115 @@ Then, add `@blokwise/dynamic` to the `modules` section of `nuxt.config.js`:
2432
}
2533
```
2634

35+
Use a different prefix for your `Dynamic` component if you like (default is `NuxtDynamic`). e.g. if you want to use the component as `HyperDynamic`:
36+
37+
```js[nuxt.config.js]
38+
{
39+
modules: [
40+
'@blokwise/dynamic', {
41+
prefix: 'Hyper'
42+
}
43+
],
44+
}
45+
```
46+
2747
## Props
2848

29-
### `component`
49+
### `isComponent`
3050

3151
- **Type**: `String`
3252

33-
The name of the component which should be imported.
34-
If the component was initialized with a prefix in `@nuxt/components` config, it should be loaded as such. Nevertheless it is possible to **ommit the prefix to automatically detect the right component** _(if there are no conflincting names)_.
53+
The name of the component which should be imported and rendered as registered by nuxt. The component name can be passed in PascalCase, snake_case or kebab-case.
3554

36-
_**Heads up**: Starting with version `v1.4.0` the prop `component` replaces the deprecated prop `name`.
37-
Passing the component name by using `name` still works through `$attrs.name` internally.
38-
However, this workaround will be removed in the next major version (`v.2.0.0+`)._
55+
### `never`
3956

40-
### `hydration`
57+
- **Type**: `Boolean`
58+
- **Default**: `false`
4159

42-
- **Type**: `String`
43-
- **Default**: `'WhenIdle'`
44-
- _Options_: `'WhenIdle'`, `'WhenVisible'`, `'OnInteraction'`, `'Never'`
60+
If `true`, the component gets never hydrated.
4561

46-
The hydration prop controls **when / how the component will be hydrated**. The hydration is implemented with `vue-lazy-hydration` thanks to [Markus Oberlehner](https://github.com/maoberlehner/vue-lazy-hydration).
62+
### `whenIdle`
4763

48-
### `componentRef`
64+
- **Type**: `[Booelan, Number]`
65+
- **Default**: `null`
66+
67+
If `true`, component gets hydrated when browser is idle (or after default timeout of 2000ms).
68+
If `Number` is passed, it'll be used as max timeout to start hydration.
4969

50-
- **Type**: `String` or `Number`
70+
### `whenVisible`
71+
72+
- **Type**: `[Number, Object]`
5173
- **Default**: `null`
5274

53-
The componentRef prop adds a reference to the child component.
75+
If `true`, the component gets hydrated when visible.
76+
If custom configuration for Intersection Observer API is needed, an `Object` can be passed. The configuration needs to be defined according to [Official Intersection Observer API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API).
5477

55-
## Usage
78+
### `on`
5679

57-
### Use dynamic component
80+
- **Type**: `[Boolean, Array, String]`
81+
- **Default**: `null`
5882

59-
The dynamic component will be loaded as `NuxtDynamic`. The component will be loaded wheter you pass the name prefix or not. So in the following case it could load a component called `Logo` without prefix or a component called `BlokwiseLogo` which is prefixed with `Blokwise` according to `@nuxt/components` configuration of your project / third party libraries.
83+
If `true`, the component gets hydrated on event 'focus'.
84+
If you want to define custom events pass the event names as `String` or `Array` to hydrate the component when events are triggered.
6085

61-
```vue
62-
<template>
63-
<NuxtDynamic component="Logo" />
64-
</template>
65-
```
86+
### `hydration`
87+
88+
- **Type**: `Object`
89+
- **Default**: `() => ({})`
6690

67-
### Load the component lazily
91+
The hydration prop controls **when / how the component will be hydrated** and can be assigned dynamically. The object passed:
92+
- needs to have a property `type` as String (`'never'`, `'whenIdle'`, `'whenVisible'`, `'on'`)
93+
- and optionally can have a property `options` to define further config as described in the above component props (e.g. if `type` is `whenIdle`, `options` could be used to set the max timeout to `7000`).
6894

69-
The dynamic component can be loaded lazily as `LazyNuxtDynamic`.
95+
## NuxtDynamic
7096

97+
Use `NuxtDynamic` to **auto import any component** _dynamically_ which is registered by nuxt. If you want to ommit the hydration and load the component instantly (tho lazily / async), ommit any hydration prop such as `never`, `when-idle`, `when-visible` or `on`.
98+
99+
Some example of how to use the component:
71100
```vue
72101
<template>
73-
<LazyNuxtDynamic component="Logo" />
102+
<NuxtDynamic is-component="Logo" />
103+
104+
<NuxtDynamic is-component="Logo">
105+
<span>using the default slot as expected</span>
106+
</NuxtDynamic>
107+
108+
<NuxtDynamic
109+
v-for="(componentName, i) in ['Logo', 'Grid', 'Nav']"
110+
:key="i"
111+
:is-component="componentName"
112+
/>
113+
114+
<!-- hydration -->
115+
<NuxtDynamic is-component="Logo" never />
116+
117+
<NuxtDynamic is-component="Logo" when-idle />
118+
119+
<NuxtDynamic is-component="Logo" :when-idle="4000" />
120+
121+
<NuxtDynamic is-component="Logo" when-visible />
122+
123+
<NuxtDynamic is-component="Logo" :when-visible="{
124+
rootMargin: '120px',
125+
threshold: 1.0
126+
}" />
127+
128+
<NuxtDynamic is-component="Logo" on />
129+
130+
<NuxtDynamic is-component="Logo" on="mouseover" />
131+
132+
<NuxtDynamic is-component="Logo" :on="['mouseover', 'click']" />
133+
134+
<NuxtDynamic is-component="Logo" :hydration="{
135+
type: 'whenVisible',
136+
options: {
137+
rootMargin: '120px',
138+
threshold: 1.0
139+
}
140+
}" />
74141
</template>
75142
```
143+
144+
## Credits
145+
146+
All the hydration magic is implemented with `vue3-lazy-hydration` thanks to [freddy38510](https://github.com/freddy38510/vue3-lazy-hydration).

docs/content/en/index.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
---
22
title: Introduction
3-
description: "Dynamic components for @nuxt/components"
3+
description: "Dynamic components for nuxt v3"
44
position: 1
55
category: ""
66
features:
77
- Extends nuxt/component
88
- Auto-importing of dynamic components
9+
- Easily hydrate your dynamic components on the fly
910
---
1011

1112
<img src="/preview.png" class="light-img" width="1280" height="640" alt=""/>
@@ -21,6 +22,8 @@ Let Nuxt auto-import your dynamic components with a breeze - automagically.
2122

2223
<list :items="features"></list>
2324

24-
This `nuxt.js` module only works with [`@nuxt/components`](https://www.npmjs.com/package/@nuxt/components).
25+
<alert type="info">
26+
Starting with <code>v2.0.0</code>, this module only works with <code>nuxt v3</code>. To use this module with <code>nuxt v2</code> and <a href="https://www.npmjs.com/package/@nuxt/components"><code>@nuxt/components</code></a> use <code>v1.5.0</code> (or lower).
27+
</alert>
2528

2629
<p class="flex items-center">Enjoy light and dark mode:&nbsp;<app-color-switcher class="inline-flex ml-2"></app-color-switcher></p>

docs/content/en/setup.md

+12
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,16 @@ Then, add `@blokwise/dynamic` to the `modules` section of `nuxt.config.js`:
3636
}
3737
```
3838

39+
Use a different prefix for your `Dynamic` component if you like (default is `NuxtDynamic`). e.g. if you want to use the component as `HyperDynamic`:
40+
41+
```js[nuxt.config.js]
42+
{
43+
modules: [
44+
'@blokwise/dynamic', {
45+
prefix: 'Hyper'
46+
}
47+
],
48+
}
49+
```
50+
3951
Check the [Nuxt.js documentation](https://nuxtjs.org/guides/configuration-glossary/configuration-modules) for more information about installing and using modules in Nuxt.js.

docs/content/en/usage.md

+77-43
Original file line numberDiff line numberDiff line change
@@ -7,75 +7,109 @@ category: Guide
77

88
## Props
99

10-
### `component`
10+
### `isComponent`
1111

12-
- **Type**: `String`
12+
- Type: `String`
1313

14-
The name of the component which should be imported.
15-
If the component was initialized with a prefix in `@nuxt/components` config, it should be loaded as such. Nevertheless it is possible to **ommit the prefix to automatically detect the right component** _(if there are no conflincting names)_.
14+
The name of the component which should be imported and rendered as registered by nuxt. The component name can be passed in PascalCase, snake_case or kebab-case.
1615

1716
<alert type="info">
18-
<b>
19-
<i class="font-light"><span class="font-bold">Heads up</span>: Starting with version <code>v1.4.0</code> the prop <code>component`</code> replaces the deprecated prop <code>name</code>.
20-
Passing the component name by using <code>name</code> still works through <code>$attrs.name</code> internally.
21-
However, this workaround will be removed in the next major version (<code>v.2.0.0+</code>).</i>
17+
<p>
18+
<i class="font-light"><span class="font-bold">Heads up</span>: Starting with version <code>v2.0.0</code> the prop <code>isComponent`</code> replaces the deprecated prop <code>component</code>.
19+
Passing the component name by using <code>component</code> still works through <code>$attrs.component</code> internally.
20+
However, this workaround will be removed in the next major version (<code>v3.0.0+</code>).</i>
2221
</p>
2322
</alert>
2423

25-
### `hydration`
24+
### `never`
2625

27-
- **Type**: `String`
28-
- **Default**: `'WhenIdle'`
29-
- _Options_: `'WhenIdle'`, `'WhenVisible'`, `'OnInteraction'`, `'Never'`
26+
- Type: `Boolean`
27+
- Default: `false`
3028

31-
The hydration prop controls **when / how the component will be hydrated**. The hydration is implemented with `vue-lazy-hydration` thanks to [Markus Oberlehner](https://github.com/maoberlehner/vue-lazy-hydration).
29+
If `true`, the component gets never hydrated.
3230

33-
### `componentRef`
31+
### `whenIdle`
3432

35-
- **Type**: `String` or `Number`
36-
- **Default**: `null`
33+
- Type: `[Booelan, Number]`
34+
- Default: `null`
3735

38-
The componentRef prop adds a reference to the child component.
36+
If `true`, component gets hydrated when browser is idle (or after default timeout of 2000ms).
37+
If `Number` is passed, it'll be used as max timeout to start hydration.
3938

40-
## NuxtDynamic
39+
### `whenVisible`
4140

42-
Use `NuxtDynamic` to **auto import any component** which is initialized through `@nuxt/components` _dynamically_.
41+
- Type: `[Number, Object]`
42+
- Default: `null`
4343

44-
```vue
45-
<template>
46-
<NuxtDynamic component="Logo" />
44+
If `true`, the component gets hydrated when visible.
45+
If custom configuration for Intersection Observer API is needed, an `Object` can be passed. The configuration needs to be defined according to [Official Intersection Observer API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API).
4746

48-
<NuxtDynamic
49-
v-for="(component, i) in ['Logo', 'Grid', 'Nav']"
50-
:key="i"
51-
:component="component"
52-
/>
53-
</template>
54-
```
47+
### `on`
5548

56-
## LazyNuxtDynamic
49+
- Type: `[Boolean, Array, String]`
50+
- Default: `null`
5751

58-
Use `LazyNuxtDynamic` if you want the component itself being imported lazily.
52+
If `true`, the component gets hydrated on event 'focus'.
53+
If you want to define custom events pass the event names as `String` or `Array` to hydrate the component when events are triggered.
5954

60-
```vue
61-
<template>
62-
<LazyNuxtDynamic component="Logo" />
63-
</template>
64-
```
55+
### `hydration`
56+
57+
- Type: `Object`
58+
- Default: `() => ({})`
6559

60+
The hydration prop controls **when / how the component will be hydrated** and can be assigned dynamically. The object passed:
61+
- needs to have a property `type` as String (`'never'`, `'whenIdle'`, `'whenVisible'`, `'on'`)
62+
- and optionally can have a property `options` to define further config as described in the above component props (e.g. if `type` is `whenIdle`, `options` could be used to set the max timeout to `7000`).
6663

67-
## Assign Ref to child component
64+
## NuxtDynamic
6865

69-
Use `componentRef` to assign a `ref` to the child component.
66+
Use `NuxtDynamic` to **auto import any component** _dynamically_ which is registered by nuxt. If you want to ommit the hydration and load the component instantly (tho lazily / async), ommit any hydration prop such as `never`, `when-idle`, `when-visible` or `on`.
7067

68+
Some example of how to use the component:
7169
```vue
7270
<template>
73-
<NuxtDynamic component="Logo" componentRef="logoChild" ref="logo" />
71+
<NuxtDynamic is-component="Logo" />
72+
73+
<NuxtDynamic is-component="Logo">
74+
<span>using the default slot as expected</span>
75+
</NuxtDynamic>
76+
77+
<NuxtDynamic
78+
v-for="(componentName, i) in ['Logo', 'Grid', 'Nav']"
79+
:key="i"
80+
:is-component="componentName"
81+
/>
82+
83+
<!-- hydration -->
84+
<NuxtDynamic is-component="Logo" never />
85+
86+
<NuxtDynamic is-component="Logo" when-idle />
87+
88+
<NuxtDynamic is-component="Logo" :when-idle="4000" />
89+
90+
<NuxtDynamic is-component="Logo" when-visible />
91+
92+
<NuxtDynamic is-component="Logo" :when-visible="{
93+
rootMargin: '120px',
94+
threshold: 1.0
95+
}" />
96+
97+
<NuxtDynamic is-component="Logo" on />
98+
99+
<NuxtDynamic is-component="Logo" on="mouseover" />
100+
101+
<NuxtDynamic is-component="Logo" :on="['mouseover', 'click']" />
102+
103+
<NuxtDynamic is-component="Logo" :hydration="{
104+
type: 'whenVisible',
105+
options: {
106+
rootMargin: '120px',
107+
threshold: 1.0
108+
}
109+
}" />
74110
</template>
75111
```
76112

77-
This allows you to call methods on the child component or access its data:
113+
## Credits
78114

79-
```js
80-
this.$refs.logo.$refs.logoChild
81-
```
115+
All the hydration magic is implemented with `vue3-lazy-hydration` thanks to [freddy38510](https://github.com/freddy38510/vue3-lazy-hydration).

docs/nuxt.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import theme from '@nuxt/content-theme-docs'
22

33
export default theme({
44
docs: {
5-
primaryColor: '#32a6e0',
6-
},
5+
primaryColor: '#32a6e0'
6+
}
77
})

docs/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@blokwise/dynamic",
3-
"version": "1.0.0",
3+
"version": "2.0.0",
44
"private": true,
55
"scripts": {
66
"dev": "nuxt",

0 commit comments

Comments
 (0)