PickerToolbar.mjs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { defineComponent, createVNode as _createVNode } from "vue";
  2. import { bem, t } from "./utils.mjs";
  3. import { createNamespace, HAPTICS_FEEDBACK } from "../utils/index.mjs";
  4. const [name] = createNamespace("picker-toolbar");
  5. const pickerToolbarProps = {
  6. title: String,
  7. cancelButtonText: String,
  8. confirmButtonText: String
  9. };
  10. const pickerToolbarSlots = ["cancel", "confirm", "title", "toolbar"];
  11. const pickerToolbarPropKeys = Object.keys(pickerToolbarProps);
  12. var stdin_default = defineComponent({
  13. name,
  14. props: pickerToolbarProps,
  15. emits: ["confirm", "cancel"],
  16. setup(props, {
  17. emit,
  18. slots
  19. }) {
  20. const renderTitle = () => {
  21. if (slots.title) {
  22. return slots.title();
  23. }
  24. if (props.title) {
  25. return _createVNode("div", {
  26. "class": [bem("title"), "van-ellipsis"]
  27. }, [props.title]);
  28. }
  29. };
  30. const onCancel = () => emit("cancel");
  31. const onConfirm = () => emit("confirm");
  32. const renderCancel = () => {
  33. var _a;
  34. const text = (_a = props.cancelButtonText) != null ? _a : t("cancel");
  35. if (!slots.cancel && !text) {
  36. return;
  37. }
  38. return _createVNode("button", {
  39. "type": "button",
  40. "class": [bem("cancel"), HAPTICS_FEEDBACK],
  41. "onClick": onCancel
  42. }, [slots.cancel ? slots.cancel() : text]);
  43. };
  44. const renderConfirm = () => {
  45. var _a;
  46. const text = (_a = props.confirmButtonText) != null ? _a : t("confirm");
  47. if (!slots.confirm && !text) {
  48. return;
  49. }
  50. return _createVNode("button", {
  51. "type": "button",
  52. "class": [bem("confirm"), HAPTICS_FEEDBACK],
  53. "onClick": onConfirm
  54. }, [slots.confirm ? slots.confirm() : text]);
  55. };
  56. return () => _createVNode("div", {
  57. "class": bem("toolbar")
  58. }, [slots.toolbar ? slots.toolbar() : [renderCancel(), renderTitle(), renderConfirm()]]);
  59. }
  60. });
  61. export {
  62. stdin_default as default,
  63. pickerToolbarPropKeys,
  64. pickerToolbarProps,
  65. pickerToolbarSlots
  66. };