draft-components 1.0.0-beta.8 → 1.0.0-beta.9

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.
@@ -5,23 +5,25 @@ const react = require('react');
5
5
  const reactHelpers = require('../../lib/react-helpers.cjs');
6
6
  const spinner = require('../spinner/spinner.cjs');
7
7
 
8
- const Button = react.forwardRef(function Button({ isBlock = false, disabled = false, loading = false, type = 'button', size = 'sm', variant = 'filled', appearance = 'default', icon = null, caption = null, renderAs, className, children, ...props }, ref) {
9
- const shouldRenderIcon = Boolean(icon);
10
- const shouldRenderLabel = Boolean(children);
11
- const shouldRenderCaption = Boolean(caption);
12
- let leadingAddOn = null;
8
+ const Button = react.forwardRef(function Button({ isBlock = false, disabled = false, loading = false, type = 'button', size = 'sm', variant = 'filled', appearance = 'default', iconLeft = null, iconRight = null, caption = null, renderAs, className, children, ...props }, ref) {
9
+ let addOnLeft = null;
13
10
  if (loading) {
14
- leadingAddOn = (jsxRuntime.jsx("span", { "data-testid": "button-spinner", className: "dc-button__spinner", children: jsxRuntime.jsx(spinner.Spinner, { size: "1.15em" }) }));
11
+ addOnLeft = (jsxRuntime.jsx("span", { "data-testid": "button-spinner", className: "dc-button__spinner", children: jsxRuntime.jsx(spinner.Spinner, { size: "1.15em" }) }));
12
+ }
13
+ else if (iconLeft) {
14
+ addOnLeft = (jsxRuntime.jsx("span", { "data-testid": "button-icon", className: "dc-button__icon", children: iconLeft }));
15
15
  }
16
- else if (shouldRenderIcon) {
17
- leadingAddOn = (jsxRuntime.jsx("span", { "data-testid": "button-icon", className: "dc-button__icon", children: icon }));
16
+ let addOnRight = null;
17
+ if (iconRight) {
18
+ addOnRight = (jsxRuntime.jsx("span", { "data-testid": "button-icon", className: "dc-button__icon", children: iconRight }));
18
19
  }
19
- const content = (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [leadingAddOn, shouldRenderLabel && (jsxRuntime.jsxs("span", { className: "dc-button__body", children: [jsxRuntime.jsx("span", { className: "dc-button__label", children: children }), shouldRenderCaption && (jsxRuntime.jsx("small", { className: "dc-button__caption", children: caption }))] }))] }));
20
+ const shouldRenderLabel = Boolean(children);
21
+ const shouldRenderCaption = Boolean(caption);
22
+ const content = (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [addOnLeft, shouldRenderLabel && (jsxRuntime.jsxs("span", { className: "dc-button__body", children: [jsxRuntime.jsx("span", { className: "dc-button__label", children: children }), shouldRenderCaption && (jsxRuntime.jsx("small", { className: "dc-button__caption", children: caption }))] })), addOnRight] }));
20
23
  className = reactHelpers.classNames(className, {
21
24
  'dc-button': true,
22
25
  'dc-button_block': isBlock,
23
26
  'dc-button_loading': loading,
24
- 'dc-button_has_icon': shouldRenderIcon,
25
27
  'dc-button_has_caption': shouldRenderCaption,
26
28
  [`dc-button_${size}`]: size,
27
29
  [`dc-button_appearance_${appearance}`]: appearance,
@@ -5,8 +5,8 @@ const react = require('react');
5
5
  const reactHelpers = require('../../lib/react-helpers.cjs');
6
6
  const button = require('./button.cjs');
7
7
 
8
- const IconButton = react.forwardRef(function IconButton({ className, ...props }, ref) {
9
- return jsxRuntime.jsx(button.Button, { ref: ref, className: reactHelpers.classNames('dc-button_icon-only', className), ...props });
8
+ const IconButton = react.forwardRef(function IconButton({ className, icon, ...props }, ref) {
9
+ return jsxRuntime.jsx(button.Button, { ...props, ref: ref, iconLeft: icon, className: reactHelpers.classNames('dc-button_icon-only', className) });
10
10
  });
11
11
 
12
12
  exports.IconButton = IconButton;
@@ -751,12 +751,20 @@
751
751
  justify-content: center;
752
752
  }
753
753
 
754
- .dc-button__icon,
755
- .dc-button__spinner {
754
+ .dc-button__spinner,
755
+ .dc-button__icon {
756
756
  flex: none;
757
+ }
758
+
759
+ .dc-button__spinner,
760
+ .dc-button__icon:first-child {
757
761
  margin-right: 0.5em;
758
762
  }
759
763
 
764
+ .dc-button__icon:last-child {
765
+ margin-left: 0.5em;
766
+ }
767
+
760
768
  .dc-button__body {
761
769
  flex: auto;
762
770
  flex-direction: column;
@@ -771,6 +779,7 @@
771
779
  .dc-button_icon-only .dc-button__icon,
772
780
  .dc-button_icon-only .dc-button__spinner {
773
781
  margin-right: 0;
782
+ margin-left: 0;
774
783
  }
775
784
 
776
785
  .dc-button_has_caption .dc-button__icon,
@@ -3,23 +3,25 @@ import { forwardRef } from 'react';
3
3
  import { classNames } from '../../lib/react-helpers.js';
4
4
  import { Spinner } from '../spinner/spinner.js';
5
5
 
6
- const Button = forwardRef(function Button({ isBlock = false, disabled = false, loading = false, type = 'button', size = 'sm', variant = 'filled', appearance = 'default', icon = null, caption = null, renderAs, className, children, ...props }, ref) {
7
- const shouldRenderIcon = Boolean(icon);
8
- const shouldRenderLabel = Boolean(children);
9
- const shouldRenderCaption = Boolean(caption);
10
- let leadingAddOn = null;
6
+ const Button = forwardRef(function Button({ isBlock = false, disabled = false, loading = false, type = 'button', size = 'sm', variant = 'filled', appearance = 'default', iconLeft = null, iconRight = null, caption = null, renderAs, className, children, ...props }, ref) {
7
+ let addOnLeft = null;
11
8
  if (loading) {
12
- leadingAddOn = (jsx("span", { "data-testid": "button-spinner", className: "dc-button__spinner", children: jsx(Spinner, { size: "1.15em" }) }));
9
+ addOnLeft = (jsx("span", { "data-testid": "button-spinner", className: "dc-button__spinner", children: jsx(Spinner, { size: "1.15em" }) }));
10
+ }
11
+ else if (iconLeft) {
12
+ addOnLeft = (jsx("span", { "data-testid": "button-icon", className: "dc-button__icon", children: iconLeft }));
13
13
  }
14
- else if (shouldRenderIcon) {
15
- leadingAddOn = (jsx("span", { "data-testid": "button-icon", className: "dc-button__icon", children: icon }));
14
+ let addOnRight = null;
15
+ if (iconRight) {
16
+ addOnRight = (jsx("span", { "data-testid": "button-icon", className: "dc-button__icon", children: iconRight }));
16
17
  }
17
- const content = (jsxs(Fragment, { children: [leadingAddOn, shouldRenderLabel && (jsxs("span", { className: "dc-button__body", children: [jsx("span", { className: "dc-button__label", children: children }), shouldRenderCaption && (jsx("small", { className: "dc-button__caption", children: caption }))] }))] }));
18
+ const shouldRenderLabel = Boolean(children);
19
+ const shouldRenderCaption = Boolean(caption);
20
+ const content = (jsxs(Fragment, { children: [addOnLeft, shouldRenderLabel && (jsxs("span", { className: "dc-button__body", children: [jsx("span", { className: "dc-button__label", children: children }), shouldRenderCaption && (jsx("small", { className: "dc-button__caption", children: caption }))] })), addOnRight] }));
18
21
  className = classNames(className, {
19
22
  'dc-button': true,
20
23
  'dc-button_block': isBlock,
21
24
  'dc-button_loading': loading,
22
- 'dc-button_has_icon': shouldRenderIcon,
23
25
  'dc-button_has_caption': shouldRenderCaption,
24
26
  [`dc-button_${size}`]: size,
25
27
  [`dc-button_appearance_${appearance}`]: appearance,
@@ -3,8 +3,8 @@ import { forwardRef } from 'react';
3
3
  import { classNames } from '../../lib/react-helpers.js';
4
4
  import { Button } from './button.js';
5
5
 
6
- const IconButton = forwardRef(function IconButton({ className, ...props }, ref) {
7
- return jsx(Button, { ref: ref, className: classNames('dc-button_icon-only', className), ...props });
6
+ const IconButton = forwardRef(function IconButton({ className, icon, ...props }, ref) {
7
+ return jsx(Button, { ...props, ref: ref, iconLeft: icon, className: classNames('dc-button_icon-only', className) });
8
8
  });
9
9
 
10
10
  export { IconButton };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "draft-components",
3
- "version": "1.0.0-beta.8",
3
+ "version": "1.0.0-beta.9",
4
4
  "description": "The React based UI components library.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -6,14 +6,15 @@ export type ButtonRenderFn = (props: {
6
6
  className: string;
7
7
  children: JSX.Element;
8
8
  }) => JSX.Element;
9
- export type ButtonProps = ComponentPropsWithRef<'button'> & {
9
+ export type ButtonProps = {
10
10
  isBlock?: boolean;
11
11
  loading?: boolean;
12
12
  size?: ButtonSize;
13
13
  variant?: ButtonVariant;
14
14
  appearance?: ButtonAppearance;
15
- icon?: ReactNode;
15
+ iconLeft?: ReactNode;
16
+ iconRight?: ReactNode;
16
17
  caption?: ReactNode;
17
18
  renderAs?: ButtonRenderFn;
18
- };
19
- export declare const Button: import("react").ForwardRefExoticComponent<Pick<ButtonProps, "caption" | "key" | "icon" | "variant" | "appearance" | "size" | "renderAs" | keyof import("react").ButtonHTMLAttributes<HTMLButtonElement> | "isBlock" | "loading"> & import("react").RefAttributes<HTMLButtonElement>>;
19
+ } & ComponentPropsWithRef<'button'>;
20
+ export declare const Button: import("react").ForwardRefExoticComponent<Pick<ButtonProps, "caption" | "key" | "variant" | "appearance" | "size" | "renderAs" | keyof import("react").ButtonHTMLAttributes<HTMLButtonElement> | "isBlock" | "loading" | "iconLeft" | "iconRight"> & import("react").RefAttributes<HTMLButtonElement>>;
@@ -1,6 +1,7 @@
1
1
  import { type ReactNode } from 'react';
2
2
  import { type ButtonProps } from './button';
3
- export type IconButtonProps = Omit<ButtonProps, 'children' | 'caption'> & {
3
+ export type IconButtonBaseProps = Omit<ButtonProps, 'children' | 'caption' | 'iconLeft' | 'iconRight'>;
4
+ export type IconButtonProps = {
4
5
  icon: ReactNode;
5
- };
6
+ } & IconButtonBaseProps;
6
7
  export declare const IconButton: import("react").ForwardRefExoticComponent<Pick<IconButtonProps, "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" | "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" | "variant" | "appearance" | "size" | "value" | "type" | "renderAs" | "name" | "autoFocus" | "disabled" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "isBlock" | "loading"> & import("react").RefAttributes<HTMLButtonElement>>;