Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. /*
  2. Обычный инпут, принимающий все стандартные html-атрибуты
  3. Может принимать props label - в качестве плавающего плейсхолдера
  4. Может принимать props error - для отображении подписи с ошибкой
  5.  
  6. todo: описать propTypes
  7. */
  8.  
  9. import * as React from 'react'
  10. import styled from 'styled-components'
  11. import { observable } from 'mobx'
  12. // import * as ReactDOM from 'react-dom'
  13.  
  14. import { BLUE, DARK_LINES, PLACEHOLDER } from '~/components/pru/ui-colors'
  15. import { IInputProps } from './StaticPlaceholderInput.d'
  16. import { CloseBtn } from '~/components/pru'
  17. import { MEDIA } from '~/constants/media-queries'
  18.  
  19. const Field = styled.div`
  20. position: relative;
  21. `
  22.  
  23. const Label = styled.label`
  24. display: block;
  25. width: 100%;
  26. position: absolute;
  27. top: 10px;
  28. left: 0;
  29. font-size: 18px;
  30. font-weight: 300;
  31. line-height: 1;
  32. color: rgba(48, 48, 48, 0.5);
  33. -webkit-user-select: none;
  34. -moz-user-select: none;
  35. -ms-user-select: none;
  36. user-select: none;
  37. pointer-events: none;
  38. transform-origin: 0 100%;
  39. transition: all 0.3s;
  40. `
  41.  
  42. const Underline = styled.div`
  43. position: absolute;
  44. right: 0;
  45. bottom: -1px;
  46. left: 0;
  47. height: 1px;
  48. background: ${DARK_LINES};
  49. transition: opacity 0.2s linear;
  50.  
  51. &::after {
  52. content: '';
  53. position: absolute;
  54. width: 100%;
  55. height: 100%;
  56. background: ${BLUE};
  57. transform: scaleX(0);
  58. transform-origin: 0 0;
  59. transition: all 0.4s;
  60. }
  61. `
  62.  
  63. const ResetInputBtn = styled(CloseBtn)`
  64. top: 15px;
  65. right: 8px;
  66. width: 16px;
  67. height: 16px;
  68. position: absolute;
  69. display: none;
  70.  
  71. &:hover {
  72. background-color: transparent;
  73. }
  74.  
  75. &::before,
  76. &::after {
  77. height: 1px;
  78. }
  79.  
  80. &:hover::before,
  81. &:hover::after {
  82. background-color: ${PLACEHOLDER};
  83. }
  84. `
  85.  
  86. const Input = styled.input`
  87. display: block;
  88. width: 100%;
  89. height: 100%;
  90. font-size: 18px;
  91. font-weight: 300;
  92. color: #000;
  93. border: 0;
  94. outline: 0;
  95. /* opacity: 0; */
  96. box-shadow: none;
  97. transition: opacity .4s linear;
  98. padding: 7px 0;
  99.  
  100. /* &:focus,
  101. &:valid {
  102. opacity: 1;
  103. } */
  104.  
  105. &:focus + ${Label},
  106. &:valid ~ ${Label} {
  107. transform: translateY(-140%) scale(.7);
  108. }
  109.  
  110. &:focus ~ ${Underline}::after,
  111. &:valid ~ ${Underline}::after {
  112. transform: scaleX(1);
  113. }
  114.  
  115. &:valid ~ ${ResetInputBtn} {
  116. display: block;
  117. }
  118.  
  119. &::-webkit-input-placeholder { color: ${PLACEHOLDER}; }
  120. &:-ms-input-placeholder { color: ${PLACEHOLDER}; }
  121. &::-ms-input-placeholder { color: ${PLACEHOLDER}; }
  122. &::placeholder { color: ${PLACEHOLDER}; }
  123.  
  124. @media ${MEDIA.untilTablet} {
  125. padding: 5px 0;
  126. }
  127. `
  128.  
  129. export default class InputSet extends React.Component<IInputProps> {
  130. @observable data = ''
  131. InputRef: any = null
  132.  
  133. constructor(props: React.Props<{}>) {
  134. super(props)
  135. this.handleResetInputClick = this.handleResetInputClick.bind(this)
  136. }
  137.  
  138. handleResetInputClick(event: any) {
  139. // console.log(event.target.getAttribute('data-input'))
  140. // this.refs.fieldName.value=""
  141. // console.log(this.refs.fieldName)
  142. // console.log(this.InputRef.props.value)
  143. this.InputRef.props.value = 'w'
  144. // const modal = ReactDOM.findDOMNode(this.inputEntry)
  145. // console.log(modal)
  146. // this.textInput.value =''
  147. // const actionElement = event.target.closest('input')
  148. // console.log(actionElement)
  149. // this[event.target.name] = event.target.value
  150. // this[event.target.name] = event.target.value
  151. }
  152.  
  153. render() {
  154. // const { label, error, ...inputAttributes } = this.props
  155. const { ...inputAttributes } = this.props
  156. // console.log(this.refs)
  157. // const textInput: any
  158. // console.log(this.InputRef)
  159.  
  160. return (
  161. <Field>
  162. <Input
  163. {...inputAttributes}
  164. required={true}
  165. ref={(ref: any) => {
  166. this.InputRef = ref
  167. }}
  168. />
  169. <ResetInputBtn
  170. onClick={this.handleResetInputClick}
  171. data-input={this.props.name}
  172. />
  173. <Underline />
  174. </Field>
  175. )
  176. }
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement