@grandbazar/ui-baza 1.1.5 → 1.2.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/index.cjs +61 -14
- package/dist/index.d.ts +6 -17
- package/dist/index.js +61 -14
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -20,6 +20,27 @@ function classNames(...classes) {
|
|
|
20
20
|
return classes.filter(Boolean).join(" ");
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
function composeEventHandlers(childHandler, parentHandler) {
|
|
24
|
+
return (event) => {
|
|
25
|
+
childHandler?.(event);
|
|
26
|
+
if (!event.defaultPrevented) {
|
|
27
|
+
parentHandler?.(event);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function composeRefs(...refs) {
|
|
33
|
+
return (node) => {
|
|
34
|
+
for (const ref of refs) {
|
|
35
|
+
if (typeof ref === "function") {
|
|
36
|
+
ref(node);
|
|
37
|
+
} else if (ref != null) {
|
|
38
|
+
ref.current = node;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
23
44
|
function createRange(start, length) {
|
|
24
45
|
return Array.from({ length }, (_, index) => start + index);
|
|
25
46
|
}
|
|
@@ -604,26 +625,44 @@ const styles$r = {
|
|
|
604
625
|
defaultSeparator: defaultSeparator
|
|
605
626
|
};
|
|
606
627
|
|
|
628
|
+
function isEventHandler(key) {
|
|
629
|
+
return /^on[A-Z]/.test(key);
|
|
630
|
+
}
|
|
631
|
+
|
|
607
632
|
function Slot({
|
|
608
633
|
children,
|
|
634
|
+
ref,
|
|
609
635
|
...props
|
|
610
636
|
}) {
|
|
611
637
|
if (React.isValidElement(children)) {
|
|
612
638
|
const childProps = children.props;
|
|
613
|
-
const
|
|
614
|
-
const
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
style
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
639
|
+
const mergedProps = { ...childProps };
|
|
640
|
+
for (const key of Object.keys(props)) {
|
|
641
|
+
const parentValue = props[key];
|
|
642
|
+
const childValue = childProps[key];
|
|
643
|
+
if (key === "style") {
|
|
644
|
+
mergedProps.style = {
|
|
645
|
+
...childValue,
|
|
646
|
+
...parentValue
|
|
647
|
+
};
|
|
648
|
+
} else if (key === "className") {
|
|
649
|
+
mergedProps.className = classNames(childValue, parentValue);
|
|
650
|
+
} else if (isEventHandler(key) && typeof childValue === "function") {
|
|
651
|
+
mergedProps[key] = composeEventHandlers(
|
|
652
|
+
childValue,
|
|
653
|
+
parentValue
|
|
654
|
+
);
|
|
655
|
+
} else {
|
|
656
|
+
mergedProps[key] = parentValue;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
if (ref) {
|
|
660
|
+
mergedProps.ref = composeRefs(childProps.ref, ref);
|
|
661
|
+
}
|
|
623
662
|
return React.cloneElement(children, mergedProps);
|
|
624
663
|
}
|
|
625
664
|
if (React.Children.count(children) > 1) {
|
|
626
|
-
|
|
665
|
+
throw new Error("Slot expects a single child element");
|
|
627
666
|
}
|
|
628
667
|
return null;
|
|
629
668
|
}
|
|
@@ -726,11 +765,19 @@ function Button({
|
|
|
726
765
|
color = "accent",
|
|
727
766
|
size = "lg",
|
|
728
767
|
mode = "primary",
|
|
729
|
-
|
|
768
|
+
asChild,
|
|
730
769
|
...props
|
|
731
770
|
}) {
|
|
732
|
-
const
|
|
733
|
-
return
|
|
771
|
+
const Component = asChild ? Slot : "button";
|
|
772
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
773
|
+
Component,
|
|
774
|
+
{
|
|
775
|
+
className: classNames(styles$p.button, styles$p[color], styles$p[size], styles$p[mode], className),
|
|
776
|
+
...!asChild && { type: "button" },
|
|
777
|
+
...props,
|
|
778
|
+
children
|
|
779
|
+
}
|
|
780
|
+
);
|
|
734
781
|
}
|
|
735
782
|
Button.Function = ButtonFunction;
|
|
736
783
|
|
package/dist/index.d.ts
CHANGED
|
@@ -70,18 +70,16 @@ export declare namespace Breadcrumbs {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
|
-
* Button renders a clickable button
|
|
74
|
-
* Supports
|
|
73
|
+
* Button renders a clickable button element with various styles.
|
|
74
|
+
* Supports the asChild pattern for polymorphic rendering via Slot.
|
|
75
75
|
*
|
|
76
76
|
* @param color - Color variant of the button (accent, neutral)
|
|
77
77
|
* @param size - Size of the button (lg, md, sm)
|
|
78
78
|
* @param mode - Visual mode of the button (primary, secondary, tertiary, line)
|
|
79
|
-
* @param
|
|
79
|
+
* @param asChild - When true, merges props onto the child element instead of rendering a button
|
|
80
80
|
* @param children - Content to display inside the button
|
|
81
81
|
*/
|
|
82
|
-
export declare function Button(props:
|
|
83
|
-
|
|
84
|
-
export declare function Button(props: TButtonAsAnchorProps): React.JSX.Element;
|
|
82
|
+
export declare function Button({ children, className, color, size, mode, asChild, ...props }: TButtonProps): JSX.Element;
|
|
85
83
|
|
|
86
84
|
export declare namespace Button {
|
|
87
85
|
var Function: typeof ButtonFunction;
|
|
@@ -507,20 +505,11 @@ declare type TBreadcrumbsProps = {
|
|
|
507
505
|
separator?: default_2.ReactNode;
|
|
508
506
|
};
|
|
509
507
|
|
|
510
|
-
export declare type TButtonAsAnchorProps = TButtonCommonProps & React.AnchorHTMLAttributes<HTMLAnchorElement> & {
|
|
511
|
-
as: 'a';
|
|
512
|
-
ref?: React.Ref<HTMLAnchorElement> | null;
|
|
513
|
-
};
|
|
514
|
-
|
|
515
|
-
export declare type TButtonAsButtonProps = TButtonCommonProps & React.ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
516
|
-
as?: 'button';
|
|
517
|
-
ref?: React.Ref<HTMLButtonElement> | null;
|
|
518
|
-
};
|
|
519
|
-
|
|
520
508
|
declare type TButtonCommonProps = {
|
|
521
509
|
color?: TArrayElement<typeof BUTTON_COLORS>;
|
|
522
510
|
size?: TArrayElement<typeof BUTTON_SIZES>;
|
|
523
511
|
mode?: TArrayElement<typeof BUTTON_MODES>;
|
|
512
|
+
className?: string;
|
|
524
513
|
};
|
|
525
514
|
|
|
526
515
|
declare type TButtonFunctionProps = TAsChildProps<React.ButtonHTMLAttributes<HTMLButtonElement>> & {
|
|
@@ -530,7 +519,7 @@ declare type TButtonFunctionProps = TAsChildProps<React.ButtonHTMLAttributes<HTM
|
|
|
530
519
|
disabled?: boolean;
|
|
531
520
|
};
|
|
532
521
|
|
|
533
|
-
export declare type TButtonProps =
|
|
522
|
+
export declare type TButtonProps = TAsChildProps<React.ButtonHTMLAttributes<HTMLButtonElement>> & TButtonCommonProps;
|
|
534
523
|
|
|
535
524
|
export declare type TCalendarDay = {
|
|
536
525
|
date: number;
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,27 @@ function classNames(...classes) {
|
|
|
16
16
|
return classes.filter(Boolean).join(" ");
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
function composeEventHandlers(childHandler, parentHandler) {
|
|
20
|
+
return (event) => {
|
|
21
|
+
childHandler?.(event);
|
|
22
|
+
if (!event.defaultPrevented) {
|
|
23
|
+
parentHandler?.(event);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function composeRefs(...refs) {
|
|
29
|
+
return (node) => {
|
|
30
|
+
for (const ref of refs) {
|
|
31
|
+
if (typeof ref === "function") {
|
|
32
|
+
ref(node);
|
|
33
|
+
} else if (ref != null) {
|
|
34
|
+
ref.current = node;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
19
40
|
function createRange(start, length) {
|
|
20
41
|
return Array.from({ length }, (_, index) => start + index);
|
|
21
42
|
}
|
|
@@ -600,26 +621,44 @@ const styles$r = {
|
|
|
600
621
|
defaultSeparator: defaultSeparator
|
|
601
622
|
};
|
|
602
623
|
|
|
624
|
+
function isEventHandler(key) {
|
|
625
|
+
return /^on[A-Z]/.test(key);
|
|
626
|
+
}
|
|
627
|
+
|
|
603
628
|
function Slot({
|
|
604
629
|
children,
|
|
630
|
+
ref,
|
|
605
631
|
...props
|
|
606
632
|
}) {
|
|
607
633
|
if (isValidElement(children)) {
|
|
608
634
|
const childProps = children.props;
|
|
609
|
-
const
|
|
610
|
-
const
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
style
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
635
|
+
const mergedProps = { ...childProps };
|
|
636
|
+
for (const key of Object.keys(props)) {
|
|
637
|
+
const parentValue = props[key];
|
|
638
|
+
const childValue = childProps[key];
|
|
639
|
+
if (key === "style") {
|
|
640
|
+
mergedProps.style = {
|
|
641
|
+
...childValue,
|
|
642
|
+
...parentValue
|
|
643
|
+
};
|
|
644
|
+
} else if (key === "className") {
|
|
645
|
+
mergedProps.className = classNames(childValue, parentValue);
|
|
646
|
+
} else if (isEventHandler(key) && typeof childValue === "function") {
|
|
647
|
+
mergedProps[key] = composeEventHandlers(
|
|
648
|
+
childValue,
|
|
649
|
+
parentValue
|
|
650
|
+
);
|
|
651
|
+
} else {
|
|
652
|
+
mergedProps[key] = parentValue;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
if (ref) {
|
|
656
|
+
mergedProps.ref = composeRefs(childProps.ref, ref);
|
|
657
|
+
}
|
|
619
658
|
return cloneElement(children, mergedProps);
|
|
620
659
|
}
|
|
621
660
|
if (React.Children.count(children) > 1) {
|
|
622
|
-
|
|
661
|
+
throw new Error("Slot expects a single child element");
|
|
623
662
|
}
|
|
624
663
|
return null;
|
|
625
664
|
}
|
|
@@ -722,11 +761,19 @@ function Button({
|
|
|
722
761
|
color = "accent",
|
|
723
762
|
size = "lg",
|
|
724
763
|
mode = "primary",
|
|
725
|
-
|
|
764
|
+
asChild,
|
|
726
765
|
...props
|
|
727
766
|
}) {
|
|
728
|
-
const
|
|
729
|
-
return
|
|
767
|
+
const Component = asChild ? Slot : "button";
|
|
768
|
+
return /* @__PURE__ */ jsx(
|
|
769
|
+
Component,
|
|
770
|
+
{
|
|
771
|
+
className: classNames(styles$p.button, styles$p[color], styles$p[size], styles$p[mode], className),
|
|
772
|
+
...!asChild && { type: "button" },
|
|
773
|
+
...props,
|
|
774
|
+
children
|
|
775
|
+
}
|
|
776
|
+
);
|
|
730
777
|
}
|
|
731
778
|
Button.Function = ButtonFunction;
|
|
732
779
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grandbazar/ui-baza",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A lightweight and modular UI kit for building modern, accessible web interfaces. Designed for flexibility, scalability, and developer happiness.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|