@mobilestock-native/drawer 0.1.0 → 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 +22 -3
- package/index.js +8 -7
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -69,6 +69,7 @@ interface DrawerCompactItemProps extends Omit<ClickableProps, 'children' | 'acce
|
|
|
69
69
|
*/
|
|
70
70
|
declare function CompactItem({ icon, accessibilityLabel, label, active, color, badge, size, onHoverIn, onHoverOut, onFocus, onBlur, onPressIn, onLongPress, ...props }: DrawerCompactItemProps): react_jsx_runtime.JSX.Element;
|
|
71
71
|
|
|
72
|
+
type DrawerFooterSize = 'MD' | 'SM';
|
|
72
73
|
interface DrawerFooterProps {
|
|
73
74
|
children: ReactNode;
|
|
74
75
|
/**
|
|
@@ -77,12 +78,19 @@ interface DrawerFooterProps {
|
|
|
77
78
|
* @example compact
|
|
78
79
|
*/
|
|
79
80
|
compact?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* @description Vertical padding for the size of the items inside: `MD` for the 48px compact item or the 44px row,
|
|
83
|
+
* `SM` for the 40px compact item or the 36px row, which lines the footer up with a 49px bottom tab bar.
|
|
84
|
+
* Default: 'MD'
|
|
85
|
+
* @example size="SM"
|
|
86
|
+
*/
|
|
87
|
+
size?: DrawerFooterSize;
|
|
80
88
|
}
|
|
81
89
|
/**
|
|
82
90
|
* @description Bottom area of the side menu, under the scrolling entries: a hairline on top, in the divider color of
|
|
83
91
|
* the drawer, and the padding of the menu. Holds the logout (and the login of a visitor).
|
|
84
92
|
*/
|
|
85
|
-
declare function Footer({ children, compact }: DrawerFooterProps): react_jsx_runtime.JSX.Element;
|
|
93
|
+
declare function Footer({ children, compact, size }: DrawerFooterProps): react_jsx_runtime.JSX.Element;
|
|
86
94
|
|
|
87
95
|
/**
|
|
88
96
|
* @description Color of the icon and the label of an item: `DEFAULT` is the text color, `SELECTED` is the active
|
|
@@ -90,6 +98,10 @@ declare function Footer({ children, compact }: DrawerFooterProps): react_jsx_run
|
|
|
90
98
|
*/
|
|
91
99
|
type DrawerItemColor = 'DEFAULT' | 'SELECTED' | 'DANGER';
|
|
92
100
|
|
|
101
|
+
/**
|
|
102
|
+
* @description Size of the item: `MD` the 44px row, `SM` the 36px row with a smaller label.
|
|
103
|
+
*/
|
|
104
|
+
type DrawerItemSize = 'MD' | 'SM';
|
|
93
105
|
interface DrawerItemProps extends Omit<ClickableProps, 'children'> {
|
|
94
106
|
/**
|
|
95
107
|
* @description Text of the item. It is also the accessibility label, unless `accessibilityLabel` is given.
|
|
@@ -130,12 +142,19 @@ interface DrawerItemProps extends Omit<ClickableProps, 'children'> {
|
|
|
130
142
|
* @example href="https://necso.com.br/conta"
|
|
131
143
|
*/
|
|
132
144
|
href?: string;
|
|
145
|
+
/**
|
|
146
|
+
* @description `MD` is the 44px row with the small label; `SM` the 36px row with the extra-small label, for a
|
|
147
|
+
* denser menu (a phone).
|
|
148
|
+
* Default: 'MD'
|
|
149
|
+
* @example size="SM"
|
|
150
|
+
*/
|
|
151
|
+
size?: DrawerItemSize;
|
|
133
152
|
}
|
|
134
153
|
/**
|
|
135
154
|
* @description One row of the expanded side menu: icon, label and an optional trailing element, with a touch height
|
|
136
155
|
* of at least 44px and the radius of the theme. `active` tints the row with the active colors of the drawer.
|
|
137
156
|
*/
|
|
138
|
-
declare function Item({ label, icon, color, active, trailing, href, accessibilityLabel, ...props }: DrawerItemProps): react_jsx_runtime.JSX.Element;
|
|
157
|
+
declare function Item({ label, icon, color, active, trailing, href, accessibilityLabel, size, ...props }: DrawerItemProps): react_jsx_runtime.JSX.Element;
|
|
139
158
|
|
|
140
159
|
/**
|
|
141
160
|
* @description Box of the item (or divider) a floating label names, in window coordinates.
|
|
@@ -244,4 +263,4 @@ declare const Drawer: {
|
|
|
244
263
|
Footer: typeof Footer;
|
|
245
264
|
};
|
|
246
265
|
|
|
247
|
-
export { Drawer, type DrawerCompactItemColor, type DrawerCompactItemProps, type DrawerCompactItemSize, type DrawerFooterProps, type DrawerItemColor, type DrawerItemProps, type DrawerRootProps, type DrawerSectionTitleProps, type DrawerSide, type FloatingLabelRequest, HOVER_EXPAND_DELAY_IN_MILLISECONDS };
|
|
266
|
+
export { Drawer, type DrawerCompactItemColor, type DrawerCompactItemProps, type DrawerCompactItemSize, type DrawerFooterProps, type DrawerFooterSize, type DrawerItemColor, type DrawerItemProps, type DrawerItemSize, type DrawerRootProps, type DrawerSectionTitleProps, type DrawerSide, type FloatingLabelRequest, HOVER_EXPAND_DELAY_IN_MILLISECONDS };
|
package/index.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
"use strict";var Ye=Object.create;var
|
|
1
|
+
"use strict";var Ye=Object.create;var N=Object.defineProperty,Ze=Object.defineProperties,qe=Object.getOwnPropertyDescriptor,Je=Object.getOwnPropertyDescriptors,Qe=Object.getOwnPropertyNames,V=Object.getOwnPropertySymbols,je=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty,ce=Object.prototype.propertyIsEnumerable;var le=(e,t,r)=>t in e?N(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,F=(e,t)=>{for(var r in t||(t={}))j.call(t,r)&&le(e,r,t[r]);if(V)for(var r of V(t))ce.call(t,r)&&le(e,r,t[r]);return e},X=(e,t)=>Ze(e,Je(t));var z=(e,t)=>{var r={};for(var o in e)j.call(e,o)&&t.indexOf(o)<0&&(r[o]=e[o]);if(e!=null&&V)for(var o of V(e))t.indexOf(o)<0&&ce.call(e,o)&&(r[o]=e[o]);return r};var et=(e,t)=>{for(var r in t)N(e,r,{get:t[r],enumerable:!0})},se=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Qe(t))!j.call(e,n)&&n!==r&&N(e,n,{get:()=>t[n],enumerable:!(o=qe(t,n))||o.enumerable});return e};var $=(e,t,r)=>(r=e!=null?Ye(je(e)):{},se(t||!e||!e.__esModule?N(r,"default",{value:e,enumerable:!0}):r,e)),tt=e=>se(N({},"__esModule",{value:!0}),e);var Dt={};et(Dt,{Drawer:()=>It,HOVER_EXPAND_DELAY_IN_MILLISECONDS:()=>re});module.exports=tt(Dt);var S=require("react"),x=require("react-native"),De=require("styled-components/native"),Se=require("@mobilestock-native/badge"),Ee=require("@mobilestock-native/clickable"),Le=require("@mobilestock-native/icons");function U(e,t,r){return r||t==="SELECTED"?e.colors.drawer.activeForeground:t==="DANGER"?e.colors.text.danger:e.colors.text.default}function W(e){var t;return(t=e.colors.listItem)==null?void 0:t.hover}var de=require("react-native");function T(e,t){if(!e)return;let r=e;if(de.Platform.OS==="web"&&typeof r.getBoundingClientRect=="function"){let o=r.getBoundingClientRect();t(o.left,o.top,o.width,o.height);return}e.measureInWindow(t)}var ue=require("react-native"),te=$(require("styled-components/native")),me=require("@mobilestock-native/typography"),ee=require("react/jsx-runtime"),A=28,P=12;function K({text:e,visible:t,top:r,left:o,right:n}){if(!t)return null;let c={position:ue.Platform.OS==="web"?"fixed":"absolute",top:r,left:o,right:n};return(0,ee.jsx)(rt,{pointerEvents:"none",accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",style:c,testID:"drawer-floating-label",children:(0,ee.jsx)(ot,{size:"XS",weight:"MEDIUM",withEllipsis:!0,children:e})})}var rt=te.default.View`
|
|
2
2
|
z-index: 1000;
|
|
3
|
-
height: ${
|
|
3
|
+
height: ${A}px;
|
|
4
4
|
justify-content: center;
|
|
5
5
|
padding: 0 ${({theme:e})=>e.spacing.xs};
|
|
6
6
|
border-radius: ${({theme:e})=>e.borderRadius.default};
|
|
7
7
|
background-color: ${({theme:e})=>e.colors.drawer.labelBackground};
|
|
8
|
-
`,ot=(0,
|
|
8
|
+
`,ot=(0,te.default)(me.Typography)`
|
|
9
9
|
color: ${({theme:e})=>e.colors.drawer.labelText};
|
|
10
|
-
`;var
|
|
10
|
+
`;var d=require("react"),D=require("react-native"),pe=require("styled-components/native");var M=require("react/jsx-runtime"),be=(0,d.createContext)(null);function Y(){return(0,d.useContext)(be)}var re=400,nt='[data-testid="drawer-compact-item"], [data-testid="drawer-item"]';function it(e,t){var n;if(e.key==="Escape"){t.hideLabel(),(n=t.onEscape)==null||n.call(t);return}if(e.key!=="ArrowDown"&&e.key!=="ArrowUp"||t.activeIndex===-1||t.entries.length===0)return;e.preventDefault();let r=e.key==="ArrowDown"?1:-1,o=(t.activeIndex+r+t.entries.length)%t.entries.length;t.entries[o].focus()}function fe(e,t,r){let{anchor:o}=e,n=o.top+(o.height-A)/2-r.top;return t==="right"?{text:e.text,top:n,right:r.left+r.width-o.left+P}:{text:e.text,top:n,left:o.left+o.width+P-r.left}}function at(){var t;return(typeof document=="undefined"?0:(t=document.documentElement)==null?void 0:t.clientWidth)||D.Dimensions.get("window").width}function lt(e){return typeof(e==null?void 0:e.addEventListener)=="function"}function we({children:e,side:t="left",onEscape:r,onHoverIn:o,onHoverOut:n,hoverDelayInMilliseconds:c=re}){var C,p;let f=(0,pe.useTheme)(),u=(0,d.useRef)(null),s=(0,d.useRef)(null),w=(0,d.useRef)(!1),[i,l]=(0,d.useState)(null);(0,d.useEffect)(()=>g,[]);function g(){s.current&&(clearTimeout(s.current),s.current=null)}function E(){o&&(g(),s.current=setTimeout(()=>{s.current=null,w.current=!0,l(null),o()},c))}function G(){g(),w.current&&(w.current=!1,n==null||n())}let R={side:t,show(L){if(D.Platform.OS==="web"){l(fe(L,t,{left:0,top:0,width:at()}));return}T(u.current,(m,I,h)=>{l(fe(L,t,{left:m,top:I,width:h}))})},hide:()=>l(null)};return(0,d.useEffect)(()=>{let L=u.current,m=typeof document=="undefined"?void 0:document;if(D.Platform.OS!=="web"||!lt(L)||!m)return;let I=L,h=m;function b(){l(null)}function _(J){let v=Array.from(I.querySelectorAll(nt));it(J,{entries:v,activeIndex:v.indexOf(h.activeElement),hideLabel:b,onEscape:r})}return I.addEventListener("keydown",_),h.addEventListener("scroll",b,!0),()=>{I.removeEventListener("keydown",_),h.removeEventListener("scroll",b,!0)}},[r]),(0,M.jsx)(be.Provider,{value:R,children:(0,M.jsxs)(D.View,{ref:u,collapsable:!1,style:[ct.root,{backgroundColor:f.colors.drawer.background}],onPointerEnter:E,onPointerLeave:G,testID:"drawer-root",children:[e,(0,M.jsx)(K,{text:(C=i==null?void 0:i.text)!=null?C:"",visible:i!==null,top:(p=i==null?void 0:i.top)!=null?p:0,left:i==null?void 0:i.left,right:i==null?void 0:i.right})]})})}var ct=D.StyleSheet.create({root:{flex:1}});var y=require("react/jsx-runtime"),st=250,dt=1500,ge={MD:"3rem",SM:"2.5rem"},ut={MD:"MD",SM:"SM"};function ye(G){var R=G,{icon:e,accessibilityLabel:t,label:r=t,active:o=!1,color:n="DEFAULT",badge:c,size:f="MD",onHoverIn:u,onHoverOut:s,onFocus:w,onBlur:i,onPressIn:l,onLongPress:g}=R,E=z(R,["icon","accessibilityLabel","label","active","color","badge","size","onHoverIn","onHoverOut","onFocus","onBlur","onPressIn","onLongPress"]);var oe;let C=(0,De.useTheme)(),p=Y(),L=(0,S.useRef)(null),m=(0,S.useRef)(null),I=(0,S.useRef)(!1),h=(0,S.useRef)(!1),[b,_]=(0,S.useState)(null),J=U(C,n,o),v=W(C),Oe=C.colors.drawer.activeBackground,Ge=c?`${t}, ${c}`:t;(0,S.useEffect)(()=>()=>{k(),I.current&&(p==null||p.hide())},[]);function k(){m.current&&(clearTimeout(m.current),m.current=null)}function Q(){T(L.current,(a,ne,ie,ae)=>{if(p){I.current=!0,p.show({text:r,anchor:{left:a,top:ne,width:ie,height:ae}});return}x.Platform.OS==="web"&&_({top:ne+(ae-A)/2,left:a+ie+P})})}function H(){if(k(),p){I.current=!1,p.hide();return}_(null)}function He(){k(),Q(),m.current=setTimeout(()=>{m.current=null,H()},dt)}function Ve(a){k(),m.current=setTimeout(()=>{m.current=null,Q()},a)}function Xe(a){Ve(st),u==null||u(a)}function ze(a){H(),s==null||s(a)}function $e(a){h.current?h.current=!1:(k(),Q()),w==null||w(a)}function Ue(a){h.current=!1,H(),i==null||i(a)}function We(a){h.current=!0,H(),l==null||l(a)}function Ke(a){x.Platform.OS!=="web"&&p&&He(),g==null||g(a)}return(0,y.jsxs)(x.View,{ref:L,collapsable:!1,style:Ie.anchor,testID:"drawer-compact-item-anchor",children:[(0,y.jsx)(Ee.Clickable,X(F({accessibilityRole:"button",accessibilityLabel:Ge,accessibilityState:{selected:o},width:ge[f],height:ge[f],align:"CENTER_CENTER",borderRadius:"MEDIUM",backgroundColor:o?Oe:void 0,whenHovered:v?{backgroundColor:v}:void 0,whenPressed:v?{backgroundColor:v}:void 0,onHoverIn:Xe,onHoverOut:ze,onFocus:$e,onBlur:Ue,onPressIn:We,onLongPress:Ke},E),{testID:"drawer-compact-item",children:(0,y.jsx)(Le.Icon,{name:e,size:ut[f],color:J})})),c&&(0,y.jsx)(x.View,{style:Ie.badge,pointerEvents:"none",testID:"drawer-compact-item-badge",children:(0,y.jsx)(Se.Badge,{text:c,type:"DANGER",size:"2XS",isRounded:!0})}),(0,y.jsx)(K,{text:r,visible:b!==null,top:(oe=b==null?void 0:b.top)!=null?oe:0,left:b==null?void 0:b.left})]})}var he=2,Ie=x.StyleSheet.create({anchor:{alignSelf:"center"},badge:{position:"absolute",top:he,right:he}});var xe=$(require("styled-components/native")),ve=require("@mobilestock-native/container"),Ce=require("react/jsx-runtime"),mt={MD:"XS",SM:"2XS"};function Re({children:e,compact:t=!1,size:r="MD"}){let o=`${mt[r]}_${t?"NONE":"SM"}`;return(0,Ce.jsx)(ft,{padding:o,testID:"drawer-footer",children:e})}var ft=(0,xe.default)(ve.Container)`
|
|
11
11
|
border-top-width: 1px;
|
|
12
12
|
border-top-color: ${({theme:e})=>e.colors.drawer.divider};
|
|
13
|
-
`;var
|
|
13
|
+
`;var Z=$(require("styled-components/native")),Te=require("@mobilestock-native/clickable"),_e=require("@mobilestock-native/icons"),ke=require("@mobilestock-native/typography");var B=require("react/jsx-runtime"),pt={MD:"2.75rem",SM:"2.25rem"},bt={MD:"SM",SM:"XS"};function Ne(w){var i=w,{label:e,icon:t,color:r="DEFAULT",active:o=!1,trailing:n,href:c,accessibilityLabel:f,size:u="MD"}=i,s=z(i,["label","icon","color","active","trailing","href","accessibilityLabel","size"]);let l=(0,Z.useTheme)(),g=U(l,r,o),E=W(l),G=l.colors.drawer.activeBackground,R=Math.round(Number(l.font.size.sm)*l.font.lineHeight);return(0,B.jsxs)(Te.Clickable,X(F(F({accessibilityRole:c?"link":"button",accessibilityLabel:f!=null?f:e,accessibilityState:{selected:o},direction:"ROW",align:"START_CENTER",gap:"SM",padding:"2XS_XS",minHeight:pt[u],borderRadius:"DEFAULT",backgroundColor:o?G:void 0,whenHovered:E?{backgroundColor:E}:void 0,whenPressed:E?{backgroundColor:E}:void 0},c?{href:c}:null),s),{testID:"drawer-item",children:[(0,B.jsx)(_e.Icon,{name:t,size:"SM",color:g}),(0,B.jsx)(wt,{size:bt[u],$color:g,$lineHeight:R,withEllipsis:!0,testID:"drawer-item-label",children:e}),n]}))}var wt=(0,Z.default)(ke.Typography)`
|
|
14
14
|
flex-shrink: 1;
|
|
15
|
+
line-height: ${({$lineHeight:e})=>e}px;
|
|
15
16
|
color: ${({$color:e})=>e};
|
|
16
|
-
`;var
|
|
17
|
+
`;var Fe=require("react"),q=require("react-native"),Ae=$(require("styled-components/native")),Pe=require("@mobilestock-native/container"),Me=require("@mobilestock-native/typography");var O=require("react/jsx-runtime");function Be({title:e,compact:t=!1}){let r=Y(),o=(0,Fe.useRef)(null);function n(){r&&T(o.current,(f,u,s,w)=>{r.show({text:e,anchor:{left:f,top:u,width:s,height:w}})})}function c(){r==null||r.hide()}return t?(0,O.jsx)(q.View,{ref:o,collapsable:!1,style:ht.dividerRow,accessible:!0,accessibilityRole:"header",accessibilityLabel:e,onPointerEnter:n,onPointerLeave:c,testID:"drawer-section-divider",children:(0,O.jsx)(gt,{testID:"drawer-section-divider-line"})}):(0,O.jsx)(Pe.Container,{padding:"SM_XS_2XS_XS",testID:"drawer-section-title",children:(0,O.jsx)(Me.Typography,{size:"XS",weight:"BOLD",color:"DEFAULT_200",transform:"UPPERCASE",accessibilityRole:"header",children:e})})}var gt=Ae.default.View`
|
|
17
18
|
width: 32px;
|
|
18
19
|
height: 1px;
|
|
19
20
|
background-color: ${({theme:e})=>e.colors.drawer.divider};
|
|
20
|
-
`,
|
|
21
|
+
`,ht=q.StyleSheet.create({dividerRow:{alignItems:"center",paddingVertical:4}});var It={Root:we,Item:Ne,CompactItem:ye,SectionTitle:Be,Footer:Re};0&&(module.exports={Drawer,HOVER_EXPAND_DELAY_IN_MILLISECONDS});
|