@amaui/ui-react
Version:
UI for React
68 lines • 3.73 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
const _excluded = ["tonal", "color", "size", "hover", "selected", "position", "Component", "className", "children"];
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
import React from 'react';
import { classNames, style as styleMethod, useAmauiTheme } from '@amaui/style-react';
import SurfaceElement from '../Surface';
import { staticClassName } from '../utils';
import { is } from '@amaui/utils';
const useStyle = styleMethod(theme => ({
root: {
display: 'table-row',
position: 'relative'
},
hover: {
'&:hover': {
'& .amaui-TableCell-root::before': {
opacity: theme.palette.visual_contrast.default.opacity.hover
}
}
},
selected: {
'& .amaui-TableCell-root::before': {
opacity: [theme.palette.visual_contrast.default.opacity.selected, '!important']
}
}
}), {
name: 'amaui-TableRow'
});
const TableRow = /*#__PURE__*/React.forwardRef((props_, ref) => {
const theme = useAmauiTheme();
const props = React.useMemo(() => _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.amauiTableRow?.props?.default), props_), [props_]);
const Surface = React.useMemo(() => theme?.elements?.Surface || SurfaceElement, [theme]);
const {
tonal = true,
color = 'themed',
size = 'regular',
hover = true,
selected,
position = 'body',
Component = 'tr',
className,
children
} = props,
other = _objectWithoutProperties(props, _excluded);
const {
classes
} = useStyle();
return /*#__PURE__*/React.createElement(Surface, _extends({
ref: ref,
tonal: tonal,
color: color,
role: "row",
Component: Component,
className: classNames([staticClassName('TableRow', theme) && [`amaui-TableRow-root`, `amaui-TableRow-size-${size}`, hover && position === 'body' && `amaui-TableRow-hover`, selected && `amaui-TableRow-selected`], className, classes.root, hover && position === 'body' && classes.hover, selected && classes.selected])
}, other), React.Children.toArray(children).map((item, index) => is('object', item) ? /*#__PURE__*/React.cloneElement(item, {
tonal: item.props.tonal !== undefined ? item.props.tonal : tonal,
color: item.props.color !== undefined ? item.props.color : color,
size: item.props.size !== undefined ? item.props.size : size,
justify: item.props.justify !== undefined ? item.props.justify : index === 0 ? 'flex-start' : 'flex-end',
position: props.position !== undefined ? props.position : index === 0 && position === 'body' ? 'head' : position,
noWeight: index === 0 && position === 'body'
}) : item));
});
TableRow.displayName = 'amaui-TableRow';
export default TableRow;