@highlanderrobotics/magnolia-react-native 0.0.0-stage → 0.2.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/CHANGELOG.md +23 -0
- package/README.md +2 -2
- package/dist/index.d.ts +205 -0
- package/dist/index.js +270 -0
- package/package.json +44 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# @highlanderrobotics/magnolia-react-native
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 9755af6: Align visible control dimensions, state colors, switch geometry and original selection artwork with the Lovat Figma components. Add selectable Pill controls and a source-linked comparison gallery with self-hosted fonts. Preserve larger activation areas, accessible contrast and native platform behavior; Lovat consumer dependencies are unchanged.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [9755af6]
|
|
12
|
+
- @highlanderrobotics/magnolia-tokens@0.2.0
|
|
13
|
+
|
|
14
|
+
## 0.1.0
|
|
15
|
+
|
|
16
|
+
### Minor Changes
|
|
17
|
+
|
|
18
|
+
- Introduce the cross-platform Magnolia design system with generated tokens, Svelte 5 accessible controls, native React Native controls and a Starlight theme adapter. Consumer migrations are deferred.
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies
|
|
23
|
+
- @highlanderrobotics/magnolia-tokens@0.1.0
|
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Magnolia UI — react-native
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Part of [Highlander Robotics Magnolia UI](https://github.com/HighlanderRobotics/magnolia-ui). See the repository README and docs for installation, component contracts, token API, migration and release gates. Fonts and application logic remain application-owned. Package version does not imply a published registry release.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { PropsWithChildren, ReactNode } from 'react';
|
|
3
|
+
import { TextInput } from 'react-native';
|
|
4
|
+
import type { PressableProps, TextProps, TextInputProps, SwitchProps, StyleProp, ViewStyle } from 'react-native';
|
|
5
|
+
import type { Density, ThemeMode } from '@highlanderrobotics/magnolia-tokens';
|
|
6
|
+
export type { Density, ThemeMode };
|
|
7
|
+
export type ColorSet = {
|
|
8
|
+
default: string;
|
|
9
|
+
hover: string;
|
|
10
|
+
faded: string;
|
|
11
|
+
};
|
|
12
|
+
type Theme = {
|
|
13
|
+
mode: ThemeMode;
|
|
14
|
+
density: Density;
|
|
15
|
+
fontFamily: string;
|
|
16
|
+
iconFontFamily: string;
|
|
17
|
+
};
|
|
18
|
+
export declare function MagnoliaProvider({ children, mode, density, fontFamily, iconFontFamily, }: PropsWithChildren<Partial<Theme>>): React.JSX.Element;
|
|
19
|
+
export declare function useMagnolia(): {
|
|
20
|
+
colors: {
|
|
21
|
+
readonly primary: "#350868";
|
|
22
|
+
readonly primaryHover: "#5a3b7d";
|
|
23
|
+
readonly primaryDisabled: "#a59ab0";
|
|
24
|
+
readonly secondary: "#dbdbdb";
|
|
25
|
+
readonly secondaryHover: "#b4b4b4";
|
|
26
|
+
readonly secondaryDisabled: "#dddddd";
|
|
27
|
+
readonly surface: "#ffffff";
|
|
28
|
+
readonly background: "#f5f5f5";
|
|
29
|
+
readonly onBackground: "#000000";
|
|
30
|
+
readonly muted: "#454545";
|
|
31
|
+
readonly onPrimary: "#f5f5f5";
|
|
32
|
+
readonly onSecondary: "#000000";
|
|
33
|
+
readonly danger: "#9e2c2c";
|
|
34
|
+
readonly dangerHover: "#772727";
|
|
35
|
+
readonly onDanger: "#ffffff";
|
|
36
|
+
readonly errorText: "#9e2c2c";
|
|
37
|
+
readonly outline: "#828282";
|
|
38
|
+
readonly placeholder: "#666666";
|
|
39
|
+
readonly focus: "#350868";
|
|
40
|
+
readonly disabledText: "#909090";
|
|
41
|
+
readonly disabledSurface: "#dddddd";
|
|
42
|
+
readonly onPrimaryDisabled: "#dbd7df";
|
|
43
|
+
readonly onSecondaryDisabled: "#909090";
|
|
44
|
+
readonly dangerDisabled: "#9d7979";
|
|
45
|
+
readonly onDangerDisabled: "#d8c9c9";
|
|
46
|
+
readonly fieldDisabledBackground: "#f5f5f5";
|
|
47
|
+
readonly fieldDisabledBorder: "#dddddd";
|
|
48
|
+
readonly fieldDisabledText: "#b4b4b4";
|
|
49
|
+
readonly fieldDisabledPlaceholder: "#dddddd";
|
|
50
|
+
readonly switchThumb: "#ffffff";
|
|
51
|
+
readonly selectionDisabledLabel: "#828282";
|
|
52
|
+
readonly selectionDisabledBackground: "#f5f5f5";
|
|
53
|
+
readonly selectionDisabledBorder: "#eeeeee";
|
|
54
|
+
readonly menuText: "#000000";
|
|
55
|
+
readonly pillPrimaryActive: "#bbaaf0";
|
|
56
|
+
readonly pillOnPrimaryActive: "#1f1f1f";
|
|
57
|
+
readonly pillSecondaryActive: "#292929";
|
|
58
|
+
readonly pillOnSecondaryActive: "#e0e0e0";
|
|
59
|
+
} | {
|
|
60
|
+
readonly primary: "#b59aff";
|
|
61
|
+
readonly primaryHover: "#bbaaf0";
|
|
62
|
+
readonly primaryDisabled: "#564b75";
|
|
63
|
+
readonly secondary: "#424242";
|
|
64
|
+
readonly secondaryHover: "#585858";
|
|
65
|
+
readonly secondaryDisabled: "#2d2d2d";
|
|
66
|
+
readonly surface: "#292929";
|
|
67
|
+
readonly background: "#1f1f1f";
|
|
68
|
+
readonly onBackground: "#e0e0e0";
|
|
69
|
+
readonly muted: "#b8b8b8";
|
|
70
|
+
readonly onPrimary: "#1f1f1f";
|
|
71
|
+
readonly onSecondary: "#e0e0e0";
|
|
72
|
+
readonly danger: "#b13b3b";
|
|
73
|
+
readonly dangerHover: "#963333";
|
|
74
|
+
readonly onDanger: "#ffffff";
|
|
75
|
+
readonly errorText: "#ffb4ab";
|
|
76
|
+
readonly outline: "#929292";
|
|
77
|
+
readonly placeholder: "#a3a3a3";
|
|
78
|
+
readonly focus: "#b59aff";
|
|
79
|
+
readonly disabledText: "#929292";
|
|
80
|
+
readonly disabledSurface: "#2d2d2d";
|
|
81
|
+
readonly onPrimaryDisabled: "#1f1f1f";
|
|
82
|
+
readonly onSecondaryDisabled: "#5f5f5f";
|
|
83
|
+
readonly dangerDisabled: "#563333";
|
|
84
|
+
readonly onDangerDisabled: "#746767";
|
|
85
|
+
readonly fieldDisabledBackground: "#1f1f1f";
|
|
86
|
+
readonly fieldDisabledBorder: "#2d2d2d";
|
|
87
|
+
readonly fieldDisabledText: "#585858";
|
|
88
|
+
readonly fieldDisabledPlaceholder: "#424242";
|
|
89
|
+
readonly switchThumb: "#1f1f1f";
|
|
90
|
+
readonly selectionDisabledLabel: "#404040";
|
|
91
|
+
readonly selectionDisabledBackground: "#212121";
|
|
92
|
+
readonly selectionDisabledBorder: "#272727";
|
|
93
|
+
readonly menuText: "#cccccc";
|
|
94
|
+
readonly pillPrimaryActive: "#bbaaf0";
|
|
95
|
+
readonly pillOnPrimaryActive: "#1f1f1f";
|
|
96
|
+
readonly pillSecondaryActive: "#292929";
|
|
97
|
+
readonly pillOnSecondaryActive: "#e0e0e0";
|
|
98
|
+
};
|
|
99
|
+
sizes: {
|
|
100
|
+
readonly paddingY: 10;
|
|
101
|
+
readonly paddingX: 20;
|
|
102
|
+
readonly fontSize: 16;
|
|
103
|
+
readonly radius: 7;
|
|
104
|
+
readonly target: 48;
|
|
105
|
+
readonly visualHeight: 44;
|
|
106
|
+
readonly fieldPaddingX: 14;
|
|
107
|
+
readonly selectionSize: 24;
|
|
108
|
+
readonly selectionGap: 10;
|
|
109
|
+
readonly selectionRadius: 5;
|
|
110
|
+
readonly menuPaddingX: 14;
|
|
111
|
+
readonly menuPaddingY: 8;
|
|
112
|
+
} | {
|
|
113
|
+
readonly paddingY: 6;
|
|
114
|
+
readonly paddingX: 12;
|
|
115
|
+
readonly fontSize: 14;
|
|
116
|
+
readonly radius: 5;
|
|
117
|
+
readonly target: 44;
|
|
118
|
+
readonly visualHeight: 33;
|
|
119
|
+
readonly fieldPaddingX: 10;
|
|
120
|
+
readonly selectionSize: 18;
|
|
121
|
+
readonly selectionGap: 8;
|
|
122
|
+
readonly selectionRadius: 4;
|
|
123
|
+
readonly menuPaddingX: 10;
|
|
124
|
+
readonly menuPaddingY: 6;
|
|
125
|
+
};
|
|
126
|
+
frc: {
|
|
127
|
+
readonly redAlliance: "#ce8c8c";
|
|
128
|
+
readonly onRedAlliance: "#6b3232";
|
|
129
|
+
readonly blueAlliance: "#8a92d1";
|
|
130
|
+
readonly onBlueAlliance: "#2b325c";
|
|
131
|
+
} | {
|
|
132
|
+
readonly redAlliance: "#793f3f";
|
|
133
|
+
readonly onRedAlliance: "#d0a2a2";
|
|
134
|
+
readonly blueAlliance: "#364077";
|
|
135
|
+
readonly onBlueAlliance: "#a2a7d0";
|
|
136
|
+
};
|
|
137
|
+
mode: ThemeMode;
|
|
138
|
+
density: Density;
|
|
139
|
+
fontFamily: string;
|
|
140
|
+
iconFontFamily: string;
|
|
141
|
+
};
|
|
142
|
+
export declare function Text({ style, color, ...props }: TextProps & {
|
|
143
|
+
color?: string;
|
|
144
|
+
}): React.JSX.Element;
|
|
145
|
+
export declare function BodyMedium(props: TextProps & {
|
|
146
|
+
color?: string;
|
|
147
|
+
}): React.JSX.Element;
|
|
148
|
+
export declare function LabelSmall(props: TextProps & {
|
|
149
|
+
color?: string;
|
|
150
|
+
}): React.JSX.Element;
|
|
151
|
+
export declare function TitleLarge(props: TextProps & {
|
|
152
|
+
color?: string;
|
|
153
|
+
}): React.JSX.Element;
|
|
154
|
+
export declare function TitleMedium(props: TextProps & {
|
|
155
|
+
color?: string;
|
|
156
|
+
}): React.JSX.Element;
|
|
157
|
+
export declare function Heading1Small(props: TextProps & {
|
|
158
|
+
color?: string;
|
|
159
|
+
}): React.JSX.Element;
|
|
160
|
+
export type ButtonProps = Omit<PressableProps, 'children' | 'onPress' | 'style'> & {
|
|
161
|
+
children: ReactNode;
|
|
162
|
+
variant?: 'primary' | 'secondary' | 'danger';
|
|
163
|
+
filled?: boolean;
|
|
164
|
+
density?: Density;
|
|
165
|
+
onPress?: () => void | Promise<void>;
|
|
166
|
+
loading?: boolean;
|
|
167
|
+
loadingChildren?: ReactNode;
|
|
168
|
+
flex?: number;
|
|
169
|
+
borderRadius?: number;
|
|
170
|
+
backgroundColorSet?: ColorSet;
|
|
171
|
+
style?: PressableProps['style'];
|
|
172
|
+
onError?: (error: unknown) => void;
|
|
173
|
+
};
|
|
174
|
+
export declare function Button({ children, variant, filled, disabled, density, onPress, loading, loadingChildren, style, flex, borderRadius, backgroundColorSet, onError, ...rest }: ButtonProps): React.JSX.Element;
|
|
175
|
+
export declare const TextField: React.ForwardRefExoticComponent<TextInputProps & {
|
|
176
|
+
density?: Density;
|
|
177
|
+
errorMessage?: string;
|
|
178
|
+
error?: boolean;
|
|
179
|
+
label?: string;
|
|
180
|
+
} & React.RefAttributes<TextInput>>;
|
|
181
|
+
export declare function Switch(props: SwitchProps): React.JSX.Element;
|
|
182
|
+
export declare function Checkbox({ label, checked, disabled, onChange, style, }: {
|
|
183
|
+
label: string;
|
|
184
|
+
checked?: boolean;
|
|
185
|
+
disabled?: boolean;
|
|
186
|
+
onChange?: (checked: boolean) => void;
|
|
187
|
+
style?: StyleProp<ViewStyle>;
|
|
188
|
+
}): React.JSX.Element;
|
|
189
|
+
export declare function Icon({ name, size, color, label, renderIcon, }: {
|
|
190
|
+
name: string;
|
|
191
|
+
size?: number;
|
|
192
|
+
color?: string;
|
|
193
|
+
label?: string;
|
|
194
|
+
renderIcon?: (name: string, size: number, color: string) => ReactNode;
|
|
195
|
+
}): React.JSX.Element;
|
|
196
|
+
export declare function Alert({ children, variant, }: PropsWithChildren<{
|
|
197
|
+
variant?: 'info' | 'danger';
|
|
198
|
+
}>): React.JSX.Element;
|
|
199
|
+
/** Selectable filter pill; applications own which pills form an exclusive group. */
|
|
200
|
+
export declare function Pill({ active, variant, disabled, onChange, children, ...props }: Omit<PressableProps, 'children'> & {
|
|
201
|
+
active?: boolean;
|
|
202
|
+
variant?: 'primary' | 'secondary';
|
|
203
|
+
onChange?: (active: boolean) => void;
|
|
204
|
+
children: ReactNode;
|
|
205
|
+
}): React.JSX.Element;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React, { createContext, forwardRef, useContext, useEffect, useRef, useState, } from 'react';
|
|
3
|
+
import { ActivityIndicator, Pressable, Switch as NativeSwitch, Text as NativeText, TextInput, View, } from 'react-native';
|
|
4
|
+
import { tokens } from '@highlanderrobotics/magnolia-tokens';
|
|
5
|
+
const Context = createContext({
|
|
6
|
+
mode: 'dark',
|
|
7
|
+
density: 'comfortable',
|
|
8
|
+
fontFamily: 'Heebo_400Regular',
|
|
9
|
+
iconFontFamily: 'MaterialSymbols_500Rounded',
|
|
10
|
+
});
|
|
11
|
+
export function MagnoliaProvider({ children, mode = 'dark', density = 'comfortable', fontFamily = 'Heebo_400Regular', iconFontFamily = 'MaterialSymbols_500Rounded', }) {
|
|
12
|
+
return (_jsx(Context.Provider, { value: { mode, density, fontFamily, iconFontFamily }, children: children }));
|
|
13
|
+
}
|
|
14
|
+
export function useMagnolia() {
|
|
15
|
+
const theme = useContext(Context);
|
|
16
|
+
return {
|
|
17
|
+
...theme,
|
|
18
|
+
colors: tokens.themes[theme.mode],
|
|
19
|
+
sizes: tokens.density[theme.density],
|
|
20
|
+
frc: tokens.frc[theme.mode],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export function Text({ style, color, ...props }) {
|
|
24
|
+
const t = useMagnolia();
|
|
25
|
+
return (_jsx(NativeText, { ...props, style: [
|
|
26
|
+
{
|
|
27
|
+
fontFamily: t.fontFamily,
|
|
28
|
+
fontSize: tokens.typography.body,
|
|
29
|
+
color: color ?? t.colors.onBackground,
|
|
30
|
+
},
|
|
31
|
+
style,
|
|
32
|
+
] }));
|
|
33
|
+
}
|
|
34
|
+
export function BodyMedium(props) {
|
|
35
|
+
const t = useMagnolia();
|
|
36
|
+
return (_jsx(Text, { ...props, style: [
|
|
37
|
+
{ fontSize: tokens.typography.small, color: t.colors.muted },
|
|
38
|
+
props.style,
|
|
39
|
+
] }));
|
|
40
|
+
}
|
|
41
|
+
export function LabelSmall(props) {
|
|
42
|
+
return (_jsx(Text, { ...props, style: [{ fontSize: tokens.typography.small }, props.style] }));
|
|
43
|
+
}
|
|
44
|
+
export function TitleLarge(props) {
|
|
45
|
+
return (_jsx(Text, { ...props, accessibilityRole: "header", style: [{ fontSize: 40, fontWeight: '500' }, props.style] }));
|
|
46
|
+
}
|
|
47
|
+
export function TitleMedium(props) {
|
|
48
|
+
return (_jsx(Text, { ...props, accessibilityRole: "header", style: [{ fontSize: 30, fontWeight: '500' }, props.style] }));
|
|
49
|
+
}
|
|
50
|
+
export function Heading1Small(props) {
|
|
51
|
+
return (_jsx(Text, { ...props, accessibilityRole: "header", style: [{ fontSize: 20, lineHeight: 32, fontWeight: '500' }, props.style] }));
|
|
52
|
+
}
|
|
53
|
+
export function Button({ children, variant = 'secondary', filled = true, disabled = false, density, onPress, loading = false, loadingChildren, style, flex, borderRadius, backgroundColorSet, onError, ...rest }) {
|
|
54
|
+
const t = useMagnolia();
|
|
55
|
+
const sizes = tokens.density[density ?? t.density];
|
|
56
|
+
const [busy, setBusy] = useState(false);
|
|
57
|
+
const [error, setError] = useState(null);
|
|
58
|
+
const inFlight = useRef(false);
|
|
59
|
+
const mounted = useRef(true);
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
mounted.current = true;
|
|
62
|
+
return () => {
|
|
63
|
+
mounted.current = false;
|
|
64
|
+
};
|
|
65
|
+
}, []);
|
|
66
|
+
const inactive = disabled || loading || busy;
|
|
67
|
+
const disabledBackground = backgroundColorSet?.faded ??
|
|
68
|
+
(variant === 'primary'
|
|
69
|
+
? t.colors.primaryDisabled
|
|
70
|
+
: variant === 'danger'
|
|
71
|
+
? t.colors.dangerDisabled
|
|
72
|
+
: t.colors.secondaryDisabled);
|
|
73
|
+
const disabledForeground = variant === 'primary'
|
|
74
|
+
? t.colors.onPrimaryDisabled
|
|
75
|
+
: variant === 'danger'
|
|
76
|
+
? t.colors.onDangerDisabled
|
|
77
|
+
: t.colors.onSecondaryDisabled;
|
|
78
|
+
const color = variant === 'primary'
|
|
79
|
+
? t.colors.primary
|
|
80
|
+
: variant === 'danger'
|
|
81
|
+
? t.colors.danger
|
|
82
|
+
: t.colors.secondary;
|
|
83
|
+
const foreground = variant === 'primary'
|
|
84
|
+
? t.colors.onPrimary
|
|
85
|
+
: variant === 'danger'
|
|
86
|
+
? t.colors.onDanger
|
|
87
|
+
: t.colors.onSecondary;
|
|
88
|
+
async function press() {
|
|
89
|
+
if (inFlight.current || inactive)
|
|
90
|
+
return;
|
|
91
|
+
inFlight.current = true;
|
|
92
|
+
setError(null);
|
|
93
|
+
setBusy(true);
|
|
94
|
+
try {
|
|
95
|
+
await onPress?.();
|
|
96
|
+
}
|
|
97
|
+
catch (cause) {
|
|
98
|
+
if (mounted.current) {
|
|
99
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
100
|
+
onError?.(cause);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
inFlight.current = false;
|
|
105
|
+
if (mounted.current)
|
|
106
|
+
setBusy(false);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return (_jsxs(View, { style: flex === undefined ? undefined : { flex }, children: [error && (_jsx(Text, { accessibilityRole: "alert", accessibilityLiveRegion: "polite", color: t.colors.errorText, children: error })), _jsxs(Pressable, { ...rest, accessibilityRole: "button", accessibilityState: {
|
|
110
|
+
...rest.accessibilityState,
|
|
111
|
+
disabled: !!inactive,
|
|
112
|
+
busy: busy || loading,
|
|
113
|
+
}, disabled: inactive, onPress: press, style: (state) => [
|
|
114
|
+
{
|
|
115
|
+
minHeight: Math.max(48, sizes.target),
|
|
116
|
+
minWidth: 48,
|
|
117
|
+
paddingVertical: sizes.paddingY,
|
|
118
|
+
paddingHorizontal: sizes.paddingX,
|
|
119
|
+
borderRadius: borderRadius ?? sizes.radius,
|
|
120
|
+
alignItems: 'center',
|
|
121
|
+
justifyContent: 'center',
|
|
122
|
+
flexDirection: 'row',
|
|
123
|
+
gap: tokens.spacing.sm,
|
|
124
|
+
backgroundColor: !filled
|
|
125
|
+
? 'transparent'
|
|
126
|
+
: inactive
|
|
127
|
+
? disabledBackground
|
|
128
|
+
: backgroundColorSet
|
|
129
|
+
? state.pressed
|
|
130
|
+
? backgroundColorSet.hover
|
|
131
|
+
: backgroundColorSet.default
|
|
132
|
+
: state.pressed
|
|
133
|
+
? variant === 'primary'
|
|
134
|
+
? t.colors.primaryHover
|
|
135
|
+
: variant === 'danger'
|
|
136
|
+
? t.colors.dangerHover
|
|
137
|
+
: t.colors.secondaryHover
|
|
138
|
+
: color,
|
|
139
|
+
},
|
|
140
|
+
typeof style === 'function' ? style(state) : style,
|
|
141
|
+
], children: [(busy || loading) && (_jsx(ActivityIndicator, { color: filled ? foreground : color })), _jsx(Text, { style: {
|
|
142
|
+
fontSize: sizes.fontSize,
|
|
143
|
+
fontWeight: '500',
|
|
144
|
+
color: inactive ? disabledForeground : filled ? foreground : color,
|
|
145
|
+
}, children: busy || loading ? (loadingChildren ?? children) : children })] })] }));
|
|
146
|
+
}
|
|
147
|
+
export const TextField = forwardRef(({ density, errorMessage, error, label, style, ...props }, ref) => {
|
|
148
|
+
const t = useMagnolia();
|
|
149
|
+
const sizes = tokens.density[density ?? t.density];
|
|
150
|
+
const [focused, setFocused] = useState(false);
|
|
151
|
+
return (_jsxs(View, { children: [label && _jsx(Text, { children: label }), _jsx(TextInput, { ...props, ref: ref, accessibilityLabel: props.accessibilityLabel ?? label, accessibilityHint: [props.accessibilityHint, errorMessage].filter(Boolean).join('. ') ||
|
|
152
|
+
undefined, placeholderTextColor: props.placeholderTextColor ?? t.colors.placeholder, onFocus: (event) => {
|
|
153
|
+
setFocused(true);
|
|
154
|
+
props.onFocus?.(event);
|
|
155
|
+
}, onBlur: (event) => {
|
|
156
|
+
setFocused(false);
|
|
157
|
+
props.onBlur?.(event);
|
|
158
|
+
}, style: [
|
|
159
|
+
{
|
|
160
|
+
minHeight: 48,
|
|
161
|
+
fontFamily: t.fontFamily,
|
|
162
|
+
fontSize: sizes.fontSize,
|
|
163
|
+
color: props.editable === false
|
|
164
|
+
? t.colors.disabledText
|
|
165
|
+
: t.colors.onBackground,
|
|
166
|
+
backgroundColor: props.editable === false
|
|
167
|
+
? t.colors.disabledSurface
|
|
168
|
+
: t.colors.surface,
|
|
169
|
+
borderWidth: 2,
|
|
170
|
+
borderColor: errorMessage || error
|
|
171
|
+
? t.colors.errorText
|
|
172
|
+
: focused
|
|
173
|
+
? t.colors.focus
|
|
174
|
+
: t.colors.outline,
|
|
175
|
+
borderRadius: sizes.radius,
|
|
176
|
+
paddingVertical: sizes.paddingY,
|
|
177
|
+
paddingHorizontal: sizes.fieldPaddingX,
|
|
178
|
+
},
|
|
179
|
+
style,
|
|
180
|
+
] }), errorMessage && (_jsx(Text, { accessibilityRole: "alert", accessibilityLiveRegion: "polite", color: t.colors.errorText, children: errorMessage }))] }));
|
|
181
|
+
});
|
|
182
|
+
TextField.displayName = 'MagnoliaTextField';
|
|
183
|
+
export function Switch(props) {
|
|
184
|
+
const t = useMagnolia();
|
|
185
|
+
return (_jsx(NativeSwitch, { ...props, accessibilityRole: "switch", accessibilityState: {
|
|
186
|
+
...props.accessibilityState,
|
|
187
|
+
checked: !!props.value,
|
|
188
|
+
disabled: !!props.disabled,
|
|
189
|
+
}, trackColor: { false: t.colors.secondary, true: t.colors.primary } }));
|
|
190
|
+
}
|
|
191
|
+
export function Checkbox({ label, checked = false, disabled = false, onChange, style, }) {
|
|
192
|
+
const t = useMagnolia();
|
|
193
|
+
return (_jsxs(Pressable, { accessibilityRole: "checkbox", accessibilityLabel: label, accessibilityState: { checked, disabled }, disabled: disabled, onPress: () => onChange?.(!checked), style: [
|
|
194
|
+
{
|
|
195
|
+
minHeight: 48,
|
|
196
|
+
minWidth: 48,
|
|
197
|
+
flexDirection: 'row',
|
|
198
|
+
alignItems: 'center',
|
|
199
|
+
gap: t.sizes.selectionGap,
|
|
200
|
+
},
|
|
201
|
+
style,
|
|
202
|
+
], children: [_jsx(View, { accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", style: {
|
|
203
|
+
width: t.sizes.selectionSize,
|
|
204
|
+
height: t.sizes.selectionSize,
|
|
205
|
+
borderWidth: 2,
|
|
206
|
+
borderColor: t.colors.outline,
|
|
207
|
+
borderRadius: t.sizes.selectionRadius,
|
|
208
|
+
backgroundColor: checked ? t.colors.primary : t.colors.surface,
|
|
209
|
+
alignItems: 'center',
|
|
210
|
+
justifyContent: 'center',
|
|
211
|
+
}, children: checked && _jsx(Text, { color: t.colors.onPrimary, children: "\u2713" }) }), _jsx(Text, { color: disabled ? t.colors.disabledText : t.colors.onBackground, children: label })] }));
|
|
212
|
+
}
|
|
213
|
+
export function Icon({ name, size = 24, color, label, renderIcon, }) {
|
|
214
|
+
const t = useMagnolia();
|
|
215
|
+
const resolved = color ?? t.colors.onBackground;
|
|
216
|
+
return (_jsx(View, { accessible: !!label, accessibilityRole: label ? 'image' : undefined, accessibilityLabel: label, accessibilityElementsHidden: !label, importantForAccessibility: label ? 'yes' : 'no-hide-descendants', children: renderIcon ? (renderIcon(name, size, resolved)) : (_jsx(NativeText, { allowFontScaling: false, style: {
|
|
217
|
+
fontFamily: t.iconFontFamily,
|
|
218
|
+
fontSize: size,
|
|
219
|
+
color: resolved,
|
|
220
|
+
}, children: name })) }));
|
|
221
|
+
}
|
|
222
|
+
export function Alert({ children, variant = 'info', }) {
|
|
223
|
+
const t = useMagnolia();
|
|
224
|
+
return (_jsx(View, { accessibilityRole: variant === 'danger' ? 'alert' : undefined, accessibilityLiveRegion: "polite", style: {
|
|
225
|
+
padding: tokens.spacing.md,
|
|
226
|
+
borderWidth: 1,
|
|
227
|
+
borderColor: t.colors.outline,
|
|
228
|
+
borderRadius: tokens.radius.control,
|
|
229
|
+
}, children: _jsx(Text, { color: variant === 'danger' ? t.colors.errorText : t.colors.onBackground, children: children }) }));
|
|
230
|
+
}
|
|
231
|
+
/** Selectable filter pill; applications own which pills form an exclusive group. */
|
|
232
|
+
export function Pill({ active = false, variant = 'primary', disabled = false, onChange, children, ...props }) {
|
|
233
|
+
const t = useMagnolia();
|
|
234
|
+
return (_jsx(Pressable, { ...props, disabled: disabled, accessibilityRole: "button", accessibilityState: {
|
|
235
|
+
...props.accessibilityState,
|
|
236
|
+
selected: active,
|
|
237
|
+
disabled: !!disabled,
|
|
238
|
+
}, onPress: (event) => {
|
|
239
|
+
props.onPress?.(event);
|
|
240
|
+
if (!event?.isDefaultPrevented())
|
|
241
|
+
onChange?.(!active);
|
|
242
|
+
}, style: (state) => [
|
|
243
|
+
{
|
|
244
|
+
position: 'relative',
|
|
245
|
+
minHeight: 48,
|
|
246
|
+
minWidth: 48,
|
|
247
|
+
alignItems: 'center',
|
|
248
|
+
justifyContent: 'center',
|
|
249
|
+
paddingVertical: tokens.controls.pillPaddingY,
|
|
250
|
+
paddingHorizontal: tokens.controls.pillPaddingX,
|
|
251
|
+
borderRadius: tokens.controls.pillRadius,
|
|
252
|
+
backgroundColor: active
|
|
253
|
+
? variant === 'primary'
|
|
254
|
+
? t.colors.pillPrimaryActive
|
|
255
|
+
: t.colors.pillSecondaryActive
|
|
256
|
+
: 'transparent',
|
|
257
|
+
},
|
|
258
|
+
typeof props.style === 'function' ? props.style(state) : props.style,
|
|
259
|
+
], children: _jsx(Text, { style: {
|
|
260
|
+
fontSize: tokens.controls.selectionFontSize,
|
|
261
|
+
fontWeight: '500',
|
|
262
|
+
color: disabled
|
|
263
|
+
? t.colors.disabledText
|
|
264
|
+
: active
|
|
265
|
+
? variant === 'primary'
|
|
266
|
+
? t.colors.pillOnPrimaryActive
|
|
267
|
+
: t.colors.pillOnSecondaryActive
|
|
268
|
+
: t.colors.onBackground,
|
|
269
|
+
}, children: children }) }));
|
|
270
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@highlanderrobotics/magnolia-react-native",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Magnolia UI react-native design system",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/HighlanderRobotics/magnolia-ui.git",
|
|
9
|
+
"directory": "packages/react-native"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public",
|
|
13
|
+
"registry": "https://registry.npmjs.org/"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"CHANGELOG.md"
|
|
19
|
+
],
|
|
20
|
+
"sideEffects": [
|
|
21
|
+
"**/*.css"
|
|
22
|
+
],
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"react-native": "./dist/index.js",
|
|
27
|
+
"import": "./dist/index.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"react": ">=19 <20",
|
|
32
|
+
"react-native": ">=0.81 <1"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@highlanderrobotics/magnolia-tokens": "0.2.0"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsc -p tsconfig.json",
|
|
39
|
+
"check": "tsc -p tsconfig.json --noEmit"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://github.com/HighlanderRobotics/magnolia-ui#readme",
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/HighlanderRobotics/magnolia-ui/issues"
|
|
44
|
+
},
|
|
45
|
+
"license": "UNLICENSED"
|
|
46
|
+
}
|