Skip to content
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

Allow add new defaultFields types #700

Open
htmldiz opened this issue Nov 13, 2024 · 0 comments
Open

Allow add new defaultFields types #700

htmldiz opened this issue Nov 13, 2024 · 0 comments

Comments

@htmldiz
Copy link

htmldiz commented Nov 13, 2024

File location: /packages/core/components/AutoField/index.tsx

Code Before Modification:

const defaultFields = {
    array: ArrayField,
    external: ExternalField,
    object: ObjectField,
    select: SelectField,
    textarea: TextareaField,
    radio: RadioField,
    text: DefaultField,
    number: DefaultField,
  };

Code after modification:

let defaultFields = {
    array: ArrayField,
    external: ExternalField,
    object: ObjectField,
    select: SelectField,
    textarea: TextareaField,
    radio: RadioField,
    text: DefaultField,
    number: DefaultField,
    ...overrides.defaultFields,
  };

Usage Example:

const overrides = {
	header: PanelHeader,
	fields: PanelFields,
	fieldTypes: {
		accordion: AccordionField
	},
	defaultFields: {
		accordion: AccordionField
	},
};
export const AccordionField = ({
  field,
  onChange,
  value,
  name,
  label,
  Label,
  readOnly,
  id,
}) => {
	const { selectedItem } = usePuck();
	if(!selectedItem) {
		return null;
	}
	  if (field.type !== "accordion" || !field.objectFields) {
		return null;
	  }
	let readOnlyFields = selectedItem.readOnly || {};
  const data = value || {};
  return (
<div
      label={label || name}
      icon={<MoreVertical size={16} />}
      el="div"
      readOnly={readOnly}
    >
      <div className={getClassName()}>
        ...
      </div>
    </div>
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants