@onlynative/components 0.0.0-alpha.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.
@@ -0,0 +1,467 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/chip/index.ts
21
+ var chip_exports = {};
22
+ __export(chip_exports, {
23
+ Chip: () => Chip
24
+ });
25
+ module.exports = __toCommonJS(chip_exports);
26
+
27
+ // src/chip/Chip.tsx
28
+ var import_react = require("react");
29
+ var import_react_native4 = require("react-native");
30
+ var import_core = require("@onlynative/core");
31
+
32
+ // ../utils/dist/chunk-OQRDRRQA.mjs
33
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
34
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
35
+ }) : x)(function(x) {
36
+ if (typeof require !== "undefined") return require.apply(this, arguments);
37
+ throw Error('Dynamic require of "' + x + '" is not supported');
38
+ });
39
+
40
+ // ../utils/dist/index.mjs
41
+ var import_react_native = require("react-native");
42
+ var import_react_native2 = require("react-native");
43
+ function parseHexColor(color) {
44
+ const normalized = color.replace("#", "");
45
+ if (normalized.length !== 6 && normalized.length !== 8) {
46
+ return null;
47
+ }
48
+ const r = Number.parseInt(normalized.slice(0, 2), 16);
49
+ const g = Number.parseInt(normalized.slice(2, 4), 16);
50
+ const b = Number.parseInt(normalized.slice(4, 6), 16);
51
+ if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {
52
+ return null;
53
+ }
54
+ return { r, g, b };
55
+ }
56
+ function clampAlpha(alpha) {
57
+ return Math.max(0, Math.min(1, alpha));
58
+ }
59
+ function alphaColor(color, alpha) {
60
+ const channels = parseHexColor(color);
61
+ const boundedAlpha = clampAlpha(alpha);
62
+ if (!channels) {
63
+ return color;
64
+ }
65
+ return `rgba(${channels.r}, ${channels.g}, ${channels.b}, ${boundedAlpha})`;
66
+ }
67
+ function blendColor(base, overlay, overlayAlpha) {
68
+ const baseChannels = parseHexColor(base);
69
+ const overlayChannels = parseHexColor(overlay);
70
+ const boundedAlpha = clampAlpha(overlayAlpha);
71
+ if (!baseChannels || !overlayChannels) {
72
+ return alphaColor(overlay, boundedAlpha);
73
+ }
74
+ const r = Math.round(
75
+ (1 - boundedAlpha) * baseChannels.r + boundedAlpha * overlayChannels.r
76
+ );
77
+ const g = Math.round(
78
+ (1 - boundedAlpha) * baseChannels.g + boundedAlpha * overlayChannels.g
79
+ );
80
+ const b = Math.round(
81
+ (1 - boundedAlpha) * baseChannels.b + boundedAlpha * overlayChannels.b
82
+ );
83
+ return `rgb(${r}, ${g}, ${b})`;
84
+ }
85
+ function elevationStyle(level) {
86
+ if (import_react_native.Platform.OS === "web") {
87
+ const { shadowOffset, shadowOpacity, shadowRadius } = level;
88
+ if (shadowOpacity === 0) {
89
+ return { boxShadow: "none" };
90
+ }
91
+ return {
92
+ boxShadow: `${shadowOffset.width}px ${shadowOffset.height}px ${shadowRadius}px rgba(0, 0, 0, ${shadowOpacity})`
93
+ };
94
+ }
95
+ return {
96
+ shadowColor: level.shadowColor,
97
+ shadowOffset: {
98
+ width: level.shadowOffset.width,
99
+ height: level.shadowOffset.height
100
+ },
101
+ shadowOpacity: level.shadowOpacity,
102
+ shadowRadius: level.shadowRadius,
103
+ elevation: level.elevation
104
+ };
105
+ }
106
+ var _MCIcons = null;
107
+ var _resolved = false;
108
+ function getMaterialCommunityIcons() {
109
+ if (!_resolved) {
110
+ _resolved = true;
111
+ try {
112
+ const mod = __require("@expo/vector-icons/MaterialCommunityIcons");
113
+ _MCIcons = mod.default || mod;
114
+ } catch {
115
+ _MCIcons = null;
116
+ }
117
+ }
118
+ if (!_MCIcons) {
119
+ throw new Error(
120
+ "@expo/vector-icons is required for icon support. Install it with: npx expo install @expo/vector-icons"
121
+ );
122
+ }
123
+ return _MCIcons;
124
+ }
125
+
126
+ // src/chip/styles.ts
127
+ var import_react_native3 = require("react-native");
128
+ function getVariantColors(theme, variant, elevated, selected) {
129
+ const disabledContainerColor = alphaColor(theme.colors.onSurface, 0.12);
130
+ const disabledLabelColor = alphaColor(theme.colors.onSurface, 0.38);
131
+ const disabledOutlineColor = alphaColor(theme.colors.onSurface, 0.12);
132
+ if (variant === "filter" && selected) {
133
+ return {
134
+ backgroundColor: theme.colors.secondaryContainer,
135
+ textColor: theme.colors.onSecondaryContainer,
136
+ borderColor: "transparent",
137
+ borderWidth: 0,
138
+ hoveredBackgroundColor: blendColor(
139
+ theme.colors.secondaryContainer,
140
+ theme.colors.onSecondaryContainer,
141
+ theme.stateLayer.hoveredOpacity
142
+ ),
143
+ pressedBackgroundColor: blendColor(
144
+ theme.colors.secondaryContainer,
145
+ theme.colors.onSecondaryContainer,
146
+ theme.stateLayer.pressedOpacity
147
+ ),
148
+ disabledBackgroundColor: disabledContainerColor,
149
+ disabledTextColor: disabledLabelColor,
150
+ disabledBorderColor: "transparent"
151
+ };
152
+ }
153
+ if (elevated && variant !== "input") {
154
+ const textColor2 = variant === "assist" ? theme.colors.onSurface : theme.colors.onSurfaceVariant;
155
+ return {
156
+ backgroundColor: theme.colors.surfaceContainerLow,
157
+ textColor: textColor2,
158
+ borderColor: "transparent",
159
+ borderWidth: 0,
160
+ hoveredBackgroundColor: blendColor(
161
+ theme.colors.surfaceContainerLow,
162
+ textColor2,
163
+ theme.stateLayer.hoveredOpacity
164
+ ),
165
+ pressedBackgroundColor: blendColor(
166
+ theme.colors.surfaceContainerLow,
167
+ textColor2,
168
+ theme.stateLayer.pressedOpacity
169
+ ),
170
+ disabledBackgroundColor: disabledContainerColor,
171
+ disabledTextColor: disabledLabelColor,
172
+ disabledBorderColor: "transparent"
173
+ };
174
+ }
175
+ const textColor = variant === "assist" ? theme.colors.onSurface : theme.colors.onSurfaceVariant;
176
+ return {
177
+ backgroundColor: theme.colors.surface,
178
+ textColor,
179
+ borderColor: theme.colors.outline,
180
+ borderWidth: 1,
181
+ hoveredBackgroundColor: blendColor(
182
+ theme.colors.surface,
183
+ textColor,
184
+ theme.stateLayer.hoveredOpacity
185
+ ),
186
+ pressedBackgroundColor: blendColor(
187
+ theme.colors.surface,
188
+ textColor,
189
+ theme.stateLayer.pressedOpacity
190
+ ),
191
+ disabledBackgroundColor: disabledContainerColor,
192
+ disabledTextColor: disabledLabelColor,
193
+ disabledBorderColor: disabledOutlineColor
194
+ };
195
+ }
196
+ function applyColorOverrides(theme, colors, containerColor, contentColor) {
197
+ if (!containerColor && !contentColor) return colors;
198
+ const result = { ...colors };
199
+ if (contentColor) {
200
+ result.textColor = contentColor;
201
+ }
202
+ if (containerColor) {
203
+ const overlay = contentColor != null ? contentColor : colors.textColor;
204
+ result.backgroundColor = containerColor;
205
+ result.borderColor = containerColor;
206
+ result.hoveredBackgroundColor = blendColor(
207
+ containerColor,
208
+ overlay,
209
+ theme.stateLayer.hoveredOpacity
210
+ );
211
+ result.pressedBackgroundColor = blendColor(
212
+ containerColor,
213
+ overlay,
214
+ theme.stateLayer.pressedOpacity
215
+ );
216
+ } else if (contentColor) {
217
+ if (colors.backgroundColor === "transparent") {
218
+ result.hoveredBackgroundColor = alphaColor(
219
+ contentColor,
220
+ theme.stateLayer.hoveredOpacity
221
+ );
222
+ result.pressedBackgroundColor = alphaColor(
223
+ contentColor,
224
+ theme.stateLayer.pressedOpacity
225
+ );
226
+ } else {
227
+ result.hoveredBackgroundColor = blendColor(
228
+ colors.backgroundColor,
229
+ contentColor,
230
+ theme.stateLayer.hoveredOpacity
231
+ );
232
+ result.pressedBackgroundColor = blendColor(
233
+ colors.backgroundColor,
234
+ contentColor,
235
+ theme.stateLayer.pressedOpacity
236
+ );
237
+ }
238
+ }
239
+ return result;
240
+ }
241
+ function createStyles(theme, variant, elevated, selected, hasLeadingContent, hasTrailingContent, containerColor, contentColor) {
242
+ const baseColors = getVariantColors(theme, variant, elevated, selected);
243
+ const colors = applyColorOverrides(
244
+ theme,
245
+ baseColors,
246
+ containerColor,
247
+ contentColor
248
+ );
249
+ const labelStyle = theme.typography.labelLarge;
250
+ const elevationLevel0 = elevationStyle(theme.elevation.level0);
251
+ const elevationLevel1 = elevationStyle(theme.elevation.level1);
252
+ const elevationLevel2 = elevationStyle(theme.elevation.level2);
253
+ const isElevated = elevated && variant !== "input";
254
+ const baseElevation = isElevated ? elevationLevel1 : elevationLevel0;
255
+ return import_react_native3.StyleSheet.create({
256
+ container: {
257
+ alignSelf: "flex-start",
258
+ alignItems: "center",
259
+ flexDirection: "row",
260
+ height: 32,
261
+ paddingStart: hasLeadingContent ? 8 : 16,
262
+ paddingEnd: hasTrailingContent ? 8 : 16,
263
+ borderRadius: theme.shape.cornerSmall,
264
+ backgroundColor: colors.backgroundColor,
265
+ borderColor: colors.borderColor,
266
+ borderWidth: colors.borderWidth,
267
+ cursor: "pointer",
268
+ ...baseElevation
269
+ },
270
+ hoveredContainer: {
271
+ backgroundColor: colors.hoveredBackgroundColor,
272
+ ...isElevated ? elevationLevel2 : void 0
273
+ },
274
+ pressedContainer: {
275
+ backgroundColor: colors.pressedBackgroundColor
276
+ },
277
+ disabledContainer: {
278
+ backgroundColor: colors.disabledBackgroundColor,
279
+ borderColor: colors.disabledBorderColor,
280
+ cursor: "auto",
281
+ ...elevationLevel0
282
+ },
283
+ label: {
284
+ fontFamily: labelStyle.fontFamily,
285
+ fontSize: labelStyle.fontSize,
286
+ lineHeight: labelStyle.lineHeight,
287
+ fontWeight: labelStyle.fontWeight,
288
+ letterSpacing: labelStyle.letterSpacing,
289
+ color: colors.textColor
290
+ },
291
+ disabledLabel: {
292
+ color: colors.disabledTextColor
293
+ },
294
+ leadingIcon: {
295
+ marginEnd: theme.spacing.sm
296
+ },
297
+ avatar: {
298
+ marginEnd: theme.spacing.sm,
299
+ width: 24,
300
+ height: 24,
301
+ borderRadius: 12,
302
+ overflow: "hidden"
303
+ },
304
+ closeButton: {
305
+ marginStart: theme.spacing.sm
306
+ }
307
+ });
308
+ }
309
+
310
+ // src/chip/Chip.tsx
311
+ var import_jsx_runtime = require("react/jsx-runtime");
312
+ function resolveStyle(containerStyle, hoveredContainerStyle, pressedContainerStyle, disabledContainerStyle, disabled, style) {
313
+ if (typeof style === "function") {
314
+ return (state) => [
315
+ containerStyle,
316
+ state.hovered && !state.pressed && !disabled ? hoveredContainerStyle : void 0,
317
+ state.pressed && !disabled ? pressedContainerStyle : void 0,
318
+ disabled ? disabledContainerStyle : void 0,
319
+ style(state)
320
+ ];
321
+ }
322
+ return (state) => [
323
+ containerStyle,
324
+ state.hovered && !state.pressed && !disabled ? hoveredContainerStyle : void 0,
325
+ state.pressed && !disabled ? pressedContainerStyle : void 0,
326
+ disabled ? disabledContainerStyle : void 0,
327
+ style
328
+ ];
329
+ }
330
+ function Chip({
331
+ children,
332
+ style,
333
+ variant = "assist",
334
+ elevated = false,
335
+ selected = false,
336
+ leadingIcon,
337
+ iconSize = 18,
338
+ avatar,
339
+ onClose,
340
+ containerColor,
341
+ contentColor,
342
+ labelStyle: labelStyleOverride,
343
+ disabled = false,
344
+ ...props
345
+ }) {
346
+ const isDisabled = Boolean(disabled);
347
+ const isSelected = variant === "filter" ? Boolean(selected) : false;
348
+ const showCloseIcon = onClose !== void 0 && (variant === "input" || variant === "filter" && isSelected);
349
+ const hasLeadingContent = Boolean(
350
+ variant === "input" && avatar || leadingIcon || variant === "filter" && isSelected
351
+ );
352
+ const needsIcons = Boolean(leadingIcon) || variant === "filter" && isSelected || showCloseIcon;
353
+ const MaterialCommunityIcons = needsIcons ? getMaterialCommunityIcons() : null;
354
+ const theme = (0, import_core.useTheme)();
355
+ const styles = (0, import_react.useMemo)(
356
+ () => createStyles(
357
+ theme,
358
+ variant,
359
+ elevated,
360
+ isSelected,
361
+ hasLeadingContent,
362
+ showCloseIcon,
363
+ containerColor,
364
+ contentColor
365
+ ),
366
+ [
367
+ theme,
368
+ variant,
369
+ elevated,
370
+ isSelected,
371
+ hasLeadingContent,
372
+ showCloseIcon,
373
+ containerColor,
374
+ contentColor
375
+ ]
376
+ );
377
+ const resolvedIconColor = (0, import_react.useMemo)(() => {
378
+ const base = import_react_native4.StyleSheet.flatten([
379
+ styles.label,
380
+ isDisabled ? styles.disabledLabel : void 0
381
+ ]);
382
+ return typeof (base == null ? void 0 : base.color) === "string" ? base.color : void 0;
383
+ }, [styles.label, styles.disabledLabel, isDisabled]);
384
+ const computedLabelStyle = (0, import_react.useMemo)(
385
+ () => [
386
+ styles.label,
387
+ isDisabled ? styles.disabledLabel : void 0,
388
+ labelStyleOverride
389
+ ],
390
+ [isDisabled, styles.disabledLabel, styles.label, labelStyleOverride]
391
+ );
392
+ const renderLeadingContent = () => {
393
+ if (variant === "input" && avatar) {
394
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native4.View, { style: styles.avatar, children: avatar });
395
+ }
396
+ if (leadingIcon) {
397
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
398
+ MaterialCommunityIcons,
399
+ {
400
+ name: leadingIcon,
401
+ size: iconSize,
402
+ color: resolvedIconColor,
403
+ style: styles.leadingIcon
404
+ }
405
+ );
406
+ }
407
+ if (variant === "filter" && isSelected) {
408
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
409
+ MaterialCommunityIcons,
410
+ {
411
+ name: "check",
412
+ size: iconSize,
413
+ color: resolvedIconColor,
414
+ style: styles.leadingIcon
415
+ }
416
+ );
417
+ }
418
+ return null;
419
+ };
420
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
421
+ import_react_native4.Pressable,
422
+ {
423
+ ...props,
424
+ accessibilityRole: "button",
425
+ accessibilityState: {
426
+ disabled: isDisabled,
427
+ ...variant === "filter" ? { selected: isSelected } : void 0
428
+ },
429
+ hitSlop: import_react_native4.Platform.OS === "web" ? void 0 : 4,
430
+ disabled: isDisabled,
431
+ style: resolveStyle(
432
+ styles.container,
433
+ styles.hoveredContainer,
434
+ styles.pressedContainer,
435
+ styles.disabledContainer,
436
+ isDisabled,
437
+ style
438
+ ),
439
+ children: [
440
+ renderLeadingContent(),
441
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native4.Text, { style: computedLabelStyle, children }),
442
+ showCloseIcon ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
443
+ import_react_native4.Pressable,
444
+ {
445
+ onPress: onClose,
446
+ accessibilityRole: "button",
447
+ accessibilityLabel: "Remove",
448
+ hitSlop: 4,
449
+ style: styles.closeButton,
450
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
451
+ MaterialCommunityIcons,
452
+ {
453
+ name: "close",
454
+ size: iconSize,
455
+ color: resolvedIconColor
456
+ }
457
+ )
458
+ }
459
+ ) : null
460
+ ]
461
+ }
462
+ );
463
+ }
464
+ // Annotate the CommonJS export names for ESM import in node:
465
+ 0 && (module.exports = {
466
+ Chip
467
+ });
@@ -0,0 +1,10 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { I as IconButtonProps } from '../types-D3hlyvz-.js';
3
+ export { a as IconButtonSize, b as IconButtonVariant } from '../types-D3hlyvz-.js';
4
+ import '@expo/vector-icons/MaterialCommunityIcons';
5
+ import 'react';
6
+ import 'react-native';
7
+
8
+ declare function IconButton({ icon, selectedIcon, iconColor, contentColor, containerColor, style, onPress, disabled, variant, selected, size, hitSlop, accessibilityLabel, ...props }: IconButtonProps): react_jsx_runtime.JSX.Element;
9
+
10
+ export { IconButton, IconButtonProps };