mirror of
https://github.com/documenso/documenso.git
synced 2025-11-10 04:22:32 +10:00
Rework: - Field styling to improve visibility - Field insertions, better alignment, centering and overflows ## Changes General changes: - Set default text alignment to left if no meta found - Reduce borders and rings around fields to allow smaller fields - Removed lots of redundant duplicated code surrounding field rendering - Make fields more consistent across viewing, editing and signing - Add more transparency to fields to allow users to see under fields - No more optional/required/etc colors when signing, required fields will be highlighted as orange when form is "validating" Highlighted internal changes: - Utilize native PDF fields to insert text, instead of drawing text - Change font auto scaling to only apply to when the height overflows AND no custom font is set ⚠️ Multiline changes: Multi line is enabled for a field under these conditions 1. Field content exceeds field width 2. Field includes a new line 3. Field type is TEXT ## [BEFORE] Field UI Signing  ## [AFTER] Field UI Signing  ## [BEFORE] Signing a checkbox   ## [AFTER] Signing a checkbox   ## [BEFORE] What a 2nd recipient sees once someone else signed a document  ## [AFTER] What a 2nd recipient sees once someone else signed a document  ## **[BEFORE]** Inserting fields  ## **[AFTER]** Inserting fields  ## Overflows, multilines and field alignments testing Debugging borders: - Red border = The original field placement without any modifications - Blue border = The available space to overflow ### Single line overflows and field alignments This is left aligned fields, overflow will always go to the end of the page and will not wrap  This is center aligned fields, the max width is the closest edge to the page * 2  This is right aligned text, the width will extend all the way to the left hand side of the page  ### Multiline line overflows and field alignments These are text fields that can be overflowed  Another example of left aligned text overflows with more text 
43 lines
973 B
TypeScript
43 lines
973 B
TypeScript
import React, { useEffect, useState } from 'react';
|
|
|
|
export type ElementVisibleProps = {
|
|
target: string;
|
|
children: React.ReactNode;
|
|
};
|
|
|
|
export const ElementVisible = ({ target, children }: ElementVisibleProps) => {
|
|
const [visible, setVisible] = useState(false);
|
|
|
|
useEffect(() => {
|
|
const observer = new MutationObserver((_mutations) => {
|
|
const $el = document.querySelector(target);
|
|
|
|
// Wait a fraction of a second to allow the scrollbar to load if it exists.
|
|
// If we don't wait, then the elements on the first page will be
|
|
// shifted across.
|
|
setTimeout(() => {
|
|
setVisible(!!$el);
|
|
}, 100);
|
|
});
|
|
|
|
observer.observe(document.body, {
|
|
childList: true,
|
|
subtree: true,
|
|
});
|
|
|
|
return () => {
|
|
observer.disconnect();
|
|
};
|
|
}, [target]);
|
|
|
|
useEffect(() => {
|
|
setVisible(!!document.querySelector(target));
|
|
}, [target]);
|
|
|
|
if (!visible) {
|
|
return null;
|
|
}
|
|
|
|
return <>{children}</>;
|
|
};
|