Skip to content

Commit

Permalink
fix typings
Browse files Browse the repository at this point in the history
  • Loading branch information
vutran committed Dec 16, 2017
1 parent 828332a commit ca9c78c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
10 changes: 8 additions & 2 deletions __tests__/ResultsItem.tsx
Expand Up @@ -6,15 +6,21 @@ describe('ResultsItem', () => {
it('should render a <ResultsItem />', () => {
const item = { title: 'Google', url: 'https://google.com' };
const tree = renderer
.create(React.createElement(ResultsItem, { item }))
.create(React.createElement(ResultsItem, { item, children: null }))
.toJSON();
expect(tree).toMatchSnapshot();
});

it('should render a highlighted <ResultsItem />', () => {
const item = { title: 'Google', url: 'https://google.com' };
const tree = renderer
.create(React.createElement(ResultsItem, { item, highlighted: true }))
.create(
React.createElement(ResultsItem, {
item,
highlighted: true,
children: null,
})
)
.toJSON();
expect(tree).toMatchSnapshot();
});
Expand Down
1 change: 1 addition & 0 deletions src/ResultsItem.tsx
@@ -1,5 +1,6 @@
import * as React from 'react';
import { COLORS } from './constants';
import { AnchorItem } from './modifiers/anchor';
import AnchorRenderer from './modifiers/anchor/AnchorRenderer';

interface Props<T> {
Expand Down
6 changes: 3 additions & 3 deletions src/modifiers/anchor/AnchorRenderer.tsx
Expand Up @@ -2,9 +2,9 @@ import * as React from 'react';
import { AnchorItem } from './';
import { COLORS } from '../../constants';

interface Props {
interface Props<T> {
// the item
item: AnchorItem;
item: AnchorItem & T;
}

const ANCHOR_STYLE: React.CSSProperties = {
Expand All @@ -15,7 +15,7 @@ const ANCHOR_STYLE: React.CSSProperties = {
paddingRight: 15,
};

export default function AnchorRenderer(props: Props) {
export default function AnchorRenderer<T>(props: Props<T>) {
return (
<a href={props.item.url} style={ANCHOR_STYLE}>
{props.item.title}
Expand Down
8 changes: 7 additions & 1 deletion typings/index.d.ts
Expand Up @@ -9,7 +9,13 @@ declare namespace Omnibar {
type Extension<T> = FunctionalExtension<T>;

// Renderers
type ResultRenderer<T> = ({ item }: { item: T }) => React.ReactNode;
type ResultRenderer<T> = (
{
item,
}: {
item: T;
}
) => React.ReactNode;

interface Props<T> {
// results renderer function
Expand Down

0 comments on commit ca9c78c

Please sign in to comment.