Skip to content

Commit

Permalink
WEB-1936 add maybe types to touchable
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Ladaria committed Sep 2, 2024
1 parent 2dbc411 commit 8e888d6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/__acceptance_tests__/__ssr_pages__/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const CardsTest = (): JSX.Element => (
title="title"
subtitle="subtitle"
description="description"
icon={<IconAcademicLight />}
asset={<IconAcademicLight />}
button={
<ButtonPrimary small href="https://google.com">
Action
Expand Down
8 changes: 3 additions & 5 deletions src/__acceptance_tests__/__ssr_pages__/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ const HeaderTest = (): JSX.Element => (
<HeaderLayout
header={
<Header
title="La última factura de diciembre ya esta disponible"
preamount="Cuota mensual (IVA incluido)"
amount="60,44 €"
button={<ButtonPrimary href="asdf">Descargar factura</ButtonPrimary>}
subtitle="Y esto es un subtitulo"
title="This is a title"
pretitle="This is the pretitle"
description="This is a nice description"
/>
}
/>
Expand Down
8 changes: 8 additions & 0 deletions src/__type_tests__/chip-type-test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as React from 'react';
import Chip from '../chip';

import type {PressHandler} from '../touchable';

<Chip>hello</Chip>;
<Chip badge={3}>hello</Chip>;
<Chip badge>hello</Chip>;
Expand Down Expand Up @@ -62,3 +64,9 @@ import Chip from '../chip';
<Chip to="/" onClose={() => {}}>
hello
</Chip>;

const ChipMaybeOnPress = ({text, onPress}: {text: string; onPress?: PressHandler}): JSX.Element => (
<Chip maybe onPress={onPress}>
{text}
</Chip>
);
2 changes: 1 addition & 1 deletion src/chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface ToggleChipProps extends SimpleChipProps {
active: boolean;
}

type ClickableChipProps = TouchableComponentProps<SimpleChipProps & {active?: boolean}>;
type ClickableChipProps = TouchableComponentProps<SimpleChipProps> & {active?: boolean};

type ChipProps = ExclusifyUnion<ClosableChipProps | ToggleChipProps | ClickableChipProps>;

Expand Down
12 changes: 9 additions & 3 deletions src/touchable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,19 @@ type SubmitProps = {
export type AlwaysTouchableComponentProps = ExclusifyUnion<OnPressProps | HrefProps | ToProps> &
Pick<CommonProps, 'trackingEvent' | 'dataAttributes' | 'role' | 'aria-label'>;

type Maybe<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K> & {maybe: true};

export type TouchableComponentProps<Props> = ExclusifyUnion<
Props | (OnPressProps & Props) | (HrefProps & Props) | (ToProps & Props)
| Props
| (OnPressProps & Props)
| (HrefProps & Props)
| (ToProps & Props)
| (Maybe<OnPressProps, 'onPress'> & Props)
| (Maybe<HrefProps, 'href'> & Props)
| (Maybe<ToProps, 'to'> & Props)
> &
Pick<CommonProps, 'trackingEvent' | 'dataAttributes' | 'role' | 'aria-label'>;

type Maybe<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K> & {maybe: true};

export type TouchableProps = ExclusifyUnion<
| OnPressProps
| HrefProps
Expand Down

0 comments on commit 8e888d6

Please sign in to comment.