Skip to content

Commit

Permalink
refactor: add types for synchronous resolveProps
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvxd committed Oct 31, 2023
1 parent fdf97c7 commit 5425aad
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions apps/demo/config/blocks/Hero/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @next/next/no-img-element */
import React, { useState } from "react";
import { ComponentConfig } from "@measured/puck";
import { ComponentConfig } from "@measured/puck/types/Config";
import styles from "./styles.module.css";
import { getClassNameFactory } from "@measured/puck/lib";
import { Button } from "@measured/puck/components/Button";
Expand Down Expand Up @@ -89,7 +89,7 @@ export const Hero: ComponentConfig<HeroProps> = {
*
* For example, requesting a third-party API for the latest content.
*/
resolveProps: async (props) => {
resolveProps: (props) => {
if (!props.quote)
return { props, readOnly: { title: false, description: false } };

Expand Down
13 changes: 9 additions & 4 deletions packages/core/types/Config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,15 @@ export type ComponentConfig<
render: (props: WithPuckProps<ComponentProps>) => ReactElement;
defaultProps?: DefaultProps;
fields?: Fields<ComponentProps>;
resolveProps?: (props: WithPuckProps<ComponentProps>) => Promise<{
props: WithPuckProps<ComponentProps>;
readOnly?: Partial<Record<keyof ComponentProps, boolean>>;
}>;
resolveProps?: (props: WithPuckProps<ComponentProps>) =>
| Promise<{
props: WithPuckProps<ComponentProps>;
readOnly?: Partial<Record<keyof ComponentProps, boolean>>;
}>
| {
props: WithPuckProps<ComponentProps>;
readOnly?: Partial<Record<keyof ComponentProps, boolean>>;
};
};

type Category<ComponentName> = {
Expand Down

0 comments on commit 5425aad

Please sign in to comment.