Files
o2o-weather/mobile/src/components/today/rails.tsx
T

55 lines
2.1 KiB
TypeScript

import type { BandArticle } from '@nalssigak/shared/api/client/types.gen';
import { cardBg } from '@nalssigak/shared/lib';
import { LinearGradient } from 'expo-linear-gradient';
import type { Href } from 'expo-router';
import type { ReactNode } from 'react';
import { Pressable, View } from 'react-native';
import { Text } from '@/components/text';
import { Rail, Sec, Thumb } from '@/components/ui';
import { CARD_BG, BAND_BG } from '@/lib/colors';
import { useSheet } from '@/lib/sheet';
import { useSky } from '@/lib/sky';
const CARD = 'overflow-hidden rounded-[22px] border-b-[5px] border-shade bg-card';
function Band({ tone, title, sub, to, children }: { tone: 1 | 2 | 3; title: string; sub: string; to: Href; children: ReactNode }) {
const { kind } = useSky();
return (
<View className="mt-3.5 pb-3.5" accessibilityLabel={title}>
<LinearGradient colors={BAND_BG[kind === 'night' ? 'night' : 'day'][tone]} style={{ position: 'absolute', inset: 0 }} />
<View className="-mt-[6px]">
<Sec title={title} sub={sub} more={to} />
</View>
{children}
</View>
);
}
function useCardBg() {
const { kind } = useSky();
return CARD_BG[kind === 'night' ? 'night' : 'day'];
}
export function SeasonBand({ news }: { news: BandArticle[] }) {
const bg = useCardBg();
const { open } = useSheet();
return (
<Band tone={3} title="이번 주 계절 이야기" sub="예년 이맘때의 소식" to="/season">
<Rail>
{news.map((a) => (
<Pressable key={a.article_id} onPress={() => open({ type: 'article', articleId: a.article_id })} className={`w-[200px] ${CARD}`}>
<Thumb image={a.image} icon={a.icon} iconSize={76} className="h-[116px]">
<LinearGradient colors={bg[cardBg(a.icon, a.article_id)]} style={{ position: 'absolute', inset: 0, zIndex: -1 }} />
</Thumb>
<View className="px-3 pt-2.5 pb-3">
<Text className="font-jua text-[16.5px] leading-snug text-ink">{a.title}</Text>
<Text className="text-[12.5px] font-semibold text-ink2">{a.meta}</Text>
</View>
</Pressable>
))}
</Rail>
</Band>
);
}