Skip to content

Commit 6c28b78

Browse files
committed
v0.1.0, added configuration via theme to add more colors
1 parent c6e3cc9 commit 6c28b78

File tree

4 files changed

+95
-31
lines changed

4 files changed

+95
-31
lines changed

.eslintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ module.exports = {
44
browser: true,
55
es6: true,
66
},
7+
parserOptions: {
8+
ecmaVersion: 2018,
9+
},
710
rules: {
811
'brace-style': 'warn', // [1tbs default, stroustrup, allman]
912
'comma-dangle': ['warn', 'always-multiline'],

README.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Tailwindcss plugin to make skeleton screen easier than ever.
66
![npm bundle size (scoped)](https://img.shields.io/bundlephobia/min/@gradin/tailwindcss-skeleton-screen)
77
![npm](https://img.shields.io/npm/dw/@gradin/tailwindcss-skeleton-screen)
88

9-
[Live Demo](https://play.tailwindcss.com/YSl180l7et)
9+
[Live Demo](https://play.tailwindcss.com/dcAoaNpFYu)
1010

1111
## Installation
1212

@@ -25,8 +25,58 @@ module.exports = {
2525
theme: {
2626
// ...
2727
},
28+
2829
plugins: [
2930
require('@gradin/tailwindcss-skeleton-screen'),
3031
],
32+
33+
}
34+
```
35+
36+
## Customization
37+
38+
You can change the color and animation via `theme` settings.
39+
40+
The object keys will be appended to the end of the `.loading` class.
41+
The base `.loading` class can be configured by `DEFAULT` key.
42+
43+
```js
44+
module.exports = {
45+
theme: {
46+
skeletonScreen: {
47+
DEFAULT: { // .loading
48+
baseColor: '#c7c7c7',
49+
movingColor: 'linear-gradient(to right, transparent 0%, #E8E8E8 50%, transparent 100%)',
50+
duration: '1s',
51+
timing: 'cubic-bezier(0.4, 0.0, 0.2, 1)',
52+
},
53+
// specify another color to have multiple loading colors.
54+
blue: { // .loading-blue
55+
baseColor: 'blue',
56+
movingColor: 'linear-gradient(to right, transparent 0%, lightblue 50%, transparent 100%)',
57+
duration: '.3s',
58+
timing: 'ease',
59+
},
60+
},
61+
},
62+
}
63+
```
64+
65+
Or you can use `theme.extend` to add another color in addition to the default.
66+
67+
```js
68+
module.exports = {
69+
theme: {
70+
extend: {
71+
skeletonScreen: {
72+
red: { // .loading-red
73+
baseColor: 'red',
74+
movingColor: 'pink',
75+
duration: '3s',
76+
timing: 'ease',
77+
},
78+
},
79+
},
80+
},
3181
}
3282
```

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gradin/tailwindcss-skeleton-screen",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Tailwindcss plugin to make skeleton screen easier than ever.",
55
"main": "src/index.js",
66
"scripts": {},
@@ -28,4 +28,4 @@
2828
"eslint": "^7.24.0",
2929
"tailwindcss": "^2.1.1"
3030
}
31-
}
31+
}

src/index.js

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,45 @@
11
const plugin = require('tailwindcss/plugin')
22

3-
module.exports = plugin(
4-
function ({ addUtilities }) {
5-
addUtilities([
6-
{
7-
'.loading': {
8-
position: 'relative',
9-
overflow: 'hidden',
10-
backgroundColor: '#c7c7c7',
11-
},
12-
'.loading::after': {
13-
display: 'block',
14-
position: 'absolute',
15-
height: '100%',
16-
top: 0,
3+
module.exports = plugin(function ({ theme, addUtilities }) {
4+
let styleDefault = {
5+
'DEFAULT': {
6+
baseColor: '#c7c7c7',
7+
movingColor: 'linear-gradient(to right, transparent 0%, #E8E8E8 50%, transparent 100%)',
8+
duration: '1s',
9+
timing: 'cubic-bezier(0.4, 0.0, 0.2, 1)',
10+
},
11+
}
12+
const styles = { ...styleDefault, ...theme('skeletonScreen', {}) }
13+
const utilities = Object.entries(styles).map(([key, value]) => {
14+
let className = '.loading' + (key === 'DEFAULT' ? '' : '-' + key)
15+
16+
return {
17+
[className]: {
18+
position: 'relative',
19+
overflow: 'hidden',
20+
backgroundColor: value.baseColor,
21+
},
22+
[`${className}::after`]: {
23+
display: 'block',
24+
position: 'absolute',
25+
height: '100%',
26+
top: 0,
27+
left: '-10rem',
28+
width: '10rem',
29+
content: "''",
30+
background: value.movingColor,
31+
animation: `skeletonloading ${value.duration} ${value.timing} infinite`,
32+
},
33+
'@keyframes skeletonloading': {
34+
from: {
1735
left: '-10rem',
18-
width: '10rem',
19-
content: "''",
20-
background: 'linear-gradient(to right, transparent 0%, #E8E8E8 50%, transparent 100%)',
21-
animation: 'skeletonloading 1s cubic-bezier(0.4, 0.0, 0.2, 1) infinite',
2236
},
23-
'@keyframes skeletonloading': {
24-
from: {
25-
left: '-10rem',
26-
},
27-
to: {
28-
left: '100%',
29-
},
37+
to: {
38+
left: '100%',
3039
},
3140
},
32-
])
33-
}
34-
)
41+
}
42+
})
43+
44+
addUtilities(utilities)
45+
})

0 commit comments

Comments
 (0)