Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add chakra ui integration #156

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
94a8952
fix: resolved Mantine fieldConfig.description, mantine-zod advanced f…
adityacodepublic Jan 15, 2025
ac13117
date field key props spread
adityacodepublic Jan 15, 2025
2d4e92c
added test wrapper to 'renders select field correctly' test
adityacodepublic Jan 15, 2025
8b710a5
re added the conditional theme provider rendering
adityacodepublic Jan 16, 2025
ace9aee
refined ant package, restored react package to previous
adityacodepublic Jan 16, 2025
db6a00c
refactor(ant): improve implementation, fix bugs, and add tests
adityacodepublic Jan 24, 2025
66ed95c
restore default ant autoform props
adityacodepublic Jan 24, 2025
65e161a
added changeset
adityacodepublic Jan 24, 2025
0c8660d
added changeset version and changelog
adityacodepublic Jan 24, 2025
e374044
commit deleted changeset
adityacodepublic Jan 24, 2025
418ef11
rename AutoFormProps of packages/ant/AutoForm in camelCase
adityacodepublic Jan 25, 2025
c10352d
ant package version 1.0.0 -> 1.1.0
adityacodepublic Jan 28, 2025
d4f43e0
feat: integrate chakra ui
adityacodepublic Jan 29, 2025
74c8066
added cypress tests for chakra ui
adityacodepublic Jan 29, 2025
3624012
fix: chakra styles
adityacodepublic Feb 1, 2025
6f7c453
object wrapper styles
adityacodepublic Feb 1, 2025
1247e46
fixed: focus on error, for all fields.
adityacodepublic Feb 2, 2025
c2df4f0
fix: ant package field focus on error
adityacodepublic Feb 2, 2025
bd087b5
update web page imports
adityacodepublic Feb 2, 2025
7147f9a
feat: integrate chakra ui
adityacodepublic Jan 29, 2025
5887b32
added cypress tests for chakra ui
adityacodepublic Jan 29, 2025
f16fdab
fix: chakra styles
adityacodepublic Feb 1, 2025
d7d5274
object wrapper styles
adityacodepublic Feb 1, 2025
979b69f
fixed: focus on error, for all fields.
adityacodepublic Feb 2, 2025
4cb0c6d
update web page imports
adityacodepublic Feb 2, 2025
29034eb
Merge branch 'add-chakra' of https://github.com/adityacodepublic/auto…
adityacodepublic Feb 2, 2025
7638b86
test(chakra): Add Cypress tests for chakra package, added name attrib…
adityacodepublic Feb 2, 2025
2eba1a5
fix: select field accept input props
adityacodepublic Feb 4, 2025
791b515
fix: date and select field bugs
adityacodepublic Feb 10, 2025
bf5bd7f
chore: delete unnecessary components (dialog and drawer)
adityacodepublic Feb 10, 2025
3e47ba8
Merge remote-tracking branch 'origin/main' into add-chakra
adityacodepublic Feb 11, 2025
faa3542
chore: update ant package readme
adityacodepublic Feb 11, 2025
1375d5d
chore: removed avatar component chakra
adityacodepublic Feb 12, 2025
577e57a
chore: remove slider and tooltip form chakra package
adityacodepublic Feb 12, 2025
46d5849
chore: update all.cy.tsx
adityacodepublic Feb 12, 2025
a8ab6e3
fix:added some tests which were not added in the all.cy
adityacodepublic Feb 12, 2025
90d6952
docs: Todo: ticked Chakra UI
adityacodepublic Feb 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/docs/pages/docs/technical/todo.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { Callout } from "nextra/components";

- UI libraries
- [x] MUI
- [ ] Chakra UI
- [x] Chakra UI
- [x] Ant Design
- [x] Mantine
- [x] shadcn/ui registry
Expand Down
12 changes: 4 additions & 8 deletions apps/web/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import type { Metadata } from "next";
import "./globals.css";
import "@mantine/core/styles.css";
import "@autoform/shadcn/globals.css";
import { createTheme, MantineProvider } from "@mantine/core";
import { ColorSchemeScript } from "@mantine/core";
// import "./globals.css";
// import { ColorSchemeScript } from "@mantine/core";

const theme = createTheme({});

export const metadata: Metadata = {
title: "AutoForm Demo",
Expand All @@ -20,10 +16,10 @@ export default function RootLayout({
return (
<html lang="en">
<head>
<ColorSchemeScript />
{/* <ColorSchemeScript /> */}
</head>
<body>
<MantineProvider theme={theme}>{children}</MantineProvider>
{children}
</body>
</html>
);
Expand Down
10 changes: 7 additions & 3 deletions apps/web/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"use client";
import { Card, CardContent, Container, Typography } from "@mui/material";
// import Basics from "../components/Basics";
import Ant from "../components/Ant";
// import Ant from "../components/Ant";
import Chakra from "components/Chakra";
// import Mantine from "components/Mantine";
// import Array from "components/Array";
// import Basics from "../components/Basics";

export default function Home() {
return (
<div>
Expand All @@ -16,7 +19,8 @@ export default function Home() {
{/* <Array /> */}
{/* <Mantine /> */}
{/* <Shadcn /> */}
<Ant />
{/* <Ant /> */}
<Chakra/>
</CardContent>
</Card>
</Container>
Expand Down
4 changes: 2 additions & 2 deletions apps/web/components/Basics.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AutoForm } from "@autoform/shadcn/components/ui/autoform/AutoForm";
import { ZodProvider } from "@autoform/zod";
import { zodSchemaProvider } from "./utils";
import { AutoFormFieldProps } from "@autoform/react";
import { zodSchemaProvider } from "./utils";
import "@autoform/shadcn/globals.css";

function Basics() {
return (
Expand Down
19 changes: 19 additions & 0 deletions apps/web/components/Chakra.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { AutoForm, fieldConfig } from "@autoform/chakra";
import { zodSchemaProvider } from "./utils";

function Chakra() {
return (
<AutoForm
schema={zodSchemaProvider}
onSubmit={(data) => {
console.log(JSON.stringify(data, null, 2));
}}
colorModeProps={{
enableSystem: false,
}}
withSubmit
/>
);
}

export default Chakra;
19 changes: 12 additions & 7 deletions apps/web/components/Mantine.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { createTheme, MantineProvider } from "@mantine/core";
import { AutoForm, fieldConfig } from "@autoform/mantine";
import { zodSchemaProvider } from "./utils";
import "@mantine/core/styles.css";

function Mantine() {
const theme = createTheme({});
return (
<AutoForm
schema={zodSchemaProvider}
onSubmit={(data) => {
console.log(JSON.stringify(data, null, 2));
}}
withSubmit
/>
<MantineProvider theme={theme}>
<AutoForm
schema={zodSchemaProvider}
onSubmit={(data) => {
console.log(JSON.stringify(data, null, 2));
}}
withSubmit
/>
</MantineProvider>
);
}

Expand Down
5 changes: 3 additions & 2 deletions apps/web/cypress/component/autoform/all.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "./ant-zod/all.cy"
import "./chakra-zod/all.cy"
import "./mantine-zod/all.cy";
import "./mui-yup/all.cy";
import "./mui-zod/all.cy";
import "./mantine-zod/all.cy";
import "./shadcn-zod/all.cy";
import "./ant-zod/all.cy"
4 changes: 3 additions & 1 deletion apps/web/cypress/component/autoform/ant-zod/all.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import "./basic.cy";
import "./arrays.cy";
import "./subobjects.cy";
import "./advanced-features.cy";
import "./form-props.cy";
import "./validation.cy";
import "./custom-fields.cy";
import "./controlled-form.cy";
import "./ui-customization.cy";
import "./advanced-features.cy";
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import React from "react";
import { AutoForm } from "@autoform/chakra";
import { ZodProvider, fieldConfig } from "@autoform/zod";
import { z } from "zod";

describe("AutoForm Advanced Features Tests", () => {
const advancedSchema = z.object({
username: z
.string()
.min(3, "Username must be at least 3 characters")
.superRefine(
fieldConfig({
description: "Choose a unique username",
order: 1,
inputProps: {
placeholder: "Enter username",
},
})
),
password: z
.string()
.min(8, "Password must be at least 8 characters")
.superRefine(
fieldConfig({
description: "Use a strong password",
order: 2,
inputProps: {
type: "password",
},
})
),
favoriteColor: z.enum(["red", "green", "blue"]).superRefine(
fieldConfig({
fieldType: "select",
order: 3,
})
),
bio: z
.string()
.optional()
.superRefine(
fieldConfig({
order: 4,
})
),
});

const schemaProvider = new ZodProvider(advancedSchema);

it("renders fields in the correct order", () => {
cy.mount(
<AutoForm
schema={schemaProvider}
onSubmit={cy.stub().as("onSubmit")}
withSubmit
/>
);

cy.get(".chakra-field__root")
.eq(0)
.find("input")
.should("have.attr", "name", "username");
cy.get(".chakra-field__root")
.eq(1)
.find("input")
.should("have.attr", "name", "password");
cy.get(".chakra-field__root").eq(2).find("select");
cy.get(".chakra-field__root")
.eq(3)
.find("input")
.should("have.attr", "name", "bio");
});

it("displays field descriptions", () => {
cy.mount(
<AutoForm
schema={schemaProvider}
onSubmit={cy.stub().as("onSubmit")}
withSubmit
/>
);

cy.contains("Choose a unique username").should("be.visible");
cy.contains("Use a strong password").should("be.visible");
});

it("applies custom input props", () => {
cy.mount(
<AutoForm
schema={schemaProvider}
onSubmit={cy.stub().as("onSubmit")}
withSubmit
/>
);

cy.get('input[name="username"]').should(
"have.attr",
"placeholder",
"Enter username"
);
cy.get('input[name="password"]').should("have.attr", "type", "password");
});

it("renders select field correctly", () => {
cy.mount(
<AutoForm
schema={schemaProvider}
onSubmit={cy.stub().as("onSubmit")}
withSubmit
/>
);

cy.get('.chakra-select__root').should("exist").within(() => {
cy.get('select').should("have.attr", "name", "favoriteColor");
}).click();

cy.get('.chakra-select__content').should("exist").within(() => {
cy.get('.chakra-select__item').should('exist').should('contain', 'red');
cy.get('.chakra-select__item').should('exist').should('contain', 'green');
cy.get('.chakra-select__item').should('exist').should('contain', 'blue');
});

});

it("renders textarea field correctly", () => {
cy.mount(
<AutoForm
schema={schemaProvider}
onSubmit={cy.stub().as("onSubmit")}
withSubmit
/>
);

cy.get('input[name="bio"]').should("exist");
});
});
9 changes: 9 additions & 0 deletions apps/web/cypress/component/autoform/chakra-zod/all.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import "./basic.cy";
import "./arrays.cy";
import "./subobjects.cy";
import "./form-props.cy";
import "./validation.cy";
import "./custom-fields.cy";
import "./controlled-form.cy";
import "./ui-customization.cy";
import "./advanced-features.cy";
67 changes: 67 additions & 0 deletions apps/web/cypress/component/autoform/chakra-zod/arrays.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React from "react";
import { AutoForm } from "@autoform/chakra";
import { ZodProvider } from "@autoform/zod";
import { z } from "zod";

describe("AutoForm Arrays Tests", () => {
const arraySchema = z.object({
tags: z.array(z.string()),
friends: z.array(
z.object({
name: z.string(),
age: z.coerce.number(),
})
),
});

const schemaProvider = new ZodProvider(arraySchema);

it("renders array fields correctly", () => {
cy.mount(
<AutoForm
schema={schemaProvider}
onSubmit={cy.stub().as("onSubmit")}
withSubmit
/>
);

cy.get('button[name="add-array-item"]').eq(0).should('exist');
cy.get('button[name="add-array-item"]').eq(1).should('exist');
});

it("allows adding and removing array items", () => {
cy.mount(
<AutoForm
schema={schemaProvider}
onSubmit={cy.stub().as("onSubmit")}
withSubmit
/>
);

// Add tags
cy.get('button[name="add-array-item"]').eq(0).click();
cy.get('input[name="tags.0"]').type("tag1");
cy.get('button[name="add-array-item"]').eq(0).click();
cy.get('input[name="tags.1"]').type("tag2");

// Add friends
cy.get('button[name="add-array-item"]').eq(1).click();
cy.get('input[name="friends.0.name"]').type("Alice");
cy.get('input[name="friends.0.age"]').type("25");
cy.get('button[name="add-array-item"]').eq(1).click();
cy.get('input[name="friends.1.name"]').type("Bob");
cy.get('input[name="friends.1.age"]').type("30");

// Remove a tag and a friend
cy.get('button[name="remove-array-item"]').eq(0).click();
cy.get('button[name="remove-array-item"]').eq(1).click();

cy.get('button[type="submit"]').click();

cy.get("@onSubmit").should("have.been.calledOnce");
cy.get("@onSubmit").should("have.been.calledWith", {
tags: ["tag2"],
friends: [{ name: "Bob", age: 30 }],
});
});
});
Loading