Skip to content

Commit

Permalink
disable random color as renderer option
Browse files Browse the repository at this point in the history
  • Loading branch information
madox2 committed May 23, 2016
1 parent 13ff047 commit 244583e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 11 additions & 2 deletions __tests__/defaultRenderer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,21 @@ describe('defaultRenderer', () => {
expect(tag.props.style).toEqual(objectContaining({ color: 'custom' }));
});

it('should disable random color', () => {
it('should disable random color using custom props', () => {
// deprecated
const render = defaultRenderer({
props: { disableRandomColor: true }
});
const tag = render({ value: 'tag1', count: 33 }, 18, 1);
expect(tag.props.style).toEqual(objectContaining({ color: 'black' }));
expect(tag.props.style.color).not.toBeDefined();
});

it('should disable random color using options', () => {
const render = defaultRenderer({
disableRandomColor: true
});
const tag = render({ value: 'tag1', count: 33 }, 18, 1);
expect(tag.props.style.color).not.toBeDefined();
});

});
3 changes: 2 additions & 1 deletion src/defaultRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ export const defaultRenderer = (options = {}) => (tag, size, key, handlers = {})
const {
tagRenderer = tag => tag.value,
colorOptions = {},
disableRandomColor = false,
props = {}
} = options;

const className = 'tag-cloud-tag';
const fontSize = size + 'px';
const color = props.disableRandomColor ? tag.color || 'black' : randomColor(colorOptions);
const color = (props.disableRandomColor || disableRandomColor) ? tag.color || undefined : randomColor(colorOptions);

const eventHandlers = {};
Object.keys(handlers).forEach(key => handlers[key] && (eventHandlers[key] = (e) => handlers[key](tag, e)));
Expand Down

0 comments on commit 244583e

Please sign in to comment.