Skip to content

Commit

Permalink
Support placeholders with arbitrary width, height and borderRadius (#34)
Browse files Browse the repository at this point in the history
* Add a box placeholder type with customizable width, height and border radius

* Add docs

* Fix comment

* Extend the media component to handle arbitrary width and height

* Revert "Extend the media component to handle arbitrary width and height"

This reverts commit 6699ab1.

* Use radius instead of borderRadius and default to a square

* Replace borderRadius -> radius in api example

* Fix default height in example
  • Loading branch information
kadikraman authored and Marvin Frachet committed Dec 18, 2017
1 parent 8ba64fd commit c31510a
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 1 deletion.
23 changes: 22 additions & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ width="200" src="https://img15.hostingpics.net/pics/198734skeletonloaderandroid.

# Components

The project currently supports 4 different placeholder components.
The project currently supports 5 different placeholder components.

Each of this components are wrapped in a HOC that brings two others (optional) props :

Expand Down Expand Up @@ -126,6 +126,27 @@ Display a Media on the left / right part of a Paragraph
/>
```

<h2 name="box">Box</h2>

Display a generic rectangle shape with customisable width, height, color and border radius

#### Props available
- `height: Number | String`: the height of the component (default: `50`)
- `width: Number | String`: the width of the component (default: `50`)
- `radius: Number`: the border radius of the component (default: `0`)
- `color: String`: the background color of the component (default: `#efefef`)

#### Example

```javascript
<Placeholder.Box
height={50}
width="100%"
radius={5}
color="teal"
/>
```

<h2 name="custom">Custom components</h2>

You can create your own placeholder component based on your own ones. Based on that, we're exposing a `Placeholder.connect` function that returns a new `ComponentContainer`.
Expand Down
33 changes: 33 additions & 0 deletions src/box/__tests__/box.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import { shallow } from 'enzyme';
import { View } from 'react-native';
import Box from './../box';

describe('Box#render', () => {
let wrapper;

beforeEach(() => {
wrapper = shallow(<Box />);
});

it('should own a props style that matches the default style', () => {
const style = {
height: 50,
width: 50,
borderRadius: 0,
backgroundColor: '#efefef',
};
expect(wrapper.find(View).prop('style')).toEqual(style);
});

it('should own a props style that matches the props', () => {
wrapper = shallow(<Box height={50} width={20} color="red" radius={5} />);
const style = {
height: 50,
width: 20,
backgroundColor: 'red',
borderRadius: 5,
};
expect(wrapper.find(View).prop('style')).toEqual(style);
});
});
10 changes: 10 additions & 0 deletions src/box/box.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import { View } from 'react-native';
import computeStyle from './box.style';

/**
* Create a box placeholder
*/
export default function (props) {
return <View style={computeStyle(props)} />;
}
6 changes: 6 additions & 0 deletions src/box/box.style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default ({ height = 50, width = 50, radius = 0, color = '#efefef' }) => ({
height,
width,
borderRadius: radius,
backgroundColor: color,
});
2 changes: 2 additions & 0 deletions src/placeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Media from './media/media';
import Line from './line/line';
import ImageContent from './imageContent/imageContent';
import MultiWords from './multiWords/multiWords';
import Box from './box/box';

/**
* Export the placeholder
Expand All @@ -14,5 +15,6 @@ export default {
Media: connect(Media),
Line: connect(Line),
MultiWords: connect(MultiWords),
Box: connect(Box),
connect,
};

0 comments on commit c31510a

Please sign in to comment.