1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
3 | var _excluded = ["id", "bsPrefix", "bsCustomPrefix", "disabled", "isValid", "isInvalid", "feedbackTooltip", "feedback", "className", "style", "label", "children", "custom", "lang", "data-browse", "as", "inputAs"];
|
4 | import classNames from 'classnames';
|
5 | import React, { useContext, useMemo } from 'react';
|
6 | import all from 'prop-types-extra/lib/all';
|
7 | import Feedback from './Feedback';
|
8 | import FormFileInput from './FormFileInput';
|
9 | import FormFileLabel from './FormFileLabel';
|
10 | import FormContext from './FormContext';
|
11 | import { useBootstrapPrefix } from './ThemeProvider';
|
12 | var FormFile = React.forwardRef(function (_ref, ref) {
|
13 | var id = _ref.id,
|
14 | bsPrefix = _ref.bsPrefix,
|
15 | bsCustomPrefix = _ref.bsCustomPrefix,
|
16 | _ref$disabled = _ref.disabled,
|
17 | disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
18 | _ref$isValid = _ref.isValid,
|
19 | isValid = _ref$isValid === void 0 ? false : _ref$isValid,
|
20 | _ref$isInvalid = _ref.isInvalid,
|
21 | isInvalid = _ref$isInvalid === void 0 ? false : _ref$isInvalid,
|
22 | _ref$feedbackTooltip = _ref.feedbackTooltip,
|
23 | feedbackTooltip = _ref$feedbackTooltip === void 0 ? false : _ref$feedbackTooltip,
|
24 | feedback = _ref.feedback,
|
25 | className = _ref.className,
|
26 | style = _ref.style,
|
27 | label = _ref.label,
|
28 | children = _ref.children,
|
29 | custom = _ref.custom,
|
30 | lang = _ref.lang,
|
31 | dataBrowse = _ref['data-browse'],
|
32 | _ref$as = _ref.as,
|
33 | Component = _ref$as === void 0 ? 'div' : _ref$as,
|
34 | _ref$inputAs = _ref.inputAs,
|
35 | inputAs = _ref$inputAs === void 0 ? 'input' : _ref$inputAs,
|
36 | props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
37 |
|
38 | var _ref2 = custom ? [bsCustomPrefix, 'custom'] : [bsPrefix, 'form-file'],
|
39 | prefix = _ref2[0],
|
40 | defaultPrefix = _ref2[1];
|
41 |
|
42 | bsPrefix = useBootstrapPrefix(prefix, defaultPrefix);
|
43 | var type = 'file';
|
44 |
|
45 | var _useContext = useContext(FormContext),
|
46 | controlId = _useContext.controlId;
|
47 |
|
48 | var innerFormContext = useMemo(function () {
|
49 | return {
|
50 | controlId: id || controlId,
|
51 | custom: custom
|
52 | };
|
53 | }, [controlId, custom, id]);
|
54 | var hasLabel = label != null && label !== false && !children;
|
55 | var input = React.createElement(FormFileInput, _extends({}, props, {
|
56 | ref: ref,
|
57 | isValid: isValid,
|
58 | isInvalid: isInvalid,
|
59 | disabled: disabled,
|
60 | as: inputAs,
|
61 | lang: lang
|
62 | }));
|
63 | return React.createElement(FormContext.Provider, {
|
64 | value: innerFormContext
|
65 | }, React.createElement(Component, {
|
66 | style: style,
|
67 | className: classNames(className, bsPrefix, custom && "custom-" + type)
|
68 | }, children || React.createElement(React.Fragment, null, custom ? React.createElement(React.Fragment, null, input, hasLabel && React.createElement(FormFileLabel, {
|
69 | "data-browse": dataBrowse
|
70 | }, label)) : React.createElement(React.Fragment, null, hasLabel && React.createElement(FormFileLabel, null, label), input), (isValid || isInvalid) && React.createElement(Feedback, {
|
71 | type: isValid ? 'valid' : 'invalid',
|
72 | tooltip: feedbackTooltip
|
73 | }, feedback))));
|
74 | });
|
75 | FormFile.displayName = 'FormFile';
|
76 | FormFile.Input = FormFileInput;
|
77 | FormFile.Label = FormFileLabel;
|
78 | export default FormFile; |
\ | No newline at end of file |