diff --git a/.storybook/main.ts b/.storybook/main.ts index 28f0f002..d59901ba 100644 --- a/.storybook/main.ts +++ b/.storybook/main.ts @@ -10,6 +10,10 @@ const config: StorybookConfig = { titlePrefix: "Styling", directory: "../packages/tailwind-formio" }, + { + titlePrefix: "Atoms", + directory: "../packages/react-formio/src/atoms" + }, { titlePrefix: "Molecules", directory: "../packages/react-formio/src/molecules" diff --git a/package.json b/package.json index 9cfea7c9..3ed5bc29 100644 --- a/package.json +++ b/package.json @@ -7,12 +7,12 @@ "type": "module", "repository": { "type": "git", - "url": "https://github.com/TypedProject/tsed-formio.git" + "url": "https://github.com/tsedio/tsed-formio.git" }, "bugs": { - "url": "https://github.com/TypedProject/tsed-formio/issues" + "url": "https://github.com/tsedio/tsed-formio/issues" }, - "homepage": "https://github.com/TypedProject/tsed-formio", + "homepage": "https://github.com/tsedio/tsed-formio", "scripts": { "configure": "monorepo ci configure", "test": "lerna run test --stream", diff --git a/packages/react-formio-container/package.json b/packages/react-formio-container/package.json index 57185c4f..41c14f30 100644 --- a/packages/react-formio-container/package.json +++ b/packages/react-formio-container/package.json @@ -97,5 +97,6 @@ "tooltip.js": { "optional": false } - } + }, + "dependencies": {} } diff --git a/packages/react-formio-stores/src/stores/auth/auth.reducers.ts b/packages/react-formio-stores/src/stores/auth/auth.reducers.ts index 40f33310..afe27b42 100644 --- a/packages/react-formio-stores/src/stores/auth/auth.reducers.ts +++ b/packages/react-formio-stores/src/stores/auth/auth.reducers.ts @@ -1,4 +1,4 @@ -import type { FormType, RoleType, SubmissionType } from "@tsed/react-formio"; +import { FormType, JSON, RoleType, SubmissionType } from "@tsed/react-formio"; import { createReducer } from "@tsed/redux-utils"; import { @@ -14,7 +14,7 @@ import { } from "./auth.actions"; import { AUTH } from "./auth.constant"; -export interface AuthState { +export interface AuthState { init: boolean; isActive: boolean; user: null | SubmissionType; diff --git a/packages/react-formio/src/molecules/forms/select/components/ChoicesSelect.stories.tsx b/packages/react-formio/src/molecules/forms/select/components/ChoicesSelect.stories.tsx index 604fa7d3..1448b2f8 100644 --- a/packages/react-formio/src/molecules/forms/select/components/ChoicesSelect.stories.tsx +++ b/packages/react-formio/src/molecules/forms/select/components/ChoicesSelect.stories.tsx @@ -1,7 +1,7 @@ import "./ChoicesSelect"; import { Meta, StoryObj } from "@storybook/react"; -import { expect, fn, userEvent, within } from "@storybook/test"; +import { fn } from "@storybook/test"; import { iconClass } from "../../../../utils/iconClass"; import { useValue } from "../../../__fixtures__/useValue.hook"; @@ -95,24 +95,6 @@ export const Usage: Story = { value: "option-1", options, onChange: fn() - }, - play: async ({ canvasElement, args }) => { - const canvas = within(canvasElement); - - const select = canvas.getByTestId("select_name"); - - await expect(select).toBeInTheDocument(); - await expect(select).toHaveValue("option-1"); - - await userEvent.selectOptions(select, "option-2"); - - await expect(select).toHaveValue("option-2"); - await expect(args.onChange).toHaveBeenCalledWith("name", "option-2"); - - const label = canvas.getByTestId("form-group-name"); - - await expect(label).toBeInTheDocument(); - await expect(label).toHaveTextContent("Label"); } }; @@ -125,19 +107,6 @@ export const WithPlaceholder: Story = { placeholder: "Select an option", options, onChange: fn() - }, - play: async ({ canvasElement, args }) => { - const canvas = within(canvasElement); - - const select = canvas.getByTestId("select_name"); - - await expect(select).toBeInTheDocument(); - await expect(select).toHaveValue(""); - - await userEvent.selectOptions(select, "option-2"); - - await expect(select).toHaveValue("option-2"); - await expect(args.onChange).toHaveBeenCalledWith("name", "option-2"); } }; /** @@ -150,19 +119,6 @@ export const WithPlaceholderAndRequired: Story = { options, required: true, onChange: fn() - }, - play: async ({ canvasElement, args }) => { - const canvas = within(canvasElement); - - const select = canvas.getByTestId("select_name"); - - await expect(select).toBeInTheDocument(); - await expect(select).toHaveValue(""); - - await userEvent.selectOptions(select, "option-2"); - - await expect(select).toHaveValue("option-2"); - await expect(args.onChange).toHaveBeenCalledWith("name", "option-2"); } }; /** diff --git a/packages/react-formio/src/molecules/forms/select/components/HtmlSelect.tsx b/packages/react-formio/src/molecules/forms/select/components/HtmlSelect.tsx index 9e889dc2..d16a4dd4 100644 --- a/packages/react-formio/src/molecules/forms/select/components/HtmlSelect.tsx +++ b/packages/react-formio/src/molecules/forms/select/components/HtmlSelect.tsx @@ -17,8 +17,8 @@ export function HTMLSelect({ name, id = name, size, value, multiple, onChange, o return ( {hasTypeChoices && (
-
)} {enableTags && ( @@ -100,3 +104,5 @@ export function FormParameters({ ); } + +registerComponent("FormParameters", FormParameters); diff --git a/packages/react-formio/src/organisms/form/builder/all.ts b/packages/react-formio/src/organisms/form/builder/all.ts new file mode 100644 index 00000000..24156e99 --- /dev/null +++ b/packages/react-formio/src/organisms/form/builder/all.ts @@ -0,0 +1,13 @@ +import "../../../atoms/icon/Icon"; +import "../../../molecules/button/Button"; +import "../../../molecules/forms/input-text/InputText"; +import "../../../molecules/forms/select/Select"; +import "../../../molecules/forms/select/components/HtmlSelect"; +import "../../../molecules/forms/input-tags/InputTags"; + +export * from "./FormBuilder"; +export * from "./FormEdit"; +export * from "./FormEditCtas"; +export * from "./FormParameters"; +export * from "./useFormBuilder"; +export * from "./useFormEdit"; diff --git a/packages/react-formio/src/organisms/table/actions/ActionsTable.spec.tsx b/packages/react-formio/src/organisms/table/actions/ActionsTable.spec.tsx index 4d35e88d..d7ff9aa1 100644 --- a/packages/react-formio/src/organisms/table/actions/ActionsTable.spec.tsx +++ b/packages/react-formio/src/organisms/table/actions/ActionsTable.spec.tsx @@ -1,3 +1,5 @@ +import "../../../molecules/forms/select/all.ts"; + import { fireEvent, render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; diff --git a/packages/react-formio/src/organisms/table/actions/ActionsTable.stories.tsx b/packages/react-formio/src/organisms/table/actions/ActionsTable.stories.tsx index 51186ca4..ae415b2c 100644 --- a/packages/react-formio/src/organisms/table/actions/ActionsTable.stories.tsx +++ b/packages/react-formio/src/organisms/table/actions/ActionsTable.stories.tsx @@ -1,3 +1,5 @@ +import "../../../molecules/forms/select/all.ts"; + import type { Meta, StoryObj } from "@storybook/react"; import { expect, fn, userEvent, within } from "@storybook/test"; diff --git a/packages/react-formio/src/organisms/table/actions/ActionsTable.tsx b/packages/react-formio/src/organisms/table/actions/ActionsTable.tsx index 57ffb034..ef14d842 100644 --- a/packages/react-formio/src/organisms/table/actions/ActionsTable.tsx +++ b/packages/react-formio/src/organisms/table/actions/ActionsTable.tsx @@ -37,7 +37,7 @@ export function ActionsTable({ data-testid={"action-table-select"} name={"actions"} value={currentAction} - choices={[{ label: i18n("Select an action"), value: "" }].concat(availableActions)} + options={[{ label: i18n("Select an action"), value: "" }].concat(availableActions)} onChange={(name: string, action: string) => setAction(action)} />
diff --git a/packages/react-formio/src/organisms/table/forms/FormsTable.stories.tsx b/packages/react-formio/src/organisms/table/forms/FormsTable.stories.tsx index c686fb43..bf4fe5fd 100644 --- a/packages/react-formio/src/organisms/table/forms/FormsTable.stories.tsx +++ b/packages/react-formio/src/organisms/table/forms/FormsTable.stories.tsx @@ -1,3 +1,8 @@ +import "../../../molecules/button/Button"; +import "../../../molecules/forms/input-text/InputText"; +import "../../../molecules/forms/select/all"; +import "../../../molecules/pagination/all"; + import tailwind from "@tsed/tailwind-formio"; import { FormsTable } from "./FormsTable"; diff --git a/packages/react-formio/src/organisms/table/submissions/SubmissionsTable.stories.tsx b/packages/react-formio/src/organisms/table/submissions/SubmissionsTable.stories.tsx index 66bb9de7..be719cf9 100644 --- a/packages/react-formio/src/organisms/table/submissions/SubmissionsTable.stories.tsx +++ b/packages/react-formio/src/organisms/table/submissions/SubmissionsTable.stories.tsx @@ -1,3 +1,8 @@ +import "../../../molecules/button/Button"; +import "../../../molecules/forms/input-text/InputText"; +import "../../../molecules/forms/select/all"; +import "../../../molecules/pagination/all"; + import { useState } from "react"; import { mapPagination } from "../../../utils/mapPagination"; diff --git a/packages/redux-utils/package.json b/packages/redux-utils/package.json index 772290cd..7a9e950e 100644 --- a/packages/redux-utils/package.json +++ b/packages/redux-utils/package.json @@ -27,5 +27,6 @@ "peerDependencies": { "react": "^18.3.1", "redux": "^4.0.5" - } + }, + "dependencies": {} } diff --git a/packages/tailwind-formio/package.json b/packages/tailwind-formio/package.json index 80af637f..8b81c29e 100644 --- a/packages/tailwind-formio/package.json +++ b/packages/tailwind-formio/package.json @@ -49,5 +49,7 @@ "last 1 firefox version", "last 1 safari version" ] - } + }, + "dependencies": {}, + "peerDependencies": {} } diff --git a/stories/Getting-started.mdx b/stories/Getting-started.mdx index 6a478002..963c83d8 100644 --- a/stories/Getting-started.mdx +++ b/stories/Getting-started.mdx @@ -1,73 +1,52 @@ import {Canvas, Meta} from '@storybook/blocks' import * as FormBuilderStories from '../packages/react-formio/src/organisms/form/builder/FormBuilder.stories' +import {StoryBanner} from './home/StoryBanner.jsx' + + + - - -
- Ts.ED logo -
- -
-

Ts.ED - React Formio

- -
- Build & Release - semantic-release - code style: prettier - backers -
-
- -
- Website -   •   - Tutorial -   •   - Slack -   •   - Twitter -
- -
- -A [React](http://facebook.github.io/react/) library for rendering out forms based on the [Form.io](https://www.form.io) -platform. - -This module is based on the original [react-formio](https://github.com/formio/react-formio) and add extra features -listed above. -See our [storybook](https://formio.tsed.io/) to see all available components. + + +> This module is based on the original [react-formio](https://github.com/formio/react-formio) and add extra features +listed above. ## Features Many components are provided to build your own backoffice based on Formio.js API: -- [ActionsTable](/story/organisms-table-actions-actionstable--sandbox), -- [FormAccess](/story/organisms-form-access-formaccess--sandbox), -- [FormAction](/story/organisms-form-action-formaction--sandbox), -- [Form](/docs/documentation-form--docs), -- [FormBuilder](/docs/documentation-formbuilder--docs), -- [FormEdit](/docs/documentation-formedit--docs), -- [FormsTable](/docs/documentation-formstable--docs), -- [InputTags](/story/reactformio-inputtags--sandbox), -- [InputText](/story/reactformio-inputtext--sandbox), -- [Pagination](/story/reactformio-pagination--sandbox), -- [Select](/story/reactformio-select--sandbox), -- [SubmissionsTable](/docs/documentation-submissionstable--docs). -- [Table](/story/reactformio-table--sandbox), +- [ActionsTable](?path=/docs/organisms-table-actions-actionstable--docs), +- [FormAccess](?path=/docs/organisms-form-access-formaccess--docs), +- [FormAction](?path=/docs/organisms-form-action-formaction--docs), +- [Form](?path=/docs/organisms-form-form--docs), +- [FormBuilder](?path=/docs/organisms-form-builder-formbuilder--docs), +- [FormEdit](?path=/docs/organisms-form-builder-formedit--docs), +- [FormsTable](?path=/docs/organisms-table-forms-formstable--docs), +- [InputTags](?path=/docs/molecules-forms-inputtags--docs), +- [InputText](?path=/docs/molecules-forms-inputtext--docs), +- [Pagination](?path=/docs/molecules-pagination--docs), +- Select: [Choicejs](?path=/docs/molecules-forms-select-choicejs--docs), [HTML5](?path=/docs/molecules-forms-select-html5--docs) or [ReactSelect](?path=/docs/molecules-forms-select-react--docs), +- [SubmissionsTable](?path=/docs/organisms-table-submissions-submissionstable--docs). +- [Table](?path=/docs/molecules-table--docs), - Predefined Reducers for Actions, Action, Form, Forms, Submission, Submissions, etc..., - TypeScript support. - Tailwind support. +## Install + +`@tsed/react-formio` can be used on the server, or bundled for the client using an +npm-compatible packaging system such as [Vite](https://vite.dev/), [webpack](http://webpack.github.io/) or [Rollup](https://rollupjs.org/). + + +```sh +npm install @tsed/react-formio react-table --save +npm install formiojs choices.js --save // Install formiojs since it is a peerDependency +``` + + ## Migrate to v2 -If you use redux actions with v2, you have to install `@tsed/redux-formio-stores` and remplace your imports: +If you use redux actions with v2, you have to install `@tsed/redux-formio-stores` and replace your imports: ```diff - import { defaultFormioReducer, formsReducer } from "@tsed/react-formio"; @@ -87,22 +66,11 @@ Example: + import { Form } from "@tsed/react-formio/organisms/form/Form"; ``` -## Install - -`@tsed/react-formio` can be used on the server, or bundled for the client using an -npm-compatible packaging system such as [Browserify](http://browserify.org/) or -[webpack](http://webpack.github.io/). - -``` -npm install @tsed/react-formio react-table --save -npm install formiojs choices.js --save // Install formiojs since it is a peerDependency -``` - ## Usage ```tsx import React from "react"; -import { FormBuilder } from "@tsed/react-formio"; +import { FormBuilder } from "@tsed/react-formio/organisms/form/builder/FormBuilder"; function App() { return ( @@ -115,7 +83,41 @@ function App() { export default App; ``` - + + +## Registering react components + +You can register your own components to be used within the `@tsed/react-formio` library. This is useful if you want to +customize `FormEdit` or `Table` components. + +For example FormEdit component use the followings components: + +```ts +import "@tsed/react-formio/atoms/icon/Icon"; +import "@tsed/react-formio/molecules/button/Button"; +import "@tsed/react-formio/molecules/forms/input-text/InputText"; +import "@tsed/react-formio/molecules/forms/select/Select"; +import "@tsed/react-formio/molecules/forms/select/components/HtmlSelect"; +import "@tsed/react-formio/molecules/forms/input-tags/InputTags"; +import "@tsed/react-formio/organisms/form/builder/FormParameters"; +import "@tsed/react-formio/organisms/form/builder/FormBuilder"; +import "@tsed/react-formio/organisms/form/builder/FormEditCtas"; +``` + +You can replace for example replace the default React Button component provided by the library by your own Button: + +```tsx +import {registerComponent} from "@tsed/react-formio/registries/components"; +import type {ButtonProps} from "@tsed/react-formio/molecules/button/Button"; + +registerComponent("button", (props: ButtonProps) => { + return ; +}); +``` +A large part of the provided component from the library can be replaced by your own component. + +> Note: Override Button react component doesn't affect the button design and implementation used by formio.js. +> To styling the original button component formio, you have to redefine the `.btn` class in your CSS. ## Contributors @@ -140,7 +142,7 @@ website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)] The MIT License (MIT) -Copyright (c) 2016 - 2021 Romain Lenzotti +Copyright (c) 2016 - Today Romain Lenzotti Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the diff --git a/stories/home/StoryBanner.jsx b/stories/home/StoryBanner.jsx new file mode 100644 index 00000000..3dfd8ffe --- /dev/null +++ b/stories/home/StoryBanner.jsx @@ -0,0 +1,53 @@ +export function StoryBanner() { + return ( +
+ + +
@tsed/react-formio
+ +
+
+
A React library for rendering out forms based on the Form.io platform.
+
+
+ +
+ +
+ Ts.ED +   •   + Tutorial +   •   + Slack +   •   + Twitter +
+ +
+ + +
+ ); +} diff --git a/tools/typescript/package.json b/tools/typescript/package.json index 4fc3396b..1fc61fbc 100644 --- a/tools/typescript/package.json +++ b/tools/typescript/package.json @@ -7,5 +7,8 @@ "main": "index.js", "exports": { "./tsconfig.web.json": "./tsconfig.web.json" - } + }, + "dependencies": {}, + "devDependencies": {}, + "peerDependencies": {} } diff --git a/tools/vitest/package.json b/tools/vitest/package.json index bd3cf39a..27af42f5 100644 --- a/tools/vitest/package.json +++ b/tools/vitest/package.json @@ -14,5 +14,7 @@ }, "scripts": { "generate": "node index.js" - } + }, + "dependencies": {}, + "peerDependencies": {} }