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