feat(ui): component kit, layout primitives and git components
- UI kit: button, card, field, avatar, badge, list-item, segmented, skeleton, empty/error/loading state views, icon + icon-button, search bar - layout: Screen, SectionHeader, header buttons, QueryList with pull-to-refresh - git components: repo list item, file rows/breadcrumbs, commit row, issue row, native Markdown renderer, notification row with subject-URL parsing
This commit is contained in:
1 parent
e0ca502cc9
commit
08229fdf86
26 files changed
+2816
No files matched your search
@@ -0,0 +1,105 @@
|
|||||||
|
import { Pressable, StyleSheet, View } from 'react-native';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
|
import { AppText } from '@/components/ui/app-text';
|
||||||
|
import { Avatar } from '@/components/ui/avatar';
|
||||||
|
import { Icon } from '@/components/ui/icon';
|
||||||
|
import type { Commit } from '@/core/api/types';
|
||||||
|
import { firstLine, formatRelativeTime, shortSha } from '@/core/utils/format';
|
||||||
|
import { useTheme } from '@/theme/theme-provider';
|
||||||
|
import { HIT_TARGET, radius, spacing } from '@/theme/tokens';
|
||||||
|
|
||||||
|
export interface CommitRowProps {
|
||||||
|
commit: Commit;
|
||||||
|
onPress?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Commit list row: author avatar, message, sha, date, +/− stats. */
|
||||||
|
export function CommitRow({ commit, onPress }: CommitRowProps) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const { colors } = useTheme();
|
||||||
|
|
||||||
|
const authorName = commit.author?.login ?? commit.commit.author?.name ?? t('common.unknown');
|
||||||
|
const avatarUrl = commit.author?.avatar_url;
|
||||||
|
const message = firstLine(commit.commit.message);
|
||||||
|
const date = commit.commit.author?.date ?? commit.created;
|
||||||
|
const additions = commit.stats?.additions ?? 0;
|
||||||
|
const deletions = commit.stats?.deletions ?? 0;
|
||||||
|
|
||||||
|
const body = (
|
||||||
|
<View style={[styles.row, { borderBottomColor: colors.border }]}>
|
||||||
|
<Avatar url={avatarUrl} name={authorName} size={32} />
|
||||||
|
<View style={styles.body}>
|
||||||
|
<AppText variant="bodyMedium" numberOfLines={2}>
|
||||||
|
{message}
|
||||||
|
</AppText>
|
||||||
|
<View style={styles.meta}>
|
||||||
|
<AppText variant="caption" tone="tertiary">
|
||||||
|
{authorName}
|
||||||
|
</AppText>
|
||||||
|
<View style={[styles.shaChip, { backgroundColor: colors.surfaceSecondary }]}>
|
||||||
|
<Icon name="commit" size={11} color={colors.textTertiary} />
|
||||||
|
<AppText variant="monoSmall" tone="tertiary">
|
||||||
|
{shortSha(commit.sha)}
|
||||||
|
</AppText>
|
||||||
|
</View>
|
||||||
|
<AppText variant="caption" tone="tertiary">
|
||||||
|
{formatRelativeTime(date, t)}
|
||||||
|
</AppText>
|
||||||
|
{commit.stats ? (
|
||||||
|
<View style={styles.stats}>
|
||||||
|
<AppText variant="caption" style={{ color: colors.success }}>
|
||||||
|
+{additions}
|
||||||
|
</AppText>
|
||||||
|
<AppText variant="caption" style={{ color: colors.error }}>
|
||||||
|
−{deletions}
|
||||||
|
</AppText>
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
{onPress ? <Icon name="chevronRight" size={16} color={colors.textTertiary} /> : null}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!onPress) return body;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
onPress={onPress}
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel={message}
|
||||||
|
style={({ pressed }) => pressed && { backgroundColor: colors.surfacePressed }}
|
||||||
|
>
|
||||||
|
{body}
|
||||||
|
</Pressable>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
row: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'flex-start',
|
||||||
|
gap: spacing.md,
|
||||||
|
minHeight: HIT_TARGET,
|
||||||
|
paddingVertical: spacing.md,
|
||||||
|
paddingHorizontal: spacing.lg,
|
||||||
|
borderBottomWidth: StyleSheet.hairlineWidth,
|
||||||
|
},
|
||||||
|
body: { flex: 1, gap: spacing.xs },
|
||||||
|
meta: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
flexWrap: 'wrap',
|
||||||
|
gap: spacing.sm,
|
||||||
|
},
|
||||||
|
shaChip: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: 3,
|
||||||
|
paddingHorizontal: spacing.xs,
|
||||||
|
paddingVertical: 1,
|
||||||
|
borderRadius: radius.sm,
|
||||||
|
},
|
||||||
|
stats: { flexDirection: 'row', gap: spacing.sm },
|
||||||
|
});
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
import { Pressable, StyleSheet, View } from 'react-native';
|
||||||
|
|
||||||
|
import { AppText } from '@/components/ui/app-text';
|
||||||
|
import { Icon, type IconName } from '@/components/ui/icon';
|
||||||
|
import type { ContentsEntry, ContentsType } from '@/core/api/types';
|
||||||
|
import { formatBytes } from '@/core/utils/format';
|
||||||
|
import { useTheme } from '@/theme/theme-provider';
|
||||||
|
import { HIT_TARGET, radius, spacing } from '@/theme/tokens';
|
||||||
|
|
||||||
|
function iconForType(type: ContentsType): IconName {
|
||||||
|
switch (type) {
|
||||||
|
case 'dir':
|
||||||
|
return 'folder';
|
||||||
|
case 'submodule':
|
||||||
|
return 'package';
|
||||||
|
case 'symlink':
|
||||||
|
return 'link';
|
||||||
|
default:
|
||||||
|
return 'file';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FileRowProps {
|
||||||
|
entry: ContentsEntry;
|
||||||
|
onPress: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** One row in a directory listing. */
|
||||||
|
export function FileRow({ entry, onPress }: FileRowProps) {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
const isDir = entry.type === 'dir';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
onPress={onPress}
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel={`${entry.name} ${entry.type}`}
|
||||||
|
style={({ pressed }) => [
|
||||||
|
styles.row,
|
||||||
|
{ borderBottomColor: colors.border },
|
||||||
|
pressed && { backgroundColor: colors.surfacePressed },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Icon name={iconForType(entry.type)} size={20} color={isDir ? colors.primary : colors.textTertiary} />
|
||||||
|
<AppText variant="body" numberOfLines={1} style={styles.name}>
|
||||||
|
{entry.name}
|
||||||
|
</AppText>
|
||||||
|
<AppText variant="caption" tone="tertiary">
|
||||||
|
{isDir ? '' : entry.size >= 0 ? formatBytes(entry.size) : ''}
|
||||||
|
</AppText>
|
||||||
|
</Pressable>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BreadcrumbProps {
|
||||||
|
/** Full path relative to repo root ("" = root). */
|
||||||
|
path: string;
|
||||||
|
onNavigate: (path: string) => void;
|
||||||
|
rootLabel: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Path breadcrumb with horizontal scrolling; last segment is the current one. */
|
||||||
|
export function Breadcrumb({ path, onNavigate, rootLabel }: BreadcrumbProps) {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
const segments = path.split('/').filter(Boolean);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={styles.crumbRow}>
|
||||||
|
<Pressable
|
||||||
|
onPress={() => onNavigate('')}
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel={rootLabel}
|
||||||
|
style={styles.crumb}
|
||||||
|
>
|
||||||
|
<Icon name="repo" size={14} color={colors.textSecondary} />
|
||||||
|
<AppText variant="caption" tone={segments.length === 0 ? 'default' : 'secondary'}>
|
||||||
|
{rootLabel}
|
||||||
|
</AppText>
|
||||||
|
</Pressable>
|
||||||
|
|
||||||
|
{segments.map((segment, index) => {
|
||||||
|
const target = segments.slice(0, index + 1).join('/');
|
||||||
|
const isLast = index === segments.length - 1;
|
||||||
|
return (
|
||||||
|
<View key={target} style={styles.crumbWrap}>
|
||||||
|
<Icon name="chevronRight" size={12} color={colors.textTertiary} />
|
||||||
|
<Pressable
|
||||||
|
onPress={() => !isLast && onNavigate(target)}
|
||||||
|
disabled={isLast}
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel={target}
|
||||||
|
style={styles.crumb}
|
||||||
|
>
|
||||||
|
<AppText
|
||||||
|
variant="caption"
|
||||||
|
tone={isLast ? 'default' : 'secondary'}
|
||||||
|
numberOfLines={1}
|
||||||
|
style={isLast && { fontWeight: '700' }}
|
||||||
|
>
|
||||||
|
{segment}
|
||||||
|
</AppText>
|
||||||
|
</Pressable>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
row: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: spacing.md,
|
||||||
|
minHeight: HIT_TARGET,
|
||||||
|
paddingVertical: spacing.md,
|
||||||
|
paddingHorizontal: spacing.lg,
|
||||||
|
borderBottomWidth: StyleSheet.hairlineWidth,
|
||||||
|
},
|
||||||
|
name: { flex: 1 },
|
||||||
|
crumbRow: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
flexWrap: 'nowrap',
|
||||||
|
paddingHorizontal: spacing.lg,
|
||||||
|
paddingVertical: spacing.sm,
|
||||||
|
gap: spacing.xs,
|
||||||
|
minHeight: 38,
|
||||||
|
},
|
||||||
|
crumbWrap: { flexDirection: 'row', alignItems: 'center', gap: spacing.xs, flexShrink: 1 },
|
||||||
|
crumb: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: spacing.xs,
|
||||||
|
paddingVertical: spacing.xs,
|
||||||
|
paddingHorizontal: spacing.xs,
|
||||||
|
borderRadius: radius.sm,
|
||||||
|
flexShrink: 1,
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
import { Pressable, StyleSheet, View } from 'react-native';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
|
import { AppText } from '@/components/ui/app-text';
|
||||||
|
import { StatusBadge } from '@/components/ui/badge';
|
||||||
|
import { LabelChip } from '@/components/ui/label-chip';
|
||||||
|
import type { Issue } from '@/core/api/types';
|
||||||
|
import { formatRelativeTime } from '@/core/utils/format';
|
||||||
|
import { useTheme } from '@/theme/theme-provider';
|
||||||
|
import { HIT_TARGET, spacing } from '@/theme/tokens';
|
||||||
|
|
||||||
|
export interface IssueRowProps {
|
||||||
|
issue: Issue;
|
||||||
|
/** Show the `owner/repo` context (cross-repo lists). */
|
||||||
|
showRepository?: boolean;
|
||||||
|
/** Overrides the computed state (e.g. merged PRs). */
|
||||||
|
stateOverride?: 'open' | 'closed' | 'merged' | 'draft';
|
||||||
|
onPress?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Issue / pull request row used in every list. */
|
||||||
|
export function IssueRow({ issue, showRepository = false, stateOverride, onPress }: IssueRowProps) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const { colors } = useTheme();
|
||||||
|
|
||||||
|
const isPull = Boolean(issue.pull_request);
|
||||||
|
const state: 'open' | 'closed' | 'merged' | 'draft' =
|
||||||
|
stateOverride ??
|
||||||
|
(issue.pull_request?.merged
|
||||||
|
? 'merged'
|
||||||
|
: isPull && issue.pull_request?.draft && issue.state === 'open'
|
||||||
|
? 'draft'
|
||||||
|
: issue.state === 'closed'
|
||||||
|
? 'closed'
|
||||||
|
: 'open');
|
||||||
|
|
||||||
|
const stateLabel = {
|
||||||
|
open: t('issues.open'),
|
||||||
|
closed: t('issues.closed'),
|
||||||
|
merged: t('pulls.stateMerged'),
|
||||||
|
draft: t('pulls.draft'),
|
||||||
|
}[state];
|
||||||
|
|
||||||
|
const repoName = issue.repository?.full_name;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
onPress={onPress}
|
||||||
|
disabled={!onPress}
|
||||||
|
accessibilityRole={onPress ? 'button' : undefined}
|
||||||
|
accessibilityLabel={`${issue.title} ${issue.number}`}
|
||||||
|
style={({ pressed }) => [
|
||||||
|
styles.row,
|
||||||
|
{ borderBottomColor: colors.border },
|
||||||
|
pressed && onPress && { backgroundColor: colors.surfacePressed },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<View style={styles.topLine}>
|
||||||
|
<StatusBadge label={stateLabel} state={state} />
|
||||||
|
<AppText variant="bodyMedium" numberOfLines={2} style={styles.title}>
|
||||||
|
{issue.title}
|
||||||
|
</AppText>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<View style={styles.metaLine}>
|
||||||
|
<AppText variant="caption" tone="tertiary" numberOfLines={1}>
|
||||||
|
{[
|
||||||
|
showRepository && repoName ? repoName : null,
|
||||||
|
`#${issue.number}`,
|
||||||
|
issue.created_at ? formatRelativeTime(issue.created_at, t) : null,
|
||||||
|
issue.comments ? t('issues.comments', { count: issue.comments }) : null,
|
||||||
|
]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join(' · ')}
|
||||||
|
</AppText>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
{issue.labels && issue.labels.length > 0 ? (
|
||||||
|
<View style={styles.labels}>
|
||||||
|
{issue.labels.slice(0, 4).map((label, index) => (
|
||||||
|
<LabelChip key={label.id ?? `${label.name}-${index}`} name={label.name} color={label.color} />
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
</Pressable>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
row: {
|
||||||
|
gap: spacing.xs,
|
||||||
|
minHeight: HIT_TARGET,
|
||||||
|
paddingVertical: spacing.md,
|
||||||
|
paddingHorizontal: spacing.lg,
|
||||||
|
borderBottomWidth: StyleSheet.hairlineWidth,
|
||||||
|
},
|
||||||
|
topLine: { flexDirection: 'row', alignItems: 'center', gap: spacing.sm },
|
||||||
|
title: { flex: 1 },
|
||||||
|
metaLine: { flexDirection: 'row', flexWrap: 'wrap' },
|
||||||
|
labels: { flexDirection: 'row', flexWrap: 'wrap', gap: spacing.xs, marginTop: 2 },
|
||||||
|
});
|
||||||
@@ -0,0 +1,382 @@
|
|||||||
|
/**
|
||||||
|
* Native markdown renderer built on `marked`'s lexer.
|
||||||
|
*
|
||||||
|
* Renders headings, paragraphs, emphasis, links, inline code, code blocks,
|
||||||
|
* lists (incl. nesting + task items), blockquotes, tables, rules and images
|
||||||
|
* (as linked placeholders — remote SVG/badges aren't rendered as images).
|
||||||
|
* No WebView: everything is native Text/View so it inherits fonts, themes
|
||||||
|
* and accessibility scaling.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { marked, type Token, type Tokens } from 'marked';
|
||||||
|
import { Fragment, useMemo, type ReactNode } from 'react';
|
||||||
|
import { Linking, ScrollView, StyleSheet, Text as TextBase, View } from 'react-native';
|
||||||
|
|
||||||
|
import { AppText } from '@/components/ui/app-text';
|
||||||
|
import { useTheme } from '@/theme/theme-provider';
|
||||||
|
import { fontFamily, fontSize, radius, spacing } from '@/theme/tokens';
|
||||||
|
|
||||||
|
export interface MarkdownProps {
|
||||||
|
content: string;
|
||||||
|
/** Instance base URL used to resolve root-relative links (""/undefined → link skipped). */
|
||||||
|
baseUrl?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Ctx {
|
||||||
|
colors: ReturnType<typeof useTheme>['colors'];
|
||||||
|
open: (url: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Markdown({ content, baseUrl = '' }: MarkdownProps) {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
|
||||||
|
const tokens = useMemo(() => {
|
||||||
|
try {
|
||||||
|
return marked.lexer(content);
|
||||||
|
} catch {
|
||||||
|
return [] as Token[];
|
||||||
|
}
|
||||||
|
}, [content]);
|
||||||
|
|
||||||
|
const open = (url: string) => {
|
||||||
|
let target: string | null = null;
|
||||||
|
if (/^https?:\/\//i.test(url)) target = url;
|
||||||
|
else if (baseUrl && url.startsWith('/')) target = `${baseUrl}${url}`;
|
||||||
|
// Relative links (./ ../) are intentionally not resolved — too easy to
|
||||||
|
// guess wrong; users can open the instance in a browser instead.
|
||||||
|
if (target) void Linking.openURL(target).catch(() => undefined);
|
||||||
|
};
|
||||||
|
|
||||||
|
const ctx: Ctx = { colors, open };
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={styles.block}>
|
||||||
|
{tokens.map((token, index) => (
|
||||||
|
<Fragment key={index}>{renderBlock(token, ctx, String(index))}</Fragment>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Inline
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
function renderInline(tokens: Token[] | undefined, ctx: Ctx, key: string): ReactNode {
|
||||||
|
if (!tokens || tokens.length === 0) return null;
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{tokens.map((token, index) => (
|
||||||
|
<Fragment key={`${key}-${index}`}>{renderInlineToken(token, ctx, `${key}-${index}`)}</Fragment>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderInlineToken(token: Token, ctx: Ctx, key: string): ReactNode {
|
||||||
|
const { colors } = ctx;
|
||||||
|
switch (token.type) {
|
||||||
|
case 'text': {
|
||||||
|
const t = token as Tokens.Text;
|
||||||
|
if (t.tokens && t.tokens.length > 0) return renderInline(t.tokens, ctx, key);
|
||||||
|
return <TextSpan key={key}>{t.text}</TextSpan>;
|
||||||
|
}
|
||||||
|
case 'escape':
|
||||||
|
return <TextSpan key={key}>{(token as Tokens.Escape).text}</TextSpan>;
|
||||||
|
case 'em':
|
||||||
|
return (
|
||||||
|
<TextSpan key={key} style={styles.italic}>
|
||||||
|
{renderInline((token as Tokens.Em).tokens, ctx, key)}
|
||||||
|
</TextSpan>
|
||||||
|
);
|
||||||
|
case 'strong':
|
||||||
|
return (
|
||||||
|
<TextSpan key={key} style={styles.strong}>
|
||||||
|
{renderInline((token as Tokens.Strong).tokens, ctx, key)}
|
||||||
|
</TextSpan>
|
||||||
|
);
|
||||||
|
case 'del':
|
||||||
|
return (
|
||||||
|
<TextSpan key={key} style={styles.strike}>
|
||||||
|
{renderInline((token as Tokens.Del).tokens, ctx, key)}
|
||||||
|
</TextSpan>
|
||||||
|
);
|
||||||
|
case 'codespan':
|
||||||
|
return (
|
||||||
|
<TextSpan key={key} style={[styles.codespan, { backgroundColor: colors.codeBackground }]}>
|
||||||
|
{(token as Tokens.Codespan).text}
|
||||||
|
</TextSpan>
|
||||||
|
);
|
||||||
|
case 'br':
|
||||||
|
return <TextSpan key={key}>{'\n'}</TextSpan>;
|
||||||
|
case 'link': {
|
||||||
|
const link = token as Tokens.Link;
|
||||||
|
const internal = /^https?:\/\//i.test(link.href) || link.href.startsWith('/');
|
||||||
|
return (
|
||||||
|
<TextSpan
|
||||||
|
key={key}
|
||||||
|
style={{ color: colors.link }}
|
||||||
|
onPress={internal ? () => ctx.open(link.href) : undefined}
|
||||||
|
>
|
||||||
|
{renderInline(link.tokens, ctx, key)}
|
||||||
|
</TextSpan>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
case 'image': {
|
||||||
|
const image = token as Tokens.Image;
|
||||||
|
const label = image.text ? `[${image.text}]` : '';
|
||||||
|
const internal = /^https?:\/\//i.test(image.href) || image.href.startsWith('/');
|
||||||
|
return (
|
||||||
|
<TextSpan
|
||||||
|
key={key}
|
||||||
|
style={{ color: colors.link }}
|
||||||
|
onPress={internal ? () => ctx.open(image.href) : undefined}
|
||||||
|
>
|
||||||
|
{label}
|
||||||
|
</TextSpan>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
case 'html':
|
||||||
|
case 'xmlprocessing':
|
||||||
|
return null;
|
||||||
|
default: {
|
||||||
|
const anyToken = token as { text?: string; tokens?: Token[] };
|
||||||
|
if (anyToken.tokens) return renderInline(anyToken.tokens, ctx, key);
|
||||||
|
if (anyToken.text) return <TextSpan key={key}>{anyToken.text}</TextSpan>;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** RN requires Text inside Text; this is that primitive. */
|
||||||
|
function TextSpan({
|
||||||
|
children,
|
||||||
|
style,
|
||||||
|
onPress,
|
||||||
|
}: {
|
||||||
|
children: ReactNode;
|
||||||
|
style?: object | object[];
|
||||||
|
onPress?: () => void;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<TextBase onPress={onPress} style={style} suppressHighlighting={!onPress}>
|
||||||
|
{children}
|
||||||
|
</TextBase>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Blocks
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
function renderBlock(token: Token, ctx: Ctx, key: string): ReactNode {
|
||||||
|
const { colors } = ctx;
|
||||||
|
switch (token.type) {
|
||||||
|
case 'heading': {
|
||||||
|
const heading = token as Tokens.Heading;
|
||||||
|
const variant =
|
||||||
|
heading.depth === 1
|
||||||
|
? 'title'
|
||||||
|
: heading.depth === 2
|
||||||
|
? 'heading'
|
||||||
|
: heading.depth === 3
|
||||||
|
? 'subheading'
|
||||||
|
: 'bodyMedium';
|
||||||
|
return (
|
||||||
|
<View key={key} style={styles.blockItem}>
|
||||||
|
<AppText variant={variant}>{renderInline(heading.tokens, ctx, key)}</AppText>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
case 'paragraph':
|
||||||
|
case 'text': {
|
||||||
|
const paragraph = token as Tokens.Paragraph | Tokens.Text;
|
||||||
|
const inline = paragraph.tokens ?? [];
|
||||||
|
return (
|
||||||
|
<View key={key} style={styles.blockItem}>
|
||||||
|
<AppText variant="body">{renderInline(inline, ctx, key)}</AppText>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
case 'code': {
|
||||||
|
const code = token as Tokens.Code;
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
key={key}
|
||||||
|
style={[styles.blockItem, styles.codeBlock, { backgroundColor: colors.codeBackground }]}
|
||||||
|
>
|
||||||
|
<ScrollView horizontal showsHorizontalScrollIndicator={false}>
|
||||||
|
<AppText variant="mono" style={styles.codeText} selectable>
|
||||||
|
{code.text}
|
||||||
|
</AppText>
|
||||||
|
</ScrollView>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
case 'hr':
|
||||||
|
return <View key={key} style={[styles.blockItem, styles.hr, { backgroundColor: colors.border }]} />;
|
||||||
|
case 'blockquote': {
|
||||||
|
const quote = token as Tokens.Blockquote;
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
key={key}
|
||||||
|
style={[
|
||||||
|
styles.blockItem,
|
||||||
|
styles.quote,
|
||||||
|
{ borderLeftColor: colors.borderStrong, backgroundColor: colors.surfaceSecondary },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
{quote.tokens.map((child, index) => (
|
||||||
|
<Fragment key={index}>{renderBlock(child, ctx, `${key}-${index}`)}</Fragment>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
case 'list':
|
||||||
|
return <View key={key}>{renderList(token as Tokens.List, ctx, key)}</View>;
|
||||||
|
case 'table':
|
||||||
|
return <View key={key}>{renderTable(token as Tokens.Table, ctx, key)}</View>;
|
||||||
|
case 'html':
|
||||||
|
return null;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderList(list: Tokens.List, ctx: Ctx, key: string): ReactNode {
|
||||||
|
return (
|
||||||
|
<View style={styles.blockItem}>
|
||||||
|
{list.items.map((raw, index) => {
|
||||||
|
const item = raw as Tokens.ListItem;
|
||||||
|
const marker = list.ordered
|
||||||
|
? `${Number(list.start ?? 1) + index}.`
|
||||||
|
: item.task
|
||||||
|
? item.checked
|
||||||
|
? '☑'
|
||||||
|
: '☐'
|
||||||
|
: '•';
|
||||||
|
const inlineTokens = item.tokens?.filter(isInlineToken) ?? [];
|
||||||
|
const blockTokens = item.tokens?.filter((t) => !isInlineToken(t)) ?? [];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View key={index} style={styles.listRow}>
|
||||||
|
<AppText
|
||||||
|
variant="body"
|
||||||
|
style={[styles.listMarker, list.ordered && styles.listMarkerOrdered]}
|
||||||
|
>
|
||||||
|
{marker}
|
||||||
|
</AppText>
|
||||||
|
<View style={styles.listContent}>
|
||||||
|
{inlineTokens.length > 0 || blockTokens.length === 0 ? (
|
||||||
|
<AppText variant="body">
|
||||||
|
{renderInline(
|
||||||
|
inlineTokens.length > 0
|
||||||
|
? inlineTokens
|
||||||
|
: [{ type: 'text', text: item.text } as Token],
|
||||||
|
ctx,
|
||||||
|
`${key}-${index}`,
|
||||||
|
)}
|
||||||
|
</AppText>
|
||||||
|
) : null}
|
||||||
|
{blockTokens.map((child, childIndex) => (
|
||||||
|
<Fragment key={childIndex}>
|
||||||
|
{renderBlock(child, ctx, `${key}-${index}-${childIndex}`)}
|
||||||
|
</Fragment>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
<View />
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
<View style={{ height: spacing.xs }} />
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const INLINE_TYPES = new Set([
|
||||||
|
'text',
|
||||||
|
'escape',
|
||||||
|
'em',
|
||||||
|
'strong',
|
||||||
|
'del',
|
||||||
|
'codespan',
|
||||||
|
'br',
|
||||||
|
'link',
|
||||||
|
'image',
|
||||||
|
'html',
|
||||||
|
'xmlprocessing',
|
||||||
|
]);
|
||||||
|
|
||||||
|
function isInlineToken(token: Token): boolean {
|
||||||
|
return INLINE_TYPES.has(token.type);
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderTable(table: Tokens.Table, ctx: Ctx, key: string): ReactNode {
|
||||||
|
const { colors } = ctx;
|
||||||
|
return (
|
||||||
|
<ScrollView
|
||||||
|
horizontal
|
||||||
|
showsHorizontalScrollIndicator={false}
|
||||||
|
style={[styles.blockItem, styles.tableScroll]}
|
||||||
|
contentContainerStyle={styles.tableContent}
|
||||||
|
>
|
||||||
|
<View>
|
||||||
|
<View style={[styles.tableRow, { borderBottomWidth: 1, borderBottomColor: colors.borderStrong }]}>
|
||||||
|
{table.header.map((cell, index) => (
|
||||||
|
<View key={index} style={styles.tableCell}>
|
||||||
|
<AppText variant="label">{renderInline(cell.tokens, ctx, `${key}-h-${index}`)}</AppText>
|
||||||
|
</View>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
{table.rows.map((row, rowIndex) => (
|
||||||
|
<View
|
||||||
|
key={rowIndex}
|
||||||
|
style={[styles.tableRow, { borderBottomWidth: StyleSheet.hairlineWidth, borderBottomColor: colors.border }]}
|
||||||
|
>
|
||||||
|
{row.map((cell, cellIndex) => (
|
||||||
|
<View key={cellIndex} style={styles.tableCell}>
|
||||||
|
<AppText variant="caption">
|
||||||
|
{renderInline(cell.tokens, ctx, `${key}-${rowIndex}-${cellIndex}`)}
|
||||||
|
</AppText>
|
||||||
|
</View>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
</ScrollView>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
block: { gap: spacing.md },
|
||||||
|
blockItem: { marginTop: 0 },
|
||||||
|
italic: { fontStyle: 'italic' },
|
||||||
|
strong: { fontWeight: '700' },
|
||||||
|
strike: { textDecorationLine: 'line-through' },
|
||||||
|
codespan: {
|
||||||
|
fontFamily: fontFamily.mono,
|
||||||
|
fontSize: fontSize.sm,
|
||||||
|
paddingHorizontal: 4,
|
||||||
|
borderRadius: 4,
|
||||||
|
},
|
||||||
|
codeBlock: {
|
||||||
|
borderRadius: radius.md,
|
||||||
|
padding: spacing.md,
|
||||||
|
},
|
||||||
|
codeText: { fontSize: fontSize.sm },
|
||||||
|
hr: { height: StyleSheet.hairlineWidth, width: '100%' },
|
||||||
|
quote: {
|
||||||
|
borderLeftWidth: 3,
|
||||||
|
borderRadius: radius.sm,
|
||||||
|
padding: spacing.md,
|
||||||
|
gap: spacing.sm,
|
||||||
|
},
|
||||||
|
listRow: { flexDirection: 'row', gap: spacing.sm, paddingVertical: 2 },
|
||||||
|
listMarker: { width: 22, textAlign: 'right' },
|
||||||
|
listMarkerOrdered: { width: 28 },
|
||||||
|
listContent: { flex: 1, gap: spacing.xs },
|
||||||
|
tableScroll: { flexGrow: 0 },
|
||||||
|
tableContent: { paddingRight: spacing.md },
|
||||||
|
tableRow: { flexDirection: 'row' },
|
||||||
|
tableCell: { minWidth: 90, maxWidth: 260, paddingVertical: spacing.sm, paddingHorizontal: spacing.sm },
|
||||||
|
});
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/** Notification subject URL → navigation target parsing. */
|
||||||
|
|
||||||
|
import { parseSubjectUrl } from './notification-row';
|
||||||
|
|
||||||
|
describe('parseSubjectUrl', () => {
|
||||||
|
it('returns null for missing input', () => {
|
||||||
|
expect(parseSubjectUrl(undefined)).toBeNull();
|
||||||
|
expect(parseSubjectUrl(null)).toBeNull();
|
||||||
|
expect(parseSubjectUrl('')).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('parses API paths', () => {
|
||||||
|
expect(parseSubjectUrl('/api/v1/repos/octo/repo/issues/7')).toEqual({
|
||||||
|
kind: 'issue',
|
||||||
|
owner: 'octo',
|
||||||
|
repo: 'repo',
|
||||||
|
index: 7,
|
||||||
|
});
|
||||||
|
expect(parseSubjectUrl('/repos/octo/repo/pulls/3')).toEqual({
|
||||||
|
kind: 'pull',
|
||||||
|
owner: 'octo',
|
||||||
|
repo: 'repo',
|
||||||
|
index: 3,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('parses absolute instance URLs', () => {
|
||||||
|
expect(parseSubjectUrl('https://codeberg.org/octo/repo/commits/abc123')).toEqual({
|
||||||
|
kind: 'commit',
|
||||||
|
owner: 'octo',
|
||||||
|
repo: 'repo',
|
||||||
|
sha: 'abc123',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('falls back to a repository target', () => {
|
||||||
|
expect(parseSubjectUrl('/api/v1/repos/octo/repo')).toEqual({
|
||||||
|
kind: 'repo',
|
||||||
|
owner: 'octo',
|
||||||
|
repo: 'repo',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rejects non-repository URLs and non-numeric indexes', () => {
|
||||||
|
expect(parseSubjectUrl('/api/v1/user')).toBeNull();
|
||||||
|
expect(parseSubjectUrl('/repos/octo/repo/issues/not-a-number')).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,144 @@
|
|||||||
|
import { Pressable, StyleSheet, View } from 'react-native';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
|
import { AppText } from '@/components/ui/app-text';
|
||||||
|
import { Icon, type IconName } from '@/components/ui/icon';
|
||||||
|
import type { NotificationSubjectType, NotificationThread } from '@/core/api/types';
|
||||||
|
import { formatRelativeTime } from '@/core/utils/format';
|
||||||
|
import { useTheme } from '@/theme/theme-provider';
|
||||||
|
import { HIT_TARGET, radius, spacing } from '@/theme/tokens';
|
||||||
|
|
||||||
|
export type NotificationTarget =
|
||||||
|
| { kind: 'issue'; owner: string; repo: string; index: number }
|
||||||
|
| { kind: 'pull'; owner: string; repo: string; index: number }
|
||||||
|
| { kind: 'commit'; owner: string; repo: string; sha: string }
|
||||||
|
| { kind: 'repo'; owner: string; repo: string };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts a navigation target from a notification subject URL.
|
||||||
|
* Accepts both API paths (`/api/v1/repos/…`) and absolute instance URLs.
|
||||||
|
*/
|
||||||
|
export function parseSubjectUrl(url: string | undefined | null): NotificationTarget | null {
|
||||||
|
if (!url) return null;
|
||||||
|
let path = url;
|
||||||
|
try {
|
||||||
|
const parsed = new URL(url);
|
||||||
|
path = parsed.pathname;
|
||||||
|
} catch {
|
||||||
|
// Relative path — use as-is.
|
||||||
|
}
|
||||||
|
const match = path.match(
|
||||||
|
/^\/(?:api\/v1\/)?(?:repos\/)?([^/]+)\/([^/]+?)(?:\/(issues|pulls|commits?)\/([^/?#]+))?$/,
|
||||||
|
);
|
||||||
|
if (!match) return null;
|
||||||
|
const [, owner, repo, section, tail] = match;
|
||||||
|
if (section === 'issues') {
|
||||||
|
const index = Number(tail);
|
||||||
|
return Number.isInteger(index) && index > 0 ? { kind: 'issue', owner, repo, index } : null;
|
||||||
|
}
|
||||||
|
if (section === 'pulls') {
|
||||||
|
const index = Number(tail);
|
||||||
|
return Number.isInteger(index) && index > 0 ? { kind: 'pull', owner, repo, index } : null;
|
||||||
|
}
|
||||||
|
if (section === 'commits' && tail) return { kind: 'commit', owner, repo, sha: tail };
|
||||||
|
if (section === 'commit' && tail) return { kind: 'commit', owner, repo, sha: tail };
|
||||||
|
return { kind: 'repo', owner, repo };
|
||||||
|
}
|
||||||
|
|
||||||
|
function iconForType(type: NotificationSubjectType | undefined): IconName {
|
||||||
|
switch (type) {
|
||||||
|
case 'Issue':
|
||||||
|
return 'issue';
|
||||||
|
case 'Pull':
|
||||||
|
return 'pullRequest';
|
||||||
|
case 'Commit':
|
||||||
|
return 'commit';
|
||||||
|
default:
|
||||||
|
return 'repo';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface NotificationRowProps {
|
||||||
|
thread: NotificationThread;
|
||||||
|
onPress: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Inbox row: unread indicator, subject, repository and relative time. */
|
||||||
|
export function NotificationRow({ thread, onPress }: NotificationRowProps) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const { colors } = useTheme();
|
||||||
|
|
||||||
|
const unread = thread.unread === true;
|
||||||
|
const type = thread.subject?.type;
|
||||||
|
const typeLabel = {
|
||||||
|
Issue: t('inbox.typeIssue'),
|
||||||
|
Pull: t('inbox.typePull'),
|
||||||
|
Commit: t('inbox.typeCommit'),
|
||||||
|
Repository: t('inbox.typeRepository'),
|
||||||
|
}[type ?? 'Repository'];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
onPress={onPress}
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel={`${thread.subject?.title ?? ''} ${thread.repository?.full_name ?? ''}`}
|
||||||
|
style={({ pressed }) => [
|
||||||
|
styles.row,
|
||||||
|
{ borderBottomColor: colors.border },
|
||||||
|
pressed && { backgroundColor: colors.surfacePressed },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
styles.unreadDot,
|
||||||
|
{ backgroundColor: unread ? colors.primary : 'transparent' },
|
||||||
|
]}
|
||||||
|
accessibilityElementsHidden
|
||||||
|
importantForAccessibility="no"
|
||||||
|
/>
|
||||||
|
<View style={[styles.iconBox, { backgroundColor: colors.surfaceSecondary }]}>
|
||||||
|
<Icon name={iconForType(type)} size={18} color={colors.textSecondary} />
|
||||||
|
</View>
|
||||||
|
<View style={styles.body}>
|
||||||
|
<AppText variant="bodyMedium" numberOfLines={2} style={!unread && { opacity: 0.85 }}>
|
||||||
|
{thread.subject?.title ?? thread.repository?.full_name ?? ''}
|
||||||
|
</AppText>
|
||||||
|
<AppText variant="caption" tone="tertiary" numberOfLines={1}>
|
||||||
|
{[
|
||||||
|
thread.repository?.full_name,
|
||||||
|
typeLabel,
|
||||||
|
thread.updated_at ? formatRelativeTime(thread.updated_at, t) : null,
|
||||||
|
]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join(' · ')}
|
||||||
|
</AppText>
|
||||||
|
</View>
|
||||||
|
{unread ? <AppText variant="caption" tone="primary">{t('inbox.unread')}</AppText> : null}
|
||||||
|
</Pressable>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
row: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: spacing.sm,
|
||||||
|
minHeight: HIT_TARGET,
|
||||||
|
paddingVertical: spacing.md,
|
||||||
|
paddingHorizontal: spacing.lg,
|
||||||
|
borderBottomWidth: StyleSheet.hairlineWidth,
|
||||||
|
},
|
||||||
|
unreadDot: {
|
||||||
|
width: 8,
|
||||||
|
height: 8,
|
||||||
|
borderRadius: radius.pill,
|
||||||
|
},
|
||||||
|
iconBox: {
|
||||||
|
width: 32,
|
||||||
|
height: 32,
|
||||||
|
borderRadius: radius.md,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
},
|
||||||
|
body: { flex: 1, gap: 2 },
|
||||||
|
});
|
||||||
@@ -0,0 +1,119 @@
|
|||||||
|
import { Pressable, StyleSheet, View } from 'react-native';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
|
import { AppText } from '@/components/ui/app-text';
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { Icon } from '@/components/ui/icon';
|
||||||
|
import { formatCount, formatRelativeTime } from '@/core/utils/format';
|
||||||
|
import type { Repository } from '@/core/api/types';
|
||||||
|
import { useTheme } from '@/theme/theme-provider';
|
||||||
|
import { HIT_TARGET, radius, spacing } from '@/theme/tokens';
|
||||||
|
|
||||||
|
export interface RepoListItemProps {
|
||||||
|
repo: Repository;
|
||||||
|
onPress?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Repository row: owner/name, description, badges and a compact meta line. */
|
||||||
|
export function RepoListItem({ repo, onPress }: RepoListItemProps) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const { colors } = useTheme();
|
||||||
|
|
||||||
|
const owner = repo.owner?.login ?? repo.full_name.split('/')[0] ?? '';
|
||||||
|
const name = repo.name;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
onPress={onPress}
|
||||||
|
disabled={!onPress}
|
||||||
|
accessibilityRole={onPress ? 'button' : undefined}
|
||||||
|
accessibilityLabel={repo.full_name}
|
||||||
|
style={({ pressed }) => [
|
||||||
|
styles.row,
|
||||||
|
{ borderBottomColor: colors.border },
|
||||||
|
pressed && { backgroundColor: colors.surfacePressed },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<View style={[styles.iconBox, { backgroundColor: colors.surfaceSecondary }]}>
|
||||||
|
<Icon name="repo" size={20} color={colors.textSecondary} />
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<View style={styles.body}>
|
||||||
|
<View style={styles.titleLine}>
|
||||||
|
<AppText variant="caption" tone="tertiary" numberOfLines={1}>
|
||||||
|
{owner}/
|
||||||
|
</AppText>
|
||||||
|
<AppText variant="bodyMedium" numberOfLines={1} style={styles.nameText}>
|
||||||
|
{name}
|
||||||
|
</AppText>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
{repo.description ? (
|
||||||
|
<AppText variant="secondary" tone="tertiary" numberOfLines={2}>
|
||||||
|
{repo.description}
|
||||||
|
</AppText>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<View style={styles.metaLine}>
|
||||||
|
{repo.private ? <Badge tone="neutral" icon="lock">{t('repositories.private')}</Badge> : null}
|
||||||
|
{repo.fork ? <Badge tone="neutral" icon="fork">{t('repositories.fork')}</Badge> : null}
|
||||||
|
{repo.archived ? <Badge tone="warning" icon="shield">{t('repositories.archived')}</Badge> : null}
|
||||||
|
{repo.template ? <Badge tone="info" icon="package">{t('repositories.template')}</Badge> : null}
|
||||||
|
{repo.mirror ? <Badge tone="info" icon="autoRenew">{t('repositories.mirror')}</Badge> : null}
|
||||||
|
|
||||||
|
{repo.stars_count ? (
|
||||||
|
<Meta icon="starOutline" text={formatCount(repo.stars_count)} />
|
||||||
|
) : null}
|
||||||
|
{repo.forks_count ? (
|
||||||
|
<Meta icon="fork" text={formatCount(repo.forks_count)} />
|
||||||
|
) : null}
|
||||||
|
<Meta icon="clock" text={formatRelativeTime(repo.pushed_at ?? repo.updated_at, t)} />
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
{onPress ? <Icon name="chevronRight" size={16} color={colors.textTertiary} /> : null}
|
||||||
|
</Pressable>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Meta({ icon, text }: { icon: 'starOutline' | 'fork' | 'clock'; text: string }) {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
return (
|
||||||
|
<View style={styles.meta}>
|
||||||
|
<Icon name={icon} size={13} color={colors.textTertiary} />
|
||||||
|
<AppText variant="caption" tone="tertiary">
|
||||||
|
{text}
|
||||||
|
</AppText>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
row: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: spacing.md,
|
||||||
|
minHeight: HIT_TARGET,
|
||||||
|
paddingVertical: spacing.md,
|
||||||
|
paddingHorizontal: spacing.lg,
|
||||||
|
borderBottomWidth: StyleSheet.hairlineWidth,
|
||||||
|
},
|
||||||
|
iconBox: {
|
||||||
|
width: 36,
|
||||||
|
height: 36,
|
||||||
|
borderRadius: radius.md,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
},
|
||||||
|
body: { flex: 1, gap: spacing.xs },
|
||||||
|
titleLine: { flexDirection: 'row', alignItems: 'baseline', flexWrap: 'wrap' },
|
||||||
|
nameText: { flexShrink: 1 },
|
||||||
|
metaLine: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
flexWrap: 'wrap',
|
||||||
|
gap: spacing.md,
|
||||||
|
marginTop: 2,
|
||||||
|
},
|
||||||
|
meta: { flexDirection: 'row', alignItems: 'center', gap: spacing.xs },
|
||||||
|
});
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
/**
|
||||||
|
* Reusable header buttons. They navigate to root-level screens (Settings,
|
||||||
|
* Accounts modal) from anywhere by typing the navigation prop as the root
|
||||||
|
* stack — React Navigation bubbles the navigation when the screen doesn't
|
||||||
|
* exist in the current navigator.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { useNavigation } from '@react-navigation/native';
|
||||||
|
import type { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
|
import { IconButton } from '@/components/ui/icon-button';
|
||||||
|
import { useSession } from '@/features/accounts/use-session';
|
||||||
|
import { Avatar } from '@/components/ui/avatar';
|
||||||
|
import { Pressable, View } from 'react-native';
|
||||||
|
import { HIT_TARGET } from '@/theme/tokens';
|
||||||
|
import type { RootStackParamList } from '@/navigation/types';
|
||||||
|
|
||||||
|
type RootNavigation = NativeStackNavigationProp<RootStackParamList>;
|
||||||
|
|
||||||
|
export function HeaderAccountButton() {
|
||||||
|
const navigation = useNavigation<RootNavigation>();
|
||||||
|
const { account, token, instance } = useSession();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
onPress={() => navigation.navigate('Accounts', { screen: 'Accounts' })}
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel={t('accounts.title')}
|
||||||
|
hitSlop={6}
|
||||||
|
style={({ pressed }) => [
|
||||||
|
{
|
||||||
|
width: HIT_TARGET,
|
||||||
|
height: HIT_TARGET,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
borderRadius: 999,
|
||||||
|
},
|
||||||
|
pressed && { opacity: 0.7 },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Avatar
|
||||||
|
url={account?.avatarUrl ?? null}
|
||||||
|
name={account?.login ?? '?'}
|
||||||
|
size={30}
|
||||||
|
token={token}
|
||||||
|
host={instance ? new URL(instance.baseUrl).host : null}
|
||||||
|
/>
|
||||||
|
</Pressable>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function HeaderSettingsButton() {
|
||||||
|
const navigation = useNavigation<RootNavigation>();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
return (
|
||||||
|
<IconButton
|
||||||
|
name="gear"
|
||||||
|
muted
|
||||||
|
accessibilityLabel={t('settings.title')}
|
||||||
|
onPress={() => navigation.navigate('Settings', { screen: 'Settings' })}
|
||||||
|
testID="header-settings"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function HeaderAccountAndSettings() {
|
||||||
|
return (
|
||||||
|
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
|
||||||
|
<HeaderSettingsButton />
|
||||||
|
<HeaderAccountButton />
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,150 @@
|
|||||||
|
import { FlashList } from '@shopify/flash-list';
|
||||||
|
import type { ReactElement, ReactNode } from 'react';
|
||||||
|
import { ActivityIndicator, StyleSheet, View } from 'react-native';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import type { InfiniteData, UseInfiniteQueryResult } from '@tanstack/react-query';
|
||||||
|
|
||||||
|
import type { RawResponse } from '@/core/api/client';
|
||||||
|
import { apiErrorMessage } from '@/core/api/error-text';
|
||||||
|
import { ErrorState, LoadingView } from '@/components/ui/state-views';
|
||||||
|
import { Skeleton } from '@/components/ui/skeleton';
|
||||||
|
import { useTheme } from '@/theme/theme-provider';
|
||||||
|
import { spacing } from '@/theme/tokens';
|
||||||
|
|
||||||
|
type ListQuery<T> = UseInfiniteQueryResult<InfiniteData<RawResponse<T[]>>, Error>;
|
||||||
|
|
||||||
|
export interface QueryListProps<T> {
|
||||||
|
query: ListQuery<T>;
|
||||||
|
items: T[];
|
||||||
|
keyExtractor: (item: T, index: number) => string;
|
||||||
|
renderItem: (item: T, index: number) => ReactElement | null;
|
||||||
|
/** Rendered when the query succeeded with zero items. */
|
||||||
|
empty: ReactNode;
|
||||||
|
/** Rows of skeleton placeholders during the first load. */
|
||||||
|
loadingRows?: number;
|
||||||
|
header?: ReactElement;
|
||||||
|
footer?: ReactElement;
|
||||||
|
/** Extra bottom padding for the last item (avoids a clipped feel at scroll end). */
|
||||||
|
bottomInset?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One list behaviour for the whole app:
|
||||||
|
* first-load skeleton → error+retry → empty state → FlashList with pull-to-refresh
|
||||||
|
* and infinite scroll (`onEndReached` guarded by `hasNextPage`).
|
||||||
|
*/
|
||||||
|
export function QueryList<T>({
|
||||||
|
query,
|
||||||
|
items,
|
||||||
|
keyExtractor,
|
||||||
|
renderItem,
|
||||||
|
empty,
|
||||||
|
loadingRows = 6,
|
||||||
|
header,
|
||||||
|
footer,
|
||||||
|
bottomInset = spacing.xl,
|
||||||
|
}: QueryListProps<T>) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const { colors } = useTheme();
|
||||||
|
|
||||||
|
const hasData = query.data !== undefined;
|
||||||
|
|
||||||
|
if (!hasData && query.isPending) {
|
||||||
|
return (
|
||||||
|
<View style={styles.flex}>
|
||||||
|
{header}
|
||||||
|
<ListSkeleton rows={loadingRows} />
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasData && query.isError) {
|
||||||
|
return (
|
||||||
|
<View style={styles.flex}>
|
||||||
|
{header}
|
||||||
|
<ErrorState
|
||||||
|
title={t('errors.title')}
|
||||||
|
body={apiErrorMessage(query.error, t)}
|
||||||
|
retryLabel={t('common.retry')}
|
||||||
|
onRetry={() => void query.refetch()}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FlashList
|
||||||
|
data={items}
|
||||||
|
keyExtractor={keyExtractor}
|
||||||
|
renderItem={({ item, index }) => renderItem(item, index)}
|
||||||
|
onEndReachedThreshold={0.4}
|
||||||
|
onEndReached={() => {
|
||||||
|
if (query.hasNextPage && !query.isFetchingNextPage) void query.fetchNextPage();
|
||||||
|
}}
|
||||||
|
refreshing={query.isRefetching && !query.isFetchingNextPage}
|
||||||
|
onRefresh={() => void query.refetch()}
|
||||||
|
ListHeaderComponent={header}
|
||||||
|
ListEmptyComponent={query.isError ? (
|
||||||
|
<ErrorState
|
||||||
|
title={t('errors.title')}
|
||||||
|
body={apiErrorMessage(query.error, t)}
|
||||||
|
retryLabel={t('common.retry')}
|
||||||
|
onRetry={() => void query.refetch()}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<EmptyWrapper>{empty}</EmptyWrapper>
|
||||||
|
)}
|
||||||
|
ListFooterComponent={
|
||||||
|
<>
|
||||||
|
{query.isFetchingNextPage ? (
|
||||||
|
<View style={styles.footerSpinner}>
|
||||||
|
<ActivityIndicator color={colors.primary} />
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
{footer}
|
||||||
|
<View style={{ height: bottomInset }} />
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
contentContainerStyle={items.length === 0 ? styles.grow : undefined}
|
||||||
|
showsVerticalScrollIndicator
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function EmptyWrapper({ children }: { children: ReactNode }) {
|
||||||
|
return <View style={styles.empty}>{children}</View>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** First-load placeholder rows (avatar/icon + two text lines). */
|
||||||
|
export function ListSkeleton({ rows = 6 }: { rows?: number }) {
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
{Array.from({ length: rows }, (_, index) => (
|
||||||
|
<View key={index} style={styles.skeletonRow}>
|
||||||
|
<Skeleton width={36} height={36} circular />
|
||||||
|
<View style={styles.skeletonBody}>
|
||||||
|
<Skeleton width="72%" height={14} />
|
||||||
|
<Skeleton width="48%" height={12} />
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const queryListLoadingView = LoadingView;
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
flex: { flex: 1 },
|
||||||
|
grow: { flexGrow: 1 },
|
||||||
|
empty: { flexGrow: 1, paddingTop: spacing.xxl },
|
||||||
|
footerSpinner: { paddingVertical: spacing.lg, alignItems: 'center' },
|
||||||
|
skeletonRow: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: spacing.md,
|
||||||
|
paddingHorizontal: spacing.lg,
|
||||||
|
paddingVertical: spacing.md,
|
||||||
|
},
|
||||||
|
skeletonBody: { flex: 1, gap: spacing.sm },
|
||||||
|
});
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
import type { ReactNode } from 'react';
|
||||||
|
import {
|
||||||
|
ScrollView,
|
||||||
|
StyleSheet,
|
||||||
|
View,
|
||||||
|
type ScrollViewProps,
|
||||||
|
type StyleProp,
|
||||||
|
type ViewStyle,
|
||||||
|
} from 'react-native';
|
||||||
|
|
||||||
|
import { useTheme } from '@/theme/theme-provider';
|
||||||
|
import { spacing } from '@/theme/tokens';
|
||||||
|
|
||||||
|
export interface ScreenProps {
|
||||||
|
children: ReactNode;
|
||||||
|
/** Wrap in a ScrollView (default false — lists bring their own). */
|
||||||
|
scroll?: boolean;
|
||||||
|
/** Apply horizontal screen padding (default true). */
|
||||||
|
padded?: boolean;
|
||||||
|
/** Optional pull-to-refresh control forwarded to the ScrollView. */
|
||||||
|
refreshControl?: ScrollViewProps['refreshControl'];
|
||||||
|
contentContainerStyle?: StyleProp<ViewStyle>;
|
||||||
|
style?: StyleProp<ViewStyle>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Base screen container: themed background, consistent padding, optional scroll. */
|
||||||
|
export function Screen({
|
||||||
|
children,
|
||||||
|
scroll = false,
|
||||||
|
padded = true,
|
||||||
|
refreshControl,
|
||||||
|
contentContainerStyle,
|
||||||
|
style,
|
||||||
|
}: ScreenProps) {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
const padding = padded ? spacing.lg : 0;
|
||||||
|
|
||||||
|
if (scroll) {
|
||||||
|
return (
|
||||||
|
<ScrollView
|
||||||
|
style={[styles.flex, { backgroundColor: colors.background }]}
|
||||||
|
contentContainerStyle={[
|
||||||
|
styles.scrollContent,
|
||||||
|
{ padding: padding },
|
||||||
|
refreshControl ? null : { flexGrow: 1 },
|
||||||
|
contentContainerStyle,
|
||||||
|
]}
|
||||||
|
refreshControl={refreshControl}
|
||||||
|
keyboardShouldPersistTaps="handled"
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</ScrollView>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={[styles.flex, { backgroundColor: colors.background, padding }, style]}>{children}</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Standard vertical gap between stacked screen sections. */
|
||||||
|
export const SECTION_GAP = spacing.lg;
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
flex: { flex: 1 },
|
||||||
|
scrollContent: { gap: spacing.lg },
|
||||||
|
});
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import { Pressable, StyleSheet, View } from 'react-native';
|
||||||
|
|
||||||
|
import { AppText } from '@/components/ui/app-text';
|
||||||
|
import { Icon } from '@/components/ui/icon';
|
||||||
|
import { useTheme } from '@/theme/theme-provider';
|
||||||
|
import { spacing } from '@/theme/tokens';
|
||||||
|
|
||||||
|
export interface SectionHeaderProps {
|
||||||
|
title: string;
|
||||||
|
actionLabel?: string;
|
||||||
|
onAction?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Small section title with an optional "view all" action. */
|
||||||
|
export function SectionHeader({ title, actionLabel, onAction }: SectionHeaderProps) {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
return (
|
||||||
|
<View style={styles.row}>
|
||||||
|
<AppText variant="subheading" style={styles.title}>
|
||||||
|
{title}
|
||||||
|
</AppText>
|
||||||
|
{actionLabel && onAction ? (
|
||||||
|
<Pressable
|
||||||
|
onPress={onAction}
|
||||||
|
accessibilityRole="button"
|
||||||
|
style={styles.action}
|
||||||
|
hitSlop={8}
|
||||||
|
>
|
||||||
|
<AppText variant="caption" tone="primary">
|
||||||
|
{actionLabel}
|
||||||
|
</AppText>
|
||||||
|
<Icon name="chevronRight" size={13} color={colors.primary} />
|
||||||
|
</Pressable>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
row: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
gap: spacing.sm,
|
||||||
|
},
|
||||||
|
title: { flexShrink: 1 },
|
||||||
|
action: { flexDirection: 'row', alignItems: 'center', gap: 2 },
|
||||||
|
});
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
import { Text, type StyleProp, type TextProps, type TextStyle } from 'react-native';
|
||||||
|
|
||||||
|
import { useTheme } from '@/theme/theme-provider';
|
||||||
|
import { fontFamily, fontSize, fontWeight } from '@/theme/tokens';
|
||||||
|
|
||||||
|
export type TextVariant =
|
||||||
|
| 'display'
|
||||||
|
| 'title'
|
||||||
|
| 'heading'
|
||||||
|
| 'subheading'
|
||||||
|
| 'body'
|
||||||
|
| 'bodyMedium'
|
||||||
|
| 'secondary'
|
||||||
|
| 'caption'
|
||||||
|
| 'label'
|
||||||
|
| 'mono'
|
||||||
|
| 'monoSmall';
|
||||||
|
|
||||||
|
export type TextTone =
|
||||||
|
| 'default'
|
||||||
|
| 'primary'
|
||||||
|
| 'secondary'
|
||||||
|
| 'tertiary'
|
||||||
|
| 'success'
|
||||||
|
| 'warning'
|
||||||
|
| 'error'
|
||||||
|
| 'info'
|
||||||
|
| 'merged'
|
||||||
|
| 'link'
|
||||||
|
| 'onPrimary';
|
||||||
|
|
||||||
|
interface AppTextProps extends TextProps {
|
||||||
|
variant?: TextVariant;
|
||||||
|
tone?: TextTone;
|
||||||
|
style?: StyleProp<TextStyle>;
|
||||||
|
children: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
const VARIANT_STYLE: Record<TextVariant, TextStyle> = {
|
||||||
|
display: { fontSize: fontSize.xxxl, fontWeight: fontWeight.bold, lineHeight: 36 },
|
||||||
|
title: { fontSize: fontSize.xxl, fontWeight: fontWeight.bold, lineHeight: 30 },
|
||||||
|
heading: { fontSize: fontSize.xl, fontWeight: fontWeight.semibold, lineHeight: 26 },
|
||||||
|
subheading: { fontSize: fontSize.lg, fontWeight: fontWeight.semibold, lineHeight: 22 },
|
||||||
|
body: { fontSize: fontSize.md, fontWeight: fontWeight.regular, lineHeight: 21 },
|
||||||
|
bodyMedium: { fontSize: fontSize.md, fontWeight: fontWeight.medium, lineHeight: 21 },
|
||||||
|
secondary: { fontSize: fontSize.md, fontWeight: fontWeight.regular, lineHeight: 21 },
|
||||||
|
caption: { fontSize: fontSize.xs, fontWeight: fontWeight.regular, lineHeight: 16 },
|
||||||
|
label: { fontSize: fontSize.sm, fontWeight: fontWeight.semibold, lineHeight: 18 },
|
||||||
|
mono: { fontSize: fontSize.md, fontWeight: fontWeight.regular, lineHeight: 21, fontFamily: fontFamily.mono },
|
||||||
|
monoSmall: { fontSize: fontSize.sm, fontWeight: fontWeight.regular, lineHeight: 18, fontFamily: fontFamily.mono },
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The app's single text primitive. Every visible string in the app should be
|
||||||
|
* rendered through this component (usually with a translated `t()` value) so
|
||||||
|
* colors, type scale and font scaling behave consistently.
|
||||||
|
*/
|
||||||
|
export function AppText({ variant = 'body', tone = 'default', style, children, ...rest }: AppTextProps) {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
|
||||||
|
const toneColor =
|
||||||
|
tone === 'default'
|
||||||
|
? variant === 'secondary'
|
||||||
|
? colors.textSecondary
|
||||||
|
: colors.text
|
||||||
|
: {
|
||||||
|
primary: colors.primary,
|
||||||
|
secondary: colors.textSecondary,
|
||||||
|
tertiary: colors.textTertiary,
|
||||||
|
success: colors.success,
|
||||||
|
warning: colors.warning,
|
||||||
|
error: colors.error,
|
||||||
|
info: colors.info,
|
||||||
|
merged: colors.merged,
|
||||||
|
link: colors.link,
|
||||||
|
onPrimary: colors.onPrimary,
|
||||||
|
}[tone];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Text
|
||||||
|
{...rest}
|
||||||
|
maxFontSizeMultiplier={3}
|
||||||
|
style={[VARIANT_STYLE[variant], { color: toneColor }, style]}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</Text>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
import { Image } from 'expo-image';
|
||||||
|
import { StyleSheet, View } from 'react-native';
|
||||||
|
|
||||||
|
import { AppText } from '@/components/ui/app-text';
|
||||||
|
import { useTheme } from '@/theme/theme-provider';
|
||||||
|
import { radius } from '@/theme/tokens';
|
||||||
|
|
||||||
|
export interface AvatarProps {
|
||||||
|
/** Absolute avatar URL (from the API). */
|
||||||
|
url?: string | null;
|
||||||
|
/** Display name / username — used for initials fallback and alt text. */
|
||||||
|
name: string;
|
||||||
|
size?: number;
|
||||||
|
/**
|
||||||
|
* Auth token for the avatar's instance, when the instance requires auth
|
||||||
|
* for avatar requests. Never persisted — passed from the in-memory session.
|
||||||
|
*/
|
||||||
|
token?: string | null;
|
||||||
|
/** Host the URL belongs to; token is only sent to this host. */
|
||||||
|
host?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function initials(name: string): string {
|
||||||
|
const parts = name.trim().split(/[\s._-]+/).filter(Boolean);
|
||||||
|
if (parts.length === 0) return '?';
|
||||||
|
if (parts.length === 1) return parts[0].slice(0, 2).toUpperCase();
|
||||||
|
return (parts[0][0] + parts[1][0]).toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User/org avatar with initials fallback. When a token is supplied it is only
|
||||||
|
* attached to requests for the matching host (no cross-host token leakage).
|
||||||
|
*/
|
||||||
|
export function Avatar({ url, name, size = 40, token, host }: AvatarProps) {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
|
||||||
|
let headers: Record<string, string> | undefined;
|
||||||
|
if (token && host && url) {
|
||||||
|
try {
|
||||||
|
if (new URL(url).host === host) {
|
||||||
|
headers = { Authorization: `token ${token}` };
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Malformed URL → no headers, image simply fails to its own fallback.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (url) {
|
||||||
|
return (
|
||||||
|
<Image
|
||||||
|
source={{ uri: url, headers }}
|
||||||
|
style={[styles.image, { width: size, height: size, borderRadius: radius.pill }]}
|
||||||
|
contentFit="cover"
|
||||||
|
transition={150}
|
||||||
|
accessibilityLabel={name}
|
||||||
|
placeholder={{ blurhash: 'L5A[t~00~q00_300xu00~q00' }}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
styles.image,
|
||||||
|
styles.fallback,
|
||||||
|
{
|
||||||
|
width: size,
|
||||||
|
height: size,
|
||||||
|
borderRadius: radius.pill,
|
||||||
|
backgroundColor: colors.primaryMuted,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
accessibilityLabel={name}
|
||||||
|
>
|
||||||
|
<AppText
|
||||||
|
variant="label"
|
||||||
|
style={{ color: colors.primary, fontSize: Math.max(11, size * 0.36) }}
|
||||||
|
>
|
||||||
|
{initials(name)}
|
||||||
|
</AppText>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
image: { overflow: 'hidden' },
|
||||||
|
fallback: { alignItems: 'center', justifyContent: 'center' },
|
||||||
|
});
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
import { StyleSheet, View, type StyleProp, type ViewStyle } from 'react-native';
|
||||||
|
|
||||||
|
import { AppText } from '@/components/ui/app-text';
|
||||||
|
import { Icon, type IconName } from '@/components/ui/icon';
|
||||||
|
import { useTheme } from '@/theme/theme-provider';
|
||||||
|
import { radius, spacing } from '@/theme/tokens';
|
||||||
|
|
||||||
|
export type BadgeTone = 'primary' | 'success' | 'warning' | 'error' | 'info' | 'neutral' | 'merged';
|
||||||
|
|
||||||
|
export interface BadgeProps {
|
||||||
|
children: string;
|
||||||
|
tone?: BadgeTone;
|
||||||
|
icon?: IconName;
|
||||||
|
style?: StyleProp<ViewStyle>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Small pill for statuses and counts. */
|
||||||
|
export function Badge({ children, tone = 'neutral', icon, style }: BadgeProps) {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
|
||||||
|
const bg = {
|
||||||
|
primary: colors.primaryMuted,
|
||||||
|
success: colors.successMuted,
|
||||||
|
warning: colors.warningMuted,
|
||||||
|
error: colors.errorMuted,
|
||||||
|
info: colors.infoMuted,
|
||||||
|
neutral: colors.neutralMuted,
|
||||||
|
merged: colors.mergedMuted,
|
||||||
|
}[tone];
|
||||||
|
|
||||||
|
const fg = {
|
||||||
|
primary: colors.primary,
|
||||||
|
success: colors.success,
|
||||||
|
warning: colors.warning,
|
||||||
|
error: colors.error,
|
||||||
|
info: colors.info,
|
||||||
|
neutral: colors.neutral,
|
||||||
|
merged: colors.merged,
|
||||||
|
}[tone];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={[styles.pill, { backgroundColor: bg }, style]}>
|
||||||
|
{icon ? <Icon name={icon} size={12} color={fg} /> : null}
|
||||||
|
<AppText variant="caption" style={{ color: fg, fontWeight: '600' }}>
|
||||||
|
{children}
|
||||||
|
</AppText>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StatusBadgeProps {
|
||||||
|
/** 'open' | 'closed' | 'merged' | 'draft' — already translated by the caller. */
|
||||||
|
label: string;
|
||||||
|
state: 'open' | 'closed' | 'merged' | 'draft';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The canonical issue/PR state marker (GitHub-like semantics):
|
||||||
|
* open = green, closed = red, merged = purple, draft = neutral.
|
||||||
|
*/
|
||||||
|
export function StatusBadge({ label, state }: StatusBadgeProps) {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
const { tone, icon } = {
|
||||||
|
open: { tone: 'success' as const, icon: 'check' as const },
|
||||||
|
closed: { tone: 'error' as const, icon: 'close' as const },
|
||||||
|
merged: { tone: 'merged' as const, icon: 'pullRequest' as const },
|
||||||
|
draft: { tone: 'neutral' as const, icon: 'edit' as const },
|
||||||
|
}[state];
|
||||||
|
|
||||||
|
const bg = {
|
||||||
|
success: colors.successMuted,
|
||||||
|
error: colors.errorMuted,
|
||||||
|
merged: colors.mergedMuted,
|
||||||
|
neutral: colors.neutralMuted,
|
||||||
|
}[tone] as string;
|
||||||
|
|
||||||
|
const fg = {
|
||||||
|
success: colors.success,
|
||||||
|
error: colors.error,
|
||||||
|
merged: colors.merged,
|
||||||
|
neutral: colors.neutral,
|
||||||
|
}[tone] as string;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={[styles.status, { backgroundColor: bg }]}>
|
||||||
|
<Icon name={icon} size={13} color={fg} />
|
||||||
|
<AppText variant="caption" style={{ color: fg, fontWeight: '700' }}>
|
||||||
|
{label}
|
||||||
|
</AppText>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
pill: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: spacing.xs,
|
||||||
|
paddingHorizontal: spacing.sm,
|
||||||
|
paddingVertical: 3,
|
||||||
|
borderRadius: radius.pill,
|
||||||
|
alignSelf: 'flex-start',
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: spacing.xs,
|
||||||
|
paddingHorizontal: spacing.md,
|
||||||
|
paddingVertical: 4,
|
||||||
|
borderRadius: radius.pill,
|
||||||
|
alignSelf: 'flex-start',
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
/** Button: press handling, disabled and busy states (minimum touch target is CSS, not asserted). */
|
||||||
|
|
||||||
|
import { fireEvent, render, screen } from '@testing-library/react-native';
|
||||||
|
import type { ReactElement } from 'react';
|
||||||
|
|
||||||
|
import { AppThemeProvider } from '@/theme/theme-provider';
|
||||||
|
|
||||||
|
import { Button } from './button';
|
||||||
|
|
||||||
|
async function renderWithTheme(ui: ReactElement) {
|
||||||
|
await render(<AppThemeProvider>{ui}</AppThemeProvider>);
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('Button', () => {
|
||||||
|
it('renders its label and fires onPress', async () => {
|
||||||
|
const onPress = jest.fn();
|
||||||
|
await renderWithTheme(<Button label="Sign in" onPress={onPress} testID="btn" />);
|
||||||
|
expect(screen.getByTestId('btn')).toBeTruthy();
|
||||||
|
await fireEvent.press(screen.getByTestId('btn'));
|
||||||
|
expect(onPress).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not fire when disabled', async () => {
|
||||||
|
const onPress = jest.fn();
|
||||||
|
await renderWithTheme(<Button label="Sign in" onPress={onPress} disabled testID="btn" />);
|
||||||
|
await fireEvent.press(screen.getByTestId('btn'));
|
||||||
|
expect(onPress).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('blocks presses while loading and reports a busy state', async () => {
|
||||||
|
const onPress = jest.fn();
|
||||||
|
await renderWithTheme(<Button label="Sign in" onPress={onPress} loading testID="btn" />);
|
||||||
|
await fireEvent.press(screen.getByTestId('btn'));
|
||||||
|
expect(onPress).not.toHaveBeenCalled();
|
||||||
|
expect(screen.getByTestId('btn').props.accessibilityState).toMatchObject({
|
||||||
|
busy: true,
|
||||||
|
disabled: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
import {
|
||||||
|
ActivityIndicator,
|
||||||
|
Pressable,
|
||||||
|
StyleSheet,
|
||||||
|
type StyleProp,
|
||||||
|
type ViewStyle,
|
||||||
|
} from 'react-native';
|
||||||
|
|
||||||
|
import { AppText } from '@/components/ui/app-text';
|
||||||
|
import { Icon, type IconName } from '@/components/ui/icon';
|
||||||
|
import { useTheme } from '@/theme/theme-provider';
|
||||||
|
import { fontSize, fontWeight, HIT_TARGET, radius, spacing } from '@/theme/tokens';
|
||||||
|
|
||||||
|
export type ButtonVariant = 'primary' | 'secondary' | 'ghost' | 'danger';
|
||||||
|
export type ButtonSize = 'md' | 'lg';
|
||||||
|
|
||||||
|
export interface ButtonProps {
|
||||||
|
label: string;
|
||||||
|
onPress?: () => void;
|
||||||
|
variant?: ButtonVariant;
|
||||||
|
size?: ButtonSize;
|
||||||
|
iconLeft?: IconName;
|
||||||
|
iconRight?: IconName;
|
||||||
|
loading?: boolean;
|
||||||
|
disabled?: boolean;
|
||||||
|
fullWidth?: boolean;
|
||||||
|
style?: StyleProp<ViewStyle>;
|
||||||
|
accessibilityLabel?: string;
|
||||||
|
testID?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The app's primary pressable. Guarantees a 44pt minimum touch target,
|
||||||
|
* clear pressed/disabled states and a busy (loading) mode that blocks
|
||||||
|
* double-submits.
|
||||||
|
*/
|
||||||
|
export function Button({
|
||||||
|
label,
|
||||||
|
onPress,
|
||||||
|
variant = 'primary',
|
||||||
|
size = 'md',
|
||||||
|
iconLeft,
|
||||||
|
iconRight,
|
||||||
|
loading = false,
|
||||||
|
disabled = false,
|
||||||
|
fullWidth = false,
|
||||||
|
style,
|
||||||
|
accessibilityLabel,
|
||||||
|
testID,
|
||||||
|
}: ButtonProps) {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
const isDisabled = disabled || loading;
|
||||||
|
|
||||||
|
const palette = {
|
||||||
|
primary: { bg: colors.primary, pressed: colors.primaryPressed, fg: colors.onPrimary, pressedFg: colors.onPrimary },
|
||||||
|
secondary: { bg: colors.surfaceSecondary, pressed: colors.surfacePressed, fg: colors.text, pressedFg: colors.text },
|
||||||
|
ghost: { bg: 'transparent', pressed: colors.surfaceSecondary, fg: colors.primary, pressedFg: colors.primary },
|
||||||
|
danger: { bg: colors.errorMuted, pressed: colors.error, fg: colors.error, pressedFg: colors.onPrimary },
|
||||||
|
}[variant];
|
||||||
|
|
||||||
|
const height = size === 'lg' ? 50 : HIT_TARGET;
|
||||||
|
const labelSize = size === 'lg' ? fontSize.lg : fontSize.md;
|
||||||
|
const iconSize = size === 'lg' ? 20 : 18;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
onPress={onPress}
|
||||||
|
disabled={isDisabled}
|
||||||
|
testID={testID}
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel={accessibilityLabel ?? label}
|
||||||
|
accessibilityState={{ disabled: isDisabled, busy: loading }}
|
||||||
|
style={({ pressed }) => [
|
||||||
|
styles.base,
|
||||||
|
{ height, borderRadius: radius.md, backgroundColor: pressed ? palette.pressed : palette.bg },
|
||||||
|
fullWidth && styles.fullWidth,
|
||||||
|
isDisabled && { opacity: 0.55 },
|
||||||
|
style,
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
{({ pressed }) => {
|
||||||
|
if (loading) {
|
||||||
|
return (
|
||||||
|
<ActivityIndicator color={variant === 'primary' ? colors.onPrimary : colors.primary} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const fg = pressed ? palette.pressedFg : palette.fg;
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{iconLeft ? <Icon name={iconLeft} size={iconSize} color={fg} /> : null}
|
||||||
|
<AppText style={{ color: fg, fontSize: labelSize, fontWeight: fontWeight.semibold }}>
|
||||||
|
{label}
|
||||||
|
</AppText>
|
||||||
|
{iconRight ? <Icon name={iconRight} size={iconSize} color={fg} /> : null}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
</Pressable>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
base: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
gap: spacing.sm,
|
||||||
|
paddingHorizontal: spacing.lg,
|
||||||
|
},
|
||||||
|
fullWidth: { alignSelf: 'stretch' },
|
||||||
|
});
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import { Pressable, StyleSheet, type StyleProp, type ViewStyle, View } from 'react-native';
|
||||||
|
|
||||||
|
import { useTheme } from '@/theme/theme-provider';
|
||||||
|
import { radius, shadows, spacing } from '@/theme/tokens';
|
||||||
|
|
||||||
|
export interface CardProps {
|
||||||
|
children: React.ReactNode;
|
||||||
|
onPress?: () => void;
|
||||||
|
/** Subtle by default; `floating` adds a stronger shadow (for fixed footers). */
|
||||||
|
variant?: 'default' | 'flat' | 'floating';
|
||||||
|
padded?: boolean;
|
||||||
|
style?: StyleProp<ViewStyle>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Surface container used for grouped content across the app. */
|
||||||
|
export function Card({ children, onPress, variant = 'default', padded = true, style }: CardProps) {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
|
||||||
|
const base: ViewStyle = {
|
||||||
|
backgroundColor: colors.surface,
|
||||||
|
borderRadius: radius.lg,
|
||||||
|
borderWidth: variant === 'flat' ? StyleSheet.hairlineWidth : 1,
|
||||||
|
borderColor: colors.border,
|
||||||
|
padding: padded ? spacing.lg : 0,
|
||||||
|
...(variant === 'floating' ? shadows.floating : variant === 'default' ? shadows.card : null),
|
||||||
|
};
|
||||||
|
|
||||||
|
if (onPress) {
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
onPress={onPress}
|
||||||
|
accessibilityRole="button"
|
||||||
|
style={({ pressed }) => [base, pressed && { backgroundColor: colors.surfacePressed }, style]}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</Pressable>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return <View style={[base, style]}>{children}</View>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,163 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
import {
|
||||||
|
Platform,
|
||||||
|
Pressable,
|
||||||
|
StyleSheet,
|
||||||
|
TextInput,
|
||||||
|
View,
|
||||||
|
type KeyboardTypeOptions,
|
||||||
|
} from 'react-native';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
|
import { AppText } from '@/components/ui/app-text';
|
||||||
|
import { Icon, type IconName } from '@/components/ui/icon';
|
||||||
|
import { useTheme } from '@/theme/theme-provider';
|
||||||
|
import { fontSize, radius, spacing } from '@/theme/tokens';
|
||||||
|
|
||||||
|
export interface FieldProps {
|
||||||
|
label: string;
|
||||||
|
value: string;
|
||||||
|
onChangeText: (text: string) => void;
|
||||||
|
placeholder?: string;
|
||||||
|
helper?: string;
|
||||||
|
error?: string;
|
||||||
|
/** Red border + error message. */
|
||||||
|
showError?: boolean;
|
||||||
|
secureTextEntry?: boolean;
|
||||||
|
mono?: boolean;
|
||||||
|
autoCapitalize?: 'none' | 'sentences' | 'words' | 'characters';
|
||||||
|
autoCorrect?: boolean;
|
||||||
|
keyboardType?: KeyboardTypeOptions;
|
||||||
|
returnKeyType?: 'done' | 'go' | 'next' | 'search' | 'send';
|
||||||
|
onSubmitEditing?: () => void;
|
||||||
|
editable?: boolean;
|
||||||
|
/** Trailing clear (×) button when there is text. */
|
||||||
|
clearable?: boolean;
|
||||||
|
leadingIcon?: IconName;
|
||||||
|
autoFocus?: boolean;
|
||||||
|
testID?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Labeled text input with helper/error text, optional secret masking with a
|
||||||
|
* reveal toggle, and monospace mode for URLs/tokens.
|
||||||
|
*/
|
||||||
|
export function Field({
|
||||||
|
label,
|
||||||
|
value,
|
||||||
|
onChangeText,
|
||||||
|
placeholder,
|
||||||
|
helper,
|
||||||
|
error,
|
||||||
|
showError = false,
|
||||||
|
secureTextEntry = false,
|
||||||
|
mono = false,
|
||||||
|
autoCapitalize = 'none',
|
||||||
|
autoCorrect = false,
|
||||||
|
keyboardType,
|
||||||
|
returnKeyType,
|
||||||
|
onSubmitEditing,
|
||||||
|
editable = true,
|
||||||
|
clearable = false,
|
||||||
|
leadingIcon,
|
||||||
|
autoFocus = false,
|
||||||
|
testID,
|
||||||
|
}: FieldProps) {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [revealed, setRevealed] = useState(false);
|
||||||
|
|
||||||
|
const borderColor = showError && error ? colors.error : colors.border;
|
||||||
|
const resolvedSecure = secureTextEntry && !revealed;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={styles.container}>
|
||||||
|
<AppText variant="label" tone="secondary">
|
||||||
|
{label}
|
||||||
|
</AppText>
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
styles.inputRow,
|
||||||
|
{ backgroundColor: colors.surface, borderColor, borderRadius: radius.md },
|
||||||
|
!editable && { opacity: 0.6 },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
{leadingIcon ? (
|
||||||
|
<Icon name={leadingIcon} size={18} color={colors.textTertiary} style={styles.leading} />
|
||||||
|
) : null}
|
||||||
|
<TextInput
|
||||||
|
testID={testID}
|
||||||
|
value={value}
|
||||||
|
onChangeText={onChangeText}
|
||||||
|
placeholder={placeholder}
|
||||||
|
placeholderTextColor={colors.textTertiary}
|
||||||
|
secureTextEntry={resolvedSecure}
|
||||||
|
autoCapitalize={autoCapitalize}
|
||||||
|
autoCorrect={autoCorrect}
|
||||||
|
keyboardType={keyboardType}
|
||||||
|
returnKeyType={returnKeyType}
|
||||||
|
onSubmitEditing={onSubmitEditing}
|
||||||
|
editable={editable}
|
||||||
|
autoFocus={autoFocus}
|
||||||
|
maxFontSizeMultiplier={2}
|
||||||
|
style={[
|
||||||
|
styles.input,
|
||||||
|
{ color: colors.text, fontSize: fontSize.md },
|
||||||
|
mono && styles.mono,
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
{clearable && value.length > 0 && editable ? (
|
||||||
|
<Pressable
|
||||||
|
onPress={() => onChangeText('')}
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel={t('common.clearField')}
|
||||||
|
hitSlop={8}
|
||||||
|
style={styles.trailing}
|
||||||
|
>
|
||||||
|
<Icon name="close" size={16} color={colors.textTertiary} />
|
||||||
|
</Pressable>
|
||||||
|
) : null}
|
||||||
|
{secureTextEntry && editable ? (
|
||||||
|
<Pressable
|
||||||
|
onPress={() => setRevealed((r) => !r)}
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel={revealed ? t('common.hideSecret') : t('common.showSecret')}
|
||||||
|
hitSlop={8}
|
||||||
|
style={styles.trailing}
|
||||||
|
>
|
||||||
|
<Icon name={revealed ? 'eyeOff' : 'eye'} size={18} color={colors.textTertiary} />
|
||||||
|
</Pressable>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
{showError && error ? (
|
||||||
|
<AppText variant="caption" tone="error">
|
||||||
|
{error}
|
||||||
|
</AppText>
|
||||||
|
) : helper ? (
|
||||||
|
<AppText variant="caption" tone="tertiary">
|
||||||
|
{helper}
|
||||||
|
</AppText>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
container: { gap: spacing.xs },
|
||||||
|
inputRow: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
borderWidth: 1,
|
||||||
|
paddingHorizontal: spacing.md,
|
||||||
|
minHeight: 46,
|
||||||
|
},
|
||||||
|
input: {
|
||||||
|
flex: 1,
|
||||||
|
paddingVertical: spacing.sm,
|
||||||
|
},
|
||||||
|
mono: {
|
||||||
|
fontFamily: Platform.select({ ios: 'ui-monospace', android: 'monospace', default: 'monospace' }),
|
||||||
|
},
|
||||||
|
leading: { marginRight: spacing.sm },
|
||||||
|
trailing: { marginLeft: spacing.sm, padding: spacing.xs },
|
||||||
|
});
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import { Pressable, type StyleProp, type ViewStyle } from 'react-native';
|
||||||
|
|
||||||
|
import { Icon, type IconName } from '@/components/ui/icon';
|
||||||
|
import { useTheme } from '@/theme/theme-provider';
|
||||||
|
import { HIT_TARGET } from '@/theme/tokens';
|
||||||
|
|
||||||
|
export interface IconButtonProps {
|
||||||
|
name: IconName;
|
||||||
|
onPress: () => void;
|
||||||
|
accessibilityLabel: string;
|
||||||
|
size?: number;
|
||||||
|
/** Dimmed until pressed (header style) vs. always solid. */
|
||||||
|
muted?: boolean;
|
||||||
|
style?: StyleProp<ViewStyle>;
|
||||||
|
testID?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 44×44 hit-target icon button used in headers and toolbars. */
|
||||||
|
export function IconButton({
|
||||||
|
name,
|
||||||
|
onPress,
|
||||||
|
accessibilityLabel,
|
||||||
|
size = 22,
|
||||||
|
muted = false,
|
||||||
|
style,
|
||||||
|
testID,
|
||||||
|
}: IconButtonProps) {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
onPress={onPress}
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel={accessibilityLabel}
|
||||||
|
hitSlop={6}
|
||||||
|
testID={testID}
|
||||||
|
style={({ pressed }) => [
|
||||||
|
{
|
||||||
|
width: HIT_TARGET,
|
||||||
|
height: HIT_TARGET,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
borderRadius: 8,
|
||||||
|
},
|
||||||
|
pressed && { backgroundColor: colors.surfacePressed },
|
||||||
|
style,
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Icon name={name} size={size} color={muted ? colors.textSecondary : colors.text} />
|
||||||
|
</Pressable>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,212 @@
|
|||||||
|
import { MaterialIcons } from '@expo/vector-icons';
|
||||||
|
import { SymbolView, type SymbolViewProps } from 'expo-symbols';
|
||||||
|
import { Platform, type StyleProp, type TextStyle } from 'react-native';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cross-platform icon: SF Symbols on iOS, Material Icons on Android/web.
|
||||||
|
* Every name is verified against both glyph sets.
|
||||||
|
*/
|
||||||
|
export type IconName =
|
||||||
|
| 'home'
|
||||||
|
| 'repo'
|
||||||
|
| 'file'
|
||||||
|
| 'folder'
|
||||||
|
| 'issue'
|
||||||
|
| 'pullRequest'
|
||||||
|
| 'bell'
|
||||||
|
| 'search'
|
||||||
|
| 'chevronLeft'
|
||||||
|
| 'chevronRight'
|
||||||
|
| 'chevronDown'
|
||||||
|
| 'close'
|
||||||
|
| 'check'
|
||||||
|
| 'plus'
|
||||||
|
| 'refresh'
|
||||||
|
| 'lock'
|
||||||
|
| 'person'
|
||||||
|
| 'people'
|
||||||
|
| 'star'
|
||||||
|
| 'starOutline'
|
||||||
|
| 'fork'
|
||||||
|
| 'branch'
|
||||||
|
| 'commit'
|
||||||
|
| 'tag'
|
||||||
|
| 'gear'
|
||||||
|
| 'externalLink'
|
||||||
|
| 'shield'
|
||||||
|
| 'globe'
|
||||||
|
| 'moon'
|
||||||
|
| 'sun'
|
||||||
|
| 'trash'
|
||||||
|
| 'info'
|
||||||
|
| 'warning'
|
||||||
|
| 'eye'
|
||||||
|
| 'eyeOff'
|
||||||
|
| 'copy'
|
||||||
|
| 'sort'
|
||||||
|
| 'filter'
|
||||||
|
| 'clock'
|
||||||
|
| 'at'
|
||||||
|
| 'package'
|
||||||
|
| 'book'
|
||||||
|
| 'key'
|
||||||
|
| 'inbox'
|
||||||
|
| 'mail'
|
||||||
|
| 'link'
|
||||||
|
| 'code'
|
||||||
|
| 'download'
|
||||||
|
| 'more'
|
||||||
|
| 'arrowLeft'
|
||||||
|
| 'history'
|
||||||
|
| 'dashboard'
|
||||||
|
| 'sortByDate'
|
||||||
|
| 'autoRenew'
|
||||||
|
| 'blocked'
|
||||||
|
| 'verified'
|
||||||
|
| 'unverified'
|
||||||
|
| 'edit';
|
||||||
|
|
||||||
|
const SF: Record<IconName, SymbolViewProps['name']> = {
|
||||||
|
home: 'house.fill',
|
||||||
|
repo: 'folder.fill',
|
||||||
|
file: 'doc.text',
|
||||||
|
folder: 'folder.fill',
|
||||||
|
issue: 'exclamationmark.circle',
|
||||||
|
pullRequest: 'arrow.triangle.merge',
|
||||||
|
bell: 'bell.fill',
|
||||||
|
search: 'magnifyingglass',
|
||||||
|
chevronLeft: 'chevron.left',
|
||||||
|
chevronRight: 'chevron.right',
|
||||||
|
chevronDown: 'chevron.down',
|
||||||
|
close: 'xmark',
|
||||||
|
check: 'checkmark',
|
||||||
|
plus: 'plus',
|
||||||
|
refresh: 'arrow.clockwise',
|
||||||
|
lock: 'lock.fill',
|
||||||
|
person: 'person.fill',
|
||||||
|
people: 'person.2.fill',
|
||||||
|
star: 'star.fill',
|
||||||
|
starOutline: 'star',
|
||||||
|
fork: 'arrow.triangle.branch',
|
||||||
|
branch: 'chevron.left.chevron.right',
|
||||||
|
commit: 'chevron.left.slash.chevron.right',
|
||||||
|
tag: 'tag.fill',
|
||||||
|
gear: 'gearshape',
|
||||||
|
externalLink: 'arrow.up.right.square',
|
||||||
|
shield: 'shield.fill',
|
||||||
|
globe: 'globe',
|
||||||
|
moon: 'moon.fill',
|
||||||
|
sun: 'sun.max.fill',
|
||||||
|
trash: 'trash',
|
||||||
|
info: 'info.circle',
|
||||||
|
warning: 'exclamationmark.triangle',
|
||||||
|
eye: 'eye.fill',
|
||||||
|
eyeOff: 'eye.slash.fill',
|
||||||
|
copy: 'doc.on.doc',
|
||||||
|
sort: 'arrow.up.arrow.down',
|
||||||
|
filter: 'line.3.horizontal.decrease',
|
||||||
|
clock: 'clock',
|
||||||
|
at: 'at',
|
||||||
|
package: 'shippingbox.fill',
|
||||||
|
book: 'book.closed.fill',
|
||||||
|
key: 'key.fill',
|
||||||
|
inbox: 'tray.fill',
|
||||||
|
mail: 'envelope.fill',
|
||||||
|
link: 'link',
|
||||||
|
code: 'chevron.left.forwardslash.chevron.right',
|
||||||
|
download: 'arrow.down.to.line',
|
||||||
|
more: 'ellipsis',
|
||||||
|
arrowLeft: 'arrow.left',
|
||||||
|
history: 'clock.arrow.circlepath',
|
||||||
|
dashboard: 'square.grid.2x2.fill',
|
||||||
|
sortByDate: 'calendar',
|
||||||
|
autoRenew: 'arrow.2.circlepath',
|
||||||
|
blocked: 'nosign',
|
||||||
|
verified: 'checkmark.seal.fill',
|
||||||
|
unverified: 'questionmark.circle',
|
||||||
|
edit: 'pencil',
|
||||||
|
};
|
||||||
|
|
||||||
|
const MD: Record<IconName, keyof typeof MaterialIcons.glyphMap> = {
|
||||||
|
home: 'home',
|
||||||
|
repo: 'folder',
|
||||||
|
file: 'insert-drive-file',
|
||||||
|
folder: 'folder',
|
||||||
|
issue: 'radio-button-unchecked',
|
||||||
|
pullRequest: 'merge-type',
|
||||||
|
bell: 'notifications',
|
||||||
|
search: 'search',
|
||||||
|
chevronLeft: 'chevron-left',
|
||||||
|
chevronRight: 'chevron-right',
|
||||||
|
chevronDown: 'expand-more',
|
||||||
|
close: 'close',
|
||||||
|
check: 'check',
|
||||||
|
plus: 'add',
|
||||||
|
refresh: 'refresh',
|
||||||
|
lock: 'lock',
|
||||||
|
person: 'person',
|
||||||
|
people: 'people',
|
||||||
|
star: 'star',
|
||||||
|
starOutline: 'star-border',
|
||||||
|
fork: 'call-split',
|
||||||
|
branch: 'account-tree',
|
||||||
|
commit: 'commit',
|
||||||
|
tag: 'label',
|
||||||
|
gear: 'settings',
|
||||||
|
externalLink: 'open-in-new',
|
||||||
|
shield: 'shield',
|
||||||
|
globe: 'public',
|
||||||
|
moon: 'dark-mode',
|
||||||
|
sun: 'light-mode',
|
||||||
|
trash: 'delete',
|
||||||
|
info: 'info-outline',
|
||||||
|
warning: 'warning-amber',
|
||||||
|
eye: 'visibility',
|
||||||
|
eyeOff: 'visibility-off',
|
||||||
|
copy: 'content-copy',
|
||||||
|
sort: 'sort',
|
||||||
|
filter: 'filter-list',
|
||||||
|
clock: 'schedule',
|
||||||
|
at: 'alternate-email',
|
||||||
|
package: 'inventory-2',
|
||||||
|
book: 'menu-book',
|
||||||
|
key: 'key',
|
||||||
|
inbox: 'inbox',
|
||||||
|
mail: 'mail-outline',
|
||||||
|
link: 'link',
|
||||||
|
code: 'code',
|
||||||
|
download: 'download',
|
||||||
|
more: 'more-horiz',
|
||||||
|
arrowLeft: 'arrow-back',
|
||||||
|
history: 'history',
|
||||||
|
dashboard: 'dashboard',
|
||||||
|
sortByDate: 'schedule',
|
||||||
|
autoRenew: 'autorenew',
|
||||||
|
blocked: 'block',
|
||||||
|
verified: 'verified-user',
|
||||||
|
unverified: 'gpp-maybe',
|
||||||
|
edit: 'edit',
|
||||||
|
};
|
||||||
|
|
||||||
|
export interface IconProps {
|
||||||
|
name: IconName;
|
||||||
|
size?: number;
|
||||||
|
color?: string;
|
||||||
|
style?: StyleProp<TextStyle>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Icon({ name, size = 20, color, style }: IconProps) {
|
||||||
|
if (Platform.OS === 'ios' || Platform.OS === 'macos') {
|
||||||
|
return (
|
||||||
|
<SymbolView
|
||||||
|
name={SF[name]}
|
||||||
|
size={size}
|
||||||
|
tintColor={color}
|
||||||
|
style={style}
|
||||||
|
resizeMode="scaleAspectFit"
|
||||||
|
weight="regular"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return <MaterialIcons name={MD[name]} size={size} color={color} style={style} />;
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
import { StyleSheet, View } from 'react-native';
|
||||||
|
|
||||||
|
import { AppText } from '@/components/ui/app-text';
|
||||||
|
import { useTheme } from '@/theme/theme-provider';
|
||||||
|
import { fontSize, radius, spacing } from '@/theme/tokens';
|
||||||
|
|
||||||
|
/** Computes readable foreground text for an arbitrary background color. */
|
||||||
|
export function contrastForeground(hex: string): string {
|
||||||
|
const clean = hex.replace('#', '');
|
||||||
|
const full =
|
||||||
|
clean.length === 3
|
||||||
|
? clean
|
||||||
|
.split('')
|
||||||
|
.map((c) => c + c)
|
||||||
|
.join('')
|
||||||
|
: clean;
|
||||||
|
if (full.length !== 6) return '#FFFFFF';
|
||||||
|
const r = parseInt(full.slice(0, 2), 16);
|
||||||
|
const g = parseInt(full.slice(2, 4), 16);
|
||||||
|
const b = parseInt(full.slice(4, 6), 16);
|
||||||
|
if ([r, g, b].some((v) => Number.isNaN(v))) return '#FFFFFF';
|
||||||
|
// WCAG relative luminance.
|
||||||
|
const luminance = (0.2126 * r + 0.7152 * g + 0.0722 * b) / 255;
|
||||||
|
return luminance > 0.62 ? '#172019' : '#FFFFFF';
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LabelChipProps {
|
||||||
|
name: string;
|
||||||
|
/** Gitea label color, with or without '#'. */
|
||||||
|
color?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders a Gitea label as a solid chip using the server-provided color,
|
||||||
|
* with contrast-aware text color. Falls back to the neutral palette when
|
||||||
|
* the color is missing or malformed.
|
||||||
|
*/
|
||||||
|
export function LabelChip({ name, color }: LabelChipProps) {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
let background: string | null = null;
|
||||||
|
if (color && /^#?[0-9a-fA-F]{3}([0-9a-fA-F]{3})?$/.test(color)) {
|
||||||
|
background = color.startsWith('#') ? color : `#${color}`;
|
||||||
|
}
|
||||||
|
const foreground = background ? contrastForeground(background) : null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
styles.chip,
|
||||||
|
background
|
||||||
|
? { backgroundColor: background }
|
||||||
|
: {
|
||||||
|
backgroundColor: colors.neutralMuted,
|
||||||
|
borderWidth: StyleSheet.hairlineWidth,
|
||||||
|
borderColor: colors.border,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<AppText
|
||||||
|
variant="caption"
|
||||||
|
numberOfLines={1}
|
||||||
|
style={[styles.text, foreground ? { color: foreground } : { color: colors.textSecondary }]}
|
||||||
|
>
|
||||||
|
{name}
|
||||||
|
</AppText>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
chip: {
|
||||||
|
paddingHorizontal: spacing.sm,
|
||||||
|
paddingVertical: 2,
|
||||||
|
borderRadius: radius.pill,
|
||||||
|
maxWidth: 180,
|
||||||
|
},
|
||||||
|
text: {
|
||||||
|
fontSize: fontSize.xs,
|
||||||
|
fontWeight: '700',
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
import { Pressable, StyleSheet, View, type StyleProp, type ViewStyle } from 'react-native';
|
||||||
|
|
||||||
|
import { AppText } from '@/components/ui/app-text';
|
||||||
|
import { Icon, type IconName } from '@/components/ui/icon';
|
||||||
|
import { useTheme } from '@/theme/theme-provider';
|
||||||
|
import { HIT_TARGET, radius, spacing } from '@/theme/tokens';
|
||||||
|
|
||||||
|
export interface ListItemProps {
|
||||||
|
title: string;
|
||||||
|
subtitle?: string;
|
||||||
|
/** Third line (e.g. timestamps or meta). */
|
||||||
|
meta?: string;
|
||||||
|
/** Leading visual: an icon name (rendered in a tinted square). */
|
||||||
|
leadingIcon?: IconName;
|
||||||
|
/** Extra content on the left, e.g. an <Avatar/> (takes precedence). */
|
||||||
|
leading?: React.ReactNode;
|
||||||
|
/** Right-aligned content, e.g. a Badge. */
|
||||||
|
trailing?: React.ReactNode;
|
||||||
|
/** Show a chevron on the right (default true when onPress is set). */
|
||||||
|
showChevron?: boolean;
|
||||||
|
/** Right-aligned numeric/meta text instead of a chevron. */
|
||||||
|
rightText?: string;
|
||||||
|
onPress?: () => void;
|
||||||
|
/** Adds a bottom divider (list look). */
|
||||||
|
divider?: boolean;
|
||||||
|
style?: StyleProp<ViewStyle>;
|
||||||
|
accessibilityLabel?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Standard row used in every list in the app. */
|
||||||
|
export function ListItem({
|
||||||
|
title,
|
||||||
|
subtitle,
|
||||||
|
meta,
|
||||||
|
leadingIcon,
|
||||||
|
leading,
|
||||||
|
trailing,
|
||||||
|
showChevron,
|
||||||
|
rightText,
|
||||||
|
onPress,
|
||||||
|
divider = true,
|
||||||
|
style,
|
||||||
|
accessibilityLabel,
|
||||||
|
}: ListItemProps) {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
const chevron = showChevron ?? Boolean(onPress);
|
||||||
|
|
||||||
|
const content = (
|
||||||
|
<View style={[styles.row, divider && { borderBottomWidth: StyleSheet.hairlineWidth, borderBottomColor: colors.border }, style]}>
|
||||||
|
{leading ?? (leadingIcon ? (
|
||||||
|
<View style={[styles.iconBox, { backgroundColor: colors.surfaceSecondary }]}>
|
||||||
|
<Icon name={leadingIcon} size={20} color={colors.textSecondary} />
|
||||||
|
</View>
|
||||||
|
) : null)}
|
||||||
|
<View style={styles.body}>
|
||||||
|
<AppText variant="bodyMedium" numberOfLines={2}>
|
||||||
|
{title}
|
||||||
|
</AppText>
|
||||||
|
{subtitle ? (
|
||||||
|
<AppText variant="secondary" tone="tertiary" numberOfLines={2}>
|
||||||
|
{subtitle}
|
||||||
|
</AppText>
|
||||||
|
) : null}
|
||||||
|
{meta ? (
|
||||||
|
<AppText variant="caption" tone="tertiary" numberOfLines={1}>
|
||||||
|
{meta}
|
||||||
|
</AppText>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
{trailing ? <View style={styles.trailing}>{trailing}</View> : null}
|
||||||
|
{rightText ? (
|
||||||
|
<AppText variant="caption" tone="tertiary" style={styles.trailingText}>
|
||||||
|
{rightText}
|
||||||
|
</AppText>
|
||||||
|
) : null}
|
||||||
|
{chevron && !trailing ? (
|
||||||
|
<Icon name="chevronRight" size={16} color={colors.textTertiary} style={styles.chevron} />
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!onPress) return content;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
onPress={onPress}
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel={accessibilityLabel ?? title}
|
||||||
|
style={({ pressed }) => pressed && { backgroundColor: colors.surfacePressed }}
|
||||||
|
>
|
||||||
|
{content}
|
||||||
|
</Pressable>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
row: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: spacing.md,
|
||||||
|
minHeight: HIT_TARGET,
|
||||||
|
paddingVertical: spacing.md,
|
||||||
|
paddingHorizontal: spacing.lg,
|
||||||
|
},
|
||||||
|
iconBox: {
|
||||||
|
width: 36,
|
||||||
|
height: 36,
|
||||||
|
borderRadius: radius.md,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
},
|
||||||
|
body: { flex: 1, gap: 2 },
|
||||||
|
trailing: { alignItems: 'flex-end', gap: 2 },
|
||||||
|
trailingText: { textAlign: 'right' },
|
||||||
|
chevron: { marginLeft: spacing.xs },
|
||||||
|
});
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
import { Pressable, StyleSheet, TextInput, View } from 'react-native';
|
||||||
|
|
||||||
|
import { Icon } from '@/components/ui/icon';
|
||||||
|
import { useTheme } from '@/theme/theme-provider';
|
||||||
|
import { fontSize, radius, spacing } from '@/theme/tokens';
|
||||||
|
|
||||||
|
export interface SearchBarProps {
|
||||||
|
value: string;
|
||||||
|
onChangeText: (text: string) => void;
|
||||||
|
placeholder: string;
|
||||||
|
accessibilityLabel?: string;
|
||||||
|
testID?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Rounded search field used above every list. */
|
||||||
|
export function SearchBar({
|
||||||
|
value,
|
||||||
|
onChangeText,
|
||||||
|
placeholder,
|
||||||
|
accessibilityLabel,
|
||||||
|
testID,
|
||||||
|
}: SearchBarProps) {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
return (
|
||||||
|
<View style={[styles.wrap, { backgroundColor: colors.surfaceSecondary }]}>
|
||||||
|
<Icon name="search" size={17} color={colors.textTertiary} />
|
||||||
|
<TextInput
|
||||||
|
testID={testID}
|
||||||
|
value={value}
|
||||||
|
onChangeText={onChangeText}
|
||||||
|
placeholder={placeholder}
|
||||||
|
placeholderTextColor={colors.textTertiary}
|
||||||
|
accessibilityLabel={accessibilityLabel ?? placeholder}
|
||||||
|
autoCapitalize="none"
|
||||||
|
autoCorrect={false}
|
||||||
|
returnKeyType="search"
|
||||||
|
clearButtonMode="never"
|
||||||
|
maxFontSizeMultiplier={2}
|
||||||
|
style={[styles.input, { color: colors.text }]}
|
||||||
|
/>
|
||||||
|
{value.length > 0 ? (
|
||||||
|
<Pressable
|
||||||
|
onPress={() => onChangeText('')}
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel={placeholder}
|
||||||
|
hitSlop={8}
|
||||||
|
>
|
||||||
|
<Icon name="close" size={16} color={colors.textSecondary} />
|
||||||
|
</Pressable>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
wrap: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: spacing.sm,
|
||||||
|
borderRadius: radius.md,
|
||||||
|
paddingHorizontal: spacing.md,
|
||||||
|
minHeight: 40,
|
||||||
|
marginHorizontal: spacing.lg,
|
||||||
|
marginVertical: spacing.sm,
|
||||||
|
},
|
||||||
|
input: {
|
||||||
|
flex: 1,
|
||||||
|
fontSize: fontSize.md,
|
||||||
|
paddingVertical: spacing.sm,
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
import { Pressable, StyleSheet, View } from 'react-native';
|
||||||
|
|
||||||
|
import { AppText } from '@/components/ui/app-text';
|
||||||
|
import { useTheme } from '@/theme/theme-provider';
|
||||||
|
import { fontSize, radius, spacing } from '@/theme/tokens';
|
||||||
|
|
||||||
|
export interface SegmentedControlProps<T extends string> {
|
||||||
|
options: readonly { value: T; label: string }[];
|
||||||
|
value: T;
|
||||||
|
onChange: (value: T) => void;
|
||||||
|
/** Accessibility name for the whole control. */
|
||||||
|
accessibilityLabel?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* iOS-style segmented control (also used on Android for consistency).
|
||||||
|
* Options split evenly; fits up to ~4 options comfortably, wraps beyond that.
|
||||||
|
*/
|
||||||
|
export function SegmentedControl<T extends string>({
|
||||||
|
options,
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
accessibilityLabel,
|
||||||
|
}: SegmentedControlProps<T>) {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
style={[styles.track, { backgroundColor: colors.surfaceSecondary }]}
|
||||||
|
accessibilityRole="tablist"
|
||||||
|
accessibilityLabel={accessibilityLabel}
|
||||||
|
>
|
||||||
|
{options.map((option) => {
|
||||||
|
const selected = option.value === value;
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
key={option.value}
|
||||||
|
onPress={() => onChange(option.value)}
|
||||||
|
accessibilityRole="tab"
|
||||||
|
accessibilityState={{ selected }}
|
||||||
|
style={[
|
||||||
|
styles.segment,
|
||||||
|
selected && { backgroundColor: colors.surface, borderColor: colors.border },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<AppText
|
||||||
|
variant="caption"
|
||||||
|
numberOfLines={1}
|
||||||
|
style={[
|
||||||
|
styles.label,
|
||||||
|
{ color: selected ? colors.text : colors.textSecondary },
|
||||||
|
selected && { fontWeight: '700' },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
{option.label}
|
||||||
|
</AppText>
|
||||||
|
</Pressable>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
track: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
borderRadius: radius.md,
|
||||||
|
padding: 3,
|
||||||
|
gap: 3,
|
||||||
|
},
|
||||||
|
segment: {
|
||||||
|
flex: 1,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
paddingVertical: spacing.sm,
|
||||||
|
paddingHorizontal: spacing.sm,
|
||||||
|
borderRadius: radius.sm,
|
||||||
|
borderWidth: StyleSheet.hairlineWidth,
|
||||||
|
borderColor: 'transparent',
|
||||||
|
minHeight: 34,
|
||||||
|
},
|
||||||
|
label: { fontSize: fontSize.sm },
|
||||||
|
});
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
import { useEffect } from 'react';
|
||||||
|
import { type StyleProp, type ViewStyle } from 'react-native';
|
||||||
|
import Animated, {
|
||||||
|
useAnimatedStyle,
|
||||||
|
useSharedValue,
|
||||||
|
withRepeat,
|
||||||
|
withTiming,
|
||||||
|
} from 'react-native-reanimated';
|
||||||
|
|
||||||
|
import { useTheme } from '@/theme/theme-provider';
|
||||||
|
import { radius, spacing } from '@/theme/tokens';
|
||||||
|
|
||||||
|
export interface SkeletonProps {
|
||||||
|
width?: number | `${number}%`;
|
||||||
|
height?: number;
|
||||||
|
/** Corner radius; defaults to a small pill for text-like shapes. */
|
||||||
|
circular?: boolean;
|
||||||
|
style?: StyleProp<ViewStyle>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Content-loading placeholder with a gentle pulse (Reanimated, UI-thread).
|
||||||
|
* Respect for reduced-motion is handled by the OS reducing animation scale;
|
||||||
|
* the pulse is opacity-only to stay cheap.
|
||||||
|
*/
|
||||||
|
export function Skeleton({ width = '100%', height = 16, circular = false, style }: SkeletonProps) {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
const progress = useSharedValue(0.5);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
progress.value = withRepeat(withTiming(1, { duration: 900 }), -1, true);
|
||||||
|
}, [progress]);
|
||||||
|
|
||||||
|
const animatedStyle = useAnimatedStyle(() => ({ opacity: progress.value }));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Animated.View
|
||||||
|
accessibilityElementsHidden
|
||||||
|
importantForAccessibility="no-hide-descendants"
|
||||||
|
style={[
|
||||||
|
{
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
borderRadius: circular ? height / 2 : radius.sm,
|
||||||
|
backgroundColor: colors.surfaceSecondary,
|
||||||
|
},
|
||||||
|
animatedStyle,
|
||||||
|
style,
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Stack of skeleton lines with varying widths, for list/text placeholders. */
|
||||||
|
export function SkeletonText({ lines = 3, style }: { lines?: number; style?: StyleProp<ViewStyle> }) {
|
||||||
|
const widths: `${number}%`[] = ['100%', '86%', '64%', '92%', '74%'];
|
||||||
|
return (
|
||||||
|
<Animated.View style={[{ gap: spacing.sm }, style]}>
|
||||||
|
{Array.from({ length: lines }, (_, i) => (
|
||||||
|
<Skeleton key={i} width={widths[i % widths.length]} height={14} />
|
||||||
|
))}
|
||||||
|
</Animated.View>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,115 @@
|
|||||||
|
import { ActivityIndicator, StyleSheet, View, type StyleProp, type ViewStyle } from 'react-native';
|
||||||
|
|
||||||
|
import { AppText } from '@/components/ui/app-text';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Icon, type IconName } from '@/components/ui/icon';
|
||||||
|
import { useTheme } from '@/theme/theme-provider';
|
||||||
|
import { radius, spacing } from '@/theme/tokens';
|
||||||
|
|
||||||
|
/** Centered spinner with an optional label — used for first-page loads. */
|
||||||
|
export function LoadingView({ label, style }: { label?: string; style?: StyleProp<ViewStyle> }) {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
return (
|
||||||
|
<View style={[styles.center, style]} accessibilityRole="progressbar">
|
||||||
|
<ActivityIndicator color={colors.primary} size="large" />
|
||||||
|
{label ? (
|
||||||
|
<AppText variant="secondary" tone="tertiary" style={{ marginTop: spacing.md }}>
|
||||||
|
{label}
|
||||||
|
</AppText>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EmptyStateProps {
|
||||||
|
icon?: IconName;
|
||||||
|
title: string;
|
||||||
|
body?: string;
|
||||||
|
actionLabel?: string;
|
||||||
|
onAction?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Friendly "nothing here" state — never a blank screen. */
|
||||||
|
export function EmptyState({ icon = 'inbox', title, body, actionLabel, onAction }: EmptyStateProps) {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
return (
|
||||||
|
<View style={styles.center}>
|
||||||
|
<View
|
||||||
|
style={[styles.iconCircle, { backgroundColor: colors.surfaceSecondary }]}
|
||||||
|
accessibilityElementsHidden
|
||||||
|
importantForAccessibility="no"
|
||||||
|
>
|
||||||
|
<Icon name={icon} size={28} color={colors.textTertiary} />
|
||||||
|
</View>
|
||||||
|
<AppText variant="subheading" style={{ textAlign: 'center' }}>
|
||||||
|
{title}
|
||||||
|
</AppText>
|
||||||
|
{body ? (
|
||||||
|
<AppText variant="secondary" tone="tertiary" style={{ textAlign: 'center' }}>
|
||||||
|
{body}
|
||||||
|
</AppText>
|
||||||
|
) : null}
|
||||||
|
{actionLabel && onAction ? (
|
||||||
|
<Button label={actionLabel} variant="secondary" onPress={onAction} style={{ marginTop: spacing.sm }} />
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ErrorStateProps {
|
||||||
|
title?: string;
|
||||||
|
body?: string;
|
||||||
|
onRetry?: () => void;
|
||||||
|
retryLabel: string;
|
||||||
|
style?: StyleProp<ViewStyle>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Error state with retry — the message body is already localized by the caller. */
|
||||||
|
export function ErrorState({ title, body, onRetry, retryLabel, style }: ErrorStateProps) {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
return (
|
||||||
|
<View style={[styles.center, style]}>
|
||||||
|
<View
|
||||||
|
style={[styles.iconCircle, { backgroundColor: colors.errorMuted }]}
|
||||||
|
accessibilityElementsHidden
|
||||||
|
importantForAccessibility="no"
|
||||||
|
>
|
||||||
|
<Icon name="warning" size={26} color={colors.error} />
|
||||||
|
</View>
|
||||||
|
<AppText variant="subheading" style={{ textAlign: 'center' }}>
|
||||||
|
{title}
|
||||||
|
</AppText>
|
||||||
|
{body ? (
|
||||||
|
<AppText variant="secondary" tone="tertiary" style={{ textAlign: 'center' }}>
|
||||||
|
{body}
|
||||||
|
</AppText>
|
||||||
|
) : null}
|
||||||
|
{onRetry ? (
|
||||||
|
<Button
|
||||||
|
label={retryLabel}
|
||||||
|
variant="secondary"
|
||||||
|
iconLeft="refresh"
|
||||||
|
onPress={onRetry}
|
||||||
|
style={{ marginTop: spacing.sm }}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
center: {
|
||||||
|
flexGrow: 1,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
gap: spacing.md,
|
||||||
|
padding: spacing.xl,
|
||||||
|
},
|
||||||
|
iconCircle: {
|
||||||
|
width: 64,
|
||||||
|
height: 64,
|
||||||
|
borderRadius: radius.pill,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
},
|
||||||
|
});
|
||||||
Reference in new issue
Block a user