component.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { useEditor } from "@/modules/editor";
  2. import { css, cx } from "@linaria/core";
  3. import { watch } from "vue";
  4. import { string } from "vue-types";
  5. import { useCompData } from ".";
  6. import { Text } from "../../../basicUI";
  7. import { createUIComp } from "../../../defines/createUIComp";
  8. export const Component = createUIComp({
  9. props: {
  10. compId: string().isRequired,
  11. },
  12. setup(props) {
  13. const { helper } = useEditor();
  14. const { value } = useCompData(props.compId);
  15. watch(
  16. () => [value.columns],
  17. () => {
  18. const { columns, list } = value;
  19. const offset = columns - list.length;
  20. if (offset > 0) {
  21. Array.from({ length: offset }, () => {
  22. list.push({ label: "标题", content: "内容" });
  23. });
  24. } else {
  25. list.splice(columns, offset * -1);
  26. }
  27. }
  28. );
  29. return () => (
  30. <div class={rootStyles}>
  31. {value.list.map((d) => (
  32. <div
  33. class="flex items-center text-primary px-0.1rem"
  34. style={{
  35. margin: helper.designToNaturalSize(value.gap),
  36. }}
  37. >
  38. <div
  39. class={cx(
  40. "py-0.08rem px-0.1rem",
  41. value.showBackground ? "label text-white" : "text-secondary"
  42. )}
  43. style={{
  44. width: helper.designToNaturalSize(value.width),
  45. }}
  46. >
  47. <Text.Component
  48. v-model={[d.label, "value"]}
  49. class="text text-center"
  50. />
  51. </div>
  52. <Text.Component
  53. v-model={[d.content, "value"]}
  54. class="flex-1 ml-0.3rem"
  55. />
  56. </div>
  57. ))}
  58. </div>
  59. );
  60. },
  61. });
  62. const rootStyles = css`
  63. .label {
  64. position: relative;
  65. z-index: 1;
  66. .text {
  67. position: relative;
  68. z-index: 1;
  69. }
  70. &::before {
  71. content: "";
  72. position: absolute;
  73. top: 0;
  74. left: 4%;
  75. width: 92%;
  76. height: 100%;
  77. background-color: #333;
  78. transform: skewX(347deg);
  79. z-index: 0;
  80. }
  81. }
  82. `;