tgui-core 1.0.0

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.
Files changed (152) hide show
  1. package/.editorconfig +10 -0
  2. package/.eslintrc.cjs +78 -0
  3. package/.gitattributes +4 -0
  4. package/.prettierrc.yml +1 -0
  5. package/.vscode/extensions.json +6 -0
  6. package/.vscode/settings.json +5 -0
  7. package/README.md +1 -0
  8. package/global.d.ts +173 -0
  9. package/package.json +25 -0
  10. package/src/assets.ts +43 -0
  11. package/src/backend.ts +369 -0
  12. package/src/common/collections.ts +349 -0
  13. package/src/common/color.ts +94 -0
  14. package/src/common/events.ts +45 -0
  15. package/src/common/exhaustive.ts +19 -0
  16. package/src/common/fp.ts +38 -0
  17. package/src/common/keycodes.ts +86 -0
  18. package/src/common/keys.ts +39 -0
  19. package/src/common/math.ts +98 -0
  20. package/src/common/perf.ts +72 -0
  21. package/src/common/random.ts +32 -0
  22. package/src/common/react.ts +65 -0
  23. package/src/common/redux.ts +196 -0
  24. package/src/common/storage.js +196 -0
  25. package/src/common/string.ts +173 -0
  26. package/src/common/timer.ts +68 -0
  27. package/src/common/type-utils.ts +41 -0
  28. package/src/common/types.ts +9 -0
  29. package/src/common/uuid.ts +24 -0
  30. package/src/common/vector.ts +51 -0
  31. package/src/components/AnimatedNumber.tsx +185 -0
  32. package/src/components/Autofocus.tsx +23 -0
  33. package/src/components/Blink.jsx +69 -0
  34. package/src/components/BlockQuote.tsx +15 -0
  35. package/src/components/BodyZoneSelector.tsx +149 -0
  36. package/src/components/Box.tsx +255 -0
  37. package/src/components/Button.tsx +415 -0
  38. package/src/components/ByondUi.jsx +121 -0
  39. package/src/components/Chart.tsx +160 -0
  40. package/src/components/Collapsible.tsx +45 -0
  41. package/src/components/ColorBox.tsx +30 -0
  42. package/src/components/Dialog.tsx +85 -0
  43. package/src/components/Dimmer.tsx +19 -0
  44. package/src/components/Divider.tsx +26 -0
  45. package/src/components/DmIcon.tsx +72 -0
  46. package/src/components/DraggableControl.jsx +282 -0
  47. package/src/components/Dropdown.tsx +246 -0
  48. package/src/components/FakeTerminal.jsx +52 -0
  49. package/src/components/FitText.tsx +99 -0
  50. package/src/components/Flex.tsx +105 -0
  51. package/src/components/Grid.tsx +44 -0
  52. package/src/components/Icon.tsx +91 -0
  53. package/src/components/Image.tsx +63 -0
  54. package/src/components/InfinitePlane.jsx +192 -0
  55. package/src/components/Input.tsx +181 -0
  56. package/src/components/KeyListener.tsx +40 -0
  57. package/src/components/Knob.tsx +185 -0
  58. package/src/components/LabeledControls.tsx +50 -0
  59. package/src/components/LabeledList.tsx +130 -0
  60. package/src/components/MenuBar.tsx +238 -0
  61. package/src/components/Modal.tsx +25 -0
  62. package/src/components/NoticeBox.tsx +48 -0
  63. package/src/components/NumberInput.tsx +328 -0
  64. package/src/components/Popper.tsx +100 -0
  65. package/src/components/ProgressBar.tsx +79 -0
  66. package/src/components/RestrictedInput.jsx +301 -0
  67. package/src/components/RoundGauge.tsx +189 -0
  68. package/src/components/Section.tsx +125 -0
  69. package/src/components/Slider.tsx +173 -0
  70. package/src/components/Stack.tsx +101 -0
  71. package/src/components/StyleableSection.tsx +30 -0
  72. package/src/components/Table.tsx +90 -0
  73. package/src/components/Tabs.tsx +90 -0
  74. package/src/components/TextArea.tsx +198 -0
  75. package/src/components/TimeDisplay.jsx +64 -0
  76. package/src/components/Tooltip.tsx +147 -0
  77. package/src/components/TrackOutsideClicks.tsx +35 -0
  78. package/src/components/VirtualList.tsx +69 -0
  79. package/src/constants.ts +355 -0
  80. package/src/debug/KitchenSink.jsx +56 -0
  81. package/src/debug/actions.js +11 -0
  82. package/src/debug/hooks.js +10 -0
  83. package/src/debug/index.ts +10 -0
  84. package/src/debug/middleware.js +86 -0
  85. package/src/debug/reducer.js +22 -0
  86. package/src/debug/selectors.js +7 -0
  87. package/src/drag.ts +280 -0
  88. package/src/events.ts +237 -0
  89. package/src/focus.ts +25 -0
  90. package/src/format.ts +173 -0
  91. package/src/hotkeys.ts +212 -0
  92. package/src/http.ts +16 -0
  93. package/src/layouts/Layout.tsx +75 -0
  94. package/src/layouts/NtosWindow.tsx +162 -0
  95. package/src/layouts/Pane.tsx +56 -0
  96. package/src/layouts/Window.tsx +227 -0
  97. package/src/renderer.ts +50 -0
  98. package/styles/base.scss +32 -0
  99. package/styles/colors.scss +92 -0
  100. package/styles/components/BlockQuote.scss +20 -0
  101. package/styles/components/Button.scss +175 -0
  102. package/styles/components/ColorBox.scss +12 -0
  103. package/styles/components/Dialog.scss +105 -0
  104. package/styles/components/Dimmer.scss +22 -0
  105. package/styles/components/Divider.scss +27 -0
  106. package/styles/components/Dropdown.scss +72 -0
  107. package/styles/components/Flex.scss +31 -0
  108. package/styles/components/Icon.scss +25 -0
  109. package/styles/components/Input.scss +68 -0
  110. package/styles/components/Knob.scss +131 -0
  111. package/styles/components/LabeledList.scss +49 -0
  112. package/styles/components/MenuBar.scss +75 -0
  113. package/styles/components/Modal.scss +14 -0
  114. package/styles/components/NoticeBox.scss +65 -0
  115. package/styles/components/NumberInput.scss +76 -0
  116. package/styles/components/ProgressBar.scss +63 -0
  117. package/styles/components/RoundGauge.scss +88 -0
  118. package/styles/components/Section.scss +143 -0
  119. package/styles/components/Slider.scss +54 -0
  120. package/styles/components/Stack.scss +59 -0
  121. package/styles/components/Table.scss +44 -0
  122. package/styles/components/Tabs.scss +144 -0
  123. package/styles/components/TextArea.scss +84 -0
  124. package/styles/components/Tooltip.scss +24 -0
  125. package/styles/functions.scss +79 -0
  126. package/styles/layouts/Layout.scss +57 -0
  127. package/styles/layouts/NtosHeader.scss +20 -0
  128. package/styles/layouts/NtosWindow.scss +26 -0
  129. package/styles/layouts/TitleBar.scss +111 -0
  130. package/styles/layouts/Window.scss +103 -0
  131. package/styles/main.scss +97 -0
  132. package/styles/reset.scss +68 -0
  133. package/styles/themes/abductor.scss +68 -0
  134. package/styles/themes/admin.scss +38 -0
  135. package/styles/themes/cardtable.scss +57 -0
  136. package/styles/themes/hackerman.scss +70 -0
  137. package/styles/themes/malfunction.scss +67 -0
  138. package/styles/themes/neutral.scss +50 -0
  139. package/styles/themes/ntOS95.scss +166 -0
  140. package/styles/themes/ntos.scss +44 -0
  141. package/styles/themes/ntos_cat.scss +148 -0
  142. package/styles/themes/ntos_darkmode.scss +44 -0
  143. package/styles/themes/ntos_lightmode.scss +67 -0
  144. package/styles/themes/ntos_spooky.scss +69 -0
  145. package/styles/themes/ntos_synth.scss +99 -0
  146. package/styles/themes/ntos_terminal.scss +112 -0
  147. package/styles/themes/paper.scss +184 -0
  148. package/styles/themes/retro.scss +72 -0
  149. package/styles/themes/spookyconsole.scss +73 -0
  150. package/styles/themes/syndicate.scss +67 -0
  151. package/styles/themes/wizard.scss +68 -0
  152. package/tsconfig.json +34 -0
@@ -0,0 +1,185 @@
1
+ /**
2
+ * @file
3
+ * @copyright 2020 Aleksej Komarov
4
+ * @license MIT
5
+ */
6
+
7
+ import { keyOfMatchingRange, scale } from '../common/math';
8
+ import { BooleanLike, classes } from '../common/react';
9
+
10
+ import { BoxProps, computeBoxClassName, computeBoxProps } from './Box';
11
+ import { DraggableControl } from './DraggableControl';
12
+
13
+ type Props = {
14
+ /** Value itself, controls the position of the cursor. */
15
+ value: number;
16
+ } & Partial<{
17
+ /** Animates the value if it was changed externally. */
18
+ animated: boolean;
19
+ /** Knob can be bipolar or unipolar. */
20
+ bipolar: boolean;
21
+ /** Color of the outer ring around the knob. */
22
+ color: string | BooleanLike;
23
+ /** If set, this value will be used to set the fill percentage of the outer ring independently of the main value. */
24
+ fillValue: number;
25
+ /** Format value using this function before displaying it. */
26
+ format: (value: number) => string;
27
+ /** Highest possible value. */
28
+ maxValue: number;
29
+ /** Lowest possible value. */
30
+ minValue: number;
31
+ /** Adjust value by this amount when dragging the input. */
32
+ onChange: (event: Event, value: number) => void;
33
+ /** An event, which fires about every 500ms when you drag the input up and down, on release and on manual editing. */
34
+ onDrag: (event: Event, value: number) => void;
35
+ /** Applies a `color` to the outer ring around the knob based on whether the value lands in the range between `from` and `to`. */
36
+ ranges: Record<string, [number, number]>;
37
+ /** Relative size of the knob. `1` is normal size, `2` is two times bigger. Fractional numbers are supported. */
38
+ size: number;
39
+ /** Adjust value by this amount when dragging the input. */
40
+ step: number;
41
+ /** Screen distance mouse needs to travel to adjust value by one `step`. */
42
+ stepPixelSize: number;
43
+ /** 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. */
44
+ suppressFlicker: boolean;
45
+ /** Unit to display to the right of value. */
46
+ unit: string;
47
+ /** Whether to clamp the value to the range. */
48
+ unclamped: boolean;
49
+ }> &
50
+ BoxProps;
51
+
52
+ /**
53
+ * ## Knob
54
+ * A radial control which allows dialing in precise values by dragging it
55
+ * up and down.
56
+ *
57
+ * Single click opens an input box to manually type in a number.
58
+ */
59
+ export function Knob(props: Props) {
60
+ const {
61
+ // Draggable props (passthrough)
62
+ animated,
63
+ format,
64
+ maxValue,
65
+ minValue,
66
+ onChange,
67
+ onDrag,
68
+ step,
69
+ stepPixelSize,
70
+ suppressFlicker,
71
+ unclamped,
72
+ unit,
73
+ value,
74
+ // Own props
75
+ bipolar,
76
+ children,
77
+ className,
78
+ color,
79
+ fillValue,
80
+ ranges = {},
81
+ size = 1,
82
+ style,
83
+ ...rest
84
+ } = props;
85
+
86
+ return (
87
+ <DraggableControl
88
+ dragMatrix={[0, -1]}
89
+ {...{
90
+ animated,
91
+ format,
92
+ maxValue,
93
+ minValue,
94
+ onChange,
95
+ onDrag,
96
+ step,
97
+ stepPixelSize,
98
+ suppressFlicker,
99
+ unclamped,
100
+ unit,
101
+ value,
102
+ }}
103
+ >
104
+ {(control) => {
105
+ const {
106
+ displayElement,
107
+ displayValue,
108
+ dragging,
109
+ handleDragStart,
110
+ inputElement,
111
+ value,
112
+ } = control;
113
+ const scaledFillValue = scale(
114
+ fillValue ?? displayValue,
115
+ minValue,
116
+ maxValue
117
+ );
118
+ const scaledDisplayValue = scale(displayValue, minValue, maxValue);
119
+ const effectiveColor =
120
+ color || keyOfMatchingRange(fillValue ?? value, ranges) || 'default';
121
+ const rotation = Math.min((scaledDisplayValue - 0.5) * 270, 225);
122
+
123
+ return (
124
+ <div
125
+ className={classes([
126
+ 'Knob',
127
+ 'Knob--color--' + effectiveColor,
128
+ bipolar && 'Knob--bipolar',
129
+ className,
130
+ computeBoxClassName(rest),
131
+ ])}
132
+ {...computeBoxProps({
133
+ style: {
134
+ fontSize: size + 'em',
135
+ ...style,
136
+ },
137
+ ...rest,
138
+ })}
139
+ onMouseDown={handleDragStart}
140
+ >
141
+ <div className="Knob__circle">
142
+ <div
143
+ className="Knob__cursorBox"
144
+ style={{
145
+ transform: `rotate(${rotation}deg)`,
146
+ }}
147
+ >
148
+ <div className="Knob__cursor" />
149
+ </div>
150
+ </div>
151
+ {dragging && (
152
+ <div className="Knob__popupValue">{displayElement}</div>
153
+ )}
154
+ <svg
155
+ className="Knob__ring Knob__ringTrackPivot"
156
+ viewBox="0 0 100 100"
157
+ >
158
+ <circle className="Knob__ringTrack" cx="50" cy="50" r="50" />
159
+ </svg>
160
+ <svg
161
+ className="Knob__ring Knob__ringFillPivot"
162
+ viewBox="0 0 100 100"
163
+ >
164
+ <circle
165
+ className="Knob__ringFill"
166
+ style={{
167
+ strokeDashoffset: Math.max(
168
+ ((bipolar ? 2.75 : 2.0) - scaledFillValue * 1.5) *
169
+ Math.PI *
170
+ 50,
171
+ 0
172
+ ),
173
+ }}
174
+ cx="50"
175
+ cy="50"
176
+ r="50"
177
+ />
178
+ </svg>
179
+ {inputElement}
180
+ </div>
181
+ );
182
+ }}
183
+ </DraggableControl>
184
+ );
185
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @file
3
+ * @copyright 2020 Aleksej Komarov
4
+ * @license MIT
5
+ */
6
+
7
+ import { Flex, FlexProps } from './Flex';
8
+
9
+ export function LabeledControls(props: FlexProps) {
10
+ const { children, wrap, ...rest } = props;
11
+
12
+ return (
13
+ <Flex
14
+ mx={-0.5}
15
+ wrap={wrap}
16
+ align="stretch"
17
+ justify="space-between"
18
+ {...rest}
19
+ >
20
+ {children}
21
+ </Flex>
22
+ );
23
+ }
24
+
25
+ type ItemProps = {
26
+ label: string;
27
+ } & FlexProps;
28
+
29
+ function LabeledControlsItem(props: ItemProps) {
30
+ const { label, children, mx = 1, ...rest } = props;
31
+
32
+ return (
33
+ <Flex.Item mx={mx}>
34
+ <Flex
35
+ height="100%"
36
+ direction="column"
37
+ align="center"
38
+ textAlign="center"
39
+ justify="space-between"
40
+ {...rest}
41
+ >
42
+ <Flex.Item />
43
+ <Flex.Item>{children}</Flex.Item>
44
+ <Flex.Item color="label">{label}</Flex.Item>
45
+ </Flex>
46
+ </Flex.Item>
47
+ );
48
+ }
49
+
50
+ LabeledControls.Item = LabeledControlsItem;
@@ -0,0 +1,130 @@
1
+ /**
2
+ * @file
3
+ * @copyright 2020 Aleksej Komarov
4
+ * @license MIT
5
+ */
6
+
7
+ import { BooleanLike, classes } from '../common/react';
8
+ import { PropsWithChildren, ReactNode } from 'react';
9
+
10
+ import { Box, unit } from './Box';
11
+ import { Divider } from './Divider';
12
+ import { Tooltip } from './Tooltip';
13
+
14
+ export const LabeledList = (props: PropsWithChildren) => {
15
+ const { children } = props;
16
+ return <table className="LabeledList">{children}</table>;
17
+ };
18
+
19
+ type LabeledListItemProps = Partial<{
20
+ buttons: ReactNode;
21
+ className: string | BooleanLike;
22
+ color: string;
23
+ key: string | number;
24
+ label: string | ReactNode | BooleanLike;
25
+ labelColor: string;
26
+ labelWrap: boolean;
27
+ textAlign: string;
28
+ /** @deprecated */
29
+ content: any;
30
+ children: ReactNode;
31
+ verticalAlign: string;
32
+ tooltip: string;
33
+ }>;
34
+
35
+ const LabeledListItem = (props: LabeledListItemProps) => {
36
+ const {
37
+ className,
38
+ label,
39
+ labelColor = 'label',
40
+ labelWrap,
41
+ color,
42
+ textAlign,
43
+ buttons,
44
+ content,
45
+ children,
46
+ verticalAlign = 'baseline',
47
+ tooltip,
48
+ } = props;
49
+
50
+ let innerLabel;
51
+ if (label) {
52
+ innerLabel = label;
53
+ if (typeof label === 'string') innerLabel += ':';
54
+ }
55
+
56
+ if (tooltip !== undefined) {
57
+ innerLabel = (
58
+ <Tooltip content={tooltip}>
59
+ <Box
60
+ as="span"
61
+ style={{
62
+ borderBottom: '2px dotted rgba(255, 255, 255, 0.8)',
63
+ }}
64
+ >
65
+ {innerLabel}
66
+ </Box>
67
+ </Tooltip>
68
+ );
69
+ }
70
+
71
+ let labelChild = (
72
+ <Box
73
+ as="td"
74
+ color={labelColor}
75
+ className={classes([
76
+ 'LabeledList__cell',
77
+ // Kinda flipped because we want nowrap as default. Cleaner CSS this way though.
78
+ !labelWrap && 'LabeledList__label--nowrap',
79
+ ])}
80
+ verticalAlign={verticalAlign}
81
+ >
82
+ {innerLabel}
83
+ </Box>
84
+ );
85
+
86
+ return (
87
+ <tr className={classes(['LabeledList__row', className])}>
88
+ {labelChild}
89
+ <Box
90
+ as="td"
91
+ color={color}
92
+ textAlign={textAlign}
93
+ className={classes(['LabeledList__cell', 'LabeledList__content'])}
94
+ // @ts-ignore
95
+ colSpan={buttons ? undefined : 2}
96
+ verticalAlign={verticalAlign}
97
+ >
98
+ {content}
99
+ {children}
100
+ </Box>
101
+ {buttons && (
102
+ <td className="LabeledList__cell LabeledList__buttons">{buttons}</td>
103
+ )}
104
+ </tr>
105
+ );
106
+ };
107
+
108
+ type LabeledListDividerProps = {
109
+ size?: number;
110
+ };
111
+
112
+ const LabeledListDivider = (props: LabeledListDividerProps) => {
113
+ const padding = props.size ? unit(Math.max(0, props.size - 1)) : 0;
114
+ return (
115
+ <tr className="LabeledList__row">
116
+ <td
117
+ colSpan={3}
118
+ style={{
119
+ paddingTop: padding,
120
+ paddingBottom: padding,
121
+ }}
122
+ >
123
+ <Divider />
124
+ </td>
125
+ </tr>
126
+ );
127
+ };
128
+
129
+ LabeledList.Item = LabeledListItem;
130
+ LabeledList.Divider = LabeledListDivider;
@@ -0,0 +1,238 @@
1
+ /**
2
+ * @file
3
+ * @copyright 2022 Aleksej Komarov
4
+ * @license MIT
5
+ */
6
+
7
+ import { classes } from '../common/react';
8
+ import { Component, createRef, ReactNode, RefObject } from 'react';
9
+
10
+ import { logger } from '../logging';
11
+ import { Box } from './Box';
12
+ import { Icon } from './Icon';
13
+
14
+ type MenuProps = {
15
+ children: any;
16
+ width: string;
17
+ menuRef: RefObject<HTMLElement>;
18
+ onOutsideClick: () => void;
19
+ };
20
+
21
+ class Menu extends Component<MenuProps> {
22
+ private readonly handleClick: (event) => void;
23
+
24
+ constructor(props) {
25
+ super(props);
26
+ this.handleClick = (event) => {
27
+ if (!this.props.menuRef.current) {
28
+ logger.log(`Menu.handleClick(): No ref`);
29
+ return;
30
+ }
31
+
32
+ if (this.props.menuRef.current.contains(event.target)) {
33
+ logger.log(`Menu.handleClick(): Inside`);
34
+ } else {
35
+ logger.log(`Menu.handleClick(): Outside`);
36
+ this.props.onOutsideClick();
37
+ }
38
+ };
39
+ }
40
+
41
+ // eslint-disable-next-line react/no-deprecated
42
+ componentWillMount() {
43
+ window.addEventListener('click', this.handleClick);
44
+ }
45
+
46
+ componentWillUnmount() {
47
+ window.removeEventListener('click', this.handleClick);
48
+ }
49
+
50
+ render() {
51
+ const { width, children } = this.props;
52
+ return (
53
+ <div
54
+ className={'MenuBar__menu'}
55
+ style={{
56
+ width: width,
57
+ }}
58
+ >
59
+ {children}
60
+ </div>
61
+ );
62
+ }
63
+ }
64
+
65
+ type MenuBarDropdownProps = {
66
+ open: boolean;
67
+ openWidth: string;
68
+ children: any;
69
+ disabled?: boolean;
70
+ display: any;
71
+ onMouseOver: () => void;
72
+ onClick: () => void;
73
+ onOutsideClick: () => void;
74
+ className?: string;
75
+ };
76
+
77
+ class MenuBarButton extends Component<MenuBarDropdownProps> {
78
+ private readonly menuRef: RefObject<HTMLDivElement>;
79
+
80
+ constructor(props) {
81
+ super(props);
82
+ this.menuRef = createRef();
83
+ }
84
+
85
+ render() {
86
+ const { props } = this;
87
+ const {
88
+ open,
89
+ openWidth,
90
+ children,
91
+ disabled,
92
+ display,
93
+ onMouseOver,
94
+ onClick,
95
+ onOutsideClick,
96
+ ...boxProps
97
+ } = props;
98
+ const { className, ...rest } = boxProps;
99
+
100
+ return (
101
+ <div ref={this.menuRef}>
102
+ <Box
103
+ className={classes([
104
+ 'MenuBar__MenuBarButton',
105
+ 'MenuBar__font',
106
+ 'MenuBar__hover',
107
+ className,
108
+ ])}
109
+ {...rest}
110
+ onClick={disabled ? () => null : onClick}
111
+ onMouseOver={onMouseOver}
112
+ >
113
+ <span className="MenuBar__MenuBarButton-text">{display}</span>
114
+ </Box>
115
+ {open && (
116
+ <Menu
117
+ width={openWidth}
118
+ menuRef={this.menuRef}
119
+ onOutsideClick={onOutsideClick}
120
+ >
121
+ {children}
122
+ </Menu>
123
+ )}
124
+ </div>
125
+ );
126
+ }
127
+ }
128
+
129
+ type MenuBarItemProps = {
130
+ entry: string;
131
+ children: any;
132
+ openWidth: string;
133
+ display: ReactNode;
134
+ setOpenMenuBar: (entry: string | null) => void;
135
+ openMenuBar: string | null;
136
+ setOpenOnHover: (flag: boolean) => void;
137
+ openOnHover: boolean;
138
+ disabled?: boolean;
139
+ className?: string;
140
+ };
141
+
142
+ export const Dropdown = (props: MenuBarItemProps) => {
143
+ const {
144
+ entry,
145
+ children,
146
+ openWidth,
147
+ display,
148
+ setOpenMenuBar,
149
+ openMenuBar,
150
+ setOpenOnHover,
151
+ openOnHover,
152
+ disabled,
153
+ className,
154
+ } = props;
155
+
156
+ return (
157
+ <MenuBarButton
158
+ openWidth={openWidth}
159
+ display={display}
160
+ disabled={disabled}
161
+ open={openMenuBar === entry}
162
+ className={className}
163
+ onClick={() => {
164
+ const open = openMenuBar === entry ? null : entry;
165
+ setOpenMenuBar(open);
166
+ setOpenOnHover(!openOnHover);
167
+ }}
168
+ onOutsideClick={() => {
169
+ setOpenMenuBar(null);
170
+ setOpenOnHover(false);
171
+ }}
172
+ onMouseOver={() => {
173
+ if (openOnHover) {
174
+ setOpenMenuBar(entry);
175
+ }
176
+ }}
177
+ >
178
+ {children}
179
+ </MenuBarButton>
180
+ );
181
+ };
182
+
183
+ const MenuItemToggle = (props) => {
184
+ const { value, displayText, onClick, checked } = props;
185
+ return (
186
+ <Box
187
+ className={classes([
188
+ 'MenuBar__font',
189
+ 'MenuBar__MenuItem',
190
+ 'MenuBar__MenuItemToggle',
191
+ 'MenuBar__hover',
192
+ ])}
193
+ onClick={() => onClick(value)}
194
+ >
195
+ <div className="MenuBar__MenuItemToggle__check">
196
+ {checked && <Icon size={1.3} name="check" />}
197
+ </div>
198
+ {displayText}
199
+ </Box>
200
+ );
201
+ };
202
+
203
+ Dropdown.MenuItemToggle = MenuItemToggle;
204
+
205
+ const MenuItem = (props) => {
206
+ const { value, displayText, onClick } = props;
207
+ return (
208
+ <Box
209
+ className={classes([
210
+ 'MenuBar__font',
211
+ 'MenuBar__MenuItem',
212
+ 'MenuBar__hover',
213
+ ])}
214
+ onClick={() => onClick(value)}
215
+ >
216
+ {displayText}
217
+ </Box>
218
+ );
219
+ };
220
+
221
+ Dropdown.MenuItem = MenuItem;
222
+
223
+ const Separator = () => {
224
+ return <div className="MenuBar__Separator" />;
225
+ };
226
+
227
+ Dropdown.Separator = Separator;
228
+
229
+ type MenuBarProps = {
230
+ children: any;
231
+ };
232
+
233
+ export const MenuBar = (props: MenuBarProps) => {
234
+ const { children } = props;
235
+ return <Box className="MenuBar">{children}</Box>;
236
+ };
237
+
238
+ MenuBar.Dropdown = Dropdown;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @file
3
+ * @copyright 2020 Aleksej Komarov
4
+ * @license MIT
5
+ */
6
+
7
+ import { classes } from '../common/react';
8
+
9
+ import { BoxProps, computeBoxClassName, computeBoxProps } from './Box';
10
+ import { Dimmer } from './Dimmer';
11
+
12
+ export function Modal(props: BoxProps) {
13
+ const { className, children, ...rest } = props;
14
+
15
+ return (
16
+ <Dimmer>
17
+ <div
18
+ className={classes(['Modal', className, computeBoxClassName(rest)])}
19
+ {...computeBoxProps(rest)}
20
+ >
21
+ {children}
22
+ </div>
23
+ </Dimmer>
24
+ );
25
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @file
3
+ * @copyright 2020 Aleksej Komarov
4
+ * @license MIT
5
+ */
6
+
7
+ import { classes } from '../common/react';
8
+
9
+ import { Box, BoxProps } from './Box';
10
+
11
+ type Props = ExclusiveProps & BoxProps;
12
+
13
+ /** You MUST use only one or none */
14
+ type NoticeType = 'info' | 'success' | 'danger';
15
+
16
+ type None = {
17
+ [K in NoticeType]?: undefined;
18
+ };
19
+
20
+ type ExclusiveProps =
21
+ | None
22
+ | (Omit<None, 'info'> & {
23
+ info: boolean;
24
+ })
25
+ | (Omit<None, 'success'> & {
26
+ success: boolean;
27
+ })
28
+ | (Omit<None, 'danger'> & {
29
+ danger: boolean;
30
+ });
31
+
32
+ export function NoticeBox(props: Props) {
33
+ const { className, color, info, success, danger, ...rest } = props;
34
+
35
+ return (
36
+ <Box
37
+ className={classes([
38
+ 'NoticeBox',
39
+ color && 'NoticeBox--color--' + color,
40
+ info && 'NoticeBox--type--info',
41
+ success && 'NoticeBox--type--success',
42
+ danger && 'NoticeBox--type--danger',
43
+ className,
44
+ ])}
45
+ {...rest}
46
+ />
47
+ );
48
+ }