You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import type { CSSProperties } from 'react'
  2. import React from 'react'
  3. import { type VariantProps, cva } from 'class-variance-authority'
  4. import cn from '@/utils/classnames'
  5. const textareaVariants = cva(
  6. '',
  7. {
  8. variants: {
  9. size: {
  10. small: 'py-1 rounded-md system-xs-regular',
  11. regular: 'px-3 rounded-md system-sm-regular',
  12. large: 'px-4 rounded-lg system-md-regular',
  13. },
  14. },
  15. defaultVariants: {
  16. size: 'regular',
  17. },
  18. },
  19. )
  20. export type TextareaProps = {
  21. value: string
  22. disabled?: boolean
  23. destructive?: boolean
  24. styleCss?: CSSProperties
  25. ref?: React.Ref<HTMLTextAreaElement>
  26. } & React.TextareaHTMLAttributes<HTMLTextAreaElement> & VariantProps<typeof textareaVariants>
  27. const Textarea = ({ className, value, onChange, disabled, size, destructive, styleCss, ref, ...props }: TextareaProps) => {
  28. return (
  29. <textarea
  30. ref={ref}
  31. style={styleCss}
  32. className={cn(
  33. 'min-h-20 w-full appearance-none border border-transparent bg-components-input-bg-normal p-2 text-components-input-text-filled caret-primary-600 outline-none placeholder:text-components-input-text-placeholder hover:border-components-input-border-hover hover:bg-components-input-bg-hover focus:border-components-input-border-active focus:bg-components-input-bg-active focus:shadow-xs',
  34. textareaVariants({ size }),
  35. disabled && 'cursor-not-allowed border-transparent bg-components-input-bg-disabled text-components-input-text-filled-disabled hover:border-transparent hover:bg-components-input-bg-disabled',
  36. destructive && 'border-components-input-border-destructive bg-components-input-bg-destructive text-components-input-text-filled hover:border-components-input-border-destructive hover:bg-components-input-bg-destructive focus:border-components-input-border-destructive focus:bg-components-input-bg-destructive',
  37. className,
  38. )}
  39. value={value ?? ''}
  40. onChange={onChange}
  41. disabled={disabled}
  42. {...props}
  43. >
  44. </textarea>
  45. )
  46. }
  47. Textarea.displayName = 'Textarea'
  48. export default Textarea
  49. export { Textarea, textareaVariants }