@stackshift-ui/system 2.0.0 → 6.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@stackshift-ui/system",
3
- "version": "2.0.0",
3
+ "version": "6.0.3",
4
4
  "private": false,
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.mjs",
8
8
  "types": "./dist/index.d.ts",
9
9
  "files": [
10
- "dist/**"
10
+ "dist/**",
11
+ "src"
11
12
  ],
12
13
  "devDependencies": {
13
14
  "@testing-library/react": "^16.0.1",
@@ -24,8 +25,8 @@
24
25
  "typescript": "^5.6.2",
25
26
  "vite-tsconfig-paths": "^5.0.1",
26
27
  "vitest": "^2.1.1",
27
- "@stackshift-ui/eslint-config": "1.0.0",
28
- "@stackshift-ui/typescript-config": "2.0.0"
28
+ "@stackshift-ui/typescript-config": "6.0.2",
29
+ "@stackshift-ui/eslint-config": "6.0.2"
29
30
  },
30
31
  "dependencies": {
31
32
  "nextjs-darkmode": "^1.0.4",
@@ -33,7 +34,7 @@
33
34
  "r18gs": "^2.0.0",
34
35
  "react-live": "^4.1.7",
35
36
  "react18-loaders": "latest",
36
- "@stackshift-ui/scripts": "1.0.0"
37
+ "@stackshift-ui/scripts": "6.0.2"
37
38
  },
38
39
  "peerDependencies": {
39
40
  "@types/react": "16.8 - 19",
@@ -0,0 +1,28 @@
1
+ /* eslint-disable @typescript-eslint/no-unsafe-call */
2
+ import { cleanup, render, screen } from "@testing-library/react";
3
+ import { afterEach, describe, it } from "vitest";
4
+ import { DefaultComponent } from "./default-component";
5
+
6
+ describe("DefaultComponent", () => {
7
+ afterEach(cleanup);
8
+
9
+ it("should render a div by default", ({ expect }) => {
10
+ render(<DefaultComponent />);
11
+ const divElements = screen.getAllByRole("generic");
12
+
13
+ expect(divElements[0].nodeName).toBe("DIV");
14
+ });
15
+
16
+ it("should render the specified component", ({ expect }) => {
17
+ render(<DefaultComponent as="span" />);
18
+
19
+ expect(screen.getByTestId("span").nodeName).toBe("SPAN");
20
+ });
21
+
22
+ it("should pass props to the rendered component", ({ expect }) => {
23
+ render(<DefaultComponent as="button" type="submit" />);
24
+
25
+ expect(screen.getByRole("button").nodeName).toBe("BUTTON");
26
+ expect(screen.getByRole("button").getAttribute("type")).toBe("submit");
27
+ });
28
+ });
@@ -0,0 +1,10 @@
1
+ import type { HTMLProps } from "react";
2
+
3
+ export const DefaultComponent = <T extends keyof JSX.IntrinsicElements>(
4
+ props: HTMLProps<T>,
5
+ ): JSX.Element => {
6
+ const { as = "div", ...rest } = props;
7
+ const Component = as;
8
+
9
+ return <Component {...rest} data-testid={as} />;
10
+ };
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ "use client";
2
+
3
+ // component exports
4
+ export { DefaultComponent } from "./default-component";
5
+ export { StackShiftUIProvider, useStackShiftUIComponents } from "./system";
@@ -0,0 +1,44 @@
1
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
2
+ import { cleanup, render, screen } from "@testing-library/react";
3
+ import { afterEach, describe, expect, it } from "vitest";
4
+ import { StackShiftUIProvider, useStackShiftUIComponents } from "./system";
5
+
6
+ describe("StackShiftUIProvider", () => {
7
+ afterEach(cleanup);
8
+
9
+ it("should provide custom components", () => {
10
+ function CustomComponent() {
11
+ return <div>Custom Component</div>;
12
+ }
13
+ const components = { CustomComponent };
14
+
15
+ render(
16
+ <StackShiftUIProvider components={components}>
17
+ <CustomComponent />
18
+ </StackShiftUIProvider>,
19
+ );
20
+
21
+ const element = screen.getByText("Custom Component");
22
+
23
+ expect(element).not.toBeNull(); // Check that the element is not null
24
+ expect(document.body.contains(element)).toBe(true); // Check that the element is in the document
25
+ });
26
+
27
+ it("should use default components if none are provided", () => {
28
+ function DefaultComponent() {
29
+ const { DefaultComponent: Component = "div" } = useStackShiftUIComponents();
30
+ return <Component>Default Component</Component>;
31
+ }
32
+
33
+ render(
34
+ <StackShiftUIProvider>
35
+ <DefaultComponent />
36
+ </StackShiftUIProvider>,
37
+ );
38
+
39
+ const element = screen.getByText("Default Component");
40
+
41
+ expect(element).not.toBeNull(); // Check that the element is not null
42
+ expect(document.body.contains(element)).toBe(true); // Check that the element is in the document
43
+ });
44
+ });
package/src/system.tsx ADDED
@@ -0,0 +1,25 @@
1
+ import { createContext, ReactNode, useContext } from "react";
2
+
3
+ // Define the type for the components object
4
+ interface Components {
5
+ [key: string]: React.ComponentType<any>;
6
+ }
7
+
8
+ // Create a context for components
9
+ const ComponentContext = createContext<Components>({});
10
+
11
+ // Create a provider that allows passing custom components
12
+ interface ComponentProviderProps {
13
+ components?: Components;
14
+ children: ReactNode;
15
+ }
16
+
17
+ export const StackShiftUIProvider: React.FC<ComponentProviderProps> = ({
18
+ components = {},
19
+ children,
20
+ }) => {
21
+ return <ComponentContext.Provider value={components}>{children}</ComponentContext.Provider>;
22
+ };
23
+
24
+ // Hook to use the components
25
+ export const useStackShiftUIComponents = () => useContext(ComponentContext);