RadioInput.jsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. import checkedImage from './images/checked.svg'
  21. const Wrapper = styled.div`
  22. ${props => props.disabled ? 'opacity: 0.5;' : ''}
  23. ${props => props.disabledLoading ? StyleProps.animations.disabledLoading : ''}
  24. `
  25. const LabelStyled = styled.label`
  26. display: flex;
  27. `
  28. const Text = styled.div`
  29. margin-left: 16px;
  30. `
  31. const InputStyled = styled.input`
  32. width: 16px;
  33. height: 16px;
  34. border: 1px solid ${Palette.grayscale[3]};
  35. border-radius: 50%;
  36. background: white;
  37. appearance: none;
  38. outline: 0;
  39. transition: all ${StyleProps.animations.swift};
  40. position: relative;
  41. margin: 0;
  42. cursor: pointer;
  43. &:checked {
  44. background: url('${checkedImage}') center no-repeat;
  45. border-color: transparent;
  46. }
  47. `
  48. type Props = {
  49. label: string,
  50. disabledLoading?: boolean,
  51. disabled?: boolean,
  52. }
  53. @observer
  54. class RadioInput extends React.Component<Props> {
  55. render() {
  56. let disabled = this.props.disabled || this.props.disabledLoading
  57. return (
  58. <Wrapper {...this.props} disabled={disabled} disabledLoading={this.props.disabledLoading}>
  59. <LabelStyled>
  60. <InputStyled type="radio" {...this.props} disabled={disabled} data-test-id="radioInput-input" />
  61. <Text data-test-id="radioInput-label">{this.props.label}</Text>
  62. </LabelStyled>
  63. </Wrapper>
  64. )
  65. }
  66. }
  67. export default RadioInput