Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions apps/collection/app/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { MagnoliaProvider } from "@highlanderrobotics/magnolia-react-native";
import { TrainingConnection } from "../lib/training/TrainingConnection";
import { SplashScreen, Stack } from "expo-router";
import { NativeModules } from "react-native";
Expand Down Expand Up @@ -130,20 +131,22 @@ export default function Layout() {
}

return (
<KeyboardProvider>
<TrainingConnection />
<GestureHandlerRootView
style={{ backgroundColor: colors.background.default, flex: 1 }}
>
<Stack
screenOptions={{
headerShown: false,
contentStyle: {
backgroundColor: colors.background.default,
},
}}
/>
</GestureHandlerRootView>
</KeyboardProvider>
<MagnoliaProvider mode="dark">
<KeyboardProvider>
<TrainingConnection />
<GestureHandlerRootView
style={{ backgroundColor: colors.background.default, flex: 1 }}
>
<Stack
screenOptions={{
headerShown: false,
contentStyle: {
backgroundColor: colors.background.default,
},
}}
/>
</GestureHandlerRootView>
</KeyboardProvider>
</MagnoliaProvider>
);
}
7 changes: 6 additions & 1 deletion apps/collection/jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ module.exports = {
"<rootDir>/test/jest/**/*.test.tsx",
],
setupFilesAfterEnv: ["<rootDir>/test/jest/setup.ts"],
// Jest transforms tests to CommonJS; map the package's real ESM entry explicitly.
moduleNameMapper: {
"^@highlanderrobotics/magnolia-tokens$":
"<rootDir>/node_modules/@highlanderrobotics/magnolia-tokens/dist/index.js",
},
clearMocks: true,
restoreMocks: true,
coverageDirectory: "test-report/coverage",
Expand All @@ -27,6 +32,6 @@ module.exports = {
["jest-junit", { outputDirectory: "test-report", outputName: "junit.xml" }],
],
transformIgnorePatterns: [
"node_modules/(?!((jest-)?react-native|@react-native(-community)?|expo(nent)?|@expo(nent)?/.*|expo-router|@react-navigation/.*|react-native-svg|react-native-safe-area-context|uuid|jotai|zustand))",
"node_modules/(?!((jest-)?react-native|@react-native(-community)?|@highlanderrobotics/.*|expo(nent)?|@expo(nent)?/.*|expo-router|@react-navigation/.*|react-native-svg|react-native-safe-area-context|uuid|jotai|zustand))",
],
};
29 changes: 16 additions & 13 deletions apps/collection/lib/colors.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { tokens } from "@highlanderrobotics/magnolia-tokens";
const theme = tokens.themes.dark;

export type ColorSet = {
default: string;
hover: string;
Expand All @@ -6,30 +9,30 @@ export type ColorSet = {

export const colors = {
victoryPurple: {
default: "#b59aff",
hover: "#bbaaf0",
faded: "#564b75",
default: theme.primary,
hover: theme.primaryHover,
faded: theme.primaryDisabled,
},
gray: {
default: "#424242",
hover: "#585858",
faded: "#2d2d2d",
default: theme.secondary,
hover: theme.secondaryHover,
faded: theme.secondaryDisabled,
},
danger: {
default: "#b13b3b",
hover: "#ab5858",
faded: "#563333",
default: theme.danger,
hover: theme.dangerHover,
faded: theme.dangerDisabled,
},
secondaryContainer: {
default: "#292929",
default: theme.surface,
},
background: {
default: "#1f1f1f",
default: theme.background,
},
onBackground: {
default: "#e0e0e0",
default: theme.onBackground,
},
body: {
default: "#b8b8b8",
default: theme.muted,
},
} as const satisfies Record<string, Partial<ColorSet>>;
128 changes: 26 additions & 102 deletions apps/collection/lib/components/TextField.tsx
Original file line number Diff line number Diff line change
@@ -1,107 +1,31 @@
import { KeyboardTypeOptions } from "react-native";
import { colors } from "../colors";
import { TextInput } from "react-native";
import {
ComponentRef,
forwardRef,
ForwardRefRenderFunction,
useState,
} from "react";
import { TextField as MagnoliaTextField } from "@highlanderrobotics/magnolia-react-native";
import { forwardRef, type ComponentProps } from "react";
import type { TextInput } from "react-native";

type TextInputProps = {
density?: "comfortable" | "compact";
placeholder?: string;
autoFocus?: boolean;
autoCapitalize?: "none" | "sentences" | "words" | "characters";
autoCorrect?: boolean;
returnKeyType?: "done" | "go" | "next" | "search" | "send";
onChangeText?: (text: string) => void;
onSubmitEditing?: () => void;
editable?: boolean;
error?: boolean;
value?: string;
keyboardType?: KeyboardTypeOptions;
multiline?: boolean;
onFocus?: () => void;
onBlur?: () => void;
};
type Props = Omit<ComponentProps<typeof MagnoliaTextField>, "ref">;

const TextField: ForwardRefRenderFunction<
ComponentRef<typeof TextInput>,
TextInputProps
> = (
{
density = "comfortable",
placeholder = "",
autoFocus,
autoCapitalize,
autoCorrect,
returnKeyType,
onChangeText,
onSubmitEditing,
editable = true,
error,
value,
keyboardType,
multiline,
onFocus,
onBlur,
},
ref,
) => {
const [isFocused, setIsFocused] = useState(false);

return (
<TextInput
style={{
minHeight: multiline ? 48 : undefined,
textAlignVertical: multiline ? "top" : "auto",
fontFamily: "Heebo_400Regular",
fontSize: density === "comfortable" ? 16 : 14,
lineHeight: density === "comfortable" ? 23.5 : 20.56,
color: editable ? colors.onBackground.default : "#535353",
backgroundColor: editable
? colors.secondaryContainer.default
: "#252525",
borderRadius: 7,
paddingTop: density === "comfortable" ? 10 : 6,
paddingBottom: density === "comfortable" ? 10 : 6,
paddingHorizontal: density === "comfortable" ? 14 : 10,
borderWidth: 2,
borderColor: error
? colors.danger.default
: editable
? isFocused
? colors.gray.hover
: colors.gray.default
: "#2F2F2F",
}}
placeholder={placeholder}
placeholderTextColor={editable ? "#626262" : "#3D3D3D"}
autoFocus={autoFocus}
autoCapitalize={autoCapitalize}
autoCorrect={autoCorrect}
returnKeyType={returnKeyType}
keyboardType={keyboardType}
onChangeText={onChangeText}
onSubmitEditing={onSubmitEditing}
editable={editable}
// Keep Collection's multiline keyboard/scroll contract while sharing field states.
const TextField = forwardRef<TextInput, Props>(
({ multiline, density = "comfortable", style, ...props }, ref) => (
<MagnoliaTextField
{...props}
ref={ref}
onFocus={() => {
setIsFocused(true);
if (onFocus) onFocus();
}}
onBlur={() => {
setIsFocused(false);
if (onBlur) onBlur();
}}
submitBehavior={multiline ? "newline" : "blurAndSubmit"}
value={value}
density={density}
multiline={multiline}
// Let the form own scrolling while multiline fields grow with their text.
scrollEnabled={multiline ? false : undefined}
accessibilityLabel={props.accessibilityLabel ?? props.placeholder}
submitBehavior={
props.submitBehavior ?? (multiline ? "newline" : "blurAndSubmit")
}
scrollEnabled={multiline ? false : props.scrollEnabled}
style={[
{
textAlignVertical: multiline ? "top" : "auto",
lineHeight: density === "comfortable" ? 23.5 : 20.56,
},
style,
]}
/>
);
};

export default forwardRef(TextField);
),
);
TextField.displayName = "CollectionTextField";
export default TextField;
2 changes: 1 addition & 1 deletion apps/collection/lib/components/text/BodyMedium.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Text } from "react-native";
import { Text } from "@highlanderrobotics/magnolia-react-native";
import { colors } from "../../colors";
import React from "react";

Expand Down
3 changes: 2 additions & 1 deletion apps/collection/lib/components/text/Heading1Small.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { StyleProp, Text, TextStyle } from "react-native";
import { Text } from "@highlanderrobotics/magnolia-react-native";
import { StyleProp, TextStyle } from "react-native";
import { colors } from "../../colors";

const Heading1Small = ({
Expand Down
2 changes: 1 addition & 1 deletion apps/collection/lib/components/text/LabelSmall.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Text } from "react-native";
import { Text } from "@highlanderrobotics/magnolia-react-native";
import { colors } from "../../colors";

const LabelSmall = ({
Expand Down
2 changes: 1 addition & 1 deletion apps/collection/lib/components/text/TitleLarge.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Text } from "react-native";
import { Text } from "@highlanderrobotics/magnolia-react-native";
import { colors } from "../../colors";

const TitleLarge = ({
Expand Down
2 changes: 1 addition & 1 deletion apps/collection/lib/components/text/TitleMedium.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Text } from "react-native";
import { Text } from "@highlanderrobotics/magnolia-react-native";
import { colors } from "../../colors";

const TitleMedium = ({
Expand Down
21 changes: 21 additions & 0 deletions apps/collection/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion apps/collection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@
"typescript": "~6.0.3",
"uuid": "^14.0.3",
"zod": "^4.6.7",
"zustand": "^5.0.16"
"zustand": "^5.0.16",
"@highlanderrobotics/magnolia-react-native": "0.2.0",
"@highlanderrobotics/magnolia-tokens": "0.2.0"
},
"devDependencies": {
"@babel/core": "^7.29.7",
Expand Down
54 changes: 54 additions & 0 deletions apps/collection/test/jest/magnolia.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React, { createRef } from "react";
import { expect, jest, test } from "@jest/globals";
import { fireEvent, render, screen } from "@testing-library/react-native";
import { TextInput } from "react-native";
import { MagnoliaProvider } from "@highlanderrobotics/magnolia-react-native";
import TextField from "../../lib/components/TextField";
import BodyMedium from "../../lib/components/text/BodyMedium";
import { colors } from "../../lib/colors";

test("shared fields retain Collection's multiline behavior, refs and callbacks", async () => {
const change = jest.fn();
const ref = createRef<TextInput>();
await render(
<MagnoliaProvider mode="dark">
<TextField
ref={ref}
placeholder="Match notes"
multiline
value=""
onChangeText={change}
/>
</MagnoliaProvider>,
);
const input = screen.getByLabelText("Match notes");
expect(input.props.submitBehavior).toBe("newline");
expect(input.props.scrollEnabled).toBe(false);
expect(ref.current).toBeTruthy();
await fireEvent.changeText(input, "Scored in auto");
expect(change).toHaveBeenCalledWith("Scored in auto");
});

test("shared fields retain single-line submission and disabled state", async () => {
await render(
<MagnoliaProvider mode="dark">
<TextField placeholder="Team" editable={false} />
</MagnoliaProvider>,
);
const input = screen.getByLabelText("Team");
expect(input.props.submitBehavior).toBe("blurAndSubmit");
expect(input.props.editable).toBe(false);
});

test("text wrappers retain bundled fonts and semantic colors", async () => {
await render(
<MagnoliaProvider mode="dark">
<BodyMedium>Report caption</BodyMedium>
</MagnoliaProvider>,
);
expect(screen.getByText("Report caption")).toHaveStyle({
fontFamily: "Heebo_400Regular",
color: colors.body.default,
fontSize: 14,
});
});
Loading
Loading