@rpg-engine/long-bow 0.1.794 → 0.2.2
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/LICENSE +20 -20
- package/README.md +181 -181
- package/dist/components/Button.d.ts +1 -0
- package/dist/components/Equipment/EquipmentSet.d.ts +5 -3
- package/dist/components/Item/Cards/ItemTooltip.d.ts +6 -0
- package/dist/components/Item/Inventory/ItemContainer.d.ts +4 -6
- package/dist/components/Item/Inventory/ItemContainerTypes.d.ts +6 -0
- package/dist/components/Item/Inventory/ItemSlot.d.ts +5 -9
- package/dist/components/Item/Inventory/itemContainerHelper.d.ts +2 -7
- package/dist/components/PropertySelect/PropertySelect.d.ts +12 -0
- package/dist/components/QuestInfo/QuestInfo.d.ts +14 -0
- package/dist/components/RelativeListMenu.d.ts +13 -0
- package/dist/index.d.ts +1 -1
- package/dist/long-bow.cjs.development.js +748 -1194
- package/dist/long-bow.cjs.development.js.map +1 -1
- package/dist/long-bow.cjs.production.min.js +1 -1
- package/dist/long-bow.cjs.production.min.js.map +1 -1
- package/dist/long-bow.esm.js +748 -1196
- package/dist/long-bow.esm.js.map +1 -1
- package/dist/mocks/equipmentSet.mocks.d.ts +2 -2
- package/dist/stories/Button.stories.d.ts +5 -0
- package/dist/stories/Chat.stories.d.ts +5 -0
- package/dist/stories/CheckButton.stories.d.ts +5 -0
- package/dist/stories/DraggableContainer.stories.d.ts +5 -0
- package/dist/stories/Dropdown.stories.d.ts +5 -0
- package/dist/stories/EquipmentSet.stories.d.ts +5 -0
- package/dist/stories/ItemContainer.stories.d.ts +5 -0
- package/dist/stories/ListMenu.stories.d.ts +5 -0
- package/dist/stories/Multitab.stories.d.ts +6 -0
- package/dist/stories/NPCDialog.stories.d.ts +7 -0
- package/dist/stories/ProgressBar.stories.d.ts +8 -0
- package/dist/stories/PropertySelect.stories.d.ts +5 -0
- package/dist/stories/QuestInfo.stories.d.ts +5 -0
- package/dist/stories/RPGUIContainers.stories.d.ts +5 -0
- package/dist/stories/RadioButton.stories.d.ts +5 -0
- package/dist/stories/RangeSlider.stories.d.ts +5 -0
- package/dist/stories/ScrollList.stories.d.ts +5 -0
- package/dist/stories/SimpleProgressBar.stories.d.ts +5 -0
- package/dist/stories/SkillProgressBar.stories.d.ts +5 -0
- package/dist/stories/SkillsContainer.stories.d.ts +5 -0
- package/dist/stories/Text.stories.d.ts +7 -0
- package/package.json +98 -96
- package/src/components/Abstractions/SlotsContainer.tsx +42 -42
- package/src/components/Button.tsx +30 -29
- package/src/components/Chat/Chat.tsx +193 -193
- package/src/components/CheckButton.tsx +65 -65
- package/src/components/DraggableContainer.tsx +150 -150
- package/src/components/Dropdown.tsx +57 -57
- package/src/components/Equipment/EquipmentSet.tsx +138 -180
- package/src/components/Input.tsx +11 -11
- package/src/components/Item/Cards/ItemTooltip.tsx +32 -0
- package/src/components/Item/Inventory/ItemContainer.tsx +68 -113
- package/src/components/Item/Inventory/ItemContainerTypes.ts +6 -0
- package/src/components/Item/Inventory/ItemSlot.tsx +212 -158
- package/src/components/Item/Inventory/itemContainerHelper.ts +146 -81
- package/src/components/ListMenu.tsx +65 -65
- package/src/components/Multitab/Tab.tsx +57 -57
- package/src/components/Multitab/TabBody.tsx +13 -13
- package/src/components/Multitab/TabsContainer.tsx +97 -97
- package/src/components/NPCDialog/NPCDialog.tsx +145 -145
- package/src/components/NPCDialog/NPCDialogText.tsx +53 -53
- package/src/components/NPCDialog/QuestionDialog/QuestionDialog.tsx +237 -242
- package/src/components/ProgressBar.tsx +91 -91
- package/src/components/PropertySelect/PropertySelect.tsx +101 -0
- package/src/components/PropertySelect/img/ui-arrows/arrow01-left-clicked.png +0 -0
- package/src/components/PropertySelect/img/ui-arrows/arrow01-left.png +0 -0
- package/src/components/PropertySelect/img/ui-arrows/arrow01-right-clicked.png +0 -0
- package/src/components/PropertySelect/img/ui-arrows/arrow01-right.png +0 -0
- package/src/components/PropertySelect/img/ui-arrows/arrow02-left-clicked.png +0 -0
- package/src/components/PropertySelect/img/ui-arrows/arrow02-left.png +0 -0
- package/src/components/PropertySelect/img/ui-arrows/arrow02-right-clicked.png +0 -0
- package/src/components/PropertySelect/img/ui-arrows/arrow02-right.png +0 -0
- package/src/components/QuestInfo/QuestInfo.tsx +143 -0
- package/src/components/QuestInfo/img/default.png +0 -0
- package/src/components/RPGUIContainer.tsx +47 -47
- package/src/components/RPGUIRoot.tsx +14 -14
- package/src/components/RadioButton.tsx +53 -53
- package/src/components/RangeSlider.tsx +68 -68
- package/src/components/RelativeListMenu.tsx +83 -0
- package/src/components/ScrollList.tsx +77 -77
- package/src/components/SimpleProgressBar.tsx +62 -62
- package/src/components/SkillProgressBar.tsx +123 -124
- package/src/components/SkillsContainer.tsx +196 -235
- package/src/components/TextArea.tsx +11 -11
- package/src/components/Truncate.tsx +25 -25
- package/src/components/shared/Column.tsx +16 -16
- package/src/components/shared/SpriteFromAtlas.tsx +99 -99
- package/src/components/typography/DynamicText.tsx +49 -49
- package/src/constants/uiColors.ts +10 -10
- package/src/hooks/useEventListener.ts +21 -21
- package/src/hooks/useOutsideAlerter.ts +25 -25
- package/src/index.tsx +25 -25
- package/src/libs/StringHelpers.ts +3 -3
- package/src/mocks/atlas/icons/icons.json +735 -303
- package/src/mocks/atlas/icons/icons.png +0 -0
- package/src/mocks/atlas/items/items.json +5215 -5195
- package/src/mocks/atlas/items/items.png +0 -0
- package/src/mocks/equipmentSet.mocks.ts +347 -347
- package/src/mocks/itemContainer.mocks.ts +281 -249
- package/src/mocks/skills.mocks.ts +122 -122
- package/src/stories/Button.stories.tsx +36 -0
- package/src/stories/Chat.stories.tsx +170 -0
- package/src/stories/CheckButton.stories.tsx +48 -0
- package/src/stories/DraggableContainer.stories.tsx +28 -0
- package/src/stories/Dropdown.stories.tsx +46 -0
- package/src/stories/EquipmentSet.stories.tsx +51 -0
- package/src/stories/ItemContainer.stories.tsx +51 -0
- package/src/stories/ListMenu.stories.tsx +56 -0
- package/src/stories/Multitab.stories.tsx +51 -0
- package/src/stories/NPCDialog.stories.tsx +130 -0
- package/src/stories/ProgressBar.stories.tsx +23 -0
- package/src/stories/PropertySelect.stories.tsx +41 -0
- package/src/stories/QuestInfo.stories.tsx +76 -0
- package/src/stories/RPGUIContainers.stories.tsx +42 -0
- package/src/stories/RadioButton.stories.tsx +49 -0
- package/src/stories/RangeSlider.stories.tsx +60 -0
- package/src/stories/ScrollList.stories.tsx +85 -0
- package/src/stories/SimpleProgressBar.stories.tsx +22 -0
- package/src/stories/SkillProgressBar.stories.tsx +30 -0
- package/src/stories/SkillsContainer.stories.tsx +31 -0
- package/src/stories/Text.stories.tsx +42 -0
- package/src/types/eventTypes.ts +4 -4
- package/src/types/index.d.ts +2 -2
- package/dist/components/Item/Cards/ItemCard.d.ts +0 -9
- package/dist/components/shared/SpriteIcon.d.ts +0 -9
- package/dist/components/store/UI.store.d.ts +0 -38
- package/src/components/Item/Cards/ItemCard.tsx +0 -36
- package/src/components/shared/SpriteIcon.tsx +0 -67
- package/src/components/store/UI.store.ts +0 -232
|
@@ -1,150 +1,150 @@
|
|
|
1
|
-
import React, { useEffect, useRef } from 'react';
|
|
2
|
-
import Draggable, { DraggableData } from 'react-draggable';
|
|
3
|
-
import styled from 'styled-components';
|
|
4
|
-
import { useOutsideClick } from '../hooks/useOutsideAlerter';
|
|
5
|
-
import { IPosition } from '../types/eventTypes';
|
|
6
|
-
import { RPGUIContainerTypes } from './RPGUIContainer';
|
|
7
|
-
|
|
8
|
-
export interface IDraggableContainerProps {
|
|
9
|
-
children: React.ReactNode;
|
|
10
|
-
width?: string;
|
|
11
|
-
height?: string;
|
|
12
|
-
className?: string;
|
|
13
|
-
type?: RPGUIContainerTypes;
|
|
14
|
-
title?: string;
|
|
15
|
-
imgSrc?: string;
|
|
16
|
-
imgWidth?: string;
|
|
17
|
-
onCloseButton?: () => void;
|
|
18
|
-
cancelDrag?: string;
|
|
19
|
-
onPositionChange?: (position: IPosition) => void;
|
|
20
|
-
onOutsideClick?: () => void;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const DraggableContainer: React.FC<IDraggableContainerProps> = ({
|
|
24
|
-
children,
|
|
25
|
-
width = '50%',
|
|
26
|
-
height,
|
|
27
|
-
className,
|
|
28
|
-
type = RPGUIContainerTypes.FramedGold,
|
|
29
|
-
onCloseButton,
|
|
30
|
-
title,
|
|
31
|
-
imgSrc,
|
|
32
|
-
imgWidth = '20px',
|
|
33
|
-
cancelDrag,
|
|
34
|
-
onPositionChange,
|
|
35
|
-
onOutsideClick,
|
|
36
|
-
}) => {
|
|
37
|
-
const draggableRef = useRef(null);
|
|
38
|
-
|
|
39
|
-
useOutsideClick(draggableRef, 'item-container');
|
|
40
|
-
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
document.addEventListener('clickOutside', event => {
|
|
43
|
-
const e = event as CustomEvent;
|
|
44
|
-
|
|
45
|
-
if (e.detail.id === 'item-container') {
|
|
46
|
-
if (onOutsideClick) {
|
|
47
|
-
onOutsideClick();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
return () => {
|
|
53
|
-
document.removeEventListener('clickOutside', _e => {});
|
|
54
|
-
};
|
|
55
|
-
}, []);
|
|
56
|
-
|
|
57
|
-
return (
|
|
58
|
-
<Draggable
|
|
59
|
-
cancel={`.container-close,${cancelDrag}`}
|
|
60
|
-
onDrag={(_e, data: DraggableData) => {
|
|
61
|
-
if (onPositionChange) {
|
|
62
|
-
onPositionChange({
|
|
63
|
-
x: data.x,
|
|
64
|
-
y: data.y,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}}
|
|
68
|
-
>
|
|
69
|
-
<Container
|
|
70
|
-
ref={draggableRef}
|
|
71
|
-
width={width}
|
|
72
|
-
height={height || 'auto'}
|
|
73
|
-
className={`rpgui-container ${type} ${className}`}
|
|
74
|
-
>
|
|
75
|
-
{title && (
|
|
76
|
-
<TitleContainer className="drag-handler">
|
|
77
|
-
<Title>
|
|
78
|
-
{imgSrc && <Icon src={imgSrc} width={imgWidth} />}
|
|
79
|
-
{title}
|
|
80
|
-
</Title>
|
|
81
|
-
</TitleContainer>
|
|
82
|
-
)}
|
|
83
|
-
{onCloseButton && (
|
|
84
|
-
<CloseButton
|
|
85
|
-
className="container-close"
|
|
86
|
-
onClick={onCloseButton}
|
|
87
|
-
onTouchStart={onCloseButton}
|
|
88
|
-
>
|
|
89
|
-
X
|
|
90
|
-
</CloseButton>
|
|
91
|
-
)}
|
|
92
|
-
|
|
93
|
-
{children}
|
|
94
|
-
</Container>
|
|
95
|
-
</Draggable>
|
|
96
|
-
);
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
interface IContainerProps {
|
|
100
|
-
width: string;
|
|
101
|
-
height: string;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const Container = styled.div<IContainerProps>`
|
|
105
|
-
height: ${props => props.height};
|
|
106
|
-
width: ${({ width }) => width};
|
|
107
|
-
display: flex;
|
|
108
|
-
flex-wrap: wrap;
|
|
109
|
-
image-rendering: pixelated;
|
|
110
|
-
|
|
111
|
-
&.rpgui-container {
|
|
112
|
-
padding-top: 1.5rem;
|
|
113
|
-
}
|
|
114
|
-
`;
|
|
115
|
-
|
|
116
|
-
const CloseButton = styled.div`
|
|
117
|
-
position: absolute;
|
|
118
|
-
top: 3px;
|
|
119
|
-
right: 0px;
|
|
120
|
-
color: white;
|
|
121
|
-
z-index: 22;
|
|
122
|
-
font-size: 0.8rem;
|
|
123
|
-
`;
|
|
124
|
-
|
|
125
|
-
const TitleContainer = styled.div`
|
|
126
|
-
width: 100%;
|
|
127
|
-
height: 100%;
|
|
128
|
-
display: flex;
|
|
129
|
-
flex-wrap: wrap;
|
|
130
|
-
justify-content: flex-start;
|
|
131
|
-
align-items: center;
|
|
132
|
-
`;
|
|
133
|
-
|
|
134
|
-
const Title = styled.h1`
|
|
135
|
-
color: white;
|
|
136
|
-
z-index: 22;
|
|
137
|
-
font-size: 0.6rem;
|
|
138
|
-
`;
|
|
139
|
-
|
|
140
|
-
interface ICustomIconProps {
|
|
141
|
-
width: string;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const Icon = styled.img`
|
|
145
|
-
color: white;
|
|
146
|
-
z-index: 22;
|
|
147
|
-
font-size: 10px;
|
|
148
|
-
width: ${(props: ICustomIconProps) => props.width};
|
|
149
|
-
margin-right: 0.5rem;
|
|
150
|
-
`;
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
import Draggable, { DraggableData } from 'react-draggable';
|
|
3
|
+
import styled from 'styled-components';
|
|
4
|
+
import { useOutsideClick } from '../hooks/useOutsideAlerter';
|
|
5
|
+
import { IPosition } from '../types/eventTypes';
|
|
6
|
+
import { RPGUIContainerTypes } from './RPGUIContainer';
|
|
7
|
+
|
|
8
|
+
export interface IDraggableContainerProps {
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
width?: string;
|
|
11
|
+
height?: string;
|
|
12
|
+
className?: string;
|
|
13
|
+
type?: RPGUIContainerTypes;
|
|
14
|
+
title?: string;
|
|
15
|
+
imgSrc?: string;
|
|
16
|
+
imgWidth?: string;
|
|
17
|
+
onCloseButton?: () => void;
|
|
18
|
+
cancelDrag?: string;
|
|
19
|
+
onPositionChange?: (position: IPosition) => void;
|
|
20
|
+
onOutsideClick?: () => void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const DraggableContainer: React.FC<IDraggableContainerProps> = ({
|
|
24
|
+
children,
|
|
25
|
+
width = '50%',
|
|
26
|
+
height,
|
|
27
|
+
className,
|
|
28
|
+
type = RPGUIContainerTypes.FramedGold,
|
|
29
|
+
onCloseButton,
|
|
30
|
+
title,
|
|
31
|
+
imgSrc,
|
|
32
|
+
imgWidth = '20px',
|
|
33
|
+
cancelDrag,
|
|
34
|
+
onPositionChange,
|
|
35
|
+
onOutsideClick,
|
|
36
|
+
}) => {
|
|
37
|
+
const draggableRef = useRef(null);
|
|
38
|
+
|
|
39
|
+
useOutsideClick(draggableRef, 'item-container');
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
document.addEventListener('clickOutside', event => {
|
|
43
|
+
const e = event as CustomEvent;
|
|
44
|
+
|
|
45
|
+
if (e.detail.id === 'item-container') {
|
|
46
|
+
if (onOutsideClick) {
|
|
47
|
+
onOutsideClick();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return () => {
|
|
53
|
+
document.removeEventListener('clickOutside', _e => {});
|
|
54
|
+
};
|
|
55
|
+
}, []);
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<Draggable
|
|
59
|
+
cancel={`.container-close,${cancelDrag}`}
|
|
60
|
+
onDrag={(_e, data: DraggableData) => {
|
|
61
|
+
if (onPositionChange) {
|
|
62
|
+
onPositionChange({
|
|
63
|
+
x: data.x,
|
|
64
|
+
y: data.y,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}}
|
|
68
|
+
>
|
|
69
|
+
<Container
|
|
70
|
+
ref={draggableRef}
|
|
71
|
+
width={width}
|
|
72
|
+
height={height || 'auto'}
|
|
73
|
+
className={`rpgui-container ${type} ${className}`}
|
|
74
|
+
>
|
|
75
|
+
{title && (
|
|
76
|
+
<TitleContainer className="drag-handler">
|
|
77
|
+
<Title>
|
|
78
|
+
{imgSrc && <Icon src={imgSrc} width={imgWidth} />}
|
|
79
|
+
{title}
|
|
80
|
+
</Title>
|
|
81
|
+
</TitleContainer>
|
|
82
|
+
)}
|
|
83
|
+
{onCloseButton && (
|
|
84
|
+
<CloseButton
|
|
85
|
+
className="container-close"
|
|
86
|
+
onClick={onCloseButton}
|
|
87
|
+
onTouchStart={onCloseButton}
|
|
88
|
+
>
|
|
89
|
+
X
|
|
90
|
+
</CloseButton>
|
|
91
|
+
)}
|
|
92
|
+
|
|
93
|
+
{children}
|
|
94
|
+
</Container>
|
|
95
|
+
</Draggable>
|
|
96
|
+
);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
interface IContainerProps {
|
|
100
|
+
width: string;
|
|
101
|
+
height: string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const Container = styled.div<IContainerProps>`
|
|
105
|
+
height: ${props => props.height};
|
|
106
|
+
width: ${({ width }) => width};
|
|
107
|
+
display: flex;
|
|
108
|
+
flex-wrap: wrap;
|
|
109
|
+
image-rendering: pixelated;
|
|
110
|
+
|
|
111
|
+
&.rpgui-container {
|
|
112
|
+
padding-top: 1.5rem;
|
|
113
|
+
}
|
|
114
|
+
`;
|
|
115
|
+
|
|
116
|
+
const CloseButton = styled.div`
|
|
117
|
+
position: absolute;
|
|
118
|
+
top: 3px;
|
|
119
|
+
right: 0px;
|
|
120
|
+
color: white;
|
|
121
|
+
z-index: 22;
|
|
122
|
+
font-size: 0.8rem;
|
|
123
|
+
`;
|
|
124
|
+
|
|
125
|
+
const TitleContainer = styled.div`
|
|
126
|
+
width: 100%;
|
|
127
|
+
height: 100%;
|
|
128
|
+
display: flex;
|
|
129
|
+
flex-wrap: wrap;
|
|
130
|
+
justify-content: flex-start;
|
|
131
|
+
align-items: center;
|
|
132
|
+
`;
|
|
133
|
+
|
|
134
|
+
const Title = styled.h1`
|
|
135
|
+
color: white;
|
|
136
|
+
z-index: 22;
|
|
137
|
+
font-size: 0.6rem;
|
|
138
|
+
`;
|
|
139
|
+
|
|
140
|
+
interface ICustomIconProps {
|
|
141
|
+
width: string;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const Icon = styled.img`
|
|
145
|
+
color: white;
|
|
146
|
+
z-index: 22;
|
|
147
|
+
font-size: 10px;
|
|
148
|
+
width: ${(props: ICustomIconProps) => props.width};
|
|
149
|
+
margin-right: 0.5rem;
|
|
150
|
+
`;
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react';
|
|
2
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
-
import { _RPGUI } from './RPGUIRoot';
|
|
4
|
-
|
|
5
|
-
export interface IOptionsProps {
|
|
6
|
-
id: number;
|
|
7
|
-
value: string;
|
|
8
|
-
option: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface IDropdownProps {
|
|
12
|
-
options: IOptionsProps[];
|
|
13
|
-
width?: string;
|
|
14
|
-
onChange: (value: string) => void;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const Dropdown: React.FC<IDropdownProps> = ({
|
|
18
|
-
options,
|
|
19
|
-
width,
|
|
20
|
-
onChange,
|
|
21
|
-
}) => {
|
|
22
|
-
const dropdownId = uuidv4();
|
|
23
|
-
|
|
24
|
-
const [selectedValue, setSelectedValue] = useState<string>('');
|
|
25
|
-
|
|
26
|
-
useEffect(() => {
|
|
27
|
-
const element = document.getElementById(`rpgui-dropdown-${dropdownId}`);
|
|
28
|
-
const dropdownValue = _RPGUI.get_value(element);
|
|
29
|
-
setSelectedValue(dropdownValue);
|
|
30
|
-
|
|
31
|
-
element?.addEventListener('change', (event: any) => {
|
|
32
|
-
setSelectedValue(event?.target.value);
|
|
33
|
-
});
|
|
34
|
-
}, []);
|
|
35
|
-
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
if (selectedValue) {
|
|
38
|
-
onChange(selectedValue);
|
|
39
|
-
}
|
|
40
|
-
}, [selectedValue]);
|
|
41
|
-
|
|
42
|
-
return (
|
|
43
|
-
<select
|
|
44
|
-
id={`rpgui-dropdown-${dropdownId}`}
|
|
45
|
-
style={{ width: width }}
|
|
46
|
-
className="rpgui-dropdown"
|
|
47
|
-
>
|
|
48
|
-
{options.map(option => {
|
|
49
|
-
return (
|
|
50
|
-
<option key={option.id} value={option.value}>
|
|
51
|
-
{option.option}
|
|
52
|
-
</option>
|
|
53
|
-
);
|
|
54
|
-
})}
|
|
55
|
-
</select>
|
|
56
|
-
);
|
|
57
|
-
};
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
+
import { _RPGUI } from './RPGUIRoot';
|
|
4
|
+
|
|
5
|
+
export interface IOptionsProps {
|
|
6
|
+
id: number;
|
|
7
|
+
value: string;
|
|
8
|
+
option: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface IDropdownProps {
|
|
12
|
+
options: IOptionsProps[];
|
|
13
|
+
width?: string;
|
|
14
|
+
onChange: (value: string) => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const Dropdown: React.FC<IDropdownProps> = ({
|
|
18
|
+
options,
|
|
19
|
+
width,
|
|
20
|
+
onChange,
|
|
21
|
+
}) => {
|
|
22
|
+
const dropdownId = uuidv4();
|
|
23
|
+
|
|
24
|
+
const [selectedValue, setSelectedValue] = useState<string>('');
|
|
25
|
+
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
const element = document.getElementById(`rpgui-dropdown-${dropdownId}`);
|
|
28
|
+
const dropdownValue = _RPGUI.get_value(element);
|
|
29
|
+
setSelectedValue(dropdownValue);
|
|
30
|
+
|
|
31
|
+
element?.addEventListener('change', (event: any) => {
|
|
32
|
+
setSelectedValue(event?.target.value);
|
|
33
|
+
});
|
|
34
|
+
}, []);
|
|
35
|
+
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
if (selectedValue) {
|
|
38
|
+
onChange(selectedValue);
|
|
39
|
+
}
|
|
40
|
+
}, [selectedValue]);
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<select
|
|
44
|
+
id={`rpgui-dropdown-${dropdownId}`}
|
|
45
|
+
style={{ width: width }}
|
|
46
|
+
className="rpgui-dropdown"
|
|
47
|
+
>
|
|
48
|
+
{options.map(option => {
|
|
49
|
+
return (
|
|
50
|
+
<option key={option.id} value={option.value}>
|
|
51
|
+
{option.option}
|
|
52
|
+
</option>
|
|
53
|
+
);
|
|
54
|
+
})}
|
|
55
|
+
</select>
|
|
56
|
+
);
|
|
57
|
+
};
|