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