@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,315 @@
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/switch/index.ts
31
+ var switch_exports = {};
32
+ __export(switch_exports, {
33
+ Switch: () => Switch
34
+ });
35
+ module.exports = __toCommonJS(switch_exports);
36
+
37
+ // src/switch/Switch.tsx
38
+ var import_MaterialCommunityIcons = __toESM(require("@expo/vector-icons/MaterialCommunityIcons"));
39
+ var import_react = require("react");
40
+ var import_react_native2 = require("react-native");
41
+ var import_core = require("@onlynative/core");
42
+
43
+ // src/switch/styles.ts
44
+ var import_react_native = 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/switch/styles.ts
91
+ function getColors(theme, selected) {
92
+ const disabledOnSurface12 = alphaColor(theme.colors.onSurface, 0.12);
93
+ const disabledOnSurface38 = alphaColor(theme.colors.onSurface, 0.38);
94
+ if (selected) {
95
+ return {
96
+ trackColor: theme.colors.primary,
97
+ thumbColor: theme.colors.onPrimary,
98
+ iconColor: theme.colors.onPrimaryContainer,
99
+ hoveredTrackColor: blendColor(
100
+ theme.colors.primary,
101
+ theme.colors.onPrimary,
102
+ theme.stateLayer.hoveredOpacity
103
+ ),
104
+ pressedTrackColor: blendColor(
105
+ theme.colors.primary,
106
+ theme.colors.onPrimary,
107
+ theme.stateLayer.pressedOpacity
108
+ ),
109
+ borderColor: "transparent",
110
+ borderWidth: 0,
111
+ disabledTrackColor: disabledOnSurface12,
112
+ disabledThumbColor: theme.colors.surface,
113
+ disabledBorderColor: "transparent",
114
+ disabledBorderWidth: 0
115
+ };
116
+ }
117
+ return {
118
+ trackColor: theme.colors.surfaceContainerHighest,
119
+ thumbColor: theme.colors.outline,
120
+ iconColor: theme.colors.surfaceContainerHighest,
121
+ hoveredTrackColor: blendColor(
122
+ theme.colors.surfaceContainerHighest,
123
+ theme.colors.onSurface,
124
+ theme.stateLayer.hoveredOpacity
125
+ ),
126
+ pressedTrackColor: blendColor(
127
+ theme.colors.surfaceContainerHighest,
128
+ theme.colors.onSurface,
129
+ theme.stateLayer.pressedOpacity
130
+ ),
131
+ borderColor: theme.colors.outline,
132
+ borderWidth: 2,
133
+ disabledTrackColor: disabledOnSurface12,
134
+ disabledThumbColor: disabledOnSurface38,
135
+ disabledBorderColor: disabledOnSurface12,
136
+ disabledBorderWidth: 2
137
+ };
138
+ }
139
+ function applyColorOverrides(theme, colors, containerColor, contentColor) {
140
+ if (!containerColor && !contentColor) return colors;
141
+ const result = { ...colors };
142
+ if (contentColor) {
143
+ result.thumbColor = contentColor;
144
+ result.iconColor = contentColor;
145
+ }
146
+ if (containerColor) {
147
+ const overlay = contentColor != null ? contentColor : colors.thumbColor;
148
+ result.trackColor = containerColor;
149
+ result.borderColor = containerColor;
150
+ result.hoveredTrackColor = blendColor(
151
+ containerColor,
152
+ overlay,
153
+ theme.stateLayer.hoveredOpacity
154
+ );
155
+ result.pressedTrackColor = blendColor(
156
+ containerColor,
157
+ overlay,
158
+ theme.stateLayer.pressedOpacity
159
+ );
160
+ if (contentColor) {
161
+ result.iconColor = containerColor;
162
+ }
163
+ }
164
+ return result;
165
+ }
166
+ function createStyles(theme, selected, hasIcon, containerColor, contentColor) {
167
+ const colors = applyColorOverrides(
168
+ theme,
169
+ getColors(theme, selected),
170
+ containerColor,
171
+ contentColor
172
+ );
173
+ const thumbSize = selected || hasIcon ? 24 : 16;
174
+ const trackWidth = 52;
175
+ const trackHeight = 32;
176
+ const trackPadding = 4;
177
+ const thumbOffset = selected ? trackWidth - trackPadding - thumbSize : trackPadding;
178
+ return import_react_native.StyleSheet.create({
179
+ track: {
180
+ width: trackWidth,
181
+ height: trackHeight,
182
+ borderRadius: trackHeight / 2,
183
+ backgroundColor: colors.trackColor,
184
+ borderColor: colors.borderColor,
185
+ borderWidth: colors.borderWidth,
186
+ justifyContent: "center",
187
+ cursor: "pointer"
188
+ },
189
+ hoveredTrack: {
190
+ backgroundColor: colors.hoveredTrackColor
191
+ },
192
+ pressedTrack: {
193
+ backgroundColor: colors.pressedTrackColor
194
+ },
195
+ disabledTrack: {
196
+ backgroundColor: colors.disabledTrackColor,
197
+ borderColor: colors.disabledBorderColor,
198
+ borderWidth: colors.disabledBorderWidth,
199
+ cursor: "auto"
200
+ },
201
+ thumb: {
202
+ width: thumbSize,
203
+ height: thumbSize,
204
+ borderRadius: thumbSize / 2,
205
+ backgroundColor: colors.thumbColor,
206
+ marginStart: thumbOffset,
207
+ alignItems: "center",
208
+ justifyContent: "center"
209
+ },
210
+ disabledThumb: {
211
+ backgroundColor: colors.disabledThumbColor
212
+ },
213
+ iconColor: {
214
+ color: colors.iconColor
215
+ },
216
+ disabledIconColor: {
217
+ color: alphaColor(theme.colors.onSurface, 0.38)
218
+ }
219
+ });
220
+ }
221
+
222
+ // src/switch/Switch.tsx
223
+ var import_jsx_runtime = require("react/jsx-runtime");
224
+ function resolveStyle(trackStyle, hoveredTrackStyle, pressedTrackStyle, disabledTrackStyle, disabled, style) {
225
+ if (typeof style === "function") {
226
+ return (state) => [
227
+ trackStyle,
228
+ state.hovered && !state.pressed && !disabled ? hoveredTrackStyle : void 0,
229
+ state.pressed && !disabled ? pressedTrackStyle : void 0,
230
+ disabled ? disabledTrackStyle : void 0,
231
+ style(state)
232
+ ];
233
+ }
234
+ return (state) => [
235
+ trackStyle,
236
+ state.hovered && !state.pressed && !disabled ? hoveredTrackStyle : void 0,
237
+ state.pressed && !disabled ? pressedTrackStyle : void 0,
238
+ disabled ? disabledTrackStyle : void 0,
239
+ style
240
+ ];
241
+ }
242
+ function Switch({
243
+ style,
244
+ value = false,
245
+ onValueChange,
246
+ selectedIcon = "check",
247
+ unselectedIcon,
248
+ containerColor,
249
+ contentColor,
250
+ disabled = false,
251
+ ...props
252
+ }) {
253
+ const isDisabled = Boolean(disabled);
254
+ const isSelected = Boolean(value);
255
+ const hasIcon = isSelected || Boolean(unselectedIcon);
256
+ const theme = (0, import_core.useTheme)();
257
+ const styles = (0, import_react.useMemo)(
258
+ () => createStyles(theme, isSelected, hasIcon, containerColor, contentColor),
259
+ [theme, isSelected, hasIcon, containerColor, contentColor]
260
+ );
261
+ const resolvedIconColor = (0, import_react.useMemo)(() => {
262
+ const base = import_react_native2.StyleSheet.flatten([
263
+ styles.iconColor,
264
+ isDisabled ? styles.disabledIconColor : void 0
265
+ ]);
266
+ return typeof (base == null ? void 0 : base.color) === "string" ? base.color : void 0;
267
+ }, [styles.iconColor, styles.disabledIconColor, isDisabled]);
268
+ const handlePress = () => {
269
+ if (!isDisabled) {
270
+ onValueChange == null ? void 0 : onValueChange(!isSelected);
271
+ }
272
+ };
273
+ const iconName = isSelected ? selectedIcon : unselectedIcon;
274
+ const iconSize = 16;
275
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
276
+ import_react_native2.Pressable,
277
+ {
278
+ ...props,
279
+ accessibilityRole: "switch",
280
+ accessibilityState: {
281
+ disabled: isDisabled,
282
+ checked: isSelected
283
+ },
284
+ hitSlop: import_react_native2.Platform.OS === "web" ? void 0 : 4,
285
+ disabled: isDisabled,
286
+ onPress: handlePress,
287
+ style: resolveStyle(
288
+ styles.track,
289
+ styles.hoveredTrack,
290
+ styles.pressedTrack,
291
+ styles.disabledTrack,
292
+ isDisabled,
293
+ style
294
+ ),
295
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
296
+ import_react_native2.View,
297
+ {
298
+ style: [styles.thumb, isDisabled ? styles.disabledThumb : void 0],
299
+ children: iconName ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
300
+ import_MaterialCommunityIcons.default,
301
+ {
302
+ name: iconName,
303
+ size: iconSize,
304
+ color: resolvedIconColor
305
+ }
306
+ ) : null
307
+ }
308
+ )
309
+ }
310
+ );
311
+ }
312
+ // Annotate the CommonJS export names for ESM import in node:
313
+ 0 && (module.exports = {
314
+ Switch
315
+ });
@@ -0,0 +1,52 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import MaterialCommunityIcons from '@expo/vector-icons/MaterialCommunityIcons';
3
+ import { ComponentProps } from 'react';
4
+ import { TextInputProps, StyleProp, TextStyle } from 'react-native';
5
+
6
+ /** Visual container style for the text field. */
7
+ type TextFieldVariant = 'filled' | 'outlined';
8
+ interface TextFieldProps extends Omit<TextInputProps, 'placeholderTextColor' | 'editable'> {
9
+ /** Floating label text. Animates above the input when focused or filled. */
10
+ label?: string;
11
+ /**
12
+ * Container style.
13
+ * @default 'filled'
14
+ */
15
+ variant?: TextFieldVariant;
16
+ /** Helper text displayed below the field. Hidden when `error` or `errorText` is active. */
17
+ supportingText?: string;
18
+ /** Error message. When provided, implicitly sets `error` to `true` and replaces `supportingText`. */
19
+ errorText?: string;
20
+ /**
21
+ * When `true`, renders the field in error state with error colors.
22
+ * @default false
23
+ */
24
+ error?: boolean;
25
+ /**
26
+ * Disables text input and reduces opacity.
27
+ * @default false
28
+ */
29
+ disabled?: boolean;
30
+ /** MaterialCommunityIcons icon name rendered at the start of the field. */
31
+ leadingIcon?: ComponentProps<typeof MaterialCommunityIcons>['name'];
32
+ /** MaterialCommunityIcons icon name rendered at the end of the field. */
33
+ trailingIcon?: ComponentProps<typeof MaterialCommunityIcons>['name'];
34
+ /** Called when the trailing icon is pressed. */
35
+ onTrailingIconPress?: () => void;
36
+ /**
37
+ * Override the container (background) color.
38
+ * Disabled state still uses the standard disabled appearance.
39
+ */
40
+ containerColor?: string;
41
+ /**
42
+ * Override the content (input text and icon) color.
43
+ * Error and disabled states take precedence.
44
+ */
45
+ contentColor?: string;
46
+ /** Additional style applied to the text input element. */
47
+ inputStyle?: StyleProp<TextStyle>;
48
+ }
49
+
50
+ declare function TextField({ value, onChangeText, label, placeholder, variant, supportingText, errorText, error, disabled, leadingIcon, trailingIcon, onTrailingIconPress, multiline, onFocus, onBlur, style, containerColor, contentColor, inputStyle, ...textInputProps }: TextFieldProps): react_jsx_runtime.JSX.Element;
51
+
52
+ export { TextField, type TextFieldProps, type TextFieldVariant };