tabler-react-2 0.1.81 → 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,13 +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
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
var _excluded = ["prompt", "values", "items", "value", "onChange", "aprops", "showSearch", "loading", "disabled", "disabledText", "label", "showLabel", "color", "outline"];
|
|
9
|
+
var _index = require("../index");
|
|
10
|
+
var _excluded = ["prompt", "values", "items", "value", "onChange", "aprops", "showSearch"],
|
|
11
|
+
_excluded2 = ["values", "value", "onChange", "prompt", "loading", "label", "showLabel", "disabled", "disabledText"];
|
|
13
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
14
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); }
|
|
15
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; }
|
|
@@ -32,45 +31,11 @@ var DropdownInput = exports.DropdownInput = function DropdownInput(_ref) {
|
|
|
32
31
|
aprops = _ref.aprops,
|
|
33
32
|
_ref$showSearch = _ref.showSearch,
|
|
34
33
|
showSearch = _ref$showSearch === void 0 ? true : _ref$showSearch,
|
|
35
|
-
_ref$loading = _ref.loading,
|
|
36
|
-
loading = _ref$loading === void 0 ? false : _ref$loading,
|
|
37
|
-
_ref$disabled = _ref.disabled,
|
|
38
|
-
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
39
|
-
disabledText = _ref.disabledText,
|
|
40
|
-
label = _ref.label,
|
|
41
|
-
_ref$showLabel = _ref.showLabel,
|
|
42
|
-
showLabel = _ref$showLabel === void 0 ? true : _ref$showLabel,
|
|
43
|
-
color = _ref.color,
|
|
44
|
-
outline = _ref.outline,
|
|
45
34
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
46
|
-
|
|
47
|
-
var values = ivalues || items || [];
|
|
48
|
-
|
|
49
|
-
// When loading, show a Button in a container with an optional label.
|
|
50
|
-
if (loading) {
|
|
51
|
-
return /*#__PURE__*/_react["default"].createElement(_util["default"].Col, null, showLabel && label && /*#__PURE__*/_react["default"].createElement("label", {
|
|
52
|
-
className: "form-label"
|
|
53
|
-
}, label), /*#__PURE__*/_react["default"].createElement(_button.Button, {
|
|
54
|
-
loading: true,
|
|
55
|
-
disabled: true
|
|
56
|
-
}, prompt));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// When disabled, show a disabled Button (with alternate text if provided).
|
|
60
|
-
if (disabled) {
|
|
61
|
-
return /*#__PURE__*/_react["default"].createElement(_util["default"].Col, null, showLabel && label && /*#__PURE__*/_react["default"].createElement("label", {
|
|
62
|
-
className: "form-label"
|
|
63
|
-
}, label), /*#__PURE__*/_react["default"].createElement(_button.Button, {
|
|
64
|
-
disabled: true
|
|
65
|
-
}, disabledText || prompt));
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Helper: if value is an object, use its id; otherwise, assume the value itself is the id.
|
|
35
|
+
var values = ivalues || items;
|
|
69
36
|
var getId = function getId(val) {
|
|
70
37
|
return _typeof(val) === "object" && val !== null ? val.id : val;
|
|
71
38
|
};
|
|
72
|
-
|
|
73
|
-
// Set up state for the selected value and search/filtering.
|
|
74
39
|
var _useState = (0, _react.useState)(values.find(function (val) {
|
|
75
40
|
return val.id === getId(value);
|
|
76
41
|
}) || null),
|
|
@@ -86,7 +51,7 @@ var DropdownInput = exports.DropdownInput = function DropdownInput(_ref) {
|
|
|
86
51
|
filteredValues = _useState6[0],
|
|
87
52
|
setFilteredValues = _useState6[1];
|
|
88
53
|
|
|
89
|
-
// Update
|
|
54
|
+
// Update selected value if the `value` prop changes
|
|
90
55
|
(0, _react.useEffect)(function () {
|
|
91
56
|
var matchedValue = values.find(function (val) {
|
|
92
57
|
return val.id === getId(value);
|
|
@@ -94,55 +59,48 @@ var DropdownInput = exports.DropdownInput = function DropdownInput(_ref) {
|
|
|
94
59
|
setSelectedValue(matchedValue);
|
|
95
60
|
}, [value, values]);
|
|
96
61
|
|
|
97
|
-
// Filter values based on the search query
|
|
62
|
+
// Filter the dropdown values based on the search query
|
|
98
63
|
(0, _react.useEffect)(function () {
|
|
99
64
|
setFilteredValues(values.filter(function (val) {
|
|
100
65
|
return JSON.stringify(val).toLowerCase().includes(searchQuery.toLowerCase());
|
|
101
66
|
}));
|
|
102
67
|
}, [searchQuery, values]);
|
|
103
|
-
var handleSelection = function handleSelection(
|
|
104
|
-
setSelectedValue(
|
|
68
|
+
var handleSelection = function handleSelection(value) {
|
|
69
|
+
setSelectedValue(value);
|
|
105
70
|
if (onChange) {
|
|
106
|
-
onChange(
|
|
71
|
+
onChange(value); // Return the full object
|
|
107
72
|
}
|
|
108
73
|
};
|
|
109
|
-
|
|
110
|
-
// The main dropdown markup.
|
|
111
|
-
var dropdownContent = /*#__PURE__*/_react["default"].createElement("div", _extends({
|
|
74
|
+
return /*#__PURE__*/_react["default"].createElement("div", _extends({
|
|
112
75
|
className: "dropdown"
|
|
113
76
|
}, props), /*#__PURE__*/_react["default"].createElement("a", _extends({
|
|
114
77
|
href: "#",
|
|
115
|
-
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) : ""),
|
|
116
79
|
"data-bs-toggle": "dropdown"
|
|
117
80
|
}, aprops), selectedValue ? selectedValue.label : prompt), /*#__PURE__*/_react["default"].createElement("div", {
|
|
118
81
|
className: "dropdown-menu"
|
|
119
82
|
}, showSearch && /*#__PURE__*/_react["default"].createElement("div", {
|
|
120
83
|
className: "px-2 py-1"
|
|
121
|
-
}, /*#__PURE__*/_react["default"].createElement(
|
|
84
|
+
}, /*#__PURE__*/_react["default"].createElement(_index.Input, {
|
|
122
85
|
placeholder: "Search...",
|
|
123
86
|
value: searchQuery,
|
|
124
87
|
onChange: function onChange(value) {
|
|
125
88
|
return setSearchQuery(value);
|
|
126
89
|
}
|
|
127
|
-
})), filteredValues.map(function (
|
|
90
|
+
})), filteredValues.map(function (value, index) {
|
|
128
91
|
return /*#__PURE__*/_react["default"].createElement("a", {
|
|
129
92
|
key: index,
|
|
130
|
-
className: "dropdown-item".concat(selectedValue && selectedValue.id ===
|
|
93
|
+
className: "dropdown-item".concat(selectedValue && selectedValue.id === value.id ? " active" : ""),
|
|
131
94
|
onClick: function onClick() {
|
|
132
|
-
return handleSelection(
|
|
95
|
+
return handleSelection(value);
|
|
133
96
|
},
|
|
134
97
|
style: {
|
|
135
98
|
cursor: "pointer"
|
|
136
99
|
}
|
|
137
|
-
},
|
|
100
|
+
}, value.dropdownText || value.label);
|
|
138
101
|
}), filteredValues.length === 0 && /*#__PURE__*/_react["default"].createElement("div", {
|
|
139
102
|
className: "dropdown-item text-muted"
|
|
140
103
|
}, "No results found")));
|
|
141
|
-
|
|
142
|
-
// If a label is provided, wrap the dropdown with the label inside a container.
|
|
143
|
-
return label && showLabel ? /*#__PURE__*/_react["default"].createElement(_util["default"].Col, null, /*#__PURE__*/_react["default"].createElement("label", {
|
|
144
|
-
className: "form-label"
|
|
145
|
-
}, label), dropdownContent) : dropdownContent;
|
|
146
104
|
};
|
|
147
105
|
DropdownInput.propTypes = {
|
|
148
106
|
prompt: _propTypes["default"].string.isRequired,
|
|
@@ -150,23 +108,45 @@ DropdownInput.propTypes = {
|
|
|
150
108
|
id: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]).isRequired,
|
|
151
109
|
label: _propTypes["default"].string.isRequired,
|
|
152
110
|
dropdownText: _propTypes["default"].string
|
|
153
|
-
})),
|
|
154
|
-
items: _propTypes["default"].arrayOf(_propTypes["default"].shape({
|
|
155
|
-
id: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]).isRequired,
|
|
156
|
-
label: _propTypes["default"].string.isRequired,
|
|
157
|
-
dropdownText: _propTypes["default"].string
|
|
158
|
-
})),
|
|
111
|
+
})).isRequired,
|
|
159
112
|
value: _propTypes["default"].oneOfType([_propTypes["default"].shape({
|
|
160
113
|
id: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]).isRequired
|
|
161
114
|
}), _propTypes["default"].string, _propTypes["default"].number]),
|
|
162
115
|
onChange: _propTypes["default"].func.isRequired,
|
|
163
|
-
aprops: _propTypes["default"].object,
|
|
164
|
-
showSearch: _propTypes["default"].bool,
|
|
165
|
-
loading: _propTypes["default"].bool,
|
|
166
|
-
disabled: _propTypes["default"].bool,
|
|
167
|
-
disabledText: _propTypes["default"].string,
|
|
168
|
-
label: _propTypes["default"].string,
|
|
169
|
-
showLabel: _propTypes["default"].bool,
|
|
170
116
|
color: _propTypes["default"].string,
|
|
171
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)));
|
|
172
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
|
-
##
|