tgui-core 1.0.2 → 1.0.3
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/{src/components → components}/AnimatedNumber.tsx +185 -185
- package/{src/components → components}/BlockQuote.tsx +15 -15
- package/{src/components → components}/BodyZoneSelector.tsx +149 -149
- package/{src/components → components}/Box.tsx +255 -255
- package/{src/components → components}/Button.tsx +415 -415
- package/{src/components → components}/ByondUi.jsx +121 -121
- package/{src/components → components}/Chart.tsx +160 -160
- package/{src/components → components}/ColorBox.tsx +30 -30
- package/{src/components → components}/Dimmer.tsx +19 -19
- package/{src/components → components}/Divider.tsx +26 -26
- package/{src/components → components}/DmIcon.tsx +72 -72
- package/{src/components → components}/DraggableControl.jsx +282 -282
- package/{src/components → components}/Dropdown.tsx +246 -246
- package/{src/components → components}/Flex.tsx +105 -105
- package/{src/components → components}/Icon.tsx +91 -91
- package/{src/components → components}/Input.tsx +181 -181
- package/{src/components → components}/KeyListener.tsx +40 -40
- package/{src/components → components}/Knob.tsx +185 -185
- package/{src/components → components}/LabeledList.tsx +130 -130
- package/{src/components → components}/MenuBar.tsx +233 -238
- package/{src/components → components}/Modal.tsx +25 -25
- package/{src/components → components}/NoticeBox.tsx +48 -48
- package/{src/components → components}/NumberInput.tsx +328 -328
- package/{src/components → components}/ProgressBar.tsx +79 -79
- package/{src/components → components}/RestrictedInput.jsx +301 -301
- package/{src/components → components}/RoundGauge.tsx +189 -189
- package/{src/components → components}/Section.tsx +125 -125
- package/{src/components → components}/Slider.tsx +173 -173
- package/{src/components → components}/Stack.tsx +101 -101
- package/{src/components → components}/Table.tsx +90 -90
- package/{src/components → components}/Tabs.tsx +90 -90
- package/{src/components → components}/TextArea.tsx +198 -198
- package/{src/components → components}/TimeDisplay.jsx +64 -64
- package/components/index.ts +51 -0
- package/{src/debug/KitchenSink.jsx → debug/KitchenSink.tsx} +56 -56
- package/{src/debug/actions.js → debug/actions.ts} +11 -11
- package/{src/debug/hooks.js → debug/hooks.ts} +10 -10
- package/{src/debug/middleware.js → debug/middleware.ts} +86 -86
- package/{src/debug/reducer.js → debug/reducer.ts} +27 -22
- package/{src/debug/selectors.js → debug/selectors.ts} +7 -7
- package/{src/layouts → layouts}/Layout.tsx +75 -75
- package/{src/layouts → layouts}/NtosWindow.tsx +162 -162
- package/{src/layouts → layouts}/Pane.tsx +56 -56
- package/{src/layouts → layouts}/Window.tsx +227 -227
- package/layouts/index.ts +10 -0
- package/package.json +3 -2
- package/src/assets.ts +43 -43
- package/src/backend.ts +369 -369
- package/src/drag.ts +280 -280
- package/src/events.ts +237 -237
- package/src/hotkeys.ts +212 -212
- package/src/renderer.ts +50 -50
- package/stories/Blink.stories.tsx +20 -0
- package/stories/BlockQuote.stories.tsx +23 -0
- package/stories/Box.stories.tsx +27 -0
- package/stories/Button.stories.tsx +68 -0
- package/stories/ByondUi.stories.tsx +45 -0
- package/stories/Collapsible.stories.tsx +23 -0
- package/stories/Flex.stories.tsx +68 -0
- package/stories/Input.stories.tsx +124 -0
- package/stories/LabeledList.stories.tsx +73 -0
- package/stories/Popper.stories.tsx +58 -0
- package/stories/ProgressBar.stories.tsx +58 -0
- package/stories/Stack.stories.tsx +55 -0
- package/stories/Storage.stories.tsx +46 -0
- package/stories/Themes.stories.tsx +30 -0
- package/stories/Tooltip.stories.tsx +48 -0
- package/stories/common.tsx +19 -0
- package/tsconfig.json +0 -21
- package/src/components/Grid.tsx +0 -44
- /package/{src/common → common}/collections.ts +0 -0
- /package/{src/common → common}/color.ts +0 -0
- /package/{src/common → common}/events.ts +0 -0
- /package/{src/common → common}/exhaustive.ts +0 -0
- /package/{src/common → common}/fp.ts +0 -0
- /package/{src/common → common}/keycodes.ts +0 -0
- /package/{src/common → common}/keys.ts +0 -0
- /package/{src/common → common}/math.ts +0 -0
- /package/{src/common → common}/perf.ts +0 -0
- /package/{src/common → common}/random.ts +0 -0
- /package/{src/common → common}/react.ts +0 -0
- /package/{src/common → common}/redux.ts +0 -0
- /package/{src/common → common}/storage.js +0 -0
- /package/{src/common → common}/string.ts +0 -0
- /package/{src/common → common}/timer.ts +0 -0
- /package/{src/common → common}/type-utils.ts +0 -0
- /package/{src/common → common}/types.ts +0 -0
- /package/{src/common → common}/uuid.ts +0 -0
- /package/{src/common → common}/vector.ts +0 -0
- /package/{src/components → components}/Autofocus.tsx +0 -0
- /package/{src/components → components}/Blink.jsx +0 -0
- /package/{src/components → components}/Collapsible.tsx +0 -0
- /package/{src/components → components}/Dialog.tsx +0 -0
- /package/{src/components → components}/FakeTerminal.jsx +0 -0
- /package/{src/components → components}/FitText.tsx +0 -0
- /package/{src/components → components}/Image.tsx +0 -0
- /package/{src/components → components}/InfinitePlane.jsx +0 -0
- /package/{src/components → components}/LabeledControls.tsx +0 -0
- /package/{src/components → components}/Popper.tsx +0 -0
- /package/{src/components → components}/StyleableSection.tsx +0 -0
- /package/{src/components → components}/Tooltip.tsx +0 -0
- /package/{src/components → components}/TrackOutsideClicks.tsx +0 -0
- /package/{src/components → components}/VirtualList.tsx +0 -0
- /package/{src/debug → debug}/index.ts +0 -0
- /package/{src/styles → styles}/base.scss +0 -0
- /package/{src/styles → styles}/colors.scss +0 -0
- /package/{src/styles → styles}/components/BlockQuote.scss +0 -0
- /package/{src/styles → styles}/components/Button.scss +0 -0
- /package/{src/styles → styles}/components/ColorBox.scss +0 -0
- /package/{src/styles → styles}/components/Dialog.scss +0 -0
- /package/{src/styles → styles}/components/Dimmer.scss +0 -0
- /package/{src/styles → styles}/components/Divider.scss +0 -0
- /package/{src/styles → styles}/components/Dropdown.scss +0 -0
- /package/{src/styles → styles}/components/Flex.scss +0 -0
- /package/{src/styles → styles}/components/Icon.scss +0 -0
- /package/{src/styles → styles}/components/Input.scss +0 -0
- /package/{src/styles → styles}/components/Knob.scss +0 -0
- /package/{src/styles → styles}/components/LabeledList.scss +0 -0
- /package/{src/styles → styles}/components/MenuBar.scss +0 -0
- /package/{src/styles → styles}/components/Modal.scss +0 -0
- /package/{src/styles → styles}/components/NoticeBox.scss +0 -0
- /package/{src/styles → styles}/components/NumberInput.scss +0 -0
- /package/{src/styles → styles}/components/ProgressBar.scss +0 -0
- /package/{src/styles → styles}/components/RoundGauge.scss +0 -0
- /package/{src/styles → styles}/components/Section.scss +0 -0
- /package/{src/styles → styles}/components/Slider.scss +0 -0
- /package/{src/styles → styles}/components/Stack.scss +0 -0
- /package/{src/styles → styles}/components/Table.scss +0 -0
- /package/{src/styles → styles}/components/Tabs.scss +0 -0
- /package/{src/styles → styles}/components/TextArea.scss +0 -0
- /package/{src/styles → styles}/components/Tooltip.scss +0 -0
- /package/{src/styles → styles}/functions.scss +0 -0
- /package/{src/styles → styles}/layouts/Layout.scss +0 -0
- /package/{src/styles → styles}/layouts/NtosHeader.scss +0 -0
- /package/{src/styles → styles}/layouts/NtosWindow.scss +0 -0
- /package/{src/styles → styles}/layouts/TitleBar.scss +0 -0
- /package/{src/styles → styles}/layouts/Window.scss +0 -0
- /package/{src/styles → styles}/main.scss +0 -0
- /package/{src/styles → styles}/reset.scss +0 -0
- /package/{src/styles → styles}/themes/abductor.scss +0 -0
- /package/{src/styles → styles}/themes/admin.scss +0 -0
- /package/{src/styles → styles}/themes/cardtable.scss +0 -0
- /package/{src/styles → styles}/themes/hackerman.scss +0 -0
- /package/{src/styles → styles}/themes/malfunction.scss +0 -0
- /package/{src/styles → styles}/themes/neutral.scss +0 -0
- /package/{src/styles → styles}/themes/ntOS95.scss +0 -0
- /package/{src/styles → styles}/themes/ntos.scss +0 -0
- /package/{src/styles → styles}/themes/ntos_cat.scss +0 -0
- /package/{src/styles → styles}/themes/ntos_darkmode.scss +0 -0
- /package/{src/styles → styles}/themes/ntos_lightmode.scss +0 -0
- /package/{src/styles → styles}/themes/ntos_spooky.scss +0 -0
- /package/{src/styles → styles}/themes/ntos_synth.scss +0 -0
- /package/{src/styles → styles}/themes/ntos_terminal.scss +0 -0
- /package/{src/styles → styles}/themes/paper.scss +0 -0
- /package/{src/styles → styles}/themes/retro.scss +0 -0
- /package/{src/styles → styles}/themes/spookyconsole.scss +0 -0
- /package/{src/styles → styles}/themes/syndicate.scss +0 -0
- /package/{src/styles → styles}/themes/wizard.scss +0 -0
|
@@ -1,181 +1,181 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file
|
|
3
|
-
* @copyright 2020 Aleksej Komarov
|
|
4
|
-
* @license MIT
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { KEY } from '../common/keys';
|
|
8
|
-
import { classes } from '../common/react';
|
|
9
|
-
import { debounce } from '../common/timer';
|
|
10
|
-
import { KeyboardEvent, SyntheticEvent, useEffect, useRef } from 'react';
|
|
11
|
-
|
|
12
|
-
import { Box, BoxProps } from './Box';
|
|
13
|
-
|
|
14
|
-
type ConditionalProps =
|
|
15
|
-
| {
|
|
16
|
-
/**
|
|
17
|
-
* Mark this if you want to debounce onInput.
|
|
18
|
-
*
|
|
19
|
-
* This is useful for expensive filters, large lists etc.
|
|
20
|
-
*
|
|
21
|
-
* Requires `onInput` to be set.
|
|
22
|
-
*/
|
|
23
|
-
expensive?: boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Fires on each key press / value change. Used for searching.
|
|
26
|
-
*
|
|
27
|
-
* If it's a large list, consider using `expensive` prop.
|
|
28
|
-
*/
|
|
29
|
-
onInput: (event: SyntheticEvent<HTMLInputElement>, value: string) => void;
|
|
30
|
-
}
|
|
31
|
-
| {
|
|
32
|
-
/** This prop requires onInput to be set */
|
|
33
|
-
expensive?: never;
|
|
34
|
-
onInput?: never;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
type OptionalProps = Partial<{
|
|
38
|
-
/** Automatically focuses the input on mount */
|
|
39
|
-
autoFocus: boolean;
|
|
40
|
-
/** Automatically selects the input value on focus */
|
|
41
|
-
autoSelect: boolean;
|
|
42
|
-
/** The class name of the input */
|
|
43
|
-
className: string;
|
|
44
|
-
/** Disables the input */
|
|
45
|
-
disabled: boolean;
|
|
46
|
-
/** Mark this if you want the input to be as wide as possible */
|
|
47
|
-
fluid: boolean;
|
|
48
|
-
/** The maximum length of the input value */
|
|
49
|
-
maxLength: number;
|
|
50
|
-
/** Mark this if you want to use a monospace font */
|
|
51
|
-
monospace: boolean;
|
|
52
|
-
/** Fires when user is 'done typing': Clicked out, blur, enter key */
|
|
53
|
-
onChange: (event: SyntheticEvent<HTMLInputElement>, value: string) => void;
|
|
54
|
-
/** Fires once the enter key is pressed */
|
|
55
|
-
onEnter?: (event: SyntheticEvent<HTMLInputElement>, value: string) => void;
|
|
56
|
-
/** Fires once the escape key is pressed */
|
|
57
|
-
onEscape: (event: SyntheticEvent<HTMLInputElement>) => void;
|
|
58
|
-
/** The placeholder text when everything is cleared */
|
|
59
|
-
placeholder: string;
|
|
60
|
-
/** Clears the input value on enter */
|
|
61
|
-
selfClear: boolean;
|
|
62
|
-
/** The state variable of the input. */
|
|
63
|
-
value: string | number;
|
|
64
|
-
}>;
|
|
65
|
-
|
|
66
|
-
type Props = OptionalProps & ConditionalProps & BoxProps;
|
|
67
|
-
|
|
68
|
-
export function toInputValue(value: string | number | undefined) {
|
|
69
|
-
return typeof value !== 'number' && typeof value !== 'string'
|
|
70
|
-
? ''
|
|
71
|
-
: String(value);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const inputDebounce = debounce((onInput: () => void) => onInput(), 250);
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* ### Input
|
|
78
|
-
* A basic text input which allow users to enter text into a UI.
|
|
79
|
-
* > Input does not support custom font size and height due to the way
|
|
80
|
-
* > it's implemented in CSS. Eventually, this needs to be fixed.
|
|
81
|
-
*/
|
|
82
|
-
export function Input(props: Props) {
|
|
83
|
-
const {
|
|
84
|
-
autoFocus,
|
|
85
|
-
autoSelect,
|
|
86
|
-
className,
|
|
87
|
-
disabled,
|
|
88
|
-
expensive,
|
|
89
|
-
fluid,
|
|
90
|
-
maxLength,
|
|
91
|
-
monospace,
|
|
92
|
-
onChange,
|
|
93
|
-
onEnter,
|
|
94
|
-
onEscape,
|
|
95
|
-
onInput,
|
|
96
|
-
placeholder,
|
|
97
|
-
selfClear,
|
|
98
|
-
value,
|
|
99
|
-
...rest
|
|
100
|
-
} = props;
|
|
101
|
-
|
|
102
|
-
// The ref to the input field
|
|
103
|
-
const inputRef = useRef<HTMLInputElement>(null);
|
|
104
|
-
|
|
105
|
-
function handleInput(event: SyntheticEvent<HTMLInputElement>) {
|
|
106
|
-
if (!onInput) return;
|
|
107
|
-
|
|
108
|
-
const value = event.currentTarget?.value;
|
|
109
|
-
|
|
110
|
-
if (expensive) {
|
|
111
|
-
inputDebounce(() => onInput(event, value));
|
|
112
|
-
} else {
|
|
113
|
-
onInput(event, value);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function handleKeyDown(event: KeyboardEvent<HTMLInputElement>) {
|
|
118
|
-
if (event.key === KEY.Enter) {
|
|
119
|
-
onEnter?.(event, event.currentTarget.value);
|
|
120
|
-
if (selfClear) {
|
|
121
|
-
event.currentTarget.value = '';
|
|
122
|
-
} else {
|
|
123
|
-
event.currentTarget.blur();
|
|
124
|
-
onChange?.(event, event.currentTarget.value);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (event.key === KEY.Escape) {
|
|
131
|
-
onEscape?.(event);
|
|
132
|
-
|
|
133
|
-
event.currentTarget.value = toInputValue(value);
|
|
134
|
-
event.currentTarget.blur();
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/** Focuses the input on mount */
|
|
139
|
-
useEffect(() => {
|
|
140
|
-
const input = inputRef.current;
|
|
141
|
-
if (!input) return;
|
|
142
|
-
|
|
143
|
-
const newValue = toInputValue(value);
|
|
144
|
-
|
|
145
|
-
if (input.value !== newValue) input.value = newValue;
|
|
146
|
-
|
|
147
|
-
if (!autoFocus && !autoSelect) return;
|
|
148
|
-
|
|
149
|
-
setTimeout(() => {
|
|
150
|
-
input.focus();
|
|
151
|
-
|
|
152
|
-
if (autoSelect) {
|
|
153
|
-
input.select();
|
|
154
|
-
}
|
|
155
|
-
}, 1);
|
|
156
|
-
}, []);
|
|
157
|
-
|
|
158
|
-
return (
|
|
159
|
-
<Box
|
|
160
|
-
className={classes([
|
|
161
|
-
'Input',
|
|
162
|
-
fluid && 'Input--fluid',
|
|
163
|
-
monospace && 'Input--monospace',
|
|
164
|
-
className,
|
|
165
|
-
])}
|
|
166
|
-
{...rest}
|
|
167
|
-
>
|
|
168
|
-
<div className="Input__baseline">.</div>
|
|
169
|
-
<input
|
|
170
|
-
className="Input__input"
|
|
171
|
-
disabled={disabled}
|
|
172
|
-
maxLength={maxLength}
|
|
173
|
-
onBlur={(event) => onChange?.(event, event.target.value)}
|
|
174
|
-
onChange={handleInput}
|
|
175
|
-
onKeyDown={handleKeyDown}
|
|
176
|
-
placeholder={placeholder}
|
|
177
|
-
ref={inputRef}
|
|
178
|
-
/>
|
|
179
|
-
</Box>
|
|
180
|
-
);
|
|
181
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @file
|
|
3
|
+
* @copyright 2020 Aleksej Komarov
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { KEY } from '../common/keys';
|
|
8
|
+
import { classes } from '../common/react';
|
|
9
|
+
import { debounce } from '../common/timer';
|
|
10
|
+
import { KeyboardEvent, SyntheticEvent, useEffect, useRef } from 'react';
|
|
11
|
+
|
|
12
|
+
import { Box, BoxProps } from './Box';
|
|
13
|
+
|
|
14
|
+
type ConditionalProps =
|
|
15
|
+
| {
|
|
16
|
+
/**
|
|
17
|
+
* Mark this if you want to debounce onInput.
|
|
18
|
+
*
|
|
19
|
+
* This is useful for expensive filters, large lists etc.
|
|
20
|
+
*
|
|
21
|
+
* Requires `onInput` to be set.
|
|
22
|
+
*/
|
|
23
|
+
expensive?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Fires on each key press / value change. Used for searching.
|
|
26
|
+
*
|
|
27
|
+
* If it's a large list, consider using `expensive` prop.
|
|
28
|
+
*/
|
|
29
|
+
onInput: (event: SyntheticEvent<HTMLInputElement>, value: string) => void;
|
|
30
|
+
}
|
|
31
|
+
| {
|
|
32
|
+
/** This prop requires onInput to be set */
|
|
33
|
+
expensive?: never;
|
|
34
|
+
onInput?: never;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
type OptionalProps = Partial<{
|
|
38
|
+
/** Automatically focuses the input on mount */
|
|
39
|
+
autoFocus: boolean;
|
|
40
|
+
/** Automatically selects the input value on focus */
|
|
41
|
+
autoSelect: boolean;
|
|
42
|
+
/** The class name of the input */
|
|
43
|
+
className: string;
|
|
44
|
+
/** Disables the input */
|
|
45
|
+
disabled: boolean;
|
|
46
|
+
/** Mark this if you want the input to be as wide as possible */
|
|
47
|
+
fluid: boolean;
|
|
48
|
+
/** The maximum length of the input value */
|
|
49
|
+
maxLength: number;
|
|
50
|
+
/** Mark this if you want to use a monospace font */
|
|
51
|
+
monospace: boolean;
|
|
52
|
+
/** Fires when user is 'done typing': Clicked out, blur, enter key */
|
|
53
|
+
onChange: (event: SyntheticEvent<HTMLInputElement>, value: string) => void;
|
|
54
|
+
/** Fires once the enter key is pressed */
|
|
55
|
+
onEnter?: (event: SyntheticEvent<HTMLInputElement>, value: string) => void;
|
|
56
|
+
/** Fires once the escape key is pressed */
|
|
57
|
+
onEscape: (event: SyntheticEvent<HTMLInputElement>) => void;
|
|
58
|
+
/** The placeholder text when everything is cleared */
|
|
59
|
+
placeholder: string;
|
|
60
|
+
/** Clears the input value on enter */
|
|
61
|
+
selfClear: boolean;
|
|
62
|
+
/** The state variable of the input. */
|
|
63
|
+
value: string | number;
|
|
64
|
+
}>;
|
|
65
|
+
|
|
66
|
+
type Props = OptionalProps & ConditionalProps & BoxProps;
|
|
67
|
+
|
|
68
|
+
export function toInputValue(value: string | number | undefined) {
|
|
69
|
+
return typeof value !== 'number' && typeof value !== 'string'
|
|
70
|
+
? ''
|
|
71
|
+
: String(value);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const inputDebounce = debounce((onInput: () => void) => onInput(), 250);
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* ### Input
|
|
78
|
+
* A basic text input which allow users to enter text into a UI.
|
|
79
|
+
* > Input does not support custom font size and height due to the way
|
|
80
|
+
* > it's implemented in CSS. Eventually, this needs to be fixed.
|
|
81
|
+
*/
|
|
82
|
+
export function Input(props: Props) {
|
|
83
|
+
const {
|
|
84
|
+
autoFocus,
|
|
85
|
+
autoSelect,
|
|
86
|
+
className,
|
|
87
|
+
disabled,
|
|
88
|
+
expensive,
|
|
89
|
+
fluid,
|
|
90
|
+
maxLength,
|
|
91
|
+
monospace,
|
|
92
|
+
onChange,
|
|
93
|
+
onEnter,
|
|
94
|
+
onEscape,
|
|
95
|
+
onInput,
|
|
96
|
+
placeholder,
|
|
97
|
+
selfClear,
|
|
98
|
+
value,
|
|
99
|
+
...rest
|
|
100
|
+
} = props;
|
|
101
|
+
|
|
102
|
+
// The ref to the input field
|
|
103
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
104
|
+
|
|
105
|
+
function handleInput(event: SyntheticEvent<HTMLInputElement>) {
|
|
106
|
+
if (!onInput) return;
|
|
107
|
+
|
|
108
|
+
const value = event.currentTarget?.value;
|
|
109
|
+
|
|
110
|
+
if (expensive) {
|
|
111
|
+
inputDebounce(() => onInput(event, value));
|
|
112
|
+
} else {
|
|
113
|
+
onInput(event, value);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function handleKeyDown(event: KeyboardEvent<HTMLInputElement>) {
|
|
118
|
+
if (event.key === KEY.Enter) {
|
|
119
|
+
onEnter?.(event, event.currentTarget.value);
|
|
120
|
+
if (selfClear) {
|
|
121
|
+
event.currentTarget.value = '';
|
|
122
|
+
} else {
|
|
123
|
+
event.currentTarget.blur();
|
|
124
|
+
onChange?.(event, event.currentTarget.value);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (event.key === KEY.Escape) {
|
|
131
|
+
onEscape?.(event);
|
|
132
|
+
|
|
133
|
+
event.currentTarget.value = toInputValue(value);
|
|
134
|
+
event.currentTarget.blur();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Focuses the input on mount */
|
|
139
|
+
useEffect(() => {
|
|
140
|
+
const input = inputRef.current;
|
|
141
|
+
if (!input) return;
|
|
142
|
+
|
|
143
|
+
const newValue = toInputValue(value);
|
|
144
|
+
|
|
145
|
+
if (input.value !== newValue) input.value = newValue;
|
|
146
|
+
|
|
147
|
+
if (!autoFocus && !autoSelect) return;
|
|
148
|
+
|
|
149
|
+
setTimeout(() => {
|
|
150
|
+
input.focus();
|
|
151
|
+
|
|
152
|
+
if (autoSelect) {
|
|
153
|
+
input.select();
|
|
154
|
+
}
|
|
155
|
+
}, 1);
|
|
156
|
+
}, []);
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<Box
|
|
160
|
+
className={classes([
|
|
161
|
+
'Input',
|
|
162
|
+
fluid && 'Input--fluid',
|
|
163
|
+
monospace && 'Input--monospace',
|
|
164
|
+
className,
|
|
165
|
+
])}
|
|
166
|
+
{...rest}
|
|
167
|
+
>
|
|
168
|
+
<div className="Input__baseline">.</div>
|
|
169
|
+
<input
|
|
170
|
+
className="Input__input"
|
|
171
|
+
disabled={disabled}
|
|
172
|
+
maxLength={maxLength}
|
|
173
|
+
onBlur={(event) => onChange?.(event, event.target.value)}
|
|
174
|
+
onChange={handleInput}
|
|
175
|
+
onKeyDown={handleKeyDown}
|
|
176
|
+
placeholder={placeholder}
|
|
177
|
+
ref={inputRef}
|
|
178
|
+
/>
|
|
179
|
+
</Box>
|
|
180
|
+
);
|
|
181
|
+
}
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import { Component } from 'react';
|
|
2
|
-
|
|
3
|
-
import { KeyEvent } from '../events';
|
|
4
|
-
import { listenForKeyEvents } from '../hotkeys';
|
|
5
|
-
|
|
6
|
-
type KeyListenerProps = Partial<{
|
|
7
|
-
onKey: (key: KeyEvent) => void;
|
|
8
|
-
onKeyDown: (key: KeyEvent) => void;
|
|
9
|
-
onKeyUp: (key: KeyEvent) => void;
|
|
10
|
-
}>;
|
|
11
|
-
|
|
12
|
-
export class KeyListener extends Component<KeyListenerProps> {
|
|
13
|
-
dispose: () => void;
|
|
14
|
-
|
|
15
|
-
constructor(props) {
|
|
16
|
-
super(props);
|
|
17
|
-
|
|
18
|
-
this.dispose = listenForKeyEvents((key) => {
|
|
19
|
-
if (this.props.onKey) {
|
|
20
|
-
this.props.onKey(key);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (key.isDown() && this.props.onKeyDown) {
|
|
24
|
-
this.props.onKeyDown(key);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (key.isUp() && this.props.onKeyUp) {
|
|
28
|
-
this.props.onKeyUp(key);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
componentWillUnmount() {
|
|
34
|
-
this.dispose();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
render() {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
1
|
+
import { Component } from 'react';
|
|
2
|
+
|
|
3
|
+
import { KeyEvent } from '../src/events';
|
|
4
|
+
import { listenForKeyEvents } from '../src/hotkeys';
|
|
5
|
+
|
|
6
|
+
type KeyListenerProps = Partial<{
|
|
7
|
+
onKey: (key: KeyEvent) => void;
|
|
8
|
+
onKeyDown: (key: KeyEvent) => void;
|
|
9
|
+
onKeyUp: (key: KeyEvent) => void;
|
|
10
|
+
}>;
|
|
11
|
+
|
|
12
|
+
export class KeyListener extends Component<KeyListenerProps> {
|
|
13
|
+
dispose: () => void;
|
|
14
|
+
|
|
15
|
+
constructor(props) {
|
|
16
|
+
super(props);
|
|
17
|
+
|
|
18
|
+
this.dispose = listenForKeyEvents((key) => {
|
|
19
|
+
if (this.props.onKey) {
|
|
20
|
+
this.props.onKey(key);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (key.isDown() && this.props.onKeyDown) {
|
|
24
|
+
this.props.onKeyDown(key);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (key.isUp() && this.props.onKeyUp) {
|
|
28
|
+
this.props.onKeyUp(key);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
componentWillUnmount() {
|
|
34
|
+
this.dispose();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
render() {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|