@economic/taco 9.0.0 → 9.0.1-taco-docs-publishing.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/Drawer/components/Content.cjs +2 -3
- package/dist/components/Drawer/components/Content.cjs.map +1 -1
- package/dist/components/Drawer/components/Content.js +2 -3
- package/dist/components/Drawer/components/Content.js.map +1 -1
- package/dist/components/Pagination/PageNumbers.cjs +2 -1
- package/dist/components/Pagination/PageNumbers.cjs.map +1 -1
- package/dist/components/Pagination/PageNumbers.js +2 -1
- package/dist/components/Pagination/PageNumbers.js.map +1 -1
- package/dist/components/Pagination/Pagination.cjs +3 -3
- package/dist/components/Pagination/Pagination.cjs.map +1 -1
- package/dist/components/Pagination/Pagination.js +3 -3
- package/dist/components/Pagination/Pagination.js.map +1 -1
- package/dist/components/Select2/components/Edit.cjs +2 -2
- package/dist/components/Select2/components/Edit.cjs.map +1 -1
- package/dist/components/Select2/components/Edit.js +2 -2
- package/dist/components/Select2/components/Edit.js.map +1 -1
- package/dist/components/Table3/components/Editing/Alert.cjs +2 -2
- package/dist/components/Table3/components/Editing/Alert.cjs.map +1 -1
- package/dist/components/Table3/components/Editing/Alert.js +2 -2
- package/dist/components/Table3/components/Editing/Alert.js.map +1 -1
- package/dist/components/Table3/components/Editing/DiscardChangesConfirmationDialog.cjs +2 -2
- package/dist/components/Table3/components/Editing/DiscardChangesConfirmationDialog.cjs.map +1 -1
- package/dist/components/Table3/components/Editing/DiscardChangesConfirmationDialog.js +2 -2
- package/dist/components/Table3/components/Editing/DiscardChangesConfirmationDialog.js.map +1 -1
- package/dist/primitives/Table/Core/components/Toolbar/Toolbar.cjs +1 -2
- package/dist/primitives/Table/Core/components/Toolbar/Toolbar.cjs.map +1 -1
- package/dist/primitives/Table/Core/components/Toolbar/Toolbar.js +1 -2
- package/dist/primitives/Table/Core/components/Toolbar/Toolbar.js.map +1 -1
- package/dist/primitives/Table/Core/components/Toolbar/components/Filters/ManageFiltersPopover.cjs +2 -2
- package/dist/primitives/Table/Core/components/Toolbar/components/Filters/ManageFiltersPopover.cjs.map +1 -1
- package/dist/primitives/Table/Core/components/Toolbar/components/Filters/ManageFiltersPopover.js +2 -2
- package/dist/primitives/Table/Core/components/Toolbar/components/Filters/ManageFiltersPopover.js.map +1 -1
- package/dist/primitives/Table/Core/components/Toolbar/components/Print/PrintDialog.cjs +2 -2
- package/dist/primitives/Table/Core/components/Toolbar/components/Print/PrintDialog.cjs.map +1 -1
- package/dist/primitives/Table/Core/components/Toolbar/components/Print/PrintDialog.js +2 -2
- package/dist/primitives/Table/Core/components/Toolbar/components/Print/PrintDialog.js.map +1 -1
- package/package.json +5 -5
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const React = require("react");
|
|
4
4
|
const drawer = require("@base-ui/react/drawer");
|
|
5
5
|
const cn = require("clsx");
|
|
6
|
-
const Group = require("../../Group/Group.cjs");
|
|
7
6
|
const IconButton = require("../../LegacyComponents/IconButton/IconButton.cjs");
|
|
8
7
|
const Localization = require("../../Provider/Localization.cjs");
|
|
9
8
|
const Context$1 = require("../../Menu/Context.cjs");
|
|
@@ -57,8 +56,8 @@ const Footer = React.forwardRef(function DrawerFooter(props, ref) {
|
|
|
57
56
|
});
|
|
58
57
|
const Actions = React.forwardRef(function Actions2(props, ref) {
|
|
59
58
|
const { className, ...otherProps } = props;
|
|
60
|
-
const cName = cn("absolute top-0 right-10 mr-[
|
|
61
|
-
return /* @__PURE__ */ React.createElement(
|
|
59
|
+
const cName = cn("absolute top-0 right-10 flex gap-2 mr-[2] mt-4", className);
|
|
60
|
+
return /* @__PURE__ */ React.createElement("div", { ...otherProps, className: cName, id: "taco-drawer-actions", ref });
|
|
62
61
|
});
|
|
63
62
|
const Close = React.forwardRef(function DrawerClose(props, ref) {
|
|
64
63
|
const { onClose } = Context.useCurrentDrawer();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Content.cjs","sources":["../../../../src/components/Drawer/components/Content.tsx"],"sourcesContent":["import React from 'react';\nimport { Drawer as DrawerPrimitive } from '@base-ui/react/drawer';\nimport cn from 'clsx';\n\nimport { Group, GroupProps } from '../../Group/Group';\nimport { LegacyIconButton } from '../../LegacyComponents/IconButton/IconButton';\nimport { useLocalization } from '../../Provider/Localization';\nimport { useCurrentMenu } from '../../Menu/Context';\nimport { useCurrentDrawer } from '../Context';\nimport { useDraggable } from '../../../utils/hooks/useDraggable';\nimport { useMergedRef } from '../../../hooks/useMergedRef';\nimport { getDrawerContainerClassNames, getDrawerContentClassNames, getDrawerDragHandlerClassNames } from '../util';\n\nconst RESIZE_MIN = 360;\nconst RESIZE_MAX = 1000;\n\nexport enum DrawerAnimationDefinition {\n Visible = 'visible',\n Hidden = 'hidden',\n}\n\nconst RenderPropWrapper = React.forwardRef(function RenderPropWrapper({ children, onClick, renderProps }: any, ref) {\n const close = () => {\n onClick(new CustomEvent('close'));\n };\n\n return children({ close, ref, ...renderProps });\n});\n\nexport type DrawerTitleProps = React.HTMLAttributes<HTMLHeadingElement>;\nexport const Title = React.forwardRef(function DrawerTitle(props: DrawerTitleProps, externalRef: React.Ref<HTMLHeadingElement>) {\n const { className, children, ...otherProps } = props;\n const ref = useMergedRef<HTMLHeadingElement>(externalRef);\n const [style, setStyle] = React.useState({});\n const { texts } = useLocalization();\n const { onClickBack } = useCurrentDrawer();\n\n /**\n * By design in default drawer version Title has grey separator, but we might have exceptions like Drawer + Tabs scenario,\n * where we might want to hide the grey separator. For this reason separator was rendered with using of classNames,\n * so it can be easily overriden in exceptional scenarios.\n * */\n const cName = cn('grow-0 py-4 px-4 justify-self-start mb-0 border-b-[1px] border-gray-200 flex items-start', className);\n\n React.useEffect(() => {\n const drawer = ref?.current?.closest('[data-taco=\"drawer\"]');\n\n // This is the margin amount that we need to deduct from the margins to align with the design\n const marginAdjust = 4;\n\n const closeButton: HTMLButtonElement | null = drawer?.querySelector(`[aria-label=\"${texts.drawer.close}\"]`) ?? null;\n const closeButtonWidth = closeButton?.offsetWidth ?? 0;\n const closeButtonRightMargin = 8;\n\n const actionsWrapper: HTMLSpanElement | null = drawer?.querySelector(`#taco-drawer-actions[data-taco=\"group\"]`) ?? null;\n const actionsWrapperWidth = actionsWrapper?.offsetWidth ?? 0;\n const actionsWrapperRightMargin = 8;\n\n const marginRight =\n closeButtonWidth + actionsWrapperWidth + closeButtonRightMargin + actionsWrapperRightMargin - marginAdjust;\n\n setStyle({ marginRight });\n }, [ref, texts.drawer.close]);\n\n return (\n <DrawerPrimitive.Title className={cName} {...otherProps} ref={ref}>\n {onClickBack ? (\n <LegacyIconButton\n appearance=\"discrete\"\n aria-label={texts.drawer.back}\n className=\"mr-3 text-base\"\n icon=\"chevron-left\"\n onClick={onClickBack}\n />\n ) : null}\n {\n // We need to apply the right margin as an inline style instead of using Tailwind CSS.\n // This is necessary because we are creating styles dynamically at runtime,\n // and Tailwind doesn't support generating runtime styles.\n }\n <span className=\"line-clamp-2 inline-block overflow-y-hidden\" style={style}>\n {children}\n </span>\n </DrawerPrimitive.Title>\n );\n});\n\nexport type DrawerFooterProps = React.HTMLAttributes<HTMLDivElement>;\nexport const Footer = React.forwardRef(function DrawerFooter(props: DrawerFooterProps, ref: React.Ref<HTMLDivElement>) {\n const { className: _1, ...otherProps } = props;\n /**\n * The same scenario as Title, grey separator rendered using classNames to have posibility to override it.\n */\n const cName = cn('mt-auto flex justify-end grow-0 p-4 border-t-[1px] border-gray-200', props.className);\n return <div {...otherProps} className={cName} ref={ref} />;\n});\n\nexport const Actions = React.forwardRef(function Actions(props: GroupProps, ref: React.Ref<HTMLDivElement>) {\n const { className, ...otherProps } = props;\n const cName = cn('absolute top-0 right-10 mr-[8px] mt-4', className);\n // Id is added to identify the actions wrapper inside a useEffect in Dialog.Title\n return <Group {...otherProps} className={cName} id=\"taco-drawer-actions\" ref={ref} />;\n});\n\nexport type DrawerCloseProps = React.HTMLAttributes<HTMLButtonElement> & {\n children: React.ReactElement;\n};\n\nexport const Close = React.forwardRef(function DrawerClose(props: DrawerCloseProps, ref: React.Ref<HTMLButtonElement>) {\n const { onClose } = useCurrentDrawer();\n\n const { children, ...restProps } = props;\n\n return <DrawerPrimitive.Close {...restProps} onClick={onClose} ref={ref} render={children} />;\n});\n\nexport type DrawerInnerContentProps = React.HTMLAttributes<HTMLDivElement>;\n/**\n * It is container component, needed to provide default scrolling behaviour and padding, to simplyfy usage, requested by feature devs.\n * It is optional to use InnerContent component, if consumer need to implement custom behaviour or paddings for inner content,\n * then it's simply enough to render children and wrap them in custom implementation.\n */\nexport const InnerContent = React.forwardRef(function InnerContent(\n props: DrawerInnerContentProps,\n ref: React.Ref<HTMLDivElement>\n) {\n const { className, children, ...otherProps } = props;\n return (\n <div {...otherProps} className={cn('flex grow flex-col overflow-y-hidden', className)} ref={ref}>\n <div className=\"w-full gap-y-0.5 overflow-auto p-4\">{children}</div>\n </div>\n );\n});\n\nexport type DrawerContentProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> & {\n /** An accessible label to be announced when the side drawer is opened */\n 'aria-label': string;\n children: React.ReactNode | ((props: { close: () => void }) => React.ReactNode);\n};\nexport const Content = React.forwardRef(function Content(props: DrawerContentProps, externalRef: React.Ref<HTMLDivElement>) {\n const { containerRef, size, onResize, variant, showCloseButton, outlet } = useCurrentDrawer();\n const { className, children, ...otherProps } = props;\n const { texts } = useLocalization();\n const ref = useMergedRef<HTMLDivElement>(externalRef);\n\n const contentRef = React.useRef(null);\n\n // if the drawer was opened by a menu, we need to close the menu when the drawer closes\n // the menu is still open (and mounted) because it is the trigger for the drawer\n const menu = useCurrentMenu();\n let finalFocus: DrawerPrimitive.Popup.Props['finalFocus'];\n\n if (menu) {\n finalFocus = () => {\n menu.close();\n };\n }\n\n const containerClassName: string = React.useMemo(() => cn(getDrawerContainerClassNames(variant), className), [className]);\n\n const { contentClassName, dragHandlerClassName } = React.useMemo(() => {\n const contentClassName = getDrawerContentClassNames(size, variant);\n const dragHandlerClassName: string = getDrawerDragHandlerClassNames();\n return { contentClassName, dragHandlerClassName };\n }, [size, variant]);\n\n const [containerWidth, setContainerWidth] = React.useState<number>();\n\n // resize\n const dragHandlerRef = React.useRef<HTMLDivElement>(null);\n\n const {\n position,\n dragging,\n handleProps: dragHandleProps,\n resetPosition,\n } = useDraggable(useMergedRef<HTMLDivElement>(dragHandlerRef));\n\n const resizedWidth = React.useMemo((): number | undefined => {\n if (containerWidth) {\n return Math.min(RESIZE_MAX, Math.max(RESIZE_MIN, containerWidth - position.x || 0));\n }\n return;\n }, [containerWidth, position]);\n\n React.useImperativeHandle(\n containerRef,\n () => ({\n onOpen: () => {\n requestAnimationFrame(() => {\n if (contentRef.current) {\n setContainerWidth((contentRef.current as HTMLElement)?.offsetWidth);\n }\n });\n },\n }),\n []\n );\n\n React.useEffect(() => {\n if (onResize) {\n onResize(position.x);\n }\n }, [position]);\n\n React.useEffect(() => {\n if (!dragging && resizedWidth) {\n setContainerWidth(resizedWidth);\n resetPosition();\n }\n }, [dragging]);\n\n let output;\n\n if (typeof children === 'function') {\n output = (\n <Close>\n <RenderPropWrapper>{children}</RenderPropWrapper>\n </Close>\n );\n } else {\n output = children;\n }\n\n const content = (\n <div ref={contentRef} data-taco=\"drawer\" className={containerClassName}>\n {output}\n <div className={dragHandlerClassName} {...dragHandleProps} data-testid=\"resize-handler\" ref={dragHandlerRef}>\n {dragging ? <div data-testid=\"resize-hit-area\" className=\"fixed bottom-0 left-0 right-0 top-0\" /> : null}\n </div>\n {showCloseButton ? (\n <Close>\n <LegacyIconButton\n appearance=\"discrete\"\n aria-label={texts.drawer.close}\n className=\"absolute right-0 top-0 mr-2 mt-4\"\n icon=\"close\"\n />\n </Close>\n ) : null}\n </div>\n );\n\n if (!outlet) {\n return null;\n }\n\n return (\n <DrawerPrimitive.Portal container={outlet ?? undefined} className=\"h-full\">\n {variant === 'overlay' ? (\n <DrawerPrimitive.Backdrop\n className=\"bg-brand-midnight/[0.3] fixed inset-0 cursor-default overflow-y-auto print:absolute print:overflow-visible\"\n data-taco=\"backdrop\"\n />\n ) : null}\n <DrawerPrimitive.Viewport className=\"h-full\">\n <DrawerPrimitive.Popup\n {...otherProps}\n className={contentClassName}\n finalFocus={finalFocus}\n ref={ref}\n style={{ width: resizedWidth }}>\n <DrawerPrimitive.Content>{content}</DrawerPrimitive.Content>\n </DrawerPrimitive.Popup>\n </DrawerPrimitive.Viewport>\n </DrawerPrimitive.Portal>\n );\n});\n"],"names":["RenderPropWrapper","useMergedRef","useLocalization","useCurrentDrawer","drawer","DrawerPrimitive","LegacyIconButton","Actions","Group","InnerContent","Content","useCurrentMenu","getDrawerContainerClassNames","contentClassName","getDrawerContentClassNames","dragHandlerClassName","getDrawerDragHandlerClassNames","useDraggable"],"mappings":";;;;;;;;;;;;;AAaA,MAAM,aAAa;AACnB,MAAM,aAAa;AAOnB,MAAM,oBAAoB,MAAM,WAAW,SAASA,mBAAkB,EAAE,UAAU,SAAS,YAAY,GAAQ,KAAK;AAChH,QAAM,QAAQ,MAAM;AACR,YAAA,IAAI,YAAY,OAAO,CAAC;AAAA,EACpC;AAEA,SAAO,SAAS,EAAE,OAAO,KAAK,GAAG,aAAa;AAClD,CAAC;AAGM,MAAM,QAAQ,MAAM,WAAW,SAAS,YAAY,OAAyB,aAA4C;AAC5H,QAAM,EAAE,WAAW,UAAU,GAAG,WAAe,IAAA;AACzC,QAAA,MAAMC,0BAAiC,WAAW;AACxD,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAS,CAAA,CAAE;AACrC,QAAA,EAAE,MAAM,IAAIC,6BAAgB;AAC5B,QAAA,EAAE,YAAY,IAAIC,yBAAiB;AAOnC,QAAA,QAAQ,GAAG,4FAA4F,SAAS;AAEtH,QAAM,UAAU,MAAM;;AAClB,UAAMC,WAAS,gCAAK,YAAL,mBAAc,QAAQ;AAGrC,UAAM,eAAe;AAEf,UAAA,eAAwCA,WAAA,gBAAAA,QAAQ,cAAc,gBA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,WAAA;AAAA,IAAA;AAAA,MACG,YAAW;AAAA,MACX,cAAY,MAAM,OAAO;AAAA,MACzB,WAAU;AAAA,MACV,MAAK;AAAA,IAAA;AAAA,EAEb,CAAA,IACA,IACR;AAGJ,MAAI,CAAC,QAAQ;AACF,WAAA;AAAA,EAAA;AAIP,SAAA,sBAAA,cAACD,OAAgB,OAAA,QAAhB,EAAuB,WAAW,UAAU,QAAW,WAAU,SAC7D,GAAA,YAAY,YACT,sBAAA;AAAA,IAACA,OAAAA,OAAgB;AAAA,IAAhB;AAAA,MACG,WAAU;AAAA,MACV,aAAU;AAAA,IAAA;AAAA,EAAA,IAEd,MACJ,sBAAA,cAACA,cAAgB,UAAhB,EAAyB,WAAU,YAChC,sBAAA;AAAA,IAACA,OAAAA,OAAgB;AAAA,IAAhB;AAAA,MACI,GAAG;AAAA,MACJ,WAAW;AAAA,MACX;AAAA,MACA;AAAA,MACA,OAAO,EAAE,OAAO,aAAa;AAAA,IAAA;AAAA,IAC5B,sBAAA,cAAAA,OAAAA,OAAgB,SAAhB,MAAyB,OAAQ;AAAA,EAAA,CAE1C,CACJ;AAER,CAAC;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"Content.cjs","sources":["../../../../src/components/Drawer/components/Content.tsx"],"sourcesContent":["import React from 'react';\nimport { Drawer as DrawerPrimitive } from '@base-ui/react/drawer';\nimport cn from 'clsx';\n\nimport { GroupProps } from '../../Group/Group';\nimport { LegacyIconButton } from '../../LegacyComponents/IconButton/IconButton';\nimport { useLocalization } from '../../Provider/Localization';\nimport { useCurrentMenu } from '../../Menu/Context';\nimport { useCurrentDrawer } from '../Context';\nimport { useDraggable } from '../../../utils/hooks/useDraggable';\nimport { useMergedRef } from '../../../hooks/useMergedRef';\nimport { getDrawerContainerClassNames, getDrawerContentClassNames, getDrawerDragHandlerClassNames } from '../util';\n\nconst RESIZE_MIN = 360;\nconst RESIZE_MAX = 1000;\n\nexport enum DrawerAnimationDefinition {\n Visible = 'visible',\n Hidden = 'hidden',\n}\n\nconst RenderPropWrapper = React.forwardRef(function RenderPropWrapper({ children, onClick, renderProps }: any, ref) {\n const close = () => {\n onClick(new CustomEvent('close'));\n };\n\n return children({ close, ref, ...renderProps });\n});\n\nexport type DrawerTitleProps = React.HTMLAttributes<HTMLHeadingElement>;\nexport const Title = React.forwardRef(function DrawerTitle(props: DrawerTitleProps, externalRef: React.Ref<HTMLHeadingElement>) {\n const { className, children, ...otherProps } = props;\n const ref = useMergedRef<HTMLHeadingElement>(externalRef);\n const [style, setStyle] = React.useState({});\n const { texts } = useLocalization();\n const { onClickBack } = useCurrentDrawer();\n\n /**\n * By design in default drawer version Title has grey separator, but we might have exceptions like Drawer + Tabs scenario,\n * where we might want to hide the grey separator. For this reason separator was rendered with using of classNames,\n * so it can be easily overriden in exceptional scenarios.\n * */\n const cName = cn('grow-0 py-4 px-4 justify-self-start mb-0 border-b-[1px] border-gray-200 flex items-start', className);\n\n React.useEffect(() => {\n const drawer = ref?.current?.closest('[data-taco=\"drawer\"]');\n\n // This is the margin amount that we need to deduct from the margins to align with the design\n const marginAdjust = 4;\n\n const closeButton: HTMLButtonElement | null = drawer?.querySelector(`[aria-label=\"${texts.drawer.close}\"]`) ?? null;\n const closeButtonWidth = closeButton?.offsetWidth ?? 0;\n const closeButtonRightMargin = 8;\n\n const actionsWrapper: HTMLSpanElement | null = drawer?.querySelector(`#taco-drawer-actions[data-taco=\"group\"]`) ?? null;\n const actionsWrapperWidth = actionsWrapper?.offsetWidth ?? 0;\n const actionsWrapperRightMargin = 8;\n\n const marginRight =\n closeButtonWidth + actionsWrapperWidth + closeButtonRightMargin + actionsWrapperRightMargin - marginAdjust;\n\n setStyle({ marginRight });\n }, [ref, texts.drawer.close]);\n\n return (\n <DrawerPrimitive.Title className={cName} {...otherProps} ref={ref}>\n {onClickBack ? (\n <LegacyIconButton\n appearance=\"discrete\"\n aria-label={texts.drawer.back}\n className=\"mr-3 text-base\"\n icon=\"chevron-left\"\n onClick={onClickBack}\n />\n ) : null}\n {\n // We need to apply the right margin as an inline style instead of using Tailwind CSS.\n // This is necessary because we are creating styles dynamically at runtime,\n // and Tailwind doesn't support generating runtime styles.\n }\n <span className=\"line-clamp-2 inline-block overflow-y-hidden\" style={style}>\n {children}\n </span>\n </DrawerPrimitive.Title>\n );\n});\n\nexport type DrawerFooterProps = React.HTMLAttributes<HTMLDivElement>;\nexport const Footer = React.forwardRef(function DrawerFooter(props: DrawerFooterProps, ref: React.Ref<HTMLDivElement>) {\n const { className: _1, ...otherProps } = props;\n /**\n * The same scenario as Title, grey separator rendered using classNames to have posibility to override it.\n */\n const cName = cn('mt-auto flex justify-end grow-0 p-4 border-t-[1px] border-gray-200', props.className);\n return <div {...otherProps} className={cName} ref={ref} />;\n});\n\nexport const Actions = React.forwardRef(function Actions(props: GroupProps, ref: React.Ref<HTMLDivElement>) {\n const { className, ...otherProps } = props;\n const cName = cn('absolute top-0 right-10 flex gap-2 mr-[2] mt-4', className);\n // Id is added to identify the actions wrapper inside a useEffect in Dialog.Title\n return <div {...otherProps} className={cName} id=\"taco-drawer-actions\" ref={ref} />;\n});\n\nexport type DrawerCloseProps = React.HTMLAttributes<HTMLButtonElement> & {\n children: React.ReactElement;\n};\n\nexport const Close = React.forwardRef(function DrawerClose(props: DrawerCloseProps, ref: React.Ref<HTMLButtonElement>) {\n const { onClose } = useCurrentDrawer();\n\n const { children, ...restProps } = props;\n\n return <DrawerPrimitive.Close {...restProps} onClick={onClose} ref={ref} render={children} />;\n});\n\nexport type DrawerInnerContentProps = React.HTMLAttributes<HTMLDivElement>;\n/**\n * It is container component, needed to provide default scrolling behaviour and padding, to simplyfy usage, requested by feature devs.\n * It is optional to use InnerContent component, if consumer need to implement custom behaviour or paddings for inner content,\n * then it's simply enough to render children and wrap them in custom implementation.\n */\nexport const InnerContent = React.forwardRef(function InnerContent(\n props: DrawerInnerContentProps,\n ref: React.Ref<HTMLDivElement>\n) {\n const { className, children, ...otherProps } = props;\n return (\n <div {...otherProps} className={cn('flex grow flex-col overflow-y-hidden', className)} ref={ref}>\n <div className=\"w-full gap-y-0.5 overflow-auto p-4\">{children}</div>\n </div>\n );\n});\n\nexport type DrawerContentProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> & {\n /** An accessible label to be announced when the side drawer is opened */\n 'aria-label': string;\n children: React.ReactNode | ((props: { close: () => void }) => React.ReactNode);\n};\nexport const Content = React.forwardRef(function Content(props: DrawerContentProps, externalRef: React.Ref<HTMLDivElement>) {\n const { containerRef, size, onResize, variant, showCloseButton, outlet } = useCurrentDrawer();\n const { className, children, ...otherProps } = props;\n const { texts } = useLocalization();\n const ref = useMergedRef<HTMLDivElement>(externalRef);\n\n const contentRef = React.useRef(null);\n\n // if the drawer was opened by a menu, we need to close the menu when the drawer closes\n // the menu is still open (and mounted) because it is the trigger for the drawer\n const menu = useCurrentMenu();\n let finalFocus: DrawerPrimitive.Popup.Props['finalFocus'];\n\n if (menu) {\n finalFocus = () => {\n menu.close();\n };\n }\n\n const containerClassName: string = React.useMemo(() => cn(getDrawerContainerClassNames(variant), className), [className]);\n\n const { contentClassName, dragHandlerClassName } = React.useMemo(() => {\n const contentClassName = getDrawerContentClassNames(size, variant);\n const dragHandlerClassName: string = getDrawerDragHandlerClassNames();\n return { contentClassName, dragHandlerClassName };\n }, [size, variant]);\n\n const [containerWidth, setContainerWidth] = React.useState<number>();\n\n // resize\n const dragHandlerRef = React.useRef<HTMLDivElement>(null);\n\n const {\n position,\n dragging,\n handleProps: dragHandleProps,\n resetPosition,\n } = useDraggable(useMergedRef<HTMLDivElement>(dragHandlerRef));\n\n const resizedWidth = React.useMemo((): number | undefined => {\n if (containerWidth) {\n return Math.min(RESIZE_MAX, Math.max(RESIZE_MIN, containerWidth - position.x || 0));\n }\n return;\n }, [containerWidth, position]);\n\n React.useImperativeHandle(\n containerRef,\n () => ({\n onOpen: () => {\n requestAnimationFrame(() => {\n if (contentRef.current) {\n setContainerWidth((contentRef.current as HTMLElement)?.offsetWidth);\n }\n });\n },\n }),\n []\n );\n\n React.useEffect(() => {\n if (onResize) {\n onResize(position.x);\n }\n }, [position]);\n\n React.useEffect(() => {\n if (!dragging && resizedWidth) {\n setContainerWidth(resizedWidth);\n resetPosition();\n }\n }, [dragging]);\n\n let output;\n\n if (typeof children === 'function') {\n output = (\n <Close>\n <RenderPropWrapper>{children}</RenderPropWrapper>\n </Close>\n );\n } else {\n output = children;\n }\n\n const content = (\n <div ref={contentRef} data-taco=\"drawer\" className={containerClassName}>\n {output}\n <div className={dragHandlerClassName} {...dragHandleProps} data-testid=\"resize-handler\" ref={dragHandlerRef}>\n {dragging ? <div data-testid=\"resize-hit-area\" className=\"fixed bottom-0 left-0 right-0 top-0\" /> : null}\n </div>\n {showCloseButton ? (\n <Close>\n <LegacyIconButton\n appearance=\"discrete\"\n aria-label={texts.drawer.close}\n className=\"absolute right-0 top-0 mr-2 mt-4\"\n icon=\"close\"\n />\n </Close>\n ) : null}\n </div>\n );\n\n if (!outlet) {\n return null;\n }\n\n return (\n <DrawerPrimitive.Portal container={outlet ?? undefined} className=\"h-full\">\n {variant === 'overlay' ? (\n <DrawerPrimitive.Backdrop\n className=\"bg-brand-midnight/[0.3] fixed inset-0 cursor-default overflow-y-auto print:absolute print:overflow-visible\"\n data-taco=\"backdrop\"\n />\n ) : null}\n <DrawerPrimitive.Viewport className=\"h-full\">\n <DrawerPrimitive.Popup\n {...otherProps}\n className={contentClassName}\n finalFocus={finalFocus}\n ref={ref}\n style={{ width: resizedWidth }}>\n <DrawerPrimitive.Content>{content}</DrawerPrimitive.Content>\n </DrawerPrimitive.Popup>\n </DrawerPrimitive.Viewport>\n </DrawerPrimitive.Portal>\n );\n});\n"],"names":["RenderPropWrapper","useMergedRef","useLocalization","useCurrentDrawer","drawer","DrawerPrimitive","LegacyIconButton","Actions","InnerContent","Content","useCurrentMenu","getDrawerContainerClassNames","contentClassName","getDrawerContentClassNames","dragHandlerClassName","getDrawerDragHandlerClassNames","useDraggable"],"mappings":";;;;;;;;;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MACI,GAAG;AAAA,MACJ,WAAW;AAAA,MACX;AAAA,MACA;AAAA,MACA,OAAO,EAAE,OAAO,aAAa;AAAA,IAAA;AAAA,IAC5B,sBAAA,cAAAA,OAAAA,OAAgB,SAAhB,MAAyB,OAAQ;AAAA,EAAA,CAE1C,CACJ;AAER,CAAC;;;;;;;"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React__default from "react";
|
|
2
2
|
import { Drawer } from "@base-ui/react/drawer";
|
|
3
3
|
import cn from "clsx";
|
|
4
|
-
import { Group } from "../../Group/Group.js";
|
|
5
4
|
import { LegacyIconButton } from "../../LegacyComponents/IconButton/IconButton.js";
|
|
6
5
|
import { useLocalization } from "../../Provider/Localization.js";
|
|
7
6
|
import { useCurrentMenu } from "../../Menu/Context.js";
|
|
@@ -55,8 +54,8 @@ const Footer = React__default.forwardRef(function DrawerFooter(props, ref) {
|
|
|
55
54
|
});
|
|
56
55
|
const Actions = React__default.forwardRef(function Actions2(props, ref) {
|
|
57
56
|
const { className, ...otherProps } = props;
|
|
58
|
-
const cName = cn("absolute top-0 right-10 mr-[
|
|
59
|
-
return /* @__PURE__ */ React__default.createElement(
|
|
57
|
+
const cName = cn("absolute top-0 right-10 flex gap-2 mr-[2] mt-4", className);
|
|
58
|
+
return /* @__PURE__ */ React__default.createElement("div", { ...otherProps, className: cName, id: "taco-drawer-actions", ref });
|
|
60
59
|
});
|
|
61
60
|
const Close = React__default.forwardRef(function DrawerClose(props, ref) {
|
|
62
61
|
const { onClose } = useCurrentDrawer();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Content.js","sources":["../../../../src/components/Drawer/components/Content.tsx"],"sourcesContent":["import React from 'react';\nimport { Drawer as DrawerPrimitive } from '@base-ui/react/drawer';\nimport cn from 'clsx';\n\nimport { Group, GroupProps } from '../../Group/Group';\nimport { LegacyIconButton } from '../../LegacyComponents/IconButton/IconButton';\nimport { useLocalization } from '../../Provider/Localization';\nimport { useCurrentMenu } from '../../Menu/Context';\nimport { useCurrentDrawer } from '../Context';\nimport { useDraggable } from '../../../utils/hooks/useDraggable';\nimport { useMergedRef } from '../../../hooks/useMergedRef';\nimport { getDrawerContainerClassNames, getDrawerContentClassNames, getDrawerDragHandlerClassNames } from '../util';\n\nconst RESIZE_MIN = 360;\nconst RESIZE_MAX = 1000;\n\nexport enum DrawerAnimationDefinition {\n Visible = 'visible',\n Hidden = 'hidden',\n}\n\nconst RenderPropWrapper = React.forwardRef(function RenderPropWrapper({ children, onClick, renderProps }: any, ref) {\n const close = () => {\n onClick(new CustomEvent('close'));\n };\n\n return children({ close, ref, ...renderProps });\n});\n\nexport type DrawerTitleProps = React.HTMLAttributes<HTMLHeadingElement>;\nexport const Title = React.forwardRef(function DrawerTitle(props: DrawerTitleProps, externalRef: React.Ref<HTMLHeadingElement>) {\n const { className, children, ...otherProps } = props;\n const ref = useMergedRef<HTMLHeadingElement>(externalRef);\n const [style, setStyle] = React.useState({});\n const { texts } = useLocalization();\n const { onClickBack } = useCurrentDrawer();\n\n /**\n * By design in default drawer version Title has grey separator, but we might have exceptions like Drawer + Tabs scenario,\n * where we might want to hide the grey separator. For this reason separator was rendered with using of classNames,\n * so it can be easily overriden in exceptional scenarios.\n * */\n const cName = cn('grow-0 py-4 px-4 justify-self-start mb-0 border-b-[1px] border-gray-200 flex items-start', className);\n\n React.useEffect(() => {\n const drawer = ref?.current?.closest('[data-taco=\"drawer\"]');\n\n // This is the margin amount that we need to deduct from the margins to align with the design\n const marginAdjust = 4;\n\n const closeButton: HTMLButtonElement | null = drawer?.querySelector(`[aria-label=\"${texts.drawer.close}\"]`) ?? null;\n const closeButtonWidth = closeButton?.offsetWidth ?? 0;\n const closeButtonRightMargin = 8;\n\n const actionsWrapper: HTMLSpanElement | null = drawer?.querySelector(`#taco-drawer-actions[data-taco=\"group\"]`) ?? null;\n const actionsWrapperWidth = actionsWrapper?.offsetWidth ?? 0;\n const actionsWrapperRightMargin = 8;\n\n const marginRight =\n closeButtonWidth + actionsWrapperWidth + closeButtonRightMargin + actionsWrapperRightMargin - marginAdjust;\n\n setStyle({ marginRight });\n }, [ref, texts.drawer.close]);\n\n return (\n <DrawerPrimitive.Title className={cName} {...otherProps} ref={ref}>\n {onClickBack ? (\n <LegacyIconButton\n appearance=\"discrete\"\n aria-label={texts.drawer.back}\n className=\"mr-3 text-base\"\n icon=\"chevron-left\"\n onClick={onClickBack}\n />\n ) : null}\n {\n // We need to apply the right margin as an inline style instead of using Tailwind CSS.\n // This is necessary because we are creating styles dynamically at runtime,\n // and Tailwind doesn't support generating runtime styles.\n }\n <span className=\"line-clamp-2 inline-block overflow-y-hidden\" style={style}>\n {children}\n </span>\n </DrawerPrimitive.Title>\n );\n});\n\nexport type DrawerFooterProps = React.HTMLAttributes<HTMLDivElement>;\nexport const Footer = React.forwardRef(function DrawerFooter(props: DrawerFooterProps, ref: React.Ref<HTMLDivElement>) {\n const { className: _1, ...otherProps } = props;\n /**\n * The same scenario as Title, grey separator rendered using classNames to have posibility to override it.\n */\n const cName = cn('mt-auto flex justify-end grow-0 p-4 border-t-[1px] border-gray-200', props.className);\n return <div {...otherProps} className={cName} ref={ref} />;\n});\n\nexport const Actions = React.forwardRef(function Actions(props: GroupProps, ref: React.Ref<HTMLDivElement>) {\n const { className, ...otherProps } = props;\n const cName = cn('absolute top-0 right-10 mr-[8px] mt-4', className);\n // Id is added to identify the actions wrapper inside a useEffect in Dialog.Title\n return <Group {...otherProps} className={cName} id=\"taco-drawer-actions\" ref={ref} />;\n});\n\nexport type DrawerCloseProps = React.HTMLAttributes<HTMLButtonElement> & {\n children: React.ReactElement;\n};\n\nexport const Close = React.forwardRef(function DrawerClose(props: DrawerCloseProps, ref: React.Ref<HTMLButtonElement>) {\n const { onClose } = useCurrentDrawer();\n\n const { children, ...restProps } = props;\n\n return <DrawerPrimitive.Close {...restProps} onClick={onClose} ref={ref} render={children} />;\n});\n\nexport type DrawerInnerContentProps = React.HTMLAttributes<HTMLDivElement>;\n/**\n * It is container component, needed to provide default scrolling behaviour and padding, to simplyfy usage, requested by feature devs.\n * It is optional to use InnerContent component, if consumer need to implement custom behaviour or paddings for inner content,\n * then it's simply enough to render children and wrap them in custom implementation.\n */\nexport const InnerContent = React.forwardRef(function InnerContent(\n props: DrawerInnerContentProps,\n ref: React.Ref<HTMLDivElement>\n) {\n const { className, children, ...otherProps } = props;\n return (\n <div {...otherProps} className={cn('flex grow flex-col overflow-y-hidden', className)} ref={ref}>\n <div className=\"w-full gap-y-0.5 overflow-auto p-4\">{children}</div>\n </div>\n );\n});\n\nexport type DrawerContentProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> & {\n /** An accessible label to be announced when the side drawer is opened */\n 'aria-label': string;\n children: React.ReactNode | ((props: { close: () => void }) => React.ReactNode);\n};\nexport const Content = React.forwardRef(function Content(props: DrawerContentProps, externalRef: React.Ref<HTMLDivElement>) {\n const { containerRef, size, onResize, variant, showCloseButton, outlet } = useCurrentDrawer();\n const { className, children, ...otherProps } = props;\n const { texts } = useLocalization();\n const ref = useMergedRef<HTMLDivElement>(externalRef);\n\n const contentRef = React.useRef(null);\n\n // if the drawer was opened by a menu, we need to close the menu when the drawer closes\n // the menu is still open (and mounted) because it is the trigger for the drawer\n const menu = useCurrentMenu();\n let finalFocus: DrawerPrimitive.Popup.Props['finalFocus'];\n\n if (menu) {\n finalFocus = () => {\n menu.close();\n };\n }\n\n const containerClassName: string = React.useMemo(() => cn(getDrawerContainerClassNames(variant), className), [className]);\n\n const { contentClassName, dragHandlerClassName } = React.useMemo(() => {\n const contentClassName = getDrawerContentClassNames(size, variant);\n const dragHandlerClassName: string = getDrawerDragHandlerClassNames();\n return { contentClassName, dragHandlerClassName };\n }, [size, variant]);\n\n const [containerWidth, setContainerWidth] = React.useState<number>();\n\n // resize\n const dragHandlerRef = React.useRef<HTMLDivElement>(null);\n\n const {\n position,\n dragging,\n handleProps: dragHandleProps,\n resetPosition,\n } = useDraggable(useMergedRef<HTMLDivElement>(dragHandlerRef));\n\n const resizedWidth = React.useMemo((): number | undefined => {\n if (containerWidth) {\n return Math.min(RESIZE_MAX, Math.max(RESIZE_MIN, containerWidth - position.x || 0));\n }\n return;\n }, [containerWidth, position]);\n\n React.useImperativeHandle(\n containerRef,\n () => ({\n onOpen: () => {\n requestAnimationFrame(() => {\n if (contentRef.current) {\n setContainerWidth((contentRef.current as HTMLElement)?.offsetWidth);\n }\n });\n },\n }),\n []\n );\n\n React.useEffect(() => {\n if (onResize) {\n onResize(position.x);\n }\n }, [position]);\n\n React.useEffect(() => {\n if (!dragging && resizedWidth) {\n setContainerWidth(resizedWidth);\n resetPosition();\n }\n }, [dragging]);\n\n let output;\n\n if (typeof children === 'function') {\n output = (\n <Close>\n <RenderPropWrapper>{children}</RenderPropWrapper>\n </Close>\n );\n } else {\n output = children;\n }\n\n const content = (\n <div ref={contentRef} data-taco=\"drawer\" className={containerClassName}>\n {output}\n <div className={dragHandlerClassName} {...dragHandleProps} data-testid=\"resize-handler\" ref={dragHandlerRef}>\n {dragging ? <div data-testid=\"resize-hit-area\" className=\"fixed bottom-0 left-0 right-0 top-0\" /> : null}\n </div>\n {showCloseButton ? (\n <Close>\n <LegacyIconButton\n appearance=\"discrete\"\n aria-label={texts.drawer.close}\n className=\"absolute right-0 top-0 mr-2 mt-4\"\n icon=\"close\"\n />\n </Close>\n ) : null}\n </div>\n );\n\n if (!outlet) {\n return null;\n }\n\n return (\n <DrawerPrimitive.Portal container={outlet ?? undefined} className=\"h-full\">\n {variant === 'overlay' ? (\n <DrawerPrimitive.Backdrop\n className=\"bg-brand-midnight/[0.3] fixed inset-0 cursor-default overflow-y-auto print:absolute print:overflow-visible\"\n data-taco=\"backdrop\"\n />\n ) : null}\n <DrawerPrimitive.Viewport className=\"h-full\">\n <DrawerPrimitive.Popup\n {...otherProps}\n className={contentClassName}\n finalFocus={finalFocus}\n ref={ref}\n style={{ width: resizedWidth }}>\n <DrawerPrimitive.Content>{content}</DrawerPrimitive.Content>\n </DrawerPrimitive.Popup>\n </DrawerPrimitive.Viewport>\n </DrawerPrimitive.Portal>\n );\n});\n"],"names":["React","RenderPropWrapper","DrawerPrimitive","Actions","InnerContent","Content","contentClassName","dragHandlerClassName"],"mappings":";;;;;;;;;;;AAaA,MAAM,aAAa;AACnB,MAAM,aAAa;AAOnB,MAAM,oBAAoBA,eAAM,WAAW,SAASC,mBAAkB,EAAE,UAAU,SAAS,YAAY,GAAQ,KAAK;AAChH,QAAM,QAAQ,MAAM;AACR,YAAA,IAAI,YAAY,OAAO,CAAC;AAAA,EACpC;AAEA,SAAO,SAAS,EAAE,OAAO,KAAK,GAAG,aAAa;AAClD,CAAC;AAGM,MAAM,QAAQD,eAAM,WAAW,SAAS,YAAY,OAAyB,aAA4C;AAC5H,QAAM,EAAE,WAAW,UAAU,GAAG,WAAe,IAAA;AACzC,QAAA,MAAM,aAAiC,WAAW;AACxD,QAAM,CAAC,OAAO,QAAQ,IAAIA,eAAM,SAAS,CAAA,CAAE;AACrC,QAAA,EAAE,MAAM,IAAI,gBAAgB;AAC5B,QAAA,EAAE,YAAY,IAAI,iBAAiB;AAOnC,QAAA,QAAQ,GAAG,4FAA4F,SAAS;AAEtHA,iBAAM,UAAU,MAAM;;AAClB,UAAM,UAAS,gCAAK,YAAL,mBAAc,QAAQ;AAGrC,UAAM,eAAe;AAEf,UAAA,eAAwC,iCAAQ,cAAc,gBAAgB,MAAM,OAAO,KAAK,UAAS;AACzG,UAAA,oBAAmB,2CAAa,gBAAe;AACrD,UAAM,yBAAyB;AAE/B,UAAM,kBAAyC,iCAAQ,cAAc,+CAA8C;AAC7G,UAAA,uBAAsB,iDAAgB,gBAAe;AAC3D,UAAM,4BAA4B;AAElC,UAAM,cACF,mBAAmB,sBAAsB,yBAAyB,4BAA4B;AAEzF,aAAA,EAAE,aAAa;AAAA,KACzB,CAAC,KAAK,MAAM,OAAO,KAAK,CAAC;AAGxB,SAAAA,+BAAA,cAACE,OAAgB,OAAhB,EAAsB,WAAW,OAAQ,GAAG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AAhB,EAAyB,WAAU,YAChCF,+BAAA;AAAA,IAACE,OAAgB;AAAA,IAAhB;AAAA,MACI,GAAG;AAAA,MACJ,WAAW;AAAA,MACX;AAAA,MACA;AAAA,MACA,OAAO,EAAE,OAAO,aAAa;AAAA,IAAA;AAAA,IAC5BF,+BAAA,cAAAE,OAAgB,SAAhB,MAAyB,OAAQ;AAAA,EAAA,CAE1C,CACJ;AAER,CAAC;"}
|
|
1
|
+
{"version":3,"file":"Content.js","sources":["../../../../src/components/Drawer/components/Content.tsx"],"sourcesContent":["import React from 'react';\nimport { Drawer as DrawerPrimitive } from '@base-ui/react/drawer';\nimport cn from 'clsx';\n\nimport { GroupProps } from '../../Group/Group';\nimport { LegacyIconButton } from '../../LegacyComponents/IconButton/IconButton';\nimport { useLocalization } from '../../Provider/Localization';\nimport { useCurrentMenu } from '../../Menu/Context';\nimport { useCurrentDrawer } from '../Context';\nimport { useDraggable } from '../../../utils/hooks/useDraggable';\nimport { useMergedRef } from '../../../hooks/useMergedRef';\nimport { getDrawerContainerClassNames, getDrawerContentClassNames, getDrawerDragHandlerClassNames } from '../util';\n\nconst RESIZE_MIN = 360;\nconst RESIZE_MAX = 1000;\n\nexport enum DrawerAnimationDefinition {\n Visible = 'visible',\n Hidden = 'hidden',\n}\n\nconst RenderPropWrapper = React.forwardRef(function RenderPropWrapper({ children, onClick, renderProps }: any, ref) {\n const close = () => {\n onClick(new CustomEvent('close'));\n };\n\n return children({ close, ref, ...renderProps });\n});\n\nexport type DrawerTitleProps = React.HTMLAttributes<HTMLHeadingElement>;\nexport const Title = React.forwardRef(function DrawerTitle(props: DrawerTitleProps, externalRef: React.Ref<HTMLHeadingElement>) {\n const { className, children, ...otherProps } = props;\n const ref = useMergedRef<HTMLHeadingElement>(externalRef);\n const [style, setStyle] = React.useState({});\n const { texts } = useLocalization();\n const { onClickBack } = useCurrentDrawer();\n\n /**\n * By design in default drawer version Title has grey separator, but we might have exceptions like Drawer + Tabs scenario,\n * where we might want to hide the grey separator. For this reason separator was rendered with using of classNames,\n * so it can be easily overriden in exceptional scenarios.\n * */\n const cName = cn('grow-0 py-4 px-4 justify-self-start mb-0 border-b-[1px] border-gray-200 flex items-start', className);\n\n React.useEffect(() => {\n const drawer = ref?.current?.closest('[data-taco=\"drawer\"]');\n\n // This is the margin amount that we need to deduct from the margins to align with the design\n const marginAdjust = 4;\n\n const closeButton: HTMLButtonElement | null = drawer?.querySelector(`[aria-label=\"${texts.drawer.close}\"]`) ?? null;\n const closeButtonWidth = closeButton?.offsetWidth ?? 0;\n const closeButtonRightMargin = 8;\n\n const actionsWrapper: HTMLSpanElement | null = drawer?.querySelector(`#taco-drawer-actions[data-taco=\"group\"]`) ?? null;\n const actionsWrapperWidth = actionsWrapper?.offsetWidth ?? 0;\n const actionsWrapperRightMargin = 8;\n\n const marginRight =\n closeButtonWidth + actionsWrapperWidth + closeButtonRightMargin + actionsWrapperRightMargin - marginAdjust;\n\n setStyle({ marginRight });\n }, [ref, texts.drawer.close]);\n\n return (\n <DrawerPrimitive.Title className={cName} {...otherProps} ref={ref}>\n {onClickBack ? (\n <LegacyIconButton\n appearance=\"discrete\"\n aria-label={texts.drawer.back}\n className=\"mr-3 text-base\"\n icon=\"chevron-left\"\n onClick={onClickBack}\n />\n ) : null}\n {\n // We need to apply the right margin as an inline style instead of using Tailwind CSS.\n // This is necessary because we are creating styles dynamically at runtime,\n // and Tailwind doesn't support generating runtime styles.\n }\n <span className=\"line-clamp-2 inline-block overflow-y-hidden\" style={style}>\n {children}\n </span>\n </DrawerPrimitive.Title>\n );\n});\n\nexport type DrawerFooterProps = React.HTMLAttributes<HTMLDivElement>;\nexport const Footer = React.forwardRef(function DrawerFooter(props: DrawerFooterProps, ref: React.Ref<HTMLDivElement>) {\n const { className: _1, ...otherProps } = props;\n /**\n * The same scenario as Title, grey separator rendered using classNames to have posibility to override it.\n */\n const cName = cn('mt-auto flex justify-end grow-0 p-4 border-t-[1px] border-gray-200', props.className);\n return <div {...otherProps} className={cName} ref={ref} />;\n});\n\nexport const Actions = React.forwardRef(function Actions(props: GroupProps, ref: React.Ref<HTMLDivElement>) {\n const { className, ...otherProps } = props;\n const cName = cn('absolute top-0 right-10 flex gap-2 mr-[2] mt-4', className);\n // Id is added to identify the actions wrapper inside a useEffect in Dialog.Title\n return <div {...otherProps} className={cName} id=\"taco-drawer-actions\" ref={ref} />;\n});\n\nexport type DrawerCloseProps = React.HTMLAttributes<HTMLButtonElement> & {\n children: React.ReactElement;\n};\n\nexport const Close = React.forwardRef(function DrawerClose(props: DrawerCloseProps, ref: React.Ref<HTMLButtonElement>) {\n const { onClose } = useCurrentDrawer();\n\n const { children, ...restProps } = props;\n\n return <DrawerPrimitive.Close {...restProps} onClick={onClose} ref={ref} render={children} />;\n});\n\nexport type DrawerInnerContentProps = React.HTMLAttributes<HTMLDivElement>;\n/**\n * It is container component, needed to provide default scrolling behaviour and padding, to simplyfy usage, requested by feature devs.\n * It is optional to use InnerContent component, if consumer need to implement custom behaviour or paddings for inner content,\n * then it's simply enough to render children and wrap them in custom implementation.\n */\nexport const InnerContent = React.forwardRef(function InnerContent(\n props: DrawerInnerContentProps,\n ref: React.Ref<HTMLDivElement>\n) {\n const { className, children, ...otherProps } = props;\n return (\n <div {...otherProps} className={cn('flex grow flex-col overflow-y-hidden', className)} ref={ref}>\n <div className=\"w-full gap-y-0.5 overflow-auto p-4\">{children}</div>\n </div>\n );\n});\n\nexport type DrawerContentProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> & {\n /** An accessible label to be announced when the side drawer is opened */\n 'aria-label': string;\n children: React.ReactNode | ((props: { close: () => void }) => React.ReactNode);\n};\nexport const Content = React.forwardRef(function Content(props: DrawerContentProps, externalRef: React.Ref<HTMLDivElement>) {\n const { containerRef, size, onResize, variant, showCloseButton, outlet } = useCurrentDrawer();\n const { className, children, ...otherProps } = props;\n const { texts } = useLocalization();\n const ref = useMergedRef<HTMLDivElement>(externalRef);\n\n const contentRef = React.useRef(null);\n\n // if the drawer was opened by a menu, we need to close the menu when the drawer closes\n // the menu is still open (and mounted) because it is the trigger for the drawer\n const menu = useCurrentMenu();\n let finalFocus: DrawerPrimitive.Popup.Props['finalFocus'];\n\n if (menu) {\n finalFocus = () => {\n menu.close();\n };\n }\n\n const containerClassName: string = React.useMemo(() => cn(getDrawerContainerClassNames(variant), className), [className]);\n\n const { contentClassName, dragHandlerClassName } = React.useMemo(() => {\n const contentClassName = getDrawerContentClassNames(size, variant);\n const dragHandlerClassName: string = getDrawerDragHandlerClassNames();\n return { contentClassName, dragHandlerClassName };\n }, [size, variant]);\n\n const [containerWidth, setContainerWidth] = React.useState<number>();\n\n // resize\n const dragHandlerRef = React.useRef<HTMLDivElement>(null);\n\n const {\n position,\n dragging,\n handleProps: dragHandleProps,\n resetPosition,\n } = useDraggable(useMergedRef<HTMLDivElement>(dragHandlerRef));\n\n const resizedWidth = React.useMemo((): number | undefined => {\n if (containerWidth) {\n return Math.min(RESIZE_MAX, Math.max(RESIZE_MIN, containerWidth - position.x || 0));\n }\n return;\n }, [containerWidth, position]);\n\n React.useImperativeHandle(\n containerRef,\n () => ({\n onOpen: () => {\n requestAnimationFrame(() => {\n if (contentRef.current) {\n setContainerWidth((contentRef.current as HTMLElement)?.offsetWidth);\n }\n });\n },\n }),\n []\n );\n\n React.useEffect(() => {\n if (onResize) {\n onResize(position.x);\n }\n }, [position]);\n\n React.useEffect(() => {\n if (!dragging && resizedWidth) {\n setContainerWidth(resizedWidth);\n resetPosition();\n }\n }, [dragging]);\n\n let output;\n\n if (typeof children === 'function') {\n output = (\n <Close>\n <RenderPropWrapper>{children}</RenderPropWrapper>\n </Close>\n );\n } else {\n output = children;\n }\n\n const content = (\n <div ref={contentRef} data-taco=\"drawer\" className={containerClassName}>\n {output}\n <div className={dragHandlerClassName} {...dragHandleProps} data-testid=\"resize-handler\" ref={dragHandlerRef}>\n {dragging ? <div data-testid=\"resize-hit-area\" className=\"fixed bottom-0 left-0 right-0 top-0\" /> : null}\n </div>\n {showCloseButton ? (\n <Close>\n <LegacyIconButton\n appearance=\"discrete\"\n aria-label={texts.drawer.close}\n className=\"absolute right-0 top-0 mr-2 mt-4\"\n icon=\"close\"\n />\n </Close>\n ) : null}\n </div>\n );\n\n if (!outlet) {\n return null;\n }\n\n return (\n <DrawerPrimitive.Portal container={outlet ?? undefined} className=\"h-full\">\n {variant === 'overlay' ? (\n <DrawerPrimitive.Backdrop\n className=\"bg-brand-midnight/[0.3] fixed inset-0 cursor-default overflow-y-auto print:absolute print:overflow-visible\"\n data-taco=\"backdrop\"\n />\n ) : null}\n <DrawerPrimitive.Viewport className=\"h-full\">\n <DrawerPrimitive.Popup\n {...otherProps}\n className={contentClassName}\n finalFocus={finalFocus}\n ref={ref}\n style={{ width: resizedWidth }}>\n <DrawerPrimitive.Content>{content}</DrawerPrimitive.Content>\n </DrawerPrimitive.Popup>\n </DrawerPrimitive.Viewport>\n </DrawerPrimitive.Portal>\n );\n});\n"],"names":["React","RenderPropWrapper","DrawerPrimitive","Actions","InnerContent","Content","contentClassName","dragHandlerClassName"],"mappings":";;;;;;;;;;AAaA,MAAM,aAAa;AACnB,MAAM,aAAa;AAOnB,MAAM,oBAAoBA,eAAM,WAAW,SAASC,mBAAkB,EAAE,UAAU,SAAS,YAAY,GAAQ,KAAK;AAChH,QAAM,QAAQ,MAAM;AACR,YAAA,IAAI,YAAY,OAAO,CAAC;AAAA,EACpC;AAEA,SAAO,SAAS,EAAE,OAAO,KAAK,GAAG,aAAa;AAClD,CAAC;AAGM,MAAM,QAAQD,eAAM,WAAW,SAAS,YAAY,OAAyB,aAA4C;AAC5H,QAAM,EAAE,WAAW,UAAU,GAAG,WAAe,IAAA;AACzC,QAAA,MAAM,aAAiC,WAAW;AACxD,QAAM,CAAC,OAAO,QAAQ,IAAIA,eAAM,SAAS,CAAA,CAAE;AACrC,QAAA,EAAE,MAAM,IAAI,gBAAgB;AAC5B,QAAA,EAAE,YAAY,IAAI,iBAAiB;AAOnC,QAAA,QAAQ,GA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,GACxF,WAAWA,+BAAA,cAAC,SAAI,eAAY,mBAAkB,WAAU,uCAAsC,IAAK,IACxG,GACC,+DACI,OACG,MAAAA,+BAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,YAAW;AAAA,MACX,cAAY,MAAM,OAAO;AAAA,MACzB,WAAU;AAAA,MACV,MAAK;AAAA,IAAA;AAAA,EAEb,CAAA,IACA,IACR;AAGJ,MAAI,CAAC,QAAQ;AACF,WAAA;AAAA,EAAA;AAIP,SAAAA,+BAAA,cAACE,OAAgB,QAAhB,EAAuB,WAAW,UAAU,QAAW,WAAU,SAC7D,GAAA,YAAY,YACTF,+BAAA;AAAA,IAACE,OAAgB;AAAA,IAAhB;AAAA,MACG,WAAU;AAAA,MACV,aAAU;AAAA,IAAA;AAAA,EAAA,IAEd,MACJF,+BAAA,cAACE,OAAgB,UAAhB,EAAyB,WAAU,YAChCF,+BAAA;AAAA,IAACE,OAAgB;AAAA,IAAhB;AAAA,MACI,GAAG;AAAA,MACJ,WAAW;AAAA,MACX;AAAA,MACA;AAAA,MACA,OAAO,EAAE,OAAO,aAAa;AAAA,IAAA;AAAA,IAC5BF,+BAAA,cAAAE,OAAgB,SAAhB,MAAyB,OAAQ;AAAA,EAAA,CAE1C,CACJ;AAER,CAAC;"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const React = require("react");
|
|
4
4
|
const Button = require("../LegacyComponents/Button/Button.cjs");
|
|
5
|
+
const Inline = require("../Inline/Inline.cjs");
|
|
5
6
|
const Localization = require("../Provider/Localization.cjs");
|
|
6
7
|
function _interopNamespaceDefault(e) {
|
|
7
8
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
@@ -42,7 +43,7 @@ const createPageRange = (pageCount, pageNumber) => {
|
|
|
42
43
|
const PageNumbers = ({ currentPageIndex = 0, onClick: handleClick, pageCount }) => {
|
|
43
44
|
const range = createPageRange(pageCount, currentPageIndex + 1);
|
|
44
45
|
const { texts } = Localization.useLocalization();
|
|
45
|
-
return /* @__PURE__ */ React__namespace.createElement(
|
|
46
|
+
return /* @__PURE__ */ React__namespace.createElement(Inline.Inline, { spacing: 8 }, range.map((pageNumber) => /* @__PURE__ */ React__namespace.createElement(
|
|
46
47
|
Button.LegacyButton,
|
|
47
48
|
{
|
|
48
49
|
appearance: pageNumber === currentPageIndex + 1 ? "primary" : "default",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PageNumbers.cjs","sources":["../../../src/components/Pagination/PageNumbers.tsx"],"sourcesContent":["import * as React from 'react';\nimport { LegacyButton } from '../LegacyComponents/Button/Button';\nimport { useLocalization } from '../Provider/Localization';\n\ntype PageNumberProps = {\n currentPageIndex: number;\n onClick: (pageIndex: number) => void;\n pageCount: number;\n};\n\nconst createPageRange = (pageCount: number, pageNumber: number): number[] => {\n let lowerLimit = Math.min(pageNumber, pageCount);\n let upperLimit = Math.min(pageNumber, pageCount);\n\n for (let b = 1; b < 5 && b < pageCount; ) {\n if (lowerLimit > 1) {\n lowerLimit--;\n b++;\n }\n if (b < 5 && upperLimit < pageCount) {\n upperLimit++;\n b++;\n }\n }\n\n const range: number[] = [];\n\n for (let i = lowerLimit; i <= upperLimit; i++) {\n range.push(i);\n }\n\n return range;\n};\n\nexport const PageNumbers = ({ currentPageIndex = 0, onClick: handleClick, pageCount }: PageNumberProps): JSX.Element => {\n const range = createPageRange(pageCount, currentPageIndex + 1);\n const { texts } = useLocalization();\n\n return (\n
|
|
1
|
+
{"version":3,"file":"PageNumbers.cjs","sources":["../../../src/components/Pagination/PageNumbers.tsx"],"sourcesContent":["import * as React from 'react';\nimport { LegacyButton } from '../LegacyComponents/Button/Button';\nimport { Inline } from '../Inline/Inline';\nimport { useLocalization } from '../Provider/Localization';\n\ntype PageNumberProps = {\n currentPageIndex: number;\n onClick: (pageIndex: number) => void;\n pageCount: number;\n};\n\nconst createPageRange = (pageCount: number, pageNumber: number): number[] => {\n let lowerLimit = Math.min(pageNumber, pageCount);\n let upperLimit = Math.min(pageNumber, pageCount);\n\n for (let b = 1; b < 5 && b < pageCount; ) {\n if (lowerLimit > 1) {\n lowerLimit--;\n b++;\n }\n if (b < 5 && upperLimit < pageCount) {\n upperLimit++;\n b++;\n }\n }\n\n const range: number[] = [];\n\n for (let i = lowerLimit; i <= upperLimit; i++) {\n range.push(i);\n }\n\n return range;\n};\n\nexport const PageNumbers = ({ currentPageIndex = 0, onClick: handleClick, pageCount }: PageNumberProps): JSX.Element => {\n const range = createPageRange(pageCount, currentPageIndex + 1);\n const { texts } = useLocalization();\n\n return (\n <Inline spacing={8}>\n {range.map((pageNumber: number) => (\n <LegacyButton\n appearance={pageNumber === currentPageIndex + 1 ? 'primary' : 'default'}\n aria-current={pageNumber === currentPageIndex + 1 ? 'page' : undefined}\n key={pageNumber}\n onClick={() => handleClick(pageNumber - 1)}\n aria-label={texts.pagination.actions.pageX.replace('[X]', String(pageNumber))}\n tooltip={texts.pagination.actions.pageX.replace('[X]', String(pageNumber))}>\n {pageNumber}\n </LegacyButton>\n ))}\n </Inline>\n );\n};\n"],"names":["useLocalization","Inline","React","LegacyButton"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAWA,MAAM,kBAAkB,CAAC,WAAmB,eAAiC;AACzE,MAAI,aAAa,KAAK,IAAI,YAAY,SAAS;AAC/C,MAAI,aAAa,KAAK,IAAI,YAAY,SAAS;AAE/C,WAAS,IAAI,GAAG,IAAI,KAAK,IAAI,aAAa;AACtC,QAAI,aAAa,GAAG;AAChB;AACA;AAAA,IAAA;AAEA,QAAA,IAAI,KAAK,aAAa,WAAW;AACjC;AACA;AAAA,IAAA;AAAA,EACJ;AAGJ,QAAM,QAAkB,CAAC;AAEzB,WAAS,IAAI,YAAY,KAAK,YAAY,KAAK;AAC3C,UAAM,KAAK,CAAC;AAAA,EAAA;AAGT,SAAA;AACX;AAEa,MAAA,cAAc,CAAC,EAAE,mBAAmB,GAAG,SAAS,aAAa,gBAA8C;AACpH,QAAM,QAAQ,gBAAgB,WAAW,mBAAmB,CAAC;AACvD,QAAA,EAAE,MAAM,IAAIA,6BAAgB;AAElC,wDACKC,OAAO,QAAA,EAAA,SAAS,KACZ,MAAM,IAAI,CAAC,eACRC,iCAAA;AAAA,IAACC,OAAA;AAAA,IAAA;AAAA,MACG,YAAY,eAAe,mBAAmB,IAAI,YAAY;AAAA,MAC9D,gBAAc,eAAe,mBAAmB,IAAI,SAAS;AAAA,MAC7D,KAAK;AAAA,MACL,SAAS,MAAM,YAAY,aAAa,CAAC;AAAA,MACzC,cAAY,MAAM,WAAW,QAAQ,MAAM,QAAQ,OAAO,OAAO,UAAU,CAAC;AAAA,MAC5E,SAAS,MAAM,WAAW,QAAQ,MAAM,QAAQ,OAAO,OAAO,UAAU,CAAC;AAAA,IAAA;AAAA,IACxE;AAAA,EAAA,CAER,CACL;AAER;;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { LegacyButton } from "../LegacyComponents/Button/Button.js";
|
|
3
|
+
import { Inline } from "../Inline/Inline.js";
|
|
3
4
|
import { useLocalization } from "../Provider/Localization.js";
|
|
4
5
|
const createPageRange = (pageCount, pageNumber) => {
|
|
5
6
|
let lowerLimit = Math.min(pageNumber, pageCount);
|
|
@@ -23,7 +24,7 @@ const createPageRange = (pageCount, pageNumber) => {
|
|
|
23
24
|
const PageNumbers = ({ currentPageIndex = 0, onClick: handleClick, pageCount }) => {
|
|
24
25
|
const range = createPageRange(pageCount, currentPageIndex + 1);
|
|
25
26
|
const { texts } = useLocalization();
|
|
26
|
-
return /* @__PURE__ */ React.createElement(
|
|
27
|
+
return /* @__PURE__ */ React.createElement(Inline, { spacing: 8 }, range.map((pageNumber) => /* @__PURE__ */ React.createElement(
|
|
27
28
|
LegacyButton,
|
|
28
29
|
{
|
|
29
30
|
appearance: pageNumber === currentPageIndex + 1 ? "primary" : "default",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PageNumbers.js","sources":["../../../src/components/Pagination/PageNumbers.tsx"],"sourcesContent":["import * as React from 'react';\nimport { LegacyButton } from '../LegacyComponents/Button/Button';\nimport { useLocalization } from '../Provider/Localization';\n\ntype PageNumberProps = {\n currentPageIndex: number;\n onClick: (pageIndex: number) => void;\n pageCount: number;\n};\n\nconst createPageRange = (pageCount: number, pageNumber: number): number[] => {\n let lowerLimit = Math.min(pageNumber, pageCount);\n let upperLimit = Math.min(pageNumber, pageCount);\n\n for (let b = 1; b < 5 && b < pageCount; ) {\n if (lowerLimit > 1) {\n lowerLimit--;\n b++;\n }\n if (b < 5 && upperLimit < pageCount) {\n upperLimit++;\n b++;\n }\n }\n\n const range: number[] = [];\n\n for (let i = lowerLimit; i <= upperLimit; i++) {\n range.push(i);\n }\n\n return range;\n};\n\nexport const PageNumbers = ({ currentPageIndex = 0, onClick: handleClick, pageCount }: PageNumberProps): JSX.Element => {\n const range = createPageRange(pageCount, currentPageIndex + 1);\n const { texts } = useLocalization();\n\n return (\n
|
|
1
|
+
{"version":3,"file":"PageNumbers.js","sources":["../../../src/components/Pagination/PageNumbers.tsx"],"sourcesContent":["import * as React from 'react';\nimport { LegacyButton } from '../LegacyComponents/Button/Button';\nimport { Inline } from '../Inline/Inline';\nimport { useLocalization } from '../Provider/Localization';\n\ntype PageNumberProps = {\n currentPageIndex: number;\n onClick: (pageIndex: number) => void;\n pageCount: number;\n};\n\nconst createPageRange = (pageCount: number, pageNumber: number): number[] => {\n let lowerLimit = Math.min(pageNumber, pageCount);\n let upperLimit = Math.min(pageNumber, pageCount);\n\n for (let b = 1; b < 5 && b < pageCount; ) {\n if (lowerLimit > 1) {\n lowerLimit--;\n b++;\n }\n if (b < 5 && upperLimit < pageCount) {\n upperLimit++;\n b++;\n }\n }\n\n const range: number[] = [];\n\n for (let i = lowerLimit; i <= upperLimit; i++) {\n range.push(i);\n }\n\n return range;\n};\n\nexport const PageNumbers = ({ currentPageIndex = 0, onClick: handleClick, pageCount }: PageNumberProps): JSX.Element => {\n const range = createPageRange(pageCount, currentPageIndex + 1);\n const { texts } = useLocalization();\n\n return (\n <Inline spacing={8}>\n {range.map((pageNumber: number) => (\n <LegacyButton\n appearance={pageNumber === currentPageIndex + 1 ? 'primary' : 'default'}\n aria-current={pageNumber === currentPageIndex + 1 ? 'page' : undefined}\n key={pageNumber}\n onClick={() => handleClick(pageNumber - 1)}\n aria-label={texts.pagination.actions.pageX.replace('[X]', String(pageNumber))}\n tooltip={texts.pagination.actions.pageX.replace('[X]', String(pageNumber))}>\n {pageNumber}\n </LegacyButton>\n ))}\n </Inline>\n );\n};\n"],"names":[],"mappings":";;;;AAWA,MAAM,kBAAkB,CAAC,WAAmB,eAAiC;AACzE,MAAI,aAAa,KAAK,IAAI,YAAY,SAAS;AAC/C,MAAI,aAAa,KAAK,IAAI,YAAY,SAAS;AAE/C,WAAS,IAAI,GAAG,IAAI,KAAK,IAAI,aAAa;AACtC,QAAI,aAAa,GAAG;AAChB;AACA;AAAA,IAAA;AAEA,QAAA,IAAI,KAAK,aAAa,WAAW;AACjC;AACA;AAAA,IAAA;AAAA,EACJ;AAGJ,QAAM,QAAkB,CAAC;AAEzB,WAAS,IAAI,YAAY,KAAK,YAAY,KAAK;AAC3C,UAAM,KAAK,CAAC;AAAA,EAAA;AAGT,SAAA;AACX;AAEa,MAAA,cAAc,CAAC,EAAE,mBAAmB,GAAG,SAAS,aAAa,gBAA8C;AACpH,QAAM,QAAQ,gBAAgB,WAAW,mBAAmB,CAAC;AACvD,QAAA,EAAE,MAAM,IAAI,gBAAgB;AAElC,6CACK,QAAO,EAAA,SAAS,KACZ,MAAM,IAAI,CAAC,eACR,sBAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,YAAY,eAAe,mBAAmB,IAAI,YAAY;AAAA,MAC9D,gBAAc,eAAe,mBAAmB,IAAI,SAAS;AAAA,MAC7D,KAAK;AAAA,MACL,SAAS,MAAM,YAAY,aAAa,CAAC;AAAA,MACzC,cAAY,MAAM,WAAW,QAAQ,MAAM,QAAQ,OAAO,OAAO,UAAU,CAAC;AAAA,MAC5E,SAAS,MAAM,WAAW,QAAQ,MAAM,QAAQ,OAAO,OAAO,UAAU,CAAC;AAAA,IAAA;AAAA,IACxE;AAAA,EAAA,CAER,CACL;AAER;"}
|
|
@@ -5,7 +5,7 @@ const cn = require("clsx");
|
|
|
5
5
|
const PageNumbers = require("./PageNumbers.cjs");
|
|
6
6
|
const Localization = require("../Provider/Localization.cjs");
|
|
7
7
|
const Select2 = require("../Select2/Select2.cjs");
|
|
8
|
-
const
|
|
8
|
+
const Inline = require("../Inline/Inline.cjs");
|
|
9
9
|
const IconButton = require("../LegacyComponents/IconButton/IconButton.cjs");
|
|
10
10
|
const usePaginationShortcuts = require("./usePaginationShortcuts.cjs");
|
|
11
11
|
function _interopNamespaceDefault(e) {
|
|
@@ -69,7 +69,7 @@ const Pagination = React__namespace.forwardRef(function Pagination2(props, ref)
|
|
|
69
69
|
value: pageSize
|
|
70
70
|
},
|
|
71
71
|
pageSizes.map((size) => /* @__PURE__ */ React__namespace.createElement(Select2.Select2.Option, { key: size, value: size }, String(size)))
|
|
72
|
-
)), showPageControls && /* @__PURE__ */ React__namespace.createElement(
|
|
72
|
+
)), showPageControls && /* @__PURE__ */ React__namespace.createElement("nav", { "aria-label": texts.pagination.label }, /* @__PURE__ */ React__namespace.createElement(Inline.Inline, { spacing: 8 }, /* @__PURE__ */ React__namespace.createElement(
|
|
73
73
|
IconButton.LegacyIconButton,
|
|
74
74
|
{
|
|
75
75
|
appearance: "default",
|
|
@@ -109,7 +109,7 @@ const Pagination = React__namespace.forwardRef(function Pagination2(props, ref)
|
|
|
109
109
|
"aria-label": showShortcutTexts ? texts.pagination.actions.lastPageWithShortcut : texts.pagination.actions.lastPage,
|
|
110
110
|
tooltip: showShortcutTexts ? texts.pagination.actions.lastPageWithShortcut : texts.pagination.actions.lastPage
|
|
111
111
|
}
|
|
112
|
-
)));
|
|
112
|
+
))));
|
|
113
113
|
});
|
|
114
114
|
exports.Pagination = Pagination;
|
|
115
115
|
//# sourceMappingURL=Pagination.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Pagination.cjs","sources":["../../../src/components/Pagination/Pagination.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'clsx';\nimport { PageNumbers } from './PageNumbers';\nimport { LocalizationTexts, useLocalization } from '../Provider/Localization';\nimport { Select2 } from '../Select2/Select2';\nimport { Group } from '../Group/Group';\nimport { LegacyIconButton } from '../LegacyComponents/IconButton/IconButton';\nimport { usePaginationValues } from './usePagination';\nimport { usePaginationShortcuts } from './usePaginationShortcuts';\n\nexport * from './usePagination';\n\nexport type PaginationTextsActions = {\n /**\n * Aria-label for first page action button.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n firstPage: string;\n /**\n * Aria-label for first page action button with shortcut.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n firstPageWithShortcut: string;\n /**\n * Aria-label for next page action button.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n nextPage: string;\n /**\n * Aria-label for next page action button with shortcut.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n nextPageWithShortcut: string;\n /**\n * Aria-label for previous page action button.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n previousPage: string;\n /**\n * Aria-label for previous page action button with shortcut.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n previousPageWithShortcut: string;\n /**\n * Aria-label for last page action button.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n lastPage: string;\n /**\n * Aria-label for last page action button with shortcut.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n lastPageWithShortcut: string;\n /**\n * Aria-label for page X action button.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n pageX: string;\n};\n\nexport type PaginationTexts = {\n /**\n * Aria-label provided for page numbers and page actions group.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n label: string;\n /**\n * Aria-label provided for page size selection.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n pageSize: string;\n /**\n * Text that indicates the number of the first and last element displayed on the current page, out of total items\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n showingXofYofTotal: string;\n /**\n * Aria-labels provided for page action buttons.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n actions: PaginationTextsActions;\n};\n\nexport type PaginationProps = React.HTMLAttributes<HTMLDivElement> &\n usePaginationValues & {\n /** Indicate total number of items that will be paginated */\n length: number;\n /** Page size options */\n pageSizes?: number[];\n /** Shows page controls */\n showPageControls?: boolean;\n /** Shows page numbers between navigation buttons, which allows users to quickly navigate to a specific page */\n showPageNumbers?: boolean;\n /** Shows a dropdown with page sizes, which allows user to change the number of items displayed on the page */\n showPageSize?: boolean;\n /** Enable pagination shortcuts */\n dangerouslyHijackGlobalKeyboardNavigation?: boolean;\n };\n\nconst getShowingLabel = (length: number, pageIndex: number, pageSize: number, texts: LocalizationTexts): string => {\n const minItemIndex = pageIndex * pageSize + 1;\n const maxItemIndex = (pageIndex + 1) * pageSize;\n\n return texts.pagination.showingXofYofTotal\n .replace('[X]', length === 0 ? '0' : String(minItemIndex))\n .replace('[Y]', String(maxItemIndex > length ? length : maxItemIndex))\n .replace('[total]', String(length));\n};\n\nexport const Pagination = React.forwardRef(function Pagination(props: PaginationProps, ref: React.Ref<HTMLDivElement>) {\n const {\n length,\n pageIndex,\n pageSize,\n pageSizes = [10, 25, 50, 100, 500],\n setPageIndex,\n setPageSize,\n showPageControls = true,\n showPageNumbers = true,\n showPageSize = true,\n dangerouslyHijackGlobalKeyboardNavigation = false,\n ...otherProps\n } = props;\n const { texts } = useLocalization();\n\n const maxPageIndex = Math.ceil(length / pageSize) - 1;\n const showShortcutTexts = dangerouslyHijackGlobalKeyboardNavigation;\n\n usePaginationShortcuts({\n setPageIndex,\n maxPageIndex,\n pageIndex,\n dangerouslyHijackGlobalKeyboardNavigation,\n });\n\n const pageCount = Math.ceil(length / pageSize);\n const canPreviousPage = pageIndex > 0;\n const canNextPage = pageIndex < pageCount - 1;\n\n const className = cn('inline-flex relative justify-between items-center', props.className);\n\n return (\n <div {...otherProps} className={className} data-taco=\"pagination\" ref={ref}>\n {showPageSize && (\n <span className=\"mr-4 inline-flex items-center\">\n {getShowingLabel(length, pageIndex, pageSize, texts)}\n <Select2\n aria-label={texts.pagination.pageSize}\n className=\"ml-4 !w-20\"\n onChange={value => {\n setPageIndex(0);\n setPageSize(Number(value));\n }}\n value={pageSize}>\n {pageSizes.map(size => (\n <Select2.Option key={size} value={size}>\n {String(size)}\n </Select2.Option>\n ))}\n </Select2>\n </span>\n )}\n {showPageControls && (\n <Group as=\"nav\" aria-label={texts.pagination.label}>\n <LegacyIconButton\n appearance=\"default\"\n disabled={!canPreviousPage}\n icon=\"arrow-start\"\n onClick={() => setPageIndex(0)}\n aria-label={\n showShortcutTexts\n ? texts.pagination.actions.firstPageWithShortcut\n : texts.pagination.actions.firstPage\n }\n tooltip={\n showShortcutTexts\n ? texts.pagination.actions.firstPageWithShortcut\n : texts.pagination.actions.firstPage\n }\n />\n <LegacyIconButton\n appearance=\"default\"\n disabled={!canPreviousPage}\n icon=\"arrow-left\"\n onClick={() => setPageIndex(pageIndex - 1)}\n aria-label={\n showShortcutTexts\n ? texts.pagination.actions.previousPageWithShortcut\n : texts.pagination.actions.previousPage\n }\n tooltip={\n showShortcutTexts\n ? texts.pagination.actions.previousPageWithShortcut\n : texts.pagination.actions.previousPage\n }\n />\n {showPageNumbers && pageCount > 0 && (\n <PageNumbers pageCount={pageCount} currentPageIndex={pageIndex} onClick={setPageIndex} />\n )}\n <LegacyIconButton\n appearance=\"default\"\n disabled={!canNextPage}\n icon=\"arrow-right\"\n onClick={() => setPageIndex(pageIndex + 1)}\n aria-label={\n showShortcutTexts ? texts.pagination.actions.nextPageWithShortcut : texts.pagination.actions.nextPage\n }\n tooltip={\n showShortcutTexts ? texts.pagination.actions.nextPageWithShortcut : texts.pagination.actions.nextPage\n }\n />\n <LegacyIconButton\n appearance=\"default\"\n disabled={!canNextPage}\n icon=\"arrow-end\"\n onClick={() => setPageIndex(pageCount - 1)}\n aria-label={\n showShortcutTexts ? texts.pagination.actions.lastPageWithShortcut : texts.pagination.actions.lastPage\n }\n tooltip={\n showShortcutTexts ? texts.pagination.actions.lastPageWithShortcut : texts.pagination.actions.lastPage\n }\n />\n </Group>\n )}\n </div>\n );\n});\n"],"names":["React","Pagination","useLocalization","usePaginationShortcuts","Select2","Group","LegacyIconButton","PageNumbers"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAmGA,MAAM,kBAAkB,CAAC,QAAgB,WAAmB,UAAkB,UAAqC;AACzG,QAAA,eAAe,YAAY,WAAW;AACtC,QAAA,gBAAgB,YAAY,KAAK;AAEhC,SAAA,MAAM,WAAW,mBACnB,QAAQ,OAAO,WAAW,IAAI,MAAM,OAAO,YAAY,CAAC,EACxD,QAAQ,OAAO,OAAO,eAAe,SAAS,SAAS,YAAY,CAAC,EACpE,QAAQ,WAAW,OAAO,MAAM,CAAC;AAC1C;AAEO,MAAM,aAAaA,iBAAM,WAAW,SAASC,YAAW,OAAwB,KAAgC;AAC7G,QAAA;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAY,CAAC,IAAI,IAAI,IAAI,KAAK,GAAG;AAAA,IACjC;AAAA,IACA;AAAA,IACA,mBAAmB;AAAA,IACnB,kBAAkB;AAAA,IAClB,eAAe;AAAA,IACf,4CAA4C;AAAA,IAC5C,GAAG;AAAA,EAAA,IACH;AACE,QAAA,EAAE,MAAM,IAAIC,6BAAgB;AAElC,QAAM,eAAe,KAAK,KAAK,SAAS,QAAQ,IAAI;AACpD,QAAM,oBAAoB;AAEHC,gDAAA;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACH;AAED,QAAM,YAAY,KAAK,KAAK,SAAS,QAAQ;AAC7C,QAAM,kBAAkB,YAAY;AAC9B,QAAA,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W,QAAQ;AAAA,IAAA;AAAA,EAAA,GAGtC,mBAAmB,YAAY,KAC5BN,iCAAA,cAACO,YAAAA,aAAY,EAAA,WAAsB,kBAAkB,WAAW,SAAS,aAAA,CAAc,GAE3FP,iCAAA;AAAA,IAACM,WAAA;AAAA,IAAA;AAAA,MACG,YAAW;AAAA,MACX,UAAU,CAAC;AAAA,MACX,MAAK;AAAA,MACL,SAAS,MAAM,aAAa,YAAY,CAAC;AAAA,MACzC,cACI,oBAAoB,MAAM,WAAW,QAAQ,uBAAuB,MAAM,WAAW,QAAQ;AAAA,MAEjG,SACI,oBAAoB,MAAM,WAAW,QAAQ,uBAAuB,MAAM,WAAW,QAAQ;AAAA,IAAA;AAAA,EAGrG,GAAAN,iCAAA;AAAA,IAACM,WAAA;AAAA,IAAA;AAAA,MACG,YAAW;AAAA,MACX,UAAU,CAAC;AAAA,MACX,MAAK;AAAA,MACL,SAAS,MAAM,aAAa,YAAY,CAAC;AAAA,MACzC,cACI,oBAAoB,MAAM,WAAW,QAAQ,uBAAuB,MAAM,WAAW,QAAQ;AAAA,MAEjG,SACI,oBAAoB,MAAM,WAAW,QAAQ,uBAAuB,MAAM,WAAW,QAAQ;AAAA,IAAA;AAAA,EAAA,CAGzG,CAER;AAER,CAAC;;"}
|
|
1
|
+
{"version":3,"file":"Pagination.cjs","sources":["../../../src/components/Pagination/Pagination.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'clsx';\nimport { PageNumbers } from './PageNumbers';\nimport { LocalizationTexts, useLocalization } from '../Provider/Localization';\nimport { Select2 } from '../Select2/Select2';\nimport { Inline } from '../Inline/Inline';\nimport { LegacyIconButton } from '../LegacyComponents/IconButton/IconButton';\nimport { usePaginationValues } from './usePagination';\nimport { usePaginationShortcuts } from './usePaginationShortcuts';\n\nexport * from './usePagination';\n\nexport type PaginationTextsActions = {\n /**\n * Aria-label for first page action button.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n firstPage: string;\n /**\n * Aria-label for first page action button with shortcut.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n firstPageWithShortcut: string;\n /**\n * Aria-label for next page action button.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n nextPage: string;\n /**\n * Aria-label for next page action button with shortcut.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n nextPageWithShortcut: string;\n /**\n * Aria-label for previous page action button.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n previousPage: string;\n /**\n * Aria-label for previous page action button with shortcut.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n previousPageWithShortcut: string;\n /**\n * Aria-label for last page action button.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n lastPage: string;\n /**\n * Aria-label for last page action button with shortcut.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n lastPageWithShortcut: string;\n /**\n * Aria-label for page X action button.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n pageX: string;\n};\n\nexport type PaginationTexts = {\n /**\n * Aria-label provided for page numbers and page actions group.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n label: string;\n /**\n * Aria-label provided for page size selection.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n pageSize: string;\n /**\n * Text that indicates the number of the first and last element displayed on the current page, out of total items\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n showingXofYofTotal: string;\n /**\n * Aria-labels provided for page action buttons.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n actions: PaginationTextsActions;\n};\n\nexport type PaginationProps = React.HTMLAttributes<HTMLDivElement> &\n usePaginationValues & {\n /** Indicate total number of items that will be paginated */\n length: number;\n /** Page size options */\n pageSizes?: number[];\n /** Shows page controls */\n showPageControls?: boolean;\n /** Shows page numbers between navigation buttons, which allows users to quickly navigate to a specific page */\n showPageNumbers?: boolean;\n /** Shows a dropdown with page sizes, which allows user to change the number of items displayed on the page */\n showPageSize?: boolean;\n /** Enable pagination shortcuts */\n dangerouslyHijackGlobalKeyboardNavigation?: boolean;\n };\n\nconst getShowingLabel = (length: number, pageIndex: number, pageSize: number, texts: LocalizationTexts): string => {\n const minItemIndex = pageIndex * pageSize + 1;\n const maxItemIndex = (pageIndex + 1) * pageSize;\n\n return texts.pagination.showingXofYofTotal\n .replace('[X]', length === 0 ? '0' : String(minItemIndex))\n .replace('[Y]', String(maxItemIndex > length ? length : maxItemIndex))\n .replace('[total]', String(length));\n};\n\nexport const Pagination = React.forwardRef(function Pagination(props: PaginationProps, ref: React.Ref<HTMLDivElement>) {\n const {\n length,\n pageIndex,\n pageSize,\n pageSizes = [10, 25, 50, 100, 500],\n setPageIndex,\n setPageSize,\n showPageControls = true,\n showPageNumbers = true,\n showPageSize = true,\n dangerouslyHijackGlobalKeyboardNavigation = false,\n ...otherProps\n } = props;\n const { texts } = useLocalization();\n\n const maxPageIndex = Math.ceil(length / pageSize) - 1;\n const showShortcutTexts = dangerouslyHijackGlobalKeyboardNavigation;\n\n usePaginationShortcuts({\n setPageIndex,\n maxPageIndex,\n pageIndex,\n dangerouslyHijackGlobalKeyboardNavigation,\n });\n\n const pageCount = Math.ceil(length / pageSize);\n const canPreviousPage = pageIndex > 0;\n const canNextPage = pageIndex < pageCount - 1;\n\n const className = cn('inline-flex relative justify-between items-center', props.className);\n\n return (\n <div {...otherProps} className={className} data-taco=\"pagination\" ref={ref}>\n {showPageSize && (\n <span className=\"mr-4 inline-flex items-center\">\n {getShowingLabel(length, pageIndex, pageSize, texts)}\n <Select2\n aria-label={texts.pagination.pageSize}\n className=\"ml-4 !w-20\"\n onChange={value => {\n setPageIndex(0);\n setPageSize(Number(value));\n }}\n value={pageSize}>\n {pageSizes.map(size => (\n <Select2.Option key={size} value={size}>\n {String(size)}\n </Select2.Option>\n ))}\n </Select2>\n </span>\n )}\n {showPageControls && (\n <nav aria-label={texts.pagination.label}>\n <Inline spacing={8}>\n <LegacyIconButton\n appearance=\"default\"\n disabled={!canPreviousPage}\n icon=\"arrow-start\"\n onClick={() => setPageIndex(0)}\n aria-label={\n showShortcutTexts\n ? texts.pagination.actions.firstPageWithShortcut\n : texts.pagination.actions.firstPage\n }\n tooltip={\n showShortcutTexts\n ? texts.pagination.actions.firstPageWithShortcut\n : texts.pagination.actions.firstPage\n }\n />\n <LegacyIconButton\n appearance=\"default\"\n disabled={!canPreviousPage}\n icon=\"arrow-left\"\n onClick={() => setPageIndex(pageIndex - 1)}\n aria-label={\n showShortcutTexts\n ? texts.pagination.actions.previousPageWithShortcut\n : texts.pagination.actions.previousPage\n }\n tooltip={\n showShortcutTexts\n ? texts.pagination.actions.previousPageWithShortcut\n : texts.pagination.actions.previousPage\n }\n />\n {showPageNumbers && pageCount > 0 && (\n <PageNumbers pageCount={pageCount} currentPageIndex={pageIndex} onClick={setPageIndex} />\n )}\n <LegacyIconButton\n appearance=\"default\"\n disabled={!canNextPage}\n icon=\"arrow-right\"\n onClick={() => setPageIndex(pageIndex + 1)}\n aria-label={\n showShortcutTexts\n ? texts.pagination.actions.nextPageWithShortcut\n : texts.pagination.actions.nextPage\n }\n tooltip={\n showShortcutTexts\n ? texts.pagination.actions.nextPageWithShortcut\n : texts.pagination.actions.nextPage\n }\n />\n <LegacyIconButton\n appearance=\"default\"\n disabled={!canNextPage}\n icon=\"arrow-end\"\n onClick={() => setPageIndex(pageCount - 1)}\n aria-label={\n showShortcutTexts\n ? texts.pagination.actions.lastPageWithShortcut\n : texts.pagination.actions.lastPage\n }\n tooltip={\n showShortcutTexts\n ? texts.pagination.actions.lastPageWithShortcut\n : texts.pagination.actions.lastPage\n }\n />\n </Inline>\n </nav>\n )}\n </div>\n );\n});\n"],"names":["React","Pagination","useLocalization","usePaginationShortcuts","Select2","Inline","LegacyIconButton","PageNumbers"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAmGA,MAAM,kBAAkB,CAAC,QAAgB,WAAmB,UAAkB,UAAqC;AACzG,QAAA,eAAe,YAAY,WAAW;AACtC,QAAA,gBAAgB,YAAY,KAAK;AAEhC,SAAA,MAAM,WAAW,mBACnB,QA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ACG,YAAW;AAAA,MACX,UAAU,CAAC;AAAA,MACX,MAAK;AAAA,MACL,SAAS,MAAM,aAAa,YAAY,CAAC;AAAA,MACzC,cACI,oBACM,MAAM,WAAW,QAAQ,uBACzB,MAAM,WAAW,QAAQ;AAAA,MAEnC,SACI,oBACM,MAAM,WAAW,QAAQ,uBACzB,MAAM,WAAW,QAAQ;AAAA,IAAA;AAAA,EAG3C,CAAA,CACJ,CAER;AAER,CAAC;;"}
|
|
@@ -3,7 +3,7 @@ import cn from "clsx";
|
|
|
3
3
|
import { PageNumbers } from "./PageNumbers.js";
|
|
4
4
|
import { useLocalization } from "../Provider/Localization.js";
|
|
5
5
|
import { Select2 } from "../Select2/Select2.js";
|
|
6
|
-
import {
|
|
6
|
+
import { Inline } from "../Inline/Inline.js";
|
|
7
7
|
import { LegacyIconButton } from "../LegacyComponents/IconButton/IconButton.js";
|
|
8
8
|
import { usePaginationShortcuts } from "./usePaginationShortcuts.js";
|
|
9
9
|
const getShowingLabel = (length, pageIndex, pageSize, texts) => {
|
|
@@ -50,7 +50,7 @@ const Pagination = React.forwardRef(function Pagination2(props, ref) {
|
|
|
50
50
|
value: pageSize
|
|
51
51
|
},
|
|
52
52
|
pageSizes.map((size) => /* @__PURE__ */ React.createElement(Select2.Option, { key: size, value: size }, String(size)))
|
|
53
|
-
)), showPageControls && /* @__PURE__ */ React.createElement(
|
|
53
|
+
)), showPageControls && /* @__PURE__ */ React.createElement("nav", { "aria-label": texts.pagination.label }, /* @__PURE__ */ React.createElement(Inline, { spacing: 8 }, /* @__PURE__ */ React.createElement(
|
|
54
54
|
LegacyIconButton,
|
|
55
55
|
{
|
|
56
56
|
appearance: "default",
|
|
@@ -90,7 +90,7 @@ const Pagination = React.forwardRef(function Pagination2(props, ref) {
|
|
|
90
90
|
"aria-label": showShortcutTexts ? texts.pagination.actions.lastPageWithShortcut : texts.pagination.actions.lastPage,
|
|
91
91
|
tooltip: showShortcutTexts ? texts.pagination.actions.lastPageWithShortcut : texts.pagination.actions.lastPage
|
|
92
92
|
}
|
|
93
|
-
)));
|
|
93
|
+
))));
|
|
94
94
|
});
|
|
95
95
|
export {
|
|
96
96
|
Pagination
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Pagination.js","sources":["../../../src/components/Pagination/Pagination.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'clsx';\nimport { PageNumbers } from './PageNumbers';\nimport { LocalizationTexts, useLocalization } from '../Provider/Localization';\nimport { Select2 } from '../Select2/Select2';\nimport { Group } from '../Group/Group';\nimport { LegacyIconButton } from '../LegacyComponents/IconButton/IconButton';\nimport { usePaginationValues } from './usePagination';\nimport { usePaginationShortcuts } from './usePaginationShortcuts';\n\nexport * from './usePagination';\n\nexport type PaginationTextsActions = {\n /**\n * Aria-label for first page action button.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n firstPage: string;\n /**\n * Aria-label for first page action button with shortcut.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n firstPageWithShortcut: string;\n /**\n * Aria-label for next page action button.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n nextPage: string;\n /**\n * Aria-label for next page action button with shortcut.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n nextPageWithShortcut: string;\n /**\n * Aria-label for previous page action button.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n previousPage: string;\n /**\n * Aria-label for previous page action button with shortcut.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n previousPageWithShortcut: string;\n /**\n * Aria-label for last page action button.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n lastPage: string;\n /**\n * Aria-label for last page action button with shortcut.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n lastPageWithShortcut: string;\n /**\n * Aria-label for page X action button.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n pageX: string;\n};\n\nexport type PaginationTexts = {\n /**\n * Aria-label provided for page numbers and page actions group.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n label: string;\n /**\n * Aria-label provided for page size selection.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n pageSize: string;\n /**\n * Text that indicates the number of the first and last element displayed on the current page, out of total items\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n showingXofYofTotal: string;\n /**\n * Aria-labels provided for page action buttons.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n actions: PaginationTextsActions;\n};\n\nexport type PaginationProps = React.HTMLAttributes<HTMLDivElement> &\n usePaginationValues & {\n /** Indicate total number of items that will be paginated */\n length: number;\n /** Page size options */\n pageSizes?: number[];\n /** Shows page controls */\n showPageControls?: boolean;\n /** Shows page numbers between navigation buttons, which allows users to quickly navigate to a specific page */\n showPageNumbers?: boolean;\n /** Shows a dropdown with page sizes, which allows user to change the number of items displayed on the page */\n showPageSize?: boolean;\n /** Enable pagination shortcuts */\n dangerouslyHijackGlobalKeyboardNavigation?: boolean;\n };\n\nconst getShowingLabel = (length: number, pageIndex: number, pageSize: number, texts: LocalizationTexts): string => {\n const minItemIndex = pageIndex * pageSize + 1;\n const maxItemIndex = (pageIndex + 1) * pageSize;\n\n return texts.pagination.showingXofYofTotal\n .replace('[X]', length === 0 ? '0' : String(minItemIndex))\n .replace('[Y]', String(maxItemIndex > length ? length : maxItemIndex))\n .replace('[total]', String(length));\n};\n\nexport const Pagination = React.forwardRef(function Pagination(props: PaginationProps, ref: React.Ref<HTMLDivElement>) {\n const {\n length,\n pageIndex,\n pageSize,\n pageSizes = [10, 25, 50, 100, 500],\n setPageIndex,\n setPageSize,\n showPageControls = true,\n showPageNumbers = true,\n showPageSize = true,\n dangerouslyHijackGlobalKeyboardNavigation = false,\n ...otherProps\n } = props;\n const { texts } = useLocalization();\n\n const maxPageIndex = Math.ceil(length / pageSize) - 1;\n const showShortcutTexts = dangerouslyHijackGlobalKeyboardNavigation;\n\n usePaginationShortcuts({\n setPageIndex,\n maxPageIndex,\n pageIndex,\n dangerouslyHijackGlobalKeyboardNavigation,\n });\n\n const pageCount = Math.ceil(length / pageSize);\n const canPreviousPage = pageIndex > 0;\n const canNextPage = pageIndex < pageCount - 1;\n\n const className = cn('inline-flex relative justify-between items-center', props.className);\n\n return (\n <div {...otherProps} className={className} data-taco=\"pagination\" ref={ref}>\n {showPageSize && (\n <span className=\"mr-4 inline-flex items-center\">\n {getShowingLabel(length, pageIndex, pageSize, texts)}\n <Select2\n aria-label={texts.pagination.pageSize}\n className=\"ml-4 !w-20\"\n onChange={value => {\n setPageIndex(0);\n setPageSize(Number(value));\n }}\n value={pageSize}>\n {pageSizes.map(size => (\n <Select2.Option key={size} value={size}>\n {String(size)}\n </Select2.Option>\n ))}\n </Select2>\n </span>\n )}\n {showPageControls && (\n <Group as=\"nav\" aria-label={texts.pagination.label}>\n <LegacyIconButton\n appearance=\"default\"\n disabled={!canPreviousPage}\n icon=\"arrow-start\"\n onClick={() => setPageIndex(0)}\n aria-label={\n showShortcutTexts\n ? texts.pagination.actions.firstPageWithShortcut\n : texts.pagination.actions.firstPage\n }\n tooltip={\n showShortcutTexts\n ? texts.pagination.actions.firstPageWithShortcut\n : texts.pagination.actions.firstPage\n }\n />\n <LegacyIconButton\n appearance=\"default\"\n disabled={!canPreviousPage}\n icon=\"arrow-left\"\n onClick={() => setPageIndex(pageIndex - 1)}\n aria-label={\n showShortcutTexts\n ? texts.pagination.actions.previousPageWithShortcut\n : texts.pagination.actions.previousPage\n }\n tooltip={\n showShortcutTexts\n ? texts.pagination.actions.previousPageWithShortcut\n : texts.pagination.actions.previousPage\n }\n />\n {showPageNumbers && pageCount > 0 && (\n <PageNumbers pageCount={pageCount} currentPageIndex={pageIndex} onClick={setPageIndex} />\n )}\n <LegacyIconButton\n appearance=\"default\"\n disabled={!canNextPage}\n icon=\"arrow-right\"\n onClick={() => setPageIndex(pageIndex + 1)}\n aria-label={\n showShortcutTexts ? texts.pagination.actions.nextPageWithShortcut : texts.pagination.actions.nextPage\n }\n tooltip={\n showShortcutTexts ? texts.pagination.actions.nextPageWithShortcut : texts.pagination.actions.nextPage\n }\n />\n <LegacyIconButton\n appearance=\"default\"\n disabled={!canNextPage}\n icon=\"arrow-end\"\n onClick={() => setPageIndex(pageCount - 1)}\n aria-label={\n showShortcutTexts ? texts.pagination.actions.lastPageWithShortcut : texts.pagination.actions.lastPage\n }\n tooltip={\n showShortcutTexts ? texts.pagination.actions.lastPageWithShortcut : texts.pagination.actions.lastPage\n }\n />\n </Group>\n )}\n </div>\n );\n});\n"],"names":["Pagination"],"mappings":";;;;;;;;AAmGA,MAAM,kBAAkB,CAAC,QAAgB,WAAmB,UAAkB,UAAqC;AACzG,QAAA,eAAe,YAAY,WAAW;AACtC,QAAA,gBAAgB,YAAY,KAAK;AAEhC,SAAA,MAAM,WAAW,mBACnB,QAAQ,OAAO,WAAW,IAAI,MAAM,OAAO,YAAY,CAAC,EACxD,QAAQ,OAAO,OAAO,eAAe,SAAS,SAAS,YAAY,CAAC,EACpE,QAAQ,WAAW,OAAO,MAAM,CAAC;AAC1C;AAEO,MAAM,aAAa,MAAM,WAAW,SAASA,YAAW,OAAwB,KAAgC;AAC7G,QAAA;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAY,CAAC,IAAI,IAAI,IAAI,KAAK,GAAG;AAAA,IACjC;AAAA,IACA;AAAA,IACA,mBAAmB;AAAA,IACnB,kBAAkB;AAAA,IAClB,eAAe;AAAA,IACf,4CAA4C;AAAA,IAC5C,GAAG;AAAA,EAAA,IACH;AACE,QAAA,EAAE,MAAM,IAAI,gBAAgB;AAElC,QAAM,eAAe,KAAK,KAAK,SAAS,QAAQ,IAAI;AACpD,QAAM,oBAAoB;AAEH,yBAAA;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACH;AAED,QAAM,YAAY,KAAK,KAAK,SAAS,QAAQ;AAC7C,QAAM,kBAAkB,YAAY;AAC9B,QAAA,cAAc,YAAY,YAAY;AAE5C,QAAM,YAAY,GAAG,qDAAqD,MAAM,SAAS;AAEzF,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,aAAA,CAAc,GAE3F,sBAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,YAAW;AAAA,MACX,UAAU,CAAC;AAAA,MACX,MAAK;AAAA,MACL,SAAS,MAAM,aAAa,YAAY,CAAC;AAAA,MACzC,cACI,oBAAoB,MAAM,WAAW,QAAQ,uBAAuB,MAAM,WAAW,QAAQ;AAAA,MAEjG,SACI,oBAAoB,MAAM,WAAW,QAAQ,uBAAuB,MAAM,WAAW,QAAQ;AAAA,IAAA;AAAA,EAGrG,GAAA,sBAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,YAAW;AAAA,MACX,UAAU,CAAC;AAAA,MACX,MAAK;AAAA,MACL,SAAS,MAAM,aAAa,YAAY,CAAC;AAAA,MACzC,cACI,oBAAoB,MAAM,WAAW,QAAQ,uBAAuB,MAAM,WAAW,QAAQ;AAAA,MAEjG,SACI,oBAAoB,MAAM,WAAW,QAAQ,uBAAuB,MAAM,WAAW,QAAQ;AAAA,IAAA;AAAA,EAAA,CAGzG,CAER;AAER,CAAC;"}
|
|
1
|
+
{"version":3,"file":"Pagination.js","sources":["../../../src/components/Pagination/Pagination.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'clsx';\nimport { PageNumbers } from './PageNumbers';\nimport { LocalizationTexts, useLocalization } from '../Provider/Localization';\nimport { Select2 } from '../Select2/Select2';\nimport { Inline } from '../Inline/Inline';\nimport { LegacyIconButton } from '../LegacyComponents/IconButton/IconButton';\nimport { usePaginationValues } from './usePagination';\nimport { usePaginationShortcuts } from './usePaginationShortcuts';\n\nexport * from './usePagination';\n\nexport type PaginationTextsActions = {\n /**\n * Aria-label for first page action button.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n firstPage: string;\n /**\n * Aria-label for first page action button with shortcut.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n firstPageWithShortcut: string;\n /**\n * Aria-label for next page action button.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n nextPage: string;\n /**\n * Aria-label for next page action button with shortcut.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n nextPageWithShortcut: string;\n /**\n * Aria-label for previous page action button.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n previousPage: string;\n /**\n * Aria-label for previous page action button with shortcut.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n previousPageWithShortcut: string;\n /**\n * Aria-label for last page action button.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n lastPage: string;\n /**\n * Aria-label for last page action button with shortcut.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n lastPageWithShortcut: string;\n /**\n * Aria-label for page X action button.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n pageX: string;\n};\n\nexport type PaginationTexts = {\n /**\n * Aria-label provided for page numbers and page actions group.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n label: string;\n /**\n * Aria-label provided for page size selection.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n pageSize: string;\n /**\n * Text that indicates the number of the first and last element displayed on the current page, out of total items\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n showingXofYofTotal: string;\n /**\n * Aria-labels provided for page action buttons.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n actions: PaginationTextsActions;\n};\n\nexport type PaginationProps = React.HTMLAttributes<HTMLDivElement> &\n usePaginationValues & {\n /** Indicate total number of items that will be paginated */\n length: number;\n /** Page size options */\n pageSizes?: number[];\n /** Shows page controls */\n showPageControls?: boolean;\n /** Shows page numbers between navigation buttons, which allows users to quickly navigate to a specific page */\n showPageNumbers?: boolean;\n /** Shows a dropdown with page sizes, which allows user to change the number of items displayed on the page */\n showPageSize?: boolean;\n /** Enable pagination shortcuts */\n dangerouslyHijackGlobalKeyboardNavigation?: boolean;\n };\n\nconst getShowingLabel = (length: number, pageIndex: number, pageSize: number, texts: LocalizationTexts): string => {\n const minItemIndex = pageIndex * pageSize + 1;\n const maxItemIndex = (pageIndex + 1) * pageSize;\n\n return texts.pagination.showingXofYofTotal\n .replace('[X]', length === 0 ? '0' : String(minItemIndex))\n .replace('[Y]', String(maxItemIndex > length ? length : maxItemIndex))\n .replace('[total]', String(length));\n};\n\nexport const Pagination = React.forwardRef(function Pagination(props: PaginationProps, ref: React.Ref<HTMLDivElement>) {\n const {\n length,\n pageIndex,\n pageSize,\n pageSizes = [10, 25, 50, 100, 500],\n setPageIndex,\n setPageSize,\n showPageControls = true,\n showPageNumbers = true,\n showPageSize = true,\n dangerouslyHijackGlobalKeyboardNavigation = false,\n ...otherProps\n } = props;\n const { texts } = useLocalization();\n\n const maxPageIndex = Math.ceil(length / pageSize) - 1;\n const showShortcutTexts = dangerouslyHijackGlobalKeyboardNavigation;\n\n usePaginationShortcuts({\n setPageIndex,\n maxPageIndex,\n pageIndex,\n dangerouslyHijackGlobalKeyboardNavigation,\n });\n\n const pageCount = Math.ceil(length / pageSize);\n const canPreviousPage = pageIndex > 0;\n const canNextPage = pageIndex < pageCount - 1;\n\n const className = cn('inline-flex relative justify-between items-center', props.className);\n\n return (\n <div {...otherProps} className={className} data-taco=\"pagination\" ref={ref}>\n {showPageSize && (\n <span className=\"mr-4 inline-flex items-center\">\n {getShowingLabel(length, pageIndex, pageSize, texts)}\n <Select2\n aria-label={texts.pagination.pageSize}\n className=\"ml-4 !w-20\"\n onChange={value => {\n setPageIndex(0);\n setPageSize(Number(value));\n }}\n value={pageSize}>\n {pageSizes.map(size => (\n <Select2.Option key={size} value={size}>\n {String(size)}\n </Select2.Option>\n ))}\n </Select2>\n </span>\n )}\n {showPageControls && (\n <nav aria-label={texts.pagination.label}>\n <Inline spacing={8}>\n <LegacyIconButton\n appearance=\"default\"\n disabled={!canPreviousPage}\n icon=\"arrow-start\"\n onClick={() => setPageIndex(0)}\n aria-label={\n showShortcutTexts\n ? texts.pagination.actions.firstPageWithShortcut\n : texts.pagination.actions.firstPage\n }\n tooltip={\n showShortcutTexts\n ? texts.pagination.actions.firstPageWithShortcut\n : texts.pagination.actions.firstPage\n }\n />\n <LegacyIconButton\n appearance=\"default\"\n disabled={!canPreviousPage}\n icon=\"arrow-left\"\n onClick={() => setPageIndex(pageIndex - 1)}\n aria-label={\n showShortcutTexts\n ? texts.pagination.actions.previousPageWithShortcut\n : texts.pagination.actions.previousPage\n }\n tooltip={\n showShortcutTexts\n ? texts.pagination.actions.previousPageWithShortcut\n : texts.pagination.actions.previousPage\n }\n />\n {showPageNumbers && pageCount > 0 && (\n <PageNumbers pageCount={pageCount} currentPageIndex={pageIndex} onClick={setPageIndex} />\n )}\n <LegacyIconButton\n appearance=\"default\"\n disabled={!canNextPage}\n icon=\"arrow-right\"\n onClick={() => setPageIndex(pageIndex + 1)}\n aria-label={\n showShortcutTexts\n ? texts.pagination.actions.nextPageWithShortcut\n : texts.pagination.actions.nextPage\n }\n tooltip={\n showShortcutTexts\n ? texts.pagination.actions.nextPageWithShortcut\n : texts.pagination.actions.nextPage\n }\n />\n <LegacyIconButton\n appearance=\"default\"\n disabled={!canNextPage}\n icon=\"arrow-end\"\n onClick={() => setPageIndex(pageCount - 1)}\n aria-label={\n showShortcutTexts\n ? texts.pagination.actions.lastPageWithShortcut\n : texts.pagination.actions.lastPage\n }\n tooltip={\n showShortcutTexts\n ? texts.pagination.actions.lastPageWithShortcut\n : texts.pagination.actions.lastPage\n }\n />\n </Inline>\n </nav>\n )}\n </div>\n );\n});\n"],"names":["Pagination"],"mappings":";;;;;;;;AAmGA,MAAM,kBAAkB,CAAC,QAAgB,WAAmB,UAAkB,UAAqC;AACzG,QAAA,eAAe,YAAY,WAAW;AACtC,QAAA,gBAAgB,YAAY,KAAK;AAEhC,SAAA,MAAM,WAAW,mBACnB,QAAQ,OAAO,WAAW,IAAI,MAAM,OAAO,YAAY,CAAC,EACxD,QAAQ,OAAO,OAAO,eAAe,SAAS,SAAS,YAAY,CAAC,EACpE,QAAQ,WAAW,OAAO,MAAM,CAAC;AAC1C;AAEO,MAAM,aAAa,MAAM,WAAW,SAASA,YAAW,OAAwB,KAAgC;AAC7G,QAAA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|
|
@@ -8,7 +8,7 @@ const Popover = require("../../Popover/Popover.cjs");
|
|
|
8
8
|
const Icon = require("../../Icon/Icon.cjs");
|
|
9
9
|
const Context = require("./Context.cjs");
|
|
10
10
|
const Field = require("../../Field/Field.cjs");
|
|
11
|
-
const
|
|
11
|
+
const Inline = require("../../Inline/Inline.cjs");
|
|
12
12
|
const Localization = require("../../Provider/Localization.cjs");
|
|
13
13
|
const tailwind = require("../../../utils/tailwind.cjs");
|
|
14
14
|
const reactAriaComponents = require("react-aria-components");
|
|
@@ -112,7 +112,7 @@ const EditPopover = (props) => {
|
|
|
112
112
|
onChangeColor: setColor,
|
|
113
113
|
onKeyDown: preventKeyDownPropagation
|
|
114
114
|
}
|
|
115
|
-
)) : null, /* @__PURE__ */ React.createElement(
|
|
115
|
+
)) : null, /* @__PURE__ */ React.createElement(Inline.Inline, { spacing: 4, noWrap: true }, /* @__PURE__ */ React.createElement(Button.LegacyButton, { onClick: close }, texts.select2.cancel), /* @__PURE__ */ React.createElement(
|
|
116
116
|
Button.LegacyButton,
|
|
117
117
|
{
|
|
118
118
|
appearance: "primary",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Edit.cjs","sources":["../../../../src/components/Select2/components/Edit.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'clsx';\nimport { LegacyButton } from '../../LegacyComponents/Button/Button';\nimport { Input } from '../../Input/Input';\nimport { Popover, PopoverProps } from '../../Popover/Popover';\nimport { Icon } from '../../Icon/Icon';\nimport { Select2OptionValue } from '../types';\nimport { useSelect2Context } from './Context';\nimport { Field } from '../../Field/Field';\nimport { Group } from '../../Group/Group';\nimport { useLocalization } from '../../Provider/Localization';\nimport { Color } from '../../../types';\nimport { AVAILABLE_COLORS, getSubtleColorShadeClasses } from '../../../utils/tailwind';\nimport { RadioGroup as RadioGroupPrimitive, Radio as RadioPrimitive } from 'react-aria-components';\n\nexport type EditPopoverProps = PopoverProps & {\n color?: Color;\n text: string;\n value: Select2OptionValue;\n};\n\nexport const EditPopover = (props: EditPopoverProps) => {\n const { color: initialColor, text: initialName, value, ...popoverProps } = props;\n const ref = React.useRef<HTMLInputElement>(null);\n const { onDelete, onEdit, searchRef, ref: selectRef } = useSelect2Context();\n const { texts } = useLocalization();\n const [name, setName] = React.useState(initialName);\n const [color, setColor] = React.useState(initialColor);\n const [validationError, setValidationError] = React.useState<Error | undefined>();\n\n const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n setName(event.target.value);\n setValidationError(undefined);\n };\n\n const handleInputKeyDown = (close: () => void) => async (event: React.KeyboardEvent<HTMLInputElement>) => {\n event.stopPropagation();\n\n if (event.key === 'Escape') {\n close();\n } else if (event.key === 'Enter') {\n const fn = handleSave(close);\n await fn(event);\n }\n };\n\n const handleDelete = (close: () => void) => async (event: React.MouseEvent<HTMLButtonElement>) => {\n event.stopPropagation();\n close();\n\n if (onDelete) {\n await onDelete(value);\n }\n };\n\n const handleSave =\n (close: () => void) => async (event: React.MouseEvent<HTMLButtonElement> | React.KeyboardEvent<HTMLElement>) => {\n if (onEdit && (name !== initialName || color !== initialColor)) {\n try {\n await onEdit(value, name, color);\n close();\n } catch (error) {\n event.preventDefault();\n event.stopPropagation();\n setValidationError(error as Error);\n ref.current?.focus();\n }\n } else {\n close();\n }\n };\n\n const handleCloseAutoFocus = () => {\n setName(initialName);\n setColor(initialColor);\n setValidationError(undefined);\n\n if (searchRef?.current) {\n searchRef.current?.focus();\n } else {\n selectRef.current?.focus();\n }\n };\n\n const preventKeyDownPropagation = (event: React.KeyboardEvent) => {\n // Need to allow 'Escape', 'Tab', 'Shift + Tab' to support default focus and close behaviour of Radix Popover.\n if (event.key === 'Escape' || event.key === 'Tab' || (event.key === 'Tab' && event.shiftKey)) {\n return;\n }\n event.stopPropagation();\n };\n\n const popoverContentKeyDown = (event: React.KeyboardEvent) => {\n // Need to stop propagation of 'Tab', 'Shift + Tab' keys out of Popover content,\n // to avoid 'Tab' key execution on Option component and closing the dropdown.\n if (event.key === 'Tab' || (event.key === 'Tab' && event.shiftKey)) {\n event.stopPropagation();\n }\n };\n\n return (\n <Popover {...popoverProps} modal={false}>\n <Popover.Content\n finalFocus={handleCloseAutoFocus}\n onClick={event => event.stopPropagation()}\n onKeyDown={popoverContentKeyDown}\n placement=\"right\"\n tabIndex={-1}\n className=\"focus:!shadow-none\">\n {({ close }) => (\n <>\n <div className=\"flex w-32 flex-col space-y-2\" data-taco=\"edit-popover\">\n {onEdit ? (\n <>\n <Field\n className={cn('!min-h-fit', { '!pb-0': !validationError })}\n invalid={!!validationError}\n message={validationError?.message}>\n <Input\n invalid={!!validationError}\n onChange={handleInputChange}\n onKeyDown={handleInputKeyDown(close)}\n ref={ref}\n value={name}\n />\n </Field>\n {initialColor ? (\n <>\n <h5>Colours</h5>\n <Colours\n color={color}\n onChangeColor={setColor}\n onKeyDown={preventKeyDownPropagation}\n />\n </>\n ) : null}\n <Group>\n <LegacyButton onClick={close}>{texts.select2.cancel}</LegacyButton>\n <LegacyButton\n appearance=\"primary\"\n onClick={handleSave(close) as (event: React.MouseEvent<HTMLButtonElement>) => void}>\n {texts.select2.save}\n </LegacyButton>\n </Group>\n </>\n ) : null}\n {onEdit && onDelete ? <hr /> : null}\n {onDelete ? (\n <button\n className=\"flex items-center justify-start gap-1 hover:text-gray-700\"\n onClick={handleDelete(close)}\n onKeyDown={preventKeyDownPropagation}>\n <Icon className=\"!h-5 !w-5\" name=\"delete-permanently\" /> {texts.select2.delete}\n </button>\n ) : null}\n </div>\n </>\n )}\n </Popover.Content>\n </Popover>\n );\n};\n\ntype Props = {\n color: string | undefined;\n onChangeColor: React.Dispatch<React.SetStateAction<Color | undefined>>;\n onKeyDown: (event: React.KeyboardEvent) => void;\n};\n\nconst Colours = (props: Props) => {\n const { color, onChangeColor, onKeyDown } = props;\n const { texts } = useLocalization();\n\n return (\n <RadioGroupPrimitive\n aria-label={texts.select2.chooseColor}\n className=\"grid grid-cols-4 gap-2 focus:outline-none\"\n onChange={(value: string) => onChangeColor(value as Color)}\n value={color}>\n {AVAILABLE_COLORS.map((availableColor: Color) => (\n <RadioPrimitive\n key={availableColor}\n aria-label={color}\n onKeyDown={onKeyDown}\n value={availableColor}\n data-taco={`${availableColor}-radio`}>\n {state => (\n <div\n className={cn(\n 'flex h-6 w-6 cursor-pointer items-center justify-center rounded',\n getSubtleColorShadeClasses(availableColor as Color),\n state.isFocusVisible && 'ring-2 ring-blue-500'\n )}>\n {state.isSelected && <Icon name=\"tick\" className=\"!h-5 !w-5\" />}\n </div>\n )}\n </RadioPrimitive>\n ))}\n </RadioGroupPrimitive>\n );\n};\n"],"names":["useSelect2Context","useLocalization","Popover","Field","Input","Group","LegacyButton","Icon","RadioGroupPrimitive","AVAILABLE_COLORS","RadioPrimitive","getSubtleColorShadeClasses"],"mappings":";;;;;;;;;;;;;;AAqBa,MAAA,cAAc,CAAC,UAA4B;AAC9C,QAAA,EAAE,OAAO,cAAc,MAAM,aAAa,OAAO,GAAG,iBAAiB;AACrE,QAAA,MAAM,MAAM,OAAyB,IAAI;AAC/C,QAAM,EAAE,UAAU,QAAQ,WAAW,KAAK,cAAcA,0BAAkB;AACpE,QAAA,EAAE,MAAM,IAAIC,6BAAgB;AAClC,QAAM,CAAC,MAAM,OAAO,IAAI,MAAM,SAAS,WAAW;AAClD,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAS,YAAY;AACrD,QAAM,CAAC,iBAAiB,kBAAkB,IAAI,MAAM,SAA4B;AAE1E,QAAA,oBAAoB,CAAC,UAA+C;AAC9D,YAAA,MAAM,OAAO,KAAK;AAC1B,uBAAmB,MAAS;AAAA,EAChC;AAEA,QAAM,qBAAqB,CAAC,UAAsB,OAAO,UAAiD;AACtG,UAAM,gBAAgB;AAElB,QAAA,MAAM,QAAQ,UAAU;AAClB,YAAA;AAAA,IAAA,WACC,MAAM,QAAQ,SAAS;AACxB,YAAA,KAAK,WAAW,KAAK;AAC3B,YAAM,GAAG,KAAK;AAAA,IAAA;AAAA,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,QAAQ;AAAA,IAC5E,IACA,IACR,CACJ;AAAA,EAAA,CAGZ;AAER;AAQA,MAAM,UAAU,CAAC,UAAiB;AAC9B,QAAM,EAAE,OAAO,eAAe,UAAc,IAAA;AACtC,QAAA,EAAE,MAAM,IAAIN,6BAAgB;AAG9B,SAAA,sBAAA;AAAA,IAACO,oBAAA;AAAA,IAAA;AAAA,MACG,cAAY,MAAM,QAAQ;AAAA,MAC1B,WAAU;AAAA,MACV,UAAU,CAAC,UAAkB,cAAc,KAAc;AAAA,MACzD,OAAO;AAAA,IAAA;AAAA,IACNC,SAAAA,iBAAiB,IAAI,CAAC,mBACnB,sBAAA;AAAA,MAACC,oBAAA;AAAA,MAAA;AAAA,QACG,KAAK;AAAA,QACL,cAAY;AAAA,QACZ;AAAA,QACA,OAAO;AAAA,QACP,aAAW,GAAG,cAAc;AAAA,MAAA;AAAA,MAC3B,CACG,UAAA,sBAAA;AAAA,QAAC;AAAA,QAAA;AAAA,UACG,WAAW;AAAA,YACP;AAAA,YACAC,SAAAA,2BAA2B,cAAuB;AAAA,YAClD,MAAM,kBAAkB;AAAA,UAAA;AAAA,QAC5B;AAAA,QACC,MAAM,cAAc,sBAAA,cAACJ,KAAAA,QAAK,MAAK,QAAO,WAAU,YAAY,CAAA;AAAA,MAAA;AAAA,IAI5E,CAAA;AAAA,EACL;AAER;;"}
|
|
1
|
+
{"version":3,"file":"Edit.cjs","sources":["../../../../src/components/Select2/components/Edit.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'clsx';\nimport { LegacyButton } from '../../LegacyComponents/Button/Button';\nimport { Input } from '../../Input/Input';\nimport { Popover, PopoverProps } from '../../Popover/Popover';\nimport { Icon } from '../../Icon/Icon';\nimport { Select2OptionValue } from '../types';\nimport { useSelect2Context } from './Context';\nimport { Field } from '../../Field/Field';\nimport { Inline } from '../../Inline/Inline';\nimport { useLocalization } from '../../Provider/Localization';\nimport { Color } from '../../../types';\nimport { AVAILABLE_COLORS, getSubtleColorShadeClasses } from '../../../utils/tailwind';\nimport { RadioGroup as RadioGroupPrimitive, Radio as RadioPrimitive } from 'react-aria-components';\n\nexport type EditPopoverProps = PopoverProps & {\n color?: Color;\n text: string;\n value: Select2OptionValue;\n};\n\nexport const EditPopover = (props: EditPopoverProps) => {\n const { color: initialColor, text: initialName, value, ...popoverProps } = props;\n const ref = React.useRef<HTMLInputElement>(null);\n const { onDelete, onEdit, searchRef, ref: selectRef } = useSelect2Context();\n const { texts } = useLocalization();\n const [name, setName] = React.useState(initialName);\n const [color, setColor] = React.useState(initialColor);\n const [validationError, setValidationError] = React.useState<Error | undefined>();\n\n const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n setName(event.target.value);\n setValidationError(undefined);\n };\n\n const handleInputKeyDown = (close: () => void) => async (event: React.KeyboardEvent<HTMLInputElement>) => {\n event.stopPropagation();\n\n if (event.key === 'Escape') {\n close();\n } else if (event.key === 'Enter') {\n const fn = handleSave(close);\n await fn(event);\n }\n };\n\n const handleDelete = (close: () => void) => async (event: React.MouseEvent<HTMLButtonElement>) => {\n event.stopPropagation();\n close();\n\n if (onDelete) {\n await onDelete(value);\n }\n };\n\n const handleSave =\n (close: () => void) => async (event: React.MouseEvent<HTMLButtonElement> | React.KeyboardEvent<HTMLElement>) => {\n if (onEdit && (name !== initialName || color !== initialColor)) {\n try {\n await onEdit(value, name, color);\n close();\n } catch (error) {\n event.preventDefault();\n event.stopPropagation();\n setValidationError(error as Error);\n ref.current?.focus();\n }\n } else {\n close();\n }\n };\n\n const handleCloseAutoFocus = () => {\n setName(initialName);\n setColor(initialColor);\n setValidationError(undefined);\n\n if (searchRef?.current) {\n searchRef.current?.focus();\n } else {\n selectRef.current?.focus();\n }\n };\n\n const preventKeyDownPropagation = (event: React.KeyboardEvent) => {\n // Need to allow 'Escape', 'Tab', 'Shift + Tab' to support default focus and close behaviour of Radix Popover.\n if (event.key === 'Escape' || event.key === 'Tab' || (event.key === 'Tab' && event.shiftKey)) {\n return;\n }\n event.stopPropagation();\n };\n\n const popoverContentKeyDown = (event: React.KeyboardEvent) => {\n // Need to stop propagation of 'Tab', 'Shift + Tab' keys out of Popover content,\n // to avoid 'Tab' key execution on Option component and closing the dropdown.\n if (event.key === 'Tab' || (event.key === 'Tab' && event.shiftKey)) {\n event.stopPropagation();\n }\n };\n\n return (\n <Popover {...popoverProps} modal={false}>\n <Popover.Content\n finalFocus={handleCloseAutoFocus}\n onClick={event => event.stopPropagation()}\n onKeyDown={popoverContentKeyDown}\n placement=\"right\"\n tabIndex={-1}\n className=\"focus:!shadow-none\">\n {({ close }) => (\n <>\n <div className=\"flex w-32 flex-col space-y-2\" data-taco=\"edit-popover\">\n {onEdit ? (\n <>\n <Field\n className={cn('!min-h-fit', { '!pb-0': !validationError })}\n invalid={!!validationError}\n message={validationError?.message}>\n <Input\n invalid={!!validationError}\n onChange={handleInputChange}\n onKeyDown={handleInputKeyDown(close)}\n ref={ref}\n value={name}\n />\n </Field>\n {initialColor ? (\n <>\n <h5>Colours</h5>\n <Colours\n color={color}\n onChangeColor={setColor}\n onKeyDown={preventKeyDownPropagation}\n />\n </>\n ) : null}\n <Inline spacing={4} noWrap>\n <LegacyButton onClick={close}>{texts.select2.cancel}</LegacyButton>\n <LegacyButton\n appearance=\"primary\"\n onClick={handleSave(close) as (event: React.MouseEvent<HTMLButtonElement>) => void}>\n {texts.select2.save}\n </LegacyButton>\n </Inline>\n </>\n ) : null}\n {onEdit && onDelete ? <hr /> : null}\n {onDelete ? (\n <button\n className=\"flex items-center justify-start gap-1 hover:text-gray-700\"\n onClick={handleDelete(close)}\n onKeyDown={preventKeyDownPropagation}>\n <Icon className=\"!h-5 !w-5\" name=\"delete-permanently\" /> {texts.select2.delete}\n </button>\n ) : null}\n </div>\n </>\n )}\n </Popover.Content>\n </Popover>\n );\n};\n\ntype Props = {\n color: string | undefined;\n onChangeColor: React.Dispatch<React.SetStateAction<Color | undefined>>;\n onKeyDown: (event: React.KeyboardEvent) => void;\n};\n\nconst Colours = (props: Props) => {\n const { color, onChangeColor, onKeyDown } = props;\n const { texts } = useLocalization();\n\n return (\n <RadioGroupPrimitive\n aria-label={texts.select2.chooseColor}\n className=\"grid grid-cols-4 gap-2 focus:outline-none\"\n onChange={(value: string) => onChangeColor(value as Color)}\n value={color}>\n {AVAILABLE_COLORS.map((availableColor: Color) => (\n <RadioPrimitive\n key={availableColor}\n aria-label={color}\n onKeyDown={onKeyDown}\n value={availableColor}\n data-taco={`${availableColor}-radio`}>\n {state => (\n <div\n className={cn(\n 'flex h-6 w-6 cursor-pointer items-center justify-center rounded',\n getSubtleColorShadeClasses(availableColor as Color),\n state.isFocusVisible && 'ring-2 ring-blue-500'\n )}>\n {state.isSelected && <Icon name=\"tick\" className=\"!h-5 !w-5\" />}\n </div>\n )}\n </RadioPrimitive>\n ))}\n </RadioGroupPrimitive>\n );\n};\n"],"names":["useSelect2Context","useLocalization","Popover","Field","Input","Inline","LegacyButton","Icon","RadioGroupPrimitive","AVAILABLE_COLORS","RadioPrimitive","getSubtleColorShadeClasses"],"mappings":";;;;;;;;;;;;;;AAqBa,MAAA,cAAc,CAAC,UAA4B;AAC9C,QAAA,EAAE,OAAO,cAAc,MAAM,aAAa,OAAO,GAAG,iBAAiB;AACrE,QAAA,MAAM,MAAM,OAAyB,IAAI;AAC/C,QAAM,EAAE,UAAU,QAAQ,WAAW,KAAK,cAAcA,0BAAkB;AACpE,QAAA,EAAE,MAAM,IAAIC,6BAAgB;AAClC,QAAM,CAAC,MAAM,OAAO,IAAI,MAAM,SAAS,WAAW;AAClD,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAS,YAAY;AACrD,QAAM,CAAC,iBAAiB,kBAAkB,IAAI,MAAM,SAA4B;AAE1E,QAAA,oBAAoB,CAAC,UAA+C;AAC9D,YAAA,MAAM,OAAO,KAAK;AAC1B,uBAAmB,MAAS;AAAA,EAChC;AAEA,QAAM,qBAAqB,CAAC,UAAsB,OAAO,UAAiD;AACtG,UAAM,gBAAgB;AAEl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;AAAA,MAAA;AAAA,QACG,WAAU;AAAA,QACV,SAAS,aAAa,KAAK;AAAA,QAC3B,WAAW;AAAA,MAAA;AAAA,MACV,sBAAA,cAAAC,WAAA,EAAK,WAAU,aAAY,MAAK,sBAAqB;AAAA,MAAE;AAAA,MAAE,MAAM,QAAQ;AAAA,IAC5E,IACA,IACR,CACJ;AAAA,EAAA,CAGZ;AAER;AAQA,MAAM,UAAU,CAAC,UAAiB;AAC9B,QAAM,EAAE,OAAO,eAAe,UAAc,IAAA;AACtC,QAAA,EAAE,MAAM,IAAIN,6BAAgB;AAG9B,SAAA,sBAAA;AAAA,IAACO,oBAAA;AAAA,IAAA;AAAA,MACG,cAAY,MAAM,QAAQ;AAAA,MAC1B,WAAU;AAAA,MACV,UAAU,CAAC,UAAkB,cAAc,KAAc;AAAA,MACzD,OAAO;AAAA,IAAA;AAAA,IACNC,SAAAA,iBAAiB,IAAI,CAAC,mBACnB,sBAAA;AAAA,MAACC,oBAAA;AAAA,MAAA;AAAA,QACG,KAAK;AAAA,QACL,cAAY;AAAA,QACZ;AAAA,QACA,OAAO;AAAA,QACP,aAAW,GAAG,cAAc;AAAA,MAAA;AAAA,MAC3B,CACG,UAAA,sBAAA;AAAA,QAAC;AAAA,QAAA;AAAA,UACG,WAAW;AAAA,YACP;AAAA,YACAC,SAAAA,2BAA2B,cAAuB;AAAA,YAClD,MAAM,kBAAkB;AAAA,UAAA;AAAA,QAC5B;AAAA,QACC,MAAM,cAAc,sBAAA,cAACJ,KAAAA,QAAK,MAAK,QAAO,WAAU,YAAY,CAAA;AAAA,MAAA;AAAA,IAI5E,CAAA;AAAA,EACL;AAER;;"}
|
|
@@ -6,7 +6,7 @@ import { Popover } from "../../Popover/Popover.js";
|
|
|
6
6
|
import { Icon } from "../../Icon/Icon.js";
|
|
7
7
|
import { useSelect2Context } from "./Context.js";
|
|
8
8
|
import { Field } from "../../Field/Field.js";
|
|
9
|
-
import {
|
|
9
|
+
import { Inline } from "../../Inline/Inline.js";
|
|
10
10
|
import { useLocalization } from "../../Provider/Localization.js";
|
|
11
11
|
import { AVAILABLE_COLORS, getSubtleColorShadeClasses } from "../../../utils/tailwind.js";
|
|
12
12
|
import { RadioGroup, Radio } from "react-aria-components";
|
|
@@ -110,7 +110,7 @@ const EditPopover = (props) => {
|
|
|
110
110
|
onChangeColor: setColor,
|
|
111
111
|
onKeyDown: preventKeyDownPropagation
|
|
112
112
|
}
|
|
113
|
-
)) : null, /* @__PURE__ */ React__default.createElement(
|
|
113
|
+
)) : null, /* @__PURE__ */ React__default.createElement(Inline, { spacing: 4, noWrap: true }, /* @__PURE__ */ React__default.createElement(LegacyButton, { onClick: close }, texts.select2.cancel), /* @__PURE__ */ React__default.createElement(
|
|
114
114
|
LegacyButton,
|
|
115
115
|
{
|
|
116
116
|
appearance: "primary",
|