@mobilestock-native/chip 0.1.0 → 0.1.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 +13 -1
  2. package/index.js +1 -1
  3. package/package.json +2 -2
package/index.d.ts CHANGED
@@ -8,7 +8,12 @@ interface ChipSizeConfig {
8
8
  /** @description Minimum height of the pill. */
9
9
  minHeight: `${number}rem`;
10
10
  /** @description Horizontal padding token of the touch area and of the remove button. */
11
- horizontalPadding: 'XS' | 'SM';
11
+ horizontalPadding: '2XS' | 'XS' | 'SM';
12
+ /**
13
+ * @description Padding token at the side of the `leading` element, when the chip has one: a color dot that
14
+ * already fills the pill sits closer to the edge than a label would. Default: `horizontalPadding`.
15
+ */
16
+ leadingPadding?: '2XS' | 'XS' | 'SM';
12
17
  /** @description Font size of the label. */
13
18
  font: FontSize;
14
19
  /** @description Size of the check and of the × icons. */
@@ -164,6 +169,13 @@ interface ChipGroupBaseProps<ValueGeneric extends string> {
164
169
  * @example scrollable
165
170
  */
166
171
  scrollable?: boolean;
172
+ /**
173
+ * @description With `scrollable`, called whenever the row starts or stops having chips past its visible edge, so
174
+ * the app can offer a way to open them (a "Ver todos"). Called once the row is measured, and again on changes.
175
+ * Default: undefined
176
+ * @example onOverflowChange={setHasHiddenSizes}
177
+ */
178
+ onOverflowChange?(overflows: boolean): void;
167
179
  /**
168
180
  * @description Test identifier of the group. Each chip receives `${testID}-chip-${value}`.
169
181
  * Default: 'chip-group'
package/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var Z=Object.create;var m=Object.defineProperty,j=Object.defineProperties,ee=Object.getOwnPropertyDescriptor,ie=Object.getOwnPropertyDescriptors,oe=Object.getOwnPropertyNames,P=Object.getOwnPropertySymbols,te=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty,ne=Object.prototype.propertyIsEnumerable;var T=(e,i,o)=>i in e?m(e,i,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[i]=o,z=(e,i)=>{for(var o in i||(i={}))D.call(i,o)&&T(e,o,i[o]);if(P)for(var o of P(i))ne.call(i,o)&&T(e,o,i[o]);return e},R=(e,i)=>j(e,ie(i));var re=(e,i)=>{for(var o in i)m(e,o,{get:i[o],enumerable:!0})},N=(e,i,o,n)=>{if(i&&typeof i=="object"||typeof i=="function")for(let t of oe(i))!D.call(e,t)&&t!==o&&m(e,t,{get:()=>i[t],enumerable:!(n=ee(i,t))||n.enumerable});return e};var le=(e,i,o)=>(o=e!=null?Z(te(e)):{},N(i||!e||!e.__esModule?m(o,"default",{value:e,enumerable:!0}):o,e)),se=e=>N(m({},"__esModule",{value:!0}),e);var pe={};re(pe,{Chip:()=>ce,chipSizes:()=>y});module.exports=se(pe);var w=require("styled-components/native"),v=require("@mobilestock-native/clickable"),H=require("@mobilestock-native/container"),I=require("@mobilestock-native/icons"),x=le(require("@mobilestock-native/tools")),_=require("@mobilestock-native/typography");var y={XS:{minHeight:"1.5rem",horizontalPadding:"XS",font:"XS",icon:"2XS"},SM:{minHeight:"2rem",horizontalPadding:"XS",font:"XS",icon:"2XS"},MD:{minHeight:"2.5rem",horizontalPadding:"SM",font:"SM",icon:"XS"}};function X(e){return typeof e=="string"?y[e]:e}var d=require("react/jsx-runtime");function C({label:e,selected:i=!1,disabled:o=!1,size:n="MD",leading:t,accessibilityLabel:c,accessibilityRole:a="checkbox",testID:p="chip",onPress:h,onRemove:r}){let s=(0,w.useTheme)(),u=i?s.colors.container.inverse:s.colors.container.surface,l=x.default.defineTextColor(u),E=i&&r!==void 0,B=i&&!E,{minHeight:F,horizontalPadding:b,font:q,icon:G}=X(n),J=E?`2XS_2XS_2XS_${b}`:`2XS_${b}`,K=`2XS_${b}_2XS_2XS`;function Q(){h==null||h()}function Y(){r==null||r()}return(0,d.jsxs)(H.Container.Horizontal,{testID:p,align:"START_CENTER",borderRadius:"ROUNDED",borderWidth:"HAIRLINE",borderColor:i?"DEFAULT":"SUBTLE",backgroundColor:i?"INVERSE":"SURFACE",minHeight:F,children:[(0,d.jsxs)(v.Clickable,{testID:`${p}-toggle`,accessibilityRole:a,accessibilityLabel:c!=null?c:e,accessibilityState:{checked:i,disabled:o},disabled:o,onPress:Q,borderRadius:"ROUNDED",padding:J,gap:"2XS",align:"CENTER_CENTER",direction:"ROW",children:[t,(0,d.jsx)(_.Typography,{size:q,weight:"SEMIBOLD",style:{color:l},children:e}),B&&(0,d.jsx)(I.Icon,{name:"Check",size:G,color:l,testID:`${p}-check`})]}),E&&(0,d.jsx)(v.Clickable,{testID:`${p}-remove`,accessibilityRole:"button",accessibilityLabel:`Remover ${e}`,accessibilityState:{disabled:o},disabled:o,onPress:Y,borderRadius:"ROUNDED",padding:K,children:(0,d.jsx)(I.Icon,{name:"X",size:G,color:l})})]})}var W=require("@mobilestock-native/container");function L(e,i){return e.includes(i)?e.filter(o=>o!==i):[...e,i]}var V=require("react/jsx-runtime");function M({option:e,selected:i,size:o,accessibilityRole:n,testID:t,onPress:c,onRemove:a}){function p(){c(e.value)}function h(){a==null||a(e.value)}return(0,V.jsx)(C,{label:e.label,leading:e.leading,disabled:e.disabled,accessibilityLabel:e.accessibilityLabel,accessibilityRole:n,selected:i,size:o,testID:t,onPress:p,onRemove:a?h:void 0})}var O=require("react"),k=require("react-native"),S=require("@mobilestock-native/container");function A(e,i,o){let n=e>1,t=i-o-e>1;return{hasHiddenStart:n,hasHiddenEnd:t}}var f=require("react/jsx-runtime"),ae={offset:0,contentWidth:0,visibleWidth:0};function $({children:e,testID:i,accessibilityRole:o}){let[n,t]=(0,O.useState)(ae),c=A(n.offset,n.contentWidth,n.visibleWidth);function a(r){let{contentOffset:s,contentSize:u,layoutMeasurement:l}=r.nativeEvent;t({offset:s.x,contentWidth:u.width,visibleWidth:l.width})}function p(r){let s=r.nativeEvent.layout.width;t(u=>R(z({},u),{visibleWidth:s}))}function h(r){t(s=>R(z({},s),{contentWidth:r,offset:Math.min(s.offset,Math.max(r-s.visibleWidth,0))}))}return(0,f.jsxs)(S.Container,{testID:i,accessibilityRole:o,position:"RELATIVE",children:[(0,f.jsx)(k.ScrollView,{testID:`${i}-scroll`,horizontal:!0,showsHorizontalScrollIndicator:!1,scrollEventThrottle:16,onScroll:a,onLayout:p,onContentSizeChange:h,children:(0,f.jsx)(S.Container.Horizontal,{gap:"XS",align:"START_CENTER",children:e})}),c.hasHiddenStart&&(0,f.jsx)(S.Container,{testID:`${i}-shadow-start`,pointerEvents:"none",position:"ABSOLUTE",top:"0rem",bottom:"0rem",left:"0rem",width:"0.0625rem",shadowEdge:"RIGHT"}),c.hasHiddenEnd&&(0,f.jsx)(S.Container,{testID:`${i}-shadow-end`,pointerEvents:"none",position:"ABSOLUTE",top:"0rem",bottom:"0rem",right:"0rem",width:"0.0625rem",shadowEdge:"LEFT"})]})}var g=require("react/jsx-runtime");function U(e){let{options:i,size:o="MD",scrollable:n=!1,testID:t="chip-group",onRemove:c}=e,a=e.selection==="single",p=e.selection==="single"?[e.value]:e.value,h=a?"radio":"checkbox",r=a?"radiogroup":void 0,s=i.map(l=>(0,g.jsx)(M,{option:l,selected:p.includes(l.value),size:o,accessibilityRole:h,testID:`${t}-chip-${l.value}`,onPress:u,onRemove:c},l.value));function u(l){if(e.selection==="single"){if(l===e.value)return;e.onChange(l);return}e.onChange(L(e.value,l))}return n?(0,g.jsx)($,{testID:t,accessibilityRole:r,children:s}):(0,g.jsx)(W.Container.Horizontal,{testID:t,accessibilityRole:r,gap:"XS",wrap:!0,children:s})}var ce=Object.assign(C,{Group:U});0&&(module.exports={Chip,chipSizes});
1
+ "use strict";var ie=Object.create;var b=Object.defineProperty,oe=Object.defineProperties,te=Object.getOwnPropertyDescriptor,ne=Object.getOwnPropertyDescriptors,re=Object.getOwnPropertyNames,w=Object.getOwnPropertySymbols,se=Object.getPrototypeOf,H=Object.prototype.hasOwnProperty,le=Object.prototype.propertyIsEnumerable;var x=(e,i,o)=>i in e?b(e,i,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[i]=o,G=(e,i)=>{for(var o in i||(i={}))H.call(i,o)&&x(e,o,i[o]);if(w)for(var o of w(i))le.call(i,o)&&x(e,o,i[o]);return e},P=(e,i)=>oe(e,ne(i));var ce=(e,i)=>{for(var o in i)b(e,o,{get:i[o],enumerable:!0})},L=(e,i,o,s)=>{if(i&&typeof i=="object"||typeof i=="function")for(let t of re(i))!H.call(e,t)&&t!==o&&b(e,t,{get:()=>i[t],enumerable:!(s=te(i,t))||s.enumerable});return e};var ae=(e,i,o)=>(o=e!=null?ie(se(e)):{},L(i||!e||!e.__esModule?b(o,"default",{value:e,enumerable:!0}):o,e)),pe=e=>L(b({},"__esModule",{value:!0}),e);var ue={};ce(ue,{Chip:()=>fe,chipSizes:()=>T});module.exports=pe(ue);var A=require("styled-components/native"),N=require("@mobilestock-native/clickable"),V=require("@mobilestock-native/container"),X=require("@mobilestock-native/icons"),O=ae(require("@mobilestock-native/tools")),W=require("@mobilestock-native/typography");var T={XS:{minHeight:"1.5rem",horizontalPadding:"XS",font:"XS",icon:"2XS"},SM:{minHeight:"2rem",horizontalPadding:"XS",font:"XS",icon:"2XS"},MD:{minHeight:"2.5rem",horizontalPadding:"SM",font:"SM",icon:"XS"}};function M(e){return typeof e=="string"?T[e]:e}var d=require("react/jsx-runtime");function R({label:e,selected:i=!1,disabled:o=!1,size:s="MD",leading:t,accessibilityLabel:r,accessibilityRole:l="checkbox",testID:c="chip",onPress:a,onRemove:p}){let f=(0,A.useTheme)(),m=i?f.colors.container.inverse:f.colors.container.surface,u=O.default.defineTextColor(m),n=i&&p!==void 0,h=i&&!n,{minHeight:E,horizontalPadding:C,leadingPadding:y,font:Q,icon:D}=M(s),_=t!==void 0&&y!=null?y:C,I=n?"2XS":C,Y=_===I?`2XS_${I}`:`2XS_${I}_2XS_${_}`,Z=`2XS_${C}_2XS_2XS`;function j(){a==null||a()}function ee(){p==null||p()}return(0,d.jsxs)(V.Container.Horizontal,{testID:c,align:"START_CENTER",borderRadius:"ROUNDED",borderWidth:"HAIRLINE",borderColor:i?"DEFAULT":"SUBTLE",backgroundColor:i?"INVERSE":"SURFACE",minHeight:E,children:[(0,d.jsxs)(N.Clickable,{testID:`${c}-toggle`,accessibilityRole:l,accessibilityLabel:r!=null?r:e,accessibilityState:{checked:i,disabled:o},disabled:o,onPress:j,borderRadius:"ROUNDED",padding:Y,gap:"2XS",align:"CENTER_CENTER",direction:"ROW",children:[t,(0,d.jsx)(W.Typography,{size:Q,weight:"SEMIBOLD",style:{color:u},children:e}),h&&(0,d.jsx)(X.Icon,{name:"Check",size:D,color:u,testID:`${c}-check`})]}),n&&(0,d.jsx)(N.Clickable,{testID:`${c}-remove`,accessibilityRole:"button",accessibilityLabel:`Remover ${e}`,accessibilityState:{disabled:o},disabled:o,onPress:ee,borderRadius:"ROUNDED",padding:Z,children:(0,d.jsx)(X.Icon,{name:"X",size:D,color:u})})]})}var J=require("@mobilestock-native/container");function $(e,i){return e.includes(i)?e.filter(o=>o!==i):[...e,i]}var U=require("react/jsx-runtime");function k({option:e,selected:i,size:o,accessibilityRole:s,testID:t,onPress:r,onRemove:l}){function c(){r(e.value)}function a(){l==null||l(e.value)}return(0,U.jsx)(R,{label:e.label,leading:e.leading,disabled:e.disabled,accessibilityLabel:e.accessibilityLabel,accessibilityRole:s,selected:i,size:o,testID:t,onPress:c,onRemove:l?a:void 0})}var g=require("react"),F=require("react-native"),z=require("@mobilestock-native/container");function B(e,i,o){let s=e>1,t=i-o-e>1;return{hasHiddenStart:s,hasHiddenEnd:t}}var S=require("react/jsx-runtime"),de={offset:0,contentWidth:0,visibleWidth:0};function q({children:e,testID:i,accessibilityRole:o,onOverflowChange:s}){let t=(0,g.useRef)(!1),[r,l]=(0,g.useState)(de),c=B(r.offset,r.contentWidth,r.visibleWidth),a=r.visibleWidth>0&&r.contentWidth>0,p=a&&r.contentWidth-r.visibleWidth>1;(0,g.useEffect)(()=>{(a||t.current)&&(s==null||s(p),t.current=a)},[a,p]);function f(n){let{contentOffset:h,contentSize:E,layoutMeasurement:C}=n.nativeEvent;l({offset:h.x,contentWidth:E.width,visibleWidth:C.width})}function m(n){let h=n.nativeEvent.layout.width;l(E=>P(G({},E),{visibleWidth:h}))}function u(n){l(h=>P(G({},h),{contentWidth:n,offset:Math.min(h.offset,Math.max(n-h.visibleWidth,0))}))}return(0,S.jsxs)(z.Container,{testID:i,accessibilityRole:o,position:"RELATIVE",onLayout:m,children:[(0,S.jsx)(F.ScrollView,{testID:`${i}-scroll`,horizontal:!0,showsHorizontalScrollIndicator:!1,scrollEventThrottle:16,onScroll:f,onContentSizeChange:u,children:(0,S.jsx)(z.Container.Horizontal,{gap:"XS",align:"START_CENTER",children:e})}),c.hasHiddenStart&&(0,S.jsx)(z.Container,{testID:`${i}-shadow-start`,pointerEvents:"none",position:"ABSOLUTE",top:"0rem",bottom:"0rem",left:"0rem",width:"0.0625rem",shadowEdge:"RIGHT"}),c.hasHiddenEnd&&(0,S.jsx)(z.Container,{testID:`${i}-shadow-end`,pointerEvents:"none",position:"ABSOLUTE",top:"0rem",bottom:"0rem",right:"0rem",width:"0.0625rem",shadowEdge:"LEFT"})]})}var v=require("react/jsx-runtime");function K(e){let{options:i,size:o="MD",scrollable:s=!1,testID:t="chip-group",onRemove:r,onOverflowChange:l}=e,c=e.selection==="single",a=e.selection==="single"?[e.value]:e.value,p=c?"radio":"checkbox",f=c?"radiogroup":void 0,m=i.map(n=>(0,v.jsx)(k,{option:n,selected:a.includes(n.value),size:o,accessibilityRole:p,testID:`${t}-chip-${n.value}`,onPress:u,onRemove:r},n.value));function u(n){if(e.selection==="single"){if(n===e.value)return;e.onChange(n);return}e.onChange($(e.value,n))}return s?(0,v.jsx)(q,{testID:t,accessibilityRole:f,onOverflowChange:l,children:m}):(0,v.jsx)(J.Container.Horizontal,{testID:t,accessibilityRole:f,gap:"XS",wrap:!0,children:m})}var fe=Object.assign(R,{Group:K});0&&(module.exports={Chip,chipSizes});
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@mobilestock-native/chip",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "@mobilestock-native/clickable": "^1.1.1",
7
7
  "@mobilestock-native/container": "^1.4.0",
8
- "@mobilestock-native/icons": "^0.9.0",
9
8
  "@mobilestock-native/tools": "^0.1.0",
9
+ "@mobilestock-native/icons": "^0.9.0",
10
10
  "@mobilestock-native/typography": "^0.1.3"
11
11
  },
12
12
  "peerDependencies": {