This repository has been archived by the owner on Nov 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add TS definitions * docs: added Typescript Usage md file docs * fix(feat): missing typescript dependency * docs: added contributor, update kcd-scripts
- Loading branch information
Jedrzej Lewandowski
authored and
Kent C. Dodds
committed
Dec 9, 2017
1 parent
2c8bafa
commit 94b1a56
Showing
7 changed files
with
139 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Typescript Usage | ||
|
||
The current bundled Typescript definitions are incomplete and based around the | ||
needs of the developers who contributed them. | ||
|
||
Pull requests to improve them are welcome and appreciated. If you've never contributed to open source before, then you may find [this free video course](https://egghead.io/courses/how-to-contribute-to-an-open-source-project-on-github) helpful. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import * as React from 'react' | ||
import Toggle from '../' | ||
|
||
interface Props {} | ||
|
||
interface State {} | ||
|
||
export default class App extends React.Component<Props, State> { | ||
|
||
onClickCall = () => console.log('hello') | ||
|
||
render() { | ||
return ( | ||
<Toggle> | ||
{({ | ||
on, | ||
getTogglerProps, | ||
toggle, | ||
setOn, | ||
setOff, | ||
getInputTogglerProps, | ||
getElementTogglerProps | ||
}) => ( | ||
<div> | ||
<button {...getTogglerProps({onClick: this.onClickCall})}>Toggle</button> | ||
<button onClick={toggle}>uses toggle action</button> | ||
<button onClick={setOn}>set on</button> | ||
<button onClick={setOff}>set off</button> | ||
<input | ||
type="button" | ||
value="Toggle Input" | ||
{...getInputTogglerProps()} | ||
/> | ||
<span {...getElementTogglerProps()}>ToggleSpan</span> | ||
<div>{on ? 'Toggled On' : 'Toggled Off'}</div> | ||
</div> | ||
)} | ||
</Toggle> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"compilerOptions": { | ||
"jsx": "react", | ||
"noUnusedLocals": true | ||
}, | ||
"include": ["test/**/*.tsx"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as React from 'react' | ||
|
||
export interface GetElementPropsOptions extends React.HTMLProps<HTMLElement> {} | ||
|
||
export interface GetInputPropsOptions | ||
extends React.HTMLProps<HTMLInputElement> {} | ||
|
||
export interface GetButtonPropsOptions | ||
extends React.HTMLProps<HTMLButtonElement> {} | ||
|
||
export interface TogglerStateAndHelpers { | ||
readonly on: boolean | ||
readonly getTogglerProps: (options?: GetButtonPropsOptions) => any | ||
readonly getInputTogglerProps: (options?: GetButtonPropsOptions) => any | ||
readonly getElementTogglerProps: (options?: GetElementPropsOptions) => any | ||
readonly setOn: () => void | ||
readonly setOff: () => void | ||
readonly toggle: () => void | ||
} | ||
|
||
export type ChildrenFunction = ( | ||
options: TogglerStateAndHelpers, | ||
) => React.ReactNode | ||
|
||
export interface ReactToggledProps { | ||
readonly defaultOn?: boolean | ||
readonly onToggle?: (on: boolean, object: TogglerStateAndHelpers) => void | ||
readonly on?: boolean | ||
readonly children: ChildrenFunction | ||
} | ||
|
||
export type ReactToggledInterface = React.ComponentClass<ReactToggledProps> | ||
|
||
declare const Toggle: ReactToggledInterface | ||
export default Toggle |