@amaui/ui-react
Version:
UI for React
83 lines (82 loc) • 6.1 kB
JavaScript
"use strict";
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = __importDefault(require("react"));
const utils_1 = require("@amaui/utils");
const style_react_1 = require("@amaui/style-react");
const Line_1 = __importDefault(require("../Line"));
const Type_1 = __importDefault(require("../Type"));
const utils_2 = require("../utils");
const useStyle = (0, style_react_1.style)(theme => ({
root: {},
aside: {
flex: '0 0 auto'
},
row: {
'& > *': {
flex: '1 1 auto'
}
// '& .amaui-TextField-root, & .amaui-TextField-wrapper': {
// width: '100%'
// }
},
footer: {
marginTop: '8px'
}
}), { name: 'amaui-FormRow' });
const FormRow = react_1.default.forwardRef((props_, ref) => {
const theme = (0, style_react_1.useAmauiTheme)();
const props = react_1.default.useMemo(() => { var _a, _b, _c, _d, _e, _f, _g, _h; return (Object.assign(Object.assign(Object.assign({}, (_d = (_c = (_b = (_a = theme === null || theme === void 0 ? void 0 : theme.ui) === null || _a === void 0 ? void 0 : _a.elements) === null || _b === void 0 ? void 0 : _b.all) === null || _c === void 0 ? void 0 : _c.props) === null || _d === void 0 ? void 0 : _d.default), (_h = (_g = (_f = (_e = theme === null || theme === void 0 ? void 0 : theme.ui) === null || _e === void 0 ? void 0 : _e.elements) === null || _f === void 0 ? void 0 : _f.amauiFormRow) === null || _g === void 0 ? void 0 : _g.props) === null || _h === void 0 ? void 0 : _h.default), props_)); }, [props_]);
const Line = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Line) || Line_1.default; }, [theme]);
const Type = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Type) || Type_1.default; }, [theme]);
const { name, description, start, end, row, footer, responsive = true, Component = Line, HeaderProps, MainProps, TextProps, AsideProps, StartProps, EndProps, className, children } = props, other = __rest(props, ["name", "description", "start", "end", "row", "footer", "responsive", "Component", "HeaderProps", "MainProps", "TextProps", "AsideProps", "StartProps", "EndProps", "className", "children"]);
const { classes } = useStyle();
const text = (name || description);
const actions = (start || end);
const header = text || actions;
let justify = 'unset';
if (start && end && !text)
justify = 'space-between';
if (!start && !text && end)
justify = 'flex-end';
return ((0, jsx_runtime_1.jsxs)(Component, Object.assign({ ref: ref, gap: 1, direction: 'column', justify: 'unset', align: 'unset', fullWidth: true, className: (0, style_react_1.classNames)([
(0, utils_2.staticClassName)('FormRow', theme) && [
'amaui-FormRow-root'
],
className,
classes.root
]) }, other, { children: [header && ((0, jsx_runtime_1.jsxs)(Line, Object.assign({ direction: 'row', align: 'center', justify: justify, fullWidth: true }, HeaderProps, { children: [start && ((0, jsx_runtime_1.jsx)(Line, Object.assign({}, AsideProps, StartProps, { className: (0, style_react_1.classNames)([
AsideProps === null || AsideProps === void 0 ? void 0 : AsideProps.className,
StartProps === null || StartProps === void 0 ? void 0 : StartProps.className,
classes.aside
]) }, { children: start }))), text && ((0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 0.5, direction: 'column', flex: true }, TextProps, { children: [name && ((0, utils_1.is)('string', name) ? ((0, jsx_runtime_1.jsx)(Type, Object.assign({ version: 'l2' }, { children: name }))) : name), description && ((0, utils_1.is)('string', description) ? ((0, jsx_runtime_1.jsx)(Type, Object.assign({ version: 'b3' }, { children: description }))) : description)] }))), end && ((0, jsx_runtime_1.jsx)(Line, Object.assign({ gap: 0, direction: 'row', align: 'center' }, AsideProps, EndProps, { className: (0, style_react_1.classNames)([
AsideProps === null || AsideProps === void 0 ? void 0 : AsideProps.className,
EndProps === null || EndProps === void 0 ? void 0 : EndProps.className,
classes.aside
]) }, { children: end })))] }))), (0, jsx_runtime_1.jsx)(Line, Object.assign({ gap: 2, direction: row ? responsive ? {
default: 'row',
1400: 'column'
} : 'row' : 'column', fullWidth: true, className: (0, style_react_1.classNames)([
(0, utils_2.staticClassName)('FormRow', theme) && [
'amaui-FormRow-main'
],
MainProps === null || MainProps === void 0 ? void 0 : MainProps.className,
row && classes.row
]) }, MainProps, { children: children })), footer && ((0, jsx_runtime_1.jsx)(Line, Object.assign({ direction: 'row', justify: 'flex-end', fullWidth: true, className: classes.footer }, { children: footer })))] })));
});
FormRow.displayName = 'amaui-FormRow';
exports.default = FormRow;