lupine.components 1.0.4 → 1.0.5
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
CHANGED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { CssProps, RefProps, VNode, mountComponents } from 'lupine.web';
|
|
2
|
+
|
|
3
|
+
export type ActionSheetCloseProps = () => void;
|
|
4
|
+
|
|
5
|
+
export type ActionSheetShowProps = {
|
|
6
|
+
title: string;
|
|
7
|
+
children: VNode<any>;
|
|
8
|
+
contentMaxHeight?: string;
|
|
9
|
+
closeEvent?: () => void;
|
|
10
|
+
closeWhenClickOutside?: boolean; // default true
|
|
11
|
+
cancelButtonText?: string; // no showing if not set
|
|
12
|
+
zIndex?: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// because it's over a mask, so it can use primary colors
|
|
16
|
+
export class ActionSheet {
|
|
17
|
+
static hostNode: HTMLElement;
|
|
18
|
+
|
|
19
|
+
static async show({
|
|
20
|
+
title,
|
|
21
|
+
children,
|
|
22
|
+
contentMaxHeight,
|
|
23
|
+
closeEvent,
|
|
24
|
+
closeWhenClickOutside = true,
|
|
25
|
+
cancelButtonText = 'Cancel',
|
|
26
|
+
zIndex,
|
|
27
|
+
}: ActionSheetShowProps): Promise<ActionSheetCloseProps> {
|
|
28
|
+
const onCancel = () => {
|
|
29
|
+
handleClose();
|
|
30
|
+
};
|
|
31
|
+
const onClickContainer = (event: any) => {
|
|
32
|
+
if (closeWhenClickOutside !== false && event.target.className === 'act-sheet-box') {
|
|
33
|
+
handleClose();
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const handleClose = () => {
|
|
37
|
+
closeEvent?.();
|
|
38
|
+
ref.current.classList.remove('animation-open');
|
|
39
|
+
setTimeout(() => {
|
|
40
|
+
base.remove();
|
|
41
|
+
}, 300);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const base = document.createElement('div');
|
|
45
|
+
const ref: RefProps = {
|
|
46
|
+
onLoad: async () => {
|
|
47
|
+
setTimeout(() => {
|
|
48
|
+
ref.current.classList.add('animation-open');
|
|
49
|
+
}, 1);
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
const cssContainer: CssProps = {
|
|
53
|
+
position: 'fixed',
|
|
54
|
+
top: 0,
|
|
55
|
+
left: 0,
|
|
56
|
+
width: '100%',
|
|
57
|
+
height: '100%',
|
|
58
|
+
backgroundColor: 'var(--cover-mask-bg-color)',
|
|
59
|
+
'.act-sheet-body': {
|
|
60
|
+
display: 'flex',
|
|
61
|
+
flexDirection: 'column',
|
|
62
|
+
textAlign: 'center',
|
|
63
|
+
position: 'fixed',
|
|
64
|
+
bottom: '0px',
|
|
65
|
+
left: '0px',
|
|
66
|
+
width: '100%',
|
|
67
|
+
maxHeight: contentMaxHeight ? contentMaxHeight : '',
|
|
68
|
+
color: 'var(--primary-color)',
|
|
69
|
+
padding: '8px',
|
|
70
|
+
transition: 'all 0.3s',
|
|
71
|
+
transform: 'translateY(100%)',
|
|
72
|
+
'&.animation-open': {
|
|
73
|
+
transform: 'translateY(0)',
|
|
74
|
+
},
|
|
75
|
+
'.act-sheet-title': {
|
|
76
|
+
padding: '20px 15px 10px 15px',
|
|
77
|
+
opacity: 0.5,
|
|
78
|
+
},
|
|
79
|
+
'.act-sheet-content': {
|
|
80
|
+
display: 'flex',
|
|
81
|
+
flexDirection: 'column',
|
|
82
|
+
flex: 1,
|
|
83
|
+
overflowY: 'auto',
|
|
84
|
+
borderRadius: '8px',
|
|
85
|
+
backgroundColor: 'var(--cover-bg-color)', //'#fefefe',
|
|
86
|
+
width: '100%',
|
|
87
|
+
maxWidth: '450px',
|
|
88
|
+
margin: '0 auto',
|
|
89
|
+
},
|
|
90
|
+
'.act-sheet-bottom-item, .act-sheet-item': {
|
|
91
|
+
backgroundColor: 'var(--cover-bg-color)', //'#fefefe',
|
|
92
|
+
padding: '20px 0',
|
|
93
|
+
cursor: 'pointer',
|
|
94
|
+
transition: 'all 0.3s ease',
|
|
95
|
+
width: '100%',
|
|
96
|
+
maxWidth: '450px',
|
|
97
|
+
borderTop: '1px solid var(--primary-border-color)',
|
|
98
|
+
},
|
|
99
|
+
'.act-sheet-bottom-item': {
|
|
100
|
+
borderRadius: '8px',
|
|
101
|
+
margin: '0 auto',
|
|
102
|
+
marginTop: '4px',
|
|
103
|
+
},
|
|
104
|
+
'.act-sheet-bottom-item:hover, .act-sheet-item:hover': {
|
|
105
|
+
fontWeight: 'bold',
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
const component = (
|
|
110
|
+
<div css={cssContainer} class='act-sheet-box' onClick={onClickContainer}>
|
|
111
|
+
<div ref={ref} class='act-sheet-body'>
|
|
112
|
+
<div class='act-sheet-content'>
|
|
113
|
+
<div class='act-sheet-title'>{title}</div>
|
|
114
|
+
{children}
|
|
115
|
+
</div>
|
|
116
|
+
{cancelButtonText && (
|
|
117
|
+
<div class='act-sheet-bottom-item' onClick={onCancel}>
|
|
118
|
+
{cancelButtonText}
|
|
119
|
+
</div>
|
|
120
|
+
)}
|
|
121
|
+
</div>
|
|
122
|
+
</div>
|
|
123
|
+
);
|
|
124
|
+
base.style.position = 'fixed';
|
|
125
|
+
base.style.zIndex = zIndex || 'var(--layer-actionsheet-window)';
|
|
126
|
+
document.body.appendChild(base);
|
|
127
|
+
await mountComponents(base, component);
|
|
128
|
+
return handleClose;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export const ActionSheetSelectOptionsProps = {
|
|
133
|
+
YesNo: ['Yes', 'No'],
|
|
134
|
+
OkCancel: ['OK'],
|
|
135
|
+
};
|
|
136
|
+
export type ActionSheetSelectProps = Omit<ActionSheetShowProps, 'children'> & {
|
|
137
|
+
options: string[];
|
|
138
|
+
handleClicked: (index: number, close: ActionSheetCloseProps) => void;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export class ActionSheetSelect {
|
|
142
|
+
static async show({
|
|
143
|
+
title,
|
|
144
|
+
contentMaxHeight,
|
|
145
|
+
options = ActionSheetSelectOptionsProps.OkCancel,
|
|
146
|
+
closeEvent,
|
|
147
|
+
handleClicked,
|
|
148
|
+
closeWhenClickOutside = true,
|
|
149
|
+
cancelButtonText = 'Cancel',
|
|
150
|
+
}: ActionSheetSelectProps): Promise<ActionSheetCloseProps> {
|
|
151
|
+
const handleClose = await ActionSheet.show({
|
|
152
|
+
title,
|
|
153
|
+
children: (
|
|
154
|
+
<div>
|
|
155
|
+
{options.map((option, index) => (
|
|
156
|
+
<div class='act-sheet-item' key={index} onClick={() => handleClicked(index, handleClose)}>
|
|
157
|
+
{option}
|
|
158
|
+
</div>
|
|
159
|
+
))}
|
|
160
|
+
</div>
|
|
161
|
+
),
|
|
162
|
+
contentMaxHeight,
|
|
163
|
+
cancelButtonText,
|
|
164
|
+
closeEvent,
|
|
165
|
+
closeWhenClickOutside,
|
|
166
|
+
});
|
|
167
|
+
return handleClose;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export type ActionSheetMessageProps = Omit<ActionSheetShowProps, 'children' | 'handleClicked' | 'closeEvent'> & {
|
|
172
|
+
message: string;
|
|
173
|
+
};
|
|
174
|
+
export class ActionSheetMessage {
|
|
175
|
+
static async show({
|
|
176
|
+
title,
|
|
177
|
+
message,
|
|
178
|
+
contentMaxHeight,
|
|
179
|
+
closeWhenClickOutside = true,
|
|
180
|
+
cancelButtonText = '',
|
|
181
|
+
}: ActionSheetMessageProps): Promise<ActionSheetCloseProps> {
|
|
182
|
+
const handleClose = await ActionSheet.show({
|
|
183
|
+
title,
|
|
184
|
+
children: <div css={{ padding: '0 8px 16px 8px' }}>{message}</div>,
|
|
185
|
+
contentMaxHeight,
|
|
186
|
+
cancelButtonText,
|
|
187
|
+
closeWhenClickOutside,
|
|
188
|
+
});
|
|
189
|
+
return handleClose;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -80,7 +80,10 @@ export class FloatWindow {
|
|
|
80
80
|
|
|
81
81
|
const ref: RefProps = {
|
|
82
82
|
onLoad: async () => {
|
|
83
|
-
ref.current.classList.add('transition'
|
|
83
|
+
ref.current.classList.add('transition');
|
|
84
|
+
setTimeout(() => {
|
|
85
|
+
ref.current.classList.add('animation');
|
|
86
|
+
}, 1);
|
|
84
87
|
setTimeout(() => {
|
|
85
88
|
// don't need transition for moving
|
|
86
89
|
ref.current.classList.remove('transition');
|
package/src/components/index.ts
CHANGED
|
@@ -11,6 +11,7 @@ export const sharedThemes: ThemeProps = {
|
|
|
11
11
|
'--layer-modal': '600',
|
|
12
12
|
'--layer-modal-over': '610',
|
|
13
13
|
'--layer-float-window': '700',
|
|
14
|
+
'--layer-actionsheet-window': '710',
|
|
14
15
|
'--layer-menu': '800', // popup menu
|
|
15
16
|
'--layer-menu-sub': '810',
|
|
16
17
|
'--layer-notice': '900', // notice, loading, toast
|