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/components/PreferenceView.ts

68 lines
1.9 KiB
TypeScript
Raw Normal View History

2021-05-14 19:55:32 +08:00
import { Switch, Gravity, hlayout, HLayout, layoutConfig, switchView, Text, text, ViewComponent, vlayout } from "doric";
2021-05-14 19:32:19 +08:00
@ViewComponent
export class PreferenceView extends HLayout {
2021-05-14 19:55:32 +08:00
title: Text
subTitle: Text
switch: Switch
2021-05-14 19:32:19 +08:00
constructor() {
super()
hlayout(
2021-05-14 19:55:32 +08:00
[
vlayout(
[
this.title = text({
textSize: 20,
}),
this.subTitle = text({
textSize: 12,
}),
],
{
layoutConfig: layoutConfig().fit().configWeight(1),
space: 2,
}),
this.switch = switchView({
state: true,
}),
],
2021-05-14 19:32:19 +08:00
{
2021-05-14 19:55:32 +08:00
layoutConfig: layoutConfig().mostWidth().fitHeight(),
gravity: Gravity.Center,
padding: {
left: 10,
right: 10,
top: 10,
bottom: 10,
}
2021-05-14 19:32:19 +08:00
}).in(this)
2021-05-14 19:55:32 +08:00
this.layoutConfig = layoutConfig().mostWidth().fitHeight()
}
applyChild(config: {
title?: Partial<Text>,
subTitle?: Partial<Text>,
switch?: Partial<Switch>,
}) {
this.title.hidden = !!!config.title?.text
this.subTitle.hidden = !!!config.subTitle?.text
if (config.title) {
this.title.apply(config.title)
}
if (config.subTitle) {
this.subTitle.apply(config.subTitle)
}
if (config.switch) {
this.switch.apply(config.switch)
}
return this
}
}
export function preferenceView(config?: Partial<PreferenceView>) {
const ret = new PreferenceView
if (config) {
ret.apply(config)
2021-05-14 19:32:19 +08:00
}
2021-05-14 19:55:32 +08:00
return ret
2021-05-14 19:32:19 +08:00
}