lupine.components 1.1.8 → 1.1.10

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lupine.components",
3
- "version": "1.1.8",
3
+ "version": "1.1.10",
4
4
  "license": "MIT",
5
5
  "author": "uuware.com",
6
6
  "homepage": "https://github.com/uuware/lupine.js",
@@ -1,14 +1,16 @@
1
1
  import { CssProps, RefProps, VNode, mountInnerComponent } from 'lupine.web';
2
2
  import { backActionHelper } from '../lib';
3
3
 
4
- export type ActionSheetCloseProps = () => void;
4
+ export type ActionSheetCloseProps = (reason?: ActionSheetCloseReasonProps) => void;
5
+
6
+ export type ActionSheetCloseReasonProps = 'cancel' | 'confirm' | 'select' | undefined;
5
7
 
6
8
  export type ActionSheetShowProps = {
7
9
  title: string;
8
10
  children: string | VNode<any>;
9
11
  contentMaxWidth?: string;
10
12
  contentMaxHeight?: string;
11
- closeEvent?: () => void;
13
+ closeEvent?: (reason?: ActionSheetCloseReasonProps) => void;
12
14
  closeWhenClickOutside?: boolean; // default true
13
15
  confirmButtonText?: string; // no showing if not set
14
16
  handleConfirmClicked?: (close: ActionSheetCloseProps) => void;
@@ -36,19 +38,19 @@ export class ActionSheet {
36
38
  if (handleConfirmClicked) {
37
39
  handleConfirmClicked(handleClose);
38
40
  } else {
39
- handleClose();
41
+ handleClose('confirm');
40
42
  }
41
43
  };
42
44
  const onCancel = () => {
43
- handleClose();
45
+ handleClose('cancel');
44
46
  };
45
47
  const onClickContainer = (event: any) => {
46
48
  if (closeWhenClickOutside !== false && event.target.classList.contains('act-sheet-box')) {
47
- handleClose();
49
+ handleClose('cancel');
48
50
  }
49
51
  };
50
- const handleClose = () => {
51
- closeEvent?.();
52
+ const handleClose = (reason?: ActionSheetCloseReasonProps) => {
53
+ closeEvent?.(reason);
52
54
  ref.current.classList.remove('animation-open');
53
55
  setTimeout(() => {
54
56
  base.remove();
@@ -208,6 +210,7 @@ export class ActionSheetMessage {
208
210
  static async show({
209
211
  title,
210
212
  message,
213
+ contentMaxWidth,
211
214
  contentMaxHeight,
212
215
  closeWhenClickOutside = true,
213
216
  confirmButtonText,
@@ -216,7 +219,15 @@ export class ActionSheetMessage {
216
219
  }: ActionSheetMessageProps): Promise<ActionSheetCloseProps> {
217
220
  const handleClose = await ActionSheet.show({
218
221
  title,
219
- children: <div css={{ padding: '8px', borderTop: '1px solid var(--primary-border-color)' }}>{message}</div>,
222
+ children: (
223
+ <div
224
+ css={{ padding: '8px', borderTop: '1px solid var(--primary-border-color)' }}
225
+ onClick={() => handleClose('select')}
226
+ >
227
+ {message}
228
+ </div>
229
+ ),
230
+ contentMaxWidth,
220
231
  contentMaxHeight,
221
232
  confirmButtonText,
222
233
  handleConfirmClicked,
@@ -227,6 +238,41 @@ export class ActionSheetMessage {
227
238
  }
228
239
  }
229
240
 
241
+ export type ActionSheetMessagePromiseProps = {
242
+ message: string | VNode<any>;
243
+ title: string;
244
+ contentMaxWidth?: string;
245
+ contentMaxHeight?: string;
246
+ closeWhenClickOutside?: boolean;
247
+ confirmButtonText?: string;
248
+ zIndex?: string;
249
+ };
250
+ export const ActionSheetMessagePromise = async ({
251
+ title,
252
+ message,
253
+ contentMaxWidth,
254
+ contentMaxHeight,
255
+ closeWhenClickOutside = true,
256
+ confirmButtonText,
257
+ zIndex,
258
+ }: ActionSheetMessagePromiseProps): Promise<void> => {
259
+ return new Promise(async (resolve, reject) => {
260
+ const closeEvent = (reason?: ActionSheetCloseReasonProps) => {
261
+ resolve();
262
+ };
263
+ await ActionSheet.show({
264
+ title,
265
+ children: <div css={{ padding: '8px', borderTop: '1px solid var(--primary-border-color)' }}>{message}</div>,
266
+ contentMaxWidth,
267
+ contentMaxHeight,
268
+ confirmButtonText,
269
+ closeEvent,
270
+ closeWhenClickOutside,
271
+ zIndex,
272
+ });
273
+ });
274
+ };
275
+
230
276
  export type ActionSheetInputProps = Omit<
231
277
  ActionSheetShowProps,
232
278
  'children' | 'handleClicked' | 'closeEvent' | 'handleConfirmClicked'
@@ -268,3 +314,106 @@ export class ActionSheetInput {
268
314
  return handleClose;
269
315
  }
270
316
  }
317
+
318
+ export type ActionSheetInputPromiseProps = {
319
+ defaultValue?: string;
320
+ title: string;
321
+ contentMaxWidth?: string;
322
+ contentMaxHeight?: string;
323
+ closeWhenClickOutside?: boolean;
324
+ confirmButtonText?: string;
325
+ cancelButtonText?: string;
326
+ zIndex?: string;
327
+ };
328
+ export const ActionSheetInputPromise = async ({
329
+ title,
330
+ defaultValue,
331
+ contentMaxWidth,
332
+ contentMaxHeight,
333
+ closeWhenClickOutside = true,
334
+ confirmButtonText = 'OK',
335
+ cancelButtonText = 'Cancel',
336
+ zIndex,
337
+ }: ActionSheetInputPromiseProps): Promise<string | undefined> => {
338
+ return new Promise(async (resolve, reject) => {
339
+ const closeEvent = (reason?: ActionSheetCloseReasonProps) => {
340
+ if (reason !== 'confirm') {
341
+ resolve(undefined);
342
+ }
343
+ };
344
+ let value: string = defaultValue || '';
345
+ await ActionSheet.show({
346
+ title,
347
+ children: (
348
+ <div css={{ padding: '8px', borderTop: '1px solid var(--primary-border-color)' }}>
349
+ <input
350
+ class='input-base w-100p'
351
+ type='text'
352
+ value={value}
353
+ onInput={(e) => (value = (e.target as HTMLInputElement).value)}
354
+ />
355
+ </div>
356
+ ),
357
+ contentMaxWidth,
358
+ contentMaxHeight,
359
+ confirmButtonText,
360
+ handleConfirmClicked: (close) => {
361
+ resolve(value);
362
+ close('confirm');
363
+ },
364
+ closeEvent,
365
+ cancelButtonText,
366
+ closeWhenClickOutside,
367
+ zIndex,
368
+ });
369
+ });
370
+ };
371
+
372
+ export type ActionSheetSelectPromiseProps = {
373
+ title: string;
374
+ contentMaxWidth?: string;
375
+ contentMaxHeight?: string;
376
+ options?: string[];
377
+ closeWhenClickOutside?: boolean;
378
+ cancelButtonText?: string;
379
+ zIndex?: string;
380
+ };
381
+ export const ActionSheetSelectPromise = async ({
382
+ title,
383
+ contentMaxWidth,
384
+ contentMaxHeight,
385
+ options = ActionSheetSelectOptionsProps.Ok,
386
+ closeWhenClickOutside = true,
387
+ cancelButtonText = 'Cancel',
388
+ zIndex,
389
+ }: ActionSheetSelectPromiseProps): Promise<number> => {
390
+ return new Promise(async (resolve, reject) => {
391
+ const handleClicked = async (index: number, close: ActionSheetCloseProps) => {
392
+ resolve(index);
393
+ close('select');
394
+ };
395
+ const closeEvent = (reason?: ActionSheetCloseReasonProps) => {
396
+ if (reason !== 'select') {
397
+ resolve(-1);
398
+ }
399
+ };
400
+ const handleClose = await ActionSheet.show({
401
+ title,
402
+ children: (
403
+ <div>
404
+ {options.map((option, index) => (
405
+ <div class='act-sheet-item' key={index} onClick={() => handleClicked(index, handleClose)}>
406
+ {option}
407
+ </div>
408
+ ))}
409
+ </div>
410
+ ),
411
+ contentMaxWidth,
412
+ contentMaxHeight,
413
+ cancelButtonText,
414
+ closeEvent,
415
+ closeWhenClickOutside,
416
+ zIndex,
417
+ });
418
+ });
419
+ };
@@ -0,0 +1,41 @@
1
+ import { RefProps, VNode } from 'lupine.web';
2
+
3
+ // load async html
4
+ /*
5
+ <HtmlLoad
6
+ html={async () => {
7
+ return <Footer title={await WebConfig.get('footer', `XXX`)}></Footer>;
8
+ }}
9
+ ></HtmlLoad>
10
+ */
11
+ export type HtmlLoadHookProps = {
12
+ getRef?: () => RefProps;
13
+ render?: (html: string | VNode<any>) => void;
14
+ };
15
+ export type HtmlLoadProps = {
16
+ html: () => Promise<VNode<any>>;
17
+ initialHtml?: string | VNode<any>;
18
+ hook?: HtmlLoadHookProps;
19
+ };
20
+ export const HtmlLoad = (props: HtmlLoadProps) => {
21
+ const ref: RefProps = {
22
+ onLoad: async (el: Element) => {
23
+ const dom = await props.html();
24
+ await ref.mountInnerComponent!(dom);
25
+ },
26
+ };
27
+ if (props.hook) {
28
+ props.hook.getRef = () => ref;
29
+ props.hook.render = (html: string | VNode<any>) => {
30
+ ref.mountInnerComponent!(html);
31
+ };
32
+ }
33
+ return {
34
+ type: 'Fragment',
35
+ props: {
36
+ ref: ref,
37
+ children: props.initialHtml || '',
38
+ },
39
+ html: [],
40
+ };
41
+ };
@@ -1,15 +1,15 @@
1
1
  import { RefProps, VNode } from 'lupine.web';
2
2
 
3
- export type HtmlVarResult = { value: string | VNode<any>; ref: RefProps; node: VNode<any> };
4
-
3
+ export type HtmlVarValueProps = string | VNode<any> | (() => Promise<VNode<any>>);
4
+ export type HtmlVarResult = { value: HtmlVarValueProps; ref: RefProps; node: VNode<any> };
5
5
  export class HtmlVar implements HtmlVarResult {
6
- private _value: string | VNode<any>;
6
+ private _value: HtmlVarValueProps;
7
7
  private _dirty = false;
8
8
  private _ref: RefProps;
9
9
  private resolve!: () => void;
10
10
  private promise: Promise<void>;
11
11
 
12
- constructor(initial?: string | VNode<any>) {
12
+ constructor(initial?: HtmlVarValueProps) {
13
13
  this.promise = new Promise<void>((res) => {
14
14
  this.resolve = res;
15
15
  });
@@ -28,7 +28,8 @@ export class HtmlVar implements HtmlVarResult {
28
28
  }
29
29
 
30
30
  private async update(): Promise<void> {
31
- await this._ref.mountInnerComponent!(this._value);
31
+ const v = typeof this._value === 'function' ? await this._value() : this._value;
32
+ await this._ref.mountInnerComponent!(v);
32
33
  this._dirty = false;
33
34
  this._value = '';
34
35
  }
@@ -38,7 +39,7 @@ export class HtmlVar implements HtmlVarResult {
38
39
  await this.promise;
39
40
  }
40
41
 
41
- set value(value: string | VNode<any>) {
42
+ set value(value: HtmlVarValueProps) {
42
43
  this._value = value;
43
44
  if (this._dirty) {
44
45
  return;
@@ -55,7 +56,7 @@ export class HtmlVar implements HtmlVarResult {
55
56
  });
56
57
  }
57
58
 
58
- get value(): string | VNode<any> {
59
+ get value(): HtmlVarValueProps {
59
60
  return this._ref.current ? this._ref.current.innerHTML : this._value;
60
61
  }
61
62
 
@@ -64,13 +65,15 @@ export class HtmlVar implements HtmlVarResult {
64
65
  }
65
66
 
66
67
  get node(): VNode<any> {
67
- this._dirty = false;
68
+ // if value is a function, it will be loaded later in onLoad
69
+ const delayLoad = typeof this._value === 'function';
70
+ this._dirty = delayLoad ? true : false;
68
71
  // the Fragment Tag will be present in the html if ref is assigned
69
72
  return {
70
73
  type: 'Fragment',
71
74
  props: {
72
75
  ref: this._ref,
73
- children: this._value,
76
+ children: delayLoad ? '' : this._value,
74
77
  },
75
78
  html: [],
76
79
  };
@@ -6,6 +6,7 @@ export * from './drag-refresh';
6
6
  export * from './editable-label';
7
7
  export * from './float-window';
8
8
  export * from './grid';
9
+ export * from './html-load';
9
10
  export * from './html-var';
10
11
  export * from './input-with-title';
11
12
  export * from './link-item';
@@ -9,7 +9,7 @@ export const InputWithTitle = (
9
9
  ) => {
10
10
  return (
11
11
  <div>
12
- <div>{title}</div>
12
+ <div style={{ paddingBottom: '4px' }}>{title}</div>
13
13
  <div>
14
14
  <input
15
15
  class={className}
@@ -169,6 +169,10 @@ export const Tabs = ({ pages, defaultIndex, topClassName, pagePadding, hook: ref
169
169
  display: 'flex',
170
170
  height: 'auto',
171
171
  'border-bottom': '1px solid grey',
172
+ 'overflow-x': 'auto',
173
+ 'overflow-y': 'hidden',
174
+ 'scrollbar-width': 'thin',
175
+ 'scrollbar-color': '#ababab4d #d5d5d552',
172
176
  '> div > .tab': {
173
177
  padding: '2px 3px',
174
178
  width: 'auto',