@rpg-engine/long-bow 0.7.86 → 0.7.87
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/dist/components/Item/Inventory/ItemQuantitySelectorModal.d.ts +2 -6
- package/dist/components/QuantitySelector/QuantitySelectorModal.d.ts +14 -0
- package/dist/index.d.ts +0 -1
- package/dist/long-bow.cjs.development.js +33 -29
- 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 +34 -29
- package/dist/long-bow.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Item/Inventory/ItemQuantitySelector.tsx +126 -9
- package/src/components/Item/Inventory/ItemQuantitySelectorModal.tsx +7 -45
- package/src/components/QuantitySelector/QuantitySelectorModal.tsx +79 -0
- package/src/index.tsx +0 -1
package/package.json
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
import { Button, ButtonTypes } from '../../Button';
|
|
4
|
+
import { Input } from '../../Input';
|
|
5
|
+
import {
|
|
6
|
+
RPGUIContainer,
|
|
7
|
+
RPGUIContainerTypes,
|
|
8
|
+
} from '../../RPGUI/RPGUIContainer';
|
|
9
|
+
import { RangeSlider, RangeSliderType } from '../../RangeSlider';
|
|
3
10
|
|
|
4
11
|
export interface IItemQuantitySelectorProps {
|
|
5
12
|
quantity: number;
|
|
@@ -12,13 +19,123 @@ export const ItemQuantitySelector: React.FC<IItemQuantitySelectorProps> = ({
|
|
|
12
19
|
onConfirm,
|
|
13
20
|
onClose,
|
|
14
21
|
}) => {
|
|
22
|
+
const [value, setValue] = useState(quantity);
|
|
23
|
+
|
|
24
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
25
|
+
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (inputRef.current) {
|
|
28
|
+
inputRef.current.focus();
|
|
29
|
+
inputRef.current.select();
|
|
30
|
+
|
|
31
|
+
const closeSelector = (e: KeyboardEvent) => {
|
|
32
|
+
if (e.key === 'Escape') {
|
|
33
|
+
onClose();
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
document.addEventListener('keydown', closeSelector);
|
|
38
|
+
|
|
39
|
+
return () => {
|
|
40
|
+
document.removeEventListener('keydown', closeSelector);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return () => {};
|
|
45
|
+
}, []);
|
|
46
|
+
|
|
15
47
|
return (
|
|
16
|
-
<
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
48
|
+
<StyledContainer type={RPGUIContainerTypes.Framed} width="25rem">
|
|
49
|
+
<CloseButton className="container-close" onPointerDown={onClose}>
|
|
50
|
+
X
|
|
51
|
+
</CloseButton>
|
|
52
|
+
<h2>Select quantity to move</h2>
|
|
53
|
+
<StyledForm
|
|
54
|
+
style={{ width: '100%' }}
|
|
55
|
+
onSubmit={e => {
|
|
56
|
+
e.preventDefault();
|
|
57
|
+
|
|
58
|
+
const numberValue = Number(value);
|
|
59
|
+
|
|
60
|
+
if (Number.isNaN(numberValue)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
onConfirm(Math.max(1, Math.min(quantity, numberValue)));
|
|
65
|
+
}}
|
|
66
|
+
noValidate
|
|
67
|
+
>
|
|
68
|
+
<StyledInput
|
|
69
|
+
innerRef={inputRef}
|
|
70
|
+
placeholder="Enter quantity"
|
|
71
|
+
type="number"
|
|
72
|
+
min={1}
|
|
73
|
+
max={quantity}
|
|
74
|
+
value={value}
|
|
75
|
+
onChange={e => {
|
|
76
|
+
if (Number(e.target.value) >= quantity) {
|
|
77
|
+
setValue(quantity);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
setValue((e.target.value as unknown) as number);
|
|
82
|
+
}}
|
|
83
|
+
onBlur={e => {
|
|
84
|
+
const newValue = Math.max(
|
|
85
|
+
1,
|
|
86
|
+
Math.min(quantity, Number(e.target.value))
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
setValue(newValue);
|
|
90
|
+
}}
|
|
91
|
+
/>
|
|
92
|
+
<RangeSlider
|
|
93
|
+
type={RangeSliderType.Slider}
|
|
94
|
+
valueMin={1}
|
|
95
|
+
valueMax={quantity}
|
|
96
|
+
width="100%"
|
|
97
|
+
onChange={setValue}
|
|
98
|
+
value={value}
|
|
99
|
+
/>
|
|
100
|
+
<Button buttonType={ButtonTypes.RPGUIButton} type="submit">
|
|
101
|
+
Confirm
|
|
102
|
+
</Button>
|
|
103
|
+
</StyledForm>
|
|
104
|
+
</StyledContainer>
|
|
23
105
|
);
|
|
24
106
|
};
|
|
107
|
+
|
|
108
|
+
const StyledContainer = styled(RPGUIContainer)`
|
|
109
|
+
display: flex;
|
|
110
|
+
flex-direction: column;
|
|
111
|
+
align-items: center;
|
|
112
|
+
`;
|
|
113
|
+
|
|
114
|
+
const StyledForm = styled.form`
|
|
115
|
+
display: flex;
|
|
116
|
+
flex-direction: column;
|
|
117
|
+
align-items: center;
|
|
118
|
+
width: 100%;
|
|
119
|
+
`;
|
|
120
|
+
const StyledInput = styled(Input)`
|
|
121
|
+
text-align: center;
|
|
122
|
+
|
|
123
|
+
&::-webkit-outer-spin-button,
|
|
124
|
+
&::-webkit-inner-spin-button {
|
|
125
|
+
-webkit-appearance: none;
|
|
126
|
+
margin: 0;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
&[type='number'] {
|
|
130
|
+
-moz-appearance: textfield;
|
|
131
|
+
}
|
|
132
|
+
`;
|
|
133
|
+
|
|
134
|
+
const CloseButton = styled.div`
|
|
135
|
+
position: absolute;
|
|
136
|
+
top: 3px;
|
|
137
|
+
right: 0px;
|
|
138
|
+
color: white;
|
|
139
|
+
z-index: 22;
|
|
140
|
+
font-size: 0.8rem;
|
|
141
|
+
`;
|
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
3
|
-
import ModalPortal from '../../Abstractions/ModalPortal';
|
|
4
|
-
import { ItemQuantitySelector } from './ItemQuantitySelector';
|
|
5
|
-
|
|
6
|
-
export interface IQuantitySelect {
|
|
7
|
-
isOpen: boolean;
|
|
8
|
-
maxQuantity: number;
|
|
9
|
-
callback: (_quantity: number) => void;
|
|
10
|
-
}
|
|
2
|
+
import { IQuantitySelect, QuantitySelectorModal } from '../../QuantitySelector/QuantitySelectorModal';
|
|
11
3
|
|
|
12
4
|
interface IProps {
|
|
13
5
|
quantitySelect: IQuantitySelect;
|
|
@@ -17,43 +9,13 @@ interface IProps {
|
|
|
17
9
|
export const ItemQuantitySelectorModal = ({
|
|
18
10
|
quantitySelect,
|
|
19
11
|
setQuantitySelect,
|
|
20
|
-
}: IProps) => {
|
|
12
|
+
}: IProps): JSX.Element => {
|
|
21
13
|
return (
|
|
22
|
-
<
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
onConfirm={quantity => {
|
|
27
|
-
quantitySelect.callback(quantity);
|
|
28
|
-
setQuantitySelect({
|
|
29
|
-
isOpen: false,
|
|
30
|
-
maxQuantity: 1,
|
|
31
|
-
callback: () => {},
|
|
32
|
-
});
|
|
33
|
-
}}
|
|
34
|
-
onClose={() => {
|
|
35
|
-
quantitySelect.callback(-1);
|
|
36
|
-
setQuantitySelect({
|
|
37
|
-
isOpen: false,
|
|
38
|
-
maxQuantity: 1,
|
|
39
|
-
callback: () => {},
|
|
40
|
-
});
|
|
41
|
-
}}
|
|
42
|
-
/>
|
|
43
|
-
</QuantitySelectorContainer>
|
|
44
|
-
</ModalPortal>
|
|
14
|
+
<QuantitySelectorModal
|
|
15
|
+
quantitySelect={quantitySelect}
|
|
16
|
+
setQuantitySelect={setQuantitySelect}
|
|
17
|
+
/>
|
|
45
18
|
);
|
|
46
19
|
};
|
|
47
20
|
|
|
48
|
-
|
|
49
|
-
position: absolute;
|
|
50
|
-
top: 0;
|
|
51
|
-
left: 0;
|
|
52
|
-
width: 100vw;
|
|
53
|
-
height: 100vh;
|
|
54
|
-
z-index: 100;
|
|
55
|
-
display: flex;
|
|
56
|
-
justify-content: center;
|
|
57
|
-
align-items: center;
|
|
58
|
-
background-color: rgba(0, 0, 0, 0.5);
|
|
59
|
-
`;
|
|
21
|
+
export type { IQuantitySelect };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
import ModalPortal from '../Abstractions/ModalPortal';
|
|
4
|
+
import { QuantitySelector } from './QuantitySelector';
|
|
5
|
+
|
|
6
|
+
export interface IQuantitySelect {
|
|
7
|
+
isOpen: boolean;
|
|
8
|
+
maxQuantity: number;
|
|
9
|
+
callback: (quantity: number) => void;
|
|
10
|
+
title?: string;
|
|
11
|
+
initialQuantity?: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface IProps {
|
|
15
|
+
quantitySelect: IQuantitySelect;
|
|
16
|
+
setQuantitySelect: React.Dispatch<React.SetStateAction<IQuantitySelect>>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const validateQuantitySelect = (
|
|
20
|
+
quantitySelect: IQuantitySelect
|
|
21
|
+
): IQuantitySelect => ({
|
|
22
|
+
...quantitySelect,
|
|
23
|
+
maxQuantity: Math.max(1, quantitySelect.maxQuantity),
|
|
24
|
+
initialQuantity: quantitySelect.initialQuantity
|
|
25
|
+
? Math.max(
|
|
26
|
+
1,
|
|
27
|
+
Math.min(quantitySelect.maxQuantity, quantitySelect.initialQuantity)
|
|
28
|
+
)
|
|
29
|
+
: undefined,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export const QuantitySelectorModal = ({
|
|
33
|
+
quantitySelect,
|
|
34
|
+
setQuantitySelect,
|
|
35
|
+
}: IProps): JSX.Element => {
|
|
36
|
+
const resetQuantitySelect = () => {
|
|
37
|
+
setQuantitySelect({
|
|
38
|
+
isOpen: false,
|
|
39
|
+
maxQuantity: 1,
|
|
40
|
+
callback: () => {},
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// Validate the input values
|
|
45
|
+
const validatedQuantitySelect = validateQuantitySelect(quantitySelect);
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<ModalPortal>
|
|
49
|
+
<QuantitySelectorContainer>
|
|
50
|
+
<QuantitySelector
|
|
51
|
+
maxQuantity={validatedQuantitySelect.maxQuantity}
|
|
52
|
+
initialQuantity={validatedQuantitySelect.initialQuantity}
|
|
53
|
+
title={validatedQuantitySelect.title}
|
|
54
|
+
onConfirm={quantity => {
|
|
55
|
+
validatedQuantitySelect.callback(quantity);
|
|
56
|
+
resetQuantitySelect();
|
|
57
|
+
}}
|
|
58
|
+
onClose={() => {
|
|
59
|
+
validatedQuantitySelect.callback(-1);
|
|
60
|
+
resetQuantitySelect();
|
|
61
|
+
}}
|
|
62
|
+
/>
|
|
63
|
+
</QuantitySelectorContainer>
|
|
64
|
+
</ModalPortal>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const QuantitySelectorContainer = styled.div`
|
|
69
|
+
position: absolute;
|
|
70
|
+
top: 0;
|
|
71
|
+
left: 0;
|
|
72
|
+
width: 100vw;
|
|
73
|
+
height: 100vh;
|
|
74
|
+
z-index: 100;
|
|
75
|
+
display: flex;
|
|
76
|
+
justify-content: center;
|
|
77
|
+
align-items: center;
|
|
78
|
+
background-color: rgba(0, 0, 0, 0.5);
|
|
79
|
+
`;
|
package/src/index.tsx
CHANGED
|
@@ -21,7 +21,6 @@ export * from './components/Input';
|
|
|
21
21
|
export * from './components/InternalTabs/InternalTabs';
|
|
22
22
|
export { ErrorBoundary } from './components/Item/Inventory/ErrorBoundary';
|
|
23
23
|
export * from './components/Item/Inventory/ItemContainer';
|
|
24
|
-
export * from './components/Item/Inventory/ItemQuantitySelectorModal';
|
|
25
24
|
export * from './components/Item/Inventory/ItemSlot';
|
|
26
25
|
export * from './components/itemSelector/ItemSelector';
|
|
27
26
|
export * from './components/Leaderboard/Leaderboard';
|