Skip to content

Commit 43c7163

Browse files
committed
add some basic generated documentation for some util methods
1 parent 33375fc commit 43c7163

File tree

3 files changed

+58
-9
lines changed

3 files changed

+58
-9
lines changed

src/ui/lib/layouts/helpers/ContentCenterer.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,23 @@ type HasChildren = {
66
children: ReactNode;
77
};
88

9+
/**
10+
* Helper function that returns appropriate padding based on breakpoint.
11+
*
12+
* @param breakpoint - The current MUI breakpoint name
13+
* @returns Padding value as a CSS string
14+
*/
915
const getPaddingForBreakpoint = (breakpoint: string) =>
1016
breakpoint === 'xs' ? '16px' : '32px';
1117

18+
/**
19+
* Component that centers content with responsive padding and max-width constraints.
20+
*
21+
* Automatically adjusts padding and max-width based on the current screen size
22+
* using MUI breakpoints for optimal display across devices.
23+
*
24+
* @param children - React nodes to be centered and constrained
25+
*/
1226
export const ContentCenterer = ({ children }: HasChildren) => {
1327
const breakpoint = useCurrentBreakpoint();
1428
const padding = getPaddingForBreakpoint(breakpoint);
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { useMediaQuery, useTheme } from '@mui/material';
22

3+
/**
4+
* Custom hook that returns the current MUI breakpoint based on screen width.
5+
*
6+
* Uses Material-UI's breakpoint system to determine which breakpoint matches
7+
* the current viewport size.
8+
*
9+
* @returns {'xs' | 'sm' | 'md' | 'lg' | 'xl'} The current breakpoint name
10+
*/
311
export function useCurrentBreakpoint() {
412
const theme = useTheme();
513
const isXs = useMediaQuery(theme.breakpoints.only('xs'));
@@ -10,18 +18,14 @@ export function useCurrentBreakpoint() {
1018

1119
if (isXs) {
1220
return 'xs';
13-
}
14-
if (isSm) {
21+
} else if (isSm) {
1522
return 'sm';
16-
}
17-
if (isMd) {
23+
} else if (isMd) {
1824
return 'md';
19-
}
20-
if (isLg) {
25+
} else if (isLg) {
2126
return 'lg';
22-
}
23-
if (isXl) {
27+
} else if (isXl) {
2428
return 'xl';
2529
}
26-
return 'xl';
30+
return 'xs';
2731
}

src/ui/lib/utils/ColorHelper.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,36 @@
1+
/**
2+
* Converts a hex color string to RGB values.
3+
*
4+
* @param hex - Hex color string (e.g., "#FF5733")
5+
* @returns Object with r, g, b numeric values
6+
*/
17
function hexToRGB(hex: string) {
28
const r = parseInt(hex.slice(1, 3), 16);
39
const g = parseInt(hex.slice(3, 5), 16);
410
const b = parseInt(hex.slice(5, 7), 16);
511
return { r, g, b };
612
}
713

14+
/**
15+
* Converts RGB values to a hex color string.
16+
*
17+
* @param r - Red value (0-255)
18+
* @param g - Green value (0-255)
19+
* @param b - Blue value (0-255)
20+
* @returns Hex color string (e.g., "#FF5733")
21+
*/
822
function rgbToHex(r: number, g: number, b: number) {
923
return '#' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
1024
}
1125

26+
/**
27+
* Blends two hex colors by a specified step amount.
28+
*
29+
* @param colorA - First hex color
30+
* @param colorB - Second hex color
31+
* @param step - Blend ratio (0 = colorA, 1 = colorB)
32+
* @returns Blended hex color
33+
*/
1234
function mixColors(colorA: string, colorB: string, step: number) {
1335
const colorARGB = hexToRGB(colorA);
1436
const colorBRGB = hexToRGB(colorB);
@@ -23,6 +45,15 @@ function mixColors(colorA: string, colorB: string, step: number) {
2345
const NEURAL_WHITE = '#FFFFFF';
2446
const NEURAL_BLACK = '#0F161F';
2547

48+
/**
49+
* Generates a complete shade palette from a base color.
50+
*
51+
* Creates lighter (W10-W100) and darker (B10-B100) variations by mixing
52+
* the base color with neural white and black at different ratios.
53+
*
54+
* @param color - Base hex color to generate shades from
55+
* @returns Object mapping shade keys to hex color values
56+
*/
2657
export const generateShades = (color: string) => {
2758
const shades: { [key: string]: string } = { '0': color };
2859
for (let i = 1; i <= 9; i++) {

0 commit comments

Comments
 (0)