diff --git a/zh-cn/application-dev/ui/Readme-CN.md b/zh-cn/application-dev/ui/Readme-CN.md index 4599b0a8e6bf487794e6c6b19407c60bab0de920..1dea595ff58ca02b730ca0664e1edb8eda7a4a15 100755 --- a/zh-cn/application-dev/ui/Readme-CN.md +++ b/zh-cn/application-dev/ui/Readme-CN.md @@ -76,6 +76,7 @@ - [@Builder](ts-component-based-builder.md) - [@Extend](ts-component-based-extend.md) - [@CustomDialog](ts-component-based-customdialog.md) + - [@Styles](ts-component-based-styles.md) - UI状态管理 - [基本概念](ts-ui-state-mgmt-concepts.md) - 管理组件拥有的状态 diff --git a/zh-cn/application-dev/ui/ts-component-based-styles.md b/zh-cn/application-dev/ui/ts-component-based-styles.md new file mode 100644 index 0000000000000000000000000000000000000000..6f26561661d29ba5ab04a646b00c30dd5f07b3b6 --- /dev/null +++ b/zh-cn/application-dev/ui/ts-component-based-styles.md @@ -0,0 +1,72 @@ +# @Styles + + + +@Styles装饰器将新的属性函数添加到基本组件上,如**Text**、**Column**、**Button**等。当前@Styles仅支持[通用属性](../reference/arkui-ts/ts-universal-attributes.md)。通过@Styles装饰器可以快速定义并复用组件的自定义样式。 + +@Styles可以定义在组件内或组件外,在组件外定义时需带上function关键字,组件内定义时不需要。 + + +``` +@Styles function globalFancy() { + .backgroundColor(Color.Red) +} + +@Entry +@Component +struct FancyUse { + @Styles componentFancy() { + .backgroundColor(Color.Blue) + } + build() { + Column({ space: 10 }) { + Text("Fancy") + .globalFancy() + .width(100) + .height(100) + .fontSize(30) + Text("Fancy") + .componentFancy() + .width(100) + .height(100) + .fontSize(30) + } + } +} +``` + +@Styles还可以在[StateStyles](../reference/arkui-ts/ts-universal-attributes-polymorphic-style.md)属性内部使用,在组件处于不同的状态时赋予相应的属性。 + +在StateStyles内可以直接调用组件外定义的Styles,但需要通过this关键字调用组件内定义的Styles。 + +``` +@Styles function globalFancy() { + .width(100) + .height(100) +} + +@Entry +@Component +struct FancyUse { + @Styles function componentFancy() { + .width(50) + .height(50) + } + build() { + Row({ space: 10 }) { + Button() { + Text("Fancy") + } + .stateStyles({ + normal: { + .width(80) + .height(80) + }, + disabled: this.componentFancy, + pressed: globalFancy + }) + } + } +} +``` + diff --git a/zh-cn/application-dev/ui/ts-syntactic-sugar.md b/zh-cn/application-dev/ui/ts-syntactic-sugar.md index 6b85b89b8b385d5ae88c9fc4141b800aad122047..41b4171942ccbfafc85f39d6b6ca935baddf06d0 100644 --- a/zh-cn/application-dev/ui/ts-syntactic-sugar.md +++ b/zh-cn/application-dev/ui/ts-syntactic-sugar.md @@ -135,3 +135,34 @@ build() { Text(this.calcTextValue()) // this function call is ok. } ``` + + +## $$ + +$$支持变量双向绑定,支持简单变量、@State、@Link、@Prop等类型。 + +当前$$仅支持[bindPopup](../reference/arkui-ts/ts-universal-attributes-popup.md)属性的show参数和@State变量之间的渲染,以及Radio组件的checked属性。 + + +``` +@Entry +@Component +struct bindPopup { + @State customPopup: boolean = false + build() { + Column() { + Button(){ + Text('Popup') + } + .onClick(()=>{ + this.customPopup = !this.customPopup + }) + .bindPopup( + $$this.customPopup, { + message: "showPopup" + } + ) + } + } +} +```