opus-toolkit-components 0.2.9 → 0.3.0

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.
@@ -9020,33 +9020,41 @@ function Dropdown(_ref) {
9020
9020
  onChange,
9021
9021
  value
9022
9022
  } = _ref;
9023
- const [selectedItem, setSelectedItem] = (0,external_react_.useState)(value); // Initialize to null
9024
-
9023
+ const initialSelectedItem = items.find(item => item.value === value) || null;
9024
+ const [selectedItem, setSelectedItem] = (0,external_react_.useState)(initialSelectedItem);
9025
+ (0,external_react_.useEffect)(() => {
9026
+ const newSelectedItem = items.find(item => item.value === value) || null;
9027
+ setSelectedItem(newSelectedItem);
9028
+ }, [value, items]);
9025
9029
  const inputClasses = `inline-flex w-full justify-center gap-x-1.5 rounded-md bg-white border px-4 py-3 text-md font-normal text-gray-900 ${isValid ? 'border-slate-500' : 'border-rose-500'}`;
9026
9030
  const handleSelect = item => {
9027
- setSelectedItem(item); // Store the whole item
9028
-
9029
- // Create a synthetic event
9031
+ setSelectedItem(item);
9030
9032
  const event = {
9031
9033
  target: {
9032
9034
  name: name,
9033
- value: item.value // Use the value of the selected item
9035
+ value: item.value
9034
9036
  }
9035
9037
  };
9036
- onChange(event); // Pass the synthetic event object
9038
+ onChange(event);
9037
9039
  };
9038
9040
  return /*#__PURE__*/external_react_default().createElement(rn, {
9039
9041
  as: "div",
9040
9042
  className: "relative inline-block text-left",
9041
9043
  name: name
9042
9044
  }, /*#__PURE__*/external_react_default().createElement("label", null, label), /*#__PURE__*/external_react_default().createElement("div", null, /*#__PURE__*/external_react_default().createElement(It, {
9043
- className: inputClasses
9044
- }, selectedItem ? selectedItem.label : placeholder, " ", /*#__PURE__*/external_react_default().createElement(esm_ChevronDownIcon, {
9045
+ className: inputClasses,
9046
+ style: {
9047
+ backgroundColor: 'white'
9048
+ }
9049
+ }, selectedItem ? selectedItem.label : placeholder, /*#__PURE__*/external_react_default().createElement(esm_ChevronDownIcon, {
9045
9050
  "aria-hidden": "true",
9046
9051
  className: "-mr-1 h-5 w-5 text-gray-400"
9047
9052
  }))), /*#__PURE__*/external_react_default().createElement(gt, {
9048
9053
  transition: true,
9049
- className: "absolute right-0 z-10 mt-2 w-56 origin-top-right rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 transition focus:outline-none"
9054
+ className: "absolute right-0 z-10 mt-2 w-56 origin-top-right rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 transition focus:outline-none",
9055
+ style: {
9056
+ backgroundColor: 'white'
9057
+ }
9050
9058
  }, /*#__PURE__*/external_react_default().createElement("div", {
9051
9059
  className: "py-1"
9052
9060
  }, items.map((item, index) => /*#__PURE__*/external_react_default().createElement(Et, {
@@ -9056,15 +9064,13 @@ function Dropdown(_ref) {
9056
9064
  active
9057
9065
  } = _ref2;
9058
9066
  return /*#__PURE__*/external_react_default().createElement("button", {
9059
- type: "button" // Prevent form submission
9060
- ,
9061
- onClick: () => handleSelect(item) // Pass the whole item to handleSelect
9062
- ,
9067
+ type: "button",
9068
+ onClick: () => handleSelect(item),
9063
9069
  className: `block w-full px-4 py-2 text-left text-sm text-gray-700 ${active ? 'bg-gray-100 text-gray-900' : ''}`
9064
9070
  }, item.label);
9065
9071
  })))), !isValid && /*#__PURE__*/external_react_default().createElement("span", {
9066
9072
  className: "text-rose-500 text-sm"
9067
- }));
9073
+ }, "Please select a valid option"));
9068
9074
  }
9069
9075
  ;// ./src/index.js
9070
9076
 
@@ -9079,4 +9085,4 @@ function Dropdown(_ref) {
9079
9085
  /******/ })()
9080
9086
  ;
9081
9087
  });
9082
- //# sourceMappingURL=main.cbe51cd922acdf7e3218.js.map
9088
+ //# sourceMappingURL=main.13234ba8805408d911a7.js.map