@rpg-engine/long-bow 0.5.54 → 0.5.56

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpg-engine/long-bow",
3
- "version": "0.5.54",
3
+ "version": "0.5.56",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -83,7 +83,7 @@
83
83
  },
84
84
  "dependencies": {
85
85
  "@rollup/plugin-image": "^2.1.1",
86
- "@rpg-engine/shared": "^0.9.14",
86
+ "@rpg-engine/shared": "^0.9.19",
87
87
  "dayjs": "^1.11.2",
88
88
  "font-awesome": "^4.7.0",
89
89
  "fs-extra": "^10.1.0",
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useState } from 'react';
1
+ import React, { useState } from 'react';
2
2
  import styled from 'styled-components';
3
3
  import { v4 as uuidv4 } from 'uuid';
4
4
 
@@ -21,37 +21,19 @@ export const Dropdown: React.FC<IDropdownProps> = ({
21
21
  }) => {
22
22
  const dropdownId = uuidv4();
23
23
 
24
- const [selectedValue, setSelectedValue] = useState<string>('');
24
+ const [selectedValue, setSelectedValue] = useState<string>(options[0].value);
25
25
  const [selectedOption, setSelectedOption] = useState<string | JSX.Element>(
26
- ''
26
+ options[0].option
27
27
  );
28
28
  const [opened, setOpened] = useState<boolean>(false);
29
29
 
30
- useEffect(() => {
31
- const firstOption = options[0];
32
-
33
- if (firstOption) {
34
- let change = !selectedValue;
35
- if (!change) {
36
- change = options.filter(o => o.value === selectedValue).length < 1;
37
- }
38
-
39
- /**
40
- * make a selection if there is no selected value already present
41
- * or if there is a selected value but its not in new options
42
- */
43
- if (change) {
44
- setSelectedValue(firstOption.value);
45
- setSelectedOption(firstOption.option);
46
- }
47
- }
48
- }, [options]);
49
-
50
- useEffect(() => {
51
- if (selectedValue) {
52
- onChange(selectedValue);
30
+ const handleSelection = (value: string, option: string | JSX.Element) => {
31
+ if (value !== selectedValue) {
32
+ setSelectedValue(value);
33
+ setSelectedOption(option);
34
+ onChange(value);
53
35
  }
54
- }, [selectedValue]);
36
+ };
55
37
 
56
38
  return (
57
39
  <Container onMouseLeave={() => setOpened(false)} width={width}>
@@ -64,20 +46,17 @@ export const Dropdown: React.FC<IDropdownProps> = ({
64
46
  </DropdownSelect>
65
47
 
66
48
  <DropdownOptions className="rpgui-dropdown-imp" opened={opened}>
67
- {options.map(option => {
68
- return (
69
- <li
70
- key={option.id}
71
- onPointerUp={() => {
72
- setSelectedValue(option.value);
73
- setSelectedOption(option.option);
74
- setOpened(false);
75
- }}
76
- >
77
- {option.option}
78
- </li>
79
- );
80
- })}
49
+ {options.map(option => (
50
+ <li
51
+ key={option.id}
52
+ onPointerUp={() => {
53
+ handleSelection(option.value, option.option);
54
+ setOpened(false);
55
+ }}
56
+ >
57
+ {option.option}
58
+ </li>
59
+ ))}
81
60
  </DropdownOptions>
82
61
  </Container>
83
62
  );