UNPKG

@asafarim/react-themes

Version:

A comprehensive theme management system for React applications with automatic dark/light mode detection, custom theme creation, and smooth transitions.

181 lines (155 loc) 6.73 kB
/* @asafarim/react-themes - CSS Variables and Base Styles */ /* Theme CSS Variables - Auto-applied by the ThemeProvider */ :root { /* Colors */ --theme-color-background: var(--theme-color-background, #ffffff); --theme-color-background-secondary: var(--theme-color-background-secondary, #f8fafc); --theme-color-background-tertiary: var(--theme-color-background-tertiary, #f1f5f9); --theme-color-text: var(--theme-color-text, #0f172a); --theme-color-text-secondary: var(--theme-color-text-secondary, #475569); --theme-color-text-muted: var(--theme-color-text-muted, #64748b); --theme-color-border: var(--theme-color-border, #e2e8f0); --theme-color-border-light: var(--theme-color-border-light, #f1f5f9); --theme-color-border-hover: var(--theme-color-border-hover, #cbd5e1); --theme-color-primary: var(--theme-color-primary, #3b82f6); --theme-color-primary-hover: var(--theme-color-primary-hover, #2563eb); --theme-color-primary-active: var(--theme-color-primary-active, #1d4ed8); --theme-color-hover: var(--theme-color-hover, #f8fafc); --theme-color-active: var(--theme-color-active, #f1f5f9); --theme-color-focus: var(--theme-color-focus, rgba(59, 130, 246, 0.1)); /* Spacing */ --theme-spacing-xs: var(--theme-spacing-xs, 0.25rem); --theme-spacing-sm: var(--theme-spacing-sm, 0.5rem); --theme-spacing-md: var(--theme-spacing-md, 1rem); --theme-spacing-lg: var(--theme-spacing-lg, 1.5rem); --theme-spacing-xl: var(--theme-spacing-xl, 2rem); --theme-spacing-2xl: var(--theme-spacing-2xl, 3rem); --theme-spacing-3xl: var(--theme-spacing-3xl, 4rem); --theme-spacing-4xl: var(--theme-spacing-4xl, 6rem); /* Border Radius */ --theme-radius-none: var(--theme-radius-none, 0); --theme-radius-sm: var(--theme-radius-sm, 0.25rem); --theme-radius-md: var(--theme-radius-md, 0.375rem); --theme-radius-lg: var(--theme-radius-lg, 0.5rem); --theme-radius-xl: var(--theme-radius-xl, 0.75rem); --theme-radius-2xl: var(--theme-radius-2xl, 1rem); --theme-radius-full: var(--theme-radius-full, 9999px); /* Typography */ --theme-font-family-sans: var(--theme-font-family-sans, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif); --theme-font-family-serif: var(--theme-font-family-serif, ui-serif, Georgia, Cambria, "Times New Roman", Times, serif); --theme-font-family-mono: var(--theme-font-family-mono, ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace); /* Font Sizes */ --theme-font-size-xs: var(--theme-font-size-xs, 0.75rem); --theme-font-size-sm: var(--theme-font-size-sm, 0.875rem); --theme-font-size-base: var(--theme-font-size-base, 1rem); --theme-font-size-lg: var(--theme-font-size-lg, 1.125rem); --theme-font-size-xl: var(--theme-font-size-xl, 1.25rem); --theme-font-size-2xl: var(--theme-font-size-2xl, 1.5rem); --theme-font-size-3xl: var(--theme-font-size-3xl, 1.875rem); --theme-font-size-4xl: var(--theme-font-size-4xl, 2.25rem); --theme-font-size-5xl: var(--theme-font-size-5xl, 3rem); /* Transitions */ --theme-transition-fast: var(--theme-transition-fast, 150ms ease); --theme-transition-normal: var(--theme-transition-normal, 250ms ease); --theme-transition-slow: var(--theme-transition-slow, 350ms ease); --theme-transition-bounce: var(--theme-transition-bounce, 250ms cubic-bezier(0.68, -0.55, 0.265, 1.55)); /* Z-Index */ --theme-z-index-dropdown: var(--theme-z-index-dropdown, 1000); --theme-z-index-modal: var(--theme-z-index-modal, 1050); --theme-z-index-tooltip: var(--theme-z-index-tooltip, 1100); --theme-z-index-overlay: var(--theme-z-index-overlay, 1200); } /* Optional Base Styles */ .theme-base { font-family: var(--theme-font-family-sans); font-size: var(--theme-font-size-base); color: var(--theme-color-text); background-color: var(--theme-color-background); transition: color var(--theme-transition-normal), background-color var(--theme-transition-normal); } /* Theme Toggle Button Styles */ .theme-toggle { display: inline-flex; align-items: center; justify-content: center; padding: var(--theme-spacing-sm) var(--theme-spacing-md); border: 1px solid var(--theme-color-border); border-radius: var(--theme-radius-md); background-color: var(--theme-color-background); color: var(--theme-color-text); cursor: pointer; transition: all var(--theme-transition-normal); font-size: var(--theme-font-size-sm); font-weight: 500; } .theme-toggle:hover { background-color: var(--theme-color-hover); border-color: var(--theme-color-border-hover); } .theme-toggle:focus { outline: none; background-color: var(--theme-color-hover); border-color: var(--theme-color-primary); box-shadow: 0 0 0 3px var(--theme-color-focus); } /* Theme Selector Styles */ .theme-selector { padding: var(--theme-spacing-sm) var(--theme-spacing-md); border: 1px solid var(--theme-color-border); border-radius: var(--theme-radius-md); background-color: var(--theme-color-background); color: var(--theme-color-text); font-size: var(--theme-font-size-sm); transition: all var(--theme-transition-normal); } .theme-selector:focus { outline: none; border-color: var(--theme-color-primary); box-shadow: 0 0 0 3px var(--theme-color-focus); } /* Utility Classes */ .theme-bg-primary { background-color: var(--theme-color-background); } .theme-bg-secondary { background-color: var(--theme-color-background-secondary); } .theme-text-primary { color: var(--theme-color-text); } .theme-text-secondary { color: var(--theme-color-text-secondary); } .theme-text-muted { color: var(--theme-color-text-muted); } .theme-border { border: 1px solid var(--theme-color-border); } .theme-rounded { border-radius: var(--theme-radius-md); } .theme-shadow { box-shadow: var(--theme-color-shadow, 0 1px 3px 0 rgba(0, 0, 0, 0.1)); } /* Dark mode body class support */ body.theme-dark { color-scheme: dark; } body.theme-light { color-scheme: light; } /* Smooth transitions for theme changes */ * { transition: background-color var(--theme-transition-normal), color var(--theme-transition-normal), border-color var(--theme-transition-normal); } /* Remove transitions for users who prefer reduced motion */ @media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; } }