Skip to content

Pass props to empty field placeholders #2001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import React from 'react';

export const DefaultEmptyFieldEditingComponentText: React.FC = () => {
return <span>[No text in field]</span>;
export interface DefaultEmptyFieldEditingComponentProps {
field: unknown;
}

export const DefaultEmptyFieldEditingComponentText: React.FC<DefaultEmptyFieldEditingComponentProps> = ({
field,
...props
}) => {
return <span {...props}>[No text in field]</span>;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use React.createElement(tag || 'span',...) here as well so it would be similar to the non-empty state?

};

export const DefaultEmptyFieldEditingComponentImage: React.FC = () => {
export const DefaultEmptyFieldEditingComponentImage: React.FC<DefaultEmptyFieldEditingComponentProps> = ({
field,
...props
}) => {
const inlineStyles = {
minWidth: '48px',
minHeight: '48px',
Expand All @@ -19,6 +29,7 @@ export const DefaultEmptyFieldEditingComponentImage: React.FC = () => {
src='data:image/svg+xml,%3Csvg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 240 240" style="enable-background:new 0 0 240 240;" xml:space="preserve"%3E%3Cstyle type="text/css"%3E .st0%7Bfill:none;%7D .st1%7Bfill:%23969696;%7D .st2%7Bfill:%23FFFFFF;%7D .st3%7Bfill:%23FFFFFF;stroke:%23FFFFFF;stroke-width:0.75;stroke-miterlimit:10;%7D%0A%3C/style%3E%3Cg%3E%3Crect class="st0" width="240" height="240"/%3E%3Cg%3E%3Cg%3E%3Crect x="20" y="20" class="st1" width="200" height="200"/%3E%3C/g%3E%3Cg%3E%3Ccircle class="st2" cx="174" cy="67" r="14"/%3E%3Cpath class="st2" d="M174,54c7.17,0,13,5.83,13,13s-5.83,13-13,13s-13-5.83-13-13S166.83,54,174,54 M174,52 c-8.28,0-15,6.72-15,15s6.72,15,15,15s15-6.72,15-15S182.28,52,174,52L174,52z"/%3E%3C/g%3E%3Cpolyline class="st3" points="29.5,179.25 81.32,122.25 95.41,137.75 137.23,91.75 209.5,179.75 "/%3E%3C/g%3E%3C/g%3E%3C/svg%3E'
className="scEmptyImage"
style={inlineStyles}
{...props}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function withEmptyFieldEditingComponent<
) {
const getEmptyFieldEditingComponent = (
props: FieldComponentProps
): React.ComponentClass | React.FC => {
): React.ComponentType<WithEmptyFieldEditingComponentProps> => {
const { editable = true } = props;
if (props.field?.metadata && editable && isFieldValueEmpty(props.field)) {
return props.emptyFieldEditingComponent || options.defaultEmptyFieldEditingComponent;
Expand All @@ -61,7 +61,7 @@ export function withEmptyFieldEditingComponent<
);
return (
<>
{(EmptyFieldEditingComponent && <EmptyFieldEditingComponent />) || (
{(EmptyFieldEditingComponent && <EmptyFieldEditingComponent {...props} />) || (
<FieldComponent {...(props as FieldComponentProps)} ref={ref} />
)}
</>
Expand All @@ -74,7 +74,7 @@ export function withEmptyFieldEditingComponent<
const EmptyFieldEditingComponent = getEmptyFieldEditingComponent(props);
return (
<>
{(EmptyFieldEditingComponent && <EmptyFieldEditingComponent />) || (
{(EmptyFieldEditingComponent && <EmptyFieldEditingComponent {...props} />) || (
<FieldComponent {...props} />
)}
</>
Expand Down
Loading