Skip to content

Commit bec1a70

Browse files
committed
feat: Added AdapSwiper and AdapExpansion
1 parent f0c3e0a commit bec1a70

11 files changed

+536
-2
lines changed

package-lock.json

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,23 @@
6363
},
6464
"dependencies": {
6565
"lodash.debounce": "^4.0.8",
66+
"css-element-queries": "^1.2.3",
6667
"vue": "^2.6.10",
6768
"vue-class-component": "^7.1.0",
6869
"vue-property-decorator": "^7.2.0"
6970
},
7071
"peerDependencies": {
7172
"@simpli/resource-collection": "1.0.8",
73+
"@simpli/vue-await": "^1.0.5",
7274
"class-transformer": "0.2.3",
73-
"simple-line-icons": "^2.4.1"
75+
"simple-line-icons": "^2.4.1",
76+
"swiper": "^6.1.1",
77+
"vue-awesome-swiper": "^4.1.1",
78+
"vue-transition-expand": "^0.1.0"
7479
},
7580
"devDependencies": {
7681
"@simpli/resource-collection": "1.0.8",
82+
"@simpli/vue-await": "^1.0.5",
7783
"@types/jest": "24.0.11",
7884
"@types/node": "10.11.7",
7985
"awesome-typescript-loader": "5.2.1",
@@ -97,6 +103,7 @@
97103
"simple-line-icons": "^2.4.1",
98104
"standard-version": "5.0.2",
99105
"strip-json-comments-cli": "1.0.1",
106+
"swiper": "^6.1.1",
100107
"ts-jest": "24.0.2",
101108
"ts-loader": "5.2.1",
102109
"tslint": "5.11.0",
@@ -105,9 +112,11 @@
105112
"tslint-react": "3.6.0",
106113
"typescript": "3.4.4",
107114
"validate-commit-msg": "2.14.0",
115+
"vue-awesome-swiper": "^4.1.1",
108116
"vue-jest": "2.6.0",
109117
"vue-loader": "15.4.2",
110118
"vue-template-compiler": "^2.6.10",
119+
"vue-transition-expand": "^0.1.0",
111120
"webpack": "4.41.5",
112121
"webpack-cli": "3.1.2"
113122
},

scss/adapExpansion.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.expansible {
2+
.expansible__content {
3+
@apply relative w-full;
4+
transition: height 1000ms ease-in-out;
5+
}
6+
}

scss/adapSwiper.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.adap-swiper {
2+
.adap-swiper__content {
3+
position: relative;
4+
user-select: none;
5+
}
6+
}
7+
8+
.swiper-container {
9+
.swiper-wrapper {
10+
box-sizing: border-box;
11+
}
12+
}

src/AdapExpansion.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
const template = `
2+
<div class="expansible">
3+
<slot name="header" />
4+
5+
<div ref="content" class="expansible__content">
6+
<div>
7+
<template v-if="collection.items && !collection.isEmpty()">
8+
<slot name="notEmpty" />
9+
</template>
10+
</div>
11+
12+
<await
13+
spinner="none"
14+
:name="spinner"
15+
class="await__spinner--screen-light"
16+
/>
17+
</div>
18+
19+
<div ref="bottom">
20+
<await :name="spinner" spinnerPadding="22.5px">
21+
<transition name="fade" mode="out-in">
22+
<div v-if="collection.items && collection.isEmpty()" :key="1">
23+
<slot name="empty" />
24+
</div>
25+
26+
<div v-else-if="!collection.isLastPage" :key="2">
27+
<slot name="expand" :expandEvent="expand" />
28+
</div>
29+
</transition>
30+
</await>
31+
</div>
32+
</div>
33+
`
34+
35+
import { Component, Prop, Watch, Vue } from 'vue-property-decorator'
36+
import { ResizeSensor } from 'css-element-queries'
37+
import { IResource } from '@simpli/resource-collection'
38+
import { ExpansibleCollection } from './ExpansibleCollection'
39+
40+
@Component({ template })
41+
export class AdapExpansion extends Vue {
42+
@Prop({ type: Object, required: true })
43+
collection!: ExpansibleCollection<IResource>
44+
@Prop({ type: String, default: 'list' })
45+
spinner!: string
46+
@Prop({ type: Boolean, default: true })
47+
autoScroll!: boolean
48+
49+
sensor: ResizeSensor | null = null
50+
51+
mounted() {
52+
const el = this.$refs.content as HTMLElement
53+
const elChild = el.childNodes[0] as HTMLElement
54+
this.sensor = new ResizeSensor(elChild, ({ height }: Record<string, number>) => this.refreshHeight(height))
55+
}
56+
57+
beforeDestroy() {
58+
if (this.sensor) {
59+
this.sensor.detach()
60+
this.sensor = null
61+
}
62+
}
63+
64+
async expand() {
65+
// @ts-ignore
66+
if (this.$await) {
67+
// @ts-ignore
68+
await this.$await.run(this.spinner, () => this.collection.expand())
69+
} else {
70+
await this.collection.expand()
71+
}
72+
73+
this.$emit('expand')
74+
75+
if (this.autoScroll) {
76+
const el = this.$refs.bottom as HTMLElement
77+
// @ts-ignore
78+
if (this.$scrollTo) {
79+
// @ts-ignore
80+
this.$scrollTo(el)
81+
}
82+
}
83+
}
84+
85+
async refreshHeight(height: number) {
86+
const el = this.$refs.content as HTMLElement
87+
el.style.height = `${height}px`
88+
el.style.overflow = 'hidden'
89+
await new Promise(resolve => setTimeout(resolve, 1000))
90+
el.style.overflow = 'unset'
91+
}
92+
}

0 commit comments

Comments
 (0)