tabler-react-2 0.1.87 → 0.1.88
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modal/modal.js +0 -1
- package/dist/provider/tabler.js +4 -2
- package/dist/steps/index.js +3 -1
- package/docs/package.json +1 -1
- package/docs/src/components/ButtonedHookModal.jsx +2 -2
- package/docs/src/components/ConfirmModal.jsx +15 -0
- package/docs/src/components/Excerpt.jsx +2 -1
- package/docs/src/components/LoadableTabler.jsx +3 -0
- package/docs/src/config/sidebar.yml +6 -0
- package/docs/src/data/congressPeople.json +90 -0
- package/docs/src/docs/components/buttons.mdx +1 -1
- package/docs/src/docs/components/hook-confirm.mdx +106 -0
- package/docs/src/docs/components/hook-driven-modals.mdx +162 -1
- package/docs/src/docs/components/modals.mdx +2 -2
- package/docs/src/docs/components/steps.mdx +221 -0
- package/docs/src/docs/components/tables.mdx +454 -0
- package/docs/src/docs/components/typography.mdx +3 -5
- package/docs/src/docs/getting-started.mdx +12 -0
- package/docs/src/home/index.mdx +0 -16
- package/docs/static/democrat.png +0 -0
- package/docs/static/republican.png +0 -0
- package/package.json +1 -1
package/dist/modal/modal.js
CHANGED
|
@@ -120,7 +120,6 @@ var useModal = exports.useModal = function useModal(options) {
|
|
|
120
120
|
});
|
|
121
121
|
}, []);
|
|
122
122
|
var handleDecision = function handleDecision(decision) {
|
|
123
|
-
console.log(decision);
|
|
124
123
|
if (modalState.resolve) {
|
|
125
124
|
modalState.resolve(decision);
|
|
126
125
|
setModalState(function (prevState) {
|
package/dist/provider/tabler.js
CHANGED
|
@@ -29,7 +29,9 @@ var TablerProvider = exports.TablerProvider = function TablerProvider(_ref3) {
|
|
|
29
29
|
_ref3$colorScheme = _ref3.colorScheme,
|
|
30
30
|
colorScheme = _ref3$colorScheme === void 0 ? "light" : _ref3$colorScheme,
|
|
31
31
|
_ref3$theme = _ref3.theme,
|
|
32
|
-
themeColors = _ref3$theme === void 0 ? {} : _ref3$theme
|
|
32
|
+
themeColors = _ref3$theme === void 0 ? {} : _ref3$theme,
|
|
33
|
+
_ref3$fallbackAnchor = _ref3.fallbackAnchor,
|
|
34
|
+
fallbackAnchor = _ref3$fallbackAnchor === void 0 ? true : _ref3$fallbackAnchor;
|
|
33
35
|
(0, _react.useEffect)(function () {
|
|
34
36
|
var script1 = document.createElement("script");
|
|
35
37
|
script1.src = "https://cdn.jsdelivr.net/npm/@tabler/core@1.0.0-beta17/dist/js/tabler.min.js";
|
|
@@ -38,7 +40,7 @@ var TablerProvider = exports.TablerProvider = function TablerProvider(_ref3) {
|
|
|
38
40
|
link.rel = "stylesheet";
|
|
39
41
|
link.href = "https://cdn.jsdelivr.net/npm/@tabler/core@1.0.0-beta17/dist/css/tabler.min.css";
|
|
40
42
|
var script2 = document.createElement("script");
|
|
41
|
-
script2.textContent = "window.USE_FALLBACK_ANCHOR =
|
|
43
|
+
script2.textContent = "window.USE_FALLBACK_ANCHOR = ".concat(fallbackAnchor, ";");
|
|
42
44
|
document.head.appendChild(link);
|
|
43
45
|
document.head.appendChild(script1);
|
|
44
46
|
document.head.appendChild(script2);
|
package/dist/steps/index.js
CHANGED
|
@@ -10,13 +10,15 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default":
|
|
|
10
10
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
11
11
|
var Steps = exports.Steps = function Steps(_ref) {
|
|
12
12
|
var steps = _ref.steps,
|
|
13
|
-
|
|
13
|
+
passedColor = _ref.color,
|
|
14
|
+
passedVariant = _ref.variant,
|
|
14
15
|
_ref$numbered = _ref.numbered,
|
|
15
16
|
numbered = _ref$numbered === void 0 ? false : _ref$numbered,
|
|
16
17
|
_ref$hideText = _ref.hideText,
|
|
17
18
|
hideText = _ref$hideText === void 0 ? false : _ref$hideText,
|
|
18
19
|
_ref$vertical = _ref.vertical,
|
|
19
20
|
vertical = _ref$vertical === void 0 ? false : _ref$vertical;
|
|
21
|
+
var color = passedColor || passedVariant;
|
|
20
22
|
var stepClass = "steps ".concat(color ? "steps-".concat(color) : "", " ").concat(numbered ? "steps-counter" : "", " ").concat(vertical ? "steps-vertical" : "");
|
|
21
23
|
return /*#__PURE__*/_react["default"].createElement("ul", {
|
|
22
24
|
className: stepClass
|
package/docs/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { Button, useModal } from "tabler-react-2";
|
|
3
3
|
|
|
4
|
-
export const ButtonedHookModal = ({ hookProps, on = () => {} }) => {
|
|
4
|
+
export const ButtonedHookModal = ({ hookProps, buttonOn, on = () => {} }) => {
|
|
5
5
|
const { modal, ModalElement } = useModal(hookProps);
|
|
6
6
|
|
|
7
7
|
return (
|
|
8
8
|
<>
|
|
9
|
-
<Button onClick={async () => on(await modal())}>
|
|
9
|
+
<Button onClick={async () => on(await modal(buttonOn))}>
|
|
10
10
|
Open hook-driven modal
|
|
11
11
|
</Button>
|
|
12
12
|
{ModalElement}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Button, useConfirm } from "tabler-react-2";
|
|
3
|
+
|
|
4
|
+
export const ConfirmModal = ({ on = () => {}, hookProps, buttonOn }) => {
|
|
5
|
+
const { confirm, ConfirmModal } = useConfirm(hookProps);
|
|
6
|
+
|
|
7
|
+
return (
|
|
8
|
+
<>
|
|
9
|
+
<Button onClick={async () => on(await confirm(buttonOn))}>
|
|
10
|
+
Open confirm modal
|
|
11
|
+
</Button>
|
|
12
|
+
{ConfirmModal}
|
|
13
|
+
</>
|
|
14
|
+
);
|
|
15
|
+
};
|
|
@@ -9,7 +9,7 @@ const _Excerpt = styled.div`
|
|
|
9
9
|
background-size: 20px 20px;
|
|
10
10
|
background-position: -19px -19px;
|
|
11
11
|
border: 1.5px solid #e4e4e4;
|
|
12
|
-
border-radius:
|
|
12
|
+
border-radius: 5px;
|
|
13
13
|
min-height: 100px;
|
|
14
14
|
width: 100%;
|
|
15
15
|
padding: 16px;
|
|
@@ -18,6 +18,7 @@ const _Excerpt = styled.div`
|
|
|
18
18
|
align-items: center;
|
|
19
19
|
justify-content: center;
|
|
20
20
|
margin-bottom: 16px;
|
|
21
|
+
overflow: auto;
|
|
21
22
|
`;
|
|
22
23
|
|
|
23
24
|
export const Excerpt = ({ children, f }) => {
|
|
@@ -39,6 +39,9 @@ export const Modal = loadable(() =>
|
|
|
39
39
|
export const ButtonedHookModal = loadable(() =>
|
|
40
40
|
import("./ButtonedHookModal").then((mod) => mod.ButtonedHookModal)
|
|
41
41
|
);
|
|
42
|
+
export const ConfirmModal = loadable(() =>
|
|
43
|
+
import("./ConfirmModal").then((mod) => mod.ConfirmModal)
|
|
44
|
+
);
|
|
42
45
|
export const Ribbon = loadable(() =>
|
|
43
46
|
import("tabler-react-2").then((mod) => mod.Ribbon)
|
|
44
47
|
);
|
|
@@ -30,10 +30,16 @@
|
|
|
30
30
|
link: "/components/modals"
|
|
31
31
|
- label: "Hook-driven modals"
|
|
32
32
|
link: "/components/hook-driven-modals"
|
|
33
|
+
- label: "Hook-driven confirm"
|
|
34
|
+
link: "/components/hook-confirm"
|
|
33
35
|
- label: "Ribbons"
|
|
34
36
|
link: "/components/ribbons"
|
|
35
37
|
- label: "Spinners"
|
|
36
38
|
link: "/components/spinners"
|
|
39
|
+
- label: "Steps"
|
|
40
|
+
link: "/components/steps"
|
|
41
|
+
- label: "Tables"
|
|
42
|
+
link: "/components/tables"
|
|
37
43
|
- label: "Utilities"
|
|
38
44
|
items:
|
|
39
45
|
- label: "Colors"
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"name": "Ed Case",
|
|
4
|
+
"email": "ed.case@mail.house.gov",
|
|
5
|
+
"party": "Democrat",
|
|
6
|
+
"region": {
|
|
7
|
+
"state": "Hawaii",
|
|
8
|
+
"abbr": "HI",
|
|
9
|
+
"district": "1st"
|
|
10
|
+
},
|
|
11
|
+
"website": "https://case.house.gov"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"name": "Mike Carey",
|
|
15
|
+
"email": "mike.carey@mail.house.gov",
|
|
16
|
+
"party": "Republican",
|
|
17
|
+
"region": {
|
|
18
|
+
"state": "Ohio",
|
|
19
|
+
"abbr": "OH",
|
|
20
|
+
"district": "15th"
|
|
21
|
+
},
|
|
22
|
+
"website": "https://carey.house.gov"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"name": "Andrew Clyde",
|
|
26
|
+
"email": "andrew.clyde@mail.house.gov",
|
|
27
|
+
"party": "Republican",
|
|
28
|
+
"region": {
|
|
29
|
+
"state": "Georgia",
|
|
30
|
+
"abbr": "GA",
|
|
31
|
+
"district": "9th"
|
|
32
|
+
},
|
|
33
|
+
"website": "https://clyde.house.gov"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"name": "Angie Craig",
|
|
37
|
+
"email": "angie.craig@mail.house.gov",
|
|
38
|
+
"party": "Democrat",
|
|
39
|
+
"region": {
|
|
40
|
+
"state": "Minnesota",
|
|
41
|
+
"abbr": "MN",
|
|
42
|
+
"district": "2nd"
|
|
43
|
+
},
|
|
44
|
+
"website": "https://craig.house.gov"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"name": "Rick Crawford",
|
|
48
|
+
"email": "rick.crawford@mail.house.gov",
|
|
49
|
+
"party": "Republican",
|
|
50
|
+
"region": {
|
|
51
|
+
"state": "Arkansas",
|
|
52
|
+
"abbr": "AR",
|
|
53
|
+
"district": "1st"
|
|
54
|
+
},
|
|
55
|
+
"website": "https://crawford.house.gov"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"name": "Jared Golden",
|
|
59
|
+
"email": "jared.golden@mail.house.gov",
|
|
60
|
+
"party": "Democrat",
|
|
61
|
+
"region": {
|
|
62
|
+
"state": "Maine",
|
|
63
|
+
"abbr": "ME",
|
|
64
|
+
"district": "2nd"
|
|
65
|
+
},
|
|
66
|
+
"website": "https://golden.house.gov"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"name": "Dusty Johnson",
|
|
70
|
+
"email": "dusty.johnson@mail.house.gov",
|
|
71
|
+
"party": "Republican",
|
|
72
|
+
"region": {
|
|
73
|
+
"state": "South Dakota",
|
|
74
|
+
"abbr": "SD",
|
|
75
|
+
"district": "At-Large"
|
|
76
|
+
},
|
|
77
|
+
"website": "https://dustyjohnson.house.gov"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"name": "Susie Lee",
|
|
81
|
+
"email": "susie.lee@mail.house.gov",
|
|
82
|
+
"party": "Democrat",
|
|
83
|
+
"region": {
|
|
84
|
+
"state": "Nevada",
|
|
85
|
+
"abbr": "NV",
|
|
86
|
+
"district": "3rd"
|
|
87
|
+
},
|
|
88
|
+
"website": "https://susielee.house.gov"
|
|
89
|
+
}
|
|
90
|
+
]
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Hook-driven confirm
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
import { ConfirmModal } from "../../components/LoadableTabler.jsx";
|
|
6
|
+
import { Excerpt } from "../../components/Excerpt.jsx";
|
|
7
|
+
|
|
8
|
+
Hook-driven confirms are used to display content in a layer above the main content. They can be used to display forms, confirmations, or other types of content.
|
|
9
|
+
|
|
10
|
+
The hook will provide a `confirm` function that returns a promise. The promise will resolve with the value of the button clicked, or `false` if the modal is closed without a button click. It will also return a `<ConfirmModal />` component that you need to render in your application.
|
|
11
|
+
|
|
12
|
+
If the user clicks the cancel button, the promise will resolve with `false`, functionally the same as if the user clicked cancel.
|
|
13
|
+
|
|
14
|
+
## Signature
|
|
15
|
+
|
|
16
|
+
```jsx
|
|
17
|
+
import { useConfirm } from "tabler-react-2";
|
|
18
|
+
|
|
19
|
+
const { confirm, ConfirmModal } = useConfirm({
|
|
20
|
+
title: "Confirm Title",
|
|
21
|
+
text: "Text",
|
|
22
|
+
commitText: "Commit",
|
|
23
|
+
cancelText: "Cancel",
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
<ConfirmModal />
|
|
27
|
+
<Button onClick={() => confirm()}>Open hook-driven confirm</Button>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Props
|
|
31
|
+
|
|
32
|
+
| Prop | Required | Type | Default | Description |
|
|
33
|
+
| ------------ | -------- | -------------- | ------- | ------------------------------------- |
|
|
34
|
+
| `title` | No | String | | The title of the modal. |
|
|
35
|
+
| `text` | No | String \| node | | The text of the modal. |
|
|
36
|
+
| `commitText` | No | String | | The text of the commit button. |
|
|
37
|
+
| `cancelText` | No | String | | The text of the cancel button. |
|
|
38
|
+
| `modalProps` | No | Object | | Additional props to pass to the modal |
|
|
39
|
+
|
|
40
|
+
<blockquote>
|
|
41
|
+
<p>
|
|
42
|
+
|
|
43
|
+
**Tip**: If you need to use multiple hook driven confirms in a single scope or want to descriptively name the confirm variables you can re-assign the variable names in the deconstruction:
|
|
44
|
+
|
|
45
|
+
```jsx
|
|
46
|
+
const Home = () => {
|
|
47
|
+
const { confirm: signup, ConfirmModal: SignupPopup } = useConfirm({
|
|
48
|
+
title: "Confirm Title",
|
|
49
|
+
text: "Text",
|
|
50
|
+
commitText: "Commit",
|
|
51
|
+
cancelText: "Cancel",
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<>
|
|
56
|
+
<Button onClick={() => signup()}>Open hook-driven confirm</Button>
|
|
57
|
+
{SignupPopup}
|
|
58
|
+
</>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
</p>
|
|
64
|
+
</blockquote>
|
|
65
|
+
|
|
66
|
+
> **Note**: You don't need to use a `<Button />` component to open the confirm. The `confirm()` function is in scope and can be called directly or any other way you would typically call a function.
|
|
67
|
+
|
|
68
|
+
## Basic Usage
|
|
69
|
+
|
|
70
|
+
The `useConfirm` hook is used to display a confirm.
|
|
71
|
+
|
|
72
|
+
<Excerpt>
|
|
73
|
+
<ConfirmModal
|
|
74
|
+
on={(d) => window && window.alert(d)}
|
|
75
|
+
hookProps={{
|
|
76
|
+
title: "Confirm Title",
|
|
77
|
+
text: <kbd>A hook-driven confirm.</kbd>,
|
|
78
|
+
commitText: "Commit",
|
|
79
|
+
cancelText: "Cancel",
|
|
80
|
+
}}
|
|
81
|
+
/>
|
|
82
|
+
</Excerpt>
|
|
83
|
+
|
|
84
|
+
For the basic usage, this shows the entire component, not just the implementation like usual. This is because of the extra implementation steps.
|
|
85
|
+
|
|
86
|
+
```jsx title="./index.jsx"
|
|
87
|
+
import { useConfirm, Button } from "tabler-react-2";
|
|
88
|
+
|
|
89
|
+
const Home = () => {
|
|
90
|
+
const { confirm, ConfirmModal } = useConfirm({
|
|
91
|
+
title: "Confirm Title",
|
|
92
|
+
text: "Text",
|
|
93
|
+
commitText: "Commit",
|
|
94
|
+
cancelText: "Cancel",
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<>
|
|
99
|
+
<Button onClick={async () => alert(await confirm())}>
|
|
100
|
+
Open hook-driven confirm
|
|
101
|
+
</Button>
|
|
102
|
+
{ConfirmModal}
|
|
103
|
+
</>
|
|
104
|
+
);
|
|
105
|
+
};
|
|
106
|
+
```
|
|
@@ -7,6 +7,8 @@ import { Excerpt } from "../../components/Excerpt.jsx";
|
|
|
7
7
|
|
|
8
8
|
Hook-driven modals are used to display content in a layer above the main content. They can be used to display forms, confirmations, or other types of content.
|
|
9
9
|
|
|
10
|
+
The hook will provide a `modal` function that returns a promise. The promise will resolve with the value of the button clicked, or `false` if the modal is closed without a button click. It will also return a `<ModalElement />` component that you need to render in your application.
|
|
11
|
+
|
|
10
12
|
## Signature
|
|
11
13
|
|
|
12
14
|
```jsx
|
|
@@ -27,10 +29,37 @@ const { modal, ModalElement } = useModal({
|
|
|
27
29
|
| Prop | Required | Type | Default | Description |
|
|
28
30
|
| ------------ | -------- | ------------------------- | ------- | ------------------------------------- |
|
|
29
31
|
| `title` | No | String | | The title of the modal. |
|
|
30
|
-
| `text` | No | String
|
|
32
|
+
| `text` | No | String \| node | | The text of the modal. |
|
|
31
33
|
| `buttons` | No | [ButtonList](#buttonlist) | | An array of buttons to display |
|
|
32
34
|
| `modalProps` | No | Object | | Additional props to pass to the modal |
|
|
33
35
|
|
|
36
|
+
<blockquote>
|
|
37
|
+
<p>
|
|
38
|
+
|
|
39
|
+
**Tip**: If you need to use multiple hook driven modals in a single scope or want to descriptively name the modal variables you can re-assign the variable names in the deconstruction:
|
|
40
|
+
|
|
41
|
+
```jsx
|
|
42
|
+
const Home = () => {
|
|
43
|
+
const { modal: signup, ModalElement: SignupPopup } = useModal({
|
|
44
|
+
title: "Modal Title",
|
|
45
|
+
text: "Text",
|
|
46
|
+
buttons: [],
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<>
|
|
51
|
+
<Button onClick={() => signup()}>Open hook-driven modal</Button>
|
|
52
|
+
{SignupPopup}
|
|
53
|
+
</>
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
</p>
|
|
59
|
+
</blockquote>
|
|
60
|
+
|
|
61
|
+
> **Note**: You don't need to use a `<Button />` component to open the modal. The `modal()` function is in scope and can be called directly or any other way you would typically call a function.
|
|
62
|
+
|
|
34
63
|
## Basic Usage
|
|
35
64
|
|
|
36
65
|
The `useModal` hook is used to display a modal.
|
|
@@ -41,6 +70,118 @@ The `useModal` hook is used to display a modal.
|
|
|
41
70
|
hookProps={{
|
|
42
71
|
title: "Modal Title",
|
|
43
72
|
text: <kbd>A hook-driven modal.</kbd>,
|
|
73
|
+
}}
|
|
74
|
+
/>
|
|
75
|
+
</Excerpt>
|
|
76
|
+
|
|
77
|
+
For the basic usage, this shows the entire component, not just the implementation like usual. This is because of the extra implementation steps.
|
|
78
|
+
|
|
79
|
+
```jsx title="./index.jsx"
|
|
80
|
+
import { useModal, Button } from "tabler-react-2";
|
|
81
|
+
|
|
82
|
+
const Home = () => {
|
|
83
|
+
const { modal, ModalElement } = useModal({
|
|
84
|
+
title: "Modal Title",
|
|
85
|
+
text: "Text",
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<>
|
|
90
|
+
<Button onClick={() => modal()}>Open hook-driven modal</Button>
|
|
91
|
+
{ModalElement}
|
|
92
|
+
</>
|
|
93
|
+
);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export default Home;
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Buttons
|
|
100
|
+
|
|
101
|
+
You can pass [`ButtonList`](#buttonlist) to the `buttons` prop to display buttons in the modal footer. When the button is clicked, the modal will close and the promise returned by the `modal` function will resolve with the value of the clicked button.
|
|
102
|
+
|
|
103
|
+
<Excerpt f>
|
|
104
|
+
<ButtonedHookModal
|
|
105
|
+
on={(d) => alert(d)}
|
|
106
|
+
hookProps={{
|
|
107
|
+
title: "Modal Title",
|
|
108
|
+
text: <kbd>A hook-driven modal with buttons.</kbd>,
|
|
109
|
+
buttons: [
|
|
110
|
+
{
|
|
111
|
+
text: "Button 1",
|
|
112
|
+
variant: "danger",
|
|
113
|
+
value: "one",
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
text: "Button 2",
|
|
117
|
+
variant: "success",
|
|
118
|
+
value: "two",
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
}}
|
|
122
|
+
/>
|
|
123
|
+
</Excerpt>
|
|
124
|
+
|
|
125
|
+
```jsx
|
|
126
|
+
const Home = () => {
|
|
127
|
+
const {} = useModal({
|
|
128
|
+
title: "Modal Title",
|
|
129
|
+
text: "Text",
|
|
130
|
+
buttons: [
|
|
131
|
+
{
|
|
132
|
+
text: "Button 1",
|
|
133
|
+
variant: "danger",
|
|
134
|
+
value: "one",
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
text: "Button 2",
|
|
138
|
+
variant: "success",
|
|
139
|
+
value: "two",
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
return (
|
|
145
|
+
<>
|
|
146
|
+
<Button onClick={async () => alert(await modal())}>
|
|
147
|
+
Open hook-driven modal
|
|
148
|
+
</Button>
|
|
149
|
+
{ModalElement}
|
|
150
|
+
</>
|
|
151
|
+
);
|
|
152
|
+
};
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### ButtonList
|
|
156
|
+
|
|
157
|
+
The `buttons` prop of the `useModal` hook accepts an array of objects.
|
|
158
|
+
|
|
159
|
+
A `button` object has the following properties:
|
|
160
|
+
|
|
161
|
+
| Prop | Required | Type | Default | Description |
|
|
162
|
+
| --------- | -------- | ------ | ------- | ----------------------------------------------- |
|
|
163
|
+
| `text` | Yes | String | | The text to display in the button. |
|
|
164
|
+
| `variant` | No | String | | The color variant of the button. |
|
|
165
|
+
| `value` | No | Any | | The value to return when the button is clicked. |
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
type ButtonList = Array<{
|
|
169
|
+
text: string;
|
|
170
|
+
variant?: string;
|
|
171
|
+
value?: any;
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Overriding modal setup
|
|
176
|
+
|
|
177
|
+
You can pass an object to the `modal()` function to override the default modal setup:
|
|
178
|
+
|
|
179
|
+
<Excerpt f>
|
|
180
|
+
<ButtonedHookModal
|
|
181
|
+
on={(d) => alert(d)}
|
|
182
|
+
hookProps={{
|
|
183
|
+
title: "This not show up",
|
|
184
|
+
text: <kbd>A hook-driven modal with buttons.</kbd>,
|
|
44
185
|
buttons: [
|
|
45
186
|
{
|
|
46
187
|
text: "Button 1",
|
|
@@ -54,5 +195,25 @@ The `useModal` hook is used to display a modal.
|
|
|
54
195
|
},
|
|
55
196
|
],
|
|
56
197
|
}}
|
|
198
|
+
buttonOn={{ title: "This will though!" }}
|
|
57
199
|
/>
|
|
58
200
|
</Excerpt>
|
|
201
|
+
|
|
202
|
+
```jsx
|
|
203
|
+
const Home = () => {
|
|
204
|
+
const { modal, ModalElement } = useModal({
|
|
205
|
+
title: "This will not show up",
|
|
206
|
+
text: "Text",
|
|
207
|
+
buttons: [],
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
return (
|
|
211
|
+
<>
|
|
212
|
+
<Button onClick={() => modal({ title: "This will though!" })}>
|
|
213
|
+
Open hook-driven modal
|
|
214
|
+
</Button>
|
|
215
|
+
{ModalElement}
|
|
216
|
+
</>
|
|
217
|
+
);
|
|
218
|
+
};
|
|
219
|
+
```
|
|
@@ -113,13 +113,13 @@ You can pass [`ButtonList`](#buttonlist) to the `buttons` prop to display button
|
|
|
113
113
|
text: "Button 1",
|
|
114
114
|
variant: "danger",
|
|
115
115
|
attrs: { outline: true },
|
|
116
|
-
onClick: () => alert("Clicked button 1"),
|
|
116
|
+
onClick: () => window && window.alert("Clicked button 1"),
|
|
117
117
|
},
|
|
118
118
|
{
|
|
119
119
|
text: "Button 2",
|
|
120
120
|
variant: "success",
|
|
121
121
|
attrs: { outline: true },
|
|
122
|
-
onClick: () => alert("Clicked button 2"),
|
|
122
|
+
onClick: () => window && window.alert("Clicked button 2"),
|
|
123
123
|
},
|
|
124
124
|
]}
|
|
125
125
|
>
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Steps
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
import { Steps } from "../../components/LoadableTabler.jsx";
|
|
6
|
+
import { Excerpt } from "../../components/Excerpt.jsx";
|
|
7
|
+
|
|
8
|
+
Steps are used to display a series of steps to communicate a process or workflow.
|
|
9
|
+
|
|
10
|
+
## Signature
|
|
11
|
+
|
|
12
|
+
```jsx
|
|
13
|
+
import { Steps } from "tabler-react-2";
|
|
14
|
+
|
|
15
|
+
<Steps {...props} />;
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### Props
|
|
19
|
+
|
|
20
|
+
| Prop | Required | Type | Default | Description |
|
|
21
|
+
| ---------- | -------- | -------------------------- | ------- | ----------------------------------------- |
|
|
22
|
+
| `steps` | Yes | [`StepList`](#steplist) | | An array of step objects. |
|
|
23
|
+
| `variant` | No | [Color](/utilities/colors) | | The color of the steps. |
|
|
24
|
+
| `color` | No | [Color](/utilities/colors) | | The color of the steps. Alias of variant |
|
|
25
|
+
| `numbered` | No | Boolean | false | Whether to display the steps as numbered. |
|
|
26
|
+
| `hideText` | No | Boolean | false | Whether to hide the text of the steps. |
|
|
27
|
+
| `vertical` | No | Boolean | false | Whether to display the steps vertically. |
|
|
28
|
+
|
|
29
|
+
## Basic Usage
|
|
30
|
+
|
|
31
|
+
<Excerpt>
|
|
32
|
+
<div style={{ width: 350 }}>
|
|
33
|
+
<Steps
|
|
34
|
+
steps={[{ text: "Step 1" }, { text: "Step 2" }, { text: "Step 3" }]}
|
|
35
|
+
/>
|
|
36
|
+
</div>
|
|
37
|
+
</Excerpt>
|
|
38
|
+
|
|
39
|
+
{/* prettier-ignore */}
|
|
40
|
+
```jsx
|
|
41
|
+
<Steps steps={[
|
|
42
|
+
{ text: "Step 1" },
|
|
43
|
+
{ text: "Step 2" },
|
|
44
|
+
{ text: "Step 3" }
|
|
45
|
+
]} />
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### StepList
|
|
49
|
+
|
|
50
|
+
The `steps` prop is an array of step objects. Each step object can have the following properties:
|
|
51
|
+
|
|
52
|
+
| Prop | Required | Type | Description |
|
|
53
|
+
| --------- | -------- | -------- | ------------------------------------- |
|
|
54
|
+
| `text` | true | String | The text to display inside the step. |
|
|
55
|
+
| `tooltip` | false | String | The tooltip description for the step. |
|
|
56
|
+
| `active` | false | Bool | Whether the step is active. |
|
|
57
|
+
| `href` | false | String | The href of the step. |
|
|
58
|
+
| `onClick` | false | Function | The onClick function of the step. |
|
|
59
|
+
|
|
60
|
+
## Links & Clickable Steps
|
|
61
|
+
|
|
62
|
+
You can use the `href` or `onClick` props to make steps links or clickable.
|
|
63
|
+
|
|
64
|
+
<Excerpt>
|
|
65
|
+
<div style={{ width: 350 }}>
|
|
66
|
+
<Steps
|
|
67
|
+
steps={[
|
|
68
|
+
{ text: "Step 1", href: "#" },
|
|
69
|
+
{ text: "Step 2", href: "#" },
|
|
70
|
+
{
|
|
71
|
+
text: "Step 3",
|
|
72
|
+
onClick: () => alert("You clicked on step 3!"),
|
|
73
|
+
},
|
|
74
|
+
]}
|
|
75
|
+
/>
|
|
76
|
+
</div>
|
|
77
|
+
</Excerpt>
|
|
78
|
+
|
|
79
|
+
{/* prettier-ignore */}
|
|
80
|
+
```jsx
|
|
81
|
+
<Steps steps={[
|
|
82
|
+
{ text: "Step 1", href: "#" },
|
|
83
|
+
{ text: "Step 2", href: "#" },
|
|
84
|
+
{ text: "Step 3", onClick: () => alert("You clicked on step 3!") }
|
|
85
|
+
]} />
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Progress
|
|
89
|
+
|
|
90
|
+
You can set an `active` attribute on a step. Steps after the `active` step will be greyed out, and the `active` step will be bold.
|
|
91
|
+
|
|
92
|
+
<Excerpt>
|
|
93
|
+
<div style={{ width: 350 }}>
|
|
94
|
+
<Steps
|
|
95
|
+
steps={[
|
|
96
|
+
{ text: "Step 1" },
|
|
97
|
+
{ text: "Step 2", active: true },
|
|
98
|
+
{ text: "Step 3" },
|
|
99
|
+
]}
|
|
100
|
+
/>
|
|
101
|
+
</div>
|
|
102
|
+
</Excerpt>
|
|
103
|
+
|
|
104
|
+
```jsx
|
|
105
|
+
<Steps
|
|
106
|
+
steps={[
|
|
107
|
+
{ text: "Step 1" },
|
|
108
|
+
{ text: "Step 2", active: true },
|
|
109
|
+
{ text: "Step 3" },
|
|
110
|
+
]}
|
|
111
|
+
/>
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Colors & Variants
|
|
115
|
+
|
|
116
|
+
Steps can be colored using [Bold Colors](/utilities/color#bold-colors). Semantic, light, and brand colors do not work.
|
|
117
|
+
|
|
118
|
+
<Excerpt f>
|
|
119
|
+
{[
|
|
120
|
+
"blue",
|
|
121
|
+
"azure",
|
|
122
|
+
"indigo",
|
|
123
|
+
"purple",
|
|
124
|
+
"pink",
|
|
125
|
+
"red",
|
|
126
|
+
"orange",
|
|
127
|
+
"yellow",
|
|
128
|
+
"lime",
|
|
129
|
+
"green",
|
|
130
|
+
"teal",
|
|
131
|
+
"cyan",
|
|
132
|
+
].map((variant) => (
|
|
133
|
+
<div style={{ width: 350 }}>
|
|
134
|
+
<Steps
|
|
135
|
+
color={variant}
|
|
136
|
+
steps={[{ text: "Step 1" }, { text: "Step 2" }, { text: "Step 3" }]}
|
|
137
|
+
/>
|
|
138
|
+
</div>
|
|
139
|
+
))}
|
|
140
|
+
</Excerpt>
|
|
141
|
+
|
|
142
|
+
```jsx
|
|
143
|
+
<Steps
|
|
144
|
+
color="blue"
|
|
145
|
+
steps={[{ text: "Step 1" }, { text: "Step 2" }, { text: "Step 3" }]}
|
|
146
|
+
/>
|
|
147
|
+
<Steps
|
|
148
|
+
color="yellow"
|
|
149
|
+
steps={[{ text: "Step 1" }, { text: "Step 2" }, { text: "Step 3" }]}
|
|
150
|
+
/>
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Numbered Steps
|
|
154
|
+
|
|
155
|
+
You can include a number in the circle on the timeline of the steps by passing the `numbered` prop
|
|
156
|
+
|
|
157
|
+
<Excerpt>
|
|
158
|
+
<div style={{ width: 350 }}>
|
|
159
|
+
<Steps
|
|
160
|
+
numbered
|
|
161
|
+
steps={[{ text: "Step 1" }, { text: "Step 2" }, { text: "Step 3" }]}
|
|
162
|
+
/>
|
|
163
|
+
</div>
|
|
164
|
+
</Excerpt>
|
|
165
|
+
|
|
166
|
+
```jsx highlight={2}
|
|
167
|
+
<Steps
|
|
168
|
+
numbered
|
|
169
|
+
steps={[{ text: "Step 1" }, { text: "Step 2" }, { text: "Step 3" }]}
|
|
170
|
+
/>
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Vertical Steps
|
|
174
|
+
|
|
175
|
+
You can change the direction.
|
|
176
|
+
|
|
177
|
+
<Excerpt>
|
|
178
|
+
<div style={{ width: 350 }}>
|
|
179
|
+
<Steps
|
|
180
|
+
vertical
|
|
181
|
+
steps={[{ text: "Step 1" }, { text: "Step 2" }, { text: "Step 3" }]}
|
|
182
|
+
/>
|
|
183
|
+
</div>
|
|
184
|
+
</Excerpt>
|
|
185
|
+
|
|
186
|
+
```jsx highlight={2}
|
|
187
|
+
<Steps
|
|
188
|
+
vertical
|
|
189
|
+
steps={[{ text: "Step 1" }, { text: "Step 2" }, { text: "Step 3" }]}
|
|
190
|
+
/>
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Hide Text
|
|
194
|
+
|
|
195
|
+
You can hide the text on each step with the `hideText` attribute.
|
|
196
|
+
|
|
197
|
+
<Excerpt>
|
|
198
|
+
<div style={{ width: 350 }}>
|
|
199
|
+
<Steps
|
|
200
|
+
hideText
|
|
201
|
+
steps={[{ text: "Step 1" }, { text: "Step 2" }, { text: "Step 3" }]}
|
|
202
|
+
/>
|
|
203
|
+
<Steps
|
|
204
|
+
hideText
|
|
205
|
+
numbered
|
|
206
|
+
steps={[{ text: "Step 1" }, { text: "Step 2" }, { text: "Step 3" }]}
|
|
207
|
+
/>
|
|
208
|
+
</div>
|
|
209
|
+
</Excerpt>
|
|
210
|
+
|
|
211
|
+
```jsx highlight={2,6}
|
|
212
|
+
<Steps
|
|
213
|
+
hideText
|
|
214
|
+
steps={[{ text: "Step 1" }, { text: "Step 2" }, { text: "Step 3" }]}
|
|
215
|
+
/>
|
|
216
|
+
<Steps
|
|
217
|
+
hideText
|
|
218
|
+
numbered
|
|
219
|
+
steps={[{ text: "Step 1" }, { text: "Step 2" }, { text: "Step 3" }]}
|
|
220
|
+
/>
|
|
221
|
+
```
|
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Tables
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
import { Table } from "../../components/LoadableTabler.jsx";
|
|
6
|
+
import { Excerpt } from "../../components/Excerpt.jsx";
|
|
7
|
+
import { IconMail } from "@tabler/icons-react";
|
|
8
|
+
import congressPeople from "../../data/congressPeople.json";
|
|
9
|
+
|
|
10
|
+
Tables are used to display tabular data. They can be used to display data in a table, list, or any other tabular data.
|
|
11
|
+
|
|
12
|
+
## Signature
|
|
13
|
+
|
|
14
|
+
```jsx
|
|
15
|
+
import { Table } from "tabler-react-2";
|
|
16
|
+
|
|
17
|
+
<Table {...props} />;
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Props
|
|
21
|
+
|
|
22
|
+
| Prop | Required | Type | Default | Description |
|
|
23
|
+
| --------- | -------- | ------------------- | ------- | --------------------------- |
|
|
24
|
+
| `columns` | Yes | [`Column`](#column) | | An array of column objects. |
|
|
25
|
+
| `data` | Yes | Array | | An array of data objects. |
|
|
26
|
+
|
|
27
|
+
<blockquote>
|
|
28
|
+
<p>
|
|
29
|
+
|
|
30
|
+
<details>
|
|
31
|
+
<summary>For all of the tables on this page, we will use this list of congress people. (click to expand)</summary>
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
[
|
|
35
|
+
{
|
|
36
|
+
"name": "Ed Case",
|
|
37
|
+
"email": "ed.case@mail.house.gov",
|
|
38
|
+
"party": "Democrat",
|
|
39
|
+
"region": {
|
|
40
|
+
"state": "Hawaii",
|
|
41
|
+
"abbr": "HI",
|
|
42
|
+
"district": "1st"
|
|
43
|
+
},
|
|
44
|
+
"website": "https://case.house.gov"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"name": "Mike Carey",
|
|
48
|
+
"email": "mike.carey@mail.house.gov",
|
|
49
|
+
"party": "Republican",
|
|
50
|
+
"region": {
|
|
51
|
+
"state": "Ohio",
|
|
52
|
+
"abbr": "OH",
|
|
53
|
+
"district": "15th"
|
|
54
|
+
},
|
|
55
|
+
"website": "https://carey.house.gov"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"name": "Andrew Clyde",
|
|
59
|
+
"email": "andrew.clyde@mail.house.gov",
|
|
60
|
+
"party": "Republican",
|
|
61
|
+
"region": {
|
|
62
|
+
"state": "Georgia",
|
|
63
|
+
"abbr": "GA",
|
|
64
|
+
"district": "9th"
|
|
65
|
+
},
|
|
66
|
+
"website": "https://clyde.house.gov"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"name": "Angie Craig",
|
|
70
|
+
"email": "angie.craig@mail.house.gov",
|
|
71
|
+
"party": "Democrat",
|
|
72
|
+
"region": {
|
|
73
|
+
"state": "Minnesota",
|
|
74
|
+
"abbr": "MN",
|
|
75
|
+
"district": "2nd"
|
|
76
|
+
},
|
|
77
|
+
"website": "https://craig.house.gov"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"name": "Rick Crawford",
|
|
81
|
+
"email": "rick.crawford@mail.house.gov",
|
|
82
|
+
"party": "Republican",
|
|
83
|
+
"region": {
|
|
84
|
+
"state": "Arkansas",
|
|
85
|
+
"abbr": "AR",
|
|
86
|
+
"district": "1st"
|
|
87
|
+
},
|
|
88
|
+
"website": "https://crawford.house.gov"
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"name": "Jared Golden",
|
|
92
|
+
"email": "jared.golden@mail.house.gov",
|
|
93
|
+
"party": "Democrat",
|
|
94
|
+
"region": {
|
|
95
|
+
"state": "Maine",
|
|
96
|
+
"abbr": "ME",
|
|
97
|
+
"district": "2nd"
|
|
98
|
+
},
|
|
99
|
+
"website": "https://golden.house.gov"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"name": "Dusty Johnson",
|
|
103
|
+
"email": "dusty.johnson@mail.house.gov",
|
|
104
|
+
"party": "Republican",
|
|
105
|
+
"region": {
|
|
106
|
+
"state": "South Dakota",
|
|
107
|
+
"abbr": "SD",
|
|
108
|
+
"district": "At-Large"
|
|
109
|
+
},
|
|
110
|
+
"website": "https://dustyjohnson.house.gov"
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"name": "Susie Lee",
|
|
114
|
+
"email": "susie.lee@mail.house.gov",
|
|
115
|
+
"party": "Democrat",
|
|
116
|
+
"region": {
|
|
117
|
+
"state": "Nevada",
|
|
118
|
+
"abbr": "NV",
|
|
119
|
+
"district": "3rd"
|
|
120
|
+
},
|
|
121
|
+
"website": "https://susielee.house.gov"
|
|
122
|
+
}
|
|
123
|
+
]
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
</details>
|
|
127
|
+
|
|
128
|
+
</p>
|
|
129
|
+
</blockquote>
|
|
130
|
+
|
|
131
|
+
## Basic Usage
|
|
132
|
+
|
|
133
|
+
The `Table` component is used to display tabular data. It takes an array of objects as a prop called `columns`. Each object in the array represents a column in the table. The object should have a `label` property that is the text to display in the column header, and a `accessor` property that is the key of the object to use for the data in that column.
|
|
134
|
+
|
|
135
|
+
The `Table` component also takes a `data` prop that is an array of objects. Each object in the array represents a row in the table. The object should have a key for each column in the `columns` array.
|
|
136
|
+
|
|
137
|
+
<Excerpt>
|
|
138
|
+
<Table
|
|
139
|
+
columns={[
|
|
140
|
+
{ label: "Name", accessor: "name", sortable: true },
|
|
141
|
+
{
|
|
142
|
+
label: "Party",
|
|
143
|
+
accessor: "party",
|
|
144
|
+
render: (party) => (<><img src={`/${party}.png`} style={{width: 25}} /> {party}</>)
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
label: "State",
|
|
148
|
+
accessor: "region.state"
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
label: "District",
|
|
152
|
+
accessor: "region.district",
|
|
153
|
+
render: (district, row) => (
|
|
154
|
+
<>
|
|
155
|
+
<span className="text-secondary">{ row.region.abbr }</span> {district}
|
|
156
|
+
</>
|
|
157
|
+
),
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
label: "Email",
|
|
161
|
+
accessor: "email",
|
|
162
|
+
className: "text-secondary",
|
|
163
|
+
render: (email) => (
|
|
164
|
+
<a href={`mailto:${email}`} className="text-reset">
|
|
165
|
+
<IconMail strokeWidth={1.5} />
|
|
166
|
+
</a>
|
|
167
|
+
),
|
|
168
|
+
},
|
|
169
|
+
]}
|
|
170
|
+
data={congressPeople}
|
|
171
|
+
/>
|
|
172
|
+
|
|
173
|
+
</Excerpt>
|
|
174
|
+
|
|
175
|
+
```jsx
|
|
176
|
+
import congressPeople from "./congressPeople.json";
|
|
177
|
+
|
|
178
|
+
<Table
|
|
179
|
+
columns={[
|
|
180
|
+
{ label: "Name", accessor: "name", sortable: true },
|
|
181
|
+
{
|
|
182
|
+
label: "Party",
|
|
183
|
+
accessor: "party",
|
|
184
|
+
render: (party) => (
|
|
185
|
+
<>
|
|
186
|
+
<img src={`/${party}.png`} style={{ width: 25 }} /> {party}
|
|
187
|
+
</>
|
|
188
|
+
),
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
label: "State",
|
|
192
|
+
accessor: "region.state",
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
label: "District",
|
|
196
|
+
accessor: "region.district",
|
|
197
|
+
render: (district, row) => (
|
|
198
|
+
<>
|
|
199
|
+
<span className="text-secondary">{row.region.abbr}</span> {district}
|
|
200
|
+
</>
|
|
201
|
+
),
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
label: "Email",
|
|
205
|
+
accessor: "email",
|
|
206
|
+
className: "text-secondary",
|
|
207
|
+
render: (email) => (
|
|
208
|
+
<a href={`mailto:${email}`} className="text-reset">
|
|
209
|
+
<IconMail strokeWidth={1.5} />
|
|
210
|
+
</a>
|
|
211
|
+
),
|
|
212
|
+
},
|
|
213
|
+
]}
|
|
214
|
+
data={congressPeople}
|
|
215
|
+
/>;
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Constructing the `columns` array
|
|
219
|
+
|
|
220
|
+
The `columns` prop is an array of objects. Each object represents a column in the table. It has the following properties:
|
|
221
|
+
|
|
222
|
+
| Prop | Required | Type | Default | Description |
|
|
223
|
+
| ----------- | -------- | -------- | ------- | --------------------------------------------------------- |
|
|
224
|
+
| `label` | Yes | String | | The text to display in the column header. |
|
|
225
|
+
| `accessor` | Yes | String | | The key of the object to use for the data in that column. |
|
|
226
|
+
| `className` | No | String | | Additional CSS classes to apply to the column. |
|
|
227
|
+
| `render` | No | Function | | Custom render function for the cell content. |
|
|
228
|
+
| `sortable` | No | Boolean | false | Whether the column is sortable. |
|
|
229
|
+
| `sortFn` | No | Function | | Custom sorting function. |
|
|
230
|
+
|
|
231
|
+
### accessor
|
|
232
|
+
|
|
233
|
+
The `accessor` prop is the key of the object to use for the data in that column. It is a string that corresponds to the key of the object in the `data` array. It supports nested keys using dot notation.
|
|
234
|
+
|
|
235
|
+
Use the `accessor` prop to render simple text in your table. If you need any customization, use the `render` prop as well as `accessor`.
|
|
236
|
+
|
|
237
|
+
Setting the `accessor` prop to the string 'name' will return the values
|
|
238
|
+
|
|
239
|
+
<Excerpt>
|
|
240
|
+
<Table
|
|
241
|
+
columns={[{ label: "Name", accessor: "name" }]}
|
|
242
|
+
data={congressPeople.slice(0, 4)}
|
|
243
|
+
/>
|
|
244
|
+
</Excerpt>
|
|
245
|
+
|
|
246
|
+
```jsx
|
|
247
|
+
<Table columns={[{ label: "Name", accessor: "name" }]} data={congressPeople} />
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
You can access the nested keys of (in this case) the `region` object by using dot notation. For example, setting the `accessor` prop to `region.district` will return the values
|
|
251
|
+
|
|
252
|
+
<Excerpt>
|
|
253
|
+
<Table
|
|
254
|
+
columns={[{ label: "District", accessor: "region.district" }]}
|
|
255
|
+
data={congressPeople.slice(0, 4)}
|
|
256
|
+
/>
|
|
257
|
+
</Excerpt>
|
|
258
|
+
|
|
259
|
+
```jsx
|
|
260
|
+
<Table
|
|
261
|
+
columns={[{ label: "District", accessor: "region.district" }]}
|
|
262
|
+
data={congressPeople}
|
|
263
|
+
/>
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
To access other keys in the object (combining multiple keys in a single cell), you cannot use the accessor. Still provide something to the `accessor` prop so there is not an error, but use the `render` prop to display the content.
|
|
267
|
+
|
|
268
|
+
### render
|
|
269
|
+
|
|
270
|
+
The `render` prop is an optional function that will be called with the value of the cell and the row object.
|
|
271
|
+
|
|
272
|
+
It has the following signature:
|
|
273
|
+
|
|
274
|
+
```ts
|
|
275
|
+
render(value: any, row: object): React.ReactNode;
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
Where value is the value provided by the `accessor` and `row` is the entire row.
|
|
279
|
+
|
|
280
|
+
So, to render the congress person's party with the symbol, (assuming [`/democrat.png`](/democrat.png) and [`/republican.png`](/republican.png) exist), you can use the `render` prop to display the party.
|
|
281
|
+
|
|
282
|
+
<Excerpt>
|
|
283
|
+
<Table
|
|
284
|
+
columns={[
|
|
285
|
+
{
|
|
286
|
+
label: "Person's Party",
|
|
287
|
+
accessor: "party",
|
|
288
|
+
render: (party) => (
|
|
289
|
+
<>
|
|
290
|
+
<img src={`/${party}.png`} style={{ width: 25 }} /> {party}
|
|
291
|
+
</>
|
|
292
|
+
),
|
|
293
|
+
},
|
|
294
|
+
]}
|
|
295
|
+
data={congressPeople.slice(0, 4)}
|
|
296
|
+
/>
|
|
297
|
+
</Excerpt>
|
|
298
|
+
|
|
299
|
+
```jsx
|
|
300
|
+
<Table
|
|
301
|
+
columns={[
|
|
302
|
+
{
|
|
303
|
+
label: "Person's Party",
|
|
304
|
+
accessor: "party",
|
|
305
|
+
render: (partyFromAccessor) => (
|
|
306
|
+
<>
|
|
307
|
+
<img src={`/${partyFromAccessor}.png`} style={{ width: 25 }} />
|
|
308
|
+
{partyFromAccessor}
|
|
309
|
+
</>
|
|
310
|
+
),
|
|
311
|
+
},
|
|
312
|
+
]}
|
|
313
|
+
data={congressPeople}
|
|
314
|
+
/>
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
To include other values from the row in the cell, you can use the second argument passed to the `render` function. In this case, we will leave the accessor the same, so the first argument will be either `"democrat"` or `"republican"`. The second argument is the entire row object that we will pull the `region.state` value from.
|
|
318
|
+
|
|
319
|
+
<Excerpt>
|
|
320
|
+
<Table
|
|
321
|
+
columns={[
|
|
322
|
+
{
|
|
323
|
+
label: "Person's Party",
|
|
324
|
+
accessor: "party",
|
|
325
|
+
render: (party, row) => (
|
|
326
|
+
<>
|
|
327
|
+
{party} ({row.region.state})
|
|
328
|
+
</>
|
|
329
|
+
),
|
|
330
|
+
},
|
|
331
|
+
]}
|
|
332
|
+
data={congressPeople.slice(0, 4)}
|
|
333
|
+
/>
|
|
334
|
+
</Excerpt>
|
|
335
|
+
|
|
336
|
+
```jsx
|
|
337
|
+
<Table
|
|
338
|
+
columns={[
|
|
339
|
+
{
|
|
340
|
+
label: "Person's Party",
|
|
341
|
+
accessor: "party",
|
|
342
|
+
render: (party, row) => (
|
|
343
|
+
<>
|
|
344
|
+
{party} ({row.region.state})
|
|
345
|
+
</>
|
|
346
|
+
),
|
|
347
|
+
},
|
|
348
|
+
]}
|
|
349
|
+
data={congressPeople}
|
|
350
|
+
/>
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
### sortable
|
|
354
|
+
|
|
355
|
+
The `sortable` prop is an optional boolean that determines whether the column is sortable. If it is set to `true`, the column will be sortable. The default value is `false`. It will sort based on the value of the column's accessor.
|
|
356
|
+
|
|
357
|
+
<Excerpt>
|
|
358
|
+
<Table
|
|
359
|
+
columns={[
|
|
360
|
+
{
|
|
361
|
+
label: "Name",
|
|
362
|
+
accessor: "name",
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
label: "Party",
|
|
366
|
+
accessor: "party",
|
|
367
|
+
render: (party) => (
|
|
368
|
+
<>
|
|
369
|
+
<img src={`/${party}.png`} style={{ width: 25 }} /> {party}
|
|
370
|
+
</>
|
|
371
|
+
),
|
|
372
|
+
sortable: true,
|
|
373
|
+
},
|
|
374
|
+
{
|
|
375
|
+
label: "State",
|
|
376
|
+
accessor: "region.state",
|
|
377
|
+
sortable: true,
|
|
378
|
+
},
|
|
379
|
+
]}
|
|
380
|
+
data={congressPeople.slice(0, 4)}
|
|
381
|
+
/>
|
|
382
|
+
</Excerpt>
|
|
383
|
+
|
|
384
|
+
```jsx highlight={11,16}
|
|
385
|
+
<Table
|
|
386
|
+
columns={[
|
|
387
|
+
{
|
|
388
|
+
label: "Name",
|
|
389
|
+
accessor: "name",
|
|
390
|
+
},
|
|
391
|
+
{
|
|
392
|
+
label: "Party",
|
|
393
|
+
accessor: "party",
|
|
394
|
+
render: ...,
|
|
395
|
+
sortable: true,
|
|
396
|
+
},
|
|
397
|
+
{
|
|
398
|
+
label: "State",
|
|
399
|
+
accessor: "region.state",
|
|
400
|
+
sortable: true,
|
|
401
|
+
},
|
|
402
|
+
]}
|
|
403
|
+
data={congressPeople}
|
|
404
|
+
/>
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
You can also pass a custom sorting function to the `sortFn` prop. The sorting function should take two arguments and return `-1`, `0`, or `1`. The first argument is the value of the first cell, and the second argument is the value of the second cell.
|
|
408
|
+
|
|
409
|
+
The default sorting function is
|
|
410
|
+
|
|
411
|
+
```js title="Default sorting function"
|
|
412
|
+
const defaultSortFn = (a, b) => {
|
|
413
|
+
if (a === b) return 0;
|
|
414
|
+
return a > b ? 1 : -1;
|
|
415
|
+
};
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
If, for some reason, you wanted to sort by the length of the name, you could do the following:
|
|
419
|
+
|
|
420
|
+
<Excerpt>
|
|
421
|
+
<Table
|
|
422
|
+
columns={[
|
|
423
|
+
{
|
|
424
|
+
label: "Name",
|
|
425
|
+
accessor: "name",
|
|
426
|
+
sortFn: (a, b) => {
|
|
427
|
+
if (a.length === b.length) return 0;
|
|
428
|
+
return a.length > b.length ? 1 : -1;
|
|
429
|
+
},
|
|
430
|
+
sortable: true,
|
|
431
|
+
},
|
|
432
|
+
]}
|
|
433
|
+
data={congressPeople.slice(0, 4)}
|
|
434
|
+
/>
|
|
435
|
+
</Excerpt>
|
|
436
|
+
|
|
437
|
+
```jsx
|
|
438
|
+
const customSortFn = (a, b) => {
|
|
439
|
+
if (a.length === b.length) return 0;
|
|
440
|
+
return a.length > b.length ? 1 : -1;
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
<Table
|
|
444
|
+
columns={[
|
|
445
|
+
{
|
|
446
|
+
label: "Name",
|
|
447
|
+
accessor: "name",
|
|
448
|
+
sortFn: customSortFn,
|
|
449
|
+
sortable: true,
|
|
450
|
+
},
|
|
451
|
+
]}
|
|
452
|
+
data={congressPeople}
|
|
453
|
+
/>;
|
|
454
|
+
```
|
|
@@ -101,12 +101,10 @@ import { Typography } from "tabler-react-2";
|
|
|
101
101
|
<blockquote>
|
|
102
102
|
<p>
|
|
103
103
|
|
|
104
|
-
It will default to a `Link` component from the `react-router-dom` library
|
|
104
|
+
It will default to an `a` tag, but you can make it use a `Link` component from the `react-router-dom` library by setting `fallbackAnchor` to `false` in your `TablerProvider` component.
|
|
105
105
|
|
|
106
|
-
```
|
|
107
|
-
<
|
|
108
|
-
window.USE_FALLBACK_ANCHOR = true;
|
|
109
|
-
</script>
|
|
106
|
+
```jsx
|
|
107
|
+
<TablerProvider fallbackAnchor={false}>...</TablerProvider>
|
|
110
108
|
```
|
|
111
109
|
|
|
112
110
|
</p>
|
|
@@ -32,3 +32,15 @@ function App() {
|
|
|
32
32
|
);
|
|
33
33
|
}
|
|
34
34
|
```
|
|
35
|
+
|
|
36
|
+
<blockquote>
|
|
37
|
+
<p>
|
|
38
|
+
|
|
39
|
+
**Note:** If you are using the `react-router-dom` library, you will need to set the `fallbackAnchor` prop to `false` in the `TablerProvider` component. This way, links will use the `Link` component from `react-router-dom` instead of the default anchor tag.
|
|
40
|
+
|
|
41
|
+
```jsx
|
|
42
|
+
<TablerProvider fallbackAnchor={false}>...</TablerProvider>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
</p>
|
|
46
|
+
</blockquote>
|
package/docs/src/home/index.mdx
CHANGED
|
@@ -13,19 +13,3 @@ npm install tabler-react-2 @tabler/icons-react
|
|
|
13
13
|
```bash
|
|
14
14
|
yarn add tabler-react-2 @tabler/icons-react
|
|
15
15
|
```
|
|
16
|
-
|
|
17
|
-
## Usage
|
|
18
|
-
|
|
19
|
-
To use Tabler React 2, you need to wrap your application with the `TablerProvider` component. This component provides the necessary CSS and JavaScript files for Tabler React 2.
|
|
20
|
-
|
|
21
|
-
```jsx
|
|
22
|
-
import { TablerProvider } from "tabler-react-2";
|
|
23
|
-
|
|
24
|
-
function App() {
|
|
25
|
-
return (
|
|
26
|
-
<TablerProvider>
|
|
27
|
-
<YourApp />
|
|
28
|
-
</TablerProvider>
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
```
|
|
Binary file
|
|
Binary file
|