@appbuckets/react-ui
Version:
Just Another React UI Framework
56 lines (53 loc) • 1.54 kB
JavaScript
import { __rest, __assign } from 'tslib';
import * as React from 'react';
import clsx from 'clsx';
import '../BucketTheme/BucketTheme.js';
import { useWithDefaultProps } from '../BucketTheme/BucketContext.js';
import { useSharedClassName } from '../utils/customHook.js';
/* --------
* Component Render
* -------- */
var Form = React.forwardRef(function (receivedProps, ref) {
var props = useWithDefaultProps('form', receivedProps);
var _a = useSharedClassName(props),
className = _a.className,
_b = _a.rest,
children = _b.children;
_b.content;
var disabled = _b.disabled,
onSubmit = _b.onSubmit,
rest = __rest(_b, ['children', 'content', 'disabled', 'onSubmit']);
/** Build the element class list */
var classes = clsx({ disabled: disabled }, 'form', className);
/* --------
* Form Submit Handler
* -------- */
var handleFormSubmit = function (e) {
/** Prevent any default action, only if action props is not defined */
if (typeof props.action !== 'string') {
e.preventDefault();
}
/** Disabled Form couldn't be submitted */
if (disabled) {
return;
}
/** Call the user defined onSubmit handler */
if (typeof onSubmit === 'function') {
onSubmit(e, props);
}
};
/* --------
* Render the Form
* -------- */
return React.createElement(
'form',
__assign({}, rest, {
ref: ref,
className: classes,
onSubmit: handleFormSubmit,
}),
children
);
});
Form.displayName = 'Form';
export { Form as default };