@neo4j-ndl/react 4.5.4 → 4.5.6
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/lib/cjs/accordion/Accordion.js +3 -3
- package/lib/cjs/accordion/Accordion.js.map +1 -1
- package/lib/cjs/dialog/Dialog.js +58 -4
- package/lib/cjs/dialog/Dialog.js.map +1 -1
- package/lib/cjs/dialog/dialog-types.js.map +1 -1
- package/lib/cjs/spotlight/Spotlight.js +83 -8
- package/lib/cjs/spotlight/Spotlight.js.map +1 -1
- package/lib/cjs/spotlight/stories/spotlight-in-dialog.story.js +1 -1
- package/lib/cjs/spotlight/stories/spotlight-in-dialog.story.js.map +1 -1
- package/lib/esm/accordion/Accordion.js +3 -3
- package/lib/esm/accordion/Accordion.js.map +1 -1
- package/lib/esm/dialog/Dialog.js +25 -4
- package/lib/esm/dialog/Dialog.js.map +1 -1
- package/lib/esm/dialog/dialog-types.js.map +1 -1
- package/lib/esm/spotlight/Spotlight.js +51 -9
- package/lib/esm/spotlight/Spotlight.js.map +1 -1
- package/lib/esm/spotlight/stories/spotlight-in-dialog.story.js +1 -1
- package/lib/esm/spotlight/stories/spotlight-in-dialog.story.js.map +1 -1
- package/lib/types/accordion/Accordion.d.ts.map +1 -1
- package/lib/types/dialog/Dialog.d.ts.map +1 -1
- package/lib/types/dialog/dialog-types.d.ts +2 -0
- package/lib/types/dialog/dialog-types.d.ts.map +1 -1
- package/lib/types/spotlight/Spotlight.d.ts +1 -1
- package/lib/types/spotlight/Spotlight.d.ts.map +1 -1
- package/lib/types/spotlight/stories/spotlight-in-dialog.story.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -101,8 +101,8 @@ const AccordionComponent = function AccordionComponent(_a) {
|
|
|
101
101
|
}
|
|
102
102
|
};
|
|
103
103
|
const classes = (0, classnames_1.default)('ndl-accordion', className);
|
|
104
|
-
|
|
105
|
-
const { expandedItemId } =
|
|
104
|
+
// Destructure and omit keys from DOM spread
|
|
105
|
+
const _b = restProps, { expandedItemIds, expandedItemId } = _b, restAccordionProps = __rest(_b, ["expandedItemIds", "expandedItemId"]);
|
|
106
106
|
const contextValue = isMultiple
|
|
107
107
|
? {
|
|
108
108
|
expandedItemIds,
|
|
@@ -114,7 +114,7 @@ const AccordionComponent = function AccordionComponent(_a) {
|
|
|
114
114
|
isMultiple,
|
|
115
115
|
onChange,
|
|
116
116
|
};
|
|
117
|
-
return ((0, jsx_runtime_1.jsx)(Component, Object.assign({ className: classes, style: style, ref: accordionRef, onKeyDown: handleKeyDown, role: "presentation" },
|
|
117
|
+
return ((0, jsx_runtime_1.jsx)(Component, Object.assign({ className: classes, style: style, ref: accordionRef, onKeyDown: handleKeyDown, role: "presentation" }, restAccordionProps, htmlAttributes, { children: (0, jsx_runtime_1.jsx)(accordion_context_1.AccordionContext.Provider, { value: contextValue, children: children }) })));
|
|
118
118
|
};
|
|
119
119
|
const createItemId = (type, id) => `ndl-accordionitem${type}id-${id}`;
|
|
120
120
|
const BaseAccordionItem = ({ itemId, children, title, className = '', arrowPosition = 'leading', isDisabled = false, onExpandedChange, htmlAttributes, style, as, titleTypographyVariant = 'subheading-medium', hasDivider = true, trailingContent, }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Accordion.js","sourceRoot":"","sources":["../../../src/accordion/Accordion.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,4DAAoC;AAEpC,iCAAiE;AAGjE,4CAA6C;AAC7C,wCAAqC;AACrC,oCAAkD;AAClD,8CAA2C;AAC3C,2DAA4E;AAY5E,IAAK,iBAGJ;AAHD,WAAK,iBAAiB;IACpB,iDAA4B,CAAA;IAC5B,8FAAyE,CAAA;AAC3E,CAAC,EAHI,iBAAiB,KAAjB,iBAAiB,QAGrB;AAED,MAAM,gBAAgB,GAAG,CACvB,gBAAyB,EACzB,QAAgB,EAChB,YAA6B,MAAM,EACnB,EAAE;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CAAC;AAClE,CAAC,CAAC;AACF,aAAa,CAAC,WAAW,GAAG,gBAAgB,CAAC;AAO7C,MAAM,SAAS,GAAG,CAGhB,EAG6C,EAAE,EAAE;QAHjD,EACA,SAAS,OAEoC,EAD1C,SAAS,cAFZ,aAGD,CADa;IAEZ,MAAM,OAAO,GAAG,IAAA,oBAAU,EAAC,0BAA0B,EAAE,SAAS,CAAC,CAAC;IAElE,OAAO,CACL,uBAAC,iBAAiB,oBAAK,SAAS,IAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,IAAI,CAC5E,CAAC;AACJ,CAAC,CAAC;AAEF,SAAS,CAAC,WAAW,GAAG,qBAAqB,CAAC;AAE9C,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE;IAClD,SAAS,EAAE,SAAS;IACpB,IAAI,EAAE,aAAa;CACpB,CAAC,CAAC;AAEM,8BAAS","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport classNames from 'classnames';\nimport type React from 'react';\nimport { useCallback, useImperativeHandle, useRef } from 'react';\n\nimport { type PolymorphicCommonProps } from '../_common/types';\nimport { findUntil } from '../_common/utils';\nimport { Divider } from '../divider';\nimport { ChevronDownIconOutline } from '../icons';\nimport { Typography } from '../typography';\nimport { AccordionContext, useAccordionContext } from './accordion-context';\nimport {\n type AccordionIsMultiple,\n type AccordionIsNotMultiple,\n type AccordionItemId,\n type AccordionItemProps,\n type AccordionProps,\n type ClassicItemProps,\n type IsMultiple,\n type IsNotMultiple,\n} from './accordion-types';\n\nenum AccordionSelector {\n Item = '.ndl-accordion-item',\n ItemNotDisabled = '.ndl-accordion-item:not(.ndl-accordion-item-disabled)',\n}\n\nconst getAccordionItem = (\n accordionElement: Element,\n selector: string,\n direction: 'next' | 'prev' = 'next',\n): Element | null => {\n const itemParent = accordionElement.closest(AccordionSelector.Item);\n if (!itemParent) {\n return null;\n }\n\n return findUntil(direction, itemParent, selector);\n};\n\nconst AccordionComponent = function AccordionComponent<\n T extends AccordionItemId,\n U extends React.ElementType = 'div',\n>({\n children,\n as,\n isMultiple,\n onChange,\n className,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: PolymorphicCommonProps<U, AccordionProps<T>>) {\n const accordionRef = useRef<U>(null);\n\n useImperativeHandle(ref, () => accordionRef.current!);\n\n const Component: React.ElementType = as || 'div';\n\n // The following function includes code needed to be\n // able to navigate with the arrow keys (not tab).\n const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n const accordionElement = accordionRef.current;\n if (!accordionElement) {\n return;\n }\n const activeElement = document.activeElement as HTMLElement;\n if (event.key === 'ArrowDown') {\n event.preventDefault();\n event.stopPropagation();\n const newFocusedElement = getAccordionItem(\n activeElement,\n AccordionSelector.ItemNotDisabled,\n 'next',\n );\n const newHeader = newFocusedElement?.firstElementChild;\n\n if (newHeader && newHeader instanceof HTMLElement) {\n focusAccordionItem(newHeader as HTMLElement);\n }\n } else if (event.key === 'ArrowUp') {\n event.preventDefault();\n event.stopPropagation();\n const newFocusedElement = getAccordionItem(\n activeElement,\n AccordionSelector.ItemNotDisabled,\n 'prev',\n );\n const newHeader = newFocusedElement?.firstElementChild;\n\n if (newHeader && newHeader instanceof HTMLElement) {\n focusAccordionItem(newHeader as HTMLElement);\n }\n } else if (event.key === ' ' || event.key === 'Enter') {\n event.preventDefault();\n event.stopPropagation();\n activeElement.click();\n }\n };\n\n const focusAccordionItem = (accordionHtmlElement: HTMLElement) => {\n const accordionButton = accordionHtmlElement\n .getElementsByClassName('ndl-accordion-item-header-button')\n .item(0);\n\n if (accordionButton !== null && accordionButton instanceof HTMLElement) {\n accordionButton.focus();\n }\n };\n\n const classes = classNames('ndl-accordion', className);\n\n const { expandedItemIds } = restProps as AccordionIsMultiple<T>;\n const { expandedItemId } = restProps as AccordionIsNotMultiple<T>;\n\n const contextValue = isMultiple\n ? ({\n expandedItemIds,\n isMultiple,\n onChange,\n } as IsMultiple<T>)\n : ({\n expandedItemId,\n isMultiple,\n onChange,\n } as IsNotMultiple<T>);\n\n return (\n <Component\n className={classes}\n style={style}\n ref={accordionRef}\n onKeyDown={handleKeyDown}\n role=\"presentation\"\n {...restProps}\n {...htmlAttributes}\n >\n <AccordionContext.Provider value={contextValue}>\n {children}\n </AccordionContext.Provider>\n </Component>\n );\n};\n\nconst createItemId = (type: string, id: AccordionItemId) =>\n `ndl-accordionitem${type}id-${id}`;\n\nconst BaseAccordionItem = <\n T extends AccordionItemId,\n U extends React.ElementType = 'div',\n>({\n itemId,\n children,\n title,\n className = '',\n arrowPosition = 'leading',\n isDisabled = false,\n onExpandedChange,\n htmlAttributes,\n style,\n as,\n titleTypographyVariant = 'subheading-medium',\n hasDivider = true,\n trailingContent,\n}: PolymorphicCommonProps<U, AccordionItemProps<T>>) => {\n const contentRef = useRef<HTMLDivElement>(null);\n const innerContentRef = useRef<HTMLDivElement>(null);\n const itemElementId = createItemId('item', itemId);\n const headerElementId = createItemId('header', itemId);\n const buttonElementId = createItemId('button', itemId);\n const panelElementId = createItemId('panel', itemId);\n const Component: React.ElementType = as || 'div';\n\n const context = useAccordionContext();\n const { isMultiple } = context;\n\n const isExpanded = isMultiple\n ? context.expandedItemIds.includes(itemId)\n : context.expandedItemId === itemId;\n\n const handleOnClick = useCallback(() => {\n if (isDisabled) {\n return;\n }\n\n // Custom callback to call.\n if (onExpandedChange !== undefined) {\n onExpandedChange(!isExpanded);\n }\n\n if (isMultiple) {\n const { expandedItemIds, onChange }: IsMultiple<T> = context;\n // Multiple expanded.\n if (isExpanded) {\n // Remove from list.\n const newArray: T[] = expandedItemIds.filter(\n (activeId) => activeId !== itemId,\n );\n onChange(newArray);\n } else if (!isExpanded) {\n // Add to list.\n const newArray = [...expandedItemIds];\n newArray.push(itemId);\n onChange(newArray);\n }\n } else {\n const { onChange }: IsNotMultiple<T> = context;\n // Single expanded.\n if (isExpanded) {\n // Set null.\n onChange(null);\n } else if (!isExpanded) {\n // Set to id.\n onChange(itemId);\n }\n }\n\n // The W3 WAI-ARIA states that focus can only happen on the header not the header button.\n document.activeElement?.parentElement?.focus();\n }, [isExpanded, isMultiple, isDisabled, itemId, onExpandedChange, context]);\n\n const classes = classNames('ndl-accordion-item', className, {\n 'ndl-accordion-item-disabled': isDisabled,\n 'ndl-accordion-item-expanded': isExpanded,\n });\n\n const headerClasses = classNames('ndl-accordion-item-header', {\n 'ndl-accordion-item-header-disabled': isDisabled,\n });\n\n const iconClasses = classNames('ndl-accordion-item-header-icon-wrapper', {\n 'ndl-accordion-item-header-icon-wrapper-leading':\n arrowPosition === 'leading',\n });\n\n const buttonClasses = classNames('ndl-accordion-item-header-button', {\n 'ndl-accordion-item-header-button-disabled': isDisabled,\n });\n\n const titleClasses = classNames('ndl-accordion-item-header-button-title', {\n 'ndl-accordion-item-header-button-title': isDisabled,\n 'ndl-accordion-item-header-button-title-leading':\n arrowPosition === 'leading',\n });\n\n const contentClasses = classNames('ndl-accordion-item-content', {\n 'ndl-accordion-item-content-expanded': isExpanded,\n 'ndl-accordion-item-content-leading': arrowPosition === 'leading',\n });\n\n return (\n <Component\n className={classes}\n style={style}\n id={itemElementId}\n {...htmlAttributes}\n >\n <div className={headerClasses} id={headerElementId}>\n <button\n id={buttonElementId}\n onClick={handleOnClick}\n className={buttonClasses}\n aria-expanded={isExpanded}\n aria-disabled={isDisabled}\n aria-label={title}\n aria-controls={panelElementId}\n disabled={isDisabled}\n >\n <span className={iconClasses}>\n <Typography\n variant={titleTypographyVariant}\n className={titleClasses}\n htmlAttributes={{\n 'aria-level': 2,\n role: 'heading',\n }}\n >\n {title}\n </Typography>\n\n <ChevronDownIconOutline\n className={classNames('ndl-accordion-item-header-icon', {\n '-n-rotate-180': isExpanded,\n })}\n />\n </span>\n </button>\n {trailingContent && (\n <Typography as=\"div\" variant=\"body-medium\">\n {trailingContent}\n </Typography>\n )}\n </div>\n\n <div\n id={panelElementId}\n ref={contentRef}\n className={contentClasses}\n aria-hidden={!isExpanded}\n aria-labelledby={buttonElementId}\n role=\"region\"\n >\n {/* The <div> element has a child <button> element that allows keyboard interaction */}\n {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */}\n <div\n ref={innerContentRef}\n className=\"ndl-accordion-item-content-inner\"\n onKeyDown={(event) => event.stopPropagation()}\n >\n <Typography\n variant=\"body-medium\"\n className=\"n-text-neutral-text-weak\"\n as=\"div\"\n >\n {children}\n </Typography>\n </div>\n </div>\n {hasDivider && <Divider />}\n </Component>\n );\n};\n\nconst AccordionItem = <\n T extends AccordionItemId,\n U extends React.ElementType = 'div',\n>({\n className,\n ...restProps\n}: PolymorphicCommonProps<U, ClassicItemProps<T>>) => {\n const classes = classNames('ndl-accordion-item-classic', className);\n\n return <BaseAccordionItem {...restProps} className={classes} />;\n};\nAccordionItem.displayName = 'Accordion.Item';\n\ntype CleanItemProps<T extends AccordionItemId> = Omit<\n AccordionItemProps<T>,\n 'hasDivider'\n>;\n\nconst CleanItem = <\n T extends AccordionItemId,\n U extends React.ElementType = 'div',\n>({\n className,\n ...restProps\n}: PolymorphicCommonProps<U, CleanItemProps<T>>) => {\n const classes = classNames('ndl-accordion-item-clean', className);\n\n return (\n <BaseAccordionItem {...restProps} className={classes} hasDivider={false} />\n );\n};\n\nCleanItem.displayName = 'Accordion.CleanItem';\n\nconst Accordion = Object.assign(AccordionComponent, {\n CleanItem: CleanItem,\n Item: AccordionItem,\n});\n\nexport { Accordion };\n"]}
|
|
1
|
+
{"version":3,"file":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C,eAAe,EAAE,YAE7C,uBAAC,uBAAU,IACT,OAAO,EAAC,aAAa,EACrB,SAAS,EAAC,0BAA0B,EACpC,EAAE,EAAC,KAAK,YAEP,QAAQ,GACE,GACT,GACF,EACL,UAAU,IAAI,uBAAC,iBAAO,KAAG,KAChB,CACb,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,aAAa,GAAG,CAGpB,EAG+C,EAAE,EAAE;QAHnD,EACA,SAAS,OAEsC,EAD5C,SAAS,cAFZ,aAGD,CADa;IAEZ,MAAM,OAAO,GAAG,IAAA,oBAAU,EAAC,4BAA4B,EAAE,SAAS,CAAC,CAAC;IAEpE,OAAO,uBAAC,iBAAiB,oBAAK,SAAS,IAAE,SAAS,EAAE,OAAO,IAAI,CAAC;AAClE,CAAC,CAAC;AACF,aAAa,CAAC,WAAW,GAAG,gBAAgB,CAAC;AAO7C,MAAM,SAAS,GAAG,CAGhB,EAG6C,EAAE,EAAE;QAHjD,EACA,SAAS,OAEoC,EAD1C,SAAS,cAFZ,aAGD,CADa;IAEZ,MAAM,OAAO,GAAG,IAAA,oBAAU,EAAC,0BAA0B,EAAE,SAAS,CAAC,CAAC;IAElE,OAAO,CACL,uBAAC,iBAAiB,oBAAK,SAAS,IAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,IAAI,CAC5E,CAAC;AACJ,CAAC,CAAC;AAEF,SAAS,CAAC,WAAW,GAAG,qBAAqB,CAAC;AAE9C,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE;IAClD,SAAS,EAAE,SAAS;IACpB,IAAI,EAAE,aAAa;CACpB,CAAC,CAAC;AAEM,8BAAS","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport classNames from 'classnames';\nimport type React from 'react';\nimport { useCallback, useImperativeHandle, useRef } from 'react';\n\nimport { type PolymorphicCommonProps } from '../_common/types';\nimport { findUntil } from '../_common/utils';\nimport { Divider } from '../divider';\nimport { ChevronDownIconOutline } from '../icons';\nimport { Typography } from '../typography';\nimport { AccordionContext, useAccordionContext } from './accordion-context';\nimport {\n type AccordionItemId,\n type AccordionItemProps,\n type AccordionProps,\n type ClassicItemProps,\n type IsMultiple,\n type IsNotMultiple,\n} from './accordion-types';\n\nenum AccordionSelector {\n Item = '.ndl-accordion-item',\n ItemNotDisabled = '.ndl-accordion-item:not(.ndl-accordion-item-disabled)',\n}\n\nconst getAccordionItem = (\n accordionElement: Element,\n selector: string,\n direction: 'next' | 'prev' = 'next',\n): Element | null => {\n const itemParent = accordionElement.closest(AccordionSelector.Item);\n if (!itemParent) {\n return null;\n }\n\n return findUntil(direction, itemParent, selector);\n};\n\nconst AccordionComponent = function AccordionComponent<\n T extends AccordionItemId,\n U extends React.ElementType = 'div',\n>({\n children,\n as,\n isMultiple,\n onChange,\n className,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: PolymorphicCommonProps<U, AccordionProps<T>>) {\n const accordionRef = useRef<U>(null);\n\n useImperativeHandle(ref, () => accordionRef.current!);\n\n const Component: React.ElementType = as || 'div';\n\n // The following function includes code needed to be\n // able to navigate with the arrow keys (not tab).\n const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n const accordionElement = accordionRef.current;\n if (!accordionElement) {\n return;\n }\n const activeElement = document.activeElement as HTMLElement;\n if (event.key === 'ArrowDown') {\n event.preventDefault();\n event.stopPropagation();\n const newFocusedElement = getAccordionItem(\n activeElement,\n AccordionSelector.ItemNotDisabled,\n 'next',\n );\n const newHeader = newFocusedElement?.firstElementChild;\n\n if (newHeader && newHeader instanceof HTMLElement) {\n focusAccordionItem(newHeader as HTMLElement);\n }\n } else if (event.key === 'ArrowUp') {\n event.preventDefault();\n event.stopPropagation();\n const newFocusedElement = getAccordionItem(\n activeElement,\n AccordionSelector.ItemNotDisabled,\n 'prev',\n );\n const newHeader = newFocusedElement?.firstElementChild;\n\n if (newHeader && newHeader instanceof HTMLElement) {\n focusAccordionItem(newHeader as HTMLElement);\n }\n } else if (event.key === ' ' || event.key === 'Enter') {\n event.preventDefault();\n event.stopPropagation();\n activeElement.click();\n }\n };\n\n const focusAccordionItem = (accordionHtmlElement: HTMLElement) => {\n const accordionButton = accordionHtmlElement\n .getElementsByClassName('ndl-accordion-item-header-button')\n .item(0);\n\n if (accordionButton !== null && accordionButton instanceof HTMLElement) {\n accordionButton.focus();\n }\n };\n\n const classes = classNames('ndl-accordion', className);\n\n // Destructure and omit keys from DOM spread\n const { expandedItemIds, expandedItemId, ...restAccordionProps } =\n restProps as Record<string, unknown> as {\n expandedItemIds?: T[];\n expandedItemId?: T | null;\n [key: string]: unknown;\n };\n\n const contextValue = isMultiple\n ? ({\n expandedItemIds,\n isMultiple,\n onChange,\n } as IsMultiple<T>)\n : ({\n expandedItemId,\n isMultiple,\n onChange,\n } as IsNotMultiple<T>);\n\n return (\n <Component\n className={classes}\n style={style}\n ref={accordionRef}\n onKeyDown={handleKeyDown}\n role=\"presentation\"\n {...restAccordionProps}\n {...htmlAttributes}\n >\n <AccordionContext.Provider value={contextValue}>\n {children}\n </AccordionContext.Provider>\n </Component>\n );\n};\n\nconst createItemId = (type: string, id: AccordionItemId) =>\n `ndl-accordionitem${type}id-${id}`;\n\nconst BaseAccordionItem = <\n T extends AccordionItemId,\n U extends React.ElementType = 'div',\n>({\n itemId,\n children,\n title,\n className = '',\n arrowPosition = 'leading',\n isDisabled = false,\n onExpandedChange,\n htmlAttributes,\n style,\n as,\n titleTypographyVariant = 'subheading-medium',\n hasDivider = true,\n trailingContent,\n}: PolymorphicCommonProps<U, AccordionItemProps<T>>) => {\n const contentRef = useRef<HTMLDivElement>(null);\n const innerContentRef = useRef<HTMLDivElement>(null);\n const itemElementId = createItemId('item', itemId);\n const headerElementId = createItemId('header', itemId);\n const buttonElementId = createItemId('button', itemId);\n const panelElementId = createItemId('panel', itemId);\n const Component: React.ElementType = as || 'div';\n\n const context = useAccordionContext();\n const { isMultiple } = context;\n\n const isExpanded = isMultiple\n ? context.expandedItemIds.includes(itemId)\n : context.expandedItemId === itemId;\n\n const handleOnClick = useCallback(() => {\n if (isDisabled) {\n return;\n }\n\n // Custom callback to call.\n if (onExpandedChange !== undefined) {\n onExpandedChange(!isExpanded);\n }\n\n if (isMultiple) {\n const { expandedItemIds, onChange }: IsMultiple<T> = context;\n // Multiple expanded.\n if (isExpanded) {\n // Remove from list.\n const newArray: T[] = expandedItemIds.filter(\n (activeId) => activeId !== itemId,\n );\n onChange(newArray);\n } else if (!isExpanded) {\n // Add to list.\n const newArray = [...expandedItemIds];\n newArray.push(itemId);\n onChange(newArray);\n }\n } else {\n const { onChange }: IsNotMultiple<T> = context;\n // Single expanded.\n if (isExpanded) {\n // Set null.\n onChange(null);\n } else if (!isExpanded) {\n // Set to id.\n onChange(itemId);\n }\n }\n\n // The W3 WAI-ARIA states that focus can only happen on the header not the header button.\n document.activeElement?.parentElement?.focus();\n }, [isExpanded, isMultiple, isDisabled, itemId, onExpandedChange, context]);\n\n const classes = classNames('ndl-accordion-item', className, {\n 'ndl-accordion-item-disabled': isDisabled,\n 'ndl-accordion-item-expanded': isExpanded,\n });\n\n const headerClasses = classNames('ndl-accordion-item-header', {\n 'ndl-accordion-item-header-disabled': isDisabled,\n });\n\n const iconClasses = classNames('ndl-accordion-item-header-icon-wrapper', {\n 'ndl-accordion-item-header-icon-wrapper-leading':\n arrowPosition === 'leading',\n });\n\n const buttonClasses = classNames('ndl-accordion-item-header-button', {\n 'ndl-accordion-item-header-button-disabled': isDisabled,\n });\n\n const titleClasses = classNames('ndl-accordion-item-header-button-title', {\n 'ndl-accordion-item-header-button-title': isDisabled,\n 'ndl-accordion-item-header-button-title-leading':\n arrowPosition === 'leading',\n });\n\n const contentClasses = classNames('ndl-accordion-item-content', {\n 'ndl-accordion-item-content-expanded': isExpanded,\n 'ndl-accordion-item-content-leading': arrowPosition === 'leading',\n });\n\n return (\n <Component\n className={classes}\n style={style}\n id={itemElementId}\n {...htmlAttributes}\n >\n <div className={headerClasses} id={headerElementId}>\n <button\n id={buttonElementId}\n onClick={handleOnClick}\n className={buttonClasses}\n aria-expanded={isExpanded}\n aria-disabled={isDisabled}\n aria-label={title}\n aria-controls={panelElementId}\n disabled={isDisabled}\n >\n <span className={iconClasses}>\n <Typography\n variant={titleTypographyVariant}\n className={titleClasses}\n htmlAttributes={{\n 'aria-level': 2,\n role: 'heading',\n }}\n >\n {title}\n </Typography>\n\n <ChevronDownIconOutline\n className={classNames('ndl-accordion-item-header-icon', {\n '-n-rotate-180': isExpanded,\n })}\n />\n </span>\n </button>\n {trailingContent && (\n <Typography as=\"div\" variant=\"body-medium\">\n {trailingContent}\n </Typography>\n )}\n </div>\n\n <div\n id={panelElementId}\n ref={contentRef}\n className={contentClasses}\n aria-hidden={!isExpanded}\n aria-labelledby={buttonElementId}\n role=\"region\"\n >\n {/* The <div> element has a child <button> element that allows keyboard interaction */}\n {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */}\n <div\n ref={innerContentRef}\n className=\"ndl-accordion-item-content-inner\"\n onKeyDown={(event) => event.stopPropagation()}\n >\n <Typography\n variant=\"body-medium\"\n className=\"n-text-neutral-text-weak\"\n as=\"div\"\n >\n {children}\n </Typography>\n </div>\n </div>\n {hasDivider && <Divider />}\n </Component>\n );\n};\n\nconst AccordionItem = <\n T extends AccordionItemId,\n U extends React.ElementType = 'div',\n>({\n className,\n ...restProps\n}: PolymorphicCommonProps<U, ClassicItemProps<T>>) => {\n const classes = classNames('ndl-accordion-item-classic', className);\n\n return <BaseAccordionItem {...restProps} className={classes} />;\n};\nAccordionItem.displayName = 'Accordion.Item';\n\ntype CleanItemProps<T extends AccordionItemId> = Omit<\n AccordionItemProps<T>,\n 'hasDivider'\n>;\n\nconst CleanItem = <\n T extends AccordionItemId,\n U extends React.ElementType = 'div',\n>({\n className,\n ...restProps\n}: PolymorphicCommonProps<U, CleanItemProps<T>>) => {\n const classes = classNames('ndl-accordion-item-clean', className);\n\n return (\n <BaseAccordionItem {...restProps} className={classes} hasDivider={false} />\n );\n};\n\nCleanItem.displayName = 'Accordion.CleanItem';\n\nconst Accordion = Object.assign(AccordionComponent, {\n CleanItem: CleanItem,\n Item: AccordionItem,\n});\n\nexport { Accordion };\n"]}
|
package/lib/cjs/dialog/Dialog.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
36
|
var t = {};
|
|
4
37
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -37,7 +70,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
37
70
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
38
71
|
*/
|
|
39
72
|
const classnames_1 = __importDefault(require("classnames"));
|
|
40
|
-
const react_1 =
|
|
73
|
+
const react_1 = __importStar(require("react"));
|
|
41
74
|
const clean_icon_button_1 = require("../clean-icon-button");
|
|
42
75
|
const filled_button_1 = require("../filled-button");
|
|
43
76
|
const icons_1 = require("../icons");
|
|
@@ -61,7 +94,10 @@ const typeIcons = {
|
|
|
61
94
|
warning: ((0, jsx_runtime_1.jsx)(icons_1.ExclamationTriangleIconOutline, { htmlAttributes: { strokeWidth: 3 } })),
|
|
62
95
|
};
|
|
63
96
|
const DialogComponent = (_a) => {
|
|
97
|
+
var _b;
|
|
64
98
|
var { isOpen, onClose, children, variant, size, container, rootProps, hasDisabledCloseButton = false, htmlAttributes, className, style, ref } = _a, restProps = __rest(_a, ["isOpen", "onClose", "children", "variant", "size", "container", "rootProps", "hasDisabledCloseButton", "htmlAttributes", "className", "style", "ref"]);
|
|
99
|
+
const id = (0, react_1.useId)();
|
|
100
|
+
const [headerId, setHeaderId] = (0, react_1.useState)(id);
|
|
65
101
|
const handleCloseClick = (e) => {
|
|
66
102
|
e.preventDefault();
|
|
67
103
|
onClose === null || onClose === void 0 ? void 0 : onClose(e, dialog_types_1.DialogCloseReason.CLOSE_BUTTON_CLICK);
|
|
@@ -71,16 +107,28 @@ const DialogComponent = (_a) => {
|
|
|
71
107
|
if (reason === modal_1.ModalCloseReason.BACKDROP_CLICK) {
|
|
72
108
|
return;
|
|
73
109
|
}
|
|
74
|
-
onClose === null || onClose === void 0 ? void 0 : onClose(e, reason ? convertCloseReason(reason) : undefined);
|
|
110
|
+
onClose === null || onClose === void 0 ? void 0 : onClose(e, reason !== undefined ? convertCloseReason(reason) : undefined);
|
|
75
111
|
};
|
|
112
|
+
const hasHeaderChild = react_1.default.useMemo(() => {
|
|
113
|
+
const childrenArray = react_1.default.Children.toArray(children);
|
|
114
|
+
return childrenArray.some((child) => react_1.default.isValidElement(child) && child.type === Header);
|
|
115
|
+
}, [children]);
|
|
116
|
+
const ariaLabelledBy = (_b = htmlAttributes === null || htmlAttributes === void 0 ? void 0 : htmlAttributes['aria-labelledby']) !== null && _b !== void 0 ? _b : (hasHeaderChild ? headerId : undefined);
|
|
76
117
|
if (!isOpen) {
|
|
77
118
|
return null;
|
|
78
119
|
}
|
|
120
|
+
if ((htmlAttributes === null || htmlAttributes === void 0 ? void 0 : htmlAttributes['aria-label']) === undefined && !ariaLabelledBy) {
|
|
121
|
+
console.warn('The Dialog is missing aria-label and Header. Please add one of them for accessibility.');
|
|
122
|
+
}
|
|
79
123
|
const classes = (0, classnames_1.default)('ndl-dialog', className, {
|
|
80
124
|
'ndl-with-close-button': !hasDisabledCloseButton,
|
|
81
125
|
'ndl-with-icon': !!variant,
|
|
82
126
|
});
|
|
83
|
-
return ((0, jsx_runtime_1.jsx)(modal_1.Modal, Object.assign({ isOpen: isOpen, onClose: handleClose, container: container, rootProps: rootProps, size: size, htmlAttributes: htmlAttributes, className: classes, style: style, ref: ref }, restProps, { children: (0, jsx_runtime_1.jsxs)(dialog_context_1.DialogContext.Provider, { value: {
|
|
127
|
+
return ((0, jsx_runtime_1.jsx)(modal_1.Modal, Object.assign({ isOpen: isOpen, onClose: handleClose, container: container, rootProps: rootProps, size: size, htmlAttributes: Object.assign(Object.assign({}, htmlAttributes), { 'aria-labelledby': ariaLabelledBy }), className: classes, style: style, ref: ref }, restProps, { children: (0, jsx_runtime_1.jsxs)(dialog_context_1.DialogContext.Provider, { value: {
|
|
128
|
+
headerId,
|
|
129
|
+
setHeaderId,
|
|
130
|
+
variant,
|
|
131
|
+
}, children: [!hasDisabledCloseButton && ((0, jsx_runtime_1.jsx)(clean_icon_button_1.CleanIconButton, { size: "medium", className: "ndl-dialog-close", onClick: handleCloseClick, description: "Close", htmlAttributes: {
|
|
84
132
|
'data-testid': 'ndl-dialog-close',
|
|
85
133
|
role: 'button',
|
|
86
134
|
}, children: (0, jsx_runtime_1.jsx)(icons_1.XMarkIconOutline, {}) })), (0, jsx_runtime_1.jsxs)("div", { className: "ndl-dialog-content-wrapper", children: [variant && ((0, jsx_runtime_1.jsx)("div", { className: `ndl-dialog-type-icon ndl-${variant}`, "data-testid": "ndl-dialog-type-icon", children: typeIcons[variant] })), (0, jsx_runtime_1.jsx)("div", { className: "n-flex n-flex-col n-flex-1 n-w-full", children: children })] })] }) })));
|
|
@@ -113,9 +161,15 @@ const Actions = (_a) => {
|
|
|
113
161
|
};
|
|
114
162
|
const Header = (_a) => {
|
|
115
163
|
var { as, children, className, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["as", "children", "className", "style", "htmlAttributes", "ref"]);
|
|
164
|
+
const { headerId, setHeaderId } = (0, dialog_context_1.useDialogContext)();
|
|
116
165
|
const classes = (0, classnames_1.default)('ndl-dialog-header', className);
|
|
117
166
|
const Component = as !== null && as !== void 0 ? as : 'span';
|
|
118
|
-
|
|
167
|
+
(0, react_1.useEffect)(() => {
|
|
168
|
+
if (Boolean(htmlAttributes === null || htmlAttributes === void 0 ? void 0 : htmlAttributes.id) === true) {
|
|
169
|
+
setHeaderId === null || setHeaderId === void 0 ? void 0 : setHeaderId(htmlAttributes === null || htmlAttributes === void 0 ? void 0 : htmlAttributes.id);
|
|
170
|
+
}
|
|
171
|
+
}, [htmlAttributes === null || htmlAttributes === void 0 ? void 0 : htmlAttributes.id, setHeaderId]);
|
|
172
|
+
return ((0, jsx_runtime_1.jsx)(typography_1.Typography, Object.assign({ as: Component, className: classes, ref: ref, style: style, variant: "title-2" }, restProps, { htmlAttributes: Object.assign(Object.assign({}, htmlAttributes), { id: headerId }), children: children })));
|
|
119
173
|
};
|
|
120
174
|
const Subtitle = (_a) => {
|
|
121
175
|
var { as, children, className, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["as", "children", "className", "style", "htmlAttributes", "ref"]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dialog.js","sourceRoot":"","sources":["../../../src/dialog/Dialog.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,4DAAoC;AACpC,kDAA0B;AAO1B,4DAAuD;AACvD,oDAAgD;AAChD,oCAKkB;AAClB,oCAAmD;AACnD,wDAAoD;AACpD,gDAA4C;AAC5C,8CAA2C;AAC3C,qDAAmE;AACnE,iDASwB;AAExB,MAAM,kBAAkB,GAAG,CAAC,MAAwB,EAAqB,EAAE;IACzE,MAAM,YAAY,GAAG,MAAsC,CAAC;IAC5D,IAAI,MAAM,CAAC,MAAM,CAAC,gCAAiB,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;QAC5D,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,mBAAmB,MAAM,uBAAuB,CAAC,CAAC;AACpE,CAAC,CAAC;AACF,4CAA4C;AAC5C,MAAM,SAAS,GAGX;IACF,MAAM,EAAE,uBAAC,oCAA4B,IAAC,cAAc,EAAE,EAAE,WAAW,EAAE,CAAC,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AAQ,EACR,SAAS,EACT,KAAK,EACL,cAAc,EACd,GAAG,OAE2C,EAD3C,SAAS,cAPwC,iEAQrD,CADa;IAEZ,MAAM,OAAO,GAAG,IAAA,oBAAU,EAAC,oBAAoB,EAAE,SAAS,CAAC,CAAC;IAC5D,MAAM,SAAS,GAAsB,EAAE,aAAF,EAAE,cAAF,EAAE,GAAI,KAAK,CAAC;IAEjD,OAAO,CACL,uBAAC,SAAS,kBACR,SAAS,EAAE,OAAO,EAClB,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,GAAG,IACJ,SAAS,EACT,cAAc,cAEjB,QAAQ,IACC,CACb,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,KAAK,GAAG,CAAC,EAQwB,EAAE,EAAE;QAR5B,EACb,GAAG,EACH,GAAG,EACH,SAAS,EACT,KAAK,EACL,cAAc,EACd,GAAG,OAEkC,EADlC,SAAS,cAPC,6DAQd,CADa;IAEZ,MAAM,OAAO,GAAG,IAAA,oBAAU,EAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC;IAE1D,OAAO,CACL,8CACE,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,OAAO,EAClB,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,GAAG,IACJ,SAAS,EACT,cAAc,EAClB,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE;IAC5C,OAAO;IACP,OAAO;IACP,WAAW;IACX,MAAM;IACN,KAAK;IACL,QAAQ;CACT,CAAC,CAAC;AAEM,wBAAM","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport classNames from 'classnames';\nimport React from 'react';\n\nimport {\n type CommonProps,\n type PolymorphicCommonProps,\n} from '../_common/types';\nimport { type ButtonBase } from '../button';\nimport { CleanIconButton } from '../clean-icon-button';\nimport { FilledButton } from '../filled-button';\nimport {\n ExclamationCircleIconOutline,\n ExclamationTriangleIconOutline,\n InformationCircleIconOutline,\n XMarkIconOutline,\n} from '../icons';\nimport { Modal, ModalCloseReason } from '../modal';\nimport { OutlinedButton } from '../outlined-button';\nimport { TextButton } from '../text-button';\nimport { Typography } from '../typography';\nimport { DialogContext, useDialogContext } from './dialog-context';\nimport {\n type DialogActionsProps,\n DialogCloseReason,\n type DialogContentProps,\n type DialogDescriptionProps,\n type DialogHeaderProps,\n type DialogImageProps,\n type DialogProps,\n type DialogSubtitleProps,\n} from './dialog-types';\n\nconst convertCloseReason = (reason: ModalCloseReason): DialogCloseReason => {\n const dialogReason = reason as unknown as DialogCloseReason;\n if (Object.values(DialogCloseReason).includes(dialogReason)) {\n return dialogReason;\n }\n\n throw new Error(`Unknown reason '${reason}' received from popup`);\n};\n/* Stroke width on regular icons is 1.5px */\nconst typeIcons: Record<\n NonNullable<React.ComponentProps<typeof Dialog>['variant']>,\n React.ReactNode\n> = {\n danger: <ExclamationCircleIconOutline htmlAttributes={{ strokeWidth: 3 }} />,\n info: <InformationCircleIconOutline htmlAttributes={{ strokeWidth: 3 }} />,\n warning: (\n <ExclamationTriangleIconOutline htmlAttributes={{ strokeWidth: 3 }} />\n ),\n};\n\nconst DialogComponent = ({\n isOpen,\n onClose,\n children,\n variant,\n size,\n container,\n rootProps,\n hasDisabledCloseButton = false,\n htmlAttributes,\n className,\n style,\n ref,\n ...restProps\n}: CommonProps<'div', DialogProps>) => {\n const handleCloseClick = (e: React.MouseEvent<HTMLButtonElement>) => {\n e.preventDefault();\n onClose?.(e, DialogCloseReason.CLOSE_BUTTON_CLICK);\n };\n\n const handleClose = (\n e: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>,\n reason?: ModalCloseReason,\n ) => {\n // Dialog should not be closed when backdrop is clicked\n if (reason === ModalCloseReason.BACKDROP_CLICK) {\n return;\n }\n\n onClose?.(e, reason ? convertCloseReason(reason) : undefined);\n };\n\n if (!isOpen) {\n return null;\n }\n\n const classes = classNames('ndl-dialog', className, {\n 'ndl-with-close-button': !hasDisabledCloseButton,\n 'ndl-with-icon': !!variant,\n });\n\n return (\n <Modal\n isOpen={isOpen}\n onClose={handleClose}\n container={container}\n rootProps={rootProps}\n size={size}\n htmlAttributes={htmlAttributes}\n className={classes}\n style={style}\n ref={ref}\n {...restProps}\n >\n <DialogContext.Provider value={{ variant }}>\n {!hasDisabledCloseButton && (\n <CleanIconButton\n size=\"medium\"\n className=\"ndl-dialog-close\"\n onClick={handleCloseClick}\n description=\"Close\"\n htmlAttributes={{\n 'data-testid': 'ndl-dialog-close',\n role: 'button',\n }}\n >\n <XMarkIconOutline />\n </CleanIconButton>\n )}\n <div className=\"ndl-dialog-content-wrapper\">\n {variant && (\n <div\n className={`ndl-dialog-type-icon ndl-${variant}`}\n data-testid=\"ndl-dialog-type-icon\"\n >\n {typeIcons[variant]}\n </div>\n )}\n <div className=\"n-flex n-flex-col n-flex-1 n-w-full\">{children}</div>\n </div>\n </DialogContext.Provider>\n </Modal>\n );\n};\n\nconst Actions = <T extends React.ElementType = 'div'>({\n as,\n children,\n className,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: PolymorphicCommonProps<T, DialogActionsProps>) => {\n const { variant } = useDialogContext();\n const classes = classNames('ndl-dialog-actions', className);\n const Component: React.ElementType = as ?? 'div';\n\n let childrenToRender = children;\n\n // For danger dialogs, we want to convert primary buttons to danger buttons by default\n if (variant === 'danger') {\n childrenToRender = React.Children.map(children, (element) => {\n if (!React.isValidElement(element)) {\n return;\n }\n if (\n element.type === OutlinedButton ||\n element.type === FilledButton ||\n element.type === TextButton\n ) {\n const buttonElement = element as React.ReactElement<\n React.ComponentProps<typeof ButtonBase>\n >;\n\n if (\n buttonElement.props.variant === 'primary' ||\n buttonElement.props.variant === undefined\n ) {\n return React.cloneElement(buttonElement, {\n ...buttonElement.props,\n variant: 'danger',\n });\n }\n }\n return element;\n });\n }\n\n return (\n <Component\n className={classes}\n style={style}\n ref={ref}\n {...restProps}\n {...htmlAttributes}\n >\n {childrenToRender}\n </Component>\n );\n};\n\nconst Header = <T extends React.ElementType = 'span'>({\n as,\n children,\n className,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: PolymorphicCommonProps<T, DialogHeaderProps>) => {\n const classes = classNames('ndl-dialog-header', className);\n const Component: React.ElementType = as ?? 'span';\n\n return (\n <Typography\n as={Component}\n variant=\"title-2\"\n className={classes}\n style={style}\n ref={ref}\n {...restProps}\n {...htmlAttributes}\n >\n {children}\n </Typography>\n );\n};\n\nconst Subtitle = <T extends React.ElementType = 'div'>({\n as,\n children,\n className,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: PolymorphicCommonProps<T, DialogSubtitleProps>) => {\n const classes = classNames('ndl-dialog-subtitle', className);\n const Component: React.ElementType = as ?? 'div';\n\n return (\n <Component\n className={classes}\n style={style}\n ref={ref}\n {...restProps}\n {...htmlAttributes}\n >\n {children}\n </Component>\n );\n};\n\nconst Description = <T extends React.ElementType = 'div'>({\n as,\n children,\n className,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: PolymorphicCommonProps<T, DialogDescriptionProps>) => {\n const classes = classNames('ndl-dialog-description', className);\n const Component: React.ElementType = as ?? 'div';\n return (\n <Component\n className={classes}\n style={style}\n ref={ref}\n {...restProps}\n {...htmlAttributes}\n >\n {children}\n </Component>\n );\n};\n\nconst Content = <T extends React.ElementType = 'div'>({\n as,\n children,\n className,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: PolymorphicCommonProps<T, DialogContentProps>) => {\n const classes = classNames('ndl-dialog-content', className);\n const Component: React.ElementType = as ?? 'div';\n\n return (\n <Component\n className={classes}\n style={style}\n ref={ref}\n {...restProps}\n {...htmlAttributes}\n >\n {children}\n </Component>\n );\n};\n\nconst Image = ({\n src,\n alt,\n className,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: CommonProps<'img', DialogImageProps>) => {\n const classes = classNames('ndl-dialog-image', className);\n\n return (\n <img\n src={src}\n alt={alt}\n className={classes}\n style={style}\n ref={ref}\n {...restProps}\n {...htmlAttributes}\n />\n );\n};\n\nconst Dialog = Object.assign(DialogComponent, {\n Actions,\n Content,\n Description,\n Header,\n Image,\n Subtitle,\n});\n\nexport { Dialog };\n"]}
|
|
1
|
+
{"version":3,"file":"Dialog.js","sourceRoot":"","sources":["../../../src/dialog/Dialog.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,4DAAoC;AACpC,+CAA0D;AAO1D,4DAAuD;AACvD,oDAAgD;AAChD,oCAKkB;AAClB,oCAAmD;AACnD,wDAAoD;AACpD,gDAA4C;AAC5C,8CAA2C;AAC3C,qDAAmE;AACnE,iDASwB;AAExB,MAAM,kBAAkB,GAAG,CAAC,MAAwB,EAAqB,EAAE;IACzE,MAAM,YAAY,GAAG,MAAsC,CAAC;IAC5D,IAAI,MAAM,CAAC,MAAM,CAAC,gCAAiB,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;QAC5D,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,mBAAmB,MAAM,uBAAuB,CAAC,CAAC;AACpE,CAAC,CAAC;AACF,4CAA4C;AAC5C,MAAM,SAAS,GAGX;IACF,MAAM,EAAE,uBAAC,oCAA4B,IAAC,cAAc,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE,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AC;AACJ,CAAC,CAAC;AAEF,MAAM,OAAO,GAAG,CAAsC,EAQN,EAAE,EAAE;QARE,EACpD,EAAE,EACF,QAAQ,EACR,SAAS,EACT,KAAK,EACL,cAAc,EACd,GAAG,OAE2C,EAD3C,SAAS,cAPwC,iEAQrD,CADa;IAEZ,MAAM,OAAO,GAAG,IAAA,oBAAU,EAAC,oBAAoB,EAAE,SAAS,CAAC,CAAC;IAC5D,MAAM,SAAS,GAAsB,EAAE,aAAF,EAAE,cAAF,EAAE,GAAI,KAAK,CAAC;IAEjD,OAAO,CACL,uBAAC,SAAS,kBACR,SAAS,EAAE,OAAO,EAClB,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,GAAG,IACJ,SAAS,EACT,cAAc,cAEjB,QAAQ,IACC,CACb,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,KAAK,GAAG,CAAC,EAQwB,EAAE,EAAE;QAR5B,EACb,GAAG,EACH,GAAG,EACH,SAAS,EACT,KAAK,EACL,cAAc,EACd,GAAG,OAEkC,EADlC,SAAS,cAPC,6DAQd,CADa;IAEZ,MAAM,OAAO,GAAG,IAAA,oBAAU,EAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC;IAE1D,OAAO,CACL,8CACE,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,OAAO,EAClB,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,GAAG,IACJ,SAAS,EACT,cAAc,EAClB,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE;IAC5C,OAAO;IACP,OAAO;IACP,WAAW;IACX,MAAM;IACN,KAAK;IACL,QAAQ;CACT,CAAC,CAAC;AAEM,wBAAM","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport classNames from 'classnames';\nimport React, { useEffect, useId, useState } from 'react';\n\nimport {\n type CommonProps,\n type PolymorphicCommonProps,\n} from '../_common/types';\nimport { type ButtonBase } from '../button';\nimport { CleanIconButton } from '../clean-icon-button';\nimport { FilledButton } from '../filled-button';\nimport {\n ExclamationCircleIconOutline,\n ExclamationTriangleIconOutline,\n InformationCircleIconOutline,\n XMarkIconOutline,\n} from '../icons';\nimport { Modal, ModalCloseReason } from '../modal';\nimport { OutlinedButton } from '../outlined-button';\nimport { TextButton } from '../text-button';\nimport { Typography } from '../typography';\nimport { DialogContext, useDialogContext } from './dialog-context';\nimport {\n type DialogActionsProps,\n DialogCloseReason,\n type DialogContentProps,\n type DialogDescriptionProps,\n type DialogHeaderProps,\n type DialogImageProps,\n type DialogProps,\n type DialogSubtitleProps,\n} from './dialog-types';\n\nconst convertCloseReason = (reason: ModalCloseReason): DialogCloseReason => {\n const dialogReason = reason as unknown as DialogCloseReason;\n if (Object.values(DialogCloseReason).includes(dialogReason)) {\n return dialogReason;\n }\n\n throw new Error(`Unknown reason '${reason}' received from popup`);\n};\n/* Stroke width on regular icons is 1.5px */\nconst typeIcons: Record<\n NonNullable<React.ComponentProps<typeof Dialog>['variant']>,\n React.ReactNode\n> = {\n danger: <ExclamationCircleIconOutline htmlAttributes={{ strokeWidth: 3 }} />,\n info: <InformationCircleIconOutline htmlAttributes={{ strokeWidth: 3 }} />,\n warning: (\n <ExclamationTriangleIconOutline htmlAttributes={{ strokeWidth: 3 }} />\n ),\n};\n\nconst DialogComponent = ({\n isOpen,\n onClose,\n children,\n variant,\n size,\n container,\n rootProps,\n hasDisabledCloseButton = false,\n htmlAttributes,\n className,\n style,\n ref,\n ...restProps\n}: CommonProps<'div', DialogProps>) => {\n const id = useId();\n const [headerId, setHeaderId] = useState<string | undefined>(id);\n\n const handleCloseClick = (e: React.MouseEvent<HTMLButtonElement>) => {\n e.preventDefault();\n onClose?.(e, DialogCloseReason.CLOSE_BUTTON_CLICK);\n };\n\n const handleClose = (\n e: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>,\n reason?: ModalCloseReason,\n ) => {\n // Dialog should not be closed when backdrop is clicked\n if (reason === ModalCloseReason.BACKDROP_CLICK) {\n return;\n }\n\n onClose?.(e, reason !== undefined ? convertCloseReason(reason) : undefined);\n };\n\n const hasHeaderChild = React.useMemo(() => {\n const childrenArray = React.Children.toArray(children);\n return childrenArray.some(\n (child) => React.isValidElement(child) && child.type === Header,\n );\n }, [children]);\n\n const ariaLabelledBy =\n htmlAttributes?.['aria-labelledby'] ??\n (hasHeaderChild ? headerId : undefined);\n\n if (!isOpen) {\n return null;\n }\n\n if (htmlAttributes?.['aria-label'] === undefined && !ariaLabelledBy) {\n console.warn(\n 'The Dialog is missing aria-label and Header. Please add one of them for accessibility.',\n );\n }\n\n const classes = classNames('ndl-dialog', className, {\n 'ndl-with-close-button': !hasDisabledCloseButton,\n 'ndl-with-icon': !!variant,\n });\n\n return (\n <Modal\n isOpen={isOpen}\n onClose={handleClose}\n container={container}\n rootProps={rootProps}\n size={size}\n htmlAttributes={{\n ...htmlAttributes,\n 'aria-labelledby': ariaLabelledBy,\n }}\n className={classes}\n style={style}\n ref={ref}\n {...restProps}\n >\n <DialogContext.Provider\n value={{\n headerId,\n setHeaderId,\n variant,\n }}\n >\n {!hasDisabledCloseButton && (\n <CleanIconButton\n size=\"medium\"\n className=\"ndl-dialog-close\"\n onClick={handleCloseClick}\n description=\"Close\"\n htmlAttributes={{\n 'data-testid': 'ndl-dialog-close',\n role: 'button',\n }}\n >\n <XMarkIconOutline />\n </CleanIconButton>\n )}\n <div className=\"ndl-dialog-content-wrapper\">\n {variant && (\n <div\n className={`ndl-dialog-type-icon ndl-${variant}`}\n data-testid=\"ndl-dialog-type-icon\"\n >\n {typeIcons[variant]}\n </div>\n )}\n <div className=\"n-flex n-flex-col n-flex-1 n-w-full\">{children}</div>\n </div>\n </DialogContext.Provider>\n </Modal>\n );\n};\n\nconst Actions = <T extends React.ElementType = 'div'>({\n as,\n children,\n className,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: PolymorphicCommonProps<T, DialogActionsProps>) => {\n const { variant } = useDialogContext();\n const classes = classNames('ndl-dialog-actions', className);\n const Component: React.ElementType = as ?? 'div';\n\n let childrenToRender = children;\n\n // For danger dialogs, we want to convert primary buttons to danger buttons by default\n if (variant === 'danger') {\n childrenToRender = React.Children.map(children, (element) => {\n if (!React.isValidElement(element)) {\n return;\n }\n if (\n element.type === OutlinedButton ||\n element.type === FilledButton ||\n element.type === TextButton\n ) {\n const buttonElement = element as React.ReactElement<\n React.ComponentProps<typeof ButtonBase>\n >;\n\n if (\n buttonElement.props.variant === 'primary' ||\n buttonElement.props.variant === undefined\n ) {\n return React.cloneElement(buttonElement, {\n ...buttonElement.props,\n variant: 'danger',\n });\n }\n }\n return element;\n });\n }\n\n return (\n <Component\n className={classes}\n style={style}\n ref={ref}\n {...restProps}\n {...htmlAttributes}\n >\n {childrenToRender}\n </Component>\n );\n};\n\nconst Header = <T extends React.ElementType = 'span'>({\n as,\n children,\n className,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: PolymorphicCommonProps<T, DialogHeaderProps>) => {\n const { headerId, setHeaderId } = useDialogContext();\n const classes = classNames('ndl-dialog-header', className);\n const Component: React.ElementType = as ?? 'span';\n\n useEffect(() => {\n if (Boolean(htmlAttributes?.id) === true) {\n setHeaderId?.(htmlAttributes?.id);\n }\n }, [htmlAttributes?.id, setHeaderId]);\n\n return (\n <Typography\n as={Component}\n className={classes}\n ref={ref}\n style={style}\n variant=\"title-2\"\n {...restProps}\n htmlAttributes={{ ...htmlAttributes, id: headerId }}\n >\n {children}\n </Typography>\n );\n};\n\nconst Subtitle = <T extends React.ElementType = 'div'>({\n as,\n children,\n className,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: PolymorphicCommonProps<T, DialogSubtitleProps>) => {\n const classes = classNames('ndl-dialog-subtitle', className);\n const Component: React.ElementType = as ?? 'div';\n\n return (\n <Component\n className={classes}\n style={style}\n ref={ref}\n {...restProps}\n {...htmlAttributes}\n >\n {children}\n </Component>\n );\n};\n\nconst Description = <T extends React.ElementType = 'div'>({\n as,\n children,\n className,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: PolymorphicCommonProps<T, DialogDescriptionProps>) => {\n const classes = classNames('ndl-dialog-description', className);\n const Component: React.ElementType = as ?? 'div';\n\n return (\n <Component\n className={classes}\n style={style}\n ref={ref}\n {...restProps}\n {...htmlAttributes}\n >\n {children}\n </Component>\n );\n};\n\nconst Content = <T extends React.ElementType = 'div'>({\n as,\n children,\n className,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: PolymorphicCommonProps<T, DialogContentProps>) => {\n const classes = classNames('ndl-dialog-content', className);\n const Component: React.ElementType = as ?? 'div';\n\n return (\n <Component\n className={classes}\n style={style}\n ref={ref}\n {...restProps}\n {...htmlAttributes}\n >\n {children}\n </Component>\n );\n};\n\nconst Image = ({\n src,\n alt,\n className,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: CommonProps<'img', DialogImageProps>) => {\n const classes = classNames('ndl-dialog-image', className);\n\n return (\n <img\n src={src}\n alt={alt}\n className={classes}\n style={style}\n ref={ref}\n {...restProps}\n {...htmlAttributes}\n />\n );\n};\n\nconst Dialog = Object.assign(DialogComponent, {\n Actions,\n Content,\n Description,\n Header,\n Image,\n Subtitle,\n});\n\nexport { Dialog };\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog-types.js","sourceRoot":"","sources":["../../../src/dialog/dialog-types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;AASH,iCAAiC;AACjC,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IAC3B,sDAAiC,CAAA;IACjC,4DAAuC,CAAA;AACzC,CAAC,EAHW,iBAAiB,iCAAjB,iBAAiB,QAG5B","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport type { ModalProps } from '../modal';\n\nexport interface DialogBaseProps {\n /** The content to display within the dialog component. */\n children?: React.ReactNode;\n}\n\n// Should extend ModalCloseReason\nexport enum DialogCloseReason {\n ESCAPE_KEY_DOWN = 'escapeKeyDown',\n CLOSE_BUTTON_CLICK = 'closeButtonClick',\n}\n\nexport interface DialogProps extends Omit<ModalProps, 'onClose'> {\n /** Controls whether the dialog is open or closed. */\n isOpen: boolean;\n /** Type of dialog, which determines the icon and styling. */\n variant?: 'info' | 'warning' | 'danger';\n /** Whether to disable the close button in the top-right corner. */\n hasDisabledCloseButton?: boolean;\n /** Callback function called when the dialog is closed. */\n onClose?: (\n e: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>,\n reason?: DialogCloseReason,\n ) => void;\n}\n\nexport interface DialogContextType {\n variant?: DialogProps['variant'];\n}\n\nexport type DialogActionsProps = DialogBaseProps;\n\nexport type DialogHeaderProps = DialogBaseProps;\n\nexport type DialogSubtitleProps = DialogBaseProps;\n\nexport type DialogDescriptionProps = DialogBaseProps;\n\nexport type DialogContentProps = DialogBaseProps;\n\nexport type DialogImageProps = {\n /** Source URL of the image */\n src: string;\n /** Alternative text for the image */\n alt: string;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"dialog-types.js","sourceRoot":"","sources":["../../../src/dialog/dialog-types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;AASH,iCAAiC;AACjC,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IAC3B,sDAAiC,CAAA;IACjC,4DAAuC,CAAA;AACzC,CAAC,EAHW,iBAAiB,iCAAjB,iBAAiB,QAG5B","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport type { ModalProps } from '../modal';\n\nexport interface DialogBaseProps {\n /** The content to display within the dialog component. */\n children?: React.ReactNode;\n}\n\n// Should extend ModalCloseReason\nexport enum DialogCloseReason {\n ESCAPE_KEY_DOWN = 'escapeKeyDown',\n CLOSE_BUTTON_CLICK = 'closeButtonClick',\n}\n\nexport interface DialogProps extends Omit<ModalProps, 'onClose'> {\n /** Controls whether the dialog is open or closed. */\n isOpen: boolean;\n /** Type of dialog, which determines the icon and styling. */\n variant?: 'info' | 'warning' | 'danger';\n /** Whether to disable the close button in the top-right corner. */\n hasDisabledCloseButton?: boolean;\n /** Callback function called when the dialog is closed. */\n onClose?: (\n e: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>,\n reason?: DialogCloseReason,\n ) => void;\n}\n\nexport interface DialogContextType {\n headerId?: string;\n setHeaderId?: (id: string) => void;\n variant?: DialogProps['variant'];\n}\n\nexport type DialogActionsProps = DialogBaseProps;\n\nexport type DialogHeaderProps = DialogBaseProps;\n\nexport type DialogSubtitleProps = DialogBaseProps;\n\nexport type DialogDescriptionProps = DialogBaseProps;\n\nexport type DialogContentProps = DialogBaseProps;\n\nexport type DialogImageProps = {\n /** Source URL of the image */\n src: string;\n /** Alternative text for the image */\n alt: string;\n};\n"]}
|
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
36
|
var t = {};
|
|
4
37
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -38,25 +71,45 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
38
71
|
*/
|
|
39
72
|
const react_1 = require("@floating-ui/react");
|
|
40
73
|
const classnames_1 = __importDefault(require("classnames"));
|
|
41
|
-
const react_2 = require("react");
|
|
74
|
+
const react_2 = __importStar(require("react"));
|
|
42
75
|
const popover_1 = require("../popover");
|
|
43
76
|
const status_label_1 = require("../status-label");
|
|
44
77
|
const theme_1 = require("../theme");
|
|
45
78
|
const typography_1 = require("../typography");
|
|
46
79
|
const SpotlightProvider_1 = require("./SpotlightProvider");
|
|
80
|
+
const SpotlightInstanceContext = (0, react_2.createContext)(null);
|
|
81
|
+
const useSpotlightInstance = () => {
|
|
82
|
+
const ctx = (0, react_2.useContext)(SpotlightInstanceContext);
|
|
83
|
+
if (ctx === null) {
|
|
84
|
+
throw new Error('Spotlight subcomponents must be used within <Spotlight />');
|
|
85
|
+
}
|
|
86
|
+
return ctx;
|
|
87
|
+
};
|
|
47
88
|
const use_spotlight_1 = require("./use-spotlight");
|
|
48
89
|
const SpotlightHeader = (_a) => {
|
|
49
90
|
var { children, className, as, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["children", "className", "as", "style", "htmlAttributes", "ref"]);
|
|
50
|
-
(0, SpotlightProvider_1.useSpotlightContext)();
|
|
51
91
|
const classes = (0, classnames_1.default)('ndl-spotlight-header', className);
|
|
52
|
-
|
|
92
|
+
const { headerId, setHeaderId } = useSpotlightInstance();
|
|
93
|
+
const Component = as !== null && as !== void 0 ? as : 'div';
|
|
94
|
+
(0, react_2.useEffect)(() => {
|
|
95
|
+
if (Boolean(htmlAttributes === null || htmlAttributes === void 0 ? void 0 : htmlAttributes.id) === true) {
|
|
96
|
+
setHeaderId === null || setHeaderId === void 0 ? void 0 : setHeaderId(htmlAttributes === null || htmlAttributes === void 0 ? void 0 : htmlAttributes.id);
|
|
97
|
+
}
|
|
98
|
+
}, [setHeaderId, htmlAttributes === null || htmlAttributes === void 0 ? void 0 : htmlAttributes.id]);
|
|
99
|
+
return ((0, jsx_runtime_1.jsx)(typography_1.Typography, Object.assign({ as: Component, className: classes, ref: ref, style: style, variant: "title-4" }, restProps, { htmlAttributes: Object.assign(Object.assign({}, htmlAttributes), { id: headerId }), children: children })));
|
|
53
100
|
};
|
|
54
101
|
SpotlightHeader.displayName = 'Spotlight.Header';
|
|
55
102
|
const SpotlightBody = (_a) => {
|
|
56
103
|
var { children, className, as, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["children", "className", "as", "style", "htmlAttributes", "ref"]);
|
|
57
|
-
(0, SpotlightProvider_1.useSpotlightContext)();
|
|
58
104
|
const classes = (0, classnames_1.default)('ndl-spotlight-body', className);
|
|
59
|
-
|
|
105
|
+
const { descriptionId, setDescriptionId } = useSpotlightInstance();
|
|
106
|
+
const Component = as !== null && as !== void 0 ? as : 'div';
|
|
107
|
+
(0, react_2.useEffect)(() => {
|
|
108
|
+
if (Boolean(htmlAttributes === null || htmlAttributes === void 0 ? void 0 : htmlAttributes.id) === true) {
|
|
109
|
+
setDescriptionId === null || setDescriptionId === void 0 ? void 0 : setDescriptionId(htmlAttributes === null || htmlAttributes === void 0 ? void 0 : htmlAttributes.id);
|
|
110
|
+
}
|
|
111
|
+
}, [setDescriptionId, htmlAttributes === null || htmlAttributes === void 0 ? void 0 : htmlAttributes.id]);
|
|
112
|
+
return ((0, jsx_runtime_1.jsx)(typography_1.Typography, Object.assign({ as: Component, className: classes, ref: ref, style: style, variant: "body-medium" }, restProps, { htmlAttributes: Object.assign(Object.assign({}, htmlAttributes), { id: descriptionId }), children: children })));
|
|
60
113
|
};
|
|
61
114
|
SpotlightBody.displayName = 'Spotlight.Body';
|
|
62
115
|
const SpotlightLabel = (_a) => {
|
|
@@ -82,10 +135,27 @@ const SpotlightIconWrapper = (_a) => {
|
|
|
82
135
|
};
|
|
83
136
|
SpotlightIconWrapper.displayName = 'Spotlight.IconWrapper';
|
|
84
137
|
const SpotlightComponent = (_a) => {
|
|
138
|
+
var _b, _c;
|
|
85
139
|
var { target, beforeActions, actions, initialFocus, onClose, placement, children, className, style, htmlAttributes, closeOnClickOutside = false, onOpen, ref } = _a, restProps = __rest(_a, ["target", "beforeActions", "actions", "initialFocus", "onClose", "placement", "children", "className", "style", "htmlAttributes", "closeOnClickOutside", "onOpen", "ref"]);
|
|
140
|
+
const generatedHeaderId = (0, react_2.useId)();
|
|
141
|
+
const generatedDescriptionId = (0, react_2.useId)();
|
|
86
142
|
const [targetElement, setTargetElement] = (0, react_2.useState)(null);
|
|
87
143
|
const actionsRef = (0, react_2.useRef)(null);
|
|
88
|
-
const { isActiveSpotlight, isOpen, setActiveSpotlight, setIsOpen,
|
|
144
|
+
const { hasOverlay, isActiveSpotlight, isOpen, registeredTargets, setActiveSpotlight, setIsOpen, } = (0, SpotlightProvider_1.useSpotlightContext)();
|
|
145
|
+
const [headerId, setHeaderId] = (0, react_2.useState)(generatedHeaderId);
|
|
146
|
+
const [descriptionId, setDescriptionId] = (0, react_2.useState)(generatedDescriptionId);
|
|
147
|
+
// Determine if a Header child exists
|
|
148
|
+
const hasHeaderChild = react_2.default.useMemo(() => {
|
|
149
|
+
const childrenArray = react_2.default.Children.toArray(children);
|
|
150
|
+
return childrenArray.some((child) => react_2.default.isValidElement(child) && child.type === SpotlightHeader);
|
|
151
|
+
}, [children]);
|
|
152
|
+
// Source ARIA from htmlAttributes
|
|
153
|
+
const ariaLabel = htmlAttributes === null || htmlAttributes === void 0 ? void 0 : htmlAttributes['aria-label'];
|
|
154
|
+
const ariaLabelledBy = (_b = htmlAttributes === null || htmlAttributes === void 0 ? void 0 : htmlAttributes['aria-labelledby']) !== null && _b !== void 0 ? _b : (hasHeaderChild ? headerId : undefined);
|
|
155
|
+
const ariaDescribedBy = (_c = htmlAttributes === null || htmlAttributes === void 0 ? void 0 : htmlAttributes['aria-describedby']) !== null && _c !== void 0 ? _c : descriptionId;
|
|
156
|
+
if (ariaLabel === undefined && !ariaLabelledBy) {
|
|
157
|
+
console.warn('The Spotlight is missing aria-label and Header. Please add one of them for accessibility.');
|
|
158
|
+
}
|
|
89
159
|
const onOpenChange = (isOpen, event) => {
|
|
90
160
|
if (!isOpen) {
|
|
91
161
|
if (event instanceof PointerEvent) {
|
|
@@ -131,13 +201,18 @@ const SpotlightComponent = (_a) => {
|
|
|
131
201
|
if (!spotlight.context.open) {
|
|
132
202
|
return null;
|
|
133
203
|
}
|
|
134
|
-
return ((0, jsx_runtime_1.jsx)(react_1.FloatingPortal, { children: (0, jsx_runtime_1.jsx)(react_1.FloatingFocusManager, { context: spotlight.context, modal: true, initialFocus: findInitialFocus(), children: (0, jsx_runtime_1.jsxs)(
|
|
204
|
+
return ((0, jsx_runtime_1.jsx)(react_1.FloatingPortal, { children: (0, jsx_runtime_1.jsx)(react_1.FloatingFocusManager, { context: spotlight.context, modal: true, initialFocus: findInitialFocus(), children: (0, jsx_runtime_1.jsxs)(SpotlightInstanceContext.Provider, { value: {
|
|
205
|
+
descriptionId,
|
|
206
|
+
headerId,
|
|
207
|
+
setDescriptionId,
|
|
208
|
+
setHeaderId,
|
|
209
|
+
}, children: [hasOverlay === true && ((0, jsx_runtime_1.jsx)(react_1.FloatingOverlay, { className: "ndl-spotlight-overlay ndl-spotlight-overlay-top", onPointerDown: (e) => {
|
|
135
210
|
e.stopPropagation();
|
|
136
211
|
e.preventDefault();
|
|
137
212
|
}, onTouchStart: (e) => {
|
|
138
213
|
e.stopPropagation();
|
|
139
214
|
e.preventDefault();
|
|
140
|
-
} })), (0, jsx_runtime_1.jsxs)("div", Object.assign({ ref: mergedRef, className: classes, style: Object.assign(Object.assign(Object.assign({}, spotlight.floatingStyles), spotlight.transitionStyles), style) }, spotlight.getFloatingProps(Object.assign({}, htmlAttributes)), restProps, { children: [(0, jsx_runtime_1.jsx)("div", { children: children }), (Boolean(beforeActions) || Boolean(actions)) && ((0, jsx_runtime_1.jsxs)("div", { className: "ndl-spotlight-footer", children: [(0, jsx_runtime_1.jsx)(typography_1.Typography, { variant: "body-medium", children: beforeActions }), Boolean(actions) && ((0, jsx_runtime_1.jsx)("div", { className: "ndl-spotlight-actions", ref: actionsRef, children: actions }))] }))] }))] }) }) }));
|
|
215
|
+
} })), (0, jsx_runtime_1.jsxs)("div", Object.assign({ ref: mergedRef, className: classes, style: Object.assign(Object.assign(Object.assign({}, spotlight.floatingStyles), spotlight.transitionStyles), style) }, spotlight.getFloatingProps(Object.assign(Object.assign({}, htmlAttributes), { 'aria-describedby': ariaDescribedBy, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-modal': 'true' })), restProps, { children: [(0, jsx_runtime_1.jsx)("div", { children: children }), (Boolean(beforeActions) || Boolean(actions)) && ((0, jsx_runtime_1.jsxs)("div", { className: "ndl-spotlight-footer", children: [(0, jsx_runtime_1.jsx)(typography_1.Typography, { variant: "body-medium", children: beforeActions }), Boolean(actions) && ((0, jsx_runtime_1.jsx)("div", { className: "ndl-spotlight-actions", ref: actionsRef, children: actions }))] }))] }))] }) }) }));
|
|
141
216
|
};
|
|
142
217
|
SpotlightComponent.displayName = 'Spotlight';
|
|
143
218
|
const Spotlight = Object.assign(SpotlightComponent, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Spotlight.js","sourceRoot":"","sources":["../../../src/spotlight/Spotlight.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,8CAK4B;AAC5B,4DAAoC;AAEpC,iCAAoD;AAMpD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AAC,sBAAsB,aACnC,uBAAC,uBAAU,IAAC,OAAO,EAAC,aAAa,YAAE,aAAa,GAAc,EAC7D,OAAO,CAAC,OAAO,CAAC,IAAI,CACnB,gCAAK,SAAS,EAAC,uBAAuB,EAAC,GAAG,EAAE,UAAU,YACnD,OAAO,GACJ,CACP,IACG,CACP,KACG,IACL,GACkB,GACR,CAClB,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAkB,CAAC,WAAW,GAAG,WAAW,CAAC;AAE7C,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE;IAClD,IAAI,EAAE,aAAa;IACnB,MAAM,EAAE,eAAe;IACvB,WAAW,EAAE,oBAAoB;IACjC,KAAK,EAAE,cAAc;IACrB,KAAK,EAAE,cAAc;CACtB,CAAC,CAAC;AAEM,8BAAS","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport {\n FloatingFocusManager,\n FloatingOverlay,\n FloatingPortal,\n useMergeRefs,\n} from '@floating-ui/react';\nimport classNames from 'classnames';\nimport type React from 'react';\nimport { useEffect, useRef, useState } from 'react';\n\nimport {\n type CommonProps,\n type PolymorphicCommonProps,\n} from '../_common/types';\nimport { placementTranslation, type Popover } from '../popover';\nimport { StatusLabel } from '../status-label';\nimport { useNeedleTheme } from '../theme';\nimport { Typography } from '../typography';\nimport { useSpotlightContext } from './SpotlightProvider';\nimport { useSpotlight } from './use-spotlight';\n\ntype SpotlightHeaderProps = {\n /** The spotlight header content */\n children?: React.ReactNode;\n};\n\nconst SpotlightHeader = <T extends React.ElementType = 'div'>({\n children,\n className,\n as,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: PolymorphicCommonProps<T, SpotlightHeaderProps>) => {\n useSpotlightContext();\n const classes = classNames('ndl-spotlight-header', className);\n\n return (\n <Typography\n variant=\"title-4\"\n ref={ref}\n as={as ?? 'div'}\n className={classes}\n style={style}\n {...restProps}\n {...htmlAttributes}\n >\n {children}\n </Typography>\n );\n};\n\nSpotlightHeader.displayName = 'Spotlight.Header';\n\ntype SpotlightBodyProps = {\n /** The spotlight body content */\n children?: React.ReactNode;\n};\n\nconst SpotlightBody = <T extends React.ElementType = 'div'>({\n children,\n className,\n as,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: PolymorphicCommonProps<T, SpotlightBodyProps>) => {\n useSpotlightContext();\n const classes = classNames('ndl-spotlight-body', className);\n\n return (\n <Typography\n variant=\"body-medium\"\n className={classes}\n as={as ?? 'div'}\n style={style}\n ref={ref}\n {...restProps}\n {...htmlAttributes}\n >\n {children}\n </Typography>\n );\n};\n\nSpotlightBody.displayName = 'Spotlight.Body';\n\ntype SpotlightLabelProps = Omit<\n React.ComponentProps<typeof StatusLabel>,\n 'color' | 'fill'\n>;\n\nconst SpotlightLabel = <T extends React.ElementType = 'div'>({\n className,\n children,\n hasIcon,\n as,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: PolymorphicCommonProps<T, SpotlightLabelProps>) => {\n useSpotlightContext();\n const classes = classNames('ndl-spotlight-label', className);\n\n return (\n <StatusLabel\n fill=\"semi-filled\"\n variant=\"discovery\"\n hasIcon={hasIcon}\n ref={ref}\n as={as}\n className={classes}\n style={style}\n {...restProps}\n {...htmlAttributes}\n >\n {children}\n </StatusLabel>\n );\n};\n\nSpotlightLabel.displayName = 'Spotlight.Label';\n\ntype SpotlightImageProps = {\n /** A string that represents the URL of the image */\n src: string;\n /** A string that represents the alt text of the image */\n alt: string;\n};\n\nconst SpotlightImage = ({\n src,\n alt,\n className,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: CommonProps<'img', SpotlightImageProps>) => {\n useSpotlightContext();\n const classes = classNames('ndl-spotlight-image n-body-medium', className);\n\n return (\n <img\n src={src}\n alt={alt}\n ref={ref}\n className={classes}\n style={style}\n {...restProps}\n {...htmlAttributes}\n />\n );\n};\n\nSpotlightImage.displayName = 'Spotlight.Image';\n\ntype SpotlightIconWrapperProps = {\n /** Content displayed in the icon wrapper */\n children?: React.ReactNode;\n};\n\nconst SpotlightIconWrapper = <T extends React.ElementType = 'div'>({\n children,\n className,\n as,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: PolymorphicCommonProps<T, SpotlightIconWrapperProps>) => {\n useSpotlightContext();\n const classes = classNames('ndl-spotlight-icon-wrapper', className);\n const Component = as ?? 'div';\n\n return (\n <Component\n ref={ref}\n className={classes}\n style={style}\n {...restProps}\n {...htmlAttributes}\n >\n {children}\n </Component>\n );\n};\n\nSpotlightIconWrapper.displayName = 'Spotlight.IconWrapper';\n\nexport type SpotlightCloseAction = 'clickOutside' | 'escapeKeyDown';\n\nexport type SpotlightProps = {\n /** The id of the `SpotlightTarget` that this `Spotlight` should be rendered next to */\n target: string;\n /** The actions to be displayed in the Spotlight. Should only be TextButton or OutlinedButton components. */\n actions?: React.ReactNode;\n /** A ReactNode that can be put in the left corner of the Spotlight (left of action buttons). It should be used to display the current step if you have a multi-step tour */\n beforeActions?: React.ReactNode;\n /** A callback function that is called if the Spotlight is closed by either clicking outside the Spotlight, or by pressing the Escape key. The function has one argument: action (string that can be either \"clickOutside\" or \"escapeKeyDown\") */\n onClose?: (action: SpotlightCloseAction) => void;\n /** Callback function called when the spotlight is opened */\n onOpen?: () => void;\n /** Children should be Spotlight subcomponents */\n children?: React.ReactNode;\n} & Pick<\n React.ComponentProps<typeof Popover>,\n 'placement' | 'initialFocus' | 'closeOnClickOutside'\n>;\n\nconst SpotlightComponent = ({\n target,\n beforeActions,\n actions,\n initialFocus,\n onClose,\n placement,\n children,\n className,\n style,\n htmlAttributes,\n closeOnClickOutside = false,\n onOpen,\n ref,\n ...restProps\n}: CommonProps<'div', SpotlightProps>) => {\n const [targetElement, setTargetElement] = useState<HTMLElement | null>(null);\n const actionsRef = useRef<HTMLDivElement | null>(null);\n\n const {\n isActiveSpotlight,\n isOpen,\n setActiveSpotlight,\n setIsOpen,\n registeredTargets,\n hasOverlay,\n } = useSpotlightContext();\n\n const onOpenChange = (isOpen: boolean, event?: Event) => {\n if (!isOpen) {\n if (event instanceof PointerEvent) {\n onClose?.('clickOutside');\n } else if (event instanceof KeyboardEvent) {\n onClose?.('escapeKeyDown');\n }\n setActiveSpotlight(null);\n setIsOpen(false);\n }\n };\n\n const spotlight = useSpotlight({\n anchorElement: targetElement,\n closeOnClickOutside,\n initialFocus,\n isOpen: isActiveSpotlight(target) && isOpen && !!targetElement,\n onOpenChange,\n placement: placement ? placementTranslation[placement] : undefined,\n });\n\n const mergedRef = useMergeRefs([spotlight.refs.setFloating, ref]);\n\n const { themeClassName } = useNeedleTheme();\n const classes = classNames('ndl-spotlight', themeClassName, className);\n\n useEffect(() => {\n setTargetElement(registeredTargets[target]?.current);\n }, [target, registeredTargets]);\n\n useEffect(() => {\n if (isOpen && isActiveSpotlight(target)) {\n onOpen?.();\n }\n }, [isOpen, onOpen, isActiveSpotlight, target]);\n\n const findInitialFocus = () => {\n if (spotlight.initialFocus !== undefined) {\n return spotlight.initialFocus;\n }\n if (!actionsRef.current) {\n return undefined;\n }\n const focusableEls = actionsRef.current.querySelectorAll(\n 'button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])',\n );\n return focusableEls.length - 1;\n };\n\n if (!spotlight.context.open) {\n return null;\n }\n\n return (\n <FloatingPortal>\n <FloatingFocusManager\n context={spotlight.context}\n modal={true}\n initialFocus={findInitialFocus()}\n >\n <>\n {hasOverlay === true && (\n <FloatingOverlay\n className=\"ndl-spotlight-overlay ndl-spotlight-overlay-top\"\n onPointerDown={(e) => {\n e.stopPropagation();\n e.preventDefault();\n }}\n onTouchStart={(e) => {\n e.stopPropagation();\n e.preventDefault();\n }}\n />\n )}\n <div\n ref={mergedRef}\n className={classes}\n style={{\n ...spotlight.floatingStyles,\n ...spotlight.transitionStyles,\n ...style,\n }}\n {...spotlight.getFloatingProps({ ...htmlAttributes })}\n {...restProps}\n >\n <div>{children}</div>\n {(Boolean(beforeActions) || Boolean(actions)) && (\n <div className=\"ndl-spotlight-footer\">\n <Typography variant=\"body-medium\">{beforeActions}</Typography>\n {Boolean(actions) && (\n <div className=\"ndl-spotlight-actions\" ref={actionsRef}>\n {actions}\n </div>\n )}\n </div>\n )}\n </div>\n </>\n </FloatingFocusManager>\n </FloatingPortal>\n );\n};\n\nSpotlightComponent.displayName = 'Spotlight';\n\nconst Spotlight = Object.assign(SpotlightComponent, {\n Body: SpotlightBody,\n Header: SpotlightHeader,\n IconWrapper: SpotlightIconWrapper,\n Image: SpotlightImage,\n Label: SpotlightLabel,\n});\n\nexport { Spotlight };\n"]}
|
|
1
|
+
{"version":3,"file":"Spotlight.js","sourceRoot":"","sources":["../../../src/spotlight/Spotlight.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,8CAK4B;AAC5B,4DAAoC;AACpC,+CAOe;AAMf,wCAAgE;AAChE,kDAA8C;AAC9C,oCAA0C;AAC1C,8CAA2C;AAC3C,2DAA0D;AAU1D,MAAM,wBAAwB,GAC5B,IAAA,qBAAa,EAAsC,IAAI,CAAC,CAAC;AAE3D,MAAM,oBAAoB,GAAG,GAAiC,EAAE;IAC9D,MAAM,GAAG,GAAG,IAAA,kBAAU,EAAC,wBAAwB,CAAC,CAAC;IACjD,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CACb,2DAA2D,CAC5D,CAAC;I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ACJ,CAAC,CAAC;AAEF,kBAAkB,CAAC,WAAW,GAAG,WAAW,CAAC;AAE7C,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE;IAClD,IAAI,EAAE,aAAa;IACnB,MAAM,EAAE,eAAe;IACvB,WAAW,EAAE,oBAAoB;IACjC,KAAK,EAAE,cAAc;IACrB,KAAK,EAAE,cAAc;CACtB,CAAC,CAAC;AAEM,8BAAS","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport {\n FloatingFocusManager,\n FloatingOverlay,\n FloatingPortal,\n useMergeRefs,\n} from '@floating-ui/react';\nimport classNames from 'classnames';\nimport React, {\n createContext,\n useContext,\n useEffect,\n useId,\n useRef,\n useState,\n} from 'react';\n\nimport {\n type CommonProps,\n type PolymorphicCommonProps,\n} from '../_common/types';\nimport { placementTranslation, type Popover } from '../popover';\nimport { StatusLabel } from '../status-label';\nimport { useNeedleTheme } from '../theme';\nimport { Typography } from '../typography';\nimport { useSpotlightContext } from './SpotlightProvider';\n\n// Local instance context to pass stable ARIA ids to subcomponents\ntype SpotlightInstanceContextType = {\n headerId?: string;\n descriptionId?: string;\n setHeaderId?: (id: string | undefined) => void;\n setDescriptionId?: (id: string | undefined) => void;\n};\n\nconst SpotlightInstanceContext =\n createContext<SpotlightInstanceContextType | null>(null);\n\nconst useSpotlightInstance = (): SpotlightInstanceContextType => {\n const ctx = useContext(SpotlightInstanceContext);\n if (ctx === null) {\n throw new Error(\n 'Spotlight subcomponents must be used within <Spotlight />',\n );\n }\n return ctx;\n};\nimport { useSpotlight } from './use-spotlight';\n\ntype SpotlightHeaderProps = {\n /** The spotlight header content */\n children?: React.ReactNode;\n};\n\nconst SpotlightHeader = <T extends React.ElementType = 'div'>({\n children,\n className,\n as,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: PolymorphicCommonProps<T, SpotlightHeaderProps>) => {\n const classes = classNames('ndl-spotlight-header', className);\n const { headerId, setHeaderId } = useSpotlightInstance();\n const Component: React.ElementType = as ?? 'div';\n\n useEffect(() => {\n if (Boolean(htmlAttributes?.id) === true) {\n setHeaderId?.(htmlAttributes?.id);\n }\n }, [setHeaderId, htmlAttributes?.id]);\n\n return (\n <Typography\n as={Component}\n className={classes}\n ref={ref}\n style={style}\n variant=\"title-4\"\n {...restProps}\n htmlAttributes={{ ...htmlAttributes, id: headerId }}\n >\n {children}\n </Typography>\n );\n};\n\nSpotlightHeader.displayName = 'Spotlight.Header';\n\ntype SpotlightBodyProps = {\n /** The spotlight body content */\n children?: React.ReactNode;\n};\n\nconst SpotlightBody = <T extends React.ElementType = 'div'>({\n children,\n className,\n as,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: PolymorphicCommonProps<T, SpotlightBodyProps>) => {\n const classes = classNames('ndl-spotlight-body', className);\n const { descriptionId, setDescriptionId } = useSpotlightInstance();\n const Component: React.ElementType = as ?? 'div';\n\n useEffect(() => {\n if (Boolean(htmlAttributes?.id) === true) {\n setDescriptionId?.(htmlAttributes?.id);\n }\n }, [setDescriptionId, htmlAttributes?.id]);\n\n return (\n <Typography\n as={Component}\n className={classes}\n ref={ref}\n style={style}\n variant=\"body-medium\"\n {...restProps}\n htmlAttributes={{ ...htmlAttributes, id: descriptionId }}\n >\n {children}\n </Typography>\n );\n};\n\nSpotlightBody.displayName = 'Spotlight.Body';\n\ntype SpotlightLabelProps = Omit<\n React.ComponentProps<typeof StatusLabel>,\n 'color' | 'fill'\n>;\n\nconst SpotlightLabel = <T extends React.ElementType = 'div'>({\n className,\n children,\n hasIcon,\n as,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: PolymorphicCommonProps<T, SpotlightLabelProps>) => {\n useSpotlightContext();\n const classes = classNames('ndl-spotlight-label', className);\n\n return (\n <StatusLabel\n fill=\"semi-filled\"\n variant=\"discovery\"\n hasIcon={hasIcon}\n ref={ref}\n as={as}\n className={classes}\n style={style}\n {...restProps}\n {...htmlAttributes}\n >\n {children}\n </StatusLabel>\n );\n};\n\nSpotlightLabel.displayName = 'Spotlight.Label';\n\ntype SpotlightImageProps = {\n /** A string that represents the URL of the image */\n src: string;\n /** A string that represents the alt text of the image */\n alt: string;\n};\n\nconst SpotlightImage = ({\n src,\n alt,\n className,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: CommonProps<'img', SpotlightImageProps>) => {\n useSpotlightContext();\n const classes = classNames('ndl-spotlight-image n-body-medium', className);\n\n return (\n <img\n src={src}\n alt={alt}\n ref={ref}\n className={classes}\n style={style}\n {...restProps}\n {...htmlAttributes}\n />\n );\n};\n\nSpotlightImage.displayName = 'Spotlight.Image';\n\ntype SpotlightIconWrapperProps = {\n /** Content displayed in the icon wrapper */\n children?: React.ReactNode;\n};\n\nconst SpotlightIconWrapper = <T extends React.ElementType = 'div'>({\n children,\n className,\n as,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: PolymorphicCommonProps<T, SpotlightIconWrapperProps>) => {\n useSpotlightContext();\n const classes = classNames('ndl-spotlight-icon-wrapper', className);\n const Component = as ?? 'div';\n\n return (\n <Component\n ref={ref}\n className={classes}\n style={style}\n {...restProps}\n {...htmlAttributes}\n >\n {children}\n </Component>\n );\n};\n\nSpotlightIconWrapper.displayName = 'Spotlight.IconWrapper';\n\nexport type SpotlightCloseAction = 'clickOutside' | 'escapeKeyDown';\n\nexport type SpotlightProps = {\n /** The id of the `SpotlightTarget` that this `Spotlight` should be rendered next to */\n target: string;\n /** The actions to be displayed in the Spotlight. Should only be TextButton or OutlinedButton components. */\n actions?: React.ReactNode;\n /** A ReactNode that can be put in the left corner of the Spotlight (left of action buttons). It should be used to display the current step if you have a multi-step tour */\n beforeActions?: React.ReactNode;\n /** A callback function that is called if the Spotlight is closed by either clicking outside the Spotlight, or by pressing the Escape key. The function has one argument: action (string that can be either \"clickOutside\" or \"escapeKeyDown\") */\n onClose?: (action: SpotlightCloseAction) => void;\n /** Callback function called when the spotlight is opened */\n onOpen?: () => void;\n /** Children should be Spotlight subcomponents */\n children?: React.ReactNode;\n} & Pick<\n React.ComponentProps<typeof Popover>,\n 'placement' | 'initialFocus' | 'closeOnClickOutside'\n>;\n\nconst SpotlightComponent = ({\n target,\n beforeActions,\n actions,\n initialFocus,\n onClose,\n placement,\n children,\n className,\n style,\n htmlAttributes,\n closeOnClickOutside = false,\n onOpen,\n ref,\n ...restProps\n}: CommonProps<'div', SpotlightProps>) => {\n const generatedHeaderId = useId();\n const generatedDescriptionId = useId();\n const [targetElement, setTargetElement] = useState<HTMLElement | null>(null);\n const actionsRef = useRef<HTMLDivElement | null>(null);\n\n const {\n hasOverlay,\n isActiveSpotlight,\n isOpen,\n registeredTargets,\n setActiveSpotlight,\n setIsOpen,\n } = useSpotlightContext();\n\n const [headerId, setHeaderId] = useState<string | undefined>(\n generatedHeaderId,\n );\n const [descriptionId, setDescriptionId] = useState<string | undefined>(\n generatedDescriptionId,\n );\n\n // Determine if a Header child exists\n const hasHeaderChild = React.useMemo(() => {\n const childrenArray = React.Children.toArray(children);\n return childrenArray.some(\n (child) => React.isValidElement(child) && child.type === SpotlightHeader,\n );\n }, [children]);\n\n // Source ARIA from htmlAttributes\n const ariaLabel = htmlAttributes?.['aria-label'];\n const ariaLabelledBy =\n htmlAttributes?.['aria-labelledby'] ??\n (hasHeaderChild ? headerId : undefined);\n const ariaDescribedBy = htmlAttributes?.['aria-describedby'] ?? descriptionId;\n\n if (ariaLabel === undefined && !ariaLabelledBy) {\n console.warn(\n 'The Spotlight is missing aria-label and Header. Please add one of them for accessibility.',\n );\n }\n\n const onOpenChange = (isOpen: boolean, event?: Event) => {\n if (!isOpen) {\n if (event instanceof PointerEvent) {\n onClose?.('clickOutside');\n } else if (event instanceof KeyboardEvent) {\n onClose?.('escapeKeyDown');\n }\n setActiveSpotlight(null);\n setIsOpen(false);\n }\n };\n\n const spotlight = useSpotlight({\n anchorElement: targetElement,\n closeOnClickOutside,\n initialFocus,\n isOpen: isActiveSpotlight(target) && isOpen && !!targetElement,\n onOpenChange,\n placement: placement ? placementTranslation[placement] : undefined,\n });\n\n const mergedRef = useMergeRefs([spotlight.refs.setFloating, ref]);\n\n const { themeClassName } = useNeedleTheme();\n const classes = classNames('ndl-spotlight', themeClassName, className);\n\n useEffect(() => {\n setTargetElement(registeredTargets[target]?.current);\n }, [target, registeredTargets]);\n\n useEffect(() => {\n if (isOpen && isActiveSpotlight(target)) {\n onOpen?.();\n }\n }, [isOpen, onOpen, isActiveSpotlight, target]);\n\n const findInitialFocus = () => {\n if (spotlight.initialFocus !== undefined) {\n return spotlight.initialFocus;\n }\n if (!actionsRef.current) {\n return undefined;\n }\n const focusableEls = actionsRef.current.querySelectorAll(\n 'button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])',\n );\n return focusableEls.length - 1;\n };\n\n if (!spotlight.context.open) {\n return null;\n }\n\n return (\n <FloatingPortal>\n <FloatingFocusManager\n context={spotlight.context}\n modal={true}\n initialFocus={findInitialFocus()}\n >\n <SpotlightInstanceContext.Provider\n value={{\n descriptionId,\n headerId,\n setDescriptionId,\n setHeaderId,\n }}\n >\n {hasOverlay === true && (\n <FloatingOverlay\n className=\"ndl-spotlight-overlay ndl-spotlight-overlay-top\"\n onPointerDown={(e) => {\n e.stopPropagation();\n e.preventDefault();\n }}\n onTouchStart={(e) => {\n e.stopPropagation();\n e.preventDefault();\n }}\n />\n )}\n <div\n ref={mergedRef}\n className={classes}\n style={{\n ...spotlight.floatingStyles,\n ...spotlight.transitionStyles,\n ...style,\n }}\n {...spotlight.getFloatingProps({\n ...htmlAttributes,\n 'aria-describedby': ariaDescribedBy,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-modal': 'true',\n })}\n {...restProps}\n >\n <div>{children}</div>\n {(Boolean(beforeActions) || Boolean(actions)) && (\n <div className=\"ndl-spotlight-footer\">\n <Typography variant=\"body-medium\">{beforeActions}</Typography>\n {Boolean(actions) && (\n <div className=\"ndl-spotlight-actions\" ref={actionsRef}>\n {actions}\n </div>\n )}\n </div>\n )}\n </div>\n </SpotlightInstanceContext.Provider>\n </FloatingFocusManager>\n </FloatingPortal>\n );\n};\n\nSpotlightComponent.displayName = 'Spotlight';\n\nconst Spotlight = Object.assign(SpotlightComponent, {\n Body: SpotlightBody,\n Header: SpotlightHeader,\n IconWrapper: SpotlightIconWrapper,\n Image: SpotlightImage,\n Label: SpotlightLabel,\n});\n\nexport { Spotlight };\n"]}
|
|
@@ -35,7 +35,7 @@ const Component = (props) => {
|
|
|
35
35
|
setIsOpen(true);
|
|
36
36
|
}
|
|
37
37
|
}, [isModalOpen, setActiveSpotlight, setIsOpen, targetId, props.isChromatic]);
|
|
38
|
-
return ((0, jsx_runtime_1.jsxs)("div", { className: "n-flex n-justify-center n-gap-token-64", children: [(0, jsx_runtime_1.jsx)(react_1.FilledButton, { onClick: () => setIsModalOpen(true), children: "Open Dialog" }), (0, jsx_runtime_1.jsxs)(react_1.Dialog, { isOpen: isModalOpen, onClose: () => setIsModalOpen(false),
|
|
38
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "n-flex n-justify-center n-gap-token-64", children: [(0, jsx_runtime_1.jsx)(react_1.FilledButton, { onClick: () => setIsModalOpen(true), children: "Open Dialog" }), (0, jsx_runtime_1.jsxs)(react_1.Dialog, { isOpen: isModalOpen, onClose: () => setIsModalOpen(false), className: themeClassName, children: [(0, jsx_runtime_1.jsx)(react_1.Dialog.Header, { children: "Using Spotlight inside a dialog" }), (0, jsx_runtime_1.jsxs)(react_1.Dialog.Content, { className: "n-flex n-flex-col n-gap-token-32", children: [(0, jsx_runtime_1.jsxs)(react_1.Typography, { variant: "body-medium", children: ["Spotlight and SpotlightTarget should behave automatically correct when used inside a dialog. If positioning is not on top of everything, you might want to override the", (0, jsx_runtime_1.jsx)("code", { children: "--spotlight-z-index" }), " css variable."] }), (0, jsx_runtime_1.jsxs)("div", { className: "n-flex n-justify-center n-gap-token-64", children: [(0, jsx_runtime_1.jsx)(react_1.FilledButton, { onClick: () => setActiveSpotlight(targetId), children: "Activate Spotlight" }), (0, jsx_runtime_1.jsx)(react_1.SpotlightTarget, { id: targetId, hasPulse: !props.isChromatic, asChild: true, indicatorVariant: "border", children: (0, jsx_runtime_1.jsx)(react_1.FilledButton, { onClick: () => alert('Target button clicked'), children: "Target" }) })] })] }), (0, jsx_runtime_1.jsxs)(react_1.Spotlight, { placement: "bottom-end-top-end", target: targetId, actions: (0, jsx_runtime_1.jsx)(react_1.OutlinedButton, { onClick: () => {
|
|
39
39
|
setIsOpen(false);
|
|
40
40
|
setActiveSpotlight(null);
|
|
41
41
|
}, children: "Close" }), children: [(0, jsx_runtime_1.jsx)(react_1.Spotlight.Header, { children: "This is a header" }), (0, jsx_runtime_1.jsx)(react_1.Spotlight.Body, { children: "This is content" })] })] })] }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spotlight-in-dialog.story.js","sourceRoot":"","sources":["../../../../src/spotlight/stories/spotlight-in-dialog.story.tsx"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,mDAAiD;AAEjD,4CAS0B;AAC1B,iCAA4C;AAE5C,MAAM,SAAS,GAAG,CAAC,KAA+B,EAAE,EAAE;IACpD,MAAM,EAAE,cAAc,EAAE,GAAG,IAAA,sBAAc,GAAE,CAAC;IAC5C,MAAM,EAAE,SAAS,EAAE,kBAAkB,EAAE,GAAG,IAAA,2BAAmB,GAAE,CAAC;IAEhE,MAAM,CAAC,WA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CAAC,CAAC;4BAC3B,CAAC,sBAGc,aAGnB,uBAAC,iBAAS,CAAC,MAAM,mCAAoC,EACrD,uBAAC,iBAAS,CAAC,IAAI,kCAAiC,IACtC,IACL,IACL,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,SAAS,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport '@neo4j-ndl/base/lib/neo4j-ds-styles.css';\n\nimport {\n Dialog,\n FilledButton,\n OutlinedButton,\n Spotlight,\n SpotlightTarget,\n Typography,\n useNeedleTheme,\n useSpotlightContext,\n} from '@neo4j-ndl/react';\nimport { useEffect, useState } from 'react';\n\nconst Component = (props: { isChromatic: boolean }) => {\n const { themeClassName } = useNeedleTheme();\n const { setIsOpen, setActiveSpotlight } = useSpotlightContext();\n\n const [isModalOpen, setIsModalOpen] = useState<boolean>(props.isChromatic);\n const targetId = `test-target-${themeClassName}`;\n\n useEffect(() => {\n if (props.isChromatic && isModalOpen) {\n setActiveSpotlight(targetId);\n setIsOpen(true);\n }\n }, [isModalOpen, setActiveSpotlight, setIsOpen, targetId, props.isChromatic]);\n\n return (\n <div className=\"n-flex n-justify-center n-gap-token-64\">\n <FilledButton onClick={() => setIsModalOpen(true)}>\n Open Dialog\n </FilledButton>\n <Dialog\n isOpen={isModalOpen}\n onClose={() => setIsModalOpen(false)}\n className={themeClassName}\n >\n <Dialog.Header>Using Spotlight inside a dialog</Dialog.Header>\n <Dialog.Content className=\"n-flex n-flex-col n-gap-token-32\">\n <Typography variant=\"body-medium\">\n Spotlight and SpotlightTarget should behave automatically correct\n when used inside a dialog. If positioning is not on top of\n everything, you might want to override the\n <code>--spotlight-z-index</code> css variable.\n </Typography>\n <div className=\"n-flex n-justify-center n-gap-token-64\">\n <FilledButton onClick={() => setActiveSpotlight(targetId)}>\n Activate Spotlight\n </FilledButton>\n <SpotlightTarget\n id={targetId}\n hasPulse={!props.isChromatic}\n asChild\n indicatorVariant=\"border\"\n >\n <FilledButton onClick={() => alert('Target button clicked')}>\n Target\n </FilledButton>\n </SpotlightTarget>\n </div>\n </Dialog.Content>\n <Spotlight\n placement=\"bottom-end-top-end\"\n target={targetId}\n actions={\n <OutlinedButton\n onClick={() => {\n setIsOpen(false);\n setActiveSpotlight(null);\n }}\n >\n Close\n </OutlinedButton>\n }\n >\n <Spotlight.Header>This is a header</Spotlight.Header>\n <Spotlight.Body>This is content</Spotlight.Body>\n </Spotlight>\n </Dialog>\n </div>\n );\n};\n\nexport default Component;\n"]}
|