tgui-core 1.1.7 → 1.1.9
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/lib/common/assets.ts +38 -0
- package/lib/common/collections.ts +27 -0
- package/lib/common/color.ts +88 -0
- package/lib/common/constants.ts +349 -0
- package/lib/common/events.ts +262 -0
- package/{dist/common/exhaustive.d.ts → lib/common/exhaustive.ts} +3 -1
- package/lib/common/format.ts +167 -0
- package/{dist/common/fp.d.ts → lib/common/fp.ts} +16 -2
- package/lib/common/hotkeys.ts +207 -0
- package/lib/common/http.ts +16 -0
- package/lib/common/keycodes.ts +86 -0
- package/{dist/common/keys.d.ts → lib/common/keys.ts} +24 -21
- package/lib/common/math.ts +76 -0
- package/lib/common/perf.ts +72 -0
- package/lib/common/random.ts +32 -0
- package/lib/common/react.ts +59 -0
- package/lib/common/redux.ts +187 -0
- package/lib/common/storage.ts +207 -0
- package/lib/common/string.ts +169 -0
- package/lib/common/timer.ts +63 -0
- package/lib/common/type-utils.ts +41 -0
- package/lib/common/types.d.ts +12 -0
- package/lib/common/uuid.ts +18 -0
- package/lib/components/AnimatedNumber.tsx +180 -0
- package/lib/components/Autofocus.tsx +23 -0
- package/lib/components/Blink.tsx +91 -0
- package/lib/components/BlockQuote.tsx +9 -0
- package/lib/components/BodyZoneSelector.tsx +149 -0
- package/lib/components/Box.tsx +252 -0
- package/lib/components/Button.tsx +425 -0
- package/lib/components/ByondUi.jsx +110 -0
- package/lib/components/Chart.tsx +155 -0
- package/lib/components/Collapsible.tsx +43 -0
- package/lib/components/ColorBox.tsx +29 -0
- package/lib/components/Dialog.tsx +81 -0
- package/lib/components/Dimmer.tsx +13 -0
- package/lib/components/Divider.tsx +20 -0
- package/lib/components/DmIcon.tsx +86 -0
- package/lib/components/DraggableControl.jsx +276 -0
- package/lib/components/Dropdown.tsx +246 -0
- package/lib/components/FakeTerminal.jsx +52 -0
- package/lib/components/FitText.tsx +99 -0
- package/lib/components/Flex.tsx +159 -0
- package/lib/components/Icon.tsx +95 -0
- package/lib/components/Image.tsx +54 -0
- package/lib/components/InfinitePlane.jsx +192 -0
- package/lib/components/Input.tsx +176 -0
- package/lib/components/KeyListener.tsx +40 -0
- package/lib/components/Knob.tsx +178 -0
- package/lib/components/LabeledControls.tsx +44 -0
- package/lib/components/LabeledList.tsx +154 -0
- package/lib/components/MenuBar.tsx +228 -0
- package/lib/components/Modal.tsx +23 -0
- package/lib/components/NoticeBox.tsx +45 -0
- package/lib/components/NumberInput.tsx +328 -0
- package/lib/components/Popper.tsx +100 -0
- package/lib/components/ProgressBar.tsx +105 -0
- package/lib/components/RestrictedInput.jsx +301 -0
- package/lib/components/RoundGauge.tsx +180 -0
- package/lib/components/Section.tsx +120 -0
- package/lib/components/Slider.tsx +169 -0
- package/lib/components/Stack.tsx +96 -0
- package/lib/components/StyleableSection.tsx +33 -0
- package/lib/components/Table.tsx +84 -0
- package/lib/components/Tabs.tsx +89 -0
- package/lib/components/TextArea.tsx +182 -0
- package/lib/components/TimeDisplay.jsx +64 -0
- package/lib/components/Tooltip.tsx +152 -0
- package/lib/components/TrackOutsideClicks.tsx +35 -0
- package/lib/components/VirtualList.tsx +69 -0
- package/lib/styles/atomic/candystripe.scss +8 -0
- package/lib/styles/atomic/centered-image.scss +7 -0
- package/lib/styles/atomic/color.scss +21 -0
- package/lib/styles/atomic/debug-layout.scss +17 -0
- package/lib/styles/atomic/fit-text.scss +14 -0
- package/lib/styles/atomic/links.scss +12 -0
- package/lib/styles/atomic/outline.scss +47 -0
- package/lib/styles/atomic/text.scss +44 -0
- package/lib/styles/base.scss +32 -0
- package/lib/styles/colors.scss +92 -0
- package/lib/styles/components/BlockQuote.module.scss +20 -0
- package/lib/styles/components/BlockQuote.module.scss.d.ts +4 -0
- package/lib/styles/components/Button.module.scss +157 -0
- package/lib/styles/components/Button.module.scss.d.ts +46 -0
- package/lib/styles/components/ColorBox.module.scss +12 -0
- package/lib/styles/components/ColorBox.module.scss.d.ts +4 -0
- package/lib/styles/components/Dialog.module.scss +60 -0
- package/lib/styles/components/Dialog.module.scss.d.ts +10 -0
- package/lib/styles/components/Dimmer.module.scss +22 -0
- package/lib/styles/components/Dimmer.module.scss.d.ts +4 -0
- package/lib/styles/components/Divider.module.scss +27 -0
- package/lib/styles/components/Divider.module.scss.d.ts +6 -0
- package/lib/styles/components/Dropdown.scss +72 -0
- package/lib/styles/components/Flex.module.scss +13 -0
- package/lib/styles/components/Flex.module.scss.d.ts +5 -0
- package/lib/styles/components/Icon.module.scss +25 -0
- package/lib/styles/components/Icon.module.scss.d.ts +5 -0
- package/lib/styles/components/Input.module.scss +64 -0
- package/lib/styles/components/Input.module.scss.d.ts +8 -0
- package/lib/styles/components/Knob.module.scss +131 -0
- package/lib/styles/components/Knob.module.scss.d.ts +33 -0
- package/lib/styles/components/LabeledList.module.scss +49 -0
- package/lib/styles/components/LabeledList.module.scss.d.ts +8 -0
- package/lib/styles/components/MenuBar.module.scss +75 -0
- package/lib/styles/components/MenuBar.module.scss.d.ts +14 -0
- package/lib/styles/components/Modal.module.scss +14 -0
- package/lib/styles/components/Modal.module.scss.d.ts +4 -0
- package/lib/styles/components/NoticeBox.module.scss +65 -0
- package/lib/styles/components/NoticeBox.module.scss.d.ts +27 -0
- package/lib/styles/components/NumberInput.module.scss +71 -0
- package/lib/styles/components/NumberInput.module.scss.d.ts +9 -0
- package/lib/styles/components/ProgressBar.module.scss +63 -0
- package/lib/styles/components/ProgressBar.module.scss.d.ts +27 -0
- package/lib/styles/components/RoundGauge.module.scss +85 -0
- package/lib/styles/components/RoundGauge.module.scss.d.ts +49 -0
- package/lib/styles/components/Section.module.scss +130 -0
- package/lib/styles/components/Section.module.scss.d.ts +13 -0
- package/lib/styles/components/Slider.module.scss +54 -0
- package/lib/styles/components/Slider.module.scss.d.ts +8 -0
- package/lib/styles/components/Stack.module.scss +60 -0
- package/lib/styles/components/Stack.module.scss.d.ts +12 -0
- package/lib/styles/components/Table.module.scss +44 -0
- package/lib/styles/components/Table.module.scss.d.ts +10 -0
- package/lib/styles/components/Tabs.module.scss +144 -0
- package/lib/styles/components/Tabs.module.scss.d.ts +35 -0
- package/lib/styles/components/TextArea.module.scss +86 -0
- package/lib/styles/components/TextArea.module.scss.d.ts +11 -0
- package/lib/styles/components/Tooltip.module.scss +24 -0
- package/lib/styles/components/Tooltip.module.scss.d.ts +4 -0
- package/lib/styles/functions.scss +79 -0
- package/lib/styles/input.scss +9 -0
- package/lib/styles/main.scss +20 -0
- package/lib/styles/reset.scss +68 -0
- package/package.json +6 -6
- package/dist/ProgressBar.module-BkAFfFy0.js +0 -29
- package/dist/Section.module-CLVHJ4yA.js +0 -15
- package/dist/assets/BlockQuote.css +0 -1
- package/dist/assets/Button.css +0 -1
- package/dist/assets/ColorBox.css +0 -1
- package/dist/assets/Dialog.css +0 -1
- package/dist/assets/Dimmer.css +0 -1
- package/dist/assets/Divider.css +0 -1
- package/dist/assets/Flex.css +0 -1
- package/dist/assets/Icon.css +0 -6
- package/dist/assets/Input.css +0 -1
- package/dist/assets/Knob.css +0 -1
- package/dist/assets/LabeledList.css +0 -1
- package/dist/assets/MenuBar.css +0 -1
- package/dist/assets/Modal.css +0 -1
- package/dist/assets/NoticeBox.css +0 -1
- package/dist/assets/NumberInput.css +0 -1
- package/dist/assets/ProgressBar.css +0 -1
- package/dist/assets/RoundGauge.css +0 -1
- package/dist/assets/Section.css +0 -1
- package/dist/assets/Slider.css +0 -1
- package/dist/assets/Stack.css +0 -1
- package/dist/assets/Table.css +0 -1
- package/dist/assets/Tabs.css +0 -1
- package/dist/assets/TextArea.css +0 -1
- package/dist/assets/Tooltip.css +0 -1
- package/dist/common/assets.d.ts +0 -4
- package/dist/common/assets.js +0 -21
- package/dist/common/collections.d.ts +0 -10
- package/dist/common/collections.js +0 -15
- package/dist/common/color.d.ts +0 -25
- package/dist/common/color.js +0 -69
- package/dist/common/constants.d.ts +0 -102
- package/dist/common/constants.js +0 -312
- package/dist/common/events.d.ts +0 -33
- package/dist/common/events.js +0 -147
- package/dist/common/exhaustive.js +0 -6
- package/dist/common/format.d.ts +0 -11
- package/dist/common/format.js +0 -114
- package/dist/common/fp.js +0 -9
- package/dist/common/hotkeys.d.ts +0 -25
- package/dist/common/hotkeys.js +0 -112
- package/dist/common/http.d.ts +0 -4
- package/dist/common/http.js +0 -10
- package/dist/common/keycodes.d.ts +0 -85
- package/dist/common/keycodes.js +0 -88
- package/dist/common/keys.js +0 -8
- package/dist/common/math.d.ts +0 -39
- package/dist/common/math.js +0 -41
- package/dist/common/perf.d.ts +0 -24
- package/dist/common/perf.js +0 -33
- package/dist/common/random.d.ts +0 -16
- package/dist/common/random.js +0 -18
- package/dist/common/react.d.ts +0 -23
- package/dist/common/react.js +0 -30
- package/dist/common/redux.d.ts +0 -64
- package/dist/common/redux.js +0 -72
- package/dist/common/storage.js +0 -124
- package/dist/common/string.d.ts +0 -65
- package/dist/common/string.js +0 -83
- package/dist/common/timer.d.ts +0 -18
- package/dist/common/timer.js +0 -28
- package/dist/common/type-utils.d.ts +0 -9
- package/dist/common/type-utils.js +0 -25
- package/dist/common/uuid.d.ts +0 -9
- package/dist/common/uuid.js +0 -10
- package/dist/components/AnimatedNumber.d.ts +0 -60
- package/dist/components/AnimatedNumber.js +0 -76
- package/dist/components/Autofocus.d.ts +0 -4
- package/dist/components/Autofocus.js +0 -17
- package/dist/components/Blink.d.ts +0 -26
- package/dist/components/Blink.js +0 -56
- package/dist/components/BlockQuote.d.ts +0 -3
- package/dist/components/BlockQuote.js +0 -13
- package/dist/components/BodyZoneSelector.d.ts +0 -28
- package/dist/components/BodyZoneSelector.js +0 -115
- package/dist/components/Box.d.ts +0 -91
- package/dist/components/Box.js +0 -133
- package/dist/components/Button.d.ts +0 -93
- package/dist/components/Button.js +0 -298
- package/dist/components/ByondUi.js +0 -73
- package/dist/components/Chart.d.ts +0 -28
- package/dist/components/Chart.js +0 -95
- package/dist/components/Collapsible.d.ts +0 -15
- package/dist/components/Collapsible.js +0 -27
- package/dist/components/ColorBox.d.ts +0 -8
- package/dist/components/ColorBox.js +0 -24
- package/dist/components/Dialog.d.ts +0 -24
- package/dist/components/Dialog.js +0 -67
- package/dist/components/Dimmer.d.ts +0 -3
- package/dist/components/Dimmer.js +0 -13
- package/dist/components/Divider.d.ts +0 -6
- package/dist/components/Divider.js +0 -22
- package/dist/components/DmIcon.d.ts +0 -31
- package/dist/components/DmIcon.js +0 -31
- package/dist/components/DraggableControl.js +0 -176
- package/dist/components/Dropdown.d.ts +0 -48
- package/dist/components/Dropdown.js +0 -152
- package/dist/components/FakeTerminal.js +0 -38
- package/dist/components/FitText.d.ts +0 -22
- package/dist/components/FitText.js +0 -63
- package/dist/components/Flex.d.ts +0 -93
- package/dist/components/Flex.js +0 -72
- package/dist/components/Icon.d.ts +0 -30
- package/dist/components/Icon.js +0 -51
- package/dist/components/Image.d.ts +0 -14
- package/dist/components/Image.js +0 -35
- package/dist/components/InfinitePlane.js +0 -139
- package/dist/components/Input.d.ts +0 -61
- package/dist/components/Input.js +0 -89
- package/dist/components/KeyListener.d.ts +0 -15
- package/dist/components/KeyListener.js +0 -23
- package/dist/components/Knob.d.ts +0 -49
- package/dist/components/Knob.js +0 -162
- package/dist/components/LabeledControls.d.ts +0 -11
- package/dist/components/LabeledControls.js +0 -39
- package/dist/components/LabeledList.d.ts +0 -57
- package/dist/components/LabeledList.js +0 -94
- package/dist/components/MenuBar.d.ts +0 -28
- package/dist/components/MenuBar.js +0 -174
- package/dist/components/Modal.d.ts +0 -3
- package/dist/components/Modal.js +0 -25
- package/dist/components/NoticeBox.d.ts +0 -20
- package/dist/components/NoticeBox.js +0 -49
- package/dist/components/NumberInput.d.ts +0 -45
- package/dist/components/NumberInput.js +0 -221
- package/dist/components/Popper.d.ts +0 -27
- package/dist/components/Popper.js +0 -177
- package/dist/components/ProgressBar.d.ts +0 -46
- package/dist/components/ProgressBar.js +0 -37
- package/dist/components/RestrictedInput.js +0 -155
- package/dist/components/RoundGauge.d.ts +0 -53
- package/dist/components/RoundGauge.js +0 -147
- package/dist/components/Section.d.ts +0 -63
- package/dist/components/Section.js +0 -62
- package/dist/components/Slider.d.ts +0 -46
- package/dist/components/Slider.js +0 -124
- package/dist/components/Stack.d.ts +0 -27
- package/dist/components/Stack.js +0 -67
- package/dist/components/StyleableSection.d.ts +0 -11
- package/dist/components/StyleableSection.js +0 -16
- package/dist/components/Table.d.ts +0 -29
- package/dist/components/Table.js +0 -67
- package/dist/components/Tabs.d.ts +0 -23
- package/dist/components/Tabs.js +0 -89
- package/dist/components/TextArea.d.ts +0 -39
- package/dist/components/TextArea.js +0 -118
- package/dist/components/TimeDisplay.js +0 -34
- package/dist/components/Tooltip.d.ts +0 -29
- package/dist/components/Tooltip.js +0 -83
- package/dist/components/TrackOutsideClicks.d.ts +0 -13
- package/dist/components/TrackOutsideClicks.js +0 -24
- package/dist/components/VirtualList.d.ts +0 -8
- package/dist/components/VirtualList.js +0 -34
- package/dist/components/index.js +0 -92
- package/dist/popper-CiqSDJTE.js +0 -906
- /package/{dist/components/index.d.ts → lib/components/index.ts} +0 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
|
+
|
|
3
|
+
import { clamp01, keyOfMatchingRange, scale } from '../common/math';
|
|
4
|
+
import { classes } from '../common/react';
|
|
5
|
+
import progStyles from '../styles/components/ProgressBar.module.scss';
|
|
6
|
+
import styles from '../styles/components/Slider.module.scss';
|
|
7
|
+
import { BoxProps, computeBoxClassName, computeBoxProps } from './Box';
|
|
8
|
+
import { DraggableControl } from './DraggableControl';
|
|
9
|
+
|
|
10
|
+
type Props = {
|
|
11
|
+
/** Highest possible value. */
|
|
12
|
+
maxValue: number;
|
|
13
|
+
/** Lowest possible value. */
|
|
14
|
+
minValue: number;
|
|
15
|
+
/** Value itself, controls the position of the cursor. */
|
|
16
|
+
value: number;
|
|
17
|
+
} & Partial<{
|
|
18
|
+
/** Animates the value if it was changed externally. */
|
|
19
|
+
animated: boolean;
|
|
20
|
+
/** Custom css */
|
|
21
|
+
className: string;
|
|
22
|
+
/** Color of the slider. */
|
|
23
|
+
color: string;
|
|
24
|
+
/** If set, this value will be used to set the fill percentage of the progress bar filler independently of the main value. */
|
|
25
|
+
fillValue: number;
|
|
26
|
+
/** Format value using this function before displaying it. */
|
|
27
|
+
format: (value: number) => string;
|
|
28
|
+
/** Adjust value by this amount when dragging the input. */
|
|
29
|
+
onChange: (event: Event, value: number) => void;
|
|
30
|
+
/** An event, which fires when you release the input, or successfully enter a number. */
|
|
31
|
+
onDrag: (event: Event, value: number) => void;
|
|
32
|
+
/** Applies a `color` to the slider based on whether the value lands in the range between `from` and `to`. */
|
|
33
|
+
ranges: Record<string, [number, number]>;
|
|
34
|
+
/** Screen distance mouse needs to travel to adjust value by one `step`. */
|
|
35
|
+
step: number;
|
|
36
|
+
/** A number in milliseconds, for which the input will hold off from updating while events propagate through the backend. Default is about 250ms, increase it if you still see flickering. */
|
|
37
|
+
stepPixelSize: number;
|
|
38
|
+
/** Adjust value by this amount when dragging the input. */
|
|
39
|
+
suppressFlicker: boolean;
|
|
40
|
+
/** Unit to display to the right of value. */
|
|
41
|
+
unit: string;
|
|
42
|
+
}> &
|
|
43
|
+
BoxProps &
|
|
44
|
+
PropsWithChildren;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* ## Slider
|
|
48
|
+
* A horizontal, progressbar-like control which allows dialing
|
|
49
|
+
* in precise values by dragging it left and right.
|
|
50
|
+
*
|
|
51
|
+
* Single click opens an input box to manually type in a number.
|
|
52
|
+
*
|
|
53
|
+
*/
|
|
54
|
+
export function Slider(props: Props) {
|
|
55
|
+
const {
|
|
56
|
+
// Draggable props (passthrough)
|
|
57
|
+
animated,
|
|
58
|
+
format,
|
|
59
|
+
maxValue,
|
|
60
|
+
minValue,
|
|
61
|
+
onChange,
|
|
62
|
+
onDrag,
|
|
63
|
+
step,
|
|
64
|
+
stepPixelSize,
|
|
65
|
+
suppressFlicker,
|
|
66
|
+
unit,
|
|
67
|
+
value,
|
|
68
|
+
// Own props
|
|
69
|
+
className,
|
|
70
|
+
fillValue,
|
|
71
|
+
color,
|
|
72
|
+
ranges = {},
|
|
73
|
+
children,
|
|
74
|
+
...rest
|
|
75
|
+
} = props;
|
|
76
|
+
|
|
77
|
+
const hasContent = children !== undefined;
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<DraggableControl
|
|
81
|
+
dragMatrix={[1, 0]}
|
|
82
|
+
{...{
|
|
83
|
+
animated,
|
|
84
|
+
format,
|
|
85
|
+
maxValue,
|
|
86
|
+
minValue,
|
|
87
|
+
onChange,
|
|
88
|
+
onDrag,
|
|
89
|
+
step,
|
|
90
|
+
stepPixelSize,
|
|
91
|
+
suppressFlicker,
|
|
92
|
+
unit,
|
|
93
|
+
value,
|
|
94
|
+
}}
|
|
95
|
+
>
|
|
96
|
+
{(control) => {
|
|
97
|
+
const {
|
|
98
|
+
displayElement,
|
|
99
|
+
displayValue,
|
|
100
|
+
dragging,
|
|
101
|
+
handleDragStart,
|
|
102
|
+
inputElement,
|
|
103
|
+
value,
|
|
104
|
+
} = control;
|
|
105
|
+
|
|
106
|
+
const hasFillValue = fillValue !== undefined && fillValue !== null;
|
|
107
|
+
|
|
108
|
+
const scaledFillValue = scale(
|
|
109
|
+
fillValue ?? displayValue,
|
|
110
|
+
minValue,
|
|
111
|
+
maxValue,
|
|
112
|
+
);
|
|
113
|
+
const scaledDisplayValue = scale(displayValue, minValue, maxValue);
|
|
114
|
+
|
|
115
|
+
const effectiveColor =
|
|
116
|
+
color || keyOfMatchingRange(fillValue ?? value, ranges) || 'default';
|
|
117
|
+
|
|
118
|
+
return (
|
|
119
|
+
<div
|
|
120
|
+
className={classes([
|
|
121
|
+
styles.slider,
|
|
122
|
+
progStyles.progressBar,
|
|
123
|
+
progStyles['color__' + effectiveColor],
|
|
124
|
+
className,
|
|
125
|
+
computeBoxClassName(rest),
|
|
126
|
+
])}
|
|
127
|
+
{...computeBoxProps(rest)}
|
|
128
|
+
onMouseDown={handleDragStart}
|
|
129
|
+
>
|
|
130
|
+
<div
|
|
131
|
+
className={classes([
|
|
132
|
+
progStyles.fill,
|
|
133
|
+
hasFillValue && progStyles.fill__animated,
|
|
134
|
+
])}
|
|
135
|
+
style={{
|
|
136
|
+
width: clamp01(scaledFillValue) * 100 + '%',
|
|
137
|
+
opacity: 0.4,
|
|
138
|
+
}}
|
|
139
|
+
/>
|
|
140
|
+
<div
|
|
141
|
+
className={progStyles.fill}
|
|
142
|
+
style={{
|
|
143
|
+
width:
|
|
144
|
+
clamp01(Math.min(scaledFillValue, scaledDisplayValue)) * 100 +
|
|
145
|
+
'%',
|
|
146
|
+
}}
|
|
147
|
+
/>
|
|
148
|
+
<div
|
|
149
|
+
className={styles.cursorOffset}
|
|
150
|
+
style={{
|
|
151
|
+
width: clamp01(scaledDisplayValue) * 100 + '%',
|
|
152
|
+
}}
|
|
153
|
+
>
|
|
154
|
+
<div className={styles.cursor} />
|
|
155
|
+
<div className={styles.pointer} />
|
|
156
|
+
{dragging && (
|
|
157
|
+
<div className={styles.popupValue}>{displayElement}</div>
|
|
158
|
+
)}
|
|
159
|
+
</div>
|
|
160
|
+
<div className={progStyles.content}>
|
|
161
|
+
{hasContent ? children : displayElement}
|
|
162
|
+
</div>
|
|
163
|
+
{inputElement}
|
|
164
|
+
</div>
|
|
165
|
+
);
|
|
166
|
+
}}
|
|
167
|
+
</DraggableControl>
|
|
168
|
+
);
|
|
169
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file
|
|
3
|
+
* @copyright 2021 Aleksej Komarov
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
6
|
+
import { RefObject } from 'react';
|
|
7
|
+
|
|
8
|
+
import { classes } from '../common/react';
|
|
9
|
+
import styles from '../styles/components/Stack.module.scss';
|
|
10
|
+
import { computeBoxClassName } from './Box';
|
|
11
|
+
import {
|
|
12
|
+
computeFlexClassName,
|
|
13
|
+
computeFlexItemProps,
|
|
14
|
+
computeFlexProps,
|
|
15
|
+
FlexItemProps,
|
|
16
|
+
FlexProps,
|
|
17
|
+
} from './Flex';
|
|
18
|
+
|
|
19
|
+
type Props = Partial<{
|
|
20
|
+
/** Fills available space. */
|
|
21
|
+
fill: boolean;
|
|
22
|
+
/** Reverses the stack. */
|
|
23
|
+
reverse: boolean;
|
|
24
|
+
/** Flex column */
|
|
25
|
+
vertical: boolean;
|
|
26
|
+
/** Adds zebra striping to the stack. */
|
|
27
|
+
zebra: boolean;
|
|
28
|
+
}> &
|
|
29
|
+
FlexProps;
|
|
30
|
+
|
|
31
|
+
export function Stack(props: Props) {
|
|
32
|
+
const { className, vertical, fill, reverse, zebra, ...rest } = props;
|
|
33
|
+
|
|
34
|
+
const directionPrefix = vertical ? 'column' : 'row';
|
|
35
|
+
const directionSuffix = reverse ? '-reverse' : '';
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<div
|
|
39
|
+
className={classes([
|
|
40
|
+
fill && styles.fill,
|
|
41
|
+
vertical ? styles.vertical : styles.horizontal,
|
|
42
|
+
zebra && styles.zebra,
|
|
43
|
+
reverse && styles[`reverse${vertical ? '__vertical' : ''}`],
|
|
44
|
+
className,
|
|
45
|
+
computeFlexClassName(props),
|
|
46
|
+
])}
|
|
47
|
+
{...computeFlexProps({
|
|
48
|
+
direction: `${directionPrefix}${directionSuffix}`,
|
|
49
|
+
...rest,
|
|
50
|
+
})}
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
type StackItemProps = FlexItemProps &
|
|
56
|
+
Partial<{
|
|
57
|
+
innerRef: RefObject<HTMLDivElement>;
|
|
58
|
+
}>;
|
|
59
|
+
|
|
60
|
+
function StackItem(props: StackItemProps) {
|
|
61
|
+
const { className, innerRef, ...rest } = props;
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<div
|
|
65
|
+
className={classes([styles.item, className, computeBoxClassName(rest)])}
|
|
66
|
+
ref={innerRef}
|
|
67
|
+
{...computeFlexItemProps(rest)}
|
|
68
|
+
/>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
Stack.Item = StackItem;
|
|
73
|
+
|
|
74
|
+
type StackDividerProps = FlexItemProps &
|
|
75
|
+
Partial<{
|
|
76
|
+
hidden: boolean;
|
|
77
|
+
}>;
|
|
78
|
+
|
|
79
|
+
function StackDivider(props: StackDividerProps) {
|
|
80
|
+
const { className, hidden, ...rest } = props;
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<div
|
|
84
|
+
className={classes([
|
|
85
|
+
styles.item,
|
|
86
|
+
styles.divider,
|
|
87
|
+
hidden && styles.divider__hidden,
|
|
88
|
+
className,
|
|
89
|
+
computeBoxClassName(rest),
|
|
90
|
+
])}
|
|
91
|
+
{...computeFlexItemProps(rest)}
|
|
92
|
+
/>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
Stack.Divider = StackDivider;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { PropsWithChildren, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
import styles from '../styles/components/Section.module.scss';
|
|
4
|
+
import { Box } from './Box';
|
|
5
|
+
|
|
6
|
+
type Props = Partial<{
|
|
7
|
+
style: Record<string, any>;
|
|
8
|
+
textStyle: Record<string, any>;
|
|
9
|
+
title: ReactNode;
|
|
10
|
+
titleStyle: Record<string, any>;
|
|
11
|
+
titleSubtext: string;
|
|
12
|
+
}> &
|
|
13
|
+
PropsWithChildren;
|
|
14
|
+
|
|
15
|
+
// The cost of flexibility and prettiness.
|
|
16
|
+
export function StyleableSection(props: Props) {
|
|
17
|
+
const { children, titleStyle, titleSubtext, title, textStyle, style } = props;
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<Box style={style}>
|
|
21
|
+
{/* Yes, this box (line above) is missing the "Section" class. This is very intentional, as the layout looks *ugly* with it.*/}
|
|
22
|
+
<Box className={styles.title} style={titleStyle}>
|
|
23
|
+
<Box className={styles.titleText} style={textStyle}>
|
|
24
|
+
{title}
|
|
25
|
+
</Box>
|
|
26
|
+
<div className={styles.buttons}>{titleSubtext}</div>
|
|
27
|
+
</Box>
|
|
28
|
+
<Box className={styles.rest}>
|
|
29
|
+
<Box className={styles.content}>{children}</Box>
|
|
30
|
+
</Box>
|
|
31
|
+
</Box>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { classes } from '../common/react';
|
|
2
|
+
import styles from '../styles/components/Table.module.scss';
|
|
3
|
+
import { BoxProps, computeBoxClassName, computeBoxProps } from './Box';
|
|
4
|
+
|
|
5
|
+
type Props = Partial<{
|
|
6
|
+
/** Collapses table to the smallest possible size. */
|
|
7
|
+
collapsing: boolean;
|
|
8
|
+
}> &
|
|
9
|
+
BoxProps;
|
|
10
|
+
|
|
11
|
+
export function Table(props: Props) {
|
|
12
|
+
const { className, collapsing, children, ...rest } = props;
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<table
|
|
16
|
+
className={classes([
|
|
17
|
+
styles.table,
|
|
18
|
+
collapsing && styles.collapsing,
|
|
19
|
+
className,
|
|
20
|
+
computeBoxClassName(rest),
|
|
21
|
+
])}
|
|
22
|
+
{...computeBoxProps(rest)}
|
|
23
|
+
>
|
|
24
|
+
<tbody>{children}</tbody>
|
|
25
|
+
</table>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type RowProps = Partial<{
|
|
30
|
+
/** Whether this is a header cell. */
|
|
31
|
+
header: boolean;
|
|
32
|
+
}> &
|
|
33
|
+
BoxProps;
|
|
34
|
+
|
|
35
|
+
export function TableRow(props: RowProps) {
|
|
36
|
+
const { className, header, ...rest } = props;
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<tr
|
|
40
|
+
className={classes([
|
|
41
|
+
styles.row,
|
|
42
|
+
header && styles.row__header,
|
|
43
|
+
className,
|
|
44
|
+
computeBoxClassName(props),
|
|
45
|
+
])}
|
|
46
|
+
{...computeBoxProps(rest)}
|
|
47
|
+
/>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
Table.Row = TableRow;
|
|
52
|
+
|
|
53
|
+
type CellProps = Partial<{
|
|
54
|
+
/** Additional columns for this cell to expand, assuming there is room. */
|
|
55
|
+
colSpan: number;
|
|
56
|
+
/** Collapses table cell to the smallest possible size,
|
|
57
|
+
and stops any text inside from wrapping. */
|
|
58
|
+
collapsing: boolean;
|
|
59
|
+
/** Whether this is a header cell. */
|
|
60
|
+
header: boolean;
|
|
61
|
+
/** Rows for this cell to expand, assuming there is room. */
|
|
62
|
+
rowSpan: number;
|
|
63
|
+
}> &
|
|
64
|
+
BoxProps;
|
|
65
|
+
|
|
66
|
+
export function TableCell(props: CellProps) {
|
|
67
|
+
const { className, collapsing, colSpan, header, ...rest } = props;
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<td
|
|
71
|
+
className={classes([
|
|
72
|
+
styles.cell,
|
|
73
|
+
collapsing && styles.cell__collapsing,
|
|
74
|
+
header && styles.cell__header,
|
|
75
|
+
className,
|
|
76
|
+
computeBoxClassName(props),
|
|
77
|
+
])}
|
|
78
|
+
colSpan={colSpan}
|
|
79
|
+
{...computeBoxProps(rest)}
|
|
80
|
+
/>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
Table.Cell = TableCell;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { PropsWithChildren, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
import { canRender, classes } from '../common/react';
|
|
4
|
+
import styles from '../styles/components/Tabs.module.scss';
|
|
5
|
+
import { BoxProps, computeBoxClassName, computeBoxProps } from './Box';
|
|
6
|
+
import { Icon } from './Icon';
|
|
7
|
+
|
|
8
|
+
type Props = Partial<{
|
|
9
|
+
className: string;
|
|
10
|
+
fill: boolean;
|
|
11
|
+
fluid: boolean;
|
|
12
|
+
vertical: boolean;
|
|
13
|
+
}> &
|
|
14
|
+
BoxProps &
|
|
15
|
+
PropsWithChildren;
|
|
16
|
+
|
|
17
|
+
type TabProps = Partial<{
|
|
18
|
+
className: string;
|
|
19
|
+
color: string;
|
|
20
|
+
icon: string;
|
|
21
|
+
leftSlot: ReactNode;
|
|
22
|
+
onClick: (e?) => void;
|
|
23
|
+
rightSlot: ReactNode;
|
|
24
|
+
selected: boolean;
|
|
25
|
+
}> &
|
|
26
|
+
BoxProps &
|
|
27
|
+
PropsWithChildren;
|
|
28
|
+
|
|
29
|
+
export function Tabs(props: Props) {
|
|
30
|
+
const { className, vertical, fill, fluid, children, ...rest } = props;
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<div
|
|
34
|
+
className={classes([
|
|
35
|
+
styles.tabs,
|
|
36
|
+
vertical ? styles.vertical : styles.horizontal,
|
|
37
|
+
fill && styles.fill,
|
|
38
|
+
fluid && styles.fluid,
|
|
39
|
+
className,
|
|
40
|
+
computeBoxClassName(rest),
|
|
41
|
+
])}
|
|
42
|
+
{...computeBoxProps(rest)}
|
|
43
|
+
>
|
|
44
|
+
{children}
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function Tab(props: TabProps) {
|
|
50
|
+
const {
|
|
51
|
+
className,
|
|
52
|
+
selected,
|
|
53
|
+
color,
|
|
54
|
+
icon,
|
|
55
|
+
leftSlot,
|
|
56
|
+
rightSlot,
|
|
57
|
+
children,
|
|
58
|
+
...rest
|
|
59
|
+
} = props;
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<div
|
|
63
|
+
className={classes([
|
|
64
|
+
styles.tab,
|
|
65
|
+
styles.tabs__tab,
|
|
66
|
+
styles['color__' + color],
|
|
67
|
+
selected && styles.selected,
|
|
68
|
+
className,
|
|
69
|
+
computeBoxClassName(rest),
|
|
70
|
+
])}
|
|
71
|
+
{...computeBoxProps(rest)}
|
|
72
|
+
>
|
|
73
|
+
{(canRender(leftSlot) && (
|
|
74
|
+
<div className={styles.tab__left}>{leftSlot}</div>
|
|
75
|
+
)) ||
|
|
76
|
+
(!!icon && (
|
|
77
|
+
<div className={styles.tab__left}>
|
|
78
|
+
<Icon name={icon} />
|
|
79
|
+
</div>
|
|
80
|
+
))}
|
|
81
|
+
<div className={styles.tab__text}>{children}</div>
|
|
82
|
+
{canRender(rightSlot) && (
|
|
83
|
+
<div className={styles.tab__right}>{rightSlot}</div>
|
|
84
|
+
)}
|
|
85
|
+
</div>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
Tabs.Tab = Tab;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import {
|
|
2
|
+
forwardRef,
|
|
3
|
+
RefObject,
|
|
4
|
+
useEffect,
|
|
5
|
+
useImperativeHandle,
|
|
6
|
+
useRef,
|
|
7
|
+
useState,
|
|
8
|
+
} from 'react';
|
|
9
|
+
import { KeyboardEvent, SyntheticEvent } from 'react';
|
|
10
|
+
|
|
11
|
+
import { KEY } from '../common/keys';
|
|
12
|
+
import { classes } from '../common/react';
|
|
13
|
+
import styles from '../styles/components/TextArea.module.scss';
|
|
14
|
+
import { Box, BoxProps } from './Box';
|
|
15
|
+
import { toInputValue } from './Input';
|
|
16
|
+
|
|
17
|
+
type Props = Partial<{
|
|
18
|
+
autoFocus: boolean;
|
|
19
|
+
autoSelect: boolean;
|
|
20
|
+
displayedValue: string;
|
|
21
|
+
dontUseTabForIndent: boolean;
|
|
22
|
+
fluid: boolean;
|
|
23
|
+
maxLength: number;
|
|
24
|
+
noborder: boolean;
|
|
25
|
+
/** Fires when user is 'done typing': Clicked out, blur, enter key (but not shift+enter) */
|
|
26
|
+
onChange: (event: SyntheticEvent<HTMLTextAreaElement>, value: string) => void;
|
|
27
|
+
/** Fires once the enter key is pressed */
|
|
28
|
+
onEnter: (event: SyntheticEvent<HTMLTextAreaElement>, value: string) => void;
|
|
29
|
+
/** Fires once the escape key is pressed */
|
|
30
|
+
onEscape: (event: SyntheticEvent<HTMLTextAreaElement>) => void;
|
|
31
|
+
/** Fires on each key press / value change. Used for searching */
|
|
32
|
+
onInput: (event: SyntheticEvent<HTMLTextAreaElement>, value: string) => void;
|
|
33
|
+
placeholder: string;
|
|
34
|
+
scrollbar: boolean;
|
|
35
|
+
selfClear: boolean;
|
|
36
|
+
value: string;
|
|
37
|
+
}> &
|
|
38
|
+
BoxProps;
|
|
39
|
+
|
|
40
|
+
export const TextArea = forwardRef(
|
|
41
|
+
(props: Props, forwardedRef: RefObject<HTMLTextAreaElement>) => {
|
|
42
|
+
const {
|
|
43
|
+
autoFocus,
|
|
44
|
+
autoSelect,
|
|
45
|
+
displayedValue,
|
|
46
|
+
dontUseTabForIndent,
|
|
47
|
+
maxLength,
|
|
48
|
+
noborder,
|
|
49
|
+
onChange,
|
|
50
|
+
onEnter,
|
|
51
|
+
onEscape,
|
|
52
|
+
onInput,
|
|
53
|
+
placeholder,
|
|
54
|
+
scrollbar,
|
|
55
|
+
selfClear,
|
|
56
|
+
value,
|
|
57
|
+
...boxProps
|
|
58
|
+
} = props;
|
|
59
|
+
const { className, fluid, nowrap, ...rest } = boxProps;
|
|
60
|
+
|
|
61
|
+
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
|
62
|
+
const [scrolledAmount, setScrolledAmount] = useState(0);
|
|
63
|
+
|
|
64
|
+
function handleKeyDown(event: KeyboardEvent<HTMLTextAreaElement>) {
|
|
65
|
+
if (event.key === KEY.Enter) {
|
|
66
|
+
if (event.shiftKey) {
|
|
67
|
+
event.currentTarget.focus();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
onEnter?.(event, event.currentTarget.value);
|
|
72
|
+
if (selfClear) {
|
|
73
|
+
event.currentTarget.value = '';
|
|
74
|
+
}
|
|
75
|
+
event.currentTarget.blur();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (event.key === KEY.Escape) {
|
|
80
|
+
onEscape?.(event);
|
|
81
|
+
if (selfClear) {
|
|
82
|
+
event.currentTarget.value = '';
|
|
83
|
+
} else {
|
|
84
|
+
event.currentTarget.value = toInputValue(value);
|
|
85
|
+
event.currentTarget.blur();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (!dontUseTabForIndent && event.key === KEY.Tab) {
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
const { value, selectionStart, selectionEnd } = event.currentTarget;
|
|
94
|
+
event.currentTarget.value =
|
|
95
|
+
value.substring(0, selectionStart) +
|
|
96
|
+
'\t' +
|
|
97
|
+
value.substring(selectionEnd);
|
|
98
|
+
event.currentTarget.selectionEnd = selectionStart + 1;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
useImperativeHandle(
|
|
103
|
+
forwardedRef,
|
|
104
|
+
() => textareaRef.current as HTMLTextAreaElement,
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
/** Focuses the input on mount */
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
if (!autoFocus && !autoSelect) return;
|
|
110
|
+
|
|
111
|
+
const input = textareaRef.current;
|
|
112
|
+
if (!input) return;
|
|
113
|
+
|
|
114
|
+
if (autoFocus || autoSelect) {
|
|
115
|
+
setTimeout(() => {
|
|
116
|
+
input.focus();
|
|
117
|
+
|
|
118
|
+
if (autoSelect) {
|
|
119
|
+
input.select();
|
|
120
|
+
}
|
|
121
|
+
}, 1);
|
|
122
|
+
}
|
|
123
|
+
}, []);
|
|
124
|
+
|
|
125
|
+
/** Updates the initial value on props change */
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
const input = textareaRef.current;
|
|
128
|
+
if (!input) return;
|
|
129
|
+
|
|
130
|
+
const newValue = toInputValue(value);
|
|
131
|
+
if (input.value === newValue) return;
|
|
132
|
+
|
|
133
|
+
input.value = newValue;
|
|
134
|
+
}, [value]);
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<Box
|
|
138
|
+
className={classes([
|
|
139
|
+
styles.textArea,
|
|
140
|
+
fluid && styles.fluid,
|
|
141
|
+
noborder && styles.noborder,
|
|
142
|
+
className,
|
|
143
|
+
])}
|
|
144
|
+
{...rest}
|
|
145
|
+
>
|
|
146
|
+
{!!displayedValue && (
|
|
147
|
+
<div className={styles.wrapper}>
|
|
148
|
+
<div
|
|
149
|
+
className={classes([styles.inner, styles.custom])}
|
|
150
|
+
style={{
|
|
151
|
+
transform: `translateY(-${scrolledAmount}px)`,
|
|
152
|
+
}}
|
|
153
|
+
>
|
|
154
|
+
{displayedValue}
|
|
155
|
+
</div>
|
|
156
|
+
</div>
|
|
157
|
+
)}
|
|
158
|
+
<textarea
|
|
159
|
+
className={classes([
|
|
160
|
+
styles.inner,
|
|
161
|
+
scrollbar && styles.scrollable,
|
|
162
|
+
nowrap && styles.nowrap,
|
|
163
|
+
])}
|
|
164
|
+
maxLength={maxLength}
|
|
165
|
+
onBlur={(event) => onChange?.(event, event.target.value)}
|
|
166
|
+
onChange={(event) => onInput?.(event, event.target.value)}
|
|
167
|
+
onKeyDown={handleKeyDown}
|
|
168
|
+
onScroll={() => {
|
|
169
|
+
if (displayedValue && textareaRef.current) {
|
|
170
|
+
setScrolledAmount(textareaRef.current.scrollTop);
|
|
171
|
+
}
|
|
172
|
+
}}
|
|
173
|
+
placeholder={placeholder}
|
|
174
|
+
ref={textareaRef}
|
|
175
|
+
style={{
|
|
176
|
+
color: displayedValue ? 'rgba(0, 0, 0, 0)' : 'inherit',
|
|
177
|
+
}}
|
|
178
|
+
/>
|
|
179
|
+
</Box>
|
|
180
|
+
);
|
|
181
|
+
},
|
|
182
|
+
);
|