tgui-core 1.3.2 → 1.5.1

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 (37) hide show
  1. package/README.md +24 -2
  2. package/dist/common/ui.d.ts +113 -0
  3. package/dist/common/ui.js +137 -0
  4. package/dist/components/AnimatedNumber.d.ts +1 -0
  5. package/dist/components/BlockQuote.d.ts +5 -0
  6. package/dist/components/Box.d.ts +74 -63
  7. package/dist/components/Box.js +13 -127
  8. package/dist/components/Button.d.ts +22 -5
  9. package/dist/components/Button.js +2 -1
  10. package/dist/components/ByondUi.d.ts +50 -0
  11. package/dist/components/ByondUi.js +32 -44
  12. package/dist/components/ColorBox.js +1 -1
  13. package/dist/components/Dropdown.js +1 -1
  14. package/dist/components/Flex.js +1 -1
  15. package/dist/components/Icon.d.ts +1 -1
  16. package/dist/components/Icon.js +2 -2
  17. package/dist/components/Image.js +22 -21
  18. package/dist/components/ImageButton.js +1 -1
  19. package/dist/components/InfinitePlane.js +1 -1
  20. package/dist/components/Input.d.ts +6 -3
  21. package/dist/components/Input.js +60 -55
  22. package/dist/components/KeyListener.d.ts +2 -8
  23. package/dist/components/KeyListener.js +11 -19
  24. package/dist/components/Knob.js +1 -1
  25. package/dist/components/LabeledList.js +16 -15
  26. package/dist/components/Modal.js +1 -1
  27. package/dist/components/ProgressBar.js +1 -1
  28. package/dist/components/RoundGauge.d.ts +2 -1
  29. package/dist/components/RoundGauge.js +19 -18
  30. package/dist/components/Section.d.ts +43 -27
  31. package/dist/components/Section.js +64 -66
  32. package/dist/components/Slider.js +1 -1
  33. package/dist/components/Stack.js +1 -1
  34. package/dist/components/Table.js +1 -1
  35. package/dist/components/Tabs.js +1 -1
  36. package/dist/components/TextArea.d.ts +2 -1
  37. package/package.json +20 -12
package/README.md CHANGED
@@ -11,11 +11,11 @@ You can view the code on [GitHub](https://github.com/tgstation/tgui-core).
11
11
  (assuming you have a tgui folder, navigate to the specific package)
12
12
 
13
13
  ```sh
14
- cd tgui/packages/tgui
14
+ cd tgui/packages/{package name}
15
15
  yarn add tgui-core
16
16
  ```
17
17
 
18
- ## Usage
18
+ ## Using the components
19
19
 
20
20
  Now, you can use them like normal TGUI components.
21
21
 
@@ -32,6 +32,28 @@ import { Button } from "tgui-core/components";
32
32
  import { Box } from "../components";
33
33
  ```
34
34
 
35
+ ## Using the styles
36
+
37
+ You have two options for importing styles:
38
+
39
+ ### 1. Importing All Styles
40
+
41
+ To import all styles at once, add the following line to your main Sass file:
42
+
43
+ ```scss
44
+ @use "pkg:tgui-styles";
45
+ ```
46
+
47
+ ### 2. Importing Individual Styles
48
+
49
+ To import individual styles, add any of the exported styles to your main Sass file:
50
+
51
+ ```scss
52
+ @use "pkg:tgui-styles/components/Button";
53
+ @use "pkg:tgui-styles/components/Dialog";
54
+ @use "pkg:tgui-styles/components/NoticeBox";
55
+ ```
56
+
35
57
  ## License
36
58
 
37
59
  MIT
@@ -0,0 +1,113 @@
1
+ import { BoxProps } from '../components/Box';
2
+ import { BooleanLike } from './react';
3
+ type UnitMapper = (value: unknown) => string | undefined;
4
+ /**
5
+ * Coverts our rem-like spacing unit into a CSS unit.
6
+ */
7
+ export declare const unit: UnitMapper;
8
+ /**
9
+ * Same as `unit`, but half the size for integers numbers.
10
+ */
11
+ export declare const halfUnit: UnitMapper;
12
+ export type StringStyleMap = {
13
+ /** Align text inside the box. */
14
+ align: string | BooleanLike;
15
+ /** A direct mapping to `position` CSS property. */
16
+ position: string | BooleanLike;
17
+ /** Vertical align property. */
18
+ verticalAlign: string | BooleanLike;
19
+ /** Sets background color. */
20
+ backgroundColor: string | BooleanLike;
21
+ /** Applies an atomic `color-<name>` class to the element. */
22
+ color: string | BooleanLike;
23
+ /** Opacity, from 0 to 1. */
24
+ opacity: string | BooleanLike;
25
+ /** Sets text color. */
26
+ textColor: string | BooleanLike;
27
+ /** Margin on all sides. */
28
+ m: string | BooleanLike;
29
+ /** Bottom margin. */
30
+ mb: string | BooleanLike;
31
+ /** Left margin. */
32
+ ml: string | BooleanLike;
33
+ /** Right margin. */
34
+ mr: string | BooleanLike;
35
+ /** Top margin. */
36
+ mt: string | BooleanLike;
37
+ /** Horizontal margin. */
38
+ mx: string | BooleanLike;
39
+ /** Vertical margin. */
40
+ my: string | BooleanLike;
41
+ /** Bottom margin. */
42
+ bottom: string | BooleanLike;
43
+ /** Left margin. */
44
+ left: string | BooleanLike;
45
+ /** Right margin. */
46
+ right: string | BooleanLike;
47
+ /** Top margin. */
48
+ top: string | BooleanLike;
49
+ /** Overflow property. */
50
+ overflow: string | BooleanLike;
51
+ /** Overflow-X property. */
52
+ overflowX: string | BooleanLike;
53
+ /** Overflow-Y property. */
54
+ overflowY: string | BooleanLike;
55
+ /** Padding on all sides. */
56
+ p: string | BooleanLike;
57
+ /** Bottom padding. */
58
+ pb: string | BooleanLike;
59
+ /** Left padding. */
60
+ pl: string | BooleanLike;
61
+ /** Right padding. */
62
+ pr: string | BooleanLike;
63
+ /** Top padding. */
64
+ pt: string | BooleanLike;
65
+ /** Horizontal padding. */
66
+ px: string | BooleanLike;
67
+ /** Vertical padding. */
68
+ py: string | BooleanLike;
69
+ /** Box height. */
70
+ height: string | BooleanLike;
71
+ /** Box maximum height. */
72
+ maxHeight: string | BooleanLike;
73
+ /** Box maximum width. */
74
+ maxWidth: string | BooleanLike;
75
+ /** Box minimum height. */
76
+ minHeight: string | BooleanLike;
77
+ /** Box minimum width. */
78
+ minWidth: string | BooleanLike;
79
+ /** Box width. */
80
+ width: string | BooleanLike;
81
+ /** Font family. */
82
+ fontFamily: string | BooleanLike;
83
+ /** Font size. */
84
+ fontSize: string | BooleanLike;
85
+ /** Font weight. */
86
+ fontWeight: string | BooleanLike;
87
+ /** Directly affects the height of text lines. Useful for adjusting button height. */
88
+ lineHeight: string | BooleanLike;
89
+ /** Align text inside the box. */
90
+ textAlign: string | BooleanLike;
91
+ };
92
+ export declare const stringStyleMap: Record<keyof StringStyleMap, any>;
93
+ export type BooleanStyleMap = {
94
+ /** Make text bold. */
95
+ bold: boolean;
96
+ /** Fill positioned parent. */
97
+ fillPositionedParent: boolean;
98
+ /** Forces the `Box` to appear as an `inline-block`. */
99
+ inline: boolean;
100
+ /** Make text italic. */
101
+ italic: boolean;
102
+ /** Stops text from wrapping. */
103
+ nowrap: boolean;
104
+ /** Preserves line-breaks and spacing in text. */
105
+ preserveWhitespace: boolean;
106
+ };
107
+ export declare const booleanStyleMap: Record<keyof BooleanStyleMap, any>;
108
+ export declare function computeBoxProps(props: any): Record<string, any>;
109
+ export declare function computeBoxClassName(props: BoxProps): string;
110
+ type StyleMap = StringStyleMap & BooleanStyleMap;
111
+ /** Super light implementation of tailwind-like class names. */
112
+ export declare function computeTwClass(input: string | undefined): StyleMap;
113
+ export {};
@@ -0,0 +1,137 @@
1
+ import { CSS_COLORS as u } from "./constants.js";
2
+ import { classes as y } from "./react.js";
3
+ const f = (o) => {
4
+ if (typeof o == "string")
5
+ return o.endsWith("px") ? `${Number.parseFloat(o) / 12}rem` : o;
6
+ if (typeof o == "number")
7
+ return `${o}rem`;
8
+ }, p = (o) => {
9
+ if (typeof o == "string")
10
+ return f(o);
11
+ if (typeof o == "number")
12
+ return f(o * 0.5);
13
+ };
14
+ function w(o) {
15
+ return !h(o);
16
+ }
17
+ function h(o) {
18
+ return typeof o == "string" && u.includes(o);
19
+ }
20
+ const c = (o) => (t, i) => {
21
+ (typeof i == "number" || typeof i == "string") && (t[o] = i);
22
+ }, n = (o, t) => (i, e) => {
23
+ (typeof e == "number" || typeof e == "string") && (i[o] = t(e));
24
+ }, l = (o, t) => (i, e) => {
25
+ e && (i[o] = t);
26
+ }, s = (o, t, i) => (e, r) => {
27
+ if (typeof r == "number" || typeof r == "string")
28
+ for (let m = 0; m < i.length; m++)
29
+ e[o + i[m]] = t(r);
30
+ }, a = (o) => (t, i) => {
31
+ w(i) && (t[o] = i);
32
+ }, d = {
33
+ align: c("textAlign"),
34
+ bottom: n("bottom", f),
35
+ fontFamily: c("fontFamily"),
36
+ fontSize: n("fontSize", f),
37
+ fontWeight: c("fontWeight"),
38
+ height: n("height", f),
39
+ left: n("left", f),
40
+ maxHeight: n("maxHeight", f),
41
+ maxWidth: n("maxWidth", f),
42
+ minHeight: n("minHeight", f),
43
+ minWidth: n("minWidth", f),
44
+ opacity: c("opacity"),
45
+ overflow: c("overflow"),
46
+ overflowX: c("overflowX"),
47
+ overflowY: c("overflowY"),
48
+ position: c("position"),
49
+ right: n("right", f),
50
+ textAlign: c("textAlign"),
51
+ top: n("top", f),
52
+ verticalAlign: c("verticalAlign"),
53
+ width: n("width", f),
54
+ lineHeight: (o, t) => {
55
+ typeof t == "number" ? o.lineHeight = t : typeof t == "string" && (o.lineHeight = f(t));
56
+ },
57
+ // Margin
58
+ m: s("margin", p, [
59
+ "Top",
60
+ "Bottom",
61
+ "Left",
62
+ "Right"
63
+ ]),
64
+ mb: n("marginBottom", p),
65
+ ml: n("marginLeft", p),
66
+ mr: n("marginRight", p),
67
+ mt: n("marginTop", p),
68
+ mx: s("margin", p, ["Left", "Right"]),
69
+ my: s("margin", p, ["Top", "Bottom"]),
70
+ // Padding
71
+ p: s("padding", p, [
72
+ "Top",
73
+ "Bottom",
74
+ "Left",
75
+ "Right"
76
+ ]),
77
+ pb: n("paddingBottom", p),
78
+ pl: n("paddingLeft", p),
79
+ pr: n("paddingRight", p),
80
+ pt: n("paddingTop", p),
81
+ px: s("padding", p, ["Left", "Right"]),
82
+ py: s("padding", p, ["Top", "Bottom"]),
83
+ // Color props
84
+ color: a("color"),
85
+ textColor: a("color"),
86
+ backgroundColor: a("backgroundColor")
87
+ }, b = {
88
+ bold: l("fontWeight", "bold"),
89
+ fillPositionedParent: (o, t) => {
90
+ t && (o.position = "absolute", o.top = 0, o.bottom = 0, o.left = 0, o.right = 0);
91
+ },
92
+ inline: l("display", "inline-block"),
93
+ italic: l("fontStyle", "italic"),
94
+ nowrap: l("whiteSpace", "nowrap"),
95
+ preserveWhitespace: l("whiteSpace", "pre-wrap")
96
+ };
97
+ function T(o) {
98
+ const t = {}, i = {};
99
+ for (const e in o) {
100
+ if (e === "style")
101
+ continue;
102
+ const r = o[e], m = d[e] || b[e];
103
+ m ? m(i, r) : t[e] = r;
104
+ }
105
+ return t.style = { ...i, ...o.style }, t;
106
+ }
107
+ function S(o) {
108
+ const t = o.textColor || o.color, { backgroundColor: i } = o;
109
+ return y([
110
+ h(t) && `color-${t}`,
111
+ h(i) && `color-bg-${i}`
112
+ ]);
113
+ }
114
+ function P(o) {
115
+ const t = {};
116
+ if (!o) return t;
117
+ const i = o.split(" ");
118
+ for (const e of i) {
119
+ const [r, m] = e.split("-");
120
+ if (r)
121
+ if (r in d) {
122
+ if (m === "") continue;
123
+ const g = Number(m);
124
+ !Number.isNaN(g) && Number.isFinite(g) ? t[r] = g : t[r] = m;
125
+ } else r in b ? t[r] = !0 : console.warn(`Unknown prop ${r}`);
126
+ }
127
+ return t;
128
+ }
129
+ export {
130
+ b as booleanStyleMap,
131
+ S as computeBoxClassName,
132
+ T as computeBoxProps,
133
+ P as computeTwClass,
134
+ p as halfUnit,
135
+ d as stringStyleMap,
136
+ f as unit
137
+ };
@@ -18,6 +18,7 @@ type Props = {
18
18
  initial?: number;
19
19
  }>;
20
20
  /**
21
+ * ## AnimatedNumber
21
22
  * An animated number label. Shows a number, formatted with an optionally
22
23
  * provided function, and animates it towards its target value.
23
24
  */
@@ -1,2 +1,7 @@
1
1
  import { BoxProps } from './Box';
2
+ /**
3
+ * ## BlockQuote
4
+ * Just a block quote, just like this example in markdown:
5
+ * > Here's an example of a block quote.
6
+ */
2
7
  export declare function BlockQuote(props: BoxProps): import("react/jsx-runtime").JSX.Element;
@@ -1,8 +1,7 @@
1
1
  import { CSSProperties, KeyboardEventHandler, MouseEventHandler, ReactNode, UIEventHandler } from 'react';
2
2
  import { BooleanLike } from '../common/react';
3
- type BooleanProps = Partial<Record<keyof typeof booleanStyleMap, boolean>>;
4
- type StringProps = Partial<Record<keyof typeof stringStyleMap, string | BooleanLike>>;
5
- export type EventHandlers = Partial<{
3
+ import { BooleanStyleMap, StringStyleMap } from '../common/ui';
4
+ type EventHandlers = {
6
5
  onClick: MouseEventHandler<HTMLDivElement>;
7
6
  onContextMenu: MouseEventHandler<HTMLDivElement>;
8
7
  onDoubleClick: MouseEventHandler<HTMLDivElement>;
@@ -14,78 +13,90 @@ export type EventHandlers = Partial<{
14
13
  onMouseOver: MouseEventHandler<HTMLDivElement>;
15
14
  onMouseUp: MouseEventHandler<HTMLDivElement>;
16
15
  onScroll: UIEventHandler<HTMLDivElement>;
17
- }>;
18
- export type BoxProps = Partial<{
16
+ };
17
+ type InternalProps = {
18
+ /** The component used for the root node. */
19
19
  as: string;
20
+ /** The content of the component. */
20
21
  children: ReactNode;
22
+ /** Class name to pass into the component. */
21
23
  className: string | BooleanLike;
24
+ /** The unique id of the component. */
22
25
  id: string;
26
+ /** The inline style of the component. */
23
27
  style: CSSProperties;
24
- }> & BooleanProps & StringProps & EventHandlers;
28
+ /**
29
+ * ### tw
30
+ * A shorthand classname syntax based loosely on tailwind.
31
+ *
32
+ * This takes all Box style props with a dash separator for params, e.g.'mb-4' or the prop name alone e.g. 'bold'.
33
+ *
34
+ * It's compatible with regular Box props, even on the same component, but it will take precedence.
35
+ *
36
+ * ### Example:
37
+ * ```tsx
38
+ * <Box tw="mb-2 bold fontSize-16px">
39
+ * // Is equivalent to
40
+ * <Box mb={2} bold fontSize="16px">
41
+ * ```
42
+ *
43
+ * ### Caveats:
44
+ * 1. You can't use this for custom props from other components.
45
+ *
46
+ * 2. There is no type info or safety for this method. Like the old days, it simply won't work if you use it incorrectly.
47
+ *
48
+ * 3. This should be a static string with minimal interpolation. If you need more logic, prefer the props approach.
49
+ */
50
+ tw: string;
51
+ };
52
+ export type BoxProps = Partial<InternalProps & BooleanStyleMap & StringStyleMap & EventHandlers>;
25
53
  type DangerDoNotUse = {
26
54
  dangerouslySetInnerHTML?: {
27
55
  __html: any;
28
56
  };
29
57
  };
30
58
  /**
31
- * Coverts our rem-like spacing unit into a CSS unit.
32
- */
33
- export declare function unit(value: unknown): string | undefined;
34
- /**
35
- * Same as `unit`, but half the size for integers numbers.
59
+ * ## Box
60
+ * The Box component serves as a wrapper component for most of the CSS utility
61
+ * needs. It creates a new DOM element, a `<div>` by default that can be changed
62
+ * with the `as` property. Let's say you want to use a `<span>` instead:
63
+ *
64
+ * @example
65
+ * ```tsx
66
+ * <Box as="span" m={1}>
67
+ * <Button />
68
+ * </Box>
69
+ * ```
70
+ *
71
+ * This works great when the changes can be isolated to a new DOM element.
72
+ * For instance, you can change the margin this way.
73
+ *
74
+ * However, sometimes you have to target the underlying DOM element.
75
+ * For instance, you want to change the text color of the button. The Button
76
+ * component defines its own color. CSS inheritance doesn't help.
77
+ *
78
+ * To workaround this problem, the Box children accept a render props function.
79
+ * This way, `Button` can pull out the `className` generated by the `Box`.
80
+ *
81
+ * @example
82
+ * ```tsx
83
+ * <Box color="primary">{(props) => <Button {...props} />}</Box>
84
+ * ```
85
+ *
86
+ * ## Box Units
87
+ *
88
+ * `Box` units, like width, height and margins can be defined in two ways:
89
+ *
90
+ * - By plain numbers
91
+ * - 1 unit equals `1rem` for width, height and positioning properties.
92
+ * - 1 unit equals `0.5rem` for margins and paddings.
93
+ * - By strings with proper CSS units
94
+ * - For example: `100px`, `2em`, `1rem`, `100%`, etc.
95
+ *
96
+ * If you need more precision, you can always use fractional numbers.
97
+ *
98
+ * Default font size (`1rem`) is equal to `12px`.
36
99
  */
37
- export declare function halfUnit(value: unknown): string | undefined;
38
- declare const stringStyleMap: {
39
- readonly align: (style: any, value: any) => void;
40
- readonly bottom: (style: any, value: any) => void;
41
- readonly fontFamily: (style: any, value: any) => void;
42
- readonly fontSize: (style: any, value: any) => void;
43
- readonly fontWeight: (style: any, value: any) => void;
44
- readonly height: (style: any, value: any) => void;
45
- readonly left: (style: any, value: any) => void;
46
- readonly maxHeight: (style: any, value: any) => void;
47
- readonly maxWidth: (style: any, value: any) => void;
48
- readonly minHeight: (style: any, value: any) => void;
49
- readonly minWidth: (style: any, value: any) => void;
50
- readonly opacity: (style: any, value: any) => void;
51
- readonly overflow: (style: any, value: any) => void;
52
- readonly overflowX: (style: any, value: any) => void;
53
- readonly overflowY: (style: any, value: any) => void;
54
- readonly position: (style: any, value: any) => void;
55
- readonly right: (style: any, value: any) => void;
56
- readonly textAlign: (style: any, value: any) => void;
57
- readonly top: (style: any, value: any) => void;
58
- readonly verticalAlign: (style: any, value: any) => void;
59
- readonly width: (style: any, value: any) => void;
60
- readonly lineHeight: (style: any, value: any) => void;
61
- readonly m: (style: any, value: any) => void;
62
- readonly mb: (style: any, value: any) => void;
63
- readonly ml: (style: any, value: any) => void;
64
- readonly mr: (style: any, value: any) => void;
65
- readonly mt: (style: any, value: any) => void;
66
- readonly mx: (style: any, value: any) => void;
67
- readonly my: (style: any, value: any) => void;
68
- readonly p: (style: any, value: any) => void;
69
- readonly pb: (style: any, value: any) => void;
70
- readonly pl: (style: any, value: any) => void;
71
- readonly pr: (style: any, value: any) => void;
72
- readonly pt: (style: any, value: any) => void;
73
- readonly px: (style: any, value: any) => void;
74
- readonly py: (style: any, value: any) => void;
75
- readonly color: (style: any, value: any) => void;
76
- readonly textColor: (style: any, value: any) => void;
77
- readonly backgroundColor: (style: any, value: any) => void;
78
- };
79
- declare const booleanStyleMap: {
80
- readonly bold: (style: any, value: any) => void;
81
- readonly fillPositionedParent: (style: any, value: any) => void;
82
- readonly inline: (style: any, value: any) => void;
83
- readonly italic: (style: any, value: any) => void;
84
- readonly nowrap: (style: any, value: any) => void;
85
- readonly preserveWhitespace: (style: any, value: any) => void;
86
- };
87
- export declare function computeBoxProps(props: any): Record<string, any>;
88
- export declare function computeBoxClassName(props: BoxProps): string;
89
100
  export declare function Box(props: BoxProps & DangerDoNotUse): import('react').ReactElement<{
90
101
  className: string;
91
102
  }, string | import('react').JSXElementConstructor<any>>;
@@ -1,133 +1,19 @@
1
- import { createElement as y } from "react";
2
- import { CSS_COLORS as b } from "../common/constants.js";
3
- import { classes as u } from "../common/react.js";
4
- function p(o) {
5
- if (typeof o == "string")
6
- return o.endsWith("px") ? `${Number.parseFloat(o) / 12}rem` : o;
7
- if (typeof o == "number")
8
- return `${o}rem`;
9
- }
10
- function r(o) {
11
- if (typeof o == "string")
12
- return p(o);
13
- if (typeof o == "number")
14
- return p(o * 0.5);
15
- }
16
- function x(o) {
17
- return !a(o);
18
- }
19
- function a(o) {
20
- return typeof o == "string" && b.includes(o);
21
- }
22
- const m = (o) => (t, i) => {
23
- (typeof i == "number" || typeof i == "string") && (t[o] = i);
24
- }, n = (o, t) => (i, e) => {
25
- (typeof e == "number" || typeof e == "string") && (i[o] = t(e));
26
- }, l = (o, t) => (i, e) => {
27
- e && (i[o] = t);
28
- }, g = (o, t, i) => (e, f) => {
29
- if (typeof f == "number" || typeof f == "string")
30
- for (let c = 0; c < i.length; c++)
31
- e[o + i[c]] = t(f);
32
- }, s = (o) => (t, i) => {
33
- x(i) && (t[o] = i);
34
- }, C = {
35
- align: m("textAlign"),
36
- bottom: n("bottom", p),
37
- fontFamily: m("fontFamily"),
38
- fontSize: n("fontSize", p),
39
- fontWeight: m("fontWeight"),
40
- height: n("height", p),
41
- left: n("left", p),
42
- maxHeight: n("maxHeight", p),
43
- maxWidth: n("maxWidth", p),
44
- minHeight: n("minHeight", p),
45
- minWidth: n("minWidth", p),
46
- opacity: m("opacity"),
47
- overflow: m("overflow"),
48
- overflowX: m("overflowX"),
49
- overflowY: m("overflowY"),
50
- position: m("position"),
51
- right: n("right", p),
52
- textAlign: m("textAlign"),
53
- top: n("top", p),
54
- verticalAlign: m("verticalAlign"),
55
- width: n("width", p),
56
- lineHeight: (o, t) => {
57
- typeof t == "number" ? o.lineHeight = t : typeof t == "string" && (o.lineHeight = p(t));
58
- },
59
- // Margin
60
- m: g("margin", r, [
61
- "Top",
62
- "Bottom",
63
- "Left",
64
- "Right"
65
- ]),
66
- mb: n("marginBottom", r),
67
- ml: n("marginLeft", r),
68
- mr: n("marginRight", r),
69
- mt: n("marginTop", r),
70
- mx: g("margin", r, ["Left", "Right"]),
71
- my: g("margin", r, ["Top", "Bottom"]),
72
- // Padding
73
- p: g("padding", r, [
74
- "Top",
75
- "Bottom",
76
- "Left",
77
- "Right"
78
- ]),
79
- pb: n("paddingBottom", r),
80
- pl: n("paddingLeft", r),
81
- pr: n("paddingRight", r),
82
- pt: n("paddingTop", r),
83
- px: g("padding", r, ["Left", "Right"]),
84
- py: g("padding", r, ["Top", "Bottom"]),
85
- // Color props
86
- color: s("color"),
87
- textColor: s("color"),
88
- backgroundColor: s("backgroundColor")
89
- }, w = {
90
- bold: l("fontWeight", "bold"),
91
- fillPositionedParent: (o, t) => {
92
- t && (o.position = "absolute", o.top = 0, o.bottom = 0, o.left = 0, o.right = 0);
93
- },
94
- inline: l("display", "inline-block"),
95
- italic: l("fontStyle", "italic"),
96
- nowrap: l("whiteSpace", "nowrap"),
97
- preserveWhitespace: l("whiteSpace", "pre-wrap")
98
- };
99
- function S(o) {
100
- const t = {}, i = {};
101
- for (const e of Object.keys(o)) {
102
- if (e === "style")
103
- continue;
104
- const f = o[e], c = C[e] || w[e];
105
- c ? c(i, f) : t[e] = f;
106
- }
107
- return t.style = { ...i, ...o.style }, t;
108
- }
109
- function d(o) {
110
- const t = o.textColor || o.color, i = o.backgroundColor;
111
- return u([
112
- a(t) && `color-${t}`,
113
- a(i) && `color-bg-${i}`
114
- ]);
115
- }
116
- function W(o) {
117
- const { as: t = "div", className: i, children: e, ...f } = o, c = i ? `${i} ${d(f)}` : d(f), h = S(f);
118
- return y(
119
- typeof t == "string" ? t : "div",
1
+ import { createElement as n } from "react";
2
+ import { computeBoxClassName as s, computeBoxProps as l, computeTwClass as u } from "../common/ui.js";
3
+ function x(t) {
4
+ const { as: m = "div", className: e, children: c, tw: r, ...o } = t, a = e ? `${e} ${s(o)}` : s(o), p = l({
5
+ ...o,
6
+ ...u(r)
7
+ });
8
+ return n(
9
+ m,
120
10
  {
121
- ...h,
122
- className: c
11
+ ...p,
12
+ className: a
123
13
  },
124
- e
14
+ c
125
15
  );
126
16
  }
127
17
  export {
128
- W as Box,
129
- d as computeBoxClassName,
130
- S as computeBoxProps,
131
- r as halfUnit,
132
- p as unit
18
+ x as Box
133
19
  };
@@ -54,7 +54,10 @@ type Props = Partial<{
54
54
  /** Align content vertically using flex. Use lineHeight if the height is static. */
55
55
  verticalAlignContent: string;
56
56
  }> & EllipsisUnion & BoxProps;
57
- /** Clickable button. Comes with variants. Read more in the documentation. */
57
+ /**
58
+ * ## Button
59
+ * Buttons allow users to take actions, and make choices, with a single click.
60
+ */
58
61
  export declare function Button(props: Props): import("react/jsx-runtime").JSX.Element;
59
62
  export declare namespace Button {
60
63
  var Checkbox: typeof ButtonCheckbox;
@@ -65,14 +68,20 @@ export declare namespace Button {
65
68
  type CheckProps = Partial<{
66
69
  checked: BooleanLike;
67
70
  }> & Props;
68
- /** Visually toggles between checked and unchecked states. */
71
+ /**
72
+ * ## Button.Checkbox
73
+ * A ghetto checkbox, made entirely using existing Button API.
74
+ */
69
75
  export declare function ButtonCheckbox(props: CheckProps): import("react/jsx-runtime").JSX.Element;
70
76
  type ConfirmProps = Partial<{
71
77
  confirmColor: string;
72
78
  confirmContent: ReactNode;
73
79
  confirmIcon: string;
74
80
  }> & Props;
75
- /** Requires user confirmation before triggering its action. */
81
+ /**
82
+ * ## Button.Confirm
83
+ * A button with an extra confirmation step, using native button component.
84
+ */
76
85
  declare function ButtonConfirm(props: ConfirmProps): import("react/jsx-runtime").JSX.Element;
77
86
  type InputProps = Partial<{
78
87
  currentValue: string;
@@ -82,13 +91,21 @@ type InputProps = Partial<{
82
91
  onCommit: (e: any, value: string) => void;
83
92
  placeholder: string;
84
93
  }> & Props;
85
- /** Accepts and handles user input. */
94
+ /**
95
+ * ## Button.Input
96
+ * A button that turns into an input box after the first click.
97
+ *
98
+ * Turns back into a button after the user hits enter, defocuses, or hits escape. Enter and defocus commit, while escape cancels.
99
+ */
86
100
  declare function ButtonInput(props: InputProps): import("react/jsx-runtime").JSX.Element;
87
101
  type FileProps = {
88
102
  accept: string;
89
103
  multiple?: boolean;
90
104
  onSelectFiles: (files: string | string[]) => void;
91
105
  } & Props;
92
- /** Accepts file input */
106
+ /**
107
+ * ## Button.File
108
+ * Accepts file input, based on the native element.
109
+ */
93
110
  declare function ButtonFile(props: FileProps): import("react/jsx-runtime").JSX.Element;
94
111
  export {};
@@ -2,7 +2,8 @@ import { jsx as i, jsxs as _, Fragment as K } from "react/jsx-runtime";
2
2
  import { useState as A, createRef as V, useEffect as $, useRef as z } from "react";
3
3
  import { KEY as D, isEscape as E } from "../common/keys.js";
4
4
  import { classes as F } from "../common/react.js";
5
- import { computeBoxClassName as j, computeBoxProps as q, Box as O } from "./Box.js";
5
+ import { computeBoxClassName as j, computeBoxProps as q } from "../common/ui.js";
6
+ import { Box as O } from "./Box.js";
6
7
  import { Icon as S } from "./Icon.js";
7
8
  import { Tooltip as v } from "./Tooltip.js";
8
9
  function x(u) {