Skip to content

Commit

Permalink
auto adjust to height of time picker.
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperEVO committed Aug 24, 2017
1 parent 123460d commit 1a148ed
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 34 deletions.
2 changes: 1 addition & 1 deletion assets/common/DatePicker.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.@{prefixClass}.data-picker {
.@{prefixClass} .date-picker {
display: flex;
flex-direction: column;
background: #eee;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rmc-calendar",
"version": "0.0.4",
"version": "0.0.5",
"description": "React Mobile Calendar Component(web and react-native)",
"keywords": [
"react",
Expand Down
11 changes: 10 additions & 1 deletion src/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class StateType {
startDate?: Date = undefined;
endDate?: Date = undefined;
disConfirmBtn?: boolean = true;
clientHight?: number = 0;
}
export default class Calendar extends React.PureComponent<PropsType, StateType> {
static defaultProps = {
Expand Down Expand Up @@ -154,6 +155,12 @@ export default class Calendar extends React.PureComponent<PropsType, StateType>
});
}

setClientHight = (height: number) => {
this.setState({
clientHight: height,
});
}

render() {
const {
type, locale = {} as Models.Locale, prefixCls, visible, showHeader, pickTime, showShortcut,
Expand All @@ -163,7 +170,7 @@ export default class Calendar extends React.PureComponent<PropsType, StateType>
const {
showTimePicker, timePickerTitle,
startDate, endDate,
disConfirmBtn
disConfirmBtn, clientHight
} = this.state;

return (
Expand Down Expand Up @@ -196,6 +203,7 @@ export default class Calendar extends React.PureComponent<PropsType, StateType>
getDateExtra={getDateExtra}
onCellClick={this.onSelectedDate}
onSelectHasDisableDate={this.onSelectHasDisableDate}
onLayout={this.setClientHight}
startDate={startDate}
endDate={endDate}
rowSize={rowSize}
Expand All @@ -212,6 +220,7 @@ export default class Calendar extends React.PureComponent<PropsType, StateType>
onValueChange={this.onTimeChange}
minDate={minDate}
maxDate={maxDate}
clientHeight={clientHight}
/>
}
{
Expand Down
9 changes: 6 additions & 3 deletions src/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ export default class DatePicker extends Component {

setLayout = (dom: HTMLDivElement) => {
if (!this.scroller) {
const { infinite, initalMonths, onLayout } = this.props;
onLayout && onLayout(dom.clientHeight);

const scrollHandler = this.createOnScroll();
if (this.props.infinite) {
if (infinite) {
this.scroller = new DOMScroller(dom.children[0], {
scrollingX: false,
onScroll: () => scrollHandler({
Expand All @@ -55,7 +58,7 @@ export default class DatePicker extends Component {
}, () => {
this.canLoadPrev() && this.genMonthData(this.state.months[0].firstDate, -1);

this.visibleMonth = this.visibleMonth.slice(0, this.props.initalMonths);
this.visibleMonth = this.visibleMonth.slice(0, initalMonths);

this.state.months.forEach((m) => {
m.updateLayout && m.updateLayout();
Expand All @@ -80,7 +83,7 @@ export default class DatePicker extends Component {
const { infinite, prefixCls = '', locale = {} as Models.Locale } = this.props;

return (
<div className={`${prefixCls} data-picker`}>
<div className={`${prefixCls} date-picker`}>
<WeekPanel />
<div className="wrapper" style={{ overflow: infinite ? 'hidden' : 'scroll' }} ref={this.setLayout}>
<div>
Expand Down
5 changes: 3 additions & 2 deletions src/DatePickerProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ export default interface PropsType {
minDate?: Date;
/** 日期点击回调 */
onCellClick?: (date: Date) => void;
onLayout?: (clientHight: number) => void;
/** 选择区间包含不可用日期 */
onSelectHasDisableDate?: (date: Date[]) => void;
/** (web only) 样式前缀 */
prefixCls?: string;
/** 选择类型,default: range,one: 单日,range: 日期区间 */
type?: 'one' | 'range';
/** 行大小 */
rowSize?: 'normal' | 'xl';
/** 选择类型,default: range,one: 单日,range: 日期区间 */
type?: 'one' | 'range';
}
8 changes: 7 additions & 1 deletion src/TimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface PropsType {

minDate?: Date;
maxDate?: Date;
clientHeight?: number;
}
export interface StateType {
}
Expand Down Expand Up @@ -53,15 +54,20 @@ export default class TimePicker extends React.PureComponent<PropsType, StateType
}

render() {
const { locale, title, value, defaultValue, prefixCls, pickerPrefixCls } = this.props;
const { locale, title, value, defaultValue, prefixCls, pickerPrefixCls, clientHeight } = this.props;
const date = value || defaultValue || undefined;
const height = (clientHeight && clientHeight * 3 / 8 - 52) || Number.POSITIVE_INFINITY;

return (
<div className="time-picker">
<div className="title">{title}</div>
<DateTimePicker
prefixCls={prefixCls}
pickerPrefixCls={pickerPrefixCls}
style={{
height: height > 164 || height < 0 ? 164 : height,
overflow: 'hidden'
} as React.CSSProperties}
mode="time"
date={date}
locale={locale}
Expand Down
22 changes: 0 additions & 22 deletions src/calendar/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,6 @@ export default class Header extends React.PureComponent<{
onCancel?: () => void;
onClear?: () => void;
}, {}> {
fps: HTMLDivElement;

setFPS = (dom: HTMLDivElement) => {
if (!this.fps) {
this.fps = dom;
let time = +new Date;
let count = 0;
const raf = () => requestAnimationFrame(() => {
const now = +new Date;
if (now - time > 1 * 1000) {
dom.innerText = `JS FPS: ${count}`;
count = 0;
time = now;
console.log(dom.innerText);
} else {
count++;
}
raf();
});
raf();
}
}

render() {
const {
Expand Down
4 changes: 2 additions & 2 deletions tests/__snapshots__/Calendar.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ exports[`Calendar english. renders correctly 1`] = `
</span>
</div>
<div
class="rmc-calendar data-picker"
class="rmc-calendar date-picker"
>
<div
class="week-panel"
Expand Down Expand Up @@ -4712,7 +4712,7 @@ exports[`Calendar show shortcut. 1`] = `
</span>
</div>
<div
class="rmc-calendar data-picker"
class="rmc-calendar date-picker"
>
<div
class="week-panel"
Expand Down
2 changes: 1 addition & 1 deletion tests/__snapshots__/DatePicker.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`DatePicker renders correctly 1`] = `
<div
class="rmc-calendar data-picker"
class="rmc-calendar date-picker"
>
<div
class="week-panel"
Expand Down

0 comments on commit 1a148ed

Please sign in to comment.