From 3f7e68ea03ab20e36224c1b065d849e891b8fb52 Mon Sep 17 00:00:00 2001 From: kris-liu-smile Date: Thu, 6 Jul 2023 15:16:56 +0800 Subject: [PATCH] feat: add invoice resizable --- apps/storefront/package.json | 2 + .../invoice/components/PrintTempalte.tsx | 61 ++++++++++++++++++- yarn.lock | 27 +++++++- 3 files changed, 86 insertions(+), 4 deletions(-) diff --git a/apps/storefront/package.json b/apps/storefront/package.json index 1deb41e1..68b8434c 100644 --- a/apps/storefront/package.json +++ b/apps/storefront/package.json @@ -29,6 +29,7 @@ "@rollup/plugin-graphql": "^1.1.0", "@types/babel__core": "^7.1.19", "@types/pdfobject": "^2.2.3", + "@types/react-resizable": "^3.0.4", "copy-to-clipboard": "^3.3.3", "date-fns": "^2.28.0", "http-server": "^14.1.1", @@ -41,6 +42,7 @@ "react-mui-dropzone": "^4.0.6", "react-pdf": "^7.1.2", "react-redux": "^8.0.5", + "react-resizable": "^3.0.5", "react-router-dom": "6", "ts-tracking-number": "^1.0.16", "uuid": "^9.0.0" diff --git a/apps/storefront/src/pages/invoice/components/PrintTempalte.tsx b/apps/storefront/src/pages/invoice/components/PrintTempalte.tsx index 9c1efcf0..95da170c 100644 --- a/apps/storefront/src/pages/invoice/components/PrintTempalte.tsx +++ b/apps/storefront/src/pages/invoice/components/PrintTempalte.tsx @@ -1,4 +1,6 @@ -import { useEffect, useRef, useState } from 'react' +import { SyntheticEvent, useEffect, useRef, useState } from 'react' +import { Resizable } from 'react-resizable' +import { Box } from '@mui/material' import PDFObject from 'pdfobject' import { B3Sping } from '@/components' @@ -12,6 +14,8 @@ interface RowList { updatedAt: number } +const templateMinHeight = 300 + interface PrintTempalteProps { row: RowList } @@ -19,7 +23,18 @@ interface PrintTempalteProps { function PrintTempalte({ row }: PrintTempalteProps) { const container = useRef(null) + const dom = useRef(null) + const [loadding, setLoadding] = useState(false) + + const [height, setHeight] = useState(templateMinHeight) + + const onFirstBoxResize = ( + event: SyntheticEvent, + { size }: { size: { height: number } } + ) => { + setHeight(size.height) + } const viewPrint = async () => { setLoadding(true) const { id: invoiceId } = row @@ -43,7 +58,49 @@ function PrintTempalte({ row }: PrintTempalteProps) { return ( -
+ + +
+
+
+ + ) } diff --git a/yarn.lock b/yarn.lock index f083f925..f2232999 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1166,6 +1166,13 @@ dependencies: "@types/react" "^17" +"@types/react-resizable@^3.0.4": + version "3.0.4" + resolved "https://registry.yarnpkg.com/@types/react-resizable/-/react-resizable-3.0.4.tgz#2f5a1b6c79dd0b8729959deefc8628ab484724cc" + integrity sha512-+QguN9CDfC1lthq+4noG1fkxh8cqkV2Fv/Mu3mdknCCBiwwNLecnBdk1MmNNN7uJpT23Nx/aVkYsbt5NuWouFw== + dependencies: + "@types/react" "*" + "@types/react-transition-group@^4.4.5": version "4.4.6" resolved "https://registry.yarnpkg.com/@types/react-transition-group/-/react-transition-group-4.4.6.tgz#18187bcda5281f8e10dfc48f0943e2fdf4f75e2e" @@ -1845,7 +1852,7 @@ cliui@^8.0.1: strip-ansi "^6.0.1" wrap-ansi "^7.0.0" -clsx@^1.0.2, clsx@^1.2.1: +clsx@^1.0.2, clsx@^1.1.1, clsx@^1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/clsx/-/clsx-1.2.1.tgz#0ddc4a20a549b59c93a4116bb26f5294ca17dc12" integrity sha512-EcR6r5a8bj6pu3ycsa/E/cKVGuTgZJZdsyUYHOksG/UHIiKfjxzRxYJpyVBwYaQeOvghal9fcc4PidlgzugAQg== @@ -4771,7 +4778,7 @@ pretty-format@^27.0.2: ansi-styles "^5.0.0" react-is "^17.0.1" -prop-types@^15.5.8, prop-types@^15.6.2, prop-types@^15.7.2, prop-types@^15.8.1: +prop-types@15.x, prop-types@^15.5.8, prop-types@^15.6.2, prop-types@^15.7.2, prop-types@^15.8.1: version "15.8.1" resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5" integrity sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg== @@ -4830,6 +4837,14 @@ react-dom@^18.0.0: loose-envify "^1.1.0" scheduler "^0.23.0" +react-draggable@^4.0.3: + version "4.4.5" + resolved "https://registry.yarnpkg.com/react-draggable/-/react-draggable-4.4.5.tgz#9e37fe7ce1a4cf843030f521a0a4cc41886d7e7c" + integrity sha512-OMHzJdyJbYTZo4uQE393fHcqqPYsEtkjfMgvCHr6rejT+Ezn4OZbNyGH50vv+SunC1RMvwOTSWkEODQLzw1M9g== + dependencies: + clsx "^1.1.1" + prop-types "^15.8.1" + react-dropzone@^10.2.1: version "10.2.2" resolved "https://registry.yarnpkg.com/react-dropzone/-/react-dropzone-10.2.2.tgz#67b4db7459589a42c3b891a82eaf9ade7650b815" @@ -4922,6 +4937,14 @@ react-refresh@^0.14.0: resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.14.0.tgz#4e02825378a5f227079554d4284889354e5f553e" integrity sha512-wViHqhAd8OHeLS/IRMJjTSDHF3U9eWi62F/MledQGPdJGDhodXJ9PBLNGr6WWL7qlH12Mt3TyTpbS+hGXMjCzQ== +react-resizable@^3.0.5: + version "3.0.5" + resolved "https://registry.yarnpkg.com/react-resizable/-/react-resizable-3.0.5.tgz#362721f2efbd094976f1780ae13f1ad7739786c1" + integrity sha512-vKpeHhI5OZvYn82kXOs1bC8aOXktGU5AmKAgaZS4F5JPburCtbmDPqE7Pzp+1kN4+Wb81LlF33VpGwWwtXem+w== + dependencies: + prop-types "15.x" + react-draggable "^4.0.3" + react-router-dom@6: version "6.13.0" resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-6.13.0.tgz#6651f456bb2af42ef14f6880123b1f575539e81f"