Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.94 KB | None | 0 0
  1. import * as classNames from 'classnames';
  2. import * as React from 'react';
  3. import Select from 'react-select';
  4. // import '../../../../scss/form/v1/select/cmx-select.component.scss';
  5. // import { Input as SelectInput } from 'react-select/lib/components/Input';
  6. import { InputProps } from '../types/InputProps';
  7.  
  8. export interface Option {
  9. label: string;
  10. value: string;
  11. }
  12.  
  13. export interface OwnProps {
  14. autoComplete?: string;
  15. defaultValue?: string;
  16. disabled?: boolean;
  17. testId?: string;
  18. multi?: boolean;
  19. multiFirst?: boolean;
  20. multiLast?: boolean;
  21. options?: Option[];
  22. placeholder?: any;
  23. required?: boolean;
  24. searchable?: boolean;
  25. }
  26.  
  27. class Dropdown extends React.Component<OwnProps & InputProps, {}> {
  28. render() {
  29. const {
  30. // autoComplete,
  31. defaultValue,
  32. disabled,
  33. error,
  34. multi,
  35. multiFirst,
  36. multiLast,
  37. name,
  38. onBlur,
  39. onChange,
  40. onFocus,
  41. options,
  42. placeholder,
  43. searchable = true,
  44. testId,
  45. value,
  46. } = this.props;
  47.  
  48. return (
  49. <div data-tid={testId}>
  50. <Select
  51. className={classNames(error && 'error', multi && multiFirst && 'multiFirst', multi && multiLast && 'multiLast')}
  52. isClearable={false}
  53. styles={{
  54. control: (styles, { isFocused }) => ({
  55. ...styles,
  56. cursor: 'pointer',
  57. backgroundColor: 'white',
  58. ...(isFocused
  59. ? {
  60. border: '1px solid #3FA9F5',
  61. boxShadow: 'none',
  62. }
  63. : {}),
  64. }),
  65. option: (styles, { data, isDisabled, isFocused, isSelected }) => ({
  66. ...styles,
  67. padding: '10px 16px',
  68. ...(isSelected
  69. ? {
  70. background: 'none',
  71. color: '#3FA9F5',
  72. }
  73. : {}),
  74. ...(isFocused
  75. ? {
  76. backgroundColor: '#F4F6F9',
  77. }
  78. : {}),
  79. ':hover': {
  80. backgroundColor: '#F4F6F9',
  81. },
  82. }),
  83. indicatorSeparator: () => ({
  84. display: 'none',
  85. }),
  86. menuList: (styles) => ({
  87. ...styles,
  88. padding: 0,
  89. borderTop: '3px solid #3FA9F5',
  90. background: '#fff',
  91. borderRadius: '3px',
  92. boxShadow: '0 8px 13px rgba(0,0,0,0.3)',
  93. // ':hover': {
  94. // background: 'none',
  95. // },
  96. }),
  97. dropdownIndicator: (styles, { isHover }) => ({
  98. ...styles,
  99. color: 'white',
  100. backgroundImage: 'url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCI+PHBhdGggZmlsbD0iIzNmYTlmNSIgZD0iTTIgOS4yNmwuNzEtLjcyLjcyLS43MSA0LjI4IDMuNTdMMTIgMTVsNC4yOS0zLjU3IDQuMjgtMy41Ny43Mi43MS43MS43Mi01IDQuMjgtNSA0LjI5LTUtNC4zMnoiLz48L3N2Zz4=")',
  101. backgroundRepeat: 'no-repeat',
  102. backgroundPosition: 'calc(100% - 8px) center',
  103. backgroundSize: '16px 16px',
  104. width: '38px',
  105. height: '38px',
  106. '> svg': {
  107. display: 'none',
  108. },
  109. }),
  110. input: (styles) => ({
  111. ...styles,
  112. }),
  113. placeholder: (styles) => ({ ...styles }),
  114. singleValue: (styles, { data }) => ({
  115. ...styles,
  116. color: '#6e7d87',
  117. }),
  118. }}
  119. theme={{
  120. borderRadius: 3,
  121. colors: {
  122. primary: 'rgba(7,182,244)',
  123. primary75: 'rgba(7,182,244,.75)',
  124. primary50: 'rgba(7,182,244,.5)',
  125. primary25: 'rgba(7,182,244,.25)',
  126. danger: '#DE350B',
  127. dangerLight: '#FFBDAD',
  128. neutral0: 'hsl(0, 0%, 100%)',
  129. neutral5: 'hsl(0, 0%, 95%)',
  130. neutral10: 'hsl(0, 0%, 90%)',
  131. neutral20: 'hsl(0, 0%, 80%)',
  132. neutral30: 'hsl(0, 0%, 70%)',
  133. neutral40: 'hsl(0, 0%, 60%)',
  134. neutral50: 'hsl(0, 0%, 50%)',
  135. neutral60: 'hsl(0, 0%, 40%)',
  136. neutral70: 'hsl(0, 0%, 30%)',
  137. neutral80: 'hsl(0, 0%, 20%)',
  138. neutral90: 'hsl(0, 0%, 10%)',
  139. },
  140. spacing: {
  141. baseUnit: 4,
  142. controlHeight: 40,
  143. menuGutter: 0,
  144. },
  145. }}
  146. // inputProps={{ autoComplete }}
  147. name={name}
  148. onBlur={onBlur}
  149. onChange={onChange}
  150. onFocus={onFocus}
  151. options={options || []}
  152. placeholder={placeholder}
  153. isDisabled={disabled}
  154. value={defaultValue || value}
  155. isSearchable={searchable}
  156. // components={{
  157. // Input: (props) => (<SelectInput {...props} autoComplete={autoComplete} />)
  158. // }}
  159. />
  160. </div>
  161. );
  162. }
  163. }
  164.  
  165. export default Dropdown;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement