lupine.components 1.1.2 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/components/action-sheet.tsx +13 -7
- package/src/components/mobile-components/mobile-header-title-icon.tsx +8 -2
- package/src/components/mobile-components/mobile-header-with-back.tsx +6 -2
- package/src/components/mobile-components/mobile-side-menu.tsx +5 -1
- package/src/frames/slider-frame.tsx +3 -3
- package/src/lib/back-action-helper.ts +54 -0
- package/src/lib/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CssProps, RefProps, VNode, mountInnerComponent } from 'lupine.web';
|
|
2
|
+
import { backActionHelper } from '../lib';
|
|
2
3
|
|
|
3
4
|
export type ActionSheetCloseProps = () => void;
|
|
4
5
|
|
|
@@ -125,16 +126,21 @@ export class ActionSheet {
|
|
|
125
126
|
},
|
|
126
127
|
};
|
|
127
128
|
const component = (
|
|
128
|
-
<div
|
|
129
|
+
<div
|
|
130
|
+
css={cssContainer}
|
|
131
|
+
class='act-sheet-box'
|
|
132
|
+
onClick={onClickContainer}
|
|
133
|
+
data-back-action={backActionHelper.genBackActionId()}
|
|
134
|
+
>
|
|
129
135
|
<div ref={ref} class='act-sheet-body'>
|
|
130
136
|
<div class='act-sheet-content'>
|
|
131
137
|
<div class='act-sheet-title'>{title}</div>
|
|
132
138
|
{children}
|
|
133
139
|
{confirmButtonText && (
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
140
|
+
<div class='act-sheet-bottom-item act-sheet-confirm' onClick={onConfirm}>
|
|
141
|
+
{confirmButtonText}
|
|
142
|
+
</div>
|
|
143
|
+
)}
|
|
138
144
|
</div>
|
|
139
145
|
{cancelButtonText && (
|
|
140
146
|
<div class='act-sheet-bottom-item' onClick={onCancel}>
|
|
@@ -210,11 +216,11 @@ export class ActionSheetMessage {
|
|
|
210
216
|
}: ActionSheetMessageProps): Promise<ActionSheetCloseProps> {
|
|
211
217
|
const handleClose = await ActionSheet.show({
|
|
212
218
|
title,
|
|
213
|
-
children: <div css={{ padding: '8px',borderTop: '1px solid var(--primary-border-color)'
|
|
219
|
+
children: <div css={{ padding: '8px', borderTop: '1px solid var(--primary-border-color)' }}>{message}</div>,
|
|
214
220
|
contentMaxHeight,
|
|
215
221
|
confirmButtonText,
|
|
216
222
|
handleConfirmClicked,
|
|
217
|
-
|
|
223
|
+
cancelButtonText,
|
|
218
224
|
closeWhenClickOutside,
|
|
219
225
|
});
|
|
220
226
|
return handleClose;
|
|
@@ -2,11 +2,17 @@
|
|
|
2
2
|
MobileHeaderTitleIcon can be used in MobileHeaderComponent's Center part.
|
|
3
3
|
It has it's own Left and Right icons.
|
|
4
4
|
*/
|
|
5
|
-
import { VNode, CssProps, HtmlVar } from 'lupine.components';
|
|
5
|
+
import { VNode, CssProps, HtmlVar, backActionHelper } from 'lupine.components';
|
|
6
6
|
|
|
7
7
|
export const MobileHeadeIconHeight = '40px';
|
|
8
8
|
export const MobileHeadeBackIcon = ({ onClick }: { onClick: (event: Event) => void }) => {
|
|
9
|
-
return
|
|
9
|
+
return (
|
|
10
|
+
<i
|
|
11
|
+
class={'ifc-icon mg-arrow_back_ios_new_outlined mhti-back-icon'}
|
|
12
|
+
data-back-action={backActionHelper.genBackActionId()}
|
|
13
|
+
onClick={(event) => onClick(event)}
|
|
14
|
+
></i>
|
|
15
|
+
);
|
|
10
16
|
};
|
|
11
17
|
|
|
12
18
|
export const MobileHeadeCloseIcon = ({ onClick }: { onClick: (event: Event) => void }) => {
|
|
@@ -2,13 +2,17 @@
|
|
|
2
2
|
HeaderWithBackFrame is a full page frame with header for mobile sliders.
|
|
3
3
|
It has Back icon at Left and Close icon at Right.
|
|
4
4
|
*/
|
|
5
|
-
import { VNode, CssProps, RefProps, HtmlVar } from 'lupine.components';
|
|
5
|
+
import { VNode, CssProps, RefProps, HtmlVar, backActionHelper } from 'lupine.components';
|
|
6
6
|
import { MobileHeaderTitleIcon } from './mobile-header-title-icon';
|
|
7
7
|
|
|
8
8
|
export const HeaderWithBackFrameHeight = '40px';
|
|
9
9
|
export const HeaderWithBackFrameLeft = ({ onClick }: { onClick: (event: Event) => void }) => {
|
|
10
10
|
return (
|
|
11
|
-
<i
|
|
11
|
+
<i
|
|
12
|
+
class='ifc-icon mg-arrow_back_ios_new_outlined header-back-left-icon'
|
|
13
|
+
data-back-action={backActionHelper.genBackActionId()}
|
|
14
|
+
onClick={(event) => onClick(event)}
|
|
15
|
+
></i>
|
|
12
16
|
);
|
|
13
17
|
};
|
|
14
18
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CssProps, RefProps, VNode } from 'lupine.components';
|
|
1
|
+
import { backActionHelper, CssProps, RefProps, VNode } from 'lupine.components';
|
|
2
2
|
|
|
3
3
|
export class MobileSideMenuHelper {
|
|
4
4
|
static show() {
|
|
@@ -7,10 +7,14 @@ export class MobileSideMenuHelper {
|
|
|
7
7
|
setTimeout(() => {
|
|
8
8
|
ref.classList.add('animate-show');
|
|
9
9
|
}, 1);
|
|
10
|
+
|
|
11
|
+
const backActionId = backActionHelper.genBackActionId();
|
|
12
|
+
ref.setAttribute('data-back-action', backActionId);
|
|
10
13
|
}
|
|
11
14
|
|
|
12
15
|
static hide() {
|
|
13
16
|
const ref = document.querySelector('.mobile-side-menu-mask') as HTMLDivElement;
|
|
17
|
+
ref.removeAttribute('data-back-action');
|
|
14
18
|
ref.classList.remove('animate-show');
|
|
15
19
|
setTimeout(() => {
|
|
16
20
|
ref.classList.remove('show');
|
|
@@ -25,7 +25,7 @@ export type SliderFrameProps = {
|
|
|
25
25
|
defaultContent?: VNode<any> | string;
|
|
26
26
|
direction?: 'right' | 'bottom';
|
|
27
27
|
hook?: SliderFrameHookProps;
|
|
28
|
-
afterClose?: () => void
|
|
28
|
+
afterClose?: () => void | Promise<void>;
|
|
29
29
|
};
|
|
30
30
|
export const SliderFrame = (props: SliderFrameProps) => {
|
|
31
31
|
if (props.hook) {
|
|
@@ -39,11 +39,11 @@ export const SliderFrame = (props: SliderFrameProps) => {
|
|
|
39
39
|
props.hook.close = (event: Event) => {
|
|
40
40
|
stopPropagation(event);
|
|
41
41
|
ref.current?.classList.remove('show');
|
|
42
|
-
setTimeout(() => {
|
|
42
|
+
setTimeout(async () => {
|
|
43
43
|
ref.current?.classList.add('d-none');
|
|
44
44
|
dom.value = '';
|
|
45
45
|
if (props.afterClose) {
|
|
46
|
-
props.afterClose();
|
|
46
|
+
await props.afterClose();
|
|
47
47
|
}
|
|
48
48
|
}, 400);
|
|
49
49
|
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { uniqueIdGenerator } from 'lupine.web';
|
|
2
|
+
|
|
3
|
+
type BackFn = () => void | Promise<void>;
|
|
4
|
+
|
|
5
|
+
export const backActionUniqueId = uniqueIdGenerator('bb-'); // bb means back button
|
|
6
|
+
class BackActionHelper {
|
|
7
|
+
private backFn?: BackFn;
|
|
8
|
+
|
|
9
|
+
genBackActionId() {
|
|
10
|
+
return backActionUniqueId();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
getAllBackActionButtons() {
|
|
14
|
+
const nodes = document.querySelectorAll('[data-back-action^="bb-"]');
|
|
15
|
+
const buttons = Array.from(nodes)
|
|
16
|
+
.map((el) => {
|
|
17
|
+
const match = el.getAttribute('data-back-action')?.match(/bb-(\d+)/);
|
|
18
|
+
return match ? { el, num: parseInt(match[1], 10) } : null;
|
|
19
|
+
})
|
|
20
|
+
.filter(Boolean)
|
|
21
|
+
.sort((a, b) => b!.num - a!.num)
|
|
22
|
+
.map((item) => item!.el);
|
|
23
|
+
return buttons;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
clear() {
|
|
27
|
+
this.backFn = undefined;
|
|
28
|
+
}
|
|
29
|
+
attach(back: BackFn) {
|
|
30
|
+
this.backFn = back;
|
|
31
|
+
}
|
|
32
|
+
async processBackAction(): Promise<boolean> {
|
|
33
|
+
if (this.backFn) {
|
|
34
|
+
try {
|
|
35
|
+
await this.backFn();
|
|
36
|
+
this.clear();
|
|
37
|
+
return true;
|
|
38
|
+
} catch (e) {
|
|
39
|
+
console.error('back button back failed', e);
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const buttons = this.getAllBackActionButtons();
|
|
45
|
+
if (buttons.length) {
|
|
46
|
+
const button = buttons[0];
|
|
47
|
+
button.dispatchEvent(new Event('click'));
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const backActionHelper = /* @__PURE__ */ new BackActionHelper();
|
package/src/lib/index.ts
CHANGED