Skip to content

Commit

Permalink
docs: update storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Jun 3, 2023
1 parent f4b9f71 commit e1e4784
Show file tree
Hide file tree
Showing 50 changed files with 8,614 additions and 12,587 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
node-version: [18.x]

steps:
- uses: actions/checkout@v2
Expand All @@ -33,7 +33,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node-version: [16.x]
node-version: [18.x]

steps:
- uses: actions/checkout@v2
Expand All @@ -53,7 +53,7 @@ jobs:

strategy:
matrix:
node-version: [16.x]
node-version: [18.x]

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -84,7 +84,7 @@ jobs:

strategy:
matrix:
node-version: [14.x]
node-version: [18.x]

steps:
- uses: actions/checkout@v2
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/website.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Website

on:
workflow_dispatch:

jobs:
publish-pages:
runs-on: ubuntu-latest
needs: deploy-packages
if: ${{ github.event_name != 'pull_request' && (contains(github.ref, 'master') || contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc')) }}

strategy:
matrix:
node-version: [18.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Release packages
env:
CI: true
GH_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: yarn publish:storybook
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^12.1.5",
"@testing-library/user-event": "^14.2.1",
"@tsed/monorepo-utils": "1.17.8",
"@tsed/monorepo-utils": "^1.22.6",
"@types/ejs": "^3.0.5",
"@types/jest": "27.0.2",
"@types/lodash": "4.14.168",
Expand Down Expand Up @@ -106,7 +106,7 @@
"rimraf": "^3.0.2",
"semantic-release": "19.0.3",
"semantic-release-slack-bot": "3.5.3",
"typescript": "5.1.3",
"typescript": "4.9.5",
"webpack": "4.44.2"
},
"workspaces": {
Expand All @@ -118,11 +118,13 @@
"productionBranch": "master",
"developBranch": "master",
"npmAccess": "public",
"ghpages": {
"dir": "./packages/tailwind-formio/.out",
"url": "https://github.com/TypedProject/tsed-formio.git",
"branch": "gh-pages",
"cname": "formio.tsed.io"
}
"ghpages": [
{
"dir": "./packages/storybook/.out",
"url": "https://github.com/tsedio/tsed-formio.git",
"branch": "gh-pages",
"cname": "formio.tsed.io"
}
]
}
}
2 changes: 1 addition & 1 deletion packages/react-formio-container/coverage.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"statements": 2.29,
"branches": 0.44,
"functions": 3.17,
"functions": 2.56,
"lines": 2.43
}
8 changes: 4 additions & 4 deletions packages/react-formio/coverage.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"statements": 56.11,
"branches": 46.65,
"functions": 51.31,
"lines": 56.1
"statements": 56.02,
"branches": 46.56,
"functions": 48.33,
"lines": 56.04
}
5 changes: 3 additions & 2 deletions packages/react-formio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
},
"dependencies": {
"eventemitter2": "^6.4.3",
"prop-types": "^15.7.2"
"prop-types": "^15.7.2",
"classnames": "^2.3.1"
},
"peerDependencies": {
"@formio/choices.js": ">=9.0.1",
Expand All @@ -34,4 +35,4 @@
"@tsed/tailwind": "2.1.2",
"@tsed/tailwind-formio": "2.1.2"
}
}
}
212 changes: 17 additions & 195 deletions packages/react-formio/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,25 @@ 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.
See our [storybook](https://formio.tsed.io/?path=/docs/getting-started--docs) to see all available components.

## Features

- Many components are provided to build your own backoffice based on Formio.js API:
- [ActionsTable](https://formio.tsed.io/?path=/story/reactformio-actionstable--sandbox),
- [FormAccess](https://formio.tsed.io/?path=/story/reactformio-formaccess--sandbox),
- [FormAction](https://formio.tsed.io/?path=/story/reactformio-formaction--sandbox),
- [Form](https://formio.tsed.io/?path=/story/reactformio-form--sandbox),
- [FormBuilder](https://formio.tsed.io/?path=/story/reactformio-formbuilder--sandbox),
- [FormEdit](https://formio.tsed.io/?path=/story/reactformio-formedit--sandbox),
- [FormsTable](https://formio.tsed.io/?path=/story/reactformio-formstable--sandbox),
- [InputTags](https://formio.tsed.io/?path=/story/reactformio-inputtags--sandbox),
- [InputText](https://formio.tsed.io/?path=/story/reactformio-inputtext--sandbox),
- [Pagination](https://formio.tsed.io/?path=/story/reactformio-pagination--sandbox),
- [Select](https://formio.tsed.io/?path=/story/reactformio-select--sandbox),
- [SubmissionsTable](https://formio.tsed.io/?path=/story/reactformio-subssionsstable--sandbox).
- [Table](https://formio.tsed.io/?path=/story/reactformio-table--sandbox),
Many components are provided to build your own backoffice based on Formio.js API:

- [ActionsTable](https://formio.tsed.io/?path=story/reactformio-actionstable--sandbox),
- [FormAccess](https://formio.tsed.io/?path=story/reactformio-formaccess--sandbox),
- [FormAction](https://formio.tsed.io/?path=story/reactformio-formaction--sandbox),
- [Form](https://formio.tsed.io/?path=docs/documentation-form--docs),
- [FormBuilder](https://formio.tsed.io/?path=docs/documentation-formbuilder--docs),
- [FormEdit](https://formio.tsed.io/?path=docs/documentation-formedit--docs),
- [FormsTable](https://formio.tsed.io/?path=docs/documentation-formstable--docs),
- [InputTags](https://formio.tsed.io/?path=story/reactformio-inputtags--sandbox),
- [InputText](https://formio.tsed.io/?path=story/reactformio-inputtext--sandbox),
- [Pagination](https://formio.tsed.io/?path=story/reactformio-pagination--sandbox),
- [Select](https://formio.tsed.io/?path=/story/reactformio-select--sandbox),
- [SubmissionsTable](https://formio.tsed.io/?path=/docs/documentation-submissionstable--docs).
- [Table](https://formio.tsed.io/?path=/story/reactformio-table--sandbox),
- Predefined Reducers for Actions, Action, Form, Forms, Submission, Submissions, etc...,
- TypeScript support.
- Tailwind support.
Expand Down Expand Up @@ -90,186 +91,7 @@ function App() {
export default App;
```

## Components

### Form

The form component is the primary component of the system. It is what takes the form definition (json) and renders the
form into html. There are multiple ways to send the form to the Form component. The two main ways are to pass the `src`
prop with a url to the form definition, usually a form.io server. The other is to pass the `form` prop with the json
definition and optionally a `url` prop with the location of the form.

#### Props

| Name | Type | Default | Description |
| ------------ | ------ | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `src` | url | | The url of the form definition. This is commonly from a form.io server. When using src, the form will automatically submit the data to that url as well. |
| `url` | url | | The url of the form definition. The form will not be loaded from this url and the submission will not be saved here either. This is used for file upload, oauth and other components or actions that need to know where the server is. Use this in connection with `form` |
| `form` | object | | Instead of loading a form from the `src` url, you can preload the form definition and pass it in with the `form` prop. You should also set `url` if you are using any advanced components like file upload or oauth. |
| `submission` | object | | Submission data to fill the form. You can either load a previous submission or create a submission with some pre-filled data. If you do not provide a submissions the form will initialize an empty submission using default values from the form. |
| `options` | object | | an options object that can pass options to the formio.js Form that is rendered. You can set options such as `readOnly`, `noAlerts` or `hide`. There are [many options to be found in the formio.js library](https://github.com/formio/formio.js/wiki/Form-Renderer#options). |

#### Event Props

You can respond to various events in the form. Simply pass in a prop with a function for one of these events.

| Name | Parameters | Description |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| `onAsyncSubmit` | `submission`: object | When the submit button is pressed and the submission has started. Use this event if you submit data to external service. |
| `onSubmit` | `submission`: object | When the submit button is pressed and the submission has started. If `src` is not provided, this will be the final submit event. |
| `onSubmitDone` | `submission`: object | When the submission has successfully been made to the server. This will only fire if `src` is set. |
| `onChange` | `submission`: object, `submission.changed`: object of what changed, `submission.isValid`: boolean - if the submission passes validations. | A value in the submission has changed. |
| `onError` | `errors`: array or string or boolean | Called when an error occurs during submission such as a validation issue. |
| `onRender` | | Triggers when the form is finished rendering. |
| `onCustomEvent` | { `type`: string - event type, `component`: object - triggering component, `data`: object - data for component, `event`: string - raw event } | Event that is triggered from a button configured with "Event" type. |
| `onPrevPage` | { `page`: integer - new page number, `submission`: object - submission data } | Triggered for wizards when "Previous" button is pressed |
| `onNextPage` | { `page`: integer - new page number, `submission`: object - submission data } | Triggered for wizards when "Next" button is pressed |
| `onFormReady` | `formInstance`: Webform/Wizard - form class instance | Called when the form gets ready state |

#### Example

##### With src/url

Give `Form` a `src` property and render:

```tsx
import React from "react";
import ReactDOM from "react-dom";
import { Form } from "@tsed/react-formio";

ReactDOM.render(<Form src='https://example.form.io/example' onSubmit={console.log} />, document.getElementById("example"));
```

##### With form

Give `Form` a `src` property and render:

```tsx
import React from "react";
import ReactDOM from "react-dom";
import { Form } from "@tsed/react-formio";

interface MyFormData {
title: string;
}

const form = {
display: "form",
components: [
{
key: "title",
type: "textfield"
}
]
};

ReactDOM.render(
<Form<MyFormData>
form={form}
onAsyncSubmit={(submission) => {
return httpClient.post("/path/to/external/service", { data: submission }).catch((er) => {
err.errors = [
{
message: "My custom message about this field",
type: "custom",
path: ["title"],
level: "error"
}
];
throw error;
});
}}
/>,
document.getElementById("example")
);
```

> See [Form with error from server](https://formio.tsed.io/?path=/story/reactformio-form--trigger-error)
### FormBuilder

The [FormBuilder](https://formio.tsed.io/?path=/story/reactformio-formbuilder--sandbox)) class can be
used
to embed a form builder directly in your react application.
Please note that you'll need to include the CSS for the form builder from formio.js as well.

Please note that the [FormBuilder](<[FormsTable](https://formio.tsed.io/?path=/story/reactformio-formbuilder--sandbox)>)
component
does not load and save from/to a url. You must handle the form definition loading and saving yourself or use
the [FormEdit](https://formio.tsed.io/?path=/story/reactformio-formedit--sandbox) component.

#### Props

| Name | Type | Default | Description |
| --------- | ------ | ------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| `form` | object | | This is the form definition object. It should at least have a `display` property set to form, wizard or pdf. |
| `options` | object | | an options object that can pass options to the formio.js Form that is rendered. There are many options to be found in the formio.js library. |

#### Event Props

| Name | Parameters | Description |
| ------------------- | ------------------- | ---------------------------------------------------------------- |
| `onChange` | `schema`: object | Triggered any time the form definition changes |
| `onEditComponent` | `component`: object | Triggered when the component settings dialog is opened |
| `onSaveComponent` | `component`: object | Triggered when the component settings dialog is saved and closed |
| `onCancelComponent` | `component`: object | Triggered when the component settings dialog is cancelled |
| `onDeleteComponent` | `component`: object | Triggered when a component is removed from the form |
| `onUpdateComponent` | `component`: object | Triggered when a component is added or moved in the form |

#### Example

```tsx
import React from "react";
import ReactDOM from "react-dom";
import { FormBuilder } from "@tsed/react-formio";

ReactDOM.render(<FormBuilder form={{ display: "form" }} onChange={(schema) => console.log(schema)} />, document.getElementById("builder"));
```

### FormEdit

The [FormEdit](https://formio.tsed.io/?path=/story/reactformio-formedit--sandbox) component wraps
the [FormBuilder](<[FormsTable](https://formio.tsed.io/?path=/story/reactformio-formbuilder--sandbox)>) component and
adds the title, display, name and path fields at the top along with a save button.

#### Props

| Name | Type | Default | Description |
| --------------------------------------------------------------- | ------ | ------------------- | ----------- | --------------------------------------------------------------- |
| --------------------------------------------------------------- |
| `form` | object | {display: 'form' \ | 'wizard'} | The form definition of the exiting form that is to be modified. |

|
| `options` | object | {} | The options to be passed to FormBuilder |
| `saveText` | string | '' | The string that will be displayed in the save-button |

#### Event Props

| Name | Parameters | Description |
| ---------- | ---------- | -------------------------------------------------------------------------------------- |
| `onSubmit` | form | Called when the save button is pressed. Will pass the form definition to the callback. |

### FormsTable

The [FormsTable](https://formio.tsed.io/?path=/story/reactformio-formstable--sandbox) component can be used to render a
list of forms with buttons to edit, view, delete, etc on each row.

#### Props

| Name | Type | Default | Description |
| ------ | -------------- | ------- | ------------------------------------------- |
| `data` | array of forms | [] | A list of forms to be rendered in the grid. |

### SubmissionsTable

The submisison grid will render a list of submissions and allow clicking on one row to select it.

#### Props

| Name | Type | Default | Description |
| ------ | -------------------- | ------- | -------------------------------------------------------------------------------- |
| `data` | array of submissions | [] | A list of submissions to be rendered in the grid. |
| `form` | object | {} | The form definition for the submissions. This is used to render the submissions. |
See more on http://formio.tsed.io/?path=/docs/getting-started--docs

## Contributors

Expand Down
Loading

0 comments on commit e1e4784

Please sign in to comment.