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/TSXDemo.tsx

52 lines
980 B
TypeScript
Raw Normal View History

2021-09-01 10:47:40 +08:00
import {
2021-09-02 11:39:51 +08:00
jsx,
2021-09-01 10:47:40 +08:00
VLayout,
2021-09-02 11:39:51 +08:00
Panel,
2021-09-01 10:47:40 +08:00
Gravity,
2021-09-02 11:39:51 +08:00
Group,
2021-09-03 13:42:25 +08:00
layoutConfig,
2021-09-01 10:47:40 +08:00
Text,
2021-09-03 16:48:24 +08:00
createRef,
2021-09-01 10:47:40 +08:00
} from "doric";
2021-09-02 12:03:19 +08:00
function createFragment() {
return (
<>
<Text text="This is line 1 in fragment"></Text>
<Text text="This is line 2 in fragment"></Text>
</>
);
}
2021-09-02 11:39:51 +08:00
2021-09-01 10:47:40 +08:00
@Entry
2021-09-02 11:39:51 +08:00
class Counter extends Panel {
build(root: Group) {
2021-09-02 14:31:24 +08:00
const fragments = createFragment();
2021-09-03 16:48:24 +08:00
const ref = createRef<Text>();
2021-09-01 10:47:40 +08:00
let count = 0;
2021-09-02 11:39:51 +08:00
<VLayout
space={20}
gravity={Gravity.Center}
2021-09-03 13:42:25 +08:00
layoutConfig={layoutConfig().fit().configAlignment(Gravity.Center)}
2021-09-02 11:39:51 +08:00
parent={root}
>
2021-09-03 13:42:25 +08:00
<Text textSize={40} ref={ref}>
{`${count}`}
</Text>
2021-09-02 11:39:51 +08:00
<Text
textSize={20}
2021-09-03 13:42:25 +08:00
text="Click to count"
2021-09-02 11:39:51 +08:00
onClick={() => {
count++;
ref.current.text = `${count}`;
}}
2021-09-03 13:42:25 +08:00
></Text>
{fragments}
2021-09-02 14:31:24 +08:00
{fragments}
{[0, 1, 2, 3].map((i) => (
2021-09-03 13:42:25 +08:00
<Text text={`Index ${i}`} />
2021-09-02 14:31:24 +08:00
))}
2021-09-02 11:39:51 +08:00
</VLayout>;
2021-09-01 10:47:40 +08:00
}
}