Installation
Requirements
| Environment | Minimum version |
|---|---|
| Node.js | 18+ |
vue | 3.0.0+ (optional — only for css-magic-gradient/vue) |
react | 17.0.0+ (optional — only for css-magic-gradient/react) |
The core entry point (css-magic-gradient) never requires vue or react — only the /vue and /react subpaths do, and only when you actually import them.
Installation
bash
npm install css-magic-gradientOptional peer dependencies — install only what you need:
bash
npm install vue@>=3.0.0 # required for Vue hooks
npm install react@>=17.0.0 # required for React hooksQuick start
Vanilla TypeScript:
ts
import { createLinearGradient, sunsetGradient } from 'css-magic-gradient'
const gradient = createLinearGradient('#3498db', { direction: 'to right' })
// → 'linear-gradient(to right, #5faee3, #3498db)'
document.body.style.background = sunsetGradientVue 3:
vue
<script setup lang="ts">
import { ref } from 'vue'
import { useLinearGradient } from 'css-magic-gradient/vue'
const color = ref('#3498db')
const gradient = useLinearGradient(color, { direction: 'to right', offsetPercent: 20 })
</script>
<template>
<div :style="{ background: gradient }">Hello</div>
</template>React:
tsx
import { useState } from 'react'
import { useLinearGradient } from 'css-magic-gradient/react'
export function Demo() {
const [color, setColor] = useState('#3498db')
const gradient = useLinearGradient(color, { direction: 'to right' })
return <div style={{ background: gradient }}>Hello</div>
}