index.tsx 1019 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { css } from "@linaria/core";
  2. import { queenApi } from "queenjs";
  3. import { string } from "vue-types";
  4. import { useEditor } from "../../../..";
  5. import { createUIComp } from "../../defines/createUIComp";
  6. export const Image = createUIComp({
  7. props: {
  8. value: string().def(""),
  9. },
  10. emits: ["update:value"],
  11. setup(props, { emit }) {
  12. const { store } = useEditor();
  13. async function changeVal() {
  14. const files = await queenApi.selectFile();
  15. emit("update:value", URL.createObjectURL(files[0]));
  16. }
  17. return () => (
  18. <img
  19. class="w-1/1 h-1/1"
  20. src={props.value}
  21. onClick={store.isEditMode ? changeVal : undefined}
  22. />
  23. );
  24. },
  25. });
  26. const btnStyle = css`
  27. position: absolute;
  28. display: none;
  29. top: 50%;
  30. left: 50%;
  31. width: 0.6rem;
  32. height: 0.6rem;
  33. line-height: 0.6rem;
  34. text-align: center;
  35. border-radius: 50%;
  36. background-color: rgba(0, 0, 0, 0.5);
  37. transform: translate(-50%, -50%);
  38. cursor: pointer;
  39. &:hover {
  40. display: block;
  41. }
  42. `;