@startlibs/form 1.1.3 → 1.2.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/AutoComplete.mjs +7 -7
- package/lib/AutoComplete.mjs.map +1 -1
- package/lib/Checkbox.mjs +4 -2
- package/lib/Checkbox.mjs.map +1 -1
- package/lib/Combobox.mjs +1 -1
- package/lib/Combobox.mjs.map +1 -1
- package/lib/DatePicker.mjs +25 -9
- package/lib/DatePicker.mjs.map +1 -1
- package/lib/Errors.mjs +20 -10
- package/lib/Errors.mjs.map +1 -1
- package/lib/ExpandableBox.mjs +1 -1
- package/lib/ExpandableBox.mjs.map +1 -1
- package/lib/Field.mjs +10 -5
- package/lib/Field.mjs.map +1 -1
- package/lib/FieldBox.mjs +3 -3
- package/lib/FieldBox.mjs.map +1 -1
- package/lib/InputboxGroup.mjs +1 -1
- package/lib/InputboxGroup.mjs.map +1 -1
- package/lib/RichText.mjs +11 -6
- package/lib/RichText.mjs.map +1 -1
- package/lib/TextInput.mjs +4 -4
- package/lib/TextInput.mjs.map +1 -1
- package/lib/alt/checkbox/SimpleCheckbox.mjs +1 -1
- package/lib/alt/checkbox/SimpleCheckbox.mjs.map +1 -1
- package/lib/alt/checkbox/ToggleCheckbox.mjs +4 -3
- package/lib/alt/checkbox/ToggleCheckbox.mjs.map +1 -1
- package/lib/alt/radiobox/CleanTabRadiobox.mjs +1 -1
- package/lib/alt/radiobox/CleanTabRadiobox.mjs.map +1 -1
- package/lib/alt/radiobox/SimpleRadiobox.mjs +2 -2
- package/lib/alt/radiobox/SimpleRadiobox.mjs.map +1 -1
- package/lib/alt/radiobox/TabRadiobox.mjs +1 -1
- package/lib/alt/radiobox/TabRadiobox.mjs.map +1 -1
- package/lib/index.cjs +94 -51
- package/lib/index.cjs.map +1 -1
- package/lib/index.mjs +2 -2
- package/lib/withFormImageInput.mjs +1 -1
- package/lib/withFormImageInput.mjs.map +1 -1
- package/lib-yak/AutoComplete.mjs +705 -0
- package/lib-yak/AutoComplete.mjs.map +1 -0
- package/lib-yak/Checkbox.mjs +80 -0
- package/lib-yak/Checkbox.mjs.map +1 -0
- package/lib-yak/Combobox.mjs +652 -0
- package/lib-yak/Combobox.mjs.map +1 -0
- package/lib-yak/ComboboxWithCustom.mjs +77 -0
- package/lib-yak/ComboboxWithCustom.mjs.map +1 -0
- package/lib-yak/DatePicker.mjs +774 -0
- package/lib-yak/DatePicker.mjs.map +1 -0
- package/lib-yak/EditableBox.mjs +495 -0
- package/lib-yak/EditableBox.mjs.map +1 -0
- package/lib-yak/Errors.mjs +226 -0
- package/lib-yak/Errors.mjs.map +1 -0
- package/lib-yak/ExpandableBox.mjs +247 -0
- package/lib-yak/ExpandableBox.mjs.map +1 -0
- package/lib-yak/Field.mjs +93 -0
- package/lib-yak/Field.mjs.map +1 -0
- package/lib-yak/FieldBox.mjs +173 -0
- package/lib-yak/FieldBox.mjs.map +1 -0
- package/lib-yak/Form.mjs +322 -0
- package/lib-yak/Form.mjs.map +1 -0
- package/lib-yak/FormValue.mjs +111 -0
- package/lib-yak/FormValue.mjs.map +1 -0
- package/lib-yak/InputboxGroup.mjs +146 -0
- package/lib-yak/InputboxGroup.mjs.map +1 -0
- package/lib-yak/Radiobox.mjs +69 -0
- package/lib-yak/Radiobox.mjs.map +1 -0
- package/lib-yak/RichText.mjs +776 -0
- package/lib-yak/RichText.mjs.map +1 -0
- package/lib-yak/TextInput.mjs +589 -0
- package/lib-yak/TextInput.mjs.map +1 -0
- package/lib-yak/alt/checkbox/SimpleCheckbox.mjs +225 -0
- package/lib-yak/alt/checkbox/SimpleCheckbox.mjs.map +1 -0
- package/lib-yak/alt/checkbox/ToggleCheckbox.mjs +173 -0
- package/lib-yak/alt/checkbox/ToggleCheckbox.mjs.map +1 -0
- package/lib-yak/alt/radiobox/CleanTabRadiobox.mjs +87 -0
- package/lib-yak/alt/radiobox/CleanTabRadiobox.mjs.map +1 -0
- package/lib-yak/alt/radiobox/IconRadioBox.mjs +138 -0
- package/lib-yak/alt/radiobox/IconRadioBox.mjs.map +1 -0
- package/lib-yak/alt/radiobox/SimpleRadiobox.mjs +203 -0
- package/lib-yak/alt/radiobox/SimpleRadiobox.mjs.map +1 -0
- package/lib-yak/alt/radiobox/TabRadiobox.mjs +117 -0
- package/lib-yak/alt/radiobox/TabRadiobox.mjs.map +1 -0
- package/lib-yak/enhanceInput.mjs +131 -0
- package/lib-yak/enhanceInput.mjs.map +1 -0
- package/lib-yak/index.mjs +28 -0
- package/lib-yak/index.mjs.map +1 -0
- package/lib-yak/useConfirmDialog.mjs +117 -0
- package/lib-yak/useConfirmDialog.mjs.map +1 -0
- package/lib-yak/useDraftConfirmation.mjs +56 -0
- package/lib-yak/useDraftConfirmation.mjs.map +1 -0
- package/lib-yak/validation.mjs +91 -0
- package/lib-yak/validation.mjs.map +1 -0
- package/lib-yak/withFormImageInput.mjs +298 -0
- package/lib-yak/withFormImageInput.mjs.map +1 -0
- package/package.json +13 -3
- package/src/AutoComplete.jsx +12 -12
- package/src/Checkbox.jsx +2 -2
- package/src/Combobox.jsx +1 -1
- package/src/DatePicker.jsx +25 -22
- package/src/Errors.jsx +18 -8
- package/src/ExpandableBox.jsx +3 -3
- package/src/Field.jsx +9 -4
- package/src/FieldBox.jsx +6 -6
- package/src/IconRadioBoxOldHubt.jsx +1 -1
- package/src/InputboxGroup.jsx +1 -1
- package/src/RichText.jsx +17 -13
- package/src/TextInput.jsx +37 -26
- package/src/alt/checkbox/SimpleCheckbox.jsx +5 -5
- package/src/alt/checkbox/ToggleCheckbox.jsx +9 -8
- package/src/alt/radiobox/CleanTabRadiobox.jsx +2 -2
- package/src/alt/radiobox/SimpleRadiobox.jsx +7 -7
- package/src/alt/radiobox/TabRadiobox.jsx +4 -4
- package/src/withFormImageInput.jsx +2 -2
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/extends';
|
|
2
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
3
|
+
import { yakDomTag } from '@startlibs/utils/yakDomTag';
|
|
4
|
+
import { styled, css } from '@yak/react';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { getMargin } from '@startlibs/utils';
|
|
7
|
+
|
|
8
|
+
const _excluded = ["label", "helpText", "descText", "bellowDescText", "className", "labelClick", "focused", "mandatory", "onImage", "children", "labelFontSize"];
|
|
9
|
+
const Mandatory = styled(yakDomTag("span"))`
|
|
10
|
+
color: #c3282d;
|
|
11
|
+
margin-left: 1px;
|
|
12
|
+
vertical-align: top;
|
|
13
|
+
line-height: 100%;
|
|
14
|
+
margin-top: -1px;
|
|
15
|
+
${props => typeof props.mandatory === 'string' && css`color: ${__yakProps => {
|
|
16
|
+
const v = props.mandatory;
|
|
17
|
+
return typeof v === 'function' ? v(__yakProps) : v;
|
|
18
|
+
}};`}
|
|
19
|
+
`;
|
|
20
|
+
const Container = styled(yakDomTag("div"))`
|
|
21
|
+
position: relative;
|
|
22
|
+
margin-bottom: ${props => getMargin(props.theme.Field.margins)(props)};
|
|
23
|
+
text-align: left;
|
|
24
|
+
`;
|
|
25
|
+
// Nome próprio (não só `Field.Label = ...`): TextInput.jsx usa `${Field.Label}` como seletor
|
|
26
|
+
// (FloatingFieldType) num ARQUIVO DIFERENTE, e o yak tenta resolver isso avaliando o módulo
|
|
27
|
+
// inteiro de `Field` (um componente React de verdade) em tempo de build — falha com um
|
|
28
|
+
// `undefined` na saída (mesmo problema do Errors.Item, ver Errors.jsx). `Field.Label` continua
|
|
29
|
+
// existindo (uso interno e compatibilidade).
|
|
30
|
+
const FieldLabel = styled(yakDomTag("label")).attrs({
|
|
31
|
+
className: "styled-field-label styled-theme-field-label"
|
|
32
|
+
})`
|
|
33
|
+
font-weight: 550;
|
|
34
|
+
display: inline-block;
|
|
35
|
+
font-size: ${props => props.labelFontSize ? props.labelFontSize : '15'}px;
|
|
36
|
+
margin-bottom: .75rem;
|
|
37
|
+
${props => props.isOnImage && css`color: #fff;`}
|
|
38
|
+
|
|
39
|
+
`;
|
|
40
|
+
const HelpText = styled(yakDomTag("span")).attrs({
|
|
41
|
+
className: "styled-help-text"
|
|
42
|
+
})`
|
|
43
|
+
color: rgba(0,0,0,0.4);
|
|
44
|
+
font-weight: 400;
|
|
45
|
+
`;
|
|
46
|
+
const FieldDescription = styled(yakDomTag("span")).attrs({
|
|
47
|
+
className: "styled-field-description"
|
|
48
|
+
})`
|
|
49
|
+
color: rgba(0,0,0,0.4);
|
|
50
|
+
display: block;
|
|
51
|
+
font-size: 12px;
|
|
52
|
+
margin: 0.25rem 0 0;
|
|
53
|
+
font-weight: 400;
|
|
54
|
+
`;
|
|
55
|
+
const BellowFieldDescription = styled(FieldDescription).attrs({
|
|
56
|
+
className: "styled-bellow-field-description"
|
|
57
|
+
})`
|
|
58
|
+
margin: 0.5rem 0 0;
|
|
59
|
+
`;
|
|
60
|
+
const Field = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
61
|
+
let {
|
|
62
|
+
label,
|
|
63
|
+
helpText,
|
|
64
|
+
descText,
|
|
65
|
+
bellowDescText,
|
|
66
|
+
className,
|
|
67
|
+
labelClick,
|
|
68
|
+
focused,
|
|
69
|
+
mandatory,
|
|
70
|
+
onImage,
|
|
71
|
+
children,
|
|
72
|
+
labelFontSize
|
|
73
|
+
} = _ref,
|
|
74
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
75
|
+
return /*#__PURE__*/React.createElement(Container, _extends({
|
|
76
|
+
ref: ref
|
|
77
|
+
}, rest, {
|
|
78
|
+
className: className
|
|
79
|
+
}), label && /*#__PURE__*/React.createElement(FieldLabel, _extends({}, rest, {
|
|
80
|
+
onClick: labelClick,
|
|
81
|
+
labelFontSize: labelFontSize
|
|
82
|
+
}), label, mandatory && /*#__PURE__*/React.createElement(Mandatory, {
|
|
83
|
+
mandatory: mandatory
|
|
84
|
+
}, "*"), helpText && /*#__PURE__*/React.createElement(HelpText, null, " ", helpText), descText && /*#__PURE__*/React.createElement(FieldDescription, null, descText)), children, bellowDescText && /*#__PURE__*/React.createElement(BellowFieldDescription, null, bellowDescText));
|
|
85
|
+
});
|
|
86
|
+
Field.Label = FieldLabel;
|
|
87
|
+
Field.Container = Container;
|
|
88
|
+
Field.HelpText = HelpText;
|
|
89
|
+
Field.Description = FieldDescription;
|
|
90
|
+
Field.displayName = "Field";
|
|
91
|
+
|
|
92
|
+
export { BellowFieldDescription, Field, FieldDescription, FieldLabel, HelpText };
|
|
93
|
+
//# sourceMappingURL=Field.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Field.mjs","sources":["../src/Field.jsx"],"sourcesContent":["import styled from 'styled-components'\nimport React from 'react'\nimport {getMargin, customTheme} from '@startlibs/utils'\n\n\nconst Mandatory = styled.span`\n color: #c3282d;\n margin-left: 1px;\n vertical-align: top;\n line-height: 100%;\n margin-top: -1px;\n ${props => typeof props.mandatory === 'string' && `color: ${props.mandatory};`}\n`\nconst Container = styled.div`\n position: relative;\n margin-bottom: ${props => getMargin(props.theme.Field.margins)(props)};\n text-align: left;\n`\n// Nome próprio (não só `Field.Label = ...`): TextInput.jsx usa `${Field.Label}` como seletor\n// (FloatingFieldType) num ARQUIVO DIFERENTE, e o yak tenta resolver isso avaliando o módulo\n// inteiro de `Field` (um componente React de verdade) em tempo de build — falha com um\n// `undefined` na saída (mesmo problema do Errors.Item, ver Errors.jsx). `Field.Label` continua\n// existindo (uso interno e compatibilidade).\nexport const FieldLabel = styled.label`\n font-weight: 550;\n display: inline-block;\n font-size: ${props => props.labelFontSize ? props.labelFontSize : '15'}px;\n margin-bottom: .75rem;\n ${props => props.isOnImage && 'color: #fff;'}\n ${customTheme(\"FieldLabel\")}\n`\n\nexport const HelpText = styled.span`\n color: rgba(0,0,0,0.4);\n font-weight: 400;\n`\nexport const FieldDescription = styled.span`\n color: rgba(0,0,0,0.4);\n display: block;\n font-size: 12px;\n margin: 0.25rem 0 0;\n font-weight: 400;\n`\nexport const BellowFieldDescription = styled(FieldDescription)`\n margin: 0.5rem 0 0;\n`\n\nexport const Field = React.forwardRef((\n {\n label,\n helpText,\n descText,\n bellowDescText,\n className,\n labelClick,\n focused,\n mandatory,\n onImage,\n children,\n labelFontSize,\n ...rest\n }, ref) =>\n <Container ref={ref} {...rest} className={className}>\n {\n label &&\n <FieldLabel {...rest} onClick={labelClick} labelFontSize={labelFontSize}>\n {label}{mandatory && <Mandatory mandatory={mandatory}>*</Mandatory>}\n {helpText && <HelpText> {helpText}</HelpText>}\n {descText && <FieldDescription>{descText}</FieldDescription>}\n </FieldLabel>\n }\n {children}\n {bellowDescText && <BellowFieldDescription>{bellowDescText}</BellowFieldDescription>}\n </Container>\n)\n\nField.Label = FieldLabel\nField.Container = Container\nField.HelpText = HelpText\nField.Description = FieldDescription\nField.displayName = \"Field\""],"names":["Mandatory","styled","yakDomTag","props","mandatory","css","__yakProps","v","Container","getMargin","theme","Field","margins","FieldLabel","attrs","className","labelFontSize","isOnImage","HelpText","FieldDescription","BellowFieldDescription","React","forwardRef","_ref","ref","label","helpText","descText","bellowDescText","labelClick","focused","onImage","children","rest","_objectWithoutProperties","_excluded","createElement","_extends","onClick","Label","Description","displayName"],"mappings":";;;;;;;;AAKA,MAAMA,SAAS,GAAGC,MAAA,CAAAC,SAAA,CAAA,MAAA,CAAA,CAAA,CAAA;AAClB;AACA;AACA;AACA;AACA;AACA,EAAIC,EAAAA,KAAK,IAAI,OAAOA,KAAK,CAACC,SAAS,KAAK,QAAQ,IAAAC,GAAA,CAAA,OAAA,EAAAC,UAAA,IAAA;AAAA,EAAA,MAAAC,CAAA,GAAcJ,KAAK,CAACC,SAAS,CAAA;AAAA,EAAA,OAAA,OAAAG,CAAA,KAAAA,UAAAA,GAAAA,CAAA,CAAAD,UAAA,IAAAC,CAAA,CAAA;AAAA,CAAG,CAAA,CAAA,CAAA,CAAA;AAChF,CAAC,CAAA;AACD,MAAMC,SAAS,GAAGP,MAAA,CAAAC,SAAA,CAAA,K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WithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
3
|
+
import { yakDomTag } from '@startlibs/utils/yakDomTag';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { darken } from 'polished';
|
|
6
|
+
import { styled, css } from '@yak/react';
|
|
7
|
+
import { getColor, constrainEvent, callIfFunction } from '@startlibs/utils';
|
|
8
|
+
import { Icon, TextButton } from '@startlibs/components';
|
|
9
|
+
import { usePopupToggle } from '@startlibs/core';
|
|
10
|
+
import { HelpText } from './Field.mjs';
|
|
11
|
+
|
|
12
|
+
const _excluded = ["className", "label", "helpText", "descText", "actionLabel", "rightContainer", "onClick", "icon", "remove", "children", "dropDownMenu"];
|
|
13
|
+
const FieldBoxIcon = styled(Icon).attrs({
|
|
14
|
+
className: "styled-field-box-icon"
|
|
15
|
+
})`
|
|
16
|
+
font-size: 25px;
|
|
17
|
+
width: 25px;
|
|
18
|
+
text-align: center;
|
|
19
|
+
margin-right: 1rem;
|
|
20
|
+
`;
|
|
21
|
+
const FieldBoxAction = styled(yakDomTag("div")).attrs({
|
|
22
|
+
className: "styled-field-box-action"
|
|
23
|
+
})`
|
|
24
|
+
margin-left: auto;
|
|
25
|
+
color: ${__yakProps => {
|
|
26
|
+
const v = getColor('main');
|
|
27
|
+
return typeof v === 'function' ? v(__yakProps) : v;
|
|
28
|
+
}};
|
|
29
|
+
padding-left: 1rem;
|
|
30
|
+
font-size: 13px;
|
|
31
|
+
font-weight: 500;
|
|
32
|
+
`;
|
|
33
|
+
const FieldBoxHelpText = styled(yakDomTag("span")).attrs({
|
|
34
|
+
className: "styled-field-box-help-text"
|
|
35
|
+
})`
|
|
36
|
+
font-weight: 400;
|
|
37
|
+
color: rgba(0,0,0,0.4);
|
|
38
|
+
font-size: 12px;
|
|
39
|
+
`;
|
|
40
|
+
const FieldBoxContent = styled(yakDomTag("div"))`
|
|
41
|
+
margin-right: auto;
|
|
42
|
+
min-width: 0;
|
|
43
|
+
`;
|
|
44
|
+
const DeleteButton = styled(Icon).attrs({
|
|
45
|
+
icon: 'x'
|
|
46
|
+
})`
|
|
47
|
+
width: 24px;
|
|
48
|
+
height: 24px;
|
|
49
|
+
line-height: 24px;
|
|
50
|
+
border-radius: 50%;
|
|
51
|
+
display: inline-block;
|
|
52
|
+
font-size: 18px;
|
|
53
|
+
margin-left: 0.75rem;
|
|
54
|
+
text-align: center;
|
|
55
|
+
cursor: pointer;
|
|
56
|
+
color: ${__yakProps => {
|
|
57
|
+
const v = getColor('gray120');
|
|
58
|
+
return typeof v === 'function' ? v(__yakProps) : v;
|
|
59
|
+
}};
|
|
60
|
+
background-color: rgba(0,0,0,0.08);
|
|
61
|
+
flex-shrink: 0;
|
|
62
|
+
&:hover {
|
|
63
|
+
background: rgba(0,0,0,0.11);
|
|
64
|
+
}
|
|
65
|
+
&:active {
|
|
66
|
+
background: rgba(0,0,0,0.13);
|
|
67
|
+
}
|
|
68
|
+
`;
|
|
69
|
+
const DropdownButton = styled(Icon).attrs({
|
|
70
|
+
icon: 'arrow-down'
|
|
71
|
+
})`
|
|
72
|
+
width: 24px;
|
|
73
|
+
height: 24px;
|
|
74
|
+
line-height: 24px;
|
|
75
|
+
border-radius: 50%;
|
|
76
|
+
display: inline-block;
|
|
77
|
+
font-size: 14px;
|
|
78
|
+
margin-left: 0.75rem;
|
|
79
|
+
text-align: center;
|
|
80
|
+
cursor: pointer;
|
|
81
|
+
color: ${__yakProps => {
|
|
82
|
+
const v = getColor('gray120');
|
|
83
|
+
return typeof v === 'function' ? v(__yakProps) : v;
|
|
84
|
+
}};
|
|
85
|
+
background-color: rgba(0,0,0,0.08);
|
|
86
|
+
flex-shrink: 0;
|
|
87
|
+
position: relative;
|
|
88
|
+
&:hover {
|
|
89
|
+
background: rgba(0,0,0,0.11);
|
|
90
|
+
}
|
|
91
|
+
&:active {
|
|
92
|
+
background: rgba(0,0,0,0.13);
|
|
93
|
+
}
|
|
94
|
+
`;
|
|
95
|
+
const DescText = styled(yakDomTag("div"))`
|
|
96
|
+
font-weight: 400;
|
|
97
|
+
color: rgba(0,0,0,0.4);
|
|
98
|
+
font-size: 12px;
|
|
99
|
+
margin-top: 0.25rem;
|
|
100
|
+
`;
|
|
101
|
+
const FieldBox = styled(_ref => {
|
|
102
|
+
let {
|
|
103
|
+
className,
|
|
104
|
+
label,
|
|
105
|
+
helpText,
|
|
106
|
+
descText,
|
|
107
|
+
actionLabel,
|
|
108
|
+
rightContainer,
|
|
109
|
+
onClick,
|
|
110
|
+
icon,
|
|
111
|
+
remove,
|
|
112
|
+
children,
|
|
113
|
+
dropDownMenu
|
|
114
|
+
} = _ref,
|
|
115
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
116
|
+
const menuToggle = usePopupToggle();
|
|
117
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
|
118
|
+
className: className,
|
|
119
|
+
onClick: onClick
|
|
120
|
+
}, props), icon && /*#__PURE__*/React.createElement(FieldBoxIcon, {
|
|
121
|
+
icon: icon
|
|
122
|
+
}), /*#__PURE__*/React.createElement(FieldBoxContent, null, label, helpText && /*#__PURE__*/React.createElement(HelpText, null, " ", helpText), descText && /*#__PURE__*/React.createElement(DescText, null, descText), children), actionLabel && /*#__PURE__*/React.createElement(TextButton, null, actionLabel), rightContainer && /*#__PURE__*/React.createElement("div", {
|
|
123
|
+
className: "rightContainer"
|
|
124
|
+
}, rightContainer), remove && /*#__PURE__*/React.createElement(DeleteButton, {
|
|
125
|
+
onClick: constrainEvent(remove)
|
|
126
|
+
}), dropDownMenu && /*#__PURE__*/React.createElement(DropdownButton, {
|
|
127
|
+
onClick: constrainEvent(menuToggle.toggle)
|
|
128
|
+
}, menuToggle.isOpen && callIfFunction(dropDownMenu)));
|
|
129
|
+
}).attrs({
|
|
130
|
+
className: "styled-field-box"
|
|
131
|
+
})`
|
|
132
|
+
display: flex;
|
|
133
|
+
align-items: center;
|
|
134
|
+
width: 100%;
|
|
135
|
+
background: ${__yakProps => {
|
|
136
|
+
const v = getColor('lightBluishGray');
|
|
137
|
+
return typeof v === 'function' ? v(__yakProps) : v;
|
|
138
|
+
}};
|
|
139
|
+
border-radius: 8px;
|
|
140
|
+
min-height: 42px;
|
|
141
|
+
padding: 1rem 1.25rem;
|
|
142
|
+
align-items: center;
|
|
143
|
+
font-size: 14px;
|
|
144
|
+
color: ${__yakProps => {
|
|
145
|
+
const v = getColor('gray60');
|
|
146
|
+
return typeof v === 'function' ? v(__yakProps) : v;
|
|
147
|
+
}};
|
|
148
|
+
position: relative;
|
|
149
|
+
transition: border-radius 0.5s ease;
|
|
150
|
+
${props => props.onClick && css`
|
|
151
|
+
cursor: pointer;
|
|
152
|
+
&:hover {
|
|
153
|
+
background: ${props => darken(0.035, getColor('lightBluishGray')(props))};
|
|
154
|
+
}
|
|
155
|
+
&:active {
|
|
156
|
+
background: ${props => darken(0.05, getColor('lightBluishGray')(props))};
|
|
157
|
+
transition: none;
|
|
158
|
+
}
|
|
159
|
+
`}
|
|
160
|
+
& ~ & {
|
|
161
|
+
margin-top: 0.75rem;
|
|
162
|
+
}
|
|
163
|
+
@media (max-width: 600px) {
|
|
164
|
+
min-height: 54px;
|
|
165
|
+
font-size: 15px !important;
|
|
166
|
+
}
|
|
167
|
+
${TextButton}, .rightContainer {
|
|
168
|
+
margin-left: 1rem;
|
|
169
|
+
}
|
|
170
|
+
`;
|
|
171
|
+
|
|
172
|
+
export { FieldBox, FieldBoxAction, FieldBoxHelpText, FieldBoxIcon };
|
|
173
|
+
//# sourceMappingURL=FieldBox.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FieldBox.mjs","sources":["../src/FieldBox.jsx"],"sourcesContent":["import React from 'react'\nimport {darken} from 'polished'\nimport styled, {css} from 'styled-components'\nimport {media, callIfFunction, constrainEvent} from '@startlibs/utils';\nimport {Icon, TextButton} from '@startlibs/components'\nimport {getColor } from '@startlibs/utils';\nimport {usePopupToggle } from '@startlibs/core';\nimport {HelpText} from './Field'\n\nexport const FieldBoxIcon = styled(Icon)`\n font-size: 25px;\n width: 25px;\n text-align: center;\n margin-right: 1rem;\n`\nexport const FieldBoxAction = styled.div`\n margin-left: auto;\n color: ${getColor('main')};\n padding-left: 1rem;\n font-size: 13px;\n font-weight: 500;\n`\n \nexport const FieldBoxHelpText = styled.span`\n font-weight: 400;\n color: rgba(0,0,0,0.4);\n font-size: 12px;\n`\n\nconst FieldBoxContent = styled.div`\n margin-right: auto;\n min-width: 0;\n`\n\nconst DeleteButton = styled(Icon).attrs({icon: 'x'})`\n width: 24px;\n height: 24px;\n line-height: 24px;\n border-radius: 50%;\n display: inline-block;\n font-size: 18px;\n margin-left: 0.75rem;\n text-align: center;\n cursor: pointer;\n color: ${getColor('gray120')};\n background-color: rgba(0,0,0,0.08);\n flex-shrink: 0;\n &:hover {\n background: rgba(0,0,0,0.11);\n }\n &:active {\n background: rgba(0,0,0,0.13);\n }\n`\nconst DropdownButton = styled(Icon).attrs({icon: 'arrow-down'})`\n width: 24px;\n height: 24px;\n line-height: 24px;\n border-radius: 50%;\n display: inline-block;\n font-size: 14px;\n margin-left: 0.75rem;\n text-align: center;\n cursor: pointer;\n color: ${getColor('gray120')};\n background-color: rgba(0,0,0,0.08);\n flex-shrink: 0;\n position: relative;\n &:hover {\n background: rgba(0,0,0,0.11);\n }\n &:active {\n background: rgba(0,0,0,0.13);\n }\n`\n\nconst DescText = styled.div `\n font-weight: 400;\n color: rgba(0,0,0,0.4);\n font-size: 12px;\n margin-top: 0.25rem;\n`\n\n\nexport const FieldBox = styled(({className,label,helpText,descText,actionLabel,rightContainer,onClick,icon,remove,children,dropDownMenu,...props}) => {\n const menuToggle = usePopupToggle()\n return <div className={className} onClick={onClick} {...props}>\n {icon && <FieldBoxIcon icon={icon}/>}\n <FieldBoxContent>\n {label}{helpText && <HelpText> {helpText}</HelpText>}\n {descText && <DescText>{descText}</DescText>}\n {children}\n </FieldBoxContent>\n {actionLabel && <TextButton>{actionLabel}</TextButton>}\n {rightContainer && <div className=\"rightContainer\">{rightContainer}</div>}\n {remove && <DeleteButton onClick={constrainEvent(remove)}/>}\n {\n dropDownMenu && <DropdownButton onClick={constrainEvent(menuToggle.toggle)}>\n {menuToggle.isOpen && callIfFunction(dropDownMenu)}\n </DropdownButton>\n }\n </div>\n})`\n display: flex;\n align-items: center;\n width: 100%;\n background: ${getColor('lightBluishGray')};\n border-radius: 8px;\n min-height: 42px;\n padding: 1rem 1.25rem;\n align-items: center;\n font-size: 14px;\n color: ${getColor('gray60')};\n position: relative;\n transition: border-radius 0.5s ease;\n ${props => props.onClick && css`\n cursor: pointer;\n &:hover {\n background: ${props => darken(0.035, getColor('lightBluishGray')(props))};\n }\n &:active {\n background: ${props => darken(0.05, getColor('lightBluishGray')(props))};\n transition: none;\n }\n `}\n & ~ & {\n margin-top: 0.75rem;\n }\n ${media.mobile`\n min-height: 54px;\n font-size: 15px !important;\n `}\n ${TextButton}, .rightContainer {\n margin-left: 1rem;\n }\n`"],"names":["FieldBoxIcon","styled","Icon","attrs","className","FieldBoxAction","yakDomTag","__yakProps","v","getColor","FieldBoxHelpText","FieldBoxContent","DeleteButton","icon","DropdownButton","DescText","FieldBox","_ref","label","helpText","descText","actionLabel","rightContainer","onClick","remove","children","dropDownMenu","props","_objectWithoutProperties","_excluded","menuToggle","usePopupToggle","React","createElement","_extends","HelpText","TextButton","constrainEvent","toggle","isOpen","callIfFunction","css","darken"],"mappings":";;;;;;;;;;;;AASO,MAAMA,YAAY,GAAGC,MAAM,CAACC,IAAI,CAAC,CAAAC,KAAA,CAAA;EAAAC,SAAA,EAAA,uBAAA;AAAA,CAAA,CAAA,CAAA;AACxC;AACA;AACA;AACA;AACA,EAAC;MACYC,cAAc,GAAGJ,MAAA,CAAAK,SAAA,SAAAH,KAAA,CAAA;EAAAC,SAAA,EAAA,yBAAA;AAAA,CAAA,CAAA,CAAA;AAC9B;AACA,SAAA,EAF8BG,UAAA,IAAA;AAAA,EAAA,MAAAC,CAAA,GAEnBC,QAAQ,CAAC,MAAM,CAAC,CAA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AAG,CAAA,CAAA;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACA,EAAA,EAAIS,UAAU,CAAA;AACd;AACA;AACA;;;;"}
|
package/lib-yak/Form.mjs
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/extends';
|
|
2
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
3
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
|
+
import _set from 'lodash/fp/set';
|
|
5
|
+
import _update from 'lodash/fp/update';
|
|
6
|
+
import _isFunction from 'lodash/fp/isFunction';
|
|
7
|
+
import _get from 'lodash/fp/get';
|
|
8
|
+
import React, { useContext, useState, useMemo, useImperativeHandle, forwardRef } from 'react';
|
|
9
|
+
import { willUseSpreadState, useRefState, StartlibsContext, useToggle, useIsUnmounted, useConsumerCatalog } from '@startlibs/core';
|
|
10
|
+
import { _s, callIfFunction, ifUndefined } from '@startlibs/utils';
|
|
11
|
+
import { useProvideErrors } from './Errors.mjs';
|
|
12
|
+
import { useDraftConfirmation } from './useDraftConfirmation.mjs';
|
|
13
|
+
|
|
14
|
+
const _excluded = ["children"];
|
|
15
|
+
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; }
|
|
16
|
+
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; }
|
|
17
|
+
const getFormResponse = function (setter) {
|
|
18
|
+
let path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
19
|
+
return (_, v) => setter(_s.get(path, v));
|
|
20
|
+
};
|
|
21
|
+
const getFormValues = function (setter) {
|
|
22
|
+
let path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
23
|
+
return values => setter(_s.get(path, values));
|
|
24
|
+
};
|
|
25
|
+
const FormContext = /*#__PURE__*/React.createContext({});
|
|
26
|
+
const ComponentMetaContext = /*#__PURE__*/React.createContext({});
|
|
27
|
+
const [useProvideValues, useSpreadValue, FormValueContext] = willUseSpreadState();
|
|
28
|
+
const [useProvideMeta, useMeta] = willUseSpreadState();
|
|
29
|
+
const useFormValue = useSpreadValue;
|
|
30
|
+
const useFormValueRef = () => {
|
|
31
|
+
const [get, set] = useContext(FormValueContext);
|
|
32
|
+
return [get, set];
|
|
33
|
+
};
|
|
34
|
+
const useFormMeta = useMeta;
|
|
35
|
+
const useForm = (_ref, ref) => {
|
|
36
|
+
let {
|
|
37
|
+
action,
|
|
38
|
+
alwaysSave = false,
|
|
39
|
+
skipDom = false,
|
|
40
|
+
values: initialValues = {},
|
|
41
|
+
meta = {},
|
|
42
|
+
transform = v => v,
|
|
43
|
+
preValidation = () => false,
|
|
44
|
+
loadingBeforeValidate,
|
|
45
|
+
onSuccess = () => {},
|
|
46
|
+
onFailure = () => {},
|
|
47
|
+
onNonPreValidation,
|
|
48
|
+
onChange,
|
|
49
|
+
autoComplete
|
|
50
|
+
} = _ref;
|
|
51
|
+
const outerConfig = {
|
|
52
|
+
onSuccess,
|
|
53
|
+
onFailure,
|
|
54
|
+
transform,
|
|
55
|
+
preValidation,
|
|
56
|
+
alwaysSave,
|
|
57
|
+
action
|
|
58
|
+
};
|
|
59
|
+
const currentInitialValues = useRefState(initialValues);
|
|
60
|
+
currentInitialValues.set(initialValues);
|
|
61
|
+
const startlibs = useContext(StartlibsContext);
|
|
62
|
+
const [hasChanged, setHasChangedValue] = useState(false);
|
|
63
|
+
const hasChangedRef = useRefState(false);
|
|
64
|
+
const shouldResubmitForm = useToggle(false, (next, prev) => prev && !next && errorsUtils.removeErrorPath('_shouldResubmitForm'));
|
|
65
|
+
const resubmittingForm = useRefState(false);
|
|
66
|
+
const loading = useToggle();
|
|
67
|
+
const isUnmounted = useIsUnmounted();
|
|
68
|
+
const [ErrorsProvider, errorsContext, errorsUtils] = useProvideErrors();
|
|
69
|
+
const [registeredComponentMetas, componentMetasManager] = useConsumerCatalog();
|
|
70
|
+
const [confirmDraftContent, draftToggle, draftConfirmation] = useDraftConfirmation(() => submitForm(undefined, {
|
|
71
|
+
isConfirming: true
|
|
72
|
+
}));
|
|
73
|
+
const handleValuesChange = (prev, next) => {
|
|
74
|
+
if (!hasChangedRef.get()) {
|
|
75
|
+
setHasChanged(true);
|
|
76
|
+
}
|
|
77
|
+
callIfFunction(onChange, prev, next, utils);
|
|
78
|
+
};
|
|
79
|
+
const setHasChanged = v => {
|
|
80
|
+
shouldResubmitForm.close();
|
|
81
|
+
if (v !== hasChangedRef.get()) {
|
|
82
|
+
draftToggle.openWith(v);
|
|
83
|
+
setHasChangedValue(v);
|
|
84
|
+
hasChangedRef.set(v);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const [ValuesProvider, valuesManager, [getValues, setValues]] = useProvideValues(initialValues, handleValuesChange);
|
|
88
|
+
const [MetaProvider, metaManager, [getMeta, setMeta]] = useProvideMeta(callIfFunction(meta, initialValues), (prev, next) => {
|
|
89
|
+
if (prev.submittingFiles !== 0 && next.submittingFiles === 0) {
|
|
90
|
+
if (resubmittingForm.get()) {
|
|
91
|
+
if (shouldResubmitForm.get()) {
|
|
92
|
+
resubmittingForm.get().confirm();
|
|
93
|
+
} else {
|
|
94
|
+
resubmittingForm.get().cancel();
|
|
95
|
+
}
|
|
96
|
+
resubmittingForm.set(false);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
const validate = async function () {
|
|
101
|
+
let values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getValues();
|
|
102
|
+
let validation = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : preValidation;
|
|
103
|
+
const errors = await callIfFunction(validation, values, utils);
|
|
104
|
+
if (errors) {
|
|
105
|
+
errorsUtils.setErrors(errors);
|
|
106
|
+
}
|
|
107
|
+
return errors;
|
|
108
|
+
};
|
|
109
|
+
const verifyImagesAndSubmitForm = values => {
|
|
110
|
+
if (values && getMeta('submittedFiles')) {
|
|
111
|
+
const valuesWithUploadedImages = getMeta('submittedFiles').reduce((acc, _ref2) => {
|
|
112
|
+
let {
|
|
113
|
+
path,
|
|
114
|
+
file,
|
|
115
|
+
image
|
|
116
|
+
} = _ref2;
|
|
117
|
+
if (_s.get(path, acc) === file) {
|
|
118
|
+
return _s.set(path, image, acc);
|
|
119
|
+
} else {
|
|
120
|
+
return acc;
|
|
121
|
+
}
|
|
122
|
+
}, values);
|
|
123
|
+
return submitForm(valuesWithUploadedImages);
|
|
124
|
+
} else {
|
|
125
|
+
return submitForm(values);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const submitForm = async function (optValues) {
|
|
129
|
+
let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
130
|
+
if (loading.get()) {
|
|
131
|
+
return new Promise(() => {});
|
|
132
|
+
}
|
|
133
|
+
const values = ifUndefined(callIfFunction(optValues, getValues()), getValues());
|
|
134
|
+
if (getMeta('submittingFiles')) {
|
|
135
|
+
shouldResubmitForm.open();
|
|
136
|
+
errorsUtils.setError('_shouldResubmitForm', startlibs.FormUploadingFileError || startlibs.FormUploadingImageError);
|
|
137
|
+
if (config.isConfirming) {
|
|
138
|
+
return Promise.reject();
|
|
139
|
+
}
|
|
140
|
+
return new Promise((resolve, reject) => {
|
|
141
|
+
resubmittingForm.set({
|
|
142
|
+
confirm: () => resolve(verifyImagesAndSubmitForm(values)),
|
|
143
|
+
cancel: () => reject()
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
const {
|
|
148
|
+
onSuccess,
|
|
149
|
+
onFailure,
|
|
150
|
+
transform,
|
|
151
|
+
alwaysSave,
|
|
152
|
+
preValidation,
|
|
153
|
+
action
|
|
154
|
+
} = _objectSpread(_objectSpread({}, outerConfig), config);
|
|
155
|
+
if (preValidation && loadingBeforeValidate) {
|
|
156
|
+
loading.open();
|
|
157
|
+
}
|
|
158
|
+
const errors = await validate(values, preValidation);
|
|
159
|
+
if (errors) {
|
|
160
|
+
loading.close();
|
|
161
|
+
callIfFunction(onNonPreValidation, values, errors);
|
|
162
|
+
throw {
|
|
163
|
+
unvalidated: errors
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
const request = await transform(values, {
|
|
167
|
+
meta: getMeta()
|
|
168
|
+
});
|
|
169
|
+
if (!request) {
|
|
170
|
+
loading.close();
|
|
171
|
+
return {
|
|
172
|
+
untransformed: true
|
|
173
|
+
};
|
|
174
|
+
} else {
|
|
175
|
+
loading.open();
|
|
176
|
+
errorsUtils.clearErrors();
|
|
177
|
+
if (!alwaysSave && !hasChangedRef.get() && (!values || values === getValues())) {
|
|
178
|
+
await onSuccess(request);
|
|
179
|
+
if (!isUnmounted()) {
|
|
180
|
+
loading.close();
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
unrequested: request
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
try {
|
|
187
|
+
const response = await action(request);
|
|
188
|
+
await onSuccess(request, response);
|
|
189
|
+
if (!isUnmounted()) {
|
|
190
|
+
setHasChanged(false);
|
|
191
|
+
loading.close();
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
request,
|
|
195
|
+
response
|
|
196
|
+
};
|
|
197
|
+
} catch (rejection) {
|
|
198
|
+
if (_get([0, 'errors'], rejection)) {
|
|
199
|
+
errorsUtils.setErrors(rejection[0].errors);
|
|
200
|
+
}
|
|
201
|
+
try {
|
|
202
|
+
await onFailure(request, rejection, utils);
|
|
203
|
+
} catch (e) {
|
|
204
|
+
console.log(e);
|
|
205
|
+
}
|
|
206
|
+
if (!isUnmounted()) {
|
|
207
|
+
loading.close();
|
|
208
|
+
}
|
|
209
|
+
throw {
|
|
210
|
+
request,
|
|
211
|
+
rejection
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
const willSubmitForm = e => {
|
|
217
|
+
if (e) {
|
|
218
|
+
e.preventDefault();
|
|
219
|
+
e.stopPropagation();
|
|
220
|
+
}
|
|
221
|
+
return submitForm();
|
|
222
|
+
};
|
|
223
|
+
const inputs = [loading, hasChanged, errorsContext, initialValues, transform, preValidation, onSuccess, onFailure, alwaysSave, action, shouldResubmitForm];
|
|
224
|
+
const utils = useMemo(() => _objectSpread({
|
|
225
|
+
setValue: function (path, value) {
|
|
226
|
+
let hasChanged = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
227
|
+
setValues(_isFunction(value) ? _update(path, value) : _set(path, value), path, hasChanged ? null : {
|
|
228
|
+
ignoreCallback: true
|
|
229
|
+
});
|
|
230
|
+
},
|
|
231
|
+
setValues: function (valuesSetter) {
|
|
232
|
+
let hasChanged = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
233
|
+
setValues(valuesSetter, undefined, hasChanged ? null : {
|
|
234
|
+
ignoreCallback: true
|
|
235
|
+
});
|
|
236
|
+
},
|
|
237
|
+
resetForm: () => {
|
|
238
|
+
setValues(ifUndefined(currentInitialValues.get(), {}));
|
|
239
|
+
setHasChanged(false);
|
|
240
|
+
},
|
|
241
|
+
resetField: path => {
|
|
242
|
+
const initialValue = _s.get(path, currentInitialValues.get());
|
|
243
|
+
if (initialValue !== getValues(path)) {
|
|
244
|
+
setValues(_s.set(path, initialValue));
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
getOriginalValues: () => currentInitialValues.get(),
|
|
248
|
+
getOriginalValue: path => _s.get(path, currentInitialValues.get()),
|
|
249
|
+
getValues,
|
|
250
|
+
getValue: getValues,
|
|
251
|
+
getTransformedValues: () => transform(getValues()),
|
|
252
|
+
setHasChanged,
|
|
253
|
+
setMeta,
|
|
254
|
+
getMeta,
|
|
255
|
+
confirm: draftConfirmation,
|
|
256
|
+
validate: (props, validation) => !validate(props, validation),
|
|
257
|
+
submitForm,
|
|
258
|
+
willSubmitForm,
|
|
259
|
+
isLoading: loading.isOpen || shouldResubmitForm.isOpen,
|
|
260
|
+
hasChanged,
|
|
261
|
+
getHasChanged: () => hasChangedRef.get()
|
|
262
|
+
}, errorsUtils), inputs);
|
|
263
|
+
useImperativeHandle(ref, () => utils, inputs);
|
|
264
|
+
return [children => /*#__PURE__*/React.createElement(FormContext.Provider, {
|
|
265
|
+
value: utils
|
|
266
|
+
}, /*#__PURE__*/React.createElement(ComponentMetaContext.Provider, {
|
|
267
|
+
value: componentMetasManager
|
|
268
|
+
}, /*#__PURE__*/React.createElement(ValuesProvider, {
|
|
269
|
+
value: valuesManager
|
|
270
|
+
}, /*#__PURE__*/React.createElement(MetaProvider, {
|
|
271
|
+
value: metaManager
|
|
272
|
+
}, /*#__PURE__*/React.createElement(ErrorsProvider, {
|
|
273
|
+
value: errorsContext
|
|
274
|
+
}, !skipDom ? /*#__PURE__*/React.createElement("form", {
|
|
275
|
+
autoComplete: autoComplete,
|
|
276
|
+
noValidate: true,
|
|
277
|
+
onSubmit: willSubmitForm
|
|
278
|
+
}, callIfFunction(children, utils)) : callIfFunction(children, utils))))), confirmDraftContent), utils];
|
|
279
|
+
};
|
|
280
|
+
const WithForm = /*#__PURE__*/forwardRef((_ref3, ref) => {
|
|
281
|
+
let {
|
|
282
|
+
children
|
|
283
|
+
} = _ref3,
|
|
284
|
+
rest = _objectWithoutProperties(_ref3, _excluded);
|
|
285
|
+
return useForm(rest, ref)[0](children);
|
|
286
|
+
});
|
|
287
|
+
const Form = _ref4 => {
|
|
288
|
+
let {
|
|
289
|
+
transform,
|
|
290
|
+
preValidation,
|
|
291
|
+
onSuccess,
|
|
292
|
+
onFailure,
|
|
293
|
+
children
|
|
294
|
+
} = _ref4;
|
|
295
|
+
const form = useContext(FormContext);
|
|
296
|
+
const onSubmit = e => {
|
|
297
|
+
if (e) e.preventDefault();
|
|
298
|
+
return form.submitForm(undefined, undefined, {
|
|
299
|
+
transform,
|
|
300
|
+
preValidation,
|
|
301
|
+
onSuccess,
|
|
302
|
+
onFailure
|
|
303
|
+
});
|
|
304
|
+
};
|
|
305
|
+
return typeof children === 'function' ? children(onSubmit) : /*#__PURE__*/React.createElement("form", {
|
|
306
|
+
noValidate: true,
|
|
307
|
+
onSubmit: onSubmit
|
|
308
|
+
}, children);
|
|
309
|
+
};
|
|
310
|
+
const withForm = Component => /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE__*/React.createElement(WithForm, props, form => /*#__PURE__*/React.createElement(Component, _extends({
|
|
311
|
+
form: form
|
|
312
|
+
}, props, {
|
|
313
|
+
ref: ref
|
|
314
|
+
}))));
|
|
315
|
+
const withForm2 = () => Component => /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE__*/React.createElement(WithForm, props, form => /*#__PURE__*/React.createElement(Component, _extends({
|
|
316
|
+
form: form
|
|
317
|
+
}, props, {
|
|
318
|
+
ref: ref
|
|
319
|
+
}))));
|
|
320
|
+
|
|
321
|
+
export { ComponentMetaContext, Form, FormContext, WithForm, getFormResponse, getFormValues, useForm, useFormMeta, useFormValue, useFormValueRef, withForm, withForm2 };
|
|
322
|
+
//# sourceMappingURL=Form.mjs.map
|