ThemeText.ets 1.5 KB

@Extend(Text) function info () {
  .fontColor('#909399').backgroundColor('#f4f4f5')
  .borderColor('#e9e9eb')
}
@Extend(Text) function primary () {
  .fontColor('#1890ff').backgroundColor('#e8f4ff')
  .borderColor('#d1e9ff')
}
@Extend(Text) function warning () {
  .fontColor('#ffba00').backgroundColor('#fff8e6')
  .borderColor('#fff1cc')
}
@Extend(Text) function success () {
  .fontColor('#13ce66').backgroundColor('#e7faf0')
  .borderColor('#d0f5e0')
}
@Extend(Text) function danger () {
  .fontColor('#ff4949').backgroundColor('#ffeded')
  .borderColor('#ffdbdb')
}
@Component
export default  struct ThemeTest {
  @Prop theme: string
  @Prop textValue: string
  build() {
    if(this.theme == 'info') {
      Text(this.textValue).padding({left: 6, right: 6})
        .borderWidth(1).fontSize(12).borderRadius(4).lineHeight(16).info()
    } else if(this.theme == 'primary'){
      Text(this.textValue).padding({left: 6, right: 6})
        .borderWidth(1).fontSize(12).borderRadius(4).lineHeight(16).primary()
    } else if(this.theme == 'warning'){
      Text(this.textValue).padding({left: 6, right: 6})
        .borderWidth(1).fontSize(12).borderRadius(4).lineHeight(16).warning()
    } else if(this.theme == 'success'){
      Text(this.textValue).padding({left: 6, right: 6})
        .borderWidth(1).fontSize(12).borderRadius(4).lineHeight(16).success()
    } else if(this.theme == 'danger'){
      Text(this.textValue).padding({left: 6, right: 6})
        .borderWidth(1).fontSize(12).borderRadius(4).lineHeight(16).danger()
    }
  }
}