@rpg-engine/long-bow 0.5.60 → 0.5.61

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.60",
3
+ "version": "0.5.61",
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",
@@ -14,29 +14,38 @@ export interface IDropdownProps {
14
14
  options: IOptionsProps[];
15
15
  width?: string;
16
16
  onChange: (value: string) => void;
17
+ defaultValue?: string;
17
18
  }
18
19
 
19
20
  export const Dropdown: React.FC<IDropdownProps> = ({
20
21
  options,
21
22
  width,
22
23
  onChange,
24
+ defaultValue,
23
25
  }) => {
24
26
  const dropdownId = uuidv4();
25
27
 
26
28
  const [selectedValue, setSelectedValue] = useState<string>(
27
- options?.[0]?.value
29
+ defaultValue || options?.[0]?.value
28
30
  );
29
31
  const [selectedOption, setSelectedOption] = useState<string | JSX.Element>(
30
- options?.[0]?.option
32
+ options?.find(option => option.value === defaultValue)?.option ||
33
+ options?.[0]?.option
31
34
  );
32
35
  const [opened, setOpened] = useState<boolean>(false);
33
36
 
34
37
  useEffect(() => {
35
- if (options?.length > 0) {
38
+ if (defaultValue) {
39
+ setSelectedValue(defaultValue);
40
+ setSelectedOption(
41
+ //@ts-ignore
42
+ options?.find(option => option.value === defaultValue)?.option
43
+ );
44
+ } else if (options?.length > 0) {
36
45
  setSelectedValue(options[0].value);
37
46
  setSelectedOption(options[0].option);
38
47
  }
39
- }, [options]);
48
+ }, [options, defaultValue]);
40
49
 
41
50
  const handleSelection = (value: string, option: string | JSX.Element) => {
42
51
  if (value !== selectedValue) {
@@ -43,6 +43,7 @@ export const Default = Template.bind({});
43
43
  Default.args = {
44
44
  options: staticOptions,
45
45
  width: '100%',
46
+ defaultValue: 'Orc',
46
47
  };
47
48
 
48
49
  const AsyncTemplate: Story<IDropdownProps> = args => {