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

create HeadingComponent #11

Merged
merged 15 commits into from
Feb 23, 2025
34 changes: 34 additions & 0 deletions components/HeadingComponent.tsx
Copy link
Contributor

Choose a reason for hiding this comment

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

Please format the file. Tip: turn on format on save

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's also think about what this component does. How can you add different heading levels, like h1, h2 or h3?
I suggest we add a level prop to this component and make the user choose it.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { ComponentConfig } from "@measured/puck";
import React from "react";

export type HeadingComponentProps = {
text: string,
textAlign: any,
};

function HeadingComponent({text, textAlign}: HeadingComponentProps){
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, make sure the component is export default.

return (
<div style={{padding: 64}}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this padding needed, or is there a way to use the margin and min-height on the h1 tag?

<h1 style={{ textAlign }}>{text}</h1>
</div>
)
};

export const headingComponentConfig: ComponentConfig<HeadingComponentProps> = {
render: HeadingComponent,
fields:{
text: {type: "text"},
textAlign: {
type: "radio",
options: [
{ label: "Left", value: "left" },
{ label: "Center", value: "center" },
{ label: "Right", value: "right" },
],
},
},
defaultProps: {
text: "HeadingComponent",
textAlign: "center",
}
}
4 changes: 4 additions & 0 deletions puck.config.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import type { Config } from "@measured/puck";
import type { TextProps } from "./components/Text";
import Text from "./components/Text";
import type { HeadingComponentProps } from "./components/HeadingComponent";
import { headingComponentConfig } from "./components/HeadingComponent";

type Props = {
HeadingComponent: HeadingComponentProps
HeadingBlock: { title: string };
Text: TextProps;
};
Expand Down Expand Up @@ -30,6 +33,7 @@ export const config: Config<Props> = {
</div>
),
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you created the component can you please also remove the HeadingBlock component here. It's no longer needed.

HeadingComponent: headingComponentConfig,
},
};

Expand Down