tgui-core 1.1.11 → 1.1.12
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/ProgressBar.module-BkAFfFy0.js +29 -0
- package/dist/Section.module-CLVHJ4yA.js +15 -0
- package/dist/assets/BlockQuote.css +1 -0
- package/dist/assets/Button.css +1 -0
- package/dist/assets/ColorBox.css +1 -0
- package/dist/assets/Dialog.css +1 -0
- package/dist/assets/Dimmer.css +1 -0
- package/dist/assets/Divider.css +1 -0
- package/dist/assets/Flex.css +1 -0
- package/dist/assets/Icon.css +6 -0
- package/dist/assets/Input.css +1 -0
- package/dist/assets/Knob.css +1 -0
- package/dist/assets/LabeledList.css +1 -0
- package/dist/assets/MenuBar.css +1 -0
- package/dist/assets/Modal.css +1 -0
- package/dist/assets/NoticeBox.css +1 -0
- package/dist/assets/NumberInput.css +1 -0
- package/dist/assets/ProgressBar.css +1 -0
- package/dist/assets/RoundGauge.css +1 -0
- package/dist/assets/Section.css +1 -0
- package/dist/assets/Slider.css +1 -0
- package/dist/assets/Stack.css +1 -0
- package/dist/assets/Table.css +1 -0
- package/dist/assets/Tabs.css +1 -0
- package/dist/assets/TextArea.css +1 -0
- package/dist/assets/Tooltip.css +1 -0
- package/dist/common/assets.d.ts +4 -0
- package/dist/common/assets.js +25 -0
- package/dist/common/collections.d.ts +10 -0
- package/dist/common/collections.js +15 -0
- package/dist/common/color.d.ts +25 -0
- package/dist/common/color.js +69 -0
- package/dist/common/constants.d.ts +102 -0
- package/dist/common/constants.js +312 -0
- package/dist/common/events.d.ts +33 -0
- package/dist/common/events.js +147 -0
- package/{lib/common/exhaustive.ts → dist/common/exhaustive.d.ts} +1 -3
- package/dist/common/exhaustive.js +6 -0
- package/dist/common/format.d.ts +11 -0
- package/dist/common/format.js +114 -0
- package/{lib/common/fp.ts → dist/common/fp.d.ts} +2 -16
- package/dist/common/fp.js +9 -0
- package/dist/common/hotkeys.d.ts +25 -0
- package/dist/common/hotkeys.js +112 -0
- package/dist/common/http.d.ts +4 -0
- package/dist/common/http.js +10 -0
- package/dist/common/keycodes.d.ts +85 -0
- package/dist/common/keycodes.js +88 -0
- package/{lib/common/keys.ts → dist/common/keys.d.ts} +21 -24
- package/dist/common/keys.js +8 -0
- package/dist/common/math.d.ts +39 -0
- package/dist/common/math.js +41 -0
- package/dist/common/perf.d.ts +24 -0
- package/dist/common/perf.js +33 -0
- package/dist/common/random.d.ts +16 -0
- package/dist/common/random.js +18 -0
- package/dist/common/react.d.ts +23 -0
- package/dist/common/react.js +30 -0
- package/dist/common/redux.d.ts +64 -0
- package/dist/common/redux.js +72 -0
- package/dist/common/storage.d.ts +24 -0
- package/dist/common/storage.js +133 -0
- package/dist/common/string.d.ts +65 -0
- package/dist/common/string.js +83 -0
- package/dist/common/timer.d.ts +18 -0
- package/dist/common/timer.js +28 -0
- package/dist/common/type-utils.d.ts +9 -0
- package/dist/common/type-utils.js +25 -0
- package/dist/common/uuid.d.ts +9 -0
- package/dist/common/uuid.js +10 -0
- package/dist/components/AnimatedNumber.d.ts +60 -0
- package/dist/components/AnimatedNumber.js +76 -0
- package/dist/components/Autofocus.d.ts +4 -0
- package/dist/components/Autofocus.js +17 -0
- package/dist/components/Blink.d.ts +26 -0
- package/dist/components/Blink.js +56 -0
- package/dist/components/BlockQuote.d.ts +3 -0
- package/dist/components/BlockQuote.js +13 -0
- package/dist/components/BodyZoneSelector.d.ts +28 -0
- package/dist/components/BodyZoneSelector.js +115 -0
- package/dist/components/Box.d.ts +91 -0
- package/dist/components/Box.js +133 -0
- package/dist/components/Button.d.ts +93 -0
- package/dist/components/Button.js +298 -0
- package/dist/components/ByondUi.js +73 -0
- package/dist/components/Chart.d.ts +28 -0
- package/dist/components/Chart.js +95 -0
- package/dist/components/Collapsible.d.ts +15 -0
- package/dist/components/Collapsible.js +27 -0
- package/dist/components/ColorBox.d.ts +8 -0
- package/dist/components/ColorBox.js +24 -0
- package/dist/components/Dialog.d.ts +24 -0
- package/dist/components/Dialog.js +67 -0
- package/dist/components/Dimmer.d.ts +3 -0
- package/dist/components/Dimmer.js +13 -0
- package/dist/components/Divider.d.ts +6 -0
- package/dist/components/Divider.js +22 -0
- package/dist/components/DmIcon.d.ts +31 -0
- package/dist/components/DmIcon.js +29 -0
- package/dist/components/DraggableControl.js +176 -0
- package/dist/components/Dropdown.d.ts +48 -0
- package/dist/components/Dropdown.js +152 -0
- package/dist/components/FakeTerminal.js +38 -0
- package/dist/components/FitText.d.ts +22 -0
- package/dist/components/FitText.js +63 -0
- package/dist/components/Flex.d.ts +93 -0
- package/dist/components/Flex.js +72 -0
- package/dist/components/Icon.d.ts +30 -0
- package/dist/components/Icon.js +51 -0
- package/dist/components/Image.d.ts +14 -0
- package/dist/components/Image.js +35 -0
- package/dist/components/InfinitePlane.js +139 -0
- package/dist/components/Input.d.ts +61 -0
- package/dist/components/Input.js +89 -0
- package/dist/components/KeyListener.d.ts +15 -0
- package/dist/components/KeyListener.js +23 -0
- package/dist/components/Knob.d.ts +49 -0
- package/dist/components/Knob.js +162 -0
- package/dist/components/LabeledControls.d.ts +11 -0
- package/dist/components/LabeledControls.js +39 -0
- package/dist/components/LabeledList.d.ts +57 -0
- package/dist/components/LabeledList.js +94 -0
- package/dist/components/MenuBar.d.ts +28 -0
- package/dist/components/MenuBar.js +174 -0
- package/dist/components/Modal.d.ts +3 -0
- package/dist/components/Modal.js +25 -0
- package/dist/components/NoticeBox.d.ts +20 -0
- package/dist/components/NoticeBox.js +49 -0
- package/dist/components/NumberInput.d.ts +45 -0
- package/dist/components/NumberInput.js +221 -0
- package/dist/components/Popper.d.ts +27 -0
- package/dist/components/Popper.js +177 -0
- package/dist/components/ProgressBar.d.ts +46 -0
- package/dist/components/ProgressBar.js +37 -0
- package/dist/components/RestrictedInput.js +155 -0
- package/dist/components/RoundGauge.d.ts +53 -0
- package/dist/components/RoundGauge.js +147 -0
- package/dist/components/Section.d.ts +63 -0
- package/dist/components/Section.js +62 -0
- package/dist/components/Slider.d.ts +46 -0
- package/dist/components/Slider.js +124 -0
- package/dist/components/Stack.d.ts +27 -0
- package/dist/components/Stack.js +67 -0
- package/dist/components/StyleableSection.d.ts +11 -0
- package/dist/components/StyleableSection.js +16 -0
- package/dist/components/Table.d.ts +29 -0
- package/dist/components/Table.js +67 -0
- package/dist/components/Tabs.d.ts +23 -0
- package/dist/components/Tabs.js +89 -0
- package/dist/components/TextArea.d.ts +39 -0
- package/dist/components/TextArea.js +118 -0
- package/dist/components/TimeDisplay.js +34 -0
- package/dist/components/Tooltip.d.ts +29 -0
- package/dist/components/Tooltip.js +83 -0
- package/dist/components/TrackOutsideClicks.d.ts +13 -0
- package/dist/components/TrackOutsideClicks.js +24 -0
- package/dist/components/VirtualList.d.ts +8 -0
- package/dist/components/VirtualList.js +34 -0
- package/dist/components/index.js +92 -0
- package/dist/popper-CiqSDJTE.js +906 -0
- package/package.json +8 -10
- package/lib/common/assets.ts +0 -38
- package/lib/common/collections.ts +0 -27
- package/lib/common/color.ts +0 -88
- package/lib/common/constants.ts +0 -349
- package/lib/common/events.ts +0 -262
- package/lib/common/format.ts +0 -167
- package/lib/common/hotkeys.ts +0 -207
- package/lib/common/http.ts +0 -16
- package/lib/common/keycodes.ts +0 -86
- package/lib/common/math.ts +0 -76
- package/lib/common/perf.ts +0 -72
- package/lib/common/random.ts +0 -32
- package/lib/common/react.ts +0 -59
- package/lib/common/redux.ts +0 -187
- package/lib/common/storage.ts +0 -207
- package/lib/common/string.ts +0 -169
- package/lib/common/timer.ts +0 -63
- package/lib/common/type-utils.ts +0 -41
- package/lib/common/types.d.ts +0 -12
- package/lib/common/uuid.ts +0 -18
- package/lib/components/AnimatedNumber.tsx +0 -180
- package/lib/components/Autofocus.tsx +0 -23
- package/lib/components/Blink.tsx +0 -91
- package/lib/components/BlockQuote.tsx +0 -9
- package/lib/components/BodyZoneSelector.tsx +0 -149
- package/lib/components/Box.tsx +0 -252
- package/lib/components/Button.tsx +0 -425
- package/lib/components/ByondUi.jsx +0 -110
- package/lib/components/Chart.tsx +0 -155
- package/lib/components/Collapsible.tsx +0 -43
- package/lib/components/ColorBox.tsx +0 -29
- package/lib/components/Dialog.tsx +0 -81
- package/lib/components/Dimmer.tsx +0 -13
- package/lib/components/Divider.tsx +0 -20
- package/lib/components/DmIcon.tsx +0 -86
- package/lib/components/DraggableControl.jsx +0 -276
- package/lib/components/Dropdown.tsx +0 -246
- package/lib/components/FakeTerminal.jsx +0 -52
- package/lib/components/FitText.tsx +0 -99
- package/lib/components/Flex.tsx +0 -159
- package/lib/components/Icon.tsx +0 -95
- package/lib/components/Image.tsx +0 -54
- package/lib/components/InfinitePlane.jsx +0 -192
- package/lib/components/Input.tsx +0 -176
- package/lib/components/KeyListener.tsx +0 -40
- package/lib/components/Knob.tsx +0 -178
- package/lib/components/LabeledControls.tsx +0 -44
- package/lib/components/LabeledList.tsx +0 -154
- package/lib/components/MenuBar.tsx +0 -228
- package/lib/components/Modal.tsx +0 -23
- package/lib/components/NoticeBox.tsx +0 -45
- package/lib/components/NumberInput.tsx +0 -328
- package/lib/components/Popper.tsx +0 -100
- package/lib/components/ProgressBar.tsx +0 -105
- package/lib/components/RestrictedInput.jsx +0 -301
- package/lib/components/RoundGauge.tsx +0 -180
- package/lib/components/Section.tsx +0 -120
- package/lib/components/Slider.tsx +0 -169
- package/lib/components/Stack.tsx +0 -96
- package/lib/components/StyleableSection.tsx +0 -33
- package/lib/components/Table.tsx +0 -84
- package/lib/components/Tabs.tsx +0 -89
- package/lib/components/TextArea.tsx +0 -182
- package/lib/components/TimeDisplay.jsx +0 -64
- package/lib/components/Tooltip.tsx +0 -152
- package/lib/components/TrackOutsideClicks.tsx +0 -35
- package/lib/components/VirtualList.tsx +0 -69
- package/lib/styles/atomic/candystripe.scss +0 -8
- package/lib/styles/atomic/centered-image.scss +0 -7
- package/lib/styles/atomic/color.scss +0 -21
- package/lib/styles/atomic/debug-layout.scss +0 -17
- package/lib/styles/atomic/fit-text.scss +0 -14
- package/lib/styles/atomic/links.scss +0 -12
- package/lib/styles/atomic/outline.scss +0 -47
- package/lib/styles/atomic/text.scss +0 -44
- package/lib/styles/base.scss +0 -32
- package/lib/styles/colors.scss +0 -92
- package/lib/styles/components/BlockQuote.module.scss +0 -20
- package/lib/styles/components/BlockQuote.module.scss.d.ts +0 -4
- package/lib/styles/components/Button.module.scss +0 -157
- package/lib/styles/components/Button.module.scss.d.ts +0 -46
- package/lib/styles/components/ColorBox.module.scss +0 -12
- package/lib/styles/components/ColorBox.module.scss.d.ts +0 -4
- package/lib/styles/components/Dialog.module.scss +0 -60
- package/lib/styles/components/Dialog.module.scss.d.ts +0 -10
- package/lib/styles/components/Dimmer.module.scss +0 -22
- package/lib/styles/components/Dimmer.module.scss.d.ts +0 -4
- package/lib/styles/components/Divider.module.scss +0 -27
- package/lib/styles/components/Divider.module.scss.d.ts +0 -6
- package/lib/styles/components/Dropdown.scss +0 -72
- package/lib/styles/components/Flex.module.scss +0 -13
- package/lib/styles/components/Flex.module.scss.d.ts +0 -5
- package/lib/styles/components/Icon.module.scss +0 -25
- package/lib/styles/components/Icon.module.scss.d.ts +0 -5
- package/lib/styles/components/Input.module.scss +0 -64
- package/lib/styles/components/Input.module.scss.d.ts +0 -8
- package/lib/styles/components/Knob.module.scss +0 -131
- package/lib/styles/components/Knob.module.scss.d.ts +0 -33
- package/lib/styles/components/LabeledList.module.scss +0 -49
- package/lib/styles/components/LabeledList.module.scss.d.ts +0 -8
- package/lib/styles/components/MenuBar.module.scss +0 -75
- package/lib/styles/components/MenuBar.module.scss.d.ts +0 -14
- package/lib/styles/components/Modal.module.scss +0 -14
- package/lib/styles/components/Modal.module.scss.d.ts +0 -4
- package/lib/styles/components/NoticeBox.module.scss +0 -65
- package/lib/styles/components/NoticeBox.module.scss.d.ts +0 -27
- package/lib/styles/components/NumberInput.module.scss +0 -71
- package/lib/styles/components/NumberInput.module.scss.d.ts +0 -9
- package/lib/styles/components/ProgressBar.module.scss +0 -63
- package/lib/styles/components/ProgressBar.module.scss.d.ts +0 -27
- package/lib/styles/components/RoundGauge.module.scss +0 -85
- package/lib/styles/components/RoundGauge.module.scss.d.ts +0 -49
- package/lib/styles/components/Section.module.scss +0 -130
- package/lib/styles/components/Section.module.scss.d.ts +0 -13
- package/lib/styles/components/Slider.module.scss +0 -54
- package/lib/styles/components/Slider.module.scss.d.ts +0 -8
- package/lib/styles/components/Stack.module.scss +0 -60
- package/lib/styles/components/Stack.module.scss.d.ts +0 -12
- package/lib/styles/components/Table.module.scss +0 -44
- package/lib/styles/components/Table.module.scss.d.ts +0 -10
- package/lib/styles/components/Tabs.module.scss +0 -144
- package/lib/styles/components/Tabs.module.scss.d.ts +0 -35
- package/lib/styles/components/TextArea.module.scss +0 -86
- package/lib/styles/components/TextArea.module.scss.d.ts +0 -11
- package/lib/styles/components/Tooltip.module.scss +0 -24
- package/lib/styles/components/Tooltip.module.scss.d.ts +0 -4
- package/lib/styles/functions.scss +0 -79
- package/lib/styles/input.scss +0 -9
- package/lib/styles/main.scss +0 -20
- package/lib/styles/reset.scss +0 -68
- /package/{lib/components/index.ts → dist/components/index.d.ts} +0 -0
|
@@ -1,328 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Component,
|
|
3
|
-
createRef,
|
|
4
|
-
FocusEventHandler,
|
|
5
|
-
KeyboardEventHandler,
|
|
6
|
-
MouseEventHandler,
|
|
7
|
-
RefObject,
|
|
8
|
-
} from 'react';
|
|
9
|
-
|
|
10
|
-
import { KEY } from '../common/keys';
|
|
11
|
-
import { clamp } from '../common/math';
|
|
12
|
-
import { BooleanLike, classes } from '../common/react';
|
|
13
|
-
import styles from '../styles/components/NumberInput.module.scss';
|
|
14
|
-
import { AnimatedNumber } from './AnimatedNumber';
|
|
15
|
-
import { Box } from './Box';
|
|
16
|
-
|
|
17
|
-
type Props = Required<{
|
|
18
|
-
maxValue: number;
|
|
19
|
-
minValue: number;
|
|
20
|
-
step: number;
|
|
21
|
-
value: number | string;
|
|
22
|
-
}> &
|
|
23
|
-
Partial<{
|
|
24
|
-
animated: BooleanLike;
|
|
25
|
-
className: string;
|
|
26
|
-
disabled: BooleanLike;
|
|
27
|
-
fluid: BooleanLike;
|
|
28
|
-
fontSize: string;
|
|
29
|
-
format: (value: number) => string;
|
|
30
|
-
height: string;
|
|
31
|
-
lineHeight: string;
|
|
32
|
-
onChange: (value: number) => void;
|
|
33
|
-
onDrag: (value: number) => void;
|
|
34
|
-
stepPixelSize: number;
|
|
35
|
-
unit: string;
|
|
36
|
-
width: string;
|
|
37
|
-
}>;
|
|
38
|
-
|
|
39
|
-
type State = {
|
|
40
|
-
currentValue: number;
|
|
41
|
-
dragging: BooleanLike;
|
|
42
|
-
editing: BooleanLike;
|
|
43
|
-
origin: number;
|
|
44
|
-
previousValue: number;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export class NumberInput extends Component<Props, State> {
|
|
48
|
-
// Ref to the input field to set focus & highlight
|
|
49
|
-
inputRef: RefObject<HTMLInputElement> = createRef();
|
|
50
|
-
|
|
51
|
-
// After this time has elapsed we are in drag mode so no editing when dragging ends
|
|
52
|
-
dragTimeout: NodeJS.Timeout;
|
|
53
|
-
|
|
54
|
-
// Call onDrag at this interval
|
|
55
|
-
dragInterval: NodeJS.Timeout;
|
|
56
|
-
|
|
57
|
-
// default values for the number input state
|
|
58
|
-
state: State = {
|
|
59
|
-
editing: false,
|
|
60
|
-
dragging: false,
|
|
61
|
-
currentValue: 0,
|
|
62
|
-
previousValue: 0,
|
|
63
|
-
origin: 0,
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
constructor(props: Props) {
|
|
67
|
-
super(props);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
componentDidMount(): void {
|
|
71
|
-
const displayValue = parseFloat(this.props.value.toString());
|
|
72
|
-
|
|
73
|
-
this.setState({
|
|
74
|
-
currentValue: displayValue,
|
|
75
|
-
previousValue: displayValue,
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
handleDragStart: MouseEventHandler<HTMLDivElement> = (event) => {
|
|
80
|
-
const { value, disabled } = this.props;
|
|
81
|
-
const { editing } = this.state;
|
|
82
|
-
if (disabled || editing) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
document.body.style['pointer-events'] = 'none';
|
|
86
|
-
|
|
87
|
-
const parsedValue = parseFloat(value.toString());
|
|
88
|
-
this.setState({
|
|
89
|
-
dragging: false,
|
|
90
|
-
origin: event.screenY,
|
|
91
|
-
currentValue: parsedValue,
|
|
92
|
-
previousValue: parsedValue,
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
this.dragTimeout = setTimeout(() => {
|
|
96
|
-
this.setState({
|
|
97
|
-
dragging: true,
|
|
98
|
-
});
|
|
99
|
-
}, 250);
|
|
100
|
-
this.dragInterval = setInterval(() => {
|
|
101
|
-
const { dragging, currentValue, previousValue } = this.state;
|
|
102
|
-
const { onDrag } = this.props;
|
|
103
|
-
if (dragging && currentValue !== previousValue) {
|
|
104
|
-
this.setState({
|
|
105
|
-
previousValue: currentValue,
|
|
106
|
-
});
|
|
107
|
-
onDrag?.(currentValue);
|
|
108
|
-
}
|
|
109
|
-
}, 400);
|
|
110
|
-
|
|
111
|
-
document.addEventListener('mousemove', this.handleDragMove);
|
|
112
|
-
document.addEventListener('mouseup', this.handleDragEnd);
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
handleDragMove = (event: MouseEvent) => {
|
|
116
|
-
const { minValue, maxValue, step, stepPixelSize, disabled } = this.props;
|
|
117
|
-
if (disabled) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
this.setState((prevState) => {
|
|
122
|
-
const state = { ...prevState };
|
|
123
|
-
|
|
124
|
-
const offset = state.origin - event.screenY;
|
|
125
|
-
if (prevState.dragging) {
|
|
126
|
-
const stepOffset = isFinite(minValue) ? minValue % step : 0;
|
|
127
|
-
// Translate mouse movement to value
|
|
128
|
-
// Give it some headroom (by increasing clamp range by 1 step)
|
|
129
|
-
state.currentValue = clamp(
|
|
130
|
-
state.currentValue + (offset * step) / (stepPixelSize || 1),
|
|
131
|
-
minValue - step,
|
|
132
|
-
maxValue + step,
|
|
133
|
-
);
|
|
134
|
-
// Clamp the final value
|
|
135
|
-
state.currentValue = clamp(
|
|
136
|
-
state.currentValue - (state.currentValue % step) + stepOffset,
|
|
137
|
-
minValue,
|
|
138
|
-
maxValue,
|
|
139
|
-
);
|
|
140
|
-
// Set the new origin
|
|
141
|
-
state.origin = event.screenY;
|
|
142
|
-
} else if (Math.abs(offset) > 4) {
|
|
143
|
-
state.dragging = true;
|
|
144
|
-
}
|
|
145
|
-
return state;
|
|
146
|
-
});
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
handleDragEnd = (_event: MouseEvent) => {
|
|
150
|
-
const { dragging, currentValue } = this.state;
|
|
151
|
-
const { onDrag, onChange, disabled } = this.props;
|
|
152
|
-
if (disabled) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
document.body.style['pointer-events'] = 'auto';
|
|
156
|
-
|
|
157
|
-
clearInterval(this.dragInterval);
|
|
158
|
-
clearTimeout(this.dragTimeout);
|
|
159
|
-
|
|
160
|
-
this.setState({
|
|
161
|
-
dragging: false,
|
|
162
|
-
editing: !dragging,
|
|
163
|
-
previousValue: currentValue,
|
|
164
|
-
});
|
|
165
|
-
if (dragging) {
|
|
166
|
-
onChange?.(currentValue);
|
|
167
|
-
onDrag?.(currentValue);
|
|
168
|
-
} else if (this.inputRef) {
|
|
169
|
-
const input = this.inputRef.current;
|
|
170
|
-
if (input) {
|
|
171
|
-
input.value = `${currentValue}`;
|
|
172
|
-
setTimeout(() => {
|
|
173
|
-
input.focus();
|
|
174
|
-
input.select();
|
|
175
|
-
}, 1);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
document.removeEventListener('mousemove', this.handleDragMove);
|
|
180
|
-
document.removeEventListener('mouseup', this.handleDragEnd);
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
handleBlur: FocusEventHandler<HTMLInputElement> = (event) => {
|
|
184
|
-
const { editing, previousValue } = this.state;
|
|
185
|
-
const { minValue, maxValue, onChange, onDrag, disabled } = this.props;
|
|
186
|
-
if (disabled || !editing) {
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const targetValue = clamp(
|
|
191
|
-
parseFloat(event.target.value),
|
|
192
|
-
minValue,
|
|
193
|
-
maxValue,
|
|
194
|
-
);
|
|
195
|
-
if (isNaN(targetValue)) {
|
|
196
|
-
this.setState({
|
|
197
|
-
editing: false,
|
|
198
|
-
});
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
this.setState({
|
|
203
|
-
editing: false,
|
|
204
|
-
currentValue: targetValue,
|
|
205
|
-
previousValue: targetValue,
|
|
206
|
-
});
|
|
207
|
-
if (previousValue !== targetValue) {
|
|
208
|
-
onChange?.(targetValue);
|
|
209
|
-
onDrag?.(targetValue);
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
handleKeyDown: KeyboardEventHandler<HTMLInputElement> = (event) => {
|
|
214
|
-
const { minValue, maxValue, onChange, onDrag, disabled } = this.props;
|
|
215
|
-
if (disabled) {
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
const { previousValue } = this.state;
|
|
219
|
-
|
|
220
|
-
if (event.key === KEY.Enter) {
|
|
221
|
-
const targetValue = clamp(
|
|
222
|
-
parseFloat(event.currentTarget.value),
|
|
223
|
-
minValue,
|
|
224
|
-
maxValue,
|
|
225
|
-
);
|
|
226
|
-
if (isNaN(targetValue)) {
|
|
227
|
-
this.setState({
|
|
228
|
-
editing: false,
|
|
229
|
-
});
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
this.setState({
|
|
234
|
-
editing: false,
|
|
235
|
-
currentValue: targetValue,
|
|
236
|
-
previousValue: targetValue,
|
|
237
|
-
});
|
|
238
|
-
if (previousValue !== targetValue) {
|
|
239
|
-
onChange?.(targetValue);
|
|
240
|
-
onDrag?.(targetValue);
|
|
241
|
-
}
|
|
242
|
-
} else if (event.key === KEY.Escape) {
|
|
243
|
-
this.setState({
|
|
244
|
-
editing: false,
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
render() {
|
|
250
|
-
const { dragging, editing, currentValue } = this.state;
|
|
251
|
-
|
|
252
|
-
const {
|
|
253
|
-
className,
|
|
254
|
-
fluid,
|
|
255
|
-
animated,
|
|
256
|
-
unit,
|
|
257
|
-
value,
|
|
258
|
-
minValue,
|
|
259
|
-
maxValue,
|
|
260
|
-
height,
|
|
261
|
-
width,
|
|
262
|
-
lineHeight,
|
|
263
|
-
fontSize,
|
|
264
|
-
format,
|
|
265
|
-
} = this.props;
|
|
266
|
-
|
|
267
|
-
let displayValue = parseFloat(value.toString());
|
|
268
|
-
if (dragging) {
|
|
269
|
-
displayValue = currentValue;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
const contentElement = (
|
|
273
|
-
<div className={styles.content}>
|
|
274
|
-
{animated && !dragging ? (
|
|
275
|
-
<AnimatedNumber value={displayValue} format={format} />
|
|
276
|
-
) : format ? (
|
|
277
|
-
format(displayValue)
|
|
278
|
-
) : (
|
|
279
|
-
displayValue
|
|
280
|
-
)}
|
|
281
|
-
|
|
282
|
-
{unit ? ' ' + unit : ''}
|
|
283
|
-
</div>
|
|
284
|
-
);
|
|
285
|
-
|
|
286
|
-
return (
|
|
287
|
-
<Box
|
|
288
|
-
className={classes([
|
|
289
|
-
styles.numberInput,
|
|
290
|
-
fluid && styles.fluid,
|
|
291
|
-
className,
|
|
292
|
-
])}
|
|
293
|
-
minWidth={width}
|
|
294
|
-
minHeight={height}
|
|
295
|
-
lineHeight={lineHeight}
|
|
296
|
-
fontSize={fontSize}
|
|
297
|
-
onMouseDown={this.handleDragStart}
|
|
298
|
-
>
|
|
299
|
-
<div className={styles.barContainer}>
|
|
300
|
-
<div
|
|
301
|
-
className={styles.bar}
|
|
302
|
-
style={{
|
|
303
|
-
height:
|
|
304
|
-
clamp(
|
|
305
|
-
((displayValue - minValue) / (maxValue - minValue)) * 100,
|
|
306
|
-
0,
|
|
307
|
-
100,
|
|
308
|
-
) + '%',
|
|
309
|
-
}}
|
|
310
|
-
/>
|
|
311
|
-
</div>
|
|
312
|
-
{contentElement}
|
|
313
|
-
<input
|
|
314
|
-
ref={this.inputRef}
|
|
315
|
-
className={styles.inner}
|
|
316
|
-
style={{
|
|
317
|
-
display: !editing ? 'none' : 'inline',
|
|
318
|
-
height: height,
|
|
319
|
-
lineHeight: lineHeight,
|
|
320
|
-
fontSize: fontSize,
|
|
321
|
-
}}
|
|
322
|
-
onBlur={this.handleBlur}
|
|
323
|
-
onKeyDown={this.handleKeyDown}
|
|
324
|
-
/>
|
|
325
|
-
</Box>
|
|
326
|
-
);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { Placement } from '@popperjs/core';
|
|
2
|
-
import {
|
|
3
|
-
PropsWithChildren,
|
|
4
|
-
ReactNode,
|
|
5
|
-
useEffect,
|
|
6
|
-
useRef,
|
|
7
|
-
useState,
|
|
8
|
-
} from 'react';
|
|
9
|
-
import { usePopper } from 'react-popper';
|
|
10
|
-
|
|
11
|
-
type RequiredProps = {
|
|
12
|
-
/** The content to display in the popper */
|
|
13
|
-
content: ReactNode;
|
|
14
|
-
/** Whether the popper is open */
|
|
15
|
-
isOpen: boolean;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
type OptionalProps = Partial<{
|
|
19
|
-
/** Base z-index of the popper div
|
|
20
|
-
* @default 5
|
|
21
|
-
*/
|
|
22
|
-
baseZIndex: number;
|
|
23
|
-
/** Called when the user clicks outside the popper */
|
|
24
|
-
onClickOutside: () => void;
|
|
25
|
-
/** Where to place the popper relative to the reference element */
|
|
26
|
-
placement: Placement;
|
|
27
|
-
}>;
|
|
28
|
-
|
|
29
|
-
type Props = RequiredProps & OptionalProps;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* ## Popper
|
|
33
|
-
* Popper lets you position elements so that they don't go out of the bounds of the window.
|
|
34
|
-
* @url https://popper.js.org/react-popper/ for more information.
|
|
35
|
-
*/
|
|
36
|
-
export function Popper(props: PropsWithChildren<Props>) {
|
|
37
|
-
const { children, content, isOpen, onClickOutside, placement } = props;
|
|
38
|
-
|
|
39
|
-
const [referenceElement, setReferenceElement] =
|
|
40
|
-
useState<HTMLDivElement | null>(null);
|
|
41
|
-
const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(
|
|
42
|
-
null,
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
// One would imagine we could just use useref here, but it's against react-popper documentation and causes a positioning bug
|
|
46
|
-
// We still need them to call focus and clickoutside events :(
|
|
47
|
-
const popperRef = useRef<HTMLDivElement | null>(null);
|
|
48
|
-
const parentRef = useRef<HTMLDivElement | null>(null);
|
|
49
|
-
|
|
50
|
-
const { styles, attributes } = usePopper(referenceElement, popperElement, {
|
|
51
|
-
placement,
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
/** Close the popper when the user clicks outside */
|
|
55
|
-
function handleClickOutside(event: MouseEvent) {
|
|
56
|
-
if (
|
|
57
|
-
!popperRef.current?.contains(event.target as Node) &&
|
|
58
|
-
!parentRef.current?.contains(event.target as Node)
|
|
59
|
-
) {
|
|
60
|
-
onClickOutside?.();
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
useEffect(() => {
|
|
65
|
-
if (isOpen) {
|
|
66
|
-
document.addEventListener('mousedown', handleClickOutside);
|
|
67
|
-
} else {
|
|
68
|
-
document.removeEventListener('mousedown', handleClickOutside);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return () => {
|
|
72
|
-
document.removeEventListener('mousedown', handleClickOutside);
|
|
73
|
-
};
|
|
74
|
-
}, [isOpen]);
|
|
75
|
-
|
|
76
|
-
return (
|
|
77
|
-
<>
|
|
78
|
-
<div
|
|
79
|
-
ref={(node) => {
|
|
80
|
-
setReferenceElement(node);
|
|
81
|
-
parentRef.current = node;
|
|
82
|
-
}}
|
|
83
|
-
>
|
|
84
|
-
{children}
|
|
85
|
-
</div>
|
|
86
|
-
{isOpen && (
|
|
87
|
-
<div
|
|
88
|
-
ref={(node) => {
|
|
89
|
-
setPopperElement(node);
|
|
90
|
-
popperRef.current = node;
|
|
91
|
-
}}
|
|
92
|
-
style={{ ...styles.popper, zIndex: props.baseZIndex ?? 5 }}
|
|
93
|
-
{...attributes.popper}
|
|
94
|
-
>
|
|
95
|
-
{content}
|
|
96
|
-
</div>
|
|
97
|
-
)}
|
|
98
|
-
</>
|
|
99
|
-
);
|
|
100
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { PropsWithChildren } from 'react';
|
|
2
|
-
|
|
3
|
-
import { CSS_COLORS } from '../common/constants';
|
|
4
|
-
import { clamp01, keyOfMatchingRange, scale, toFixed } from '../common/math';
|
|
5
|
-
import { classes } from '../common/react';
|
|
6
|
-
import styles from '../styles/components/ProgressBar.module.scss';
|
|
7
|
-
import { BoxProps, computeBoxClassName, computeBoxProps } from './Box';
|
|
8
|
-
|
|
9
|
-
type Props = {
|
|
10
|
-
/**
|
|
11
|
-
* Current progress as a floating point number between `minValue` (default: 0) and `maxValue` (default: 1).
|
|
12
|
-
* Determines the percentage and how filled the bar is.
|
|
13
|
-
*/
|
|
14
|
-
value: number;
|
|
15
|
-
} & Partial<{
|
|
16
|
-
/**
|
|
17
|
-
* Color of the progress bar. Can take any of the following formats:
|
|
18
|
-
* - `#ffffff` - Hex format
|
|
19
|
-
* - `rgb(r,g,b) / rgba(r,g,b,a)` - RGB format
|
|
20
|
-
* - `<name>` - the name of a `color-<name>` CSS class. See `CSS_COLORS` in `constants.js`.
|
|
21
|
-
* - `<name>` - the name of a base CSS color, if not overridden by the definitions above.
|
|
22
|
-
*/
|
|
23
|
-
color: string;
|
|
24
|
-
/** Highest possible value. */
|
|
25
|
-
maxValue: number;
|
|
26
|
-
/** Lowest possible value. */
|
|
27
|
-
minValue: number;
|
|
28
|
-
/**
|
|
29
|
-
* Applies a `color` to the progress bar based on whether the value lands in the range between `from` and `to`.
|
|
30
|
-
* This takes an object with the following format:
|
|
31
|
-
* ```tsx
|
|
32
|
-
* {
|
|
33
|
-
* (colorname): [from, to]
|
|
34
|
-
* }
|
|
35
|
-
* ```
|
|
36
|
-
* For example:
|
|
37
|
-
* ```tsx
|
|
38
|
-
* <ProgressBar
|
|
39
|
-
* value={0.5}
|
|
40
|
-
* ranges={{
|
|
41
|
-
* bad: [0, 0.5],
|
|
42
|
-
* good: [0.5, 1],
|
|
43
|
-
* }}
|
|
44
|
-
* />
|
|
45
|
-
* ```
|
|
46
|
-
*
|
|
47
|
-
*/
|
|
48
|
-
ranges: Record<string, [number, number]>;
|
|
49
|
-
}> &
|
|
50
|
-
BoxProps &
|
|
51
|
-
PropsWithChildren;
|
|
52
|
-
|
|
53
|
-
export function ProgressBar(props: Props) {
|
|
54
|
-
const {
|
|
55
|
-
className,
|
|
56
|
-
value,
|
|
57
|
-
minValue = 0,
|
|
58
|
-
maxValue = 1,
|
|
59
|
-
color,
|
|
60
|
-
ranges = {},
|
|
61
|
-
children,
|
|
62
|
-
...rest
|
|
63
|
-
} = props;
|
|
64
|
-
const scaledValue = scale(value, minValue, maxValue);
|
|
65
|
-
const hasContent = children !== undefined;
|
|
66
|
-
|
|
67
|
-
const effectiveColor =
|
|
68
|
-
color || keyOfMatchingRange(value, ranges) || 'default';
|
|
69
|
-
|
|
70
|
-
// We permit colors to be in hex format, rgb()/rgba() format,
|
|
71
|
-
// a name for a color-<name> class, or a base CSS class.
|
|
72
|
-
const outerProps = computeBoxProps(rest);
|
|
73
|
-
|
|
74
|
-
const outerClasses = [
|
|
75
|
-
styles.progressBar,
|
|
76
|
-
className,
|
|
77
|
-
computeBoxClassName(rest),
|
|
78
|
-
];
|
|
79
|
-
const fillStyles = {
|
|
80
|
-
width: clamp01(scaledValue) * 100 + '%',
|
|
81
|
-
};
|
|
82
|
-
if (
|
|
83
|
-
CSS_COLORS.includes(effectiveColor as any) ||
|
|
84
|
-
effectiveColor === 'default'
|
|
85
|
-
) {
|
|
86
|
-
// If the color is a color-<name> class, just use that.
|
|
87
|
-
outerClasses.push(styles['color__' + effectiveColor]);
|
|
88
|
-
} else {
|
|
89
|
-
// Otherwise, set styles directly.
|
|
90
|
-
outerProps.style = { ...outerProps.style, borderColor: effectiveColor };
|
|
91
|
-
fillStyles['backgroundColor'] = effectiveColor;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return (
|
|
95
|
-
<div className={classes(outerClasses)} {...outerProps}>
|
|
96
|
-
<div
|
|
97
|
-
className={classes([styles.fill, styles.fill__animated])}
|
|
98
|
-
style={fillStyles}
|
|
99
|
-
/>
|
|
100
|
-
<div className={styles.content}>
|
|
101
|
-
{hasContent ? children : toFixed(scaledValue * 100) + '%'}
|
|
102
|
-
</div>
|
|
103
|
-
</div>
|
|
104
|
-
);
|
|
105
|
-
}
|