├── .github
└── workflows
│ └── main.yml
├── .gitignore
├── .hophoprc
├── CHANGELOG.md
├── LICENSE
├── README.md
├── docs
├── build
│ ├── 0.fda9587b.js
│ └── bundle.df7bbcc0.js
└── index.html
├── examples
├── Examples.md
└── examples.scss
├── package-lock.json
├── package.json
├── src
├── ReactPlaceholder.tsx
├── index.ts
├── placeholders
│ ├── MediaBlock.tsx
│ ├── RectShape.tsx
│ ├── RoundShape.tsx
│ ├── TextBlock.tsx
│ ├── TextRow.tsx
│ └── index.ts
├── reactPlaceholder.scss
└── utils.ts
├── styleguide.config.js
├── styleguide
├── index.html
└── setup.tsx
├── tests
├── ReactPlaceholder.test.tsx
├── __snapshots__
│ ├── ReactPlaceholder.test.tsx.snap
│ └── placeholders.test.tsx.snap
├── placeholders.test.tsx
└── setup.js
├── tsconfig.json
└── webpack.config.js
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on:
4 | push:
5 | branches: [ master ]
6 | pull_request:
7 | branches: [ master ]
8 |
9 | jobs:
10 | build:
11 | name: Test and Build
12 | runs-on: ubuntu-latest
13 | steps:
14 | - uses: actions/checkout@v2
15 | - uses: actions/setup-node@v1
16 | - run: npm ci
17 | - run: npm run preversion
18 | - run: npm run prepublishOnly
19 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | coverage
3 | *.log
4 | lib
5 | .eslintcache
6 |
--------------------------------------------------------------------------------
/.hophoprc:
--------------------------------------------------------------------------------
1 | toggl: n
2 | branchPrefix: n
3 | branchSuffix: y
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 |
4 |
5 | ## [v4.1.0](https://github.com/buildo/react-placeholder/tree/v4.1.0) (2021-02-05)
6 | [Full Changelog](https://github.com/buildo/react-placeholder/compare/v4.0.3...v4.1.0)
7 |
8 | #### New features:
9 |
10 | - Problem with React 17 and npm version 7.5.1 on mac osx [#95](https://github.com/buildo/react-placeholder/issues/95)
11 | - [Question] CSS Import [#94](https://github.com/buildo/react-placeholder/issues/94)
12 | - type CustomPlaceholderProps showLoadingAnimation is undefined instead of boolean [#90](https://github.com/buildo/react-placeholder/issues/90)
13 | - v3.0.2 TypeScript error about missing properties [#82](https://github.com/buildo/react-placeholder/issues/82)
14 | - Do `children` and `ready` really have to be required props? [#79](https://github.com/buildo/react-placeholder/issues/79)
15 |
16 | ## [v4.0.3](https://github.com/buildo/react-placeholder/tree/v4.0.3) (2020-06-11)
17 | [Full Changelog](https://github.com/buildo/react-placeholder/compare/v4.0.2...v4.0.3)
18 |
19 | ## [v4.0.2](https://github.com/buildo/react-placeholder/tree/v4.0.2) (2020-06-01)
20 | [Full Changelog](https://github.com/buildo/react-placeholder/compare/v4.0.1...v4.0.2)
21 |
22 | ## [v4.0.1](https://github.com/buildo/react-placeholder/tree/v4.0.1) (2020-03-13)
23 | [Full Changelog](https://github.com/buildo/react-placeholder/compare/v4.0.0...v4.0.1)
24 |
25 | #### New features:
26 |
27 | - TextRow/TextBlock ignores lineSpacing is equal to 0 [#86](https://github.com/buildo/react-placeholder/issues/86)
28 | - Is this package still maintained? [#84](https://github.com/buildo/react-placeholder/issues/84)
29 |
30 | ## [v4.0.0](https://github.com/buildo/react-placeholder/tree/v4.0.0) (2020-02-29)
31 | [Full Changelog](https://github.com/buildo/react-placeholder/compare/v3.0.2...v4.0.0)
32 |
33 | #### Breaking:
34 |
35 | - Warning: componentWillReceiveProps has been renamed, and is not recommended for use. [#83](https://github.com/buildo/react-placeholder/issues/83)
36 |
37 | ## [v3.0.2](https://github.com/buildo/react-placeholder/tree/v3.0.2) (2019-02-21)
38 | [Full Changelog](https://github.com/buildo/react-placeholder/compare/v3.0.1...v3.0.2)
39 |
40 | #### New features:
41 |
42 | - ReactPlaceholder text component doesn't override the width property [#78](https://github.com/buildo/react-placeholder/issues/78)
43 | - [Typings] Can't assign Element to customPlaceholder [#75](https://github.com/buildo/react-placeholder/issues/75)
44 |
45 | ## [v3.0.1](https://github.com/buildo/react-placeholder/tree/v3.0.1) (2018-05-08)
46 | [Full Changelog](https://github.com/buildo/react-placeholder/compare/v3.0.0...v3.0.1)
47 |
48 | #### Fixes (bugs & defects):
49 |
50 | - Removed CSS? [#72](https://github.com/buildo/react-placeholder/issues/72)
51 |
52 | ## [v3.0.0](https://github.com/buildo/react-placeholder/tree/v3.0.0) (2018-05-04)
53 | [Full Changelog](https://github.com/buildo/react-placeholder/compare/v2.0.0...v3.0.0)
54 |
55 | #### Breaking:
56 |
57 | - Refactor in TypeScript [#69](https://github.com/buildo/react-placeholder/issues/69)
58 |
59 | #### New features:
60 |
61 | - index.d.ts missing 'style' property [#67](https://github.com/buildo/react-placeholder/issues/67)
62 |
63 | ## [v2.0.0](https://github.com/buildo/react-placeholder/tree/v2.0.0) (2017-12-20)
64 | [Full Changelog](https://github.com/buildo/react-placeholder/compare/v1.0.10...v2.0.0)
65 |
66 | #### Breaking:
67 |
68 | - Array.apply not support ie8 in TextBlock even if I add the polyfill (again) [#65](https://github.com/buildo/react-placeholder/issues/65)
69 |
70 | ## [v1.0.10](https://github.com/buildo/react-placeholder/tree/v1.0.10) (2017-12-15)
71 | [Full Changelog](https://github.com/buildo/react-placeholder/compare/v1.0.9...v1.0.10)
72 |
73 | #### Fixes (bugs & defects):
74 |
75 | - Array.apply not support ie8 in TextBlock even if I'm add the polyfill [#62](https://github.com/buildo/react-placeholder/issues/62)
76 |
77 | #### New features:
78 |
79 | - TextBlock: make `widths` overridable [#59](https://github.com/buildo/react-placeholder/issues/59)
80 |
81 | ## [v1.0.9](https://github.com/buildo/react-placeholder/tree/v1.0.9) (2017-11-28)
82 | [Full Changelog](https://github.com/buildo/react-placeholder/compare/v1.0.8...v1.0.9)
83 |
84 | #### New features:
85 |
86 | - Bug with delay when the component is already mounted [#54](https://github.com/buildo/react-placeholder/issues/54)
87 |
88 | ## [v1.0.8](https://github.com/buildo/react-placeholder/tree/v1.0.8) (2017-10-25)
89 | [Full Changelog](https://github.com/buildo/react-placeholder/compare/v1.0.7...v1.0.8)
90 |
91 | #### New features:
92 |
93 | - Add "delay" prop to show the placeholder for a minimum time [#49](https://github.com/buildo/react-placeholder/issues/49)
94 | - React 16 warning message [#46](https://github.com/buildo/react-placeholder/issues/46)
95 |
96 | ## [v1.0.7](https://github.com/buildo/react-placeholder/tree/v1.0.7) (2017-10-16)
97 | [Full Changelog](https://github.com/buildo/react-placeholder/compare/v1.0.6...v1.0.7)
98 |
99 | #### New features:
100 |
101 | - error in ready [#44](https://github.com/buildo/react-placeholder/issues/44)
102 |
103 | ## [v1.0.6](https://github.com/buildo/react-placeholder/tree/v1.0.6) (2017-08-03)
104 | [Full Changelog](https://github.com/buildo/react-placeholder/compare/v1.0.5...v1.0.6)
105 |
106 | #### Fixes (bugs & defects):
107 |
108 | - @types/react > 33 complains [#41](https://github.com/buildo/react-placeholder/issues/41)
109 | - Animations not working with custom placeholders. [#34](https://github.com/buildo/react-placeholder/issues/34)
110 |
111 | #### New features:
112 |
113 | - Action required: Greenkeeper could not be activated 🚨 [#39](https://github.com/buildo/react-placeholder/issues/39)
114 | - Action required: Greenkeeper could not be activated 🚨 [#38](https://github.com/buildo/react-placeholder/issues/38)
115 |
116 | ## [v1.0.5](https://github.com/buildo/react-placeholder/tree/v1.0.5) (2017-06-26)
117 | [Full Changelog](https://github.com/buildo/react-placeholder/compare/v1.0.4...v1.0.5)
118 |
119 | #### Fixes (bugs & defects):
120 |
121 | - Typo in CSS selector for react-shape animation [#33](https://github.com/buildo/react-placeholder/issues/33)
122 |
123 | ## [v1.0.4](https://github.com/buildo/react-placeholder/tree/v1.0.4) (2017-06-01)
124 | [Full Changelog](https://github.com/buildo/react-placeholder/compare/v1.0.3...v1.0.4)
125 |
126 | #### Fixes (bugs & defects):
127 |
128 | - Update typings to make lineSpacing prop optional [#32](https://github.com/buildo/react-placeholder/issues/32)
129 |
130 | ## [v1.0.3](https://github.com/buildo/react-placeholder/tree/v1.0.3) (2017-05-31)
131 | [Full Changelog](https://github.com/buildo/react-placeholder/compare/v1.0.2...v1.0.3)
132 |
133 | #### New features:
134 |
135 | - animation support [#27](https://github.com/buildo/react-placeholder/issues/27)
136 |
137 | #### Fixes (bugs & defects):
138 |
139 | - Rectangle placeholder without className sets class to undefined [#24](https://github.com/buildo/react-placeholder/issues/24)
140 |
141 | ## [v1.0.2](https://github.com/buildo/react-placeholder/tree/v1.0.2) (2017-04-25)
142 | [Full Changelog](https://github.com/buildo/react-placeholder/compare/v1.0.1...v1.0.2)
143 |
144 | #### New features:
145 |
146 | - Add React 15.5 compatibility [#22](https://github.com/buildo/react-placeholder/issues/22)
147 |
148 | ## [v1.0.1](https://github.com/buildo/react-placeholder/tree/v1.0.1) (2017-04-03)
149 | [Full Changelog](https://github.com/buildo/react-placeholder/compare/v1.0.0...v1.0.1)
150 |
151 | #### New features:
152 |
153 | - replace `lodash.omit` with ES6 destructuring [#21](https://github.com/buildo/react-placeholder/issues/21)
154 |
155 | ## [v1.0.0](https://github.com/buildo/react-placeholder/tree/v1.0.0) (2017-03-23)
156 | [Full Changelog](https://github.com/buildo/react-placeholder/compare/v0.0.3...v1.0.0)
157 |
158 | #### Fixes (bugs & defects):
159 |
160 | - lodash and classnames should be deps, not devDeps [#13](https://github.com/buildo/react-placeholder/issues/13)
161 |
162 | #### Breaking:
163 |
164 | - Use relative heights [#10](https://github.com/buildo/react-placeholder/issues/10)
165 |
166 | ## [v0.0.3](https://github.com/buildo/react-placeholder/tree/v0.0.3) (2016-12-29)
167 | [Full Changelog](https://github.com/buildo/react-placeholder/compare/v0.0.2...v0.0.3)
168 |
169 | #### Fixes (bugs & defects):
170 |
171 | - package is currently broken [#6](https://github.com/buildo/react-placeholder/issues/6)
172 |
173 | ## [v0.0.2](https://github.com/buildo/react-placeholder/tree/v0.0.2) (2016-11-08)
174 |
175 |
176 | #### New features:
177 |
178 | - Replace react.createClass with ES6 class [#3](https://github.com/buildo/react-placeholder/issues/3)
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 buildo
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # React Placeholder
2 | A React component to easily replicate your page with nice placeholders while the content is loading.
3 | You can use a placeholder from the default set, or pass your own!
4 |
5 | 
6 |
7 | ```jsx
8 | import ReactPlaceholder from 'react-placeholder';
9 | import "react-placeholder/lib/reactPlaceholder.css";
10 |
11 | React.renderComponent(
12 |
13 |
14 |
15 |
16 |
,
17 | document.body);
18 | ```
19 |
20 | [**Live Demo**](http://buildo.github.io/react-placeholder/#!/ReactPlaceholder)
21 |
22 | ### Install
23 | ```
24 | npm install --save react-placeholder
25 | ```
26 |
27 | ### Props
28 |
29 | ```tsx
30 | children: ReactNode;
31 | ready: boolean;
32 | delay?: number;
33 | firstLaunchOnly?: boolean;
34 | showLoadingAnimation?: boolean;
35 | type?: 'text' | 'media' | 'textRow' | 'rect' | 'round';
36 | rows?: number;
37 | color?: string;
38 | customPlaceholder?: ReactElement;
39 | className?: string;
40 | style?: CSSProperties;
41 | ```
42 |
43 | The default props will render a `text` placeholder with `3` rows and the color `#CDCDCD`.
44 |
45 | ### Customization
46 | If the built-in set of placeholders is not enough, you can pass you own through the prop **"customPlaceholder"**
47 |
48 | ```jsx
49 | }>
50 |
51 |
52 | ```
53 |
54 | You can also import the built-in placeholders directly. This might be useful to use them to create your own customized placeholder:
55 |
56 | ```jsx
57 | import {TextBlock, MediaBlock, TextRow, RectShape, RoundShape} from 'react-placeholder/lib/placeholders';
58 |
59 | const awesomePlaceholder = (
60 |
61 |
62 |
63 |
64 | );
65 |
66 |
67 |
68 |
69 | ```
70 |
71 | ### Delay
72 | You can pass an optional `delay` prop which specifies the time (in milliseconds) `react-placeholder` should wait before displaying the placeholder element. This is useful if you want to show a placeholder for slower connections while avoiding a brief "flash" on faster connections.
73 |
74 | Note that this delay will __not__ affect the initial render, only subsequent "ready" state changes. Setting the `firstLaunchOnly` prop to `true` will also disable this feature.
75 |
76 | ### Animation
77 | `react-placeholder` already comes with one default pulse animation to better tell the user that the page is loading.
78 | The animation is defined in a separate CSS file so, in order to enable it, you should import that style in your project like this:
79 |
80 | ```js
81 | import 'react-placeholder/lib/reactPlaceholder.css';
82 | ```
83 |
84 | Once you've done this, you can simply pass the boolean prop `showLoadingAnimation` to tell `ReactPlaceholder` to animate itself:
85 |
86 | ```jsx
87 | import 'react-placeholder/lib/reactPlaceholder.css';
88 |
89 |
90 |
This is a Test.
91 |
92 | ```
93 |
94 | ### Style
95 | you can style the placeholder by passing **```className```** or **```style```** or by using the built-in classes:
96 |
97 | *"text-block", "media-block", "text-row", "rect-shape", "round-shape".*
98 |
--------------------------------------------------------------------------------
/docs/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/examples/Examples.md:
--------------------------------------------------------------------------------
1 | ## Examples
2 |
3 | ### ReactPlaceholder comes with various built-in types
4 |
5 | `type='text'`
6 | ```js
7 |
8 |
9 |
10 | ```
11 |
12 | `type='media'`
13 | ```js
14 |
15 |
16 |
17 | ```
18 |
19 | `type='textRow'`
20 | ```js
21 |
22 |
23 |
24 | ```
25 |
26 | `type='rect'`
27 | ```js
28 |
29 |
30 |
31 | ```
32 |
33 | `type='round'`
34 | ```js
35 |
36 |
37 |
38 | ```
39 |
40 | ### Use a custom placeholder
41 | You can use your own custom placeholder:
42 |
43 | ```js
44 | } ready={false}>
45 |
46 |
47 | ```
48 |
49 | ### Animation
50 | Pass `showLoadingAnimation={true}` to enable the default loading animation:
51 |
52 | ```js
53 |
54 |
55 |
56 | ```
57 |
58 | ### firstLaunchOnly
59 | With `firstLaunchOnly={true}` the placeholder will be rendered only the first time `ready` is `false`
60 |
61 | ```js
62 | initialState = { ready: false }
63 |
64 | function toggleReady() {
65 | setState({ ready: !state.ready })
66 | }
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 | ```
76 |
77 | ### delay
78 | You can delay the switch from "real component" to the placeholder with the prop `delay`
79 |
80 | ```js
81 | initialState = { ready: true }
82 |
83 | function toggleReady() {
84 | setState({ ready: !state.ready })
85 | }
86 |
87 |
,
10 | ]
11 | `;
12 |
13 | exports[`ReactPlaceholder renders content when firstLaunchOnly is true and ready changes to true, and keeps it rendered when ready changes to false 1`] = `
14 |
18 | `;
19 |
20 | exports[`ReactPlaceholder renders content when firstLaunchOnly is true and ready changes to true, and keeps it rendered when ready changes to false 2`] = `
21 |
22 | Some ready content
23 |
24 | `;
25 |
26 | exports[`ReactPlaceholder renders content when firstLaunchOnly is true and ready changes to true, and keeps it rendered when ready changes to false 3`] = `
27 |
28 | Some ready content
29 |
30 | `;
31 |
32 | exports[`ReactPlaceholder renders content when it's ready, then a placeholder when it's not ready, and finally content again when it's ready 1`] = `
33 |
34 | Some ready content
35 |
36 | `;
37 |
38 | exports[`ReactPlaceholder renders content when it's ready, then a placeholder when it's not ready, and finally content again when it's ready 2`] = `
39 |
43 |
47 |
51 |
52 | `;
53 |
54 | exports[`ReactPlaceholder renders content when it's ready, then a placeholder when it's not ready, and finally content again when it's ready 3`] = `
55 |