@mobilestock-native/form 0.1.1 → 0.2.0
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/index.d.ts +62 -2
- package/index.js +32 -7
- package/package.json +4 -3
package/index.d.ts
CHANGED
|
@@ -1,13 +1,67 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { BadgeType } from '@mobilestock-native/badge';
|
|
3
|
+
import { ButtonProps } from '@mobilestock-native/button';
|
|
1
4
|
import * as react from 'react';
|
|
2
5
|
import { RefObject } from 'react';
|
|
3
6
|
import { TextInputProps } from 'react-native';
|
|
4
7
|
import { FormHandles } from '@unform/core';
|
|
5
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
|
-
import { ButtonProps } from '@mobilestock-native/button';
|
|
7
8
|
import { ViewBaseProps } from '@mobilestock-native/container';
|
|
8
9
|
import { FormProps } from '@unform/mobile';
|
|
9
10
|
import { ZodSchema } from 'zod';
|
|
10
11
|
|
|
12
|
+
interface BadgeProps {
|
|
13
|
+
text: string;
|
|
14
|
+
renderInsidePill?: boolean;
|
|
15
|
+
type?: BadgeType;
|
|
16
|
+
}
|
|
17
|
+
declare function Badge(props: BadgeProps): react_jsx_runtime.JSX.Element;
|
|
18
|
+
declare namespace Badge {
|
|
19
|
+
var displayName: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type ButtonType = 'PLUS' | 'MINUS';
|
|
23
|
+
interface TypeButton extends Pick<ButtonProps, 'disabled' | 'text' | 'backgroundColor'> {
|
|
24
|
+
type: ButtonType;
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
declare function Minus(props: Partial<Omit<TypeButton, 'type'>>): react_jsx_runtime.JSX.Element;
|
|
29
|
+
declare namespace Minus {
|
|
30
|
+
var displayName: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
declare function Plus(props: Partial<Omit<TypeButton, 'type'>>): react_jsx_runtime.JSX.Element;
|
|
34
|
+
declare namespace Plus {
|
|
35
|
+
var displayName: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
declare function Display(): react_jsx_runtime.JSX.Element;
|
|
39
|
+
declare namespace Display {
|
|
40
|
+
var displayName: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type CounterEventName = 'INCREMENT' | 'DECREMENT' | 'EDIT';
|
|
44
|
+
|
|
45
|
+
interface CounterRootProps {
|
|
46
|
+
children?: React.ReactNode;
|
|
47
|
+
initialCount?: number;
|
|
48
|
+
maxCount?: number;
|
|
49
|
+
minCount?: number;
|
|
50
|
+
label?: string;
|
|
51
|
+
name: string;
|
|
52
|
+
editable?: boolean;
|
|
53
|
+
multiplier?: number;
|
|
54
|
+
labelPosition?: 'TOP_START' | 'LEFT' | 'TOP_CENTER';
|
|
55
|
+
buttonTransparent?: boolean;
|
|
56
|
+
groupElements?: boolean;
|
|
57
|
+
onChange?(data: {
|
|
58
|
+
value: number;
|
|
59
|
+
event: CounterEventName;
|
|
60
|
+
}): void;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
declare function CounterRoot({ children, ...props }: CounterRootProps): react_jsx_runtime.JSX.Element;
|
|
64
|
+
|
|
11
65
|
type InputType = 'text' | 'password' | 'tel' | 'email' | 'number' | 'url' | 'zipcode' | 'hidden';
|
|
12
66
|
interface InputProps extends Omit<TextInputProps, 'hitSlop'> {
|
|
13
67
|
name: string;
|
|
@@ -73,6 +127,12 @@ declare const Form: typeof FormComponent & {
|
|
|
73
127
|
Input: react.ForwardRefExoticComponent<InputProps & react.RefAttributes<InputRef>>;
|
|
74
128
|
Button: typeof FormButton;
|
|
75
129
|
Select: typeof FormSelect;
|
|
130
|
+
Counter: typeof CounterRoot & {
|
|
131
|
+
Display: typeof Display;
|
|
132
|
+
Plus: typeof Plus;
|
|
133
|
+
Minus: typeof Minus;
|
|
134
|
+
Badge: typeof Badge;
|
|
135
|
+
};
|
|
76
136
|
Vertical: typeof FormVertical;
|
|
77
137
|
Horizontal: typeof FormHorizontal;
|
|
78
138
|
};
|
package/index.js
CHANGED
|
@@ -1,25 +1,50 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
|
|
1
|
+
"use strict";var ct=Object.create;var le=Object.defineProperty,dt=Object.defineProperties,pt=Object.getOwnPropertyDescriptor,ft=Object.getOwnPropertyDescriptors,gt=Object.getOwnPropertyNames,be=Object.getOwnPropertySymbols,Ct=Object.getPrototypeOf,Ne=Object.prototype.hasOwnProperty,De=Object.prototype.propertyIsEnumerable;var ze=(e,o,t)=>o in e?le(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t,p=(e,o)=>{for(var t in o||(o={}))Ne.call(o,t)&&ze(e,t,o[t]);if(be)for(var t of be(o))De.call(o,t)&&ze(e,t,o[t]);return e},T=(e,o)=>dt(e,ft(o));var R=(e,o)=>{var t={};for(var n in e)Ne.call(e,n)&&o.indexOf(n)<0&&(t[n]=e[n]);if(e!=null&&be)for(var n of be(e))o.indexOf(n)<0&&De.call(e,n)&&(t[n]=e[n]);return t};var bt=(e,o)=>{for(var t in o)le(e,t,{get:o[t],enumerable:!0})},Ae=(e,o,t,n)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of gt(o))!Ne.call(e,r)&&r!==t&&le(e,r,{get:()=>o[r],enumerable:!(n=pt(o,r))||n.enumerable});return e};var L=(e,o,t)=>(t=e!=null?ct(Ct(e)):{},Ae(o||!e||!e.__esModule?le(t,"default",{value:e,enumerable:!0}):t,e)),Et=e=>Ae(le({},"__esModule",{value:!0}),e);var Me=(e,o,t)=>new Promise((n,r)=>{var l=a=>{try{u(t.next(a))}catch(m){r(m)}},i=a=>{try{u(t.throw(a))}catch(m){r(m)}},u=a=>a.done?n(a.value):Promise.resolve(a.value).then(l,i);u((t=t.apply(e,o)).next())});var Ot={};bt(Ot,{Form:()=>Vt,useForm:()=>O});module.exports=Et(Ot);var Ke=require("@mobilestock-native/button");var ke=require("@unform/mobile"),D=require("react"),$e=require("zod"),Ue=require("@mobilestock-native/container"),Ge=require("@mobilestock-native/modalalert");var j=require("react/jsx-runtime"),Xe=(0,D.createContext)({});function O(){return(0,D.useContext)(Xe)}function We(r){var l=r,{children:e,onSubmit:o,schema:t}=l,n=R(l,["children","onSubmit","schema"]);let i=(0,D.useRef)(null),[u,a]=(0,D.useState)(!1),[m,c]=(0,D.useState)(void 0);function d(){var f;(f=i.current)==null||f.submitForm()}function g(){var f,s;(f=i.current)==null||f.setErrors({}),(s=i.current)==null||s.reset()}function C(f){let s={};for(let N of f){let z=N.path.filter(K=>typeof K=="string"||typeof K=="number").join(".");z&&(s[String(z)]=N.message)}return s}function y(f){if(f instanceof $e.ZodError)return C(f.issues);if(typeof f=="object"&&f!==null&&"errors"in f){let s=f.errors;if(Array.isArray(s)&&s.length>0&&"message"in s[0]&&"path"in s[0])return C(s)}return null}function I(N,z){return Me(this,arguments,function*(f,{reset:s}){var K,ae,Z,Q,ge;if((K=i.current)==null||K.setErrors({}),t){let x=t.safeParse(f);if(!x.success){(ae=i.current)==null||ae.setErrors(C(x.error.issues));return}}try{a(!0),yield o({data:f,ref:i,reset:s})}catch(x){let Ce=y(x);if(Ce)(Z=i.current)==null||Z.setErrors(Ce);else{let S="Erro ao realizar opera\xE7\xE3o",b=500;if(typeof x=="object"&&x!==null&&"isAxiosError"in x&&x.isAxiosError){let U=x;b=((Q=U.response)==null?void 0:Q.status)||500;let Y=(ge=U.response)==null?void 0:ge.data;Y!=null&&Y.message&&(S=Y.message)}else x instanceof Error&&(S=x.message||S);c({message:S,status:b})}}finally{a(!1)}})}return(0,j.jsxs)(Xe.Provider,{value:{formRef:i,submitForm:d,clearForm:g,loading:u},children:[(0,j.jsx)(ke.Form,T(p({ref:i,onSubmit:I},n),{children:(0,j.jsx)(Ue.Container.Vertical,{gap:"2XS",children:e})})),(0,j.jsx)(Ge.ModalAlert,{visible:!!m,message:m==null?void 0:m.message,type:m&&m.status>=500?"FATAL_ERROR":"ERROR_NOTICE",title:"Erro ao enviar o formul\xE1rio",onClose:()=>c(void 0)})]})}var Ye=require("react/jsx-runtime");function Ze(l){var i=l,{type:e="SUBMIT",disabled:o,isLoading:t,onPress:n}=i,r=R(i,["type","disabled","isLoading","onPress"]);let{submitForm:u,clearForm:a,loading:m}=O();function c(d){switch(e){case"SUBMIT":u();break;case"RESET":a();break;default:n==null||n(d)}}return(0,Ye.jsx)(Ke.Button,T(p({size:"LG"},r),{onPress:c,isLoading:e==="SUBMIT"&&m||t,disabled:m||t||o}))}var Re=L(require("styled-components/native")),ro=require("@mobilestock-native/badge"),no=require("@mobilestock-native/container"),io=L(require("@mobilestock-native/tools")),ao=require("@mobilestock-native/typography");var Je=require("@unform/core"),w=require("react"),je=require("react/jsx-runtime"),qe=(0,w.createContext)(void 0);function Qe(e){let{fieldName:o,registerField:t,error:n,defaultValue:r}=(0,Je.useField)(e.name),[l,i]=(0,w.useState)(0),u=(0,w.useCallback)(d=>{let g=d;return e.maxCount!==void 0&&g>e.maxCount&&(g=e.maxCount),e.minCount!==void 0&&g<e.minCount&&(g=e.minCount),g},[e.maxCount,e.minCount]),a=(0,w.useCallback)(d=>{var C;let g=u(d);i(g),(C=e.onChange)==null||C.call(e,{value:g,event:"EDIT"})},[u]);(0,w.useEffect)(()=>{t({name:o,getValue:()=>l,setValue:(d,g)=>a(g),clearValue:()=>a(0)})},[o,l,t,a]),(0,w.useEffect)(()=>{a(Number(e.initialCount)||Number(r)||0)},[e.initialCount,a,r]);function m(d=1){i(g=>{var y;let C=u(g+1*d);return(y=e.onChange)==null||y.call(e,{value:C,event:"INCREMENT"}),C})}function c(d=1){i(g=>{var y;let C=u(g-1*d);return(y=e.onChange)==null||y.call(e,{value:C,event:"DECREMENT"}),C})}return(0,je.jsx)(qe.Provider,{value:{count:l,increment:m,decrement:c,configureCount:a,multiplier:e.multiplier,maxCount:e.maxCount,minCount:e.minCount,editable:e.editable,label:e.label,labelPosition:e.labelPosition,buttonTransparent:e.buttonTransparent,groupElements:e.groupElements,error:n},children:e.children})}function H(){let e=(0,w.useContext)(qe);if(!e)throw new Error("useCounter must be used within a CounterProvider");return e}var eo=L(require("styled-components/native")),oo=require("@mobilestock-native/container");var to=require("react/jsx-runtime");function J(e){return(0,to.jsx)(Tt,p({align:"CENTER"},e))}var Tt=(0,eo.default)(oo.Container.Vertical)`
|
|
2
|
+
min-width: 40px;
|
|
3
|
+
height: 34px;
|
|
4
|
+
user-select: none;
|
|
5
|
+
`;var se=require("react/jsx-runtime");function ue(e){let{groupElements:o}=H();return(0,se.jsx)(J,{children:o&&e.renderInsidePill?(0,se.jsx)(ht,{$type:e.type,full:!0,align:"CENTER",children:(0,se.jsx)(St,{$type:e.type,children:e.text})}):(0,se.jsx)(ro.Badge,{text:e.text,type:e.type,size:"XS"})})}function lo(e,o){return Object.keys(o.colors.badge).find(t=>t.toLowerCase()===(e==null?void 0:e.toLowerCase()))||"default"}var ht=(0,Re.default)(no.Container.Vertical)`
|
|
6
|
+
background-color: ${({$type:e,theme:o})=>{let t=lo(e,o);return o.colors.badge[t]}};
|
|
7
|
+
width: 100%;
|
|
8
|
+
`,St=(0,Re.default)(ao.Typography)`
|
|
9
|
+
color: ${({$type:e,theme:o})=>{let t=lo(e,o);return io.default.defineTextColor(o.colors.badge[t])}};
|
|
10
|
+
`;ue.displayName="Form.FormCounter.Badge";var M=require("react"),B=require("@mobilestock-native/container"),go=L(require("@mobilestock-native/tools"));var me=L(require("styled-components/native")),so=require("@mobilestock-native/container");var uo=require("react/jsx-runtime");function ee(t){var n=t,{children:e}=n,o=R(n,["children"]);let{groupElements:r,error:l}=H();return(0,uo.jsx)(Pt,T(p({align:"CENTER",$groupElements:r,$error:!!l},o),{children:e}))}var Pt=(0,me.default)(so.Container.Horizontal)`
|
|
11
|
+
border-radius: ${({theme:e})=>e.borderRadius.default};
|
|
12
|
+
overflow: hidden;
|
|
13
|
+
background-color: transparent;
|
|
14
|
+
border: none;
|
|
15
|
+
${({$groupElements:e,theme:o})=>e&&me.css`
|
|
16
|
+
background-color: ${o.colors.input.default};
|
|
17
|
+
|
|
18
|
+
border: 1px solid ${o.colors.input.border};
|
|
19
|
+
`}
|
|
20
|
+
${({$error:e,theme:o})=>e&&me.css`
|
|
21
|
+
background-color: ${o.colors.input.error};
|
|
22
|
+
border: 1px solid ${o.colors.alert.urgent};
|
|
23
|
+
`}
|
|
24
|
+
`;var mo=require("@mobilestock-native/typography"),co=require("react/jsx-runtime");function A({children:e}){return(0,co.jsx)(mo.Typography,{color:"DANGER_600",size:"SM",weight:"MEDIUM",children:e})}var po=require("@mobilestock-native/typography"),fo=require("react/jsx-runtime");function G({children:e}){return(0,fo.jsx)(po.Typography,{weight:"REGULAR",children:e})}var h=require("react/jsx-runtime");function Co({children:e}){let{label:o,error:t,labelPosition:n}=H(),r=[],l=[],i=(0,M.useCallback)(a=>(0,M.isValidElement)(a)&&a.type===M.Fragment?i(a.props.children):a,[]),u=i(e);return M.Children.toArray(u).forEach(a=>{(0,M.isValidElement)(a)&&go.default.isComponentWithDisplayName(a.type)&&a.type.displayName===ue.displayName&&!a.props.renderInsidePill?r.push(a):l.push(a)}),(0,h.jsxs)(B.Container.Vertical,{align:"CENTER_START",children:[n==="TOP_START"&&o&&(0,h.jsxs)(B.Container.Horizontal,{padding:"NONE_NONE_2XS_NONE",gap:"2XS",children:[(0,h.jsx)(G,{children:o}),t&&!r.length&&(0,h.jsx)(A,{children:t})]}),n!=="LEFT"&&(0,h.jsxs)(B.Container.Vertical,{align:"CENTER",children:[(n!=="TOP_START"&&o||n!=="TOP_START"&&t&&!r.length)&&(0,h.jsxs)(B.Container.Vertical,{align:"CENTER",padding:"NONE_NONE_2XS_NONE",children:[o&&(0,h.jsx)(G,{children:o}),t&&!r.length&&(0,h.jsx)(A,{children:t})]}),(0,h.jsxs)(B.Container.Horizontal,{align:"CENTER_START",children:[r.length>0&&(0,h.jsx)(B.Container.Horizontal,{padding:"NONE_2XS_NONE_NONE",children:r}),(0,h.jsxs)(B.Container.Vertical,{children:[(0,h.jsx)(ee,{children:l}),t&&!!r.length&&(0,h.jsx)(A,{children:t})]})]})]}),n==="LEFT"&&(0,h.jsx)(B.Container.Vertical,{children:(0,h.jsxs)(B.Container.Horizontal,{align:"CENTER",children:[(0,h.jsxs)(B.Container.Vertical,{padding:"NONE_2XS_NONE_NONE",children:[o&&(0,h.jsx)(G,{children:o}),t&&!r.length&&(0,h.jsx)(A,{children:t})]}),r.length>0&&(0,h.jsx)(B.Container.Horizontal,{padding:"NONE_2XS_NONE_NONE",children:r}),(0,h.jsx)(ee,{children:l})]})})]})}var X=require("@mobilestock-native/container");var bo=require("react"),Eo=require("react-native"),To=L(require("styled-components/native")),ho=require("@mobilestock-native/button");var Ie=require("react/jsx-runtime");function k(n){var r=n,{type:e,disabled:o}=r,t=R(r,["type","disabled"]);let{loading:l}=O(),i=H(),u=(0,bo.useMemo)(()=>e==="PLUS"&&i.maxCount!==void 0?i.count>=i.maxCount:e==="MINUS"&&i.minCount!==void 0?i.count<=i.minCount:!1,[e,i.count,i.maxCount,i.minCount]);function a(){e==="PLUS"?i.increment():i.decrement()}function m(){Eo.Vibration.vibrate(50),e==="PLUS"?i.increment(i.multiplier):i.decrement(i.multiplier)}return(0,Ie.jsx)(J,{children:(0,Ie.jsx)(yt,T(p({backgroundColor:e==="PLUS"?"DEFAULT_DARK":"CANCEL_DARK"},t),{size:"SM",icon:e==="PLUS"?"Plus":"Minus",variant:i.buttonTransparent?"TRANSPARENT":"DEFAULT",$grouped:i.groupElements,disabled:u||o||l,onPress:a,onLongPress:m,delayLongPress:500}))})}var yt=(0,To.default)(ho.Button)`
|
|
25
|
+
border-radius: ${({$grouped:e,theme:o})=>e?o.borderRadius.none:o.borderRadius.default};
|
|
26
|
+
`;var ce=require("react"),So=require("react-native"),Po=require("styled-components/native"),yo=require("@mobilestock-native/clickable"),ve=require("@mobilestock-native/container"),xe=require("@mobilestock-native/typography");var $=require("react/jsx-runtime");function oe(){let e=(0,Po.useTheme)(),{count:o,editable:t,configureCount:n}=H(),[r,l]=(0,ce.useState)(!1),[i,u]=(0,ce.useState)(o.toString());(0,ce.useEffect)(()=>{u(o.toString())},[o]);function a(m){n(Number(m.nativeEvent.text)||0),l(!1)}return t?(0,$.jsx)(yo.Clickable,{onPress:()=>l(!0),children:(0,$.jsx)(ve.Container.Horizontal,{padding:"NONE_2XS",children:(0,$.jsx)(J,{children:r?(0,$.jsx)(So.TextInput,{testID:"counter-input",value:i,keyboardType:"numeric",style:{fontWeight:"bold",fontSize:Number(e.font.size.lg)||16,textAlign:"center",width:40,height:40},autoFocus:!0,selectTextOnFocus:!0,onBlur:a,onChangeText:u,onEndEditing:a}):(0,$.jsx)(xe.Typography,{weight:"BOLD",size:"LG",children:o})})})}):(0,$.jsx)(ve.Container.Horizontal,{padding:"NONE_2XS",children:(0,$.jsx)(J,{children:(0,$.jsx)(xe.Typography,{weight:"BOLD",size:"LG",children:o})})})}oe.displayName="Form.FormCounter.Display";var E=require("react/jsx-runtime");function No(){let{label:e,labelPosition:o,error:t}=H();return(0,E.jsxs)(X.Container.Vertical,{align:"CENTER_START",children:[o==="TOP_START"&&e&&(0,E.jsxs)(X.Container.Horizontal,{padding:"NONE_NONE_2XS_NONE",gap:"2XS",children:[(0,E.jsx)(G,{children:e}),t&&(0,E.jsx)(A,{children:t})]}),o!=="LEFT"&&(0,E.jsxs)(X.Container.Vertical,{align:"CENTER",children:[o!=="TOP_START"&&(e||t)&&(0,E.jsxs)(X.Container.Vertical,{align:"CENTER",padding:"NONE_NONE_2XS_NONE",children:[e&&(0,E.jsx)(G,{children:e}),t&&(0,E.jsx)(A,{children:t})]}),(0,E.jsxs)(ee,{children:[(0,E.jsx)(k,{type:"MINUS"}),(0,E.jsx)(oe,{}),(0,E.jsx)(k,{type:"PLUS"})]})]}),o==="LEFT"&&(0,E.jsx)(X.Container.Vertical,{children:(0,E.jsxs)(X.Container.Horizontal,{align:"CENTER",children:[(e||t)&&(0,E.jsxs)(X.Container.Vertical,{padding:"NONE_2XS_NONE_NONE",children:[e&&(0,E.jsx)(G,{children:e}),t&&(0,E.jsx)(A,{children:t})]}),(0,E.jsxs)(ee,{children:[(0,E.jsx)(k,{type:"MINUS"}),(0,E.jsx)(oe,{}),(0,E.jsx)(k,{type:"PLUS"})]})]})})]})}var Ee=require("react/jsx-runtime");function Ro(t){var n=t,{children:e}=n,o=R(n,["children"]);return(0,Ee.jsx)(Qe,T(p({buttonTransparent:!1,labelPosition:"TOP_START",multiplier:1},o),{children:e?(0,Ee.jsx)(Co,{children:e}):(0,Ee.jsx)(No,{})}))}var Io=require("react/jsx-runtime");function Fe(e){return(0,Io.jsx)(k,T(p({},e),{type:"MINUS"}))}Fe.displayName="Form.FormCounter.Minus";var vo=require("react/jsx-runtime");function Ve(e){return(0,vo.jsx)(k,T(p({},e),{type:"PLUS"}))}Ve.displayName="Form.FormCounter.Plus";var xo=Object.assign(Ro,{Display:oe,Plus:Ve,Minus:Fe,Badge:ue});var Fo=require("@mobilestock-native/container");var Oo=require("react/jsx-runtime");function Vo(t){var n=t,{children:e}=n,o=R(n,["children"]);return(0,Oo.jsx)(Fo.Container.Horizontal,T(p({gap:"SM"},o),{children:e}))}var wo=require("@unform/core"),v=require("react"),Ho=require("react-native"),te=L(require("styled-components/native")),Bo=require("@mobilestock-native/button"),He=require("@mobilestock-native/container"),Oe=L(require("@mobilestock-native/tools")),we=require("@mobilestock-native/typography");var W=require("react/jsx-runtime"),Lo=(0,v.forwardRef)(function(C,g){var y=C,{name:o,label:t,defaultValue:n,type:r="text",autoSubmit:l=!1,format:i,onChangeText:u,autoCapitalize:a,full:m,maxLength:c}=y,d=R(y,["name","label","defaultValue","type","autoSubmit","format","onChangeText","autoCapitalize","full","maxLength"]);let{loading:I,submitForm:f}=O(),s=(0,wo.useField)(o),N=(0,v.useRef)(null),[z,K]=(0,v.useState)(!0),[ae,Z]=(0,v.useState)(""),Q=r==="password",ge=r==="tel"?15:r==="zipcode"?9:c;(0,v.useEffect)(()=>{let S=ae||n||(s==null?void 0:s.defaultValue)||"";N.current.value=S,Z(S),s.registerField({name:s.fieldName,ref:N.current,getValue(b){return(b==null?void 0:b.value)||""},setValue(b,U){b.value=U,Z(U)},clearValue(b){b.value="",Z("")}})},[s==null?void 0:s.fieldName,s==null?void 0:s.registerField]),(0,v.useImperativeHandle)(g,()=>({focus(){var S;(S=N.current)==null||S.focus()},blur(){var S;(S=N.current)==null||S.blur()}}));let x=(0,v.useCallback)(S=>{var U,Y;let b=S;switch(r){case"tel":b=Oe.default.phoneNumberFormatter(S);break;case"email":case"url":b=S.trim();break;case"number":b=S.replace(/[^0-9.,]/g,"");break;case"zipcode":b=Oe.default.formatZipcode(b);break}i&&(b=i(b)),Z(b),N.current.value=b,u==null||u(b),r==="tel"&&l&&b.length===15&&((U=N.current)==null||U.blur(),f()),r==="zipcode"&&l&&b.length===9&&((Y=N.current)==null||Y.blur(),f())},[r,i,l,u,s]),Ce=(0,v.useCallback)(()=>{switch(r){case"tel":return"phone-pad";case"email":return"email-address";case"url":return"url";case"number":return"numeric";default:return"default"}},[r]);return(0,W.jsxs)(Nt,{full:m,$show:r!=="hidden",children:[t&&(0,W.jsx)(we.Typography,{children:t}),(0,W.jsxs)(Rt,{error:!!(s!=null&&s.error),$isPassword:Q,children:[(0,W.jsx)(It,T(p({},d),{ref:N,value:ae,autoCapitalize:r&&["email","url"].includes(r)?"none":a,keyboardType:Ce(),secureTextEntry:z&&Q,onChangeText:x,maxLength:ge,editable:!I&&d.editable})),Q&&(0,W.jsx)(Bo.Button,{size:"SM",onPress:()=>K(!z),icon:z?"EyeOff":"EyeOutline",variant:"TRANSPARENT"})]}),(s==null?void 0:s.error)&&(0,W.jsx)(we.Typography,{color:"DANGER",size:"SM",children:s.error})]})}),Nt=(0,te.default)(He.Container.Vertical)`
|
|
27
|
+
${({$show:e})=>!e&&te.css`
|
|
3
28
|
display: none;
|
|
4
29
|
`}
|
|
5
|
-
`,
|
|
30
|
+
`,Rt=(0,te.default)(He.Container.Horizontal)`
|
|
6
31
|
overflow: hidden;
|
|
7
32
|
background-color: ${({error:e,theme:o})=>e?o.colors.input.error:o.colors.input.default};
|
|
8
33
|
border: 1px solid ${({error:e,theme:o})=>e?o.colors.alert.urgent:o.colors.input.border};
|
|
9
34
|
border-radius: ${({theme:e})=>e.borderRadius.default};
|
|
10
35
|
padding: ${({$isPassword:e})=>e?"0 0 0 10px":"0 10px"};
|
|
11
|
-
`,
|
|
36
|
+
`,It=(0,te.default)(Ho.TextInput)`
|
|
12
37
|
flex: 1;
|
|
13
38
|
height: 45px;
|
|
14
39
|
color: ${({theme:e})=>e.colors.text.default};
|
|
15
|
-
`;var
|
|
40
|
+
`;var nt=require("@unform/core"),it=require("react-native"),at=require("@mobilestock-native/container"),_e=require("@mobilestock-native/typography");var Ko=require("@unform/core"),de=require("react"),fe=L(require("styled-components/native")),Zo=require("@mobilestock-native/clickable"),pe=require("@mobilestock-native/container"),Yo=require("@mobilestock-native/icons"),Jo=require("@mobilestock-native/typography");var Go=require("react"),ne=require("react-native"),ye=require("react-native-gesture-handler"),P=L(require("react-native-reanimated")),Xo=require("styled-components/native"),Se=require("@mobilestock-native/container"),Pe=require("@mobilestock-native/list");var $o=require("react-native-gesture-handler"),re=require("@mobilestock-native/container");var _o=require("styled-components/native"),zo=require("@mobilestock-native/container");var Ao=require("react/jsx-runtime");function Do(e){let o=(0,_o.useTheme)();return(0,Ao.jsx)(zo.Container.Horizontal,p({style:{width:100,height:4,borderRadius:5,backgroundColor:o.colors.container.shadow}},e))}var Mo=require("@mobilestock-native/typography");var ko=require("react/jsx-runtime");function Be(e){return(0,ko.jsx)(Mo.Typography,p({size:"MD",align:"RIGHT",color:"DEFAULT_100"},e))}var _=require("react/jsx-runtime");function Uo({placeholder:e,panGesture:o}){return o?(0,_.jsx)($o.GestureDetector,{gesture:o,children:(0,_.jsxs)(re.Container.Vertical,{padding:"XS",testID:"form-sheet-header-with-gesture",children:[(0,_.jsx)(re.Container.Horizontal,{align:"CENTER",children:(0,_.jsx)(Do,{})}),(0,_.jsx)(re.Container.Horizontal,{children:(0,_.jsx)(Be,{children:e})})]})}):(0,_.jsx)(re.Container.Vertical,{padding:"XS",testID:"form-sheet-header-without-gesture",children:(0,_.jsx)(re.Container.Horizontal,{children:(0,_.jsx)(Be,{children:e})})})}var F=require("react/jsx-runtime"),{height:vt}=ne.Dimensions.get("window"),Le=vt*.8,Te=200,he=45;function Wo(e){let o=(0,Xo.useTheme)(),t=(0,Go.useMemo)(()=>Math.min(Le,e.options.length*he+he),[e.options]),n=Math.min(Te,t),r=(0,P.useSharedValue)(n),l=(0,P.useSharedValue)(n),i=ye.Gesture.Pan().onStart(()=>{l.value=r.value}).onUpdate(c=>{let d=l.value-c.translationY;r.value=Math.max(Te,Math.min(d,t))}).onEnd(c=>{c.velocityY<-1e3?r.value=(0,P.withTiming)(t):r.value>Le/2?r.value=(0,P.withTiming)(Le):r.value=(0,P.withTiming)(Te)}),u=(0,P.useAnimatedStyle)(()=>({height:r.value,bottom:0}));(0,P.useAnimatedReaction)(()=>e.visible,c=>{c&&(r.value=(0,P.withSpring)(n,{damping:20,stiffness:90,mass:.3}))},[e.visible]);function a(){"worklet";r.value=(0,P.withTiming)(0,{},()=>{(0,P.runOnJS)(e.onClose)()})}function m(c){var d;e.onSelect(c.value===((d=e.selectValue)==null?void 0:d.value)?null:c),a()}return(0,F.jsx)(ne.Modal,{visible:e.visible,transparent:!0,animationType:"none",testID:"modal",children:(0,F.jsxs)(ye.GestureHandlerRootView,{children:[(0,F.jsx)(ne.TouchableWithoutFeedback,{onPress:a,testID:"backdrop",children:(0,F.jsx)(Se.Container.Vertical,{full:!0})}),(0,F.jsxs)(P.default.View,{style:[u,{position:"absolute",width:"100%",backgroundColor:o.colors.container.default,borderTopLeftRadius:20,borderTopRightRadius:20,borderWidth:1,borderColor:o.colors.container.shadow}],children:[(0,F.jsx)(Uo,{placeholder:e.placeholder,panGesture:e.options.length*he+he>Te?i:void 0}),(0,F.jsx)(Se.Container.Main,{children:(0,F.jsx)(Pe.List,{data:e.options,itemKey:"value",ItemSeparatorComponent:()=>(0,F.jsx)(Se.Container.Horizontal,{testID:"separator",style:{backgroundColor:o.colors.container.shadow,height:1,width:"100%"}}),renderItem:c=>{var d;return(0,F.jsx)(Pe.List.Item.Horizontal,{isSelected:((d=e.selectValue)==null?void 0:d.value)===c.value,padding:"SM",onPress:()=>m(c),children:(0,F.jsx)(Pe.List.Item.Title,{children:c.label})})}})})]})]})})}var V=require("react/jsx-runtime");function qo({options:e,placeholder:o,disabled:t,defaultValue:n,name:r}){let l=(0,fe.useTheme)(),{loading:i}=O(),{fieldName:u,registerField:a,error:m,defaultValue:c}=(0,Ko.useField)(r),[d,g]=(0,de.useState)(!1),[C,y]=(0,de.useState)(c||n||null);return(0,de.useEffect)(()=>{a({name:u,getValue:()=>(C==null?void 0:C.value)||"",setValue:(I,f)=>{let s=e.find(N=>N.value===f);s&&y(s)},clearValue:()=>{y(null)}})},[u,a,C,e]),(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Zo.Clickable,{disabled:t||i,onPress:()=>g(!0),testID:"select-android",children:(0,V.jsxs)(xt,{padding:"NONE_XS_NONE_MD",error:!!m,testID:"select-android-container",align:"BETWEEN_CENTER",children:[(0,V.jsx)(pe.Container.Horizontal,{children:(0,V.jsx)(Jo.Typography,{color:C?"DEFAULT":"DEFAULT_200",children:(C==null?void 0:C.label)||o})}),(0,V.jsxs)(pe.Container.Horizontal,{style:{opacity:.3},gap:"XS",align:"CENTER",children:[(0,V.jsx)(Ft,{error:!!m}),(0,V.jsx)(Yo.Icon,{name:"ChevronDown",size:"XS",color:m?l.colors.alert.urgent:l.colors.text.default})]})]})}),!t&&!i&&(0,V.jsx)(Wo,{options:e,onClose:()=>g(!1),visible:d,placeholder:o,selectValue:C,onSelect:I=>{y(I)}})]})}var xt=(0,fe.default)(pe.Container.Horizontal)`
|
|
16
41
|
overflow: hidden;
|
|
17
42
|
height: 47px;
|
|
18
43
|
background-color: ${({error:e,theme:o})=>e?o.colors.input.error:o.colors.input.default};
|
|
19
44
|
border: 1px solid ${({error:e,theme:o})=>e?o.colors.alert.urgent:o.colors.input.border};
|
|
20
45
|
border-radius: 5px;
|
|
21
|
-
`,
|
|
46
|
+
`,Ft=(0,fe.default)(pe.Container.Vertical)`
|
|
22
47
|
width: 1px;
|
|
23
48
|
height: 30px;
|
|
24
49
|
background-color: ${({theme:e,error:o})=>o?e.colors.alert.urgent:e.colors.text.default};
|
|
25
|
-
`;var
|
|
50
|
+
`;var Qo=require("@unform/core"),jo=require("lodash"),ie=require("react"),et=L(require("react-select")),ot=require("styled-components");var rt=require("react/jsx-runtime");function tt({options:e,placeholder:o,disabled:t,name:n,defaultValue:r}){var C,y;let l=(0,ot.useTheme)(),{loading:i}=O(),{fieldName:u,defaultValue:a,registerField:m,error:c}=(0,Qo.useField)(n),d=(0,ie.useRef)(null);(0,ie.useEffect)(()=>{m({name:u,ref:d.current,getValue:I=>{var s,N,z;return((z=(N=(s=I==null?void 0:I.state)==null?void 0:s.selectValue)==null?void 0:N[0])==null?void 0:z.value)||""}})},[u,m]);let g=(0,ie.useCallback)(I=>function(f){return(0,jo.mergeWith)(f,I)},[]);return(0,rt.jsx)(et.default,{options:[{label:o,options:e}],placeholder:o,defaultInputValue:(y=(C=r==null?void 0:r.label)!=null?C:a==null?void 0:a.label)!=null?y:void 0,menuPortalTarget:typeof document!="undefined"?document.body:void 0,menuPosition:"fixed",styles:{container:g({width:"100%",display:"flex",height:"3rem"}),control:g({width:"100%",backgroundColor:c?l.colors.input.error:void 0,borderColor:c?l.colors.alert.urgent:void 0}),indicatorSeparator:g({backgroundColor:c?l.colors.alert.urgent:void 0}),dropdownIndicator:g({color:c?l.colors.alert.urgent:void 0}),option:(I,f)=>T(p({},I),{backgroundColor:f.isSelected?l.colors.listItem.selected:l.colors.listItem.default})},defaultValue:r,ref:d,isDisabled:t||i})}var q=require("react/jsx-runtime");function lt({name:e,label:o,disabled:t=!1,options:n,placeholder:r="Selecione um item",full:l=!1,defaultValue:i}){let{error:u}=(0,nt.useField)(e);return(0,q.jsxs)(at.Container.Vertical,{full:l,children:[o&&(0,q.jsx)(_e.Typography,{testID:"label",children:o}),it.Platform.OS==="web"?(0,q.jsx)(tt,{disabled:t,options:n,name:e,defaultValue:i,placeholder:r}):(0,q.jsx)(qo,{name:e,disabled:t,options:n,defaultValue:i,placeholder:r}),u&&(0,q.jsx)(_e.Typography,{color:"DANGER",size:"SM",testID:"error",children:u})]})}var st=require("@mobilestock-native/container");var mt=require("react/jsx-runtime");function ut(t){var n=t,{children:e}=n,o=R(n,["children"]);return(0,mt.jsx)(st.Container.Vertical,T(p({gap:"SM"},o),{children:e}))}var Vt=Object.assign(We,{Input:Lo,Button:Ze,Select:lt,Counter:xo,Vertical:ut,Horizontal:Vo});0&&(module.exports={Form,useForm});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mobilestock-native/form",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"lodash": "^4.17.14",
|
|
@@ -8,13 +8,14 @@
|
|
|
8
8
|
"react-select": "5.10.1",
|
|
9
9
|
"@unform/mobile": "^2.1.6",
|
|
10
10
|
"@mobilestock-native/button": "^1.0.11",
|
|
11
|
+
"@mobilestock-native/badge": "^0.0.6",
|
|
11
12
|
"@mobilestock-native/container": "^0.1.0",
|
|
12
13
|
"@mobilestock-native/icons": "^0.0.6",
|
|
13
|
-
"@mobilestock-native/modalalert": "^0.0.13",
|
|
14
14
|
"@mobilestock-native/tools": "^0.0.10",
|
|
15
15
|
"@mobilestock-native/typography": "^0.0.9",
|
|
16
16
|
"@mobilestock-native/clickable": "^1.0.6",
|
|
17
|
-
"@mobilestock-native/list": "^0.0.8"
|
|
17
|
+
"@mobilestock-native/list": "^0.0.8",
|
|
18
|
+
"@mobilestock-native/modalalert": "^0.0.13"
|
|
18
19
|
},
|
|
19
20
|
"devDependencies": {
|
|
20
21
|
"@types/lodash": "^4.17.14",
|