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