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

55 lines
1.0 KiB
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,
LayoutSpec,
2021-09-01 10:47:40 +08:00
Text,
2021-09-02 11:39:51 +08:00
makeRef,
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-02 11:39:51 +08:00
const ref = makeRef<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}
layoutConfig={{
widthSpec: LayoutSpec.MOST,
heightSpec: LayoutSpec.MOST,
}}
parent={root}
>
<Text text={`${count}`} textSize={40} ref={ref} />
<Text
text="Click to count"
textSize={20}
onClick={() => {
count++;
ref.current.text = `${count}`;
}}
/>
2021-09-02 14:31:24 +08:00
{fragments}
{[0, 1, 2, 3].map((i) => (
<>
<Text text={`Index ${i}`} />
<Text text={`Subtitle ${i}`} textSize={10} />
</>
))}
2021-09-02 11:39:51 +08:00
</VLayout>;
2021-09-01 10:47:40 +08:00
}
}