@mirohq/design-system-base-button 0.4.10 → 0.4.11

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/dist/main.js CHANGED
@@ -2,14 +2,15 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var jsxRuntime = require('react/jsx-runtime');
5
6
  var React = require('react');
6
- var button = require('@react-aria/button');
7
- var interactions = require('@react-aria/interactions');
8
7
  var utils = require('@react-aria/utils');
9
- var link = require('@react-aria/link');
10
- var focus = require('@react-aria/focus');
8
+ var designSystemUtils = require('@mirohq/design-system-utils');
9
+ var interactions = require('@react-aria/interactions');
10
+ var designSystemUsePress = require('@mirohq/design-system-use-press');
11
11
  var designSystemPrimitive = require('@mirohq/design-system-primitive');
12
12
  var designSystemStitches = require('@mirohq/design-system-stitches');
13
+ var designSystemStyles = require('@mirohq/design-system-styles');
13
14
 
14
15
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
16
 
@@ -30,96 +31,64 @@ const StyledBaseButton = designSystemStitches.styled(designSystemPrimitive.Primi
30
31
  "&[disabled]": {
31
32
  pointerEvents: "none"
32
33
  },
33
- '&[aria-disabled="true"]': {
34
+ "&[aria-disabled]": {
34
35
  cursor: "default"
35
- }
36
+ },
37
+ ...designSystemStyles.focus.defaults
36
38
  });
37
39
 
38
- function eventHandler(callback, allowEvent) {
39
- if (allowEvent) {
40
- return callback;
41
- }
42
- return void 0;
43
- }
44
40
  const BaseButton = React__default["default"].forwardRef(
45
41
  ({
46
42
  disabled = false,
47
43
  "aria-disabled": ariaDisabled,
48
- href,
49
- target,
50
- rel,
51
44
  children,
52
- onClick,
53
45
  asChild,
46
+ role,
54
47
  onHoverStart,
55
48
  onHoverEnd,
56
49
  onHoverChange,
57
- onPress,
58
- onPressStart,
59
- onPressEnd,
60
- onPressChange,
61
- onFocus,
62
- onBlur,
63
- onFocusChange,
64
50
  ...restProps
65
51
  }, forwardRef) => {
66
- const asLink = href != null;
67
- const ref = React.useRef(null);
68
- const refWithFallback = forwardRef != null ? forwardRef : ref;
69
- const allowPressEvents = ariaDisabled !== "true" && ariaDisabled !== true;
70
- const commonProps = {
71
- isDisabled: disabled,
72
- onPress: eventHandler(onPress != null ? onPress : onClick, allowPressEvents),
73
- onPressStart: eventHandler(onPressStart, allowPressEvents),
74
- onPressEnd: eventHandler(onPressEnd, allowPressEvents),
75
- onPressChange: eventHandler(onPressChange, allowPressEvents),
76
- onFocusChange,
77
- onFocus,
78
- onBlur
79
- };
80
- const { buttonProps, isPressed } = button.useButton(
81
- {
82
- href,
83
- allowFocusWhenDisabled: false,
84
- ...commonProps,
85
- ...restProps
86
- },
87
- refWithFallback
88
- );
89
- const { linkProps } = link.useLink(
90
- { ...commonProps, ...restProps },
91
- refWithFallback
92
- );
93
- const tabIndexProp = disabled && {
94
- tabIndex: -1
95
- };
96
- const { isFocusVisible, focusProps: focusPropsRing } = focus.useFocusRing();
52
+ const asLink = "href" in restProps;
53
+ const { href, target, rel = "" } = restProps;
54
+ let elementProps = restProps;
55
+ if (designSystemUtils.booleanify(ariaDisabled)) {
56
+ elementProps = designSystemUtils.removeEventProps(elementProps, ["onBlur", "onFocus"]);
57
+ }
58
+ const { pressProps, isPressed } = designSystemUsePress.usePress({
59
+ preventFocusOnPress: true,
60
+ disabled: disabled || designSystemUtils.booleanify(ariaDisabled),
61
+ ...elementProps
62
+ });
97
63
  const { hoverProps, isHovered } = interactions.useHover({
98
- onHoverStart: (e) => onHoverStart == null ? void 0 : onHoverStart(e),
99
- onHoverEnd: (e) => onHoverEnd == null ? void 0 : onHoverEnd(e),
100
- onHoverChange: (e) => onHoverChange == null ? void 0 : onHoverChange(e)
64
+ onHoverStart,
65
+ onHoverEnd,
66
+ onHoverChange
101
67
  });
102
- const elementProps = utils.mergeProps(
103
- restProps,
104
- asLink ? linkProps : buttonProps,
105
- hoverProps,
106
- focusPropsRing
68
+ elementProps = utils.mergeProps(pressProps, hoverProps);
69
+ return /* @__PURE__ */ jsxRuntime.jsx(
70
+ StyledBaseButton,
71
+ {
72
+ ...elementProps,
73
+ "data-pressed": isPressed ? "" : void 0,
74
+ "data-hovered": isHovered ? "" : void 0,
75
+ asChild: asLink || asChild,
76
+ disabled,
77
+ role: role != null ? role : asChild === true ? "button" : void 0,
78
+ "aria-disabled": designSystemUtils.booleanify(ariaDisabled) ? "true" : void 0,
79
+ tabIndex: disabled && (asLink || asChild === true) ? -1 : void 0,
80
+ ref: forwardRef,
81
+ children: asLink ? /* @__PURE__ */ jsxRuntime.jsx(
82
+ "a",
83
+ {
84
+ href,
85
+ target,
86
+ rel: target === "_blank" ? "noopener noreferrer ".concat(rel).trim() : rel,
87
+ children
88
+ }
89
+ ) : children
90
+ }
107
91
  );
108
- return /* @__PURE__ */ React__default["default"].createElement(StyledBaseButton, {
109
- ...elementProps,
110
- disabled,
111
- asChild: asLink || asChild,
112
- ...tabIndexProp,
113
- "data-pressed": isPressed ? "" : void 0,
114
- "data-focused": isFocusVisible ? "" : void 0,
115
- "data-hovered": isHovered ? "" : void 0,
116
- "aria-disabled": ariaDisabled,
117
- ref: refWithFallback
118
- }, asLink ? /* @__PURE__ */ React__default["default"].createElement("a", {
119
- href,
120
- target,
121
- rel: target === "_blank" ? `noopener noreferrer ${rel}` : rel
122
- }, children) : children);
123
92
  }
124
93
  );
125
94
 
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"main.js","sources":["../src/base-button.styled.ts","../src/base-button.tsx"],"sourcesContent":["import type { ComponentPropsWithRef } from 'react'\nimport { Primitive } from '@mirohq/design-system-primitive'\nimport { styled } from '@mirohq/design-system-stitches'\n\nexport const sizes = {\n medium: '$8',\n large: '$10',\n xLarge: '$12',\n}\n\nexport const StyledBaseButton = styled(Primitive.button, {\n all: 'unset',\n display: 'inline-flex',\n alignItems: 'center',\n boxSizing: 'border-box',\n borderRadius: '$50',\n cursor: 'pointer',\n\n '&[disabled]': {\n pointerEvents: 'none',\n },\n\n '&[aria-disabled=\"true\"]': {\n cursor: 'default',\n },\n})\n\nexport type StyledBaseButtonProps = ComponentPropsWithRef<\n typeof StyledBaseButton\n>\n","import React, { useRef } from 'react'\nimport type { ElementRef, ReactNode } from 'react'\nimport { useButton } from '@react-aria/button'\nimport { useHover } from '@react-aria/interactions'\nimport { mergeProps } from '@react-aria/utils'\nimport { useLink } from '@react-aria/link'\nimport { useFocusRing } from '@react-aria/focus'\nimport type { HoverEvents, FocusEvents } from '@react-types/shared'\nimport type { AriaButtonProps } from '@react-types/button'\n\nimport { StyledBaseButton } from './base-button.styled'\nimport type { StyledBaseButtonProps } from './base-button.styled'\n\ntype ButtonPropsA11y = StyledBaseButtonProps & AriaButtonProps<'button'>\n\nexport interface BaseButtonProps\n extends FocusEvents,\n HoverEvents,\n Omit<\n ButtonPropsA11y,\n | 'onClick'\n | 'isDisabled'\n | 'elementType'\n | 'onBlur'\n | 'onFocus'\n | 'onPressUp'\n > {\n /**\n * The content\n */\n children: ReactNode\n\n /**\n * Prevent pointer events\n */\n disabled?: boolean\n\n /**\n * A URL to link when using the button as a link\n */\n href?: string\n\n /**\n * The target window using the button as a link\n */\n target?: string\n\n /**\n * The relationship between the linked resource and the current page. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel)\n */\n rel?: string\n\n /**\n * Alias for onPress\n */\n onClick?: AriaButtonProps['onPress']\n}\n\nfunction eventHandler<T>(\n callback: ((e: T) => void) | undefined,\n allowEvent: boolean\n): ((e: T) => void) | undefined {\n if (allowEvent) {\n return callback\n }\n\n return undefined\n}\n\nexport const BaseButton = React.forwardRef<\n ElementRef<typeof StyledBaseButton | 'a'>,\n BaseButtonProps\n>(\n (\n {\n disabled = false,\n 'aria-disabled': ariaDisabled,\n href,\n target,\n rel,\n children,\n onClick,\n asChild,\n onHoverStart,\n onHoverEnd,\n onHoverChange,\n onPress,\n onPressStart,\n onPressEnd,\n onPressChange,\n onFocus,\n onBlur,\n onFocusChange,\n ...restProps\n },\n forwardRef\n ) => {\n const asLink = href != null\n\n const ref = useRef<HTMLButtonElement | HTMLAnchorElement>(null)\n const refWithFallback = forwardRef ?? ref\n\n // we cannot rely on useButton with ariaDisabled, because it doesn't support onFocus when isDisabled\n const allowPressEvents = ariaDisabled !== 'true' && ariaDisabled !== true\n\n const commonProps = {\n isDisabled: disabled,\n onPress: eventHandler(onPress ?? onClick, allowPressEvents),\n onPressStart: eventHandler(onPressStart, allowPressEvents),\n onPressEnd: eventHandler(onPressEnd, allowPressEvents),\n onPressChange: eventHandler(onPressChange, allowPressEvents),\n onFocusChange,\n onFocus,\n onBlur,\n }\n\n const { buttonProps, isPressed } = useButton(\n {\n href,\n // @ts-expect-error\n allowFocusWhenDisabled: false,\n ...commonProps,\n ...restProps,\n },\n refWithFallback\n )\n\n const { linkProps } = useLink(\n { ...commonProps, ...restProps },\n // @ts-expect-error\n refWithFallback\n )\n const tabIndexProp = disabled && {\n tabIndex: -1,\n }\n\n const { isFocusVisible, focusProps: focusPropsRing } = useFocusRing()\n\n const { hoverProps, isHovered } = useHover({\n onHoverStart: e => onHoverStart?.(e),\n onHoverEnd: e => onHoverEnd?.(e),\n onHoverChange: e => onHoverChange?.(e),\n })\n\n const elementProps = mergeProps(\n restProps,\n asLink ? linkProps : buttonProps,\n hoverProps,\n focusPropsRing\n )\n\n return (\n <StyledBaseButton\n {...elementProps}\n disabled={disabled}\n asChild={asLink || asChild}\n {...tabIndexProp}\n data-pressed={isPressed ? '' : undefined}\n data-focused={isFocusVisible ? '' : undefined}\n data-hovered={isHovered ? '' : undefined}\n aria-disabled={ariaDisabled}\n // @ts-expect-error\n ref={refWithFallback}\n >\n {asLink ? (\n <a\n href={href}\n target={target}\n rel={target === '_blank' ? `noopener noreferrer ${rel}` : rel}\n >\n {children}\n </a>\n ) : (\n children\n )}\n </StyledBaseButton>\n )\n }\n)\n"],"names":["styled","Primitive","React","useRef","useButton","useLink","useFocusRing","useHover","mergePro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AA,GAAA,KAAA,CAAA,GAAA,YAAA,CAAA,CAAA,CAAA;AAAA,MAClC,UAAA,EAAY,OAAK,UAAa,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,UAAA,CAAA,CAAA,CAAA;AAAA,MAC9B,aAAA,EAAe,OAAK,aAAgB,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,aAAA,CAAA,CAAA,CAAA;AAAA,KACrC,CAAA,CAAA;AAED,IAAA,MAAM,YAAe,GAAAC,gBAAA;AAAA,MACnB,SAAA;AAAA,MACA,SAAS,SAAY,GAAA,WAAA;AAAA,MACrB,UAAA;AAAA,MACA,cAAA;AAAA,KACF,CAAA;AAEA,IAAA,uBACGN,yBAAA,CAAA,aAAA,CAAA,gBAAA,EAAA;AAAA,MACE,GAAG,YAAA;AAAA,MACJ,QAAA;AAAA,MACA,SAAS,MAAU,IAAA,OAAA;AAAA,MAClB,GAAG,YAAA;AAAA,MACJ,cAAA,EAAc,YAAY,EAAK,GAAA,KAAA,CAAA;AAAA,MAC/B,cAAA,EAAc,iBAAiB,EAAK,GAAA,KAAA,CAAA;AAAA,MACpC,cAAA,EAAc,YAAY,EAAK,GAAA,KAAA,CAAA;AAAA,MAC/B,eAAe,EAAA,YAAA;AAAA,MAEf,GAAK,EAAA,eAAA;AAAA,KAAA,EAEJ,yBACEA,yBAAA,CAAA,aAAA,CAAA,GAAA,EAAA;AAAA,MACC,IAAA;AAAA,MACA,MAAA;AAAA,MACA,GAAK,EAAA,MAAA,KAAW,QAAW,GAAA,CAAA,oBAAA,EAAuB,GAAQ,CAAA,CAAA,GAAA,GAAA;AAAA,KAEzD,EAAA,QACH,IAEA,QAEJ,CAAA,CAAA;AAAA,GAEJ;AACF;;;;;"}
1
+ {"version":3,"file":"main.js","sources":["../src/base-button.styled.ts","../src/base-button.tsx"],"sourcesContent":["import type { ComponentPropsWithRef } from 'react'\nimport { Primitive } from '@mirohq/design-system-primitive'\nimport { styled } from '@mirohq/design-system-stitches'\nimport { focus } from '@mirohq/design-system-styles'\n\nexport const sizes = {\n medium: '$8',\n large: '$10',\n xLarge: '$12',\n}\n\nexport const StyledBaseButton = styled(Primitive.button, {\n all: 'unset',\n display: 'inline-flex',\n alignItems: 'center',\n boxSizing: 'border-box',\n borderRadius: '$50',\n cursor: 'pointer',\n\n '&[disabled]': {\n pointerEvents: 'none',\n },\n\n '&[aria-disabled]': {\n cursor: 'default',\n },\n\n ...focus.defaults,\n})\n\nexport type StyledBaseButtonProps = ComponentPropsWithRef<\n typeof StyledBaseButton\n>\n","import React from 'react'\nimport type { ElementRef, AnchorHTMLAttributes } from 'react'\nimport { mergeProps } from '@react-aria/utils'\nimport { booleanify, removeEventProps } from '@mirohq/design-system-utils'\nimport { useHover } from '@react-aria/interactions'\nimport type { HoverEvents } from '@react-types/shared'\nimport { usePress } from '@mirohq/design-system-use-press'\nimport type { PressProps } from '@mirohq/design-system-use-press'\n\nimport { StyledBaseButton } from './base-button.styled'\nimport type { StyledBaseButtonProps } from './base-button.styled'\n\n// DO NOT export it in the index\n// Fix TS2742, option 3.1 in the comment bellow\n// https://github.com/microsoft/TypeScript/issues/47663#issuecomment-1519138189\nexport type { HoverEvents } from '@react-types/shared'\n\ntype AsButtonProps = StyledBaseButtonProps & PressProps & HoverEvents\ntype AsLinkProps = AsButtonProps & AnchorHTMLAttributes<'a'> & { href: string }\n\nexport type BaseButtonProps = AsButtonProps | AsLinkProps\n\nexport const BaseButton = React.forwardRef<\n ElementRef<'button' | 'a'>,\n BaseButtonProps\n>(\n (\n {\n disabled = false,\n 'aria-disabled': ariaDisabled,\n children,\n asChild,\n role,\n onHoverStart,\n onHoverEnd,\n onHoverChange,\n ...restProps\n },\n forwardRef\n ) => {\n const asLink = 'href' in restProps\n const { href, target, rel = '' } = restProps as AsLinkProps\n\n let elementProps = restProps\n\n if (booleanify(ariaDisabled)) {\n elementProps = removeEventProps(elementProps, ['onBlur', 'onFocus'])\n }\n\n const { pressProps, isPressed } = usePress({\n preventFocusOnPress: true,\n disabled: disabled || booleanify(ariaDisabled),\n ...elementProps,\n })\n\n const { hoverProps, isHovered } = useHover({\n onHoverStart,\n onHoverEnd,\n onHoverChange,\n })\n\n elementProps = mergeProps(pressProps, hoverProps)\n\n return (\n <StyledBaseButton\n {...elementProps}\n data-pressed={isPressed ? '' : undefined}\n data-hovered={isHovered ? '' : undefined}\n asChild={asLink || asChild}\n disabled={disabled}\n role={role ?? (asChild === true ? 'button' : undefined)}\n aria-disabled={booleanify(ariaDisabled) ? 'true' : undefined}\n tabIndex={disabled && (asLink || asChild === true) ? -1 : undefined}\n // Button can be an <a> but TS will never know because it will only happen in runtime via asChild\n // @ts-expect-error\n ref={forwardRef}\n >\n {asLink ? (\n <a\n href={href}\n target={target}\n rel={\n target === '_blank' ? `noopener noreferrer ${rel}`.trim() : rel\n }\n >\n {children}\n </a>\n ) : (\n children\n )}\n </StyledBaseButton>\n )\n }\n)\n"],"names":["styled","Primitive","focus","React","booleanify","removeEventProps","usePress","useHover","mergeProps","jsx"],"mappings":";;;;;;;;;;;;;;;;;;AAKO,MAAM,KAAQ,GAAA;AAAA,EACnB,MAAQ,EAAA,IAAA;AAAA,EACR,KAAO,EAAA,KAAA;AAAA,EACP,MAAQ,EAAA,KAAA;AACV,EAAA;AAEa,MAAA,gBAAA,GAAmBA,2BAAO,CAAAC,+BAAA,CAAU,MAAQ,EAAA;AAAA,EACvD,GAAK,EAAA,OAAA;AAAA,EACL,OAAS,EAAA,aAAA;AAAA,EACT,UAAY,EAAA,QAAA;AAAA,EACZ,SAAW,EAAA,YAAA;AAAA,EACX,YAAc,EAAA,KAAA;AAAA,EACd,MAAQ,EAAA,SAAA;AAAA,EAER,aAAe,EAAA;AAAA,IACb,aAAe,EAAA,MAAA;AAAA,GACjB;AAAA,EAEA,kBAAoB,EAAA;AAAA,IAClB,MAAQ,EAAA,SAAA;AAAA,GACV;AAAA,EAEA,GAAGC,wBAAM,CAAA,QAAA;AACX,CAAC,CAAA;;ACNM,MAAM,aAAaC,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B,QAAA;AAAA,QACA,IAAM,EAAA,IAAA,IAAA,IAAA,GAAA,IAAA,GAAS,OAAY,KAAA,IAAA,GAAO,QAAW,GAAA,KAAA,CAAA;AAAA,QAC7C,eAAe,EAAAL,4BAAA,CAAW,YAAY,CAAA,GAAI,MAAS,GAAA,KAAA,CAAA;AAAA,QACnD,QAAU,EAAA,QAAA,KAAa,MAAU,IAAA,OAAA,KAAY,QAAQ,CAAK,CAAA,GAAA,KAAA,CAAA;AAAA,QAG1D,GAAK,EAAA,UAAA;AAAA,QAEJ,QACC,EAAA,MAAA,mBAAAK,cAAA;AAAA,UAAC,GAAA;AAAA,UAAA;AAAA,YACC,IAAA;AAAA,YACA,MAAA;AAAA,YACA,KACE,MAAW,KAAA,QAAA,GAAW,sBAAuB,CAAA,MAAA,CAAA,GAAA,CAAA,CAAM,MAAS,GAAA,GAAA;AAAA,YAG7D,QAAA;AAAA,WAAA;AAAA,SAGH,GAAA,QAAA;AAAA,OAAA;AAAA,KAEJ,CAAA;AAAA,GAEJ;AACF;;;;;"}
package/dist/module.js CHANGED
@@ -1,11 +1,12 @@
1
- import React, { useRef } from 'react';
2
- import { useButton } from '@react-aria/button';
3
- import { useHover } from '@react-aria/interactions';
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import React from 'react';
4
3
  import { mergeProps } from '@react-aria/utils';
5
- import { useLink } from '@react-aria/link';
6
- import { useFocusRing } from '@react-aria/focus';
4
+ import { booleanify, removeEventProps } from '@mirohq/design-system-utils';
5
+ import { useHover } from '@react-aria/interactions';
6
+ import { usePress } from '@mirohq/design-system-use-press';
7
7
  import { Primitive } from '@mirohq/design-system-primitive';
8
8
  import { styled } from '@mirohq/design-system-stitches';
9
+ import { focus } from '@mirohq/design-system-styles';
9
10
 
10
11
  const sizes = {
11
12
  medium: "$8",
@@ -22,96 +23,64 @@ const StyledBaseButton = styled(Primitive.button, {
22
23
  "&[disabled]": {
23
24
  pointerEvents: "none"
24
25
  },
25
- '&[aria-disabled="true"]': {
26
+ "&[aria-disabled]": {
26
27
  cursor: "default"
27
- }
28
+ },
29
+ ...focus.defaults
28
30
  });
29
31
 
30
- function eventHandler(callback, allowEvent) {
31
- if (allowEvent) {
32
- return callback;
33
- }
34
- return void 0;
35
- }
36
32
  const BaseButton = React.forwardRef(
37
33
  ({
38
34
  disabled = false,
39
35
  "aria-disabled": ariaDisabled,
40
- href,
41
- target,
42
- rel,
43
36
  children,
44
- onClick,
45
37
  asChild,
38
+ role,
46
39
  onHoverStart,
47
40
  onHoverEnd,
48
41
  onHoverChange,
49
- onPress,
50
- onPressStart,
51
- onPressEnd,
52
- onPressChange,
53
- onFocus,
54
- onBlur,
55
- onFocusChange,
56
42
  ...restProps
57
43
  }, forwardRef) => {
58
- const asLink = href != null;
59
- const ref = useRef(null);
60
- const refWithFallback = forwardRef != null ? forwardRef : ref;
61
- const allowPressEvents = ariaDisabled !== "true" && ariaDisabled !== true;
62
- const commonProps = {
63
- isDisabled: disabled,
64
- onPress: eventHandler(onPress != null ? onPress : onClick, allowPressEvents),
65
- onPressStart: eventHandler(onPressStart, allowPressEvents),
66
- onPressEnd: eventHandler(onPressEnd, allowPressEvents),
67
- onPressChange: eventHandler(onPressChange, allowPressEvents),
68
- onFocusChange,
69
- onFocus,
70
- onBlur
71
- };
72
- const { buttonProps, isPressed } = useButton(
73
- {
74
- href,
75
- allowFocusWhenDisabled: false,
76
- ...commonProps,
77
- ...restProps
78
- },
79
- refWithFallback
80
- );
81
- const { linkProps } = useLink(
82
- { ...commonProps, ...restProps },
83
- refWithFallback
84
- );
85
- const tabIndexProp = disabled && {
86
- tabIndex: -1
87
- };
88
- const { isFocusVisible, focusProps: focusPropsRing } = useFocusRing();
44
+ const asLink = "href" in restProps;
45
+ const { href, target, rel = "" } = restProps;
46
+ let elementProps = restProps;
47
+ if (booleanify(ariaDisabled)) {
48
+ elementProps = removeEventProps(elementProps, ["onBlur", "onFocus"]);
49
+ }
50
+ const { pressProps, isPressed } = usePress({
51
+ preventFocusOnPress: true,
52
+ disabled: disabled || booleanify(ariaDisabled),
53
+ ...elementProps
54
+ });
89
55
  const { hoverProps, isHovered } = useHover({
90
- onHoverStart: (e) => onHoverStart == null ? void 0 : onHoverStart(e),
91
- onHoverEnd: (e) => onHoverEnd == null ? void 0 : onHoverEnd(e),
92
- onHoverChange: (e) => onHoverChange == null ? void 0 : onHoverChange(e)
56
+ onHoverStart,
57
+ onHoverEnd,
58
+ onHoverChange
93
59
  });
94
- const elementProps = mergeProps(
95
- restProps,
96
- asLink ? linkProps : buttonProps,
97
- hoverProps,
98
- focusPropsRing
60
+ elementProps = mergeProps(pressProps, hoverProps);
61
+ return /* @__PURE__ */ jsx(
62
+ StyledBaseButton,
63
+ {
64
+ ...elementProps,
65
+ "data-pressed": isPressed ? "" : void 0,
66
+ "data-hovered": isHovered ? "" : void 0,
67
+ asChild: asLink || asChild,
68
+ disabled,
69
+ role: role != null ? role : asChild === true ? "button" : void 0,
70
+ "aria-disabled": booleanify(ariaDisabled) ? "true" : void 0,
71
+ tabIndex: disabled && (asLink || asChild === true) ? -1 : void 0,
72
+ ref: forwardRef,
73
+ children: asLink ? /* @__PURE__ */ jsx(
74
+ "a",
75
+ {
76
+ href,
77
+ target,
78
+ rel: target === "_blank" ? "noopener noreferrer ".concat(rel).trim() : rel,
79
+ children
80
+ }
81
+ ) : children
82
+ }
99
83
  );
100
- return /* @__PURE__ */ React.createElement(StyledBaseButton, {
101
- ...elementProps,
102
- disabled,
103
- asChild: asLink || asChild,
104
- ...tabIndexProp,
105
- "data-pressed": isPressed ? "" : void 0,
106
- "data-focused": isFocusVisible ? "" : void 0,
107
- "data-hovered": isHovered ? "" : void 0,
108
- "aria-disabled": ariaDisabled,
109
- ref: refWithFallback
110
- }, asLink ? /* @__PURE__ */ React.createElement("a", {
111
- href,
112
- target,
113
- rel: target === "_blank" ? `noopener noreferrer ${rel}` : rel
114
- }, children) : children);
115
84
  }
116
85
  );
117
86
 
@@ -1 +1 @@
1
- {"version":3,"file":"module.js","sources":["../src/base-button.styled.ts","../src/base-button.tsx"],"sourcesContent":["import type { ComponentPropsWithRef } from 'react'\nimport { Primitive } from '@mirohq/design-system-primitive'\nimport { styled } from '@mirohq/design-system-stitches'\n\nexport const sizes = {\n medium: '$8',\n large: '$10',\n xLarge: '$12',\n}\n\nexport const StyledBaseButton = styled(Primitive.button, {\n all: 'unset',\n display: 'inline-flex',\n alignItems: 'center',\n boxSizing: 'border-box',\n borderRadius: '$50',\n cursor: 'pointer',\n\n '&[disabled]': {\n pointerEvents: 'none',\n },\n\n '&[aria-disabled=\"true\"]': {\n cursor: 'default',\n },\n})\n\nexport type StyledBaseButtonProps = ComponentPropsWithRef<\n typeof StyledBaseButton\n>\n","import React, { useRef } from 'react'\nimport type { ElementRef, ReactNode } from 'react'\nimport { useButton } from '@react-aria/button'\nimport { useHover } from '@react-aria/interactions'\nimport { mergeProps } from '@react-aria/utils'\nimport { useLink } from '@react-aria/link'\nimport { useFocusRing } from '@react-aria/focus'\nimport type { HoverEvents, FocusEvents } from '@react-types/shared'\nimport type { AriaButtonProps } from '@react-types/button'\n\nimport { StyledBaseButton } from './base-button.styled'\nimport type { StyledBaseButtonProps } from './base-button.styled'\n\ntype ButtonPropsA11y = StyledBaseButtonProps & AriaButtonProps<'button'>\n\nexport interface BaseButtonProps\n extends FocusEvents,\n HoverEvents,\n Omit<\n ButtonPropsA11y,\n | 'onClick'\n | 'isDisabled'\n | 'elementType'\n | 'onBlur'\n | 'onFocus'\n | 'onPressUp'\n > {\n /**\n * The content\n */\n children: ReactNode\n\n /**\n * Prevent pointer events\n */\n disabled?: boolean\n\n /**\n * A URL to link when using the button as a link\n */\n href?: string\n\n /**\n * The target window using the button as a link\n */\n target?: string\n\n /**\n * The relationship between the linked resource and the current page. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel)\n */\n rel?: string\n\n /**\n * Alias for onPress\n */\n onClick?: AriaButtonProps['onPress']\n}\n\nfunction eventHandler<T>(\n callback: ((e: T) => void) | undefined,\n allowEvent: boolean\n): ((e: T) => void) | undefined {\n if (allowEvent) {\n return callback\n }\n\n return undefined\n}\n\nexport const BaseButton = React.forwardRef<\n ElementRef<typeof StyledBaseButton | 'a'>,\n BaseButtonProps\n>(\n (\n {\n disabled = false,\n 'aria-disabled': ariaDisabled,\n href,\n target,\n rel,\n children,\n onClick,\n asChild,\n onHoverStart,\n onHoverEnd,\n onHoverChange,\n onPress,\n onPressStart,\n onPressEnd,\n onPressChange,\n onFocus,\n onBlur,\n onFocusChange,\n ...restProps\n },\n forwardRef\n ) => {\n const asLink = href != null\n\n const ref = useRef<HTMLButtonElement | HTMLAnchorElement>(null)\n const refWithFallback = forwardRef ?? ref\n\n // we cannot rely on useButton with ariaDisabled, because it doesn't support onFocus when isDisabled\n const allowPressEvents = ariaDisabled !== 'true' && ariaDisabled !== true\n\n const commonProps = {\n isDisabled: disabled,\n onPress: eventHandler(onPress ?? onClick, allowPressEvents),\n onPressStart: eventHandler(onPressStart, allowPressEvents),\n onPressEnd: eventHandler(onPressEnd, allowPressEvents),\n onPressChange: eventHandler(onPressChange, allowPressEvents),\n onFocusChange,\n onFocus,\n onBlur,\n }\n\n const { buttonProps, isPressed } = useButton(\n {\n href,\n // @ts-expect-error\n allowFocusWhenDisabled: false,\n ...commonProps,\n ...restProps,\n },\n refWithFallback\n )\n\n const { linkProps } = useLink(\n { ...commonProps, ...restProps },\n // @ts-expect-error\n refWithFallback\n )\n const tabIndexProp = disabled && {\n tabIndex: -1,\n }\n\n const { isFocusVisible, focusProps: focusPropsRing } = useFocusRing()\n\n const { hoverProps, isHovered } = useHover({\n onHoverStart: e => onHoverStart?.(e),\n onHoverEnd: e => onHoverEnd?.(e),\n onHoverChange: e => onHoverChange?.(e),\n })\n\n const elementProps = mergeProps(\n restProps,\n asLink ? linkProps : buttonProps,\n hoverProps,\n focusPropsRing\n )\n\n return (\n <StyledBaseButton\n {...elementProps}\n disabled={disabled}\n asChild={asLink || asChild}\n {...tabIndexProp}\n data-pressed={isPressed ? '' : undefined}\n data-focused={isFocusVisible ? '' : undefined}\n data-hovered={isHovered ? '' : undefined}\n aria-disabled={ariaDisabled}\n // @ts-expect-error\n ref={refWithFallback}\n >\n {asLink ? (\n <a\n href={href}\n target={target}\n rel={target === '_blank' ? `noopener noreferrer ${rel}` : rel}\n >\n {children}\n </a>\n ) : (\n children\n )}\n </StyledBaseButton>\n )\n }\n)\n"],"names":[],"mappings":";;;;;;;;;AAIO,MAAM,KAAQ,GAAA;AAAA,EACnB,MAAQ,EAAA,IAAA;AAAA,EACR,KAAO,EAAA,KAAA;AAAA,EACP,MAAQ,EAAA,KAAA;AACV,EAAA;AAEa,MAAA,gBAAA,GAAmB,MAAO,CAAA,SAAA,CAAU,MAAQ,EAAA;AAAA,EACvD,GAAK,EAAA,OAAA;AAAA,EACL,OAAS,EAAA,aAAA;AAAA,EACT,UAAY,EAAA,QAAA;AAAA,EACZ,SAAW,EAAA,YAAA;AAAA,EACX,YAAc,EAAA,KAAA;AAAA,EACd,MAAQ,EAAA,SAAA;AAAA,EAER,aAAe,EAAA;AAAA,IACb,aAAe,EAAA,MAAA;AAAA,GACjB;AAAA,EAEA,yBAA2B,EAAA;AAAA,IACzB,MAAQ,EAAA,SAAA;AAAA,GACV;AACF,CAAC,CAAA;;ACiCD,SAAS,YAAA,CACP,UACA,UAC8B,EAAA;AAC9B,EAAA,IAAI,UAAY,EAAA;AACd,IAAO,OAAA,QAAA,CAAA;AAAA,GACT;AAEA,EAAO,OAAA,KAAA,CAAA,CAAA;AACT,CAAA;AAEO,MAAM,aAAa,KAAM,CAAA,UAAA;AAAA,EAI9B,CACE;AAAA,IACE,QAAW,GAAA,KAAA;AAAA,IACX,eAAiB,EAAA,YAAA;AAAA,IACjB,IAAA;AAAA,IACA,MAAA;AAAA,IACA,GAAA;AAAA,IACA,QAAA;AAAA,IACA,OAAA;AAAA,IACA,OAAA;AAAA,IACA,YAAA;AAAA,IACA,UAAA;AAAA,IACA,aAAA;AAA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AEzD,EAAA,QACH,IAEA,QAEJ,CAAA,CAAA;AAAA,GAEJ;AACF;;;;"}
1
+ {"version":3,"file":"module.js","sources":["../src/base-button.styled.ts","../src/base-button.tsx"],"sourcesContent":["import type { ComponentPropsWithRef } from 'react'\nimport { Primitive } from '@mirohq/design-system-primitive'\nimport { styled } from '@mirohq/design-system-stitches'\nimport { focus } from '@mirohq/design-system-styles'\n\nexport const sizes = {\n medium: '$8',\n large: '$10',\n xLarge: '$12',\n}\n\nexport const StyledBaseButton = styled(Primitive.button, {\n all: 'unset',\n display: 'inline-flex',\n alignItems: 'center',\n boxSizing: 'border-box',\n borderRadius: '$50',\n cursor: 'pointer',\n\n '&[disabled]': {\n pointerEvents: 'none',\n },\n\n '&[aria-disabled]': {\n cursor: 'default',\n },\n\n ...focus.defaults,\n})\n\nexport type StyledBaseButtonProps = ComponentPropsWithRef<\n typeof StyledBaseButton\n>\n","import React from 'react'\nimport type { ElementRef, AnchorHTMLAttributes } from 'react'\nimport { mergeProps } from '@react-aria/utils'\nimport { booleanify, removeEventProps } from '@mirohq/design-system-utils'\nimport { useHover } from '@react-aria/interactions'\nimport type { HoverEvents } from '@react-types/shared'\nimport { usePress } from '@mirohq/design-system-use-press'\nimport type { PressProps } from '@mirohq/design-system-use-press'\n\nimport { StyledBaseButton } from './base-button.styled'\nimport type { StyledBaseButtonProps } from './base-button.styled'\n\n// DO NOT export it in the index\n// Fix TS2742, option 3.1 in the comment bellow\n// https://github.com/microsoft/TypeScript/issues/47663#issuecomment-1519138189\nexport type { HoverEvents } from '@react-types/shared'\n\ntype AsButtonProps = StyledBaseButtonProps & PressProps & HoverEvents\ntype AsLinkProps = AsButtonProps & AnchorHTMLAttributes<'a'> & { href: string }\n\nexport type BaseButtonProps = AsButtonProps | AsLinkProps\n\nexport const BaseButton = React.forwardRef<\n ElementRef<'button' | 'a'>,\n BaseButtonProps\n>(\n (\n {\n disabled = false,\n 'aria-disabled': ariaDisabled,\n children,\n asChild,\n role,\n onHoverStart,\n onHoverEnd,\n onHoverChange,\n ...restProps\n },\n forwardRef\n ) => {\n const asLink = 'href' in restProps\n const { href, target, rel = '' } = restProps as AsLinkProps\n\n let elementProps = restProps\n\n if (booleanify(ariaDisabled)) {\n elementProps = removeEventProps(elementProps, ['onBlur', 'onFocus'])\n }\n\n const { pressProps, isPressed } = usePress({\n preventFocusOnPress: true,\n disabled: disabled || booleanify(ariaDisabled),\n ...elementProps,\n })\n\n const { hoverProps, isHovered } = useHover({\n onHoverStart,\n onHoverEnd,\n onHoverChange,\n })\n\n elementProps = mergeProps(pressProps, hoverProps)\n\n return (\n <StyledBaseButton\n {...elementProps}\n data-pressed={isPressed ? '' : undefined}\n data-hovered={isHovered ? '' : undefined}\n asChild={asLink || asChild}\n disabled={disabled}\n role={role ?? (asChild === true ? 'button' : undefined)}\n aria-disabled={booleanify(ariaDisabled) ? 'true' : undefined}\n tabIndex={disabled && (asLink || asChild === true) ? -1 : undefined}\n // Button can be an <a> but TS will never know because it will only happen in runtime via asChild\n // @ts-expect-error\n ref={forwardRef}\n >\n {asLink ? (\n <a\n href={href}\n target={target}\n rel={\n target === '_blank' ? `noopener noreferrer ${rel}`.trim() : rel\n }\n >\n {children}\n </a>\n ) : (\n children\n )}\n </StyledBaseButton>\n )\n }\n)\n"],"names":[],"mappings":";;;;;;;;;;AAKO,MAAM,KAAQ,GAAA;AAAA,EACnB,MAAQ,EAAA,IAAA;AAAA,EACR,KAAO,EAAA,KAAA;AAAA,EACP,MAAQ,EAAA,KAAA;AACV,EAAA;AAEa,MAAA,gBAAA,GAAmB,MAAO,CAAA,SAAA,CAAU,MAAQ,EAAA;AAAA,EACvD,GAAK,EAAA,OAAA;AAAA,EACL,OAAS,EAAA,aAAA;AAAA,EACT,UAAY,EAAA,QAAA;AAAA,EACZ,SAAW,EAAA,YAAA;AAAA,EACX,YAAc,EAAA,KAAA;AAAA,EACd,MAAQ,EAAA,SAAA;AAAA,EAER,aAAe,EAAA;AAAA,IACb,aAAe,EAAA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cAAA,EAAc,YAAY,EAAK,GAAA,KAAA,CAAA;AAAA,QAC/B,cAAA,EAAc,YAAY,EAAK,GAAA,KAAA,CAAA;AAAA,QAC/B,SAAS,MAAU,IAAA,OAAA;AAAA,QACnB,QAAA;AAAA,QACA,IAAM,EAAA,IAAA,IAAA,IAAA,GAAA,IAAA,GAAS,OAAY,KAAA,IAAA,GAAO,QAAW,GAAA,KAAA,CAAA;AAAA,QAC7C,eAAe,EAAA,UAAA,CAAW,YAAY,CAAA,GAAI,MAAS,GAAA,KAAA,CAAA;AAAA,QACnD,QAAU,EAAA,QAAA,KAAa,MAAU,IAAA,OAAA,KAAY,QAAQ,CAAK,CAAA,GAAA,KAAA,CAAA;AAAA,QAG1D,GAAK,EAAA,UAAA;AAAA,QAEJ,QACC,EAAA,MAAA,mBAAA,GAAA;AAAA,UAAC,GAAA;AAAA,UAAA;AAAA,YACC,IAAA;AAAA,YACA,MAAA;AAAA,YACA,KACE,MAAW,KAAA,QAAA,GAAW,sBAAuB,CAAA,MAAA,CAAA,GAAA,CAAA,CAAM,MAAS,GAAA,GAAA;AAAA,YAG7D,QAAA;AAAA,WAAA;AAAA,SAGH,GAAA,QAAA;AAAA,OAAA;AAAA,KAEJ,CAAA;AAAA,GAEJ;AACF;;;;"}
package/dist/types.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
- import react__default, { ComponentPropsWithRef, ReactNode } from 'react';
3
- import { FocusEvents, HoverEvents } from '@react-types/shared';
4
- import { AriaButtonProps } from '@react-types/button';
2
+ import react__default, { ComponentPropsWithRef, AnchorHTMLAttributes } from 'react';
3
+ import { HoverEvents } from '@react-types/shared';
4
+ import { PressProps } from '@mirohq/design-system-use-press';
5
5
  import * as _mirohq_design_system_primitive from '@mirohq/design-system-primitive';
6
6
  import * as _mirohq_design_system_stitches from '@mirohq/design-system-stitches';
7
7
  import * as _stitches_react_types_css_util from '@stitches/react/types/css-util';
@@ -12,7 +12,7 @@ declare const sizes: {
12
12
  large: string;
13
13
  xLarge: string;
14
14
  };
15
- declare const StyledBaseButton: react.ForwardRefExoticComponent<Pick<Omit<{}, never> & _stitches_react_types_styled_component.TransformProps<{}, {}> & _mirohq_design_system_stitches.SafeProps<Omit<Pick<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "key" | keyof react.ButtonHTMLAttributes<HTMLButtonElement>> & {
15
+ declare const StyledBaseButton: react.ForwardRefExoticComponent<Omit<Omit<{}, never> & _stitches_react_types_styled_component.TransformProps<{}, {}> & _mirohq_design_system_stitches.SafeProps<Omit<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
16
16
  ref?: ((instance: HTMLButtonElement | null) => void) | react.RefObject<HTMLButtonElement> | null | undefined;
17
17
  } & {
18
18
  asChild?: boolean | undefined;
@@ -463,36 +463,14 @@ declare const StyledBaseButton: react.ForwardRefExoticComponent<Pick<Omit<{}, ne
463
463
  }> | undefined;
464
464
  }> & {
465
465
  children?: react.ReactNode;
466
- } & _mirohq_design_system_stitches.CustomStylesProps, "form" | "slot" | "title" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "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" | "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" | "autoFocus" | "disabled" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "name" | "type" | "value" | "asChild" | keyof _mirohq_design_system_stitches.CustomStylesProps> & react.RefAttributes<HTMLButtonElement>> & _mirohq_design_system_stitches.StitchesInternals<react.ForwardRefExoticComponent<_mirohq_design_system_primitive.PrimitiveProps<"button">>, {}, {}>;
466
+ } & _mirohq_design_system_stitches.CustomStylesProps, "ref"> & react.RefAttributes<HTMLButtonElement>> & _mirohq_design_system_stitches.StitchesInternals<react.ForwardRefExoticComponent<_mirohq_design_system_primitive.PrimitiveProps<"button">>, {}, {}>;
467
467
  declare type StyledBaseButtonProps = ComponentPropsWithRef<typeof StyledBaseButton>;
468
468
 
469
- declare type ButtonPropsA11y = StyledBaseButtonProps & AriaButtonProps<'button'>;
470
- interface BaseButtonProps extends FocusEvents, HoverEvents, Omit<ButtonPropsA11y, 'onClick' | 'isDisabled' | 'elementType' | 'onBlur' | 'onFocus' | 'onPressUp'> {
471
- /**
472
- * The content
473
- */
474
- children: ReactNode;
475
- /**
476
- * Prevent pointer events
477
- */
478
- disabled?: boolean;
479
- /**
480
- * A URL to link when using the button as a link
481
- */
482
- href?: string;
483
- /**
484
- * The target window using the button as a link
485
- */
486
- target?: string;
487
- /**
488
- * The relationship between the linked resource and the current page. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel)
489
- */
490
- rel?: string;
491
- /**
492
- * Alias for onPress
493
- */
494
- onClick?: AriaButtonProps['onPress'];
495
- }
496
- declare const BaseButton: react__default.ForwardRefExoticComponent<Pick<BaseButtonProps, "form" | "slot" | "title" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "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" | "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" | "autoFocus" | "disabled" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "name" | "type" | "value" | "target" | "href" | "rel" | "asChild" | "css" | "UNSAFE_style" | "onPress" | "onPressStart" | "onPressEnd" | "onPressChange" | "onFocusChange" | "excludeFromTabOrder" | "onHoverStart" | "onHoverEnd" | "onHoverChange"> & react__default.RefAttributes<HTMLButtonElement | HTMLAnchorElement>>;
469
+ declare type AsButtonProps = StyledBaseButtonProps & PressProps & HoverEvents;
470
+ declare type AsLinkProps = AsButtonProps & AnchorHTMLAttributes<'a'> & {
471
+ href: string;
472
+ };
473
+ declare type BaseButtonProps = AsButtonProps | AsLinkProps;
474
+ declare const BaseButton: react__default.ForwardRefExoticComponent<(Omit<AsButtonProps, "ref"> | Omit<AsLinkProps, "ref">) & react__default.RefAttributes<HTMLButtonElement | HTMLAnchorElement>>;
497
475
 
498
476
  export { BaseButton, BaseButtonProps, sizes };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mirohq/design-system-base-button",
3
- "version": "0.4.10",
3
+ "version": "0.4.11",
4
4
  "description": "",
5
5
  "author": "Miro",
6
6
  "source": "src/index.ts",
@@ -26,15 +26,11 @@
26
26
  "react": "^16.14 || ^17 || ^18"
27
27
  },
28
28
  "dependencies": {
29
- "@react-aria/button": "^3.5.0",
30
- "@react-aria/focus": "^3.10.0",
31
29
  "@react-aria/interactions": "^3.13.0",
32
- "@react-aria/link": "^3.3.0",
33
30
  "@react-aria/utils": "^3.13.0",
34
- "@react-types/button": "^3.5.0",
35
31
  "@react-types/shared": "^3.16.0",
36
- "@mirohq/design-system-stitches": "^2.3.3",
37
- "@mirohq/design-system-primitive": "^1.1.0"
32
+ "@mirohq/design-system-primitive": "^1.1.0",
33
+ "@mirohq/design-system-stitches": "^2.3.4"
38
34
  },
39
35
  "scripts": {
40
36
  "build": "rollup -c ../../../../rollup.config.js",