Skip to content

Commit

Permalink
fix(Row): improve onPress/to/href types
Browse files Browse the repository at this point in the history
  • Loading branch information
atabel committed Jul 20, 2023
1 parent 45d96ce commit d88ae95
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
22 changes: 13 additions & 9 deletions src/__type_tests__/list-type-test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import {RowList, BoxedRowList, BoxedRow, Row} from '../list';

const v = true;
const v = true as boolean;

// @ts-expect-error - missing children
<RowList />;
Expand All @@ -22,40 +22,44 @@ const v = true;
<RowList>
{/* @ts-expect-error - missing props */}
<Row />

<Row title="with children">
{/* @ts-expect-error - children not allowed */}
<span>error</span>
</Row>

{/* OK - basic */}
<Row title="basic" />

{/* OK - to */}
<Row title="to" to="/to" />
<Row title="to" to="/to" trackingEvent={{name: 'something'}} />
<Row title="to" to="/to" fullPageOnWebView />
{/* @ts-expect-error - newTab not allowed in to */}
<Row title="to" to="/to" newTab />

{/* OK - href */}
<Row title="href" href="/href" />
<Row title="href" href="/href" trackingEvent={{name: 'something'}} />
<Row title="href" href="/href" newTab />
{/* @ts-expect-error - fullPageOnWebView not allowed in href */}
<Row title="href" href="/href" fullPageOnWebView />

{/* OK - onPress */}
<Row title="onPress" onPress={() => {}} />
<Row title="onPress" onPress={() => {}} trackingEvent={{name: 'something'}} />
{/* @ts-expect-error - fullPageOnWebView not allowed in onPress */}
<Row title="onPress" onPress={() => {}} fullPageOnWebView />

{/* OK - switch */}
<Row title="switch" switch={{name: 'switch', value: true}} />

<Row title="switch + onPress" switch={{name: 'switch', value: true}} onPress={() => {}} />
{/* OK - checkbox */}
<Row title="checkbox" checkbox={{name: 'checkbox', value: true}} />

<Row title="checkbox + onPress" checkbox={{name: 'checkbox', value: true}} onPress={() => {}} />
{/* OK - radio */}
<Row title="radio" radioValue="radio" />
<Row title="radio + onPress" radioValue="radio" onPress={() => {}} />
{/* @ts-expect-error - can't use trackingEvent without to/href/onPress */}
<Row title="tracking event without to/href/onPress" trackingEvent={{name: 'something'}} />

<Row title="conditional onPress" onPress={v ? () => {} : undefined} />
<Row title="conditional href" href={v ? '' : undefined} />
<Row title="conditional to" to={v ? '' : undefined} />
</RowList>;

<BoxedRowList>
Expand Down
12 changes: 6 additions & 6 deletions src/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,41 +213,41 @@ interface BasicRowContentProps extends CommonProps {
}

interface SwitchRowContentProps extends CommonProps {
onPress?: () => void;
onPress?: (() => void) | undefined;

switch: ControlProps | undefined;
}

interface CheckboxRowContentProps extends CommonProps {
onPress?: () => void;
onPress?: (() => void) | undefined;

checkbox: ControlProps | undefined;
}

interface RadioRowContentProps extends CommonProps {
onPress?: () => void;
onPress?: (() => void) | undefined;

radioValue: string;
}

interface HrefRowContentProps extends CommonProps {
trackingEvent?: TrackingEvent | ReadonlyArray<TrackingEvent>;
href: string;
href: string | undefined;
newTab?: boolean;
right?: Right;
}

interface ToRowContentProps extends CommonProps {
trackingEvent?: TrackingEvent | ReadonlyArray<TrackingEvent>;
to: string;
to: string | undefined;
fullPageOnWebView?: boolean;
replace?: boolean;
right?: Right;
}

interface OnPressRowContentProps extends CommonProps {
trackingEvent?: TrackingEvent | ReadonlyArray<TrackingEvent>;
onPress: () => void;
onPress: (() => void) | undefined;
right?: Right;
}

Expand Down

0 comments on commit d88ae95

Please sign in to comment.