@mezzanine-ui/react 1.0.0-beta.1 → 1.0.0-beta.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/Badge/Badge.js +2 -2
- package/Breadcrumb/BreadcrumbItem.d.ts +1 -1
- package/Description/Description.d.ts +40 -0
- package/Description/Description.js +33 -0
- package/Description/DescriptionContent.d.ts +41 -0
- package/Description/DescriptionContent.js +14 -0
- package/Description/DescriptionGroup.d.ts +13 -0
- package/Description/DescriptionGroup.js +12 -0
- package/Description/DescriptionTitle.d.ts +45 -0
- package/Description/DescriptionTitle.js +17 -0
- package/Description/index.d.ts +8 -0
- package/Description/index.js +4 -0
- package/Dropdown/Dropdown.d.ts +15 -3
- package/Dropdown/Dropdown.js +63 -25
- package/Dropdown/DropdownItem.d.ts +4 -4
- package/Dropdown/DropdownItemCard.d.ts +5 -5
- package/Dropdown/DropdownStatus.d.ts +2 -2
- package/Form/FormControlContext.d.ts +2 -2
- package/Form/FormField.d.ts +56 -4
- package/Form/FormField.js +8 -6
- package/Form/FormHintText.d.ts +24 -1
- package/Form/FormHintText.js +4 -4
- package/Form/FormLabel.d.ts +6 -3
- package/Form/FormLabel.js +5 -3
- package/Input/PasswordStrengthIndicator/PasswordStrengthIndicator.js +1 -1
- package/Navigation/Navigation.d.ts +10 -1
- package/Navigation/Navigation.js +22 -7
- package/Navigation/NavigationFooter.js +4 -2
- package/Navigation/NavigationHeader.d.ts +7 -1
- package/Navigation/NavigationHeader.js +5 -3
- package/Navigation/NavigationOption.d.ts +1 -1
- package/Navigation/NavigationOption.js +19 -25
- package/Navigation/NavigationOptionCategory.js +19 -2
- package/Navigation/context.d.ts +2 -0
- package/Table/Table.d.ts +53 -15
- package/Table/Table.js +178 -82
- package/Table/TableContext.d.ts +18 -42
- package/Table/components/TableActionsCell.d.ts +26 -0
- package/Table/components/TableActionsCell.js +78 -0
- package/Table/components/TableBody.d.ts +2 -5
- package/Table/components/TableBody.js +16 -19
- package/Table/components/TableBulkActions.d.ts +15 -0
- package/Table/components/TableBulkActions.js +44 -0
- package/Table/components/TableCell.d.ts +2 -0
- package/Table/components/TableCell.js +42 -10
- package/Table/components/TableColGroup.js +10 -112
- package/Table/components/TableColumnTitleMenu.d.ts +6 -0
- package/Table/components/TableColumnTitleMenu.js +20 -0
- package/Table/components/TableDragHandleCell.d.ts +2 -0
- package/Table/components/TableDragHandleCell.js +8 -1
- package/Table/components/TableExpandCell.d.ts +2 -0
- package/Table/components/TableExpandCell.js +8 -1
- package/Table/components/TableExpandedRow.js +3 -2
- package/Table/components/TableHeader.d.ts +2 -4
- package/Table/components/TableHeader.js +11 -14
- package/Table/components/TableResizeHandle.js +3 -7
- package/Table/components/TableRow.js +54 -20
- package/Table/components/TableSelectionCell.d.ts +5 -0
- package/Table/components/TableSelectionCell.js +12 -1
- package/Table/components/index.d.ts +1 -0
- package/Table/components/index.js +1 -0
- package/Table/hooks/index.d.ts +1 -1
- package/Table/hooks/index.js +1 -1
- package/Table/hooks/useTableDataSource.d.ts +2 -2
- package/Table/hooks/useTableExpansion.js +0 -6
- package/Table/hooks/useTableFixedOffsets.d.ts +1 -1
- package/Table/hooks/useTableFixedOffsets.js +19 -21
- package/Table/hooks/useTableResizedColumns.d.ts +2 -0
- package/Table/hooks/useTableResizedColumns.js +22 -0
- package/Table/hooks/useTableScroll.d.ts +3 -1
- package/Table/hooks/useTableScroll.js +25 -19
- package/Table/hooks/useTableSelection.js +32 -8
- package/Table/hooks/useTableVirtualization.d.ts +1 -1
- package/Table/index.d.ts +4 -4
- package/Table/index.js +5 -3
- package/Table/utils/calculateColumnWidths.d.ts +28 -0
- package/Table/utils/calculateColumnWidths.js +80 -0
- package/Table/utils/index.d.ts +2 -0
- package/Table/utils/index.js +1 -0
- package/Table/utils/useTableRowSelection.d.ts +5 -5
- package/Table/utils/useTableRowSelection.js +1 -1
- package/index.d.ts +6 -4
- package/index.js +9 -1
- package/package.json +4 -4
- package/utils/format-number-with-commas.d.ts +4 -0
- package/utils/format-number-with-commas.js +27 -0
- package/utils/parse-number-with-commas.d.ts +4 -0
- package/utils/parse-number-with-commas.js +22 -0
- package/Table/hooks/useTableColumns.d.ts +0 -8
- package/Table/hooks/useTableColumns.js +0 -91
package/Badge/Badge.js
CHANGED
|
@@ -15,11 +15,11 @@ const isCountVariant = (variant) => [
|
|
|
15
15
|
*/
|
|
16
16
|
const Badge = forwardRef(function Badge(props, ref) {
|
|
17
17
|
const { children, count, className, overflowCount, text, variant, ...rest } = props;
|
|
18
|
-
return (jsxs("div", { className: badgeClasses.container(!!children), children: [jsx("span", { ...rest, ref: ref, className: cx(badgeClasses.host, badgeClasses.variant(variant), { [badgeClasses.hide]: isCountVariant(variant) && count === 0 }, className), children: isCountVariant(variant)
|
|
18
|
+
return (jsxs("div", { className: badgeClasses.container(!!children), children: [children, jsx("span", { ...rest, ref: ref, className: cx(badgeClasses.host, badgeClasses.variant(variant), { [badgeClasses.hide]: isCountVariant(variant) && count === 0 }, className), children: isCountVariant(variant)
|
|
19
19
|
? overflowCount && count > overflowCount
|
|
20
20
|
? `${overflowCount}+`
|
|
21
21
|
: count
|
|
22
|
-
: text })
|
|
22
|
+
: text })] }));
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
export { Badge as default };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const BreadcrumbItem: import("react").ForwardRefExoticComponent<Omit<Omit<import("..").ComponentPropsWithoutKeyAndRef<"button">, "label" | "component" | "current" | "options" | "href" | "target"
|
|
1
|
+
declare const BreadcrumbItem: import("react").ForwardRefExoticComponent<Omit<Omit<import("..").ComponentPropsWithoutKeyAndRef<"button">, "expand" | "label" | "component" | "current" | "options" | "href" | "target"> & (import("./typings").BreadcrumbDropdownItemProps | import("./typings").BreadcrumbItemTextProps | import("./typings").BreadcrumbLinkItemProps), "component"> & {
|
|
2
2
|
component?: import("./typings").BreadcrumbItemComponent | undefined;
|
|
3
3
|
} & import("react").RefAttributes<HTMLElement>>;
|
|
4
4
|
export default BreadcrumbItem;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { DescriptionContentVariant, DescriptionOrientation } from '@mezzanine-ui/core/description';
|
|
2
|
+
import { DescriptionTitleProps } from './DescriptionTitle';
|
|
3
|
+
import { DescriptionContentProps } from './DescriptionContent';
|
|
4
|
+
import { BadgeProps } from '../Badge/typings';
|
|
5
|
+
import { ButtonProps } from '../Button';
|
|
6
|
+
import { ProgressProps } from '../Progress';
|
|
7
|
+
import { TagProps } from '../Tag/typings';
|
|
8
|
+
export interface DescriptionProps {
|
|
9
|
+
/**
|
|
10
|
+
* Custom class name for description
|
|
11
|
+
*/
|
|
12
|
+
className?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Defines what is rendered as the description content
|
|
15
|
+
*/
|
|
16
|
+
contentProps: DescriptionContentProps | {
|
|
17
|
+
variant: Extract<DescriptionContentVariant, 'badge'>;
|
|
18
|
+
badge: BadgeProps;
|
|
19
|
+
} | {
|
|
20
|
+
variant: Extract<DescriptionContentVariant, 'button'>;
|
|
21
|
+
button: ButtonProps;
|
|
22
|
+
} | {
|
|
23
|
+
variant: Extract<DescriptionContentVariant, 'progress'>;
|
|
24
|
+
progress: ProgressProps;
|
|
25
|
+
} | {
|
|
26
|
+
variant: Extract<DescriptionContentVariant, 'tags'>;
|
|
27
|
+
tags: TagProps[];
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Define the layout direction between the title and the content
|
|
31
|
+
* @default 'horizontal'
|
|
32
|
+
*/
|
|
33
|
+
orientation?: DescriptionOrientation;
|
|
34
|
+
/**
|
|
35
|
+
* Props passed to the DescriptionTitle component
|
|
36
|
+
*/
|
|
37
|
+
titleProps: DescriptionTitleProps;
|
|
38
|
+
}
|
|
39
|
+
declare const Description: import("react").ForwardRefExoticComponent<DescriptionProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
40
|
+
export default Description;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import { forwardRef, useMemo } from 'react';
|
|
4
|
+
import { descriptionClasses } from '@mezzanine-ui/core/description';
|
|
5
|
+
import DescriptionTitle from './DescriptionTitle.js';
|
|
6
|
+
import DescriptionContent from './DescriptionContent.js';
|
|
7
|
+
import Button from '../Button/Button.js';
|
|
8
|
+
import TagGroup from '../Tag/TagGroup.js';
|
|
9
|
+
import Tag from '../Tag/Tag.js';
|
|
10
|
+
import Progress from '../Progress/Progress.js';
|
|
11
|
+
import Badge from '../Badge/Badge.js';
|
|
12
|
+
import cx from 'clsx';
|
|
13
|
+
|
|
14
|
+
const Description = forwardRef(function Description(props, ref) {
|
|
15
|
+
const { className, contentProps, orientation = 'horizontal', titleProps, } = props;
|
|
16
|
+
const contentComponent = useMemo(() => {
|
|
17
|
+
switch (contentProps.variant) {
|
|
18
|
+
case 'badge':
|
|
19
|
+
return jsx(Badge, { ...contentProps.badge });
|
|
20
|
+
case 'button':
|
|
21
|
+
return jsx(Button, { ...contentProps.button });
|
|
22
|
+
case 'progress':
|
|
23
|
+
return jsx(Progress, { ...contentProps.progress });
|
|
24
|
+
case 'tags':
|
|
25
|
+
return (jsx(TagGroup, { children: contentProps.tags.map((tagProps, index) => (jsx(Tag, { ...tagProps }, `${tagProps.label}-${index}`))) }));
|
|
26
|
+
default:
|
|
27
|
+
return jsx(DescriptionContent, { ...contentProps });
|
|
28
|
+
}
|
|
29
|
+
}, [contentProps]);
|
|
30
|
+
return (jsxs("div", { className: cx(descriptionClasses.host, descriptionClasses.orientation(orientation), className), ref: ref, children: [jsx(DescriptionTitle, { ...titleProps }), contentComponent] }));
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export { Description as default };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { IconDefinition } from '@mezzanine-ui/icons';
|
|
2
|
+
import { DescriptionSize, DescriptionContentVariant } from '@mezzanine-ui/core/description';
|
|
3
|
+
interface DescriptionContentBaseProps {
|
|
4
|
+
/**
|
|
5
|
+
* Custom class name for content
|
|
6
|
+
*/
|
|
7
|
+
className?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Content text
|
|
10
|
+
*/
|
|
11
|
+
children: string;
|
|
12
|
+
/**
|
|
13
|
+
* Control the text size of the content
|
|
14
|
+
* @default 'main'
|
|
15
|
+
*/
|
|
16
|
+
size?: DescriptionSize;
|
|
17
|
+
/**
|
|
18
|
+
* Define the style and behavior of the content
|
|
19
|
+
* @default 'normal'
|
|
20
|
+
*/
|
|
21
|
+
variant?: Extract<DescriptionContentVariant, 'normal' | 'statistic' | 'trend-up' | 'trend-down'>;
|
|
22
|
+
/**
|
|
23
|
+
* Custom icon rendered after the content text
|
|
24
|
+
*/
|
|
25
|
+
icon?: never;
|
|
26
|
+
/**
|
|
27
|
+
* Click handler for the icon.
|
|
28
|
+
*/
|
|
29
|
+
onClickIcon?: never;
|
|
30
|
+
}
|
|
31
|
+
interface DescriptionContentWithClickableIcon {
|
|
32
|
+
className?: string;
|
|
33
|
+
children: string;
|
|
34
|
+
size?: DescriptionSize;
|
|
35
|
+
variant: Extract<DescriptionContentVariant, 'with-icon'>;
|
|
36
|
+
icon: IconDefinition;
|
|
37
|
+
onClickIcon?: VoidFunction;
|
|
38
|
+
}
|
|
39
|
+
export type DescriptionContentProps = DescriptionContentBaseProps | DescriptionContentWithClickableIcon;
|
|
40
|
+
declare const DescriptionContent: import("react").ForwardRefExoticComponent<DescriptionContentProps & import("react").RefAttributes<HTMLSpanElement>>;
|
|
41
|
+
export default DescriptionContent;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { forwardRef } from 'react';
|
|
4
|
+
import { CaretUpIcon, CaretDownIcon } from '@mezzanine-ui/icons';
|
|
5
|
+
import { descriptionClasses } from '@mezzanine-ui/core/description';
|
|
6
|
+
import Icon from '../Icon/Icon.js';
|
|
7
|
+
import cx from 'clsx';
|
|
8
|
+
|
|
9
|
+
const DescriptionContent = forwardRef(function DescriptionContent(props, ref) {
|
|
10
|
+
const { className, children, icon, onClickIcon, size = 'main', variant = 'normal', } = props;
|
|
11
|
+
return (jsxs("span", { className: cx(descriptionClasses.contentHost, descriptionClasses.contentVariant(variant), descriptionClasses.contentSize(size), className), ref: ref, children: [variant === 'trend-up' && (jsx(Icon, { className: descriptionClasses.contentTrendUp, icon: CaretUpIcon, size: 16 })), variant === 'trend-down' && (jsx(Icon, { className: descriptionClasses.contentTrendDown, icon: CaretDownIcon, size: 16 })), children, variant === 'with-icon' && icon && (jsx(Icon, { className: descriptionClasses.contentIcon, icon: icon, size: 16, onClick: onClickIcon }))] }));
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export { DescriptionContent as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
export interface DescriptionGroupProps {
|
|
3
|
+
/**
|
|
4
|
+
* Custom class name for group
|
|
5
|
+
*/
|
|
6
|
+
className?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Description elements to be grouped and displayed together
|
|
9
|
+
*/
|
|
10
|
+
children: ReactElement[];
|
|
11
|
+
}
|
|
12
|
+
declare const DescriptionGroup: import("react").ForwardRefExoticComponent<DescriptionGroupProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
13
|
+
export default DescriptionGroup;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { forwardRef } from 'react';
|
|
4
|
+
import { descriptionClasses } from '@mezzanine-ui/core/description';
|
|
5
|
+
import cx from 'clsx';
|
|
6
|
+
|
|
7
|
+
const DescriptionGroup = forwardRef(function DescriptionGroup(props, ref) {
|
|
8
|
+
const { className, children } = props;
|
|
9
|
+
return (jsx("div", { className: cx(descriptionClasses.groupHost, className), ref: ref, children: children }));
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export { DescriptionGroup as default };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { IconDefinition } from '@mezzanine-ui/icons';
|
|
2
|
+
import { DescriptionWidthType } from '@mezzanine-ui/core/description';
|
|
3
|
+
import { BadgeDotVariant } from '@mezzanine-ui/core/badge';
|
|
4
|
+
import { Placement } from '@floating-ui/react-dom';
|
|
5
|
+
interface DescriptionTitleBaseProps {
|
|
6
|
+
/**
|
|
7
|
+
* Displays a badge dot alongside the title text
|
|
8
|
+
*/
|
|
9
|
+
badge?: BadgeDotVariant;
|
|
10
|
+
/**
|
|
11
|
+
* Custom class name for title
|
|
12
|
+
*/
|
|
13
|
+
className?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Title text
|
|
16
|
+
*/
|
|
17
|
+
children: string;
|
|
18
|
+
/**
|
|
19
|
+
* Controls the layout width behavior of the title
|
|
20
|
+
* @default 'stretch'
|
|
21
|
+
*/
|
|
22
|
+
widthType?: DescriptionWidthType;
|
|
23
|
+
}
|
|
24
|
+
interface DescriptionTitleWithTooltip {
|
|
25
|
+
/**
|
|
26
|
+
* An icon displayed after the title text
|
|
27
|
+
*/
|
|
28
|
+
icon: IconDefinition;
|
|
29
|
+
/**
|
|
30
|
+
* Text content displayed in a tooltip when hovering over the icon
|
|
31
|
+
*/
|
|
32
|
+
tooltip: string;
|
|
33
|
+
/**
|
|
34
|
+
* Defines the placement of the tooltip relative to the icon
|
|
35
|
+
*/
|
|
36
|
+
tooltipPlacement?: Placement;
|
|
37
|
+
}
|
|
38
|
+
interface DescriptionTitleWithoutTooltip {
|
|
39
|
+
icon?: IconDefinition;
|
|
40
|
+
tooltip?: undefined;
|
|
41
|
+
tooltipPlacement?: undefined;
|
|
42
|
+
}
|
|
43
|
+
export type DescriptionTitleProps = (DescriptionTitleBaseProps & DescriptionTitleWithTooltip) | (DescriptionTitleBaseProps & DescriptionTitleWithoutTooltip);
|
|
44
|
+
declare const DescriptionTitle: import("react").ForwardRefExoticComponent<DescriptionTitleProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
45
|
+
export default DescriptionTitle;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { forwardRef } from 'react';
|
|
4
|
+
import { descriptionClasses } from '@mezzanine-ui/core/description';
|
|
5
|
+
import Badge from '../Badge/Badge.js';
|
|
6
|
+
import Tooltip from '../Tooltip/Tooltip.js';
|
|
7
|
+
import Icon from '../Icon/Icon.js';
|
|
8
|
+
import cx from 'clsx';
|
|
9
|
+
|
|
10
|
+
const DescriptionTitle = forwardRef(function DescriptionTitle(props, ref) {
|
|
11
|
+
const { badge, className, children, icon, tooltip, tooltipPlacement, widthType = 'stretch', } = props;
|
|
12
|
+
return (jsxs("div", { className: cx(descriptionClasses.titleHost, descriptionClasses.titleWidth(widthType), className), ref: ref, children: [badge ? (jsx(Badge, { variant: badge, text: children, className: descriptionClasses.titleText })) : (jsx("span", { className: descriptionClasses.titleText, children: children })), icon ? (tooltip ? (jsx(Tooltip, { title: tooltip, options: {
|
|
13
|
+
placement: tooltipPlacement !== null && tooltipPlacement !== void 0 ? tooltipPlacement : 'top',
|
|
14
|
+
}, children: ({ onMouseEnter, onMouseLeave, ref }) => (jsx(Icon, { ref: ref, icon: icon, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, size: 16 })) })) : (jsx(Icon, { icon: icon, size: 16 }))) : null] }));
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export { DescriptionTitle as default };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { default as Description } from './Description';
|
|
2
|
+
export type { DescriptionProps } from './Description';
|
|
3
|
+
export { default as DescriptionTitle } from './DescriptionTitle';
|
|
4
|
+
export type { DescriptionTitleProps } from './DescriptionTitle';
|
|
5
|
+
export { default as DescriptionContent } from './DescriptionContent';
|
|
6
|
+
export type { DescriptionContentProps } from './DescriptionContent';
|
|
7
|
+
export { default as DescriptionGroup } from './DescriptionGroup';
|
|
8
|
+
export type { DescriptionGroupProps } from './DescriptionGroup';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { default as Description } from './Description.js';
|
|
2
|
+
export { default as DescriptionTitle } from './DescriptionTitle.js';
|
|
3
|
+
export { default as DescriptionContent } from './DescriptionContent.js';
|
|
4
|
+
export { default as DescriptionGroup } from './DescriptionGroup.js';
|
package/Dropdown/Dropdown.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { DropdownInputPosition, DropdownItemSharedProps, DropdownOption, DropdownType } from '@mezzanine-ui/core/dropdown/dropdown';
|
|
3
3
|
import { ButtonProps } from '../Button';
|
|
4
4
|
import { InputProps } from '../Input';
|
|
5
5
|
import { PopperPlacement } from '../Popper';
|
|
@@ -45,7 +45,7 @@ export interface DropdownProps extends DropdownItemSharedProps {
|
|
|
45
45
|
* The position of the input.
|
|
46
46
|
* @default 'outside'
|
|
47
47
|
*/
|
|
48
|
-
inputPosition?:
|
|
48
|
+
inputPosition?: DropdownInputPosition;
|
|
49
49
|
/**
|
|
50
50
|
* Whether to match the input value.
|
|
51
51
|
* @default false
|
|
@@ -64,6 +64,10 @@ export interface DropdownProps extends DropdownItemSharedProps {
|
|
|
64
64
|
* The max height of the dropdown list.
|
|
65
65
|
*/
|
|
66
66
|
maxHeight?: number | string;
|
|
67
|
+
/**
|
|
68
|
+
* Whether the dropdown is open (controlled).
|
|
69
|
+
*/
|
|
70
|
+
open?: boolean;
|
|
67
71
|
/**
|
|
68
72
|
* Callback fired when the action cancel is clicked.
|
|
69
73
|
*/
|
|
@@ -92,6 +96,10 @@ export interface DropdownProps extends DropdownItemSharedProps {
|
|
|
92
96
|
* Callback fired when the dropdown is opened.
|
|
93
97
|
*/
|
|
94
98
|
onOpen?: () => void;
|
|
99
|
+
/**
|
|
100
|
+
* Callback fired when the dropdown visibility changes.
|
|
101
|
+
*/
|
|
102
|
+
onVisibilityChange?: (open: boolean) => void;
|
|
95
103
|
/**
|
|
96
104
|
* Callback fired when the item is selected.
|
|
97
105
|
*/
|
|
@@ -121,6 +129,10 @@ export interface DropdownProps extends DropdownItemSharedProps {
|
|
|
121
129
|
/**
|
|
122
130
|
* The type of the dropdown.
|
|
123
131
|
*/
|
|
124
|
-
type?:
|
|
132
|
+
type?: DropdownType;
|
|
133
|
+
/**
|
|
134
|
+
* The z-index of the dropdown.
|
|
135
|
+
*/
|
|
136
|
+
zIndex?: number | string;
|
|
125
137
|
}
|
|
126
138
|
export default function Dropdown(props: DropdownProps): import("react/jsx-runtime").JSX.Element;
|
package/Dropdown/Dropdown.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
-
import { useId, useMemo, useState, useRef,
|
|
3
|
+
import { useId, useMemo, useState, useRef, useCallback, useEffect, cloneElement, createElement } from 'react';
|
|
4
4
|
import cx from 'clsx';
|
|
5
5
|
import { dropdownClasses } from '@mezzanine-ui/core/dropdown/dropdown';
|
|
6
6
|
import { size, offset } from '@floating-ui/react-dom';
|
|
@@ -14,7 +14,7 @@ import DropdownItem from './DropdownItem.js';
|
|
|
14
14
|
import Popper from '../Popper/Popper.js';
|
|
15
15
|
|
|
16
16
|
function Dropdown(props) {
|
|
17
|
-
const { activeIndex: activeIndexProp, id, children, options = [], type = 'default', maxHeight, disabled = false, showDropdownActions = false, actionCancelText, actionConfirmText, actionText, actionClearText, actionCustomButtonProps, showActionShowTopBar, isMatchInputValue = false, inputPosition = 'outside', placement = 'bottom', sameWidth = false, listboxId: listboxIdProp, listboxLabel, onClose, onOpen, onSelect, onActionConfirm, onActionCancel, onActionCustom, onActionClear, onItemHover, } = props;
|
|
17
|
+
const { activeIndex: activeIndexProp, id, children, options = [], type = 'default', maxHeight, disabled = false, showDropdownActions = false, actionCancelText, actionConfirmText, actionText, actionClearText, actionCustomButtonProps, showActionShowTopBar, isMatchInputValue = false, inputPosition = 'outside', placement = 'bottom', sameWidth = false, listboxId: listboxIdProp, listboxLabel, onClose, onOpen, open: openProp, onVisibilityChange, onSelect, onActionConfirm, onActionCancel, onActionCustom, onActionClear, onItemHover, zIndex, } = props;
|
|
18
18
|
const isInline = inputPosition === 'inside';
|
|
19
19
|
const inputId = useId();
|
|
20
20
|
const defaultListboxId = `${inputId}-listbox`;
|
|
@@ -33,11 +33,27 @@ function Dropdown(props) {
|
|
|
33
33
|
onClick: onActionCustom,
|
|
34
34
|
onClear: onActionClear,
|
|
35
35
|
};
|
|
36
|
-
}, [
|
|
37
|
-
|
|
36
|
+
}, [
|
|
37
|
+
showDropdownActions,
|
|
38
|
+
actionCancelText,
|
|
39
|
+
actionConfirmText,
|
|
40
|
+
actionClearText,
|
|
41
|
+
actionText,
|
|
42
|
+
actionCustomButtonProps,
|
|
43
|
+
showActionShowTopBar,
|
|
44
|
+
onActionConfirm,
|
|
45
|
+
onActionCancel,
|
|
46
|
+
onActionCustom,
|
|
47
|
+
onActionClear,
|
|
48
|
+
]);
|
|
49
|
+
const [uncontrolledOpen, setUncontrolledOpen] = useState(false);
|
|
50
|
+
const isOpenControlled = openProp !== undefined;
|
|
51
|
+
const isOpen = isOpenControlled ? !!openProp : uncontrolledOpen;
|
|
38
52
|
const [uncontrolledActiveIndex, setUncontrolledActiveIndex] = useState(activeIndexProp !== null && activeIndexProp !== void 0 ? activeIndexProp : null);
|
|
39
53
|
const isActiveIndexControlled = activeIndexProp !== undefined;
|
|
40
|
-
const mergedActiveIndex = isActiveIndexControlled
|
|
54
|
+
const mergedActiveIndex = isActiveIndexControlled
|
|
55
|
+
? activeIndexProp
|
|
56
|
+
: uncontrolledActiveIndex;
|
|
41
57
|
const containerRef = useRef(null);
|
|
42
58
|
const ariaActivedescendant = useMemo(() => {
|
|
43
59
|
if (mergedActiveIndex !== null && mergedActiveIndex >= 0) {
|
|
@@ -96,6 +112,15 @@ function Dropdown(props) {
|
|
|
96
112
|
const placementBase = popoverPlacement.split('-')[0];
|
|
97
113
|
return placementBase === 'top' ? 'top' : 'bottom';
|
|
98
114
|
}, [isInline, popoverPlacement]);
|
|
115
|
+
const setOpen = useCallback((next) => {
|
|
116
|
+
const nextValue = typeof next === 'function'
|
|
117
|
+
? next(isOpen)
|
|
118
|
+
: next;
|
|
119
|
+
if (!isOpenControlled) {
|
|
120
|
+
setUncontrolledOpen(nextValue);
|
|
121
|
+
}
|
|
122
|
+
onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(nextValue);
|
|
123
|
+
}, [isOpen, isOpenControlled, onVisibilityChange]);
|
|
99
124
|
useEffect(() => {
|
|
100
125
|
if (prevIsOpenRef.current === isOpen)
|
|
101
126
|
return;
|
|
@@ -144,13 +169,23 @@ function Dropdown(props) {
|
|
|
144
169
|
onSelect,
|
|
145
170
|
options,
|
|
146
171
|
type,
|
|
147
|
-
}), [
|
|
172
|
+
}), [
|
|
173
|
+
actionConfig,
|
|
174
|
+
mergedActiveIndex,
|
|
175
|
+
disabled,
|
|
176
|
+
followText,
|
|
177
|
+
listboxId,
|
|
178
|
+
listboxLabel,
|
|
179
|
+
maxHeight,
|
|
180
|
+
sameWidth,
|
|
181
|
+
handleItemHover,
|
|
182
|
+
onSelect,
|
|
183
|
+
options,
|
|
184
|
+
type,
|
|
185
|
+
]);
|
|
148
186
|
const triggerElement = useMemo(() => {
|
|
149
187
|
const childWithRef = children;
|
|
150
|
-
const composedRef = composeRefs([
|
|
151
|
-
anchorRef,
|
|
152
|
-
childWithRef.ref,
|
|
153
|
-
]);
|
|
188
|
+
const composedRef = composeRefs([anchorRef, childWithRef.ref]);
|
|
154
189
|
return cloneElement(childWithRef, {
|
|
155
190
|
ref: composedRef,
|
|
156
191
|
...getComboboxProps,
|
|
@@ -160,19 +195,17 @@ function Dropdown(props) {
|
|
|
160
195
|
if (event === null || event === void 0 ? void 0 : event.defaultPrevented)
|
|
161
196
|
return;
|
|
162
197
|
if (!isInline) {
|
|
163
|
-
|
|
198
|
+
setOpen((prev) => !prev);
|
|
164
199
|
}
|
|
165
200
|
},
|
|
166
201
|
});
|
|
167
|
-
}, [children, isInline,
|
|
202
|
+
}, [children, getComboboxProps, isInline, setOpen]);
|
|
168
203
|
const inlineTriggerElement = useMemo(() => {
|
|
169
204
|
if (!isInline) {
|
|
170
205
|
return null;
|
|
171
206
|
}
|
|
172
207
|
const childWithRef = children;
|
|
173
|
-
const composedRef = composeRefs([
|
|
174
|
-
childWithRef.ref,
|
|
175
|
-
]);
|
|
208
|
+
const composedRef = composeRefs([childWithRef.ref]);
|
|
176
209
|
return cloneElement(childWithRef, {
|
|
177
210
|
ref: composedRef,
|
|
178
211
|
...getComboboxProps,
|
|
@@ -183,27 +216,29 @@ function Dropdown(props) {
|
|
|
183
216
|
return;
|
|
184
217
|
const nextFocusTarget = event === null || event === void 0 ? void 0 : event.relatedTarget;
|
|
185
218
|
const container = containerRef.current;
|
|
186
|
-
if (container &&
|
|
219
|
+
if (container &&
|
|
220
|
+
nextFocusTarget &&
|
|
221
|
+
container.contains(nextFocusTarget)) {
|
|
187
222
|
return;
|
|
188
223
|
}
|
|
189
|
-
|
|
224
|
+
setOpen(false);
|
|
190
225
|
},
|
|
191
226
|
onClick: (event) => {
|
|
192
227
|
var _a, _b;
|
|
193
228
|
(_b = (_a = childWithRef.props) === null || _a === void 0 ? void 0 : _a.onClick) === null || _b === void 0 ? void 0 : _b.call(_a, event);
|
|
194
229
|
if (event === null || event === void 0 ? void 0 : event.defaultPrevented)
|
|
195
230
|
return;
|
|
196
|
-
|
|
231
|
+
setOpen(true);
|
|
197
232
|
},
|
|
198
233
|
onFocus: (event) => {
|
|
199
234
|
var _a, _b;
|
|
200
235
|
(_b = (_a = childWithRef.props) === null || _a === void 0 ? void 0 : _a.onFocus) === null || _b === void 0 ? void 0 : _b.call(_a, event);
|
|
201
236
|
if (event === null || event === void 0 ? void 0 : event.defaultPrevented)
|
|
202
237
|
return;
|
|
203
|
-
|
|
238
|
+
setOpen(true);
|
|
204
239
|
},
|
|
205
240
|
});
|
|
206
|
-
}, [children,
|
|
241
|
+
}, [children, getComboboxProps, isInline, setOpen]);
|
|
207
242
|
useDocumentEvents(() => {
|
|
208
243
|
if (!isOpen) {
|
|
209
244
|
return;
|
|
@@ -217,19 +252,22 @@ function Dropdown(props) {
|
|
|
217
252
|
return;
|
|
218
253
|
if (isInline) {
|
|
219
254
|
if (container && !container.contains(target)) {
|
|
220
|
-
|
|
255
|
+
setOpen(false);
|
|
221
256
|
}
|
|
222
257
|
return;
|
|
223
258
|
}
|
|
224
|
-
if (anchor &&
|
|
225
|
-
|
|
259
|
+
if (anchor &&
|
|
260
|
+
popper &&
|
|
261
|
+
!anchor.contains(target) &&
|
|
262
|
+
!popper.contains(target)) {
|
|
263
|
+
setOpen(false);
|
|
226
264
|
}
|
|
227
265
|
};
|
|
228
266
|
return {
|
|
229
267
|
click: handleClickAway,
|
|
230
268
|
touchend: handleClickAway,
|
|
231
269
|
};
|
|
232
|
-
}, [isInline, isOpen]);
|
|
270
|
+
}, [isInline, isOpen, setOpen]);
|
|
233
271
|
return (jsxs("div", { id: id, ref: containerRef, className: cx(dropdownClasses.root, dropdownClasses.inputPosition(inputPosition)), children: [isInline && (jsxs(TransitionGroup, { component: null, children: [!isOpen && inlineTriggerElement && (createElement(Translate, { ...translateProps, from: translateFrom, key: "inline-trigger", in: true },
|
|
234
272
|
jsx("div", { children: inlineTriggerElement }))), isOpen && (createElement(Translate, { ...translateProps, from: translateFrom, key: "inline-list", in: true },
|
|
235
273
|
jsx("div", { children: jsx(DropdownItem, { ...baseDropdownItemProps, headerContent: inlineTriggerElement }) })))] })), !isInline && (jsx(Popper, { ref: popperRef, anchor: anchorRef, open: isOpen, disablePortal: true, options: {
|
|
@@ -238,7 +276,7 @@ function Dropdown(props) {
|
|
|
238
276
|
offsetMiddleware,
|
|
239
277
|
...(sameWidthMiddleware ? [sameWidthMiddleware] : []),
|
|
240
278
|
],
|
|
241
|
-
}, children: jsx(TransitionGroup, { component: null, children: isOpen && (createElement(Translate, { ...translateProps, from: translateFrom, key: "popper-list", in: true },
|
|
279
|
+
}, style: zIndex ? { zIndex } : undefined, children: jsx(TransitionGroup, { component: null, children: isOpen && (createElement(Translate, { ...translateProps, from: translateFrom, key: "popper-list", in: true },
|
|
242
280
|
jsx("div", { children: jsx(DropdownItem, { ...baseDropdownItemProps }) }))) }) })), !isInline && triggerElement] }));
|
|
243
281
|
}
|
|
244
282
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import { DropdownItemSharedProps, DropdownOptionsByType,
|
|
2
|
+
import { DropdownItemSharedProps, DropdownOptionsByType, DropdownType } from '@mezzanine-ui/core/dropdown/dropdown';
|
|
3
3
|
import { type DropdownActionProps } from './DropdownAction';
|
|
4
|
-
export interface DropdownItemProps<T extends
|
|
4
|
+
export interface DropdownItemProps<T extends DropdownType | undefined = DropdownType> extends Omit<DropdownItemSharedProps, 'type'> {
|
|
5
5
|
/**
|
|
6
6
|
* The action configuration for the dropdown.
|
|
7
7
|
*/
|
|
@@ -55,6 +55,6 @@ export interface DropdownItemProps<T extends dropdownType | undefined = dropdown
|
|
|
55
55
|
* - 'grouped': array with one level of children (children cannot have children)
|
|
56
56
|
* - 'tree': array with nested children up to 3 levels
|
|
57
57
|
*/
|
|
58
|
-
type?:
|
|
58
|
+
type?: DropdownType;
|
|
59
59
|
}
|
|
60
|
-
export default function DropdownItem<T extends
|
|
60
|
+
export default function DropdownItem<T extends DropdownType | undefined = DropdownType>(props: DropdownItemProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DropdownCheckPosition, DropdownItemLevel, DropdownItemValidate, DropdownMode } from "@mezzanine-ui/core/dropdown/dropdown";
|
|
2
2
|
import { type IconDefinition } from "@mezzanine-ui/icons";
|
|
3
3
|
export interface DropdownItemCardProps {
|
|
4
4
|
/**
|
|
@@ -18,7 +18,7 @@ export interface DropdownItemCardProps {
|
|
|
18
18
|
/**
|
|
19
19
|
* The position of the checkbox.
|
|
20
20
|
*/
|
|
21
|
-
checkSite?:
|
|
21
|
+
checkSite?: DropdownCheckPosition;
|
|
22
22
|
/**
|
|
23
23
|
* Controlled: Whether the option is selected/checked.
|
|
24
24
|
* Controls checkbox state in multiple mode.
|
|
@@ -53,11 +53,11 @@ export interface DropdownItemCardProps {
|
|
|
53
53
|
/**
|
|
54
54
|
* The level of the dropdown item card.
|
|
55
55
|
*/
|
|
56
|
-
level?:
|
|
56
|
+
level?: DropdownItemLevel;
|
|
57
57
|
/**
|
|
58
58
|
* The mode of the dropdown item card.
|
|
59
59
|
*/
|
|
60
|
-
mode:
|
|
60
|
+
mode: DropdownMode;
|
|
61
61
|
/**
|
|
62
62
|
* The accessible name / label for the option.
|
|
63
63
|
* Falls back to label if not provided.
|
|
@@ -91,6 +91,6 @@ export interface DropdownItemCardProps {
|
|
|
91
91
|
/**
|
|
92
92
|
* The validation of the dropdown item card.
|
|
93
93
|
*/
|
|
94
|
-
validate?:
|
|
94
|
+
validate?: DropdownItemValidate;
|
|
95
95
|
}
|
|
96
96
|
export default function DropdownItemCard(props: DropdownItemCardProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DropdownStatus as DropdownStatusType } from "@mezzanine-ui/core/dropdown/dropdown";
|
|
2
2
|
import { IconDefinition } from "@mezzanine-ui/icons";
|
|
3
3
|
export interface DropdownStatusProps {
|
|
4
4
|
/**
|
|
5
5
|
* The status of the dropdown.
|
|
6
6
|
* @default 'loading'
|
|
7
7
|
*/
|
|
8
|
-
status:
|
|
8
|
+
status: DropdownStatusType;
|
|
9
9
|
/**
|
|
10
10
|
* The text of the dropdown loading status.
|
|
11
11
|
*/
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SeverityWithInfo } from '@mezzanine-ui/system/severity';
|
|
2
2
|
export interface FormControl {
|
|
3
3
|
disabled: boolean;
|
|
4
4
|
fullWidth: boolean;
|
|
5
5
|
required: boolean;
|
|
6
|
-
severity?:
|
|
6
|
+
severity?: SeverityWithInfo;
|
|
7
7
|
}
|
|
8
8
|
export declare const FormControlContext: import("react").Context<FormControl | undefined>;
|