Skip to content

Commit

Permalink
Fix missing slots on React and Preact wrapper components
Browse files Browse the repository at this point in the history
  • Loading branch information
lemonmade committed Sep 16, 2024
1 parent b4005bd commit 26d3eca
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 19 deletions.
6 changes: 6 additions & 0 deletions .changeset/dry-mirrors-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@watching/clips-preact': patch
'@watching/clips-react': patch
---

Fix missing slots on React and Preact wrapper components
18 changes: 14 additions & 4 deletions packages/clips-preact/source/components/Action.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import type {RenderableProps} from 'preact';
import {
cloneElement,
isValidElement,
type RenderableProps,
type VNode,
} from 'preact';

import type {
Action as ActionElement,
Expand All @@ -8,23 +13,28 @@ import type {

export interface ActionProps
extends RenderableProps<Partial<ActionProperties>, ActionElement> {
overlay?: VNode<any>;
onPress?(): void | Promise<void>;
onpress?(event: ActionEvents['press']): void;
}

declare module 'preact' {
namespace JSX {
interface IntrinsicElements {
'ui-action': Omit<ActionProps, 'onPress'>;
'ui-action': Omit<ActionProps, 'onPress' | 'overlay'>;
}
}
}

export function Action({onPress, ...props}: ActionProps) {
export function Action({overlay, onPress, ...props}: ActionProps) {
return (
<ui-action
{...props}
onpress={onPress ? (event) => event.respondWith(onPress()) : undefined}
/>
>
{overlay && isValidElement(overlay)
? cloneElement(overlay, {slot: 'overlay'})
: null}
</ui-action>
);
}
4 changes: 2 additions & 2 deletions packages/clips-preact/source/components/Disclosure.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
cloneElement,
isValidElement,
type ComponentChild,
type VNode,
type RenderableProps,
} from 'preact';

Expand All @@ -15,7 +15,7 @@ export interface DisclosureProps
Omit<Partial<DisclosureProperties>, 'label'>,
DisclosureElement
> {
label?: ComponentChild;
label?: VNode<any>;
}

declare module 'preact' {
Expand Down
7 changes: 3 additions & 4 deletions packages/clips-preact/source/components/TextField.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
cloneElement,
isValidElement,
type ComponentChild,
type VNode,
type RenderableProps,
} from 'preact';

Expand All @@ -13,11 +13,10 @@ import type {

export interface TextFieldProps
extends RenderableProps<
Omit<Partial<TextFieldProperties>, 'label'> & {
label?: ComponentChild;
},
Omit<Partial<TextFieldProperties>, 'label'>,
TextFieldElement
> {
label?: VNode<any>;
onChange?(value: string): void;
onchange?(event: TextFieldEvents['change']): void;
onInput?(value: string): void;
Expand Down
20 changes: 16 additions & 4 deletions packages/clips-react/source/components/Action.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import {forwardRef, type PropsWithChildren, type ForwardedRef} from 'react';
import {
forwardRef,
isValidElement,
cloneElement,
type ReactNode,
type PropsWithChildren,
type ForwardedRef,
} from 'react';

import type {
Action as ActionElement,
Expand All @@ -9,27 +16,32 @@ import type {
export interface ActionProps
extends PropsWithChildren<Partial<ActionProperties>> {
ref?: ForwardedRef<ActionElement>;
overlay?: ReactNode;
onPress?(): void | Promise<void>;
onpress?(event: ActionEvents['press']): void;
}

declare module 'react' {
namespace JSX {
interface IntrinsicElements {
'ui-action': Omit<ActionProps, 'onPress'>;
'ui-action': Omit<ActionProps, 'onPress' | 'overlay'>;
}
}
}

export const Action = forwardRef<ActionElement, ActionProps>(function Action(
{onPress, ...props},
{overlay, onPress, ...props},
ref,
) {
return (
<ui-action
ref={ref}
{...props}
onpress={onPress ? (event) => event.respondWith(onPress()) : undefined}
/>
>
{overlay && isValidElement(overlay)
? cloneElement<any>(overlay, {slot: 'overlay'})
: null}
</ui-action>
);
});
7 changes: 2 additions & 5 deletions packages/clips-react/source/components/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ import type {
} from '@watching/clips/elements';

export interface TextFieldProps
extends PropsWithChildren<
Omit<Partial<TextFieldProperties>, 'label'> & {
label?: ReactNode;
}
> {
extends PropsWithChildren<Omit<Partial<TextFieldProperties>, 'label'>> {
ref?: ForwardedRef<TextFieldElement>;
label?: ReactNode;
onChange?(value: string): void;
onchange?(event: TextFieldEvents['change']): void;
onInput?(value: string): void;
Expand Down

0 comments on commit 26d3eca

Please sign in to comment.