Customize a UI component
A component can work correctly and still look pasted onto a page. Matching the accent color is only one part of the job. Compare its surfaces, text, spacing, focus, and selected state with the surrounding interface, then make a small set of deliberate changes.
// glass-generate · original package example
{
// Explicit offline demonstration. No backend operation is performed.
// For an application: use .mount(element, { onChange, onSubmit, ... }) instead.
const initialScene = "pastel";
const host = document.querySelector('[data-glass-more="glass-generate"]');
void(async()=>{const response=await fetch(new URL('./buttons.css',document.baseURI));if(!response.ok)throw Error('Styles unavailable');const cssText=await response.text();const controller = globalThis.SLGlassMore["glass-generate"].mountPreview(host, {scene:initialScene,cssText,assetBase:new URL('./',document.baseURI)});
window.addEventListener('pagehide', event => { if(!event.persisted) controller.destroy(); });})();
}
// glass-share · original package example
{
// Explicit offline demonstration. No backend operation is performed.
// For an application: use .mount(element, { onChange, onSubmit, ... }) instead.
const initialScene = "pastel";
const host = document.querySelector('[data-glass-more="glass-share"]');
void(async()=>{const response=await fetch(new URL('./buttons.css',document.baseURI));if(!response.ok)throw Error('Styles unavailable');const cssText=await response.text();const controller = globalThis.SLGlassMore["glass-share"].mountPreview(host, {scene:initialScene,cssText,assetBase:new URL('./',document.baseURI)});
window.addEventListener('pagehide', event => { if(!event.persisted) controller.destroy(); });})();
}Interactive demo. No data is sent.
Read the surrounding interface
Place the component where it will actually be used before judging its style. A control on a product photo faces different contrast conditions from a control inside a settings panel. Look at neighboring labels, the content hierarchy, and the available space. The component should feel connected to that specific part of the page.
Collect the project’s existing font family, text sizes, spacing, corner radii, and surface colors. Use those values before introducing new ones. If every card has a quiet border, an isolated heavy shadow may make the button look unrelated. Keep one clear visual hierarchy between a primary action and supporting controls.
Map colors by their role
Name what a color does: surface, text, border, accent, focus, success, or error. CSS custom properties give those roles reusable values. Mapping roles is safer than replacing every occurrence of a hex code, because two identical source colors may serve different purposes and need to diverge in your target design.
Start by changing a small group of tokens together. Check foreground and background as a pair, including icon strokes and muted labels. A dark button switched to a light surface also needs a suitable text color. Keep error and success meanings clear, and use wording or an icon alongside the color.
.component {
--surface: #252a32;
--text: #ffffff;
--border: #3f4857;
--focus: #748bb8;
--radius: 12px;
}Match type and spacing carefully
Use the page’s typography to connect a component to its surroundings. Compare font weight, line height, and label size at normal zoom. A similar-looking fallback font can still change the width of a button. Wait for the real font to load when checking alignment, and try the longest expected label.
Adjust outer spacing separately from the internal layout. You can move a component into the right row without changing the relationship between its icon and text. Preserve enough space for the focus ring, opened content, and a touch interaction. Test a translated label before reducing padding to make one English word fit.
Check every visible state
Review the adapted component at rest, on hover, with keyboard focus, while pressed, and when selected or disabled. If it waits for an operation, include pending and error states. Changing the base surface can expose an inherited hover rule that turns the text invisible. A screenshot of the resting state will miss that failure.
Place the preview against its real background and check at narrow widths. If a panel opens, verify its borders, text, layering, and close behavior too. Keep the original interaction intact while adapting the visual tokens. The educational palette example on this page changes local appearance only; it does not rewrite or download a library package.
Keep adaptation separate from behavior
In SL UI Library, inspect the component and take its complete package when moving into a project. Its React and Next.js entry files use the original controller, with neighboring styles and support files where required. Keep those dependencies together, then adapt the documented tokens rather than rebuilding the behavior from a screenshot.
For an AI-assisted change, ask the agent to preserve labels, keyboard interaction, reduced motion, and the action handler while mapping the visual roles. Review the diff and the rendered page. Record the actual color and spacing changes so another developer can continue the work without guessing which parts came from the library.
Reference documentation
Technical documentation behind these examples. You can use the article without opening these links.