TextArea.jsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. Copyright (C) 2017 Cloudbase Solutions SRL
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. // @flow
  15. import React from 'react'
  16. import { observer } from 'mobx-react'
  17. import styled from 'styled-components'
  18. import Palette from '../../styleUtils/Palette'
  19. import StyleProps from '../../styleUtils/StyleProps'
  20. const getInputWidth = props => {
  21. if (props.width) {
  22. return props.width
  23. }
  24. if (props.large) {
  25. return `${StyleProps.inputSizes.large.width}px`
  26. }
  27. return `${StyleProps.inputSizes.regular.width}px`
  28. }
  29. const Input = styled.textarea`
  30. width: ${props => getInputWidth(props)};
  31. height: ${props => props.height || `${StyleProps.inputSizes.regular.height * 2}px`};
  32. border-radius: ${StyleProps.borderRadius};
  33. background-color: #FFF;
  34. border: 1px solid ${props => props.highlight ? Palette.alert : Palette.grayscale[3]};
  35. color: ${Palette.black};
  36. padding: 8px;
  37. font-size: inherit;
  38. transition: all ${StyleProps.animations.swift};
  39. box-sizing: border-box;
  40. font-family: monospace;
  41. &:hover {
  42. border-color: ${props => props.highlight ? Palette.alert : Palette.primary};
  43. }
  44. &:focus {
  45. border-color: ${props => props.highlight ? Palette.alert : Palette.primary};
  46. outline: none;
  47. }
  48. &:disabled {
  49. color: ${Palette.grayscale[3]};
  50. border-color: ${Palette.grayscale[0]};
  51. background-color: ${Palette.grayscale[0]};
  52. }
  53. &::placeholder {
  54. color: ${Palette.grayscale[3]};
  55. }
  56. `
  57. @observer
  58. class TextArea extends React.Component<{}> {
  59. render() {
  60. return (
  61. <Input {...this.props} />
  62. )
  63. }
  64. }
  65. export default TextArea