@react-hive/honey-layout 1.0.0-beta → 1.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.
@@ -0,0 +1,67 @@
1
+ import { PropsWithChildren } from 'react';
2
+ import { DefaultTheme, FlattenSimpleInterpolation } from 'styled-components';
3
+ import { HoneyColorKey, HoneyCSSColor, HoneyCSSDimensionUnit, HoneyCSSDimensionValue, HoneyCSSMultiValue, HoneyDimensionName, HoneyFontName, HoneyScreenState, HoneySpacings, HoneyThemedProps, Nullable } from '../types';
4
+ import { ResolveSpacingResult } from '../helpers';
5
+ import { UseHoneyMediaQueryOptions } from '../hooks';
6
+ type HoneyLayoutContextValue = {
7
+ /**
8
+ * Represents the theme object.
9
+ */
10
+ theme: DefaultTheme;
11
+ /**
12
+ * Represents the current state of the screen.
13
+ */
14
+ screenState: HoneyScreenState;
15
+ /**
16
+ * Function to resolve spacing values based on a given theme.
17
+ *
18
+ * @template MultiValue - A type representing the spacing value(s), which could be a single value or an array of values.
19
+ * @template Unit - The CSS unit used for the resolved spacing value, e.g., 'px', 'em'.
20
+ *
21
+ * @param {MultiValue} value - The spacing value(s) to be applied, which could be a single number or an array of numbers.
22
+ * @param {Unit} unit - Optional. The CSS unit to use for the calculated value. Defaults to 'px'.
23
+ * @param {keyof HoneySpacings} type - Optional. The type of spacing to use from the theme (e.g., 'base', 'small', 'large').
24
+ *
25
+ * @returns {ResolveSpacingResult<MultiValue, Unit>} - The resolved spacing value, formatted as a string with the appropriate unit.
26
+ */
27
+ resolveSpacing: <MultiValue extends HoneyCSSMultiValue<number>, Unit extends Nullable<HoneyCSSDimensionUnit> = 'px'>(value: MultiValue, unit?: Unit, type?: keyof HoneySpacings) => ResolveSpacingResult<MultiValue, Unit>;
28
+ /**
29
+ * Function to resolve color values based on the theme.
30
+ *
31
+ * @param {HoneyColorKey} colorKey - The key representing the color in the theme.
32
+ * @param {number} [alpha] - Optional alpha value to apply to the color for transparency.
33
+ *
34
+ * @returns {HoneyCSSColor} - The resolved CSS color, optionally with alpha transparency.
35
+ */
36
+ resolveColor: (colorKey: HoneyColorKey, alpha?: number) => HoneyCSSColor;
37
+ /**
38
+ * Function to resolve font styles based on the theme.
39
+ *
40
+ * @param {HoneyFontName} fontName - The name of the font to resolve from the theme.
41
+ *
42
+ * @returns {FlattenSimpleInterpolation} - The interpolated CSS styles for the specified font.
43
+ */
44
+ resolveFont: (fontName: HoneyFontName) => FlattenSimpleInterpolation;
45
+ /**
46
+ * Function to resolve dimension values based on the theme.
47
+ *
48
+ * @param {HoneyDimensionName} dimensionName - The name of the dimension to resolve from the theme.
49
+ *
50
+ * @returns {HoneyCSSDimensionValue} - The resolved CSS dimension value (e.g., width, height).
51
+ */
52
+ resolveDimension: (dimensionName: HoneyDimensionName) => HoneyCSSDimensionValue;
53
+ };
54
+ type HoneyLayoutProviderContentProps = {
55
+ mediaQueryOptions?: UseHoneyMediaQueryOptions;
56
+ };
57
+ type HoneyLayoutProviderProps = HoneyThemedProps<HoneyLayoutProviderContentProps>;
58
+ export declare const HoneyLayoutProvider: ({ theme, ...props }: PropsWithChildren<HoneyLayoutProviderProps>) => import("react/jsx-runtime").JSX.Element;
59
+ /**
60
+ * Custom hook to access the Honey layout context.
61
+ *
62
+ * @throws Will throw an error if the hook is used outside of a `HoneyLayoutProvider` component.
63
+ *
64
+ * @returns {HoneyLayoutContextValue} - The context value providing theming utilities and screen state.
65
+ */
66
+ export declare const useHoneyLayout: () => HoneyLayoutContextValue;
67
+ export {};
@@ -0,0 +1,13 @@
1
+ import { PropsWithChildren } from 'react';
2
+ import { HoneyThemedProps } from '../types';
3
+ type HoneyLayoutThemeOverrideProps = HoneyThemedProps;
4
+ /**
5
+ * Provides a theme override context to its children.
6
+ * Merges the provided theme with the existing theme from the `ThemeContext`.
7
+ *
8
+ * @param {PropsWithChildren<HoneyLayoutThemeOverrideProps>} props - The props for `HoneyLayoutThemeOverride`.
9
+ *
10
+ * @returns The ThemeProvider with the merged theme applied to its children.
11
+ */
12
+ export declare const HoneyLayoutThemeOverride: ({ theme, ...props }: PropsWithChildren<HoneyLayoutThemeOverrideProps>) => import("react/jsx-runtime").JSX.Element;
13
+ export {};
@@ -1 +1,2 @@
1
- export * from './HoneyThemeProvider';
1
+ export * from './HoneyLayoutProvider';
2
+ export * from './HoneyLayoutThemeOverride';
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ComponentType, ReactNode } from 'react';
2
- import { Interpolation } from 'styled-components';
2
+ import { DefaultTheme, Interpolation } from 'styled-components';
3
3
  import { DataType } from 'csstype';
4
4
  import * as CSS from 'csstype';
5
5
  export type TimeoutId = ReturnType<typeof setTimeout>;
@@ -74,7 +74,7 @@ export type HoneyCSSMediaRule = {
74
74
  update?: 'none' | 'slow' | 'fast';
75
75
  };
76
76
  /**
77
- * Represents the breakpoints configuration for a responsive layout.
77
+ * Represents the breakpoints configuration in pixes for a responsive layout.
78
78
  *
79
79
  * Notes:
80
80
  * - `xs`: Extra small devices
@@ -91,14 +91,56 @@ export type HoneyBreakpoints = {
91
91
  xl: number;
92
92
  };
93
93
  export type HoneyBreakpointName = keyof HoneyBreakpoints;
94
+ export type HoneyContainer = {
95
+ /**
96
+ * Max container width in any CSS distance value.
97
+ */
98
+ maxWidth: HoneyCSSDimensionValue;
99
+ };
100
+ /**
101
+ * Represents the theme configuration.
102
+ */
103
+ export interface BaseHoneyTheme {
104
+ /**
105
+ * Breakpoints for responsive design, where keys are breakpoint names and values are breakpoint values.
106
+ */
107
+ breakpoints: Partial<HoneyBreakpoints>;
108
+ /**
109
+ * Configuration for the container.
110
+ */
111
+ container: Partial<HoneyContainer>;
112
+ /**
113
+ * Spacing values used throughout the theme.
114
+ */
115
+ spacings: HoneySpacings;
116
+ /**
117
+ * Font settings used throughout the theme.
118
+ */
119
+ fonts: HoneyFonts;
120
+ /**
121
+ * Color palette used throughout the theme.
122
+ */
123
+ colors: HoneyColors;
124
+ /**
125
+ * Dimension values used throughout the theme.
126
+ */
127
+ dimensions: HoneyDimensions;
128
+ }
129
+ export interface HoneyTheme extends BaseHoneyTheme {
130
+ }
131
+ declare module 'styled-components' {
132
+ interface DefaultTheme extends HoneyTheme {
133
+ }
134
+ }
135
+ export type HoneyThemedProps<T = unknown> = {
136
+ theme: DefaultTheme;
137
+ } & T;
94
138
  /**
95
139
  * A type representing a function that returns a value for a specific CSS property based on the provided theme.
96
140
  *
97
141
  * @template CSSProperty - The CSS property this function will generate a value for.
98
142
  */
99
- type HoneyCSSPropertyValueFn<CSSProperty extends keyof CSS.Properties> = (props: {
100
- theme: HoneyTheme;
101
- }) => CSS.Properties[CSSProperty];
143
+ type HoneyCSSPropertyValueFn<CSSProperty extends keyof CSS.Properties> = (props: HoneyThemedProps) => CSS.Properties[CSSProperty];
102
144
  /**
103
145
  * Type representing numeric values for CSS dimension properties.
104
146
  *
@@ -166,12 +208,6 @@ export type HoneyScreenState = {
166
208
  /** Indicates if the screen orientation is landscape. */
167
209
  isLandscape: boolean;
168
210
  };
169
- export type HoneyContainer = {
170
- /**
171
- * Max container width in any CSS distance value.
172
- */
173
- maxWidth: HoneyCSSDimensionValue;
174
- };
175
211
  /**
176
212
  * Defines different spacing sizes available in the theme.
177
213
  */
@@ -238,7 +274,7 @@ export interface BaseHoneyColors {
238
274
  * ```typescript
239
275
  * declare module '@react-hive/honey-layout' {
240
276
  * interface HoneyColors {
241
- * neutral: Record<'charcoalDark' | 'charcoalGray' | 'crimsonRed', HoneyColor>;
277
+ * neutral: Record<'charcoalDark' | 'charcoalGray' | 'crimsonRed', HoneyCSSColor>;
242
278
  * }
243
279
  * }
244
280
  * ```
@@ -256,8 +292,8 @@ export interface HoneyColors extends BaseHoneyColors {
256
292
  * Given the `HoneyColors` interface:
257
293
  * ```typescript
258
294
  * interface HoneyColors {
259
- * primary: Record<'blue' | 'green', HoneyColor>;
260
- * neutral: Record<'charcoalDark' | 'charcoalGray' | 'crimsonRed', HoneyColor>;
295
+ * primary: Record<'blue' | 'green', HoneyCSSColor>;
296
+ * neutral: Record<'charcoalDark' | 'charcoalGray' | 'crimsonRed', HoneyCSSColor>;
261
297
  * }
262
298
  * ```
263
299
  *
@@ -300,50 +336,10 @@ export interface HoneyDimensions {
300
336
  [key: string]: HoneyCSSDimensionValue;
301
337
  }
302
338
  export type HoneyDimensionName = keyof HoneyDimensions;
303
- /**
304
- * Represents the theme configuration.
305
- */
306
- export interface BaseHoneyTheme {
307
- /**
308
- * Breakpoints for responsive design, where keys are breakpoint names and values are breakpoint values.
309
- */
310
- breakpoints: Partial<HoneyBreakpoints>;
311
- /**
312
- * Configuration for the container.
313
- */
314
- container: Partial<HoneyContainer>;
315
- /**
316
- * Spacing values used throughout the theme.
317
- */
318
- spacings: HoneySpacings;
319
- /**
320
- * Font settings used throughout the theme.
321
- */
322
- fonts: HoneyFonts;
323
- /**
324
- * Color palette used throughout the theme.
325
- */
326
- colors: HoneyColors;
327
- /**
328
- * Dimension values used throughout the theme.
329
- */
330
- dimensions: HoneyDimensions;
331
- }
332
- export interface HoneyTheme extends BaseHoneyTheme {
333
- }
334
- declare module 'styled-components' {
335
- interface DefaultTheme extends HoneyTheme {
336
- }
337
- }
338
- export type HoneyThemedProps<T = unknown> = {
339
- theme: HoneyTheme;
340
- } & T;
341
339
  export type ComponentWithAs<T, P = object> = {
342
340
  as?: string | ComponentType<P>;
343
341
  } & T;
344
- export type HoneyModifierResultFn = () => Interpolation<{
345
- theme: HoneyTheme;
346
- }>;
342
+ export type HoneyModifierResultFn = () => Interpolation<HoneyThemedProps>;
347
343
  export type HoneyModifier<Config = unknown> = (config?: Config) => HoneyModifierResultFn;
348
344
  /**
349
345
  * Type definition for status content options in a component.
package/dist/utils.d.ts CHANGED
@@ -90,7 +90,7 @@ export declare const getTransformationValues: (element: HTMLElement) => {
90
90
  *
91
91
  * @returns A flat array of items, excluding the nested list key and including `depthLevel`, `parentId`, and `totalNestedItems` properties.
92
92
  */
93
- export declare const flattenNestedList: <OriginItem extends object>(items: OriginItem[] | undefined, itemIdKey: KeysWithNonArrayValues<OriginItem>, nestedItemsKey: KeysWithArrayValues<OriginItem>, result?: HoneyFlattenedItem<OriginItem, KeysWithArrayValues<OriginItem>>[], parentId?: OriginItem[KeysWithNonArrayValues<OriginItem>] | undefined, depthLevel?: number) => HoneyFlattenedItem<OriginItem, KeysWithArrayValues<OriginItem>>[];
93
+ export declare const flattenNestedList: <OriginItem extends object>(items: OriginItem[] | undefined, itemIdKey: KeysWithNonArrayValues<OriginItem>, nestedItemsKey: KeysWithArrayValues<OriginItem>, result?: HoneyFlattenedItem<OriginItem, typeof nestedItemsKey>[], parentId?: OriginItem[KeysWithNonArrayValues<OriginItem>] | undefined, depthLevel?: number) => HoneyFlattenedItem<OriginItem, typeof nestedItemsKey>[];
94
94
  /**
95
95
  * Filters flattened items based on the specified parent ID and an optional predicate.
96
96
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-hive/honey-layout",
3
- "version": "1.0.0-beta",
3
+ "version": "1.1.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "react",
@@ -33,8 +33,8 @@
33
33
  "@mdx-js/react": "3.0.1",
34
34
  "react": "18.2.0",
35
35
  "react-dom": "18.2.0",
36
- "react-router-dom": "6.24.1",
37
- "styled-components": "5.3.9",
36
+ "react-router-dom": "6.26.1",
37
+ "styled-components": "5.3.11",
38
38
  "highlight.js": "11.10.0"
39
39
  },
40
40
  "dependencies": {
@@ -43,11 +43,11 @@
43
43
  "csstype": "3.1.3"
44
44
  },
45
45
  "devDependencies": {
46
- "@testing-library/react": "16.0.0",
46
+ "@testing-library/react": "16.0.1",
47
47
  "@types/jest": "29.5.12",
48
- "@typescript-eslint/eslint-plugin": "7.16.0",
49
- "@typescript-eslint/parser": "7.16.0",
50
- "@types/react": "18.2.78",
48
+ "@typescript-eslint/eslint-plugin": "7.18.0",
49
+ "@typescript-eslint/parser": "7.18.0",
50
+ "@types/react": "18.2.79",
51
51
  "@types/react-dom": "18.2.25",
52
52
  "@types/styled-components": "5.1.34",
53
53
  "@types/mdx": "2.0.13",
@@ -59,16 +59,16 @@
59
59
  "eslint-config-airbnb": "19.0.4",
60
60
  "eslint-config-airbnb-typescript": "18.0.0",
61
61
  "eslint-config-prettier": "9.1.0",
62
- "eslint-plugin-import": "2.29.1",
62
+ "eslint-plugin-import": "2.30.0",
63
63
  "eslint-plugin-prettier": "5.2.1",
64
64
  "jest": "29.7.0",
65
65
  "jest-environment-jsdom": "29.7.0",
66
66
  "prettier": "3.3.3",
67
- "ts-jest": "29.2.4",
68
- "typescript": "5.4.5",
69
- "vite": "5.4.0",
70
- "vite-plugin-dts": "4.0.2",
71
- "vite-plugin-checker": "0.7.2"
67
+ "ts-jest": "29.2.5",
68
+ "typescript": "5.5.4",
69
+ "vite": "5.4.3",
70
+ "vite-plugin-dts": "4.1.0",
71
+ "vite-plugin-checker": "0.8.0"
72
72
  },
73
73
  "jest": {
74
74
  "preset": "ts-jest",
@@ -1,14 +0,0 @@
1
- import { PropsWithChildren, JSX } from 'react';
2
- import { DefaultTheme } from 'styled-components';
3
- type HoneyThemeProviderProps = {
4
- theme: DefaultTheme;
5
- };
6
- /**
7
- * Component for providing a merged theme to its children.
8
- * Merges the provided theme with the current theme from the context.
9
- *
10
- * @param {PropsWithChildren<HoneyThemeProviderProps>} props - Props containing the theme object.
11
- * @returns {JSX.Element} - The wrapped children with the merged theme.
12
- */
13
- export declare const HoneyThemeProvider: ({ children, theme, }: PropsWithChildren<HoneyThemeProviderProps>) => JSX.Element;
14
- export {};