PickerToolbar.mjs 1.8 KB

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