@mobilestock-native/chip 0.0.0-stage → 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 +244 -0
- package/index.js +1 -0
- package/package.json +14 -3
- package/README.md +0 -3
package/index.d.ts
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { DefaultTheme } from 'styled-components/native';
|
|
4
|
+
import { IconSize } from '@mobilestock-native/icons';
|
|
5
|
+
|
|
6
|
+
type FontSize = Uppercase<keyof DefaultTheme['font']['size'] & string>;
|
|
7
|
+
interface ChipSizeConfig {
|
|
8
|
+
/** @description Minimum height of the pill. */
|
|
9
|
+
minHeight: `${number}rem`;
|
|
10
|
+
/** @description Horizontal padding token of the touch area and of the remove button. */
|
|
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';
|
|
17
|
+
/** @description Font size of the label. */
|
|
18
|
+
font: FontSize;
|
|
19
|
+
/** @description Size of the check and of the × icons. */
|
|
20
|
+
icon: IconSize;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @description Every measure of the pill that changes with its size, one entry per named size. An app that needs
|
|
24
|
+
* another size passes its own `ChipSizeConfig` in `size`, usually built from one of these entries.
|
|
25
|
+
*/
|
|
26
|
+
declare const sizeMap: {
|
|
27
|
+
XS: {
|
|
28
|
+
minHeight: "1.5rem";
|
|
29
|
+
horizontalPadding: "XS";
|
|
30
|
+
font: "XS";
|
|
31
|
+
icon: "2XS";
|
|
32
|
+
};
|
|
33
|
+
SM: {
|
|
34
|
+
minHeight: "2rem";
|
|
35
|
+
horizontalPadding: "XS";
|
|
36
|
+
font: "XS";
|
|
37
|
+
icon: "2XS";
|
|
38
|
+
};
|
|
39
|
+
MD: {
|
|
40
|
+
minHeight: "2.5rem";
|
|
41
|
+
horizontalPadding: "SM";
|
|
42
|
+
font: "SM";
|
|
43
|
+
icon: "XS";
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
type ChipSizeName = keyof typeof sizeMap;
|
|
47
|
+
type ChipSize = ChipSizeName | ChipSizeConfig;
|
|
48
|
+
|
|
49
|
+
type ChipSelection = 'single' | 'multiple';
|
|
50
|
+
type ChipAccessibilityRole = 'checkbox' | 'radio';
|
|
51
|
+
interface ChipProps {
|
|
52
|
+
/**
|
|
53
|
+
* @description Text displayed in the pill. It is also the accessibility label when `accessibilityLabel` is omitted.
|
|
54
|
+
* Default: required
|
|
55
|
+
* @example label="38"
|
|
56
|
+
*/
|
|
57
|
+
label: string;
|
|
58
|
+
/**
|
|
59
|
+
* @description Marks the chip: dark background, contrast text and a check mark after the label.
|
|
60
|
+
* Default: false
|
|
61
|
+
* @example selected
|
|
62
|
+
*/
|
|
63
|
+
selected?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* @description Dims the chip and ignores every touch, on the pill and on the remove button.
|
|
66
|
+
* Default: false
|
|
67
|
+
* @example disabled
|
|
68
|
+
*/
|
|
69
|
+
disabled?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* @description Size of the pill (height, padding, font and icons): one of the named sizes, or a `ChipSizeConfig`
|
|
72
|
+
* the app defines once, so a new size needs no change in the package.
|
|
73
|
+
* Default: 'MD'
|
|
74
|
+
* @example size="SM"
|
|
75
|
+
* @example size={{ minHeight: '1.75rem', horizontalPadding: 'XS', font: 'SM', icon: '2XS' }}
|
|
76
|
+
*/
|
|
77
|
+
size?: ChipSize;
|
|
78
|
+
/**
|
|
79
|
+
* @description Element displayed before the label: a color dot, an icon, an avatar.
|
|
80
|
+
* Default: undefined (no leading element)
|
|
81
|
+
* @example leading={<ColorDot color="#111" />}
|
|
82
|
+
*/
|
|
83
|
+
leading?: ReactNode;
|
|
84
|
+
/**
|
|
85
|
+
* @description Accessibility label read by screen readers instead of the `label`.
|
|
86
|
+
* Default: undefined (uses `label`)
|
|
87
|
+
* @example accessibilityLabel="Tamanho 38"
|
|
88
|
+
*/
|
|
89
|
+
accessibilityLabel?: string;
|
|
90
|
+
/**
|
|
91
|
+
* @description Role announced to screen readers: `checkbox` for a chip that toggles on its own or inside a multiple
|
|
92
|
+
* selection, `radio` inside a single selection.
|
|
93
|
+
* Default: 'checkbox'
|
|
94
|
+
* @example accessibilityRole="radio"
|
|
95
|
+
*/
|
|
96
|
+
accessibilityRole?: ChipAccessibilityRole;
|
|
97
|
+
/**
|
|
98
|
+
* @description Test identifier of the pill. The touch area receives `${testID}-toggle` and the remove button
|
|
99
|
+
* `${testID}-remove`.
|
|
100
|
+
* Default: 'chip'
|
|
101
|
+
* @example testID="size-38"
|
|
102
|
+
*/
|
|
103
|
+
testID?: string;
|
|
104
|
+
/**
|
|
105
|
+
* @description Called when the pill is pressed. Not called when the chip is disabled or when the remove button is
|
|
106
|
+
* pressed.
|
|
107
|
+
* Default: undefined
|
|
108
|
+
* @example onPress={() => toggle('38')}
|
|
109
|
+
*/
|
|
110
|
+
onPress?(): void;
|
|
111
|
+
/**
|
|
112
|
+
* @description Shows a remove button (×) in the place of the check while the chip is selected, and calls it when
|
|
113
|
+
* that button is pressed. The button is announced as "Remover <label>". An unselected chip has nothing to remove,
|
|
114
|
+
* so it shows no button.
|
|
115
|
+
* Default: undefined (no remove button)
|
|
116
|
+
* @example onRemove={() => clearColor()}
|
|
117
|
+
*/
|
|
118
|
+
onRemove?(): void;
|
|
119
|
+
}
|
|
120
|
+
interface ChipGroupOption<ValueGeneric extends string = string> {
|
|
121
|
+
/**
|
|
122
|
+
* @description Unique value of the option, delivered to `onChange` and `onRemove`.
|
|
123
|
+
* Default: required
|
|
124
|
+
* @example value="38"
|
|
125
|
+
*/
|
|
126
|
+
value: ValueGeneric;
|
|
127
|
+
/**
|
|
128
|
+
* @description Text displayed in the chip.
|
|
129
|
+
* Default: required
|
|
130
|
+
* @example label="38"
|
|
131
|
+
*/
|
|
132
|
+
label: string;
|
|
133
|
+
/**
|
|
134
|
+
* @description Element displayed before the label of this chip.
|
|
135
|
+
* Default: undefined
|
|
136
|
+
* @example leading={<ColorDot color="#111" />}
|
|
137
|
+
*/
|
|
138
|
+
leading?: ReactNode;
|
|
139
|
+
/**
|
|
140
|
+
* @description Disables this chip: it is dimmed and ignores touches.
|
|
141
|
+
* Default: false
|
|
142
|
+
* @example disabled
|
|
143
|
+
*/
|
|
144
|
+
disabled?: boolean;
|
|
145
|
+
/**
|
|
146
|
+
* @description Accessibility label read by screen readers instead of the `label`.
|
|
147
|
+
* Default: undefined (uses `label`)
|
|
148
|
+
* @example accessibilityLabel="Cor preta"
|
|
149
|
+
*/
|
|
150
|
+
accessibilityLabel?: string;
|
|
151
|
+
}
|
|
152
|
+
interface ChipGroupBaseProps<ValueGeneric extends string> {
|
|
153
|
+
/**
|
|
154
|
+
* @description Chips displayed in the group, in order.
|
|
155
|
+
* Default: required
|
|
156
|
+
* @example options={[{ value: '37', label: '37' }, { value: '38', label: '38' }]}
|
|
157
|
+
*/
|
|
158
|
+
options: ChipGroupOption<ValueGeneric>[];
|
|
159
|
+
/**
|
|
160
|
+
* @description Size of every chip of the group: a named size or a `ChipSizeConfig` the app defines.
|
|
161
|
+
* Default: 'MD'
|
|
162
|
+
* @example size="SM"
|
|
163
|
+
*/
|
|
164
|
+
size?: ChipSize;
|
|
165
|
+
/**
|
|
166
|
+
* @description Lays the chips in one horizontal scrolling row, with a cut shadow on the edge that hides more chips.
|
|
167
|
+
* Without it the chips wrap into as many lines as needed.
|
|
168
|
+
* Default: false
|
|
169
|
+
* @example scrollable
|
|
170
|
+
*/
|
|
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;
|
|
179
|
+
/**
|
|
180
|
+
* @description Test identifier of the group. Each chip receives `${testID}-chip-${value}`.
|
|
181
|
+
* Default: 'chip-group'
|
|
182
|
+
* @example testID="sizes"
|
|
183
|
+
*/
|
|
184
|
+
testID?: string;
|
|
185
|
+
/**
|
|
186
|
+
* @description Shows a remove button (×) on the selected chips, in the place of the check, and receives the value
|
|
187
|
+
* of the chip whose button was pressed.
|
|
188
|
+
* Default: undefined (no remove buttons)
|
|
189
|
+
* @example onRemove={value => removeFilter(value)}
|
|
190
|
+
*/
|
|
191
|
+
onRemove?(value: ValueGeneric): void;
|
|
192
|
+
}
|
|
193
|
+
interface ChipGroupMultipleProps<ValueGeneric extends string> extends ChipGroupBaseProps<ValueGeneric> {
|
|
194
|
+
/**
|
|
195
|
+
* @description Several chips may be selected at once; pressing a selected chip deselects it. Chips are checkboxes.
|
|
196
|
+
* Default: 'multiple'
|
|
197
|
+
* @example selection="multiple"
|
|
198
|
+
*/
|
|
199
|
+
selection?: 'multiple';
|
|
200
|
+
/**
|
|
201
|
+
* @description Values of the selected chips (controlled component).
|
|
202
|
+
* Default: required
|
|
203
|
+
* @example value={['37', '38']}
|
|
204
|
+
*/
|
|
205
|
+
value: ValueGeneric[];
|
|
206
|
+
/**
|
|
207
|
+
* @description Called with the new list of selected values after a chip is pressed.
|
|
208
|
+
* Default: required
|
|
209
|
+
* @example onChange={values => setSizes(values)}
|
|
210
|
+
*/
|
|
211
|
+
onChange(values: ValueGeneric[]): void;
|
|
212
|
+
}
|
|
213
|
+
interface ChipGroupSingleProps<ValueGeneric extends string> extends ChipGroupBaseProps<ValueGeneric> {
|
|
214
|
+
/**
|
|
215
|
+
* @description Exactly one chip is selected; pressing the selected chip does nothing. Chips are radios inside a
|
|
216
|
+
* radiogroup.
|
|
217
|
+
* Default: required for a single selection
|
|
218
|
+
* @example selection="single"
|
|
219
|
+
*/
|
|
220
|
+
selection: 'single';
|
|
221
|
+
/**
|
|
222
|
+
* @description Value of the selected chip (controlled component).
|
|
223
|
+
* Default: required
|
|
224
|
+
* @example value="RELEVANCE"
|
|
225
|
+
*/
|
|
226
|
+
value: ValueGeneric;
|
|
227
|
+
/**
|
|
228
|
+
* @description Called with the value of the chip the user pressed.
|
|
229
|
+
* Default: required
|
|
230
|
+
* @example onChange={value => setSort(value)}
|
|
231
|
+
*/
|
|
232
|
+
onChange(value: ValueGeneric): void;
|
|
233
|
+
}
|
|
234
|
+
type ChipGroupProps<ValueGeneric extends string = string> = ChipGroupMultipleProps<ValueGeneric> | ChipGroupSingleProps<ValueGeneric>;
|
|
235
|
+
|
|
236
|
+
declare function Chip$1({ label, selected, disabled, size, leading, accessibilityLabel, accessibilityRole, testID, onPress, onRemove }: ChipProps): react_jsx_runtime.JSX.Element;
|
|
237
|
+
|
|
238
|
+
declare function ChipGroup<ValueGeneric extends string>(props: ChipGroupProps<ValueGeneric>): react_jsx_runtime.JSX.Element;
|
|
239
|
+
|
|
240
|
+
declare const Chip: typeof Chip$1 & {
|
|
241
|
+
Group: typeof ChipGroup;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
export { Chip, type ChipAccessibilityRole, type ChipGroupMultipleProps, type ChipGroupOption, type ChipGroupProps, type ChipGroupSingleProps, type ChipProps, type ChipSelection, type ChipSize, type ChipSizeConfig, type ChipSizeName, sizeMap as chipSizes };
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
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,6 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mobilestock-native/chip",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"@mobilestock-native/clickable": "^1.1.1",
|
|
7
|
+
"@mobilestock-native/container": "^1.4.0",
|
|
8
|
+
"@mobilestock-native/tools": "^0.1.0",
|
|
9
|
+
"@mobilestock-native/icons": "^0.9.0",
|
|
10
|
+
"@mobilestock-native/typography": "^0.1.3"
|
|
11
|
+
},
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"react": "18.2.0",
|
|
14
|
+
"react-native": "0.74.5",
|
|
15
|
+
"styled-components": "^6.1.8"
|
|
16
|
+
}
|
|
6
17
|
}
|
package/README.md
DELETED