Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.77 KB | None | 0 0
  1. "use strict";
  2.  
  3. import React from 'react';
  4. import Slider from 'rc-slider';
  5. import styled from 'styled-components';
  6. import 'rc-slider/assets/index.css';
  7.  
  8. import FilterSection from './FilterSection';
  9.  
  10. const Range = Slider.createSliderWithTooltip(Slider.Range);
  11.  
  12. const contributionsMarks = {
  13. '0': '0',
  14. 50: {
  15. style: {
  16. color: 'gray',
  17. },
  18. label: <strong>50</strong>,
  19. },
  20. };
  21.  
  22. const ratingMarks = {
  23. '0': '0',
  24. 5: {
  25. style: {
  26. color: 'gray',
  27. },
  28. label: <strong>5</strong>,
  29. },
  30. };
  31.  
  32. const teamSizeMarks = {
  33. '2': '2',
  34. 20: {
  35. style: {
  36. color: 'gray',
  37. },
  38. label: <strong>20</strong>,
  39. },
  40. };
  41.  
  42. const LeftDrawerWrapper = styled.div`
  43. box-sizing: border-box;
  44. display: block;
  45. border-bottom: 1px solid #ccc;
  46. border-right: 1px solid #ccc;
  47. background-color: white;
  48. color: black;
  49. border-top: 1px solid #ccc;
  50. -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  51. @media (min-width: 768px) {
  52. display:inline-block;
  53. float: left;
  54. width: 230px;
  55. border-top: 0;
  56. border-bottom: 0;
  57. }
  58. `;
  59.  
  60. const Filter = styled.div`
  61. & > button {
  62. border: 1px solid #ccc;
  63. border-radius: 4px;
  64. margin: 5px 10px;
  65. padding: 10px 15px;
  66. display: inline-block;
  67. font-size: 16px;
  68. background: transparent;
  69. color: gray;
  70.  
  71. & > i {
  72. margin-left: 15px;
  73. }
  74. }
  75.  
  76. @media (min-width: 768px) {
  77. display: none;
  78. }
  79. `;
  80.  
  81. const FiltersWrapper = styled.div`
  82. display: block;
  83.  
  84. @media (max-width: 768px) {
  85. display: ${props => props.visible ? 'block' : 'none'};
  86. }
  87. `;
  88.  
  89. const CheckboxFilter = styled.div`
  90. position: relative;
  91. padding: 20px 0 20px 32px;
  92. text-align: left;
  93. label {
  94. cursor: pointer;
  95. &:before,
  96. &:after {
  97. content: '';
  98. position: absolute;
  99. }
  100. &:before {
  101. top: 33px;
  102. left: 0;
  103. width: 20px;
  104. height: 20px;
  105. margin: -15px 0 0;
  106. border: 1px solid #ccc;
  107. border-radius: 0;
  108. }
  109. &:after {
  110. top: 31px;
  111. left: 3px;
  112. width: 16px;
  113. height: 16px;
  114. margin: -10px 0 0;
  115. opacity: 0;
  116. background: #195B8B;
  117. transition: opacity 0.25s ease-in-out;
  118. }
  119. }
  120. input[type="checkbox"] {
  121. position: absolute;
  122. top: 0;
  123. left: -9999px;
  124. visibility: hidden;
  125.  
  126. &:checked + label {
  127. &:before {
  128. }
  129. &:after {
  130. opacity: 1;
  131. }
  132. }
  133. }
  134. `;
  135.  
  136. const RangeWrapper = styled.div`
  137. padding-right: 20px;
  138.  
  139. .rc-slider-rail {
  140. background-color: #ccc;
  141. }
  142.  
  143. .rc-slider-track {
  144. background-color: #195B8B;
  145. }
  146.  
  147. .rc-slider-handle {
  148. border-color: #195B8B;
  149. border-width: 3px;
  150. }
  151.  
  152. .rc-slider-tooltip {
  153. color: red;
  154. }
  155.  
  156. .rc-slider-mark {
  157. position: inherit;
  158. top: 0;
  159. left: 0;
  160. padding: 0;
  161. .rc-slider-mark-text {
  162. left: 0 !important;
  163. top: 10px;
  164. color: gray;
  165. &:nth-child(2) {
  166. left: 100% !important;
  167. }
  168. }
  169. }
  170. `;
  171.  
  172. export default class LeftDrawer extends React.Component {
  173.  
  174. constructor(props) {
  175. super(props);
  176.  
  177. this.state = {
  178. isOpen: false,
  179. filters: this.props.filters
  180. };
  181.  
  182. this.handleFiltering = this.props.handleFiltering;
  183.  
  184. this.toggleDropdown = this.toggleDropdown.bind(this);
  185. this.handleRangeFilter = this.handleRangeFilter.bind(this);
  186. this.handleCheckboxFilter = this.handleCheckboxFilter.bind(this);
  187. }
  188.  
  189. toggleDropdown() {
  190. this.setState({isOpen: !this.state.isOpen});
  191. }
  192.  
  193. filterFrameworks(newFilters) {
  194. this.setState({filters: newFilters});
  195. this.handleFiltering(this.state.filters);
  196. }
  197.  
  198. handleRangeFilter(event, name) {
  199. const newFilters = this.state.filters;
  200. newFilters[name].from = event[0];
  201. newFilters[name].to = event[1];
  202. this.filterFrameworks(newFilters);
  203. }
  204.  
  205. handleCheckboxFilter(event, name) {
  206. const newFilters = this.state.filters;
  207. newFilters[name] = event.target.checked;
  208. this.filterFrameworks(newFilters);
  209. }
  210.  
  211. handleScopeLevelFilter(event, name) {
  212. const newFilters = this.state.filters;
  213.  
  214. if (event.target.checked) {
  215. if (this.state.filters.scopeLevel.indexOf(name) === -1)
  216. newFilters.scopeLevel.push(name);
  217. } else {
  218. newFilters.scopeLevel = newFilters.scopeLevel.filter(item => item !== name);
  219. }
  220.  
  221. this.filterFrameworks(newFilters);
  222. }
  223.  
  224. render() {
  225. return (
  226. <LeftDrawerWrapper>
  227. <Filter>
  228. <button onClick={this.toggleDropdown}>
  229. Filter <i className="fa fa-sliders"/>
  230. </button>
  231. </Filter>
  232. <FiltersWrapper visible={this.state.isOpen}>
  233. <FilterSection sectionName="Scope Level">
  234. <CheckboxFilter>
  235. <input type="checkbox" id="checkbox-enterprise"
  236. onChange={event => this.handleScopeLevelFilter(event, 'Enterprise')}/>
  237. <label htmlFor="checkbox-enterprise"> Enterprise</label>
  238. </CheckboxFilter>
  239. <CheckboxFilter>
  240. <input type="checkbox" id="checkbox-organization"
  241. onChange={event => this.handleScopeLevelFilter(event, 'IT Organization')}/>
  242. <label htmlFor="checkbox-organization">IT Organization</label>
  243. </CheckboxFilter>
  244. <CheckboxFilter>
  245. <input type="checkbox" id="checkbox-portfolio"
  246. onChange={event => this.handleScopeLevelFilter(event, 'Portfolio')}/>
  247. <label htmlFor="checkbox-portfolio">Portfolio</label>
  248. </CheckboxFilter>
  249. <CheckboxFilter>
  250. <input type="checkbox" id="checkbox-program"
  251. onChange={event => this.handleScopeLevelFilter(event, 'Program')}/>
  252. <label htmlFor="checkbox-program">Program</label>
  253. </CheckboxFilter>
  254. <CheckboxFilter>
  255. <input type="checkbox" id="checkbox-team"
  256. onChange={event => this.handleScopeLevelFilter(event, 'Team')}/>
  257. <label htmlFor="checkbox-team">Team</label>
  258. </CheckboxFilter>
  259. </FilterSection>
  260. <FilterSection sectionName="Other">
  261. <CheckboxFilter>
  262. <input type="checkbox" id="checkbox-documentation"
  263. onChange={event => this.handleCheckboxFilter(event, 'documentation')}/>
  264. <label htmlFor="checkbox-documentation">Documentation</label>
  265. </CheckboxFilter>
  266. <CheckboxFilter>
  267. <input type="checkbox" id="checkbox-community"
  268. onChange={event => this.handleCheckboxFilter(event, 'documentation')}/>
  269. <label htmlFor="checkbox-community">Community</label>
  270. </CheckboxFilter>
  271. </FilterSection>
  272. <FilterSection sectionName="Contributions">
  273. <RangeWrapper>
  274. <Range range={true}
  275. min={0}
  276. max={50}
  277. marks={contributionsMarks}
  278. value={[this.state.filters.contributions.from, this.state.filters.contributions.to]}
  279. onChange={event => this.handleRangeFilter(event, 'contributions')}/>
  280. </RangeWrapper>
  281. </FilterSection>
  282. <FilterSection sectionName="Rating">
  283. <RangeWrapper>
  284. <Range range={true}
  285. min={0}
  286. max={5}
  287. marks={ratingMarks}
  288. value={[this.state.filters.rating.from, this.state.filters.rating.to]}
  289. onChange={event => this.handleRangeFilter(event, 'rating')}/>
  290. </RangeWrapper>
  291. </FilterSection>
  292. <FilterSection sectionName="Team Size">
  293. <RangeWrapper>
  294. <Range range={true}
  295. min={2}
  296. max={20}
  297. marks={teamSizeMarks}
  298. value={[this.state.filters.teamSize.from, this.state.filters.teamSize.to]}
  299. onChange={event => this.handleRangeFilter(event, 'teamSize')}/>
  300. </RangeWrapper>
  301. </FilterSection>
  302. </FiltersWrapper>
  303. </LeftDrawerWrapper>
  304. );
  305. }
  306.  
  307. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement