@react-hive/honey-layout 2.2.0 → 2.4.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,56 +1,6 @@
1
+ import { DefaultTheme } from 'styled-components';
1
2
  import { PropsWithChildren } from 'react';
2
- import { DefaultTheme, Interpolation } from 'styled-components';
3
- import { HoneyColorKey, HoneyCSSColor, HoneyCSSDimensionUnit, HoneyCSSDimensionValue, HoneyCSSMultiValue, HoneyDimensionName, HoneyFontName, HoneyScreenState, HoneySpacings, Nullable } from '../types';
4
- import { ResolveSpacingResult } from '../helpers';
5
3
  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 {Interpolation<object>} - The CSS style rules for the specified font.
43
- */
44
- resolveFont: (fontName: HoneyFontName) => Interpolation<object>;
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
4
  type HoneyLayoutProviderContentProps = {
55
5
  mediaQueryOptions?: UseHoneyMediaQueryOptions;
56
6
  };
@@ -58,12 +8,4 @@ type HoneyLayoutProviderProps = HoneyLayoutProviderContentProps & {
58
8
  theme: DefaultTheme;
59
9
  };
60
10
  export declare const HoneyLayoutProvider: ({ theme, ...props }: PropsWithChildren<HoneyLayoutProviderProps>) => import("react/jsx-runtime").JSX.Element;
61
- /**
62
- * Custom hook to access the Honey layout context.
63
- *
64
- * @throws Will throw an error if the hook is used outside of a `HoneyLayoutProvider` component.
65
- *
66
- * @returns {HoneyLayoutContextValue} - The context value providing theming utilities and screen state.
67
- */
68
- export declare const useHoneyLayout: () => HoneyLayoutContextValue;
69
11
  export {};
@@ -0,0 +1 @@
1
+ export * from './use-honey-overlays';
@@ -0,0 +1,11 @@
1
+ import { HoneyOverlay } from '../../types';
2
+ import { HoneyRegisterOverlay, HoneyUnregisterOverlay } from '../../contexts';
3
+ /**
4
+ * Hook to manage a stack of overlays, allowing registration and unregistration of overlays,
5
+ * as well as handling keyboard events.
6
+ */
7
+ export declare const useHoneyOverlays: () => {
8
+ overlays: HoneyOverlay[];
9
+ registerOverlay: HoneyRegisterOverlay;
10
+ unregisterOverlay: HoneyUnregisterOverlay;
11
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * A union type representing commonly used keyboard key codes.
3
+ * These key codes can be used to identify specific keyboard inputs in event handling.
4
+ */
5
+ export type HoneyKeyboardEventCode = 'Escape' | 'ArrowRight' | 'ArrowLeft' | 'ArrowUp' | 'ArrowDown' | 'Enter' | 'NumpadEnter' | 'Tab' | 'Space';
@@ -4,3 +4,4 @@ export * from './state.types';
4
4
  export * from './css.types';
5
5
  export * from './component.types';
6
6
  export * from './types';
7
+ export * from './dom.types';
@@ -2,6 +2,7 @@ import { ElementType } from 'react';
2
2
  import { ExecutionContext, Interpolation } from 'styled-components';
3
3
  import { DataType } from 'csstype';
4
4
  import { HoneyCSSColorProperty, HoneyCSSDimensionNumericValue, HoneyCSSDimensionValue } from './css.types';
5
+ import { HoneyKeyboardEventCode } from './dom.types';
5
6
  import * as CSS from 'csstype';
6
7
  export type TimeoutId = ReturnType<typeof setTimeout>;
7
8
  export type Nullable<T> = T | null;
@@ -257,4 +258,72 @@ export type ComponentWithAs<T, P = object> = {
257
258
  } & T;
258
259
  export type HoneyModifierResultFn = () => Interpolation<object>;
259
260
  export type HoneyModifier<Config = unknown> = (config?: Config) => HoneyModifierResultFn;
261
+ export type HoneyOverlayId = string;
262
+ export type HoneyOverlayEventListenerType = 'keyup';
263
+ /**
264
+ * Handler function for an overlay event listener.
265
+ *
266
+ * @param keyCode - The code of the key that triggered the event.
267
+ * @param e - The original keyboard event.
268
+ */
269
+ export type HoneyOverlayEventListenerHandler = (keyCode: HoneyKeyboardEventCode, e: KeyboardEvent) => void;
270
+ /**
271
+ * A tuple representing an event listener, including the event type and the handler function.
272
+ */
273
+ export type HoneyOverlayEventListener = [
274
+ HoneyOverlayEventListenerType,
275
+ HoneyOverlayEventListenerHandler
276
+ ];
277
+ /**
278
+ * Configuration object for an overlay, used to specify the overlay's behavior and event handling.
279
+ */
280
+ export type HoneyOverlayConfig = {
281
+ /**
282
+ * Custom overlay ID. Automatically generated if not passed.
283
+ */
284
+ id?: HoneyOverlayId;
285
+ /**
286
+ * List of keyboard event codes to listen for (e.g., "Escape", "Enter").
287
+ * If undefined or empty, all key codes will be listened to.
288
+ *
289
+ * @default undefined
290
+ */
291
+ listenKeys?: HoneyKeyboardEventCode[];
292
+ /**
293
+ * Callback function to be invoked when a key event occurs for the specified key(s).
294
+ * If `listenKeys` is provided, this will only be triggered for those keys.
295
+ */
296
+ onKeyUp: HoneyOverlayEventListenerHandler;
297
+ };
298
+ /**
299
+ * Represents an overlay in the layout, allowing the registration of event listeners and notifying them when events occur.
300
+ */
301
+ export type HoneyOverlay = {
302
+ /**
303
+ * Unique identifier for the overlay.
304
+ */
305
+ id: HoneyOverlayId;
306
+ /**
307
+ * Adds an event listener to the overlay.
308
+ *
309
+ * @param type - The type of event to listen for.
310
+ * @param handler - The handler function to execute when the event is triggered.
311
+ */
312
+ addListener: (type: HoneyOverlayEventListenerType, handler: HoneyOverlayEventListenerHandler) => void;
313
+ /**
314
+ * Removes a specific event listener from the overlay.
315
+ *
316
+ * @param type - The type of event for the listener.
317
+ * @param handler - The handler function to remove.
318
+ */
319
+ removeListener: (type: HoneyOverlayEventListenerType, handler: HoneyOverlayEventListenerHandler) => void;
320
+ /**
321
+ * Notifies all listeners of a specific event type.
322
+ *
323
+ * @param type - The type of event that occurred.
324
+ * @param keyCode - The code of the key that triggered the event.
325
+ * @param e - The original keyboard event.
326
+ */
327
+ notifyListeners: (type: HoneyOverlayEventListenerType, keyCode: HoneyKeyboardEventCode, e: KeyboardEvent) => void;
328
+ };
260
329
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-hive/honey-layout",
3
- "version": "2.2.0",
3
+ "version": "2.4.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "react",
@@ -31,10 +31,10 @@
31
31
  "dist"
32
32
  ],
33
33
  "peerDependencies": {
34
- "@mdx-js/react": "3.0.1",
34
+ "@mdx-js/react": "3.1.0",
35
35
  "react": ">=18.0.0",
36
36
  "react-dom": ">=18.0.0",
37
- "react-router-dom": "6.26.2",
37
+ "react-router-dom": "6.28.0",
38
38
  "styled-components": "6.1.13",
39
39
  "highlight.js": "11.10.0"
40
40
  },
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "devDependencies": {
47
47
  "@testing-library/react": "16.0.1",
48
- "@types/jest": "29.5.13",
48
+ "@types/jest": "29.5.14",
49
49
  "@typescript-eslint/eslint-plugin": "7.18.0",
50
50
  "@typescript-eslint/parser": "7.18.0",
51
51
  "@types/react": ">=18.0.0",
@@ -53,21 +53,21 @@
53
53
  "@types/mdx": "2.0.13",
54
54
  "@types/lodash.merge": "4.6.9",
55
55
  "@types/lodash.debounce": "4.0.9",
56
- "@vitejs/plugin-react": "4.3.1",
57
- "@mdx-js/rollup": "3.0.1",
56
+ "@vitejs/plugin-react": "4.3.3",
57
+ "@mdx-js/rollup": "3.1.0",
58
58
  "eslint": "8.57.0",
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.30.0",
62
+ "eslint-plugin-import": "2.31.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
67
  "ts-jest": "29.2.5",
68
- "typescript": "5.6.2",
69
- "vite": "5.4.7",
70
- "vite-plugin-dts": "4.2.2",
68
+ "typescript": "5.6.3",
69
+ "vite": "5.4.11",
70
+ "vite-plugin-dts": "4.3.0",
71
71
  "vite-plugin-checker": "0.8.0"
72
72
  },
73
73
  "jest": {