@react-hive/honey-style 1.8.1 → 1.11.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.
@@ -1,7 +1,7 @@
1
1
  import * as CSS from 'csstype';
2
2
  import type { ElementType } from 'react';
3
3
  import { HONEY_STYLED_COMPONENT_ID_PROP } from '../constants';
4
- import type { HoneyCSSColor, HoneyCSSDimensionUnit, HoneyCSSDimensionValue } from './css.types';
4
+ import type { HoneyCSSColor, HoneyCSSDimensionUnit } from './css.types';
5
5
  /**
6
6
  * Creates a new type by omitting the specified keys `U` from the object type `T`.
7
7
  *
@@ -99,7 +99,7 @@ export interface HoneyFont {
99
99
  *
100
100
  * @example
101
101
  * ```ts
102
- * declare module '@react-hive/honey-layout' {
102
+ * declare module '@react-hive/honey-style' {
103
103
  * export interface HoneyFonts {
104
104
  * body: HoneyFont;
105
105
  * caption: HoneyFont;
@@ -163,7 +163,7 @@ interface BaseHoneyColors {
163
163
  *
164
164
  * @example
165
165
  * ```ts
166
- * declare module '@react-hive/honey-layout' {
166
+ * declare module '@react-hive/honey-style' {
167
167
  * export interface HoneyColors {
168
168
  * neutral: Record<'charcoalDark' | 'charcoalGray' | 'crimsonRed', HoneyCSSColor>;
169
169
  * }
@@ -203,11 +203,12 @@ export interface HoneyContainer {
203
203
  */
204
204
  maxWidth: `${number}${HoneyCSSDimensionUnit}`;
205
205
  }
206
+ export type HoneyDimensionValue = `${number}${HoneyCSSDimensionUnit}`;
206
207
  /**
207
208
  * Represents a map of dimension names to CSS distance values.
208
209
  */
209
210
  export interface HoneyDimensions {
210
- [key: string]: HoneyCSSDimensionValue;
211
+ [key: string]: HoneyDimensionValue;
211
212
  }
212
213
  export type HoneyDimensionName = keyof HoneyDimensions;
213
214
  /**
@@ -0,0 +1 @@
1
+ export type Nullable<T> = T | null;
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { HoneyColor, HoneyColorKey, HoneyCSSClassName, HoneyCSSColor, HoneyCSSDimensionValue, HoneyDimensionName, HoneyFontName, HoneyHEXColor, HoneyStyledComponent, HoneyStyledContext } from './types';
1
+ import type { Nullable, HoneyColor, HoneyColorKey, HoneyCSSClassName, HoneyCSSColor, HoneyCSSDimensionUnit, HoneyCSSDimensionValue, HoneyCSSShorthandDimensionOutput, HoneyCSSShorthandTuple, HoneyCSSSpacingValue, HoneyDimensionName, HoneyFontName, HoneyHEXColor, HoneySpacings, HoneyStyledComponent, HoneyStyledContext } from './types';
2
2
  export declare function assert(condition: any, message: string): asserts condition;
3
3
  export declare const generateId: (prefix: string) => string;
4
4
  export declare const toKebabCase: (str: string) => string;
@@ -72,6 +72,46 @@ export declare const pxToRem: (px: number, base?: number) => string;
72
72
  * @returns True if the string value is a theme color value, false otherwise.
73
73
  */
74
74
  export declare const checkIsThemeColorValue: (propertyValue: string) => propertyValue is HoneyColorKey;
75
+ /**
76
+ * Determines the resolved type for spacing values when processed by `resolveSpacing`.
77
+ *
78
+ * The return type adapts based on the shape of the `Value` and presence of a CSS `Unit`:
79
+ *
80
+ * - If `Value` is a `string` (e.g., raw `'10px'` or `'auto'`), it is returned as-is.
81
+ * - If `Unit` is `null`, the original value is returned (either number or shorthand array).
82
+ * - If `Unit` is provided and `Value` is a shorthand array (e.g., `[1, 2, 3, 4]`),
83
+ * it is resolved to a space-separated dimension string (e.g., `'8px 16px 24px 32px'`).
84
+ * - If `Unit` is provided and `Value` is a number, it is resolved to a single dimension string (e.g., `'16px'`).
85
+ *
86
+ * This type helps enforce correct resolution behavior depending on user input and configuration.
87
+ *
88
+ * @template Value - The input spacing value (number, shorthand array, or raw string).
89
+ * @template Unit - A CSS length unit (e.g., 'px', 'em'), or `null` to skip unit formatting.
90
+ */
91
+ export type HoneyResolveSpacingResult<Value extends HoneyCSSSpacingValue, Unit extends Nullable<HoneyCSSDimensionUnit>> = Value extends HoneyCSSDimensionValue ? Value : Unit extends null ? Value : Value extends HoneyCSSShorthandTuple<number | HoneyCSSDimensionValue> ? HoneyCSSShorthandDimensionOutput<Value, NonNullable<Unit>> : HoneyCSSDimensionValue<NonNullable<Unit>>;
92
+ /**
93
+ * Resolves a spacing value or shorthand spacing array using the theme and optional unit.
94
+ *
95
+ * This function takes spacing multipliers and converts them into pixel or unit-based values
96
+ * using a theme spacing scale (e.g., `theme.spacings.base`). Useful for applying consistent
97
+ * layout spacing with theming and token support.
98
+ *
99
+ * @template Value - The spacing value(s) to resolve. Can be:
100
+ * - A number (e.g., `1`) representing a multiplier.
101
+ * - An array of numbers (e.g., `[1, 2, 3, 4]`) for shorthand spacing.
102
+ * - A dimension string (e.g., `'10px'`) will be returned as `never`.
103
+ * @template Unit - Optional CSS unit (`'px'`, `'em'`, etc.), or `null` to skip units.
104
+ *
105
+ * @param value - Spacing multiplier(s) to apply.
106
+ * @param [unit='px'] - The CSS unit to append. If `null`, values remain numeric.
107
+ * @param [type='base'] - The spacing type to use from the theme (e.g., `'base'`, `'small'`).
108
+ *
109
+ * @returns A function that takes a theme context and returns:
110
+ * - A single resolved value (e.g., `'16px'`) if `value` is a number.
111
+ * - A space-separated string (e.g., `'8px 12px'`) if `value` is an array.
112
+ * - `never` if the input is a raw string (unsupported).
113
+ */
114
+ export declare const resolveSpacing: <Value extends HoneyCSSSpacingValue, Unit extends Nullable<HoneyCSSDimensionUnit> = "px">(value: Value, unit?: Unit, type?: keyof HoneySpacings) => ((context: HoneyStyledContext<object>) => HoneyResolveSpacingResult<Value, Unit>);
75
115
  /**
76
116
  * Resolves the font styles based on the provided font name from the theme.
77
117
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-hive/honey-style",
3
- "version": "1.8.1",
3
+ "version": "1.11.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "react",