Skip to content

Commit

Permalink
feat(components/input): polymorphic attribs to input component
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotsaha committed Nov 8, 2022
1 parent 1a2ad07 commit cd4b4e3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
10 changes: 6 additions & 4 deletions src/lib/Button/Button.tsx
Expand Up @@ -10,7 +10,8 @@ import ButtonIcon from './ButtonIcon';
/**
* Buttons allow users to take actions, and make choices, with a single tap.
*/
export interface ButtonProps<T extends React.ElementType> extends React.ComponentPropsWithRef<'button'> {
export interface ButtonProps<T extends React.ElementType>
extends React.ComponentPropsWithRef<'button'> {
/**
* The content of the component.
*/
Expand Down Expand Up @@ -84,7 +85,7 @@ export interface ButtonProps<T extends React.ElementType> extends React.Componen
}

const Button = React.forwardRef(
<T extends React.ElementType = "button">(
<T extends React.ElementType = 'button'>(
{
role = 'button',
as,
Expand All @@ -103,7 +104,8 @@ const Button = React.forwardRef(
children,
pill = false,
...btnProps
}: ButtonProps<T> & Omit<React.ComponentPropsWithoutRef<T>, keyof ButtonProps<T>>,
}: ButtonProps<T> &
Omit<React.ComponentPropsWithoutRef<T>, keyof ButtonProps<T>>,
ref: React.Ref<HTMLButtonElement | null>
) => {
const hasText = useMemo(
Expand All @@ -129,7 +131,7 @@ const Button = React.forwardRef(
const preClass = 'decaButton';

const { dark } = React.useContext(ThemeContext);

return (
<StyledButton
role={role}
Expand Down
11 changes: 6 additions & 5 deletions src/lib/Input/Input.tsx
Expand Up @@ -20,7 +20,7 @@ export type FormElement = HTMLInputElement | HTMLTextAreaElement;
/**
* Inputs allow users to enter text into a UI. They typically appear in forms and dialogs.
*/
export interface InputProps
export interface InputProps<T extends React.ElementType>
extends Modify<
React.ComponentPropsWithRef<'input'>,
{
Expand Down Expand Up @@ -58,7 +58,7 @@ export interface InputProps
/**
* Changes which tag component outputs.
*/
as?: keyof JSX.IntrinsicElements;
as?: T;
/**
* Placeholder text for component.
*/
Expand Down Expand Up @@ -114,14 +114,14 @@ export interface InputProps
}

const Input = React.forwardRef(
(
<T extends React.ElementType = 'input'>(
{
label,
className = '',
disabled = false,
size = 'md',
variant = 'solid',
as = 'input',
as,
css,
focusColor = 'primary',
maxWidth = false,
Expand All @@ -135,7 +135,8 @@ const Input = React.forwardRef(
onBlur,
pill = false,
...props
}: InputProps,
}: InputProps<T> &
Omit<React.ComponentPropsWithoutRef<T>, keyof InputProps<T>>,
ref: React.Ref<FormElement | null>
) => {
const inputRef = useRef<UnionToIntersection<FormElement>>(null);
Expand Down

0 comments on commit cd4b4e3

Please sign in to comment.