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/InputDemo.ts

119 lines
2.3 KiB
TypeScript
Raw Normal View History

2021-02-08 18:18:37 +08:00
import {
Panel,
Group,
scroller,
vlayout,
layoutConfig,
LayoutSpec,
Input,
Color,
input,
text,
} from "doric";
2021-06-11 15:17:20 +08:00
import { preferenceView } from "./components/PreferenceView";
import { title } from "./utils";
2020-05-06 15:11:57 +08:00
function getInput(c: Partial<Input>) {
2021-02-08 18:18:37 +08:00
const inputView = input(c);
const isFocused = text({
layoutConfig: {
widthSpec: LayoutSpec.MOST,
heightSpec: LayoutSpec.JUST,
},
height: 50,
});
const inputed = text({
layoutConfig: {
widthSpec: LayoutSpec.MOST,
heightSpec: LayoutSpec.JUST,
},
height: 50,
});
inputView.onFocusChange = (onFocusChange) => {
isFocused.text = onFocusChange ? `Focused` : `Unfocused`;
};
inputView.onTextChange = (text) => {
inputed.text = `Inputed:${text}`;
};
2021-06-11 15:17:20 +08:00
inputView.onSubmitEditing = (text) => {
inputed.text = `Submited: ${text}`
};
return [
inputView,
isFocused,
inputed,
preferenceView().applyChild({
title: {
text: "Multiline"
},
switch: {
state: true,
onSwitch: (ret) => {
inputView.multiline = ret
}
}
}),
preferenceView().applyChild({
title: {
text: "Editable"
},
switch: {
state: true,
onSwitch: (ret) => {
inputView.editable = ret
}
}
}),
2021-06-11 17:40:02 +08:00
preferenceView().applyChild({
title: {
text: "maxLength"
},
switch: {
state: true,
onSwitch: (ret) => {
inputView.maxLength = 20
}
}
}),
2021-06-11 15:17:20 +08:00
];
2020-05-06 15:11:57 +08:00
}
2019-12-07 15:50:37 +08:00
@Entry
class InputDemo extends Panel {
2021-02-08 18:18:37 +08:00
build(root: Group) {
2021-06-11 15:17:20 +08:00
let inputView: Input
2021-02-08 18:18:37 +08:00
scroller(
vlayout(
[
title("Demo"),
2021-06-11 15:17:20 +08:00
...getInput({
layoutConfig: {
widthSpec: LayoutSpec.MOST,
heightSpec: LayoutSpec.FIT,
},
hintText: "Please input something",
border: {
width: 1,
color: Color.GRAY,
},
2021-07-20 15:46:49 +08:00
font: 'DINPro',
hintFont: 'Hanabi',
textColor: Color.RED,
hintTextColor: Color.GREEN,
2021-06-11 15:17:20 +08:00
}),
2021-02-08 18:18:37 +08:00
],
{
space: 10,
layoutConfig: layoutConfig().most().configHeight(LayoutSpec.MOST),
}
),
{
layoutConfig: layoutConfig().most(),
}
).in(root);
}
2020-04-30 16:36:28 +08:00
}