tabler-react-2 0.1.82 → 0.1.83
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/dropdown.js
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.DropdownInput = void 0;
|
|
6
|
+
exports.LoadableDropdownInput = exports.DropdownInput = void 0;
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
-
var _input = require("./input");
|
|
10
9
|
var _index = require("../index");
|
|
11
|
-
var _excluded = ["prompt", "values", "items", "value", "onChange", "aprops", "showSearch",
|
|
10
|
+
var _excluded = ["prompt", "values", "items", "value", "onChange", "aprops", "showSearch"],
|
|
11
|
+
_excluded2 = ["values", "value", "onChange", "prompt", "loading", "label", "showLabel", "disabled", "disabledText"];
|
|
12
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
13
13
|
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); }
|
|
14
14
|
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; }
|
|
@@ -31,45 +31,11 @@ var DropdownInput = exports.DropdownInput = function DropdownInput(_ref) {
|
|
|
31
31
|
aprops = _ref.aprops,
|
|
32
32
|
_ref$showSearch = _ref.showSearch,
|
|
33
33
|
showSearch = _ref$showSearch === void 0 ? true : _ref$showSearch,
|
|
34
|
-
_ref$loading = _ref.loading,
|
|
35
|
-
loading = _ref$loading === void 0 ? false : _ref$loading,
|
|
36
|
-
_ref$disabled = _ref.disabled,
|
|
37
|
-
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
38
|
-
disabledText = _ref.disabledText,
|
|
39
|
-
label = _ref.label,
|
|
40
|
-
_ref$showLabel = _ref.showLabel,
|
|
41
|
-
showLabel = _ref$showLabel === void 0 ? true : _ref$showLabel,
|
|
42
|
-
color = _ref.color,
|
|
43
|
-
outline = _ref.outline,
|
|
44
34
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
45
|
-
|
|
46
|
-
var values = ivalues || items || [];
|
|
47
|
-
|
|
48
|
-
// When loading, show a Button in a container with an optional label.
|
|
49
|
-
if (loading) {
|
|
50
|
-
return /*#__PURE__*/_react["default"].createElement(_index.Util.Col, null, showLabel && label && /*#__PURE__*/_react["default"].createElement("label", {
|
|
51
|
-
className: "form-label"
|
|
52
|
-
}, label), /*#__PURE__*/_react["default"].createElement(_index.Button, {
|
|
53
|
-
loading: true,
|
|
54
|
-
disabled: true
|
|
55
|
-
}, prompt));
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// When disabled, show a disabled Button (with alternate text if provided).
|
|
59
|
-
if (disabled) {
|
|
60
|
-
return /*#__PURE__*/_react["default"].createElement(_index.Util.Col, null, showLabel && label && /*#__PURE__*/_react["default"].createElement("label", {
|
|
61
|
-
className: "form-label"
|
|
62
|
-
}, label), /*#__PURE__*/_react["default"].createElement(_index.Button, {
|
|
63
|
-
disabled: true
|
|
64
|
-
}, disabledText || prompt));
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Helper: if value is an object, use its id; otherwise, assume the value itself is the id.
|
|
35
|
+
var values = ivalues || items;
|
|
68
36
|
var getId = function getId(val) {
|
|
69
37
|
return _typeof(val) === "object" && val !== null ? val.id : val;
|
|
70
38
|
};
|
|
71
|
-
|
|
72
|
-
// Set up state for the selected value and search/filtering.
|
|
73
39
|
var _useState = (0, _react.useState)(values.find(function (val) {
|
|
74
40
|
return val.id === getId(value);
|
|
75
41
|
}) || null),
|
|
@@ -85,7 +51,7 @@ var DropdownInput = exports.DropdownInput = function DropdownInput(_ref) {
|
|
|
85
51
|
filteredValues = _useState6[0],
|
|
86
52
|
setFilteredValues = _useState6[1];
|
|
87
53
|
|
|
88
|
-
// Update
|
|
54
|
+
// Update selected value if the `value` prop changes
|
|
89
55
|
(0, _react.useEffect)(function () {
|
|
90
56
|
var matchedValue = values.find(function (val) {
|
|
91
57
|
return val.id === getId(value);
|
|
@@ -93,55 +59,48 @@ var DropdownInput = exports.DropdownInput = function DropdownInput(_ref) {
|
|
|
93
59
|
setSelectedValue(matchedValue);
|
|
94
60
|
}, [value, values]);
|
|
95
61
|
|
|
96
|
-
// Filter values based on the search query
|
|
62
|
+
// Filter the dropdown values based on the search query
|
|
97
63
|
(0, _react.useEffect)(function () {
|
|
98
64
|
setFilteredValues(values.filter(function (val) {
|
|
99
65
|
return JSON.stringify(val).toLowerCase().includes(searchQuery.toLowerCase());
|
|
100
66
|
}));
|
|
101
67
|
}, [searchQuery, values]);
|
|
102
|
-
var handleSelection = function handleSelection(
|
|
103
|
-
setSelectedValue(
|
|
68
|
+
var handleSelection = function handleSelection(value) {
|
|
69
|
+
setSelectedValue(value);
|
|
104
70
|
if (onChange) {
|
|
105
|
-
onChange(
|
|
71
|
+
onChange(value); // Return the full object
|
|
106
72
|
}
|
|
107
73
|
};
|
|
108
|
-
|
|
109
|
-
// The main dropdown markup.
|
|
110
|
-
var dropdownContent = /*#__PURE__*/_react["default"].createElement("div", _extends({
|
|
74
|
+
return /*#__PURE__*/_react["default"].createElement("div", _extends({
|
|
111
75
|
className: "dropdown"
|
|
112
76
|
}, props), /*#__PURE__*/_react["default"].createElement("a", _extends({
|
|
113
77
|
href: "#",
|
|
114
|
-
className: "btn dropdown-toggle ".concat(props.disabled ? "disabled" : "", " ").concat(color ? "btn-".concat(outline
|
|
78
|
+
className: "btn dropdown-toggle ".concat(props.disabled ? "disabled" : "", " ").concat(props.color ? "btn-".concat(props.outline && "outline-").concat(props.color) : ""),
|
|
115
79
|
"data-bs-toggle": "dropdown"
|
|
116
80
|
}, aprops), selectedValue ? selectedValue.label : prompt), /*#__PURE__*/_react["default"].createElement("div", {
|
|
117
81
|
className: "dropdown-menu"
|
|
118
82
|
}, showSearch && /*#__PURE__*/_react["default"].createElement("div", {
|
|
119
83
|
className: "px-2 py-1"
|
|
120
|
-
}, /*#__PURE__*/_react["default"].createElement(
|
|
84
|
+
}, /*#__PURE__*/_react["default"].createElement(_index.Input, {
|
|
121
85
|
placeholder: "Search...",
|
|
122
86
|
value: searchQuery,
|
|
123
87
|
onChange: function onChange(value) {
|
|
124
88
|
return setSearchQuery(value);
|
|
125
89
|
}
|
|
126
|
-
})), filteredValues.map(function (
|
|
90
|
+
})), filteredValues.map(function (value, index) {
|
|
127
91
|
return /*#__PURE__*/_react["default"].createElement("a", {
|
|
128
92
|
key: index,
|
|
129
|
-
className: "dropdown-item".concat(selectedValue && selectedValue.id ===
|
|
93
|
+
className: "dropdown-item".concat(selectedValue && selectedValue.id === value.id ? " active" : ""),
|
|
130
94
|
onClick: function onClick() {
|
|
131
|
-
return handleSelection(
|
|
95
|
+
return handleSelection(value);
|
|
132
96
|
},
|
|
133
97
|
style: {
|
|
134
98
|
cursor: "pointer"
|
|
135
99
|
}
|
|
136
|
-
},
|
|
100
|
+
}, value.dropdownText || value.label);
|
|
137
101
|
}), filteredValues.length === 0 && /*#__PURE__*/_react["default"].createElement("div", {
|
|
138
102
|
className: "dropdown-item text-muted"
|
|
139
103
|
}, "No results found")));
|
|
140
|
-
|
|
141
|
-
// If a label is provided, wrap the dropdown with the label inside a container.
|
|
142
|
-
return label && showLabel ? /*#__PURE__*/_react["default"].createElement(_index.Util.Col, null, /*#__PURE__*/_react["default"].createElement("label", {
|
|
143
|
-
className: "form-label"
|
|
144
|
-
}, label), dropdownContent) : dropdownContent;
|
|
145
104
|
};
|
|
146
105
|
DropdownInput.propTypes = {
|
|
147
106
|
prompt: _propTypes["default"].string.isRequired,
|
|
@@ -149,23 +108,45 @@ DropdownInput.propTypes = {
|
|
|
149
108
|
id: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]).isRequired,
|
|
150
109
|
label: _propTypes["default"].string.isRequired,
|
|
151
110
|
dropdownText: _propTypes["default"].string
|
|
152
|
-
})),
|
|
153
|
-
items: _propTypes["default"].arrayOf(_propTypes["default"].shape({
|
|
154
|
-
id: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]).isRequired,
|
|
155
|
-
label: _propTypes["default"].string.isRequired,
|
|
156
|
-
dropdownText: _propTypes["default"].string
|
|
157
|
-
})),
|
|
111
|
+
})).isRequired,
|
|
158
112
|
value: _propTypes["default"].oneOfType([_propTypes["default"].shape({
|
|
159
113
|
id: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]).isRequired
|
|
160
114
|
}), _propTypes["default"].string, _propTypes["default"].number]),
|
|
161
115
|
onChange: _propTypes["default"].func.isRequired,
|
|
162
|
-
aprops: _propTypes["default"].object,
|
|
163
|
-
showSearch: _propTypes["default"].bool,
|
|
164
|
-
loading: _propTypes["default"].bool,
|
|
165
|
-
disabled: _propTypes["default"].bool,
|
|
166
|
-
disabledText: _propTypes["default"].string,
|
|
167
|
-
label: _propTypes["default"].string,
|
|
168
|
-
showLabel: _propTypes["default"].bool,
|
|
169
116
|
color: _propTypes["default"].string,
|
|
170
117
|
outline: _propTypes["default"].bool
|
|
118
|
+
};
|
|
119
|
+
var LoadableDropdownInput = exports.LoadableDropdownInput = function LoadableDropdownInput(_ref2) {
|
|
120
|
+
var values = _ref2.values,
|
|
121
|
+
value = _ref2.value,
|
|
122
|
+
onChange = _ref2.onChange,
|
|
123
|
+
prompt = _ref2.prompt,
|
|
124
|
+
loading = _ref2.loading,
|
|
125
|
+
label = _ref2.label,
|
|
126
|
+
_ref2$showLabel = _ref2.showLabel,
|
|
127
|
+
showLabel = _ref2$showLabel === void 0 ? true : _ref2$showLabel,
|
|
128
|
+
_ref2$disabled = _ref2.disabled,
|
|
129
|
+
disabled = _ref2$disabled === void 0 ? false : _ref2$disabled,
|
|
130
|
+
disabledText = _ref2.disabledText,
|
|
131
|
+
props = _objectWithoutProperties(_ref2, _excluded2);
|
|
132
|
+
if (loading) return /*#__PURE__*/_react["default"].createElement(_index.Util.Col, null, showLabel && /*#__PURE__*/_react["default"].createElement("label", {
|
|
133
|
+
className: "form-label"
|
|
134
|
+
}, label), /*#__PURE__*/_react["default"].createElement(_index.Button, {
|
|
135
|
+
loading: true,
|
|
136
|
+
disabled: true
|
|
137
|
+
}, prompt));
|
|
138
|
+
if (disabled) return /*#__PURE__*/_react["default"].createElement(_index.Util.Col, null, showLabel && /*#__PURE__*/_react["default"].createElement("label", {
|
|
139
|
+
className: "form-label"
|
|
140
|
+
}, label), /*#__PURE__*/_react["default"].createElement(_index.Button, {
|
|
141
|
+
disabled: true
|
|
142
|
+
}, disabledText || prompt));
|
|
143
|
+
return /*#__PURE__*/_react["default"].createElement(_index.Util.Col, null, showLabel && /*#__PURE__*/_react["default"].createElement("label", {
|
|
144
|
+
className: "form-label"
|
|
145
|
+
}, label), /*#__PURE__*/_react["default"].createElement(DropdownInput, _extends({
|
|
146
|
+
values: values,
|
|
147
|
+
value: value,
|
|
148
|
+
onChange: onChange,
|
|
149
|
+
prompt: prompt,
|
|
150
|
+
"data-value": value
|
|
151
|
+
}, props)));
|
|
171
152
|
};
|
package/docs/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"componentChunkName":"component---node-modules-rocketseat-gatsby-theme-docs-core-src-templates-docs-query-js-content-file-path-src-docs-components-dropdown-input-mdx","path":"/components/dropdown-input/","result":{"data":{"mdx":{"id":"64604855-8780-5836-b431-bbea02d735f8","excerpt":"Dropdown inputs are used to select an option from a list of options. Signature\nimport { DropdownInput } from \"tabler-react-2\";\n\n<DropdownInput {...props…","fields":{"slug":"/components/dropdown-input/"},"frontmatter":{"title":"Dropdown Input","description":null,"image":null,"disableTableOfContents":null},"headings":[{"depth":2,"value":"Signature"},{"depth":3,"value":"Props"},{"depth":2,"value":"Basic Usage"},{"depth":2,"value":"State Machine"},{"depth":2,"value":"Hiding the search input"},{"depth":2,"value":"Disabled"}
|
|
1
|
+
{"componentChunkName":"component---node-modules-rocketseat-gatsby-theme-docs-core-src-templates-docs-query-js-content-file-path-src-docs-components-dropdown-input-mdx","path":"/components/dropdown-input/","result":{"data":{"mdx":{"id":"64604855-8780-5836-b431-bbea02d735f8","excerpt":"Dropdown inputs are used to select an option from a list of options. Signature\nimport { DropdownInput } from \"tabler-react-2\";\n\n<DropdownInput {...props…","fields":{"slug":"/components/dropdown-input/"},"frontmatter":{"title":"Dropdown Input","description":null,"image":null,"disableTableOfContents":null},"headings":[{"depth":2,"value":"Signature"},{"depth":3,"value":"Props"},{"depth":2,"value":"Basic Usage"},{"depth":2,"value":"State Machine"},{"depth":2,"value":"Hiding the search input"},{"depth":2,"value":"Disabled"}]}},"pageContext":{"slug":"/components/dropdown-input/","prev":{"label":"Dropdown","link":"/components/dropdown"},"next":{"label":"Colors","link":"/utilities/colors"},"repositoryEditUrl":"https://github.com/jpedroschmitz/rocketdocs/tree/main/examples/gatsby-theme-docs/src/docs/components/dropdown-input.mdx","repositoryProvider":"GitHub","frontmatter":{"title":"Dropdown Input"}}},"staticQueryHashes":["1954253342","2328931024","2501019404","973074209"],"slicesMap":{}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"componentChunkName":"component---cache-dev-404-page-js","path":"/dev-404-page/","result":{"data":{"allSiteFunction":{"nodes":[]},"allSitePage":{"nodes":[{"path":"/404/"},{"path":"/404.html"},{"path":"/"},{"path":"/faq/"},{"path":"/
|
|
1
|
+
{"componentChunkName":"component---cache-dev-404-page-js","path":"/dev-404-page/","result":{"data":{"allSiteFunction":{"nodes":[]},"allSitePage":{"nodes":[{"path":"/404/"},{"path":"/404.html"},{"path":"/"},{"path":"/faq/"},{"path":"/getting-started/"},{"path":"/components/alerts/"},{"path":"/components/avatar/"},{"path":"/todo/"},{"path":"/utilities/colors/"},{"path":"/components/badges/"},{"path":"/components/cards/"},{"path":"/components/buttons/"},{"path":"/utilities/margins/"},{"path":"/components/dropdown-input/"},{"path":"/components/hr/"},{"path":"/components/dropdown/"},{"path":"/components/typography/"}]}},"pageContext":{}},"staticQueryHashes":[],"slicesMap":{}}
|
|
@@ -33,7 +33,7 @@ The `DropdownInput` component is used to select an option from a list of options
|
|
|
33
33
|
<Excerpt>
|
|
34
34
|
<DropdownInput
|
|
35
35
|
prompt="Select a value"
|
|
36
|
-
|
|
36
|
+
items={[
|
|
37
37
|
{ id: 1, label: "Sam" },
|
|
38
38
|
{ id: 2, label: "Bob" },
|
|
39
39
|
{ id: 3, label: "John" },
|
|
@@ -142,5 +142,3 @@ You can disable the dropdown by passing in `disabled={true}`.
|
|
|
142
142
|
disabled={true}
|
|
143
143
|
/>
|
|
144
144
|
```
|
|
145
|
-
|
|
146
|
-
##
|