baseline-kit 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +127 -105
- package/dist/README.md +127 -105
- package/dist/components/Baseline/Baseline.d.ts +29 -6
- package/dist/components/Box/Box.d.ts +27 -6
- package/dist/components/Config/Config.d.ts +52 -9
- package/dist/components/Guide/Guide.d.ts +37 -13
- package/dist/components/Layout/Layout.d.ts +21 -7
- package/dist/components/Padder/Padder.d.ts +24 -7
- package/dist/components/Spacer/Spacer.d.ts +32 -35
- package/dist/components/Stack/Stack.d.ts +27 -11
- package/dist/components/types.d.ts +1 -1
- package/dist/hooks/useBaseline.d.ts +34 -51
- package/dist/hooks/useConfig.d.ts +0 -5
- package/dist/hooks/useDebug.d.ts +1 -6
- package/dist/hooks/useGuide.d.ts +2 -7
- package/dist/hooks/useMeasure.d.ts +6 -20
- package/dist/hooks/useVirtual.d.ts +0 -5
- package/dist/index.cjs +11 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +1665 -1100
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/theme.css +140 -0
- package/dist/utils/convert.d.ts +0 -5
- package/dist/utils/grid.d.ts +22 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/math.d.ts +26 -5
- package/dist/utils/merge.d.ts +54 -5
- package/dist/utils/parse.d.ts +0 -5
- package/dist/utils/snapping.d.ts +0 -5
- package/dist/utils/ssr.d.ts +33 -0
- package/dist/utils/timing.d.ts +2 -7
- package/package.json +43 -32
|
@@ -1,10 +1,24 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file Padder Component
|
|
3
|
-
* @description Low-level padding management with visual debugging
|
|
4
|
-
* @module components
|
|
5
|
-
*/
|
|
6
1
|
import * as React from 'react';
|
|
2
|
+
import { Variant } from '../types';
|
|
7
3
|
import { IndicatorNode } from '../Spacer';
|
|
4
|
+
import { DebuggingMode } from '@/components';
|
|
5
|
+
type RenderSpacerFn = (width: React.CSSProperties['width'], height: React.CSSProperties['height']) => React.ReactNode;
|
|
6
|
+
type PaddingStyles = {
|
|
7
|
+
paddingBlock?: string;
|
|
8
|
+
paddingInline?: string;
|
|
9
|
+
[key: string]: string | undefined;
|
|
10
|
+
};
|
|
11
|
+
/** Creates default container styles for Padder */
|
|
12
|
+
export declare const createPadderContainerStyles: (width: React.CSSProperties["width"], height: React.CSSProperties["height"], base: number, color: string) => Record<string, string>;
|
|
13
|
+
/** Creates padding styles when spacers are disabled */
|
|
14
|
+
export declare const createDirectPaddingStyles: (enableSpacers: boolean, padding: {
|
|
15
|
+
top: number;
|
|
16
|
+
right: number;
|
|
17
|
+
bottom: number;
|
|
18
|
+
left: number;
|
|
19
|
+
}) => PaddingStyles;
|
|
20
|
+
/** Creates a render function for spacers */
|
|
21
|
+
export declare const createRenderSpacerFn: (variant: Variant | undefined, debugging: DebuggingMode | undefined, indicatorNode?: IndicatorNode) => RenderSpacerFn;
|
|
8
22
|
/**
|
|
9
23
|
* A foundational component that manages consistent padding with visual debugging.
|
|
10
24
|
*
|
|
@@ -51,11 +65,14 @@ import { IndicatorNode } from '../Spacer';
|
|
|
51
65
|
export declare const Padder: React.NamedExoticComponent<{
|
|
52
66
|
/** Render function for custom measurement indicators */
|
|
53
67
|
indicatorNode?: IndicatorNode;
|
|
68
|
+
/** Flag to enable SSR-compatible mode (simplified initial render) */
|
|
69
|
+
ssrMode?: boolean;
|
|
54
70
|
children?: React.ReactNode;
|
|
55
71
|
} & {
|
|
56
|
-
debugging?:
|
|
72
|
+
debugging?: DebuggingMode;
|
|
57
73
|
className?: string;
|
|
58
74
|
style?: React.CSSProperties;
|
|
59
75
|
height?: React.CSSProperties["height"];
|
|
60
76
|
width?: React.CSSProperties["width"];
|
|
61
|
-
} & import("
|
|
77
|
+
} & import("@/components").SpacingProps & React.RefAttributes<HTMLDivElement>>;
|
|
78
|
+
export {};
|
|
@@ -1,55 +1,52 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file Spacer Component
|
|
3
|
-
* @description Flexible spacing element with measurement indicators
|
|
4
|
-
* @module components
|
|
5
|
-
*/
|
|
6
1
|
import * as React from 'react';
|
|
7
2
|
import { ComponentsProps, Variant } from '../types';
|
|
8
|
-
|
|
9
|
-
* Function signature for custom measurement indicators.
|
|
10
|
-
*
|
|
11
|
-
* @param value - The measurement in pixels
|
|
12
|
-
* @param dimension - Which dimension is being measured ('width' | 'height')
|
|
13
|
-
* @returns React node to display as the indicator
|
|
14
|
-
*/
|
|
15
|
-
export type IndicatorNode = (value: number, dimension: 'width' | 'height') => React.ReactNode;
|
|
3
|
+
export type IndicatorNode = (value: number, type: 'width' | 'height') => React.ReactNode;
|
|
16
4
|
export type SpacerProps = {
|
|
17
|
-
/**
|
|
18
|
-
|
|
19
|
-
/**
|
|
5
|
+
/** Explicit width (takes precedence over block) */
|
|
6
|
+
width?: React.CSSProperties['width'];
|
|
7
|
+
/** Explicit height (takes precedence over block) */
|
|
8
|
+
height?: React.CSSProperties['height'];
|
|
9
|
+
/** Visual style in debug mode */
|
|
20
10
|
variant?: Variant;
|
|
11
|
+
/** Color to use for debug visuals (overrides theme) */
|
|
12
|
+
color?: string;
|
|
21
13
|
/** Base unit for measurements (defaults to theme value) */
|
|
22
14
|
base?: number;
|
|
23
|
-
/**
|
|
24
|
-
|
|
15
|
+
/** Custom content to render (for debugging info) */
|
|
16
|
+
children?: React.ReactNode;
|
|
17
|
+
/** Custom indicator node rendering function */
|
|
18
|
+
indicatorNode?: IndicatorNode;
|
|
19
|
+
/** Flag to enable SSR-compatible mode (simplified initial render) */
|
|
20
|
+
ssrMode?: boolean;
|
|
25
21
|
} & ComponentsProps;
|
|
22
|
+
/** Creates default spacer styles */
|
|
23
|
+
export declare const createDefaultSpacerStyles: (base: number, textColor: string, flatColor: string, lineColor: string) => Record<string, string>;
|
|
24
|
+
/** Generates measurement indicators for debugging */
|
|
25
|
+
export declare const generateMeasurements: (isShown: boolean, indicatorNode: SpacerProps["indicatorNode"], normWidth: number | string, normHeight: number | string) => React.ReactNode | null;
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
27
|
+
* Creates empty space for implementing margins, gaps, and spacing.
|
|
28
28
|
*
|
|
29
29
|
* @remarks
|
|
30
|
-
*
|
|
31
|
-
* -
|
|
32
|
-
* -
|
|
33
|
-
* -
|
|
34
|
-
* - Automatic dimension normalization
|
|
30
|
+
* - Flexible sizing: Set width and height directly
|
|
31
|
+
* - Normalized values: All inputs convert to base unit multiples
|
|
32
|
+
* - Debug visuals: Shows spacing measurements with theming
|
|
33
|
+
* - Automatic: Empty in production, visible in debug mode
|
|
35
34
|
*
|
|
36
35
|
* @example
|
|
37
36
|
* ```tsx
|
|
38
|
-
* //
|
|
39
|
-
* <Spacer
|
|
40
|
-
* height="24px"
|
|
41
|
-
* base={8}
|
|
42
|
-
* />
|
|
37
|
+
* // Fixed size spacer
|
|
38
|
+
* <Spacer width={32} height={16} />
|
|
43
39
|
*
|
|
44
|
-
* //
|
|
40
|
+
* // Percentage-based spacer with debug hints
|
|
45
41
|
* <Spacer
|
|
46
|
-
* width="
|
|
47
|
-
* height=
|
|
48
|
-
* base={4}
|
|
49
|
-
* color="#ff0000"
|
|
42
|
+
* width="50%"
|
|
43
|
+
* height={32}
|
|
50
44
|
* debugging="visible"
|
|
51
|
-
*
|
|
45
|
+
* variant="line"
|
|
52
46
|
* />
|
|
47
|
+
*
|
|
48
|
+
* // Full-width spacer
|
|
49
|
+
* <Spacer height={64} />
|
|
53
50
|
* ```
|
|
54
51
|
*/
|
|
55
52
|
export declare const Spacer: React.NamedExoticComponent<SpacerProps>;
|
|
@@ -1,28 +1,44 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file Stack Component
|
|
3
|
-
* @description Flex container with baseline grid alignment
|
|
4
|
-
* @module components
|
|
5
|
-
*/
|
|
6
1
|
import * as React from 'react';
|
|
7
|
-
import type { Gaps
|
|
2
|
+
import type { Gaps } from '@components';
|
|
3
|
+
import { IndicatorNode } from '../Spacer';
|
|
8
4
|
import { ComponentsProps, Variant } from '../types';
|
|
5
|
+
export declare const DIRECTION_AXIS: Record<string, React.CSSProperties['flexDirection']>;
|
|
6
|
+
export type CSSPropertiesDirectionalAxis = keyof typeof DIRECTION_AXIS;
|
|
9
7
|
export type StackProps = {
|
|
10
8
|
/** Main axis orientation */
|
|
11
|
-
direction?: '
|
|
9
|
+
direction?: React.CSSProperties['flexDirection'] & CSSPropertiesDirectionalAxis;
|
|
12
10
|
/** Distribution of space on main axis */
|
|
13
11
|
justify?: React.CSSProperties['justifyContent'];
|
|
14
12
|
/** Alignment on cross axis */
|
|
15
13
|
align?: React.CSSProperties['alignItems'];
|
|
16
|
-
/** Container width (defaults to "
|
|
14
|
+
/** Container width (defaults to "auto") */
|
|
17
15
|
width?: React.CSSProperties['width'];
|
|
18
|
-
/** Container height (defaults to "
|
|
16
|
+
/** Container height (defaults to "auto") */
|
|
19
17
|
height?: React.CSSProperties['height'];
|
|
20
18
|
/** Custom measurement indicator renderer */
|
|
21
19
|
indicatorNode?: IndicatorNode;
|
|
22
20
|
/** Visual style in debug mode */
|
|
23
21
|
variant?: Variant;
|
|
22
|
+
/** Gap between items in base units */
|
|
23
|
+
gap?: Gaps;
|
|
24
|
+
/** Row gap when using different values for rows and columns */
|
|
25
|
+
rowGap?: Gaps;
|
|
26
|
+
/** Column gap when using different values for rows and columns */
|
|
27
|
+
columnGap?: Gaps;
|
|
28
|
+
/** Flag to enable SSR-compatible mode (simplified initial render) */
|
|
29
|
+
ssrMode?: boolean;
|
|
24
30
|
children?: React.ReactNode;
|
|
25
|
-
} & ComponentsProps
|
|
31
|
+
} & ComponentsProps;
|
|
32
|
+
/** Creates default stack styles with theme colors */
|
|
33
|
+
export declare const createDefaultStackStyles: (colors: Record<string, string>) => {
|
|
34
|
+
'--bkkw': string;
|
|
35
|
+
'--bkkh': string;
|
|
36
|
+
'--bkkcl': string;
|
|
37
|
+
'--bkkcf': string;
|
|
38
|
+
'--bkkci': string;
|
|
39
|
+
};
|
|
40
|
+
/** Creates gap styles for the stack */
|
|
41
|
+
export declare const createStackGapStyles: (rowGap?: number, columnGap?: number, gap?: number) => Record<string, number | undefined>;
|
|
26
42
|
/**
|
|
27
43
|
* A flexible container component aligning children to the baseline grid.
|
|
28
44
|
*
|
|
@@ -34,7 +50,7 @@ export type StackProps = {
|
|
|
34
50
|
* - Includes visual debug overlays
|
|
35
51
|
*
|
|
36
52
|
* Key features:
|
|
37
|
-
* - Automatic dimension management (defaults to
|
|
53
|
+
* - Automatic dimension management (defaults to auto)
|
|
38
54
|
* - Direct padding application in non-debug mode
|
|
39
55
|
* - Comprehensive alignment controls
|
|
40
56
|
* - Theme-aware debug visuals
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { DebuggingMode } from '
|
|
2
|
+
import { DebuggingMode } from './Config/Config';
|
|
3
3
|
/**
|
|
4
4
|
* Defines spacing as either a single value, start/end pair, or object with explicit edges.
|
|
5
5
|
* Used for block and inline spacing across components.
|
|
@@ -1,72 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* @description Manages baseline grid alignment calculations
|
|
4
|
-
* @module hooks
|
|
5
|
-
*/
|
|
6
|
-
import { RefObject } from 'react';
|
|
7
|
-
import { SnappingMode, Padding } from '@components';
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { SnappingMode, Padding } from '@components';
|
|
8
3
|
export interface BaselineOptions {
|
|
9
|
-
/** Base unit for alignment calculations (default: 8) */
|
|
10
4
|
base?: number;
|
|
11
|
-
/**
|
|
5
|
+
/** Snapping strategy: 'none' | 'height' | 'clamp'. */
|
|
12
6
|
snapping?: SnappingMode;
|
|
13
|
-
/** Initial
|
|
7
|
+
/** Initial padding config. e.g. { top: 10, bottom: 20 } or just 8, etc. */
|
|
14
8
|
spacing?: Partial<Padding> | number;
|
|
15
|
-
/**
|
|
9
|
+
/** Whether to warn in the console if the measured height is not a multiple of base. */
|
|
16
10
|
warnOnMisalignment?: boolean;
|
|
17
11
|
}
|
|
18
12
|
export interface BaselineResult {
|
|
19
|
-
/** Final adjusted padding values */
|
|
20
13
|
padding: Padding;
|
|
21
|
-
/** Whether the measured height is a multiple of base */
|
|
22
14
|
isAligned: boolean;
|
|
23
|
-
/** Raw measured height in pixels */
|
|
24
15
|
height: number;
|
|
25
16
|
}
|
|
26
17
|
/**
|
|
27
|
-
*
|
|
18
|
+
* Hook for managing baseline grid alignment in components.
|
|
28
19
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* This hook handles the complex calculations needed to maintain baseline grid
|
|
22
|
+
* alignment, including:
|
|
23
|
+
* ▪ Measuring element dimensions
|
|
24
|
+
* ▪ Calculating padding adjustments
|
|
25
|
+
* ▪ Potentially snapping values to ensure multiples of the base
|
|
26
|
+
* ▪ Warning about misalignments in development
|
|
36
27
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
28
|
+
* Different snapping modes affect how spacing is adjusted:
|
|
29
|
+
* ▪ 'none': Uses raw spacing values without adjustment
|
|
30
|
+
* ▪ 'height': Adjusts only the final (bottom) padding to align
|
|
31
|
+
* ▪ 'clamp': Adjusts top and bottom to align
|
|
41
32
|
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
33
|
+
* @param ref Reference to the DOM element
|
|
34
|
+
* @param options Configuration options for alignment behavior
|
|
35
|
+
* @returns Object with adjusted padding, alignment status, and height
|
|
45
36
|
*
|
|
46
37
|
* @example
|
|
47
38
|
* ```tsx
|
|
48
|
-
* function MyComponent() {
|
|
49
|
-
* const ref = useRef<HTMLDivElement>(null)
|
|
50
|
-
* const { padding
|
|
39
|
+
* export function MyComponent() {
|
|
40
|
+
* const ref = useRef<HTMLDivElement>(null)
|
|
41
|
+
* const { padding } = useBaseline(ref, {
|
|
51
42
|
* base: 8,
|
|
52
43
|
* snapping: 'height',
|
|
53
|
-
* spacing: {
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* >
|
|
64
|
-
* Content
|
|
65
|
-
* </div>
|
|
66
|
-
* );
|
|
67
|
-
* }
|
|
68
|
-
* ```
|
|
69
|
-
*
|
|
70
|
-
* @throws {Error} if base is less than 1
|
|
44
|
+
* spacing: {
|
|
45
|
+
* top: 16,
|
|
46
|
+
* bottom: 16
|
|
47
|
+
* }
|
|
48
|
+
* }}
|
|
49
|
+
* >
|
|
50
|
+
* Content
|
|
51
|
+
* </div>
|
|
52
|
+
* )
|
|
53
|
+
* }
|
|
71
54
|
*/
|
|
72
|
-
export declare function useBaseline(ref: RefObject<HTMLElement | null>, { base, snapping, spacing, warnOnMisalignment, }?: BaselineOptions): BaselineResult;
|
|
55
|
+
export declare function useBaseline(ref: React.RefObject<HTMLElement | null>, { base, snapping, spacing, warnOnMisalignment, }?: BaselineOptions): BaselineResult;
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file useConfig Hook
|
|
3
|
-
* @description Manages component-specific theme configuration
|
|
4
|
-
* @module hooks
|
|
5
|
-
*/
|
|
6
1
|
import { Config } from '@components';
|
|
7
2
|
/** Type helper that merges base configuration with component-specific settings. */
|
|
8
3
|
export type ComponentConfig<K extends keyof Config> = Config[K] & {
|
package/dist/hooks/useDebug.d.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* @file useDebug Hook
|
|
3
|
-
* @description Manages component debugging state
|
|
4
|
-
* @module hooks
|
|
5
|
-
*/
|
|
6
|
-
import { DebuggingMode } from '@components';
|
|
1
|
+
import { DebuggingMode } from '../components/Config/Config';
|
|
7
2
|
interface DebugResult {
|
|
8
3
|
/** Whether debug visuals should be shown */
|
|
9
4
|
isShown: boolean;
|
package/dist/hooks/useGuide.d.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* @file useGuide Hook
|
|
3
|
-
* @description Manages grid layout calculations for guide overlays
|
|
4
|
-
* @module hooks
|
|
5
|
-
*/
|
|
6
|
-
import { RefObject } from 'react';
|
|
1
|
+
import * as React from 'react';
|
|
7
2
|
import { GuideConfig } from '@components';
|
|
8
3
|
export interface GuideResult {
|
|
9
4
|
/** CSS grid template string */
|
|
@@ -63,4 +58,4 @@ export interface GuideResult {
|
|
|
63
58
|
* }
|
|
64
59
|
* ```
|
|
65
60
|
*/
|
|
66
|
-
export declare function useGuide(ref: RefObject<HTMLElement | null>, config: GuideConfig): GuideResult;
|
|
61
|
+
export declare function useGuide(ref: React.RefObject<HTMLElement | null>, config: GuideConfig): GuideResult;
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* @file useMeasure Hook
|
|
3
|
-
* @description Tracks element dimensions using ResizeObserver
|
|
4
|
-
* @module hooks
|
|
5
|
-
*/
|
|
6
|
-
import { RefObject } from 'react';
|
|
1
|
+
import * as React from 'react';
|
|
7
2
|
export interface MeasureResult {
|
|
8
3
|
/** Measured width in pixels */
|
|
9
4
|
width: number;
|
|
@@ -15,18 +10,9 @@ export interface MeasureResult {
|
|
|
15
10
|
/**
|
|
16
11
|
* Hook for measuring and tracking DOM element dimensions.
|
|
17
12
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* - Cache to prevent unnecessary updates
|
|
22
|
-
* - Error handling and recovery
|
|
23
|
-
* - Manual refresh capability
|
|
24
|
-
*
|
|
25
|
-
* The hook automatically:
|
|
26
|
-
* - Initializes with 0x0 dimensions
|
|
27
|
-
* - Updates on element resize
|
|
28
|
-
* - Cleans up observers on unmount
|
|
29
|
-
* - Rounds dimensions to whole pixels
|
|
13
|
+
* Provides responsive element measurements using ResizeObserver,
|
|
14
|
+
* with performance optimization (via RAF throttling), error handling,
|
|
15
|
+
* and a manual refresh method.
|
|
30
16
|
*
|
|
31
17
|
* @param ref - Reference to the DOM element to measure
|
|
32
18
|
* @returns Current dimensions and refresh function
|
|
@@ -34,7 +20,7 @@ export interface MeasureResult {
|
|
|
34
20
|
* @example
|
|
35
21
|
* ```tsx
|
|
36
22
|
* function ResponsiveBox() {
|
|
37
|
-
* const ref = useRef<HTMLDivElement>(null);
|
|
23
|
+
* const ref = React.useRef<HTMLDivElement>(null);
|
|
38
24
|
* const { width, height, refresh } = useMeasure(ref);
|
|
39
25
|
*
|
|
40
26
|
* return (
|
|
@@ -46,4 +32,4 @@ export interface MeasureResult {
|
|
|
46
32
|
* }
|
|
47
33
|
* ```
|
|
48
34
|
*/
|
|
49
|
-
export declare function useMeasure(ref: RefObject<HTMLElement | null>): MeasureResult;
|
|
35
|
+
export declare function useMeasure(ref: React.RefObject<HTMLElement | null>): MeasureResult;
|