@choice-ui/react 2.0.0 → 2.0.2
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/dist/index.d.ts +2 -9
- package/dist/components/button/dist/index.js +45 -19
- package/dist/components/checkbox/dist/index.d.ts +10 -1
- package/dist/components/checkbox/dist/index.js +49 -5
- package/dist/components/code-block/dist/index.d.ts +11 -14
- package/dist/components/code-block/dist/index.js +120 -93
- package/dist/components/colors/dist/index.d.ts +39 -6
- package/dist/components/colors/src/color-image-paint/color-image-paint.js +2 -2
- package/dist/components/dropdown/dist/index.d.ts +6 -0
- package/dist/components/dropdown/dist/index.js +20 -10
- package/dist/components/emoji-picker/dist/index.d.ts +30 -1
- package/dist/components/emoji-picker/dist/index.js +148 -44
- package/dist/components/form/src/adapters/range-adapter.js +2 -2
- package/dist/components/icon-button/dist/index.d.ts +1 -1
- package/dist/components/icon-button/dist/index.js +39 -0
- package/dist/components/list/dist/index.d.ts +1 -1
- package/dist/components/md-render/dist/index.d.ts +2 -1
- package/dist/components/md-render/dist/index.js +5 -9
- package/dist/components/md-render/src/components/markdown-block.d.ts +3 -0
- package/dist/components/md-render/src/md-render.js +4 -0
- package/dist/components/md-render/src/types.d.ts +3 -0
- package/dist/components/menus/dist/index.d.ts +5 -0
- package/dist/components/menus/dist/index.js +32 -3
- package/dist/components/modal/dist/index.js +2 -2
- package/dist/components/notifications/dist/index.d.ts +1 -5
- package/dist/components/numeric-input/dist/index.d.ts +27 -10
- package/dist/components/numeric-input/dist/index.js +132 -34
- package/dist/components/numeric-input/src/hooks/use-input-interactions.d.ts +3 -1
- package/dist/components/numeric-input/src/hooks/use-input-interactions.js +7 -3
- package/dist/components/numeric-input/src/hooks/use-numeric-input.js +15 -4
- package/dist/components/numeric-input/src/numeric-input.js +5 -4
- package/dist/components/numeric-input/src/utils/value-comparator.js +1 -5
- package/dist/components/panel/dist/index.d.ts +16 -16
- package/dist/components/picture-preview/dist/index.d.ts +5 -0
- package/dist/components/picture-preview/dist/index.js +287 -140
- package/dist/components/popover/dist/index.d.ts +5 -0
- package/dist/components/popover/dist/index.js +21 -2
- package/dist/components/radio/dist/index.d.ts +9 -1
- package/dist/components/radio/dist/index.js +50 -6
- package/dist/components/range/dist/index.d.ts +276 -20
- package/dist/components/range/dist/index.js +1030 -602
- package/dist/components/scroll-area/dist/index.d.ts +4 -27
- package/dist/components/scroll-area/dist/index.js +96 -123
- package/dist/components/separator/dist/index.d.ts +1 -8
- package/dist/components/splitter/dist/index.d.ts +1 -1
- package/dist/components/text-field/dist/index.d.ts +2 -3
- package/dist/components/text-field/dist/index.js +4 -19
- package/dist/components/textarea/dist/index.js +3 -1
- package/dist/components/toast/dist/index.d.ts +274 -0
- package/dist/components/tooltip/dist/index.d.ts +2 -0
- package/dist/components/tooltip/dist/index.js +23 -5
- package/dist/components/virtual-select/dist/index.d.ts +48 -0
- package/package.json +3 -3
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
import { HTMLProps } from 'react';
|
|
2
|
-
import { TooltipProps } from '../../tooltip/src';
|
|
3
2
|
import * as react from 'react';
|
|
4
3
|
|
|
5
|
-
interface ButtonProps extends Omit<HTMLProps<HTMLButtonElement>, "size"> {
|
|
4
|
+
interface ButtonProps extends Omit<HTMLProps<HTMLButtonElement | HTMLAnchorElement>, "size" | "as"> {
|
|
6
5
|
active?: boolean;
|
|
6
|
+
as?: React.ElementType;
|
|
7
7
|
asChild?: boolean;
|
|
8
8
|
className?: string;
|
|
9
9
|
focused?: boolean;
|
|
10
10
|
loading?: boolean;
|
|
11
11
|
readOnly?: boolean;
|
|
12
|
-
/**
|
|
13
|
-
* @default "default"
|
|
14
|
-
*/
|
|
15
12
|
size?: "default" | "large";
|
|
16
|
-
tooltip?: TooltipProps;
|
|
17
|
-
/**
|
|
18
|
-
* @default "primary"
|
|
19
|
-
*/
|
|
20
13
|
variant?: "primary" | "secondary" | "solid" | "destructive" | "secondary-destruct" | "inverse" | "success" | "link" | "link-danger" | "ghost" | "dark" | "reset";
|
|
21
14
|
}
|
|
22
15
|
declare const Button: react.ForwardRefExoticComponent<Omit<ButtonProps, "ref"> & react.RefAttributes<HTMLButtonElement>>;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { LoaderCircle } from "@choiceform/icons-react";
|
|
2
1
|
import { Slot } from "../../slot/dist/index.js";
|
|
3
|
-
import {
|
|
4
|
-
import { forwardRef, isValidElement, cloneElement
|
|
2
|
+
import { LoaderCircle } from "@choiceform/icons-react";
|
|
3
|
+
import { forwardRef, useMemo, isValidElement, cloneElement } from "react";
|
|
5
4
|
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
6
|
-
import { isMultiElement } from "../../../shared/utils/assertion.js";
|
|
7
5
|
import { tcv, tcx } from "../../../shared/utils/tcx/tcx.js";
|
|
6
|
+
import { isMultiElement } from "../../../shared/utils/assertion.js";
|
|
8
7
|
var buttonTv = tcv({
|
|
9
8
|
slots: {
|
|
10
9
|
button: [
|
|
@@ -75,6 +74,10 @@ var buttonTv = tcv({
|
|
|
75
74
|
focused: {
|
|
76
75
|
true: "",
|
|
77
76
|
false: ""
|
|
77
|
+
},
|
|
78
|
+
multiElement: {
|
|
79
|
+
true: "",
|
|
80
|
+
false: ""
|
|
78
81
|
}
|
|
79
82
|
},
|
|
80
83
|
compoundVariants: [
|
|
@@ -123,10 +126,15 @@ var buttonTv = tcv({
|
|
|
123
126
|
variant: ["link", "link-danger", "ghost"],
|
|
124
127
|
disabled: true,
|
|
125
128
|
class: {
|
|
126
|
-
button: [
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
129
|
+
button: ["text-disabled-foreground pointer-events-none"]
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
variant: ["link", "link-danger", "ghost"],
|
|
134
|
+
disabled: true,
|
|
135
|
+
multiElement: true,
|
|
136
|
+
class: {
|
|
137
|
+
button: ["border-default-boundary"]
|
|
130
138
|
}
|
|
131
139
|
},
|
|
132
140
|
{
|
|
@@ -236,6 +244,13 @@ var buttonTv = tcv({
|
|
|
236
244
|
loading: false,
|
|
237
245
|
variant: "dark",
|
|
238
246
|
class: { button: "active:bg-gray-600" }
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
disabled: false,
|
|
250
|
+
loading: false,
|
|
251
|
+
variant: "secondary",
|
|
252
|
+
active: false,
|
|
253
|
+
class: { button: "hover:bg-secondary-background" }
|
|
239
254
|
}
|
|
240
255
|
],
|
|
241
256
|
defaultVariants: {
|
|
@@ -244,7 +259,8 @@ var buttonTv = tcv({
|
|
|
244
259
|
active: false,
|
|
245
260
|
disabled: false,
|
|
246
261
|
loading: false,
|
|
247
|
-
focused: false
|
|
262
|
+
focused: false,
|
|
263
|
+
multiElement: false
|
|
248
264
|
}
|
|
249
265
|
});
|
|
250
266
|
var Button = forwardRef(function Button2(props, ref) {
|
|
@@ -259,13 +275,25 @@ var Button = forwardRef(function Button2(props, ref) {
|
|
|
259
275
|
loading,
|
|
260
276
|
asChild,
|
|
261
277
|
children,
|
|
262
|
-
|
|
278
|
+
as,
|
|
263
279
|
"aria-label": ariaLabel,
|
|
264
280
|
onClick,
|
|
265
281
|
...rest
|
|
266
282
|
} = props;
|
|
267
|
-
const
|
|
268
|
-
const
|
|
283
|
+
const As = as ?? "button";
|
|
284
|
+
const AsComponent = asChild ? Slot : As;
|
|
285
|
+
const elementProps = !asChild && As === "button" ? { type: rest.type ?? "button" } : {};
|
|
286
|
+
const tv = useMemo(
|
|
287
|
+
() => buttonTv({
|
|
288
|
+
variant,
|
|
289
|
+
size,
|
|
290
|
+
active,
|
|
291
|
+
disabled,
|
|
292
|
+
loading,
|
|
293
|
+
focused
|
|
294
|
+
}),
|
|
295
|
+
[variant, size, active, disabled, loading, focused]
|
|
296
|
+
);
|
|
269
297
|
const content = isValidElement(children) ? cloneElement(children, {
|
|
270
298
|
children: children.props.children
|
|
271
299
|
}) : loading ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
@@ -279,23 +307,21 @@ var Button = forwardRef(function Button2(props, ref) {
|
|
|
279
307
|
return props["aria-label"];
|
|
280
308
|
}, [children, props]);
|
|
281
309
|
const handleClick = readOnly ? void 0 : onClick;
|
|
282
|
-
|
|
283
|
-
|
|
310
|
+
return /* @__PURE__ */ jsx(
|
|
311
|
+
AsComponent,
|
|
284
312
|
{
|
|
285
|
-
...rest,
|
|
286
313
|
ref,
|
|
287
|
-
|
|
314
|
+
className: tcx(tv.button({ multiElement: isMultiElement(content) }), className),
|
|
315
|
+
...elementProps,
|
|
316
|
+
...rest,
|
|
288
317
|
disabled: disabled || loading,
|
|
289
318
|
onClick: handleClick,
|
|
290
|
-
className: tcx(tv.button(), className),
|
|
291
|
-
"data-multi-element": isMultiElement(content),
|
|
292
319
|
"aria-disabled": disabled || loading,
|
|
293
320
|
"aria-busy": loading,
|
|
294
321
|
"aria-label": ariaLabelProps,
|
|
295
322
|
children: content
|
|
296
323
|
}
|
|
297
324
|
);
|
|
298
|
-
return tooltip ? /* @__PURE__ */ jsx(Tooltip, { ...tooltip, children: button }) : button;
|
|
299
325
|
});
|
|
300
326
|
Button.displayName = "Button";
|
|
301
327
|
export {
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { HTMLProps, ReactNode } from 'react';
|
|
2
2
|
import * as react from 'react';
|
|
3
3
|
|
|
4
|
+
interface CheckboxIconProps extends Omit<HTMLProps<HTMLDivElement>, "children"> {
|
|
5
|
+
children?: ReactNode | ((props: {
|
|
6
|
+
value?: boolean;
|
|
7
|
+
mixed?: boolean;
|
|
8
|
+
}) => ReactNode);
|
|
9
|
+
}
|
|
10
|
+
declare const CheckboxIcon: react.MemoExoticComponent<react.ForwardRefExoticComponent<Omit<CheckboxIconProps, "ref"> & react.RefAttributes<HTMLDivElement>>>;
|
|
11
|
+
|
|
4
12
|
interface CheckboxLabelProps extends Omit<HTMLProps<HTMLLabelElement>, "htmlFor" | "id" | "disabled"> {
|
|
5
13
|
children: ReactNode;
|
|
6
14
|
}
|
|
@@ -20,9 +28,10 @@ interface CheckboxType {
|
|
|
20
28
|
(props: CheckboxProps & {
|
|
21
29
|
ref?: React.Ref<HTMLInputElement>;
|
|
22
30
|
}): JSX.Element;
|
|
31
|
+
Icon: typeof CheckboxIcon;
|
|
23
32
|
Label: typeof CheckboxLabel;
|
|
24
33
|
displayName?: string;
|
|
25
34
|
}
|
|
26
35
|
declare const Checkbox: CheckboxType;
|
|
27
36
|
|
|
28
|
-
export { Checkbox, type CheckboxProps };
|
|
37
|
+
export { Checkbox, type CheckboxIconProps, type CheckboxLabelProps, type CheckboxProps };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Indeterminate, Check } from "@choiceform/icons-react";
|
|
2
|
-
import { memo, forwardRef, useId, createContext, useContext } from "react";
|
|
2
|
+
import { memo, forwardRef, useId, Children, isValidElement, createContext, useContext } from "react";
|
|
3
3
|
import { useEventCallback } from "usehooks-ts";
|
|
4
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
5
|
import { tcv, tcx } from "../../../shared/utils/tcx/tcx.js";
|
|
@@ -137,6 +137,38 @@ var checkboxTv = tcv({
|
|
|
137
137
|
focused: false
|
|
138
138
|
}
|
|
139
139
|
});
|
|
140
|
+
var CheckboxIcon = memo(
|
|
141
|
+
forwardRef(function CheckboxIcon2(props, ref) {
|
|
142
|
+
const { className, children, ...rest } = props;
|
|
143
|
+
const { value, mixed, disabled, variant } = useCheckboxContext();
|
|
144
|
+
const tv = checkboxTv({
|
|
145
|
+
type: "checkbox",
|
|
146
|
+
variant,
|
|
147
|
+
disabled,
|
|
148
|
+
checked: value || mixed
|
|
149
|
+
});
|
|
150
|
+
const renderIcon = () => {
|
|
151
|
+
if (typeof children === "function") {
|
|
152
|
+
return children({ value, mixed });
|
|
153
|
+
}
|
|
154
|
+
if (children !== void 0) {
|
|
155
|
+
return children;
|
|
156
|
+
}
|
|
157
|
+
return mixed ? /* @__PURE__ */ jsx(Indeterminate, {}) : value ? /* @__PURE__ */ jsx(Check, {}) : null;
|
|
158
|
+
};
|
|
159
|
+
return /* @__PURE__ */ jsx(
|
|
160
|
+
"div",
|
|
161
|
+
{
|
|
162
|
+
ref,
|
|
163
|
+
className: tcx(tv.box(), className),
|
|
164
|
+
"data-active": value,
|
|
165
|
+
...rest,
|
|
166
|
+
children: renderIcon()
|
|
167
|
+
}
|
|
168
|
+
);
|
|
169
|
+
})
|
|
170
|
+
);
|
|
171
|
+
CheckboxIcon.displayName = "Checkbox.Icon";
|
|
140
172
|
var CheckboxLabel = memo(
|
|
141
173
|
forwardRef(function CheckboxLabel2(props, ref) {
|
|
142
174
|
const { children, className, ...rest } = props;
|
|
@@ -195,12 +227,23 @@ var CheckboxBase = forwardRef(function Checkbox(props, ref) {
|
|
|
195
227
|
}
|
|
196
228
|
onKeyDown == null ? void 0 : onKeyDown(e);
|
|
197
229
|
});
|
|
230
|
+
const isIconElement = (child) => {
|
|
231
|
+
var _a;
|
|
232
|
+
return isValidElement(child) && (child.type === CheckboxIcon || ((_a = child.type) == null ? void 0 : _a.displayName) === "Checkbox.Icon");
|
|
233
|
+
};
|
|
234
|
+
const childArray = Children.toArray(children);
|
|
235
|
+
const iconChild = childArray.find(isIconElement);
|
|
236
|
+
const otherChildren = childArray.filter((child) => !isIconElement(child));
|
|
198
237
|
const renderChildren = () => {
|
|
199
|
-
if (
|
|
200
|
-
|
|
238
|
+
if (otherChildren.length === 1) {
|
|
239
|
+
const child = otherChildren[0];
|
|
240
|
+
if (typeof child === "string" || typeof child === "number") {
|
|
241
|
+
return /* @__PURE__ */ jsx(CheckboxLabel, { children: child });
|
|
242
|
+
}
|
|
201
243
|
}
|
|
202
|
-
return
|
|
244
|
+
return otherChildren;
|
|
203
245
|
};
|
|
246
|
+
const renderDefaultIcon = () => /* @__PURE__ */ jsx("div", { className: tv.box(), children: mixed ? /* @__PURE__ */ jsx(Indeterminate, {}) : value ? /* @__PURE__ */ jsx(Check, {}) : null });
|
|
204
247
|
return /* @__PURE__ */ jsx(
|
|
205
248
|
CheckboxContext.Provider,
|
|
206
249
|
{
|
|
@@ -234,7 +277,7 @@ var CheckboxBase = forwardRef(function Checkbox(props, ref) {
|
|
|
234
277
|
...rest
|
|
235
278
|
}
|
|
236
279
|
),
|
|
237
|
-
|
|
280
|
+
iconChild ?? renderDefaultIcon()
|
|
238
281
|
] }),
|
|
239
282
|
renderChildren()
|
|
240
283
|
] })
|
|
@@ -243,6 +286,7 @@ var CheckboxBase = forwardRef(function Checkbox(props, ref) {
|
|
|
243
286
|
});
|
|
244
287
|
var MemoizedCheckbox = memo(CheckboxBase);
|
|
245
288
|
var Checkbox2 = MemoizedCheckbox;
|
|
289
|
+
Checkbox2.Icon = CheckboxIcon;
|
|
246
290
|
Checkbox2.Label = CheckboxLabel;
|
|
247
291
|
Checkbox2.displayName = "Checkbox";
|
|
248
292
|
export {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { default as React__default, ReactNode, HTMLProps, RefObject } from 'react';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
3
|
|
|
5
4
|
interface CodeBlockContextValue {
|
|
6
5
|
codeExpanded: boolean;
|
|
@@ -14,7 +13,7 @@ interface CodeBlockContextValue {
|
|
|
14
13
|
isExpanded: boolean;
|
|
15
14
|
language: string;
|
|
16
15
|
lineCount: number;
|
|
17
|
-
lineThreshold
|
|
16
|
+
lineThreshold?: number;
|
|
18
17
|
needsScroll: boolean;
|
|
19
18
|
scrollRef?: RefObject<HTMLDivElement>;
|
|
20
19
|
variant?: "default" | "light" | "dark";
|
|
@@ -51,35 +50,33 @@ interface CodeBlockFooterProps extends CodeBlockInjectedProps {
|
|
|
51
50
|
}
|
|
52
51
|
interface CodeBlockContentProps extends CodeBlockInjectedProps {
|
|
53
52
|
className?: string;
|
|
54
|
-
code: string;
|
|
55
53
|
language?: string;
|
|
56
54
|
withScrollArea?: boolean;
|
|
55
|
+
children?: string;
|
|
57
56
|
}
|
|
58
57
|
interface CodeBlockCodeProps extends HTMLProps<HTMLDivElement> {
|
|
59
58
|
className?: string;
|
|
60
|
-
|
|
61
|
-
/** 从 CodeBlock 传递的 context */
|
|
59
|
+
children?: string;
|
|
62
60
|
codeBlock?: CodeBlockContextValue;
|
|
63
61
|
codeBlockId?: string;
|
|
64
62
|
language?: string;
|
|
65
|
-
/** 手动指定主题,覆盖自动检测 */
|
|
66
63
|
variant?: "light" | "dark";
|
|
67
64
|
}
|
|
68
65
|
|
|
66
|
+
declare const CodeBlock: React__default.NamedExoticComponent<CodeBlockProps> & {
|
|
67
|
+
Code: React__default.NamedExoticComponent<CodeBlockCodeProps>;
|
|
68
|
+
Content: React__default.NamedExoticComponent<CodeBlockContentProps>;
|
|
69
|
+
Footer: React__default.NamedExoticComponent<CodeBlockFooterProps>;
|
|
70
|
+
Header: React__default.NamedExoticComponent<CodeBlockHeaderProps>;
|
|
71
|
+
};
|
|
72
|
+
|
|
69
73
|
declare const CodeBlockCode: React.NamedExoticComponent<CodeBlockCodeProps>;
|
|
70
74
|
|
|
71
75
|
declare const CodeBlockHeader: React__default.NamedExoticComponent<CodeBlockHeaderProps>;
|
|
72
76
|
|
|
73
77
|
declare const CodeBlockFooter: React.NamedExoticComponent<CodeBlockFooterProps>;
|
|
74
78
|
|
|
75
|
-
declare
|
|
76
|
-
|
|
77
|
-
declare const CodeBlock: React__default.NamedExoticComponent<CodeBlockProps> & {
|
|
78
|
-
Code: React__default.NamedExoticComponent<CodeBlockCodeProps>;
|
|
79
|
-
Content: typeof CodeBlockContent;
|
|
80
|
-
Footer: React__default.NamedExoticComponent<CodeBlockFooterProps>;
|
|
81
|
-
Header: React__default.NamedExoticComponent<CodeBlockHeaderProps>;
|
|
82
|
-
};
|
|
79
|
+
declare const CodeBlockContent: React.NamedExoticComponent<CodeBlockContentProps>;
|
|
83
80
|
|
|
84
81
|
declare function getDefaultFilenameForLanguage(language: string): string;
|
|
85
82
|
|