Skip to content

Commit 06de641

Browse files
committed
feat():增加bar api
1 parent a7ca94f commit 06de641

File tree

3 files changed

+76
-23
lines changed

3 files changed

+76
-23
lines changed

example/examples/src/routes/Calendar/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,20 @@ export default class CalendarView extends React.Component<CalendarViewProps> {
1313
const {route} = this.props;
1414
const description = route.params.description;
1515
const title = route.params.title;
16+
const barProps = {
17+
barRightText: '返回啦',
18+
title: '日历啦',
19+
onPressBarLeft: () => {},
20+
barLeftText: '今天啦',
21+
};
1622
return (
1723
<Container>
1824
<Layout>
1925
<Header title={title} description={description} />
2026
<Body>
21-
<Calendar />
27+
<Calendar bar={barProps} />
2228
<Spacing size={'large'} />
23-
<Calendar color="red" />
29+
<Calendar color="red" bar={{}} />
2430
</Body>
2531
<Footer />
2632
</Layout>

packages/core/src/Calendar/README.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,18 @@ export default class CalendarView extends React.Component<CalendarViewProps> {
5656
const { route } = this.props;
5757
const description = route.params.description;
5858
const title = route.params.title;
59+
const barProps = {
60+
barRightText: "返回啦",
61+
title : "日历啦",
62+
onPressBarLeft: () => { },
63+
barLeftText: "今天啦"
64+
}
5965
return (
6066
<Container>
6167
<Layout>
6268
<Header title={title} description={description} />
6369
<Body>
64-
<Calendar color="red" />
70+
<Calendar color="red" bar={barProps} />
6571
</Body>
6672
<Footer />
6773
</Layout>
@@ -73,6 +79,23 @@ export default class CalendarView extends React.Component<CalendarViewProps> {
7379

7480
### props
7581

76-
| 参数 | 说明 | 类型 | 默认值 |
77-
|------|------|-----|------|
78-
| `color` | 设置日历颜色 | String | "#329BCB" |
82+
```ts
83+
84+
interface barState {
85+
// 导航栏标题
86+
title?: string
87+
// 导航左侧文本
88+
barRightText?: string;
89+
// 导航右侧文本
90+
barLeftText?: string;
91+
// 导航左侧点击事件
92+
onPressBarLeft?: () => void;
93+
// 自定义导航栏
94+
render?: React.ReactNode
95+
}
96+
export interface CalendarProps extends ViewProps {
97+
// 日历颜色
98+
color?: string;
99+
bar: barState ;
100+
}
101+
```

packages/core/src/Calendar/index.tsx

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,23 @@ export let toYear = newDates.getFullYear();
1010
export let toMonth = newDates.getMonth();
1111
export let toDays = newDates.getDate();
1212

13+
interface barState {
14+
title?: string;
15+
barRightText?: string;
16+
barLeftText?: string;
17+
onPressBarLeft?: () => void;
18+
render?: React.ReactNode;
19+
}
1320
export interface CalendarProps extends ViewProps {
1421
// 日历颜色
15-
color: string;
22+
color?: string;
23+
bar: barState;
1624
}
1725
const Calendar = (props: CalendarProps) => {
18-
const { color = '#329BCB' } = props;
26+
const {
27+
color = '#329BCB',
28+
bar: { render = null, barRightText = '返回', title = '日历', barLeftText = '今天', onPressBarLeft = null },
29+
} = props;
1930

2031
const [currentYear, setCurrentYear] = useState<number>(toYear);
2132
const [currentMonth, setCurrentMonth] = useState<number>(toMonth);
@@ -31,6 +42,33 @@ const Calendar = (props: CalendarProps) => {
3142
setNextData(toMonths[2]);
3243
}, [currentYear, currentMonth]);
3344

45+
/**
46+
* 头部导航栏
47+
* barRightText 左侧文字
48+
* title 标题
49+
* barLeftText 右侧文字
50+
* onPressBarLeft 左侧点击事件
51+
* render 自定义导航栏
52+
*/
53+
const renderBar = render ? (
54+
render
55+
) : (
56+
<View style={[styles.header, { backgroundColor: color }]}>
57+
<TouchableOpacity onPress={() => onPressBarLeft && onPressBarLeft()}>
58+
<View style={styles.headerBtn}>
59+
<Icon name="left" size={20} color={'#fff'} />
60+
<Text style={styles.headerText}>{barRightText}</Text>
61+
</View>
62+
</TouchableOpacity>
63+
<View>
64+
<Text style={styles.headerText}>{title}</Text>
65+
</View>
66+
<TouchableOpacity onPress={() => goToday()}>
67+
<Text style={styles.headerText}>{barLeftText}</Text>
68+
</TouchableOpacity>
69+
</View>
70+
);
71+
3472
const renderWeekDays = () => {
3573
let weekdays = ['日', '一', '二', '三', '四', '五', '六'];
3674
return weekdays.map((day) => {
@@ -140,21 +178,7 @@ const Calendar = (props: CalendarProps) => {
140178

141179
return (
142180
<View style={{ flex: 1, backgroundColor: '#fff' }}>
143-
<View style={[styles.header, { backgroundColor: color }]}>
144-
<TouchableOpacity>
145-
<View style={styles.headerBtn}>
146-
<Icon name="left" size={20} color={'#fff'} />
147-
<Text style={styles.headerText}>Menu</Text>
148-
</View>
149-
</TouchableOpacity>
150-
<View>
151-
<Text style={styles.headerText}>Calendar</Text>
152-
</View>
153-
<TouchableOpacity onPress={() => goToday()}>
154-
<Text style={styles.headerText}>Today</Text>
155-
</TouchableOpacity>
156-
</View>
157-
181+
{renderBar}
158182
<View style={styles.calendarHeader}>
159183
<View style={styles.calendarHeaderItem}>
160184
<TouchableOpacity onPress={() => getCurrentYear('last')}>

0 commit comments

Comments
 (0)