CreateFolderDialog.ets 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { CommonConstants } from '../common/constants/CommonConstants';
  2. @CustomDialog
  3. export struct CreateFolderDialog {
  4. controller?: CustomDialogController;
  5. onConfirm?: (folderName: string) => void;
  6. onCancel?: () => void;
  7. initialName: string = '';
  8. title: string = '新建文件夹';
  9. placeholder: string = '请输入文件夹名称';
  10. confirmText: string = '创建';
  11. cancelText: string = '取消';
  12. themeColor: string = CommonConstants.DEFAULT_THEME_COLOR;
  13. @State folderName: string = '';
  14. aboutToAppear(): void {
  15. this.folderName = this.initialName || '';
  16. }
  17. private handleConfirm(): void {
  18. const name = this.folderName.trim();
  19. if (name.length === 0) {
  20. return;
  21. }
  22. this.onConfirm?.(name);
  23. this.controller?.close();
  24. }
  25. private handleCancel(): void {
  26. this.onCancel?.();
  27. this.controller?.close();
  28. }
  29. build() {
  30. Column() {
  31. Text(this.title)
  32. .fontSize(20)
  33. .fontWeight(FontWeight.Medium)
  34. .margin({ bottom: 12 });
  35. TextInput({ text: this.folderName, placeholder: this.placeholder })
  36. .width('100%')
  37. .height(48)
  38. .backgroundColor(Color.White)
  39. .padding({ left: 12, right: 12 })
  40. .borderRadius(12)
  41. .onChange((value: string) => {
  42. this.folderName = value;
  43. });
  44. Row() {
  45. Button(this.cancelText)
  46. .layoutWeight(1)
  47. .height(44)
  48. .backgroundColor(Color.Transparent)
  49. .fontColor(Color.Gray)
  50. .border({ color: Color.Gray, width: 1, radius: 12 })
  51. .onClick(() => this.handleCancel())
  52. .margin({ right: 8 });
  53. Button(this.confirmText)
  54. .layoutWeight(1)
  55. .height(44)
  56. .backgroundColor(this.themeColor || CommonConstants.DEFAULT_THEME_COLOR)
  57. .fontColor(Color.White)
  58. .borderRadius(12)
  59. .onClick(() => this.handleConfirm())
  60. .margin({ left: 8 });
  61. }
  62. .margin({ top: 16 })
  63. .justifyContent(FlexAlign.SpaceBetween);
  64. }
  65. .padding(24)
  66. .width('100%')
  67. .backgroundColor($r('app.color.start_window_background'))
  68. .borderRadius(24);
  69. }
  70. }