component.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { useEditor } from "@/modules/editor";
  2. import { css } from "@linaria/core";
  3. import { watch } from "vue";
  4. import { string } from "vue-types";
  5. import { useCompData, useCreateChild } 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, children } = useCompData(props.compId);
  15. const createList = useCreateChild("list");
  16. watch(
  17. () => [value.columns],
  18. () => {
  19. const { columns } = value;
  20. const { list } = children;
  21. const offset = columns - list.length;
  22. if (offset > 0) {
  23. children.list.push(...createList(offset));
  24. } else {
  25. list.splice(columns, offset * -1);
  26. }
  27. }
  28. );
  29. return () => (
  30. <div class={rootStyles}>
  31. {children.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. <Text.Component
  39. compId={d.label}
  40. class={
  41. value.showBackground
  42. ? "text relative z-0 py-0.08rem px-0.1rem text-white"
  43. : "text-secondary"
  44. }
  45. style={{
  46. width: helper.designToNaturalSize(value.width),
  47. }}
  48. />
  49. <Text.Component compId={d.content} class="flex-1 ml-0.3rem" />
  50. </div>
  51. ))}
  52. </div>
  53. );
  54. },
  55. });
  56. const rootStyles = css`
  57. .text {
  58. &::before {
  59. content: "";
  60. position: absolute;
  61. top: 0;
  62. left: 4%;
  63. width: 92%;
  64. height: 100%;
  65. background-color: #333;
  66. transform: skewX(345deg);
  67. z-index: -1;
  68. }
  69. }
  70. `;