Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 additions & 1 deletion apps/builder/app/shared/content-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,6 @@ export const richTextPlaceholders: Map<undefined | string, string> = new Map([
["blockquote", "Blockquote"],
["li", "List item"],
["a", "Link"],
["span", "Span"],
]);

const findContentTags = ({
Expand Down
1 change: 0 additions & 1 deletion packages/sdk-components-react-radix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"@radix-ui/react-switch": "^1.2.2",
"@radix-ui/react-tabs": "^1.1.9",
"@radix-ui/react-tooltip": "^1.2.4",
"@radix-ui/react-use-controllable-state": "^1.2.2",
"@webstudio-is/css-engine": "workspace:*",
"@webstudio-is/icons": "workspace:*",
"@webstudio-is/react-sdk": "workspace:*",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const meta: TemplateMeta = {
"A vertically stacked set of interactive headings that each reveal an associated section of content. Clicking on the heading will open the item and close other items.",
order: 3,
template: (
<radix.Accordion collapsible={true} defaultValue="0">
<radix.Accordion collapsible={true} value="0">
{createAccordionItem(
"Is it accessible?",
"Yes. It adheres to the WAI-ARIA design pattern."
Expand Down
18 changes: 16 additions & 2 deletions packages/sdk-components-react-radix/src/accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
forwardRef,
type ComponentProps,
type RefAttributes,
useState,
useEffect,
} from "react";
import {
Root,
Expand All @@ -21,8 +23,20 @@ export const Accordion = forwardRef<
Extract<ComponentPropsWithoutRef<typeof Root>, { type: "single" }>,
"type" | "asChild"
>
>((props, ref) => {
return <Root ref={ref} type="single" {...props} />;
>(({ defaultValue, ...props }, ref) => {
const currentValue = props.value ?? defaultValue ?? "";
const [value, setValue] = useState(currentValue);
// synchronize external value with local one when changed
useEffect(() => setValue(currentValue), [currentValue]);
return (
<Root
{...props}
ref={ref}
type="single"
value={value}
onValueChange={setValue}
/>
);
});

export const AccordionItem = forwardRef<
Expand Down
13 changes: 7 additions & 6 deletions packages/sdk-components-react-radix/src/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import {
type ComponentPropsWithRef,
forwardRef,
type ComponentProps,
useState,
useEffect,
} from "react";
import { Root, Indicator } from "@radix-ui/react-checkbox";
import { useControllableState } from "@radix-ui/react-use-controllable-state";

export const Checkbox = forwardRef<
HTMLButtonElement,
Expand All @@ -16,16 +17,16 @@ export const Checkbox = forwardRef<
defaultChecked?: boolean;
}
>(({ defaultChecked, ...props }, ref) => {
const [checked, onCheckedChange] = useControllableState({
prop: props.checked ?? defaultChecked ?? false,
defaultProp: false,
});
const currentChecked = props.checked ?? defaultChecked ?? false;
const [checked, setChecked] = useState(currentChecked);
// synchronize external value with local one when changed
useEffect(() => setChecked(currentChecked), [currentChecked]);
return (
<Root
{...props}
ref={ref}
checked={checked}
onCheckedChange={(open) => onCheckedChange(open === true)}
onCheckedChange={(open) => setChecked(open === true)}
/>
);
});
Expand Down
16 changes: 12 additions & 4 deletions packages/sdk-components-react-radix/src/collapsible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@ import {
Children,
type ComponentProps,
type RefAttributes,
useState,
useEffect,
} from "react";
import { Root, Trigger, Content } from "@radix-ui/react-collapsible";
import { type Hook, getClosestInstance } from "@webstudio-is/react-sdk/runtime";

export const Collapsible: ForwardRefExoticComponent<
Omit<ComponentProps<typeof Root>, "defaultOpen" | "asChild"> &
RefAttributes<HTMLDivElement>
> = Root;
export const Collapsible = forwardRef<
HTMLDivElement,
Omit<ComponentProps<typeof Root>, "defaultOpen" | "asChild">
>((props, ref) => {
const currentOpen = props.open ?? false;
const [open, setOpen] = useState(currentOpen);
// synchronize external value with local one when changed
useEffect(() => setOpen(currentOpen), [currentOpen]);
return <Root {...props} ref={ref} open={open} onOpenChange={setOpen} />;
});

/**
* We're not exposing the 'asChild' property for the Trigger.
Expand Down
35 changes: 15 additions & 20 deletions packages/sdk-components-react-radix/src/dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import interactionResponse from "await-interaction-response";
import {
type ComponentPropsWithoutRef,
type ReactNode,
type ComponentProps,
forwardRef,
Children,
type ComponentProps,
useEffect,
useRef,
useContext,
useCallback,
useState,
} from "react";
import * as DialogPrimitive from "@radix-ui/react-dialog";
import {
ReactSdkContext,
getClosestInstance,
type Hook,
} from "@webstudio-is/react-sdk/runtime";
import { useControllableState } from "@radix-ui/react-use-controllable-state";
import interactionResponse from "await-interaction-response";

/**
* Naive heuristic to determine if a click event will cause navigate
Expand Down Expand Up @@ -50,23 +49,19 @@ const willNavigate = (event: MouseEvent) => {
// wrap in forwardRef because Root is functional component without ref
export const Dialog = forwardRef<
HTMLDivElement,
Omit<ComponentPropsWithoutRef<typeof DialogPrimitive.Root>, "defaultOpen">
Omit<ComponentProps<typeof DialogPrimitive.Root>, "defaultOpen">
>((props, _ref) => {
const { renderer } = useContext(ReactSdkContext);

const [open, onOpenChange] = useControllableState({
prop: props.open,
defaultProp: false,
onChange: props.onOpenChange,
});

const onOpenChangeHandler = useCallback(
async (open: boolean) => {
await interactionResponse();
onOpenChange(open);
},
[onOpenChange]
);
const currentOpen = props.open ?? false;
const [open, setOpen] = useState(currentOpen);
// synchronize external value with local one when changed
useEffect(() => setOpen(currentOpen), [currentOpen]);

const onOpenChangeHandler = useCallback(async (open: boolean) => {
await interactionResponse();
setOpen(open);
}, []);

/**
* Close the dialog when a navigable link within it is clicked.
Expand Down Expand Up @@ -130,7 +125,7 @@ export const DialogTrigger = forwardRef<

export const DialogOverlay = forwardRef<
HTMLDivElement,
ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
ComponentProps<typeof DialogPrimitive.Overlay>
>((props, ref) => {
return (
<DialogPrimitive.DialogPortal>
Expand All @@ -141,7 +136,7 @@ export const DialogOverlay = forwardRef<

export const DialogContent = forwardRef<
HTMLDivElement,
ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
ComponentProps<typeof DialogPrimitive.Content>
>((props, ref) => {
const preventAutoFocusOnClose = useRef(false);
const { renderer } = useContext(ReactSdkContext);
Expand Down
1 change: 1 addition & 0 deletions packages/sdk-components-react-radix/src/dialog.ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,6 @@ export const metaDialog: WsComponentMeta = {
children: ["instance"],
descendants: [radix.DialogTrigger, radix.DialogOverlay],
},
initialProps: ["open"],
props: propsDialog,
};
10 changes: 9 additions & 1 deletion packages/sdk-components-react-radix/src/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
type ReactNode,
forwardRef,
Children,
useState,
useEffect,
} from "react";
import * as PopoverPrimitive from "@radix-ui/react-popover";
import { getClosestInstance, type Hook } from "@webstudio-is/react-sdk/runtime";
Expand All @@ -12,7 +14,13 @@ export const Popover = forwardRef<
HTMLDivElement,
Omit<ComponentPropsWithoutRef<typeof PopoverPrimitive.Root>, "defaultOpen">
>((props, _ref) => {
return <PopoverPrimitive.Root {...props} />;
const currentOpen = props.open ?? false;
const [open, setOpen] = useState(currentOpen);
// synchronize external value with local one when changed
useEffect(() => setOpen(currentOpen), [currentOpen]);
return (
<PopoverPrimitive.Root {...props} open={open} onOpenChange={setOpen} />
);
});

/**
Expand Down
22 changes: 9 additions & 13 deletions packages/sdk-components-react-radix/src/radio-group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,20 @@ import {
type RefAttributes,
type ElementRef,
forwardRef,
useState,
useEffect,
} from "react";
import { Root, Item, Indicator } from "@radix-ui/react-radio-group";
import { useControllableState } from "@radix-ui/react-use-controllable-state";

const defaultTag = "div";

export const RadioGroup = 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.
ElementRef<"div">,
ComponentProps<typeof Root>
>(({ defaultValue, ...props }, ref) => {
const [value, onValueChange] = useControllableState({
prop: props.value ?? defaultValue ?? "",
defaultProp: "",
});
return (
<Root {...props} value={value} onValueChange={onValueChange} ref={ref} />
);
const currentValue = props.value ?? defaultValue ?? "";
const [value, setValue] = useState(currentValue);
// synchronize external value with local one when changed
useEffect(() => setValue(currentValue), [currentValue]);
return <Root {...props} ref={ref} value={value} onValueChange={setValue} />;
});

export const RadioGroupItem: ForwardRefExoticComponent<
Expand Down
24 changes: 22 additions & 2 deletions packages/sdk-components-react-radix/src/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
type RefAttributes,
useContext,
type ComponentPropsWithRef,
useState,
useEffect,
} from "react";
import {
Root,
Expand All @@ -26,8 +28,26 @@ import {

export const Select: ForwardRefExoticComponent<
ComponentPropsWithRef<typeof Root>
> = forwardRef(({ value, defaultValue, ...props }, _ref) => {
return <Root {...props} defaultValue={value ?? defaultValue} />;
> = forwardRef(({ defaultOpen, defaultValue, ...props }, _ref) => {
// open state
const currentOpen = props.open ?? defaultOpen ?? false;
const [open, setOpen] = useState(currentOpen);
// synchronize external value with local one when changed
useEffect(() => setOpen(currentOpen), [currentOpen]);
// value state
const currentValue = props.value ?? defaultValue ?? "";
const [value, setValue] = useState(currentValue);
// synchronize external value with local one when changed
useEffect(() => setValue(currentValue), [currentValue]);
return (
<Root
{...props}
open={open}
onOpenChange={setOpen}
value={value}
onValueChange={setValue}
/>
);
});

export const SelectTrigger = forwardRef<
Expand Down
18 changes: 7 additions & 11 deletions packages/sdk-components-react-radix/src/switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,21 @@ import {
type ComponentProps,
type RefAttributes,
forwardRef,
useEffect,
useState,
} from "react";
import { Root, Thumb } from "@radix-ui/react-switch";
import { useControllableState } from "@radix-ui/react-use-controllable-state";

export const Switch = forwardRef<
HTMLButtonElement,
ComponentProps<typeof Root>
>(({ defaultChecked, ...props }, ref) => {
const [checked, onCheckedChange] = useControllableState({
prop: props.checked ?? defaultChecked ?? false,
defaultProp: false,
});
const currentChecked = props.checked ?? defaultChecked ?? false;
const [checked, setChecked] = useState(currentChecked);
// synchronize external value with local one when changed
useEffect(() => setChecked(currentChecked), [currentChecked]);
return (
<Root
{...props}
ref={ref}
checked={checked}
onCheckedChange={onCheckedChange}
/>
<Root {...props} ref={ref} checked={checked} onCheckedChange={setChecked} />
);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-components-react-radix/src/tabs.template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const meta: TemplateMeta = {
"A set of panels with content that are displayed one at a time. Duplicate both a tab trigger and tab content to add more tabs. Triggers and content are connected according to their order in the Navigator.",
order: 2,
template: (
<radix.Tabs defaultValue="0">
<radix.Tabs value="0">
<radix.TabsList
// inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground
ws:style={css`
Expand Down
Loading
Loading