@neo4j-ndl/react 5.7.0 → 6.0.0-alpha.0.d77a467
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 +2 -2
- package/lib/cjs/accordion/Accordion.js.map +1 -1
- package/lib/cjs/ai/preview/Preview.js +1 -1
- package/lib/cjs/ai/preview/Preview.js.map +1 -1
- package/lib/cjs/ai/reasoning/Reasoning.js +2 -2
- package/lib/cjs/ai/reasoning/Reasoning.js.map +1 -1
- package/lib/cjs/ai/thinking/Thinking.js +2 -2
- package/lib/cjs/ai/thinking/Thinking.js.map +1 -1
- package/lib/cjs/avatar/Avatar.js +1 -1
- package/lib/cjs/avatar/Avatar.js.map +1 -1
- package/lib/cjs/banner/Banner.js +1 -1
- package/lib/cjs/banner/Banner.js.map +1 -1
- package/lib/cjs/data-grid/Components.js +1 -1
- package/lib/cjs/data-grid/Components.js.map +1 -1
- package/lib/cjs/date-picker/DatePicker.js +2 -2
- package/lib/cjs/date-picker/DatePicker.js.map +1 -1
- package/lib/cjs/dialog/Dialog.js +1 -1
- package/lib/cjs/dialog/Dialog.js.map +1 -1
- package/lib/cjs/drawer/Drawer.js +1 -1
- package/lib/cjs/drawer/Drawer.js.map +1 -1
- package/lib/cjs/dropzone/Dropzone.js +2 -2
- package/lib/cjs/dropzone/Dropzone.js.map +1 -1
- package/lib/cjs/inline-edit/InlineEdit.js +1 -1
- package/lib/cjs/inline-edit/InlineEdit.js.map +1 -1
- package/lib/cjs/inline-edit/utils.js +2 -4
- package/lib/cjs/inline-edit/utils.js.map +1 -1
- package/lib/cjs/side-navigation/SideNavigation.js +2 -2
- package/lib/cjs/side-navigation/SideNavigation.js.map +1 -1
- package/lib/cjs/spotlight/Spotlight.js +1 -1
- package/lib/cjs/spotlight/Spotlight.js.map +1 -1
- package/lib/cjs/tabs/Tabs.js +1 -1
- package/lib/cjs/tabs/Tabs.js.map +1 -1
- package/lib/cjs/tooltip/Tooltip.js +1 -1
- package/lib/cjs/tooltip/Tooltip.js.map +1 -1
- package/lib/cjs/tree-view/TreeViewTextItem.js +1 -1
- package/lib/cjs/tree-view/TreeViewTextItem.js.map +1 -1
- package/lib/esm/accordion/Accordion.mjs +2 -2
- package/lib/esm/accordion/Accordion.mjs.map +1 -1
- package/lib/esm/ai/preview/Preview.mjs +1 -1
- package/lib/esm/ai/preview/Preview.mjs.map +1 -1
- package/lib/esm/ai/reasoning/Reasoning.mjs +2 -2
- package/lib/esm/ai/reasoning/Reasoning.mjs.map +1 -1
- package/lib/esm/ai/thinking/Thinking.mjs +2 -2
- package/lib/esm/ai/thinking/Thinking.mjs.map +1 -1
- package/lib/esm/avatar/Avatar.mjs +1 -1
- package/lib/esm/avatar/Avatar.mjs.map +1 -1
- package/lib/esm/banner/Banner.mjs +1 -1
- package/lib/esm/banner/Banner.mjs.map +1 -1
- package/lib/esm/data-grid/Components.mjs +1 -1
- package/lib/esm/data-grid/Components.mjs.map +1 -1
- package/lib/esm/date-picker/DatePicker.mjs +2 -2
- package/lib/esm/date-picker/DatePicker.mjs.map +1 -1
- package/lib/esm/dialog/Dialog.mjs +1 -1
- package/lib/esm/dialog/Dialog.mjs.map +1 -1
- package/lib/esm/drawer/Drawer.mjs +1 -1
- package/lib/esm/drawer/Drawer.mjs.map +1 -1
- package/lib/esm/dropzone/Dropzone.mjs +2 -2
- package/lib/esm/dropzone/Dropzone.mjs.map +1 -1
- package/lib/esm/inline-edit/InlineEdit.mjs +1 -1
- package/lib/esm/inline-edit/InlineEdit.mjs.map +1 -1
- package/lib/esm/inline-edit/utils.mjs +2 -4
- package/lib/esm/inline-edit/utils.mjs.map +1 -1
- package/lib/esm/side-navigation/SideNavigation.mjs +2 -2
- package/lib/esm/side-navigation/SideNavigation.mjs.map +1 -1
- package/lib/esm/spotlight/Spotlight.mjs +1 -1
- package/lib/esm/spotlight/Spotlight.mjs.map +1 -1
- package/lib/esm/tabs/Tabs.mjs +1 -1
- package/lib/esm/tabs/Tabs.mjs.map +1 -1
- package/lib/esm/tooltip/Tooltip.mjs +1 -1
- package/lib/esm/tooltip/Tooltip.mjs.map +1 -1
- package/lib/esm/tree-view/TreeViewTextItem.mjs +1 -1
- package/lib/esm/tree-view/TreeViewTextItem.mjs.map +1 -1
- package/lib/types/ai/thinking/Thinking.d.ts.map +1 -1
- package/lib/types/inline-edit/InlineEdit.d.ts +1 -1
- package/lib/types/inline-edit/utils.d.ts.map +1 -1
- package/package.json +4 -3
- package/skills/ndl-react/SKILL.md +2 -2
- package/skills/ndl-react/components/accordion.md +3 -3
- package/skills/ndl-react/components/clean-icon-button.md +5 -5
- package/skills/ndl-react/components/date-picker.md +2 -2
- package/skills/ndl-react/components/dropzone.md +2 -2
- package/skills/ndl-react/components/icon-button.md +5 -5
- package/skills/ndl-react/components/inline-edit.md +1 -1
- package/skills/ndl-react/components/radio.md +1 -1
- package/skills/ndl-react/components/select-icon-button.md +6 -6
- package/skills/ndl-react/components/side-navigation.md +4 -4
- package/skills/ndl-react/components/skeleton.md +3 -3
- package/skills/ndl-react/components/status-indicator.md +5 -5
- package/skills/ndl-react/components/tabs.md +4 -4
- package/skills/ndl-react/components/timezone-picker.md +1 -1
- package/skills/ndl-react/components/tooltip.md +1 -1
- package/skills/ndl-react/components/typography.md +2 -2
- package/skills/ndl-react/references/styling.md +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Spotlight.mjs","names":[],"sources":["../../../src/spotlight/Spotlight.tsx"],"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(\n 'ndl-spotlight-image ndl-typography-body-medium',\n className,\n );\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' | 'shouldCloseOnClickOutside'\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 shouldCloseOnClickOutside = 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 initialFocus,\n isOpen: isActiveSpotlight(target) && isOpen && !!targetElement,\n onOpenChange,\n placement: placement ? placementTranslation[placement] : undefined,\n shouldCloseOnClickOutside,\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={(event) => {\n event.stopPropagation();\n event.preventDefault();\n }}\n onTouchStart={(event) => {\n event.stopPropagation();\n event.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: Sp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,oBAAoB;CAClD,MAAM;CACN,QAAQ;CACR,aAAa;CACb,OAAO;CACP,OAAO;AACT,CAAC"}
|
|
1
|
+
{"version":3,"file":"Spotlight.mjs","names":[],"sources":["../../../src/spotlight/Spotlight.tsx"],"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-3\"\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(\n 'ndl-spotlight-image ndl-typography-body-medium',\n className,\n );\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' | 'shouldCloseOnClickOutside'\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 shouldCloseOnClickOutside = 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 initialFocus,\n isOpen: isActiveSpotlight(target) && isOpen && !!targetElement,\n onOpenChange,\n placement: placement ? placementTranslation[placement] : undefined,\n shouldCloseOnClickOutside,\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={(event) => {\n event.stopPropagation();\n event.preventDefault();\n }}\n onTouchStart={(event) => {\n event.stopPropagation();\n event.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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0EE;CACA;CACA;CACA;CACA;CACA;;;CAoCA;CACA;CACA;CACA;CACA;CACA;;;CAoCA;CACA;CACA;CACA;CACA;CACA;CACA;;;CAiCA;CACA;CACA;CACA;CACA;CACA;;;CA8BA;CACA;CACA;CACA;CACA;CACA;;;CA2CA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;AA5OF,MAAM,2BACJ,cAAmD,IAAI;AAEzD,MAAM,6BAA2D;CAC/D,MAAM,MAAM,WAAW,wBAAwB;CAC/C,IAAI,QAAQ,MACV,MAAM,IAAI,MACR,2DACF;CAEF,OAAO;AACT;AAQA,MAAM,mBAAwD,SAQP;CARO,IAAA,EAC5D,UACA,WACA,IACA,OACA,gBACA,QAAA,MACG,YAAA,yBAAA,MAAA,SAAA;CAEH,MAAM,UAAU,WAAW,wBAAwB,SAAS;CAC5D,MAAM,EAAE,UAAU,gBAAgB,qBAAqB;CACvD,MAAM,YAA+B,OAAA,QAAA,OAAA,KAAA,IAAA,KAAM;CAE3C,gBAAgB;EACd,IAAI,QAAA,mBAAA,QAAA,mBAAA,KAAA,IAA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CAAA,CAAC,CAAA,GACG,SAAA,GAAA,CAAA,GAAA,EAAA,UAfN,CAiBE,oBAAC,OAAD,EAAM,SAAc,CAAA,IAClB,QAAQ,aAAa,KAAK,QAAQ,OAAO,MACzC,qBAAC,OAAD;IAAK,WAAU;IAAf,UAAA,CACE,oBAAC,YAAD;KAAY,SAAQ;KAAe,UAAA;IAA0B,CAAA,GAC5D,QAAQ,OAAO,KACd,oBAAC,OAAD;KAAK,WAAU;KAAwB,KAAK;KACzC,UAAA;IACE,CAAA,CAEJ;GAEJ,CAAA,CAAA,EAAA,CAAA,CAAA,CAC4B;;CACf,CAAA,EACR,CAAA;AAEpB;AAEA,mBAAmB,cAAc;AAEjC,MAAM,YAAY,OAAO,OAAO,oBAAoB;CAClD,MAAM;CACN,QAAQ;CACR,aAAa;CACb,OAAO;CACP,OAAO;AACT,CAAC"}
|
package/lib/esm/tabs/Tabs.mjs
CHANGED
|
@@ -302,7 +302,7 @@ const TabBadge = (_ref4) => {
|
|
|
302
302
|
const classes = classNames("ndl-tab-badge", className);
|
|
303
303
|
return /* @__PURE__ */ jsx(Typography, _objectSpread2(_objectSpread2({
|
|
304
304
|
ref,
|
|
305
|
-
variant: "subheading-
|
|
305
|
+
variant: "subheading-medium",
|
|
306
306
|
className: classes,
|
|
307
307
|
style,
|
|
308
308
|
htmlAttributes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tabs.mjs","names":[],"sources":["../../../src/tabs/Tabs.tsx"],"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 { useMergeRefs } from '@floating-ui/react';\nimport classNames from 'classnames';\nimport React, {\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport {\n type CommonProps,\n type PolymorphicCommonProps,\n type TooltipObjectProps,\n} from '../_common/types';\nimport { ArrowLeftCircleIconOutline } from '../icons/generated/heroIcons/ArrowLeftCircleIconOutline';\nimport { ArrowRightCircleIconOutline } from '../icons/generated/heroIcons/ArrowRightCircleIconOutline';\nimport { Tooltip } from '../tooltip';\nimport { Typography } from '../typography';\nimport { useTabsScrollOverflow } from './use-tabs-scroll-overflow';\n\n// Reusable scroll button component\nconst ScrollButton = ({\n direction,\n isVisible,\n onClick,\n onBackground,\n}: {\n direction: 'left' | 'right';\n isVisible: boolean;\n onClick: () => void;\n onBackground: React.ComponentProps<typeof TabsComponent>['onBackground'];\n}) => {\n const Icon =\n direction === 'left'\n ? ArrowLeftCircleIconOutline\n : ArrowRightCircleIconOutline;\n const positionClass =\n direction === 'left' ? 'ndl-scroll-left-item' : 'ndl-scroll-right-item';\n\n return (\n <div\n className={classNames('ndl-scroll-item', positionClass, {\n 'ndl-scroll-item-hidden': !isVisible,\n 'ndl-scroll-item-on-background-default': onBackground === 'default',\n 'ndl-scroll-item-on-background-weak': onBackground === 'weak',\n })}\n >\n <button\n type=\"button\"\n tabIndex={-1}\n className=\"ndl-scroll-icon-wrapper\"\n onClick={onClick}\n aria-hidden=\"true\"\n >\n <Icon className=\"ndl-scroll-icon\" />\n </button>\n </div>\n );\n};\n\ntype TabId = string;\ntype Size = 'small' | 'large';\ntype Fill = 'underline' | 'filled';\n\ntype BaseTabsProps<T extends TabId> = {\n /** The currently active tabId */\n value: T;\n /** Callback function triggered when a new tab is selected */\n onChange: (event: T) => void;\n /** The content dislayed in the tabs */\n children: React.ReactNode | string;\n /** The fill type of the tabs */\n fill?: Fill;\n /** The size of the tabs */\n size?: Size;\n /** What background the Tabs is placed on. This affects the gradient background of the scroll navigation buttons. */\n onBackground?: 'weak' | 'default';\n};\n\ntype TabsContextType<T extends TabId> = Required<\n Pick<BaseTabsProps<T>, 'fill' | 'size' | 'onChange' | 'value'>\n> & {\n registerTab: (tabId: T, ref: React.RefObject<HTMLElement | null>) => void;\n unregisterTab: (tabId: T) => void;\n scrollTabIntoView: (tabId: T) => void;\n firstTabId: T | null;\n isValuePresent: boolean;\n};\n\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nconst TabsContext = React.createContext<TabsContextType<any> | null>(null);\n\nconst useTabsContext = () => {\n const context = useContext(TabsContext);\n\n if (context === null) {\n throw new Error('Tab used without context');\n }\n\n return context;\n};\n\nconst getTabPanelId = (tabId: TabId) => `tabpanel-${tabId}`;\n\nconst getGeneralTabClasses = (size: Size, fill: Fill) => {\n return {\n 'ndl-filled-tab': fill === 'filled',\n 'ndl-large': size === 'large',\n 'ndl-small': size === 'small',\n 'ndl-underline-tab': fill === 'underline',\n };\n};\n\nconst TabsComponent = <U extends TabId, T extends React.ElementType = 'div'>({\n children,\n size = 'large',\n fill = 'underline',\n onChange,\n value,\n onBackground = 'weak',\n className,\n style,\n as,\n htmlAttributes,\n ref,\n ...restProps\n}: PolymorphicCommonProps<T, BaseTabsProps<U>>) => {\n const tabRefs = useRef<Map<U, React.RefObject<HTMLElement | null>>>(\n new Map(),\n );\n const containerRef = useRef<HTMLElement>(null);\n const scrollContainerRef = useRef<HTMLDivElement>(null);\n const mergedRef = useMergeRefs([containerRef, ref]);\n const [firstTabId, setFirstTabId] = useState<U | null>(null);\n const [isValuePresent, setIsValuePresent] = useState(false);\n const valueRef = useRef(value);\n\n // Use the custom hook for scroll overflow behavior\n const { scrollState, scrollToNextItem, checkOverflow } =\n useTabsScrollOverflow(scrollContainerRef);\n\n useEffect(() => {\n valueRef.current = value;\n setIsValuePresent(tabRefs.current.has(value));\n }, [value]);\n\n const registerTab = useCallback(\n (tabId: U, tabRef: React.RefObject<HTMLElement | null>) => {\n tabRefs.current.set(tabId, tabRef);\n const first = tabRefs.current.keys().next().value ?? null;\n setFirstTabId((prev) => (prev === first ? prev : first));\n\n if (tabId === valueRef.current) {\n setIsValuePresent(true);\n }\n },\n [],\n );\n\n const unregisterTab = useCallback((tabId: U) => {\n tabRefs.current.delete(tabId);\n const first = tabRefs.current.keys().next().value ?? null;\n setFirstTabId((prev) => (prev === first ? prev : first));\n\n if (tabId === valueRef.current) {\n setIsValuePresent(false);\n }\n }, []);\n\n // Check overflow when children change\n useEffect(() => {\n checkOverflow();\n }, [checkOverflow, children]);\n\n const scrollTabIntoView = useCallback((tabId: U) => {\n const tabRef = tabRefs.current.get(tabId);\n const scrollContainer = scrollContainerRef.current;\n\n if (tabRef?.current && scrollContainer) {\n const tabRect = tabRef.current.getBoundingClientRect();\n const containerRect = scrollContainer.getBoundingClientRect();\n const containerCenter = containerRect.left + containerRect.width / 2;\n\n const targetScrollLeft =\n scrollContainer.scrollLeft +\n (tabRect.left - containerCenter + tabRect.width / 2);\n\n scrollContainer.scrollTo({\n behavior: 'smooth',\n left: targetScrollLeft,\n });\n }\n }, []);\n\n const handleKeyDown = useCallback(\n (event: React.KeyboardEvent) => {\n if (event.key !== 'ArrowLeft' && event.key !== 'ArrowRight') {\n return;\n }\n\n event.preventDefault();\n\n const tabIds = Array.from(tabRefs.current.keys());\n const focusedElement = document.activeElement;\n\n // Find the currently focused tab\n let currentIndex = -1;\n for (let index = 0; index < tabIds.length; index++) {\n const tabRef = tabRefs.current.get(tabIds[index]);\n if (tabRef?.current === focusedElement) {\n currentIndex = index;\n break;\n }\n }\n\n // If no tab is focused, focus the active tab. Or the first tab if the active tab is not present.\n if (currentIndex === -1) {\n const activeTabRef = tabRefs.current.get(value);\n if (activeTabRef?.current) {\n activeTabRef.current.focus();\n } else if (!isValuePresent && firstTabId !== null) {\n const firstTabRef = tabRefs.current.get(firstTabId);\n if (firstTabRef?.current) {\n firstTabRef.current.focus();\n }\n }\n return;\n }\n\n let nextIndex: number;\n\n if (event.key === 'ArrowRight') {\n nextIndex = currentIndex === tabIds.length - 1 ? 0 : currentIndex + 1;\n } else {\n nextIndex = currentIndex === 0 ? tabIds.length - 1 : currentIndex - 1;\n }\n\n const nextTabId = tabIds[nextIndex];\n const nextTabRef = tabRefs.current.get(nextTabId);\n\n if (nextTabRef?.current) {\n nextTabRef.current.focus();\n scrollTabIntoView(nextTabId);\n }\n },\n [value, scrollTabIntoView, firstTabId, isValuePresent],\n );\n\n const classes = classNames(\n 'ndl-tabs',\n getGeneralTabClasses(size, fill),\n className,\n );\n\n const Component: React.ElementType = as ?? 'div';\n\n return (\n <Component\n className={classes}\n style={style}\n role=\"tablist\"\n aria-orientation=\"horizontal\"\n onKeyDown={handleKeyDown}\n ref={mergedRef}\n {...restProps}\n {...htmlAttributes}\n >\n <ScrollButton\n direction=\"left\"\n isVisible={scrollState.isLeftVisible}\n onClick={() => scrollToNextItem('left')}\n onBackground={onBackground}\n />\n <ScrollButton\n direction=\"right\"\n isVisible={scrollState.isRightVisible}\n onClick={() => scrollToNextItem('right')}\n onBackground={onBackground}\n />\n <TabsContext.Provider\n value={{\n fill,\n firstTabId,\n isValuePresent,\n onChange,\n registerTab,\n scrollTabIntoView,\n size,\n unregisterTab,\n value,\n }}\n >\n <div className=\"ndl-tabs-container\" ref={scrollContainerRef}>\n {children}\n </div>\n </TabsContext.Provider>\n </Component>\n );\n};\n\nTabsComponent.displayName = 'Tabs';\n\n/**\n * @remarks\n * When the `description` prop is set, hovering over the tab will show a tooltip with the text provided in the `description` prop. `tooltipProps` can be used to customize the tooltip appearance. The `TooltipObjectProps` type is defined as: `{ root?: Partial<React.ComponentProps<typeof Tooltip>>; trigger?: Partial<React.ComponentProps<typeof Tooltip.Trigger>>; content?: Partial<React.ComponentProps<typeof Tooltip.Content>>; }`, see the Tooltip component for more details.\n */\ntype TabProps<T extends TabId> = {\n /** The id of the tab */\n id: T;\n /** The content of the tab */\n children: React.ReactNode | string;\n /** A string that will be shown as a tooltip when hovering over the button it also acts as an aria-label- {@link https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-label} */\n description?: string;\n /** Props for the tooltip component. */\n tooltipProps?: TooltipObjectProps;\n /** Trailing content that will be rendered after the tab content. Badges belong here. */\n trailingContent?: React.ReactNode;\n /** Additional class name */\n className?: string;\n /** Whether the tab is disabled */\n isDisabled?: boolean;\n};\n\nconst TabsTab = <\n U extends TabId = TabId,\n T extends React.ElementType = 'button',\n>({\n children,\n id: tabId,\n isDisabled = false,\n className,\n description,\n tooltipProps,\n style,\n as,\n htmlAttributes,\n ref,\n trailingContent,\n ...restProps\n}: PolymorphicCommonProps<T, TabProps<U>>) => {\n const {\n size,\n fill,\n value,\n onChange,\n registerTab,\n unregisterTab,\n scrollTabIntoView,\n firstTabId,\n isValuePresent,\n } = useTabsContext();\n const internalRef = useRef<HTMLElement>(null);\n\n // Create a merged ref that handles both ref objects and ref functions\n const mergedRef = useMergeRefs([\n internalRef as React.RefObject<HTMLElement>,\n ref as React.RefObject<HTMLElement>,\n ]);\n\n // Register/unregister tab for keyboard navigation\n useEffect(() => {\n registerTab(tabId, internalRef);\n\n return () => {\n unregisterTab(tabId);\n };\n }, [tabId, registerTab, unregisterTab]);\n\n const baseClasses = classNames({\n ...getGeneralTabClasses(size, fill),\n 'ndl-disabled': isDisabled,\n 'ndl-selected': value === tabId,\n });\n\n const Component: React.ElementType = as ?? 'button';\n\n const classes = classNames('ndl-tab', baseClasses, className);\n\n // Only the active tab should be in the tab sequence initially\n // Other tabs can be focused via arrow keys but are not in tab sequence\n const tabIndex =\n value === tabId || (!isValuePresent && tabId === firstTabId) ? 0 : -1;\n\n return (\n <Tooltip\n type=\"simple\"\n {...tooltipProps?.root}\n isDisabled={description === undefined}\n >\n <Tooltip.Trigger {...tooltipProps?.trigger} hasButtonWrapper>\n <Component\n className={classes}\n style={style}\n onClick={() => {\n if (!isDisabled) {\n onChange(tabId);\n scrollTabIntoView(tabId);\n }\n }}\n role=\"tab\"\n id={tabId}\n aria-disabled={isDisabled}\n aria-label={description}\n aria-selected={value === tabId}\n aria-controls={getTabPanelId(tabId)}\n tabIndex={tabIndex}\n ref={mergedRef}\n {...restProps}\n {...htmlAttributes}\n >\n <span className=\"ndl-tab-content\">{children}</span>\n {trailingContent}\n {fill === 'underline' && <span className=\"ndl-tab-underline\" />}\n </Component>\n </Tooltip.Trigger>\n <Tooltip.Content {...tooltipProps?.content}>\n {description}\n </Tooltip.Content>\n </Tooltip>\n );\n};\n\nTabsTab.displayName = 'Tabs.Tab';\n\ntype TabPanelProps = {\n /** The content displayed in the tab panel */\n children: React.ReactNode;\n /** The currently selected tabId. The tab is visible if the value is equal to the tabId */\n value: TabId;\n /** The id of the tab panel */\n tabId: TabId;\n /** Additional class name */\n className?: string;\n};\n\nconst TabsTabPanel = <T extends React.ElementType = 'div'>({\n as,\n children,\n value,\n tabId,\n style,\n className,\n htmlAttributes,\n ref,\n ...restProps\n}: PolymorphicCommonProps<T, TabPanelProps>) => {\n const Component: React.ElementType = as ?? 'div';\n\n return (\n <>\n {value === tabId ? (\n <Component\n role=\"tabpanel\"\n id={getTabPanelId(tabId)}\n aria-labelledby={tabId}\n style={style}\n className={classNames(className)}\n ref={ref}\n {...restProps}\n {...htmlAttributes}\n >\n {children}\n </Component>\n ) : null}\n </>\n );\n};\n\nTabsTabPanel.displayName = 'Tabs.TabPanel';\n\ntype TabBadgeProps = {\n /** The content of the badge */\n children: React.ReactNode;\n};\n\nconst TabBadge = ({\n children,\n ref,\n htmlAttributes,\n style,\n className,\n ...restProps\n}: CommonProps<'span', TabBadgeProps>) => {\n const classes = classNames('ndl-tab-badge', className);\n return (\n <Typography\n ref={ref}\n variant=\"subheading-small\"\n className={classes}\n style={style}\n htmlAttributes={htmlAttributes}\n {...restProps}\n >\n {children}\n </Typography>\n );\n};\n\nconst Tabs = Object.assign(TabsComponent, {\n Badge: TabBadge,\n Tab: TabsTab,\n TabPanel: TabsTabPan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,QAAQ,cAAc;AAatB,MAAM,gBAAqD,UAUX;CAVW,IAAA,EACzD,IACA,UACA,OACA,OACA,OACA,WACA,gBACA,QAAA,OACG,YAAA,yBAAA,OAAA,UAAA;CAIH,OACE,oBAAA,YAAA,EAAA,UACG,UAAU,QACT,oBAL+B,OAAA,QAAA,OAAA,KAAA,IAAA,KAAM,OAAA,eAAA,eAAA,eAAA;EAMnC,MAAK;EACL,IAAI,cAAc,KAAK;EACvB,mBAAiB;EACV;EACP,WAAW,WAAW,SAAS;EAC1B;CACD,GAAA,SAAA,GACA,cAAA,GAAA,CAAA,GAAA,EAEH,SAAA,CACQ,CAAA,IACT,KACJ,CAAA;AAEN;AAEA,aAAa,cAAc;AAO3B,MAAM,YAAY,UAOwB;CAPxB,IAAA,EAChB,UACA,KACA,gBACA,OACA,cAAA,OACG,YAAA,yBAAA,OAAA,UAAA;CAEH,MAAM,UAAU,WAAW,iBAAiB,SAAS;CACrD,OACE,oBAAC,YAAA,eAAA,eAAA;EACM;EACL,SAAQ;EACR,WAAW;EACJ;EACS;CACZ,GAAA,SAAA,GAAA,CAAA,GAAA,EAEH,SAAA,CACS,CAAA;AAEhB;AAEA,MAAM,OAAO,OAAO,OAAO,eAAe;CACxC,OAAO;CACP,KAAK;CACL,UAAU;AACZ,CAAC"}
|
|
1
|
+
{"version":3,"file":"Tabs.mjs","names":[],"sources":["../../../src/tabs/Tabs.tsx"],"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 { useMergeRefs } from '@floating-ui/react';\nimport classNames from 'classnames';\nimport React, {\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport {\n type CommonProps,\n type PolymorphicCommonProps,\n type TooltipObjectProps,\n} from '../_common/types';\nimport { ArrowLeftCircleIconOutline } from '../icons/generated/heroIcons/ArrowLeftCircleIconOutline';\nimport { ArrowRightCircleIconOutline } from '../icons/generated/heroIcons/ArrowRightCircleIconOutline';\nimport { Tooltip } from '../tooltip';\nimport { Typography } from '../typography';\nimport { useTabsScrollOverflow } from './use-tabs-scroll-overflow';\n\n// Reusable scroll button component\nconst ScrollButton = ({\n direction,\n isVisible,\n onClick,\n onBackground,\n}: {\n direction: 'left' | 'right';\n isVisible: boolean;\n onClick: () => void;\n onBackground: React.ComponentProps<typeof TabsComponent>['onBackground'];\n}) => {\n const Icon =\n direction === 'left'\n ? ArrowLeftCircleIconOutline\n : ArrowRightCircleIconOutline;\n const positionClass =\n direction === 'left' ? 'ndl-scroll-left-item' : 'ndl-scroll-right-item';\n\n return (\n <div\n className={classNames('ndl-scroll-item', positionClass, {\n 'ndl-scroll-item-hidden': !isVisible,\n 'ndl-scroll-item-on-background-default': onBackground === 'default',\n 'ndl-scroll-item-on-background-weak': onBackground === 'weak',\n })}\n >\n <button\n type=\"button\"\n tabIndex={-1}\n className=\"ndl-scroll-icon-wrapper\"\n onClick={onClick}\n aria-hidden=\"true\"\n >\n <Icon className=\"ndl-scroll-icon\" />\n </button>\n </div>\n );\n};\n\ntype TabId = string;\ntype Size = 'small' | 'large';\ntype Fill = 'underline' | 'filled';\n\ntype BaseTabsProps<T extends TabId> = {\n /** The currently active tabId */\n value: T;\n /** Callback function triggered when a new tab is selected */\n onChange: (event: T) => void;\n /** The content dislayed in the tabs */\n children: React.ReactNode | string;\n /** The fill type of the tabs */\n fill?: Fill;\n /** The size of the tabs */\n size?: Size;\n /** What background the Tabs is placed on. This affects the gradient background of the scroll navigation buttons. */\n onBackground?: 'weak' | 'default';\n};\n\ntype TabsContextType<T extends TabId> = Required<\n Pick<BaseTabsProps<T>, 'fill' | 'size' | 'onChange' | 'value'>\n> & {\n registerTab: (tabId: T, ref: React.RefObject<HTMLElement | null>) => void;\n unregisterTab: (tabId: T) => void;\n scrollTabIntoView: (tabId: T) => void;\n firstTabId: T | null;\n isValuePresent: boolean;\n};\n\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nconst TabsContext = React.createContext<TabsContextType<any> | null>(null);\n\nconst useTabsContext = () => {\n const context = useContext(TabsContext);\n\n if (context === null) {\n throw new Error('Tab used without context');\n }\n\n return context;\n};\n\nconst getTabPanelId = (tabId: TabId) => `tabpanel-${tabId}`;\n\nconst getGeneralTabClasses = (size: Size, fill: Fill) => {\n return {\n 'ndl-filled-tab': fill === 'filled',\n 'ndl-large': size === 'large',\n 'ndl-small': size === 'small',\n 'ndl-underline-tab': fill === 'underline',\n };\n};\n\nconst TabsComponent = <U extends TabId, T extends React.ElementType = 'div'>({\n children,\n size = 'large',\n fill = 'underline',\n onChange,\n value,\n onBackground = 'weak',\n className,\n style,\n as,\n htmlAttributes,\n ref,\n ...restProps\n}: PolymorphicCommonProps<T, BaseTabsProps<U>>) => {\n const tabRefs = useRef<Map<U, React.RefObject<HTMLElement | null>>>(\n new Map(),\n );\n const containerRef = useRef<HTMLElement>(null);\n const scrollContainerRef = useRef<HTMLDivElement>(null);\n const mergedRef = useMergeRefs([containerRef, ref]);\n const [firstTabId, setFirstTabId] = useState<U | null>(null);\n const [isValuePresent, setIsValuePresent] = useState(false);\n const valueRef = useRef(value);\n\n // Use the custom hook for scroll overflow behavior\n const { scrollState, scrollToNextItem, checkOverflow } =\n useTabsScrollOverflow(scrollContainerRef);\n\n useEffect(() => {\n valueRef.current = value;\n setIsValuePresent(tabRefs.current.has(value));\n }, [value]);\n\n const registerTab = useCallback(\n (tabId: U, tabRef: React.RefObject<HTMLElement | null>) => {\n tabRefs.current.set(tabId, tabRef);\n const first = tabRefs.current.keys().next().value ?? null;\n setFirstTabId((prev) => (prev === first ? prev : first));\n\n if (tabId === valueRef.current) {\n setIsValuePresent(true);\n }\n },\n [],\n );\n\n const unregisterTab = useCallback((tabId: U) => {\n tabRefs.current.delete(tabId);\n const first = tabRefs.current.keys().next().value ?? null;\n setFirstTabId((prev) => (prev === first ? prev : first));\n\n if (tabId === valueRef.current) {\n setIsValuePresent(false);\n }\n }, []);\n\n // Check overflow when children change\n useEffect(() => {\n checkOverflow();\n }, [checkOverflow, children]);\n\n const scrollTabIntoView = useCallback((tabId: U) => {\n const tabRef = tabRefs.current.get(tabId);\n const scrollContainer = scrollContainerRef.current;\n\n if (tabRef?.current && scrollContainer) {\n const tabRect = tabRef.current.getBoundingClientRect();\n const containerRect = scrollContainer.getBoundingClientRect();\n const containerCenter = containerRect.left + containerRect.width / 2;\n\n const targetScrollLeft =\n scrollContainer.scrollLeft +\n (tabRect.left - containerCenter + tabRect.width / 2);\n\n scrollContainer.scrollTo({\n behavior: 'smooth',\n left: targetScrollLeft,\n });\n }\n }, []);\n\n const handleKeyDown = useCallback(\n (event: React.KeyboardEvent) => {\n if (event.key !== 'ArrowLeft' && event.key !== 'ArrowRight') {\n return;\n }\n\n event.preventDefault();\n\n const tabIds = Array.from(tabRefs.current.keys());\n const focusedElement = document.activeElement;\n\n // Find the currently focused tab\n let currentIndex = -1;\n for (let index = 0; index < tabIds.length; index++) {\n const tabRef = tabRefs.current.get(tabIds[index]);\n if (tabRef?.current === focusedElement) {\n currentIndex = index;\n break;\n }\n }\n\n // If no tab is focused, focus the active tab. Or the first tab if the active tab is not present.\n if (currentIndex === -1) {\n const activeTabRef = tabRefs.current.get(value);\n if (activeTabRef?.current) {\n activeTabRef.current.focus();\n } else if (!isValuePresent && firstTabId !== null) {\n const firstTabRef = tabRefs.current.get(firstTabId);\n if (firstTabRef?.current) {\n firstTabRef.current.focus();\n }\n }\n return;\n }\n\n let nextIndex: number;\n\n if (event.key === 'ArrowRight') {\n nextIndex = currentIndex === tabIds.length - 1 ? 0 : currentIndex + 1;\n } else {\n nextIndex = currentIndex === 0 ? tabIds.length - 1 : currentIndex - 1;\n }\n\n const nextTabId = tabIds[nextIndex];\n const nextTabRef = tabRefs.current.get(nextTabId);\n\n if (nextTabRef?.current) {\n nextTabRef.current.focus();\n scrollTabIntoView(nextTabId);\n }\n },\n [value, scrollTabIntoView, firstTabId, isValuePresent],\n );\n\n const classes = classNames(\n 'ndl-tabs',\n getGeneralTabClasses(size, fill),\n className,\n );\n\n const Component: React.ElementType = as ?? 'div';\n\n return (\n <Component\n className={classes}\n style={style}\n role=\"tablist\"\n aria-orientation=\"horizontal\"\n onKeyDown={handleKeyDown}\n ref={mergedRef}\n {...restProps}\n {...htmlAttributes}\n >\n <ScrollButton\n direction=\"left\"\n isVisible={scrollState.isLeftVisible}\n onClick={() => scrollToNextItem('left')}\n onBackground={onBackground}\n />\n <ScrollButton\n direction=\"right\"\n isVisible={scrollState.isRightVisible}\n onClick={() => scrollToNextItem('right')}\n onBackground={onBackground}\n />\n <TabsContext.Provider\n value={{\n fill,\n firstTabId,\n isValuePresent,\n onChange,\n registerTab,\n scrollTabIntoView,\n size,\n unregisterTab,\n value,\n }}\n >\n <div className=\"ndl-tabs-container\" ref={scrollContainerRef}>\n {children}\n </div>\n </TabsContext.Provider>\n </Component>\n );\n};\n\nTabsComponent.displayName = 'Tabs';\n\n/**\n * @remarks\n * When the `description` prop is set, hovering over the tab will show a tooltip with the text provided in the `description` prop. `tooltipProps` can be used to customize the tooltip appearance. The `TooltipObjectProps` type is defined as: `{ root?: Partial<React.ComponentProps<typeof Tooltip>>; trigger?: Partial<React.ComponentProps<typeof Tooltip.Trigger>>; content?: Partial<React.ComponentProps<typeof Tooltip.Content>>; }`, see the Tooltip component for more details.\n */\ntype TabProps<T extends TabId> = {\n /** The id of the tab */\n id: T;\n /** The content of the tab */\n children: React.ReactNode | string;\n /** A string that will be shown as a tooltip when hovering over the button it also acts as an aria-label- {@link https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-label} */\n description?: string;\n /** Props for the tooltip component. */\n tooltipProps?: TooltipObjectProps;\n /** Trailing content that will be rendered after the tab content. Badges belong here. */\n trailingContent?: React.ReactNode;\n /** Additional class name */\n className?: string;\n /** Whether the tab is disabled */\n isDisabled?: boolean;\n};\n\nconst TabsTab = <\n U extends TabId = TabId,\n T extends React.ElementType = 'button',\n>({\n children,\n id: tabId,\n isDisabled = false,\n className,\n description,\n tooltipProps,\n style,\n as,\n htmlAttributes,\n ref,\n trailingContent,\n ...restProps\n}: PolymorphicCommonProps<T, TabProps<U>>) => {\n const {\n size,\n fill,\n value,\n onChange,\n registerTab,\n unregisterTab,\n scrollTabIntoView,\n firstTabId,\n isValuePresent,\n } = useTabsContext();\n const internalRef = useRef<HTMLElement>(null);\n\n // Create a merged ref that handles both ref objects and ref functions\n const mergedRef = useMergeRefs([\n internalRef as React.RefObject<HTMLElement>,\n ref as React.RefObject<HTMLElement>,\n ]);\n\n // Register/unregister tab for keyboard navigation\n useEffect(() => {\n registerTab(tabId, internalRef);\n\n return () => {\n unregisterTab(tabId);\n };\n }, [tabId, registerTab, unregisterTab]);\n\n const baseClasses = classNames({\n ...getGeneralTabClasses(size, fill),\n 'ndl-disabled': isDisabled,\n 'ndl-selected': value === tabId,\n });\n\n const Component: React.ElementType = as ?? 'button';\n\n const classes = classNames('ndl-tab', baseClasses, className);\n\n // Only the active tab should be in the tab sequence initially\n // Other tabs can be focused via arrow keys but are not in tab sequence\n const tabIndex =\n value === tabId || (!isValuePresent && tabId === firstTabId) ? 0 : -1;\n\n return (\n <Tooltip\n type=\"simple\"\n {...tooltipProps?.root}\n isDisabled={description === undefined}\n >\n <Tooltip.Trigger {...tooltipProps?.trigger} hasButtonWrapper>\n <Component\n className={classes}\n style={style}\n onClick={() => {\n if (!isDisabled) {\n onChange(tabId);\n scrollTabIntoView(tabId);\n }\n }}\n role=\"tab\"\n id={tabId}\n aria-disabled={isDisabled}\n aria-label={description}\n aria-selected={value === tabId}\n aria-controls={getTabPanelId(tabId)}\n tabIndex={tabIndex}\n ref={mergedRef}\n {...restProps}\n {...htmlAttributes}\n >\n <span className=\"ndl-tab-content\">{children}</span>\n {trailingContent}\n {fill === 'underline' && <span className=\"ndl-tab-underline\" />}\n </Component>\n </Tooltip.Trigger>\n <Tooltip.Content {...tooltipProps?.content}>\n {description}\n </Tooltip.Content>\n </Tooltip>\n );\n};\n\nTabsTab.displayName = 'Tabs.Tab';\n\ntype TabPanelProps = {\n /** The content displayed in the tab panel */\n children: React.ReactNode;\n /** The currently selected tabId. The tab is visible if the value is equal to the tabId */\n value: TabId;\n /** The id of the tab panel */\n tabId: TabId;\n /** Additional class name */\n className?: string;\n};\n\nconst TabsTabPanel = <T extends React.ElementType = 'div'>({\n as,\n children,\n value,\n tabId,\n style,\n className,\n htmlAttributes,\n ref,\n ...restProps\n}: PolymorphicCommonProps<T, TabPanelProps>) => {\n const Component: React.ElementType = as ?? 'div';\n\n return (\n <>\n {value === tabId ? (\n <Component\n role=\"tabpanel\"\n id={getTabPanelId(tabId)}\n aria-labelledby={tabId}\n style={style}\n className={classNames(className)}\n ref={ref}\n {...restProps}\n {...htmlAttributes}\n >\n {children}\n </Component>\n ) : null}\n </>\n );\n};\n\nTabsTabPanel.displayName = 'Tabs.TabPanel';\n\ntype TabBadgeProps = {\n /** The content of the badge */\n children: React.ReactNode;\n};\n\nconst TabBadge = ({\n children,\n ref,\n htmlAttributes,\n style,\n className,\n ...restProps\n}: CommonProps<'span', TabBadgeProps>) => {\n const classes = classNames('ndl-tab-badge', className);\n return (\n <Typography\n ref={ref}\n variant=\"subheading-medium\"\n className={classes}\n style={style}\n htmlAttributes={htmlAttributes}\n {...restProps}\n >\n {children}\n </Typography>\n );\n};\n\nconst Tabs = Object.assign(TabsComponent, {\n Badge: TabBadge,\n Tab: TabsTab,\n TabPanel: TabsTabPanel,\n});\n\nexport { Tabs };\n"],"mappings":";;;;;;;;;;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VW,IAAA,EACzD,IACA,UACA,OACA,OACA,OACA,WACA,gBACA,QAAA,OACG,YAAA,yBAAA,OAAA,UAAA;CAIH,OACE,oBAAA,YAAA,EAAA,UACG,UAAU,QACT,oBAL+B,OAAA,QAAA,OAAA,KAAA,IAAA,KAAM,OAAA,eAAA,eAAA,eAAA;EAMnC,MAAK;EACL,IAAI,cAAc,KAAK;EACvB,mBAAiB;EACV;EACP,WAAW,WAAW,SAAS;EAC1B;CACD,GAAA,SAAA,GACA,cAAA,GAAA,CAAA,GAAA,EAEH,SAAA,CACQ,CAAA,IACT,KACJ,CAAA;AAEN;AAEA,aAAa,cAAc;AAO3B,MAAM,YAAY,UAOwB;CAPxB,IAAA,EAChB,UACA,KACA,gBACA,OACA,cAAA,OACG,YAAA,yBAAA,OAAA,UAAA;CAEH,MAAM,UAAU,WAAW,iBAAiB,SAAS;CACrD,OACE,oBAAC,YAAA,eAAA,eAAA;EACM;EACL,SAAQ;EACR,WAAW;EACJ;EACS;CACZ,GAAA,SAAA,GAAA,CAAA,GAAA,EAEH,SAAA,CACS,CAAA;AAEhB;AAEA,MAAM,OAAO,OAAO,OAAO,eAAe;CACxC,OAAO;CACP,KAAK;CACL,UAAU;AACZ,CAAC"}
|
|
@@ -162,7 +162,7 @@ const TooltipContent = (_ref2) => {
|
|
|
162
162
|
});
|
|
163
163
|
};
|
|
164
164
|
const TooltipHeader = (_ref3) => {
|
|
165
|
-
let { children, passThroughProps, typographyVariant = "subheading-
|
|
165
|
+
let { children, passThroughProps, typographyVariant = "subheading-large", className, style, htmlAttributes, ref } = _ref3, restProps = _objectWithoutProperties(_ref3, _excluded3);
|
|
166
166
|
const context = useTooltipContext();
|
|
167
167
|
const classes = classNames("ndl-tooltip-header", className);
|
|
168
168
|
useEffect(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.mjs","names":[],"sources":["../../../src/tooltip/Tooltip.tsx"],"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 type AutoUpdateOptions,\n FloatingFocusManager,\n FloatingPortal,\n type Placement,\n type UseFloatingOptions,\n useMergeRefs,\n} from '@floating-ui/react';\nimport classNames from 'classnames';\nimport React, { useEffect } from 'react';\n\nimport { type CommonProps } from '../_common/types';\nimport { ConditionalWrap } from '../conditional-wrap';\nimport { useIsInsideDialog } from '../dialog/dialog-context';\nimport { useNeedleTheme } from '../theme';\nimport { Typography, type TypographyVariants } from '../typography';\nimport { TooltipContext, useTooltip, useTooltipContext } from './use-tooltip';\n\nexport type TooltipProps = {\n /** Content displayed inside the tooltip. Wraps `Tooltip.Trigger`, `Tooltip.Content`, and optional parts */\n children: React.ReactNode;\n /** Whether the tooltip is disabled */\n isDisabled?: boolean;\n /** Whether the tooltip should be open on first render */\n isInitialOpen?: boolean;\n /** Placement of the tooltip content relative to the trigger */\n placement?: Placement;\n /** Controls the open state . If omitted, the tooltip manages its own state */\n isOpen?: boolean;\n /**\n * Visual style of the tooltip content. `simple` renders plain text, `rich` renders a composable panel\n */\n type: 'simple' | 'rich';\n /** Whether the content is rendered in a portal. */\n isPortaled?: boolean;\n /** Callback fired when the open state changes, if omitted, the tooltip manages its own state using internal hooks */\n onOpenChange?: UseFloatingOptions['onOpenChange'];\n /** Positioning strategy of the tooltip. Defaults to `fixed` when inside a dialog, otherwise `absolute` */\n floatingStrategy?: 'absolute' | 'fixed';\n /** Hover open/close delays in milliseconds */\n hoverDelay?: {\n open: number;\n close: number;\n };\n /** Whether the tooltip should close when the reference element is clicked. Useful when the trigger moves after click. */\n shouldCloseOnReferenceClick?: boolean;\n autoUpdateOptions?: AutoUpdateOptions;\n /**\n * Whether the tooltip should be positioned at the mouse cursor. Only applies to 'simple' tooltips with mouse hover.\n * `true` follows the cursor continuously along one axis derived from `placement` (horizontal for top/bottom, vertical for left/right).\n * `'initial'` opens the tooltip at the cursor's position (both axes) and keeps it there, like the native `title` attribute; `placement` controls which side of that point the tooltip appears on.\n */\n followCursor?: boolean | 'initial';\n};\n\nconst TooltipComponent = ({\n children,\n isDisabled = false,\n type,\n isInitialOpen,\n placement,\n isOpen,\n onOpenChange,\n isPortaled: isPortaledProp,\n floatingStrategy: strategyProp,\n hoverDelay,\n shouldCloseOnReferenceClick,\n autoUpdateOptions,\n followCursor,\n}: TooltipProps) => {\n const isInsideDialog = useIsInsideDialog();\n const strategy = isInsideDialog ? 'fixed' : 'absolute';\n const isPortaled = !isInsideDialog;\n\n const tooltip = useTooltip({\n autoUpdateOptions,\n followCursor,\n hoverDelay,\n isDisabled,\n isInitialOpen,\n // if isDisabled is true tooltip will not open otherwise either controlled or uncontrolled depending on if isOpen is passed\n isOpen: isDisabled === true ? false : isOpen,\n isPortaled: isPortaledProp ?? isPortaled,\n onOpenChange,\n placement,\n shouldCloseOnReferenceClick,\n strategy: strategyProp ?? strategy,\n type,\n });\n\n return (\n <TooltipContext.Provider value={tooltip}>\n {children}\n </TooltipContext.Provider>\n );\n};\n\nTooltipComponent.displayName = 'Tooltip';\n\ntype TooltipTriggerProps = {\n /** Content displayed inside the trigger element */\n children: React.ReactNode;\n /** Whether the trigger element can be any element without an extra button wrapper. The child element will be cloned with the necessary trigger props and merged refs */\n hasButtonWrapper?: boolean;\n};\n\nconst TooltipTrigger = ({\n children,\n hasButtonWrapper = false,\n htmlAttributes,\n className,\n style,\n ref,\n ...restProps\n}: CommonProps<'button', TooltipTriggerProps>) => {\n const context = useTooltipContext();\n\n // Example from floating-ui\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n const childrenProps = (children as any).props;\n const mergedRefs = useMergeRefs([\n context.refs.setReference,\n ref,\n childrenProps?.ref,\n ]);\n\n const triggerClasses = classNames(\n {\n 'ndl-closed': !context.isOpen,\n 'ndl-open': context.isOpen,\n },\n 'ndl-tooltip-trigger',\n className,\n );\n\n // `hasButtonWrapper=true` allows the user to pass any element as the anchor\n if (hasButtonWrapper && React.isValidElement(children)) {\n const props: Record<string, unknown> = {\n className: triggerClasses,\n ...htmlAttributes,\n ...childrenProps,\n ref: mergedRefs,\n };\n\n return React.cloneElement(children, context.getReferenceProps(props));\n }\n\n return (\n <button\n type=\"button\"\n className={triggerClasses}\n style={style}\n ref={mergedRefs}\n {...context.getReferenceProps(htmlAttributes)}\n {...restProps}\n >\n {children}\n </button>\n );\n};\n\ntype TooltipContentProps = {\n /** Content displayed inside the tooltip */\n children: React.ReactNode;\n};\n\nconst TooltipContent = ({\n children,\n style,\n htmlAttributes,\n className,\n ref,\n ...restProps\n}: CommonProps<'div', TooltipContentProps>) => {\n const context = useTooltipContext();\n const mergedRef = useMergeRefs([context.refs.setFloating, ref]);\n const { themeClassName } = useNeedleTheme();\n\n const hasHeaderChild = React.useMemo(() => {\n if (context.type !== 'rich') {\n return false;\n }\n const childrenArray = React.Children.toArray(children);\n return childrenArray.some(\n (child) => React.isValidElement(child) && child.type === TooltipHeader,\n );\n }, [children, context.type]);\n\n if (!context.isOpen) {\n return null;\n }\n\n const classes = classNames('ndl-tooltip-content', themeClassName, className, {\n 'ndl-tooltip-content-rich': context.type === 'rich',\n 'ndl-tooltip-content-simple': context.type === 'simple',\n });\n\n if (context.type === 'simple') {\n return (\n <ConditionalWrap\n shouldWrap={context.isPortaled}\n wrap={(wrapChildren) => <FloatingPortal>{wrapChildren}</FloatingPortal>}\n >\n <div\n ref={mergedRef}\n className={classes}\n style={{\n ...context.floatingStyles,\n ...style,\n }}\n {...restProps}\n {...context.getFloatingProps(htmlAttributes)}\n >\n <Typography variant=\"body-medium\">{children}</Typography>\n </div>\n </ConditionalWrap>\n );\n }\n\n const ariaLabelledBy =\n htmlAttributes?.['aria-labelledby'] ??\n (hasHeaderChild ? context.headerId : undefined);\n\n if (htmlAttributes?.['aria-label'] === undefined && !ariaLabelledBy) {\n console.warn(\n 'The rich Tooltip is missing aria-label and Header. Please add one of them for accessibility.',\n );\n }\n\n return (\n <ConditionalWrap\n shouldWrap={context.isPortaled}\n wrap={(wrapChildren) => <FloatingPortal>{wrapChildren}</FloatingPortal>}\n >\n <FloatingFocusManager\n context={context.context}\n returnFocus={true}\n modal={false}\n initialFocus={0}\n closeOnFocusOut\n >\n <div\n ref={mergedRef}\n className={classes}\n style={{\n ...context.floatingStyles,\n ...style,\n }}\n {...restProps}\n {...context.getFloatingProps({\n ...htmlAttributes,\n 'aria-labelledby': ariaLabelledBy,\n })}\n >\n {children}\n </div>\n </FloatingFocusManager>\n </ConditionalWrap>\n );\n};\n\ntype TooltipHeaderProps = {\n /** Content displayed inside the header */\n children: React.ReactNode;\n /** @deprecated Use `typographyVariant` instead */\n passThroughProps?: Partial<React.ComponentPropsWithoutRef<typeof Typography>>;\n typographyVariant?: TypographyVariants;\n};\n\nconst TooltipHeader = ({\n children,\n passThroughProps,\n typographyVariant = 'subheading-medium',\n className,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: CommonProps<'span', TooltipHeaderProps>) => {\n const context = useTooltipContext();\n\n const classes = classNames('ndl-tooltip-header', className);\n\n useEffect(() => {\n if (Boolean(htmlAttributes?.id) === true) {\n context.setHeaderId?.(htmlAttributes?.id);\n }\n }, [context, htmlAttributes?.id]);\n\n if (!context.isOpen) {\n return null;\n }\n\n return (\n <Typography\n ref={ref}\n variant={typographyVariant}\n className={classes}\n style={style}\n htmlAttributes={{ ...htmlAttributes, id: context.headerId }}\n {...passThroughProps}\n {...restProps}\n >\n {children}\n </Typography>\n );\n};\n\nexport type TooltipBodyProps = {\n /** Content displayed inside the body */\n children: React.ReactNode;\n /** Additional props to pass to the Typography component */\n passThroughProps?: Partial<React.ComponentPropsWithoutRef<typeof Typography>>;\n};\n\nconst TooltipBody = ({\n children,\n className,\n style,\n htmlAttributes,\n passThroughProps,\n ref,\n ...restProps\n}: CommonProps<'span', TooltipBodyProps>) => {\n const context = useTooltipContext();\n\n const classes = classNames('ndl-tooltip-body', className);\n if (!context.isOpen) {\n return null;\n }\n\n return (\n <Typography\n ref={ref}\n variant=\"body-medium\"\n className={classes}\n style={style}\n htmlAttributes={htmlAttributes}\n {...passThroughProps}\n {...restProps}\n >\n {children}\n </Typography>\n );\n};\n\ntype ToolTipActionsProps = {\n /** Content displayed inside the actions container */\n children: React.ReactNode;\n};\n\nconst Actions = ({\n children,\n className,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: CommonProps<'div', ToolTipActionsProps>) => {\n const context = useTooltipContext();\n const mergedRefs = useMergeRefs([context.refs.setFloating, ref]);\n\n if (!context.isOpen) {\n return null;\n }\n\n const classes = classNames('ndl-tooltip-actions', className);\n\n return (\n <div\n className={classes}\n ref={mergedRefs}\n style={style}\n {...restProps}\n {...htmlAttributes}\n >\n {children}\n </div>\n );\n};\n\nActions.displayName = 'Tooltip.Actions';\n\nconst Tooltip = Object.assign(TooltipComponent, {\n Actions: Actions,\n Body: TooltipBody,\n Content: TooltipContent,\n Header: TooltipHeader,\n Trigger: TooltipTrigger,\n});\n\nexport { Tooltip };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+HE;CACA;CACA;CACA;CACA;CACA;;;CAuDA;CACA;CACA;CACA;CACA;;;CAmGA;CACA;CACA;CACA;CACA;CACA;CACA;;;CAwCA;CACA;CACA;CACA;CACA;CACA;;;CA+BA;CACA;CACA;CACA;CACA;;AA7SF,MAAM,oBAAoB,EACxB,UACA,aAAa,OACb,MACA,eACA,WACA,QACA,cACA,YAAY,gBACZ,kBAAkB,cAClB,YACA,6BACA,mBACA,mBACkB;CAClB,MAAM,iBAAiB,kB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AAA;AAEhB;AASA,MAAM,eAAe,UAQwB;CARxB,IAAA,EACnB,UACA,WACA,OACA,gBACA,kBACA,QAAA,OACG,YAAA,yBAAA,OAAA,UAAA;CAEH,MAAM,UAAU,kBAAkB;CAElC,MAAM,UAAU,WAAW,oBAAoB,SAAS;CACxD,IAAI,CAAC,QAAQ,QACX,OAAO;CAGT,OACE,oBAAC,YAAA,eAAA,eAAA,eAAA;EACM;EACL,SAAQ;EACR,WAAW;EACJ;EACS;CACZ,GAAA,gBAAA,GACA,SAAA,GAAA,CAAA,GAAA,EAEH,SAAA,CACS,CAAA;AAEhB;AAOA,MAAM,WAAW,UAO8B;CAP9B,IAAA,EACf,UACA,WACA,OACA,gBACA,QAAA,OACG,YAAA,yBAAA,OAAA,UAAA;CAEH,MAAM,UAAU,kBAAkB;CAClC,MAAM,aAAa,aAAa,CAAC,QAAQ,KAAK,aAAa,GAAG,CAAC;CAE/D,IAAI,CAAC,QAAQ,QACX,OAAO;CAGT,MAAM,UAAU,WAAW,uBAAuB,SAAS;CAE3D,OACE,oBAAC,OAAA,eAAA,eAAA,eAAA;EACC,WAAW;EACX,KAAK;EACE;CACH,GAAA,SAAA,GACA,cAAA,GAAA,CAAA,GAAA,EAEH,SAAA,CACE,CAAA;AAET;AAEA,QAAQ,cAAc;AAEtB,MAAM,UAAU,OAAO,OAAO,kBAAkB;CACrC;CACT,MAAM;CACN,SAAS;CACT,QAAQ;CACR,SAAS;AACX,CAAC"}
|
|
1
|
+
{"version":3,"file":"Tooltip.mjs","names":[],"sources":["../../../src/tooltip/Tooltip.tsx"],"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 type AutoUpdateOptions,\n FloatingFocusManager,\n FloatingPortal,\n type Placement,\n type UseFloatingOptions,\n useMergeRefs,\n} from '@floating-ui/react';\nimport classNames from 'classnames';\nimport React, { useEffect } from 'react';\n\nimport { type CommonProps } from '../_common/types';\nimport { ConditionalWrap } from '../conditional-wrap';\nimport { useIsInsideDialog } from '../dialog/dialog-context';\nimport { useNeedleTheme } from '../theme';\nimport { Typography, type TypographyVariants } from '../typography';\nimport { TooltipContext, useTooltip, useTooltipContext } from './use-tooltip';\n\nexport type TooltipProps = {\n /** Content displayed inside the tooltip. Wraps `Tooltip.Trigger`, `Tooltip.Content`, and optional parts */\n children: React.ReactNode;\n /** Whether the tooltip is disabled */\n isDisabled?: boolean;\n /** Whether the tooltip should be open on first render */\n isInitialOpen?: boolean;\n /** Placement of the tooltip content relative to the trigger */\n placement?: Placement;\n /** Controls the open state . If omitted, the tooltip manages its own state */\n isOpen?: boolean;\n /**\n * Visual style of the tooltip content. `simple` renders plain text, `rich` renders a composable panel\n */\n type: 'simple' | 'rich';\n /** Whether the content is rendered in a portal. */\n isPortaled?: boolean;\n /** Callback fired when the open state changes, if omitted, the tooltip manages its own state using internal hooks */\n onOpenChange?: UseFloatingOptions['onOpenChange'];\n /** Positioning strategy of the tooltip. Defaults to `fixed` when inside a dialog, otherwise `absolute` */\n floatingStrategy?: 'absolute' | 'fixed';\n /** Hover open/close delays in milliseconds */\n hoverDelay?: {\n open: number;\n close: number;\n };\n /** Whether the tooltip should close when the reference element is clicked. Useful when the trigger moves after click. */\n shouldCloseOnReferenceClick?: boolean;\n autoUpdateOptions?: AutoUpdateOptions;\n /**\n * Whether the tooltip should be positioned at the mouse cursor. Only applies to 'simple' tooltips with mouse hover.\n * `true` follows the cursor continuously along one axis derived from `placement` (horizontal for top/bottom, vertical for left/right).\n * `'initial'` opens the tooltip at the cursor's position (both axes) and keeps it there, like the native `title` attribute; `placement` controls which side of that point the tooltip appears on.\n */\n followCursor?: boolean | 'initial';\n};\n\nconst TooltipComponent = ({\n children,\n isDisabled = false,\n type,\n isInitialOpen,\n placement,\n isOpen,\n onOpenChange,\n isPortaled: isPortaledProp,\n floatingStrategy: strategyProp,\n hoverDelay,\n shouldCloseOnReferenceClick,\n autoUpdateOptions,\n followCursor,\n}: TooltipProps) => {\n const isInsideDialog = useIsInsideDialog();\n const strategy = isInsideDialog ? 'fixed' : 'absolute';\n const isPortaled = !isInsideDialog;\n\n const tooltip = useTooltip({\n autoUpdateOptions,\n followCursor,\n hoverDelay,\n isDisabled,\n isInitialOpen,\n // if isDisabled is true tooltip will not open otherwise either controlled or uncontrolled depending on if isOpen is passed\n isOpen: isDisabled === true ? false : isOpen,\n isPortaled: isPortaledProp ?? isPortaled,\n onOpenChange,\n placement,\n shouldCloseOnReferenceClick,\n strategy: strategyProp ?? strategy,\n type,\n });\n\n return (\n <TooltipContext.Provider value={tooltip}>\n {children}\n </TooltipContext.Provider>\n );\n};\n\nTooltipComponent.displayName = 'Tooltip';\n\ntype TooltipTriggerProps = {\n /** Content displayed inside the trigger element */\n children: React.ReactNode;\n /** Whether the trigger element can be any element without an extra button wrapper. The child element will be cloned with the necessary trigger props and merged refs */\n hasButtonWrapper?: boolean;\n};\n\nconst TooltipTrigger = ({\n children,\n hasButtonWrapper = false,\n htmlAttributes,\n className,\n style,\n ref,\n ...restProps\n}: CommonProps<'button', TooltipTriggerProps>) => {\n const context = useTooltipContext();\n\n // Example from floating-ui\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n const childrenProps = (children as any).props;\n const mergedRefs = useMergeRefs([\n context.refs.setReference,\n ref,\n childrenProps?.ref,\n ]);\n\n const triggerClasses = classNames(\n {\n 'ndl-closed': !context.isOpen,\n 'ndl-open': context.isOpen,\n },\n 'ndl-tooltip-trigger',\n className,\n );\n\n // `hasButtonWrapper=true` allows the user to pass any element as the anchor\n if (hasButtonWrapper && React.isValidElement(children)) {\n const props: Record<string, unknown> = {\n className: triggerClasses,\n ...htmlAttributes,\n ...childrenProps,\n ref: mergedRefs,\n };\n\n return React.cloneElement(children, context.getReferenceProps(props));\n }\n\n return (\n <button\n type=\"button\"\n className={triggerClasses}\n style={style}\n ref={mergedRefs}\n {...context.getReferenceProps(htmlAttributes)}\n {...restProps}\n >\n {children}\n </button>\n );\n};\n\ntype TooltipContentProps = {\n /** Content displayed inside the tooltip */\n children: React.ReactNode;\n};\n\nconst TooltipContent = ({\n children,\n style,\n htmlAttributes,\n className,\n ref,\n ...restProps\n}: CommonProps<'div', TooltipContentProps>) => {\n const context = useTooltipContext();\n const mergedRef = useMergeRefs([context.refs.setFloating, ref]);\n const { themeClassName } = useNeedleTheme();\n\n const hasHeaderChild = React.useMemo(() => {\n if (context.type !== 'rich') {\n return false;\n }\n const childrenArray = React.Children.toArray(children);\n return childrenArray.some(\n (child) => React.isValidElement(child) && child.type === TooltipHeader,\n );\n }, [children, context.type]);\n\n if (!context.isOpen) {\n return null;\n }\n\n const classes = classNames('ndl-tooltip-content', themeClassName, className, {\n 'ndl-tooltip-content-rich': context.type === 'rich',\n 'ndl-tooltip-content-simple': context.type === 'simple',\n });\n\n if (context.type === 'simple') {\n return (\n <ConditionalWrap\n shouldWrap={context.isPortaled}\n wrap={(wrapChildren) => <FloatingPortal>{wrapChildren}</FloatingPortal>}\n >\n <div\n ref={mergedRef}\n className={classes}\n style={{\n ...context.floatingStyles,\n ...style,\n }}\n {...restProps}\n {...context.getFloatingProps(htmlAttributes)}\n >\n <Typography variant=\"body-medium\">{children}</Typography>\n </div>\n </ConditionalWrap>\n );\n }\n\n const ariaLabelledBy =\n htmlAttributes?.['aria-labelledby'] ??\n (hasHeaderChild ? context.headerId : undefined);\n\n if (htmlAttributes?.['aria-label'] === undefined && !ariaLabelledBy) {\n console.warn(\n 'The rich Tooltip is missing aria-label and Header. Please add one of them for accessibility.',\n );\n }\n\n return (\n <ConditionalWrap\n shouldWrap={context.isPortaled}\n wrap={(wrapChildren) => <FloatingPortal>{wrapChildren}</FloatingPortal>}\n >\n <FloatingFocusManager\n context={context.context}\n returnFocus={true}\n modal={false}\n initialFocus={0}\n closeOnFocusOut\n >\n <div\n ref={mergedRef}\n className={classes}\n style={{\n ...context.floatingStyles,\n ...style,\n }}\n {...restProps}\n {...context.getFloatingProps({\n ...htmlAttributes,\n 'aria-labelledby': ariaLabelledBy,\n })}\n >\n {children}\n </div>\n </FloatingFocusManager>\n </ConditionalWrap>\n );\n};\n\ntype TooltipHeaderProps = {\n /** Content displayed inside the header */\n children: React.ReactNode;\n /** @deprecated Use `typographyVariant` instead */\n passThroughProps?: Partial<React.ComponentPropsWithoutRef<typeof Typography>>;\n typographyVariant?: TypographyVariants;\n};\n\nconst TooltipHeader = ({\n children,\n passThroughProps,\n typographyVariant = 'subheading-large',\n className,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: CommonProps<'span', TooltipHeaderProps>) => {\n const context = useTooltipContext();\n\n const classes = classNames('ndl-tooltip-header', className);\n\n useEffect(() => {\n if (Boolean(htmlAttributes?.id) === true) {\n context.setHeaderId?.(htmlAttributes?.id);\n }\n }, [context, htmlAttributes?.id]);\n\n if (!context.isOpen) {\n return null;\n }\n\n return (\n <Typography\n ref={ref}\n variant={typographyVariant}\n className={classes}\n style={style}\n htmlAttributes={{ ...htmlAttributes, id: context.headerId }}\n {...passThroughProps}\n {...restProps}\n >\n {children}\n </Typography>\n );\n};\n\nexport type TooltipBodyProps = {\n /** Content displayed inside the body */\n children: React.ReactNode;\n /** Additional props to pass to the Typography component */\n passThroughProps?: Partial<React.ComponentPropsWithoutRef<typeof Typography>>;\n};\n\nconst TooltipBody = ({\n children,\n className,\n style,\n htmlAttributes,\n passThroughProps,\n ref,\n ...restProps\n}: CommonProps<'span', TooltipBodyProps>) => {\n const context = useTooltipContext();\n\n const classes = classNames('ndl-tooltip-body', className);\n if (!context.isOpen) {\n return null;\n }\n\n return (\n <Typography\n ref={ref}\n variant=\"body-medium\"\n className={classes}\n style={style}\n htmlAttributes={htmlAttributes}\n {...passThroughProps}\n {...restProps}\n >\n {children}\n </Typography>\n );\n};\n\ntype ToolTipActionsProps = {\n /** Content displayed inside the actions container */\n children: React.ReactNode;\n};\n\nconst Actions = ({\n children,\n className,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: CommonProps<'div', ToolTipActionsProps>) => {\n const context = useTooltipContext();\n const mergedRefs = useMergeRefs([context.refs.setFloating, ref]);\n\n if (!context.isOpen) {\n return null;\n }\n\n const classes = classNames('ndl-tooltip-actions', className);\n\n return (\n <div\n className={classes}\n ref={mergedRefs}\n style={style}\n {...restProps}\n {...htmlAttributes}\n >\n {children}\n </div>\n );\n};\n\nActions.displayName = 'Tooltip.Actions';\n\nconst Tooltip = Object.assign(TooltipComponent, {\n Actions: Actions,\n Body: TooltipBody,\n Content: TooltipContent,\n Header: TooltipHeader,\n Trigger: TooltipTrigger,\n});\n\nexport { Tooltip };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+HE;CACA;CACA;CACA;CACA;CACA;;;CAuDA;CACA;CACA;CACA;CACA;;;CAmGA;CACA;CACA;CACA;CACA;CACA;CACA;;;CAwCA;CACA;CACA;CACA;CACA;CACA;;;CA+BA;CACA;CACA;CACA;CACA;;AA7SF,MAAM,oBAAoB,EACxB,UACA,aAAa,OACb,MACA,eACA,WACA,QACA,cACA,YAAY,gBACZ,kBAAkB,cAClB,YACA,6BACA,mBACA,mBACkB;CAClB,MAAM,iBAAiB,kBAAkB;CAIzC,MAAM,UAAU,WAAW;EACzB;EACA;EACA;EACA;EACA;EAEA,QAAQ,eAAe,OAAO,QAAQ;EACtC,YAAY,mBAAA,QAAA,mBAAA,KAAA,IAAA,iBAAkB,CAVZ;EAWlB;EACA;EACA;EACA,UAAU,iBAAA,QAAA,iBAAA,KAAA,IAAA,eAfK,iB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CAGT,OACE,oBAAC,YAAA,eAAA,eAAA,eAAA;EACM;EACL,SAAQ;EACR,WAAW;EACJ;EACS;CACZ,GAAA,gBAAA,GACA,SAAA,GAAA,CAAA,GAAA,EAEH,SAAA,CACS,CAAA;AAEhB;AAOA,MAAM,WAAW,UAO8B;CAP9B,IAAA,EACf,UACA,WACA,OACA,gBACA,QAAA,OACG,YAAA,yBAAA,OAAA,UAAA;CAEH,MAAM,UAAU,kBAAkB;CAClC,MAAM,aAAa,aAAa,CAAC,QAAQ,KAAK,aAAa,GAAG,CAAC;CAE/D,IAAI,CAAC,QAAQ,QACX,OAAO;CAGT,MAAM,UAAU,WAAW,uBAAuB,SAAS;CAE3D,OACE,oBAAC,OAAA,eAAA,eAAA,eAAA;EACC,WAAW;EACX,KAAK;EACE;CACH,GAAA,SAAA,GACA,cAAA,GAAA,CAAA,GAAA,EAEH,SAAA,CACE,CAAA;AAET;AAEA,QAAQ,cAAc;AAEtB,MAAM,UAAU,OAAO,OAAO,kBAAkB;CACrC;CACT,MAAM;CACN,SAAS;CACT,QAAQ;CACR,SAAS;AACX,CAAC"}
|
|
@@ -184,7 +184,7 @@ const TreeViewTextItem = (_ref) => {
|
|
|
184
184
|
children
|
|
185
185
|
}),
|
|
186
186
|
children: /* @__PURE__ */ jsx(Typography, {
|
|
187
|
-
variant: item.canHaveSubItems ? "subheading-
|
|
187
|
+
variant: item.canHaveSubItems ? "subheading-medium" : "body-medium",
|
|
188
188
|
htmlAttributes: { style: {
|
|
189
189
|
overflow: "hidden",
|
|
190
190
|
textOverflow: "ellipsis",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeViewTextItem.mjs","names":[],"sources":["../../../src/tree-view/TreeViewTextItem.tsx"],"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 type React from 'react';\n\nimport { Checkbox } from '../checkbox';\nimport { CleanIconButton } from '../clean-icon-button';\nimport { ConditionalWrap } from '../conditional-wrap';\nimport { ChevronDownIconOutline } from '../icons/generated/heroIcons/ChevronDownIconOutline';\nimport { ChevronRightIconOutline } from '../icons/generated/heroIcons/ChevronRightIconOutline';\nimport { Skeleton } from '../skeleton';\nimport { Typography } from '../typography';\nimport {\n type FlattenedTreeItem,\n type TextItemData,\n type TreeItemComponentProps,\n} from './tree-view-types';\nimport { TreeItemWrapper } from './TreeItemWrapper';\n\n/**\n * checks if any parent is checked\n * @param item - Tree item\n * @param items - Flattened tree items\n * @returns\n */\nconst parentIsCheckedRecursively = (\n item: FlattenedTreeItem<TextItemData>,\n items: FlattenedTreeItem<TextItemData>[],\n): boolean => {\n const parent = items.find((parentItem) => parentItem.id === item.parentId);\n if (parent) {\n if (parent.isSelected) {\n return true;\n }\n return parentIsCheckedRecursively(parent, items);\n }\n return false;\n};\n\n/**\n * checks if any children are checked\n * @param item - Tree item\n * @param items - Flattened tree items\n * @returns\n */\nconst childrenCheckedRecursively = (\n item: FlattenedTreeItem<TextItemData>,\n items: FlattenedTreeItem<TextItemData>[],\n): boolean => {\n const children = items.filter((childItem) => childItem.parentId === item.id);\n if (children.length === 0) {\n return false;\n }\n return children.some(\n (childItem) =>\n childItem.isSelected || childrenCheckedRecursively(childItem, items),\n );\n};\n\nexport const TreeViewTextItem = <T extends TextItemData>({\n depth,\n shouldDisableInteraction,\n shouldDisableSorting,\n isGhost,\n indentationWidth,\n isIndicator,\n isCollapsed,\n onCollapse,\n item,\n parent,\n isOver,\n isOverParent,\n setNodeRef,\n setActivatorNodeRef,\n dragHandleProps,\n style,\n trails,\n onItemsChanged,\n items,\n tabIndex,\n ref,\n ...restProps\n}: TreeItemComponentProps<T> & { ref?: React.Ref<HTMLElement> }) => {\n const isAnyParentChecked = parentIsCheckedRecursively(item, items);\n const isAnyChildChecked = childrenCheckedRecursively(item, items);\n\n const isIndeterminate =\n isAnyChildChecked === true &&\n isAnyParentChecked === false &&\n item.isSelected === false\n ? true\n : false;\n\n return (\n <TreeItemWrapper\n depth={depth}\n shouldDisableInteraction={shouldDisableInteraction}\n shouldDisableSorting={shouldDisableSorting}\n isGhost={isGhost}\n indentationWidth={indentationWidth}\n isIndicator={isIndicator}\n isCollapsed={isCollapsed}\n onCollapse={onCollapse}\n item={item}\n parent={parent}\n isOver={isOver}\n isOverParent={isOverParent}\n setNodeRef={setNodeRef}\n setActivatorNodeRef={setActivatorNodeRef}\n dragHandleProps={dragHandleProps}\n style={style}\n trails={trails}\n // oxlint-disable-next-line @typescript-eslint/no-empty-function\n onItemsChanged={() => {}}\n ref={ref}\n items={items}\n tabIndex={tabIndex}\n {...restProps}\n >\n {item.canHaveSubItems && onCollapse && (\n <button\n type=\"button\"\n className=\"ndl-tree-view-collapse-button\"\n onClick={() => onCollapse()}\n aria-label={item.isCollapsed ? 'Expand' : 'Collapse'}\n aria-expanded={item.isCollapsed ? 'false' : 'true'}\n /**\n * Tab index is set to -1 to prevent the item from being focused when the tree is navigated with tab\n * since we use the arrow keys instead\n */\n tabIndex={tabIndex}\n >\n {item.isCollapsed && <ChevronRightIconOutline className=\"ndl-icon\" />}\n {!item.isCollapsed && <ChevronDownIconOutline className=\"ndl-icon\" />}\n </button>\n )}\n {item.isSelected !== undefined && (\n <Skeleton\n onBackground=\"weak\"\n shape=\"rectangular\"\n {...item.skeletonProps}\n isLoading={item.isSkeletonLoading}\n >\n <Checkbox\n isIndeterminate={isIndeterminate}\n isChecked={item.isSelected}\n ariaLabel={item.data.text}\n htmlAttributes={{\n tabIndex,\n }}\n onChange={(event) => {\n const newItems = items.map((treeItem) => {\n if (treeItem.id === item.id) {\n return {\n ...treeItem,\n isSelected: event.target.checked,\n };\n }\n return treeItem;\n });\n\n // Uncheck parents if a child is unchecked\n if (!event.target.checked) {\n let parentId = item.parentId;\n while (parentId !== null) {\n const parent = newItems.find(\n (newItem) => newItem.id === parentId,\n );\n if (parent) {\n newItems.forEach((newItem) => {\n if (newItem.id === parent.id) {\n newItem.isSelected = false;\n }\n });\n parentId = parent.parentId;\n } else {\n parentId = null;\n }\n }\n }\n // Check children if a parent is checked\n if (item.canHaveSubItems) {\n const childIdsToUncheck = items\n .filter((childItem) => childItem.parentId === item.id)\n .map((childItem) => childItem.id);\n while (childIdsToUncheck.length > 0) {\n const childId = childIdsToUncheck.pop();\n const child = items.find(\n (childItem) => childItem.id === childId,\n );\n if (child) {\n newItems.forEach((newItem) => {\n if (newItem.id === child.id) {\n newItem.isSelected = event.target.checked;\n }\n });\n newItems\n .filter((childItem) => childItem.parentId === child.id)\n .forEach((childItem) => {\n childIdsToUncheck.push(childItem.id);\n });\n }\n }\n }\n onItemsChanged(newItems, { item, reason: 'selected' });\n }}\n aria-label={item.data.text}\n />\n </Skeleton>\n )}\n\n <Skeleton\n onBackground=\"weak\"\n shape=\"rectangular\"\n height=\"20px\"\n {...item.skeletonProps}\n isLoading={item.isSkeletonLoading}\n >\n <ConditionalWrap\n shouldWrap={item.data.onTextClick !== undefined}\n wrap={(children) => (\n <button\n type=\"button\"\n onClick={item.data.onTextClick}\n className=\"ndl-tree-view-text-clickable\"\n tabIndex={tabIndex}\n >\n {children}\n </button>\n )}\n >\n <Typography\n variant={item.canHaveSubItems ? 'subheading-small' : 'body-medium'}\n htmlAttributes={{\n style: {\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n whiteSpace: 'nowrap',\n },\n }}\n >\n {item.data.text}\n </Typography>\n </ConditionalWrap>\n </Skeleton>\n <div className=\"ndl-tree-view-actions\">\n {item.data.actions &&\n item.data.actions.map((action, index) => {\n return (\n <CleanIconButton\n key={index}\n className=\"ndl-tree-view-action\"\n size=\"small\"\n {...action.buttonProps}\n htmlAttributes={{\n tabIndex,\n ...action.buttonProps.htmlAttributes,\n }}\n >\n {action.icon}\n </CleanIconButton>\n );\n })}\n </div>\n </TreeItemWrapper>\n );\n};\n"],"mappings":";;;;;;;;;;;;;CA6EE;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAvDF,MAAM,8BACJ,MACA,UACY;CACZ,MAAM,SAAS,MAAM,MAAM,eAAe,WAAW,OAAO,KAAK,QAAQ;CACzE,IAAI,QAAQ;EACV,IAAI,OAAO,YACT,OAAO;EAET,OAAO,2BAA2B,QAAQ,KAAK;CACjD;CACA,OAAO;AACT;;;;;;;AAQA,MAAM,8BACJ,MACA,UACY;CACZ,MAAM,WAAW,MAAM,QAAQ,cAAc,UAAU,aAAa,KAAK,EAAE;CAC3E,IAAI,SAAS,WAAW,GACtB,OAAO;CAET,OAAO,SAAS,MACb,cACC,UAAU,cAAc,2BAA2B,WAAW,KAAK,CACvE;AACF;AAEA,MAAa,oBAA4C,SAuBW;CAvBX,IAAA,EACvD,OACA,0BACA,sBACA,SACA,kBACA,aACA,aACA,YACA,MACA,QACA,QACA,cACA,YACA,qBACA,iBACA,OACA,QACA,gBACA,OACA,UACA,QAAA,MACG,YAAA,yBAAA,MAAA,SAAA;CAEH,MAAM,qBAAqB,2BAA2B,MAAM,KAAK;CAGjE,MAAM,kBAFoB,2BAA2B,MAAM,KAGzC,MAAM,QACtB,uBAAuB,SACvB,KAAK,eAAe,QAChB,OACA;CAEN,OACE,qBAAC,iBAAA,eAAA,eAAA;EACQ;EACmB;EACJ;EACb;EACS;EACL;EACA;EACD;EACN;EACE;EACA;EACM;EACF;EACS;EACJ;EACV;EACC;EAER,sBAAsB,CAAC;EAClB;EACE;EACG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AAA,CAAA,CAAA;AAErB"}
|
|
1
|
+
{"version":3,"file":"TreeViewTextItem.mjs","names":[],"sources":["../../../src/tree-view/TreeViewTextItem.tsx"],"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 type React from 'react';\n\nimport { Checkbox } from '../checkbox';\nimport { CleanIconButton } from '../clean-icon-button';\nimport { ConditionalWrap } from '../conditional-wrap';\nimport { ChevronDownIconOutline } from '../icons/generated/heroIcons/ChevronDownIconOutline';\nimport { ChevronRightIconOutline } from '../icons/generated/heroIcons/ChevronRightIconOutline';\nimport { Skeleton } from '../skeleton';\nimport { Typography } from '../typography';\nimport {\n type FlattenedTreeItem,\n type TextItemData,\n type TreeItemComponentProps,\n} from './tree-view-types';\nimport { TreeItemWrapper } from './TreeItemWrapper';\n\n/**\n * checks if any parent is checked\n * @param item - Tree item\n * @param items - Flattened tree items\n * @returns\n */\nconst parentIsCheckedRecursively = (\n item: FlattenedTreeItem<TextItemData>,\n items: FlattenedTreeItem<TextItemData>[],\n): boolean => {\n const parent = items.find((parentItem) => parentItem.id === item.parentId);\n if (parent) {\n if (parent.isSelected) {\n return true;\n }\n return parentIsCheckedRecursively(parent, items);\n }\n return false;\n};\n\n/**\n * checks if any children are checked\n * @param item - Tree item\n * @param items - Flattened tree items\n * @returns\n */\nconst childrenCheckedRecursively = (\n item: FlattenedTreeItem<TextItemData>,\n items: FlattenedTreeItem<TextItemData>[],\n): boolean => {\n const children = items.filter((childItem) => childItem.parentId === item.id);\n if (children.length === 0) {\n return false;\n }\n return children.some(\n (childItem) =>\n childItem.isSelected || childrenCheckedRecursively(childItem, items),\n );\n};\n\nexport const TreeViewTextItem = <T extends TextItemData>({\n depth,\n shouldDisableInteraction,\n shouldDisableSorting,\n isGhost,\n indentationWidth,\n isIndicator,\n isCollapsed,\n onCollapse,\n item,\n parent,\n isOver,\n isOverParent,\n setNodeRef,\n setActivatorNodeRef,\n dragHandleProps,\n style,\n trails,\n onItemsChanged,\n items,\n tabIndex,\n ref,\n ...restProps\n}: TreeItemComponentProps<T> & { ref?: React.Ref<HTMLElement> }) => {\n const isAnyParentChecked = parentIsCheckedRecursively(item, items);\n const isAnyChildChecked = childrenCheckedRecursively(item, items);\n\n const isIndeterminate =\n isAnyChildChecked === true &&\n isAnyParentChecked === false &&\n item.isSelected === false\n ? true\n : false;\n\n return (\n <TreeItemWrapper\n depth={depth}\n shouldDisableInteraction={shouldDisableInteraction}\n shouldDisableSorting={shouldDisableSorting}\n isGhost={isGhost}\n indentationWidth={indentationWidth}\n isIndicator={isIndicator}\n isCollapsed={isCollapsed}\n onCollapse={onCollapse}\n item={item}\n parent={parent}\n isOver={isOver}\n isOverParent={isOverParent}\n setNodeRef={setNodeRef}\n setActivatorNodeRef={setActivatorNodeRef}\n dragHandleProps={dragHandleProps}\n style={style}\n trails={trails}\n // oxlint-disable-next-line @typescript-eslint/no-empty-function\n onItemsChanged={() => {}}\n ref={ref}\n items={items}\n tabIndex={tabIndex}\n {...restProps}\n >\n {item.canHaveSubItems && onCollapse && (\n <button\n type=\"button\"\n className=\"ndl-tree-view-collapse-button\"\n onClick={() => onCollapse()}\n aria-label={item.isCollapsed ? 'Expand' : 'Collapse'}\n aria-expanded={item.isCollapsed ? 'false' : 'true'}\n /**\n * Tab index is set to -1 to prevent the item from being focused when the tree is navigated with tab\n * since we use the arrow keys instead\n */\n tabIndex={tabIndex}\n >\n {item.isCollapsed && <ChevronRightIconOutline className=\"ndl-icon\" />}\n {!item.isCollapsed && <ChevronDownIconOutline className=\"ndl-icon\" />}\n </button>\n )}\n {item.isSelected !== undefined && (\n <Skeleton\n onBackground=\"weak\"\n shape=\"rectangular\"\n {...item.skeletonProps}\n isLoading={item.isSkeletonLoading}\n >\n <Checkbox\n isIndeterminate={isIndeterminate}\n isChecked={item.isSelected}\n ariaLabel={item.data.text}\n htmlAttributes={{\n tabIndex,\n }}\n onChange={(event) => {\n const newItems = items.map((treeItem) => {\n if (treeItem.id === item.id) {\n return {\n ...treeItem,\n isSelected: event.target.checked,\n };\n }\n return treeItem;\n });\n\n // Uncheck parents if a child is unchecked\n if (!event.target.checked) {\n let parentId = item.parentId;\n while (parentId !== null) {\n const parent = newItems.find(\n (newItem) => newItem.id === parentId,\n );\n if (parent) {\n newItems.forEach((newItem) => {\n if (newItem.id === parent.id) {\n newItem.isSelected = false;\n }\n });\n parentId = parent.parentId;\n } else {\n parentId = null;\n }\n }\n }\n // Check children if a parent is checked\n if (item.canHaveSubItems) {\n const childIdsToUncheck = items\n .filter((childItem) => childItem.parentId === item.id)\n .map((childItem) => childItem.id);\n while (childIdsToUncheck.length > 0) {\n const childId = childIdsToUncheck.pop();\n const child = items.find(\n (childItem) => childItem.id === childId,\n );\n if (child) {\n newItems.forEach((newItem) => {\n if (newItem.id === child.id) {\n newItem.isSelected = event.target.checked;\n }\n });\n newItems\n .filter((childItem) => childItem.parentId === child.id)\n .forEach((childItem) => {\n childIdsToUncheck.push(childItem.id);\n });\n }\n }\n }\n onItemsChanged(newItems, { item, reason: 'selected' });\n }}\n aria-label={item.data.text}\n />\n </Skeleton>\n )}\n\n <Skeleton\n onBackground=\"weak\"\n shape=\"rectangular\"\n height=\"20px\"\n {...item.skeletonProps}\n isLoading={item.isSkeletonLoading}\n >\n <ConditionalWrap\n shouldWrap={item.data.onTextClick !== undefined}\n wrap={(children) => (\n <button\n type=\"button\"\n onClick={item.data.onTextClick}\n className=\"ndl-tree-view-text-clickable\"\n tabIndex={tabIndex}\n >\n {children}\n </button>\n )}\n >\n <Typography\n variant={item.canHaveSubItems ? 'subheading-medium' : 'body-medium'}\n htmlAttributes={{\n style: {\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n whiteSpace: 'nowrap',\n },\n }}\n >\n {item.data.text}\n </Typography>\n </ConditionalWrap>\n </Skeleton>\n <div className=\"ndl-tree-view-actions\">\n {item.data.actions &&\n item.data.actions.map((action, index) => {\n return (\n <CleanIconButton\n key={index}\n className=\"ndl-tree-view-action\"\n size=\"small\"\n {...action.buttonProps}\n htmlAttributes={{\n tabIndex,\n ...action.buttonProps.htmlAttributes,\n }}\n >\n {action.icon}\n </CleanIconButton>\n );\n })}\n </div>\n </TreeItemWrapper>\n );\n};\n"],"mappings":";;;;;;;;;;;;;CA6EE;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAvDF,MAAM,8BACJ,MACA,UACY;CACZ,MAAM,SAAS,MAAM,MAAM,eAAe,WAAW,OAAO,KAAK,QAAQ;CACzE,IAAI,QAAQ;EACV,IAAI,OAAO,YACT,OAAO;EAET,OAAO,2BAA2B,QAAQ,KAAK;CACjD;CACA,OAAO;AACT;;;;;;;AAQA,MAAM,8BACJ,MACA,UACY;CACZ,MAAM,WAAW,MAAM,QAAQ,cAAc,UAAU,aAAa,KAAK,EAAE;CAC3E,IAAI,SAAS,WAAW,GACtB,OAAO;CAET,OAAO,SAAS,MACb,cACC,UAAU,cAAc,2BAA2B,WAAW,KAAK,CACvE;AACF;AAEA,MAAa,oBAA4C,SAuBW;CAvBX,IAAA,EACvD,OACA,0BACA,sBACA,SACA,kBACA,aACA,aACA,YACA,MACA,QACA,QACA,cACA,YACA,qBACA,iBACA,OACA,QACA,gBACA,OACA,UACA,QAAA,MACG,YAAA,yBAAA,MAAA,SAAA;CAEH,MAAM,qBAAqB,2BAA2B,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,KAAK,KAAK,QAAQ,KAAK,QAAQ,UAAU;IACvC,OACE,oBAAC,iBAAA,eAAA,eAAA;KAEC,WAAU;KACV,MAAK;IACD,GAAA,OAAO,WAAA,GAAA,CAAA,GAAA;KACX,gBAAA,eAAA,EACE,SAAA,GACG,OAAO,YAAY,cACxB;KAEC,UAAA,OAAO;IACO,CAAA,GAVV,KAUU;GAErB,CAAC;EACA,CAAA;CACU,EAAA,CAAA,CAAA;AAErB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Thinking.d.ts","sourceRoot":"","sources":["../../../../src/ai/thinking/Thinking.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAKvD,KAAK,aAAa,GAAG;IACnB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,mDAAmD;IACnD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;;GAMG;AACH,QAAA,MAAM,QAAQ,GAAI,iFAQf,WAAW,CAAC,KAAK,EAAE,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"Thinking.d.ts","sourceRoot":"","sources":["../../../../src/ai/thinking/Thinking.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAKvD,KAAK,aAAa,GAAG;IACnB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,mDAAmD;IACnD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;;GAMG;AACH,QAAA,MAAM,QAAQ,GAAI,iFAQf,WAAW,CAAC,KAAK,EAAE,aAAa,CAAC,4CAuCnC,CAAC;AAEF,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/inline-edit/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAExD,KAAK,kBAAkB,GAAG,CACxB,KAAK,EAAE,MAAM,KACV,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,GAAG,IAAI,GAAG,MAAM,CAAC;AAE5C,wBAAsB,aAAa,CACjC,KAAK,EAAE,MAAM,EACb,QAAQ,CAAC,EAAE,kBAAkB,GAC5B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAmBxB;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,kBAAkB,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/inline-edit/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAExD,KAAK,kBAAkB,GAAG,CACxB,KAAK,EAAE,MAAM,KACV,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,GAAG,IAAI,GAAG,MAAM,CAAC;AAE5C,wBAAsB,aAAa,CACjC,KAAK,EAAE,MAAM,EACb,QAAQ,CAAC,EAAE,kBAAkB,GAC5B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAmBxB;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,kBAAkB,GAAG,MAAM,CAUzE;AAED,eAAO,MAAM,YAAY,GACvB,SAAS,kBAAkB,KAC1B,KAAK,CAAC,aAGP,CAAC;AAEH,eAAO,MAAM,YAAY,GAAI,SAAS,kBAAkB,KAAG,MAE1D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neo4j-ndl/react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-alpha.0.d77a467",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"description": "React implementation of Neo4j Design System",
|
|
6
6
|
"keywords": [
|
|
@@ -434,7 +434,7 @@
|
|
|
434
434
|
"@tanstack/react-table": "8.21.3",
|
|
435
435
|
"react": ">=19.0.0",
|
|
436
436
|
"react-dom": ">=19.0.0",
|
|
437
|
-
"@neo4j-ndl/base": "^
|
|
437
|
+
"@neo4j-ndl/base": "^6.0.0-alpha.0.d77a467"
|
|
438
438
|
},
|
|
439
439
|
"dependencies": {
|
|
440
440
|
"@dnd-kit/core": "6.3.1",
|
|
@@ -461,7 +461,8 @@
|
|
|
461
461
|
"temporal-polyfill": "1.0.1",
|
|
462
462
|
"tinycolor2": "1.6.0",
|
|
463
463
|
"usehooks-ts": "3.1.1",
|
|
464
|
-
"zod": "4.6.7"
|
|
464
|
+
"zod": "4.6.7",
|
|
465
|
+
"@neo4j-ndl/base": "6.0.0-alpha.0.d77a467"
|
|
465
466
|
},
|
|
466
467
|
"scripts": {
|
|
467
468
|
"generate-component": "node ./scripts/component-generator.js",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: ndl-react
|
|
3
3
|
metadata:
|
|
4
4
|
package: '@neo4j-ndl/react'
|
|
5
|
-
version: '
|
|
5
|
+
version: '6.0.0-alpha.0.d77a467'
|
|
6
6
|
description: >-
|
|
7
7
|
Build and edit UI with the Neo4j Needle React design system
|
|
8
8
|
(@neo4j-ndl/react). Use when adding, composing, or modifying Needle components
|
|
@@ -15,7 +15,7 @@ description: >-
|
|
|
15
15
|
|
|
16
16
|
# Neo4j Needle (@neo4j-ndl/react)
|
|
17
17
|
|
|
18
|
-
> 📌 Shipped with `@neo4j-ndl/react`
|
|
18
|
+
> 📌 Shipped with `@neo4j-ndl/react` v6.0.0-alpha.0.d77a467. Once installed into your repo (e.g. via
|
|
19
19
|
> `npx skills add`) this folder is detached from the package — the installed
|
|
20
20
|
> package (TypeScript types in `node_modules/@neo4j-ndl/react`) is the source of
|
|
21
21
|
> truth.
|
|
@@ -33,7 +33,7 @@ Where `T` is of the type `string | number | undefined`.
|
|
|
33
33
|
| `onExpandedChange` | `(expanded: boolean) => void` | | | Callback function on accordion item expand/collapse change. |
|
|
34
34
|
| `ref` | `any` | | | A ref to apply to the root element. |
|
|
35
35
|
| `title` | `string` | ✅ | | The title of the accordion item. |
|
|
36
|
-
| `titleTypographyVariant` | `'body-large' \| 'body-medium' \| 'body-small' \| 'code' \| 'display' \| '
|
|
36
|
+
| `titleTypographyVariant` | `'body-large' \| 'body-medium' \| 'body-small' \| 'code' \| 'display' \| 'subheading-large' \| 'subheading-medium' \| 'subheading-small' \| 'title-1' \| 'title-2' \| 'title-3' \| 'title-4'` | | `subheading-large` | The typography variant for the title. |
|
|
37
37
|
| `trailingContent` | `ReactNode` | | | The content to display on the trailing side of accordion item. |
|
|
38
38
|
|
|
39
39
|
Where `T` is of the type `string | number | undefined`.
|
|
@@ -54,7 +54,7 @@ Where `T` is of the type `string | number | undefined`.
|
|
|
54
54
|
|
|
55
55
|
Where `T` is of the type `string | number | undefined`.
|
|
56
56
|
|
|
57
|
-
`TypographyVariants` is of the type `'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'subheading-large' | 'subheading-medium' | 'subheading-small' | 'body-large' | 'body-medium' | 'body-small' | 'code'
|
|
57
|
+
`TypographyVariants` is of the type `'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'subheading-large' | 'subheading-medium' | 'subheading-small' | 'body-large' | 'body-medium' | 'body-small' | 'code'`.
|
|
58
58
|
|
|
59
59
|
## Accessibility
|
|
60
60
|
|
|
@@ -213,7 +213,7 @@ const Component = () => {
|
|
|
213
213
|
onExpandedChange={onExpandedChange}
|
|
214
214
|
trailingContent={<Checkbox label="Right content" />}
|
|
215
215
|
title={`Accordion ${itemIds[1]}`}
|
|
216
|
-
titleTypographyVariant="title-
|
|
216
|
+
titleTypographyVariant="title-3"
|
|
217
217
|
>
|
|
218
218
|
{itemIds[1]}
|
|
219
219
|
</Accordion.CleanItem>
|
|
@@ -150,19 +150,19 @@ const Component = () => {
|
|
|
150
150
|
<CleanIconButton description="Search" size="small">
|
|
151
151
|
<MagnifyingGlassIconOutline />
|
|
152
152
|
</CleanIconButton>
|
|
153
|
-
<Typography variant="
|
|
153
|
+
<Typography variant="title-4"> Small</Typography>
|
|
154
154
|
</div>
|
|
155
155
|
<div className="flex flex-row gap-token-16 items-center">
|
|
156
156
|
<CleanIconButton description="Search" size="medium">
|
|
157
157
|
<MagnifyingGlassIconOutline />
|
|
158
158
|
</CleanIconButton>
|
|
159
|
-
<Typography variant="
|
|
159
|
+
<Typography variant="title-4"> Medium</Typography>
|
|
160
160
|
</div>
|
|
161
161
|
<div className="flex flex-row gap-token-16 items-center">
|
|
162
162
|
<CleanIconButton description="Search" size="large">
|
|
163
163
|
<MagnifyingGlassIconOutline />
|
|
164
164
|
</CleanIconButton>
|
|
165
|
-
<Typography variant="
|
|
165
|
+
<Typography variant="title-4"> Large</Typography>
|
|
166
166
|
</div>
|
|
167
167
|
</div>
|
|
168
168
|
);
|
|
@@ -186,13 +186,13 @@ const Component = () => {
|
|
|
186
186
|
<CleanIconButton description="Search" variant="neutral">
|
|
187
187
|
<MagnifyingGlassIconOutline />
|
|
188
188
|
</CleanIconButton>
|
|
189
|
-
<Typography variant="
|
|
189
|
+
<Typography variant="title-4">Default</Typography>
|
|
190
190
|
</div>
|
|
191
191
|
<div className="flex flex-row gap-token-16 items-center">
|
|
192
192
|
<CleanIconButton description="Search" variant="danger">
|
|
193
193
|
<MagnifyingGlassIconOutline />
|
|
194
194
|
</CleanIconButton>
|
|
195
|
-
<Typography variant="
|
|
195
|
+
<Typography variant="title-4">Danger</Typography>
|
|
196
196
|
</div>
|
|
197
197
|
</div>
|
|
198
198
|
);
|
|
@@ -648,7 +648,7 @@ export const DatePickerWithTimeZoneBothMode = () => {
|
|
|
648
648
|
|
|
649
649
|
return (
|
|
650
650
|
<div style={{ maxWidth: '400px', padding: '20px' }}>
|
|
651
|
-
<Typography variant="title-
|
|
651
|
+
<Typography variant="title-3" style={{ marginBottom: '16px' }}>
|
|
652
652
|
DatePicker with TimeZone (Both Mode)
|
|
653
653
|
</Typography>
|
|
654
654
|
<Typography variant="body-medium" style={{ marginBottom: '24px' }}>
|
|
@@ -691,7 +691,7 @@ export const DatePickerWithTimeZoneBothMode = () => {
|
|
|
691
691
|
padding: '16px',
|
|
692
692
|
}}
|
|
693
693
|
>
|
|
694
|
-
<Typography variant="
|
|
694
|
+
<Typography variant="title-4">Selected Values:</Typography>
|
|
695
695
|
<Typography variant="body-small">
|
|
696
696
|
<strong>Date: </strong>
|
|
697
697
|
{selectedDate?.toISOString() ?? 'None'}
|
|
@@ -276,7 +276,7 @@ const Component = () => {
|
|
|
276
276
|
return (
|
|
277
277
|
<div className="flex flex-col justify-center items-center gap-y-token-32">
|
|
278
278
|
<Typography
|
|
279
|
-
variant="title-
|
|
279
|
+
variant="title-3"
|
|
280
280
|
className="text-success-text font-semibold"
|
|
281
281
|
>
|
|
282
282
|
Upload Complete!
|
|
@@ -296,7 +296,7 @@ const Component = () => {
|
|
|
296
296
|
{errors.map((message, index) => (
|
|
297
297
|
<Typography
|
|
298
298
|
key={index}
|
|
299
|
-
variant="
|
|
299
|
+
variant="title-4"
|
|
300
300
|
className="text-danger-text font-semibold"
|
|
301
301
|
htmlAttributes={{ role: 'alert' }}
|
|
302
302
|
>
|
|
@@ -143,19 +143,19 @@ const Component = () => {
|
|
|
143
143
|
<IconButton description="Search" size="small">
|
|
144
144
|
<MagnifyingGlassIconOutline />
|
|
145
145
|
</IconButton>
|
|
146
|
-
<Typography variant="
|
|
146
|
+
<Typography variant="title-4"> Small</Typography>
|
|
147
147
|
</div>
|
|
148
148
|
<div className="flex flex-row gap-token-16 items-center">
|
|
149
149
|
<IconButton description="Search" size="medium">
|
|
150
150
|
<MagnifyingGlassIconOutline />
|
|
151
151
|
</IconButton>
|
|
152
|
-
<Typography variant="
|
|
152
|
+
<Typography variant="title-4"> Medium</Typography>
|
|
153
153
|
</div>
|
|
154
154
|
<div className="flex flex-row gap-token-16 items-center">
|
|
155
155
|
<IconButton description="Search" size="large">
|
|
156
156
|
<MagnifyingGlassIconOutline />
|
|
157
157
|
</IconButton>
|
|
158
|
-
<Typography variant="
|
|
158
|
+
<Typography variant="title-4"> Large</Typography>
|
|
159
159
|
</div>
|
|
160
160
|
</div>
|
|
161
161
|
);
|
|
@@ -179,13 +179,13 @@ const Component = () => {
|
|
|
179
179
|
<IconButton description="Search" variant="neutral">
|
|
180
180
|
<MagnifyingGlassIconOutline />
|
|
181
181
|
</IconButton>
|
|
182
|
-
<Typography variant="
|
|
182
|
+
<Typography variant="title-4">Default</Typography>
|
|
183
183
|
</div>
|
|
184
184
|
<div className="flex flex-row gap-token-16 items-center">
|
|
185
185
|
<IconButton description="Search" variant="danger">
|
|
186
186
|
<MagnifyingGlassIconOutline />
|
|
187
187
|
</IconButton>
|
|
188
|
-
<Typography variant="
|
|
188
|
+
<Typography variant="title-4">Danger</Typography>
|
|
189
189
|
</div>
|
|
190
190
|
</div>
|
|
191
191
|
);
|