@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.
- package/dist/components/Button/Button.d.ts +1 -1
- package/dist/components/Button/Button.js +8 -9
- package/dist/components/Button/ButtonContext.d.ts +2 -4
- package/dist/components/Label/Label.js +5 -6
- package/dist/components/Label/LabelContext.d.ts +2 -1
- package/dist/components/Label/LabelContext.js +1 -1
- package/dist/components/Link/Link.d.ts +3 -1
- package/dist/components/Link/Link.js +6 -1
- package/dist/components/Text/Text.js +4 -4
- package/dist/components/Text/TextContext.d.ts +2 -4
- package/dist/components/Text/TextContext.js +3 -1
- package/dist/utils/index.js +2 -2
- package/package.json +3 -3
- package/dist/utils/useSlottedContext.d.ts +0 -4
- package/dist/utils/useSlottedContext.js +0 -11
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ComponentPropsWithRef, ElementType } from 'react';
|
|
2
|
-
import type { ButtonBaseProps } from './types
|
|
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
|
|
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
|
-
} =
|
|
23
|
+
} = ctxProps;
|
|
25
24
|
const Tag = as || "button";
|
|
26
|
-
const domRef = useDOMRef(
|
|
25
|
+
const domRef = useDOMRef(ctxRef);
|
|
27
26
|
const { isHovered, isPressed, isFocused, isFocusVisible, buttonProps } = useButton(
|
|
28
27
|
{
|
|
29
|
-
...
|
|
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
|
|
80
|
-
|
|
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
|
|
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 {
|
|
4
|
-
import {
|
|
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
|
|
9
|
-
const
|
|
10
|
-
|
|
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,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,
|
|
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
|
|
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 {
|
|
4
|
+
import { useContextProps } from "../../utils/index.js";
|
|
5
5
|
import { TextContext } from "./TextContext.js";
|
|
6
6
|
const Text = polymorphicForwardRef((props, ref) => {
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
return /* @__PURE__ */ jsx(Tag, { ...
|
|
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
|
|
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>>;
|
package/dist/utils/index.js
CHANGED
|
@@ -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
|
|
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.
|
|
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/
|
|
75
|
-
"@koobiq/
|
|
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,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
|
-
};
|