idea-react 3.0.0-alpha.0 → 3.0.0-alpha.1

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.
Files changed (60) hide show
  1. package/AGENTS.md +31 -10
  2. package/ReadMe.md +42 -35
  3. package/dist/index.d.mts +301 -100
  4. package/dist/index.d.ts +301 -100
  5. package/dist/index.js +16 -16
  6. package/dist/index.mjs +15 -15
  7. package/dist/style.css +5 -5
  8. package/package.json +4 -7
  9. package/source/Avatar.tsx +65 -12
  10. package/source/Button.tsx +13 -4
  11. package/source/ButtonGroup.tsx +28 -0
  12. package/source/Card.tsx +26 -0
  13. package/source/ClickBoundary.tsx +6 -5
  14. package/source/CloseButton.tsx +23 -0
  15. package/source/CodeBlock.tsx +5 -3
  16. package/source/Countdown.tsx +2 -0
  17. package/source/Drawer.tsx +62 -0
  18. package/source/Editor.tsx +5 -8
  19. package/source/Grid.tsx +92 -0
  20. package/source/HorizontalMarquee/index.tsx +4 -10
  21. package/source/Image.tsx +15 -0
  22. package/source/ListGroup.tsx +103 -0
  23. package/source/LiveTSX.tsx +1 -1
  24. package/source/Loading.tsx +4 -3
  25. package/source/Menu.tsx +99 -1
  26. package/source/MonthCalendar.tsx +60 -22
  27. package/source/NativeDialog/index.tsx +37 -1
  28. package/source/Nav.tsx +52 -0
  29. package/source/Navbar.tsx +48 -1
  30. package/source/Overlay.ts +22 -0
  31. package/source/OverlayBox.tsx +200 -32
  32. package/source/PageNav.tsx +56 -32
  33. package/source/Popover.tsx +36 -0
  34. package/source/ScrollNav/Scroller.tsx +107 -0
  35. package/source/ScrollNav/index.tsx +12 -99
  36. package/source/Select.tsx +66 -55
  37. package/source/ShareBox.tsx +5 -11
  38. package/source/Spinner.tsx +30 -0
  39. package/source/SpinnerButton.tsx +8 -10
  40. package/source/Table.tsx +59 -0
  41. package/source/TableSpinner.tsx +7 -5
  42. package/source/{TextTruncate.tsx → TextTruncate/Content.tsx} +24 -20
  43. package/source/TextTruncate/index.tsx +25 -0
  44. package/source/Time.tsx +7 -33
  45. package/source/TimeDistance.tsx +1 -1
  46. package/source/Timeline/index.tsx +7 -7
  47. package/source/Toast.tsx +114 -29
  48. package/source/ToggleButton.tsx +47 -0
  49. package/source/Tooltip.tsx +32 -0
  50. package/source/TypeEcho/Content.tsx +58 -0
  51. package/source/TypeEcho/index.tsx +14 -0
  52. package/source/UserRank/index.module.less +9 -20
  53. package/source/UserRank/index.tsx +35 -32
  54. package/source/VerticalMarquee/index.module.less +0 -1
  55. package/source/VerticalMarquee/index.tsx +3 -5
  56. package/source/ZodiacBar.tsx +1 -1
  57. package/source/animate.ts +4 -2
  58. package/source/color.ts +3 -5
  59. package/source/index.ts +13 -0
  60. package/source/TypeEcho.tsx +0 -49
@@ -1,3 +1,5 @@
1
+ 'use client';
2
+
1
3
  import {
2
4
  createRef,
3
5
  DetailedHTMLProps,
@@ -8,8 +10,8 @@ import {
8
10
 
9
11
  export type ClickBoundaryProps = PropsWithChildren<
10
12
  {
11
- onInnerClick?: (event: MouseEvent) => any;
12
- onOuterClick?: (event: MouseEvent) => any;
13
+ onInnerClick?: (event: MouseEvent) => unknown;
14
+ onOuterClick?: (event: MouseEvent) => unknown;
13
15
  } & DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>
14
16
  >;
15
17
 
@@ -19,8 +21,7 @@ export class ClickBoundary extends PureComponent<ClickBoundaryProps> {
19
21
  switchClick = (event: MouseEvent) => {
20
22
  const { onInnerClick, onOuterClick } = this.props;
21
23
 
22
- if (this.root.current?.contains(event.target as Node))
23
- onInnerClick?.(event);
24
+ if (this.root.current?.contains(event.target as Node)) onInnerClick?.(event);
24
25
  else onOuterClick?.(event);
25
26
  };
26
27
 
@@ -33,7 +34,7 @@ export class ClickBoundary extends PureComponent<ClickBoundaryProps> {
33
34
  }
34
35
 
35
36
  render() {
36
- const { children, onInnerClick, onOuterClick, ...props } = this.props;
37
+ const { children, onInnerClick: _, onOuterClick: __, ...props } = this.props;
37
38
 
38
39
  return (
39
40
  <div ref={this.root} {...props}>
@@ -0,0 +1,23 @@
1
+ import classNames from 'classnames';
2
+ import { ComponentPropsWithRef, FC } from 'react';
3
+
4
+ export interface CloseButtonProps extends ComponentPropsWithRef<'button'> {
5
+ dismiss?: string;
6
+ }
7
+
8
+ export const CloseButton: FC<CloseButtonProps> = ({
9
+ dismiss,
10
+ className,
11
+ type = 'button',
12
+ 'aria-label': ariaLabel = 'Close',
13
+ ...props
14
+ }) => (
15
+ <button
16
+ {...props}
17
+ type={type}
18
+ className={classNames('btn-close', className)}
19
+ data-bs-dismiss={dismiss}
20
+ aria-label={ariaLabel}
21
+ />
22
+ );
23
+ CloseButton.displayName = 'CloseButton';
@@ -2,6 +2,7 @@ import js from '@shikijs/langs/javascript';
2
2
  import jsx from '@shikijs/langs/jsx';
3
3
  import tsx from '@shikijs/langs/tsx';
4
4
  import ts from '@shikijs/langs/typescript';
5
+ import githubDark from '@shikijs/themes/github-dark';
5
6
  import githubLight from '@shikijs/themes/github-light';
6
7
  import { FC, HTMLAttributes, isValidElement } from 'react';
7
8
  import reactElementToJSXString from 'react-element-to-jsx-string';
@@ -9,7 +10,7 @@ import { createHighlighterCoreSync } from 'shiki/core';
9
10
  import { createJavaScriptRegexEngine } from 'shiki/engine/javascript';
10
11
 
11
12
  const highlighter = createHighlighterCoreSync({
12
- themes: [githubLight],
13
+ themes: [githubLight, githubDark],
13
14
  langs: [js, jsx, ts, tsx],
14
15
  engine: createJavaScriptRegexEngine()
15
16
  });
@@ -26,12 +27,13 @@ export const CodeBlock: FC<CodeBlockProps> = ({ className = '', language, childr
26
27
 
27
28
  const __html = highlighter.codeToHtml(sourceCode, {
28
29
  lang: language,
29
- theme: 'github-light',
30
+ themes: { light: 'github-light', dark: 'github-dark' },
31
+ defaultColor: 'light',
30
32
  structure: 'inline'
31
33
  });
32
34
 
33
35
  return (
34
- <pre className={`m-0 language-${language} ${className}`} {...props}>
36
+ <pre className={`m-0 shiki language-${language} ${className}`} {...props}>
35
37
  <code dangerouslySetInnerHTML={{ __html }} className={`language-${language}`} />
36
38
  </pre>
37
39
  );
@@ -1,3 +1,5 @@
1
+ 'use client';
2
+
1
3
  import { computed, observable } from 'mobx';
2
4
  import { observer } from 'mobx-react';
3
5
  import { ObservedComponent, reaction } from 'mobx-react-helper';
@@ -0,0 +1,62 @@
1
+ 'use client';
2
+
3
+ import classNames from 'classnames';
4
+ import { ComponentPropsWithRef, FC, ReactNode } from 'react';
5
+
6
+ import { CloseButton } from './CloseButton';
7
+ import { NativeDialog, NativeDialogProps } from './NativeDialog';
8
+
9
+ export type DrawerPlacement = 'start' | 'end' | 'top' | 'bottom';
10
+
11
+ export const DrawerHeader: FC<ComponentPropsWithRef<'div'>> = ({ className, ...props }) => (
12
+ <div {...props} className={classNames('drawer-header', className)} />
13
+ );
14
+
15
+ export const DrawerTitle: FC<ComponentPropsWithRef<'h5'>> = ({ className, ...props }) => (
16
+ <h5 {...props} className={classNames('drawer-title', className)} />
17
+ );
18
+
19
+ export const DrawerBody: FC<ComponentPropsWithRef<'div'>> = ({ className, ...props }) => (
20
+ <div {...props} className={classNames('drawer-body', className)} />
21
+ );
22
+
23
+ export const DrawerFooter: FC<ComponentPropsWithRef<'div'>> = ({ className, ...props }) => (
24
+ <div {...props} className={classNames('drawer-footer', className)} />
25
+ );
26
+
27
+ export interface DrawerProps extends Omit<NativeDialogProps, 'dialog' | 'onClose' | 'title'> {
28
+ title?: ReactNode;
29
+ placement?: DrawerPlacement;
30
+ footer?: ReactNode;
31
+ bodyClassName?: string;
32
+ onDismiss?: () => void;
33
+ }
34
+
35
+ export const Drawer: FC<DrawerProps> = ({
36
+ title,
37
+ placement = 'end',
38
+ footer,
39
+ bodyClassName,
40
+ onDismiss,
41
+ className,
42
+ children,
43
+ ...props
44
+ }) => (
45
+ <NativeDialog
46
+ {...props}
47
+ dialog={false}
48
+ tabIndex={-1}
49
+ aria-label={typeof title === 'string' ? title : props['aria-label']}
50
+ className={classNames('drawer', `drawer-${placement}`, className)}
51
+ onClose={onDismiss}
52
+ >
53
+ <DrawerHeader>
54
+ <DrawerTitle>{title}</DrawerTitle>
55
+ <CloseButton onClick={onDismiss} />
56
+ </DrawerHeader>
57
+ <DrawerBody className={bodyClassName}>{children}</DrawerBody>
58
+ {footer && <DrawerFooter>{footer}</DrawerFooter>}
59
+ </NativeDialog>
60
+ );
61
+
62
+ Drawer.displayName = 'Drawer';
package/source/Editor.tsx CHANGED
@@ -1,3 +1,5 @@
1
+ 'use client';
2
+
1
3
  import { EditorCore, WrapperProps } from '@react-editor-js/core';
2
4
  import { observable } from 'mobx';
3
5
  import { observer } from 'mobx-react';
@@ -7,8 +9,7 @@ import { createReactEditorJS } from 'react-editor-js';
7
9
  const ReactEditorJS = createReactEditorJS();
8
10
 
9
11
  export type EditorProps = PropsWithoutRef<
10
- WrapperProps &
11
- Pick<InputHTMLAttributes<HTMLInputElement>, 'name' | 'required'>
12
+ WrapperProps & Pick<InputHTMLAttributes<HTMLInputElement>, 'name' | 'required'>
12
13
  >;
13
14
 
14
15
  @observer
@@ -23,16 +24,12 @@ export class Editor extends Component<EditorProps> {
23
24
  save = async () => this.core && (this.innerValue = await this.core.save());
24
25
 
25
26
  render() {
26
- const { name, required, children, ...editorProps } = this.props,
27
+ const { name, required, children: _children, ...editorProps } = this.props,
27
28
  { innerValue } = this;
28
29
 
29
30
  return (
30
31
  <div className="form-control" tabIndex={-1} onBlur={this.save}>
31
- <input
32
- hidden
33
- {...{ name, required }}
34
- value={JSON.stringify(innerValue)}
35
- />
32
+ <input hidden {...{ name, required }} value={JSON.stringify(innerValue)} />
36
33
  <ReactEditorJS
37
34
  {...editorProps}
38
35
  onInitialize={core => {
@@ -0,0 +1,92 @@
1
+ import classNames from 'classnames';
2
+ import { ComponentPropsWithRef, FC } from 'react';
3
+
4
+ export type Breakpoint = 'sm' | 'md' | 'lg' | 'xl' | '2xl';
5
+ export type ColSize = number | 'auto';
6
+ export type BreakpointColSize = ColSize | true;
7
+
8
+ export interface ContainerProps extends ComponentPropsWithRef<'div'> {
9
+ fluid?: boolean;
10
+ breakpoint?: Breakpoint;
11
+ }
12
+
13
+ export const Container: FC<ContainerProps> = ({ fluid, breakpoint, className, ...props }) => (
14
+ <div
15
+ {...props}
16
+ className={classNames(
17
+ breakpoint ? `${breakpoint}:container` : fluid ? 'container-fluid' : 'container',
18
+ className
19
+ )}
20
+ />
21
+ );
22
+
23
+ export type RowCols = number | 'auto';
24
+
25
+ export interface RowProps extends ComponentPropsWithRef<'div'> {
26
+ cols?: RowCols;
27
+ sm?: RowCols;
28
+ md?: RowCols;
29
+ lg?: RowCols;
30
+ xl?: RowCols;
31
+ '2xl'?: RowCols;
32
+ }
33
+
34
+ export const Row: FC<RowProps> = ({ cols, sm, md, lg, xl, '2xl': xxl, className, ...props }) => {
35
+ const sizes: [Breakpoint, RowCols | undefined][] = [
36
+ ['sm', sm],
37
+ ['md', md],
38
+ ['lg', lg],
39
+ ['xl', xl],
40
+ ['2xl', xxl]
41
+ ];
42
+
43
+ return (
44
+ <div
45
+ {...props}
46
+ className={classNames(
47
+ 'row',
48
+ cols !== undefined && `row-cols-${cols}`,
49
+ sizes.map(
50
+ ([breakpoint, size]) => size !== undefined && `${breakpoint}:row-cols-${size}`
51
+ ),
52
+ className
53
+ )}
54
+ />
55
+ );
56
+ };
57
+
58
+ export interface ColProps extends ComponentPropsWithRef<'div'> {
59
+ span?: ColSize;
60
+ sm?: BreakpointColSize;
61
+ md?: BreakpointColSize;
62
+ lg?: BreakpointColSize;
63
+ xl?: BreakpointColSize;
64
+ '2xl'?: BreakpointColSize;
65
+ }
66
+
67
+ export const Col: FC<ColProps> = ({ span, sm, md, lg, xl, '2xl': xxl, className, ...props }) => {
68
+ const sizes: [Breakpoint, BreakpointColSize | undefined][] = [
69
+ ['sm', sm],
70
+ ['md', md],
71
+ ['lg', lg],
72
+ ['xl', xl],
73
+ ['2xl', xxl]
74
+ ];
75
+ const sized = sizes.some(([, size]) => size !== undefined);
76
+
77
+ return (
78
+ <div
79
+ {...props}
80
+ className={classNames(
81
+ !span && !sized && 'col',
82
+ span !== undefined && `col-${span}`,
83
+ sizes.map(
84
+ ([breakpoint, size]) =>
85
+ size !== undefined &&
86
+ (size === true ? `${breakpoint}:col` : `${breakpoint}:col-${size}`)
87
+ ),
88
+ className
89
+ )}
90
+ />
91
+ );
92
+ };
@@ -13,7 +13,7 @@ export const HorizontalMarquee: FC<HorizontalMarqueeProps> = ({
13
13
  height,
14
14
  ...props
15
15
  }) => (
16
- <div className={`overflow-hidden mw-100 ${className}`} {...props}>
16
+ <div className={`overflow-hidden max-w-100 ${className}`} {...props}>
17
17
  <div
18
18
  className={`d-inline-block align-top text-nowrap ${style.scrollWrap}`}
19
19
  style={{
@@ -45,23 +45,17 @@ export const HorizontalMarqueeBox: FC<HorizontalMarqueeProps> = ({
45
45
  // @ts-expect-error remove after React 19 released
46
46
  style={{ maxWidth: maxWidth, '--scroll-height': height }}
47
47
  >
48
- <div
49
- className={`d-inline-block overflow-hidden mw-100 ${style.scrollContainer}`}
50
- >
48
+ <div className={`d-inline-block overflow-hidden max-w-100 ${style.scrollContainer}`}>
51
49
  <div
52
50
  className={`d-block overflow-hidden text-wrap text-break ${style.unScrollItem}`}
53
51
  >
54
52
  {children}
55
53
  </div>
56
- <HorizontalMarquee duration={duration}>
57
- {children}
58
- </HorizontalMarquee>
54
+ <HorizontalMarquee duration={duration}>{children}</HorizontalMarquee>
59
55
  </div>
60
56
  </div>
61
57
  ) : (
62
- <HorizontalMarquee {...{ maxWidth, duration, height }}>
63
- {children}
64
- </HorizontalMarquee>
58
+ <HorizontalMarquee {...{ maxWidth, duration, height }}>{children}</HorizontalMarquee>
65
59
  );
66
60
 
67
61
  HorizontalMarquee.displayName = 'HorizontalMarquee';
@@ -0,0 +1,15 @@
1
+ import classNames from 'classnames';
2
+ import { ComponentPropsWithRef, FC } from 'react';
3
+
4
+ export interface ImageProps extends ComponentPropsWithRef<'img'> {
5
+ fluid?: boolean;
6
+ thumbnail?: boolean;
7
+ }
8
+
9
+ export const Image: FC<ImageProps> = ({ fluid, thumbnail, className, ...props }) => (
10
+ <img
11
+ {...props}
12
+ className={classNames({ 'img-fluid': fluid, 'img-thumbnail': thumbnail }, className)}
13
+ />
14
+ );
15
+ Image.displayName = 'Image';
@@ -0,0 +1,103 @@
1
+ import classNames from 'classnames';
2
+ import { ComponentPropsWithRef, FC } from 'react';
3
+
4
+ import type { ComponentTheme } from './Button';
5
+ import type { Breakpoint } from './Grid';
6
+
7
+ export type ListGroupHorizontal = boolean | Breakpoint;
8
+
9
+ export interface ListGroupProps extends ComponentPropsWithRef<'ul'> {
10
+ flush?: boolean;
11
+ numbered?: boolean;
12
+ horizontal?: ListGroupHorizontal;
13
+ }
14
+
15
+ export const ListGroup: FC<ListGroupProps> = ({
16
+ flush,
17
+ numbered,
18
+ horizontal,
19
+ className,
20
+ ...props
21
+ }) => (
22
+ <ul
23
+ {...props}
24
+ className={classNames(
25
+ 'list-group',
26
+ { 'list-group-flush': flush, 'list-group-numbered': numbered },
27
+ horizontal &&
28
+ (horizontal === true
29
+ ? 'list-group-horizontal'
30
+ : `${horizontal}:list-group-horizontal`),
31
+ className
32
+ )}
33
+ />
34
+ );
35
+
36
+ interface ListGroupItemStyleProps {
37
+ theme?: ComponentTheme;
38
+ action?: boolean;
39
+ active?: boolean;
40
+ disabled?: boolean;
41
+ }
42
+
43
+ type ListGroupItemLinkAttributes = ComponentPropsWithRef<'a'> & { href: string };
44
+ type ListGroupItemButtonAttributes = ComponentPropsWithRef<'button'> & { href?: never };
45
+ type ListGroupItemAttributes = ComponentPropsWithRef<'li'> & { href?: never; type?: never };
46
+ type ListGroupItemElementAttributes =
47
+ ListGroupItemLinkAttributes | ListGroupItemButtonAttributes | ListGroupItemAttributes;
48
+
49
+ export type ListGroupItemProps = ListGroupItemStyleProps & ListGroupItemElementAttributes;
50
+
51
+ const isLink = (props: ListGroupItemElementAttributes): props is ListGroupItemLinkAttributes =>
52
+ typeof props.href === 'string';
53
+
54
+ const isButton = (props: ListGroupItemElementAttributes): props is ListGroupItemButtonAttributes =>
55
+ typeof props.type === 'string';
56
+
57
+ export const ListGroupItem: FC<ListGroupItemProps> = ({
58
+ theme,
59
+ action,
60
+ active,
61
+ disabled,
62
+ className,
63
+ ...props
64
+ }) => {
65
+ const classes = classNames(
66
+ 'list-group-item',
67
+ theme && `theme-${theme}`,
68
+ action && 'list-group-item-action',
69
+ { active, disabled },
70
+ disabled && 'pe-none',
71
+ className
72
+ );
73
+
74
+ return isLink(props) ? (
75
+ <a
76
+ {...props}
77
+ className={classes}
78
+ href={disabled ? undefined : props.href}
79
+ aria-current={active ? 'true' : undefined}
80
+ aria-disabled={disabled || undefined}
81
+ tabIndex={disabled ? -1 : props.tabIndex}
82
+ onClick={disabled ? undefined : props.onClick}
83
+ />
84
+ ) : isButton(props) ? (
85
+ <button
86
+ {...props}
87
+ type={props.type || 'button'}
88
+ className={classes}
89
+ aria-current={active ? 'true' : undefined}
90
+ disabled={disabled}
91
+ />
92
+ ) : (
93
+ <li
94
+ {...(props as ListGroupItemAttributes)}
95
+ className={classes}
96
+ aria-current={active ? 'true' : undefined}
97
+ aria-disabled={disabled || undefined}
98
+ />
99
+ );
100
+ };
101
+
102
+ ListGroup.displayName = 'ListGroup';
103
+ ListGroupItem.displayName = 'ListGroupItem';
@@ -12,7 +12,7 @@ export const LiveTSX: FC<LiveTSXProps> = ({ scope, children }) => {
12
12
  <LiveProvider code={code} scope={scope} language="tsx">
13
13
  <LivePreview className="mb-3" />
14
14
  <LiveEditor />
15
- <LiveError className="text-danger small p-2" />
15
+ <LiveError className="fg-danger small p-2" />
16
16
  </LiveProvider>
17
17
  );
18
18
  };
@@ -1,5 +1,6 @@
1
1
  import { FC, HTMLAttributes } from 'react';
2
- import { Spinner } from 'react-bootstrap';
2
+
3
+ import { Spinner } from './Spinner';
3
4
 
4
5
  export type LoadingProps = HTMLAttributes<HTMLDivElement>;
5
6
 
@@ -12,9 +13,9 @@ export const Loading: FC<LoadingProps> = ({
12
13
  className={`fixed-top h-100 w-100 d-flex justify-content-center align-items-center opacity-25 bg-black ${className}`}
13
14
  {...props}
14
15
  >
15
- <Spinner animation="border" variant="success" />
16
+ <Spinner theme="success" />
16
17
 
17
- <span className="ml-3 text-white">{children}</span>
18
+ <span className="ms-3 fg-white">{children}</span>
18
19
  </div>
19
20
  );
20
21
 
package/source/Menu.tsx CHANGED
@@ -11,6 +11,7 @@ import {
11
11
  HTMLAttributes,
12
12
  KeyboardEvent,
13
13
  MouseEvent,
14
+ PropsWithChildren,
14
15
  ReactNode
15
16
  } from 'react';
16
17
 
@@ -20,6 +21,102 @@ export const MenuItem: FC<ButtonProps> = ({ className, ...props }) => (
20
21
  <Button {...props} className={classNames('menu-item', className)} />
21
22
  );
22
23
 
24
+ export const MenuPanel: FC<HTMLAttributes<HTMLDivElement>> = ({ className, ...props }) => (
25
+ <div {...props} className={classNames('menu', className)} />
26
+ );
27
+
28
+ export const MenuText: FC<HTMLAttributes<HTMLSpanElement>> = ({ className, ...props }) => (
29
+ <span {...props} className={classNames('menu-text', className)} />
30
+ );
31
+
32
+ export const MenuHeader: FC<HTMLAttributes<HTMLHeadingElement>> = ({ className, ...props }) => (
33
+ <h6 {...props} className={classNames('menu-header', className)} />
34
+ );
35
+
36
+ export const MenuDivider: FC<HTMLAttributes<HTMLHRElement>> = ({ className, ...props }) => (
37
+ <hr {...props} className={classNames('menu-divider', className)} />
38
+ );
39
+
40
+ export const MenuItemContent: FC<HTMLAttributes<HTMLSpanElement>> = ({ className, ...props }) => (
41
+ <span {...props} className={classNames('menu-item-content', className)} />
42
+ );
43
+
44
+ export const MenuItemDescription: FC<HTMLAttributes<HTMLElement>> = ({ className, ...props }) => (
45
+ <small {...props} className={classNames('menu-item-description', className)} />
46
+ );
47
+
48
+ export interface MenuSubmenuProps extends PropsWithChildren {
49
+ label: ReactNode;
50
+ className?: string;
51
+ }
52
+
53
+ @observer
54
+ export class MenuSubmenu extends Component<MenuSubmenuProps> {
55
+ @observable accessor open = false;
56
+
57
+ panel = createRef<HTMLDivElement>();
58
+
59
+ @action
60
+ setOpen = (open: boolean) => {
61
+ this.open = open;
62
+ };
63
+
64
+ handleClick = () => this.setOpen(!this.open);
65
+
66
+ handleMouseEnter = () => this.setOpen(true);
67
+
68
+ handleMouseLeave = () => this.setOpen(false);
69
+
70
+ handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
71
+ const { key } = event;
72
+
73
+ if (key === 'ArrowRight') {
74
+ event.preventDefault();
75
+ this.setOpen(true);
76
+
77
+ queueMicrotask(() =>
78
+ this.panel.current
79
+ ?.querySelector<HTMLElement>('a[href], button:not(:disabled)')
80
+ ?.focus()
81
+ );
82
+ }
83
+ if (key === 'ArrowLeft' && this.open) {
84
+ event.preventDefault();
85
+ this.setOpen(false);
86
+ }
87
+ };
88
+
89
+ render() {
90
+ const { label, className, children } = this.props;
91
+ const { open } = this;
92
+
93
+ return (
94
+ <div
95
+ className={classNames('submenu', { show: open }, className)}
96
+ onMouseEnter={this.handleMouseEnter}
97
+ onMouseLeave={this.handleMouseLeave}
98
+ onKeyDown={this.handleKeyDown}
99
+ >
100
+ <Button
101
+ className="menu-item"
102
+ aria-haspopup="true"
103
+ aria-expanded={open}
104
+ onClick={this.handleClick}
105
+ >
106
+ {label}
107
+ </Button>
108
+ <div
109
+ ref={this.panel}
110
+ className={classNames('menu start-100 top-0', { show: open })}
111
+ hidden={!open}
112
+ >
113
+ {children}
114
+ </div>
115
+ </div>
116
+ );
117
+ }
118
+ }
119
+
23
120
  export interface MenuProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange'> {
24
121
  label: ReactNode;
25
122
  autoClose?: boolean | 'inside' | 'outside';
@@ -124,6 +221,7 @@ export class Menu extends Component<MenuProps> {
124
221
  autoClose &&
125
222
  autoClose !== 'outside' &&
126
223
  target instanceof Element &&
224
+ !target.closest('.submenu > .menu-item') &&
127
225
  target.closest('a[href], button:not(:disabled)')
128
226
  )
129
227
  this.setOpen(false);
@@ -151,7 +249,7 @@ export class Menu extends Component<MenuProps> {
151
249
  {...props}
152
250
  ref={this.root}
153
251
  id={id}
154
- className={classNames('position-relative', className)}
252
+ className={classNames('d-inline-block position-relative', className)}
155
253
  onKeyDown={this.handleKeyDown}
156
254
  onBlur={this.handleBlur}
157
255
  >