Skip to content

Commit

Permalink
Merge pull request #135 from sannajammeh/solid
Browse files Browse the repository at this point in the history
Solid
  • Loading branch information
sannajammeh authored Dec 13, 2023
2 parents 08de2b0 + f04cc69 commit e32704c
Show file tree
Hide file tree
Showing 11 changed files with 1,503 additions and 315 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-humans-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tw-classed/solid": patch
---

Fix solid types - Rename Polymorphic.d.ts to polymorphic.ts to ensure dts plugin emits in bundle
16 changes: 8 additions & 8 deletions packages/solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@
},
"devDependencies": {
"@solidjs/testing-library": "^0.8.4",
"@testing-library/jest-dom": "^6.1.3",
"@testing-library/jest-dom": "^6.1.5",
"@types/testing-library__jest-dom": "^6.0.0",
"jsdom": "^22.1.0",
"solid-js": "^1.7.12",
"typescript": "^5.2.2",
"vite": "^4.4.9",
"vite-plugin-dts": "^3.5.3",
"vite-plugin-solid": "^2.7.0",
"vitest": "^0.34.4"
"jsdom": "^23.0.1",
"solid-js": "^1.8.7",
"typescript": "^5.3.3",
"vite": "^5.0.8",
"vite-plugin-dts": "^3.6.4",
"vite-plugin-solid": "^2.8.0",
"vitest": "^1.0.4"
}
}
File renamed without changes.
232 changes: 116 additions & 116 deletions packages/solid/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type {
InferVariantProps,
Variants,
$$ClassedProps,
$$ClassedVariants,
InferVariantProps,
Variants,
$$ClassedProps,
$$ClassedVariants,
} from "@tw-classed/core";
import type { Component, JSX } from "solid-js";
import * as Util from "./util";
Expand All @@ -11,146 +11,146 @@ import * as Polymorphic from "./polymorphic";
export { InferVariantProps, Variants };

interface InferableClassedType {
[$$ClassedVariants]: { variants: {} };
[$$ClassedVariants]: { variants: {} };
}

export type VariantProps<T extends InferableClassedType> = InferVariantProps<
T[$$ClassedVariants]["variants"]
T[$$ClassedVariants]["variants"]
>;

export type AnyComponent = Component<any>;

export interface ClassedComponentType<
Type extends keyof JSX.IntrinsicElements | AnyComponent,
Props extends {} = {},
TComposedVariants extends {} = {},
Type extends keyof JSX.IntrinsicElements | AnyComponent,
Props extends {} = {},
TComposedVariants extends {} = {}
> extends Polymorphic.PolymorphicComponent<Type, Props> {
[$$ClassedProps]: Props;
[$$ClassedVariants]: TComposedVariants;
[$$ClassedProps]: Props;
[$$ClassedVariants]: TComposedVariants;
}

export type DerivedComponentType<
Type extends keyof JSX.IntrinsicElements | Component<any>,
Props extends {} = {},
TComposedVariants extends {} = {},
Type extends keyof JSX.IntrinsicElements | Component<any>,
Props extends {} = {},
TComposedVariants extends {} = {}
> = ClassedComponentType<Type, Omit<Props, "as">, TComposedVariants>;

/** Returns the cumulative props from the given array of compositions. */
export type ClassedComponentProps<T extends any[]> =
($$ClassedProps extends keyof T[0]
? T[0][$$ClassedProps]
: T[0] extends { variants: { [name: string]: unknown } }
? InferVariantProps<T[0]["variants"]>
: {}) &
(T extends [lead: any, ...tail: infer V] ? ClassedComponentProps<V> : {});
($$ClassedProps extends keyof T[0]
? T[0][$$ClassedProps]
: T[0] extends { variants: { [name: string]: unknown } }
? InferVariantProps<T[0]["variants"]>
: {}) &
(T extends [lead: any, ...tail: infer V] ? ClassedComponentProps<V> : {});

/** Returns the cumulative variants from the given array of compositions. */
export type ClassedComponentVariants<T extends any[]> =
($$ClassedVariants extends keyof T[0]
? T[0][$$ClassedVariants]
: T[0] extends { variants: { [name: string]: unknown } }
? Pick<T[0], "variants" | "defaultVariants">
: {}) &
(T extends [lead: any, ...tail: infer V]
? ClassedComponentVariants<V>
: {});
($$ClassedVariants extends keyof T[0]
? T[0][$$ClassedVariants]
: T[0] extends { variants: { [name: string]: unknown } }
? Pick<T[0], "variants" | "defaultVariants">
: {}) &
(T extends [lead: any, ...tail: infer V]
? ClassedComponentVariants<V>
: {});

export interface ClassedFunctionType {
<
Type extends keyof JSX.IntrinsicElements | AnyComponent,
Composers extends (
| string
| Util.Function
| {
base?: string;
variants?: { [name: string]: unknown };
}
)[],
>(
type: Type,
...composers: {
[K in keyof Composers]: string extends Composers[K]
? Composers[K]
: Composers[K] extends string | Util.Function
? Composers[K]
: {
base?: string;
variants?: Variants;
defaultVariants?: "variants" extends keyof Composers[K]
? {
[Name in keyof Composers[K]["variants"]]?: Util.Widen<
keyof Composers[K]["variants"][Name]
>;
}
: never;
<
Type extends keyof JSX.IntrinsicElements | AnyComponent,
Composers extends (
| string
| Util.Function
| {
base?: string;
variants?: { [name: string]: unknown };
}
)[]
>(
type: Type,
...composers: {
[K in keyof Composers]: string extends Composers[K]
? Composers[K]
: Composers[K] extends string | Util.Function
? Composers[K]
: {
base?: string;
variants?: Variants;
defaultVariants?: "variants" extends keyof Composers[K]
? {
[Name in keyof Composers[K]["variants"]]?: Util.Widen<
keyof Composers[K]["variants"][Name]
>;
}
: never;

compoundVariants?: (("variants" extends keyof Composers[K]
? {
[Name in keyof Composers[K]["variants"]]?:
| Util.Widen<keyof Composers[K]["variants"][Name]>
| Util.String;
}
: never) & {
className?: Util.String;
class?: Util.String;
})[];
};
}
): ClassedComponentType<
Type,
ClassedComponentProps<Composers>,
ClassedComponentVariants<Composers>
>;
compoundVariants?: (("variants" extends keyof Composers[K]
? {
[Name in keyof Composers[K]["variants"]]?:
| Util.Widen<keyof Composers[K]["variants"][Name]>
| Util.String;
}
: never) & {
className?: Util.String;
class?: Util.String;
})[];
};
}
): ClassedComponentType<
Type,
ClassedComponentProps<Composers>,
ClassedComponentVariants<Composers>
>;
}

export interface ClassedProxyFunctionType<
Type extends keyof JSX.IntrinsicElements | AnyComponent,
Type extends keyof JSX.IntrinsicElements | AnyComponent
> {
<
Composers extends (
| string
| Util.Function
| {
base?: string;
variants?: { [name: string]: unknown };
}
)[],
>(
...composers: {
[K in keyof Composers]: string extends Composers[K]
? Composers[K]
: Composers[K] extends string | Util.Function
? Composers[K]
: {
base?: string;
variants?: Variants;
defaultVariants?: "variants" extends keyof Composers[K]
? {
[Name in keyof Composers[K]["variants"]]?: Util.Widen<
keyof Composers[K]["variants"][Name]
>;
}
: never;
<
Composers extends (
| string
| Util.Function
| {
base?: string;
variants?: { [name: string]: unknown };
}
)[]
>(
...composers: {
[K in keyof Composers]: string extends Composers[K]
? Composers[K]
: Composers[K] extends string | Util.Function
? Composers[K]
: {
base?: string;
variants?: Variants;
defaultVariants?: "variants" extends keyof Composers[K]
? {
[Name in keyof Composers[K]["variants"]]?: Util.Widen<
keyof Composers[K]["variants"][Name]
>;
}
: never;

compoundVariants?: (("variants" extends keyof Composers[K]
? {
[Name in keyof Composers[K]["variants"]]?:
| Util.Widen<keyof Composers[K]["variants"][Name]>
| Util.String;
}
: never) & {
className?: Util.String;
class?: Util.String;
})[];
};
}
): ClassedComponentType<
Type,
ClassedComponentProps<Composers>,
ClassedComponentVariants<Composers>
>;
compoundVariants?: (("variants" extends keyof Composers[K]
? {
[Name in keyof Composers[K]["variants"]]?:
| Util.Widen<keyof Composers[K]["variants"][Name]>
| Util.String;
}
: never) & {
className?: Util.String;
class?: Util.String;
})[];
};
}
): ClassedComponentType<
Type,
ClassedComponentProps<Composers>,
ClassedComponentVariants<Composers>
>;
}

export type ClassedFunctionProxy = ClassedFunctionType & {
[K in keyof JSX.IntrinsicElements]: ClassedProxyFunctionType<K>;
[K in keyof JSX.IntrinsicElements]: ClassedProxyFunctionType<K>;
};
2 changes: 1 addition & 1 deletion packages/solid/test/classed.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, it } from "vitest";
import { expect, it, describe } from "vitest";
import { classed, VariantProps } from "../src";

import { render, screen } from "@solidjs/testing-library";
Expand Down
1 change: 1 addition & 0 deletions packages/solid/test/composition.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { cleanup, render, screen } from "@solidjs/testing-library";
import { Component } from "solid-js";
import { classed } from "../src";
import { expect, it } from "vitest";

it("Should inherit classNames from Classed Component in creator fn", () => {
const A = classed(
Expand Down
1 change: 1 addition & 0 deletions packages/solid/test/compound.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "@testing-library/jest-dom";
import { classed } from "../src";
import { render, screen } from "@solidjs/testing-library";
import { expect, it } from "vitest";

it("Should apply compound variants", () => {
const Button = classed("button", {
Expand Down
1 change: 1 addition & 0 deletions packages/solid/test/interop.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { classed as core } from "@tw-classed/core";

import { classed } from "../src";
import { render, screen } from "@solidjs/testing-library";
import { describe, expect, it } from "vitest";

describe("Interop: Core -> React", () => {
it("Should inherit classNames", () => {
Expand Down
1 change: 1 addition & 0 deletions packages/solid/test/proxy.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "@testing-library/jest-dom";
import { classed } from "../src";
import { render, screen } from "@solidjs/testing-library";
import { expect, it } from "vitest";

it("Should function like classed when to proxy path exists", () => {
const Button = classed("button", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import pkg from "./package.json";
export default defineConfig({
plugins: [
dts({
tsConfigFilePath: "./tsconfig.json",
tsconfigPath: "./tsconfig.json",
insertTypesEntry: true,
noEmitOnError: true,
skipDiagnostics: false,
}),
solidPlugin(),
],
Expand All @@ -35,10 +33,7 @@ export default defineConfig({
test: {
environment: "jsdom",
globals: true,

transformMode: {
web: [/\.[jt]sx?$/],
},
setupFiles: ["./test/setup.ts"],
},
resolve: {
conditions: ["development", "browser"],
Expand Down
Loading

0 comments on commit e32704c

Please sign in to comment.