@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,575 @@
|
|
|
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/icon-button/index.ts
|
|
31
|
+
var icon_button_exports = {};
|
|
32
|
+
__export(icon_button_exports, {
|
|
33
|
+
IconButton: () => IconButton
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(icon_button_exports);
|
|
36
|
+
|
|
37
|
+
// src/icon-button/IconButton.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/icon-button/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/icon-button/styles.ts
|
|
91
|
+
function createStyles(theme) {
|
|
92
|
+
const disabledContainerColor = alphaColor(theme.colors.onSurface, 0.12);
|
|
93
|
+
const disabledOutlineColor = alphaColor(theme.colors.onSurface, 0.12);
|
|
94
|
+
const toggleUnselectedContainerColor = theme.colors.surfaceContainerHighest;
|
|
95
|
+
return import_react_native.StyleSheet.create({
|
|
96
|
+
container: {
|
|
97
|
+
borderRadius: theme.shape.cornerFull,
|
|
98
|
+
alignItems: "center",
|
|
99
|
+
justifyContent: "center",
|
|
100
|
+
cursor: "pointer"
|
|
101
|
+
},
|
|
102
|
+
sizeSmall: {
|
|
103
|
+
width: 32,
|
|
104
|
+
height: 32
|
|
105
|
+
},
|
|
106
|
+
sizeMedium: {
|
|
107
|
+
width: 40,
|
|
108
|
+
height: 40
|
|
109
|
+
},
|
|
110
|
+
sizeLarge: {
|
|
111
|
+
width: 48,
|
|
112
|
+
height: 48
|
|
113
|
+
},
|
|
114
|
+
colorFilled: {
|
|
115
|
+
backgroundColor: theme.colors.primary,
|
|
116
|
+
borderColor: theme.colors.primary,
|
|
117
|
+
borderWidth: 0
|
|
118
|
+
},
|
|
119
|
+
colorFilledToggleUnselected: {
|
|
120
|
+
backgroundColor: toggleUnselectedContainerColor,
|
|
121
|
+
borderColor: toggleUnselectedContainerColor,
|
|
122
|
+
borderWidth: 0
|
|
123
|
+
},
|
|
124
|
+
colorFilledToggleSelected: {
|
|
125
|
+
backgroundColor: theme.colors.primary,
|
|
126
|
+
borderColor: theme.colors.primary,
|
|
127
|
+
borderWidth: 0
|
|
128
|
+
},
|
|
129
|
+
colorTonal: {
|
|
130
|
+
backgroundColor: theme.colors.secondaryContainer,
|
|
131
|
+
borderColor: theme.colors.secondaryContainer,
|
|
132
|
+
borderWidth: 0
|
|
133
|
+
},
|
|
134
|
+
colorTonalToggleUnselected: {
|
|
135
|
+
backgroundColor: toggleUnselectedContainerColor,
|
|
136
|
+
borderColor: toggleUnselectedContainerColor,
|
|
137
|
+
borderWidth: 0
|
|
138
|
+
},
|
|
139
|
+
colorTonalToggleSelected: {
|
|
140
|
+
backgroundColor: theme.colors.secondaryContainer,
|
|
141
|
+
borderColor: theme.colors.secondaryContainer,
|
|
142
|
+
borderWidth: 0
|
|
143
|
+
},
|
|
144
|
+
colorOutlined: {
|
|
145
|
+
borderColor: theme.colors.outline,
|
|
146
|
+
borderWidth: 1
|
|
147
|
+
},
|
|
148
|
+
colorOutlinedToggleSelected: {
|
|
149
|
+
backgroundColor: theme.colors.inverseSurface,
|
|
150
|
+
borderColor: theme.colors.inverseSurface,
|
|
151
|
+
borderWidth: 0
|
|
152
|
+
},
|
|
153
|
+
colorStandard: {
|
|
154
|
+
borderWidth: 0
|
|
155
|
+
},
|
|
156
|
+
colorStandardToggleSelected: {
|
|
157
|
+
borderWidth: 0
|
|
158
|
+
},
|
|
159
|
+
// Hover states (M3: 8% state layer)
|
|
160
|
+
hoveredFilled: {
|
|
161
|
+
backgroundColor: blendColor(
|
|
162
|
+
theme.colors.primary,
|
|
163
|
+
theme.colors.onPrimary,
|
|
164
|
+
theme.stateLayer.hoveredOpacity
|
|
165
|
+
)
|
|
166
|
+
},
|
|
167
|
+
hoveredFilledToggleUnselected: {
|
|
168
|
+
backgroundColor: blendColor(
|
|
169
|
+
toggleUnselectedContainerColor,
|
|
170
|
+
theme.colors.primary,
|
|
171
|
+
theme.stateLayer.hoveredOpacity
|
|
172
|
+
)
|
|
173
|
+
},
|
|
174
|
+
hoveredFilledToggleSelected: {
|
|
175
|
+
backgroundColor: blendColor(
|
|
176
|
+
theme.colors.primary,
|
|
177
|
+
theme.colors.onPrimary,
|
|
178
|
+
theme.stateLayer.hoveredOpacity
|
|
179
|
+
)
|
|
180
|
+
},
|
|
181
|
+
hoveredTonal: {
|
|
182
|
+
backgroundColor: blendColor(
|
|
183
|
+
theme.colors.secondaryContainer,
|
|
184
|
+
theme.colors.onSecondaryContainer,
|
|
185
|
+
theme.stateLayer.hoveredOpacity
|
|
186
|
+
)
|
|
187
|
+
},
|
|
188
|
+
hoveredTonalToggleUnselected: {
|
|
189
|
+
backgroundColor: blendColor(
|
|
190
|
+
toggleUnselectedContainerColor,
|
|
191
|
+
theme.colors.onSurfaceVariant,
|
|
192
|
+
theme.stateLayer.hoveredOpacity
|
|
193
|
+
)
|
|
194
|
+
},
|
|
195
|
+
hoveredTonalToggleSelected: {
|
|
196
|
+
backgroundColor: blendColor(
|
|
197
|
+
theme.colors.secondaryContainer,
|
|
198
|
+
theme.colors.onSecondaryContainer,
|
|
199
|
+
theme.stateLayer.hoveredOpacity
|
|
200
|
+
)
|
|
201
|
+
},
|
|
202
|
+
hoveredOutlined: {
|
|
203
|
+
backgroundColor: alphaColor(
|
|
204
|
+
theme.colors.onSurfaceVariant,
|
|
205
|
+
theme.stateLayer.hoveredOpacity
|
|
206
|
+
)
|
|
207
|
+
},
|
|
208
|
+
hoveredOutlinedToggleUnselected: {
|
|
209
|
+
backgroundColor: alphaColor(
|
|
210
|
+
theme.colors.onSurfaceVariant,
|
|
211
|
+
theme.stateLayer.hoveredOpacity
|
|
212
|
+
)
|
|
213
|
+
},
|
|
214
|
+
hoveredOutlinedToggleSelected: {
|
|
215
|
+
backgroundColor: blendColor(
|
|
216
|
+
theme.colors.inverseSurface,
|
|
217
|
+
theme.colors.inverseOnSurface,
|
|
218
|
+
theme.stateLayer.hoveredOpacity
|
|
219
|
+
)
|
|
220
|
+
},
|
|
221
|
+
hoveredStandard: {
|
|
222
|
+
backgroundColor: alphaColor(
|
|
223
|
+
theme.colors.onSurfaceVariant,
|
|
224
|
+
theme.stateLayer.hoveredOpacity
|
|
225
|
+
)
|
|
226
|
+
},
|
|
227
|
+
hoveredStandardToggleUnselected: {
|
|
228
|
+
backgroundColor: alphaColor(
|
|
229
|
+
theme.colors.onSurfaceVariant,
|
|
230
|
+
theme.stateLayer.hoveredOpacity
|
|
231
|
+
)
|
|
232
|
+
},
|
|
233
|
+
hoveredStandardToggleSelected: {
|
|
234
|
+
backgroundColor: alphaColor(
|
|
235
|
+
theme.colors.primary,
|
|
236
|
+
theme.stateLayer.hoveredOpacity
|
|
237
|
+
)
|
|
238
|
+
},
|
|
239
|
+
// Pressed states (M3: 12% state layer)
|
|
240
|
+
pressedFilled: {
|
|
241
|
+
backgroundColor: blendColor(
|
|
242
|
+
theme.colors.primary,
|
|
243
|
+
theme.colors.onPrimary,
|
|
244
|
+
theme.stateLayer.pressedOpacity
|
|
245
|
+
)
|
|
246
|
+
},
|
|
247
|
+
pressedFilledToggleUnselected: {
|
|
248
|
+
backgroundColor: blendColor(
|
|
249
|
+
toggleUnselectedContainerColor,
|
|
250
|
+
theme.colors.primary,
|
|
251
|
+
theme.stateLayer.pressedOpacity
|
|
252
|
+
)
|
|
253
|
+
},
|
|
254
|
+
pressedFilledToggleSelected: {
|
|
255
|
+
backgroundColor: blendColor(
|
|
256
|
+
theme.colors.primary,
|
|
257
|
+
theme.colors.onPrimary,
|
|
258
|
+
theme.stateLayer.pressedOpacity
|
|
259
|
+
)
|
|
260
|
+
},
|
|
261
|
+
pressedTonal: {
|
|
262
|
+
backgroundColor: blendColor(
|
|
263
|
+
theme.colors.secondaryContainer,
|
|
264
|
+
theme.colors.onSecondaryContainer,
|
|
265
|
+
theme.stateLayer.pressedOpacity
|
|
266
|
+
)
|
|
267
|
+
},
|
|
268
|
+
pressedTonalToggleUnselected: {
|
|
269
|
+
backgroundColor: blendColor(
|
|
270
|
+
toggleUnselectedContainerColor,
|
|
271
|
+
theme.colors.onSurfaceVariant,
|
|
272
|
+
theme.stateLayer.pressedOpacity
|
|
273
|
+
)
|
|
274
|
+
},
|
|
275
|
+
pressedTonalToggleSelected: {
|
|
276
|
+
backgroundColor: blendColor(
|
|
277
|
+
theme.colors.secondaryContainer,
|
|
278
|
+
theme.colors.onSecondaryContainer,
|
|
279
|
+
theme.stateLayer.pressedOpacity
|
|
280
|
+
)
|
|
281
|
+
},
|
|
282
|
+
pressedOutlined: {
|
|
283
|
+
backgroundColor: alphaColor(
|
|
284
|
+
theme.colors.onSurfaceVariant,
|
|
285
|
+
theme.stateLayer.pressedOpacity
|
|
286
|
+
)
|
|
287
|
+
},
|
|
288
|
+
pressedOutlinedToggleUnselected: {
|
|
289
|
+
backgroundColor: alphaColor(
|
|
290
|
+
theme.colors.onSurfaceVariant,
|
|
291
|
+
theme.stateLayer.pressedOpacity
|
|
292
|
+
)
|
|
293
|
+
},
|
|
294
|
+
pressedOutlinedToggleSelected: {
|
|
295
|
+
backgroundColor: blendColor(
|
|
296
|
+
theme.colors.inverseSurface,
|
|
297
|
+
theme.colors.inverseOnSurface,
|
|
298
|
+
theme.stateLayer.pressedOpacity
|
|
299
|
+
)
|
|
300
|
+
},
|
|
301
|
+
pressedStandard: {
|
|
302
|
+
backgroundColor: alphaColor(
|
|
303
|
+
theme.colors.onSurfaceVariant,
|
|
304
|
+
theme.stateLayer.pressedOpacity
|
|
305
|
+
)
|
|
306
|
+
},
|
|
307
|
+
pressedStandardToggleUnselected: {
|
|
308
|
+
backgroundColor: alphaColor(
|
|
309
|
+
theme.colors.onSurfaceVariant,
|
|
310
|
+
theme.stateLayer.pressedOpacity
|
|
311
|
+
)
|
|
312
|
+
},
|
|
313
|
+
pressedStandardToggleSelected: {
|
|
314
|
+
backgroundColor: alphaColor(
|
|
315
|
+
theme.colors.primary,
|
|
316
|
+
theme.stateLayer.pressedOpacity
|
|
317
|
+
)
|
|
318
|
+
},
|
|
319
|
+
// Disabled states
|
|
320
|
+
disabledFilled: {
|
|
321
|
+
backgroundColor: disabledContainerColor,
|
|
322
|
+
borderColor: disabledContainerColor,
|
|
323
|
+
cursor: "auto"
|
|
324
|
+
},
|
|
325
|
+
disabledTonal: {
|
|
326
|
+
backgroundColor: disabledContainerColor,
|
|
327
|
+
borderColor: disabledContainerColor,
|
|
328
|
+
cursor: "auto"
|
|
329
|
+
},
|
|
330
|
+
disabledOutlined: {
|
|
331
|
+
backgroundColor: "transparent",
|
|
332
|
+
borderColor: disabledOutlineColor,
|
|
333
|
+
cursor: "auto"
|
|
334
|
+
},
|
|
335
|
+
disabledStandard: {
|
|
336
|
+
backgroundColor: "transparent",
|
|
337
|
+
borderColor: "transparent",
|
|
338
|
+
cursor: "auto"
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// src/icon-button/IconButton.tsx
|
|
344
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
345
|
+
function getIconColor(variant, theme, disabled, isToggle, selected) {
|
|
346
|
+
if (disabled) {
|
|
347
|
+
return alphaColor(theme.colors.onSurface, 0.38);
|
|
348
|
+
}
|
|
349
|
+
if (isToggle) {
|
|
350
|
+
if (variant === "filled") {
|
|
351
|
+
return selected ? theme.colors.onPrimary : theme.colors.primary;
|
|
352
|
+
}
|
|
353
|
+
if (variant === "tonal") {
|
|
354
|
+
return selected ? theme.colors.onSecondaryContainer : theme.colors.onSurfaceVariant;
|
|
355
|
+
}
|
|
356
|
+
if (variant === "outlined") {
|
|
357
|
+
return selected ? theme.colors.inverseOnSurface : theme.colors.onSurfaceVariant;
|
|
358
|
+
}
|
|
359
|
+
return selected ? theme.colors.primary : theme.colors.onSurfaceVariant;
|
|
360
|
+
}
|
|
361
|
+
if (variant === "filled") {
|
|
362
|
+
return theme.colors.onPrimary;
|
|
363
|
+
}
|
|
364
|
+
if (variant === "tonal") {
|
|
365
|
+
return theme.colors.onSecondaryContainer;
|
|
366
|
+
}
|
|
367
|
+
return theme.colors.onSurfaceVariant;
|
|
368
|
+
}
|
|
369
|
+
function getColorStyle(styles, variant, isToggle, selected) {
|
|
370
|
+
if (isToggle) {
|
|
371
|
+
if (variant === "tonal") {
|
|
372
|
+
return selected ? styles.colorTonalToggleSelected : styles.colorTonalToggleUnselected;
|
|
373
|
+
}
|
|
374
|
+
if (variant === "outlined") {
|
|
375
|
+
return selected ? styles.colorOutlinedToggleSelected : styles.colorOutlined;
|
|
376
|
+
}
|
|
377
|
+
if (variant === "standard") {
|
|
378
|
+
return selected ? styles.colorStandardToggleSelected : styles.colorStandard;
|
|
379
|
+
}
|
|
380
|
+
return selected ? styles.colorFilledToggleSelected : styles.colorFilledToggleUnselected;
|
|
381
|
+
}
|
|
382
|
+
if (variant === "tonal") {
|
|
383
|
+
return styles.colorTonal;
|
|
384
|
+
}
|
|
385
|
+
if (variant === "outlined") {
|
|
386
|
+
return styles.colorOutlined;
|
|
387
|
+
}
|
|
388
|
+
if (variant === "standard") {
|
|
389
|
+
return styles.colorStandard;
|
|
390
|
+
}
|
|
391
|
+
return styles.colorFilled;
|
|
392
|
+
}
|
|
393
|
+
function getSizeStyle(styles, size) {
|
|
394
|
+
if (size === "small") {
|
|
395
|
+
return styles.sizeSmall;
|
|
396
|
+
}
|
|
397
|
+
if (size === "large") {
|
|
398
|
+
return styles.sizeLarge;
|
|
399
|
+
}
|
|
400
|
+
return styles.sizeMedium;
|
|
401
|
+
}
|
|
402
|
+
function getIconPixelSize(size) {
|
|
403
|
+
if (size === "small") {
|
|
404
|
+
return 18;
|
|
405
|
+
}
|
|
406
|
+
if (size === "large") {
|
|
407
|
+
return 28;
|
|
408
|
+
}
|
|
409
|
+
return 24;
|
|
410
|
+
}
|
|
411
|
+
function getDefaultHitSlop(size) {
|
|
412
|
+
if (size === "small") {
|
|
413
|
+
return 8;
|
|
414
|
+
}
|
|
415
|
+
if (size === "large") {
|
|
416
|
+
return 0;
|
|
417
|
+
}
|
|
418
|
+
return 4;
|
|
419
|
+
}
|
|
420
|
+
function getHoveredStyle(styles, variant, isToggle, selected) {
|
|
421
|
+
if (isToggle) {
|
|
422
|
+
if (variant === "tonal") {
|
|
423
|
+
return selected ? styles.hoveredTonalToggleSelected : styles.hoveredTonalToggleUnselected;
|
|
424
|
+
}
|
|
425
|
+
if (variant === "outlined") {
|
|
426
|
+
return selected ? styles.hoveredOutlinedToggleSelected : styles.hoveredOutlinedToggleUnselected;
|
|
427
|
+
}
|
|
428
|
+
if (variant === "standard") {
|
|
429
|
+
return selected ? styles.hoveredStandardToggleSelected : styles.hoveredStandardToggleUnselected;
|
|
430
|
+
}
|
|
431
|
+
return selected ? styles.hoveredFilledToggleSelected : styles.hoveredFilledToggleUnselected;
|
|
432
|
+
}
|
|
433
|
+
if (variant === "tonal") {
|
|
434
|
+
return styles.hoveredTonal;
|
|
435
|
+
}
|
|
436
|
+
if (variant === "outlined") {
|
|
437
|
+
return styles.hoveredOutlined;
|
|
438
|
+
}
|
|
439
|
+
if (variant === "standard") {
|
|
440
|
+
return styles.hoveredStandard;
|
|
441
|
+
}
|
|
442
|
+
return styles.hoveredFilled;
|
|
443
|
+
}
|
|
444
|
+
function getPressedStyle(styles, variant, isToggle, selected) {
|
|
445
|
+
if (isToggle) {
|
|
446
|
+
if (variant === "tonal") {
|
|
447
|
+
return selected ? styles.pressedTonalToggleSelected : styles.pressedTonalToggleUnselected;
|
|
448
|
+
}
|
|
449
|
+
if (variant === "outlined") {
|
|
450
|
+
return selected ? styles.pressedOutlinedToggleSelected : styles.pressedOutlinedToggleUnselected;
|
|
451
|
+
}
|
|
452
|
+
if (variant === "standard") {
|
|
453
|
+
return selected ? styles.pressedStandardToggleSelected : styles.pressedStandardToggleUnselected;
|
|
454
|
+
}
|
|
455
|
+
return selected ? styles.pressedFilledToggleSelected : styles.pressedFilledToggleUnselected;
|
|
456
|
+
}
|
|
457
|
+
if (variant === "tonal") {
|
|
458
|
+
return styles.pressedTonal;
|
|
459
|
+
}
|
|
460
|
+
if (variant === "outlined") {
|
|
461
|
+
return styles.pressedOutlined;
|
|
462
|
+
}
|
|
463
|
+
if (variant === "standard") {
|
|
464
|
+
return styles.pressedStandard;
|
|
465
|
+
}
|
|
466
|
+
return styles.pressedFilled;
|
|
467
|
+
}
|
|
468
|
+
function getDisabledStyle(styles, variant) {
|
|
469
|
+
if (variant === "tonal") {
|
|
470
|
+
return styles.disabledTonal;
|
|
471
|
+
}
|
|
472
|
+
if (variant === "outlined") {
|
|
473
|
+
return styles.disabledOutlined;
|
|
474
|
+
}
|
|
475
|
+
if (variant === "standard") {
|
|
476
|
+
return styles.disabledStandard;
|
|
477
|
+
}
|
|
478
|
+
return styles.disabledFilled;
|
|
479
|
+
}
|
|
480
|
+
function IconButton({
|
|
481
|
+
icon,
|
|
482
|
+
selectedIcon,
|
|
483
|
+
iconColor,
|
|
484
|
+
contentColor,
|
|
485
|
+
containerColor,
|
|
486
|
+
style,
|
|
487
|
+
onPress,
|
|
488
|
+
disabled = false,
|
|
489
|
+
variant = "filled",
|
|
490
|
+
selected,
|
|
491
|
+
size = "medium",
|
|
492
|
+
hitSlop,
|
|
493
|
+
accessibilityLabel,
|
|
494
|
+
...props
|
|
495
|
+
}) {
|
|
496
|
+
var _a;
|
|
497
|
+
const theme = (0, import_core.useTheme)();
|
|
498
|
+
const styles = (0, import_react.useMemo)(() => createStyles(theme), [theme]);
|
|
499
|
+
const isDisabled = Boolean(disabled);
|
|
500
|
+
const isToggle = selected !== void 0;
|
|
501
|
+
const isSelected = Boolean(selected);
|
|
502
|
+
const resolvedIconColor = (_a = contentColor != null ? contentColor : iconColor) != null ? _a : getIconColor(variant, theme, isDisabled, isToggle, isSelected);
|
|
503
|
+
const displayIcon = isToggle && isSelected && selectedIcon ? selectedIcon : icon;
|
|
504
|
+
const iconPixelSize = getIconPixelSize(size);
|
|
505
|
+
const accessibilityState = isToggle ? { disabled: isDisabled, selected: isSelected } : { disabled: isDisabled };
|
|
506
|
+
const containerOverrides = (0, import_react.useMemo)(() => {
|
|
507
|
+
if (!containerColor) return null;
|
|
508
|
+
const overlay = resolvedIconColor;
|
|
509
|
+
return {
|
|
510
|
+
base: {
|
|
511
|
+
backgroundColor: containerColor,
|
|
512
|
+
borderColor: containerColor,
|
|
513
|
+
borderWidth: 0
|
|
514
|
+
},
|
|
515
|
+
hovered: {
|
|
516
|
+
backgroundColor: blendColor(
|
|
517
|
+
containerColor,
|
|
518
|
+
overlay,
|
|
519
|
+
theme.stateLayer.hoveredOpacity
|
|
520
|
+
)
|
|
521
|
+
},
|
|
522
|
+
pressed: {
|
|
523
|
+
backgroundColor: blendColor(
|
|
524
|
+
containerColor,
|
|
525
|
+
overlay,
|
|
526
|
+
theme.stateLayer.pressedOpacity
|
|
527
|
+
)
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
}, [containerColor, resolvedIconColor, theme.stateLayer]);
|
|
531
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
532
|
+
import_react_native2.Pressable,
|
|
533
|
+
{
|
|
534
|
+
...props,
|
|
535
|
+
accessibilityRole: "button",
|
|
536
|
+
accessibilityLabel,
|
|
537
|
+
accessibilityState,
|
|
538
|
+
disabled: isDisabled,
|
|
539
|
+
hitSlop: hitSlop != null ? hitSlop : getDefaultHitSlop(size),
|
|
540
|
+
onPress,
|
|
541
|
+
style: ({
|
|
542
|
+
pressed,
|
|
543
|
+
hovered
|
|
544
|
+
}) => {
|
|
545
|
+
const base = [
|
|
546
|
+
styles.container,
|
|
547
|
+
getSizeStyle(styles, size),
|
|
548
|
+
getColorStyle(styles, variant, isToggle, isSelected),
|
|
549
|
+
containerOverrides == null ? void 0 : containerOverrides.base,
|
|
550
|
+
hovered && !pressed && !isDisabled ? containerOverrides ? containerOverrides.hovered : getHoveredStyle(styles, variant, isToggle, isSelected) : void 0,
|
|
551
|
+
pressed && !isDisabled ? containerOverrides ? containerOverrides.pressed : getPressedStyle(styles, variant, isToggle, isSelected) : void 0,
|
|
552
|
+
isDisabled ? getDisabledStyle(styles, variant) : void 0
|
|
553
|
+
];
|
|
554
|
+
if (typeof style === "function") {
|
|
555
|
+
base.push(style({ pressed }));
|
|
556
|
+
} else if (style) {
|
|
557
|
+
base.push(style);
|
|
558
|
+
}
|
|
559
|
+
return base;
|
|
560
|
+
},
|
|
561
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
562
|
+
import_MaterialCommunityIcons.default,
|
|
563
|
+
{
|
|
564
|
+
name: displayIcon,
|
|
565
|
+
size: iconPixelSize,
|
|
566
|
+
color: resolvedIconColor
|
|
567
|
+
}
|
|
568
|
+
)
|
|
569
|
+
}
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
573
|
+
0 && (module.exports = {
|
|
574
|
+
IconButton
|
|
575
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { Typography, TypographyProps, TypographyVariant } from './typography/index.js';
|
|
2
|
+
export { Box, BoxProps, Column, ColumnProps, Grid, GridProps, Layout, LayoutProps, Row, RowProps, SpacingValue } from './layout/index.js';
|
|
3
|
+
export { Button, ButtonProps, ButtonVariant } from './button/index.js';
|
|
4
|
+
export { IconButton } from './icon-button/index.js';
|
|
5
|
+
export { I as IconButtonProps, a as IconButtonSize, b as IconButtonVariant } from './types-D3hlyvz-.js';
|
|
6
|
+
export { AppBar, AppBarAction, AppBarProps, AppBarVariant } from './appbar/index.js';
|
|
7
|
+
export { Card, CardProps, CardVariant } from './card/index.js';
|
|
8
|
+
export { Chip, ChipProps, ChipVariant } from './chip/index.js';
|
|
9
|
+
export { Checkbox, CheckboxProps } from './checkbox/index.js';
|
|
10
|
+
export { Radio, RadioProps } from './radio/index.js';
|
|
11
|
+
export { Switch, SwitchProps } from './switch/index.js';
|
|
12
|
+
export { TextField, TextFieldProps, TextFieldVariant } from './text-field/index.js';
|
|
13
|
+
export { List, ListDivider, ListDividerProps, ListItem, ListItemLines, ListItemProps, ListProps } from './list/index.js';
|
|
14
|
+
import 'react/jsx-runtime';
|
|
15
|
+
import 'react';
|
|
16
|
+
import 'react-native';
|
|
17
|
+
import 'react-native-safe-area-context';
|
|
18
|
+
import '@onlynative/core';
|
|
19
|
+
import '@expo/vector-icons/MaterialCommunityIcons';
|