Usage
Every xeerpe background starts the same way: create a Builder, chain the layers you want and call toStyle(). The result is a plain style object, so it works with any framework that accepts inline styles.
Your first background
Import Builder from the package:
import { Builder } from 'xeerpe'Then describe the background. This example creates a linear gradient that starts with #34d399 and fades into #172554.
const style = new Builder()
.linearGradient({
from: '#34d399',
to: '#172554',
})
.toStyle()toStyle() returns an object with camelCase CSS properties, such as backgroundImage and backgroundPosition. Apply it to any element.
The examples below share this box class. It only gives the element a visible size:
.box {
width: 300px;
height: 100px;
border-radius: 16px;
}React
Pass the object straight to the style prop.
import { Builder } from 'xeerpe'
const DemoComponent = () => {
const xeerpeBackground = new Builder()
.linearGradient({
from: '#34d399',
to: '#172554',
})
.toStyle()
return <div className="box" style={xeerpeBackground} />
}
export default DemoComponentVue
Bind the object to :style.
<script setup lang="ts">
import { Builder } from 'xeerpe'
const xeerpeBackground = new Builder()
.linearGradient({
from: '#34d399',
to: '#172554',
})
.toStyle()
</script>
<template>
<div class="box" :style="xeerpeBackground"></div>
</template>Angular
Bind the object to [style].
import { Component } from '@angular/core'
import { Builder } from 'xeerpe'
@Component({
selector: 'app-demo',
standalone: true,
template: `<div class="box" [style]="xeerpeBackground"></div>`,
})
export class DemoComponent {
xeerpeBackground = new Builder()
.linearGradient({
from: '#34d399',
to: '#172554',
})
.toStyle()
}Vanilla JavaScript
Copy the properties onto the element's style with Object.assign.
import { Builder } from 'xeerpe'
const xeerpeBackground = new Builder()
.linearGradient({
from: '#34d399',
to: '#172554',
})
.toStyle()
const demoComponent = document.createElement('div')
demoComponent.className = 'box'
Object.assign(demoComponent.style, xeerpeBackground)
document.body.appendChild(demoComponent)Note:
toStyle()returns an object, not a CSS string, so assigning it tostyle.cssTextdoes not work.
Next, explore what you can put in the chain, starting with Gradients.
