Skip to content

Commit

Permalink
refactor(Input): remove id property
Browse files Browse the repository at this point in the history
  • Loading branch information
shervinchen committed Apr 17, 2024
1 parent 498554e commit 1f122d2
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 76 deletions.
6 changes: 2 additions & 4 deletions packages/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React, {
useRef,
} from 'react';
import classNames from 'classnames';
import { InputComponent, InputProps } from './Input.types';
import { InputProps } from './Input.types';
import { useInputCSS } from './Input.styles';
import { useControlled } from '../utils/hooks';
import { InputGroupConfig } from './InputGroup.types';
Expand Down Expand Up @@ -106,6 +106,4 @@ const Input = forwardRef<HTMLInputElement, PropsWithChildren<InputProps>>(

Input.displayName = 'RawInput';

const RawInput: InputComponent = Object.assign(Input, { id: 'Input' });

export default RawInput;
export default Input;
15 changes: 1 addition & 14 deletions packages/Input/Input.types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
InputHTMLAttributes,
ChangeEvent,
FocusEvent,
ForwardRefExoticComponent,
RefAttributes,
PropsWithChildren,
} from 'react';
import { InputHTMLAttributes, ChangeEvent, FocusEvent } from 'react';

export type InputTypes =
| 'default'
Expand Down Expand Up @@ -40,12 +33,6 @@ type NativeInputProps = Omit<

export type InputProps = BaseInputProps & NativeInputProps;

export type InputComponent = ForwardRefExoticComponent<
PropsWithChildren<InputProps> & RefAttributes<HTMLInputElement>
> & {
id: string;
};

export interface InputSizeStyles {
fontSize?: string;
height?: string;
Expand Down
14 changes: 1 addition & 13 deletions packages/Input/InputAddon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ type NativeInputAddonProps = Omit<

type InputAddonProps = BaseInputAddonProps & NativeInputAddonProps;

export type InputAddonType = FC<InputAddonProps> & {
id: string;
};

const InputAddon: FC<PropsWithChildren<InputAddonProps>> = ({
className,
children,
Expand Down Expand Up @@ -77,12 +73,4 @@ const InputRightAddon: FC<InputAddonProps> = ({
return <InputAddon className={classes} {...resetProps} />;
};

const RawInputLeftAddon: InputAddonType = Object.assign(InputLeftAddon, {
id: 'InputLeftAddon',
});

const RawInputRightAddon: InputAddonType = Object.assign(InputRightAddon, {
id: 'InputRightAddon',
});

export { RawInputLeftAddon, RawInputRightAddon };
export { InputLeftAddon, InputRightAddon };
15 changes: 1 addition & 14 deletions packages/Input/InputElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ type NativeInputElementProps = Omit<

type InputElementProps = BaseInputElementProps & NativeInputElementProps;

export type InputElementType = FC<Omit<InputElementProps, 'placement'>> & {
id: string;
};

const InputElement: FC<PropsWithChildren<InputElementProps>> = ({
placement,
clickable = false,
Expand Down Expand Up @@ -72,13 +68,4 @@ const InputRightElement: FC<Omit<InputElementProps, 'placement'>> = ({
return <InputElement className={classes} placement="right" {...resetProps} />;
};

const RawInputLeftElement: InputElementType = Object.assign(InputLeftElement, {
id: 'InputLeftElement',
});

const RawInputRightElement: InputElementType = Object.assign(
InputRightElement,
{ id: 'InputRightElement' }
);

export { RawInputLeftElement, RawInputRightElement };
export { InputLeftElement, InputRightElement };
23 changes: 10 additions & 13 deletions packages/Input/InputGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React, { FC, PropsWithChildren, cloneElement, useMemo } from 'react';
import classNames from 'classnames';
import {
InputGroupChild,
InputGroupConfig,
InputGroupProps,
} from './InputGroup.types';
import { InputGroupConfig, InputGroupProps } from './InputGroup.types';
import { InputGroupContext } from './input-group-context';
import { getValidChildren } from '../utils/common';
import { useInputStyles } from './Input.styles';
import Input from './Input';
import { InputLeftElement, InputRightElement } from './InputElement';
import { InputLeftAddon, InputRightAddon } from './InputAddon';

const useComputedInputStyles = ({ type, size, disabled }: InputGroupProps) => {
const { height, horizontalPadding } = useInputStyles({
Expand All @@ -25,26 +24,26 @@ const useComputedInputStyles = ({ type, size, disabled }: InputGroupProps) => {
};
const styles = [
{
id: 'InputLeftElement',
type: InputLeftElement,
newStyle: {
paddingLeft: height,
},
},
{
id: 'InputRightElement',
type: InputRightElement,
newStyle: {
paddingRight: height,
},
},
{
id: 'InputLeftAddon',
type: InputLeftAddon,
newStyle: {
borderTopLeftRadius: '0px',
borderBottomLeftRadius: '0px',
},
},
{
id: 'InputRightAddon',
type: InputRightAddon,
newStyle: {
borderTopRightRadius: '0px',
borderBottomRightRadius: '0px',
Expand Down Expand Up @@ -87,9 +86,7 @@ const InputGroup: FC<PropsWithChildren<InputGroupProps>> = ({
});
let computedStyle = style;
getValidChildren(children).forEach((child) => {
const result = styles.find(
(item) => item.id === (child.type as InputGroupChild).id
);
const result = styles.find((item) => item.type === child.type);
if (result) {
const { newStyle } = result;
computedStyle = { ...computedStyle, ...newStyle };
Expand All @@ -101,7 +98,7 @@ const InputGroup: FC<PropsWithChildren<InputGroupProps>> = ({
const computedInputStyle = useComputedInputStyle();

const cloneChildren = getValidChildren(children).map((child) => {
return (child.type as InputGroupChild).id !== 'Input'
return child.type !== Input
? child
: cloneElement(child, { style: computedInputStyle });
});
Expand Down
9 changes: 1 addition & 8 deletions packages/Input/InputGroup.types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { HTMLAttributes } from 'react';
import { InputComponent, InputSizes, InputTypes } from './Input.types';
import { InputAddonType } from './InputAddon';
import { InputElementType } from './InputElement';
import { InputSizes, InputTypes } from './Input.types';

interface BaseInputGroupProps {
className?: string;
Expand All @@ -18,11 +16,6 @@ type NativeInputGroupProps = Omit<

export type InputGroupProps = BaseInputGroupProps & NativeInputGroupProps;

export type InputGroupChild =
| InputAddonType
| InputElementType
| InputComponent;

export interface InputGroupConfig {
size?: InputSizes;
type?: InputTypes;
Expand Down
20 changes: 10 additions & 10 deletions packages/Input/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import Input from './Input';
import InputGroup from './InputGroup';
import { RawInputLeftElement, RawInputRightElement } from './InputElement';
import { RawInputLeftAddon, RawInputRightAddon } from './InputAddon';
import { InputLeftElement, InputRightElement } from './InputElement';
import { InputLeftAddon, InputRightAddon } from './InputAddon';

export type InputComponentType = typeof Input & {
Group: typeof InputGroup;
LeftElement: typeof RawInputLeftElement;
RightElement: typeof RawInputRightElement;
LeftAddon: typeof RawInputLeftAddon;
RightAddon: typeof RawInputRightAddon;
LeftElement: typeof InputLeftElement;
RightElement: typeof InputRightElement;
LeftAddon: typeof InputLeftAddon;
RightAddon: typeof InputRightAddon;
};

(Input as InputComponentType).Group = InputGroup;
(Input as InputComponentType).LeftElement = RawInputLeftElement;
(Input as InputComponentType).RightElement = RawInputRightElement;
(Input as InputComponentType).LeftAddon = RawInputLeftAddon;
(Input as InputComponentType).RightAddon = RawInputRightAddon;
(Input as InputComponentType).LeftElement = InputLeftElement;
(Input as InputComponentType).RightElement = InputRightElement;
(Input as InputComponentType).LeftAddon = InputLeftAddon;
(Input as InputComponentType).RightAddon = InputRightAddon;

export default Input as InputComponentType;
16 changes: 16 additions & 0 deletions packages/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React, { FC, PropsWithChildren } from 'react';
import { PaginationProps } from './Pagination.types';

const Pagination: FC<PropsWithChildren<PaginationProps>> = ({
page,

Check warning on line 5 in packages/Pagination/Pagination.tsx

View workflow job for this annotation

GitHub Actions / Release

'page' is defined but never used
defaultPage,

Check warning on line 6 in packages/Pagination/Pagination.tsx

View workflow job for this annotation

GitHub Actions / Release

'defaultPage' is defined but never used
count,

Check warning on line 7 in packages/Pagination/Pagination.tsx

View workflow job for this annotation

GitHub Actions / Release

'count' is defined but never used
limit,

Check warning on line 8 in packages/Pagination/Pagination.tsx

View workflow job for this annotation

GitHub Actions / Release

'limit' is defined but never used
onChange,

Check warning on line 9 in packages/Pagination/Pagination.tsx

View workflow job for this annotation

GitHub Actions / Release

'onChange' is defined but never used
children,

Check warning on line 10 in packages/Pagination/Pagination.tsx

View workflow job for this annotation

GitHub Actions / Release

'children' is defined but never used
...restProps

Check warning on line 11 in packages/Pagination/Pagination.tsx

View workflow job for this annotation

GitHub Actions / Release

'restProps' is defined but never used
}) => {
return <div></div>;
};

export default Pagination;
16 changes: 16 additions & 0 deletions packages/Pagination/Pagination.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { HTMLAttributes } from 'react';

interface BasePaginationProps {
page?: number;
defaultPage?: number;
count?: number;
limit?: number;
onChange?: (page: number) => void;
}

type NativePaginationProps = Omit<
HTMLAttributes<HTMLElement>,
keyof BasePaginationProps
>;

export type PaginationProps = BasePaginationProps & NativePaginationProps;
1 change: 1 addition & 0 deletions packages/Pagination/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './Pagination';

0 comments on commit 1f122d2

Please sign in to comment.