@dcl/react-ecs
Version:
Decentraland ECS
49 lines (48 loc) • 1.34 kB
JavaScript
import { parseProps } from '../utils';
import { ReactEcs } from '../../react-ecs';
import { getFont, getFontSize, getTextAlign } from '../Label/utils';
function parseUiDropdown(props) {
const { textAlign, font, fontSize, ...otherProps } = props;
return {
acceptEmpty: false,
options: [],
selectedIndex: props.acceptEmpty ? -1 : 0,
disabled: false,
...otherProps,
...getTextAlign(textAlign),
...getFont(font),
...getFontSize(fontSize)
};
}
/**
* @public
* Dropdown component
*
* A dropdown allows a user to select a value from a series of options.
*
* @example
* <Dropdown
options={['Red', 'Blue']}
color={Color4.Red()}
font="sans-serif"
fontSize={14}
selectedIndex={value}
onChange={(index) => value = index}
/>
*
* @category Component
*/
/* @__PURE__ */
export function Dropdown(props) {
const { uiTransform, uiBackground, onMouseDown, onMouseUp, onMouseEnter, onMouseLeave, ...otherProps } = props;
const dropdownProps = parseUiDropdown(otherProps);
const commonProps = parseProps({
uiTransform,
uiBackground,
onMouseDown,
onMouseUp,
onMouseEnter,
onMouseLeave
});
return ReactEcs.createElement("entity", { ...commonProps, uiDropdown: dropdownProps });
}