Skip to content

Commit e61c38d

Browse files
authored
restructured (#6)
* restructured * beta update * matched number * .5 * fixed lenis * fixed watch * multi lenis * added single instance
1 parent 5d7a1cb commit e61c38d

File tree

11 files changed

+2042
-1673
lines changed

11 files changed

+2042
-1673
lines changed

README.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# Nuxt Lenis
2+
23
This is a Nuxt wrapper for [Lenis](https://lenis.studiofreight.com/) by [Studio Freight](https://studiofreight.com/). Thank them for the incredible tool.
34

45
## Getting Started
6+
57
1. `yarn add nuxt-lenis`
68
2. Add `nuxt-lenis` to your modules in nuxt.config
79
3. In your `app.vue` file, wrap the nuxt page in the lenis component
8-
```
10+
```
911
<lenis
1012
:options="LenisOptions"
1113
@initiated="foo"
@@ -15,3 +17,33 @@ This is a Nuxt wrapper for [Lenis](https://lenis.studiofreight.com/) by [Studio
1517
</lenis>
1618
```
1719

20+
## Composable
21+
22+
```
23+
const {scrollState, lenis} = useLenis()
24+
25+
watch(scrollState, (val) => {
26+
console.log("scrollState", val);
27+
},{deep:true});
28+
29+
```
30+
### Multiple Instances
31+
If you have multiple instances of Lenis you can get each one via an ID set ont he Lenis component
32+
```
33+
<lenis id="base" >
34+
<NuxtPage />
35+
</lenis>
36+
37+
<lenis id="modal" >
38+
<NuxtPage />
39+
</lenis>
40+
41+
<!-- script -->
42+
const {scrollState, lenis} = useLenis()
43+
44+
scrollState.value.base
45+
lenis.value.base
46+
scrollState.value.modal
47+
lenis.value.modal
48+
49+
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nuxt-lenis",
3-
"version": "1.0.8",
3+
"version": "1.1.0-beta.13",
44
"license": "MIT",
55
"type": "module",
66
"repository": {

playground/app.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@
1616
</template>
1717

1818
<script setup>
19+
// const { scrollState } = useLenis();
1920
21+
// watch(scrollState, (val) => {
22+
// console.log(val);
23+
// });
2024
</script>
2125

2226
<style>
2327
* {
2428
box-sizing: border-box;
25-
26-
2729
}
28-
body{
30+
body {
2931
margin: 0;
3032
}
3133

playground/nuxt.config.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import { defineNuxtConfig } from 'nuxt/config'
22
import MyModule from '..'
33

44
export default defineNuxtConfig({
5-
modules: [
6-
MyModule
7-
],
5+
modules: [MyModule],
86
myModule: {
97
addPlugin: true
108
}

playground/pages/index.vue

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,33 @@
1010
<div>
1111
<h2 @click="stop">STOP</h2>
1212
<h2 @click="start">START</h2>
13+
<h2 @click="changeOptions">CHANGE</h2>
1314
<p>Playground for lenis scroll plugin for nuxt</p>
1415
</div>
1516

16-
<div></div>
17-
<div></div>
18-
<div></div>
17+
<div />
18+
<div />
19+
<div />
1920
<!-- </div> -->
2021
</lenis>
2122
</template>
2223

2324
<script setup>
24-
import { ref, reactive, inject, watch, onMounted } from "vue";
25-
26-
const scrollState = inject("scrollState");
25+
import { ref, reactive, watch, onMounted } from "vue";
26+
import { useLenis } from "#imports";
27+
// import { useLenis } from "#app";
28+
const { scrollState, lenis:lenisN } = useLenis();
2729
const lenisRef = ref(null);
2830
const lenisVs = ref(false);
2931
const vsOptions = reactive({
30-
wrapper: "#wrapper",
32+
// wrapper: "#wrapper",
3133
touchMultiplier: 20,
3234
infinite: false,
3335
});
3436
35-
watch(scrollState, (val) => {
36-
console.log("scrollState", val);
37-
});
37+
// watch(()=>scrollState.value.wrapper, (val) => {
38+
// console.log("scrollState", val);
39+
// },{deep:true});
3840
3941
watch(vsOptions, (newVal) => {
4042
console.log("vsOptions newVal", newVal);

src/module.ts

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,48 @@
11
import {
2-
addComponent,
3-
defineNuxtModule,
4-
addPlugin,
5-
createResolver,
6-
addImports
7-
} from '@nuxt/kit'
2+
addComponent,
3+
defineNuxtModule,
4+
addPlugin,
5+
createResolver,
6+
addImports,
7+
} from "@nuxt/kit";
88

99
export interface ModuleOptions {
1010
addPlugin: boolean;
1111
}
1212

1313
export default defineNuxtModule<ModuleOptions>({
14-
meta: {
15-
name: '@nuxt-lenis',
16-
configKey: 'nuxtLenis',
17-
compatibility: {
18-
nuxt: '^3.0.0'
19-
}
20-
},
21-
defaults: {
22-
addPlugin: true
23-
},
24-
setup (options, nuxt) {
25-
const { resolve } = createResolver(import.meta.url)
26-
addImports([
27-
{
28-
name: 'default',
29-
as: 'Lenis',
30-
from: '@studio-freight/lenis'
31-
}
32-
])
33-
addImports([
34-
{
35-
name: 'useScrollState',
36-
as: 'useScrollState',
37-
from: resolve('./runtime/composables/useScrollState')
38-
}
39-
])
14+
meta: {
15+
name: "@milkshake/nuxt-lenis",
16+
configKey: "lenis",
17+
compatibility: {
18+
nuxt: "^3.0.0",
19+
},
20+
},
21+
defaults: {
22+
addPlugin: true,
23+
},
24+
setup(options, nuxt) {
25+
const { resolve } = createResolver(import.meta.url);
26+
addImports([
27+
{
28+
name: "default",
29+
as: "Lenis",
30+
from: "@studio-freight/lenis",
31+
},
32+
]);
33+
addPlugin(resolve("./runtime/plugin"));
4034

41-
addPlugin(resolve('./runtime/plugin'))
42-
addComponent({
43-
name: 'lenis', // name of the component to be used in vue templates
44-
filePath: resolve('./runtime/components', 'lenis.vue') // resolve(runtimeDir, 'components', 'MyComponent.vue')
45-
})
46-
}
47-
})
35+
addImports([
36+
{
37+
name: "useLenis",
38+
as: "useLenis",
39+
from: resolve("./runtime/composables/useLenis"),
40+
},
41+
]);
42+
43+
addComponent({
44+
name: "Lenis", // name of the component to be used in vue templates
45+
filePath: resolve("./runtime/components", "Lenis.vue"), // resolve(runtimeDir, 'components', 'MyComponent.vue')
46+
});
47+
},
48+
});

0 commit comments

Comments
 (0)