tabler-react-2 0.1.93 → 0.1.95
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/input/enclosedselectgroup.js +40 -43
- package/dist/input/input.js +1 -1
- package/dist/segmentedControl/index.js +66 -0
- package/docs/package.json +1 -1
- package/docs/src/components/LoadableTabler.jsx +6 -0
- package/docs/src/config/sidebar.yml +8 -4
- package/docs/src/docs/components/input.mdx +430 -0
- package/docs/src/docs/components/select-group.mdx +137 -0
- package/package.json +1 -1
|
@@ -5,9 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.EnclosedSelectGroup = void 0;
|
|
8
|
-
var _react =
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
10
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
11
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
12
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
11
13
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
12
14
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
13
15
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
@@ -18,30 +20,23 @@ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread n
|
|
|
18
20
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
19
21
|
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
20
22
|
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
21
|
-
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
22
|
-
<label class="form-selectgroup-item flex-fill">
|
|
23
|
-
<input type="radio" name="form-payment" value="mastercard" class="form-selectgroup-input" checked />
|
|
24
|
-
<div class="form-selectgroup-label d-flex align-items-center p-3">
|
|
25
|
-
<div class="me-3">
|
|
26
|
-
<span class="form-selectgroup-check"></span>
|
|
27
|
-
</div>
|
|
28
|
-
<div>
|
|
29
|
-
ending in <strong>2807</strong>
|
|
30
|
-
</div>
|
|
31
|
-
</div>
|
|
32
|
-
</label>
|
|
33
|
-
|
|
34
|
-
*/
|
|
23
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
35
24
|
var EnclosedSelectGroup = exports.EnclosedSelectGroup = function EnclosedSelectGroup(_ref) {
|
|
36
25
|
var items = _ref.items,
|
|
37
26
|
value = _ref.value,
|
|
38
27
|
onChange = _ref.onChange,
|
|
28
|
+
_ref$multiple = _ref.multiple,
|
|
29
|
+
multiple = _ref$multiple === void 0 ? false : _ref$multiple,
|
|
39
30
|
_ref$direction = _ref.direction,
|
|
40
31
|
direction = _ref$direction === void 0 ? "row" : _ref$direction,
|
|
41
|
-
itemClassName = _ref.itemClassName,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
_ref$itemClassName = _ref.itemClassName,
|
|
33
|
+
itemClassName = _ref$itemClassName === void 0 ? "" : _ref$itemClassName,
|
|
34
|
+
_ref$style = _ref.style,
|
|
35
|
+
style = _ref$style === void 0 ? {} : _ref$style,
|
|
36
|
+
_ref$itemStyle = _ref.itemStyle,
|
|
37
|
+
itemStyle = _ref$itemStyle === void 0 ? {} : _ref$itemStyle;
|
|
38
|
+
// generate a unique name for each instance so radio groups don't collide
|
|
39
|
+
var groupName = (0, _react.useId)();
|
|
45
40
|
var handleChange = function handleChange(selectedItem) {
|
|
46
41
|
if (multiple) {
|
|
47
42
|
if (value.some(function (item) {
|
|
@@ -58,43 +53,40 @@ var EnclosedSelectGroup = exports.EnclosedSelectGroup = function EnclosedSelectG
|
|
|
58
53
|
}
|
|
59
54
|
};
|
|
60
55
|
var isChecked = function isChecked(item) {
|
|
61
|
-
|
|
62
|
-
return value
|
|
63
|
-
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
return (value === null || value === void 0 ? void 0 : value.value) === item.value;
|
|
56
|
+
return multiple ? value.some(function (val) {
|
|
57
|
+
return val.value === item.value;
|
|
58
|
+
}) : (value === null || value === void 0 ? void 0 : value.value) === item.value;
|
|
67
59
|
};
|
|
68
60
|
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
69
61
|
className: "form-selectgroup",
|
|
70
62
|
style: _objectSpread({
|
|
63
|
+
display: "flex",
|
|
71
64
|
flexDirection: direction
|
|
72
65
|
}, style)
|
|
73
66
|
}, items.map(function (item) {
|
|
74
67
|
return /*#__PURE__*/_react["default"].createElement("label", {
|
|
68
|
+
key: "".concat(groupName, "-").concat(item.value),
|
|
75
69
|
className: "form-selectgroup-item flex-fill ".concat(itemClassName),
|
|
76
|
-
key: item.value,
|
|
77
70
|
style: _objectSpread({
|
|
78
|
-
pointerEvents: item.disabled,
|
|
79
|
-
cursor: item.disabled ? "not-allowed" :
|
|
71
|
+
pointerEvents: item.disabled ? "none" : undefined,
|
|
72
|
+
cursor: item.disabled ? "not-allowed" : undefined
|
|
80
73
|
}, itemStyle)
|
|
81
74
|
}, /*#__PURE__*/_react["default"].createElement("input", {
|
|
82
|
-
type: "radio",
|
|
83
|
-
|
|
84
|
-
|
|
75
|
+
type: multiple ? "checkbox" : "radio",
|
|
76
|
+
name: groupName,
|
|
77
|
+
id: "".concat(groupName, "-").concat(item.value),
|
|
85
78
|
value: item.value,
|
|
86
79
|
checked: isChecked(item),
|
|
87
80
|
onChange: function onChange() {
|
|
88
|
-
return handleChange(
|
|
89
|
-
value: item.value
|
|
90
|
-
});
|
|
81
|
+
return handleChange(item);
|
|
91
82
|
},
|
|
92
|
-
disabled: item.disabled
|
|
83
|
+
disabled: item.disabled,
|
|
84
|
+
className: "form-selectgroup-input"
|
|
93
85
|
}), /*#__PURE__*/_react["default"].createElement("div", {
|
|
94
|
-
className: "form-selectgroup-label d-flex p-3 ".concat(
|
|
86
|
+
className: "form-selectgroup-label d-flex p-3 ".concat(item.disabled ? "bg-gray-400" : ""),
|
|
95
87
|
style: {
|
|
96
|
-
pointerEvents: item.disabled,
|
|
97
|
-
cursor: item.disabled ? "not-allowed" :
|
|
88
|
+
pointerEvents: item.disabled ? "none" : undefined,
|
|
89
|
+
cursor: item.disabled ? "not-allowed" : undefined
|
|
98
90
|
}
|
|
99
91
|
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
100
92
|
className: "me-3"
|
|
@@ -104,21 +96,26 @@ var EnclosedSelectGroup = exports.EnclosedSelectGroup = function EnclosedSelectG
|
|
|
104
96
|
style: {
|
|
105
97
|
textAlign: "left"
|
|
106
98
|
}
|
|
107
|
-
}, item.
|
|
99
|
+
}, item.label)));
|
|
108
100
|
}));
|
|
109
101
|
};
|
|
110
102
|
EnclosedSelectGroup.propTypes = {
|
|
111
103
|
items: _propTypes["default"].arrayOf(_propTypes["default"].shape({
|
|
112
104
|
value: _propTypes["default"].string.isRequired,
|
|
113
|
-
|
|
105
|
+
label: _propTypes["default"].node.isRequired,
|
|
106
|
+
disabled: _propTypes["default"].bool
|
|
114
107
|
})).isRequired,
|
|
115
108
|
value: _propTypes["default"].oneOfType([_propTypes["default"].shape({
|
|
116
109
|
value: _propTypes["default"].string.isRequired,
|
|
117
|
-
label: _propTypes["default"].
|
|
110
|
+
label: _propTypes["default"].any
|
|
118
111
|
}), _propTypes["default"].arrayOf(_propTypes["default"].shape({
|
|
119
112
|
value: _propTypes["default"].string.isRequired,
|
|
120
|
-
label: _propTypes["default"].
|
|
113
|
+
label: _propTypes["default"].any
|
|
121
114
|
}))]).isRequired,
|
|
122
115
|
onChange: _propTypes["default"].func.isRequired,
|
|
123
|
-
multiple: _propTypes["default"].bool
|
|
116
|
+
multiple: _propTypes["default"].bool,
|
|
117
|
+
direction: _propTypes["default"].oneOf(["row", "column"]),
|
|
118
|
+
itemClassName: _propTypes["default"].string,
|
|
119
|
+
style: _propTypes["default"].object,
|
|
120
|
+
itemStyle: _propTypes["default"].object
|
|
124
121
|
};
|
package/dist/input/input.js
CHANGED
|
@@ -100,7 +100,7 @@ var Input = exports.Input = function Input(_ref) {
|
|
|
100
100
|
}, renderInput()), /*#__PURE__*/_react["default"].createElement("div", {
|
|
101
101
|
className: "col-auto"
|
|
102
102
|
}, /*#__PURE__*/_react["default"].createElement("a", {
|
|
103
|
-
href: appendedLinkHref ? appendedLinkHref : "
|
|
103
|
+
href: appendedLinkHref ? appendedLinkHref : "javascript:void(0);",
|
|
104
104
|
onClick: appendedLinkOnClick,
|
|
105
105
|
className: "btn btn-icon",
|
|
106
106
|
"aria-label": "Button"
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SegmentedControl = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
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
|
+
var SegmentedControl = exports.SegmentedControl = function SegmentedControl(_ref) {
|
|
12
|
+
var size = _ref.size,
|
|
13
|
+
orientation = _ref.orientation,
|
|
14
|
+
value = _ref.value,
|
|
15
|
+
onChange = _ref.onChange,
|
|
16
|
+
items = _ref.items;
|
|
17
|
+
var navClasses = ["nav", orientation === "vertical" ? "nav-segmented-vertical" : "nav-segmented", size && "nav-".concat(size)].filter(Boolean).join(" ");
|
|
18
|
+
return /*#__PURE__*/_react["default"].createElement("nav", {
|
|
19
|
+
className: navClasses,
|
|
20
|
+
role: "tablist"
|
|
21
|
+
}, items.map(function (_ref2) {
|
|
22
|
+
var id = _ref2.id,
|
|
23
|
+
label = _ref2.label,
|
|
24
|
+
_onClick = _ref2.onClick,
|
|
25
|
+
icon = _ref2.icon;
|
|
26
|
+
var isActive = id === value;
|
|
27
|
+
return /*#__PURE__*/_react["default"].createElement("button", _extends({
|
|
28
|
+
key: id,
|
|
29
|
+
type: "button",
|
|
30
|
+
className: "nav-link".concat(isActive ? " active" : ""),
|
|
31
|
+
role: "tab",
|
|
32
|
+
"data-bs-toggle": "tab",
|
|
33
|
+
"aria-selected": isActive ? "true" : "false"
|
|
34
|
+
}, isActive ? {
|
|
35
|
+
"aria-current": "page"
|
|
36
|
+
} : {}, {
|
|
37
|
+
tabIndex: isActive ? undefined : -1,
|
|
38
|
+
onClick: function onClick(e) {
|
|
39
|
+
onChange(id);
|
|
40
|
+
if (_onClick) _onClick(e);
|
|
41
|
+
}
|
|
42
|
+
}), icon && /*#__PURE__*/_react["default"].createElement("span", {
|
|
43
|
+
className: "me-2"
|
|
44
|
+
}, icon), label);
|
|
45
|
+
}));
|
|
46
|
+
};
|
|
47
|
+
SegmentedControl.propTypes = {
|
|
48
|
+
/** one of 'sm' or 'lg' */
|
|
49
|
+
size: _propTypes["default"].oneOf(["sm", "lg"]),
|
|
50
|
+
/** 'horizontal' or 'vertical' */
|
|
51
|
+
orientation: _propTypes["default"].oneOf(["horizontal", "vertical"]),
|
|
52
|
+
/** the id of the currently selected item */
|
|
53
|
+
value: _propTypes["default"].string.isRequired,
|
|
54
|
+
/** callback called with the id of the clicked item */
|
|
55
|
+
onChange: _propTypes["default"].func.isRequired,
|
|
56
|
+
items: _propTypes["default"].arrayOf(_propTypes["default"].shape({
|
|
57
|
+
id: _propTypes["default"].string.isRequired,
|
|
58
|
+
label: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].node]).isRequired,
|
|
59
|
+
onClick: _propTypes["default"].func,
|
|
60
|
+
icon: _propTypes["default"].node
|
|
61
|
+
})).isRequired
|
|
62
|
+
};
|
|
63
|
+
SegmentedControl.defaultProps = {
|
|
64
|
+
orientation: "horizontal",
|
|
65
|
+
size: undefined
|
|
66
|
+
};
|
package/docs/package.json
CHANGED
|
@@ -168,3 +168,9 @@ export const Navbar = loadable(() =>
|
|
|
168
168
|
return mod.Navbar;
|
|
169
169
|
})
|
|
170
170
|
);
|
|
171
|
+
export const SelectGroup = loadable(() =>
|
|
172
|
+
import("tabler-react-2").then((mod) => mod.SelectGroup)
|
|
173
|
+
);
|
|
174
|
+
export const EnclosedSelectGroup = loadable(() =>
|
|
175
|
+
import("tabler-react-2").then((mod) => mod.EnclosedSelectGroup)
|
|
176
|
+
);
|
|
@@ -14,6 +14,14 @@
|
|
|
14
14
|
link: "/components/cards"
|
|
15
15
|
- label: "Buttons"
|
|
16
16
|
link: "/components/buttons"
|
|
17
|
+
- label: "Inputs"
|
|
18
|
+
link: "/components/input"
|
|
19
|
+
- label: "Dropdown"
|
|
20
|
+
link: "/components/dropdown"
|
|
21
|
+
- label: "Dropdown Input"
|
|
22
|
+
link: "/components/dropdown-input"
|
|
23
|
+
- label: "Select Group"
|
|
24
|
+
link: "/components/select-group"
|
|
17
25
|
- label: "Horizontal Rule"
|
|
18
26
|
link: "/components/hr"
|
|
19
27
|
- label: "Alerts"
|
|
@@ -22,10 +30,6 @@
|
|
|
22
30
|
link: "/components/avatar"
|
|
23
31
|
- label: "Badges"
|
|
24
32
|
link: "/components/badges"
|
|
25
|
-
- label: "Dropdown"
|
|
26
|
-
link: "/components/dropdown"
|
|
27
|
-
- label: "Dropdown Input"
|
|
28
|
-
link: "/components/dropdown-input"
|
|
29
33
|
- label: "Modals"
|
|
30
34
|
link: "/components/modals"
|
|
31
35
|
- label: "Hook-driven modals"
|
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Input
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
import { Input } from "../../components/LoadableTabler";
|
|
6
|
+
import { Excerpt } from "../../components/Excerpt.jsx";
|
|
7
|
+
import { IconAerialLift } from "@tabler/icons-react";
|
|
8
|
+
|
|
9
|
+
Inputs are used to collect user input.
|
|
10
|
+
|
|
11
|
+
## Signature
|
|
12
|
+
|
|
13
|
+
```jsx
|
|
14
|
+
import { Input } from "tabler-react-2";
|
|
15
|
+
|
|
16
|
+
<Input {...props}>{children}</Input>;
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Props
|
|
20
|
+
|
|
21
|
+
| Prop | Required | Type | Default | Description |
|
|
22
|
+
| --------------------- | -------- | -------------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------- |
|
|
23
|
+
| `type` | No | [InputType](#inputtype) | `text` | The type of input. |
|
|
24
|
+
| `label` | No | String | | The label of the input to be shown above the input box. |
|
|
25
|
+
| `placeholder` | No | String | | The placeholder text to be shown in the input box. |
|
|
26
|
+
| `value` | No | String | | The value of the input. |
|
|
27
|
+
| `onChange` | No | Function | | The function to be called when the input value changes. It is called with the new value as the argument, not the event. |
|
|
28
|
+
| `onInput` | No | Function | | The function to be called when the input value changes. It is called with the new value as the argument, not the event. |
|
|
29
|
+
| `onRawChange` | No | Function | | The function to be called when the input value changes. It is called with the event as the argument. |
|
|
30
|
+
| `icon` | No | Node | | The icon to be shown in the input. |
|
|
31
|
+
| `iconPos` | No | [`leading` \| `trailing`] | `leading` | The position of the icon. |
|
|
32
|
+
| `loader` | No | Boolean | | Whether the input should show a spinner. |
|
|
33
|
+
| `separated` | No | Boolean | | Whether the input should be separated from an appended button. |
|
|
34
|
+
| `prependedText` | No | String | | The text to be shown before the input in the box. |
|
|
35
|
+
| `appendedText` | No | String | | The text to be shown after the input in the box. |
|
|
36
|
+
| `appendedLinkText` | No | String | | The text to be shown in the appended link. |
|
|
37
|
+
| `appendedLinkHref` | No | String | | The href of the appended link. |
|
|
38
|
+
| `appendedLinkOnClick` | No | Function | | The function to be called when the appended link is clicked. |
|
|
39
|
+
| `datalistItems` | No | Array of Strings | | The list of items to be shown in the datalist. |
|
|
40
|
+
| `variant` | No | [color](/utilities/colors) | | The color variant of the button. |
|
|
41
|
+
| `size` | No | [`sm`, `md`, `lg`] | `md` | The size of the button. |
|
|
42
|
+
| `inputProps` | No | Object | | The props to be passed to the input. |
|
|
43
|
+
|
|
44
|
+
## Basic Usage
|
|
45
|
+
|
|
46
|
+
The `Input` component is used to collect user input.
|
|
47
|
+
|
|
48
|
+
<Excerpt>
|
|
49
|
+
<Input
|
|
50
|
+
label="Input"
|
|
51
|
+
placeholder="Type here..."
|
|
52
|
+
value={"Starting value"}
|
|
53
|
+
onInput={console.log}
|
|
54
|
+
/>
|
|
55
|
+
</Excerpt>
|
|
56
|
+
|
|
57
|
+
```jsx
|
|
58
|
+
<Input
|
|
59
|
+
label="Input"
|
|
60
|
+
placeholder="Type here..."
|
|
61
|
+
value={"Starting value"}
|
|
62
|
+
onInput={console.log}
|
|
63
|
+
/>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Labels and Placeholders
|
|
67
|
+
|
|
68
|
+
The `Input` component can be used to collect user input. The `label` and `placeholder` props are used to show a label and placeholder text in the input box. Traditionally, the `label` should describe the input, and the `placeholder` should provide a hint or an example. This way the user can still understand what a field is asking for even when the input is not empty.
|
|
69
|
+
|
|
70
|
+
<Excerpt>
|
|
71
|
+
<Input label="Your Name" placeholder="Johnny Appleseed" />
|
|
72
|
+
</Excerpt>
|
|
73
|
+
|
|
74
|
+
```jsx
|
|
75
|
+
<Input label="Your Name" placeholder="Johnny Appleseed" />
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Input Types
|
|
79
|
+
|
|
80
|
+
The `Input` component can be used to collect different types of input. The `type` prop accepts a string value of any [input type](#inputtype).
|
|
81
|
+
|
|
82
|
+
<Excerpt>
|
|
83
|
+
<Input
|
|
84
|
+
label="Email input"
|
|
85
|
+
placeholder="Type here..."
|
|
86
|
+
onInput={console.log}
|
|
87
|
+
type="email"
|
|
88
|
+
/>
|
|
89
|
+
<Input
|
|
90
|
+
label="Password input"
|
|
91
|
+
placeholder="Type here..."
|
|
92
|
+
onInput={console.log}
|
|
93
|
+
type="password"
|
|
94
|
+
/>
|
|
95
|
+
<Input
|
|
96
|
+
label="Number input"
|
|
97
|
+
placeholder="Type here..."
|
|
98
|
+
onInput={console.log}
|
|
99
|
+
type="number"
|
|
100
|
+
/>
|
|
101
|
+
<Input
|
|
102
|
+
label="Date input"
|
|
103
|
+
placeholder="Type here..."
|
|
104
|
+
onInput={console.log}
|
|
105
|
+
type="date"
|
|
106
|
+
/>
|
|
107
|
+
<Input
|
|
108
|
+
label="Datetime input"
|
|
109
|
+
placeholder="Type here..."
|
|
110
|
+
onInput={console.log}
|
|
111
|
+
type="datetime-local"
|
|
112
|
+
/>
|
|
113
|
+
<Input
|
|
114
|
+
label="Month input"
|
|
115
|
+
placeholder="Type here..."
|
|
116
|
+
onInput={console.log}
|
|
117
|
+
type="month"
|
|
118
|
+
/>
|
|
119
|
+
<Input
|
|
120
|
+
label="Time input"
|
|
121
|
+
placeholder="Type here..."
|
|
122
|
+
onInput={console.log}
|
|
123
|
+
type="time"
|
|
124
|
+
/>
|
|
125
|
+
<Input
|
|
126
|
+
label="URL input"
|
|
127
|
+
placeholder="Type here..."
|
|
128
|
+
onInput={console.log}
|
|
129
|
+
type="url"
|
|
130
|
+
/>
|
|
131
|
+
</Excerpt>
|
|
132
|
+
|
|
133
|
+
```jsx highlight={4,9,14,19,24,29,34,39}
|
|
134
|
+
<Input
|
|
135
|
+
label="Email input"
|
|
136
|
+
placeholder="Type here..."
|
|
137
|
+
type="email"
|
|
138
|
+
/>
|
|
139
|
+
<Input
|
|
140
|
+
label="Password input"
|
|
141
|
+
placeholder="Type here..."
|
|
142
|
+
type="password"
|
|
143
|
+
/>
|
|
144
|
+
<Input
|
|
145
|
+
label="Number input"
|
|
146
|
+
placeholder="Type here..."
|
|
147
|
+
type="number"
|
|
148
|
+
/>
|
|
149
|
+
<Input
|
|
150
|
+
label="Date input"
|
|
151
|
+
placeholder="Type here..."
|
|
152
|
+
type="date"
|
|
153
|
+
/>
|
|
154
|
+
<Input
|
|
155
|
+
label="Datetime input"
|
|
156
|
+
placeholder="Type here..."
|
|
157
|
+
type="datetime-local"
|
|
158
|
+
/>
|
|
159
|
+
<Input
|
|
160
|
+
label="Month input"
|
|
161
|
+
placeholder="Type here..."
|
|
162
|
+
type="month"
|
|
163
|
+
/>
|
|
164
|
+
<Input
|
|
165
|
+
label="Time input"
|
|
166
|
+
placeholder="Type here..."
|
|
167
|
+
type="time"
|
|
168
|
+
/>
|
|
169
|
+
<Input
|
|
170
|
+
label="URL input"
|
|
171
|
+
placeholder="Type here..."
|
|
172
|
+
type="url"
|
|
173
|
+
/>
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## `onChange`, `onInput` and `onRawChange` callbacks
|
|
177
|
+
|
|
178
|
+
The `Input` component can call back to provided functions of `onChange` or `onInput` (which are the same), or `onRawChange`. The `onChange` and `onInput` callbacks are called with the new value as the argument, not the event. The `onRawChange` callback is called with the event as the argument.
|
|
179
|
+
|
|
180
|
+
<Excerpt>
|
|
181
|
+
<Input
|
|
182
|
+
label="Input"
|
|
183
|
+
placeholder="Type here..."
|
|
184
|
+
value={"Starting value"}
|
|
185
|
+
onChange={console.log}
|
|
186
|
+
onInput={console.log}
|
|
187
|
+
onRawChange={console.log}
|
|
188
|
+
/>
|
|
189
|
+
</Excerpt>
|
|
190
|
+
|
|
191
|
+
```jsx highlight={5-7}
|
|
192
|
+
<Input
|
|
193
|
+
label="Input"
|
|
194
|
+
placeholder="Type here..."
|
|
195
|
+
value={"Starting value"}
|
|
196
|
+
onChange={console.log}
|
|
197
|
+
onInput={console.log}
|
|
198
|
+
onRawChange={console.log}
|
|
199
|
+
/>
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
When this example is run, the following will be logged to the console:
|
|
203
|
+
|
|
204
|
+
```js
|
|
205
|
+
"Starting value"
|
|
206
|
+
"Starting value"
|
|
207
|
+
{
|
|
208
|
+
...
|
|
209
|
+
target: {
|
|
210
|
+
...
|
|
211
|
+
value: "Starting value"
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Icon
|
|
217
|
+
|
|
218
|
+
You can supply an icon to the `Input` component. The `icon` prop accepts a node.
|
|
219
|
+
|
|
220
|
+
<Excerpt>
|
|
221
|
+
<Input label="Input" placeholder="Type here..." icon={<IconAerialLift />} />
|
|
222
|
+
<Input
|
|
223
|
+
label="Input with icon on the right"
|
|
224
|
+
placeholder="Type here..."
|
|
225
|
+
icon={<IconAerialLift />}
|
|
226
|
+
iconPos="trailing"
|
|
227
|
+
/>
|
|
228
|
+
</Excerpt>
|
|
229
|
+
|
|
230
|
+
```jsx highlight={4,9-10}
|
|
231
|
+
<Input
|
|
232
|
+
label="Input"
|
|
233
|
+
placeholder="Type here..."
|
|
234
|
+
icon={<IconAerialLift />}
|
|
235
|
+
/>
|
|
236
|
+
<Input
|
|
237
|
+
label="Input with icon on the right"
|
|
238
|
+
placeholder="Type here..."
|
|
239
|
+
icon={<IconAerialLift />}
|
|
240
|
+
iconPos="trailing"
|
|
241
|
+
/>
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Loader
|
|
245
|
+
|
|
246
|
+
You can supply a boolean value to the `loader` prop to show a spinner.
|
|
247
|
+
|
|
248
|
+
<Excerpt>
|
|
249
|
+
<Input label="Input" placeholder="Type here..." loader />
|
|
250
|
+
</Excerpt>
|
|
251
|
+
|
|
252
|
+
```jsx
|
|
253
|
+
<Input label="Input" placeholder="Type here..." loader />
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Separated
|
|
257
|
+
|
|
258
|
+
You can create seperate inputs by passing the `separated` prop. If you do this, you must also provide either an icon or loader, and use the `appendedLinkOnClick` or `appendedLinkHref` props to handle press events.
|
|
259
|
+
|
|
260
|
+
<Excerpt>
|
|
261
|
+
<Input
|
|
262
|
+
label="Input"
|
|
263
|
+
placeholder="Type here..."
|
|
264
|
+
appendedLinkOnClick={() => alert("Clicked")}
|
|
265
|
+
icon={<IconAerialLift size={18} />}
|
|
266
|
+
separated
|
|
267
|
+
/>
|
|
268
|
+
<Input
|
|
269
|
+
label="Input"
|
|
270
|
+
placeholder="Type here..."
|
|
271
|
+
appendedLinkOnClick={() => alert("Clicked")}
|
|
272
|
+
loader
|
|
273
|
+
separated
|
|
274
|
+
/>
|
|
275
|
+
</Excerpt>
|
|
276
|
+
|
|
277
|
+
```jsx
|
|
278
|
+
<Input
|
|
279
|
+
label="Input"
|
|
280
|
+
placeholder="Type here..."
|
|
281
|
+
appendedLinkOnClick={() => alert("Clicked")}
|
|
282
|
+
icon={<IconAerialLift size={18} />}
|
|
283
|
+
separated
|
|
284
|
+
/>
|
|
285
|
+
<Input
|
|
286
|
+
label="Input"
|
|
287
|
+
placeholder="Type here..."
|
|
288
|
+
appendedLinkOnClick={() => alert("Clicked")}
|
|
289
|
+
icon={<IconAerialLift size={18} />}
|
|
290
|
+
separated
|
|
291
|
+
/>
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
## Prepended and Appended Text or Links
|
|
295
|
+
|
|
296
|
+
You can embed text or links in the input box by passing the `prependedText` or `appendedText` props. You can also pass an `appendedLinkText` prop to show a link in the text. The `appendedLinkHref` prop is used to set the href of the link. The `appendedLinkOnClick` prop is used to handle the click event of the link. You can only add event handlers to the appended link. If using links, you cannot also use a prependedText.
|
|
297
|
+
|
|
298
|
+
<Excerpt>
|
|
299
|
+
<Input
|
|
300
|
+
label="Input"
|
|
301
|
+
placeholder="Type here..."
|
|
302
|
+
prependedText="https://"
|
|
303
|
+
appendedText=".com"
|
|
304
|
+
/>
|
|
305
|
+
<Input
|
|
306
|
+
label="Input"
|
|
307
|
+
placeholder="Type here..."
|
|
308
|
+
appendedLinkText="Link"
|
|
309
|
+
appendedLinkHref="javascript:void(0);"
|
|
310
|
+
appendedLinkOnClick={() => alert("Clicked")}
|
|
311
|
+
/>
|
|
312
|
+
</Excerpt>
|
|
313
|
+
|
|
314
|
+
```jsx
|
|
315
|
+
<Input
|
|
316
|
+
label="Input"
|
|
317
|
+
placeholder="Type here..."
|
|
318
|
+
prependedText="https://"
|
|
319
|
+
appendedText=".com"
|
|
320
|
+
/>
|
|
321
|
+
<Input
|
|
322
|
+
label="Input"
|
|
323
|
+
placeholder="Type here..."
|
|
324
|
+
appendedLinkText="Link"
|
|
325
|
+
appendedLinkHref="javascript:void(0);"
|
|
326
|
+
appendedLinkOnClick={() => alert("Clicked")}
|
|
327
|
+
/>
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
## Variants
|
|
331
|
+
|
|
332
|
+
You can pass a `variant` prop to the `Input` component to change the color of the input box.
|
|
333
|
+
|
|
334
|
+
<Excerpt>
|
|
335
|
+
{[
|
|
336
|
+
"primary",
|
|
337
|
+
"secondary",
|
|
338
|
+
"success",
|
|
339
|
+
"danger",
|
|
340
|
+
"warning",
|
|
341
|
+
"info",
|
|
342
|
+
"light",
|
|
343
|
+
"dark",
|
|
344
|
+
"pink",
|
|
345
|
+
"yellow",
|
|
346
|
+
].map((color) => (
|
|
347
|
+
<Input
|
|
348
|
+
key={color}
|
|
349
|
+
label="Input"
|
|
350
|
+
placeholder="Type here..."
|
|
351
|
+
variant={color}
|
|
352
|
+
/>
|
|
353
|
+
))}
|
|
354
|
+
</Excerpt>
|
|
355
|
+
|
|
356
|
+
```jsx
|
|
357
|
+
<Input
|
|
358
|
+
label="Input"
|
|
359
|
+
placeholder="Type here..."
|
|
360
|
+
variant="primary"
|
|
361
|
+
/>
|
|
362
|
+
<Input
|
|
363
|
+
label="Input"
|
|
364
|
+
placeholder="Type here..."
|
|
365
|
+
variant="secondary"
|
|
366
|
+
/>
|
|
367
|
+
...
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
## Invalid
|
|
371
|
+
|
|
372
|
+
There is not `invalid` prop. You can use the `variant` prop to change the color of the input box to indicate an invalid state.
|
|
373
|
+
|
|
374
|
+
<Excerpt>
|
|
375
|
+
<Input label="Input" placeholder="Type here..." variant="danger" />
|
|
376
|
+
</Excerpt>
|
|
377
|
+
|
|
378
|
+
```jsx
|
|
379
|
+
<Input label="Input" placeholder="Type here..." variant="danger" />
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
## Sizes
|
|
383
|
+
|
|
384
|
+
You can pass a `size` prop to the `Input` component to change the size of the input box.
|
|
385
|
+
|
|
386
|
+
<Excerpt>
|
|
387
|
+
{["sm", "md", "lg"].map((size) => (
|
|
388
|
+
<Input key={size} label="Input" placeholder="Type here..." size={size} />
|
|
389
|
+
))}
|
|
390
|
+
</Excerpt>
|
|
391
|
+
|
|
392
|
+
```jsx
|
|
393
|
+
<Input
|
|
394
|
+
label="Input"
|
|
395
|
+
placeholder="Type here..."
|
|
396
|
+
size="sm"
|
|
397
|
+
/>
|
|
398
|
+
<Input
|
|
399
|
+
label="Input"
|
|
400
|
+
placeholder="Type here..."
|
|
401
|
+
size="md"
|
|
402
|
+
/>
|
|
403
|
+
<Input
|
|
404
|
+
label="Input"
|
|
405
|
+
placeholder="Type here..."
|
|
406
|
+
size="lg"
|
|
407
|
+
/>
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
## Datalist (Autocomplete)
|
|
411
|
+
|
|
412
|
+
You can supply a list of items to the `datalistItems` prop to show a datalist. The `datalistItems` prop accepts an array of strings.
|
|
413
|
+
|
|
414
|
+
<Excerpt>
|
|
415
|
+
<Input
|
|
416
|
+
label="Input"
|
|
417
|
+
placeholder="Type here..."
|
|
418
|
+
datalistItems={["One", "Two", "Three"]}
|
|
419
|
+
/>
|
|
420
|
+
</Excerpt>
|
|
421
|
+
|
|
422
|
+
```jsx
|
|
423
|
+
<Input
|
|
424
|
+
label="Input"
|
|
425
|
+
placeholder="Type here..."
|
|
426
|
+
datalistItems={["One", "Two", "Three"]}
|
|
427
|
+
/>
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
This is different than a DropdownInput because the datalist is not exclusive, meaning the user can use a value that is not in the list.
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Select Group
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
SelectGroup,
|
|
7
|
+
EnclosedSelectGroup,
|
|
8
|
+
} from "../../components/LoadableTabler.jsx";
|
|
9
|
+
import { Excerpt } from "../../components/Excerpt.jsx";
|
|
10
|
+
import { useState } from "react";
|
|
11
|
+
|
|
12
|
+
Select Groups are used to mask radio and checkbox inputs in boxes with a label.
|
|
13
|
+
|
|
14
|
+
## Signature
|
|
15
|
+
|
|
16
|
+
export const ControlledSelectGroup = (props) => {
|
|
17
|
+
const [value, setValue] = useState(props.value);
|
|
18
|
+
return (
|
|
19
|
+
<>
|
|
20
|
+
<SelectGroup
|
|
21
|
+
{...props}
|
|
22
|
+
value={value}
|
|
23
|
+
onChange={(d) => {
|
|
24
|
+
setValue(d);
|
|
25
|
+
props.onChange && props.onChange(d);
|
|
26
|
+
}}
|
|
27
|
+
/>
|
|
28
|
+
</>
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const ControlledEnclosedSelectGroup = (props) => {
|
|
33
|
+
const [value, setValue] = useState(props.value);
|
|
34
|
+
return (
|
|
35
|
+
<>
|
|
36
|
+
<EnclosedSelectGroup
|
|
37
|
+
{...props}
|
|
38
|
+
value={value}
|
|
39
|
+
onChange={(d) => {
|
|
40
|
+
setValue(d);
|
|
41
|
+
props.onChange && props.onChange(d);
|
|
42
|
+
}}
|
|
43
|
+
/>
|
|
44
|
+
</>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
```jsx
|
|
49
|
+
import { SelectGroup } from "tabler-react-2";
|
|
50
|
+
|
|
51
|
+
<SelectGroup {...props} />;
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Props
|
|
55
|
+
|
|
56
|
+
| Prop | Required | Type | Default | Description |
|
|
57
|
+
| ---------- | -------- | -------------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
58
|
+
| `items` | Yes | Array of objects | | The items to be shown in the select group. Each item should have a `value` and `label` prop. |
|
|
59
|
+
| `value` | Yes | Object or Array of Objects if multiple | | The value of the select group. If the value is an array, multiple items can be selected. The value of each item should be the same as the `value` prop of the item. |
|
|
60
|
+
| `onChange` | Yes | Function | | The function to be called when the value of the select group changes. It is called with the new value as the argument, not the event. If the value is an array, the new value is an array of objects. The value of each item should be the same as the `value` prop of the item. |
|
|
61
|
+
| `multiple` | No | Boolean | | Whether multiple items can be selected. |
|
|
62
|
+
|
|
63
|
+
## Basic Usage
|
|
64
|
+
|
|
65
|
+
The `SelectGroup` component is used to mask radio and checkbox inputs in boxes with a label.
|
|
66
|
+
|
|
67
|
+
<Excerpt>
|
|
68
|
+
<ControlledSelectGroup
|
|
69
|
+
items={[
|
|
70
|
+
{ value: "one", label: "One" },
|
|
71
|
+
{ value: "two", label: "Two" },
|
|
72
|
+
{ value: "three", label: "Three" },
|
|
73
|
+
]}
|
|
74
|
+
value={null}
|
|
75
|
+
onChange={console.log}
|
|
76
|
+
/>
|
|
77
|
+
|
|
78
|
+
</Excerpt>
|
|
79
|
+
|
|
80
|
+
```jsx
|
|
81
|
+
<SelectGroup
|
|
82
|
+
items={[
|
|
83
|
+
{ value: "one", label: "One" },
|
|
84
|
+
{ value: "two", label: "Two" },
|
|
85
|
+
{ value: "three", label: "Three" },
|
|
86
|
+
]}
|
|
87
|
+
value={null}
|
|
88
|
+
onChange={console.log}
|
|
89
|
+
/>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Multiple Select
|
|
93
|
+
|
|
94
|
+
The `multiple` prop can be used to allow multiple items to be selected.
|
|
95
|
+
|
|
96
|
+
<Excerpt>
|
|
97
|
+
<ControlledSelectGroup
|
|
98
|
+
items={[
|
|
99
|
+
{ value: "one", label: "One" },
|
|
100
|
+
{ value: "two", label: "Two" },
|
|
101
|
+
{ value: "three", label: "Three" },
|
|
102
|
+
]}
|
|
103
|
+
value={[]}
|
|
104
|
+
onChange={console.log}
|
|
105
|
+
multiple
|
|
106
|
+
/>
|
|
107
|
+
|
|
108
|
+
</Excerpt>
|
|
109
|
+
|
|
110
|
+
```jsx
|
|
111
|
+
<SelectGroup
|
|
112
|
+
items={[
|
|
113
|
+
{ value: "one", label: "One" },
|
|
114
|
+
{ value: "two", label: "Two" },
|
|
115
|
+
{ value: "three", label: "Three" },
|
|
116
|
+
]}
|
|
117
|
+
value={null}
|
|
118
|
+
onChange={console.log}
|
|
119
|
+
multiple
|
|
120
|
+
/>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Enclosed Select Group
|
|
124
|
+
|
|
125
|
+
The `EnclosedSelectGroup` component is used to mask radio and checkbox inputs in boxes with a label.
|
|
126
|
+
|
|
127
|
+
<Excerpt>
|
|
128
|
+
<ControlledEnclosedSelectGroup
|
|
129
|
+
items={[
|
|
130
|
+
{ value: "one", content: <b>One</b> },
|
|
131
|
+
{ value: "two", content: "Two" },
|
|
132
|
+
{ value: "three", content: "Three" },
|
|
133
|
+
]}
|
|
134
|
+
value={null}
|
|
135
|
+
onChange={console.log}
|
|
136
|
+
/>
|
|
137
|
+
</Excerpt>
|