diff --git a/.changeset/fast-hats-teach.md b/.changeset/fast-hats-teach.md new file mode 100644 index 000000000..1632ff750 --- /dev/null +++ b/.changeset/fast-hats-teach.md @@ -0,0 +1,5 @@ +--- +'@cube-dev/ui-kit': patch +--- + +Futher improvement of typings. diff --git a/.changeset/serious-windows-search.md b/.changeset/serious-windows-search.md new file mode 100644 index 000000000..b00bad25f --- /dev/null +++ b/.changeset/serious-windows-search.md @@ -0,0 +1,5 @@ +--- +'@cube-dev/ui-kit': minor +--- + +Add support for more complex selectors in mods. diff --git a/.changeset/swift-pets-roll.md b/.changeset/swift-pets-roll.md new file mode 100644 index 000000000..945370d7f --- /dev/null +++ b/.changeset/swift-pets-roll.md @@ -0,0 +1,5 @@ +--- +'@cube-dev/ui-kit': minor +--- + +Improve typings and add support for the most html attributes and event handlers. diff --git a/src/components/actions/Action/Action.tsx b/src/components/actions/Action/Action.tsx index 63a5c32c2..d5f3d6eaa 100644 --- a/src/components/actions/Action/Action.tsx +++ b/src/components/actions/Action/Action.tsx @@ -1,24 +1,24 @@ -import { forwardRef, MouseEventHandler } from 'react'; +import { forwardRef } from 'react'; import { AriaButtonProps } from 'react-aria'; import { FocusableRef } from '@react-types/shared'; import { - BaseProps, + AllBaseProps, BaseStyleProps, CONTAINER_STYLES, ContainerStyleProps, extractStyles, Styles, - TagNameProps, TEXT_STYLES, TextStyleProps, tasty, + TagName, } from '../../../tasty'; import { useAction } from '../use-action'; -export interface CubeActionProps - extends BaseProps, - TagNameProps, +export interface CubeActionProps< + T extends TagName = 'a' | 'button' | 'span' | 'div', +> extends Omit, 'htmlType'>, BaseStyleProps, ContainerStyleProps, TextStyleProps, @@ -27,9 +27,6 @@ export interface CubeActionProps label?: string; htmlType?: 'button' | 'submit' | 'reset' | undefined; download?: string; - onClick?: MouseEventHandler; - onMouseEnter?: MouseEventHandler; - onMouseLeave?: MouseEventHandler; } const DEFAULT_ACTION_STYLES: Styles = { diff --git a/src/components/actions/Button/Button.stories.tsx b/src/components/actions/Button/Button.stories.tsx index d733bd204..676a1613d 100644 --- a/src/components/actions/Button/Button.stories.tsx +++ b/src/components/actions/Button/Button.stories.tsx @@ -41,7 +41,6 @@ const Template: StoryFn = ({ icon, rightIcon, label, - onClick, ...props }) => ( extends AllBaseProps, Omit { to?: string; label?: string; htmlType?: 'button' | 'submit' | 'reset' | undefined; - onClick?: MouseEventHandler; - onMouseEnter?: MouseEventHandler; - onMouseLeave?: MouseEventHandler; } const FILTER_OPTIONS = { propNames: new Set(['onMouseEnter', 'onMouseLeave']) }; diff --git a/src/components/content/ActiveZone/ActiveZone.tsx b/src/components/content/ActiveZone/ActiveZone.tsx index e3d5a85a7..8c94e4219 100644 --- a/src/components/content/ActiveZone/ActiveZone.tsx +++ b/src/components/content/ActiveZone/ActiveZone.tsx @@ -12,7 +12,6 @@ import { extractStyles, filterBaseProps, Styles, - TagNameProps, TEXT_STYLES, TextStyleProps, } from '../../../tasty'; @@ -20,7 +19,6 @@ import { useFocus } from '../../../utils/react/interactions'; export interface CubeActiveZoneProps extends BaseProps, - TagNameProps, BaseStyleProps, ContainerStyleProps, TextStyleProps, diff --git a/src/components/content/Text.tsx b/src/components/content/Text.tsx index 49b810ab1..2f80acf81 100644 --- a/src/components/content/Text.tsx +++ b/src/components/content/Text.tsx @@ -2,14 +2,14 @@ import { CSSProperties, forwardRef } from 'react'; import { BASE_STYLES, - BaseProps, + AllBaseProps, BaseStyleProps, COLOR_STYLES, ColorStyleProps, extractStyles, filterBaseProps, ResponsiveStyleValue, - TagNameProps, + TagName, tasty, TEXT_STYLES, TextStyleProps, @@ -24,9 +24,8 @@ export const TEXT_PROP_MAP = { italic: 'fontStyle', } as const; -export interface CubeTextProps - extends BaseProps, - TagNameProps, +export interface CubeTextProps + extends AllBaseProps, TextStyleProps, BaseStyleProps, ColorStyleProps { @@ -111,12 +110,10 @@ const _Text = Object.assign(Text, { Success: forwardRef(function SuccessText(props: CubeTextProps, ref) { return ; }), - Strong: forwardRef(function StrongText(props: CubeTextProps, ref) { - return ( - - ); + Strong: forwardRef(function StrongText(props: CubeTextProps<'strong'>, ref) { + return ; }), - Emphasis: forwardRef(function EmphasisText(props: CubeTextProps, ref) { + Emphasis: forwardRef(function StrongText(props: CubeTextProps<'em'>, ref) { return ; }), Selection: forwardRef(function SelectionText(props: CubeTextProps, ref) { diff --git a/src/components/content/Title.tsx b/src/components/content/Title.tsx index da24d2e98..aa63fc2ce 100644 --- a/src/components/content/Title.tsx +++ b/src/components/content/Title.tsx @@ -7,7 +7,6 @@ import { extractStyles, filterBaseProps, PositionStyleProps, - TagNameProps, tasty, TEXT_STYLES, } from '../../tasty'; @@ -20,7 +19,6 @@ const STYLE_LIST = [...TEXT_STYLES, ...CONTAINER_STYLES]; export interface CubeTitleProps extends BaseProps, CubeTextProps, - TagNameProps, ContainerStyleProps, PositionStyleProps { /** The level of the heading **/ diff --git a/src/components/fields/Select/Select.tsx b/src/components/fields/Select/Select.tsx index 249b6982a..3505fdb2d 100644 --- a/src/components/fields/Select/Select.tsx +++ b/src/components/fields/Select/Select.tsx @@ -22,7 +22,7 @@ import { AriaSelectProps, } from 'react-aria'; import styled from 'styled-components'; -import { CollectionBase, DOMRef } from '@react-types/shared'; +import { AriaLabelingProps, CollectionBase, DOMRef } from '@react-types/shared'; import { useFieldProps, useFormProps, wrapWithField } from '../../form'; import { useProviderProps } from '../../../provider'; @@ -243,6 +243,7 @@ const StyledOverlayElement = styled(OverlayElement)` export interface CubeSelectBaseProps extends BasePropsWithoutChildren, + AriaLabelingProps, OuterStyleProps, FieldBaseProps, BlockStyleProps, diff --git a/src/components/form/Label.tsx b/src/components/form/Label.tsx index f41ae8b1a..3c6cd51cc 100644 --- a/src/components/form/Label.tsx +++ b/src/components/form/Label.tsx @@ -1,5 +1,5 @@ import { useDOMRef } from '@react-spectrum/utils'; -import { forwardRef, MouseEventHandler } from 'react'; +import { forwardRef } from 'react'; import { useProviderProps } from '../../provider'; import { @@ -9,7 +9,6 @@ import { extractStyles, filterBaseProps, Styles, - TagNameProps, tasty, } from '../../tasty/index'; import { @@ -78,10 +77,7 @@ const LabelElement = tasty({ styles: LABEL_STYLES, }); -export interface CubeLabelProps - extends BaseProps, - TagNameProps, - ContainerStyleProps { +export interface CubeLabelProps extends BaseProps, ContainerStyleProps { labelPosition?: LabelPosition; necessityIndicator?: NecessityIndicator; isRequired?: boolean; @@ -89,7 +85,6 @@ export interface CubeLabelProps htmlFor?: string; for?: string; validationState?: ValidationState; - onClick?: MouseEventHandler; } function Label(props: CubeLabelProps, ref) { @@ -107,7 +102,6 @@ function Label(props: CubeLabelProps, ref) { isDisabled, validationState, for: labelFor, - onClick, ...otherProps } = props; @@ -143,7 +137,6 @@ function Label(props: CubeLabelProps, ref) { invalid: validationState === 'invalid', valid: validationState === 'valid', }} - onClick={onClick} > {typeof children !== 'string' ? ( children diff --git a/src/index.ts b/src/index.ts index ad051ebf1..245dc5ab6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -138,7 +138,6 @@ export * from './components/fields'; export type { TagName, - TagNameProps, AllBaseProps, BaseProps, BaseStyleProps, diff --git a/src/tasty/index.ts b/src/tasty/index.ts index 46e4b3e08..259b17802 100644 --- a/src/tasty/index.ts +++ b/src/tasty/index.ts @@ -32,7 +32,6 @@ export type { FlowStyleProps, ShortGridStyles, GlobalStyledProps, - TagNameProps, TagName, } from './types'; export type { diff --git a/src/tasty/types.ts b/src/tasty/types.ts index 8f9131eef..a0826cb3a 100644 --- a/src/tasty/types.ts +++ b/src/tasty/types.ts @@ -46,8 +46,9 @@ type Caps = | 'Y' | 'Z'; -export interface BasePropsWithoutChildren +export interface BasePropsWithoutChildren extends Pick, 'className' | 'role' | 'id'> { + as?: K; /** QA ID for e2e testing. An alias for `data-qa` attribute. */ qa?: string; /** QA value for e2e testing. An alias for `data-qaval` attribute. */ @@ -80,28 +81,33 @@ export interface BasePropsWithoutChildren theme?: 'default' | 'danger' | 'special' | (string & {}); } -export interface BaseProps +export interface BaseProps extends AriaLabelingProps, - BasePropsWithoutChildren, + BasePropsWithoutChildren, Pick, 'children'> {} -export interface AllBaseProps - extends BaseProps, +export interface AllBaseProps + extends BaseProps, Omit< AllHTMLAttributes, | 'style' - | 'size' | 'disabled' | 'hidden' | 'css' + | 'content' + | 'translate' + | 'as' + | 'form' + | 'bgcolor' + | 'background' + | 'align' + | 'border' | 'color' | 'height' + | 'size' | 'width' - | 'content' - | 'translate' - > { - as?: K; -} + | 'prefix' + > {} export type BaseStyleProps = Pick; export type PositionStyleProps = Pick; @@ -131,8 +137,3 @@ export interface Props { } export type TagName = keyof HTMLElementTagNameMap; - -export interface TagNameProps { - /** The tag name you want to use for the element */ - as?: TagName; -} diff --git a/src/tasty/utils/styles.ts b/src/tasty/utils/styles.ts index 8206c0194..828ae7bf6 100644 --- a/src/tasty/utils/styles.ts +++ b/src/tasty/utils/styles.ts @@ -906,7 +906,7 @@ export function styleMapToStyleMapStateList( } const STATES_REGEXP = - /([&|!^])|([()])|([a-z][a-z0-9-]+)|(:[a-z][a-z0-9-]+\([:a-z0-9-]+\)|:[a-z][a-z0-9-]+)|(\.[a-z][a-z0-9-]+)|(\[[^\]]+])/gi; + /([&|!^])|([()])|([a-z][a-z0-9-]+)|(:[a-z][a-z0-9-]+\([^)]+\)|:[a-z][a-z0-9-]+)|(\.[a-z][a-z0-9-]+)|(\[[^\]]+])/gi; export const STATE_OPERATORS = { NOT: '!', AND: '&',