Skip to content
This repository was archived by the owner on Apr 1, 2021. It is now read-only.

Commit ffb06f1

Browse files
committed
add selectors and fix minor problems
1 parent 53793ff commit ffb06f1

File tree

6 files changed

+57
-6
lines changed

6 files changed

+57
-6
lines changed

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ The need a fast way to bind keys to a react-powered UI with awesome redux for st
1313
## Installation
1414
`react-keys` requires **React 0.14 or later**
1515

16-
`yarn install react-keys`
16+
`yarn add react-keys`
1717

1818
## Dependencies
1919

2020
While not having direct dependencies, react-keys have to be used with `react`, `react-dom` and `redux` :
2121

2222
```javscript
23-
yarn install react
24-
yarn install react-dom
25-
yarn install redux
23+
yarn add react
24+
yarn add react-dom
25+
yarn add redux
2626
```
2727

2828
# Link it with Redux (Otherwise it doesn't work !)
@@ -147,6 +147,7 @@ renderWithId('mosaic-1-1');
147147
* `filter` (string / *optional*) class name which exclude element
148148
* `debounce` (number / *optional*) define a debounce for keys press in ms (default global debounce)
149149
* `enterStrategy` (string / *optional*) define strape strategy on enter: `start` / `mirror` / `memory` / `none` (default `none`)
150+
* `position` (string / *optional*) to better handle for enterStrategy (vertial/horizontal) (default `horizontal`)
150151
* `gap` (number / *optional*) reduce or increase elements margin (default `0`)`
151152
* `boundedGap` (number / *optional*) reduce or increase bounded margin (default `0`)
152153
* `topGap` (number / *optional*) reduce or increase last top margin (default `0`)
@@ -278,6 +279,14 @@ the keys store will manage the state of each binders (no matter how many they ar
278279
279280
So you can listen the change of theses values for each binder
280281
282+
### Selectors
283+
Selectors give you easy control on your data binder, here few selectors for common use. they return a function
284+
* `isCurrentBinder(binderId)` determine if your binder is the current binder
285+
* `isBinderActive(binderId)` determine if your binder is active
286+
* `getBinderMarginLeft(binderId)` determine marginLeft of a binder
287+
* `getBinderMarginTop(binderId)` determine marginTop of a binder
288+
* `getBinderSelectedId(binderId)` determine selectedId of a binder
289+
281290
### Action launchers
282291
* `activeBinder(binderId, selectedId(optional))` activate a new binder by giving its id (first id by default)
283292
* `resetBinder(binderId, selectedId(optional))` reset binder by giving its id (first id by default)

src/components/Binder.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class Binder extends Component {
3131
React.PropTypes.array,
3232
]),
3333
selector: PropTypes.string,
34+
position: PropTypes.string,
3435
wrapper: PropTypes.string,
3536
filter: PropTypes.string,
3637
gap: PropTypes.number,

src/components/Carousel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class Carousel extends Component {
144144
render() {
145145
const { size, elWidth, childrenClassName, className } = this.props;
146146
const { elements } = this.state;
147-
return <div className={className} style={{ position: 'absolute', overflow: 'hidden' }}>
147+
return <div className={className} style={{ overflow: 'hidden' }}>
148148
{elements.map((element, inc) => {
149149
if (!element) return;
150150
const gap = (inc - 2) * elWidth;

src/index.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ import _catcher from './catcher';
55
import { _init, getConfig } from './listener';
66
import { _keyReducer } from './redux/reducer';
77
import { _activeBinder, _updateBinder, _resetBinder, _resetCarousel } from './redux/actions';
8-
import { _selector } from './selector';
8+
import {
9+
_selector,
10+
_isCurrentBinder,
11+
_isBinderActive,
12+
_getBinderMarginLeft,
13+
_getBinderMarginTop,
14+
_getBinderSelectedId
15+
} from './selector';
916
import blocks from './blocks';
1017

1118
export const config = getConfig;
@@ -17,6 +24,11 @@ export const Carousel = _Carousel;
1724

1825
export const keysReducer = _keyReducer;
1926
export const keysSelector = _selector;
27+
export const isCurrentBinder = _isCurrentBinder;
28+
export const isBinderActive = _isBinderActive;
29+
export const getBinderMarginLeft = _getBinderMarginLeft;
30+
export const getBinderMarginTop = _getBinderMarginTop;
31+
export const getBinderSelectedId = _getBinderSelectedId;
2032

2133
export const catcher = _catcher;
2234

src/redux/actions.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export function addBinderToStore(props, type) {
6363
leftGap,
6464
downGap,
6565
enterStrategy,
66+
position,
6667
} = props;
6768
globalStore.dispatch({
6869
type: ADD_BINDER_TO_STORE,
@@ -80,6 +81,7 @@ export function addBinderToStore(props, type) {
8081
leftGap,
8182
downGap,
8283
enterStrategy,
84+
position,
8385
elements: elements || [],
8486
prevEl: null,
8587
prevDir: null,

src/selector.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,30 @@ export function _selector(id) {
66
ensureState();
77
return () => globalStore.getState()[NAME][id] || { marginLeft: 0, marginTop: 0 };
88
}
9+
10+
export function _isCurrentBinder(id) {
11+
ensureState();
12+
const currentBinderId = globalStore.getState()['current'] &&
13+
globalStore.getState()['current'].binderId;
14+
return () => currentBinderId === id;
15+
}
16+
17+
export function _getBinderSelectedId(id) {
18+
ensureState();
19+
return () => globalStore.getState()[NAME][id] ? globalStore.getState()[NAME][id].selectedId : '';
20+
}
21+
22+
export function _getBinderMarginLeft(id) {
23+
ensureState();
24+
return () => globalStore.getState()[NAME][id] ? globalStore.getState()[NAME][id].marginLeft : 0;
25+
}
26+
27+
export function _getBinderMarginTop(id) {
28+
ensureState();
29+
return () => globalStore.getState()[NAME][id] ? globalStore.getState()[NAME][id].marginTop : 0;
30+
}
31+
32+
export function _isBinderActive(id) {
33+
ensureState();
34+
return () => globalStore.getState()[NAME][id] && globalStore.getState()[NAME][id].active;
35+
}

0 commit comments

Comments
 (0)