Skip to content

Commit

Permalink
Prioritize component's own props (#58)
Browse files Browse the repository at this point in the history
* Fix for prop collision issues.

* add changeset

* Docs update
  • Loading branch information
nsaunders committed Jun 29, 2024
1 parent 4ba4be8 commit 2a74e6b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/tricky-steaks-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@embellish/react": patch
---

Avoid prop collision issues by prioritizing component's own props.
16 changes: 10 additions & 6 deletions docs/api/react.componentprops.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ P,
C extends string,
Is extends keyof JSX.IntrinsicElements | React.JSXElementConstructor<any>,
InlineConditionName extends string,
> = {
is?: Is;
} & Omit<JSX.LibraryManagedAttributes<Is, ComponentPropsWithRef<Is>>, never> &
(string extends C
OwnProps = (string extends C
? unknown
: {
conditions?: {
Expand All @@ -37,7 +34,14 @@ Partial<{
: PropName extends keyof P
? P[PropName]
: never;
}>;
}>,
> = {
is?: Is;
} & Omit<
JSX.LibraryManagedAttributes<Is, ComponentPropsWithRef<Is>>,
keyof OwnProps
> &
OwnProps;
```
**References:** [ComponentPropsWithRef](./react.componentpropswithref.md)<!-- -->, [ValidConditionName](./react.validconditionname.md)<!-- -->, [Condition](./react.condition.md)
**References:** [ValidConditionName](./react.validconditionname.md)<!-- -->, [Condition](./react.condition.md)<!-- -->, [ComponentPropsWithRef](./react.componentpropswithref.md)

39 changes: 22 additions & 17 deletions packages/react/src/component.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface ComponentOptions<P, C extends string, DefaultIs> {
* @typeParam C - Type of supported condition names
* @typeParam Is - Type of element to render the component
* @typeParam InlineConditionName - Type of inline condition names
* @typeParam OwnProps - Type of the component's own props
*
* @public
*/
Expand All @@ -60,30 +61,34 @@ export type ComponentProps<
C extends string,
Is extends keyof JSX.IntrinsicElements | React.JSXElementConstructor<any>,
InlineConditionName extends string,
> = {
is?: Is;
} & Omit<JSX.LibraryManagedAttributes<Is, ComponentPropsWithRef<Is>>, never> &
(string extends C
OwnProps = (string extends C
? unknown
: {
conditions?: {
[Name in InlineConditionName]: ValidConditionName<Name> &
Condition<C>;
};
}) &
Partial<{
[PropName in
| keyof P
| (keyof P extends string
? `${C | InlineConditionName}:${keyof P}`
: never)]: PropName extends `${C | InlineConditionName}:${infer BasePropName}`
? BasePropName extends keyof P
? P[BasePropName]
: never
: PropName extends keyof P
? P[PropName]
: never;
}>;
Partial<{
[PropName in
| keyof P
| (keyof P extends string
? `${C | InlineConditionName}:${keyof P}`
: never)]: PropName extends `${C | InlineConditionName}:${infer BasePropName}`
? BasePropName extends keyof P
? P[BasePropName]
: never
: PropName extends keyof P
? P[PropName]
: never;
}>,
> = {
is?: Is;
} & Omit<
JSX.LibraryManagedAttributes<Is, ComponentPropsWithRef<Is>>,
keyof OwnProps
> &
OwnProps;

/**
* Polymorphic component with first-class style props and conditional styling
Expand Down

0 comments on commit 2a74e6b

Please sign in to comment.