Styling and Theming
Relevant source files
The following files were used as context for generating this wiki page:The Medical Calculators application employs a modern, consistent styling architecture centered around Tailwind CSS. The design is characterized by a dark theme, responsive layout, and a set of reusable, pre-styled components. This document outlines the core technologies, theming strategy, and implementation details of the application's styling system.
The overall aesthetic is a dark, professional user interface, with a clear visual hierarchy and interactive feedback on elements like buttons and cards.
Sources: README.md, PROJECT_SUMMARY.md, src/app/globals.css
Core Styling Technologies
The project's styling is built upon Tailwind CSS, a utility-first CSS framework. This is supplemented by custom CSS variables for theming and global styles for base layout and typography.
Sources: package.json:20, src/app/globals.css:1
Technology Stack
| Technology | Version | Purpose |
|---|---|---|
tailwindcss | 4 | The primary utility-first CSS framework for styling components. |
@tailwindcss/postcss | 4 | PostCSS plugin for Tailwind CSS. |
next/font | 15.4.5 | Used to import and manage custom fonts (Geist and Geist_Mono). |
Sources: package.json:20-21, src/app/layout.tsx:2
Styling Architecture Flow
The following diagram illustrates how styling assets are processed and applied within the application.
This diagram shows that Tailwind CSS is configured and its base styles are imported into globals.css. The PostCSS process generates the final CSS, which is applied globally by the RootLayout component, and utility classes are used directly within individual React components.
Sources: package.json, src/app/globals.css, src/app/layout.tsx
Theming and Color Palette
The application uses a dark theme defined by a set of custom CSS variables in the :root of src/app/globals.css. This approach allows for consistent color usage across the application and simplifies potential future theming changes.
Sources: src/app/globals.css:3-17, CONTRIBUTING.md:94-107
CSS Color Variables
The core color palette is defined using CSS variables. These variables provide semantic names for colors used throughout the UI.
| Variable | Default Value | Description |
|---|---|---|
--background | #1a202c | Main background color of the application. |
--foreground | #ffffff | Default text color. |
--card | #2d3748 | Background color for card components. |
--card-foreground | #ffffff | Text color inside cards. |
--border | #4a5568 | Color for borders and dividers. |
--input | #2d3748 | Background color for input fields. |
--primary | #63b3ed | Primary accent color for buttons, links, and highlights. |
--primary-foreground | #ffffff | Text color on primary-colored elements. |
--secondary | #4a5568 | Secondary accent color. |
--secondary-foreground | #ffffff | Text color on secondary-colored elements. |
--accent | #2c5282 | An accent color, used for highlighted sections. |
--accent-foreground | #ffffff | Text color on accent-colored elements. |
--muted | #4a5568 | A muted color for less important elements. |
--muted-foreground | #a0aec0 | Text color for muted or placeholder text. |
Sources: src/app/globals.css:4-17, CONTRIBUTING.md:94-107
The following code snippet from globals.css shows the definition of these variables.
/* src/app/globals.css:3-17 */
:root {
--background: #1a202c;
--foreground: #ffffff;
--card: #2d3748;
--card-foreground: #ffffff;
--border: #4a5568;
--input: #2d3748;
--primary: #63b3ed;
--primary-foreground: #ffffff;
--secondary: #4a5568;
--secondary-foreground: #ffffff;
--accent: #2c5282;
--accent-foreground: #ffffff;
--muted: #4a5568;
--muted-foreground: #a0aec0;
}
Global Styles and Fonts
Global styles and font definitions are managed in src/app/globals.css and applied in src/app/layout.tsx.
Base Styles
The body element is styled with the theme's background and foreground colors, and the primary font family is applied.
/* src/app/globals.css:32-39 */
body {
background: var(--background);
color: var(--foreground);
font-family: var(--font-sans), Arial, Helvetica, sans-serif;
min-height: 100vh;
display: flex;
flex-direction: column;
font-size: 16px; /* Base font size for mobile */
}
Sources: src/app/globals.css:32-39
Fonts
The project uses the Geist font family for both sans-serif and monospace text. These are loaded in src/app/layout.tsx and assigned to CSS variables, which are then referenced in globals.css.
// src/app/layout.tsx:5-14
const geistSans = Geist({
variable: "--font-geist-sans",
subsets: ["latin"],
});
const geistMono = Geist_Mono({
variable: "--font-geist-mono",
subsets: ["latin"],
});
These variables are then applied to the <body> element.
// src/app/layout.tsx:24-26
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased h-full`}
>
Sources: src/app/layout.tsx:5-14, 24-26
Custom Global Classes
globals.css also defines custom utility classes for common effects, such as hover transitions on cards and buttons.
.card-hover: Adds a transition and atranslateYtransform on hover to lift the card slightly..btn-hover: Provides a similartranslateYeffect for buttons, along with a box-shadow.
Sources: src/app/globals.css:51-58, 116-121
Component-Level Styling
Components are styled primarily using Tailwind CSS utility classes directly within the TSX files. This co-location of markup and styling is a key feature of the project's development approach.
Sources: CONTRIBUTING.md:109-115, src/app/page.tsx
Example: Calculator Card
The main page (src/app/page.tsx) features cards for each calculator. The styling for these cards is a good example of combining theme colors and Tailwind utilities.
// src/app/page.tsx:181-183
<div className="bg-card border border-border rounded-lg p-6 hover:border-primary/50 transition-all duration-200 cursor-pointer group card-hover"
onClick={() => setActiveCalculator('electrolyte')}>
Here, classes like bg-card and border-border use the custom theme colors, while rounded-lg, p-6, and transition-all are standard Tailwind utilities.
Sources: src/app/page.tsx:181-183
Example: Button Variants
The CONTRIBUTING.md file indicates that Button components have variants like primary and outline. This is demonstrated in src/app/page.tsx where buttons are styled differently based on the active calculator.
// CONTRIBUTING.md:71-76
<Button
onClick={calculate}
variant="primary">
Рассчитать
</Button>
<Button onClick={reset} variant="outline">
Сбросить
</Button>
This implies the Button component has internal logic to map the variant prop to specific CSS classes.
Sources: CONTRIBUTING.md:71-76
Example: Complex Component Styling
More complex components, like the BloodGasAnalysisCalculator, use a combination of grid layouts, custom background gradients, and conditional classes to create a rich user interface.
// src/calculators/BloodGasAnalysisCalculator.tsx:1174-1176
<div className="p-6 bg-gradient-to-br from-slate-800 to-slate-900 rounded-2xl border border-slate-700 shadow-lg">
<h3 className="text-xl lg:text-2xl font-bold text-slate-100 mb-4 text-center">
🔍 Интерпретация
</h3>
This snippet shows the use of Tailwind's gradient, border, and shadow utilities to create a distinct "Interpretation" section.
Sources: src/calculators/BloodGasAnalysisCalculator.tsx:1174-1178
Responsive Design
The application is responsive and adapts to different screen sizes. Media queries are defined in src/app/globals.css to handle mobile-specific adjustments.
Breakpoints and Adjustments
Two main breakpoints are used for mobile devices:
max-width: 768px(tablets and smaller)max-width: 480px(small mobile devices)
The following diagram shows the logic for applying responsive styles.
Key responsive adjustments include:
- Disabling Hover Effects: The
transformon.card-hoveris set tononeon screens smaller than 768px to avoid awkward interactions on touch devices. - Touch-Friendly Targets: Buttons, links, and form elements are given a
min-heightandmin-widthof44pxto ensure they are easy to tap. - Font and Spacing Adjustments: Font sizes for headings and container padding are reduced on smaller screens to optimize content display.
Sources: src/app/globals.css:59-114
Summary
The styling and theming system of the Medical Calculators project is robust and maintainable. It leverages the power of Tailwind CSS for rapid component development, while a centralized theming strategy using CSS variables ensures a consistent look and feel. The dark theme is well-defined, and a thoughtful responsive design ensures a good user experience across all devices. The code demonstrates a clear understanding of modern CSS practices and component-based styling.