@rpg-engine/long-bow 0.5.60 → 0.5.62

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.
@@ -8,5 +8,6 @@ export interface IDropdownProps {
8
8
  options: IOptionsProps[];
9
9
  width?: string;
10
10
  onChange: (value: string) => void;
11
+ defaultValue?: string;
11
12
  }
12
13
  export declare const Dropdown: React.FC<IDropdownProps>;
@@ -17,7 +17,6 @@ var ReactDOM = _interopDefault(require('react-dom'));
17
17
  var lodash = require('lodash');
18
18
  var mobxReactLite = require('mobx-react-lite');
19
19
  var uuid = require('uuid');
20
- var reactSpinners = require('react-spinners');
21
20
  var ai = require('react-icons/ai');
22
21
  require('rpgui/rpgui.css');
23
22
  require('rpgui/rpgui.min.js');
@@ -14798,33 +14797,55 @@ var ItemTypes = /*#__PURE__*/styled__default.div.withConfig({
14798
14797
  })(["display:flex;overflow-y:scroll;overflow-x:hidden;width:max-content;flex-direction:column;padding-right:5px;@media (max-width:", "){overflow-x:scroll;overflow-y:hidden;padding-right:0;width:100%;}"], mobilePortrait.width);
14799
14798
 
14800
14799
  var Dropdown = function Dropdown(_ref) {
14801
- var _options$, _options$2;
14802
14800
  var options = _ref.options,
14803
14801
  width = _ref.width,
14804
- onChange = _ref.onChange;
14802
+ onChange = _ref.onChange,
14803
+ defaultValue = _ref.defaultValue;
14805
14804
  var dropdownId = uuid.v4();
14806
- var _useState = React.useState(options == null ? void 0 : (_options$ = options[0]) == null ? void 0 : _options$.value),
14805
+ var _useState = React.useState(defaultValue || ''),
14807
14806
  selectedValue = _useState[0],
14808
14807
  setSelectedValue = _useState[1];
14809
- var _useState2 = React.useState(options == null ? void 0 : (_options$2 = options[0]) == null ? void 0 : _options$2.option),
14808
+ var _useState2 = React.useState(''),
14810
14809
  selectedOption = _useState2[0],
14811
14810
  setSelectedOption = _useState2[1];
14812
14811
  var _useState3 = React.useState(false),
14813
14812
  opened = _useState3[0],
14814
14813
  setOpened = _useState3[1];
14815
14814
  React.useEffect(function () {
14816
- if ((options == null ? void 0 : options.length) > 0) {
14817
- setSelectedValue(options[0].value);
14818
- setSelectedOption(options[0].option);
14815
+ var firstOption = options[0];
14816
+ if (firstOption) {
14817
+ var change = !selectedValue;
14818
+ if (!change) {
14819
+ change = options.filter(function (o) {
14820
+ return o.value === selectedValue;
14821
+ }).length < 1;
14822
+ }
14823
+ /**
14824
+ * make a selection if there is no selected value already present
14825
+ * or if there is a selected value but its not in new options
14826
+ */
14827
+ if (change) {
14828
+ setSelectedValue(firstOption.value);
14829
+ setSelectedOption(firstOption.option);
14830
+ }
14819
14831
  }
14820
14832
  }, [options]);
14821
- var handleSelection = function handleSelection(value, option) {
14822
- if (value !== selectedValue) {
14823
- setSelectedValue(value);
14824
- setSelectedOption(option);
14825
- onChange(value);
14833
+ React.useEffect(function () {
14834
+ if (defaultValue) {
14835
+ var option = options.find(function (o) {
14836
+ return o.value === defaultValue;
14837
+ });
14838
+ if (option) {
14839
+ setSelectedValue(option.value);
14840
+ setSelectedOption(option.option);
14841
+ }
14826
14842
  }
14827
- };
14843
+ }, [defaultValue]);
14844
+ React.useEffect(function () {
14845
+ if (selectedValue) {
14846
+ onChange(selectedValue);
14847
+ }
14848
+ }, [selectedValue]);
14828
14849
  return React__default.createElement(Container$d, {
14829
14850
  onMouseLeave: function onMouseLeave() {
14830
14851
  return setOpened(false);
@@ -14838,43 +14859,33 @@ var Dropdown = function Dropdown(_ref) {
14838
14859
  return !prev;
14839
14860
  });
14840
14861
  }
14841
- }, React__default.createElement(DropdownDisplay, null, React__default.createElement(DropdownLabel, null, "\u25BC"), " ", selectedOption, !options.length && React__default.createElement(reactSpinners.BeatLoader, {
14842
- size: 4,
14843
- color: uiColors.white
14844
- }))), React__default.createElement(DropdownOptions, {
14862
+ }, React__default.createElement("label", null, "\u25BC"), " ", selectedOption), React__default.createElement(DropdownOptions, {
14845
14863
  className: "rpgui-dropdown-imp",
14846
14864
  opened: opened
14847
- }, options == null ? void 0 : options.map(function (option) {
14865
+ }, options.map(function (option) {
14848
14866
  return React__default.createElement("li", {
14849
14867
  key: option.id,
14850
14868
  onPointerUp: function onPointerUp() {
14851
- handleSelection(option.value, option.option);
14869
+ setSelectedValue(option.value);
14870
+ setSelectedOption(option.option);
14852
14871
  setOpened(false);
14853
14872
  }
14854
14873
  }, option.option);
14855
14874
  })));
14856
14875
  };
14857
- var DropdownDisplay = /*#__PURE__*/styled__default.span.withConfig({
14858
- displayName: "Dropdown__DropdownDisplay",
14859
- componentId: "sc-8arn65-0"
14860
- })(["display:flex;flex-wrap:wrap;justify-content:start;align-items:center;"]);
14861
- var DropdownLabel = /*#__PURE__*/styled__default.label.withConfig({
14862
- displayName: "Dropdown__DropdownLabel",
14863
- componentId: "sc-8arn65-1"
14864
- })(["margin-right:0.5rem;"]);
14865
14876
  var Container$d = /*#__PURE__*/styled__default.div.withConfig({
14866
14877
  displayName: "Dropdown__Container",
14867
- componentId: "sc-8arn65-2"
14878
+ componentId: "sc-8arn65-0"
14868
14879
  })(["position:relative;width:", ";"], function (props) {
14869
14880
  return props.width || '100%';
14870
14881
  });
14871
14882
  var DropdownSelect = /*#__PURE__*/styled__default.p.withConfig({
14872
14883
  displayName: "Dropdown__DropdownSelect",
14873
- componentId: "sc-8arn65-3"
14884
+ componentId: "sc-8arn65-1"
14874
14885
  })(["width:100%;box-sizing:border-box;label{display:inline-block;transform:translateY(-2px);}"]);
14875
14886
  var DropdownOptions = /*#__PURE__*/styled__default.ul.withConfig({
14876
14887
  displayName: "Dropdown__DropdownOptions",
14877
- componentId: "sc-8arn65-4"
14888
+ componentId: "sc-8arn65-2"
14878
14889
  })(["position:absolute;width:100%;max-height:300px;overflow-y:auto;display:", ";box-sizing:border-box;@media (max-width:768px){padding:8px 0;}"], function (props) {
14879
14890
  return props.opened ? 'block' : 'none';
14880
14891
  });