@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.
- package/index.d.ts +13 -1
- package/index.js +1 -1
- 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
|
|
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.
|
|
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": {
|