This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/doric-demo/src/ModalDemo.ts

156 lines
6.6 KiB
TypeScript
Raw Normal View History

import { Group, Panel, text, Color, LayoutSpec, vlayout, Gravity, scroller, layoutConfig, modal, Text } from "doric";
2019-12-04 14:07:14 +08:00
import { colors, label } from "./utils";
@Entry
2020-09-04 18:22:45 +08:00
export class ModalDemo extends Panel {
2019-12-04 14:07:14 +08:00
build(rootView: Group): void {
2020-01-06 10:43:18 +08:00
scroller(
vlayout(
[
text({
text: "Modal",
layoutConfig: layoutConfig().configWidth(LayoutSpec.MOST),
textSize: 30,
textColor: Color.WHITE,
backgroundColor: colors[1],
textAlignment: Gravity.Center,
height: 50,
}),
label('toast on bottom'),
label('Click me').apply({
width: 200,
height: 50,
backgroundColor: colors[0],
textSize: 30,
textColor: Color.WHITE,
layoutConfig: layoutConfig().just(),
onClick: () => {
2020-09-05 12:41:12 +08:00
modal(this.context).toast('This is a toast.')
2020-01-06 10:43:18 +08:00
}
}),
2020-01-06 10:43:18 +08:00
label('toast on top'),
label('Click me').apply({
width: 200,
height: 50,
backgroundColor: colors[0],
textSize: 30,
textColor: Color.WHITE,
layoutConfig: layoutConfig().just(),
onClick: () => {
2020-09-05 12:41:12 +08:00
modal(this.context).toast('This is a toast.', Gravity.Top)
2020-01-06 10:43:18 +08:00
}
}),
2019-12-04 14:07:14 +08:00
2020-01-06 10:43:18 +08:00
label('toast on center'),
label('Click me').apply({
width: 200,
height: 50,
backgroundColor: colors[0],
textSize: 30,
textColor: Color.WHITE,
layoutConfig: layoutConfig().just(),
onClick: () => {
2020-09-05 12:41:12 +08:00
modal(this.context).toast('This is a toast.', Gravity.Center)
2020-01-06 10:43:18 +08:00
}
} as Partial<Text>),
2020-01-06 10:43:18 +08:00
text({
text: "Alert",
layoutConfig: layoutConfig().configWidth(LayoutSpec.MOST),
textSize: 30,
textColor: Color.WHITE,
backgroundColor: colors[2],
textAlignment: Gravity.Center,
height: 50,
}),
label('Click me').apply({
width: 200,
height: 50,
backgroundColor: colors[0],
textSize: 30,
textColor: Color.WHITE,
layoutConfig: layoutConfig().just(),
onClick: () => {
2020-09-05 12:41:12 +08:00
modal(this.context).alert({
2020-01-06 10:43:18 +08:00
msg: 'This is alert.',
title: 'Alert title',
okLabel: "OkLabel"
}).then(e => {
2020-09-05 12:41:12 +08:00
modal(this.context).toast('Clicked OK.')
2020-01-06 10:43:18 +08:00
})
}
}),
2020-01-06 10:43:18 +08:00
text({
text: "Confirm",
layoutConfig: layoutConfig().configWidth(LayoutSpec.MOST),
textSize: 30,
textColor: Color.WHITE,
backgroundColor: colors[3],
textAlignment: Gravity.Center,
height: 50,
}),
label('Click me').apply({
width: 200,
height: 50,
backgroundColor: colors[0],
textSize: 30,
textColor: Color.WHITE,
layoutConfig: layoutConfig().just(),
onClick: () => {
2020-09-05 12:41:12 +08:00
modal(this.context).confirm({
2020-01-06 10:43:18 +08:00
msg: 'This is Confirm.',
title: 'Confirm title',
okLabel: "OkLabel",
cancelLabel: 'CancelLabel',
}).then(
() => {
2020-09-05 12:41:12 +08:00
modal(this.context).toast('Clicked OK.')
2020-01-06 10:43:18 +08:00
},
() => {
2020-09-05 12:41:12 +08:00
modal(this.context).toast('Clicked Cancel.')
2020-01-06 10:43:18 +08:00
})
}
}),
2020-01-06 10:43:18 +08:00
text({
text: "Prompt",
layoutConfig: layoutConfig().configWidth(LayoutSpec.MOST),
textSize: 30,
textColor: Color.WHITE,
backgroundColor: colors[4],
textAlignment: Gravity.Center,
height: 50,
}),
label('Click me').apply({
width: 200,
height: 50,
backgroundColor: colors[0],
textSize: 30,
textColor: Color.WHITE,
layoutConfig: layoutConfig().just(),
onClick: () => {
2020-09-05 12:41:12 +08:00
modal(this.context).prompt({
2020-01-06 10:43:18 +08:00
msg: 'This is Prompt.',
title: 'Prompt title',
okLabel: "OkLabel",
cancelLabel: 'CancelLabel',
}).then(
e => {
2020-09-05 12:41:12 +08:00
modal(this.context).toast(`Clicked OK.Input:${e}`)
2020-01-06 10:43:18 +08:00
},
e => {
2020-09-05 12:41:12 +08:00
modal(this.context).toast(`Clicked Cancel.Input:${e}`)
2020-01-06 10:43:18 +08:00
})
}
}),
2020-01-06 10:43:18 +08:00
],
{
layoutConfig: layoutConfig().most().configHeight(LayoutSpec.FIT),
gravity: Gravity.Center,
space: 10,
2019-12-04 14:07:14 +08:00
}
2020-01-06 10:43:18 +08:00
),
{
layoutConfig: layoutConfig().most(),
}
).in(rootView)
2019-12-04 14:07:14 +08:00
}
}