Merge pull request #28814 from SamHH/dayzed

dayzed: initial types
This commit is contained in:
Nathan Shively-Sanders
2018-09-18 10:51:14 -07:00
committed by GitHub
4 changed files with 125 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
import * as React from 'react';
import { render } from 'react-dom';
import Dayzed, { DateObj } from 'dayzed';
interface State {
selectedDate: Date;
monthOffset: number;
}
class App extends React.Component<{}, State> {
state = {
selectedDate: new Date(),
monthOffset: 0,
};
handleSetDate = (dateObj: DateObj) => {
this.setState({ selectedDate: dateObj.date });
}
render() {
return (
<Dayzed
selected={this.state.selectedDate}
offset={this.state.monthOffset}
onDateSelected={this.handleSetDate}
>
{({ calendars, ...rp }) => calendars.map(cal => (
<div>
Calendar:
{cal.weeks.map(week => (
<div>
Week:
{week.map(day => day && (
<span {...rp.getDateProps({ dateObj: day })}>Day({day.date.getDate()}):</span>
))}
</div>
))}
</div>
))}
</Dayzed>
);
}
}
render(<App />, document.body);
+52
View File
@@ -0,0 +1,52 @@
// Type definitions for dayzed 2.2
// Project: https://github.com/deseretdigital/dayzed
// Definitions by: Sam A. Horvath-Hunt <https://github.com/samhh>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import { Component, ReactNode } from 'react';
export interface DateObj {
date: Date;
nextMonth: boolean;
prevMonth: boolean;
selectable: boolean;
selected: boolean;
today: boolean;
}
interface Calendar {
firstDayOfMonth: Date;
lastDayOfMonth: Date;
month: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11;
weeks: Array<Array<DateObj | ''>>;
year: number;
}
interface RenderProps {
calendars: Calendar[];
getBackProps: (data: { calendars: Calendar[]; offset?: number; }) => Record<string, any>;
getForwardProps: (data: { calendars: Calendar[]; offset?: number; }) => Record<string, any>;
getDateProps: (data: { dateObj: DateObj; }) => Record<string, any>;
}
type RenderFn = (renderProps: RenderProps) => ReactNode;
interface Props {
date?: Date;
maxDate?: Date;
minDate?: Date;
monthsToDisplay?: number;
firstDayOfWeek?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
showOutsideDays?: boolean;
selected?: Date | Date[];
children?: RenderFn;
render?: RenderFn;
offset?: number;
onOffsetChanged?(offset: number): void;
onDateSelected(selectedDate: DateObj): void;
}
declare class Dayzed extends Component<Props> { }
export default Dayzed;
+25
View File
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"jsx": "react",
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"dayzed-tests.tsx"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }