@rpg-engine/long-bow 0.5.83 → 0.5.85

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.83",
3
+ "version": "0.5.85",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -0,0 +1,33 @@
1
+ import React, { useState } from 'react';
2
+
3
+ export interface ICheckItemProps {
4
+ label: string;
5
+ value: string;
6
+ onChange: (label: string, selected: boolean) => void;
7
+ }
8
+
9
+ export const CheckItem: React.FC<ICheckItemProps> = ({
10
+ label,
11
+ value,
12
+ onChange,
13
+ }) => {
14
+ const [selected, setSelected] = useState(false);
15
+
16
+ const handleClick = () => {
17
+ setSelected(!selected);
18
+ onChange(label, !selected);
19
+ };
20
+
21
+ return (
22
+ <div key={value}>
23
+ <input
24
+ className="rpgui-checkbox"
25
+ type="checkbox"
26
+ checked={selected}
27
+ onChange={() => {}}
28
+ />
29
+ <label onPointerDown={handleClick}>{label}</label>
30
+ <br />
31
+ </div>
32
+ );
33
+ };
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useRef, useState } from 'react';
1
+ import React, { useCallback, useEffect, useRef, useState } from 'react';
2
2
  import styled from 'styled-components';
3
3
  import { v4 as uuidv4 } from 'uuid';
4
4
 
@@ -14,58 +14,63 @@ export interface IRangeSliderProps {
14
14
  width: string;
15
15
  onChange: (value: number) => void;
16
16
  value: number;
17
+ step?: number;
17
18
  }
18
19
 
19
- export const RangeSlider: React.FC<IRangeSliderProps> = ({
20
- type,
21
- valueMin,
22
- valueMax,
23
- width,
24
- onChange,
25
- value,
26
- }) => {
27
- const sliderId = uuidv4();
20
+ export const RangeSlider: React.FC<IRangeSliderProps> = React.memo(
21
+ ({ type, valueMin, valueMax, width, onChange, value, step = 1 }) => {
22
+ const sliderId = uuidv4();
28
23
 
29
- const containerRef = useRef<HTMLDivElement>(null);
30
- const [left, setLeft] = useState(0);
24
+ const containerRef = useRef<HTMLDivElement>(null);
25
+ const [left, setLeft] = useState(0);
31
26
 
32
- useEffect(() => {
33
- const calculatedWidth = containerRef.current?.clientWidth || 0;
34
- setLeft(
35
- Math.max(
36
- ((value - valueMin) / (valueMax - valueMin)) * (calculatedWidth - 35) +
37
- 10
38
- )
39
- );
40
- }, [value, valueMin, valueMax]);
27
+ useEffect(() => {
28
+ const calculatedWidth = containerRef.current?.clientWidth || 0;
29
+ setLeft(
30
+ Math.max(
31
+ ((value - valueMin) / (valueMax - valueMin)) *
32
+ (calculatedWidth - 35) +
33
+ 10
34
+ )
35
+ );
36
+ }, [value, valueMin, valueMax]);
37
+
38
+ const typeClass = type === RangeSliderType.GoldSlider ? 'golden' : '';
41
39
 
42
- const typeClass = type === RangeSliderType.GoldSlider ? 'golden' : '';
40
+ const handleChange = useCallback(
41
+ (e: { target: { value: any } }) => {
42
+ onChange(Number(e.target.value));
43
+ },
44
+ [onChange]
45
+ );
43
46
 
44
- return (
45
- <div
46
- style={{ width: width, position: 'relative' }}
47
- className={`rpgui-slider-container ${typeClass}`}
48
- id={`rpgui-slider-${sliderId}`}
49
- ref={containerRef}
50
- >
51
- <div style={{ pointerEvents: 'none' }}>
52
- <div className={`rpgui-slider-track ${typeClass}`} />
53
- <div className={`rpgui-slider-left-edge ${typeClass}`} />
54
- <div className={`rpgui-slider-right-edge ${typeClass}`} />
55
- <div className={`rpgui-slider-thumb ${typeClass}`} style={{ left }} />
47
+ return (
48
+ <div
49
+ style={{ width: width, position: 'relative' }}
50
+ className={`rpgui-slider-container ${typeClass}`}
51
+ id={`rpgui-slider-${sliderId}`}
52
+ ref={containerRef}
53
+ >
54
+ <div style={{ pointerEvents: 'none' }}>
55
+ <div className={`rpgui-slider-track ${typeClass}`} />
56
+ <div className={`rpgui-slider-left-edge ${typeClass}`} />
57
+ <div className={`rpgui-slider-right-edge ${typeClass}`} />
58
+ <div className={`rpgui-slider-thumb ${typeClass}`} style={{ left }} />
59
+ </div>
60
+ <Input
61
+ type="range"
62
+ style={{ width: width }}
63
+ min={valueMin}
64
+ max={valueMax}
65
+ step={step}
66
+ onChange={handleChange}
67
+ value={value}
68
+ className="rpgui-cursor-point"
69
+ />
56
70
  </div>
57
- <Input
58
- type="range"
59
- style={{ width: width }}
60
- min={valueMin}
61
- max={valueMax}
62
- onChange={e => onChange(Number(e.target.value))}
63
- value={value}
64
- className="rpgui-cursor-point"
65
- />
66
- </div>
67
- );
68
- };
71
+ );
72
+ }
73
+ );
69
74
 
70
75
  const Input = styled.input`
71
76
  opacity: 0;
package/src/index.tsx CHANGED
@@ -5,6 +5,7 @@ export * from './components/Chat/Chat';
5
5
  export * from './components/ChatRevamp/ChatRevamp';
6
6
  export * from './components/Chatdeprecated/ChatDeprecated';
7
7
  export * from './components/CheckButton';
8
+ export * from './components/CheckItem';
8
9
  export * from './components/CircularController/CircularController';
9
10
  export * from './components/CraftBook/CraftBook';
10
11
  export * from './components/DraggableContainer';
@@ -61,4 +61,5 @@ Default.args = {
61
61
  type: RangeSliderType.Slider,
62
62
  valueMin: 0,
63
63
  valueMax: 100,
64
+ step: 0.5,
64
65
  };