tabler-react-2 0.1.86 → 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/provider/tabler.js +4 -2
- package/dist/steps/index.js +3 -1
- package/docs/gatsby-config.js +4 -4
- package/docs/package.json +2 -1
- package/docs/src/components/ButtonedHookModal.jsx +15 -0
- package/docs/src/components/ConfirmModal.jsx +15 -0
- package/docs/src/components/Excerpt.jsx +2 -1
- package/docs/src/components/LoadableTabler.jsx +6 -0
- package/docs/src/config/sidebar.yml +10 -0
- package/docs/src/data/congressPeople.json +90 -0
- package/docs/src/docs/components/buttons.mdx +1 -1
- package/docs/src/docs/components/dropdown-input.mdx +0 -13
- package/docs/src/docs/components/hook-confirm.mdx +106 -0
- package/docs/src/docs/components/hook-driven-modals.mdx +219 -0
- 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/docs/theme.mdx +151 -0
- package/docs/src/home/index.mdx +9 -17
- package/docs/static/democrat.png +0 -0
- package/docs/static/favicon.png +0 -0
- package/docs/static/republican.png +0 -0
- package/package.json +1 -1
- package/docs/src/docs/themes.mdx +0 -28
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/gatsby-config.js
CHANGED
|
@@ -19,7 +19,7 @@ module.exports = {
|
|
|
19
19
|
docsPath: `src/docs`,
|
|
20
20
|
homePath: `src/home`,
|
|
21
21
|
yamlFilesPath: `src/yamlFiles`,
|
|
22
|
-
repositoryUrl: `https://github.com/
|
|
22
|
+
repositoryUrl: `https://github.com/jackcrane/tabler-react-2`,
|
|
23
23
|
baseDir: `examples/gatsby-theme-docs`,
|
|
24
24
|
gatsbyRemarkPlugins: [],
|
|
25
25
|
},
|
|
@@ -27,9 +27,9 @@ module.exports = {
|
|
|
27
27
|
{
|
|
28
28
|
resolve: `gatsby-plugin-manifest`,
|
|
29
29
|
options: {
|
|
30
|
-
name: `
|
|
31
|
-
short_name: `
|
|
32
|
-
start_url:
|
|
30
|
+
name: `Tabler React 2 Docs`,
|
|
31
|
+
short_name: `Tabler React 2 Docs`,
|
|
32
|
+
start_url: `/getting-started`,
|
|
33
33
|
background_color: `#ffffff`,
|
|
34
34
|
display: `standalone`,
|
|
35
35
|
icon: `static/favicon.png`,
|
package/docs/package.json
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@loadable/component": "^5.16.4",
|
|
11
11
|
"@rocketseat/gatsby-theme-docs": "^4.0.0",
|
|
12
|
+
"@tabler/icons-react": "^3.30.0",
|
|
12
13
|
"ajv": "^8.17.1",
|
|
13
14
|
"gatsby": "^5.9.0",
|
|
14
15
|
"gatsby-plugin-canonical-urls": "^5.9.0",
|
|
@@ -21,7 +22,7 @@
|
|
|
21
22
|
"react": "^18.2.0",
|
|
22
23
|
"react-dom": "^18.2.0",
|
|
23
24
|
"styled-components": "^6.1.15",
|
|
24
|
-
"tabler-react-2": "0.1.
|
|
25
|
+
"tabler-react-2": "0.1.87"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {},
|
|
27
28
|
"keywords": [
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Button, useModal } from "tabler-react-2";
|
|
3
|
+
|
|
4
|
+
export const ButtonedHookModal = ({ hookProps, buttonOn, on = () => {} }) => {
|
|
5
|
+
const { modal, ModalElement } = useModal(hookProps);
|
|
6
|
+
|
|
7
|
+
return (
|
|
8
|
+
<>
|
|
9
|
+
<Button onClick={async () => on(await modal(buttonOn))}>
|
|
10
|
+
Open hook-driven modal
|
|
11
|
+
</Button>
|
|
12
|
+
{ModalElement}
|
|
13
|
+
</>
|
|
14
|
+
);
|
|
15
|
+
};
|
|
@@ -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 }) => {
|
|
@@ -36,6 +36,12 @@ export const Input = loadable(() =>
|
|
|
36
36
|
export const Modal = loadable(() =>
|
|
37
37
|
import("tabler-react-2").then((mod) => mod.Modal)
|
|
38
38
|
);
|
|
39
|
+
export const ButtonedHookModal = loadable(() =>
|
|
40
|
+
import("./ButtonedHookModal").then((mod) => mod.ButtonedHookModal)
|
|
41
|
+
);
|
|
42
|
+
export const ConfirmModal = loadable(() =>
|
|
43
|
+
import("./ConfirmModal").then((mod) => mod.ConfirmModal)
|
|
44
|
+
);
|
|
39
45
|
export const Ribbon = loadable(() =>
|
|
40
46
|
import("tabler-react-2").then((mod) => mod.Ribbon)
|
|
41
47
|
);
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
link: "/"
|
|
5
5
|
- label: "Getting started"
|
|
6
6
|
link: "/getting-started"
|
|
7
|
+
- label: "Theme"
|
|
8
|
+
link: "/theme"
|
|
7
9
|
- label: "Components"
|
|
8
10
|
items:
|
|
9
11
|
- label: "Typography"
|
|
@@ -26,10 +28,18 @@
|
|
|
26
28
|
link: "/components/dropdown-input"
|
|
27
29
|
- label: "Modals"
|
|
28
30
|
link: "/components/modals"
|
|
31
|
+
- label: "Hook-driven modals"
|
|
32
|
+
link: "/components/hook-driven-modals"
|
|
33
|
+
- label: "Hook-driven confirm"
|
|
34
|
+
link: "/components/hook-confirm"
|
|
29
35
|
- label: "Ribbons"
|
|
30
36
|
link: "/components/ribbons"
|
|
31
37
|
- label: "Spinners"
|
|
32
38
|
link: "/components/spinners"
|
|
39
|
+
- label: "Steps"
|
|
40
|
+
link: "/components/steps"
|
|
41
|
+
- label: "Tables"
|
|
42
|
+
link: "/components/tables"
|
|
33
43
|
- label: "Utilities"
|
|
34
44
|
items:
|
|
35
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
|
+
]
|
|
@@ -224,19 +224,6 @@ You can show a loading indicator by passing in `loading={true}`.
|
|
|
224
224
|
/>
|
|
225
225
|
```
|
|
226
226
|
|
|
227
|
-
## Custom content
|
|
228
|
-
|
|
229
|
-
<Excerpt>
|
|
230
|
-
<DropdownInput
|
|
231
|
-
prompt="Select a value"
|
|
232
|
-
items={[
|
|
233
|
-
{ id: 1, label: "Sam" },
|
|
234
|
-
{ id: 2, label: "Bob" },
|
|
235
|
-
{ id: 3, label: "John" },
|
|
236
|
-
]}
|
|
237
|
-
/>
|
|
238
|
-
</Excerpt>
|
|
239
|
-
|
|
240
227
|
## ItemList
|
|
241
228
|
|
|
242
229
|
The `items` prop of the `DropdownInput` component accepts an array of objects. It accepts 2 types of entries: an `item` and a `divider`.
|
|
@@ -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
|
+
```
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Hook-driven modals
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
import { ButtonedHookModal } from "../../components/LoadableTabler.jsx";
|
|
6
|
+
import { Excerpt } from "../../components/Excerpt.jsx";
|
|
7
|
+
|
|
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
|
+
|
|
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
|
+
|
|
12
|
+
## Signature
|
|
13
|
+
|
|
14
|
+
```jsx
|
|
15
|
+
import { useModal } from "tabler-react-2";
|
|
16
|
+
|
|
17
|
+
const { modal, ModalElement } = useModal({
|
|
18
|
+
title: "Modal Title",
|
|
19
|
+
text: "Text",
|
|
20
|
+
buttons: []
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
<ModalElement />
|
|
24
|
+
<Button onClick={() => modal()}>Open hook-driven modal</Button>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Props
|
|
28
|
+
|
|
29
|
+
| Prop | Required | Type | Default | Description |
|
|
30
|
+
| ------------ | -------- | ------------------------- | ------- | ------------------------------------- |
|
|
31
|
+
| `title` | No | String | | The title of the modal. |
|
|
32
|
+
| `text` | No | String \| node | | The text of the modal. |
|
|
33
|
+
| `buttons` | No | [ButtonList](#buttonlist) | | An array of buttons to display |
|
|
34
|
+
| `modalProps` | No | Object | | Additional props to pass to the modal |
|
|
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
|
+
|
|
63
|
+
## Basic Usage
|
|
64
|
+
|
|
65
|
+
The `useModal` hook is used to display a modal.
|
|
66
|
+
|
|
67
|
+
<Excerpt>
|
|
68
|
+
<ButtonedHookModal
|
|
69
|
+
on={console.log}
|
|
70
|
+
hookProps={{
|
|
71
|
+
title: "Modal Title",
|
|
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>,
|
|
185
|
+
buttons: [
|
|
186
|
+
{
|
|
187
|
+
text: "Button 1",
|
|
188
|
+
variant: "danger",
|
|
189
|
+
value: "one",
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
text: "Button 2",
|
|
193
|
+
variant: "success",
|
|
194
|
+
value: "two",
|
|
195
|
+
},
|
|
196
|
+
],
|
|
197
|
+
}}
|
|
198
|
+
buttonOn={{ title: "This will though!" }}
|
|
199
|
+
/>
|
|
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
|
>
|