Skip to content

Commit 0c70e03

Browse files
committed
fix: improve typings
1 parent 8ad92dd commit 0c70e03

File tree

10 files changed

+23
-46
lines changed

10 files changed

+23
-46
lines changed

src/components/actions/Action/Action.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
import { forwardRef, MouseEventHandler } from 'react';
1+
import { forwardRef } from 'react';
22
import { AriaButtonProps } from 'react-aria';
33
import { FocusableRef } from '@react-types/shared';
44

55
import {
6-
BaseProps,
6+
AllBaseProps,
77
BaseStyleProps,
88
CONTAINER_STYLES,
99
ContainerStyleProps,
1010
extractStyles,
1111
Styles,
12-
TagNameProps,
1312
TEXT_STYLES,
1413
TextStyleProps,
1514
tasty,
1615
} from '../../../tasty';
1716
import { useAction } from '../use-action';
1817

1918
export interface CubeActionProps
20-
extends BaseProps,
21-
TagNameProps,
19+
extends Omit<AllBaseProps, 'htmlType'>,
2220
BaseStyleProps,
2321
ContainerStyleProps,
2422
TextStyleProps,
@@ -27,9 +25,6 @@ export interface CubeActionProps
2725
label?: string;
2826
htmlType?: 'button' | 'submit' | 'reset' | undefined;
2927
download?: string;
30-
onClick?: MouseEventHandler;
31-
onMouseEnter?: MouseEventHandler;
32-
onMouseLeave?: MouseEventHandler;
3328
}
3429

3530
const DEFAULT_ACTION_STYLES: Styles = {

src/components/actions/use-action.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@ import { FocusableRef, PressEvent } from '@react-types/shared';
66
import { UIKitContext } from '../../provider';
77
import { mergeProps } from '../../utils/react';
88
import { useFocus } from '../../utils/react/interactions';
9-
import { BaseProps, filterBaseProps, TagNameProps } from '../../tasty';
9+
import { AllBaseProps, filterBaseProps, TagName } from '../../tasty';
1010
import { useTracking } from '../../providers/TrackingProvider';
1111
import { useEvent } from '../../_internal';
1212

1313
const LINK_PRESS_EVENT = 'Link Press';
1414
const BUTTON_PRESS_EVENT = 'Button Press';
1515

16-
export interface CubeUseActionProps
17-
extends BaseProps,
18-
TagNameProps,
16+
export interface CubeUseActionProps<T extends TagName = TagName>
17+
extends AllBaseProps<T>,
1918
Omit<AriaButtonProps, 'type'> {
2019
to?: string;
2120
label?: string;

src/components/content/ActiveZone/ActiveZone.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ import {
1212
extractStyles,
1313
filterBaseProps,
1414
Styles,
15-
TagNameProps,
1615
TEXT_STYLES,
1716
TextStyleProps,
1817
} from '../../../tasty';
1918
import { useFocus } from '../../../utils/react/interactions';
2019

2120
export interface CubeActiveZoneProps
2221
extends BaseProps,
23-
TagNameProps,
2422
BaseStyleProps,
2523
ContainerStyleProps,
2624
TextStyleProps,

src/components/content/Text.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { CSSProperties, forwardRef } from 'react';
22

33
import {
44
BASE_STYLES,
5-
BaseProps,
5+
AllBaseProps,
66
BaseStyleProps,
77
COLOR_STYLES,
88
ColorStyleProps,
99
extractStyles,
1010
filterBaseProps,
1111
ResponsiveStyleValue,
12-
TagNameProps,
12+
TagName,
1313
tasty,
1414
TEXT_STYLES,
1515
TextStyleProps,
@@ -24,9 +24,8 @@ export const TEXT_PROP_MAP = {
2424
italic: 'fontStyle',
2525
} as const;
2626

27-
export interface CubeTextProps
28-
extends BaseProps,
29-
TagNameProps,
27+
export interface CubeTextProps<T extends TagName = TagName>
28+
extends AllBaseProps<T>,
3029
TextStyleProps,
3130
BaseStyleProps,
3231
ColorStyleProps {
@@ -111,14 +110,11 @@ const _Text = Object.assign(Text, {
111110
Success: forwardRef(function SuccessText(props: CubeTextProps, ref) {
112111
return <Text ref={ref} color="#success-text" {...props} />;
113112
}),
114-
Strong: forwardRef(function StrongText(props: CubeTextProps, ref) {
113+
Strong: forwardRef(function StrongText(props: CubeTextProps<'strong'>, ref) {
115114
return (
116115
<Text ref={ref} as="strong" preset="strong" color="#dark" {...props} />
117116
);
118117
}),
119-
Emphasis: forwardRef(function EmphasisText(props: CubeTextProps, ref) {
120-
return <Text ref={ref} as="em" preset="em" {...props} />;
121-
}),
122118
Selection: forwardRef(function SelectionText(props: CubeTextProps, ref) {
123119
return <Text ref={ref} color="#dark" fill="#note.30" {...props} />;
124120
}),

src/components/content/Title.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
extractStyles,
88
filterBaseProps,
99
PositionStyleProps,
10-
TagNameProps,
1110
tasty,
1211
TEXT_STYLES,
1312
} from '../../tasty';
@@ -20,7 +19,6 @@ const STYLE_LIST = [...TEXT_STYLES, ...CONTAINER_STYLES];
2019
export interface CubeTitleProps
2120
extends BaseProps,
2221
CubeTextProps,
23-
TagNameProps,
2422
ContainerStyleProps,
2523
PositionStyleProps {
2624
/** The level of the heading **/

src/components/fields/Select/Select.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
AriaSelectProps,
2323
} from 'react-aria';
2424
import styled from 'styled-components';
25-
import { CollectionBase, DOMRef } from '@react-types/shared';
25+
import { AriaLabelingProps, CollectionBase, DOMRef } from '@react-types/shared';
2626

2727
import { useFieldProps, useFormProps, wrapWithField } from '../../form';
2828
import { useProviderProps } from '../../../provider';
@@ -243,6 +243,7 @@ const StyledOverlayElement = styled(OverlayElement)`
243243

244244
export interface CubeSelectBaseProps<T>
245245
extends BasePropsWithoutChildren,
246+
AriaLabelingProps,
246247
OuterStyleProps,
247248
FieldBaseProps,
248249
BlockStyleProps,

src/components/form/Label.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
extractStyles,
1010
filterBaseProps,
1111
Styles,
12-
TagNameProps,
1312
tasty,
1413
} from '../../tasty/index';
1514
import {
@@ -78,10 +77,7 @@ const LabelElement = tasty({
7877
styles: LABEL_STYLES,
7978
});
8079

81-
export interface CubeLabelProps
82-
extends BaseProps,
83-
TagNameProps,
84-
ContainerStyleProps {
80+
export interface CubeLabelProps extends BaseProps, ContainerStyleProps {
8581
labelPosition?: LabelPosition;
8682
necessityIndicator?: NecessityIndicator;
8783
isRequired?: boolean;

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ export * from './components/fields';
138138

139139
export type {
140140
TagName,
141-
TagNameProps,
142141
AllBaseProps,
143142
BaseProps,
144143
BaseStyleProps,

src/tasty/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export type {
3232
FlowStyleProps,
3333
ShortGridStyles,
3434
GlobalStyledProps,
35-
TagNameProps,
3635
TagName,
3736
} from './types';
3837
export type {

src/tasty/types.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ type Caps =
4646
| 'Y'
4747
| 'Z';
4848

49-
export interface BasePropsWithoutChildren
49+
export interface BasePropsWithoutChildren<K extends TagName = TagName>
5050
extends Pick<AllHTMLAttributes<HTMLElement>, 'className' | 'role' | 'id'> {
51+
as?: K;
5152
/** QA ID for e2e testing. An alias for `data-qa` attribute. */
5253
qa?: string;
5354
/** QA value for e2e testing. An alias for `data-qaval` attribute. */
@@ -80,13 +81,13 @@ export interface BasePropsWithoutChildren
8081
theme?: 'default' | 'danger' | 'special' | (string & {});
8182
}
8283

83-
export interface BaseProps<K extends keyof HTMLElementTagNameMap = 'div'>
84+
export interface BaseProps<K extends TagName = TagName>
8485
extends AriaLabelingProps,
85-
BasePropsWithoutChildren,
86+
BasePropsWithoutChildren<K>,
8687
Pick<AllHTMLAttributes<HTMLElementTagNameMap[K]>, 'children'> {}
8788

88-
export interface AllBaseProps<K extends keyof HTMLElementTagNameMap = 'div'>
89-
extends BaseProps,
89+
export interface AllBaseProps<K extends TagName = TagName>
90+
extends BaseProps<K>,
9091
Omit<
9192
AllHTMLAttributes<HTMLElementTagNameMap[K]>,
9293
| 'style'
@@ -99,9 +100,9 @@ export interface AllBaseProps<K extends keyof HTMLElementTagNameMap = 'div'>
99100
| 'width'
100101
| 'content'
101102
| 'translate'
102-
> {
103-
as?: K;
104-
}
103+
| 'as'
104+
| 'form'
105+
> {}
105106

106107
export type BaseStyleProps = Pick<Styles, (typeof BASE_STYLES)[number]>;
107108
export type PositionStyleProps = Pick<Styles, (typeof POSITION_STYLES)[number]>;
@@ -131,8 +132,3 @@ export interface Props {
131132
}
132133

133134
export type TagName = keyof HTMLElementTagNameMap;
134-
135-
export interface TagNameProps {
136-
/** The tag name you want to use for the element */
137-
as?: TagName;
138-
}

0 commit comments

Comments
 (0)