
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
SkeletorJS is a Javascript library that allow you to ease your skeleton loading screen creation. It use predefined shapes you can configure and compose to create more complex skeleton.
SkulletorJS is a Javascript library that allows you to ease your skeleton loading screen creation. It uses predefined shapes you can configure and compose to create more complex skeletons.
The created skeletons are CSS based. SkulletorJS also provides control capabilities such as end, disappear.
This basic script produces a vanilla javascript skeleton. Easy to create, it simply uses some basic shapes and appends the result to the DOM.
const bluePrint = () => [
{
width: '35%',
height: '365px',
},
circle({ radius: 35, left: 15, top: 15, color: { r: 255, g: 255, b: 255, a: 1 } }),
rectangle({ height: '185px' }),
line({ fontSize: 22, width: '180px', topGap: 20, left: 20 }),
line({ fontSize: 22, width: '120px', topGap: 20, left: 20 }),
line({ fontSize: 36, width: '150px', topGap: 20, left: 20 }),
]
const { Skulletor } = skulletor([bluePrint(), bluePrint()])
const dom = document.getElementById('root')
dom.appendChild(Skulletor)
The result :
npm install --save skulletor
First of all, you need to choose your adapter.
In the library you have 3 adapters available : Vanilla, React (Hooks) or React. It will define what kind of skulletor you're going to use, but the call remains similar.
import skulletor from 'skulletor/lib/adapter/vanilla'
// Here, 'Skeletor' is a domNode ready to be injected inside the document ...
const { Skulletor } = skulletor([bluePrint()])
dom.appendChild(Skulletor)
import React from 'react'
import skulletor from 'skulletor/lib/adapter/react-hooks'
// ... while here, 'Skeletor' is a React Component.
const { Skulletor } = skulletor([bluePrint()])
ReactDOM.render(
<div>
<Skulletor />
</div>,
dom,
)
import React from 'react'
import skulletor from 'skulletor/lib/adapter/react'
// Same as React Hooks, this Skulletor is a React Component.
const { Skulletor } = skulletor([bluePrint()])
ReactDOM.render(
<div>
<Skulletor />
</div>,
dom,
)
SkulletorJS provides some basic shapes sufficient to satisfy common needs. (To implement custom shapes, please refer to chapter 'Raw CSS' or 'Going further'). Shape creation is very simple, each of them are functions with predefined and comprehensive parameters (fontSize, width etc.).
There are four basic shapes : rectangle, line, circle and square (square is equal to rectangle but use only size instead of width / height params).
import { rectangle, line, circle, square } from 'skulletor/lib/shapes'
const white = { r: 255, g: 255, b: 255, a: 1 }
const authorIcon = circle({ radius: 35, left: 15, top: 15, color: white })
const photo = rectangle({ height: '185px' })
const title = line({ fontSize: 22, width: '180px', topGap: 20, left: 20 })
const bluePrint = [authorIcon, photo, title]
The blueprint order is important :
whiteIcon
shape will overlap the greyRectangle
.const bluePrint = [
whiteIcon, // Will be on top if shapes should overlap.
greyRectangle,
...
]
topGap
and/or leftGap
properties. Those values are relative to the previous object defined in the blueprint.const bluePrint = [
rectangle({ height: '185px' }),
line({ fontSize: 22, topGap: 20 }), // Will be positioned 20px after the rectangle.
...
]
const bluePrint = [
rectangle({ height: '185px' }),
line({ fontSize: 22, topGap: -22, leftGap: 20 }), // Will be positioned 20px next to the rectangle. Note the use of topGap with a negative number so the line removes its heights in the gaping
...
]
SkulletorJS uses a simple middleware system to improve itself.
Some of them are adapter-specific like applyFadeOut
while others are generic.
N.B. : The base skulletor function uses 3 middlewares, but you can change this by calling the skulletorFactory
function used to generate your own "skulletor" function.
import { skulletorFactory, applyFadeOut } from 'skulletor/lib/adapter/vanilla'
import { applyBaseCSS, applyAnimation } from 'skulletor/lib/middlewares'
// Generate your own skulletor function with some middlewares.
const mySkulletor = skulletorFactory([applyBaseCSS(), applyAnimation(), applyFadeOut()])
const { Skulletor } = mySkulletor([bluePrint()])
When applying the middleware applyAnimation
, the laser ray style animation is applied on our skeleton :
It's possible to provide your own middlewares (refer to "going further" section).
N.B. : Middlewares are functions that will be handlded by the middlewareHandler. Provided middlewares are generators so you can custom them as follows.
// Custom fadeOut duration and timing function
const mySkulletor = skulletorFactory([applyBaseCSS(), applyAnimation(), applyFadeOut({ time: '0.8s', timingFunction: 'ease-out' })])
SkulletorJS provides control capabilites which can differ greatly between the Vanilla and the React adapter. This chapter focuses on the Vanilla version (the React version will be explained in the next chapter with a full example).
import skulletor from 'skulletor/lib/adapter/vanilla'
const { Skulletor, end } = skulletor([bluePrint()])
const dom = document.getElementById('root')
dom.appendChild(Skulletor)
// The skeleton will end after 2 seconds, and when it disapears, display a text.
setTimeout(() => {
end().then(() => {
dom.innerText = 'Loading finish !'
})
}, 2000)
Be careful, end
and disapear
are two different concepts.
When end
is called, the skeletor is asked to finish, but the promise will only be resolved when all middlewares release.
For instance, with applyFadeOut
middleware, the skeleton loader could end but will disapear only when fadeout is terminated.
import React, { Fragment, Component } from 'react'
import ReactDOM from 'react-dom'
import skulletor from 'skulletor/lib/adapter/react'
import { rectangle, line, circle } from 'skulletor/lib/shapes'
const bluePrint = () => [
{
width: [35, '%'],
height: [365, 'px'],
},
circle({ radius: 35, left: 15, top: 15, color: { r: 255, g: 255, b: 255, a: 1 } }),
rectangle({ height: [185, 'px'] }),
line({ fontSize: 22, width: [180, 'px'], topGap: 20, left: 20 }),
line({ fontSize: 22, width: [120, 'px'], topGap: 20, left: 20 }),
line({ fontSize: 36, width: [150, 'px'], topGap: 20, left: 20 }),
]
const { Skulletor } = skulletor([bluePrint()])
class App extends Component {
state = {
isLoading: true,
displayFinishMessage: false,
}
componentDidMount() {
setTimeout(() => this.setState({ isLoading: false }), 2000)
}
render() {
const { isLoading, displayFinishMessage } = this.state
return (
<Fragment>
<Skulletor end={!isLoading} onDisapear={() => this.setState({ displayFinishMessage: true })} />
{displayFinishMessage && 'Loading finish !'}
</Fragment>
)
}
}
ReactDOM.render(<App />, document.getElementById('root'))
You can provide media queries in order to handle responsive skeletons :
const bluePrintSmall = () => [ ... ]
const bluePrintLarge = () => [ ... ]
const { Skulletor } = skulletor({
'max-width: 639px': [bluePrintSmall(), bluePrintSmall()],
'min-width: 640px': [bluePrintLarge(), bluePrintLarge()],
})
FAQs
SkeletorJS is a Javascript library that allow you to ease your skeleton loading screen creation. It use predefined shapes you can configure and compose to create more complex skeleton.
The npm package skulletor receives a total of 142 weekly downloads. As such, skulletor popularity was classified as not popular.
We found that skulletor demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.