Skip to content

Commit

Permalink
export locale type define.
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperEVO committed Aug 24, 2017
1 parent df990b6 commit 7be0075
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 54 deletions.
3 changes: 0 additions & 3 deletions index.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import getList from 'react-native-index-page';

getList({
demos: [
require('./_ts2js/examples/picker'),
require('./_ts2js/examples/multi-picker'),
require('./_ts2js/examples/popup'),
],
title: require('./package.json').name,
});
8 changes: 4 additions & 4 deletions src/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import ConfirmPanel from './calendar/ConfirmPanel';
import ShortcutPanel from './calendar/ShortcutPanel';
import AnimateWrapper from './calendar/AnimateWrapper';
import Header from './calendar/Header';
import { Models as DateModels } from './date/DataTypes';
import { Models } from './date/DataTypes';
import PropsType from './CalendarProps';

import { mergeDateTime } from './util';

import defaultLocale from './locale/zh_CN';

export type ExtraData = DateModels.ExtraData;
export type ExtraData = Models.ExtraData;
export { PropsType };

export class StateType {
Expand Down Expand Up @@ -45,7 +45,7 @@ export default class Calendar extends React.PureComponent<PropsType, StateType>
selectDate = (date: Date, useDateTime = false, startDate?: Date, endDate?: Date) => {
if (!date) return {} as StateType;
let newState = {} as StateType;
const { type, pickTime, defaultTimeValue, locale = {} as GlobalModels.Locale } = this.props;
const { type, pickTime, defaultTimeValue, locale = {} as Models.Locale } = this.props;
const newDate = pickTime && !useDateTime ? mergeDateTime(date, defaultTimeValue) : date;

switch (type) {
Expand Down Expand Up @@ -156,7 +156,7 @@ export default class Calendar extends React.PureComponent<PropsType, StateType>

render() {
const {
type, locale = {} as GlobalModels.Locale, prefixCls, visible, showHeader, pickTime, showShortcut,
type, locale = {} as Models.Locale, prefixCls, visible, showHeader, pickTime, showShortcut,
infinite, infiniteOpt, initalMonths, defaultDate, minDate, maxDate, getDateExtra,
defaultTimeValue, renderShortcut, enterDirection,
} = this.props;
Expand Down
6 changes: 3 additions & 3 deletions src/CalendarProps.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Models as DateModels } from './date/DataTypes';
import { Models } from './date/DataTypes';

export default interface PropsType {
/** 入场方向,default: vertical,vertical: 垂直,horizontal: 水平 */
enterDirection?: 'horizontal' | 'vertical';
/** 本地化 */
locale?: GlobalModels.Locale;
locale?: Models.Locale;
/** 关闭时回调 */
onCancel?: () => void;
/** 确认时回调 */
Expand All @@ -30,7 +30,7 @@ export default interface PropsType {
/** 显示开始日期,default: today */
defaultDate?: Date;
/** 日期扩展数据 */
getDateExtra?: (date: Date) => DateModels.ExtraData;
getDateExtra?: (date: Date) => Models.ExtraData;
/** 无限滚动,default: true */
infinite?: boolean;
/** 无限滚动优化(大范围选择),default: false */
Expand Down
4 changes: 2 additions & 2 deletions src/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class DatePicker extends Component {
if (!data) return;

return <SingleMonth key={data.title}
locale={this.props.locale || {} as GlobalModels.Locale}
locale={this.props.locale || {} as Models.Locale}
monthData={data}
onCellClick={this.onCellClick}
getDateExtra={this.props.getDateExtra}
Expand Down Expand Up @@ -76,7 +76,7 @@ export default class DatePicker extends Component {
}

render() {
const { infinite, prefixCls = '', locale = {} as GlobalModels.Locale } = this.props;
const { infinite, prefixCls = '', locale = {} as Models.Locale } = this.props;

return (
<div className={`${prefixCls} data-picker`}>
Expand Down
2 changes: 1 addition & 1 deletion src/DatePickerProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default interface PropsType {
/** 初始化月个数,default: 6 */
initalMonths?: number;
/** 本地化 */
locale?: GlobalModels.Locale;
locale?: Models.Locale;
/** 最大日期 */
maxDate?: Date;
/** 最小日期 */
Expand Down
3 changes: 2 additions & 1 deletion src/TimePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';
import DateTimePicker from 'rmc-date-picker';
import { Models } from './date/DataTypes';

export interface PropsType {
locale: GlobalModels.Locale;
locale: Models.Locale;
title?: string;
defaultValue?: Date;
value?: Date;
Expand Down
3 changes: 2 additions & 1 deletion src/calendar/ConfirmPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as React from 'react';
import { formatDate } from '../util';
import { Models } from '../date/DataTypes';

export interface ConfirmPanelPropsType {
type?: 'one' | 'range';
locale: GlobalModels.Locale;
locale: Models.Locale;
onlyConfirm?: boolean;
disableBtn?: boolean;
startDateTime?: Date;
Expand Down
5 changes: 3 additions & 2 deletions src/calendar/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as React from 'react';
import { Models } from '../date/DataTypes';

export default class Header extends React.PureComponent<{
title?: string;
locale?: GlobalModels.Locale;
locale?: Models.Locale;
showClear?: boolean;
onCancel?: () => void;
onClear?: () => void;
Expand Down Expand Up @@ -33,7 +34,7 @@ export default class Header extends React.PureComponent<{
render() {
const {
title,
locale = {} as GlobalModels.Locale,
locale = {} as Models.Locale,
onCancel,
onClear,
showClear
Expand Down
3 changes: 2 additions & 1 deletion src/calendar/ShortcutPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as React from 'react';
import { Models } from '../date/DataTypes';

export interface PropsType {
locale: GlobalModels.Locale;
locale: Models.Locale;
onSelect: (startDate?: Date, endDate?: Date) => void;
}
export default class ShortcutPanel extends React.PureComponent<PropsType, {}> {
Expand Down
28 changes: 28 additions & 0 deletions src/date/DataTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,32 @@ export namespace Models {
updateLayout?: Function;
componentRef?: SingleMonth;
}

export interface Locale {
title: string;
today: string;
month: string;
year: string;
am: string;
pm: string;
dateFormat: string;
dateTimeFormat: string;
noChoose: string;
week: string[];
clear: string;
selectTime: string;
selectStartTime: string;
selectEndTime: string;
start: string;
end: string;
begin: string;
over: string;
begin_over: string;
confirm: string;
monthTitle: string;
loadPrevMonth: string;
yesterday: string;
lastWeek: string;
lastMonth: string;
}
}
2 changes: 1 addition & 1 deletion src/date/SingleMonth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { Models } from './DataTypes';

export interface PropsType {
locale: GlobalModels.Locale;
locale: Models.Locale;
monthData: Models.MonthData;
getDateExtra?: (date: Date) => Models.ExtraData;
onCellClick?: (data: Models.CellData, monthData: Models.MonthData) => void;
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { Models } from './date/DataTypes';

export { default as Calendar, ExtraData, PropsType as CalendarPropsType } from './Calendar';
export { default as DatePicker, PropsType as DatePickerPropsType } from './DatePicker';

import zhCN from './locale/zh_CN';
import enUS from './locale/en_US';
const Locale = { zhCN, enUS };

export { Locale };
type LocaleType = Models.Locale;
export { Locale, LocaleType };
4 changes: 3 additions & 1 deletion src/locale/en_US.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const locale: GlobalModels.Locale = {
import { Models } from '../date/DataTypes';

const locale: Models.Locale = {
title: 'Calendar',
today: 'Today',
month: 'Month',
Expand Down
4 changes: 3 additions & 1 deletion src/locale/zh_CN.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const locale: GlobalModels.Locale = {
import { Models } from '../date/DataTypes';

const locale: Models.Locale = {
title: '日期选择',
today: '今天',
month: '月',
Expand Down
4 changes: 3 additions & 1 deletion src/util/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Models } from '../date/DataTypes';

export const mergeDateTime = (date?: Date, time?: Date) => {
date = date || new Date;
if (!time) return date;
Expand All @@ -11,7 +13,7 @@ export const mergeDateTime = (date?: Date, time?: Date) => {
);
};

export const formatDate = (date: Date, format: string, locale?: GlobalModels.Locale) => {
export const formatDate = (date: Date, format: string, locale?: Models.Locale) => {
const week = locale && locale.week;

let o: { [key: string]: any } = {
Expand Down
31 changes: 0 additions & 31 deletions typings/models.d.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,2 @@
declare module 'rc-animate';
declare module 'zscroller/lib/DOMScroller';

declare namespace GlobalModels {

interface Locale {
title: string,
today: string,
month: string,
year: string,
am: string,
pm: string,
dateFormat: string,
dateTimeFormat: string,
noChoose: string,
week: string[],
clear: string,
selectTime: string,
selectStartTime: string,
selectEndTime: string,
start: string,
end: string,
begin: string,
over: string,
begin_over: string,
confirm: string,
monthTitle: string,
loadPrevMonth: string,
yesterday: string,
lastWeek: string,
lastMonth: string,
}
}

0 comments on commit 7be0075

Please sign in to comment.