Skip to content

Commit 1ad7ea2

Browse files
committed
fix(types): correct types in List components and implement Form Props Types
- Fixed TypeScript types and definitions in List components to ensure consistency. - Implemented Form Props Types by inheriting from the PuiBaseProps interface.
1 parent 31afae5 commit 1ad7ea2

30 files changed

+342
-155
lines changed

src/modules/base/ts/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { IPUIProps } from './types';
44

55
// Define the interface for the base component
66
interface /*bundle*/ BaseComponentProps<T = HTMLElement> extends IPUIProps<T> {
7-
as?: keyof JSX.IntrinsicElements; // The HTML tag to be used
87
motion?: boolean; // Flag to determine if framer-motion should be used
8+
[key: string]: any; // Allow any other prop
99
}
1010

1111
// Create the base component using a function with a constructor

src/modules/base/ts/types.ts src/modules/base/ts/types/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { MotionProps } from 'framer-motion';
2-
import React, { HTMLAttributes, AnimationEventHandler } from 'react';
2+
import React, { HTMLAttributes, AnimationEventHandler, ElementType, ReactHTML } from 'react';
33

44
type ConflictingProps = 'onAnimationStart' | 'onAnimationEnd' | 'onAnimationIteration';
55

@@ -15,6 +15,7 @@ export /*bundle*/ interface IPUIProps<T = unknown> extends HTMLMotionProps<T> {
1515
* @deprecated
1616
*/
1717
type?: string;
18+
as?: ElementType & keyof ReactHTML;
1819
title?: string;
1920
children?: React.ReactNode;
2021
variant?: Variant;
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// text-labels.ts
2+
import { IPUIProps } from './index';
3+
4+
/**
5+
* Props for link elements like <a>.
6+
*/
7+
export /*bundle*/ interface ILinkProps<T = HTMLAnchorElement> extends IPUIProps<T> {
8+
as: 'a';
9+
href?: string;
10+
target?: '_blank' | '_self' | '_parent' | '_top';
11+
rel?: string;
12+
}
13+
14+
/**
15+
* Props for inline text styling elements like <strong>, <em>, <span>.
16+
*/
17+
export /*bundle*/ interface IInlineTextProps<T = HTMLElement> extends IPUIProps<T> {
18+
as: 'strong' | 'em' | 'span';
19+
}
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// multimedia-labels.ts
2+
import { IPUIProps } from './';
3+
4+
/**
5+
* Props for image elements like <img>.
6+
*/
7+
export /*bundle*/ interface IImageProps<T = HTMLImageElement> extends IPUIProps<T> {
8+
as: 'img';
9+
src: string;
10+
alt: string;
11+
width?: number | string;
12+
height?: number | string;
13+
}
14+
15+
/**
16+
* Props for audio elements like <audio>.
17+
*/
18+
export /*bundle*/ interface IAudioProps<T = HTMLAudioElement> extends IPUIProps<T> {
19+
as: 'audio';
20+
src: string;
21+
controls?: boolean;
22+
autoPlay?: boolean;
23+
loop?: boolean;
24+
muted?: boolean;
25+
}
26+
27+
/**
28+
* Props for video elements like <video>.
29+
*/
30+
export /*bundle*/ interface IVideoProps<T = HTMLVideoElement> extends IPUIProps<T> {
31+
as: 'video';
32+
src: string;
33+
controls?: boolean;
34+
autoPlay?: boolean;
35+
loop?: boolean;
36+
muted?: boolean;
37+
width?: number | string;
38+
height?: number | string;
39+
}

src/modules/common/components/ts/html-wrapper.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface HtmlRenderProps<T extends HTMLElement = HTMLElement> extends React.HTM
77
*/
88
tag?: keyof JSX.IntrinsicElements;
99
as?: keyof JSX.IntrinsicElements;
10-
params: Record<string, string>;
10+
params?: Record<string, string>;
1111
}
1212

1313
export /*bundle*/ function HtmlWrapper({

src/modules/form/controls/ts/checkbox/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { IPUIProps } from 'pragmate-ui/base';
22
import React, { MouseEvent, RefAttributes, forwardRef, useEffect, useState } from 'react';
3-
import { IFormCheckableProps } from '../types';
3+
import { IFormCheckableProps } from '../types/interfaces';
44

55
export /*bundle*/ const Checkbox: React.FC<IPUIProps & RefAttributes<HTMLInputElement>> = forwardRef(function (
66
props: IFormCheckableProps,
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import React from 'react';
22
import { Icon } from 'pragmate-ui/icons';
33
import { useInputContext } from '../context';
4-
interface HTMLInputWithPicker extends HTMLInputElement {
5-
showPicker: () => void;
6-
}
74

85
export function Date(): JSX.Element {
96
const { input, props, icon, isDate } = useInputContext();
@@ -13,15 +10,8 @@ export function Date(): JSX.Element {
1310

1411
const showPicker = () => {
1512
if (props.disabled) return;
16-
(input.current as any).showPicker()
17-
}
18-
19-
return (
20-
<Icon
21-
key='icon'
22-
icon={iconValue}
23-
className='pui-input__icon'
24-
onClick={showPicker}
25-
/>
26-
);
13+
(input.current as any).showPicker();
14+
};
15+
16+
return <Icon key='icon' icon={iconValue} className='pui-input__icon' onClick={showPicker} />;
2717
}

src/modules/form/controls/ts/input/components/label.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from 'react';
22
import { useInputContext } from '../context';
3-
import { ILabelProps } from '../interfaces';
3+
44
import { BaseComponent } from 'pragmate-ui/base';
5+
import { ILabelProps } from '../../types/label';
56
export /*bundle */ function Label({ required, position, children }: ILabelProps = {}) {
67
const { name, id } = useInputContext();
78

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { IInputContextValue } from './interfaces';
2+
import { IInputContextValue } from './types';
33

44
export const InputContext: React.Context<IInputContextValue> = React.createContext({});
55
export const useInputContext = (): IInputContextValue => React.useContext(InputContext);

src/modules/form/controls/ts/input/control.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { ChangeEvent, useEffect } from 'react';
22
import { useInputContext } from './context';
33
import { internalProps } from './internal-props';
4-
import { IProps } from './interfaces';
4+
import { IProps } from '../types/interfaces';
55
import { IconContainer } from './components/icon-container';
66
import { BaseComponent } from 'pragmate-ui/base';
77

src/modules/form/controls/ts/input/index.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import React, { MutableRefObject, useRef } from 'react';
22
import { useState } from 'react';
3-
import type { IInputContainer, IInputContextValue, ILabelProps, IProps, TState } from './interfaces';
3+
import type { IInputContainer, IProps } from '../types/interfaces';
44
import { InputContext } from './context';
55
import { Label } from './components/label';
66
import { ControlSelector } from './control';
77
import { Error } from './components/error';
8-
import { BaseComponent } from 'pragmate-ui/base';
8+
9+
import { IInputContextValue, TState } from './types';
10+
import { ILabelProps } from '../types/label';
911

1012
/**
1113
*

src/modules/form/controls/ts/input/interfaces/index.ts

-49
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { InputHTMLAttributes, MutableRefObject } from 'react';
2+
import { IProps } from '../types/interfaces';
3+
4+
export interface TState {
5+
value?: string | number | readonly string[];
6+
type?: InputHTMLAttributes<HTMLInputElement>['type'];
7+
}
8+
9+
export interface IInputContextValue {
10+
state?: TState;
11+
id?: string;
12+
value?: string;
13+
name?: string;
14+
props?: IProps;
15+
icon?: string;
16+
setState?: any;
17+
setValue?: (value) => void;
18+
input?: MutableRefObject<HTMLInputElement>;
19+
isDate?: boolean;
20+
}
+15-21
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,25 @@
11
import { IPUIProps } from 'pragmate-ui/base';
22
import React, { MutableRefObject, useRef } from 'react';
3-
import { IFormProps } from './types';
3+
import { IFormProps } from './types/interfaces';
44

5-
interface IPropsRadio extends InputHTMLAttributes<HTMLInputElement> {
6-
label?: string;
7-
}
8-
9-
type CombinedProps = IPropsRadio & IPUIProps<HTMLInputElement>;
10-
11-
export /*bundle*/ function Radio(props: CombinedProps): JSX.Element {
12-
const input: MutableRefObject<HTMLInputElement> = useRef<HTMLInputElement>(null);
5+
export /*bundle*/ function Radio(props: IFormProps): JSX.Element {
6+
const input: MutableRefObject<HTMLInputElement> = useRef<HTMLInputElement>(null);
137

14-
const onClick = (event): void => {
15-
event.stopPropagation();
16-
input.current.checked = true;
17-
if (!!props.onChange) props.onChange(event);
18-
};
8+
const onClick = (event): void => {
9+
event.stopPropagation();
10+
input.current.checked = true;
11+
if (!!props.onChange) props.onChange(event);
12+
};
1913

2014
const properties: IFormProps = { ...props };
2115
delete properties.onChange;
2216

23-
const cls: string = `pragmate-element-radio ${properties.className ? properties.className : ''}`;
17+
const cls: string = `pragmate-element-radio ${properties.className ? properties.className : ''}`;
2418

25-
return (
26-
<label className={cls} onClick={onClick}>
27-
<input ref={input} {...properties} type='radio' onChange={onClick} />
28-
{properties.label && <span>{properties.label}</span>}
29-
</label>
30-
);
19+
return (
20+
<label className={cls} onClick={onClick}>
21+
<input ref={input} {...properties} type='radio' onChange={onClick} />
22+
{properties.label && <span>{properties.label}</span>}
23+
</label>
24+
);
3125
}

src/modules/form/controls/ts/switch.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { IFormCheckableProps } from './types';
2+
import { IFormCheckableProps } from './types/interfaces';
33

44
export /* bundle */ function Switch(props: IFormCheckableProps): JSX.Element {
55
const { checked, onChange, variant = 'primary', disabled, sizing = 'md', className } = props;

src/modules/form/controls/ts/textarea/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { ChangeEvent, useRef, useState } from 'react';
3-
import { IProps, IState } from './types';
3+
import { IProps, IState } from '../types/textarea';
44
import { TextareaError } from './error';
55
import { TextareaCounter } from './counter';
66

+29-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,36 @@
1+
import { InputHTMLAttributes, ReactNode } from 'react';
12
import { IPUIProps } from 'pragmate-ui/base';
2-
export interface IFormProps extends IPUIProps<HTMLInputElement> {
3+
4+
/**
5+
* Unified IFormProps interface containing all common properties.
6+
*/
7+
export /*bundle*/ interface IFormProps<T = HTMLElement> extends IPUIProps<T> {
38
disabled?: boolean;
49
label?: string;
5-
name?: string;
6-
sizing?: 'small' | 'medium' | 'large'; // Validate if size or sizing
10+
value?: string | number;
11+
placeholder?: string;
12+
children?: ReactNode;
13+
}
14+
15+
/**
16+
* Props for input elements like <input>.
17+
*/
18+
export /*bundle*/ interface IInputProps<T = HTMLInputElement> extends IFormProps<T> {
19+
type?: string;
20+
checked?: boolean;
21+
readOnly?: boolean;
22+
}
23+
24+
/**
25+
* Props for button elements like <button>.
26+
*/
27+
export /*bundle*/ interface IButtonProps<T = HTMLButtonElement> extends IFormProps<T> {
28+
type?: 'button' | 'submit' | 'reset';
729
}
830

9-
export interface IFormCheckableProps extends IFormProps {
31+
/**
32+
* Extended form checkable props for elements like <input> of type checkbox or radio.
33+
*/
34+
export /*bundle*/ interface IFormCheckableProps<T = HTMLInputElement> extends IInputProps<T> {
1035
checked?: boolean;
1136
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { InputHTMLAttributes, ReactNode } from 'react';
2+
import { IPUIProps } from 'pragmate-ui/base';
3+
export interface IFormProps extends IPUIProps<HTMLInputElement> {
4+
disabled?: boolean;
5+
label?: string;
6+
name?: string;
7+
sizing?: 'small' | 'medium' | 'large'; // Validate if size or sizing
8+
}
9+
10+
export interface IFormCheckableProps extends IFormProps {
11+
checked?: boolean;
12+
}
13+
14+
export interface IProps extends InputHTMLAttributes<HTMLInputElement> {
15+
ref?: any;
16+
variant?: string;
17+
icon?: string;
18+
errorMessage?: string;
19+
value?: string;
20+
label?: any;
21+
children?: ReactNode;
22+
hasError?: boolean;
23+
password?: boolean;
24+
}
25+
26+
export interface IPropsState {
27+
value?: string;
28+
errorMessage: string;
29+
lengthMessage: string;
30+
emptyMessage: string;
31+
_hasError?: boolean;
32+
type: InputHTMLAttributes<HTMLInputElement>['type'];
33+
}
34+
35+
export interface IInputContainer {
36+
className?: string;
37+
}

0 commit comments

Comments
 (0)