sales-frontend-components 0.0.39 → 0.0.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/camera/camera.module.scss +5 -0
- package/dist/index.cjs.js +84 -30
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +9 -7
- package/dist/index.esm.js +84 -30
- package/dist/index.esm.js.map +1 -1
- package/dist/modal/sample/test.module.scss +5 -0
- package/package.json +8 -8
|
@@ -119,6 +119,7 @@
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
.add-photo-item {
|
|
122
|
+
background-color: colors(background-200);
|
|
122
123
|
.add-photo-button {
|
|
123
124
|
position: relative;
|
|
124
125
|
display: flex;
|
|
@@ -146,6 +147,10 @@
|
|
|
146
147
|
height: 40px;
|
|
147
148
|
}
|
|
148
149
|
}
|
|
150
|
+
|
|
151
|
+
span {
|
|
152
|
+
@include apply-typography(subtitle3);
|
|
153
|
+
}
|
|
149
154
|
}
|
|
150
155
|
|
|
151
156
|
.add-photo-button-single {
|
package/dist/index.cjs.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var reactTable = require('@tanstack/react-table');
|
|
5
|
-
var styles = require('./data-table/data-table.module.scss');
|
|
6
5
|
var salesFrontendDesignSystem = require('sales-frontend-design-system');
|
|
6
|
+
var styles = require('./data-table/data-table.module.scss');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var reactHookForm = require('react-hook-form');
|
|
9
9
|
var styles$1 = require('./form/form-signautre/form-signature.module.scss');
|
|
@@ -326,9 +326,13 @@ const FormSignature = ({
|
|
|
326
326
|
const [currentStrokeLength, setCurrentStrokeLength] = React.useState(0);
|
|
327
327
|
React.useEffect(() => {
|
|
328
328
|
const canvas = canvasRef.current;
|
|
329
|
-
if (!canvas)
|
|
329
|
+
if (!canvas) {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
330
332
|
const ctx = canvas.getContext("2d");
|
|
331
|
-
if (!ctx)
|
|
333
|
+
if (!ctx) {
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
332
336
|
ctx.strokeStyle = "#000000";
|
|
333
337
|
ctx.lineWidth = Math.max(1, canvasWidth / 400);
|
|
334
338
|
ctx.lineCap = "round";
|
|
@@ -348,7 +352,9 @@ const FormSignature = ({
|
|
|
348
352
|
}, [isDrawing]);
|
|
349
353
|
const getCanvasCoordinates = React.useCallback((e) => {
|
|
350
354
|
const canvas = canvasRef.current;
|
|
351
|
-
if (!canvas)
|
|
355
|
+
if (!canvas) {
|
|
356
|
+
return { x: 0, y: 0 };
|
|
357
|
+
}
|
|
352
358
|
const rect = canvas.getBoundingClientRect();
|
|
353
359
|
const scaleX = canvas.width / rect.width;
|
|
354
360
|
const scaleY = canvas.height / rect.height;
|
|
@@ -363,9 +369,13 @@ const FormSignature = ({
|
|
|
363
369
|
const startDrawing = React.useCallback(
|
|
364
370
|
(e) => {
|
|
365
371
|
const canvas = canvasRef.current;
|
|
366
|
-
if (!canvas)
|
|
372
|
+
if (!canvas) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
367
375
|
const ctx = canvas.getContext("2d");
|
|
368
|
-
if (!ctx)
|
|
376
|
+
if (!ctx) {
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
369
379
|
const { x, y } = getCanvasCoordinates(e);
|
|
370
380
|
setIsDrawing(true);
|
|
371
381
|
setIsMousePressed(true);
|
|
@@ -379,11 +389,17 @@ const FormSignature = ({
|
|
|
379
389
|
);
|
|
380
390
|
const draw = React.useCallback(
|
|
381
391
|
(e) => {
|
|
382
|
-
if (!isDrawing)
|
|
392
|
+
if (!isDrawing) {
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
383
395
|
const canvas = canvasRef.current;
|
|
384
|
-
if (!canvas)
|
|
396
|
+
if (!canvas) {
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
385
399
|
const ctx = canvas.getContext("2d");
|
|
386
|
-
if (!ctx)
|
|
400
|
+
if (!ctx) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
387
403
|
const { x, y } = getCanvasCoordinates(e);
|
|
388
404
|
const currentPoint = { x, y };
|
|
389
405
|
if (lastPoint) {
|
|
@@ -413,9 +429,13 @@ const FormSignature = ({
|
|
|
413
429
|
(e) => {
|
|
414
430
|
if (isMousePressed && !isDrawing) {
|
|
415
431
|
const canvas = canvasRef.current;
|
|
416
|
-
if (!canvas)
|
|
432
|
+
if (!canvas) {
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
417
435
|
const ctx = canvas.getContext("2d");
|
|
418
|
-
if (!ctx)
|
|
436
|
+
if (!ctx) {
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
419
439
|
const { x, y } = getCanvasCoordinates(e);
|
|
420
440
|
setIsDrawing(true);
|
|
421
441
|
setLastPoint({ x, y });
|
|
@@ -433,9 +453,13 @@ const FormSignature = ({
|
|
|
433
453
|
}, [isDrawing]);
|
|
434
454
|
const clearSignature = React.useCallback(() => {
|
|
435
455
|
const canvas = canvasRef.current;
|
|
436
|
-
if (!canvas)
|
|
456
|
+
if (!canvas) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
437
459
|
const ctx = canvas.getContext("2d");
|
|
438
|
-
if (!ctx)
|
|
460
|
+
if (!ctx) {
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
439
463
|
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
|
|
440
464
|
setIsEmpty(true);
|
|
441
465
|
setSignatureData("");
|
|
@@ -493,7 +517,9 @@ const FormSignature = ({
|
|
|
493
517
|
};
|
|
494
518
|
}, [signatureData, isEmpty, totalLineLength, strokeLengths]);
|
|
495
519
|
const handleSubmit = React.useCallback(() => {
|
|
496
|
-
if (!validateForm())
|
|
520
|
+
if (!validateForm()) {
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
497
523
|
const data = getSignatureDataObject();
|
|
498
524
|
if (data) {
|
|
499
525
|
console.log("\uC81C\uCD9C\uB41C \uB370\uC774\uD130:", data);
|
|
@@ -505,7 +531,9 @@ const FormSignature = ({
|
|
|
505
531
|
onReset?.();
|
|
506
532
|
}, [clearSignature, onReset]);
|
|
507
533
|
const handleRecentSignatureLoad = React.useCallback(async () => {
|
|
508
|
-
if (!onRecentSignatureLoad)
|
|
534
|
+
if (!onRecentSignatureLoad) {
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
509
537
|
try {
|
|
510
538
|
setIsLoadingSignature(true);
|
|
511
539
|
const loadedSignature = await onRecentSignatureLoad();
|
|
@@ -642,10 +670,16 @@ const useFormSignature = ({ onSubmit, onError, onClear, minLength = 100 } = {})
|
|
|
642
670
|
}, []);
|
|
643
671
|
const isValid = React.useCallback(() => {
|
|
644
672
|
const basicValid = signatureRef.current?.isValid() ?? false;
|
|
645
|
-
if (!basicValid)
|
|
673
|
+
if (!basicValid) {
|
|
674
|
+
return false;
|
|
675
|
+
}
|
|
646
676
|
const data = signatureRef.current?.getSignatureData();
|
|
647
|
-
if (!data)
|
|
648
|
-
|
|
677
|
+
if (!data) {
|
|
678
|
+
return false;
|
|
679
|
+
}
|
|
680
|
+
if (isLoadedFromRecent) {
|
|
681
|
+
return true;
|
|
682
|
+
}
|
|
649
683
|
return data.totalLineLength >= minLength;
|
|
650
684
|
}, [minLength, isLoadedFromRecent]);
|
|
651
685
|
const getSignatureData = React.useCallback(() => {
|
|
@@ -722,7 +756,14 @@ const StepIndicator = ({
|
|
|
722
756
|
};
|
|
723
757
|
|
|
724
758
|
const cx = classNames.bind(styles$3);
|
|
725
|
-
function
|
|
759
|
+
function Attachment({
|
|
760
|
+
photos,
|
|
761
|
+
onAddPhoto,
|
|
762
|
+
onRemovePhoto,
|
|
763
|
+
show,
|
|
764
|
+
type = "multiple",
|
|
765
|
+
buttonText
|
|
766
|
+
}) {
|
|
726
767
|
const handleAddPhoto = () => {
|
|
727
768
|
onAddPhoto();
|
|
728
769
|
};
|
|
@@ -733,7 +774,7 @@ function Attachement({ photos, onAddPhoto, onRemovePhoto, show, type = "multiple
|
|
|
733
774
|
if (photos.length === 0) {
|
|
734
775
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cx("single-photo-item", "add-photo-item"), children: /* @__PURE__ */ jsxRuntime.jsxs("button", { className: cx("add-photo-button-single"), onClick: handleAddPhoto, children: [
|
|
735
776
|
/* @__PURE__ */ jsxRuntime.jsx(salesFrontendDesignSystem.Icon, { name: "illust/camera" }),
|
|
736
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "\uC0AC\uC9C4 \uCCA8\uBD80\uD558\uAE30" })
|
|
777
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: buttonText || "\uC0AC\uC9C4 \uCCA8\uBD80\uD558\uAE30" })
|
|
737
778
|
] }) });
|
|
738
779
|
}
|
|
739
780
|
return photos.map((photo) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cx("single-photo-item"), children: [
|
|
@@ -748,7 +789,7 @@ function Attachement({ photos, onAddPhoto, onRemovePhoto, show, type = "multiple
|
|
|
748
789
|
gridItems.push(
|
|
749
790
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: cx("photo-item", "add-photo-item"), children: /* @__PURE__ */ jsxRuntime.jsxs("button", { className: cx("add-photo-button"), onClick: handleAddPhoto, children: [
|
|
750
791
|
/* @__PURE__ */ jsxRuntime.jsx(salesFrontendDesignSystem.Icon, { name: "illust/camera" }),
|
|
751
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "\uCCA8\uBD80\uD558\uAE30" }),
|
|
792
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: buttonText || "\uCCA8\uBD80\uD558\uAE30" }),
|
|
752
793
|
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: cx("photo-count"), children: [
|
|
753
794
|
"(",
|
|
754
795
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: cx("photo-count-number"), children: photos.length }),
|
|
@@ -831,7 +872,7 @@ function resize(image, options = { ext: "jpeg", filesize: maxImageSize }) {
|
|
|
831
872
|
return;
|
|
832
873
|
}
|
|
833
874
|
const mimeType = ext === "png" ? "image/png" : "image/jpeg";
|
|
834
|
-
const fileName = image.name ? image.name.replace(/\.[^/.]+$/, "")
|
|
875
|
+
const fileName = image.name ? `${image.name.replace(/\.[^/.]+$/, "")}.${ext}` : `resized.${ext}`;
|
|
835
876
|
const resizedFile = new File([blob], fileName, { type: mimeType });
|
|
836
877
|
resolve(resizedFile);
|
|
837
878
|
},
|
|
@@ -869,7 +910,8 @@ function useCamera({
|
|
|
869
910
|
cameraOnly,
|
|
870
911
|
onDelete,
|
|
871
912
|
show,
|
|
872
|
-
type = "multiple"
|
|
913
|
+
type = "multiple",
|
|
914
|
+
buttonText
|
|
873
915
|
} = {}) {
|
|
874
916
|
const [attachedPhotos, setAttachedPhotos] = React.useState([]);
|
|
875
917
|
const findImage = (imageId) => {
|
|
@@ -884,7 +926,7 @@ function useCamera({
|
|
|
884
926
|
}
|
|
885
927
|
input.addEventListener("change", async (event) => {
|
|
886
928
|
const target = event.target;
|
|
887
|
-
const files = target
|
|
929
|
+
const { files } = target;
|
|
888
930
|
if (files && files.length > 0) {
|
|
889
931
|
const file = files[0];
|
|
890
932
|
if (file) {
|
|
@@ -894,7 +936,11 @@ function useCamera({
|
|
|
894
936
|
src: URL.createObjectURL(resizedFile),
|
|
895
937
|
name: `\uC11C\uB958\uC0AC\uC9C4_${attachedPhotos.length + 1}`
|
|
896
938
|
};
|
|
897
|
-
|
|
939
|
+
if (type === "single") {
|
|
940
|
+
setAttachedPhotos([newPhoto]);
|
|
941
|
+
} else {
|
|
942
|
+
setAttachedPhotos([...attachedPhotos, newPhoto]);
|
|
943
|
+
}
|
|
898
944
|
onChange && onChange(file);
|
|
899
945
|
}
|
|
900
946
|
}
|
|
@@ -908,14 +954,22 @@ function useCamera({
|
|
|
908
954
|
const imageIndex = attachedPhotos.findIndex((image) => image.id === imageId);
|
|
909
955
|
if (imageIndex > -1) {
|
|
910
956
|
const item = attachedPhotos.splice(imageIndex, 1);
|
|
911
|
-
URL.revokeObjectURL(item[0].src);
|
|
957
|
+
item[0] && URL.revokeObjectURL(item[0].src);
|
|
912
958
|
setAttachedPhotos([...attachedPhotos]);
|
|
913
959
|
onDelete && onDelete(imageId);
|
|
914
960
|
}
|
|
915
961
|
};
|
|
916
|
-
const CameraComponent =
|
|
917
|
-
|
|
918
|
-
|
|
962
|
+
const CameraComponent = () => /* @__PURE__ */ jsxRuntime.jsx(
|
|
963
|
+
Attachment,
|
|
964
|
+
{
|
|
965
|
+
show: !!show,
|
|
966
|
+
onAddPhoto: onClick,
|
|
967
|
+
onRemovePhoto: deleteImage,
|
|
968
|
+
photos: attachedPhotos,
|
|
969
|
+
type,
|
|
970
|
+
buttonText
|
|
971
|
+
}
|
|
972
|
+
);
|
|
919
973
|
React.useEffect(() => {
|
|
920
974
|
return () => {
|
|
921
975
|
attachedPhotos.forEach((image) => {
|
|
@@ -932,7 +986,7 @@ function useCamera({
|
|
|
932
986
|
};
|
|
933
987
|
}
|
|
934
988
|
|
|
935
|
-
exports.
|
|
989
|
+
exports.Attachment = Attachment;
|
|
936
990
|
exports.DataTable = DataTable;
|
|
937
991
|
exports.FormDatePicker = FormDatePicker;
|
|
938
992
|
exports.FormSegmentGroup = FormSegmentGroup;
|