@razorpay/blade
Version:
The Design System that powers Razorpay
195 lines (192 loc) • 7.97 kB
JavaScript
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import styled from 'styled-components';
import { StyledCell, CellWrapper } from './TableBody.web.js';
import { useTableContext } from './TableContext.js';
import { rowDensityToIsTableInputCellMapping, tableEditableCellRowDensityToInputSizeMap, validationStateToInputTrailingIconMap } from './tokens.js';
import { ComponentIds } from './componentIds.js';
import { TableEditableCellContext } from './TableEditableCellContext.js';
import '../../utils/getFocusRingStyles/index.js';
import '../../utils/metaAttribute/index.js';
import '../Box/BaseBox/index.js';
import '../Box/index.js';
import '../Input/BaseInput/index.js';
import '../../utils/index.js';
import '../../utils/assignWithoutSideEffects/index.js';
import '../Dropdown/index.js';
import { jsx } from 'react/jsx-runtime';
import { getFocusRingStyles } from '../../utils/getFocusRingStyles/getFocusRingStyles.web.js';
import { metaAttribute } from '../../utils/metaAttribute/metaAttribute.web.js';
import { MetaConstants } from '../../utils/metaAttribute/metaConstants.js';
import { BaseBox } from '../Box/BaseBox/BaseBox.web.js';
import { Box } from '../Box/Box.js';
import { BaseInput } from '../Input/BaseInput/BaseInput.js';
import { castWebType } from '../../utils/platform/castUtils.js';
import { Dropdown } from '../Dropdown/Dropdown.js';
import { assignWithoutSideEffects } from '../../utils/assignWithoutSideEffects/assignWithoutSideEffects.js';
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var StyledEditableCell = /*#__PURE__*/styled(StyledCell).withConfig({
displayName: "TableEditableCellweb__StyledEditableCell",
componentId: "cvczp8-0"
})(function (_ref) {
var theme = _ref.theme,
$rowDensity = _ref.$rowDensity;
return {
'&&&': {
'&:focus-visible': {
outline: '1px solid'
},
'&:focus-within': _objectSpread({}, $rowDensity !== 'comfortable' ? getFocusRingStyles({
theme: theme,
negativeOffset: true
}) : {})
}
};
});
var getEditableInputMargin = function getEditableInputMargin(_ref2) {
var rowDensity = _ref2.rowDensity;
if (rowDensity === 'comfortable') {
return ['spacing.4', 'spacing.4'];
}
return 'spacing.2';
};
var _TableEditableCell = function _TableEditableCell(_ref3) {
var _ref3$validationState = _ref3.validationState,
validationState = _ref3$validationState === void 0 ? 'none' : _ref3$validationState,
accessibilityLabel = _ref3.accessibilityLabel,
autoCapitalize = _ref3.autoCapitalize,
autoCompleteSuggestionType = _ref3.autoCompleteSuggestionType,
autoFocus = _ref3.autoFocus,
defaultValue = _ref3.defaultValue,
isDisabled = _ref3.isDisabled,
isRequired = _ref3.isRequired,
keyboardReturnKeyType = _ref3.keyboardReturnKeyType,
leadingIcon = _ref3.leadingIcon,
maxCharacters = _ref3.maxCharacters,
name = _ref3.name,
onBlur = _ref3.onBlur,
onChange = _ref3.onChange,
onClick = _ref3.onClick,
onFocus = _ref3.onFocus,
onSubmit = _ref3.onSubmit,
placeholder = _ref3.placeholder,
prefix = _ref3.prefix,
suffix = _ref3.suffix,
value = _ref3.value,
testID = _ref3.testID,
trailingButton = _ref3.trailingButton,
errorText = _ref3.errorText,
successText = _ref3.successText;
var _useTableContext = useTableContext(),
rowDensity = _useTableContext.rowDensity,
showStripedRows = _useTableContext.showStripedRows,
backgroundColor = _useTableContext.backgroundColor;
return /*#__PURE__*/jsx(StyledEditableCell, _objectSpread(_objectSpread({
role: "cell",
$backgroundColor: backgroundColor,
$rowDensity: rowDensity
}, metaAttribute({
name: MetaConstants.TableCell
})), {}, {
children: /*#__PURE__*/jsx(BaseBox, {
className: "cell-wrapper-base",
display: "flex",
alignItems: "center",
height: "100%",
children: /*#__PURE__*/jsx(CellWrapper, {
className: "cell-wrapper",
$rowDensity: rowDensity,
showStripedRows: showStripedRows,
display: "flex",
alignItems: "center",
flex: 1,
hasPadding: false,
children: /*#__PURE__*/jsx(Box, {
margin: getEditableInputMargin({
rowDensity: rowDensity
}),
width: "100%",
children: /*#__PURE__*/jsx(BaseInput, {
isTableInputCell: rowDensityToIsTableInputCellMapping[rowDensity],
validationState: validationState,
id: "table-editable-cell-input",
type: "text",
size: tableEditableCellRowDensityToInputSizeMap[rowDensity],
trailingIcon: validationStateToInputTrailingIconMap[validationState],
accessibilityLabel: accessibilityLabel,
autoCapitalize: autoCapitalize,
autoCompleteSuggestionType: autoCompleteSuggestionType
// eslint-disable-next-line jsx-a11y/no-autofocus
,
autoFocus: autoFocus,
defaultValue: defaultValue,
isDisabled: isDisabled,
isRequired: isRequired,
keyboardReturnKeyType: keyboardReturnKeyType,
leadingIcon: leadingIcon,
maxCharacters: maxCharacters,
name: name,
onBlur: onBlur,
onChange: onChange,
onClick: onClick,
onFocus: onFocus,
onSubmit: castWebType(onSubmit),
placeholder: placeholder,
prefix: prefix,
suffix: suffix,
value: value,
testID: testID,
trailingButton: trailingButton,
errorText: errorText,
successText: successText,
showHintsAsTooltip: true
})
})
})
})
}));
};
var TableEditableDropdownCell = function TableEditableDropdownCell(dropdownProps) {
var _useTableContext2 = useTableContext(),
rowDensity = _useTableContext2.rowDensity,
showStripedRows = _useTableContext2.showStripedRows,
backgroundColor = _useTableContext2.backgroundColor;
return /*#__PURE__*/jsx(TableEditableCellContext.Provider, {
value: {
isInsideTableEditableCell: true
},
children: /*#__PURE__*/jsx(StyledEditableCell, _objectSpread(_objectSpread({
role: "cell",
$backgroundColor: backgroundColor,
$rowDensity: rowDensity
}, metaAttribute({
name: MetaConstants.TableCell
})), {}, {
children: /*#__PURE__*/jsx(BaseBox, {
className: "cell-wrapper-base",
display: "flex",
alignItems: "center",
height: "100%",
width: "100%",
children: /*#__PURE__*/jsx(CellWrapper, {
className: "cell-wrapper",
$rowDensity: rowDensity,
showStripedRows: showStripedRows,
display: "flex",
alignItems: "center",
flex: 1,
hasPadding: false,
children: /*#__PURE__*/jsx(Dropdown, _objectSpread({
_width: "100%",
margin: "spacing.2"
}, dropdownProps))
})
})
}))
});
};
var TableEditableCell = /*#__PURE__*/assignWithoutSideEffects(_TableEditableCell, {
componentId: ComponentIds.TableEditableCell
});
export { TableEditableCell, TableEditableDropdownCell };
//# sourceMappingURL=TableEditableCell.web.js.map