Skip to content

Commit 339a3c8

Browse files
committed
refactor(collapsible): removed animejs
1 parent f02fd3e commit 339a3c8

File tree

3 files changed

+29
-51
lines changed

3 files changed

+29
-51
lines changed

sass/components/_collapsible.scss

+13-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@
3131
}
3232
}
3333

34+
.collapsible-header::after {
35+
content: '';
36+
text-align: right;
37+
margin-right: 0.25rem;
38+
width: 100%;
39+
}
40+
.active .collapsible-header::after {
41+
content: "";
42+
}
43+
44+
3445
.keyboard-focused .collapsible-header:focus {
3546
background-color: $surface-focus-color-opaque;
3647
}
@@ -39,7 +50,8 @@
3950
display: none;
4051
border-bottom: 1px solid $collapsible-border-color;
4152
box-sizing: border-box;
42-
padding: 2rem;
53+
padding: 0 2rem;
54+
overflow: hidden;
4355
background-color: $collapsible-bg-color;
4456
}
4557

src/collapsible.ts

+16-49
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import anim from "animejs";
2-
31
import { Utils } from "./utils";
42
import { Component, BaseOptions, InitElements, MElement } from "./component";
53

@@ -144,64 +142,33 @@ export class Collapsible extends Component<CollapsibleOptions> {
144142
}
145143

146144
_animateIn(index: number) {
147-
const li = this.el.children[index];
145+
const li = <HTMLLIElement>this.el.children[index];
148146
if (!li) return;
149147
const body: HTMLElement = li.querySelector('.collapsible-body');
150-
anim.remove(body);
151148
body.style.display = 'block';
152-
body.style.overflow = 'hidden';
153-
body.style.height = '0';
154-
body.style.paddingTop = '';
155-
body.style.paddingBottom = '';
156-
const pTop = getComputedStyle(body).paddingTop; // . css('padding-top');
157-
const pBottom = getComputedStyle(body).paddingBottom; //body.css('padding-bottom');
158-
const finalHeight = body.scrollHeight;
159-
body.style.paddingTop = '0';
160-
body.style.paddingBottom = '0';
161-
anim({
162-
targets: body,
163-
height: finalHeight,
164-
paddingTop: pTop,
165-
paddingBottom: pBottom,
166-
duration: this.options.inDuration,
167-
easing: 'easeInOutCubic',
168-
complete: (anim) => {
169-
body.style.overflow = '';
170-
body.style.height = '';
171-
body.style.paddingTop = '';
172-
body.style.paddingBottom = '';
173-
// onOpenEnd callback
174-
if (typeof this.options.onOpenEnd === 'function') {
175-
this.options.onOpenEnd.call(this, li);
176-
}
149+
body.style.maxHeight = '0';
150+
const duration = this.options.inDuration; // easeInOutCubic
151+
body.style.transition = `max-height ${duration}ms ease-out`;
152+
body.style.maxHeight = body.scrollHeight + "px";
153+
setTimeout(() => {
154+
if (typeof this.options.onOpenEnd === 'function') {
155+
this.options.onOpenEnd.call(this, li);
177156
}
178-
});
157+
}, duration);
179158
}
180159

181160
_animateOut(index: number) {
182161
const li = this.el.children[index];
183162
if (!li) return;
184163
const body: HTMLElement = li.querySelector('.collapsible-body');
185-
anim.remove(body);
186-
body.style.overflow = 'hidden';
187-
anim({
188-
targets: body,
189-
height: 0,
190-
paddingTop: 0,
191-
paddingBottom: 0,
192-
duration: this.options.outDuration,
193-
easing: 'easeInOutCubic',
194-
complete: () => {
195-
body.style.overflow = '';
196-
body.style.height = '';
197-
body.style.padding = '';
198-
body.style.display = '';
199-
// onCloseEnd callback
200-
if (typeof this.options.onCloseEnd === 'function') {
201-
this.options.onCloseEnd.call(this, li);
202-
}
164+
const duration = this.options.outDuration; // easeInOutCubic
165+
body.style.transition = `max-height ${duration}ms ease-out`;
166+
body.style.maxHeight = "0";
167+
setTimeout(() => {
168+
if (typeof this.options.onCloseEnd === 'function') {
169+
this.options.onCloseEnd.call(this, li);
203170
}
204-
});
171+
}, duration);
205172
}
206173

207174
/**

src/modal.ts

-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ export class Modal extends Component<ModalOptions> {
241241
const isBottomSheet = this.el.classList.contains('bottom-sheet');
242242
if (!isBottomSheet) {
243243
this.el.style.top = this.options.endingTop;
244-
// this.el.style.transform = 'scaleX(0.9) scaleY(0.9)';
245244
}
246245

247246
// Overlay

0 commit comments

Comments
 (0)