Skip to main content

CSS Custom Properties

The library uses CSS custom properties (CSS variables) for theming. Override these variables to customize the appearance:
:root {
  /* Colors */
  --primary-color: #007bff;
  --primary-hover: #0056b3;
  --secondary-color: #6c757d;
  --secondary-hover: #545b62;
  --danger-color: #dc3545;
  --success-color: #28a745;
  --warning-color: #ffc107;
  --info-color: #17a2b8;
  
  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  
  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  
  /* Borders */
  --border-radius: 0.375rem;
  --border-width: 1px;
  --border-color: #dee2e6;
}

Custom Theme Example

Create a custom theme by overriding variables:
/* theme.css */
:root {
  --primary-color: #8b5cf6;
  --primary-hover: #7c3aed;
  --border-radius: 0.5rem;
  --font-family: 'Inter', sans-serif;
}
Import your theme after the library styles:
import '@abdalkader/component-library/dist/styles.css';
import './theme.css';

Dark Mode

Implement dark mode using CSS variables:
/* Dark mode theme */
[data-theme='dark'] {
  --primary-color: #3b9eff;
  --primary-hover: #007bff;
  --dark-color: #f8f9fa;
  --light-color: #343a40;
  --border-color: #495057;
}
Toggle dark mode in your app:
function App() {
  const [theme, setTheme] = useState('light');
  
  useEffect(() => {
    document.documentElement.setAttribute('data-theme', theme);
  }, [theme]);
  
  return (
    <div>
      <Button onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')}>
        Toggle Theme
      </Button>
    </div>
  );
}

Component-Specific Styling

Override styles for specific components:
/* Custom button styles */
.btn--primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
}

.btn--primary:hover {
  background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
}

Scoped Theming

Apply different themes to different parts of your app:
<div style={{ '--primary-color': '#e91e63' }}>
  <Button variant="primary">Pink Button</Button>
</div>

<div style={{ '--primary-color': '#4caf50' }}>
  <Button variant="primary">Green Button</Button>
</div>

Available Variables

Colors

VariableDefaultDescription
--primary-color#007bffPrimary brand color
--primary-hover#0056b3Primary hover state
--secondary-color#6c757dSecondary color
--danger-color#dc3545Danger/error color
--success-color#28a745Success color

Typography

VariableDefaultDescription
--font-familySystem fontsFont family
--font-size-base1remBase font size
--font-weight-medium500Medium font weight
--line-height-base1.5Base line height

Spacing

VariableDefaultDescription
--spacing-xs0.25remExtra small spacing
--spacing-sm0.5remSmall spacing
--spacing-md1remMedium spacing
--spacing-lg1.5remLarge spacing

Borders

VariableDefaultDescription
--border-radius0.375remBorder radius
--border-width1pxBorder width
--border-color#dee2e6Border color

Best Practices

Define colors based on their purpose (primary, danger) rather than their appearance (blue, red).
Ensure text and interactive elements meet WCAG AA standards (4.5:1 for normal text).
If implementing dark mode, test all components in both light and dark themes.
Use rem/em for spacing and sizing to support user font size preferences.

Examples