draft-components 1.0.0-beta.5 → 1.0.0-beta.7

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.
@@ -2,11 +2,18 @@ import { jsx, jsxs } from 'react/jsx-runtime';
2
2
  import { forwardRef } from 'react';
3
3
  import { classNames } from '../../lib/react-helpers.js';
4
4
 
5
- const MenuItem = forwardRef(function MenuItem({ icon = null, appearance = 'default', className, children, ...props }, ref) {
6
- return (jsx("li", { role: "presentation", children: jsxs("button", { ...props, ref: ref, className: classNames(className, {
7
- 'dc-menu-btn': true,
5
+ const MenuItem = forwardRef(function MenuItem({ role = 'menuitem', appearance = 'default', iconLeft = null, iconRight = null, className, children, ...props }, ref) {
6
+ let label = children;
7
+ if (iconLeft || iconRight) {
8
+ const className = classNames('dc-menu-btn__label', {
9
+ 'dc-menu-btn__label_gap_left': iconLeft,
10
+ 'dc-menu-btn__label_gap_right': iconRight,
11
+ });
12
+ label = jsx("span", { className: className, children: label });
13
+ }
14
+ return (jsx("li", { role: "presentation", children: jsxs("button", { ...props, ref: ref, className: classNames(className, 'dc-menu-btn', {
8
15
  [`dc-menu-btn_${appearance}`]: appearance,
9
- }), type: "button", role: "menuitem", tabIndex: -1, children: [Boolean(icon) && jsx("span", { className: "dc-menu-btn__icon", children: icon }), jsx("span", { className: "dc-menu-btn__label", children: children })] }) }));
16
+ }), type: "button", role: role, tabIndex: -1, children: [iconLeft, label, iconRight] }) }));
10
17
  });
11
18
 
12
19
  export { MenuItem };
@@ -8,7 +8,7 @@ import '../button/icon-button.js';
8
8
  import { Popover } from '../popover/popover.js';
9
9
  import { MenuItem } from './menu-item.js';
10
10
 
11
- function Menu({ defaultIsOpen = false, placement = 'bottom', alignment = 'start', buttonAppearance = 'default', buttonVariant = 'filled', button, className, children, onOpen, onClose, onKeyDown, ...props }) {
11
+ function Menu({ defaultIsOpen = false, placement = 'bottom', alignment = 'start', buttonClassName = '', buttonAppearance = 'default', buttonVariant = 'filled', button, className, children, onOpen, onClose, onKeyDown, ...props }) {
12
12
  const id = useId();
13
13
  const menuId = props.id || id;
14
14
  const buttonId = `menu-button-${menuId}`;
@@ -81,12 +81,11 @@ function Menu({ defaultIsOpen = false, placement = 'bottom', alignment = 'start'
81
81
  const handleButtonClick = (event) => {
82
82
  if (isOpen) {
83
83
  closeMenu();
84
- focusMenuButton();
85
84
  }
86
85
  else {
87
86
  openMenu();
88
- window.setTimeout(focusFirstMenuItem);
89
87
  }
88
+ focusMenuButton();
90
89
  event.preventDefault();
91
90
  event.stopPropagation();
92
91
  };
@@ -157,7 +156,7 @@ function Menu({ defaultIsOpen = false, placement = 'bottom', alignment = 'start'
157
156
  closeMenu,
158
157
  });
159
158
  }
160
- return (jsx(Button, { ref: ref, id: buttonId, "aria-haspopup": true, "aria-expanded": isOpen, "aria-controls": menuId, onClick: handleButtonClick, onKeyDown: handleButtonKeyDown, appearance: buttonAppearance, variant: buttonVariant, children: button }));
159
+ return (jsx(Button, { "data-testid": "menu-button", ref: ref, id: buttonId, "aria-haspopup": true, "aria-expanded": isOpen, "aria-controls": menuId, onClick: handleButtonClick, onKeyDown: handleButtonKeyDown, className: buttonClassName, appearance: buttonAppearance, variant: buttonVariant, children: button }));
161
160
  };
162
161
  return (jsx(Popover, { className: "dc-menu__container", placement: placement, alignment: alignment, anchor: renderAnchor, isOpen: isOpen, onClose: closeMenu, children: jsx("ul", { ...props, className: classNames('dc-menu', className), role: "menu", id: menuId, "aria-labelledby": buttonId, onKeyDown: handleMenuKeyDown, children: Children.map(children, (child) => {
163
162
  if (isMenuItem(child)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "draft-components",
3
- "version": "1.0.0-beta.5",
3
+ "version": "1.0.0-beta.7",
4
4
  "description": "The React based UI components library.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -102,8 +102,8 @@
102
102
  "vite": "4.0.4"
103
103
  },
104
104
  "lint-staged": {
105
- "src/**/*.ts?(x)": "npm run lint",
106
- "src/**/*.css": "npm run stylelint"
105
+ "*.ts?(x)": "npm run lint",
106
+ "*.css": "npm run lint-styles"
107
107
  },
108
108
  "engines": {
109
109
  "node": ">= 14.16"
@@ -1,11 +1,14 @@
1
1
  import { type ComponentPropsWithRef, type ReactNode } from 'react';
2
2
  type MenuItemHTMLProps = ComponentPropsWithRef<'button'>;
3
- type MenuItemBaseProps = Omit<MenuItemHTMLProps, 'children'>;
3
+ type MenuItemBaseProps = Omit<MenuItemHTMLProps, 'children' | 'role'>;
4
4
  export type MenuItemAppearance = 'default' | 'destructive';
5
+ export type MenuItemRole = 'menuitem' | 'menuitemradio';
5
6
  export type MenuItemProps = {
7
+ role?: MenuItemRole;
6
8
  appearance?: MenuItemAppearance;
7
- icon?: ReactNode;
9
+ iconLeft?: ReactNode;
10
+ iconRight?: ReactNode;
8
11
  children: ReactNode;
9
12
  } & MenuItemBaseProps;
10
- export declare const MenuItem: import("react").ForwardRefExoticComponent<Pick<MenuItemProps, "hidden" | "form" | "slot" | "style" | "title" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "id" | "lang" | "nonce" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onResize" | "onResizeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "icon" | "appearance" | "value" | "type" | "name" | "autoFocus" | "disabled" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget"> & import("react").RefAttributes<HTMLButtonElement>>;
13
+ export declare const MenuItem: import("react").ForwardRefExoticComponent<Pick<MenuItemProps, "hidden" | "form" | "slot" | "style" | "title" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "id" | "lang" | "nonce" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onResize" | "onResizeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "appearance" | "value" | "type" | "name" | "autoFocus" | "disabled" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "iconLeft" | "iconRight"> & import("react").RefAttributes<HTMLButtonElement>>;
11
14
  export {};
@@ -1,7 +1,7 @@
1
1
  import { type ComponentPropsWithoutRef, type KeyboardEventHandler, type MouseEventHandler, type ReactNode, type RefCallback } from 'react';
2
2
  import { type ButtonAppearance, type ButtonVariant } from '../button';
3
3
  import { type PopoverAlignment, type PopoverPlacement } from '../popover';
4
- export type MenuAnchorRenderFn = (props: {
4
+ export type MenuButtonRenderFn = (props: {
5
5
  ref: RefCallback<HTMLElement>;
6
6
  id: string;
7
7
  'aria-haspopup': true;
@@ -23,9 +23,10 @@ export type MenuProps = {
23
23
  alignment?: MenuAlignment;
24
24
  onOpen?: () => void;
25
25
  onClose?: () => void;
26
- button: ReactNode | MenuAnchorRenderFn;
26
+ button: ReactNode | MenuButtonRenderFn;
27
+ buttonClassName?: string;
27
28
  buttonAppearance?: ButtonAppearance;
28
29
  buttonVariant?: ButtonVariant;
29
30
  } & MenuHTMLProps;
30
- export declare function Menu({ defaultIsOpen, placement, alignment, buttonAppearance, buttonVariant, button, className, children, onOpen, onClose, onKeyDown, ...props }: MenuProps): JSX.Element;
31
+ export declare function Menu({ defaultIsOpen, placement, alignment, buttonClassName, buttonAppearance, buttonVariant, button, className, children, onOpen, onClose, onKeyDown, ...props }: MenuProps): JSX.Element;
31
32
  export {};