### Install Dependencies and Run Development Server (Bash)
Source: https://github.com/z1code/glass-refraction/blob/master/CONTRIBUTING.md
This snippet shows how to clone the glass-refraction repository, navigate into the project directory, install necessary dependencies using npm, and start the development server in watch mode.
```bash
git clone https://github.com/moeez-shabbir/glass-refraction.git
cd glass-refraction
npm install
npm run dev # watch mode
```
--------------------------------
### Install glass-refraction Package
Source: https://github.com/z1code/glass-refraction/blob/master/README.md
This snippet shows the command to install the glass-refraction package using npm. It's a prerequisite for using the library in your project.
```bash
npm install glass-refraction
```
--------------------------------
### Full Application Example with Glass Components (React/TSX)
Source: https://context7.com/z1code/glass-refraction/llms.txt
A comprehensive example demonstrating the integration of various glass-refraction components (GlassFilters, Glass, GlassCard, GlassPill) within a full-page application layout. It showcases navigation, hero sections, feature cards, and tag displays with glass effects.
```tsx
"use client";
import { GlassFilters, Glass, GlassCard, GlassPill } from 'glass-refraction';
export default function GlassDemo() {
const features = [
{
title: 'SVG Refraction',
description: 'Uses feTurbulence and feDisplacementMap for realistic light bending effects.'
},
{
title: 'Chromatic Dispersion',
description: 'Rainbow edge tinting simulates light wavelength separation through glass.'
},
{
title: 'Specular Highlights',
description: 'Animated breathing highlights mimic overhead light reflections.'
},
];
const tags = ['React', 'CSS', 'SVG Filters', 'Liquid Glass', 'TypeScript'];
return (
{/* Mount SVG refraction filters once */}
{/* Navigation */}
Glass App
Beautiful frosted glass effects for modern web applications
{/* Feature Cards */}
{features.map((feature, index) => (
{feature.title}
{feature.description}
))}
{/* Tags Section */}
{tags.map((tag) => (
{tag}
))}
{/* Footer */}
Built with glass-refraction — MIT License
);
}
```
--------------------------------
### GlassPill Component Examples (React/TSX)
Source: https://context7.com/z1code/glass-refraction/llms.txt
Demonstrates the usage of the GlassPill component for rendering tags, badges, and inline elements. It shows basic rendering, creating lists of tags, and using the polymorphic 'as' prop to render pills as buttons or links.
```tsx
import { GlassPill } from 'glass-refraction';
// Basic pill/tag
function BasicPill() {
return (
React
);
}
// Tag list
function TagList() {
const tags = ['React', 'TypeScript', 'Next.js', 'CSS', 'SVG'];
return (
{tags.map((tag) => (
{tag}
))}
);
}
// Polymorphic pill as button
function PillButton() {
return (
console.log('clicked')}
className="px-4 py-2 cursor-pointer"
>
Click me
);
}
// Pill as link
function PillLink() {
return (
React
);
}
```
--------------------------------
### Build Project for Production (Bash)
Source: https://github.com/z1code/glass-refraction/blob/master/CONTRIBUTING.md
This command builds the glass-refraction project for production. The output, including compiled CSS and JavaScript, will be placed in the `dist/` directory.
```bash
npm run build
```
--------------------------------
### Apply glass-refraction CSS Classes to HTML Elements
Source: https://github.com/z1code/glass-refraction/blob/master/README.md
Shows how to apply the predefined CSS classes from the glass-refraction library to standard HTML elements to achieve different glass effects.
```html
Content card
Badge
```
--------------------------------
### Import CSS Stylesheet for glass-refraction
Source: https://github.com/z1code/glass-refraction/blob/master/README.md
Demonstrates how to import the glass-refraction CSS stylesheet. This can be done directly in CSS or within JavaScript/TypeScript files to enable the glass effects.
```css
@import 'glass-refraction/css';
```
```javascript
import 'glass-refraction/css';
```
--------------------------------
### React Usage of glass-refraction Components
Source: https://github.com/z1code/glass-refraction/blob/master/README.md
Illustrates how to use the React components provided by the glass-refraction library. It includes importing components and rendering them within a React application. React components automatically handle CSS imports.
```tsx
import { GlassFilters, Glass, GlassCard, GlassPill } from 'glass-refraction';
export default function App() {
return (
<>
Navbar
Card title
Card content
Tag
>
);
}
```
--------------------------------
### Theming glass-refraction CSS Custom Properties
Source: https://github.com/z1code/glass-refraction/blob/master/README.md
Demonstrates how to theme the glass-refraction components by overriding CSS custom properties. This allows customization of blur, saturation, border radius, background, chromatic dispersion, and animation timings.
```css
:root {
/* Blur */
--gr-blur: 26px;
--gr-blur-card: 20px;
--gr-blur-pill: 8px;
/* Saturation */
--gr-saturation: 1.7;
--gr-saturation-card: 1.5;
--gr-saturation-pill: 1.3;
/* Border radius */
--gr-radius: 20px;
--gr-radius-card: 16px;
--gr-radius-pill: 9999px;
/* Base background */
--gr-bg-start: rgba(18, 22, 35, 0.48);
--gr-bg-end: rgba(12, 16, 28, 0.42);
/* Chromatic dispersion */
--gr-chromatic-blue: rgba(0, 180, 255, 0.045);
--gr-chromatic-violet: rgba(120, 80, 255, 0.04);
--gr-chromatic-pink: rgba(255, 100, 200, 0.035);
--gr-chromatic-green: rgba(100, 255, 180, 0.025);
/* Animation timing */
--gr-shimmer-duration: 7s;
--gr-specular-duration: 5s;
}
```
--------------------------------
### Apply Dense Frosted Glass Effect (CSS)
Source: https://context7.com/z1code/glass-refraction/llms.txt
Applies the dense frosted glass effect using the `.glass` CSS class. This effect is ideal for navigation bars, footers, and hero overlays, providing rich visual depth with animations and chromatic dispersion. It requires importing the library's CSS.
```html
```
```javascript
import 'glass-refraction/css';
```
--------------------------------
### Apply Lightweight Glass Effect (CSS)
Source: https://context7.com/z1code/glass-refraction/llms.txt
Applies a subtle frosted glass effect with a hover brighten effect using the `.glass-pill` CSS class. This is designed for inline elements like tags and badges, offering minimal blur and a gentle visual enhancement on interaction.
```html
ReactTypeScriptCSSSVG Filters
```
--------------------------------
### Apply Medium-Density Glass Effect with Hover (.glass-card)
Source: https://github.com/z1code/glass-refraction/blob/master/examples/vanilla/index.html
Implements a medium-density glass effect for cards, including a hover lift effect, a specular top-edge line, and chromatic edges that appear on hover. This CSS is designed for card elements.
```css
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1.5rem; width: 100%; max-width: 800px; }
.glass-card { padding: 1.5rem; }
.glass-card h3 { margin-bottom: 0.5rem; }
.glass-card p { opacity: 0.7; font-size: 0.9rem; line-height: 1.5; }
```
--------------------------------
### Create Polymorphic Glass Elements (TSX)
Source: https://context7.com/z1code/glass-refraction/llms.txt
A polymorphic wrapper component that renders a `.glass` element, allowing it to be rendered as any HTML element type using the `as` prop. It supports basic usage and various element types like nav, header, section, and footer, along with variant overrides.
```tsx
import { Glass } from 'glass-refraction';
// Basic usage - renders as div by default
function BasicGlass() {
return (
Content inside glass container
);
}
// Polymorphic usage - render as different elements
function PolymorphicGlass() {
return (
<>
{/* Navigation bar */}
LogoMenu
{/* Header element */}
Card content with hover lift effect and chromatic edge highlighting.
Static Card
No hover animation on this card.
```
--------------------------------
### Customize Glass Appearance with CSS Variables
Source: https://context7.com/z1code/glass-refraction/llms.txt
Allows customization of the glass effect's appearance by overriding CSS custom properties defined on the `:root`. Properties control blur intensity, color saturation, border radius, background gradients, chromatic edge colors, and animation timings. Custom themes can be applied by creating new CSS classes.
```css
:root {
/* Blur intensity for each tier */
--gr-blur: 26px;
--gr-blur-card: 20px;
--gr-blur-pill: 8px;
/* Color saturation boost */
--gr-saturation: 1.7;
--gr-saturation-card: 1.5;
--gr-saturation-pill: 1.3;
/* Border radius */
--gr-radius: 20px;
--gr-radius-card: 16px;
--gr-radius-pill: 9999px;
/* Base background gradient colors */
--gr-bg-start: rgba(18, 22, 35, 0.48);
--gr-bg-end: rgba(12, 16, 28, 0.42);
/* Chromatic dispersion edge colors */
--gr-chromatic-blue: rgba(0, 180, 255, 0.045);
--gr-chromatic-violet: rgba(120, 80, 255, 0.04);
--gr-chromatic-pink: rgba(255, 100, 200, 0.035);
--gr-chromatic-green: rgba(100, 255, 180, 0.025);
/* Animation timing */
--gr-shimmer-duration: 7s;
--gr-specular-duration: 5s;
}
/* Example: Custom theme with faster animations and more blur */
.my-custom-glass {
--gr-blur: 32px;
--gr-shimmer-duration: 4s;
--gr-bg-start: rgba(30, 40, 60, 0.5);
--gr-bg-end: rgba(20, 30, 50, 0.45);
}
```
--------------------------------
### Apply Dense Frosted Glass Effect (.glass)
Source: https://github.com/z1code/glass-refraction/blob/master/examples/vanilla/index.html
Applies a dense frosted glass effect to an element, featuring an animated shimmer, specular highlights, and chromatic edge dispersion. This CSS is intended for direct use in HTML.
```css
*, *::before, *::after { box-sizing: border-box; margin: 0; }
body { min-height: 100vh; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; color: #e2e8f0; background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #0f172a 100%); display: flex; flex-direction: column; align-items: center; gap: 2rem; padding: 2rem; }
/* SVG refraction filters (inline for vanilla usage) */
.sr-only { position: absolute; width: 0; height: 0; overflow: hidden; }
nav.glass { width: 100%; max-width: 800px; padding: 1rem 2rem; display: flex; justify-content: space-between; align-items: center; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1.5rem; width: 100%; max-width: 800px; }
.glass-card { padding: 1.5rem; }
.glass-card h3 { margin-bottom: 0.5rem; }
.glass-card p { opacity: 0.7; font-size: 0.9rem; line-height: 1.5; }
.pills { display: flex; gap: 0.75rem; flex-wrap: wrap; justify-content: center; }
.glass-pill { padding: 0.35rem 1rem; font-size: 0.85rem; }
footer.glass { width: 100%; max-width: 800px; padding: 1rem 2rem; text-align: center; font-size: 0.85rem; opacity: 0.7; }
```
--------------------------------
### Apply Lightweight Frosted Pill Effect (.glass-pill)
Source: https://github.com/z1code/glass-refraction/blob/master/examples/vanilla/index.html
Provides a lightweight frosted glass effect suitable for tags, badges, or inline elements. This CSS styles elements with the class 'glass-pill' for a subtle frosted appearance.
```css
.pills { display: flex; gap: 0.75rem; flex-wrap: wrap; justify-content: center; }
.glass-pill { padding: 0.35rem 1rem; font-size: 0.85rem; }
```
--------------------------------
### Applying SVG Refraction Filters (React/TSX)
Source: https://context7.com/z1code/glass-refraction/llms.txt
Shows how to apply SVG refraction effects to HTML elements using the `` component and CSS `filter` property. It demonstrates subtle and strong refraction effects on images and div elements.
```tsx
import { GlassFilters } from 'glass-refraction';
function RefractionDemo() {
return (
<>
{/* Subtle refraction on images */}
{/* Strong refraction for hero elements */}
Hero Content
>
);
}
/* CSS approach */
/*
.refracted {
filter: url(#glass-refract);
}
.refracted-strong {
filter: url(#glass-refract-strong);
}
*/
```
--------------------------------
### Apply SVG Refraction Filters using CSS
Source: https://github.com/z1code/glass-refraction/blob/master/README.md
This CSS snippet shows how to apply the SVG refraction filters generated by the `` React component to elements. It uses the `filter` property with URLs pointing to the filter IDs.
```css
.refracted { filter: url(#glass-refract); }
.refracted-strong { filter: url(#glass-refract-strong); }
```
--------------------------------
### Render Glass Refraction Filters (TSX)
Source: https://context7.com/z1code/glass-refraction/llms.txt
Provides two SVG refraction filters (`#glass-refract` and `#glass-refract-strong`) that can be placed once at the application root. It accepts custom configuration props for scale, base frequency, octaves, and seed.
```tsx
import { GlassFilters } from 'glass-refraction';
export default function App() {
return (
<>
{/* Mount filters once at app root */}
{/* Your app content */}
>
);
}
// With custom configuration
function CustomFilters() {
return (
);
}
```
--------------------------------
### Create Glass Content Cards (TSX)
Source: https://context7.com/z1code/glass-refraction/llms.txt
A medium-density glass component designed for content cards and panels, featuring a default hover lift effect that can be disabled. It supports polymorphic rendering as other HTML elements and can be used in various layouts like grids.
```tsx
import { GlassCard } from 'glass-refraction';
// Basic card with hover effect
function BasicCard() {
return (
Card Title
Card content with automatic hover lift and chromatic edge effects.
);
}
// Static card without hover effects
function StaticCard() {
return (
Static Card
This card does not lift on hover.
);
}
// Polymorphic card as article element
function ArticleCard() {
return (
Blog Post Title
Article excerpt goes here...
);
}
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.