mirror of
https://gitlab.nic.cz/turris/reforis/foris-js.git
synced 2025-04-19 08:06:40 +02:00
Fix code snippets syntax highlighting & some refactoring
This commit is contained in:
parent
d6fda7d732
commit
964b46b0b5
@ -4,7 +4,7 @@ using in foris forms.
|
|||||||
All additional `props` are passed to the `<input type="checkbox">` HTML
|
All additional `props` are passed to the `<input type="checkbox">` HTML
|
||||||
component.
|
component.
|
||||||
|
|
||||||
```js
|
```jsx
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
const [value, setValue] = useState(false);
|
const [value, setValue] = useState(false);
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ be used with `readOnly` and `disabled` parameters, please see an example.
|
|||||||
|
|
||||||
All additional `props` are passed to the `<input type="text">` HTML component.
|
All additional `props` are passed to the `<input type="text">` HTML component.
|
||||||
|
|
||||||
```js
|
```jsx
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
const [value, setValue] = useState("Text to appear in clipboard.");
|
const [value, setValue] = useState("Text to appear in clipboard.");
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ Adopted from `react-datetime/DateTime` datatime picker component. It uses
|
|||||||
It requires `ForisTranslations.locale` to be defined in order to use right
|
It requires `ForisTranslations.locale` to be defined in order to use right
|
||||||
locale.
|
locale.
|
||||||
|
|
||||||
```js
|
```jsx
|
||||||
ForisTranslations = { locale: "en" };
|
ForisTranslations = { locale: "en" };
|
||||||
|
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
|
@ -5,6 +5,6 @@ Firefox. See
|
|||||||
[related issue](https://bugzilla.mozilla.org/show_bug.cgi?id=858538) for more
|
[related issue](https://bugzilla.mozilla.org/show_bug.cgi?id=858538) for more
|
||||||
details.
|
details.
|
||||||
|
|
||||||
```js
|
```jsx
|
||||||
<DownloadButton href="example.zip">Download</DownloadButton>
|
<DownloadButton href="example.zip">Download</DownloadButton>
|
||||||
```
|
```
|
||||||
|
@ -4,10 +4,12 @@ checking. It's only meaningful using inside `<form>`.
|
|||||||
|
|
||||||
All additional `props` are passed to the `<input type="email">` HTML component.
|
All additional `props` are passed to the `<input type="email">` HTML component.
|
||||||
|
|
||||||
```js
|
```jsx
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import Button from "./Button";
|
import Button from "./Button";
|
||||||
|
|
||||||
const [email, setEmail] = useState("Wrong email");
|
const [email, setEmail] = useState("Wrong email");
|
||||||
|
|
||||||
<form onSubmit={(e) => e.preventDefault()}>
|
<form onSubmit={(e) => e.preventDefault()}>
|
||||||
<EmailInput
|
<EmailInput
|
||||||
value={email}
|
value={email}
|
||||||
|
@ -3,7 +3,7 @@ structure for using in foris forms.
|
|||||||
|
|
||||||
All additional `props` are passed to the `<input type="file">` HTML component.
|
All additional `props` are passed to the `<input type="file">` HTML component.
|
||||||
|
|
||||||
```js
|
```jsx
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
const [files, setFiles] = useState([]);
|
const [files, setFiles] = useState([]);
|
||||||
@ -23,7 +23,7 @@ const label = files.length === 1 ? files[0].name : "Choose file";
|
|||||||
|
|
||||||
### FileInput with multiple files
|
### FileInput with multiple files
|
||||||
|
|
||||||
```js
|
```jsx
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
const [files, setFiles] = useState([]);
|
const [files, setFiles] = useState([]);
|
||||||
|
@ -6,9 +6,9 @@ the page since modals are rendered in portals.
|
|||||||
Modals also have three optional sizes, which can be defined through the `size`
|
Modals also have three optional sizes, which can be defined through the `size`
|
||||||
prop:
|
prop:
|
||||||
|
|
||||||
- small - `sm`
|
- small - `sm`
|
||||||
- large - `lg`
|
- large - `lg`
|
||||||
- extra-large - `xl`
|
- extra-large - `xl`
|
||||||
|
|
||||||
For more details please visit Bootstrap
|
For more details please visit Bootstrap
|
||||||
<a href="https://getbootstrap.com/docs/4.5/components/modal/#optional-sizes" target="_blank">
|
<a href="https://getbootstrap.com/docs/4.5/components/modal/#optional-sizes" target="_blank">
|
||||||
@ -18,7 +18,7 @@ documentation</a>.
|
|||||||
<div id="modal-container" />
|
<div id="modal-container" />
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```jsx
|
||||||
import { ModalHeader, ModalBody, ModalFooter } from "./Modal";
|
import { ModalHeader, ModalBody, ModalFooter } from "./Modal";
|
||||||
|
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
@ -3,8 +3,9 @@ structure for using in foris forms.
|
|||||||
|
|
||||||
All additional `props` are passed to the `<input type="number">` HTML component.
|
All additional `props` are passed to the `<input type="number">` HTML component.
|
||||||
|
|
||||||
```js
|
```jsx
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
const [value, setValue] = useState(42);
|
const [value, setValue] = useState(42);
|
||||||
|
|
||||||
<NumberInput
|
<NumberInput
|
||||||
|
@ -4,7 +4,7 @@ for using in foris forms. Can be used with "eye" button, see example.
|
|||||||
All additional `props` are passed to the `<input type="password">` HTML
|
All additional `props` are passed to the `<input type="password">` HTML
|
||||||
component.
|
component.
|
||||||
|
|
||||||
```js
|
```jsx
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
const [value, setValue] = useState("secret");
|
const [value, setValue] = useState("secret");
|
||||||
|
|
||||||
|
@ -5,8 +5,9 @@ All additional `props` are passed to the `<input type="number">` HTML component.
|
|||||||
|
|
||||||
Unless `helpText` is set for one of the options they are displayed inline.
|
Unless `helpText` is set for one of the options they are displayed inline.
|
||||||
|
|
||||||
```js
|
```jsx
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
const CHOICES = [
|
const CHOICES = [
|
||||||
{ value: "one", label: "1" },
|
{ value: "one", label: "1" },
|
||||||
{ value: "two", label: "2" },
|
{ value: "two", label: "2" },
|
||||||
|
@ -3,8 +3,9 @@ and structure for using in foris forms.
|
|||||||
|
|
||||||
All additional `props` are passed to the `<select>` HTML component.
|
All additional `props` are passed to the `<select>` HTML component.
|
||||||
|
|
||||||
```js
|
```jsx
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
const CHOICES = {
|
const CHOICES = {
|
||||||
apple: "Apple",
|
apple: "Apple",
|
||||||
banana: "Banana",
|
banana: "Banana",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
Spiner Bootstrap component.
|
Spiner Bootstrap component.
|
||||||
|
|
||||||
```js
|
```jsx
|
||||||
<Spinner>You can put text inside or any component you wish.</Spinner>
|
<Spinner>You can put text inside or any component you wish.</Spinner>
|
||||||
```
|
```
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
Switch example:
|
Switch example:
|
||||||
|
|
||||||
```js
|
```jsx
|
||||||
<Switch label="Enable Switch" helpText="Toggle that switch!" />
|
<Switch label="Enable Switch" helpText="Toggle that switch!" />
|
||||||
```
|
```
|
||||||
|
@ -3,8 +3,9 @@ using in foris forms.
|
|||||||
|
|
||||||
All additional `props` are passed to the `<input type="text">` HTML component.
|
All additional `props` are passed to the `<input type="text">` HTML component.
|
||||||
|
|
||||||
```js
|
```jsx
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
const [value, setValue] = useState("Bla bla");
|
const [value, setValue] = useState("Bla bla");
|
||||||
|
|
||||||
<TextInput
|
<TextInput
|
||||||
|
@ -2,7 +2,7 @@ ThreeDotsMenu Bootstrap component is a dropdown menu that appears when the user
|
|||||||
clicks on three dots. It is used to display a list of actions that can be
|
clicks on three dots. It is used to display a list of actions that can be
|
||||||
performed on a particular item.
|
performed on a particular item.
|
||||||
|
|
||||||
```js
|
```jsx
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { faEdit, faTrash } from "@fortawesome/free-solid-svg-icons";
|
import { faEdit, faTrash } from "@fortawesome/free-solid-svg-icons";
|
||||||
|
@ -4,132 +4,14 @@ Rich Table is a table component based on
|
|||||||
[Tanstack React Table](https://tanstack.com/table/). It adds some features to
|
[Tanstack React Table](https://tanstack.com/table/). It adds some features to
|
||||||
the table component, such as:
|
the table component, such as:
|
||||||
|
|
||||||
- **Pagination**: The table can be paginated.
|
- **Pagination**: The table can be paginated.
|
||||||
- **Sorting**: The table can be sorted by columns.
|
- **Sorting**: The table can be sorted by columns.
|
||||||
- **Row Expansion**: The table rows can be expanded. (To be implemented)
|
- **Row Expansion**: The table rows can be expanded. (To be implemented)
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
```js
|
```jsx
|
||||||
import RichTable from "./RichTable";
|
import { columns, data } from "./mockData";
|
||||||
|
|
||||||
const columns = [
|
|
||||||
{
|
|
||||||
header: "Name",
|
|
||||||
accessorKey: "name",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
header: "Surname",
|
|
||||||
accessorKey: "surname",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
header: "Age",
|
|
||||||
accessorKey: "age",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
header: "Phone",
|
|
||||||
accessorKey: "phone",
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const data = [
|
|
||||||
{
|
|
||||||
name: "John",
|
|
||||||
surname: "Coltrane",
|
|
||||||
age: 30,
|
|
||||||
phone: "123456789",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Jane",
|
|
||||||
surname: "Doe",
|
|
||||||
age: 25,
|
|
||||||
phone: "987654321",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Alice",
|
|
||||||
surname: "Smith",
|
|
||||||
age: 35,
|
|
||||||
phone: "123456789",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Bob",
|
|
||||||
surname: "Smith",
|
|
||||||
age: 40,
|
|
||||||
phone: "987654321",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Charlie",
|
|
||||||
surname: "Brown",
|
|
||||||
age: 45,
|
|
||||||
phone: "123456789",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Daisy",
|
|
||||||
surname: "Brown",
|
|
||||||
age: 50,
|
|
||||||
phone: "987654321",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Eve",
|
|
||||||
surname: "Johnson",
|
|
||||||
age: 55,
|
|
||||||
phone: "123456789",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Frank",
|
|
||||||
surname: "Johnson",
|
|
||||||
age: 60,
|
|
||||||
phone: "987654321",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Grace",
|
|
||||||
surname: "Williams",
|
|
||||||
age: 65,
|
|
||||||
phone: "123456789",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Henry",
|
|
||||||
surname: "Williams",
|
|
||||||
age: 70,
|
|
||||||
phone: "987654321",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Ivy",
|
|
||||||
surname: "Brown",
|
|
||||||
age: 75,
|
|
||||||
phone: "123456789",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Jack",
|
|
||||||
surname: "Brown",
|
|
||||||
age: 80,
|
|
||||||
phone: "987654321",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Kelly",
|
|
||||||
surname: "Johnson",
|
|
||||||
age: 85,
|
|
||||||
phone: "123456789",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Liam",
|
|
||||||
surname: "Johnson",
|
|
||||||
age: 90,
|
|
||||||
phone: "987654321",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Mia",
|
|
||||||
surname: "Williams",
|
|
||||||
age: 95,
|
|
||||||
phone: "123456789",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Nathan",
|
|
||||||
surname: "Williams",
|
|
||||||
age: 100,
|
|
||||||
phone: "987654321",
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
<RichTable columns={columns} data={data} withPagination />;
|
<RichTable columns={columns} data={data} withPagination />;
|
||||||
```
|
```
|
||||||
|
119
src/common/RichTable/mockData.js
Normal file
119
src/common/RichTable/mockData.js
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
header: "Name",
|
||||||
|
accessorKey: "name",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "Surname",
|
||||||
|
accessorKey: "surname",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "Age",
|
||||||
|
accessorKey: "age",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "Phone",
|
||||||
|
accessorKey: "phone",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const data = [
|
||||||
|
{
|
||||||
|
name: "John",
|
||||||
|
surname: "Coltrane",
|
||||||
|
age: 30,
|
||||||
|
phone: "123456789",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Jane",
|
||||||
|
surname: "Doe",
|
||||||
|
age: 25,
|
||||||
|
phone: "987654321",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Alice",
|
||||||
|
surname: "Smith",
|
||||||
|
age: 35,
|
||||||
|
phone: "123456789",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Bob",
|
||||||
|
surname: "Smith",
|
||||||
|
age: 40,
|
||||||
|
phone: "987654321",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Charlie",
|
||||||
|
surname: "Brown",
|
||||||
|
age: 45,
|
||||||
|
phone: "123456789",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Daisy",
|
||||||
|
surname: "Brown",
|
||||||
|
age: 50,
|
||||||
|
phone: "987654321",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Eve",
|
||||||
|
surname: "Johnson",
|
||||||
|
age: 55,
|
||||||
|
phone: "123456789",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Frank",
|
||||||
|
surname: "Johnson",
|
||||||
|
age: 60,
|
||||||
|
phone: "987654321",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Grace",
|
||||||
|
surname: "Williams",
|
||||||
|
age: 65,
|
||||||
|
phone: "123456789",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Henry",
|
||||||
|
surname: "Williams",
|
||||||
|
age: 70,
|
||||||
|
phone: "987654321",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Ivy",
|
||||||
|
surname: "Brown",
|
||||||
|
age: 75,
|
||||||
|
phone: "123456789",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Jack",
|
||||||
|
surname: "Brown",
|
||||||
|
age: 80,
|
||||||
|
phone: "987654321",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Kelly",
|
||||||
|
surname: "Johnson",
|
||||||
|
age: 85,
|
||||||
|
phone: "123456789",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Liam",
|
||||||
|
surname: "Johnson",
|
||||||
|
age: 90,
|
||||||
|
phone: "987654321",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Mia",
|
||||||
|
surname: "Williams",
|
||||||
|
age: 95,
|
||||||
|
phone: "123456789",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Nathan",
|
||||||
|
surname: "Williams",
|
||||||
|
age: 100,
|
||||||
|
phone: "987654321",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export { columns, data };
|
@ -6,26 +6,30 @@ comfort API and allows to create typical Foris module forms easily.
|
|||||||
|
|
||||||
You can pass more forms as children.
|
You can pass more forms as children.
|
||||||
|
|
||||||
```js
|
```jsx static
|
||||||
<ForisForm
|
export default function WAN({ ws }) {
|
||||||
ws={ws}
|
return (
|
||||||
forisConfig={{
|
<ForisForm
|
||||||
endpoint: API_URLs.wan,
|
ws={ws}
|
||||||
wsModule: "wan",
|
forisConfig={{
|
||||||
}}
|
endpoint: API_URLs.wan,
|
||||||
prepData={prepData}
|
wsModule: "wan",
|
||||||
prepDataToSubmit={prepDataToSubmit}
|
}}
|
||||||
validator={validator}
|
prepData={prepData}
|
||||||
>
|
prepDataToSubmit={prepDataToSubmit}
|
||||||
<WANForm />
|
validator={validator}
|
||||||
<WAN6Form />
|
>
|
||||||
<MACForm />
|
<WANForm />
|
||||||
</ForisForm>
|
<WAN6Form />
|
||||||
|
<MACForm />
|
||||||
|
</ForisForm>
|
||||||
|
);
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Example of children forms `props` usage
|
### Example of children forms `props` usage
|
||||||
|
|
||||||
```js
|
```jsx static
|
||||||
export default function MACForm({
|
export default function MACForm({
|
||||||
formData,
|
formData,
|
||||||
formErrors,
|
formErrors,
|
||||||
@ -64,9 +68,9 @@ export default function MACForm({
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The <ForisForm/> passes subsequent `props` to the child components.
|
The `<ForisForm/>` passes subsequent `props` to the child components.
|
||||||
|
|
||||||
| Prop | Type | Description |
|
| Prop name | Type | Description |
|
||||||
| -------------- | ------ | -------------------------------------------------------------------------- |
|
| -------------- | ------ | -------------------------------------------------------------------------- |
|
||||||
| `formData` | object | Data returned from API. |
|
| `formData` | object | Data returned from API. |
|
||||||
| `formErrors` | object | Errors returned after validation via validator. |
|
| `formErrors` | object | Errors returned after validation via validator. |
|
||||||
|
Loading…
x
Reference in New Issue
Block a user