1
0
mirror of https://gitlab.nic.cz/turris/reforis/foris-js.git synced 2025-04-25 08:46:39 +02:00

docs: Fix code snippets syntax highlighting & some refactoring

This commit is contained in:
Aleksandr Gumroian 2025-04-17 17:13:54 +02:00
parent d6fda7d732
commit 69b1b38202
No known key found for this signature in database
GPG Key ID: 9E77849C64F0A733
18 changed files with 171 additions and 160 deletions

View File

@ -4,7 +4,7 @@ using in foris forms.
All additional `props` are passed to the `<input type="checkbox">` HTML
component.
```js
```jsx
import { useState } from "react";
const [value, setValue] = useState(false);

View File

@ -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.
```js
```jsx
import React, { useState } from "react";
const [value, setValue] = useState("Text to appear in clipboard.");

View File

@ -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
locale.
```js
```jsx
ForisTranslations = { locale: "en" };
import { useState, useEffect } from "react";

View File

@ -5,6 +5,6 @@ Firefox. See
[related issue](https://bugzilla.mozilla.org/show_bug.cgi?id=858538) for more
details.
```js
```jsx
<DownloadButton href="example.zip">Download</DownloadButton>
```

View File

@ -4,10 +4,12 @@ checking. It's only meaningful using inside `<form>`.
All additional `props` are passed to the `<input type="email">` HTML component.
```js
```jsx
import { useState } from "react";
import Button from "./Button";
const [email, setEmail] = useState("Wrong email");
<form onSubmit={(e) => e.preventDefault()}>
<EmailInput
value={email}

View File

@ -3,7 +3,7 @@ structure for using in foris forms.
All additional `props` are passed to the `<input type="file">` HTML component.
```js
```jsx
import { useState } from "react";
const [files, setFiles] = useState([]);
@ -23,7 +23,7 @@ const label = files.length === 1 ? files[0].name : "Choose file";
### FileInput with multiple files
```js
```jsx
import { useState } from "react";
const [files, setFiles] = useState([]);

View File

@ -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`
prop:
- small - `sm`
- large - `lg`
- extra-large - `xl`
- small - `sm`
- large - `lg`
- extra-large - `xl`
For more details please visit Bootstrap
<a href="https://getbootstrap.com/docs/4.5/components/modal/#optional-sizes" target="_blank">
@ -18,7 +18,7 @@ documentation</a>.
<div id="modal-container" />
```
```js
```jsx
import { ModalHeader, ModalBody, ModalFooter } from "./Modal";
import { useState } from "react";

View File

@ -3,8 +3,9 @@ structure for using in foris forms.
All additional `props` are passed to the `<input type="number">` HTML component.
```js
```jsx
import { useState } from "react";
const [value, setValue] = useState(42);
<NumberInput

View File

@ -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
component.
```js
```jsx
import { useState } from "react";
const [value, setValue] = useState("secret");

View File

@ -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.
```js
```jsx
import { useState } from "react";
const CHOICES = [
{ value: "one", label: "1" },
{ value: "two", label: "2" },

View File

@ -3,8 +3,9 @@ and structure for using in foris forms.
All additional `props` are passed to the `<select>` HTML component.
```js
```jsx
import { useState } from "react";
const CHOICES = {
apple: "Apple",
banana: "Banana",

View File

@ -1,5 +1,5 @@
Spiner Bootstrap component.
```js
```jsx
<Spinner>You can put text inside or any component you wish.</Spinner>
```

View File

@ -1,5 +1,5 @@
Switch example:
```js
```jsx
<Switch label="Enable Switch" helpText="Toggle that switch!" />
```

View File

@ -3,8 +3,9 @@ using in foris forms.
All additional `props` are passed to the `<input type="text">` HTML component.
```js
```jsx
import { useState } from "react";
const [value, setValue] = useState("Bla bla");
<TextInput

View File

@ -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
performed on a particular item.
```js
```jsx
import { useState } from "react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faEdit, faTrash } from "@fortawesome/free-solid-svg-icons";

View File

@ -4,132 +4,14 @@ Rich Table is a table component based on
[Tanstack React Table](https://tanstack.com/table/). It adds some features to
the table component, such as:
- **Pagination**: The table can be paginated.
- **Sorting**: The table can be sorted by columns.
- **Row Expansion**: The table rows can be expanded. (To be implemented)
- **Pagination**: The table can be paginated.
- **Sorting**: The table can be sorted by columns.
- **Row Expansion**: The table rows can be expanded. (To be implemented)
### Example
```js
import RichTable from "./RichTable";
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",
},
];
```jsx
import { columns, data } from "./mockData";
<RichTable columns={columns} data={data} withPagination />;
```

View 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 };

View File

@ -6,26 +6,30 @@ comfort API and allows to create typical Foris module forms easily.
You can pass more forms as children.
```js
<ForisForm
ws={ws}
forisConfig={{
endpoint: API_URLs.wan,
wsModule: "wan",
}}
prepData={prepData}
prepDataToSubmit={prepDataToSubmit}
validator={validator}
>
<WANForm />
<WAN6Form />
<MACForm />
</ForisForm>
```jsx static
export default function WAN({ ws }) {
return (
<ForisForm
ws={ws}
forisConfig={{
endpoint: API_URLs.wan,
wsModule: "wan",
}}
prepData={prepData}
prepDataToSubmit={prepDataToSubmit}
validator={validator}
>
<WANForm />
<WAN6Form />
<MACForm />
</ForisForm>
);
}
```
### Example of children forms `props` usage
```js
```jsx static
export default function MACForm({
formData,
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. |
| `formErrors` | object | Errors returned after validation via validator. |