forked from harness/canary
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e786e2
commit 881d78e
Showing
15 changed files
with
279 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { HTMLAttributes } from 'react' | ||
|
||
import { cn } from '@utils/cn' | ||
|
||
interface ControlGroupProps extends HTMLAttributes<HTMLDivElement> { | ||
type?: 'button' | 'input' | ||
} | ||
|
||
export function ControlGroup({ children, type, className, ...props }: ControlGroupProps) { | ||
return ( | ||
<div | ||
className={cn('relative flex flex-col', { 'mt-2': type === 'button' }, className)} | ||
role="group" | ||
aria-label={type === 'button' ? 'Button control group' : 'Input control group'} | ||
{...props} | ||
> | ||
{children} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { HTMLAttributes } from 'react' | ||
|
||
import { cn } from '@utils/cn' | ||
|
||
import { Text } from './text' | ||
|
||
export enum ErrorMessageTheme { | ||
SUCCESS = 'success', | ||
WARNING = 'warning', | ||
ERROR = 'error', | ||
DEFAULT = 'default' | ||
} | ||
|
||
interface FormErrorMessageProps extends HTMLAttributes<HTMLDivElement> { | ||
theme: ErrorMessageTheme | ||
} | ||
|
||
const themeClassMap: Record<ErrorMessageTheme, string> = { | ||
[ErrorMessageTheme.SUCCESS]: 'text-success', | ||
[ErrorMessageTheme.WARNING]: 'text-warning', | ||
[ErrorMessageTheme.ERROR]: 'text-foreground-danger', | ||
[ErrorMessageTheme.DEFAULT]: 'text-tertiary-background' | ||
} | ||
|
||
export function FormErrorMessage({ children, theme, className }: FormErrorMessageProps) { | ||
const textClass = themeClassMap[theme] | ||
const role = theme === ErrorMessageTheme.ERROR ? 'alert' : 'status' | ||
const ariaLive = theme === ErrorMessageTheme.ERROR ? 'assertive' : 'polite' | ||
|
||
return ( | ||
<div className={cn(textClass, className)} role={role} aria-live={ariaLive}> | ||
<Text as="p" size={2} className="text-inherit"> | ||
{children} | ||
</Text> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,49 @@ | ||
// ToDo: Need to be reviewed by the XD team | ||
|
||
import { ComponentPropsWithoutRef, ElementRef, forwardRef } from 'react' | ||
import { ComponentPropsWithoutRef, ElementRef, forwardRef, PropsWithChildren } from 'react' | ||
|
||
import * as LabelPrimitive from '@radix-ui/react-label' | ||
import { cn } from '@utils/cn' | ||
import { cva, type VariantProps } from 'class-variance-authority' | ||
|
||
const labelVariants = cva('block leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70', { | ||
const labelVariants = cva('peer-disabled:cursor-not-allowed peer-disabled:opacity-70', { | ||
variants: { | ||
variant: { | ||
default: 'text-sm leading-none', | ||
sm: 'text-xs font-light' | ||
default: 'text-sm font-normal leading-none' | ||
}, | ||
color: { | ||
'foreground-1': 'text-foreground-1', | ||
'foreground-2': 'text-foreground-2', | ||
'foreground-5': 'text-foreground-5', | ||
'foreground-9': 'text-foreground-9' | ||
} | ||
}, | ||
defaultVariants: { | ||
variant: 'default' | ||
variant: 'default', | ||
color: 'foreground-1' | ||
} | ||
}) | ||
|
||
const Label = forwardRef< | ||
const LabelRoot = forwardRef< | ||
ElementRef<typeof LabelPrimitive.Root>, | ||
ComponentPropsWithoutRef<typeof LabelPrimitive.Root> & VariantProps<typeof labelVariants> | ||
>(({ className, variant, ...props }, ref) => ( | ||
<LabelPrimitive.Root | ||
ref={ref} | ||
className={cn('text-foreground-2', labelVariants({ variant }), className)} | ||
{...props} | ||
/> | ||
Omit<ComponentPropsWithoutRef<typeof LabelPrimitive.Root>, 'color'> & VariantProps<typeof labelVariants> | ||
>(({ className, variant, color, ...props }, ref) => ( | ||
<LabelPrimitive.Root ref={ref} className={cn(labelVariants({ variant, color }), className)} {...props} /> | ||
)) | ||
Label.displayName = LabelPrimitive.Root.displayName | ||
LabelRoot.displayName = LabelPrimitive.Root.displayName | ||
|
||
interface LabelProps extends VariantProps<typeof labelVariants>, PropsWithChildren { | ||
htmlFor?: string | ||
optional?: boolean | ||
className?: string | ||
} | ||
|
||
const Label = ({ htmlFor, optional, color, variant, children, className }: LabelProps) => { | ||
return ( | ||
<LabelRoot htmlFor={htmlFor} variant={variant} color={color} className={className}> | ||
{children} {optional && <span className="text-foreground-7 align-top">(optional)</span>} | ||
</LabelRoot> | ||
) | ||
} | ||
|
||
export { Label } |
Oops, something went wrong.