Skip to content

Commit 398a540

Browse files
committed
feat: use Heading JSX and apply margin to all heading levels (#4999)
1 parent cdb57bf commit 398a540

File tree

2 files changed

+69
-18
lines changed

2 files changed

+69
-18
lines changed

packages/sdk-components-react-radix/src/accordion.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
type RefAttributes,
77
useState,
88
useEffect,
9-
createElement,
109
} from "react";
1110
import {
1211
Root,
@@ -53,21 +52,13 @@ export const AccordionItem = forwardRef<
5352

5453
const defaultTag = "h3";
5554
type Tag = "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
56-
type Props = ComponentPropsWithoutRef<typeof Header> & { tag?: Tag };
55+
type Props = ComponentProps<typeof Header> & { tag?: Tag };
5756
export const AccordionHeader = forwardRef<HTMLHeadingElement, Props>(
5857
({ tag: legacyTag, ...props }, ref) => {
59-
const tag = getTagFromProps(props) ?? legacyTag ?? defaultTag;
58+
const Heading = getTagFromProps(props) ?? legacyTag ?? defaultTag;
6059
return (
6160
<Header asChild>
62-
{createElement(tag, {
63-
...props,
64-
ref,
65-
style: {
66-
...(props.style || {}),
67-
marginTop: 0,
68-
marginBottom: 0,
69-
},
70-
})}
61+
<Heading ref={ref} {...props} />
7162
</Header>
7263
);
7364
}

packages/sdk-components-react-radix/src/accordion.ws.ts

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,72 @@ export const metaAccordionHeader: WsComponentMeta = {
6161
descendants: [radix.AccordionTrigger],
6262
},
6363
presetStyle: {
64-
h1,
65-
h2,
66-
h3,
67-
h4,
68-
h5,
69-
h6,
64+
h1: [
65+
...h1,
66+
{
67+
property: "margin-top",
68+
value: { type: "unit", unit: "px", value: 0 },
69+
},
70+
{
71+
property: "margin-bottom",
72+
value: { type: "unit", unit: "px", value: 0 },
73+
},
74+
],
75+
h2: [
76+
...h2,
77+
{
78+
property: "margin-top",
79+
value: { type: "unit", unit: "px", value: 0 },
80+
},
81+
{
82+
property: "margin-bottom",
83+
value: { type: "unit", unit: "px", value: 0 },
84+
},
85+
],
86+
h3: [
87+
...h3,
88+
{
89+
property: "margin-top",
90+
value: { type: "unit", unit: "px", value: 0 },
91+
},
92+
{
93+
property: "margin-bottom",
94+
value: { type: "unit", unit: "px", value: 0 },
95+
},
96+
],
97+
h4: [
98+
...h4,
99+
{
100+
property: "margin-top",
101+
value: { type: "unit", unit: "px", value: 0 },
102+
},
103+
{
104+
property: "margin-bottom",
105+
value: { type: "unit", unit: "px", value: 0 },
106+
},
107+
],
108+
h5: [
109+
...h5,
110+
{
111+
property: "margin-top",
112+
value: { type: "unit", unit: "px", value: 0 },
113+
},
114+
{
115+
property: "margin-bottom",
116+
value: { type: "unit", unit: "px", value: 0 },
117+
},
118+
],
119+
h6: [
120+
...h6,
121+
{
122+
property: "margin-top",
123+
value: { type: "unit", unit: "px", value: 0 },
124+
},
125+
{
126+
property: "margin-bottom",
127+
value: { type: "unit", unit: "px", value: 0 },
128+
},
129+
],
70130
},
71131
initialProps: ["tag"],
72132
props: {

0 commit comments

Comments
 (0)