Skip to content

Commit 4a44169

Browse files
authored
Merge pull request #57 from seeliang/breaking-return-value-instead-of-index
Breaking: return value instead of index
2 parents 51d1dc8 + 23397a1 commit 4a44169

25 files changed

+524
-344
lines changed

.eslintrc.js

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
module.exports = {
2+
"env": {
3+
"node": true,
4+
"browser": true,
5+
"mocha": true,
6+
"es6": true
7+
},
8+
"extends": "eslint:recommended",
9+
"parser": "babel-eslint",
10+
"parserOptions": {
11+
"arrowFunctions": true,
12+
"binaryLiterals": true,
13+
"blockBindings": true,
14+
"classes": true,
15+
"defaultParams": true,
16+
"destructuring": true,
17+
"forOf": true,
18+
"generators": true,
19+
"modules": true,
20+
"objectLiteralComputedProperties": true,
21+
"objectLiteralDuplicateProperties": true,
22+
"objectLiteralShorthandMethods": true,
23+
"objectLiteralShorthandProperties": true,
24+
"octalLiterals": true,
25+
"sourceType": "module",
26+
"spread": true,
27+
"templateStrings": true,
28+
"globalReturn": true, // React JSX support
29+
"jsx": true
30+
},
31+
"plugins": ["react"],
32+
"rules": {
33+
"camelcase": 2,
34+
"comma-dangle": 2,
35+
"comma-style": [2, "last"],
36+
"consistent-this": [2, "self"],
37+
"curly": [2, "all"],
38+
"eol-last": 2,
39+
"eqeqeq": 2,
40+
"func-names": 2,
41+
"indent": [2, 2],
42+
"max-len": [2, 120, 2], // 2 spaces per tab, max 120 chars per line
43+
"new-cap": 2,
44+
"no-array-constructor": 2,
45+
"no-inner-declarations": [2, "both"],
46+
"no-mixed-spaces-and-tabs": 2,
47+
"no-new-object": 2,
48+
"no-shadow-restricted-names": 2,
49+
"no-trailing-spaces": [2, { "skipBlankLines": false }],
50+
"no-underscore-dangle": 0, // dangling underscores are fine
51+
"quotes": [2, "single", "avoid-escape"],
52+
"quote-props": [2, "consistent-as-needed"],
53+
"radix": 2,
54+
55+
"semi": [2, "always"],
56+
"space-before-blocks": [2, "always"],
57+
"space-infix-ops": 2,
58+
"strict": [2, "global"],
59+
"vars-on-top": 2,
60+
61+
"react/display-name": 1,
62+
"react/forbid-prop-types": 1,
63+
"jsx-quotes": 1,
64+
"react/jsx-boolean-value": 1,
65+
"react/jsx-closing-bracket-location": 1,
66+
"react/jsx-curly-spacing": 1,
67+
"react/jsx-max-props-per-line": 1,
68+
"react/jsx-no-duplicate-props": 1,
69+
"react/jsx-no-undef": 1,
70+
"react/jsx-sort-props": 1,
71+
"react/jsx-uses-react": 1,
72+
"react/jsx-uses-vars": 1,
73+
"react/jsx-wrap-multilines": 1,
74+
"react/no-danger": 1,
75+
"react/no-did-mount-set-state": 1,
76+
"react/no-did-update-set-state": 1,
77+
"react/no-direct-mutation-state": 1,
78+
"react/no-multi-comp": 1,
79+
"react/no-set-state": 1,
80+
"react/no-unknown-property": 1,
81+
"react/react-in-jsx-scope": 1,
82+
"react/self-closing-comp": 1,
83+
"react/sort-comp": 1,
84+
"react/sort-prop-types": 1
85+
}
86+
}

README.md

+15-3
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,34 @@
55
[![Dependencies](https://david-dm.org/seeliang/react-range-selector.svg)](https://david-dm.org/seeliang/react-range-selector)
66

77
# React two points range selector
8-
the [html5 input range](https://www.w3.org/wiki/HTML/Elements/input/range) only supports one point, and it's not easy to use for mobile. this npm pack is an alternative solution with input checkbox
9-
[Demo](http://seeliang.github.io/react-range-selector/)
8+
the [html5 input range](https://www.w3.org/wiki/HTML/Elements/input/range) only supports one point, and it's not easy to use for mobile. this npm pack is an alternative solution with input checkbox
9+
10+
## Demo
11+
[Demo page](http://seeliang.github.io/react-range-selector/)
12+
13+
* [use as a package](https://github.com/seeliang/react-range-selector/blob/master/demo/import-set/form.js)
14+
* [use as a plugin](https://github.com/seeliang/react-range-selector/blob/master/app.html#L35)
1015

1116
## Features
1217
* based on [BEM](https://css-tricks.com/bem-101/)
1318
* has "is-start " class, "in-range" and "is-end" class for special styling set
1419
* support initial selected range
1520
* support customize range
1621
* standalong react [plugin](https://cdn.rawgit.com/seeliang/react-range-selector/master/build/js/react-range-selector.js) with options set for your quick prototype, [check the Demo](http://seeliang.github.io/react-range-selector/)
17-
22+
1823

1924
## License
2025

2126
MIT licensed
2227

2328
## Release
29+
30+
### 2.0
31+
* BREAKING: `rangeUpdate` return object [data](https://github.com/seeliang/react-range-selector/pull/57/files#diff-3d89a121d9489b4df1b85aa9fb02ef15R50) with `values`, `section`, `selectedIndex`
32+
* BREAKING: [move to flat css structure](https://github.com/seeliang/react-range-selector/pull/57/commits/e2ab48a341449d24b20f47b0e039881cd8196b2b)
33+
* FEAT: `initialFormState` to [generate initial state from data](https://github.com/seeliang/react-range-selector/pull/57/files#diff-3d89a121d9489b4df1b85aa9fb02ef15R32)
34+
* FEAT: `generatePropsWithData` [mapping data to RangerSelector](https://github.com/seeliang/react-range-selector/pull/57/files#diff-3d89a121d9489b4df1b85aa9fb02ef15R44)
35+
* CHORE: recover lint
2436
### 1.3.0
2537
* add package feature
2638

__tests__/checkbox/__snapshots__/input-checkbox__test.js.snap

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
exports[`renders correctly 1`] = `
44
<div
5-
className="range-selector__item-input is-in-range"
5+
className="range-selector__item"
66
>
77
<input
88
checked={true}
9-
className="range-selector__item-input-checkbox"
9+
className="range-selector__item-checkbox"
1010
id="checkboxName"
1111
onChange={[Function]}
1212
type="checkbox"
1313
value="checkboxName"
1414
/>
1515
<label
16-
className="range-selector__item-input-text"
16+
className="range-selector__item-label is-in-range"
1717
htmlFor="checkboxName"
1818
>
1919
3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {generatePropsWithData} from '../../src/helpers';
2+
3+
it('should covert data to props with correct data', () => {
4+
const selectors =
5+
{
6+
name: 'Frequency',
7+
customiseRange: [2.5,3.4,4.2,6.3],
8+
initialSelected: [0,2],
9+
callback: {}
10+
};
11+
expect(generatePropsWithData(selectors)).toMatchObject(
12+
{componentName: 'range-selector',
13+
customiseRange: [2.5, 3.4, 4.2, 6.3],
14+
initialSelected: [0, 2],
15+
key: 'Frequency',
16+
name: 'Frequency',
17+
rangeUpdate: {}});
18+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {initialFormState} from '../../src/helpers';
2+
3+
it('should covert selectors to state with correct data', () => {
4+
const selectors = [
5+
{
6+
name: 'Cores',
7+
range: [3,8]
8+
},
9+
{
10+
name: 'Frequency',
11+
customiseRange: [2.5,3.4,4.2,6.3],
12+
initialSelected: [0,2]
13+
},
14+
{
15+
name: 'PCIE slots',
16+
range: [1,4],
17+
initialSelected: [0,1]
18+
},
19+
{
20+
name: 'Ram size',
21+
customiseRange: [2,4,6,8],
22+
initialSelected: [2,3]
23+
}
24+
];
25+
expect(initialFormState(selectors)).toMatchObject({indexRange: {'Frequency': [0, 2], 'PCIE slots': [0, 1], 'Ram size': [2, 3]}, values: {'Frequency': [2.5, 3.4, 4.2], 'PCIE slots': [1, 2], 'Ram size': [6, 8]}});
26+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {mappingSelectedIndexToResult} from '../../src/helpers';
2+
3+
it('should covert range of two points to list with correct values', () => {
4+
expect(mappingSelectedIndexToResult({list:[3,4,5,6], selectedIndex: [1,3]})).toMatchObject([4,5,6]);
5+
});
6+
7+
it('should covert range of one points to list with correct range', () => {
8+
expect(mappingSelectedIndexToResult({list:[3,4,5,6], selectedIndex: [1]})).toMatchObject([4]);
9+
});
10+
11+
it('should throw if list is not an array', () => {
12+
expect(() => {mappingSelectedIndexToResult({list: {}, selectedIndex: [1]});}).toThrow();
13+
});
14+
15+
it('should throw if list is empty array', () => {
16+
expect(() => {mappingSelectedIndexToResult({list: [], selectedIndex: [1]});}).toThrow();
17+
});
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {rangeToList} from '../../src/helpers';
2+
3+
it('should covert range to list with correct range', () => {
4+
expect(rangeToList([3,6])).toMatchObject([3,4,5,6]);
5+
});

0 commit comments

Comments
 (0)