index.tsx 2.1 KB

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