added react-albus (#27300)

* added react-albus

* react-albus: fix lint errors
This commit is contained in:
Sindre
2018-07-15 21:31:54 +02:00
committed by Ryan Cavanaugh
parent 1f95827a0d
commit fa96e1d7a3
4 changed files with 116 additions and 0 deletions

38
types/react-albus/index.d.ts vendored Normal file
View File

@@ -0,0 +1,38 @@
// Type definitions for react-albus 2.0
// Project: https://github.com/americanexpress/react-albus#readme
// Definitions by: Sindre Seppola <https://github.com/sseppola>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.6
import * as React from "react";
import { History } from "history";
export interface WizardStepObject {
id: string;
}
export interface WizardContext {
step: WizardStepObject;
steps: WizardStepObject[];
history: History;
next: () => void;
previous: () => void;
go: (n: number) => void;
push: (id?: string) => void;
replace: (id?: string) => void;
}
export const Wizard: React.ComponentType<{
onNext?: (wizard: WizardContext) => void;
render?: (wizard: WizardContext) => React.ReactNode;
history?: History;
}>;
export const Steps: React.ComponentType<{
step?: WizardStepObject;
}>;
export const Step: React.ComponentType<{
id: string;
render: (wizard: WizardContext) => React.ReactNode;
}>;

View File

@@ -0,0 +1,52 @@
import * as React from "react";
import { Wizard, Step, Steps } from "react-albus";
const Example = () => (
<Wizard
onNext={wiz => {
wiz.go(0);
const location = wiz.history.location;
wiz.next();
wiz.previous();
wiz.push("merlin");
wiz.replace(wiz.step.id);
wiz.steps.map(step => {
wiz.push(step.id);
});
}}
render={wiz => (
<Steps>
<Step
id="merlin"
render={() => (
<div>
<h1>Merlin</h1>
<button onClick={() => wiz.next()}>Next</button>
</div>
)}
/>
<Step
id="gandalf"
render={stepWiz => (
<div>
<h1>Gandalf</h1>
<button onClick={() => stepWiz.next()}>Next</button>
<button onClick={() => stepWiz.previous()}>
Previous
</button>
</div>
)}
/>
<Step
id="dumbledore"
render={({ previous }) => (
<div>
<h1>Dumbledore</h1>
<button onClick={previous}>Previous</button>
</div>
)}
/>
</Steps>
)}
/>
);

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",
"react-albus-tests.tsx"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }