Skip to content

Commit

Permalink
fix typings for resultRenderer (#12)
Browse files Browse the repository at this point in the history
* fix typings for resultRenderer

* extract typings for result renderere
  • Loading branch information
vutran authored Nov 4, 2017
1 parent 4bc20c2 commit 6959f0f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface Props<T> {
// optional row override style
rowStyle?: React.CSSProperties;
// optional result renderering function
resultRenderer?: <T>(item: T) => React.ReactChild;
resultRenderer?: Omnibar.ResultRenderer;
}

const LIST_STYLE: React.CSSProperties = {
Expand Down
6 changes: 3 additions & 3 deletions src/ResultsItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ interface Props<T> {
// onMouseLeave item callback
onMouseLeave?: (e: any /* Event */) => void;
// onClick callback
onClickItem: (e: any /* Event */) => void;
onClickItem?: (e: any /* Event */) => void;
// set to true to highlight the given item
highlighted?: boolean;
// optional style override
style?: React.CSSProperties;
// optional result renderering function
resultRenderer?: <T>(item: T) => React.ReactChild;
resultRenderer?: Omnibar.ResultRenderer;
}

interface State {
Expand Down Expand Up @@ -73,7 +73,7 @@ export default class ResultRenderer<T> extends React.PureComponent<

const renderer = this.props.resultRenderer
? this.props.resultRenderer
: AnchorRenderer;
: AnchorRenderer as Omnibar.ResultRenderer;

return (
<li
Expand Down
5 changes: 4 additions & 1 deletion typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ declare namespace Omnibar {
type FunctionalExtension<T> = (query: string) => Results<T>;
type Extension<T> = FunctionalExtension<T>;

// Renderers
type ResultRenderer = <T>({ item }: { item: T }) => JSX.Element;

interface Props<T> {
// list of extensions
extensions: Array<Omnibar.Extension<T>>;
Expand All @@ -32,7 +35,7 @@ declare namespace Omnibar {
// options style on the root element
rootStyle?: React.CSSProperties;
// optional result renderering function
resultRenderer?: <T>(item: T) => React.ReactChild;
resultRenderer?: ResultRenderer;
// optional action override
onAction?: <T>(item: T) => void;
// optional input delay override
Expand Down

0 comments on commit 6959f0f

Please sign in to comment.