Skip to content

Commit ff24def

Browse files
committed
chore: update types, input variants
1 parent 0cb1e9f commit ff24def

File tree

13 files changed

+16884
-10443
lines changed

13 files changed

+16884
-10443
lines changed

apps/gitness/src/pages-v2/signin.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { FC } from 'react'
12
import { useNavigate } from 'react-router-dom'
23

34
import { getUser, useOnLoginMutation } from '@harnessio/code-service-client'
4-
import { SignInDataProps, SignInPage } from '@harnessio/ui/views'
5+
import { SignInData, SignInPage } from '@harnessio/ui/views'
56

67
import { useAppContext } from '../framework/context/AppContext'
78

8-
export const SignIn: React.FC = () => {
9+
export const SignIn: FC = () => {
910
const navigate = useNavigate()
1011
const { setCurrentUser } = useAppContext()
1112
const {
@@ -31,7 +32,7 @@ export const SignIn: React.FC = () => {
3132
return (
3233
<SignInPage
3334
isLoading={isLoading}
34-
handleSignIn={(data: SignInDataProps) => {
35+
handleSignIn={(data: SignInData) => {
3536
login({
3637
body: {
3738
login_identifier: data.email,

apps/gitness/src/pages-v2/signup.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useEffect } from 'react'
22
import { useNavigate } from 'react-router-dom'
33

44
import { useOnRegisterMutation } from '@harnessio/code-service-client'
5-
import { SignUpDataProps, SignUpPage } from '@harnessio/ui/views'
5+
import { SignUpData, SignUpPage } from '@harnessio/ui/views'
66

77
export const SignUp: React.FC = () => {
88
const navigate = useNavigate()
@@ -20,7 +20,7 @@ export const SignUp: React.FC = () => {
2020
}
2121
}, [isSuccess])
2222

23-
const handleSignUp = (data: SignUpDataProps) => {
23+
const handleSignUp = (data: SignUpData) => {
2424
register({
2525
body: {
2626
email: data.email,

packages/ui/src/components/card.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react'
1+
import { forwardRef, HTMLAttributes } from 'react'
22

33
import { cn } from '@utils/cn'
44
import { cva, type VariantProps } from 'class-variance-authority'
@@ -15,7 +15,7 @@ const cardVariants = cva('rounded-lg border bg-card text-card-foreground shadow'
1515
}
1616
})
1717

18-
export interface CardProps extends React.HTMLAttributes<HTMLDivElement>, VariantProps<typeof cardVariants> {
18+
export interface CardProps extends HTMLAttributes<HTMLDivElement>, VariantProps<typeof cardVariants> {
1919
width?: 'auto' | 'full' | 'screen' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | string
2020
}
2121

@@ -32,47 +32,47 @@ const widthClasses = {
3232
'2xl': 'w-96'
3333
}
3434

35-
const Card = React.forwardRef<HTMLDivElement, CardProps>(({ variant, className, width = 'auto', ...props }, ref) => {
35+
const Card = forwardRef<HTMLDivElement, CardProps>(({ variant, className, width = 'auto', ...props }, ref) => {
3636
const widthClass = widthClasses[width as keyof typeof widthClasses] || width
3737

3838
return <div ref={ref} className={cn(cardVariants({ variant }), widthClass, className)} {...props} />
3939
})
4040

4141
Card.displayName = 'Card'
4242

43-
const CardHeader = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
43+
const CardHeader = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(
4444
({ className = 'space-y-1.5 p-6', ...props }, ref) => (
4545
<div ref={ref} className={cn('flex flex-col', className)} {...props} />
4646
)
4747
)
4848
CardHeader.displayName = 'CardHeader'
4949

50-
interface CardTitleProps extends React.HTMLAttributes<HTMLHeadingElement> {
50+
interface CardTitleProps extends HTMLAttributes<HTMLHeadingElement> {
5151
as?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'
5252
}
5353

54-
const CardTitle = React.forwardRef<HTMLHeadingElement, CardTitleProps>(
54+
const CardTitle = forwardRef<HTMLHeadingElement, CardTitleProps>(
5555
({ className, children, as: Tag = 'h3', ...props }, ref) => (
56-
<Tag ref={ref} className={cn('font-medium leading-snug tracking-tight', className)} {...props}>
56+
<Tag ref={ref} className={cn('font-medium text-24 leading-snug tracking-tighter', className)} {...props}>
5757
{children}
5858
</Tag>
5959
)
6060
)
6161
CardTitle.displayName = 'CardTitle'
6262

63-
const CardDescription = React.forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLParagraphElement>>(
63+
const CardDescription = forwardRef<HTMLParagraphElement, HTMLAttributes<HTMLParagraphElement>>(
6464
({ className, ...props }, ref) => (
6565
<p ref={ref} className={cn('text-muted-foreground text-sm', className)} {...props} />
6666
)
6767
)
6868
CardDescription.displayName = 'CardDescription'
6969

70-
const CardContent = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
70+
const CardContent = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(
7171
({ className = 'p-6', ...props }, ref) => <div ref={ref} className={cn('pt-0', className)} {...props} />
7272
)
7373
CardContent.displayName = 'CardContent'
7474

75-
const CardFooter = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
75+
const CardFooter = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(
7676
({ className = 'p-6', ...props }, ref) => (
7777
<div ref={ref} className={cn('flex items-center pt-0', className)} {...props} />
7878
)

packages/ui/src/components/input-otp.tsx

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import * as React from 'react'
1+
import { ComponentPropsWithoutRef, ElementRef, forwardRef, useContext } from 'react'
22

33
import { DashIcon } from '@radix-ui/react-icons'
44
import { OTPInput, OTPInputContext } from 'input-otp'
55

66
import { cn } from '../utils/cn'
77

8-
const InputOTP = React.forwardRef<React.ElementRef<typeof OTPInput>, React.ComponentPropsWithoutRef<typeof OTPInput>>(
8+
const InputOTP = forwardRef<ElementRef<typeof OTPInput>, ComponentPropsWithoutRef<typeof OTPInput>>(
99
({ className, containerClassName, ...props }, ref) => (
1010
<OTPInput
1111
ref={ref}
@@ -17,17 +17,17 @@ const InputOTP = React.forwardRef<React.ElementRef<typeof OTPInput>, React.Compo
1717
)
1818
InputOTP.displayName = 'InputOTP'
1919

20-
const InputOTPGroup = React.forwardRef<React.ElementRef<'div'>, React.ComponentPropsWithoutRef<'div'>>(
21-
({ className, ...props }, ref) => <div ref={ref} className={cn('flex items-center', className)} {...props} />
22-
)
20+
const InputOTPGroup = forwardRef<ElementRef<'div'>, ComponentPropsWithoutRef<'div'>>(({ className, ...props }, ref) => (
21+
<div ref={ref} className={cn('flex items-center', className)} {...props} />
22+
))
2323
InputOTPGroup.displayName = 'InputOTPGroup'
2424

25-
interface InputOTPSlotProps extends React.ComponentPropsWithoutRef<'div'> {
25+
interface InputOTPSlotProps extends ComponentPropsWithoutRef<'div'> {
2626
index: number
2727
}
2828

29-
const InputOTPSlot = React.forwardRef<HTMLDivElement, InputOTPSlotProps>(({ index, className, ...props }, ref) => {
30-
const inputOTPContext = React.useContext(OTPInputContext)
29+
const InputOTPSlot = forwardRef<HTMLDivElement, InputOTPSlotProps>(({ index, className, ...props }, ref) => {
30+
const inputOTPContext = useContext(OTPInputContext)
3131

3232
if (!inputOTPContext?.slots?.[index]) {
3333
console.error(`No slot data available for index ${index}`)
@@ -57,13 +57,11 @@ const InputOTPSlot = React.forwardRef<HTMLDivElement, InputOTPSlotProps>(({ inde
5757
})
5858
InputOTPSlot.displayName = 'InputOTPSlot'
5959

60-
const InputOTPSeparator = React.forwardRef<React.ElementRef<'div'>, React.ComponentPropsWithoutRef<'div'>>(
61-
({ ...props }, ref) => (
62-
<div ref={ref} role="separator" {...props}>
63-
<DashIcon />
64-
</div>
65-
)
66-
)
60+
const InputOTPSeparator = forwardRef<ElementRef<'div'>, ComponentPropsWithoutRef<'div'>>(({ ...props }, ref) => (
61+
<div ref={ref} role="separator" {...props}>
62+
<DashIcon />
63+
</div>
64+
))
6765
InputOTPSeparator.displayName = 'InputOTPSeparator'
6866

6967
export { InputOTP, InputOTPGroup, InputOTPSlot, InputOTPSeparator }

packages/ui/src/components/input.tsx

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,51 @@
1-
import * as React from 'react'
1+
import { forwardRef, InputHTMLAttributes } from 'react'
2+
3+
import { cva, VariantProps } from 'class-variance-authority'
24

35
import { cn } from '../utils/cn'
46
import { Text } from './'
57

6-
export interface BaseInputProps extends React.InputHTMLAttributes<HTMLInputElement> {
7-
isExtended?: boolean
8-
error?: string
8+
export interface BaseInputProps
9+
extends Omit<InputHTMLAttributes<HTMLInputElement>, 'size'>,
10+
VariantProps<typeof inputVariants> {
911
wrapperClassName?: string
12+
error?: string
1013
}
1114

12-
const BaseInput = React.forwardRef<HTMLInputElement, BaseInputProps>(
13-
({ className, type, isExtended, error, wrapperClassName, ...props }, ref) => {
14-
const commonClassName =
15-
'remove-autocomplete-styles bg-transparent placeholder:text-foreground-5 text-foreground-1 px-3 py-1'
16-
const specificClassNames = isExtended
17-
? 'border-none grow focus-visible:outline-none'
18-
: cn(
15+
const inputVariants = cva(
16+
'remove-autocomplete-styles bg-transparent placeholder:text-foreground-5 text-foreground-1 px-3 py-1',
17+
{
18+
variants: {
19+
variant: {
20+
default:
1921
'flex h-9 w-full rounded border text-sm shadow-sm transition-colors file:border-0 focus-visible:outline-none file:bg-transparent file:text-sm file:font-medium placeholder:text-foreground-4 disabled:cursor-not-allowed disabled:opacity-50',
20-
error ? 'border-borders-danger' : 'border-borders-2 focus-visible:border-borders-3'
21-
)
22+
extended: 'grow border-none focus-visible:outline-none'
23+
},
24+
theme: {
25+
default: 'border-borders-2 focus-visible:border-borders-3',
26+
danger: 'border-borders-danger'
27+
}
28+
}
29+
}
30+
)
2231

32+
const BaseInput = forwardRef<HTMLInputElement, BaseInputProps>(
33+
({ className, type, variant = 'default', theme = 'default', error, wrapperClassName, ...props }, ref) => {
2334
return (
2435
<div className={cn('relative flex flex-col', wrapperClassName)}>
25-
<input className={cn(commonClassName, specificClassNames, className)} type={type} ref={ref} {...props} />
36+
<input
37+
className={cn(
38+
inputVariants({ variant, theme }),
39+
className,
40+
error ? 'border-borders-danger' : 'border-borders-2'
41+
)}
42+
type={type}
43+
ref={ref}
44+
{...props}
45+
/>
2646
{error && (
2747
<Text
28-
className="absolute top-full translate-y-1 leading-none tracking-tight text-foreground-danger"
48+
className="absolute top-full translate-y-1 text-foreground-danger leading-none tracking-tight"
2949
weight="light"
3050
size={0}
3151
>
@@ -51,7 +71,7 @@ const containerClassName =
5171
'remove-autocomplete-styles flex h-9 w-full rounded border border-input text-sm shadow-sm transition-colors placeholder:text-foreground-4 focus-within:outline-none focus-within:ring-1 focus-within:ring-ring disabled:cursor-not-allowed disabled:opacity-50'
5272
const leftRightCommonClassName = 'flex items-center text-muted-foreground'
5373

54-
const ExtendedInput = React.forwardRef<HTMLInputElement, ExtendedInputProps>(
74+
const ExtendedInput = forwardRef<HTMLInputElement, ExtendedInputProps>(
5575
({ className, type, left, leftStyle, leftClassName, right, rightStyle, rightClassName, ...props }, ref) => {
5676
return (
5777
<div className={cn(containerClassName, className)}>
@@ -67,7 +87,7 @@ const ExtendedInput = React.forwardRef<HTMLInputElement, ExtendedInputProps>(
6787
{left}
6888
</div>
6989
)}
70-
<BaseInput className={className} type={type} {...props} ref={ref} isExtended={true} />
90+
<BaseInput className={className} type={type} {...props} ref={ref} variant="extended" />
7191
{right && (
7292
<div
7393
className={cn(
@@ -86,9 +106,9 @@ const ExtendedInput = React.forwardRef<HTMLInputElement, ExtendedInputProps>(
86106
)
87107
ExtendedInput.displayName = 'ExtendedInput'
88108

89-
interface InputProps extends Omit<BaseInputProps, 'isExtended'>, ExtendedInputProps {}
109+
interface InputProps extends ExtendedInputProps {}
90110

91-
const Input = React.forwardRef<HTMLInputElement, InputProps>(({ left, right, ...props }, ref) => {
111+
const Input = forwardRef<HTMLInputElement, InputProps>(({ left, right, ...props }, ref) => {
92112
if (left || right) {
93113
return <ExtendedInput left={left} right={right} {...props} ref={ref} />
94114
}

packages/ui/src/components/label.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ToDo: Need to be reviewed by the XD team
22

3-
import * as React from 'react'
3+
import { ComponentPropsWithoutRef, ElementRef, forwardRef } from 'react'
44

55
import * as LabelPrimitive from '@radix-ui/react-label'
66
import { cn } from '@utils/cn'
@@ -18,9 +18,9 @@ const labelVariants = cva('block leading-none peer-disabled:cursor-not-allowed p
1818
}
1919
})
2020

21-
const Label = React.forwardRef<
22-
React.ElementRef<typeof LabelPrimitive.Root>,
23-
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> & VariantProps<typeof labelVariants>
21+
const Label = forwardRef<
22+
ElementRef<typeof LabelPrimitive.Root>,
23+
ComponentPropsWithoutRef<typeof LabelPrimitive.Root> & VariantProps<typeof labelVariants>
2424
>(({ className, variant, ...props }, ref) => (
2525
<LabelPrimitive.Root
2626
ref={ref}

packages/ui/src/views/auth/forgot-password-page.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ import { Button, Card, CardContent, CardHeader, CardTitle, Input, Label, Spacer,
1010
import { Agreements } from './components/agreements'
1111
import { AnimatedHarnessLogo } from './components/animated-harness-logo'
1212

13-
interface PageProps {
13+
interface ForgotPasswordPageProps {
1414
isLoading?: boolean
15-
onSubmit?: (emailData: ForgotPasswordDataProps) => void
15+
onSubmit?: (emailData: ForgotPasswordData) => void
1616
error?: string
1717
}
1818

19-
export interface ForgotPasswordDataProps {
19+
export interface ForgotPasswordData {
2020
email?: string
2121
}
2222

2323
const forgotPasswordSchema = z.object({
2424
email: z.string().email({ message: 'Invalid email address' })
2525
})
2626

27-
export function ForgotPasswordPage({ isLoading, onSubmit, error }: PageProps) {
27+
export function ForgotPasswordPage({ isLoading, onSubmit, error }: ForgotPasswordPageProps) {
2828
const [serverError, setServerError] = useState<string | null>(null)
2929
const {
3030
register,
@@ -37,7 +37,7 @@ export function ForgotPasswordPage({ isLoading, onSubmit, error }: PageProps) {
3737
resolver: zodResolver(forgotPasswordSchema)
3838
})
3939

40-
const handleOnSubmit: SubmitHandler<ForgotPasswordDataProps> = data => {
40+
const handleOnSubmit: SubmitHandler<ForgotPasswordData> = data => {
4141
// Handle the submission of the forgot password form
4242
if (onSubmit) {
4343
onSubmit(data)
@@ -76,10 +76,10 @@ export function ForgotPasswordPage({ isLoading, onSubmit, error }: PageProps) {
7676
<Card className="relative z-10 mb-8 max-w-full" variant="plain" width="xl">
7777
<CardHeader className="items-center">
7878
<AnimatedHarnessLogo theme={hasError ? 'error' : 'blue'} />
79-
<CardTitle className="mt-3 text-center text-2xl" as="h1">
79+
<CardTitle className="mt-3 text-center" as="h1">
8080
Forgot password?
8181
</CardTitle>
82-
<Text className="mt-0.5" size={2} color="foreground-4" align="center" as="p">
82+
<Text className="mt-0.5 leading-snug" size={2} color="foreground-4" align="center" as="p">
8383
Enter your email to receive the verification code.
8484
</Text>
8585
</CardHeader>

packages/ui/src/views/auth/new-password-page.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import { Button, Card, CardContent, CardHeader, CardTitle, Input, Label, Text }
99
import { Agreements } from './components/agreements'
1010
import { AnimatedHarnessLogo } from './components/animated-harness-logo'
1111

12-
interface PageProps {
12+
interface NewPasswordPageProps {
1313
isLoading?: boolean
14-
handleFormSubmit?: (data: NewPasswordDataProps) => void
14+
handleFormSubmit?: (data: NewPasswordData) => void
1515
error?: string
1616
}
1717

18-
export interface NewPasswordDataProps {
18+
export interface NewPasswordData {
1919
password?: string
2020
confirmPassword?: string
2121
}
@@ -30,7 +30,7 @@ const newPasswordSchema = z
3030
path: ['confirmPassword']
3131
})
3232

33-
export function NewPasswordPage({ isLoading, handleFormSubmit, error }: PageProps) {
33+
export function NewPasswordPage({ isLoading, handleFormSubmit, error }: NewPasswordPageProps) {
3434
const [serverError, setServerError] = useState<string | null>(null)
3535
const {
3636
register,
@@ -43,7 +43,7 @@ export function NewPasswordPage({ isLoading, handleFormSubmit, error }: PageProp
4343
resolver: zodResolver(newPasswordSchema)
4444
})
4545

46-
const onFormSubmit = (data: NewPasswordDataProps) => {
46+
const onFormSubmit = (data: NewPasswordData) => {
4747
handleFormSubmit?.(data)
4848
}
4949

@@ -83,10 +83,10 @@ export function NewPasswordPage({ isLoading, handleFormSubmit, error }: PageProp
8383
<Card className="relative z-10 mb-8 max-w-full" variant="plain" width="xl">
8484
<CardHeader className="items-center">
8585
<AnimatedHarnessLogo theme={hasError ? 'error' : 'blue'} />
86-
<CardTitle className="mt-3 text-center text-2xl" as="h1">
86+
<CardTitle className="mt-3 text-center" as="h1">
8787
Create new password
8888
</CardTitle>
89-
<Text className="mt-0.5" size={2} color="foreground-4" align="center" as="p">
89+
<Text className="mt-0.5 leading-snug" size={2} color="foreground-4" align="center" as="p">
9090
Your new password must be different from your previously used password.
9191
</Text>
9292
</CardHeader>

0 commit comments

Comments
 (0)