From b99d8e6d6eaad9369528b554005bb1d6eb0797fc Mon Sep 17 00:00:00 2001 From: prafull-opensignlabs Date: Thu, 14 Mar 2024 16:50:46 +0530 Subject: [PATCH] feat: add show/hide label in checkbox and radio widget --- .../components/pdf/DropdownWidgetOption.js | 55 ++++--- .../src/components/pdf/Placeholder.js | 29 ++-- .../src/components/pdf/PlaceholderBorder.js | 27 +++- .../src/components/pdf/PlaceholderType.js | 134 ++++++++++-------- apps/OpenSign/src/constant/Utils.js | 28 +++- apps/OpenSign/src/pages/Form.js | 2 +- apps/OpenSign/src/pages/PdfRequestFiles.js | 1 - apps/OpenSign/src/pages/PlaceHolderSign.js | 9 +- apps/OpenSign/src/pages/SignyourselfPdf.js | 8 +- .../OpenSign/src/pages/TemplatePlaceholder.js | 13 +- apps/OpenSign/src/styles/signature.css | 2 + 11 files changed, 194 insertions(+), 114 deletions(-) diff --git a/apps/OpenSign/src/components/pdf/DropdownWidgetOption.js b/apps/OpenSign/src/components/pdf/DropdownWidgetOption.js index 1d9b2f415..b4d3b1dd6 100644 --- a/apps/OpenSign/src/components/pdf/DropdownWidgetOption.js +++ b/apps/OpenSign/src/components/pdf/DropdownWidgetOption.js @@ -11,6 +11,7 @@ function DropdownWidgetOption(props) { const [maxCount, setMaxCount] = useState(0); const [dropdownName, setDropdownName] = useState(props.type); const [isReadOnly, setIsReadOnly] = useState(false); + const [isHideLabel, setIsHideLabel] = useState(false); const [status, setStatus] = useState("required"); const [defaultValue, setDefaultValue] = useState(""); const statusArr = ["required", "optional"]; @@ -20,6 +21,7 @@ function DropdownWidgetOption(props) { setDropdownOptionList(["option-1", "option-2"]); setDropdownName(props.type); setIsReadOnly(false); + setIsHideLabel(false); setMinCount(0); setMaxCount(0); setDefaultCheckbox([]); @@ -40,6 +42,7 @@ function DropdownWidgetOption(props) { props.currWidgetsDetails?.options?.validation?.maxRequiredCount ); setIsReadOnly(props.currWidgetsDetails?.options?.isReadOnly); + setIsHideLabel(props.currWidgetsDetails?.options?.isHideLabel); setStatus(props.currWidgetsDetails?.options?.status || "required"); setDefaultValue(props.currWidgetsDetails?.options?.defaultValue || ""); setDefaultCheckbox(props.currWidgetsDetails?.options?.defaultValue || []); @@ -107,13 +110,15 @@ function DropdownWidgetOption(props) { null, null, status, - defaultData + defaultData, + isHideLabel ); // props.setShowDropdown(false); setDropdownOptionList(["option-1", "option-2"]); setDropdownName(props.type); // props.setCurrWidgetsDetails({}); setIsReadOnly(false); + setIsHideLabel(false); setMinCount(0); setMaxCount(0); setDefaultCheckbox([]); @@ -154,20 +159,6 @@ function DropdownWidgetOption(props) { }} >
- {["checkbox", radioButtonWidget].includes(props.type) && - !props.isSignYourself && ( -
- { - setIsReadOnly(e.target.checked); - }} - /> - - -
- )} @@ -358,8 +349,40 @@ function DropdownWidgetOption(props) {
)} - + {["checkbox", radioButtonWidget].includes(props.type) && ( +
+ {!props.isSignYourself && ( +
+ { + setIsReadOnly(e.target.checked); + }} + /> + +
+ )} +
+ { + setIsHideLabel(e.target.checked); + }} + /> + +
+
+ )} +
{}, []); //function change format array list with selected date and format const changeDateFormat = () => { const updateDate = []; @@ -463,12 +461,8 @@ function Placeholder(props) { )} { - handleCopyPlaceholder(e); - }} - onTouchEnd={(e) => { - handleCopyPlaceholder(e); - }} + onClick={(e) => handleCopyPlaceholder(e)} + onTouchEnd={(e) => handleCopyPlaceholder(e)} style={{ color: "#188ae2", right: @@ -526,7 +520,6 @@ function Placeholder(props) { return ( { setDraggingEnabled(true); props.handleTabDrag && props.handleTabDrag(props.pos.key); }} size={{ - width: props.posWidth(props.pos, props.isSignYourself), - height: props.posHeight(props.pos, props.isSignYourself) + width: + props.pos.type === radioButtonWidget || props.pos.type === "checkbox" + ? "auto" + : props.posWidth(props.pos, props.isSignYourself), + height: + props.pos.type === radioButtonWidget || props.pos.type === "checkbox" + ? "auto" + : props.posHeight(props.pos, props.isSignYourself) }} onResizeStart={() => { setDraggingEnabled(true); diff --git a/apps/OpenSign/src/components/pdf/PlaceholderBorder.js b/apps/OpenSign/src/components/pdf/PlaceholderBorder.js index 996d1332a..22907f296 100644 --- a/apps/OpenSign/src/components/pdf/PlaceholderBorder.js +++ b/apps/OpenSign/src/components/pdf/PlaceholderBorder.js @@ -13,6 +13,24 @@ function PlaceholderBorder(props) { const defaultWidth = defaultWidthHeight(props.pos.type).width; const defaultHeight = defaultWidthHeight(props.pos.type).height; + const handleMinWidth = () => { + if (props.pos.type === "checkbox" || props.pos.type === radioButtonWidget) { + return "120%"; + } else { + return props.pos.Width + ? props.pos.Width + getResizeBorderExtraWidth + : defaultWidth + getResizeBorderExtraWidth; + } + }; + const handleMinHeight = () => { + if (props.pos.type === "checkbox" || props.pos.type === radioButtonWidget) { + return "120%"; + } else { + return props.pos.Height + ? props.pos.Height + getResizeBorderExtraWidth + : defaultHeight + getResizeBorderExtraWidth; + } + }; return (
{ - return {value}; - }; const ExampleCustomInput = forwardRef(({ value, onClick }, ref) => (
- {dateValue(value)} + {value}
)); @@ -277,7 +274,6 @@ function PlaceholderType(props) { isRadio ); }; - //function to set onchange date const handleOnDateChange = (date) => { props.setStartDate(date); @@ -336,46 +332,54 @@ function PlaceholderType(props) {
{props.pos.options?.values?.map((data, ind) => { return ( - { - if (e.target.checked) { - if (!props.isPlaceholder) { - const maxRequired = - props.pos.options?.validation?.maxRequiredCount; - const maxCountInt = maxRequired && parseInt(maxRequired); +
+ { + if (e.target.checked) { + if (!props.isPlaceholder) { + const maxRequired = + props.pos.options?.validation?.maxRequiredCount; + const maxCountInt = + maxRequired && parseInt(maxRequired); - if (maxCountInt > 0) { - if ( - selectedCheckbox && - selectedCheckbox?.length <= maxCountInt - 1 - ) { + if (maxCountInt > 0) { + if ( + selectedCheckbox && + selectedCheckbox?.length <= maxCountInt - 1 + ) { + handleCheckboxValue(e.target.checked, ind); + } + } else { handleCheckboxValue(e.target.checked, ind); } - } else { - handleCheckboxValue(e.target.checked, ind); } + } else { + handleCheckboxValue(e.target.checked, ind); } - } else { - handleCheckboxValue(e.target.checked, ind); - } - }} - /> + }} + /> + {!props.pos.options?.isHideLabel && ( + + )} +
); })}
@@ -706,28 +710,38 @@ function PlaceholderType(props) {
{props.pos.options?.values.map((data, ind) => { return ( - { - if (!props.isPlaceholder) { - handleCheckRadio(e.target.checked, data); + className="flex flex-row items-center gap-1 min-w-max" + > + + checked={handleRadioCheck(data)} + onChange={(e) => { + if (!props.isPlaceholder) { + handleCheckRadio(e.target.checked, data); + } + }} + /> + {!props.pos.options?.isHideLabel && ( + + )} +
); })}
diff --git a/apps/OpenSign/src/constant/Utils.js b/apps/OpenSign/src/constant/Utils.js index 7e26226c2..ee89a2666 100644 --- a/apps/OpenSign/src/constant/Utils.js +++ b/apps/OpenSign/src/constant/Utils.js @@ -238,7 +238,7 @@ export const addWidgetOptions = (type) => { case "stamp": return defaultOpt; case "checkbox": - return defaultOpt; + return { defaultOpt, options: { isReadOnly: false, isHideLabel: false } }; case textInputWidget: return { ...defaultOpt, validation: { type: "text", pattern: "" } }; case "initials": @@ -262,7 +262,12 @@ export const addWidgetOptions = (type) => { case "dropdown": return defaultOpt; case radioButtonWidget: - return { ...defaultOpt, values: [] }; + return { + ...defaultOpt, + values: [], + isReadOnly: false, + isHideLabel: false + }; case textWidget: return defaultOpt; default: @@ -1176,6 +1181,14 @@ export const multiSignEmbed = async ( yPosition = yPos(position, ind); addYPosition = height + 8; } + if (!position?.options?.isHideLabel) { + // below line of code is used to embed label with radio button in pdf + page.drawText(item, { + x: xPos(position) + 15, + y: yPosition + 2, + size: height + }); + } checkbox.addToPage(page, { x: xPos(position), y: yPosition, @@ -1270,7 +1283,8 @@ export const multiSignEmbed = async ( x: xPos(position), y: yPos(position), width: scaleWidth, - height: scaleHeight + height: scaleHeight, + borderWidth: 0 }); dropdown.enableReadOnly(); } else if (position.type === radioButtonWidget) { @@ -1287,6 +1301,14 @@ export const multiSignEmbed = async ( yPosition = yPos(position); } + if (!position?.options?.isHideLabel) { + // below line of code is used to embed label with radio button in pdf + page.drawText(data, { + x: xPos(position) + 15, + y: yPosition + 2, + size: 11 + }); + } radioGroup.addOptionToPage(data, page, { x: xPos(position), y: yPosition, diff --git a/apps/OpenSign/src/pages/Form.js b/apps/OpenSign/src/pages/Form.js index bd081ef12..4aa442bda 100644 --- a/apps/OpenSign/src/pages/Form.js +++ b/apps/OpenSign/src/pages/Form.js @@ -413,7 +413,7 @@ const Forms = (props) => { type="submit" disabled={isSubmit} > - Submit + Next
{ setWidgetsTour(false); diff --git a/apps/OpenSign/src/pages/PlaceHolderSign.js b/apps/OpenSign/src/pages/PlaceHolderSign.js index 7fe365374..35351be3e 100644 --- a/apps/OpenSign/src/pages/PlaceHolderSign.js +++ b/apps/OpenSign/src/pages/PlaceHolderSign.js @@ -1055,7 +1055,8 @@ function PlaceHolderSign() { addOption, deleteOption, status, - defaultValue + defaultValue, + isHideLabel ) => { const filterSignerPos = signerPos.filter((data) => data.Id === uniqueId); if (filterSignerPos.length > 0) { @@ -1093,7 +1094,8 @@ function PlaceHolderSign() { ...position.options, name: dropdownName, values: dropdownOptions, - isReadOnly: isReadOnly, + isReadOnly: isReadOnly || false, + isHideLabel: isHideLabel || false, defaultValue: defaultValue } }; @@ -1125,7 +1127,8 @@ function PlaceHolderSign() { maxRequiredCount: maxCount }, defaultValue: defaultValue, - isReadOnly: isReadOnly + isReadOnly: isReadOnly || false, + isHideLabel: isHideLabel || false } }; } diff --git a/apps/OpenSign/src/pages/SignyourselfPdf.js b/apps/OpenSign/src/pages/SignyourselfPdf.js index 2dd3ec38b..1d4803e9f 100644 --- a/apps/OpenSign/src/pages/SignyourselfPdf.js +++ b/apps/OpenSign/src/pages/SignyourselfPdf.js @@ -870,7 +870,10 @@ function SignYourSelf() { maxCount, isReadOnly, addOption, - deleteOption + deleteOption, + status, + defaultValue, + isHideLabel ) => { const getPageNumer = xyPostion.filter( (data) => data.pageNumber === pageNumber @@ -902,7 +905,8 @@ function SignYourSelf() { ...position.options, name: dropdownName, values: dropdownOptions, - isReadOnly: isReadOnly + isReadOnly: isReadOnly, + isHideLabel: isHideLabel || false } }; } diff --git a/apps/OpenSign/src/pages/TemplatePlaceholder.js b/apps/OpenSign/src/pages/TemplatePlaceholder.js index 76b5ef7ac..dc71aaa9c 100644 --- a/apps/OpenSign/src/pages/TemplatePlaceholder.js +++ b/apps/OpenSign/src/pages/TemplatePlaceholder.js @@ -976,7 +976,8 @@ const TemplatePlaceholder = () => { addOption, deleteOption, status, - defaultValue + defaultValue, + isHideLabel ) => { const filterSignerPos = signerPos.filter((data) => data.Id === uniqueId); if (filterSignerPos.length > 0) { @@ -996,7 +997,6 @@ const TemplatePlaceholder = () => { if (addOption) { return { ...position, - Height: position.Height ? position.Height + 15 : defaultWidthHeight(widgetType).height + 15 @@ -1016,7 +1016,9 @@ const TemplatePlaceholder = () => { name: dropdownName, values: dropdownOptions, status: status, - defaultValue: defaultValue + defaultValue: defaultValue, + isReadOnly: isReadOnly || false, + isHideLabel: isHideLabel || false } }; } @@ -1046,8 +1048,9 @@ const TemplatePlaceholder = () => { minRequiredCount: minCount, maxRequiredCount: maxCount }, - isReadOnly: isReadOnly, - defaultValue: defaultValue + isReadOnly: isReadOnly || false, + defaultValue: defaultValue, + isHideLabel: isHideLabel || false } }; } diff --git a/apps/OpenSign/src/styles/signature.css b/apps/OpenSign/src/styles/signature.css index 8229cdb05..47c3d9e73 100644 --- a/apps/OpenSign/src/styles/signature.css +++ b/apps/OpenSign/src/styles/signature.css @@ -339,6 +339,8 @@ display: flex !important; justify-content: center !important; align-items: center !important; + min-width:max-content; + min-height: max-content; } .finishBtn {