Skip to content
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
21 changes: 16 additions & 5 deletions packages/sdk-components-react-radix/src/accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import {
Trigger,
Content,
} from "@radix-ui/react-accordion";
import { getIndexWithinAncestorFromProps } from "@webstudio-is/sdk/runtime";
import {
getIndexWithinAncestorFromProps,
getTagFromProps,
} from "@webstudio-is/sdk/runtime";
import { getClosestInstance, type Hook } from "@webstudio-is/react-sdk/runtime";

export const Accordion = forwardRef<
Expand Down Expand Up @@ -47,10 +50,18 @@ export const AccordionItem = forwardRef<
return <Item ref={ref} value={value ?? index ?? ""} {...props} />;
});

export const AccordionHeader: ForwardRefExoticComponent<
Omit<ComponentProps<typeof Header>, "asChild"> &
RefAttributes<HTMLHeadingElement>
> = Header;
const defaultTag = "h1";
type Props = ComponentProps<typeof Header>;
export const AccordionHeader = forwardRef<HTMLHeadingElement, Props>(
({ ...props }, ref) => {
const Heading = getTagFromProps(props) ?? defaultTag;
return (
<Header asChild>
<Heading ref={ref} {...props} />
</Header>
);
}
);

export const AccordionTrigger: ForwardRefExoticComponent<
Omit<ComponentProps<typeof Trigger>, "asChild"> &
Expand Down
77 changes: 75 additions & 2 deletions packages/sdk-components-react-radix/src/accordion.ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ import {
ContentIcon,
} from "@webstudio-is/icons/svg";
import type { WsComponentMeta } from "@webstudio-is/sdk";
import { div, h3, button } from "@webstudio-is/sdk/normalize.css";
import {
h1,
h2,
h3,
h4,
h5,
h6,
div,
button,
} from "@webstudio-is/sdk/normalize.css";
import { radix } from "./shared/meta";
import { buttonReset } from "./shared/preset-styles";
import {
Expand Down Expand Up @@ -52,6 +61,28 @@ export const metaAccordionHeader: WsComponentMeta = {
descendants: [radix.AccordionTrigger],
},
presetStyle: {
h1: [
...h1,
{
property: "margin-top",
value: { type: "unit", unit: "px", value: 0 },
},
{
property: "margin-bottom",
value: { type: "unit", unit: "px", value: 0 },
},
],
h2: [
...h2,
{
property: "margin-top",
value: { type: "unit", unit: "px", value: 0 },
},
{
property: "margin-bottom",
value: { type: "unit", unit: "px", value: 0 },
},
],
h3: [
...h3,
{
Expand All @@ -63,8 +94,50 @@ export const metaAccordionHeader: WsComponentMeta = {
value: { type: "unit", unit: "px", value: 0 },
},
],
h4: [
...h4,
{
property: "margin-top",
value: { type: "unit", unit: "px", value: 0 },
},
{
property: "margin-bottom",
value: { type: "unit", unit: "px", value: 0 },
},
],
h5: [
...h5,
{
property: "margin-top",
value: { type: "unit", unit: "px", value: 0 },
},
{
property: "margin-bottom",
value: { type: "unit", unit: "px", value: 0 },
},
],
h6: [
...h6,
{
property: "margin-top",
value: { type: "unit", unit: "px", value: 0 },
},
{
property: "margin-bottom",
value: { type: "unit", unit: "px", value: 0 },
},
],
},
initialProps: ["tag"],
props: {
...propsAccordionHeader,
tag: {
required: true,
control: "tag",
type: "string",
options: ["h1", "h2", "h3", "h4", "h5", "h6"],
},
},
props: propsAccordionHeader,
};

export const metaAccordionTrigger: WsComponentMeta = {
Expand Down