Skip to content

Commit

Permalink
Type fixes (#33)
Browse files Browse the repository at this point in the history
* react component type fixes

* add changeset
  • Loading branch information
nsaunders authored May 26, 2024
1 parent 6568f38 commit c0971bf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/cold-games-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@embellish/react": patch
---

Made `createComponent` config type more permissive for less confusing DX.
30 changes: 17 additions & 13 deletions packages/react/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {
RefAttributes,
} from "react";

export * from "@embellish/core";
export { createHooks, createConditions } from "@embellish/core";

export type ValidComponentDisplayName<Name> =
Name extends `${UppercaseLetter}${infer Tail}`
Expand All @@ -35,18 +35,18 @@ export type ComponentPropsWithRef<C extends ElementType> = PropsWithRef<
>;

export function createComponent<
const DisplayName extends string,
StyleProps,
ConditionName extends string,
const DisplayName extends string = "Box",
Conds,
DefaultIs extends keyof JSX.IntrinsicElements = "div",
>(config: {
displayName?: DisplayName & ValidComponentDisplayName<DisplayName>;
displayName: DisplayName & ValidComponentDisplayName<DisplayName>;
defaultIs?: DefaultIs;
defaultStyle?: CSSProperties;
styleProps: StyleProps & {
styleProps?: StyleProps & {
[P in keyof StyleProps]: ValidStylePropName<P> & StyleProps[P];
} & Record<string, (value: any) => CSSProperties>; // eslint-disable-line @typescript-eslint/no-explicit-any
conditions?: Conditions<ConditionName>;
conditions?: Conds;
fallback?: "revert-layer" | "unset";
}): <
Is extends
Expand All @@ -60,16 +60,20 @@ export function createComponent<
JSX.LibraryManagedAttributes<Is, ComponentPropsWithRef<Is>>,
"style"
> & {
[P in ConditionName extends never
? never
: `${Uncapitalize<DisplayName>}:conditions`]?: {
[P in LocalConditionName]: ValidConditionName<P> &
Condition<ConditionName>;
};
[P in Conds extends Conditions<unknown>
? `${Uncapitalize<DisplayName>}:conditions`
: never]?: Conds extends Conditions<infer ConditionName>
? {
[P in LocalConditionName]: ValidConditionName<P> &
Condition<ConditionName>;
}
: never;
} & Partial<{
[P in `${
| "initial"
| ConditionName
| (Conds extends Conditions<infer ConditionName>
? ConditionName
: never)
| LocalConditionName}:${keyof StyleProps extends string ? keyof StyleProps : never}`]: P extends `${string}:${infer PropertyName}`
? PropertyName extends keyof StyleProps
? StyleProps[PropertyName] extends (value: any) => unknown // eslint-disable-line @typescript-eslint/no-explicit-any
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createLocalConditions } from "@embellish/core";
import { createElement, forwardRef } from "react";

export * from "@embellish/core";
export { createHooks, createConditions } from "@embellish/core";

const unitlessNumbers = new Set([
"animationIterationCount",
Expand Down

0 comments on commit c0971bf

Please sign in to comment.