@koobiq/react-primitives 0.20.0 → 0.21.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,4 +1,4 @@
1
1
  import type { ComponentPropsWithRef, ElementType } from 'react';
2
- import type { ButtonBaseProps } from './types.js';
2
+ import type { ButtonBaseProps } from './types';
3
3
  export declare const Button: import("@koobiq/react-core").PolyForwardComponent<"button", ButtonBaseProps, ElementType>;
4
4
  export type ButtonProps<As extends ElementType = 'button'> = ComponentPropsWithRef<typeof Button<As>>;
@@ -1,13 +1,12 @@
1
1
  "use client";
2
2
  import { jsx } from "react/jsx-runtime";
3
3
  import { polymorphicForwardRef, useDOMRef, filterDOMProps, mergeProps } from "@koobiq/react-core";
4
- import { useRenderProps } from "../../utils/index.js";
5
- import { useSlottedContext } from "../../utils/useSlottedContext.js";
4
+ import { useContextProps, useRenderProps } from "../../utils/index.js";
6
5
  import { ButtonContext } from "./ButtonContext.js";
7
6
  import { useButton } from "../../behaviors/useButton.js";
8
7
  const Button = polymorphicForwardRef(
9
8
  (props, ref) => {
10
- const commonProps = useSlottedContext(props, ButtonContext, props.slot);
9
+ const [ctxProps, ctxRef] = useContextProps(props, ref, ButtonContext);
11
10
  const {
12
11
  as,
13
12
  tabIndex,
@@ -21,12 +20,12 @@ const Button = polymorphicForwardRef(
21
20
  formMethod,
22
21
  formNoValidate,
23
22
  formTarget
24
- } = commonProps;
23
+ } = ctxProps;
25
24
  const Tag = as || "button";
26
- const domRef = useDOMRef(ref);
25
+ const domRef = useDOMRef(ctxRef);
27
26
  const { isHovered, isPressed, isFocused, isFocusVisible, buttonProps } = useButton(
28
27
  {
29
- ...commonProps,
28
+ ...ctxProps,
30
29
  ...(isLoading || isDisabled) && {
31
30
  onPress: void 0,
32
31
  onPressStart: void 0,
@@ -74,11 +73,11 @@ const Button = polymorphicForwardRef(
74
73
  "data-hovered": isHovered || void 0,
75
74
  "data-pressed": isPressed || void 0,
76
75
  "data-focused": isFocused || void 0,
76
+ "data-loading": isLoading || void 0,
77
77
  "data-disabled": isDisabled || void 0,
78
78
  "data-focus-visible": isFocusVisible || void 0,
79
- tabIndex: buttonProps.tabIndex,
80
- ..."tabIndex" in commonProps && { tabIndex },
81
- "aria-hidden": commonProps["aria-hidden"],
79
+ ..."tabIndex" in ctxProps && { tabIndex },
80
+ "aria-hidden": ctxProps["aria-hidden"],
82
81
  "aria-disabled": isLoading ? "true" : buttonProps["aria-disabled"],
83
82
  "aria-busy": isLoading,
84
83
  ref: domRef,
@@ -1,5 +1,3 @@
1
+ import type { ContextValue } from '../../utils';
1
2
  import type { ButtonProps } from './index';
2
- export type ButtonContextProps = {
3
- slots?: Record<string, ButtonProps>;
4
- };
5
- export declare const ButtonContext: import("react").Context<ButtonContextProps>;
3
+ export declare const ButtonContext: import("react").Context<ContextValue<ButtonProps, HTMLElement>>;
@@ -1,14 +1,13 @@
1
1
  "use client";
2
2
  import { jsx } from "react/jsx-runtime";
3
- import { useContext } from "react";
4
- import { polymorphicForwardRef, mergeProps } from "@koobiq/react-core";
3
+ import { polymorphicForwardRef } from "@koobiq/react-core";
4
+ import { useContextProps } from "../../utils/index.js";
5
5
  import { LabelContext } from "./LabelContext.js";
6
6
  const Label = polymorphicForwardRef(
7
7
  (props, ref) => {
8
- const { as: Tag = "label", children, ...other } = props;
9
- const defaultProps = useContext(LabelContext);
10
- const commonProps = mergeProps(defaultProps, other);
11
- return /* @__PURE__ */ jsx(Tag, { ...commonProps, ref, children });
8
+ const [ctxProps, ctxRef] = useContextProps(props, ref, LabelContext);
9
+ const { as: Tag = "label", children, ...other } = ctxProps;
10
+ return /* @__PURE__ */ jsx(Tag, { ...other, ref: ctxRef, children });
12
11
  }
13
12
  );
14
13
  Label.displayName = "Label";
@@ -1,2 +1,3 @@
1
+ import type { ContextValue } from '../../utils';
1
2
  import type { LabelProps } from './index';
2
- export declare const LabelContext: import("react").Context<LabelProps>;
3
+ export declare const LabelContext: import("react").Context<ContextValue<LabelProps, HTMLElement>>;
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { createContext } from "react";
3
- const LabelContext = createContext({});
3
+ const LabelContext = createContext(null);
4
4
  export {
5
5
  LabelContext
6
6
  };
@@ -1,2 +1,4 @@
1
+ import type { ComponentPropsWithRef, ElementType } from 'react';
1
2
  import type { LinkBaseProps } from './types.js';
2
- export declare const Link: import("@koobiq/react-core").PolyForwardComponent<"a", LinkBaseProps, import("react").ElementType>;
3
+ export declare const Link: import("@koobiq/react-core").PolyForwardComponent<"a", LinkBaseProps, ElementType>;
4
+ export type LinkProps<As extends ElementType = 'a'> = ComponentPropsWithRef<typeof Link<As>>;
@@ -37,8 +37,13 @@ const Link = polymorphicForwardRef((props, ref) => {
37
37
  return /* @__PURE__ */ jsx(
38
38
  Tag,
39
39
  {
40
+ "data-hovered": isHovered || void 0,
41
+ "data-pressed": isPressed || void 0,
42
+ "data-focused": isFocused || void 0,
43
+ "data-disabled": props.isDisabled || void 0,
44
+ "data-focus-visible": isFocusVisible || void 0,
40
45
  ...mergeProps(linkProps, renderProps),
41
- tabIndex: props.tabIndex || linkProps.tabIndex,
46
+ ..."tabIndex" in props && { tabIndex: props.tabIndex },
42
47
  ref: domRef,
43
48
  children: renderProps.children
44
49
  }
@@ -1,12 +1,12 @@
1
1
  "use client";
2
2
  import { jsx } from "react/jsx-runtime";
3
3
  import { polymorphicForwardRef } from "@koobiq/react-core";
4
- import { useSlottedContext } from "../../utils/useSlottedContext.js";
4
+ import { useContextProps } from "../../utils/index.js";
5
5
  import { TextContext } from "./TextContext.js";
6
6
  const Text = polymorphicForwardRef((props, ref) => {
7
- const { as: Tag = "p", children, slot, ...other } = props;
8
- const commonProps = useSlottedContext(other, TextContext, slot);
9
- return /* @__PURE__ */ jsx(Tag, { ...commonProps, ref, children });
7
+ const [ctxProps, ctxRef] = useContextProps(props, ref, TextContext);
8
+ const { as: Tag = "p", children, ...other } = ctxProps;
9
+ return /* @__PURE__ */ jsx(Tag, { ...other, ref: ctxRef, children });
10
10
  });
11
11
  Text.displayName = "Text";
12
12
  export {
@@ -1,5 +1,3 @@
1
+ import type { ContextValue } from '../../utils';
1
2
  import type { TextProps } from './Text';
2
- export type TextContextProps = {
3
- slots?: Record<string, TextProps>;
4
- };
5
- export declare const TextContext: import("react").Context<TextContextProps>;
3
+ export declare const TextContext: import("react").Context<ContextValue<TextProps, HTMLElement>>;
@@ -1,6 +1,8 @@
1
1
  "use client";
2
2
  import { createContext } from "react";
3
- const TextContext = createContext({});
3
+ const TextContext = createContext(
4
+ {}
5
+ );
4
6
  export {
5
7
  TextContext
6
8
  };
@@ -1,6 +1,6 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { useMemo, useContext } from "react";
3
- import { useObjectRef, mergeRefs, mergeProps } from "@koobiq/react-core";
3
+ import { isNotNil, useObjectRef, mergeRefs, mergeProps } from "@koobiq/react-core";
4
4
  const DEFAULT_SLOT = Symbol("default");
5
5
  function useRenderProps(props) {
6
6
  const {
@@ -69,7 +69,7 @@ function removeDataAttributes(props) {
69
69
  }
70
70
  function useSlottedContext(context, slot) {
71
71
  const ctx = useContext(context);
72
- if (slot === null) {
72
+ if (!isNotNil(slot)) {
73
73
  return null;
74
74
  }
75
75
  if (ctx && typeof ctx === "object" && "slots" in ctx && ctx.slots) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koobiq/react-primitives",
3
- "version": "0.20.0",
3
+ "version": "0.21.0",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -71,8 +71,8 @@
71
71
  "@react-stately/toggle": "^3.9.2",
72
72
  "@react-stately/tooltip": "^3.5.5",
73
73
  "@react-stately/tree": "^3.8.9",
74
- "@koobiq/logger": "0.20.0",
75
- "@koobiq/react-core": "0.20.0"
74
+ "@koobiq/react-core": "0.21.0",
75
+ "@koobiq/logger": "0.21.0"
76
76
  },
77
77
  "peerDependencies": {
78
78
  "react": "18.x || 19.x",
@@ -1,4 +0,0 @@
1
- import type { Context } from 'react';
2
- export declare function useSlottedContext<PROPS extends object, CONTEXT extends Context<{
3
- slots?: Record<string, any>;
4
- }>>(props: PROPS, context: CONTEXT, slot: string | undefined): PROPS;
@@ -1,11 +0,0 @@
1
- import { useContext } from "react";
2
- import { mergeProps } from "@koobiq/react-core";
3
- function useSlottedContext(props, context, slot) {
4
- const slotContext = useContext(context);
5
- if (!slot) return props;
6
- const propsContext = slotContext.slots?.[slot];
7
- return mergeProps(propsContext, props);
8
- }
9
- export {
10
- useSlottedContext
11
- };