@mobilestock-native/search 0.0.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.
Files changed (3) hide show
  1. package/index.d.ts +12 -0
  2. package/index.js +21 -0
  3. package/package.json +17 -0
package/index.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { TextInputProps } from 'react-native';
3
+
4
+ interface SearchProps extends TextInputProps {
5
+ fetchSuggestions(query: string): Promise<string[]> | string[];
6
+ onSearch(query: string): void;
7
+ placeholder?: string;
8
+ isLoading?: boolean;
9
+ }
10
+ declare function Search({ placeholder, fetchSuggestions, onSearch, isLoading, ...rest }: SearchProps): react_jsx_runtime.JSX.Element;
11
+
12
+ export { Search, type SearchProps };
package/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";var F=Object.create;var m=Object.defineProperty,W=Object.defineProperties,A=Object.getOwnPropertyDescriptor,K=Object.getOwnPropertyDescriptors,U=Object.getOwnPropertyNames,h=Object.getOwnPropertySymbols,_=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty,E=Object.prototype.propertyIsEnumerable;var z=(t,e,o)=>e in t?m(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,L=(t,e)=>{for(var o in e||(e={}))I.call(e,o)&&z(t,o,e[o]);if(h)for(var o of h(e))E.call(e,o)&&z(t,o,e[o]);return t},$=(t,e)=>W(t,K(e));var w=(t,e)=>{var o={};for(var r in t)I.call(t,r)&&e.indexOf(r)<0&&(o[r]=t[r]);if(t!=null&&h)for(var r of h(t))e.indexOf(r)<0&&E.call(t,r)&&(o[r]=t[r]);return o};var G=(t,e)=>{for(var o in e)m(t,o,{get:e[o],enumerable:!0})},H=(t,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of U(e))!I.call(t,a)&&a!==o&&m(t,a,{get:()=>e[a],enumerable:!(r=A(e,a))||r.enumerable});return t};var P=(t,e,o)=>(o=t!=null?F(_(t)):{},H(e||!t||!t.__esModule?m(o,"default",{value:t,enumerable:!0}):o,t)),J=t=>H(m({},"__esModule",{value:!0}),t);var y=(t,e,o)=>new Promise((r,a)=>{var T=i=>{try{l(o.next(i))}catch(c){a(c)}},f=i=>{try{l(o.throw(i))}catch(c){a(c)}},l=i=>i.done?r(i.value):Promise.resolve(i.value).then(T,f);l((o=o.apply(t,e)).next())});var tt={};G(tt,{Search:()=>Q});module.exports=J(tt);var u=require("react"),D=require("react-native"),p=P(require("styled-components/native")),M=require("@mobilestock-native/button"),S=require("@mobilestock-native/container"),g=require("@mobilestock-native/list"),R=P(require("@mobilestock-native/tools"));var s=require("react/jsx-runtime");function Q(T){var f=T,{placeholder:t="ID, Nome e/ou tamanho do produto",fetchSuggestions:e,onSearch:o,isLoading:r=!1}=f,a=w(f,["placeholder","fetchSuggestions","onSearch","isLoading"]);let l=(0,u.useRef)(!1),[i,c]=(0,u.useState)(""),[v,N]=(0,u.useState)([]),[k,x]=(0,u.useState)(!1),C=3,V=500;(0,u.useEffect)(()=>{if(l.current){l.current=!1;return}let n=setTimeout(O,V);return()=>clearTimeout(n)},[i]);function O(){return y(this,null,function*(){let n=i.trim();if(n.length<C){x(!1);return}let d=yield e(n);N(d),x(!0)})}function b(n){let d=n.trim();d.length>=C&&(x(!1),o(d))}function q(n){l.current=!0,c(n),b(n)}let B=(0,u.useCallback)(n=>{c(n)},[]);return(0,s.jsxs)(X,{children:[(0,s.jsxs)(Y,{align:"CENTER",overflow:"HIDDEN",children:[(0,s.jsx)(Z,$(L({},a),{value:i,onChangeText:B,placeholder:t,onSubmitEditing:()=>b(i)})),(0,s.jsx)(j,{icon:"Search",size:"SM",backgroundColor:"DEFAULT",onPress:()=>b(i),isLoading:r})]}),k&&(0,s.jsx)(S.Container.Horizontal,{children:(0,s.jsx)(g.List,{data:v,renderItem:n=>(0,s.jsx)(g.List.Item.Horizontal,{padding:"SM",onPress:()=>q(n),children:(0,s.jsx)(g.List.Item.Text,{children:n})}),itemKey:(n,d)=>`${n}-${d}`,isLoading:r,whenEmptyList:(0,s.jsx)(g.List.Item.Horizontal,{padding:"MD_SM",align:"CENTER",children:(0,s.jsx)(g.List.Item.Text,{size:"MD",children:"Nenhum resultado encontrado"})})})})]})}var X=p.default.View`
2
+ border-radius: ${({theme:t})=>t.borderRadius.default};
3
+ background-color: ${({theme:t})=>t.colors.container.default};
4
+ elevation: 5;
5
+ `,Y=(0,p.default)(S.Container.Horizontal)`
6
+ width: 100%;
7
+ height: 40px;
8
+ border-radius: ${({theme:t})=>t.borderRadius.default};
9
+ `,Z=(0,p.default)(D.TextInput).attrs(({theme:t})=>({placeholderTextColor:t.colors.text.default}))`
10
+ flex: 1;
11
+ padding: 0 16px;
12
+ height: 100%;
13
+ background-color: ${({theme:t})=>t.colors.input.default};
14
+ font-size: ${({theme:t})=>t.font.size.md}px;
15
+ color: ${({theme:t})=>R.default.defineTextColor(t.colors.input.default)};
16
+ border-width: 0;
17
+ `,j=(0,p.default)(M.Button)`
18
+ height: 100%;
19
+ width: 64px;
20
+ border-radius: ${({theme:t})=>t.borderRadius.none};
21
+ `;0&&(module.exports={Search});
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@mobilestock-native/search",
3
+ "version": "0.0.1",
4
+ "main": "index.js",
5
+ "peerDependencies": {
6
+ "react": "18.2.0",
7
+ "react-dom": "18.2.0",
8
+ "styled-components": "^6.1.8",
9
+ "react-native": "0.74.5"
10
+ },
11
+ "dependencies": {
12
+ "@mobilestock-native/button": "^1.0.9",
13
+ "@mobilestock-native/container": "^0.0.4",
14
+ "@mobilestock-native/list": "^0.0.4",
15
+ "@mobilestock-native/tools": "^0.0.9"
16
+ }
17
+ }