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