@koobiq/react-primitives 0.20.0 → 0.21.1
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/NumberField/NumberField.js +3 -1
- package/dist/components/Radio/RadioGroup.js +2 -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/components/TextField/TextField.js +3 -1
- 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
|
}
|
|
@@ -5,7 +5,7 @@ import { filterDOMProps } from "@koobiq/react-core";
|
|
|
5
5
|
import { useLocale } from "@react-aria/i18n";
|
|
6
6
|
import { useNumberField } from "@react-aria/numberfield";
|
|
7
7
|
import { useNumberFieldState } from "@react-stately/numberfield";
|
|
8
|
-
import { useSlottedContext, removeDataAttributes, useRenderProps, Provider } from "../../utils/index.js";
|
|
8
|
+
import { useSlottedContext, removeDataAttributes, useRenderProps, Provider, DEFAULT_SLOT } from "../../utils/index.js";
|
|
9
9
|
import { GroupContext } from "../Group/GroupContext.js";
|
|
10
10
|
import { LabelContext } from "../Label/LabelContext.js";
|
|
11
11
|
import { InputContext } from "../Input/InputContext.js";
|
|
@@ -57,6 +57,7 @@ const NumberField = forwardRef(
|
|
|
57
57
|
ButtonContext,
|
|
58
58
|
{
|
|
59
59
|
slots: {
|
|
60
|
+
[DEFAULT_SLOT]: {},
|
|
60
61
|
increment: incrementButtonProps,
|
|
61
62
|
decrement: decrementButtonProps
|
|
62
63
|
}
|
|
@@ -66,6 +67,7 @@ const NumberField = forwardRef(
|
|
|
66
67
|
TextContext,
|
|
67
68
|
{
|
|
68
69
|
slots: {
|
|
70
|
+
[DEFAULT_SLOT]: {},
|
|
69
71
|
description: descriptionProps,
|
|
70
72
|
errorMessage: errorMessageProps
|
|
71
73
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import { forwardRef } from "react";
|
|
4
4
|
import { filterDOMProps } from "@koobiq/react-core";
|
|
5
|
-
import { useSlottedContext, removeDataAttributes, useRenderProps, Provider } from "../../utils/index.js";
|
|
5
|
+
import { useSlottedContext, removeDataAttributes, useRenderProps, Provider, DEFAULT_SLOT } from "../../utils/index.js";
|
|
6
6
|
import { useRadioGroupState } from "../../behaviors/useRadioGroupState.js";
|
|
7
7
|
import { useRadioGroup } from "../../behaviors/useRadioGroup.js";
|
|
8
8
|
import { FieldErrorContext } from "../FieldError/FieldError.js";
|
|
@@ -59,6 +59,7 @@ const RadioGroup = forwardRef(
|
|
|
59
59
|
TextContext,
|
|
60
60
|
{
|
|
61
61
|
slots: {
|
|
62
|
+
[DEFAULT_SLOT]: {},
|
|
62
63
|
description: descriptionProps,
|
|
63
64
|
errorMessage: errorMessageProps
|
|
64
65
|
}
|
|
@@ -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>>;
|
|
@@ -3,7 +3,7 @@ import { jsx } from "react/jsx-runtime";
|
|
|
3
3
|
import { forwardRef, useRef, useCallback } from "react";
|
|
4
4
|
import { useLocalizedStringFormatter, useControlledState, useIsomorphicEffect, filterDOMProps } from "@koobiq/react-core";
|
|
5
5
|
import { useTextField } from "@react-aria/textfield";
|
|
6
|
-
import { useSlottedContext, removeDataAttributes, useRenderProps, Provider } from "../../utils/index.js";
|
|
6
|
+
import { useSlottedContext, removeDataAttributes, useRenderProps, Provider, DEFAULT_SLOT } from "../../utils/index.js";
|
|
7
7
|
import intlMessages from "./intl.json.js";
|
|
8
8
|
import { InputContext } from "../Input/InputContext.js";
|
|
9
9
|
import { TextareaContext } from "../Textarea/TextareaContext.js";
|
|
@@ -99,6 +99,7 @@ function TextFieldRender(props, ref) {
|
|
|
99
99
|
TextContext,
|
|
100
100
|
{
|
|
101
101
|
slots: {
|
|
102
|
+
[DEFAULT_SLOT]: {},
|
|
102
103
|
description: descriptionProps,
|
|
103
104
|
errorMessage: errorMessageProps
|
|
104
105
|
}
|
|
@@ -108,6 +109,7 @@ function TextFieldRender(props, ref) {
|
|
|
108
109
|
ButtonContext,
|
|
109
110
|
{
|
|
110
111
|
slots: {
|
|
112
|
+
[DEFAULT_SLOT]: {},
|
|
111
113
|
"clear-button": {
|
|
112
114
|
"aria-label": stringFormatter.format("clear"),
|
|
113
115
|
preventFocusOnPress: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koobiq/react-primitives",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.1",
|
|
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.
|
|
75
|
-
"@koobiq/react-core": "0.
|
|
74
|
+
"@koobiq/logger": "0.21.1",
|
|
75
|
+
"@koobiq/react-core": "0.21.1"
|
|
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
|
-
};
|