Skip to content

Commit

Permalink
feat: use predefined HTML element props as a base for our components …
Browse files Browse the repository at this point in the history
…build on top of those (#16)

* feat: use HTML element props as base for our input and button props

* fix: remove "incremental" option, since without tsbuildinfo it fails to build
  • Loading branch information
rauno56 authored Apr 2, 2024
1 parent 487cca1 commit 1b56ebf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
12 changes: 4 additions & 8 deletions src/design.system/button/button.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
import React, { FC } from 'react';
import React, { ButtonHTMLAttributes, FC } from 'react';
import { StyledButton, ButtonContainer } from './button.styled';

interface ButtonProps {
interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
// Additional custom props if needed
variant?: string;
children: JSX.Element | JSX.Element[];
onClick?: () => void;
style?: object;
disabled?: boolean;
type?: 'button' | 'submit' | 'reset' | undefined;
}

export const Button: FC<ButtonProps> = ({
variant = 'primary',
children,
style,
onClick,
disabled,
type = 'button',
...rest
}) => {
return (
<ButtonContainer variant={variant} disabled={disabled}>
<StyledButton
type={type}
variant={variant}
disabled={disabled}
onClick={onClick}
style={{ ...style }}
{...rest}
>
{children}
</StyledButton>
Expand Down
17 changes: 7 additions & 10 deletions src/design.system/input/input.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ChangeEvent, useState } from 'react';
import React, { ChangeEvent, InputHTMLAttributes, useState } from 'react';
import {
StyledInputContainer,
StyledInput,
Expand All @@ -11,17 +11,13 @@ import EyeOpenIcon from '@/assets/icons/eye-open.svg';
import EyeCloseIcon from '@/assets/icons/eye-close.svg';
import { Tooltip } from '../tooltip';
import theme from '@/styles/palette';
interface InputProps {

interface InputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'onChange'> {
label?: string;
value: string;
onChange: (value: string) => void;
type?: string;
error?: string;
style?: React.CSSProperties;
placeholder?: string;
onKeyDown?: (e: React.KeyboardEvent<HTMLInputElement>) => void;
tooltip?: string;
required?: boolean;
}

export function Input({
Expand All @@ -31,10 +27,11 @@ export function Input({
type = 'text',
error = '',
style = {},
placeholder,
onKeyDown,
tooltip,
required,
autoComplete = "off",
...rest
}: InputProps): JSX.Element {
const [showPassword, setShowPassword] = useState<boolean>(false);

Expand Down Expand Up @@ -68,9 +65,9 @@ export function Input({
type={showPassword ? 'text' : type}
value={value}
onChange={handleChange}
autoComplete="off"
placeholder={placeholder}
autoComplete={autoComplete}
onKeyDown={onKeyDown}
{...rest}
/>
{type === 'password' && (
<DisplayIconsWrapper onClick={() => setShowPassword(!showPassword)}>
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"@/*": [
"./src/*"
]
},
"incremental": true
}
},
"include": [
"next-env.d.ts",
Expand Down

0 comments on commit 1b56ebf

Please sign in to comment.