@dcl-regenesislabs/react-ecs 0.0.0-stage → 7.0.0-42722791062.commit-bc8d909
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/README.md +130 -2
- package/dist/components/Button/index.d.ts +15 -0
- package/dist/components/Button/index.js +62 -0
- package/dist/components/Button/types.d.ts +16 -0
- package/dist/components/Button/types.js +1 -0
- package/dist/components/Dropdown/index.d.ts +21 -0
- package/dist/components/Dropdown/index.js +48 -0
- package/dist/components/Dropdown/types.d.ts +13 -0
- package/dist/components/Dropdown/types.js +1 -0
- package/dist/components/Input/index.d.ts +25 -0
- package/dist/components/Input/index.js +49 -0
- package/dist/components/Input/types.d.ts +15 -0
- package/dist/components/Input/types.js +1 -0
- package/dist/components/InteractableArea/index.d.ts +23 -0
- package/dist/components/InteractableArea/index.js +34 -0
- package/dist/components/InteractableArea/types.d.ts +23 -0
- package/dist/components/InteractableArea/types.js +1 -0
- package/dist/components/Label/index.d.ts +17 -0
- package/dist/components/Label/index.js +37 -0
- package/dist/components/Label/types.d.ts +34 -0
- package/dist/components/Label/types.js +1 -0
- package/dist/components/Label/utils.d.ts +11 -0
- package/dist/components/Label/utils.js +69 -0
- package/dist/components/ScreenInsetArea/index.d.ts +22 -0
- package/dist/components/ScreenInsetArea/index.js +33 -0
- package/dist/components/ScreenInsetArea/types.d.ts +22 -0
- package/dist/components/ScreenInsetArea/types.js +1 -0
- package/dist/components/index.d.ts +26 -0
- package/dist/components/index.js +36 -0
- package/dist/components/listeners/types.d.ts +19 -0
- package/dist/components/listeners/types.js +11 -0
- package/dist/components/types.d.ts +45 -0
- package/dist/components/types.js +1 -0
- package/dist/components/uiBackground/index.d.ts +6 -0
- package/dist/components/uiBackground/index.js +16 -0
- package/dist/components/uiBackground/types.d.ts +61 -0
- package/dist/components/uiBackground/types.js +1 -0
- package/dist/components/uiBackground/utils.d.ts +1 -0
- package/dist/components/uiBackground/utils.js +51 -0
- package/dist/components/uiTransform/index.d.ts +6 -0
- package/dist/components/uiTransform/index.js +91 -0
- package/dist/components/uiTransform/types.d.ts +134 -0
- package/dist/components/uiTransform/types.js +1 -0
- package/dist/components/uiTransform/utils.d.ts +42 -0
- package/dist/components/uiTransform/utils.js +246 -0
- package/dist/components/utils.d.ts +1 -0
- package/dist/components/utils.js +195 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +15 -0
- package/dist/platform.d.ts +12 -0
- package/dist/platform.js +26 -0
- package/dist/react-ecs.d.ts +87 -0
- package/dist/react-ecs.js +10 -0
- package/dist/reconciler/index.d.ts +6 -0
- package/dist/reconciler/index.js +322 -0
- package/dist/reconciler/types.d.ts +31 -0
- package/dist/reconciler/types.js +1 -0
- package/dist/reconciler/utils.d.ts +40 -0
- package/dist/reconciler/utils.js +174 -0
- package/dist/system.d.ts +92 -0
- package/dist/system.js +264 -0
- package/package.json +41 -3
package/README.md
CHANGED
|
@@ -1,3 +1,131 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @dcl/react-ecs
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
React bindings for Decentraland's Entity Component System (ECS), providing a declarative way to build UIs in Decentraland scenes using React's component model and JSX syntax.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Flexbox-based Layout**: Implements a subset of CSS Flexbox for powerful and intuitive UI layouts
|
|
8
|
+
- **React Components**: Familiar React-like component API for building UIs
|
|
9
|
+
- **Type Safety**: Full TypeScript support with proper type definitions
|
|
10
|
+
- **Event Handling**: Support for mouse events and user interactions
|
|
11
|
+
- **Performance**: Optimized reconciliation for minimal runtime overhead
|
|
12
|
+
- **Theme Support**: Built-in light and dark theme system with context-based switching
|
|
13
|
+
|
|
14
|
+
## Component Guidelines
|
|
15
|
+
|
|
16
|
+
All components in @dcl/react-ecs must:
|
|
17
|
+
|
|
18
|
+
- Return JSX.Elements for consistency and composability
|
|
19
|
+
- Support theme integration through context
|
|
20
|
+
- Be reusable and composable with other components
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install @dcl/react-ecs
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Basic Usage
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import { ReactEcs, UiEntity, Label, Button } from '@dcl/react-ecs'
|
|
32
|
+
|
|
33
|
+
export function MyUI() {
|
|
34
|
+
return (
|
|
35
|
+
<UiEntity
|
|
36
|
+
uiTransform={{
|
|
37
|
+
width: 300,
|
|
38
|
+
height: 100,
|
|
39
|
+
display: 'flex',
|
|
40
|
+
justifyContent: 'center',
|
|
41
|
+
alignItems: 'center'
|
|
42
|
+
}}
|
|
43
|
+
>
|
|
44
|
+
<Label value="Hello Decentraland!" />
|
|
45
|
+
<Button value="Click Me!" onMouseDown={() => console.log('clicked!')} />
|
|
46
|
+
</UiEntity>
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Theme System
|
|
52
|
+
|
|
53
|
+
The package includes a theme system for consistent UI styling:
|
|
54
|
+
|
|
55
|
+
```tsx
|
|
56
|
+
import { ReactEcs, ThemeProvider, Button } from '@dcl/react-ecs'
|
|
57
|
+
|
|
58
|
+
// Wrap your UI with ThemeProvider
|
|
59
|
+
export function MyUI() {
|
|
60
|
+
return (
|
|
61
|
+
<ThemeProvider>
|
|
62
|
+
<Button value="Theme-Aware Button" />
|
|
63
|
+
</ThemeProvider>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Use themes in custom components
|
|
68
|
+
function CustomComponent() {
|
|
69
|
+
const { theme, toggleTheme } = React.useContext(ThemeContext)
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<UiEntity
|
|
73
|
+
uiBackground={{
|
|
74
|
+
color: theme === 'light' ? '#FFFFFF' : '#000000'
|
|
75
|
+
}}
|
|
76
|
+
onMouseDown={toggleTheme}
|
|
77
|
+
/>
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Components
|
|
83
|
+
|
|
84
|
+
### Core Components
|
|
85
|
+
|
|
86
|
+
- **UiEntity**: Base component for UI elements
|
|
87
|
+
- **Label**: Text display component
|
|
88
|
+
- **Button**: Interactive button component
|
|
89
|
+
- **Input**: Text input field
|
|
90
|
+
- **Dropdown**: Selection dropdown menu
|
|
91
|
+
|
|
92
|
+
### Layout System
|
|
93
|
+
|
|
94
|
+
The layout system is based on Flexbox and supports the following properties:
|
|
95
|
+
|
|
96
|
+
- `display: 'flex'`
|
|
97
|
+
- `flexDirection: 'row' | 'column'`
|
|
98
|
+
- `justifyContent: 'flex-start' | 'center' | 'flex-end' | 'space-between' | 'space-around'`
|
|
99
|
+
- `alignItems: 'flex-start' | 'center' | 'flex-end' | 'stretch'`
|
|
100
|
+
- `width`, `height`
|
|
101
|
+
- `margin`, `padding`
|
|
102
|
+
- `positionType: 'absolute' | 'relative'`
|
|
103
|
+
|
|
104
|
+
## Event Handling
|
|
105
|
+
|
|
106
|
+
Components support the following mouse events:
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
<Button onMouseDown={() => {}} onMouseUp={() => {}} onMouseEnter={() => {}} onMouseLeave={() => {}} />
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Technical Details
|
|
113
|
+
|
|
114
|
+
The package implements a custom React reconciler that bridges React's component model with Decentraland's ECS. It:
|
|
115
|
+
|
|
116
|
+
1. Translates JSX into ECS entities and components
|
|
117
|
+
2. Manages component lifecycle and updates
|
|
118
|
+
3. Handles event delegation and bubbling
|
|
119
|
+
4. Provides a performant update mechanism
|
|
120
|
+
|
|
121
|
+
## Related Documentation
|
|
122
|
+
|
|
123
|
+
For more details about the UI system architecture and design decisions:
|
|
124
|
+
|
|
125
|
+
- [ADR-124: Implementing Flexbox-based UI](https://adr.decentraland.org/adr/ADR-124)
|
|
126
|
+
- [ADR-125: User Interface Components](https://adr.decentraland.org/adr/ADR-125)
|
|
127
|
+
- [ADR-237: SDK 7 Custom UI Components](https://adr.decentraland.org/adr/ADR-237)
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
Apache 2.0
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ReactEcs } from '../../react-ecs';
|
|
2
|
+
import { UiButtonProps } from './types';
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
* Button component
|
|
7
|
+
*
|
|
8
|
+
* A Button indicates a possible user action.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* <Button variant="primary" value="Click me!" />
|
|
12
|
+
*
|
|
13
|
+
* @category Component
|
|
14
|
+
*/
|
|
15
|
+
export declare function Button(props: UiButtonProps): ReactEcs.JSX.Element;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ReactEcs } from '../../react-ecs';
|
|
2
|
+
import { getFont, getFontSize, getTextAlign, getTextWrap } from '../Label/utils';
|
|
3
|
+
import { parseUiBackground } from '../uiBackground';
|
|
4
|
+
import { parseUiTransform } from '../uiTransform';
|
|
5
|
+
function getButtonProps(props) {
|
|
6
|
+
if (props.variant === 'secondary') {
|
|
7
|
+
return {
|
|
8
|
+
uiBackground: { color: { r: 1, g: 1, b: 1, a: 1 } },
|
|
9
|
+
uiText: { color: { r: 0.98, g: 0.17, b: 0.33, a: 1 } }
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
// 'primary' variant by default
|
|
13
|
+
return {
|
|
14
|
+
uiBackground: { color: { r: 0.98, g: 0.17, b: 0.33, a: 1 } },
|
|
15
|
+
uiText: { color: { r: 1, g: 1, b: 1, a: 1 } }
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @public
|
|
21
|
+
* Button component
|
|
22
|
+
*
|
|
23
|
+
* A Button indicates a possible user action.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* <Button variant="primary" value="Click me!" />
|
|
27
|
+
*
|
|
28
|
+
* @category Component
|
|
29
|
+
*/
|
|
30
|
+
/* @__PURE__ */
|
|
31
|
+
export function Button(props) {
|
|
32
|
+
const { uiTransform, uiBackground, onMouseDown, onMouseUp, onMouseEnter, onMouseLeave, ...otherProps } = props;
|
|
33
|
+
const buttonProps = getButtonProps(props);
|
|
34
|
+
const uiBackgroundProps = parseUiBackground({
|
|
35
|
+
...buttonProps.uiBackground,
|
|
36
|
+
...uiBackground
|
|
37
|
+
});
|
|
38
|
+
const { font, textAlign, fontSize, textWrap, ...uiTexProps } = otherProps;
|
|
39
|
+
const textProps = {
|
|
40
|
+
...buttonProps.uiText,
|
|
41
|
+
...uiTexProps,
|
|
42
|
+
...getFont(font),
|
|
43
|
+
...getTextAlign(textAlign),
|
|
44
|
+
...getFontSize(fontSize),
|
|
45
|
+
...getTextWrap(textWrap)
|
|
46
|
+
};
|
|
47
|
+
const uiTransformProps = parseUiTransform({
|
|
48
|
+
height: 36,
|
|
49
|
+
...uiTransform
|
|
50
|
+
});
|
|
51
|
+
if (!!props.disabled) {
|
|
52
|
+
// Both objects are shallow copies, so their colors are still the caller's.
|
|
53
|
+
// Dimming them in place would halve the alpha of whatever the scene holds,
|
|
54
|
+
// again on every render, until the color it passed in is fully transparent.
|
|
55
|
+
if (textProps.color)
|
|
56
|
+
textProps.color = { ...textProps.color, a: textProps.color.a / 2 };
|
|
57
|
+
if (uiBackgroundProps && uiBackgroundProps.color) {
|
|
58
|
+
uiBackgroundProps.color = { ...uiBackgroundProps.color, a: uiBackgroundProps.color.a / 2 };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return (ReactEcs.createElement("entity", { onMouseDown: !!props.disabled ? undefined : onMouseDown, onMouseUp: !!props.disabled ? undefined : onMouseUp, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, uiTransform: uiTransformProps, uiText: textProps, uiBackground: uiBackgroundProps }));
|
|
62
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { UiLabelProps } from '../Label/types';
|
|
2
|
+
import { EntityPropTypes } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Button Component Props
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export interface UiButtonProps extends UiLabelProps, EntityPropTypes {
|
|
8
|
+
/**
|
|
9
|
+
* Use any of the available button style types to create a styled button.
|
|
10
|
+
*/
|
|
11
|
+
variant?: 'primary' | 'secondary';
|
|
12
|
+
/**
|
|
13
|
+
* Enable or disable the pointer events on the button
|
|
14
|
+
*/
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ReactEcs } from '../../react-ecs';
|
|
2
|
+
import { UiDropdownProps } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
* Dropdown component
|
|
6
|
+
*
|
|
7
|
+
* A dropdown allows a user to select a value from a series of options.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* <Dropdown
|
|
11
|
+
options={['Red', 'Blue']}
|
|
12
|
+
color={Color4.Red()}
|
|
13
|
+
font="sans-serif"
|
|
14
|
+
fontSize={14}
|
|
15
|
+
selectedIndex={value}
|
|
16
|
+
onChange={(index) => value = index}
|
|
17
|
+
/>
|
|
18
|
+
*
|
|
19
|
+
* @category Component
|
|
20
|
+
*/
|
|
21
|
+
export declare function Dropdown(props: UiDropdownProps): ReactEcs.JSX.Element;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { parseProps } from '../utils';
|
|
2
|
+
import { ReactEcs } from '../../react-ecs';
|
|
3
|
+
import { getFont, getFontSize, getTextAlign } from '../Label/utils';
|
|
4
|
+
function parseUiDropdown(props) {
|
|
5
|
+
const { textAlign, font, fontSize, ...otherProps } = props;
|
|
6
|
+
return {
|
|
7
|
+
acceptEmpty: false,
|
|
8
|
+
options: [],
|
|
9
|
+
selectedIndex: props.acceptEmpty ? -1 : 0,
|
|
10
|
+
disabled: false,
|
|
11
|
+
...otherProps,
|
|
12
|
+
...getTextAlign(textAlign),
|
|
13
|
+
...getFont(font),
|
|
14
|
+
...getFontSize(fontSize)
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @public
|
|
19
|
+
* Dropdown component
|
|
20
|
+
*
|
|
21
|
+
* A dropdown allows a user to select a value from a series of options.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* <Dropdown
|
|
25
|
+
options={['Red', 'Blue']}
|
|
26
|
+
color={Color4.Red()}
|
|
27
|
+
font="sans-serif"
|
|
28
|
+
fontSize={14}
|
|
29
|
+
selectedIndex={value}
|
|
30
|
+
onChange={(index) => value = index}
|
|
31
|
+
/>
|
|
32
|
+
*
|
|
33
|
+
* @category Component
|
|
34
|
+
*/
|
|
35
|
+
/* @__PURE__ */
|
|
36
|
+
export function Dropdown(props) {
|
|
37
|
+
const { uiTransform, uiBackground, onMouseDown, onMouseUp, onMouseEnter, onMouseLeave, ...otherProps } = props;
|
|
38
|
+
const dropdownProps = parseUiDropdown(otherProps);
|
|
39
|
+
const commonProps = parseProps({
|
|
40
|
+
uiTransform,
|
|
41
|
+
uiBackground,
|
|
42
|
+
onMouseDown,
|
|
43
|
+
onMouseUp,
|
|
44
|
+
onMouseEnter,
|
|
45
|
+
onMouseLeave
|
|
46
|
+
});
|
|
47
|
+
return ReactEcs.createElement("entity", { ...commonProps, uiDropdown: dropdownProps });
|
|
48
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PBUiDropdown } from '@dcl/ecs';
|
|
2
|
+
import { TextAlignType, UiFontType } from '../Label/types';
|
|
3
|
+
import { EntityPropTypes, ScaleUnit } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
* Dropdown Props
|
|
7
|
+
*/
|
|
8
|
+
export interface UiDropdownProps extends EntityPropTypes, Omit<Partial<PBUiDropdown>, 'textAlign' | 'font' | 'fontSize'> {
|
|
9
|
+
onChange?(value: number): void;
|
|
10
|
+
font?: UiFontType;
|
|
11
|
+
textAlign?: TextAlignType;
|
|
12
|
+
fontSize?: ScaleUnit;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ReactEcs } from '../../react-ecs';
|
|
2
|
+
import { EntityPropTypes } from '../types';
|
|
3
|
+
import { UiInputProps } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
* Input component
|
|
7
|
+
*
|
|
8
|
+
* An Input is a field used to obtain a response from a user.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
<Input
|
|
12
|
+
placeholder="Please enter your email"
|
|
13
|
+
onChange={(value) => {
|
|
14
|
+
email = value
|
|
15
|
+
}}
|
|
16
|
+
onSubmit={(value) => {
|
|
17
|
+
email = value
|
|
18
|
+
}}
|
|
19
|
+
uiBackground={{ color: Color4.Red() }}
|
|
20
|
+
uiTransform={{ width: 200, height: 36 }}
|
|
21
|
+
value={textValue}
|
|
22
|
+
/>
|
|
23
|
+
*
|
|
24
|
+
* @category Component
|
|
25
|
+
*/ export declare function Input(props: EntityPropTypes & Partial<UiInputProps>): ReactEcs.JSX.Element;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { parseProps } from '../utils';
|
|
2
|
+
import { ReactEcs } from '../../react-ecs';
|
|
3
|
+
import { getTextAlign, getFont, getFontSize } from '../Label/utils';
|
|
4
|
+
function parseUiInput(props) {
|
|
5
|
+
const { textAlign, font, fontSize, ...otherProps } = props;
|
|
6
|
+
return {
|
|
7
|
+
disabled: false,
|
|
8
|
+
placeholder: '',
|
|
9
|
+
...otherProps,
|
|
10
|
+
...getTextAlign(textAlign),
|
|
11
|
+
...getFont(font),
|
|
12
|
+
...getFontSize(fontSize)
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* @public
|
|
17
|
+
* Input component
|
|
18
|
+
*
|
|
19
|
+
* An Input is a field used to obtain a response from a user.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
<Input
|
|
23
|
+
placeholder="Please enter your email"
|
|
24
|
+
onChange={(value) => {
|
|
25
|
+
email = value
|
|
26
|
+
}}
|
|
27
|
+
onSubmit={(value) => {
|
|
28
|
+
email = value
|
|
29
|
+
}}
|
|
30
|
+
uiBackground={{ color: Color4.Red() }}
|
|
31
|
+
uiTransform={{ width: 200, height: 36 }}
|
|
32
|
+
value={textValue}
|
|
33
|
+
/>
|
|
34
|
+
*
|
|
35
|
+
* @category Component
|
|
36
|
+
*/ /* @__PURE__ */
|
|
37
|
+
export function Input(props) {
|
|
38
|
+
const { uiTransform, uiBackground, onMouseDown, onMouseUp, onMouseEnter, onMouseLeave, ...otherProps } = props;
|
|
39
|
+
const inputProps = parseUiInput(otherProps);
|
|
40
|
+
const commonProps = parseProps({
|
|
41
|
+
uiTransform,
|
|
42
|
+
uiBackground,
|
|
43
|
+
onMouseDown,
|
|
44
|
+
onMouseUp,
|
|
45
|
+
onMouseEnter,
|
|
46
|
+
onMouseLeave
|
|
47
|
+
});
|
|
48
|
+
return ReactEcs.createElement("entity", { ...commonProps, uiInput: inputProps });
|
|
49
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PBUiInput } from '@dcl/ecs';
|
|
2
|
+
import { TextAlignType, UiFontType } from '../Label/types';
|
|
3
|
+
import { ScaleUnit } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export interface UiInputProps extends Omit<PBUiInput, 'font' | 'textAlign' | 'fontSize'> {
|
|
8
|
+
/** function to be called on value change */
|
|
9
|
+
onChange?(value: string): void;
|
|
10
|
+
/** function to be called on text field submit */
|
|
11
|
+
onSubmit?(value: string): void;
|
|
12
|
+
font?: UiFontType;
|
|
13
|
+
textAlign?: TextAlignType;
|
|
14
|
+
fontSize?: ScaleUnit;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ReactEcs } from '../../react-ecs';
|
|
2
|
+
import { UiInteractableAreaProps } from './types';
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
* InteractableArea component
|
|
7
|
+
*
|
|
8
|
+
* Constrains its children to the area inside the renderer-reported interactable
|
|
9
|
+
* area. This is the portion of the screen not covered by client UI such as the
|
|
10
|
+
* minimap, chat window, or other platform overlays. On the Unity desktop client
|
|
11
|
+
* the left 25% of the screen is reserved for client UI, so this container
|
|
12
|
+
* positions its children within the remaining 75%.
|
|
13
|
+
*
|
|
14
|
+
* The container is absolutely positioned with top/left/right/bottom matching
|
|
15
|
+
* the current `UiCanvasInformation.interactableArea`, so a child sized
|
|
16
|
+
* 100%x100% fills the interactable area exactly.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* <InteractableArea><MyHud /></InteractableArea>
|
|
20
|
+
*
|
|
21
|
+
* @category Component
|
|
22
|
+
*/
|
|
23
|
+
export declare function InteractableArea(props: UiInteractableAreaProps): ReactEcs.JSX.Element;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ReactEcs } from '../../react-ecs';
|
|
2
|
+
import { UiEntity } from '../index';
|
|
3
|
+
import { compensateInsetForUiScale, getInteractableArea } from '../utils';
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
* InteractableArea component
|
|
8
|
+
*
|
|
9
|
+
* Constrains its children to the area inside the renderer-reported interactable
|
|
10
|
+
* area. This is the portion of the screen not covered by client UI such as the
|
|
11
|
+
* minimap, chat window, or other platform overlays. On the Unity desktop client
|
|
12
|
+
* the left 25% of the screen is reserved for client UI, so this container
|
|
13
|
+
* positions its children within the remaining 75%.
|
|
14
|
+
*
|
|
15
|
+
* The container is absolutely positioned with top/left/right/bottom matching
|
|
16
|
+
* the current `UiCanvasInformation.interactableArea`, so a child sized
|
|
17
|
+
* 100%x100% fills the interactable area exactly.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* <InteractableArea><MyHud /></InteractableArea>
|
|
21
|
+
*
|
|
22
|
+
* @category Component
|
|
23
|
+
*/
|
|
24
|
+
/* @__PURE__ */
|
|
25
|
+
export function InteractableArea(props) {
|
|
26
|
+
// Insets are canvas px; pre-divide so the parser's scale multiplication cancels out.
|
|
27
|
+
const { top, left, right, bottom } = compensateInsetForUiScale(getInteractableArea());
|
|
28
|
+
const { uiTransform, ...otherProps } = props;
|
|
29
|
+
return (ReactEcs.createElement(UiEntity, { ...otherProps, uiTransform: {
|
|
30
|
+
...uiTransform,
|
|
31
|
+
positionType: 'absolute',
|
|
32
|
+
position: { top, left, right, bottom }
|
|
33
|
+
} }));
|
|
34
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { EntityPropTypes } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* InteractableArea component props
|
|
4
|
+
*
|
|
5
|
+
* The container reads the current `interactableArea` reported by the renderer
|
|
6
|
+
* via `UiCanvasInformation` (the HUD-safe zone — the portion of the screen not
|
|
7
|
+
* covered by client UI such as the minimap, chat window, or other overlays) and
|
|
8
|
+
* constrains its children to the area inside those insets using absolute
|
|
9
|
+
* positioning. Layout props that control the container's own position
|
|
10
|
+
* (`positionType`, `position`) are owned by the component and are not
|
|
11
|
+
* configurable from props — every other layout, background and event prop is
|
|
12
|
+
* forwarded as usual.
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export type UiInteractableAreaProps = Omit<EntityPropTypes, 'uiTransform'> & {
|
|
17
|
+
/**
|
|
18
|
+
* Layout overrides forwarded to the underlying entity. The
|
|
19
|
+
* `positionType` and `position` fields are reserved by the container and
|
|
20
|
+
* any value provided here is ignored.
|
|
21
|
+
*/
|
|
22
|
+
uiTransform?: Omit<NonNullable<EntityPropTypes['uiTransform']>, 'positionType' | 'position'>;
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ReactEcs } from '../../react-ecs';
|
|
2
|
+
import { EntityPropTypes } from '../types';
|
|
3
|
+
import { UiLabelProps } from './types';
|
|
4
|
+
export { scaleFontSize } from './utils';
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
* Label component
|
|
9
|
+
*
|
|
10
|
+
* A label displays text content
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* <Label value="SDK 7" uiTransform={{ margin: { left: 10 } }} />
|
|
14
|
+
*
|
|
15
|
+
* @category Component
|
|
16
|
+
*/
|
|
17
|
+
export declare function Label(props: EntityPropTypes & UiLabelProps): ReactEcs.JSX.Element;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { parseProps } from '../utils';
|
|
2
|
+
import { ReactEcs } from '../../react-ecs';
|
|
3
|
+
import { getFont, getFontSize, getTextAlign, getTextWrap } from './utils';
|
|
4
|
+
export { scaleFontSize } from './utils';
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
* Label component
|
|
9
|
+
*
|
|
10
|
+
* A label displays text content
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* <Label value="SDK 7" uiTransform={{ margin: { left: 10 } }} />
|
|
14
|
+
*
|
|
15
|
+
* @category Component
|
|
16
|
+
*/
|
|
17
|
+
/* @__PURE__ */
|
|
18
|
+
export function Label(props) {
|
|
19
|
+
const { uiTransform, uiBackground, onMouseDown, onMouseUp, onMouseEnter, onMouseLeave, ...uiTextProps } = props;
|
|
20
|
+
const commonProps = parseProps({
|
|
21
|
+
uiTransform,
|
|
22
|
+
uiBackground,
|
|
23
|
+
onMouseDown,
|
|
24
|
+
onMouseUp,
|
|
25
|
+
onMouseEnter,
|
|
26
|
+
onMouseLeave
|
|
27
|
+
});
|
|
28
|
+
const { font, textAlign, fontSize, textWrap, ...textProps } = uiTextProps;
|
|
29
|
+
const uiText = {
|
|
30
|
+
...textProps,
|
|
31
|
+
...getFont(font),
|
|
32
|
+
...getTextAlign(textAlign),
|
|
33
|
+
...getFontSize(fontSize),
|
|
34
|
+
...getTextWrap(textWrap)
|
|
35
|
+
};
|
|
36
|
+
return ReactEcs.createElement("entity", { ...commonProps, uiText: uiText });
|
|
37
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Color4 } from '@dcl/ecs/dist/components/generated/pb/decentraland/common/colors.gen';
|
|
2
|
+
import { ScaleUnit } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Label component props
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export interface UiLabelProps {
|
|
8
|
+
/** Primary content. */
|
|
9
|
+
value: string;
|
|
10
|
+
/** Color of the label. @defaultValue `{ r: 1, g: 1, b: 1, a: 1 }` */
|
|
11
|
+
color?: Color4 | undefined;
|
|
12
|
+
/** Label font size. @defaultValue 10 */
|
|
13
|
+
fontSize?: ScaleUnit | undefined;
|
|
14
|
+
/** Label align position. @defaultValue 'middle-center' */
|
|
15
|
+
textAlign?: TextAlignType | undefined;
|
|
16
|
+
/** Label font type. @defaultValue 'sans-serif' */
|
|
17
|
+
font?: UiFontType | undefined;
|
|
18
|
+
/** Path to a `.ttf` file in the scene content. `font` is used when it can't be loaded. */
|
|
19
|
+
fontSrc?: string | undefined;
|
|
20
|
+
/** Behaviour when text reached. @defaultValue 'wrap' */
|
|
21
|
+
textWrap?: UiTextWrapType | undefined;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export type UiFontType = 'sans-serif' | 'serif' | 'monospace';
|
|
27
|
+
/**
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export type UiTextWrapType = 'wrap' | 'nowrap';
|
|
31
|
+
/**
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
export type TextAlignType = 'top-left' | 'top-center' | 'top-right' | 'middle-left' | 'middle-center' | 'middle-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ScaleContext, ScaleUnit } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Scales a font size depending on a context's width/height
|
|
4
|
+
* @param {number} fontSize size of the font to scale
|
|
5
|
+
* @param {ScaleUnit} [scaleUnit=0.39] the scaling unit (uses "width" as unit if a number is supplied)
|
|
6
|
+
* @param {ScaleContext} [ctx=viewport] the context where to apply the scaling
|
|
7
|
+
* @returns {number} the fontSize scaled
|
|
8
|
+
* @see https://matthewjamestaylor.com/responsive-font-size#fluid
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export declare function scaleFontSize(fontSize: number, scaleUnit?: ScaleUnit, ctx?: ScaleContext | undefined): number;
|