@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.
- package/README.md +105 -0
- package/dist/appbar/index.d.ts +90 -0
- package/dist/appbar/index.js +1030 -0
- package/dist/avatar/index.d.ts +46 -0
- package/dist/avatar/index.js +250 -0
- package/dist/button/index.d.ts +41 -0
- package/dist/button/index.js +468 -0
- package/dist/card/index.d.ts +31 -0
- package/dist/card/index.js +263 -0
- package/dist/checkbox/index.d.ts +25 -0
- package/dist/checkbox/index.js +308 -0
- package/dist/chip/index.d.ts +62 -0
- package/dist/chip/index.js +467 -0
- package/dist/icon-button/index.d.ts +10 -0
- package/dist/icon-button/index.js +592 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +3681 -0
- package/dist/keyboard-avoiding-wrapper/index.d.ts +36 -0
- package/dist/keyboard-avoiding-wrapper/index.js +98 -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 +302 -0
- package/dist/radio/index.d.ts +25 -0
- package/dist/radio/index.js +252 -0
- package/dist/switch/index.d.ts +37 -0
- package/dist/switch/index.js +332 -0
- package/dist/text-field/index.d.ts +52 -0
- package/dist/text-field/index.js +510 -0
- package/dist/types-D3hlyvz-.d.ts +51 -0
- package/dist/typography/index.d.ts +28 -0
- package/dist/typography/index.js +78 -0
- package/llms.txt +458 -0
- package/package.json +202 -0
|
@@ -0,0 +1,302 @@
|
|
|
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/list/index.ts
|
|
21
|
+
var list_exports = {};
|
|
22
|
+
__export(list_exports, {
|
|
23
|
+
List: () => List,
|
|
24
|
+
ListDivider: () => ListDivider,
|
|
25
|
+
ListItem: () => ListItem
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(list_exports);
|
|
28
|
+
|
|
29
|
+
// src/list/List.tsx
|
|
30
|
+
var import_react = require("react");
|
|
31
|
+
var import_react_native4 = require("react-native");
|
|
32
|
+
var import_core = require("@onlynative/core");
|
|
33
|
+
|
|
34
|
+
// src/list/styles.ts
|
|
35
|
+
var import_react_native3 = require("react-native");
|
|
36
|
+
|
|
37
|
+
// ../utils/dist/index.mjs
|
|
38
|
+
var import_react_native = require("react-native");
|
|
39
|
+
var import_react_native2 = require("react-native");
|
|
40
|
+
function parseHexColor(color) {
|
|
41
|
+
const normalized = color.replace("#", "");
|
|
42
|
+
if (normalized.length !== 6 && normalized.length !== 8) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
const r = Number.parseInt(normalized.slice(0, 2), 16);
|
|
46
|
+
const g = Number.parseInt(normalized.slice(2, 4), 16);
|
|
47
|
+
const b = Number.parseInt(normalized.slice(4, 6), 16);
|
|
48
|
+
if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
return { r, g, b };
|
|
52
|
+
}
|
|
53
|
+
function clampAlpha(alpha) {
|
|
54
|
+
return Math.max(0, Math.min(1, alpha));
|
|
55
|
+
}
|
|
56
|
+
function alphaColor(color, alpha) {
|
|
57
|
+
const channels = parseHexColor(color);
|
|
58
|
+
const boundedAlpha = clampAlpha(alpha);
|
|
59
|
+
if (!channels) {
|
|
60
|
+
return color;
|
|
61
|
+
}
|
|
62
|
+
return `rgba(${channels.r}, ${channels.g}, ${channels.b}, ${boundedAlpha})`;
|
|
63
|
+
}
|
|
64
|
+
function blendColor(base, overlay, overlayAlpha) {
|
|
65
|
+
const baseChannels = parseHexColor(base);
|
|
66
|
+
const overlayChannels = parseHexColor(overlay);
|
|
67
|
+
const boundedAlpha = clampAlpha(overlayAlpha);
|
|
68
|
+
if (!baseChannels || !overlayChannels) {
|
|
69
|
+
return alphaColor(overlay, boundedAlpha);
|
|
70
|
+
}
|
|
71
|
+
const r = Math.round(
|
|
72
|
+
(1 - boundedAlpha) * baseChannels.r + boundedAlpha * overlayChannels.r
|
|
73
|
+
);
|
|
74
|
+
const g = Math.round(
|
|
75
|
+
(1 - boundedAlpha) * baseChannels.g + boundedAlpha * overlayChannels.g
|
|
76
|
+
);
|
|
77
|
+
const b = Math.round(
|
|
78
|
+
(1 - boundedAlpha) * baseChannels.b + boundedAlpha * overlayChannels.b
|
|
79
|
+
);
|
|
80
|
+
return `rgb(${r}, ${g}, ${b})`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/list/styles.ts
|
|
84
|
+
var ITEM_PADDING_VERTICAL = 12;
|
|
85
|
+
var INSET_START = 56;
|
|
86
|
+
var MIN_HEIGHT = {
|
|
87
|
+
1: 56,
|
|
88
|
+
2: 72,
|
|
89
|
+
3: 88
|
|
90
|
+
};
|
|
91
|
+
function createListStyles(theme) {
|
|
92
|
+
return import_react_native3.StyleSheet.create({
|
|
93
|
+
container: {
|
|
94
|
+
paddingVertical: theme.spacing.sm
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function getItemColors(theme, containerColor) {
|
|
99
|
+
const base = containerColor != null ? containerColor : "transparent";
|
|
100
|
+
if (containerColor) {
|
|
101
|
+
return {
|
|
102
|
+
backgroundColor: containerColor,
|
|
103
|
+
hoveredBackgroundColor: blendColor(
|
|
104
|
+
containerColor,
|
|
105
|
+
theme.colors.onSurface,
|
|
106
|
+
theme.stateLayer.hoveredOpacity
|
|
107
|
+
),
|
|
108
|
+
pressedBackgroundColor: blendColor(
|
|
109
|
+
containerColor,
|
|
110
|
+
theme.colors.onSurface,
|
|
111
|
+
theme.stateLayer.pressedOpacity
|
|
112
|
+
)
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
backgroundColor: base,
|
|
117
|
+
hoveredBackgroundColor: alphaColor(
|
|
118
|
+
theme.colors.onSurface,
|
|
119
|
+
theme.stateLayer.hoveredOpacity
|
|
120
|
+
),
|
|
121
|
+
pressedBackgroundColor: alphaColor(
|
|
122
|
+
theme.colors.onSurface,
|
|
123
|
+
theme.stateLayer.pressedOpacity
|
|
124
|
+
)
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function createListItemStyles(theme, lines, containerColor) {
|
|
128
|
+
const colors = getItemColors(theme, containerColor);
|
|
129
|
+
return import_react_native3.StyleSheet.create({
|
|
130
|
+
container: {
|
|
131
|
+
flexDirection: "row",
|
|
132
|
+
alignItems: lines === 3 ? "flex-start" : "center",
|
|
133
|
+
minHeight: MIN_HEIGHT[lines],
|
|
134
|
+
paddingHorizontal: theme.spacing.md,
|
|
135
|
+
paddingVertical: ITEM_PADDING_VERTICAL,
|
|
136
|
+
backgroundColor: colors.backgroundColor
|
|
137
|
+
},
|
|
138
|
+
interactiveContainer: {
|
|
139
|
+
cursor: "pointer"
|
|
140
|
+
},
|
|
141
|
+
hoveredContainer: {
|
|
142
|
+
backgroundColor: colors.hoveredBackgroundColor
|
|
143
|
+
},
|
|
144
|
+
pressedContainer: {
|
|
145
|
+
backgroundColor: colors.pressedBackgroundColor
|
|
146
|
+
},
|
|
147
|
+
disabledContainer: {
|
|
148
|
+
cursor: "auto"
|
|
149
|
+
},
|
|
150
|
+
disabledContentWrapper: {
|
|
151
|
+
flexDirection: "row",
|
|
152
|
+
flex: 1,
|
|
153
|
+
opacity: theme.stateLayer.disabledOpacity
|
|
154
|
+
},
|
|
155
|
+
leadingContent: {
|
|
156
|
+
marginEnd: theme.spacing.md
|
|
157
|
+
},
|
|
158
|
+
textBlock: {
|
|
159
|
+
flex: 1
|
|
160
|
+
},
|
|
161
|
+
overlineText: {
|
|
162
|
+
...theme.typography.labelSmall,
|
|
163
|
+
color: theme.colors.onSurfaceVariant
|
|
164
|
+
},
|
|
165
|
+
headlineText: {
|
|
166
|
+
...theme.typography.bodyLarge,
|
|
167
|
+
color: theme.colors.onSurface
|
|
168
|
+
},
|
|
169
|
+
supportingText: {
|
|
170
|
+
...theme.typography.bodyMedium,
|
|
171
|
+
color: theme.colors.onSurfaceVariant
|
|
172
|
+
},
|
|
173
|
+
trailingBlock: {
|
|
174
|
+
marginStart: theme.spacing.md,
|
|
175
|
+
alignItems: "flex-end"
|
|
176
|
+
},
|
|
177
|
+
trailingSupportingText: {
|
|
178
|
+
...theme.typography.labelSmall,
|
|
179
|
+
color: theme.colors.onSurfaceVariant
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
function createDividerStyles(theme, inset) {
|
|
184
|
+
return import_react_native3.StyleSheet.create({
|
|
185
|
+
divider: {
|
|
186
|
+
height: 1,
|
|
187
|
+
backgroundColor: theme.colors.outlineVariant,
|
|
188
|
+
...inset ? { marginStart: INSET_START } : void 0
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// src/list/List.tsx
|
|
194
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
195
|
+
function List({ children, style, ...props }) {
|
|
196
|
+
const theme = (0, import_core.useTheme)();
|
|
197
|
+
const styles = (0, import_react.useMemo)(() => createListStyles(theme), [theme]);
|
|
198
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native4.View, { ...props, style: [styles.container, style], children });
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// src/list/ListItem.tsx
|
|
202
|
+
var import_react2 = require("react");
|
|
203
|
+
var import_react_native5 = require("react-native");
|
|
204
|
+
var import_core2 = require("@onlynative/core");
|
|
205
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
206
|
+
function getLines(supportingText, overlineText, supportingTextNumberOfLines) {
|
|
207
|
+
if (supportingText && overlineText || supportingText && supportingTextNumberOfLines && supportingTextNumberOfLines > 1) {
|
|
208
|
+
return 3;
|
|
209
|
+
}
|
|
210
|
+
if (supportingText || overlineText) return 2;
|
|
211
|
+
return 1;
|
|
212
|
+
}
|
|
213
|
+
function ListItem({
|
|
214
|
+
headlineText,
|
|
215
|
+
supportingText,
|
|
216
|
+
overlineText,
|
|
217
|
+
trailingSupportingText,
|
|
218
|
+
leadingContent,
|
|
219
|
+
trailingContent,
|
|
220
|
+
onPress,
|
|
221
|
+
disabled = false,
|
|
222
|
+
containerColor,
|
|
223
|
+
supportingTextNumberOfLines = 1,
|
|
224
|
+
style,
|
|
225
|
+
...props
|
|
226
|
+
}) {
|
|
227
|
+
const isDisabled = Boolean(disabled);
|
|
228
|
+
const isInteractive = onPress !== void 0;
|
|
229
|
+
const theme = (0, import_core2.useTheme)();
|
|
230
|
+
const lines = getLines(supportingText, overlineText, supportingTextNumberOfLines);
|
|
231
|
+
const styles = (0, import_react2.useMemo)(
|
|
232
|
+
() => createListItemStyles(theme, lines, containerColor),
|
|
233
|
+
[theme, lines, containerColor]
|
|
234
|
+
);
|
|
235
|
+
const content = /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
236
|
+
leadingContent != null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native5.View, { style: styles.leadingContent, children: leadingContent }),
|
|
237
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native5.View, { style: styles.textBlock, children: [
|
|
238
|
+
overlineText != null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native5.Text, { style: styles.overlineText, numberOfLines: 1, children: overlineText }),
|
|
239
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native5.Text, { style: styles.headlineText, numberOfLines: 1, children: headlineText }),
|
|
240
|
+
supportingText != null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
241
|
+
import_react_native5.Text,
|
|
242
|
+
{
|
|
243
|
+
style: styles.supportingText,
|
|
244
|
+
numberOfLines: supportingTextNumberOfLines,
|
|
245
|
+
children: supportingText
|
|
246
|
+
}
|
|
247
|
+
)
|
|
248
|
+
] }),
|
|
249
|
+
(trailingContent != null || trailingSupportingText != null) && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native5.View, { style: styles.trailingBlock, children: [
|
|
250
|
+
trailingSupportingText != null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native5.Text, { style: styles.trailingSupportingText, numberOfLines: 1, children: trailingSupportingText }),
|
|
251
|
+
trailingContent
|
|
252
|
+
] })
|
|
253
|
+
] });
|
|
254
|
+
if (!isInteractive) {
|
|
255
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native5.View, { ...props, style: [styles.container, style], children: content });
|
|
256
|
+
}
|
|
257
|
+
const resolvedStyle = (state) => [
|
|
258
|
+
styles.container,
|
|
259
|
+
styles.interactiveContainer,
|
|
260
|
+
state.hovered && !state.pressed && !isDisabled ? styles.hoveredContainer : void 0,
|
|
261
|
+
state.pressed && !isDisabled ? styles.pressedContainer : void 0,
|
|
262
|
+
isDisabled ? styles.disabledContainer : void 0,
|
|
263
|
+
typeof style === "function" ? style(state) : style
|
|
264
|
+
];
|
|
265
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
266
|
+
import_react_native5.Pressable,
|
|
267
|
+
{
|
|
268
|
+
...props,
|
|
269
|
+
role: "button",
|
|
270
|
+
accessibilityState: { disabled: isDisabled },
|
|
271
|
+
hitSlop: import_react_native5.Platform.OS === "web" ? void 0 : 4,
|
|
272
|
+
disabled: isDisabled,
|
|
273
|
+
onPress,
|
|
274
|
+
style: resolvedStyle,
|
|
275
|
+
children: isDisabled ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native5.View, { style: styles.disabledContentWrapper, children: content }) : content
|
|
276
|
+
}
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// src/list/ListDivider.tsx
|
|
281
|
+
var import_react3 = require("react");
|
|
282
|
+
var import_react_native6 = require("react-native");
|
|
283
|
+
var import_core3 = require("@onlynative/core");
|
|
284
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
285
|
+
function ListDivider({
|
|
286
|
+
inset = false,
|
|
287
|
+
style,
|
|
288
|
+
...props
|
|
289
|
+
}) {
|
|
290
|
+
const theme = (0, import_core3.useTheme)();
|
|
291
|
+
const styles = (0, import_react3.useMemo)(
|
|
292
|
+
() => createDividerStyles(theme, inset),
|
|
293
|
+
[theme, inset]
|
|
294
|
+
);
|
|
295
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native6.View, { ...props, style: [styles.divider, style] });
|
|
296
|
+
}
|
|
297
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
298
|
+
0 && (module.exports = {
|
|
299
|
+
List,
|
|
300
|
+
ListDivider,
|
|
301
|
+
ListItem
|
|
302
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { PressableProps } from 'react-native';
|
|
3
|
+
|
|
4
|
+
interface RadioProps extends Omit<PressableProps, 'children'> {
|
|
5
|
+
/**
|
|
6
|
+
* Whether the radio button is selected.
|
|
7
|
+
* @default false
|
|
8
|
+
*/
|
|
9
|
+
value?: boolean;
|
|
10
|
+
/** Callback fired when the radio is pressed. Receives the new value. */
|
|
11
|
+
onValueChange?: (value: boolean) => void;
|
|
12
|
+
/**
|
|
13
|
+
* Override the outer ring and inner dot color when selected.
|
|
14
|
+
* State-layer colors (hover, press) are derived automatically.
|
|
15
|
+
*/
|
|
16
|
+
containerColor?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Override the outer ring color when unselected.
|
|
19
|
+
*/
|
|
20
|
+
contentColor?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
declare function Radio({ style, value, onValueChange, containerColor, contentColor, disabled, ...props }: RadioProps): react_jsx_runtime.JSX.Element;
|
|
24
|
+
|
|
25
|
+
export { Radio, type RadioProps };
|
|
@@ -0,0 +1,252 @@
|
|
|
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/radio/index.ts
|
|
21
|
+
var radio_exports = {};
|
|
22
|
+
__export(radio_exports, {
|
|
23
|
+
Radio: () => Radio
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(radio_exports);
|
|
26
|
+
|
|
27
|
+
// src/radio/Radio.tsx
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
var import_react_native4 = require("react-native");
|
|
30
|
+
var import_core = require("@onlynative/core");
|
|
31
|
+
|
|
32
|
+
// src/radio/styles.ts
|
|
33
|
+
var import_react_native3 = require("react-native");
|
|
34
|
+
|
|
35
|
+
// ../utils/dist/index.mjs
|
|
36
|
+
var import_react_native = require("react-native");
|
|
37
|
+
var import_react_native2 = require("react-native");
|
|
38
|
+
function parseHexColor(color) {
|
|
39
|
+
const normalized = color.replace("#", "");
|
|
40
|
+
if (normalized.length !== 6 && normalized.length !== 8) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const r = Number.parseInt(normalized.slice(0, 2), 16);
|
|
44
|
+
const g = Number.parseInt(normalized.slice(2, 4), 16);
|
|
45
|
+
const b = Number.parseInt(normalized.slice(4, 6), 16);
|
|
46
|
+
if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
return { r, g, b };
|
|
50
|
+
}
|
|
51
|
+
function clampAlpha(alpha) {
|
|
52
|
+
return Math.max(0, Math.min(1, alpha));
|
|
53
|
+
}
|
|
54
|
+
function alphaColor(color, alpha) {
|
|
55
|
+
const channels = parseHexColor(color);
|
|
56
|
+
const boundedAlpha = clampAlpha(alpha);
|
|
57
|
+
if (!channels) {
|
|
58
|
+
return color;
|
|
59
|
+
}
|
|
60
|
+
return `rgba(${channels.r}, ${channels.g}, ${channels.b}, ${boundedAlpha})`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// src/radio/styles.ts
|
|
64
|
+
function getColors(theme, selected) {
|
|
65
|
+
const disabledOnSurface38 = alphaColor(theme.colors.onSurface, 0.38);
|
|
66
|
+
if (selected) {
|
|
67
|
+
return {
|
|
68
|
+
borderColor: theme.colors.primary,
|
|
69
|
+
dotColor: theme.colors.primary,
|
|
70
|
+
hoveredBackgroundColor: alphaColor(
|
|
71
|
+
theme.colors.primary,
|
|
72
|
+
theme.stateLayer.hoveredOpacity
|
|
73
|
+
),
|
|
74
|
+
pressedBackgroundColor: alphaColor(
|
|
75
|
+
theme.colors.primary,
|
|
76
|
+
theme.stateLayer.pressedOpacity
|
|
77
|
+
),
|
|
78
|
+
disabledBorderColor: disabledOnSurface38,
|
|
79
|
+
disabledDotColor: disabledOnSurface38
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
borderColor: theme.colors.onSurfaceVariant,
|
|
84
|
+
dotColor: "transparent",
|
|
85
|
+
hoveredBackgroundColor: alphaColor(
|
|
86
|
+
theme.colors.onSurface,
|
|
87
|
+
theme.stateLayer.hoveredOpacity
|
|
88
|
+
),
|
|
89
|
+
pressedBackgroundColor: alphaColor(
|
|
90
|
+
theme.colors.onSurface,
|
|
91
|
+
theme.stateLayer.pressedOpacity
|
|
92
|
+
),
|
|
93
|
+
disabledBorderColor: disabledOnSurface38,
|
|
94
|
+
disabledDotColor: "transparent"
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function applyColorOverrides(theme, colors, containerColor, contentColor) {
|
|
98
|
+
if (!containerColor && !contentColor) return colors;
|
|
99
|
+
const result = { ...colors };
|
|
100
|
+
if (containerColor) {
|
|
101
|
+
result.borderColor = containerColor;
|
|
102
|
+
result.dotColor = containerColor;
|
|
103
|
+
result.hoveredBackgroundColor = alphaColor(
|
|
104
|
+
containerColor,
|
|
105
|
+
theme.stateLayer.hoveredOpacity
|
|
106
|
+
);
|
|
107
|
+
result.pressedBackgroundColor = alphaColor(
|
|
108
|
+
containerColor,
|
|
109
|
+
theme.stateLayer.pressedOpacity
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
if (contentColor) {
|
|
113
|
+
result.borderColor = contentColor;
|
|
114
|
+
}
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
function createStyles(theme, selected, containerColor, contentColor) {
|
|
118
|
+
const colors = applyColorOverrides(
|
|
119
|
+
theme,
|
|
120
|
+
getColors(theme, selected),
|
|
121
|
+
containerColor,
|
|
122
|
+
contentColor
|
|
123
|
+
);
|
|
124
|
+
const outerSize = 20;
|
|
125
|
+
const innerSize = 10;
|
|
126
|
+
const touchTarget = 48;
|
|
127
|
+
return import_react_native3.StyleSheet.create({
|
|
128
|
+
container: {
|
|
129
|
+
width: touchTarget,
|
|
130
|
+
height: touchTarget,
|
|
131
|
+
alignItems: "center",
|
|
132
|
+
justifyContent: "center",
|
|
133
|
+
cursor: "pointer"
|
|
134
|
+
},
|
|
135
|
+
hoveredContainer: {
|
|
136
|
+
borderRadius: touchTarget / 2,
|
|
137
|
+
backgroundColor: colors.hoveredBackgroundColor
|
|
138
|
+
},
|
|
139
|
+
pressedContainer: {
|
|
140
|
+
borderRadius: touchTarget / 2,
|
|
141
|
+
backgroundColor: colors.pressedBackgroundColor
|
|
142
|
+
},
|
|
143
|
+
disabledContainer: {
|
|
144
|
+
cursor: "auto"
|
|
145
|
+
},
|
|
146
|
+
outer: {
|
|
147
|
+
width: outerSize,
|
|
148
|
+
height: outerSize,
|
|
149
|
+
borderRadius: outerSize / 2,
|
|
150
|
+
borderWidth: 2,
|
|
151
|
+
borderColor: colors.borderColor,
|
|
152
|
+
alignItems: "center",
|
|
153
|
+
justifyContent: "center"
|
|
154
|
+
},
|
|
155
|
+
disabledOuter: {
|
|
156
|
+
borderColor: colors.disabledBorderColor
|
|
157
|
+
},
|
|
158
|
+
inner: {
|
|
159
|
+
width: innerSize,
|
|
160
|
+
height: innerSize,
|
|
161
|
+
borderRadius: innerSize / 2,
|
|
162
|
+
backgroundColor: colors.dotColor
|
|
163
|
+
},
|
|
164
|
+
disabledInner: {
|
|
165
|
+
backgroundColor: colors.disabledDotColor
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// src/radio/Radio.tsx
|
|
171
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
172
|
+
function resolveStyle(containerStyle, hoveredContainerStyle, pressedContainerStyle, disabledContainerStyle, disabled, style) {
|
|
173
|
+
if (typeof style === "function") {
|
|
174
|
+
return (state) => [
|
|
175
|
+
containerStyle,
|
|
176
|
+
state.hovered && !state.pressed && !disabled ? hoveredContainerStyle : void 0,
|
|
177
|
+
state.pressed && !disabled ? pressedContainerStyle : void 0,
|
|
178
|
+
disabled ? disabledContainerStyle : void 0,
|
|
179
|
+
style(state)
|
|
180
|
+
];
|
|
181
|
+
}
|
|
182
|
+
return (state) => [
|
|
183
|
+
containerStyle,
|
|
184
|
+
state.hovered && !state.pressed && !disabled ? hoveredContainerStyle : void 0,
|
|
185
|
+
state.pressed && !disabled ? pressedContainerStyle : void 0,
|
|
186
|
+
disabled ? disabledContainerStyle : void 0,
|
|
187
|
+
style
|
|
188
|
+
];
|
|
189
|
+
}
|
|
190
|
+
function Radio({
|
|
191
|
+
style,
|
|
192
|
+
value = false,
|
|
193
|
+
onValueChange,
|
|
194
|
+
containerColor,
|
|
195
|
+
contentColor,
|
|
196
|
+
disabled = false,
|
|
197
|
+
...props
|
|
198
|
+
}) {
|
|
199
|
+
const isDisabled = Boolean(disabled);
|
|
200
|
+
const isSelected = Boolean(value);
|
|
201
|
+
const theme = (0, import_core.useTheme)();
|
|
202
|
+
const styles = (0, import_react.useMemo)(
|
|
203
|
+
() => createStyles(theme, isSelected, containerColor, contentColor),
|
|
204
|
+
[theme, isSelected, containerColor, contentColor]
|
|
205
|
+
);
|
|
206
|
+
const handlePress = () => {
|
|
207
|
+
if (!isDisabled) {
|
|
208
|
+
onValueChange == null ? void 0 : onValueChange(!isSelected);
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
212
|
+
import_react_native4.Pressable,
|
|
213
|
+
{
|
|
214
|
+
...props,
|
|
215
|
+
accessibilityRole: "radio",
|
|
216
|
+
accessibilityState: {
|
|
217
|
+
disabled: isDisabled,
|
|
218
|
+
checked: isSelected
|
|
219
|
+
},
|
|
220
|
+
hitSlop: import_react_native4.Platform.OS === "web" ? void 0 : 4,
|
|
221
|
+
disabled: isDisabled,
|
|
222
|
+
onPress: handlePress,
|
|
223
|
+
style: resolveStyle(
|
|
224
|
+
styles.container,
|
|
225
|
+
styles.hoveredContainer,
|
|
226
|
+
styles.pressedContainer,
|
|
227
|
+
styles.disabledContainer,
|
|
228
|
+
isDisabled,
|
|
229
|
+
style
|
|
230
|
+
),
|
|
231
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
232
|
+
import_react_native4.View,
|
|
233
|
+
{
|
|
234
|
+
style: [styles.outer, isDisabled ? styles.disabledOuter : void 0],
|
|
235
|
+
children: isSelected ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
236
|
+
import_react_native4.View,
|
|
237
|
+
{
|
|
238
|
+
style: [
|
|
239
|
+
styles.inner,
|
|
240
|
+
isDisabled ? styles.disabledInner : void 0
|
|
241
|
+
]
|
|
242
|
+
}
|
|
243
|
+
) : null
|
|
244
|
+
}
|
|
245
|
+
)
|
|
246
|
+
}
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
250
|
+
0 && (module.exports = {
|
|
251
|
+
Radio
|
|
252
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
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 } from 'react-native';
|
|
5
|
+
|
|
6
|
+
interface SwitchProps extends Omit<PressableProps, 'children'> {
|
|
7
|
+
/**
|
|
8
|
+
* Whether the switch is toggled on.
|
|
9
|
+
* @default false
|
|
10
|
+
*/
|
|
11
|
+
value?: boolean;
|
|
12
|
+
/** Callback fired when the switch is toggled. Receives the new value. */
|
|
13
|
+
onValueChange?: (value: boolean) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Name of a MaterialCommunityIcons icon to show on the thumb when selected.
|
|
16
|
+
* @default 'check'
|
|
17
|
+
*/
|
|
18
|
+
selectedIcon?: ComponentProps<typeof MaterialCommunityIcons>['name'];
|
|
19
|
+
/**
|
|
20
|
+
* Name of a MaterialCommunityIcons icon to show on the thumb when unselected.
|
|
21
|
+
* When provided, the thumb renders at the larger selected size.
|
|
22
|
+
*/
|
|
23
|
+
unselectedIcon?: ComponentProps<typeof MaterialCommunityIcons>['name'];
|
|
24
|
+
/**
|
|
25
|
+
* Override the track color.
|
|
26
|
+
* State-layer colors (hover, press) are derived automatically.
|
|
27
|
+
*/
|
|
28
|
+
containerColor?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Override the thumb and icon color.
|
|
31
|
+
*/
|
|
32
|
+
contentColor?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
declare function Switch({ style, value, onValueChange, selectedIcon, unselectedIcon, containerColor, contentColor, disabled, ...props }: SwitchProps): react_jsx_runtime.JSX.Element;
|
|
36
|
+
|
|
37
|
+
export { Switch, type SwitchProps };
|