feat(mp): 小程序统一组件库 Phase 1 — Token 扩展 + 10 组件 + useListPage Hook

三层架构组件库:
- 第 1 层原子组件:PageShell/ContentCard/StatusTag/SectionTitle/LoadingCard
- 第 2 层组合模式:PageHeader/SearchSection/CardList/PaginationBar
- 第 3 层 Hook:useListPage(列表页通用逻辑抽象)

Token 扩展:新增 --tk-card-*/--tk-gap-*/--tk-page-* 等结构化 CSS 变量,
关怀模式通过变量覆写自动生效,新组件零额外代码即获关怀支持。

设计规格:docs/superpowers/specs/2026-05-16-miniprogram-unified-components-design.md
This commit is contained in:
iven
2026-05-16 00:47:39 +08:00
parent 3fb5a77ac0
commit d758563a13
21 changed files with 1138 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
@import '../../styles/variables';
.content-card {
background: var(--tk-card-bg);
border-radius: var(--tk-card-radius);
box-shadow: $shadow-sm;
margin-bottom: var(--tk-gap-md);
transition: background 0.15s, opacity 0.15s, transform 0.15s;
&--outlined {
box-shadow: none;
border: 1px solid $bd;
}
&--elevated {
box-shadow: $shadow-md;
}
&--pressable {
cursor: pointer;
}
&--feedback-bg.content-card--pressable:active {
background: $bd-l;
}
&--feedback-opacity.content-card--pressable:active {
opacity: var(--tk-touch-feedback-opacity);
}
&--feedback-scale.content-card--pressable:active {
transform: scale(0.98);
}
}

View File

@@ -0,0 +1,52 @@
import { View } from '@tarojs/components';
import { CSSProperties, ReactNode, useMemo } from 'react';
import './index.scss';
interface ContentCardProps {
variant?: 'default' | 'outlined' | 'elevated';
onPress?: () => void;
padding?: 'none' | 'sm' | 'md' | 'lg';
activeFeedback?: 'bg' | 'opacity' | 'scale' | 'none';
className?: string;
style?: CSSProperties;
children: ReactNode;
}
const PADDING_MAP = {
none: '0',
sm: '12px',
md: 'var(--tk-card-padding)',
lg: '32px',
} as const;
const ContentCard: React.FC<ContentCardProps> = ({
variant = 'default',
onPress,
padding = 'md',
activeFeedback = 'bg',
className,
style,
children,
}) => {
const innerStyle = useMemo(() => ({
padding: PADDING_MAP[padding],
...style,
}), [padding, style]);
const hasPress = !!onPress;
const cls = [
'content-card',
`content-card--${variant}`,
hasPress && 'content-card--pressable',
hasPress && activeFeedback !== 'none' && `content-card--feedback-${activeFeedback}`,
className,
].filter(Boolean).join(' ');
return (
<View className={cls} style={innerStyle} onClick={onPress}>
{children}
</View>
);
};
export default React.memo(ContentCard);