Ringtone app
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

94 lignes
1.7 KiB

  1. import {ChangeEventHandler, CSSProperties, FC, FocusEventHandler, forwardRef, PropsWithoutRef} from 'react';
  2. import styled from 'styled-components'
  3. const Base = styled('div')({
  4. borderRadius: '0.25rem',
  5. overflow: 'hidden',
  6. position: 'relative',
  7. backgroundColor: 'var(--color-bg, white)',
  8. '::before': {
  9. content: "''",
  10. borderWidth: 1,
  11. borderStyle: 'solid',
  12. position: 'absolute',
  13. top: 0,
  14. left: 0,
  15. width: '100%',
  16. height: '100%',
  17. borderRadius: 'inherit',
  18. boxSizing: 'border-box',
  19. opacity: 0.5,
  20. },
  21. })
  22. const ClickArea = styled('label')({
  23. position: 'relative',
  24. height: '100%',
  25. })
  26. const Label = styled('span')({
  27. position: 'absolute',
  28. left: -999999,
  29. })
  30. const Input = styled('textarea')({
  31. display: 'block',
  32. width: '100%',
  33. minHeight: '3rem',
  34. margin: 0,
  35. padding: '1rem 1rem',
  36. boxSizing: 'border-box',
  37. font: 'inherit',
  38. border: 0,
  39. backgroundColor: 'transparent',
  40. color: 'inherit',
  41. outline: 0,
  42. })
  43. type Props = {
  44. label: string,
  45. name: string,
  46. className?: string,
  47. block?: boolean,
  48. placeholder?: string,
  49. defaultValue?: string | number | readonly string[],
  50. readOnly?: boolean,
  51. onChange?: ChangeEventHandler<HTMLTextAreaElement>,
  52. onBlur?: FocusEventHandler<HTMLTextAreaElement>,
  53. style?: CSSProperties,
  54. }
  55. const TextArea = forwardRef<HTMLTextAreaElement, PropsWithoutRef<Props>>(({
  56. label,
  57. className,
  58. block,
  59. style = {},
  60. ...etcProps
  61. }, ref) => {
  62. return (
  63. <Base
  64. className={className}
  65. style={{
  66. display: block ? 'block' : 'inline-block',
  67. width: block ? '100%' : undefined,
  68. }}
  69. >
  70. <ClickArea>
  71. <Label>
  72. {label}
  73. </Label>
  74. <Input
  75. {...etcProps}
  76. ref={ref}
  77. style={{
  78. ...style,
  79. resize: block ? 'vertical' : undefined,
  80. }}
  81. />
  82. </ClickArea>
  83. </Base>
  84. )
  85. })
  86. export default TextArea