Skip to content

Commit dfc6298

Browse files
authored
fix: improve typings (#529)
1 parent 8ad92dd commit dfc6298

File tree

15 files changed

+55
-61
lines changed

15 files changed

+55
-61
lines changed

.changeset/fast-hats-teach.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cube-dev/ui-kit': patch
3+
---
4+
5+
Futher improvement of typings.

.changeset/serious-windows-search.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cube-dev/ui-kit': minor
3+
---
4+
5+
Add support for more complex selectors in mods.

.changeset/swift-pets-roll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cube-dev/ui-kit': minor
3+
---
4+
5+
Improve typings and add support for the most html attributes and event handlers.

src/components/actions/Action/Action.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
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,
15+
TagName,
1616
} from '../../../tasty';
1717
import { useAction } from '../use-action';
1818

19-
export interface CubeActionProps
20-
extends BaseProps,
21-
TagNameProps,
19+
export interface CubeActionProps<
20+
T extends TagName = 'a' | 'button' | 'span' | 'div',
21+
> extends Omit<AllBaseProps<T>, 'htmlType'>,
2222
BaseStyleProps,
2323
ContainerStyleProps,
2424
TextStyleProps,
@@ -27,9 +27,6 @@ export interface CubeActionProps
2727
label?: string;
2828
htmlType?: 'button' | 'submit' | 'reset' | undefined;
2929
download?: string;
30-
onClick?: MouseEventHandler;
31-
onMouseEnter?: MouseEventHandler;
32-
onMouseLeave?: MouseEventHandler;
3330
}
3431

3532
const DEFAULT_ACTION_STYLES: Styles = {

src/components/actions/Button/Button.stories.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ const Template: StoryFn<CubeButtonProps> = ({
4141
icon,
4242
rightIcon,
4343
label,
44-
onClick,
4544
...props
4645
}) => (
4746
<Space

src/components/actions/use-action.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
1-
import { MouseEventHandler, useContext } from 'react';
1+
import { useContext } from 'react';
22
import { useFocusableRef } from '@react-spectrum/utils';
33
import { useHover, useButton, AriaButtonProps } from 'react-aria';
44
import { FocusableRef, PressEvent } from '@react-types/shared';
55

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<
17+
T extends TagName = 'a' | 'button' | 'span' | 'div',
18+
> extends AllBaseProps<T>,
1919
Omit<AriaButtonProps, 'type'> {
2020
to?: string;
2121
label?: string;
2222
htmlType?: 'button' | 'submit' | 'reset' | undefined;
23-
onClick?: MouseEventHandler;
24-
onMouseEnter?: MouseEventHandler;
25-
onMouseLeave?: MouseEventHandler;
2623
}
2724

2825
const FILTER_OPTIONS = { propNames: new Set(['onMouseEnter', 'onMouseLeave']) };

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: 7 additions & 10 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,12 +110,10 @@ 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) {
115-
return (
116-
<Text ref={ref} as="strong" preset="strong" color="#dark" {...props} />
117-
);
113+
Strong: forwardRef(function StrongText(props: CubeTextProps<'strong'>, ref) {
114+
return <Text ref={ref} as="strong" preset="strong" {...props} />;
118115
}),
119-
Emphasis: forwardRef(function EmphasisText(props: CubeTextProps, ref) {
116+
Emphasis: forwardRef(function StrongText(props: CubeTextProps<'em'>, ref) {
120117
return <Text ref={ref} as="em" preset="em" {...props} />;
121118
}),
122119
Selection: forwardRef(function SelectionText(props: CubeTextProps, ref) {

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,

0 commit comments

Comments
 (0)