@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 +46 -77
- package/dist/main.js.map +1 -1
- package/dist/module.js +47 -78
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +11 -33
- package/package.json +3 -7
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
|
|
10
|
-
var
|
|
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
|
-
|
|
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
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
|
99
|
-
onHoverEnd
|
|
100
|
-
onHoverChange
|
|
64
|
+
onHoverStart,
|
|
65
|
+
onHoverEnd,
|
|
66
|
+
onHoverChange
|
|
101
67
|
});
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
|
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,yBAAM,CAAA,UAAA;AAAA,EAI9B,CACE;AAAA,IACE,QAAW,GAAA,KAAA;AAAA,IACX,eAAiB,EAAA,YAAA;AAAA,IACjB,QAAA;AAAA,IACA,OAAA;AAAA,IACA,IAAA;AAAA,IACA,YAAA;AAAA,IACA,UAAA;AAAA,IACA,aAAA;AA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A,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
|
|
2
|
-
import
|
|
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 {
|
|
6
|
-
import {
|
|
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
|
-
|
|
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
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
|
91
|
-
onHoverEnd
|
|
92
|
-
onHoverChange
|
|
56
|
+
onHoverStart,
|
|
57
|
+
onHoverEnd,
|
|
58
|
+
onHoverChange
|
|
93
59
|
});
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
|
package/dist/module.js.map
CHANGED
|
@@ -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
|
|
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,MAAA;AAAA,GACjB;AAAA,EAEA,kBAAoB,EAAA;AAAA,IAClB,MAAQ,EAAA,SAAA;AAAA,GACV;AAAA,EAEA,GAAG,KAAM,CAAA,QAAA;AACX,CAAC,CAAA;;ACNM,MAAM,aAAa,KAAM,CAAA,UAAA;AAAA,EAI9B,CACE;AAAA,IACE,QAAW,GAAA,KAAA;AAAA,IACX,eAAiB,EAAA,YAAA;AAAA,IACjB,QAAA;AAAA,IACA,OAAA;AAAA,IACA,IAAA;AAAA,IACA,YAAA;AAAA,IACA,UAAA;AAAA,IACA,aAAA;AAAA,IACA,GAAG,SAAA;AAAA,KAEL,UACG,KAAA;AACH,IAAA,MAAM,SAAS,MAAU,IAAA,SAAA,CAAA;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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,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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<
|
|
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, "
|
|
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
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
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.
|
|
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-
|
|
37
|
-
"@mirohq/design-system-
|
|
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",
|