@lumx/react 2.1.0-alpha.12 → 2.1.0-alpha.15
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/esm/_internal/AlertDialog.js +2 -1
- package/esm/_internal/AlertDialog.js.map +1 -1
- package/esm/_internal/AutocompleteMultiple.js +2 -1
- package/esm/_internal/AutocompleteMultiple.js.map +1 -1
- package/esm/_internal/Avatar2.js +2 -1
- package/esm/_internal/Avatar2.js.map +1 -1
- package/esm/_internal/Badge2.js +2 -1
- package/esm/_internal/Badge2.js.map +1 -1
- package/esm/_internal/Button2.js +2 -1
- package/esm/_internal/Button2.js.map +1 -1
- package/esm/_internal/ButtonGroup.js +2 -1
- package/esm/_internal/ButtonGroup.js.map +1 -1
- package/esm/_internal/ButtonRoot.js +2 -1
- package/esm/_internal/ButtonRoot.js.map +1 -1
- package/esm/_internal/Checkbox2.js +2 -1
- package/esm/_internal/Checkbox2.js.map +1 -1
- package/esm/_internal/Chip2.js +2 -1
- package/esm/_internal/Chip2.js.map +1 -1
- package/esm/_internal/ChipGroup.js +2 -1
- package/esm/_internal/ChipGroup.js.map +1 -1
- package/esm/_internal/ClickAwayProvider.js +2 -1
- package/esm/_internal/ClickAwayProvider.js.map +1 -1
- package/esm/_internal/CommentBlock.js +2 -1
- package/esm/_internal/CommentBlock.js.map +1 -1
- package/esm/_internal/DatePickerField.js +2 -1
- package/esm/_internal/DatePickerField.js.map +1 -1
- package/esm/_internal/Dialog2.js +13 -4
- package/esm/_internal/Dialog2.js.map +1 -1
- package/esm/_internal/Divider2.js +2 -1
- package/esm/_internal/Divider2.js.map +1 -1
- package/esm/_internal/DragHandle.js +2 -1
- package/esm/_internal/DragHandle.js.map +1 -1
- package/esm/_internal/Dropdown2.js +9 -3
- package/esm/_internal/Dropdown2.js.map +1 -1
- package/esm/_internal/ExpansionPanel.js +2 -1
- package/esm/_internal/ExpansionPanel.js.map +1 -1
- package/esm/_internal/Flag2.js +2 -1
- package/esm/_internal/Flag2.js.map +1 -1
- package/esm/_internal/FlexBox.js +2 -1
- package/esm/_internal/FlexBox.js.map +1 -1
- package/esm/_internal/GridItem.js +2 -1
- package/esm/_internal/GridItem.js.map +1 -1
- package/esm/_internal/Icon2.js +2 -1
- package/esm/_internal/Icon2.js.map +1 -1
- package/esm/_internal/IconButton.js +2 -1
- package/esm/_internal/IconButton.js.map +1 -1
- package/esm/_internal/ImageBlock.js +2 -1
- package/esm/_internal/ImageBlock.js.map +1 -1
- package/esm/_internal/InputHelper.js +2 -1
- package/esm/_internal/InputHelper.js.map +1 -1
- package/esm/_internal/InputLabel.js +2 -1
- package/esm/_internal/InputLabel.js.map +1 -1
- package/esm/_internal/Lightbox2.js +2 -1
- package/esm/_internal/Lightbox2.js.map +1 -1
- package/esm/_internal/Link2.js +8 -1
- package/esm/_internal/Link2.js.map +1 -1
- package/esm/_internal/LinkPreview.js +2 -1
- package/esm/_internal/LinkPreview.js.map +1 -1
- package/esm/_internal/List2.js +2 -1
- package/esm/_internal/List2.js.map +1 -1
- package/esm/_internal/ListSubheader.js +2 -1
- package/esm/_internal/ListSubheader.js.map +1 -1
- package/esm/_internal/Message2.js +2 -1
- package/esm/_internal/Message2.js.map +1 -1
- package/esm/_internal/Mosaic2.js +2 -1
- package/esm/_internal/Mosaic2.js.map +1 -1
- package/esm/_internal/Notification2.js +2 -1
- package/esm/_internal/Notification2.js.map +1 -1
- package/esm/_internal/Popover2.js +2 -1
- package/esm/_internal/Popover2.js.map +1 -1
- package/esm/_internal/PostBlock.js +2 -1
- package/esm/_internal/PostBlock.js.map +1 -1
- package/esm/_internal/Progress2.js +2 -1
- package/esm/_internal/Progress2.js.map +1 -1
- package/esm/_internal/ProgressTrackerStepPanel.js +2 -1
- package/esm/_internal/ProgressTrackerStepPanel.js.map +1 -1
- package/esm/_internal/RadioGroup.js +2 -1
- package/esm/_internal/RadioGroup.js.map +1 -1
- package/esm/_internal/SelectMultiple.js +2 -1
- package/esm/_internal/SelectMultiple.js.map +1 -1
- package/esm/_internal/SideNavigationItem.js +2 -1
- package/esm/_internal/SideNavigationItem.js.map +1 -1
- package/esm/_internal/SkeletonTypography.js +2 -1
- package/esm/_internal/SkeletonTypography.js.map +1 -1
- package/esm/_internal/Slider2.js +2 -1
- package/esm/_internal/Slider2.js.map +1 -1
- package/esm/_internal/SlideshowControls.js +2 -1
- package/esm/_internal/SlideshowControls.js.map +1 -1
- package/esm/_internal/Switch2.js +2 -1
- package/esm/_internal/Switch2.js.map +1 -1
- package/esm/_internal/TabPanel.js +2 -1
- package/esm/_internal/TabPanel.js.map +1 -1
- package/esm/_internal/TableRow.js +2 -1
- package/esm/_internal/TableRow.js.map +1 -1
- package/esm/_internal/TextField.js +2 -1
- package/esm/_internal/TextField.js.map +1 -1
- package/esm/_internal/Thumbnail2.js +2 -1
- package/esm/_internal/Thumbnail2.js.map +1 -1
- package/esm/_internal/Toolbar2.js +2 -1
- package/esm/_internal/Toolbar2.js.map +1 -1
- package/esm/_internal/Tooltip2.js +2 -1
- package/esm/_internal/Tooltip2.js.map +1 -1
- package/esm/_internal/Uploader2.js +2 -1
- package/esm/_internal/Uploader2.js.map +1 -1
- package/esm/_internal/UserBlock.js +2 -1
- package/esm/_internal/UserBlock.js.map +1 -1
- package/esm/_internal/_rollupPluginBabelHelpers.js +167 -0
- package/esm/_internal/_rollupPluginBabelHelpers.js.map +1 -0
- package/esm/_internal/alert-dialog.js +3 -1
- package/esm/_internal/alert-dialog.js.map +1 -1
- package/esm/_internal/autocomplete.js +2 -1
- package/esm/_internal/autocomplete.js.map +1 -1
- package/esm/_internal/avatar.js +2 -1
- package/esm/_internal/avatar.js.map +1 -1
- package/esm/_internal/badge.js +2 -1
- package/esm/_internal/badge.js.map +1 -1
- package/esm/_internal/button.js +2 -1
- package/esm/_internal/button.js.map +1 -1
- package/esm/_internal/checkbox.js +2 -1
- package/esm/_internal/checkbox.js.map +1 -1
- package/esm/_internal/chip.js +2 -1
- package/esm/_internal/chip.js.map +1 -1
- package/esm/_internal/comment-block.js +2 -1
- package/esm/_internal/comment-block.js.map +1 -1
- package/esm/_internal/components.js +48 -3
- package/esm/_internal/components.js.map +1 -1
- package/esm/_internal/date-picker.js +2 -1
- package/esm/_internal/date-picker.js.map +1 -1
- package/esm/_internal/dialog.js +3 -1
- package/esm/_internal/dialog.js.map +1 -1
- package/esm/_internal/divider.js +2 -1
- package/esm/_internal/divider.js.map +1 -1
- package/esm/_internal/drag-handle.js +2 -1
- package/esm/_internal/drag-handle.js.map +1 -1
- package/esm/_internal/dropdown.js +2 -1
- package/esm/_internal/dropdown.js.map +1 -1
- package/esm/_internal/expansion-panel.js +2 -1
- package/esm/_internal/expansion-panel.js.map +1 -1
- package/esm/_internal/flag.js +2 -1
- package/esm/_internal/flag.js.map +1 -1
- package/esm/_internal/flex-box.js +2 -1
- package/esm/_internal/flex-box.js.map +1 -1
- package/esm/_internal/getRootClassName.js +2 -166
- package/esm/_internal/getRootClassName.js.map +1 -1
- package/esm/_internal/grid.js +2 -1
- package/esm/_internal/grid.js.map +1 -1
- package/esm/_internal/icon.js +2 -1
- package/esm/_internal/icon.js.map +1 -1
- package/esm/_internal/image-block.js +2 -1
- package/esm/_internal/image-block.js.map +1 -1
- package/esm/_internal/input-helper.js +2 -1
- package/esm/_internal/input-helper.js.map +1 -1
- package/esm/_internal/input-label.js +2 -1
- package/esm/_internal/input-label.js.map +1 -1
- package/esm/_internal/lightbox.js +2 -1
- package/esm/_internal/lightbox.js.map +1 -1
- package/esm/_internal/link-preview.js +2 -1
- package/esm/_internal/link-preview.js.map +1 -1
- package/esm/_internal/link.js +2 -1
- package/esm/_internal/link.js.map +1 -1
- package/esm/_internal/list.js +2 -1
- package/esm/_internal/list.js.map +1 -1
- package/esm/_internal/message.js +2 -1
- package/esm/_internal/message.js.map +1 -1
- package/esm/_internal/mosaic.js +2 -1
- package/esm/_internal/mosaic.js.map +1 -1
- package/esm/_internal/notification.js +2 -1
- package/esm/_internal/notification.js.map +1 -1
- package/esm/_internal/popover.js +2 -1
- package/esm/_internal/popover.js.map +1 -1
- package/esm/_internal/post-block.js +2 -1
- package/esm/_internal/post-block.js.map +1 -1
- package/esm/_internal/progress-tracker.js +2 -1
- package/esm/_internal/progress-tracker.js.map +1 -1
- package/esm/_internal/progress.js +2 -1
- package/esm/_internal/progress.js.map +1 -1
- package/esm/_internal/radio-button.js +2 -1
- package/esm/_internal/radio-button.js.map +1 -1
- package/esm/_internal/renderLink.js +1 -1
- package/esm/_internal/select.js +2 -1
- package/esm/_internal/select.js.map +1 -1
- package/esm/_internal/side-navigation.js +2 -1
- package/esm/_internal/side-navigation.js.map +1 -1
- package/esm/_internal/skeleton.js +2 -1
- package/esm/_internal/skeleton.js.map +1 -1
- package/esm/_internal/slider.js +2 -1
- package/esm/_internal/slider.js.map +1 -1
- package/esm/_internal/slideshow.js +2 -1
- package/esm/_internal/slideshow.js.map +1 -1
- package/esm/_internal/switch.js +2 -1
- package/esm/_internal/switch.js.map +1 -1
- package/esm/_internal/table.js +2 -1
- package/esm/_internal/table.js.map +1 -1
- package/esm/_internal/tabs.js +2 -1
- package/esm/_internal/tabs.js.map +1 -1
- package/esm/_internal/text-field.js +2 -1
- package/esm/_internal/text-field.js.map +1 -1
- package/esm/_internal/thumbnail.js +2 -1
- package/esm/_internal/thumbnail.js.map +1 -1
- package/esm/_internal/toolbar.js +2 -1
- package/esm/_internal/toolbar.js.map +1 -1
- package/esm/_internal/tooltip.js +2 -1
- package/esm/_internal/tooltip.js.map +1 -1
- package/esm/_internal/types.js +1 -1
- package/esm/_internal/uploader.js +2 -1
- package/esm/_internal/uploader.js.map +1 -1
- package/esm/_internal/useDelayedVisibility.js +1 -1
- package/esm/_internal/useDisableBodyScroll.js +9 -1
- package/esm/_internal/useDisableBodyScroll.js.map +1 -1
- package/esm/_internal/useRovingTabIndex.js +1 -1
- package/esm/_internal/user-block.js +2 -1
- package/esm/_internal/user-block.js.map +1 -1
- package/esm/index.js +3 -2
- package/esm/index.js.map +1 -1
- package/package.json +4 -4
- package/src/components/dialog/Dialog.tsx +9 -3
- package/src/components/dropdown/Dropdown.tsx +1 -0
- package/src/components/dropdown/__snapshots__/Dropdown.test.tsx.snap +1 -1
- package/src/components/index.ts +46 -3
- package/src/components/link/Link.stories.tsx +24 -8
- package/src/components/link/Link.tsx +8 -2
- package/src/components/skeleton/SkeletonRectangle.stories.tsx +1 -1
- package/src/components/skeleton/SkeletonRectangle.tsx +1 -1
- package/src/components/skeleton/SkeletonTypography.tsx +2 -2
- package/src/components/skeleton/__snapshots__/SkeletonRectangle.test.tsx.snap +7 -0
- package/src/hooks/useDisableBodyScroll.ts +9 -1
- package/src/hooks/useInfiniteScroll.tsx +14 -3
- package/types.d.ts +68 -5
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { b as _objectWithoutProperties, c as _extends } from './_rollupPluginBabelHelpers.js';
|
|
1
2
|
import { Size, Theme } from './components.js';
|
|
2
|
-
import { g as getRootClassName, a as _objectWithoutProperties, b as _extends, d as classnames, h as handleBasicClasses } from './getRootClassName.js';
|
|
3
3
|
import React, { forwardRef, Children } from 'react';
|
|
4
|
+
import { g as getRootClassName, c as classnames, h as handleBasicClasses } from './getRootClassName.js';
|
|
4
5
|
import { A as Avatar } from './Avatar2.js';
|
|
5
6
|
import isFunction from 'lodash/isFunction';
|
|
6
7
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommentBlock.js","sources":["../../../src/components/comment-block/CommentBlock.tsx"],"sourcesContent":["import React, { Children, forwardRef, KeyboardEvent, KeyboardEventHandler, ReactNode } from 'react';\n\nimport classNames from 'classnames';\n\nimport { Avatar, Size, Theme } from '@lumx/react';\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses, ValueOf } from '@lumx/react/utils';\n\nimport isFunction from 'lodash/isFunction';\nimport { AvatarProps } from '../avatar/Avatar';\n\n/**\n * Comment block variants.\n */\nexport const CommentBlockVariant = {\n indented: 'indented',\n linear: 'linear',\n} as const;\nexport type CommentBlockVariant = ValueOf<typeof CommentBlockVariant>;\n\n/**\n * Defines the props of the component.\n */\nexport interface CommentBlockProps extends GenericProps {\n /** Action toolbar content. */\n actions?: ReactNode;\n /** Props to pass to the avatar. */\n avatarProps: AvatarProps;\n /** Comment block replies. */\n children?: ReactNode;\n /** Comment date. */\n date: string;\n /** Whether the component has actions to display or not. */\n hasActions?: boolean;\n /** Action toolbar header content. */\n headerActions?: ReactNode;\n /** Whether the component is open or not. */\n isOpen?: boolean;\n /** Whether the comment is relevant or not. */\n isRelevant?: boolean;\n /** Comment author name. */\n name: string;\n /** On click callback. */\n onClick?(): void;\n /** On mouse enter callback. */\n onMouseEnter?(): void;\n /** On mouse leave callback. */\n onMouseLeave?(): void;\n /** Comment content. */\n text: ReactNode | string;\n /** Theme adapting the component to light or dark background. */\n theme?: Theme;\n /** Comment variant. */\n variant?: CommentBlockVariant;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'CommentBlock';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Component default props.\n */\nconst DEFAULT_PROPS: Partial<CommentBlockProps> = {\n theme: Theme.light,\n variant: CommentBlockVariant.indented,\n};\n\n/**\n * CommentBlock component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const CommentBlock: Comp<CommentBlockProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n actions,\n avatarProps,\n children,\n className,\n date,\n hasActions,\n headerActions,\n isOpen,\n isRelevant,\n name,\n onClick,\n onMouseEnter,\n onMouseLeave,\n text,\n theme,\n variant,\n ...forwardedProps\n } = props;\n const enterKeyPress: KeyboardEventHandler<HTMLElement> = (evt: KeyboardEvent<HTMLElement>) => {\n if (evt.key === 'Enter' && isFunction(onClick)) {\n onClick();\n }\n };\n const hasChildren = Children.count(children) > 0;\n\n return (\n <div\n ref={ref}\n className={classNames(\n className,\n handleBasicClasses({\n hasChildren: hasChildren && isOpen,\n hasIndentedChildren: hasChildren && variant === CommentBlockVariant.indented,\n hasLinearChildren: hasChildren && variant === CommentBlockVariant.linear,\n isRelevant,\n prefix: CLASSNAME,\n theme,\n }),\n )}\n {...forwardedProps}\n >\n <div className={`${CLASSNAME}__wrapper`}>\n <div className={`${CLASSNAME}__avatar`}>\n <Avatar\n {...avatarProps}\n size={Size.m}\n tabIndex={onClick ? 0 : -1}\n onClick={onClick}\n onKeyPress={enterKeyPress}\n />\n </div>\n\n <div className={`${CLASSNAME}__container`}>\n <div className={`${CLASSNAME}__content`}>\n <div className={`${CLASSNAME}__meta`}>\n <span\n className={`${CLASSNAME}__name`}\n onClick={onClick}\n onKeyPress={enterKeyPress}\n onMouseEnter={onMouseEnter}\n onMouseLeave={onMouseLeave}\n role=\"button\"\n tabIndex={onClick ? 0 : -1}\n >\n {name}\n </span>\n {date && <span className={`${CLASSNAME}__date`}>{date}</span>}\n {headerActions && <span className={`${CLASSNAME}__header-actions`}>{headerActions}</span>}\n </div>\n\n <div className={`${CLASSNAME}__text`}>{text}</div>\n </div>\n {hasActions && <div className={`${CLASSNAME}__actions`}>{actions}</div>}\n </div>\n </div>\n\n {hasChildren && isOpen && <div className={`${CLASSNAME}__children`}>{children}</div>}\n </div>\n );\n});\nCommentBlock.displayName = COMPONENT_NAME;\nCommentBlock.className = CLASSNAME;\nCommentBlock.defaultProps = DEFAULT_PROPS;\n"],"names":["CommentBlockVariant","indented","linear","COMPONENT_NAME","CLASSNAME","getRootClassName","DEFAULT_PROPS","theme","Theme","light","variant","CommentBlock","forwardRef","props","ref","actions","avatarProps","children","className","date","hasActions","headerActions","isOpen","isRelevant","name","onClick","onMouseEnter","onMouseLeave","text","forwardedProps","enterKeyPress","evt","key","isFunction","hasChildren","Children","count","classNames","handleBasicClasses","hasIndentedChildren","hasLinearChildren","prefix","Size","m","displayName","defaultProps"],"mappings":"
|
|
1
|
+
{"version":3,"file":"CommentBlock.js","sources":["../../../src/components/comment-block/CommentBlock.tsx"],"sourcesContent":["import React, { Children, forwardRef, KeyboardEvent, KeyboardEventHandler, ReactNode } from 'react';\n\nimport classNames from 'classnames';\n\nimport { Avatar, Size, Theme } from '@lumx/react';\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses, ValueOf } from '@lumx/react/utils';\n\nimport isFunction from 'lodash/isFunction';\nimport { AvatarProps } from '../avatar/Avatar';\n\n/**\n * Comment block variants.\n */\nexport const CommentBlockVariant = {\n indented: 'indented',\n linear: 'linear',\n} as const;\nexport type CommentBlockVariant = ValueOf<typeof CommentBlockVariant>;\n\n/**\n * Defines the props of the component.\n */\nexport interface CommentBlockProps extends GenericProps {\n /** Action toolbar content. */\n actions?: ReactNode;\n /** Props to pass to the avatar. */\n avatarProps: AvatarProps;\n /** Comment block replies. */\n children?: ReactNode;\n /** Comment date. */\n date: string;\n /** Whether the component has actions to display or not. */\n hasActions?: boolean;\n /** Action toolbar header content. */\n headerActions?: ReactNode;\n /** Whether the component is open or not. */\n isOpen?: boolean;\n /** Whether the comment is relevant or not. */\n isRelevant?: boolean;\n /** Comment author name. */\n name: string;\n /** On click callback. */\n onClick?(): void;\n /** On mouse enter callback. */\n onMouseEnter?(): void;\n /** On mouse leave callback. */\n onMouseLeave?(): void;\n /** Comment content. */\n text: ReactNode | string;\n /** Theme adapting the component to light or dark background. */\n theme?: Theme;\n /** Comment variant. */\n variant?: CommentBlockVariant;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'CommentBlock';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Component default props.\n */\nconst DEFAULT_PROPS: Partial<CommentBlockProps> = {\n theme: Theme.light,\n variant: CommentBlockVariant.indented,\n};\n\n/**\n * CommentBlock component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const CommentBlock: Comp<CommentBlockProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n actions,\n avatarProps,\n children,\n className,\n date,\n hasActions,\n headerActions,\n isOpen,\n isRelevant,\n name,\n onClick,\n onMouseEnter,\n onMouseLeave,\n text,\n theme,\n variant,\n ...forwardedProps\n } = props;\n const enterKeyPress: KeyboardEventHandler<HTMLElement> = (evt: KeyboardEvent<HTMLElement>) => {\n if (evt.key === 'Enter' && isFunction(onClick)) {\n onClick();\n }\n };\n const hasChildren = Children.count(children) > 0;\n\n return (\n <div\n ref={ref}\n className={classNames(\n className,\n handleBasicClasses({\n hasChildren: hasChildren && isOpen,\n hasIndentedChildren: hasChildren && variant === CommentBlockVariant.indented,\n hasLinearChildren: hasChildren && variant === CommentBlockVariant.linear,\n isRelevant,\n prefix: CLASSNAME,\n theme,\n }),\n )}\n {...forwardedProps}\n >\n <div className={`${CLASSNAME}__wrapper`}>\n <div className={`${CLASSNAME}__avatar`}>\n <Avatar\n {...avatarProps}\n size={Size.m}\n tabIndex={onClick ? 0 : -1}\n onClick={onClick}\n onKeyPress={enterKeyPress}\n />\n </div>\n\n <div className={`${CLASSNAME}__container`}>\n <div className={`${CLASSNAME}__content`}>\n <div className={`${CLASSNAME}__meta`}>\n <span\n className={`${CLASSNAME}__name`}\n onClick={onClick}\n onKeyPress={enterKeyPress}\n onMouseEnter={onMouseEnter}\n onMouseLeave={onMouseLeave}\n role=\"button\"\n tabIndex={onClick ? 0 : -1}\n >\n {name}\n </span>\n {date && <span className={`${CLASSNAME}__date`}>{date}</span>}\n {headerActions && <span className={`${CLASSNAME}__header-actions`}>{headerActions}</span>}\n </div>\n\n <div className={`${CLASSNAME}__text`}>{text}</div>\n </div>\n {hasActions && <div className={`${CLASSNAME}__actions`}>{actions}</div>}\n </div>\n </div>\n\n {hasChildren && isOpen && <div className={`${CLASSNAME}__children`}>{children}</div>}\n </div>\n );\n});\nCommentBlock.displayName = COMPONENT_NAME;\nCommentBlock.className = CLASSNAME;\nCommentBlock.defaultProps = DEFAULT_PROPS;\n"],"names":["CommentBlockVariant","indented","linear","COMPONENT_NAME","CLASSNAME","getRootClassName","DEFAULT_PROPS","theme","Theme","light","variant","CommentBlock","forwardRef","props","ref","actions","avatarProps","children","className","date","hasActions","headerActions","isOpen","isRelevant","name","onClick","onMouseEnter","onMouseLeave","text","forwardedProps","enterKeyPress","evt","key","isFunction","hasChildren","Children","count","classNames","handleBasicClasses","hasIndentedChildren","hasLinearChildren","prefix","Size","m","displayName","defaultProps"],"mappings":";;;;;;;AAUA;;;IAGaA,mBAAmB,GAAG;AAC/BC,EAAAA,QAAQ,EAAE,UADqB;AAE/BC,EAAAA,MAAM,EAAE;AAFuB;;AA0CnC;;;AAGA,IAAMC,cAAc,GAAG,cAAvB;AAEA;;;;AAGA,IAAMC,SAAS,GAAGC,gBAAgB,CAACF,cAAD,CAAlC;AAEA;;;;AAGA,IAAMG,aAAyC,GAAG;AAC9CC,EAAAA,KAAK,EAAEC,KAAK,CAACC,KADiC;AAE9CC,EAAAA,OAAO,EAAEV,mBAAmB,CAACC;AAFiB,CAAlD;AAKA;;;;;;;;IAOaU,YAAqD,GAAGC,UAAU,CAAC,UAACC,KAAD,EAAQC,GAAR,EAAgB;AAAA,MAExFC,OAFwF,GAmBxFF,KAnBwF,CAExFE,OAFwF;AAAA,MAGxFC,WAHwF,GAmBxFH,KAnBwF,CAGxFG,WAHwF;AAAA,MAIxFC,QAJwF,GAmBxFJ,KAnBwF,CAIxFI,QAJwF;AAAA,MAKxFC,SALwF,GAmBxFL,KAnBwF,CAKxFK,SALwF;AAAA,MAMxFC,IANwF,GAmBxFN,KAnBwF,CAMxFM,IANwF;AAAA,MAOxFC,UAPwF,GAmBxFP,KAnBwF,CAOxFO,UAPwF;AAAA,MAQxFC,aARwF,GAmBxFR,KAnBwF,CAQxFQ,aARwF;AAAA,MASxFC,MATwF,GAmBxFT,KAnBwF,CASxFS,MATwF;AAAA,MAUxFC,UAVwF,GAmBxFV,KAnBwF,CAUxFU,UAVwF;AAAA,MAWxFC,IAXwF,GAmBxFX,KAnBwF,CAWxFW,IAXwF;AAAA,MAYxFC,OAZwF,GA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edToArray } from './_rollupPluginBabelHelpers.js';
|
|
1
2
|
import { Emphasis } from './components.js';
|
|
2
|
-
import { g as getRootClassName, b as _extends, d as classnames, _ as _defineProperty, a as _objectWithoutProperties, f as _slicedToArray } from './getRootClassName.js';
|
|
3
3
|
import React, { forwardRef, useState, useRef, useCallback } from 'react';
|
|
4
|
+
import { g as getRootClassName, c as classnames } from './getRootClassName.js';
|
|
4
5
|
import { f as mdiChevronRight, g as mdiChevronLeft } from './mdi.js';
|
|
5
6
|
import 'lodash/isBoolean';
|
|
6
7
|
import 'lodash/isEmpty';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatePickerField.js","sources":["../../../src/components/date-picker/constants.ts","../../../../lumx-core/src/js/date-picker.ts","../../../src/components/date-picker/DatePickerControlled.tsx","../../../src/components/date-picker/DatePicker.tsx","../../../src/components/date-picker/DatePickerField.tsx"],"sourcesContent":["import { getRootClassName } from '@lumx/react/utils';\n\n/**\n * Component display name.\n */\nexport const COMPONENT_NAME = 'DatePicker';\n\n/**\n * Component default class name and class prefix.\n */\nexport const CLASSNAME = getRootClassName(COMPONENT_NAME);\n","import range from 'lodash/range';\nimport mMoment, { Moment } from 'moment';\nimport { extendMoment } from 'moment-range';\n\nconst moment = extendMoment(mMoment as any);\n\nconst DAYS_PER_WEEK = 7;\n\ninterface AnnotatedDate {\n date: Moment;\n isDisplayed: boolean;\n isClickable: boolean;\n isToday: boolean;\n}\n\n/**\n * Get the list of days in a week based on locale.\n *\n * @param locale The locale using to generate the order of days in a week.\n * @return The list of days in a week based on locale.\n */\nexport function getWeekDays(locale: string): Moment[] {\n return range(DAYS_PER_WEEK).map((_, i) => moment().locale(locale).weekday(i));\n}\n\n/**\n * Get month calendar based on locale and start date.\n *\n * @param locale The locale using to generate the order of days in a week.\n * @param selectedMonth The selected month.\n * @return The list of days in a week based on locale.\n */\nexport function getMonthCalendar(locale: string, selectedMonth?: Moment): Moment[] {\n const firstDayOfMonth = moment(selectedMonth).startOf('month');\n const endDayOfMonth = moment(selectedMonth).endOf('month');\n // The first day of the week depends on the locale used. In FR the first day is a monday but in EN the first day is sunday\n const firstDay = firstDayOfMonth.locale(locale).startOf('week');\n const monthRange = moment.range(firstDay.toDate(), endDayOfMonth.toDate());\n\n return Array.from(monthRange.by('day'));\n}\n\n/**\n * Get month calendar based on locale and start date.\n * Each day is annotated to know if they are displayed and/or clickable.\n *\n * @param locale The locale using to generate the order of days in a week.\n * @param minDate The first selectable date.\n * @param maxDate The last selectable date.\n * @param selectedMonth The selected month.\n * @return The list of days in a week based on locale.\n */\nexport function getAnnotatedMonthCalendar(\n locale: string,\n minDate?: Date,\n maxDate?: Date,\n selectedMonth?: Moment,\n): AnnotatedDate[] {\n const month = moment(selectedMonth).locale(locale).month();\n\n const clickableRange = moment.range(minDate!, maxDate!);\n\n return getMonthCalendar(locale, selectedMonth).map((date) => {\n return {\n date,\n isClickable: clickableRange.contains(date),\n isDisplayed: date.month() === month,\n isToday: date.isSame(moment(), 'day'),\n };\n });\n}\n","import React, { forwardRef } from 'react';\nimport moment from 'moment';\nimport classNames from 'classnames';\nimport { DatePickerProps, Emphasis, IconButton, Toolbar } from '@lumx/react';\nimport { mdiChevronLeft, mdiChevronRight } from '@lumx/icons';\nimport { getAnnotatedMonthCalendar, getWeekDays } from '@lumx/core/js/date-picker';\nimport { Comp } from '@lumx/react/utils';\nimport { CLASSNAME } from './constants';\n\n/**\n * Defines the props of the component.\n */\nexport interface DatePickerControlledProps extends DatePickerProps {\n /** Selected month to display. */\n selectedMonth: Date;\n /** On previous month change callback. */\n onPrevMonthChange(): void;\n /** On next month change callback. */\n onNextMonthChange(): void;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'DatePickerControlled';\n\n/**\n * DatePickerControlled component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const DatePickerControlled: Comp<DatePickerControlledProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n locale,\n maxDate,\n minDate,\n nextButtonProps,\n onChange,\n onNextMonthChange,\n onPrevMonthChange,\n previousButtonProps,\n selectedMonth,\n todayOrSelectedDateRef,\n value,\n } = props;\n const days = React.useMemo(() => {\n return getAnnotatedMonthCalendar(locale, minDate, maxDate, moment(selectedMonth));\n }, [locale, minDate, maxDate, selectedMonth]);\n\n const weekDays = React.useMemo(() => {\n return getWeekDays(locale);\n }, [locale]);\n\n return (\n <div ref={ref} className={`${CLASSNAME}`}>\n <Toolbar\n className={`${CLASSNAME}__toolbar`}\n after={\n <IconButton\n {...nextButtonProps}\n emphasis={Emphasis.low}\n icon={mdiChevronRight}\n onClick={onNextMonthChange}\n />\n }\n before={\n <IconButton\n {...previousButtonProps}\n emphasis={Emphasis.low}\n icon={mdiChevronLeft}\n onClick={onPrevMonthChange}\n />\n }\n label={\n <span className={`${CLASSNAME}__month`}>\n {moment(selectedMonth).locale(locale).format('MMMM YYYY')}\n </span>\n }\n />\n <div className={`${CLASSNAME}__calendar`}>\n <div className={`${CLASSNAME}__week-days ${CLASSNAME}__days-wrapper`}>\n {weekDays.map((weekDay) => (\n <div key={weekDay.unix()} className={`${CLASSNAME}__day-wrapper`}>\n <span className={`${CLASSNAME}__week-day`}>\n {weekDay.format('dddd').slice(0, 1).toLocaleUpperCase()}\n </span>\n </div>\n ))}\n </div>\n\n <div className={`${CLASSNAME}__month-days ${CLASSNAME}__days-wrapper`}>\n {days.map((annotatedDate) => {\n if (annotatedDate.isDisplayed) {\n return (\n <div key={annotatedDate.date.unix()} className={`${CLASSNAME}__day-wrapper`}>\n <button\n ref={\n (value && annotatedDate.date.isSame(value, 'day')) ||\n (!value && annotatedDate.isToday)\n ? todayOrSelectedDateRef\n : null\n }\n className={classNames(`${CLASSNAME}__month-day`, {\n [`${CLASSNAME}__month-day--is-selected`]:\n value && annotatedDate.date.isSame(value, 'day'),\n [`${CLASSNAME}__month-day--is-today`]:\n annotatedDate.isClickable && annotatedDate.isToday,\n })}\n disabled={!annotatedDate.isClickable}\n type=\"button\"\n onClick={() => onChange(moment(annotatedDate.date).toDate())}\n >\n <span>{annotatedDate.date.format('DD')}</span>\n </button>\n </div>\n );\n }\n return <div key={annotatedDate.date.unix()} className={`${CLASSNAME}__day-wrapper`} />;\n })}\n </div>\n </div>\n </div>\n );\n});\nDatePickerControlled.displayName = COMPONENT_NAME;\nDatePickerControlled.className = CLASSNAME;\n","import moment from 'moment';\nimport React, { forwardRef, useState } from 'react';\nimport { Comp } from '@lumx/react/utils';\nimport { CLASSNAME, COMPONENT_NAME } from './constants';\nimport { DatePickerControlled } from './DatePickerControlled';\nimport { DatePickerProps } from './types';\n\n/**\n * DatePicker component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const DatePicker: Comp<DatePickerProps, HTMLDivElement> = forwardRef((props, ref) => {\n const { defaultMonth, locale, value, onChange, ...forwardedProps } = props;\n let castedValue;\n if (value) {\n castedValue = moment(value);\n } else if (defaultMonth) {\n castedValue = moment(defaultMonth);\n }\n if (castedValue && !castedValue.isValid()) {\n // eslint-disable-next-line no-console\n console.warn(`[@lumx/react/DatePicker] Invalid date provided ${castedValue}`);\n }\n const selectedDay = castedValue && castedValue.isValid() ? castedValue : moment();\n\n const [monthOffset, setMonthOffset] = useState(0);\n\n const setPrevMonth = () => setMonthOffset(monthOffset - 1);\n const setNextMonth = () => setMonthOffset(monthOffset + 1);\n\n const onDatePickerChange = (newDate?: Date) => {\n onChange(newDate);\n setMonthOffset(0);\n };\n\n const selectedMonth = moment(selectedDay).locale(locale).add(monthOffset, 'months').toDate();\n\n return (\n <DatePickerControlled\n ref={ref}\n {...forwardedProps}\n defaultMonth={defaultMonth}\n locale={locale}\n value={value}\n onPrevMonthChange={setPrevMonth}\n onNextMonthChange={setNextMonth}\n selectedMonth={selectedMonth}\n onChange={onDatePickerChange}\n />\n );\n});\nDatePicker.displayName = COMPONENT_NAME;\nDatePicker.className = CLASSNAME;\n","import { DatePicker, Placement, Popover, TextField, IconButtonProps } from '@lumx/react';\nimport { useFocusTrap } from '@lumx/react/hooks/useFocusTrap';\n\nimport moment from 'moment';\n\nimport React, { forwardRef, SyntheticEvent, useCallback, useRef, useState } from 'react';\n\nimport { useFocus } from '@lumx/react/hooks/useFocus';\nimport { Comp, GenericProps } from '@lumx/react/utils';\n\n/**\n * Defines the props of the component.\n */\nexport interface DatePickerFieldProps extends GenericProps {\n /** Default month. */\n defaultMonth?: Date;\n /** Whether the component is disabled or not. */\n isDisabled?: boolean;\n /** Locale (language or region) to use. */\n locale: string;\n /** Date after which dates can't be selected. */\n maxDate?: Date;\n /** Date before which dates can't be selected. */\n minDate?: Date;\n /** Native input name property. */\n name?: string;\n /** Props to pass to the next month button (minus those already set by the DatePickerControlled props). */\n nextButtonProps: Pick<IconButtonProps, 'label'> & Omit<IconButtonProps, 'label' | 'onClick' | 'icon' | 'emphasis'>;\n /** Props to pass to the previous month button (minus those already set by the DatePickerControlled props). */\n previousButtonProps: Pick<IconButtonProps, 'label'> &\n Omit<IconButtonProps, 'label' | 'onClick' | 'icon' | 'emphasis'>;\n /** Currently selected date. */\n value: Date | undefined;\n /** On change callback. */\n onChange(value: Date | undefined, name?: string, event?: SyntheticEvent): void;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'DatePickerField';\n\n/**\n * DatePickerField component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const DatePickerField: Comp<DatePickerFieldProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n defaultMonth,\n disabled,\n isDisabled = disabled,\n locale,\n maxDate,\n minDate,\n name,\n nextButtonProps,\n onChange,\n previousButtonProps,\n value,\n ...forwardedProps\n } = props;\n const wrapperRef = useRef(null);\n const anchorRef = useRef(null);\n\n const [isOpen, setIsOpen] = useState(false);\n\n const toggleSimpleMenu = () => {\n setIsOpen(!isOpen);\n };\n\n const onClose = useCallback(() => {\n setIsOpen(false);\n }, []);\n\n useFocus(anchorRef.current, isOpen);\n const handleKeyboardNav = (evt: React.KeyboardEvent) => {\n if ((evt.key === 'Enter' || evt.key === ' ') && toggleSimpleMenu) {\n toggleSimpleMenu();\n }\n };\n\n // Handle focus trap.\n const todayOrSelectedDateRef = useRef<HTMLButtonElement>(null);\n useFocusTrap(todayOrSelectedDateRef.current && wrapperRef.current, todayOrSelectedDateRef.current);\n\n const onTextFieldChange = (textFieldValue: string, textFieldName?: string, event?: SyntheticEvent) => {\n if (!textFieldValue) {\n onChange(undefined, textFieldName, event);\n }\n };\n\n const onDatePickerChange = (newDate?: Date) => {\n onChange(newDate, name);\n onClose();\n };\n\n return (\n <>\n <TextField\n ref={ref}\n {...forwardedProps}\n name={name}\n forceFocusStyle={isOpen}\n textFieldRef={anchorRef}\n value={value ? moment(value).locale(locale).format('LL') : ''}\n onClick={toggleSimpleMenu}\n onChange={onTextFieldChange}\n onKeyPress={handleKeyboardNav}\n isDisabled={isDisabled}\n readOnly\n />\n {isOpen ? (\n <Popover\n anchorRef={anchorRef}\n placement={Placement.BOTTOM_START}\n isOpen={isOpen}\n onClose={onClose}\n closeOnClickAway\n closeOnEscape\n >\n <div ref={wrapperRef}>\n <DatePicker\n locale={locale}\n maxDate={maxDate}\n minDate={minDate}\n value={value}\n onChange={onDatePickerChange}\n todayOrSelectedDateRef={todayOrSelectedDateRef}\n defaultMonth={defaultMonth}\n nextButtonProps={nextButtonProps}\n previousButtonProps={previousButtonProps}\n />\n </div>\n </Popover>\n ) : null}\n </>\n );\n});\nDatePickerField.displayName = COMPONENT_NAME;\n"],"names":["COMPONENT_NAME","CLASSNAME","getRootClassName","moment","extendMoment","mMoment","DAYS_PER_WEEK","getWeekDays","locale","range","map","_","i","weekday","getMonthCalendar","selectedMonth","firstDayOfMonth","startOf","endDayOfMonth","endOf","firstDay","monthRange","toDate","Array","from","by","getAnnotatedMonthCalendar","minDate","maxDate","month","clickableRange","date","isClickable","contains","isDisplayed","isToday","isSame","DatePickerControlled","forwardRef","props","ref","nextButtonProps","onChange","onNextMonthChange","onPrevMonthChange","previousButtonProps","todayOrSelectedDateRef","value","days","React","useMemo","weekDays","Emphasis","low","mdiChevronRight","mdiChevronLeft","format","weekDay","unix","slice","toLocaleUpperCase","annotatedDate","classNames","displayName","className","DatePicker","defaultMonth","forwardedProps","castedValue","isValid","console","warn","selectedDay","useState","monthOffset","setMonthOffset","setPrevMonth","setNextMonth","onDatePickerChange","newDate","add","DatePickerField","disabled","isDisabled","name","wrapperRef","useRef","anchorRef","isOpen","setIsOpen","toggleSimpleMenu","onClose","useCallback","useFocus","current","handleKeyboardNav","evt","key","useFocusTrap","onTextFieldChange","textFieldValue","textFieldName","event","undefined","Placement","BOTTOM_START"],"mappings":";;;;;;;;;;;;;;;;;AAEA;;;;AAGO,IAAMA,cAAc,GAAG,YAAvB;AAEP;;;;AAGO,IAAMC,SAAS,GAAGC,gBAAgB,CAACF,cAAD,CAAlC;;ACNP,IAAMG,MAAM,GAAGC,YAAY,CAACC,QAAD,CAA3B;AAEA,IAAMC,aAAa,GAAG,CAAtB;;AASA;;;;;;AAMO,SAASC,WAAT,CAAqBC,MAArB,EAA+C;AAClD,SAAOC,KAAK,CAACH,aAAD,CAAL,CAAqBI,GAArB,CAAyB,UAACC,CAAD,EAAIC,CAAJ;AAAA,WAAUT,MAAM,GAAGK,MAAT,CAAgBA,MAAhB,EAAwBK,OAAxB,CAAgCD,CAAhC,CAAV;AAAA,GAAzB,CAAP;AACH;AAED;;;;;;;;AAOO,SAASE,gBAAT,CAA0BN,MAA1B,EAA0CO,aAA1C,EAA4E;AAC/E,MAAMC,eAAe,GAAGb,MAAM,CAACY,aAAD,CAAN,CAAsBE,OAAtB,CAA8B,OAA9B,CAAxB;AACA,MAAMC,aAAa,GAAGf,MAAM,CAACY,aAAD,CAAN,CAAsBI,KAAtB,CAA4B,OAA5B,CAAtB,CAF+E;;AAI/E,MAAMC,QAAQ,GAAGJ,eAAe,CAACR,MAAhB,CAAuBA,MAAvB,EAA+BS,OAA/B,CAAuC,MAAvC,CAAjB;AACA,MAAMI,UAA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,IAAA,UAAU,EAAEZ,UAVhB;AAWI,IAAA,QAAQ;AAXZ,KADJ,EAcKK,MAAM,GACH,oBAAC,OAAD;AACI,IAAA,SAAS,EAAED,SADf;AAEI,IAAA,SAAS,EAAEiB,SAAS,CAACC,YAFzB;AAGI,IAAA,MAAM,EAAEjB,MAHZ;AAII,IAAA,OAAO,EAAEG,OAJb;AAKI,IAAA,gBAAgB,MALpB;AAMI,IAAA,aAAa;AANjB,KAQI;AAAK,IAAA,GAAG,EAAEN;AAAV,KACI,oBAAC,UAAD;AACI,IAAA,MAAM,EAAE7E,MADZ;AAEI,IAAA,OAAO,EAAEoB,OAFb;AAGI,IAAA,OAAO,EAAED,OAHb;AAII,IAAA,KAAK,EAAEoB,KAJX;AAKI,IAAA,QAAQ,EAAE+B,kBALd;AAMI,IAAA,sBAAsB,EAAEhC,sBAN5B;AAOI,IAAA,YAAY,EAAEoB,YAPlB;AAQI,IAAA,eAAe,EAAEzB,eARrB;AASI,IAAA,mBAAmB,EAAEI;AATzB,IADJ,CARJ,CADG,GAuBH,IArCR,CADJ;AAyCH,CA3FoF;AA4FrFoC,eAAe,CAAClB,WAAhB,GAA8B/D,gBAA9B;;;;"}
|
|
1
|
+
{"version":3,"file":"DatePickerField.js","sources":["../../../src/components/date-picker/constants.ts","../../../../lumx-core/src/js/date-picker.ts","../../../src/components/date-picker/DatePickerControlled.tsx","../../../src/components/date-picker/DatePicker.tsx","../../../src/components/date-picker/DatePickerField.tsx"],"sourcesContent":["import { getRootClassName } from '@lumx/react/utils';\n\n/**\n * Component display name.\n */\nexport const COMPONENT_NAME = 'DatePicker';\n\n/**\n * Component default class name and class prefix.\n */\nexport const CLASSNAME = getRootClassName(COMPONENT_NAME);\n","import range from 'lodash/range';\nimport mMoment, { Moment } from 'moment';\nimport { extendMoment } from 'moment-range';\n\nconst moment = extendMoment(mMoment as any);\n\nconst DAYS_PER_WEEK = 7;\n\ninterface AnnotatedDate {\n date: Moment;\n isDisplayed: boolean;\n isClickable: boolean;\n isToday: boolean;\n}\n\n/**\n * Get the list of days in a week based on locale.\n *\n * @param locale The locale using to generate the order of days in a week.\n * @return The list of days in a week based on locale.\n */\nexport function getWeekDays(locale: string): Moment[] {\n return range(DAYS_PER_WEEK).map((_, i) => moment().locale(locale).weekday(i));\n}\n\n/**\n * Get month calendar based on locale and start date.\n *\n * @param locale The locale using to generate the order of days in a week.\n * @param selectedMonth The selected month.\n * @return The list of days in a week based on locale.\n */\nexport function getMonthCalendar(locale: string, selectedMonth?: Moment): Moment[] {\n const firstDayOfMonth = moment(selectedMonth).startOf('month');\n const endDayOfMonth = moment(selectedMonth).endOf('month');\n // The first day of the week depends on the locale used. In FR the first day is a monday but in EN the first day is sunday\n const firstDay = firstDayOfMonth.locale(locale).startOf('week');\n const monthRange = moment.range(firstDay.toDate(), endDayOfMonth.toDate());\n\n return Array.from(monthRange.by('day'));\n}\n\n/**\n * Get month calendar based on locale and start date.\n * Each day is annotated to know if they are displayed and/or clickable.\n *\n * @param locale The locale using to generate the order of days in a week.\n * @param minDate The first selectable date.\n * @param maxDate The last selectable date.\n * @param selectedMonth The selected month.\n * @return The list of days in a week based on locale.\n */\nexport function getAnnotatedMonthCalendar(\n locale: string,\n minDate?: Date,\n maxDate?: Date,\n selectedMonth?: Moment,\n): AnnotatedDate[] {\n const month = moment(selectedMonth).locale(locale).month();\n\n const clickableRange = moment.range(minDate!, maxDate!);\n\n return getMonthCalendar(locale, selectedMonth).map((date) => {\n return {\n date,\n isClickable: clickableRange.contains(date),\n isDisplayed: date.month() === month,\n isToday: date.isSame(moment(), 'day'),\n };\n });\n}\n","import React, { forwardRef } from 'react';\nimport moment from 'moment';\nimport classNames from 'classnames';\nimport { DatePickerProps, Emphasis, IconButton, Toolbar } from '@lumx/react';\nimport { mdiChevronLeft, mdiChevronRight } from '@lumx/icons';\nimport { getAnnotatedMonthCalendar, getWeekDays } from '@lumx/core/js/date-picker';\nimport { Comp } from '@lumx/react/utils';\nimport { CLASSNAME } from './constants';\n\n/**\n * Defines the props of the component.\n */\nexport interface DatePickerControlledProps extends DatePickerProps {\n /** Selected month to display. */\n selectedMonth: Date;\n /** On previous month change callback. */\n onPrevMonthChange(): void;\n /** On next month change callback. */\n onNextMonthChange(): void;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'DatePickerControlled';\n\n/**\n * DatePickerControlled component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const DatePickerControlled: Comp<DatePickerControlledProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n locale,\n maxDate,\n minDate,\n nextButtonProps,\n onChange,\n onNextMonthChange,\n onPrevMonthChange,\n previousButtonProps,\n selectedMonth,\n todayOrSelectedDateRef,\n value,\n } = props;\n const days = React.useMemo(() => {\n return getAnnotatedMonthCalendar(locale, minDate, maxDate, moment(selectedMonth));\n }, [locale, minDate, maxDate, selectedMonth]);\n\n const weekDays = React.useMemo(() => {\n return getWeekDays(locale);\n }, [locale]);\n\n return (\n <div ref={ref} className={`${CLASSNAME}`}>\n <Toolbar\n className={`${CLASSNAME}__toolbar`}\n after={\n <IconButton\n {...nextButtonProps}\n emphasis={Emphasis.low}\n icon={mdiChevronRight}\n onClick={onNextMonthChange}\n />\n }\n before={\n <IconButton\n {...previousButtonProps}\n emphasis={Emphasis.low}\n icon={mdiChevronLeft}\n onClick={onPrevMonthChange}\n />\n }\n label={\n <span className={`${CLASSNAME}__month`}>\n {moment(selectedMonth).locale(locale).format('MMMM YYYY')}\n </span>\n }\n />\n <div className={`${CLASSNAME}__calendar`}>\n <div className={`${CLASSNAME}__week-days ${CLASSNAME}__days-wrapper`}>\n {weekDays.map((weekDay) => (\n <div key={weekDay.unix()} className={`${CLASSNAME}__day-wrapper`}>\n <span className={`${CLASSNAME}__week-day`}>\n {weekDay.format('dddd').slice(0, 1).toLocaleUpperCase()}\n </span>\n </div>\n ))}\n </div>\n\n <div className={`${CLASSNAME}__month-days ${CLASSNAME}__days-wrapper`}>\n {days.map((annotatedDate) => {\n if (annotatedDate.isDisplayed) {\n return (\n <div key={annotatedDate.date.unix()} className={`${CLASSNAME}__day-wrapper`}>\n <button\n ref={\n (value && annotatedDate.date.isSame(value, 'day')) ||\n (!value && annotatedDate.isToday)\n ? todayOrSelectedDateRef\n : null\n }\n className={classNames(`${CLASSNAME}__month-day`, {\n [`${CLASSNAME}__month-day--is-selected`]:\n value && annotatedDate.date.isSame(value, 'day'),\n [`${CLASSNAME}__month-day--is-today`]:\n annotatedDate.isClickable && annotatedDate.isToday,\n })}\n disabled={!annotatedDate.isClickable}\n type=\"button\"\n onClick={() => onChange(moment(annotatedDate.date).toDate())}\n >\n <span>{annotatedDate.date.format('DD')}</span>\n </button>\n </div>\n );\n }\n return <div key={annotatedDate.date.unix()} className={`${CLASSNAME}__day-wrapper`} />;\n })}\n </div>\n </div>\n </div>\n );\n});\nDatePickerControlled.displayName = COMPONENT_NAME;\nDatePickerControlled.className = CLASSNAME;\n","import moment from 'moment';\nimport React, { forwardRef, useState } from 'react';\nimport { Comp } from '@lumx/react/utils';\nimport { CLASSNAME, COMPONENT_NAME } from './constants';\nimport { DatePickerControlled } from './DatePickerControlled';\nimport { DatePickerProps } from './types';\n\n/**\n * DatePicker component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const DatePicker: Comp<DatePickerProps, HTMLDivElement> = forwardRef((props, ref) => {\n const { defaultMonth, locale, value, onChange, ...forwardedProps } = props;\n let castedValue;\n if (value) {\n castedValue = moment(value);\n } else if (defaultMonth) {\n castedValue = moment(defaultMonth);\n }\n if (castedValue && !castedValue.isValid()) {\n // eslint-disable-next-line no-console\n console.warn(`[@lumx/react/DatePicker] Invalid date provided ${castedValue}`);\n }\n const selectedDay = castedValue && castedValue.isValid() ? castedValue : moment();\n\n const [monthOffset, setMonthOffset] = useState(0);\n\n const setPrevMonth = () => setMonthOffset(monthOffset - 1);\n const setNextMonth = () => setMonthOffset(monthOffset + 1);\n\n const onDatePickerChange = (newDate?: Date) => {\n onChange(newDate);\n setMonthOffset(0);\n };\n\n const selectedMonth = moment(selectedDay).locale(locale).add(monthOffset, 'months').toDate();\n\n return (\n <DatePickerControlled\n ref={ref}\n {...forwardedProps}\n defaultMonth={defaultMonth}\n locale={locale}\n value={value}\n onPrevMonthChange={setPrevMonth}\n onNextMonthChange={setNextMonth}\n selectedMonth={selectedMonth}\n onChange={onDatePickerChange}\n />\n );\n});\nDatePicker.displayName = COMPONENT_NAME;\nDatePicker.className = CLASSNAME;\n","import { DatePicker, Placement, Popover, TextField, IconButtonProps } from '@lumx/react';\nimport { useFocusTrap } from '@lumx/react/hooks/useFocusTrap';\n\nimport moment from 'moment';\n\nimport React, { forwardRef, SyntheticEvent, useCallback, useRef, useState } from 'react';\n\nimport { useFocus } from '@lumx/react/hooks/useFocus';\nimport { Comp, GenericProps } from '@lumx/react/utils';\n\n/**\n * Defines the props of the component.\n */\nexport interface DatePickerFieldProps extends GenericProps {\n /** Default month. */\n defaultMonth?: Date;\n /** Whether the component is disabled or not. */\n isDisabled?: boolean;\n /** Locale (language or region) to use. */\n locale: string;\n /** Date after which dates can't be selected. */\n maxDate?: Date;\n /** Date before which dates can't be selected. */\n minDate?: Date;\n /** Native input name property. */\n name?: string;\n /** Props to pass to the next month button (minus those already set by the DatePickerControlled props). */\n nextButtonProps: Pick<IconButtonProps, 'label'> & Omit<IconButtonProps, 'label' | 'onClick' | 'icon' | 'emphasis'>;\n /** Props to pass to the previous month button (minus those already set by the DatePickerControlled props). */\n previousButtonProps: Pick<IconButtonProps, 'label'> &\n Omit<IconButtonProps, 'label' | 'onClick' | 'icon' | 'emphasis'>;\n /** Currently selected date. */\n value: Date | undefined;\n /** On change callback. */\n onChange(value: Date | undefined, name?: string, event?: SyntheticEvent): void;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'DatePickerField';\n\n/**\n * DatePickerField component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const DatePickerField: Comp<DatePickerFieldProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n defaultMonth,\n disabled,\n isDisabled = disabled,\n locale,\n maxDate,\n minDate,\n name,\n nextButtonProps,\n onChange,\n previousButtonProps,\n value,\n ...forwardedProps\n } = props;\n const wrapperRef = useRef(null);\n const anchorRef = useRef(null);\n\n const [isOpen, setIsOpen] = useState(false);\n\n const toggleSimpleMenu = () => {\n setIsOpen(!isOpen);\n };\n\n const onClose = useCallback(() => {\n setIsOpen(false);\n }, []);\n\n useFocus(anchorRef.current, isOpen);\n const handleKeyboardNav = (evt: React.KeyboardEvent) => {\n if ((evt.key === 'Enter' || evt.key === ' ') && toggleSimpleMenu) {\n toggleSimpleMenu();\n }\n };\n\n // Handle focus trap.\n const todayOrSelectedDateRef = useRef<HTMLButtonElement>(null);\n useFocusTrap(todayOrSelectedDateRef.current && wrapperRef.current, todayOrSelectedDateRef.current);\n\n const onTextFieldChange = (textFieldValue: string, textFieldName?: string, event?: SyntheticEvent) => {\n if (!textFieldValue) {\n onChange(undefined, textFieldName, event);\n }\n };\n\n const onDatePickerChange = (newDate?: Date) => {\n onChange(newDate, name);\n onClose();\n };\n\n return (\n <>\n <TextField\n ref={ref}\n {...forwardedProps}\n name={name}\n forceFocusStyle={isOpen}\n textFieldRef={anchorRef}\n value={value ? moment(value).locale(locale).format('LL') : ''}\n onClick={toggleSimpleMenu}\n onChange={onTextFieldChange}\n onKeyPress={handleKeyboardNav}\n isDisabled={isDisabled}\n readOnly\n />\n {isOpen ? (\n <Popover\n anchorRef={anchorRef}\n placement={Placement.BOTTOM_START}\n isOpen={isOpen}\n onClose={onClose}\n closeOnClickAway\n closeOnEscape\n >\n <div ref={wrapperRef}>\n <DatePicker\n locale={locale}\n maxDate={maxDate}\n minDate={minDate}\n value={value}\n onChange={onDatePickerChange}\n todayOrSelectedDateRef={todayOrSelectedDateRef}\n defaultMonth={defaultMonth}\n nextButtonProps={nextButtonProps}\n previousButtonProps={previousButtonProps}\n />\n </div>\n </Popover>\n ) : null}\n </>\n );\n});\nDatePickerField.displayName = COMPONENT_NAME;\n"],"names":["COMPONENT_NAME","CLASSNAME","getRootClassName","moment","extendMoment","mMoment","DAYS_PER_WEEK","getWeekDays","locale","range","map","_","i","weekday","getMonthCalendar","selectedMonth","firstDayOfMonth","startOf","endDayOfMonth","endOf","firstDay","monthRange","toDate","Array","from","by","getAnnotatedMonthCalendar","minDate","maxDate","month","clickableRange","date","isClickable","contains","isDisplayed","isToday","isSame","DatePickerControlled","forwardRef","props","ref","nextButtonProps","onChange","onNextMonthChange","onPrevMonthChange","previousButtonProps","todayOrSelectedDateRef","value","days","React","useMemo","weekDays","Emphasis","low","mdiChevronRight","mdiChevronLeft","format","weekDay","unix","slice","toLocaleUpperCase","annotatedDate","classNames","displayName","className","DatePicker","defaultMonth","forwardedProps","castedValue","isValid","console","warn","selectedDay","useState","monthOffset","setMonthOffset","setPrevMonth","setNextMonth","onDatePickerChange","newDate","add","DatePickerField","disabled","isDisabled","name","wrapperRef","useRef","anchorRef","isOpen","setIsOpen","toggleSimpleMenu","onClose","useCallback","useFocus","current","handleKeyboardNav","evt","key","useFocusTrap","onTextFieldChange","textFieldValue","textFieldName","event","undefined","Placement","BOTTOM_START"],"mappings":";;;;;;;;;;;;;;;;;;AAEA;;;;AAGO,IAAMA,cAAc,GAAG,YAAvB;AAEP;;;;AAGO,IAAMC,SAAS,GAAGC,gBAAgB,CAACF,cAAD,CAAlC;;ACNP,IAAMG,MAAM,GAAGC,YAAY,CAACC,QAAD,CAA3B;AAEA,IAAMC,aAAa,GAAG,CAAtB;;AASA;;;;;;AAMO,SAASC,WAAT,CAAqBC,MAArB,EAA+C;AAClD,SAAOC,KAAK,CAACH,aAAD,CAAL,CAAqBI,GAArB,CAAyB,UAACC,CAAD,EAAIC,CAAJ;AAAA,WAAUT,MAAM,GAAGK,MAAT,CAAgBA,MAAhB,EAAwBK,OAAxB,CAAgCD,CAAhC,CAAV;AAAA,GAAzB,CAAP;AACH;AAED;;;;;;;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ADT,KAEQ2B,cAFR;AAGI,IAAA,IAAI,EAAEiB,IAHV;AAII,IAAA,eAAe,EAAEI,MAJrB;AAKI,IAAA,YAAY,EAAED,SALlB;AAMI,IAAA,KAAK,EAAExC,KAAK,GAAG5C,QAAM,CAAC4C,KAAD,CAAN,CAAcvC,MAAd,CAAqBA,MAArB,EAA6BgD,MAA7B,CAAoC,IAApC,CAAH,GAA+C,EAN/D;AAOI,IAAA,OAAO,EAAEkC,gBAPb;AAQI,IAAA,QAAQ,EAAES,iBARd;AASI,IAAA,UAAU,EAAEJ,iBAThB;AAUI,IAAA,UAAU,EAAEZ,UAVhB;AAWI,IAAA,QAAQ;AAXZ,KADJ,EAcKK,MAAM,GACH,oBAAC,OAAD;AACI,IAAA,SAAS,EAAED,SADf;AAEI,IAAA,SAAS,EAAEiB,SAAS,CAACC,YAFzB;AAGI,IAAA,MAAM,EAAEjB,MAHZ;AAII,IAAA,OAAO,EAAEG,OAJb;AAKI,IAAA,gBAAgB,MALpB;AAMI,IAAA,aAAa;AANjB,KAQI;AAAK,IAAA,GAAG,EAAEN;AAAV,KACI,oBAAC,UAAD;AACI,IAAA,MAAM,EAAE7E,MADZ;AAEI,IAAA,OAAO,EAAEoB,OAFb;AAGI,IAAA,OAAO,EAAED,OAHb;AAII,IAAA,KAAK,EAAEoB,KAJX;AAKI,IAAA,QAAQ,EAAE+B,kBALd;AAMI,IAAA,sBAAsB,EAAEhC,sBAN5B;AAOI,IAAA,YAAY,EAAEoB,YAPlB;AAQI,IAAA,eAAe,EAAEzB,eARrB;AASI,IAAA,mBAAmB,EAAEI;AATzB,IADJ,CARJ,CADG,GAuBH,IArCR,CADJ;AAyCH,CA3FoF;AA4FrFoC,eAAe,CAAClB,WAAhB,GAA8B/D,gBAA9B;;;;"}
|
package/esm/_internal/Dialog2.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { d as _slicedToArray, e as _toConsumableArray, b as _objectWithoutProperties, c as _extends } from './_rollupPluginBabelHelpers.js';
|
|
1
2
|
import { Size } from './components.js';
|
|
2
|
-
import { f as _slicedToArray, i as _toConsumableArray, g as getRootClassName, a as _objectWithoutProperties, b as _extends, d as classnames, h as handleBasicClasses, D as DIALOG_TRANSITION_DURATION } from './getRootClassName.js';
|
|
3
3
|
import React, { useState, useEffect, forwardRef, useRef, useMemo, Children } from 'react';
|
|
4
|
+
import { g as getRootClassName, c as classnames, h as handleBasicClasses, D as DIALOG_TRANSITION_DURATION } from './getRootClassName.js';
|
|
4
5
|
import { D as DOCUMENT } from './constants.js';
|
|
5
6
|
import { p as partitionMulti } from './partitionMulti.js';
|
|
6
7
|
import { i as isComponent } from './type.js';
|
|
8
|
+
import { m as mergeRefs } from './mergeRefs.js';
|
|
7
9
|
import { u as useFocusTrap } from './useFocusTrap.js';
|
|
8
10
|
import { createPortal } from 'react-dom';
|
|
9
11
|
import { u as useCallbackOnEscape, C as ClickAwayProvider } from './ClickAwayProvider.js';
|
|
@@ -161,12 +163,19 @@ var Dialog = forwardRef(function (props, ref) {
|
|
|
161
163
|
|
|
162
164
|
useCallbackOnEscape(handleClose, isOpen && !preventAutoClose); // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
163
165
|
|
|
164
|
-
var wrapperRef = useRef(null);
|
|
166
|
+
var wrapperRef = useRef(null);
|
|
167
|
+
/**
|
|
168
|
+
* Since the `contentRef` comes from the parent and is optional,
|
|
169
|
+
* we need to create a stable contentRef that will always be available.
|
|
170
|
+
*/
|
|
171
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
172
|
+
|
|
173
|
+
var localContentRef = useRef(null); // Handle focus trap.
|
|
165
174
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
166
175
|
|
|
167
176
|
useFocusTrap(wrapperRef.current, focusElement === null || focusElement === void 0 ? void 0 : focusElement.current); // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
168
177
|
|
|
169
|
-
useDisableBodyScroll(isOpen &&
|
|
178
|
+
useDisableBodyScroll(isOpen && localContentRef.current); // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
170
179
|
|
|
171
180
|
var _useState = useState(null),
|
|
172
181
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -233,7 +242,7 @@ var Dialog = forwardRef(function (props, ref) {
|
|
|
233
242
|
}, (header || headerChildContent) && React.createElement("header", _extends({}, headerChildProps, {
|
|
234
243
|
className: classnames("".concat(CLASSNAME, "__header"), (forceHeaderDivider || hasTopIntersection) && "".concat(CLASSNAME, "__header--has-divider"), headerChildProps === null || headerChildProps === void 0 ? void 0 : headerChildProps.className)
|
|
235
244
|
}), header, headerChildContent), React.createElement("div", {
|
|
236
|
-
ref: contentRef,
|
|
245
|
+
ref: mergeRefs(contentRef, localContentRef),
|
|
237
246
|
className: "".concat(CLASSNAME, "__content")
|
|
238
247
|
}, React.createElement("div", {
|
|
239
248
|
className: "".concat(CLASSNAME, "__sentinel ").concat(CLASSNAME, "__sentinel--top"),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dialog2.js","sources":["../../../src/hooks/useIntersectionObserver.tsx","../../../src/components/dialog/Dialog.tsx"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nexport type Intersections<T> = Map<T, IntersectionObserverEntry>;\n\n/**\n * Convenient hook to create interaction observers.\n *\n * @param elements Elements to observe.\n * @param options IntersectionObserver options.\n * @return Map of intersections.\n */\nexport function useIntersectionObserver<T extends Element>(\n elements: Array<T | null | undefined>,\n options?: IntersectionObserverInit,\n): Intersections<T> {\n const [intersections, setIntersections] = useState<Intersections<T>>(() => new Map());\n\n useEffect(\n () => {\n if (elements.length < 1 || !elements.some(Boolean)) {\n return undefined;\n }\n\n const observer = new IntersectionObserver((entries) => {\n for (const entry of entries) {\n intersections.set(entry.target as T, entry);\n }\n setIntersections(new Map(intersections));\n }, options);\n\n for (const element of elements) {\n if (element) {\n observer.observe(element);\n }\n }\n return () => observer.disconnect();\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [...elements],\n );\n\n return intersections;\n}\n","import React, { Children, forwardRef, ReactElement, ReactNode, RefObject, useMemo, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\n\nimport classNames from 'classnames';\n\nimport { Progress, ProgressVariant, Size } from '@lumx/react';\n\nimport { DIALOG_TRANSITION_DURATION, DOCUMENT } from '@lumx/react/constants';\nimport { useCallbackOnEscape } from '@lumx/react/hooks/useCallbackOnEscape';\nimport { useFocusTrap } from '@lumx/react/hooks/useFocusTrap';\nimport { useIntersectionObserver } from '@lumx/react/hooks/useIntersectionObserver';\nimport {\n Comp,\n GenericProps,\n getRootClassName,\n handleBasicClasses,\n isComponent,\n partitionMulti,\n} from '@lumx/react/utils';\nimport { ClickAwayProvider } from '@lumx/react/utils/ClickAwayProvider';\n\nimport { useDelayedVisibility } from '@lumx/react/hooks/useDelayedVisibility';\nimport { useDisableBodyScroll } from '@lumx/react/hooks/useDisableBodyScroll';\n\n/**\n * Defines the props of the component.\n */\nexport interface DialogProps extends GenericProps {\n /** Footer content. */\n footer?: ReactNode;\n /** Whether the divider between the dialog content and the footer is always displayed (instead of showing it on scroll). */\n forceFooterDivider?: boolean;\n /** Header content. */\n header?: ReactNode;\n /** Whether the divider between the dialog content and the footer is always displayed (instead of showing it on scroll). */\n forceHeaderDivider?: boolean;\n /** Whether the indefinite progress indicator over the dialog content is displayed or not. */\n isLoading?: boolean;\n /** Whether the component is open or not. */\n isOpen?: boolean;\n /** Reference to the parent element that triggered modal opening (will get back focus on close). */\n parentElement?: RefObject<HTMLElement>;\n /** Reference to the dialog content element. */\n contentRef?: RefObject<HTMLDivElement>;\n /** Reference to the of the element that should get the focus when the dialogs opens. By default, the first child will take focus. */\n focusElement?: RefObject<HTMLElement>;\n /** Whether to keep the dialog open on clickaway or escape press. */\n preventAutoClose?: boolean;\n /** Size variant. */\n size?: DialogSizes;\n /** Z-axis position. */\n zIndex?: number;\n /** Z-axis position. */\n dialogProps?: GenericProps;\n /** On close callback. */\n onClose?(): void;\n /** Callback called when the open animation starts and the close animation finishes. */\n onVisibilityChange?(isVisible: boolean): void;\n}\n\nexport type DialogSizes = Extract<Size, 'tiny' | 'regular' | 'big' | 'huge'>;\n\nconst isHeader = isComponent('header');\nconst isFooter = isComponent('footer');\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'Dialog';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Component default props.\n */\nconst DEFAULT_PROPS: Partial<DialogProps> = {\n size: Size.big,\n};\n\n/**\n * Dialog component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const Dialog: Comp<DialogProps, HTMLDivElement> = forwardRef((props, ref) => {\n if (!DOCUMENT) {\n // Can't render in SSR.\n return null;\n }\n\n const {\n children,\n className,\n header,\n focusElement,\n forceFooterDivider,\n forceHeaderDivider,\n footer,\n isLoading,\n isOpen,\n onClose,\n parentElement,\n contentRef,\n preventAutoClose,\n size,\n zIndex,\n dialogProps,\n onVisibilityChange,\n ...forwardedProps\n } = props;\n\n const handleClose = onClose\n ? () => {\n onClose();\n // Focus the parent element on close.\n if (parentElement && parentElement.current) {\n parentElement.current.focus();\n }\n }\n : undefined;\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useCallbackOnEscape(handleClose, isOpen && !preventAutoClose);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const wrapperRef = useRef<HTMLDivElement>(null);\n\n // Handle focus trap.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useFocusTrap(wrapperRef.current, focusElement?.current);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useDisableBodyScroll(isOpen && wrapperRef.current);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const [sentinelTop, setSentinelTop] = useState<Element | null>(null);\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const [sentinelBottom, setSentinelBottom] = useState<Element | null>(null);\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const intersections = useIntersectionObserver([sentinelTop, sentinelBottom], {\n threshold: [0, 1],\n });\n\n const hasTopIntersection = sentinelTop && !(intersections.get(sentinelTop)?.isIntersecting ?? true);\n const hasBottomIntersection = sentinelBottom && !(intersections.get(sentinelBottom)?.isIntersecting ?? true);\n\n // Separate header, footer and dialog content from children.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const [[headerChild], [footerChild], content] = useMemo(\n () => partitionMulti(Children.toArray(children), [isHeader, isFooter]),\n [children],\n );\n const headerChildProps = (headerChild as ReactElement)?.props;\n const headerChildContent = headerChildProps?.children;\n const footerChildProps = (footerChild as ReactElement)?.props;\n const footerChildContent = footerChildProps?.children;\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const isVisible = useDelayedVisibility(Boolean(isOpen), DIALOG_TRANSITION_DURATION, onVisibilityChange);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const clickAwayRefs = useRef([wrapperRef]);\n\n return isOpen || isVisible\n ? createPortal(\n <div\n ref={ref}\n {...forwardedProps}\n className={classNames(\n className,\n handleBasicClasses({\n isHidden: !isOpen,\n isLoading,\n isShown: isOpen || isVisible,\n prefix: CLASSNAME,\n size,\n }),\n )}\n style={{ zIndex }}\n >\n <div className={`${CLASSNAME}__overlay`} />\n\n <section className={`${CLASSNAME}__container`} role=\"dialog\" aria-modal=\"true\" {...dialogProps}>\n <ClickAwayProvider callback={!preventAutoClose && handleClose} refs={clickAwayRefs}>\n <div className={`${CLASSNAME}__wrapper`} ref={wrapperRef}>\n {(header || headerChildContent) && (\n <header\n {...headerChildProps}\n className={classNames(\n `${CLASSNAME}__header`,\n (forceHeaderDivider || hasTopIntersection) &&\n `${CLASSNAME}__header--has-divider`,\n headerChildProps?.className,\n )}\n >\n {header}\n {headerChildContent}\n </header>\n )}\n\n <div ref={contentRef} className={`${CLASSNAME}__content`}>\n <div\n className={`${CLASSNAME}__sentinel ${CLASSNAME}__sentinel--top`}\n ref={setSentinelTop}\n />\n\n {content}\n\n <div\n className={`${CLASSNAME}__sentinel ${CLASSNAME}__sentinel--bottom`}\n ref={setSentinelBottom}\n />\n </div>\n\n {(footer || footerChildContent) && (\n <footer\n {...footerChildProps}\n className={classNames(\n `${CLASSNAME}__footer`,\n (forceFooterDivider || hasBottomIntersection) &&\n `${CLASSNAME}__footer--has-divider`,\n footerChildProps?.className,\n )}\n >\n {footer}\n {footerChildContent}\n </footer>\n )}\n\n {isLoading && (\n <div className={`${CLASSNAME}__progress-overlay`}>\n <Progress variant={ProgressVariant.circular} />\n </div>\n )}\n </div>\n </ClickAwayProvider>\n </section>\n </div>,\n document.body,\n )\n : null;\n});\nDialog.displayName = COMPONENT_NAME;\nDialog.className = CLASSNAME;\nDialog.defaultProps = DEFAULT_PROPS;\n"],"names":["useIntersectionObserver","elements","options","useState","Map","intersections","setIntersections","useEffect","length","some","Boolean","undefined","observer","IntersectionObserver","entries","entry","set","target","element","observe","disconnect","isHeader","isComponent","isFooter","COMPONENT_NAME","CLASSNAME","getRootClassName","DEFAULT_PROPS","size","Size","big","Dialog","forwardRef","props","ref","DOCUMENT","children","className","header","focusElement","forceFooterDivider","forceHeaderDivider","footer","isLoading","isOpen","onClose","parentElement","contentRef","preventAutoClose","zIndex","dialogProps","onVisibilityChange","forwardedProps","handleClose","current","focus","useCallbackOnEscape","wrapperRef","useRef","useFocusTrap","useDisableBodyScroll","sentinelTop","setSentinelTop","sentinelBottom","setSentinelBottom","threshold","hasTopIntersection","get","isIntersecting","hasBottomIntersection","useMemo","partitionMulti","Children","toArray","headerChild","footerChild","content","headerChildProps","headerChildContent","footerChildProps","footerChildContent","isVisible","useDelayedVisibility","DIALOG_TRANSITION_DURATION","clickAwayRefs","createPortal","classNames","handleBasicClasses","isHidden","isShown","prefix","ProgressVariant","circular","document","body","displayName","defaultProps"],"mappings":";;;;;;;;;;;;;AAIA;;;;;;;AAOO,SAASA,uBAAT,CACHC,QADG,EAEHC,OAFG,EAGa;AAAA,kBAC0BC,QAAQ,CAAmB;AAAA,WAAM,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ATL,EAUKsC,kBAVL,CA/BR,EA6CKrC,SAAS,IACN;AAAK,IAAA,SAAS,YAAKlB,SAAL;AAAd,KACI,oBAAC,QAAD;AAAU,IAAA,OAAO,EAAEkE,eAAe,CAACC;AAAnC,IADJ,CA9CR,CADJ,CADJ,CAjBJ,CADQ,EA0ERC,QAAQ,CAACC,IA1ED,CADX,GA6ED,IA7EN;AA8EH,CA7JkE;AA8JnE/D,MAAM,CAACgE,WAAP,GAAqBvE,cAArB;AACAO,MAAM,CAACM,SAAP,GAAmBZ,SAAnB;AACAM,MAAM,CAACiE,YAAP,GAAsBrE,aAAtB;;;;"}
|
|
1
|
+
{"version":3,"file":"Dialog2.js","sources":["../../../src/hooks/useIntersectionObserver.tsx","../../../src/components/dialog/Dialog.tsx"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nexport type Intersections<T> = Map<T, IntersectionObserverEntry>;\n\n/**\n * Convenient hook to create interaction observers.\n *\n * @param elements Elements to observe.\n * @param options IntersectionObserver options.\n * @return Map of intersections.\n */\nexport function useIntersectionObserver<T extends Element>(\n elements: Array<T | null | undefined>,\n options?: IntersectionObserverInit,\n): Intersections<T> {\n const [intersections, setIntersections] = useState<Intersections<T>>(() => new Map());\n\n useEffect(\n () => {\n if (elements.length < 1 || !elements.some(Boolean)) {\n return undefined;\n }\n\n const observer = new IntersectionObserver((entries) => {\n for (const entry of entries) {\n intersections.set(entry.target as T, entry);\n }\n setIntersections(new Map(intersections));\n }, options);\n\n for (const element of elements) {\n if (element) {\n observer.observe(element);\n }\n }\n return () => observer.disconnect();\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [...elements],\n );\n\n return intersections;\n}\n","import React, { Children, forwardRef, ReactElement, ReactNode, RefObject, useMemo, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\n\nimport classNames from 'classnames';\n\nimport { Progress, ProgressVariant, Size } from '@lumx/react';\n\nimport { DIALOG_TRANSITION_DURATION, DOCUMENT } from '@lumx/react/constants';\nimport { useCallbackOnEscape } from '@lumx/react/hooks/useCallbackOnEscape';\nimport { useFocusTrap } from '@lumx/react/hooks/useFocusTrap';\nimport { useIntersectionObserver } from '@lumx/react/hooks/useIntersectionObserver';\nimport {\n Comp,\n GenericProps,\n getRootClassName,\n handleBasicClasses,\n isComponent,\n partitionMulti,\n} from '@lumx/react/utils';\nimport { ClickAwayProvider } from '@lumx/react/utils/ClickAwayProvider';\nimport { mergeRefs } from '@lumx/react/utils/mergeRefs';\n\nimport { useDelayedVisibility } from '@lumx/react/hooks/useDelayedVisibility';\nimport { useDisableBodyScroll } from '@lumx/react/hooks/useDisableBodyScroll';\n\n/**\n * Defines the props of the component.\n */\nexport interface DialogProps extends GenericProps {\n /** Footer content. */\n footer?: ReactNode;\n /** Whether the divider between the dialog content and the footer is always displayed (instead of showing it on scroll). */\n forceFooterDivider?: boolean;\n /** Header content. */\n header?: ReactNode;\n /** Whether the divider between the dialog content and the footer is always displayed (instead of showing it on scroll). */\n forceHeaderDivider?: boolean;\n /** Whether the indefinite progress indicator over the dialog content is displayed or not. */\n isLoading?: boolean;\n /** Whether the component is open or not. */\n isOpen?: boolean;\n /** Reference to the parent element that triggered modal opening (will get back focus on close). */\n parentElement?: RefObject<HTMLElement>;\n /** Reference to the dialog content element. */\n contentRef?: RefObject<HTMLDivElement>;\n /** Reference to the of the element that should get the focus when the dialogs opens. By default, the first child will take focus. */\n focusElement?: RefObject<HTMLElement>;\n /** Whether to keep the dialog open on clickaway or escape press. */\n preventAutoClose?: boolean;\n /** Size variant. */\n size?: DialogSizes;\n /** Z-axis position. */\n zIndex?: number;\n /** Z-axis position. */\n dialogProps?: GenericProps;\n /** On close callback. */\n onClose?(): void;\n /** Callback called when the open animation starts and the close animation finishes. */\n onVisibilityChange?(isVisible: boolean): void;\n}\n\nexport type DialogSizes = Extract<Size, 'tiny' | 'regular' | 'big' | 'huge'>;\n\nconst isHeader = isComponent('header');\nconst isFooter = isComponent('footer');\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'Dialog';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Component default props.\n */\nconst DEFAULT_PROPS: Partial<DialogProps> = {\n size: Size.big,\n};\n\n/**\n * Dialog component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const Dialog: Comp<DialogProps, HTMLDivElement> = forwardRef((props, ref) => {\n if (!DOCUMENT) {\n // Can't render in SSR.\n return null;\n }\n\n const {\n children,\n className,\n header,\n focusElement,\n forceFooterDivider,\n forceHeaderDivider,\n footer,\n isLoading,\n isOpen,\n onClose,\n parentElement,\n contentRef,\n preventAutoClose,\n size,\n zIndex,\n dialogProps,\n onVisibilityChange,\n ...forwardedProps\n } = props;\n\n const handleClose = onClose\n ? () => {\n onClose();\n // Focus the parent element on close.\n if (parentElement && parentElement.current) {\n parentElement.current.focus();\n }\n }\n : undefined;\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useCallbackOnEscape(handleClose, isOpen && !preventAutoClose);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const wrapperRef = useRef<HTMLDivElement>(null);\n /**\n * Since the `contentRef` comes from the parent and is optional,\n * we need to create a stable contentRef that will always be available.\n */\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const localContentRef = useRef<HTMLDivElement>(null);\n // Handle focus trap.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useFocusTrap(wrapperRef.current, focusElement?.current);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useDisableBodyScroll(isOpen && localContentRef.current);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const [sentinelTop, setSentinelTop] = useState<Element | null>(null);\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const [sentinelBottom, setSentinelBottom] = useState<Element | null>(null);\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const intersections = useIntersectionObserver([sentinelTop, sentinelBottom], {\n threshold: [0, 1],\n });\n\n const hasTopIntersection = sentinelTop && !(intersections.get(sentinelTop)?.isIntersecting ?? true);\n const hasBottomIntersection = sentinelBottom && !(intersections.get(sentinelBottom)?.isIntersecting ?? true);\n\n // Separate header, footer and dialog content from children.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const [[headerChild], [footerChild], content] = useMemo(\n () => partitionMulti(Children.toArray(children), [isHeader, isFooter]),\n [children],\n );\n const headerChildProps = (headerChild as ReactElement)?.props;\n const headerChildContent = headerChildProps?.children;\n const footerChildProps = (footerChild as ReactElement)?.props;\n const footerChildContent = footerChildProps?.children;\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const isVisible = useDelayedVisibility(Boolean(isOpen), DIALOG_TRANSITION_DURATION, onVisibilityChange);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const clickAwayRefs = useRef([wrapperRef]);\n\n return isOpen || isVisible\n ? createPortal(\n <div\n ref={ref}\n {...forwardedProps}\n className={classNames(\n className,\n handleBasicClasses({\n isHidden: !isOpen,\n isLoading,\n isShown: isOpen || isVisible,\n prefix: CLASSNAME,\n size,\n }),\n )}\n style={{ zIndex }}\n >\n <div className={`${CLASSNAME}__overlay`} />\n\n <section className={`${CLASSNAME}__container`} role=\"dialog\" aria-modal=\"true\" {...dialogProps}>\n <ClickAwayProvider callback={!preventAutoClose && handleClose} refs={clickAwayRefs}>\n <div className={`${CLASSNAME}__wrapper`} ref={wrapperRef}>\n {(header || headerChildContent) && (\n <header\n {...headerChildProps}\n className={classNames(\n `${CLASSNAME}__header`,\n (forceHeaderDivider || hasTopIntersection) &&\n `${CLASSNAME}__header--has-divider`,\n headerChildProps?.className,\n )}\n >\n {header}\n {headerChildContent}\n </header>\n )}\n\n <div ref={mergeRefs(contentRef, localContentRef)} className={`${CLASSNAME}__content`}>\n <div\n className={`${CLASSNAME}__sentinel ${CLASSNAME}__sentinel--top`}\n ref={setSentinelTop}\n />\n\n {content}\n\n <div\n className={`${CLASSNAME}__sentinel ${CLASSNAME}__sentinel--bottom`}\n ref={setSentinelBottom}\n />\n </div>\n\n {(footer || footerChildContent) && (\n <footer\n {...footerChildProps}\n className={classNames(\n `${CLASSNAME}__footer`,\n (forceFooterDivider || hasBottomIntersection) &&\n `${CLASSNAME}__footer--has-divider`,\n footerChildProps?.className,\n )}\n >\n {footer}\n {footerChildContent}\n </footer>\n )}\n\n {isLoading && (\n <div className={`${CLASSNAME}__progress-overlay`}>\n <Progress variant={ProgressVariant.circular} />\n </div>\n )}\n </div>\n </ClickAwayProvider>\n </section>\n </div>,\n document.body,\n )\n : null;\n});\nDialog.displayName = COMPONENT_NAME;\nDialog.className = CLASSNAME;\nDialog.defaultProps = DEFAULT_PROPS;\n"],"names":["useIntersectionObserver","elements","options","useState","Map","intersections","setIntersections","useEffect","length","some","Boolean","undefined","observer","IntersectionObserver","entries","entry","set","target","element","observe","disconnect","isHeader","isComponent","isFooter","COMPONENT_NAME","CLASSNAME","getRootClassName","DEFAULT_PROPS","size","Size","big","Dialog","forwardRef","props","ref","DOCUMENT","children","className","header","focusElement","forceFooterDivider","forceHeaderDivider","footer","isLoading","isOpen","onClose","parentElement","contentRef","preventAutoClose","zIndex","dialogProps","onVisibilityChange","forwardedProps","handleClose","current","focus","useCallbackOnEscape","wrapperRef","useRef","localContentRef","useFocusTrap","useDisableBodyScroll","sentinelTop","setSentinelTop","sentinelBottom","setSentinelBottom","threshold","hasTopIntersection","get","isIntersecting","hasBottomIntersection","useMemo","partitionMulti","Children","toArray","headerChild","footerChild","content","headerChildProps","headerChildContent","footerChildProps","footerChildContent","isVisible","useDelayedVisibility","DIALOG_TRANSITION_DURATION","clickAwayRefs","createPortal","classNames","handleBasicClasses","isHidden","isShown","prefix","mergeRefs","ProgressVariant","circular","document","body","displayName","defaultProps"],"mappings":";;;;;;;;;;;;;;;AAIA;;;;;;;AAOO,SAASA,uBAAT,CACHC,QADG,EAEHC,OAFG,EAGa;AAAA,kBAC0BC,QAAQ,CAAmB;AAAA,WAAM,IAAIC,GAAJ,EAAN;AAAA,GAAnB,C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B,aAIjBA,gBAJiB,uBAIjBA,gBAAgB,CAAE3C,SAJD;AAFzB,MASKK,MATL,EAUKuC,kBAVL,CA/BR,EA6CKtC,SAAS,IACN;AAAK,IAAA,SAAS,YAAKlB,SAAL;AAAd,KACI,oBAAC,QAAD;AAAU,IAAA,OAAO,EAAEoE,eAAe,CAACC;AAAnC,IADJ,CA9CR,CADJ,CADJ,CAjBJ,CADQ,EA0ERC,QAAQ,CAACC,IA1ED,CADX,GA6ED,IA7EN;AA8EH,CAlKkE;AAmKnEjE,MAAM,CAACkE,WAAP,GAAqBzE,cAArB;AACAO,MAAM,CAACM,SAAP,GAAmBZ,SAAnB;AACAM,MAAM,CAACmE,YAAP,GAAsBvE,aAAtB;;;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { b as _objectWithoutProperties, c as _extends } from './_rollupPluginBabelHelpers.js';
|
|
1
2
|
import { Theme } from './components.js';
|
|
2
|
-
import { g as getRootClassName, a as _objectWithoutProperties, b as _extends, d as classnames, h as handleBasicClasses } from './getRootClassName.js';
|
|
3
3
|
import React, { forwardRef } from 'react';
|
|
4
|
+
import { g as getRootClassName, c as classnames, h as handleBasicClasses } from './getRootClassName.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Defines the props of the component.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Divider2.js","sources":["../../../src/components/divider/Divider.tsx"],"sourcesContent":["import React, { forwardRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport { Theme } from '@lumx/react';\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils';\n\n/**\n * Defines the props of the component.\n */\nexport interface DividerProps extends GenericProps {\n /** Theme adapting the component to light or dark background. */\n theme?: Theme;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'Divider';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Component default props.\n */\nexport const DEFAULT_PROPS: Partial<DividerProps> = {\n theme: Theme.light,\n};\n\n/**\n * Divider component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const Divider: Comp<DividerProps, HTMLHRElement> = forwardRef((props, ref) => {\n const { className, theme, ...forwardedProps } = props;\n\n return (\n <hr\n ref={ref}\n {...forwardedProps}\n className={classNames(className, handleBasicClasses({ prefix: CLASSNAME, theme }))}\n />\n );\n});\nDivider.displayName = COMPONENT_NAME;\nDivider.className = CLASSNAME;\nDivider.defaultProps = DEFAULT_PROPS;\n"],"names":["COMPONENT_NAME","CLASSNAME","getRootClassName","DEFAULT_PROPS","theme","Theme","light","Divider","forwardRef","props","ref","className","forwardedProps","classNames","handleBasicClasses","prefix","displayName","defaultProps"],"mappings":"
|
|
1
|
+
{"version":3,"file":"Divider2.js","sources":["../../../src/components/divider/Divider.tsx"],"sourcesContent":["import React, { forwardRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport { Theme } from '@lumx/react';\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils';\n\n/**\n * Defines the props of the component.\n */\nexport interface DividerProps extends GenericProps {\n /** Theme adapting the component to light or dark background. */\n theme?: Theme;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'Divider';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Component default props.\n */\nexport const DEFAULT_PROPS: Partial<DividerProps> = {\n theme: Theme.light,\n};\n\n/**\n * Divider component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const Divider: Comp<DividerProps, HTMLHRElement> = forwardRef((props, ref) => {\n const { className, theme, ...forwardedProps } = props;\n\n return (\n <hr\n ref={ref}\n {...forwardedProps}\n className={classNames(className, handleBasicClasses({ prefix: CLASSNAME, theme }))}\n />\n );\n});\nDivider.displayName = COMPONENT_NAME;\nDivider.className = CLASSNAME;\nDivider.defaultProps = DEFAULT_PROPS;\n"],"names":["COMPONENT_NAME","CLASSNAME","getRootClassName","DEFAULT_PROPS","theme","Theme","light","Divider","forwardRef","props","ref","className","forwardedProps","classNames","handleBasicClasses","prefix","displayName","defaultProps"],"mappings":";;;;;AAOA;;;;AAQA;;;AAGA,IAAMA,cAAc,GAAG,SAAvB;AAEA;;;;AAGA,IAAMC,SAAS,GAAGC,gBAAgB,CAACF,cAAD,CAAlC;AAEA;;;;IAGaG,aAAoC,GAAG;AAChDC,EAAAA,KAAK,EAAEC,KAAK,CAACC;AADmC;AAIpD;;;;;;;;IAOaC,OAA0C,GAAGC,UAAU,CAAC,UAACC,KAAD,EAAQC,GAAR,EAAgB;AAAA,MACzEC,SADyE,GACjCF,KADiC,CACzEE,SADyE;AAAA,MAC9DP,KAD8D,GACjCK,KADiC,CAC9DL,KAD8D;AAAA,MACpDQ,cADoD,4BACjCH,KADiC;;AAGjF,SACI;AACI,IAAA,GAAG,EAAEC;AADT,KAEQE,cAFR;AAGI,IAAA,SAAS,EAAEC,UAAU,CAACF,SAAD,EAAYG,kBAAkB,CAAC;AAAEC,MAAAA,MAAM,EAAEd,SAAV;AAAqBG,MAAAA,KAAK,EAALA;AAArB,KAAD,CAA9B;AAHzB,KADJ;AAOH,CAVmE;AAWpEG,OAAO,CAACS,WAAR,GAAsBhB,cAAtB;AACAO,OAAO,CAACI,SAAR,GAAoBV,SAApB;AACAM,OAAO,CAACU,YAAR,GAAuBd,aAAvB;;;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { b as _objectWithoutProperties, c as _extends } from './_rollupPluginBabelHelpers.js';
|
|
1
2
|
import { Theme, ColorPalette, Size } from './components.js';
|
|
2
|
-
import { g as getRootClassName, a as _objectWithoutProperties, b as _extends, d as classnames, h as handleBasicClasses } from './getRootClassName.js';
|
|
3
3
|
import React, { forwardRef } from 'react';
|
|
4
|
+
import { g as getRootClassName, c as classnames, h as handleBasicClasses } from './getRootClassName.js';
|
|
4
5
|
import { h as mdiDragVertical } from './mdi.js';
|
|
5
6
|
import { I as Icon } from './Icon2.js';
|
|
6
7
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DragHandle.js","sources":["../../../src/components/drag-handle/DragHandle.tsx"],"sourcesContent":["import React, { forwardRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport { mdiDragVertical } from '@lumx/icons';\nimport { ColorPalette, Icon, Size, Theme } from '@lumx/react';\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils';\n\n/**\n * Defines the props of the component.\n */\nexport interface DragHandleProps extends GenericProps {\n /** Theme adapting the component to light or dark background. */\n theme?: Theme;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'DragHandle';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * DragHandle component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const DragHandle: Comp<DragHandleProps, HTMLDivElement> = forwardRef((props, ref) => {\n const { className, theme, ...forwardedProps } = props;\n\n return (\n <div\n ref={ref}\n {...forwardedProps}\n className={classNames(className, handleBasicClasses({ prefix: CLASSNAME, theme }))}\n >\n <Icon icon={mdiDragVertical} color={theme === Theme.dark ? ColorPalette.light : undefined} size={Size.xs} />\n </div>\n );\n});\nDragHandle.displayName = COMPONENT_NAME;\nDragHandle.className = CLASSNAME;\n"],"names":["COMPONENT_NAME","CLASSNAME","getRootClassName","DragHandle","forwardRef","props","ref","className","theme","forwardedProps","classNames","handleBasicClasses","prefix","mdiDragVertical","Theme","dark","ColorPalette","light","undefined","Size","xs","displayName"],"mappings":"
|
|
1
|
+
{"version":3,"file":"DragHandle.js","sources":["../../../src/components/drag-handle/DragHandle.tsx"],"sourcesContent":["import React, { forwardRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport { mdiDragVertical } from '@lumx/icons';\nimport { ColorPalette, Icon, Size, Theme } from '@lumx/react';\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils';\n\n/**\n * Defines the props of the component.\n */\nexport interface DragHandleProps extends GenericProps {\n /** Theme adapting the component to light or dark background. */\n theme?: Theme;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'DragHandle';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * DragHandle component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const DragHandle: Comp<DragHandleProps, HTMLDivElement> = forwardRef((props, ref) => {\n const { className, theme, ...forwardedProps } = props;\n\n return (\n <div\n ref={ref}\n {...forwardedProps}\n className={classNames(className, handleBasicClasses({ prefix: CLASSNAME, theme }))}\n >\n <Icon icon={mdiDragVertical} color={theme === Theme.dark ? ColorPalette.light : undefined} size={Size.xs} />\n </div>\n );\n});\nDragHandle.displayName = COMPONENT_NAME;\nDragHandle.className = CLASSNAME;\n"],"names":["COMPONENT_NAME","CLASSNAME","getRootClassName","DragHandle","forwardRef","props","ref","className","theme","forwardedProps","classNames","handleBasicClasses","prefix","mdiDragVertical","Theme","dark","ColorPalette","light","undefined","Size","xs","displayName"],"mappings":";;;;;;;AAQA;;;;AAQA;;;AAGA,IAAMA,cAAc,GAAG,YAAvB;AAEA;;;;AAGA,IAAMC,SAAS,GAAGC,gBAAgB,CAACF,cAAD,CAAlC;AAEA;;;;;;;;IAOaG,UAAiD,GAAGC,UAAU,CAAC,UAACC,KAAD,EAAQC,GAAR,EAAgB;AAAA,MAChFC,SADgF,GACxCF,KADwC,CAChFE,SADgF;AAAA,MACrEC,KADqE,GACxCH,KADwC,CACrEG,KADqE;AAAA,MAC3DC,cAD2D,4BACxCJ,KADwC;;AAGxF,SACI;AACI,IAAA,GAAG,EAAEC;AADT,KAEQG,cAFR;AAGI,IAAA,SAAS,EAAEC,UAAU,CAACH,SAAD,EAAYI,kBAAkB,CAAC;AAAEC,MAAAA,MAAM,EAAEX,SAAV;AAAqBO,MAAAA,KAAK,EAALA;AAArB,KAAD,CAA9B;AAHzB,MAKI,oBAAC,IAAD;AAAM,IAAA,IAAI,EAAEK,eAAZ;AAA6B,IAAA,KAAK,EAAEL,KAAK,KAAKM,KAAK,CAACC,IAAhB,GAAuBC,YAAY,CAACC,KAApC,GAA4CC,SAAhF;AAA2F,IAAA,IAAI,EAAEC,IAAI,CAACC;AAAtG,IALJ,CADJ;AASH,CAZ0E;AAa3EjB,UAAU,CAACkB,WAAX,GAAyBrB,cAAzB;AACAG,UAAU,CAACI,SAAX,GAAuBN,SAAvB;;;;"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { b as _objectWithoutProperties, _ as _objectSpread2, c as _extends } from './_rollupPluginBabelHelpers.js';
|
|
2
2
|
import React, { useEffect, forwardRef, useRef, useMemo, cloneElement } from 'react';
|
|
3
|
+
import { g as getRootClassName, c as classnames, h as handleBasicClasses } from './getRootClassName.js';
|
|
3
4
|
import { i as isComponent } from './type.js';
|
|
4
5
|
import { a as Popover, P as Placement } from './Popover2.js';
|
|
5
6
|
import { L as List } from './List2.js';
|
|
6
7
|
|
|
8
|
+
// The error margin in px we want to have for triggering infinite scroll
|
|
9
|
+
var SCROLL_TRIGGER_MARGIN = 5;
|
|
7
10
|
/**
|
|
8
11
|
* Listen to clicks away from a given element and callback the passed in function.
|
|
9
12
|
*
|
|
@@ -11,8 +14,10 @@ import { L as List } from './List2.js';
|
|
|
11
14
|
* @param [callback] A callback function to call when the bottom of the reference element is reached.
|
|
12
15
|
* @param [callbackOnMount] A callback function to call when the component is mounted.
|
|
13
16
|
*/
|
|
17
|
+
|
|
14
18
|
var useInfiniteScroll = function useInfiniteScroll(ref, callback) {
|
|
15
19
|
var callbackOnMount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
20
|
+
var scrollTriggerMargin = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : SCROLL_TRIGGER_MARGIN;
|
|
16
21
|
useEffect(function () {
|
|
17
22
|
var current = ref.current;
|
|
18
23
|
|
|
@@ -21,7 +26,7 @@ var useInfiniteScroll = function useInfiniteScroll(ref, callback) {
|
|
|
21
26
|
}
|
|
22
27
|
|
|
23
28
|
var isAtBottom = function isAtBottom() {
|
|
24
|
-
return Boolean(current && current.scrollTop + current.clientHeight
|
|
29
|
+
return Boolean(current && current.scrollHeight - (current.scrollTop + current.clientHeight) <= scrollTriggerMargin);
|
|
25
30
|
};
|
|
26
31
|
|
|
27
32
|
var onScroll = function onScroll(e) {
|
|
@@ -40,7 +45,7 @@ var useInfiniteScroll = function useInfiniteScroll(ref, callback) {
|
|
|
40
45
|
current.removeEventListener('scroll', onScroll);
|
|
41
46
|
current.removeEventListener('resize', onScroll);
|
|
42
47
|
};
|
|
43
|
-
}, [ref, callback]);
|
|
48
|
+
}, [ref, callback, scrollTriggerMargin]);
|
|
44
49
|
useEffect(function () {
|
|
45
50
|
if (callback && callbackOnMount) {
|
|
46
51
|
callback();
|
|
@@ -125,6 +130,7 @@ var Dropdown = forwardRef(function (props, ref) {
|
|
|
125
130
|
className: classnames(className, handleBasicClasses({
|
|
126
131
|
prefix: CLASSNAME
|
|
127
132
|
})),
|
|
133
|
+
elevation: 0,
|
|
128
134
|
closeOnClickAway: closeOnClickAway,
|
|
129
135
|
closeOnEscape: closeOnEscape,
|
|
130
136
|
fitToAnchorWidth: fitToAnchorWidth,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dropdown2.js","sources":["../../../src/hooks/useInfiniteScroll.tsx","../../../src/components/dropdown/Dropdown.tsx"],"sourcesContent":["import React, { useEffect } from 'react';\n\ntype useInfiniteScrollType = (\n ref: React.RefObject<HTMLElement>,\n callback?: EventCallback,\n callbackOnMount?: boolean,\n) => void;\ntype EventCallback = (evt?: Event) => void;\n\n/**\n * Listen to clicks away from a given element and callback the passed in function.\n *\n * @param ref A reference to the element on which you want to listen scroll event.\n * @param [callback] A callback function to call when the bottom of the reference element is reached.\n * @param [callbackOnMount] A callback function to call when the component is mounted.\n */\nexport const useInfiniteScroll: useInfiniteScrollType = (ref, callback, callbackOnMount = false) => {\n useEffect(() => {\n const { current } = ref;\n if (!callback || !current) {\n return undefined;\n }\n\n const isAtBottom = () => Boolean(current && current.scrollTop + current.clientHeight >= current.scrollHeight);\n\n const onScroll = (e?: Event): void => {\n if (isAtBottom()) {\n callback(e);\n }\n };\n\n if (isAtBottom()) {\n onScroll();\n }\n\n current.addEventListener('scroll', onScroll);\n current.addEventListener('resize', onScroll);\n return () => {\n current.removeEventListener('scroll', onScroll);\n current.removeEventListener('resize', onScroll);\n };\n }, [ref, callback]);\n\n useEffect(() => {\n if (callback && callbackOnMount) {\n callback();\n }\n }, [callback, callbackOnMount]);\n};\n","import React, { cloneElement, forwardRef, useMemo, useRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport { List, ListProps } from '@lumx/react/components/list/List';\nimport { Offset, Placement, Popover } from '@lumx/react/components/popover/Popover';\nimport { useInfiniteScroll } from '@lumx/react/hooks/useInfiniteScroll';\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses, isComponent } from '@lumx/react/utils';\n\n/**\n * Defines the props of the component.\n */\nexport interface DropdownProps extends GenericProps {\n /** Reference to the element around which the dropdown is placed.\n * @see {@link PopoverProps#anchorRef}\n */\n anchorRef: React.RefObject<HTMLElement>;\n /** Dropdown content. */\n children: React.ReactNode;\n /**\n * Whether a click anywhere out of the Dropdown would close it or not.\n * @see {@link PopoverProps#closeOnClickAway}\n */\n closeOnClickAway?: boolean;\n /**\n * Whether to close the Dropdown when clicking in it or not.\n */\n closeOnClick?: boolean;\n /**\n * Whether an escape key press would close the Dropdown or not.\n * @see {@link PopoverProps#closeOnEscape}\n */\n closeOnEscape?: boolean;\n /**\n * Whether the dropdown should fit to the anchor width (if dropdown is smaller) or not.\n * @see {@link PopoverProps#fitToAnchorWidth}\n */\n fitToAnchorWidth?: boolean;\n /**\n * Whether the dropdown should shrink to fit within the viewport height or not.\n * @see {@link PopoverProps#fitWithinViewportHeight}\n */\n fitWithinViewportHeight?: boolean;\n /**\n * Whether the dropdown should be displayed or not. Useful to control the Dropdown from outside the component.\n * @see {@link PopoverProps#isOpen}\n */\n isOpen: boolean;\n /**\n * Offset applied to the Dropdown position.\n * @see {@link PopoverProps#offset}\n */\n offset?: Offset;\n /**\n * Preferred Dropdown placement against the anchor element.\n * @see {@link PopoverProps#placement}\n */\n placement?: Placement;\n /** Whether the focus should be set on the list when the dropdown is open or not. */\n shouldFocusOnOpen?: boolean;\n /**\n * Z-axis position.\n * @see {@link PopoverProps#zIndex}\n */\n zIndex?: number;\n /**\n * On close callback.\n * @see {@link PopoverProps#onClose}\n */\n onClose?(): void;\n /** On scroll end callback. */\n onInfiniteScroll?(): void;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'Dropdown';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Component default props.\n */\nconst DEFAULT_PROPS: Partial<DropdownProps> = {\n closeOnClick: true,\n closeOnClickAway: true,\n closeOnEscape: true,\n fitToAnchorWidth: true,\n fitWithinViewportHeight: true,\n placement: Placement.BOTTOM_START,\n shouldFocusOnOpen: true,\n};\n\n/**\n * Dropdown component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const Dropdown: Comp<DropdownProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n anchorRef,\n children,\n className,\n closeOnClick,\n closeOnClickAway,\n closeOnEscape,\n fitToAnchorWidth,\n fitWithinViewportHeight,\n isOpen,\n offset,\n onClose,\n onInfiniteScroll,\n placement,\n shouldFocusOnOpen,\n zIndex,\n ...forwardedProps\n } = props;\n const innerRef = useRef<HTMLDivElement>(null);\n const listElement = useRef(null);\n\n useInfiniteScroll(innerRef, onInfiniteScroll);\n\n const popperElement = useMemo(() => {\n return !Array.isArray(children) && isComponent(List)(children)\n ? cloneElement<ListProps>(children, {\n ...children.props,\n ref: listElement,\n onClick(evt: MouseEvent) {\n children.props.onClick?.(evt);\n\n if (closeOnClick) {\n onClose?.();\n }\n },\n isClickable: true,\n })\n : children;\n }, [children, closeOnClick, onClose]);\n\n return isOpen ? (\n <Popover\n ref={ref}\n {...forwardedProps}\n anchorRef={anchorRef}\n className={classNames(className, handleBasicClasses({ prefix: CLASSNAME }))}\n closeOnClickAway={closeOnClickAway}\n closeOnEscape={closeOnEscape}\n fitToAnchorWidth={fitToAnchorWidth}\n fitWithinViewportHeight={fitWithinViewportHeight}\n focusElement={shouldFocusOnOpen ? listElement : undefined}\n isOpen={isOpen}\n offset={offset}\n onClose={onClose}\n placement={placement}\n zIndex={zIndex}\n >\n <div className={`${CLASSNAME}__menu`} ref={innerRef}>\n {popperElement}\n </div>\n </Popover>\n ) : null;\n});\nDropdown.displayName = COMPONENT_NAME;\nDropdown.className = CLASSNAME;\nDropdown.defaultProps = DEFAULT_PROPS;\n"],"names":["useInfiniteScroll","ref","callback","callbackOnMount","useEffect","current","undefined","isAtBottom","Boolean","scrollTop","clientHeight","scrollHeight","onScroll","e","addEventListener","removeEventListener","COMPONENT_NAME","CLASSNAME","getRootClassName","DEFAULT_PROPS","closeOnClick","closeOnClickAway","closeOnEscape","fitToAnchorWidth","fitWithinViewportHeight","placement","Placement","BOTTOM_START","shouldFocusOnOpen","Dropdown","forwardRef","props","anchorRef","children","className","isOpen","offset","onClose","onInfiniteScroll","zIndex","forwardedProps","innerRef","useRef","listElement","popperElement","useMemo","Array","isArray","isComponent","List","cloneElement","onClick","evt","isClickable","classNames","handleBasicClasses","prefix","displayName","defaultProps"],"mappings":";;;;;;AASA;;;;;;;AAOO,IAAMA,iBAAwC,GAAG,SAA3CA,iBAA2C,CAACC,GAAD,EAAMC,QAAN,EAA4C;AAAA,MAA5BC,eAA4B,uEAAV,KAAU;AAChGC,EAAAA,SAAS,CAAC,YAAM;AAAA,QACJC,OADI,GACQJ,GADR,CACJI,OADI;;AAEZ,QAAI,CAACH,QAAD,IAAa,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IAAA,SAAS,YAAKtB,SAAL,WAAd;AAAsC,IAAA,GAAG,EAAEwB;AAA3C,KACKG,aADL,CAhBJ,CADS,GAqBT,IArBJ;AAsBH,CA/DsE;AAgEvEf,QAAQ,CAAC4B,WAAT,GAAuBzC,cAAvB;AACAa,QAAQ,CAACK,SAAT,GAAqBjB,SAArB;AACAY,QAAQ,CAAC6B,YAAT,GAAwBvC,aAAxB;;;;"}
|
|
1
|
+
{"version":3,"file":"Dropdown2.js","sources":["../../../src/hooks/useInfiniteScroll.tsx","../../../src/components/dropdown/Dropdown.tsx"],"sourcesContent":["import React, { useEffect } from 'react';\n\ntype useInfiniteScrollType = (\n ref: React.RefObject<HTMLElement>,\n callback?: EventCallback,\n callbackOnMount?: boolean,\n) => void;\ntype EventCallback = (evt?: Event) => void;\n\n// The error margin in px we want to have for triggering infinite scroll\nconst SCROLL_TRIGGER_MARGIN = 5;\n\n/**\n * Listen to clicks away from a given element and callback the passed in function.\n *\n * @param ref A reference to the element on which you want to listen scroll event.\n * @param [callback] A callback function to call when the bottom of the reference element is reached.\n * @param [callbackOnMount] A callback function to call when the component is mounted.\n */\nexport const useInfiniteScroll: useInfiniteScrollType = (\n ref,\n callback,\n callbackOnMount = false,\n scrollTriggerMargin = SCROLL_TRIGGER_MARGIN,\n) => {\n useEffect(() => {\n const { current } = ref;\n if (!callback || !current) {\n return undefined;\n }\n\n const isAtBottom = () =>\n Boolean(\n current && current.scrollHeight - (current.scrollTop + current.clientHeight) <= scrollTriggerMargin,\n );\n\n const onScroll = (e?: Event): void => {\n if (isAtBottom()) {\n callback(e);\n }\n };\n\n if (isAtBottom()) {\n onScroll();\n }\n\n current.addEventListener('scroll', onScroll);\n current.addEventListener('resize', onScroll);\n return () => {\n current.removeEventListener('scroll', onScroll);\n current.removeEventListener('resize', onScroll);\n };\n }, [ref, callback, scrollTriggerMargin]);\n\n useEffect(() => {\n if (callback && callbackOnMount) {\n callback();\n }\n }, [callback, callbackOnMount]);\n};\n","import React, { cloneElement, forwardRef, useMemo, useRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport { List, ListProps } from '@lumx/react/components/list/List';\nimport { Offset, Placement, Popover } from '@lumx/react/components/popover/Popover';\nimport { useInfiniteScroll } from '@lumx/react/hooks/useInfiniteScroll';\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses, isComponent } from '@lumx/react/utils';\n\n/**\n * Defines the props of the component.\n */\nexport interface DropdownProps extends GenericProps {\n /** Reference to the element around which the dropdown is placed.\n * @see {@link PopoverProps#anchorRef}\n */\n anchorRef: React.RefObject<HTMLElement>;\n /** Dropdown content. */\n children: React.ReactNode;\n /**\n * Whether a click anywhere out of the Dropdown would close it or not.\n * @see {@link PopoverProps#closeOnClickAway}\n */\n closeOnClickAway?: boolean;\n /**\n * Whether to close the Dropdown when clicking in it or not.\n */\n closeOnClick?: boolean;\n /**\n * Whether an escape key press would close the Dropdown or not.\n * @see {@link PopoverProps#closeOnEscape}\n */\n closeOnEscape?: boolean;\n /**\n * Whether the dropdown should fit to the anchor width (if dropdown is smaller) or not.\n * @see {@link PopoverProps#fitToAnchorWidth}\n */\n fitToAnchorWidth?: boolean;\n /**\n * Whether the dropdown should shrink to fit within the viewport height or not.\n * @see {@link PopoverProps#fitWithinViewportHeight}\n */\n fitWithinViewportHeight?: boolean;\n /**\n * Whether the dropdown should be displayed or not. Useful to control the Dropdown from outside the component.\n * @see {@link PopoverProps#isOpen}\n */\n isOpen: boolean;\n /**\n * Offset applied to the Dropdown position.\n * @see {@link PopoverProps#offset}\n */\n offset?: Offset;\n /**\n * Preferred Dropdown placement against the anchor element.\n * @see {@link PopoverProps#placement}\n */\n placement?: Placement;\n /** Whether the focus should be set on the list when the dropdown is open or not. */\n shouldFocusOnOpen?: boolean;\n /**\n * Z-axis position.\n * @see {@link PopoverProps#zIndex}\n */\n zIndex?: number;\n /**\n * On close callback.\n * @see {@link PopoverProps#onClose}\n */\n onClose?(): void;\n /** On scroll end callback. */\n onInfiniteScroll?(): void;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'Dropdown';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Component default props.\n */\nconst DEFAULT_PROPS: Partial<DropdownProps> = {\n closeOnClick: true,\n closeOnClickAway: true,\n closeOnEscape: true,\n fitToAnchorWidth: true,\n fitWithinViewportHeight: true,\n placement: Placement.BOTTOM_START,\n shouldFocusOnOpen: true,\n};\n\n/**\n * Dropdown component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const Dropdown: Comp<DropdownProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n anchorRef,\n children,\n className,\n closeOnClick,\n closeOnClickAway,\n closeOnEscape,\n fitToAnchorWidth,\n fitWithinViewportHeight,\n isOpen,\n offset,\n onClose,\n onInfiniteScroll,\n placement,\n shouldFocusOnOpen,\n zIndex,\n ...forwardedProps\n } = props;\n const innerRef = useRef<HTMLDivElement>(null);\n const listElement = useRef(null);\n\n useInfiniteScroll(innerRef, onInfiniteScroll);\n\n const popperElement = useMemo(() => {\n return !Array.isArray(children) && isComponent(List)(children)\n ? cloneElement<ListProps>(children, {\n ...children.props,\n ref: listElement,\n onClick(evt: MouseEvent) {\n children.props.onClick?.(evt);\n\n if (closeOnClick) {\n onClose?.();\n }\n },\n isClickable: true,\n })\n : children;\n }, [children, closeOnClick, onClose]);\n\n return isOpen ? (\n <Popover\n ref={ref}\n {...forwardedProps}\n anchorRef={anchorRef}\n className={classNames(className, handleBasicClasses({ prefix: CLASSNAME }))}\n elevation={0 as any}\n closeOnClickAway={closeOnClickAway}\n closeOnEscape={closeOnEscape}\n fitToAnchorWidth={fitToAnchorWidth}\n fitWithinViewportHeight={fitWithinViewportHeight}\n focusElement={shouldFocusOnOpen ? listElement : undefined}\n isOpen={isOpen}\n offset={offset}\n onClose={onClose}\n placement={placement}\n zIndex={zIndex}\n >\n <div className={`${CLASSNAME}__menu`} ref={innerRef}>\n {popperElement}\n </div>\n </Popover>\n ) : null;\n});\nDropdown.displayName = COMPONENT_NAME;\nDropdown.className = CLASSNAME;\nDropdown.defaultProps = DEFAULT_PROPS;\n"],"names":["SCROLL_TRIGGER_MARGIN","useInfiniteScroll","ref","callback","callbackOnMount","scrollTriggerMargin","useEffect","current","undefined","isAtBottom","Boolean","scrollHeight","scrollTop","clientHeight","onScroll","e","addEventListener","removeEventListener","COMPONENT_NAME","CLASSNAME","getRootClassName","DEFAULT_PROPS","closeOnClick","closeOnClickAway","closeOnEscape","fitToAnchorWidth","fitWithinViewportHeight","placement","Placement","BOTTOM_START","shouldFocusOnOpen","Dropdown","forwardRef","props","anchorRef","children","className","isOpen","offset","onClose","onInfiniteScroll","zIndex","forwardedProps","innerRef","useRef","listElement","popperElement","useMemo","Array","isArray","isComponent","List","cloneElement","onClick","evt","isClickable","classNames","handleBasicClasses","prefix","displayName","defaultProps"],"mappings":";;;;;;;AASA;AACA,IAAMA,qBAAqB,GAAG,CAA9B;AAEA;;;;;;;;AAOO,IAAMC,iBAAwC,GAAG,SAA3CA,iBAA2C,CACpDC,GADoD,EAEpDC,QAFoD,EAKnD;AAAA,MAFDC,eAEC,uEAFiB,KAEjB;AAAA,MADDC,mBACC,uEADqBL,qBACrB;AACDM,EAAAA,SAAS,CAAC,YAAM;AAAA,QACJC,OADI,GACQL,GADR,CACJK,OADI;;AAEZ,QAAI,CAACJ,QAAD,IAAa,CAACI,OAAlB,EAA2B;AACvB,aAAOC,SAAP;AACH;;AAED,QAAMC,UAAU,GAAG,SAAbA,UAAa;AAAA,aACfC,OAAO,CACHH,OAAO,IAAIA,OAAO,CAACI,YAAR,IAAwBJ,OAAO,CAACK,SAAR,GAAoBL,OAAO,CAACM,YAApD,KAAqER,mBAD7E,CADQ;AAAA,KAAnB;;AAKA,QAAMS,QAAQ,GAAG,SAAXA,QAAW,CAACC,CAAD,EAAqB;AAClC,UAAIN,UAAU,EAAd,EAAkB;AACdN,QAAAA,QAAQ,CAACY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 @@
|
|
|
1
|
+
import { b as _objectWithoutProperties, d as _slicedToArray, c as _extends } from './_rollupPluginBabelHelpers.js';
|
|
1
2
|
import { Emphasis, Theme, ColorPalette } from './components.js';
|
|
2
|
-
import { g as getRootClassName, a as _objectWithoutProperties, f as _slicedToArray, d as classnames, h as handleBasicClasses, b as _extends } from './getRootClassName.js';
|
|
3
3
|
import React, { forwardRef, Children, useRef, useState, useEffect } from 'react';
|
|
4
|
+
import { g as getRootClassName, c as classnames, h as handleBasicClasses } from './getRootClassName.js';
|
|
4
5
|
import { i as mdiChevronUp, j as mdiChevronDown } from './mdi.js';
|
|
5
6
|
import isEmpty from 'lodash/isEmpty';
|
|
6
7
|
import { p as partitionMulti } from './partitionMulti.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpansionPanel.js","sources":["../../../src/components/expansion-panel/ExpansionPanel.tsx"],"sourcesContent":["import React, { Children, forwardRef, PropsWithChildren, ReactNode, useEffect, useRef, useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport { mdiChevronDown, mdiChevronUp } from '@lumx/icons';\n\nimport get from 'lodash/get';\nimport isEmpty from 'lodash/isEmpty';\nimport isFunction from 'lodash/isFunction';\n\nimport { ColorPalette, DragHandle, Emphasis, IconButton, IconButtonProps, Theme } from '@lumx/react';\nimport {\n Callback,\n Comp,\n GenericProps,\n getRootClassName,\n handleBasicClasses,\n isComponent,\n partitionMulti,\n} from '@lumx/react/utils';\n\n/**\n * Defines the props of the component.\n */\nexport interface ExpansionPanelProps extends GenericProps {\n /** Whether the expansion panel has a background. */\n hasBackground?: boolean;\n /** Whether the header has a divider. */\n hasHeaderDivider?: boolean;\n /** Whether the component is open or not. */\n isOpen?: boolean;\n /** Label text (overwritten if a `<header>` is provided in the children). */\n label?: string;\n /** Theme adapting the component to light or dark background. */\n theme?: Theme;\n /** On open callback. */\n onOpen?: Callback;\n /** On close callback. */\n onClose?: Callback;\n /** Props to pass to the toggle button (minus those already set by the ExpansionPanel props). */\n toggleButtonProps: Pick<IconButtonProps, 'label'> &\n Omit<IconButtonProps, 'label' | 'onClick' | 'icon' | 'emphasis' | 'color'>;\n /** On toggle open or close callback. */\n onToggleOpen?(shouldOpen: boolean): void;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'ExpansionPanel';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Component default props.\n */\nconst DEFAULT_PROPS: Partial<ExpansionPanelProps> = {\n theme: Theme.light,\n};\n\nconst isDragHandle = isComponent(DragHandle);\nconst isHeader = isComponent('header');\nconst isFooter = isComponent('footer');\n\n/**\n * ExpansionPanel component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const ExpansionPanel: Comp<ExpansionPanelProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n className,\n children: anyChildren,\n hasBackground,\n hasHeaderDivider,\n isOpen,\n label,\n onClose,\n onOpen,\n onToggleOpen,\n theme,\n toggleButtonProps,\n ...forwardedProps\n } = props;\n\n const children: ReactNode[] = Children.toArray(anyChildren);\n\n // Partition children by types.\n const [[dragHandle], [header], [footer], content] = partitionMulti(children, [isDragHandle, isHeader, isFooter]);\n\n // Either take the header in children or create one with the label.\n const headerProps: PropsWithChildren<any> = React.isValidElement(header) ? header.props : {};\n const headerContent = !isEmpty(headerProps.children) ? (\n headerProps.children\n ) : (\n <span className={`${CLASSNAME}__label`}>{label}</span>\n );\n\n const toggleOpen = () => {\n const shouldOpen = !isOpen;\n if (isFunction(onOpen) && shouldOpen) {\n onOpen();\n }\n if (isFunction(onClose) && !shouldOpen) {\n onClose();\n }\n if (isFunction(onToggleOpen)) {\n onToggleOpen(shouldOpen);\n }\n };\n\n const color = theme === Theme.dark ? ColorPalette.light : ColorPalette.dark;\n\n const rootClassName = classNames(\n className,\n handleBasicClasses({\n hasBackground,\n hasHeader: Boolean(!isEmpty(headerProps.children)),\n hasHeaderDivider,\n isClose: !isOpen,\n isDraggable: Boolean(dragHandle),\n isOpen,\n prefix: CLASSNAME,\n theme,\n }),\n );\n\n const wrapperRef = useRef<HTMLDivElement>(null);\n const isContentVisible = (): boolean => get(wrapperRef.current, 'clientHeight', 0) > 0;\n\n // Switch max height on/off to activate the CSS transition (updates when children changes).\n const [maxHeight, setMaxHeight] = useState('0');\n useEffect(() => {\n const height = isOpen ? get(wrapperRef.current, 'offsetHeight', 0) : 0;\n setMaxHeight(`${height}px`);\n }, [children, isOpen]);\n\n return (\n <section ref={ref} {...forwardedProps} className={rootClassName}>\n {/* eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions */}\n <header className={`${CLASSNAME}__header`} onClick={toggleOpen}>\n {dragHandle && <div className={`${CLASSNAME}__header-drag`}>{dragHandle}</div>}\n\n <div {...headerProps} className={`${CLASSNAME}__header-content`}>\n {headerContent}\n </div>\n\n <div className={`${CLASSNAME}__header-toggle`}>\n <IconButton\n {...toggleButtonProps}\n color={color}\n emphasis={Emphasis.low}\n icon={isOpen ? mdiChevronUp : mdiChevronDown}\n />\n </div>\n </header>\n\n {(isOpen || isContentVisible()) && (\n <div className={`${CLASSNAME}__wrapper`} style={{ maxHeight }}>\n <div className={`${CLASSNAME}__container`} ref={wrapperRef}>\n <div className={`${CLASSNAME}__content`}>{content}</div>\n\n {footer && <div className={`${CLASSNAME}__footer`}>{footer}</div>}\n </div>\n </div>\n )}\n </section>\n );\n});\nExpansionPanel.displayName = COMPONENT_NAME;\nExpansionPanel.className = CLASSNAME;\nExpansionPanel.defaultProps = DEFAULT_PROPS;\n"],"names":["COMPONENT_NAME","CLASSNAME","getRootClassName","DEFAULT_PROPS","theme","Theme","light","isDragHandle","isComponent","DragHandle","isHeader","isFooter","ExpansionPanel","forwardRef","props","ref","className","anyChildren","children","hasBackground","hasHeaderDivider","isOpen","label","onClose","onOpen","onToggleOpen","toggleButtonProps","forwardedProps","Children","toArray","partitionMulti","dragHandle","header","footer","content","headerProps","React","isValidElement","headerContent","isEmpty","toggleOpen","shouldOpen","isFunction","color","dark","ColorPalette","rootClassName","classNames","handleBasicClasses","hasHeader","Boolean","isClose","isDraggable","prefix","wrapperRef","useRef","isContentVisible","get","current","useState","maxHeight","setMaxHeight","useEffect","height","Emphasis","low","mdiChevronUp","mdiChevronDown","displayName","defaultProps"],"mappings":";;;;;;;;;;;;AAqBA;;;;AAyBA;;;AAGA,IAAMA,cAAc,GAAG,gBAAvB;AAEA;;;;AAGA,IAAMC,SAAS,GAAGC,gBAAgB,CAACF,cAAD,CAAlC;AAEA;;;;AAGA,IAAMG,aAA2C,GAAG;AAChDC,EAAAA,KAAK,EAAEC,KAAK,CAACC;AADmC,CAApD;AAIA,IAAMC,YAAY,GAAGC,WAAW,CAACC,UAAD,CAAhC;AACA,IAAMC,QAAQ,GAAGF,WAAW,CAAC,QAAD,CAA5B;AACA,IAAMG,QAAQ,GAAGH,WAAW,CAAC,QAAD,CAA5B;AAEA;;;;;;;;IAOaI,cAAyD,GAAGC,UAAU,CAAC,UAACC,KAAD,EAAQC,GAAR,EAAgB;AAAA,MAE5FC,SAF4F,GAc5FF,KAd4F,CAE5FE,SAF4F;AAAA,MAGlFC,WAHkF,GAc5FH,KAd4F,CAG5FI,QAH4F;AAAA,MAI5FC,aAJ4F,GAc5FL,KAd4F,CAI5FK,aAJ4F;AAAA,MAK5FC,gBAL4F,GAc5FN,KAd4F,CAK5FM,gBAL4F;AAAA,MAM5FC,MAN4F,GAc5FP,KAd4F,CAM5FO,MAN4F;AAAA,MAO5FC,KAP4F,GAc5FR,KAd4F,CAO5FQ,KAP4F;AAAA,MAQ5FC,OAR4F,GAc5FT,KAd4F,CAQ5FS,OAR4F;AAAA,MAS5FC,MAT4F,GAc5FV,KAd4F,CAS5FU,MAT4F;AAAA,MAU5FC,YAV4F,GAc5FX,KAd4F,CAU5FW,YAV4F;AAAA,MAW5FrB,KAX4F,GAc5FU,KAd4F,CAW5FV,KAX4F;AAAA,MAY5FsB,iBAZ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SAAL;AAA/B,MACKqC,aADL,CAHJ,EAOI;AAAK,IAAA,SAAS,YAAKrC,SAAL;AAAd,KACI,oBAAC,UAAD,eACQyB,iBADR;AAEI,IAAA,KAAK,EAAEiB,KAFX;AAGI,IAAA,QAAQ,EAAEqB,QAAQ,CAACC,GAHvB;AAII,IAAA,IAAI,EAAE5C,MAAM,GAAG6C,YAAH,GAAkBC;AAJlC,KADJ,CAPJ,CAFJ,EAmBK,CAAC9C,MAAM,IAAImC,gBAAgB,EAA3B,KACG;AAAK,IAAA,SAAS,YAAKvD,SAAL,cAAd;AAAyC,IAAA,KAAK,EAAE;AAAE2D,MAAAA,SAAS,EAATA;AAAF;AAAhD,KACI;AAAK,IAAA,SAAS,YAAK3D,SAAL,gBAAd;AAA2C,IAAA,GAAG,EAAEqD;AAAhD,KACI;AAAK,IAAA,SAAS,YAAKrD,SAAL;AAAd,KAA0CiC,OAA1C,CADJ,EAGKD,MAAM,IAAI;AAAK,IAAA,SAAS,YAAKhC,SAAL;AAAd,KAAyCgC,MAAzC,CAHf,CADJ,CApBR,CADJ;AA+BH,CAnGkF;AAoGnFrB,cAAc,CAACwD,WAAf,GAA6BpE,cAA7B;AACAY,cAAc,CAACI,SAAf,GAA2Bf,SAA3B;AACAW,cAAc,CAACyD,YAAf,GAA8BlE,aAA9B;;;;"}
|
|
1
|
+
{"version":3,"file":"ExpansionPanel.js","sources":["../../../src/components/expansion-panel/ExpansionPanel.tsx"],"sourcesContent":["import React, { Children, forwardRef, PropsWithChildren, ReactNode, useEffect, useRef, useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport { mdiChevronDown, mdiChevronUp } from '@lumx/icons';\n\nimport get from 'lodash/get';\nimport isEmpty from 'lodash/isEmpty';\nimport isFunction from 'lodash/isFunction';\n\nimport { ColorPalette, DragHandle, Emphasis, IconButton, IconButtonProps, Theme } from '@lumx/react';\nimport {\n Callback,\n Comp,\n GenericProps,\n getRootClassName,\n handleBasicClasses,\n isComponent,\n partitionMulti,\n} from '@lumx/react/utils';\n\n/**\n * Defines the props of the component.\n */\nexport interface ExpansionPanelProps extends GenericProps {\n /** Whether the expansion panel has a background. */\n hasBackground?: boolean;\n /** Whether the header has a divider. */\n hasHeaderDivider?: boolean;\n /** Whether the component is open or not. */\n isOpen?: boolean;\n /** Label text (overwritten if a `<header>` is provided in the children). */\n label?: string;\n /** Theme adapting the component to light or dark background. */\n theme?: Theme;\n /** On open callback. */\n onOpen?: Callback;\n /** On close callback. */\n onClose?: Callback;\n /** Props to pass to the toggle button (minus those already set by the ExpansionPanel props). */\n toggleButtonProps: Pick<IconButtonProps, 'label'> &\n Omit<IconButtonProps, 'label' | 'onClick' | 'icon' | 'emphasis' | 'color'>;\n /** On toggle open or close callback. */\n onToggleOpen?(shouldOpen: boolean): void;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'ExpansionPanel';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Component default props.\n */\nconst DEFAULT_PROPS: Partial<ExpansionPanelProps> = {\n theme: Theme.light,\n};\n\nconst isDragHandle = isComponent(DragHandle);\nconst isHeader = isComponent('header');\nconst isFooter = isComponent('footer');\n\n/**\n * ExpansionPanel component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const ExpansionPanel: Comp<ExpansionPanelProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n className,\n children: anyChildren,\n hasBackground,\n hasHeaderDivider,\n isOpen,\n label,\n onClose,\n onOpen,\n onToggleOpen,\n theme,\n toggleButtonProps,\n ...forwardedProps\n } = props;\n\n const children: ReactNode[] = Children.toArray(anyChildren);\n\n // Partition children by types.\n const [[dragHandle], [header], [footer], content] = partitionMulti(children, [isDragHandle, isHeader, isFooter]);\n\n // Either take the header in children or create one with the label.\n const headerProps: PropsWithChildren<any> = React.isValidElement(header) ? header.props : {};\n const headerContent = !isEmpty(headerProps.children) ? (\n headerProps.children\n ) : (\n <span className={`${CLASSNAME}__label`}>{label}</span>\n );\n\n const toggleOpen = () => {\n const shouldOpen = !isOpen;\n if (isFunction(onOpen) && shouldOpen) {\n onOpen();\n }\n if (isFunction(onClose) && !shouldOpen) {\n onClose();\n }\n if (isFunction(onToggleOpen)) {\n onToggleOpen(shouldOpen);\n }\n };\n\n const color = theme === Theme.dark ? ColorPalette.light : ColorPalette.dark;\n\n const rootClassName = classNames(\n className,\n handleBasicClasses({\n hasBackground,\n hasHeader: Boolean(!isEmpty(headerProps.children)),\n hasHeaderDivider,\n isClose: !isOpen,\n isDraggable: Boolean(dragHandle),\n isOpen,\n prefix: CLASSNAME,\n theme,\n }),\n );\n\n const wrapperRef = useRef<HTMLDivElement>(null);\n const isContentVisible = (): boolean => get(wrapperRef.current, 'clientHeight', 0) > 0;\n\n // Switch max height on/off to activate the CSS transition (updates when children changes).\n const [maxHeight, setMaxHeight] = useState('0');\n useEffect(() => {\n const height = isOpen ? get(wrapperRef.current, 'offsetHeight', 0) : 0;\n setMaxHeight(`${height}px`);\n }, [children, isOpen]);\n\n return (\n <section ref={ref} {...forwardedProps} className={rootClassName}>\n {/* eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions */}\n <header className={`${CLASSNAME}__header`} onClick={toggleOpen}>\n {dragHandle && <div className={`${CLASSNAME}__header-drag`}>{dragHandle}</div>}\n\n <div {...headerProps} className={`${CLASSNAME}__header-content`}>\n {headerContent}\n </div>\n\n <div className={`${CLASSNAME}__header-toggle`}>\n <IconButton\n {...toggleButtonProps}\n color={color}\n emphasis={Emphasis.low}\n icon={isOpen ? mdiChevronUp : mdiChevronDown}\n />\n </div>\n </header>\n\n {(isOpen || isContentVisible()) && (\n <div className={`${CLASSNAME}__wrapper`} style={{ maxHeight }}>\n <div className={`${CLASSNAME}__container`} ref={wrapperRef}>\n <div className={`${CLASSNAME}__content`}>{content}</div>\n\n {footer && <div className={`${CLASSNAME}__footer`}>{footer}</div>}\n </div>\n </div>\n )}\n </section>\n );\n});\nExpansionPanel.displayName = COMPONENT_NAME;\nExpansionPanel.className = CLASSNAME;\nExpansionPanel.defaultProps = DEFAULT_PROPS;\n"],"names":["COMPONENT_NAME","CLASSNAME","getRootClassName","DEFAULT_PROPS","theme","Theme","light","isDragHandle","isComponent","DragHandle","isHeader","isFooter","ExpansionPanel","forwardRef","props","ref","className","anyChildren","children","hasBackground","hasHeaderDivider","isOpen","label","onClose","onOpen","onToggleOpen","toggleButtonProps","forwardedProps","Children","toArray","partitionMulti","dragHandle","header","footer","content","headerProps","React","isValidElement","headerContent","isEmpty","toggleOpen","shouldOpen","isFunction","color","dark","ColorPalette","rootClassName","classNames","handleBasicClasses","hasHeader","Boolean","isClose","isDraggable","prefix","wrapperRef","useRef","isContentVisible","get","current","useState","maxHeight","setMaxHeight","useEffect","height","Emphasis","low","mdiChevronUp","mdiChevronDown","displayName","defaultProps"],"mappings":";;;;;;;;;;;;;AAqBA;;;;AAyBA;;;AAGA,IAAMA,cAAc,GAAG,gBAAvB;AAEA;;;;AAGA,IAAMC,SAAS,GAAGC,gBAAgB,CAACF,cAAD,CAAlC;AAEA;;;;AAGA,IAAMG,aAA2C,GAAG;AAChDC,EAAAA,KAAK,EAAEC,KAAK,CAACC;AADmC,CAApD;AAIA,IAAMC,YAAY,GAAGC,WAAW,CAACC,UAAD,CAAhC;AACA,IAAMC,QAAQ,GAAGF,WAAW,CAAC,QAAD,CAA5B;AACA,IAAMG,QAAQ,GAAGH,WAAW,CAAC,QAAD,CAA5B;AAEA;;;;;;;;IAOaI,cAAyD,GAAGC,UAAU,CAAC,UAACC,KAAD,EAAQC,GAAR,EAAgB;AAAA,MAE5FC,SAF4F,GAc5FF,KAd4F,CAE5FE,SAF4F;AAAA,MAGlFC,WAHkF,GAc5FH,KAd4F,CAG5FI,QAH4F;AAAA,MAI5FC,aAJ4F,GAc5FL,KAd4F,CAI5FK,aAJ4F;AAAA,MAK5FC,gBAL4F,GAc5FN,KAd4F,CAK5FM,gBAL4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import { b as _objectWithoutProperties, c as _extends } from './_rollupPluginBabelHelpers.js';
|
|
1
2
|
import { ColorVariant, Size, Theme, ColorPalette } from './components.js';
|
|
2
|
-
import { g as getRootClassName, a as _objectWithoutProperties, b as _extends, d as classnames, h as handleBasicClasses } from './getRootClassName.js';
|
|
3
3
|
import React, { forwardRef } from 'react';
|
|
4
|
+
import { g as getRootClassName, c as classnames, h as handleBasicClasses } from './getRootClassName.js';
|
|
4
5
|
import { I as Icon } from './Icon2.js';
|
|
5
6
|
|
|
6
7
|
var COMPONENT_NAME = 'Flag';
|