@lobehub/ui
Version:
Lobe UI is an open-source UI component library for building AIGC web apps
68 lines (67 loc) • 6.45 kB
JavaScript
'use client';
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
var _excluded = ["desc", "tag", "minWidth", "avatar", "className", "label", "children", "divider", "layout"];
var _templateObject, _templateObject2, _templateObject3, _templateObject4;
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; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
import { Form } from 'antd';
import { createStyles } from 'antd-style';
import { isNumber } from 'lodash-es';
import { memo } from 'react';
import FormDivider from "./FormDivider";
import FormTitle from "./FormTitle";
import { jsx as _jsx } from "react/jsx-runtime";
import { Fragment as _Fragment } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var Item = Form.Item;
export var useStyles = createStyles(function (_ref, _ref2) {
var css = _ref.css,
responsive = _ref.responsive,
prefixCls = _ref.prefixCls;
var minWidth = _ref2.minWidth;
return {
item: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n &.", "-form-item {\n padding-block: 16px;\n padding-inline: 0;\n\n .", "-form-item-label {\n text-align: start;\n }\n\n .", "-row {\n gap: 12px;\n justify-content: space-between;\n\n > div {\n flex: unset;\n flex-grow: unset;\n }\n }\n\n .", "-form-item-required::before {\n align-self: flex-start;\n }\n\n ", " {\n .", "-row {\n flex-direction: column;\n align-items: stretch;\n\n > div {\n width: 100%;\n }\n }\n }\n\n ", " {\n padding-block: 16px;\n padding-inline: 0;\n\n .", "-row {\n flex-wrap: wrap;\n gap: 4px;\n }\n }\n }\n "])), prefixCls, prefixCls, prefixCls, prefixCls, responsive.md, prefixCls, responsive.mobile, prefixCls),
itemMinWidth: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n .", "-form-item-control {\n width: ", ";\n }\n ", " {\n .", "-row {\n flex-direction: column;\n gap: 4px;\n }\n\n .", "-form-item-control {\n flex: 1;\n width: 100%;\n }\n }\n "])), prefixCls, isNumber(minWidth) ? "".concat(minWidth, "px") : minWidth, responsive.mobile, prefixCls, prefixCls),
itemNoDivider: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n &:not(:first-child) {\n padding-block-start: 0;\n }\n "]))),
verticalLayout: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n &.", "-form-item {\n .", "-row {\n align-items: stretch;\n }\n }\n "])), prefixCls, prefixCls)
};
});
var FormItem = /*#__PURE__*/memo(function (_ref3) {
var desc = _ref3.desc,
tag = _ref3.tag,
minWidth = _ref3.minWidth,
avatar = _ref3.avatar,
className = _ref3.className,
label = _ref3.label,
children = _ref3.children,
divider = _ref3.divider,
layout = _ref3.layout,
rest = _objectWithoutProperties(_ref3, _excluded);
var _useStyles = useStyles({
minWidth: minWidth
}),
cx = _useStyles.cx,
styles = _useStyles.styles;
var isVertical = layout === 'vertical';
return /*#__PURE__*/_jsxs(_Fragment, {
children: [divider && /*#__PURE__*/_jsx(FormDivider, {}), /*#__PURE__*/_jsx(Item, _objectSpread(_objectSpread({
className: cx(styles.item, Boolean(minWidth) && styles.itemMinWidth, !divider && styles.itemNoDivider, isVertical && styles.verticalLayout, className),
label: /*#__PURE__*/_jsx(FormTitle, {
avatar: avatar,
desc: desc,
tag: tag,
title: label
}),
layout: layout
}, rest), {}, {
children: children
}))]
});
});
export default FormItem;