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