Skip to content

Commit

Permalink
Try to add pure annotation to radix components
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound committed Nov 13, 2024
1 parent a56057b commit 3007ba0
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 33 deletions.
4 changes: 2 additions & 2 deletions packages/sdk-components-react-radix/src/accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
type Hook,
} from "@webstudio-is/react-sdk/runtime";

export const Accordion = forwardRef<
export const Accordion = /*@__PURE__*/ forwardRef<
HTMLDivElement,
Omit<
Extract<ComponentPropsWithoutRef<typeof Root>, { type: "single" }>,
Expand All @@ -29,7 +29,7 @@ export const Accordion = forwardRef<
return <Root ref={ref} type="single" {...props} />;
});

export const AccordionItem = forwardRef<
export const AccordionItem = /*@__PURE__*/ forwardRef<
HTMLDivElement,
Omit<ComponentPropsWithoutRef<typeof Item>, "value"> & { value?: string }
>(({ value, ...props }, ref) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-components-react-radix/src/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from "react";
import { Root, Indicator } from "@radix-ui/react-checkbox";

export const Checkbox = forwardRef<
export const Checkbox = /*@__PURE__*/ forwardRef<
HTMLButtonElement,
// radix checked has complex named type which cannot be parsed
// cast to boolean
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-components-react-radix/src/collapsible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const Collapsible: ForwardRefExoticComponent<
* This avoids situations where the Trigger inadvertently passes all styles to its child,
* which would prevent us from displaying styles properly in the builder.
*/
export const CollapsibleTrigger = forwardRef<
export const CollapsibleTrigger = /*@__PURE__*/ forwardRef<
HTMLButtonElement,
{ children: ReactNode }
>(({ children, ...props }, ref) => {
Expand Down
10 changes: 5 additions & 5 deletions packages/sdk-components-react-radix/src/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const willNavigate = (event: MouseEvent) => {
};

// wrap in forwardRef because Root is functional component without ref
export const Dialog = forwardRef<
export const Dialog = /*@__PURE__*/ forwardRef<
HTMLDivElement,
Omit<ComponentPropsWithoutRef<typeof DialogPrimitive.Root>, "defaultOpen">
>((props, _ref) => {
Expand Down Expand Up @@ -94,7 +94,7 @@ export const Dialog = forwardRef<
* This avoids situations where the Trigger inadvertently passes all styles to its child,
* which would prevent us from displaying styles properly in the builder.
*/
export const DialogTrigger = forwardRef<
export const DialogTrigger = /*@__PURE__*/ forwardRef<
HTMLButtonElement,
{ children: ReactNode }
>(({ children, ...props }, ref) => {
Expand All @@ -107,7 +107,7 @@ export const DialogTrigger = forwardRef<
);
});

export const DialogOverlay = forwardRef<
export const DialogOverlay = /*@__PURE__*/ forwardRef<
HTMLDivElement,
ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
>((props, ref) => {
Expand All @@ -118,7 +118,7 @@ export const DialogOverlay = forwardRef<
);
});

export const DialogContent = forwardRef<
export const DialogContent = /*@__PURE__*/ forwardRef<
HTMLDivElement,
ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
>((props, ref) => {
Expand Down Expand Up @@ -172,7 +172,7 @@ export const DialogClose = DialogPrimitive.Close;

type Tag = "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
const defaultTag = "h1";
export const DialogTitle = forwardRef<
export const DialogTitle = /*@__PURE__*/ forwardRef<
HTMLHeadingElement,
ComponentProps<typeof DialogPrimitive.DialogTitle> & { tag?: Tag }
>(({ tag: Tag = defaultTag, children, ...props }, ref) => (
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-components-react-radix/src/label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {

import * as LabelPrimitive from "@radix-ui/react-label";

export const Label = forwardRef<
export const Label = /*@__PURE__*/ forwardRef<
ElementRef<typeof LabelPrimitive.Root>,
Omit<ComponentPropsWithoutRef<typeof LabelPrimitive.Root>, "asChild">
>((props, ref) => <LabelPrimitive.Root ref={ref} {...props} />);
8 changes: 4 additions & 4 deletions packages/sdk-components-react-radix/src/navigation-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
useContext,
} from "react";

export const NavigationMenu = forwardRef<
export const NavigationMenu = /*@__PURE__*/ forwardRef<
HTMLLIElement,
Omit<
ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Root>,
Expand All @@ -40,7 +40,7 @@ export const NavigationMenuList = NavigationMenuPrimitive.List;
export const NavigationMenuViewport = NavigationMenuPrimitive.Viewport;
export const NavigationMenuContent = NavigationMenuPrimitive.Content;

export const NavigationMenuItem = forwardRef<
export const NavigationMenuItem = /*@__PURE__*/ forwardRef<
HTMLLIElement,
Omit<ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Item>, "asChild">
>(({ value, ...props }, ref) => {
Expand All @@ -50,7 +50,7 @@ export const NavigationMenuItem = forwardRef<
);
});

export const NavigationMenuLink = forwardRef<
export const NavigationMenuLink = /*@__PURE__*/ forwardRef<
HTMLAnchorElement,
ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Link>
>(({ children, ...props }, ref) => {
Expand All @@ -63,7 +63,7 @@ export const NavigationMenuLink = forwardRef<
);
});

export const NavigationMenuTrigger = forwardRef<
export const NavigationMenuTrigger = /*@__PURE__*/ forwardRef<
HTMLButtonElement,
ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Trigger>
>(({ children, ...props }, ref) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk-components-react-radix/src/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from "@webstudio-is/react-sdk/runtime";

// wrap in forwardRef because Root is functional component without ref
export const Popover = forwardRef<
export const Popover = /*@__PURE__*/ forwardRef<
HTMLDivElement,
Omit<ComponentPropsWithoutRef<typeof PopoverPrimitive.Root>, "defaultOpen">
>((props, _ref) => {
Expand All @@ -25,7 +25,7 @@ export const Popover = forwardRef<
* This avoids situations where the Trigger inadvertently passes all styles to its child,
* which would prevent us from displaying styles properly in the builder.
*/
export const PopoverTrigger = forwardRef<
export const PopoverTrigger = /*@__PURE__*/ forwardRef<
HTMLButtonElement,
{ children: ReactNode }
>(({ children, ...props }, ref) => {
Expand All @@ -38,7 +38,7 @@ export const PopoverTrigger = forwardRef<
);
});

export const PopoverContent = forwardRef<
export const PopoverContent = /*@__PURE__*/ forwardRef<
HTMLDivElement,
ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>
>(
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-components-react-radix/src/radio-group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Root, Item, Indicator } from "@radix-ui/react-radio-group";

const defaultTag = "div";

export const RadioGroup = forwardRef<
export const RadioGroup = /*@__PURE__*/ forwardRef<
ElementRef<typeof defaultTag>,
ComponentProps<typeof Root> & RefAttributes<typeof defaultTag>
// Make sure children are not passed down to an input, because this will result in error.
Expand Down
17 changes: 9 additions & 8 deletions packages/sdk-components-react-radix/src/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ import {
ReactSdkContext,
} from "@webstudio-is/react-sdk/runtime";

export const Select = forwardRef<HTMLDivElement, ComponentProps<typeof Root>>(
({ value, defaultValue, ...props }, _ref) => {
return <Root {...props} defaultValue={value ?? defaultValue} />;
}
);
export const Select = /*@__PURE__*/ forwardRef<
HTMLDivElement,
ComponentProps<typeof Root>
>(({ value, defaultValue, ...props }, _ref) => {
return <Root {...props} defaultValue={value ?? defaultValue} />;
});

export const SelectTrigger = forwardRef<
export const SelectTrigger = /*@__PURE__*/ forwardRef<
HTMLButtonElement,
ComponentPropsWithoutRef<typeof Trigger>
>((props, ref) => {
Expand All @@ -46,7 +47,7 @@ export const SelectTrigger = forwardRef<
return <Trigger onPointerDown={onPointerDown} ref={ref} {...props} />;
});

export const SelectValue = forwardRef<
export const SelectValue = /*@__PURE__*/ forwardRef<
HTMLDivElement,
Omit<ComponentPropsWithoutRef<typeof Value>, "placeholder"> & {
placeholder?: string;
Expand All @@ -55,7 +56,7 @@ export const SelectValue = forwardRef<
return <Value ref={ref} {...props} />;
});

export const SelectContent = forwardRef<
export const SelectContent = /*@__PURE__*/ forwardRef<
HTMLDivElement,
Omit<ComponentPropsWithoutRef<typeof Content>, "position" | "side">
>((props, ref) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-components-react-radix/src/sheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const SheetClose = Dialog.DialogClose;
export const SheetTitle = Dialog.DialogTitle;
export const SheetDescription = Dialog.DialogDescription;

export const SheetContent = forwardRef<
export const SheetContent = /*@__PURE__*/ forwardRef<
ElementRef<"div">,
ComponentPropsWithoutRef<typeof Dialog.DialogContent> & {
tag?: "div" | "nav";
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-components-react-radix/src/switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from "react";
import { Root, Thumb } from "@radix-ui/react-switch";

export const Switch = forwardRef<
export const Switch = /*@__PURE__*/ forwardRef<
HTMLButtonElement,
ComponentProps<typeof Root>
>(({ checked, defaultChecked, ...props }, ref) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk-components-react-radix/src/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ export const Tabs: ForwardRefExoticComponent<

export const TabsList = List;

export const TabsTrigger = forwardRef<
export const TabsTrigger = /*@__PURE__*/ forwardRef<
HTMLButtonElement,
Omit<ComponentPropsWithoutRef<typeof Trigger>, "value"> & { value?: string }
>(({ value, ...props }, ref) => {
const index = getIndexWithinAncestorFromComponentProps(props);
return <Trigger ref={ref} value={value ?? index ?? ""} {...props} />;
});

export const TabsContent = forwardRef<
export const TabsContent = /*@__PURE__*/ forwardRef<
HTMLDivElement,
Omit<ComponentPropsWithoutRef<typeof Content>, "value"> & { value?: string }
>(({ value, ...props }, ref) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk-components-react-radix/src/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
Children,
} from "react";

export const Tooltip = forwardRef<
export const Tooltip = /*@__PURE__*/ forwardRef<
HTMLDivElement,
Omit<ComponentPropsWithoutRef<typeof TooltipPrimitive.Root>, "defaultOpen">
>((props, _ref) => {
Expand All @@ -29,7 +29,7 @@ export const Tooltip = forwardRef<
* This avoids situations where the Trigger inadvertently passes all styles to its child,
* which would prevent us from displaying styles properly in the builder.
*/
export const TooltipTrigger = forwardRef<
export const TooltipTrigger = /*@__PURE__*/ forwardRef<
HTMLButtonElement,
{ children: ReactNode }
>(({ children, ...props }, ref) => {
Expand All @@ -42,7 +42,7 @@ export const TooltipTrigger = forwardRef<
);
});

export const TooltipContent = forwardRef<
export const TooltipContent = /*@__PURE__*/ forwardRef<
HTMLDivElement,
ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
>(({ sideOffset = 4, hideWhenDetached = true, ...props }, ref) => (
Expand Down

0 comments on commit 3007ba0

Please sign in to comment.