You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`Await` is a utility component that helps you build UI components based on asynchronous data (i.e.: a JavaScript [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) object).
83
+
84
+
#### Signature
85
+
86
+
```js
87
+
Await(
88
+
{
89
+
value, // A `Promise` object for asynchronous data
90
+
container, // The container of the result. Default `div`
91
+
Loading, // What to render when the data is being loaded
92
+
Error, // What to render when error occurs
93
+
},
94
+
children,
95
+
) =><The created UI element>
96
+
```
97
+
98
+
The `children` parameter (type: `(data: T) => ValidChildDomValue`) is a function that takes the resolved data as input and returns a valid child DOM value (`Node`, primitives, `null` or `undefined`), used to indicate what to render after the data is loaded.
99
+
100
+
#### Examples
101
+
102
+
Preview with [CodeSandbox](https://codesandbox.io/p/sandbox/github/vanjs-org/van/tree/main/components/examples/await?file=%2Fsrc%2Fmain.ts%3A1%2C1).
*`value`: Type `Promise`. Required. The asynchronous data that the result UI element is based on.
167
+
*`container`: Type `TagFunction<Element>`. Default `div` (`van.tags.div`). Optional. The type of the wrapper HTML element for the result.
168
+
*`Loading`: Type `() => ValidChildDomValue`. Optional. If specified, indicates what to render when the asynchronous data is being loaded.
169
+
*`Error`: Type `(reason: Error) => ValidChildDomValue`. Optional. If specified, indicates what to render when error occurs while fetching the asynchronous data.
You can live preview the examples with [CodeSandbox](https://codesandbox.io/p/sandbox/github/vanjs-org/van/tree/main/components/examples/modal?file=%2Fsrc%2Fmain.ts%3A1%2C1).
129
-
130
225
#### Property Reference
131
226
132
227
*`closed`: Type `State<boolean>`. Required. A `State` object used to close the created modal window. Basically, setting `closed.val = true` will close the created modal window. You can also subscribe the closing event of the modal window via [`van.derive`](https://vanjs.org/tutorial#api-derive).
@@ -151,6 +246,8 @@ The `tabContents` parameter is an object whose keys are the titles of the tabs a
151
246
152
247
#### Example
153
248
249
+
Preview with [CodeSandbox](https://codesandbox.io/p/sandbox/github/vanjs-org/van/tree/main/components/examples/tabs?file=%2Fsrc%2Fmain.ts%3A1%2C1).
250
+
154
251
```ts
155
252
van.add(document.body, Tabs(
156
253
{
@@ -177,8 +274,6 @@ van.add(document.body, Tabs(
177
274
))
178
275
```
179
276
180
-
You can live preview the example with [CodeSandbox](https://codesandbox.io/p/sandbox/github/vanjs-org/van/tree/main/components/examples/tabs?file=%2Fsrc%2Fmain.ts%3A1%2C1).
181
-
182
277
#### Property Reference
183
278
184
279
*`activeTab`: Type `State<string>`. Optional. If specified, you can activate a tab via the specified `State` object with `activeTab.val = "<tab title>"`, and subscribe to the changes of active tab via [`van.derive`](https://vanjs.org/tutorial#api-derive).
@@ -222,6 +317,8 @@ board.remove()
222
317
223
318
#### Examples
224
319
320
+
Preview with [CodeSandbox](https://codesandbox.io/p/sandbox/github/vanjs-org/van/tree/main/components/examples/message?file=%2Fsrc%2Fmain.ts%3A1%2C1).
You can live preview the examples with [CodeSandbox](https://codesandbox.io/p/sandbox/github/vanjs-org/van/tree/main/components/examples/message?file=/src/main.ts).
241
-
242
337
#### Property Reference
243
338
244
339
Message board properties:
@@ -274,6 +369,8 @@ Tooltip({...props}) => <The created tooltip element>
274
369
275
370
#### Examples
276
371
372
+
Preview with [CodeSandbox](https://codesandbox.io/p/sandbox/github/vanjs-org/van/tree/main/components/examples/tooltip?file=%2Fsrc%2Fmain.ts%3A1%2C1).
373
+
277
374
```ts
278
375
const tooltip1Show =van.state(false)
279
376
const tooltip2Show =van.state(false)
@@ -301,8 +398,6 @@ van.add(document.body,
301
398
)
302
399
```
303
400
304
-
You can live preview the examples with [CodeSandbox](https://codesandbox.io/p/sandbox/github/vanjs-org/van/tree/main/components/examples/tooltip?file=/src/main.ts:1,1).
305
-
306
401
Note that the lines:
307
402
308
403
```ts
@@ -340,15 +435,15 @@ Toggle({...props}) => <The created toggle switch>
340
435
341
436
#### Example
342
437
438
+
Preview with [CodeSandbox](https://codesandbox.io/p/sandbox/github/vanjs-org/van/tree/main/components/examples/toggle?file=%2Fsrc%2Fmain.ts%3A1%2C1).
439
+
343
440
```ts
344
441
van.add(document.body, Toggle({
345
442
size: 2,
346
443
onColor: "#4CAF50"
347
444
}))
348
445
```
349
446
350
-
You can live preview the example with [CodeSandbox](https://codesandbox.io/p/sandbox/github/vanjs-org/van/tree/main/components/examples/toggle?file=%2Fsrc%2Fmain.ts%3A1%2C1).
351
-
352
447
#### Property Reference
353
448
354
449
*`on`: Type `boolean | State<boolean>`. Default`false`. Optional. A boolean or a boolean-typed `State` object to indicate the status of the toggle. If a `State` object is specified, you can turn on/off the toggle via the specified `State` object with`on.val = <true|false>`, and subscribe to the status change of the toggle via [`van.derive`](https://vanjs.org/tutorial#api-derive).
@@ -379,6 +474,8 @@ The `options` parameter is a `string[]` for all the options.
379
474
380
475
#### Example
381
476
477
+
Preview with [CodeSandbox](https://codesandbox.io/p/sandbox/github/vanjs-org/van/tree/main/components/examples/option-group?file=%2Fsrc%2Fmain.ts%3A1%2C1).
478
+
382
479
```ts
383
480
const selected = van.state("")
384
481
const options = ["Water", "Coffee", "Juice"]
@@ -391,8 +488,6 @@ van.add(document.body,
391
488
)
392
489
```
393
490
394
-
You can live preview the example with [CodeSandbox](https://codesandbox.io/p/sandbox/github/vanjs-org/van/tree/main/components/examples/option-group?file=%2Fsrc%2Fmain.ts%3A1%2C1).
395
-
396
491
#### Property Reference
397
492
398
493
*`selected`: Type `State<string>`. Required. A`State` object for the currently selected option. You can change the selected option with`selected.val = <option string>`, and subscribe to the selection change via [`van.derive`](https://vanjs.org/tutorial#api-derive).
Preview with [CodeSandbox](https://codesandbox.io/p/sandbox/github/vanjs-org/van/tree/main/components/examples/banner?file=%2Fsrc%2Fmain.ts%3A1%2C1).
518
+
422
519
```ts
423
520
van.add(document.body,
424
521
h2("Sticky Banner"),
@@ -434,8 +531,6 @@ van.add(document.body,
434
531
)
435
532
```
436
533
437
-
You can live preview the examples with [CodeSandbox](https://codesandbox.io/p/sandbox/github/vanjs-org/van/tree/main/components/examples/banner?file=/src/main.ts:1,1).
438
-
439
534
#### Property Reference
440
535
441
536
*`backgroundColor`: Type `string`. Default`#fff1a8`. Optional. The background color of the banner.
0 commit comments