CardContainer.ets 908 B

12345678910111213141516171819202122232425262728293031323334353637
  1. @Component
  2. export struct CardContainer {
  3. @Prop radius: number | string = 16
  4. @Prop bgColor: string = '#FFFFFF'
  5. @Prop shadowColor: string = '#000000'
  6. @Prop shadowOpacity: number = 0.1
  7. @Prop blurRadius: number = 40
  8. @Prop cardColor: Color = Color.White
  9. @Prop paddings: Padding | Length = 0
  10. @Prop margins: Margin = {}
  11. // 是否裁剪超出部分
  12. @Prop needClip: boolean = true
  13. @BuilderParam children: () => void = this.content
  14. build() {
  15. Stack() {
  16. // 内容插槽
  17. this.children()
  18. }
  19. .padding(this.paddings)
  20. .borderRadius(this.radius)
  21. .backgroundColor(this.bgColor)
  22. .margin(this.margins)
  23. .clip(this.needClip)
  24. .shadow({
  25. radius: this.blurRadius,
  26. color: this.shadowColor.replace("#", "#" + Math.round(this.shadowOpacity * 255).toString(16).padStart(2, '0')),
  27. offsetX: 0,
  28. offsetY: 0
  29. })
  30. }
  31. @Builder
  32. content() {
  33. }
  34. }