@mirohq/design-system-button 2.1.2-button.0 → 2.1.2-test-changelog.0

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/module.js CHANGED
@@ -1,289 +1,297 @@
1
- import React, { Children } from 'react';
1
+ import React, { useRef } from 'react';
2
+ import { useButton } from '@react-aria/button';
3
+ import { mergeProps } from '@react-aria/utils';
2
4
  import { Spinner } from '@mirohq/design-system-spinner';
5
+ import { useLink } from '@react-aria/link';
6
+ import { useFocusRing } from '@react-aria/focus';
3
7
  import { Primitive } from '@mirohq/design-system-primitive';
4
8
  import { styled } from '@mirohq/design-system-stitches';
5
- import { BaseButton, sizes } from '@mirohq/design-system-base-button';
9
+ import { focus } from '@mirohq/design-system-styles';
6
10
 
7
- const StyledIconSlot = styled(Primitive.svg, {});
8
- const IconSlot = React.forwardRef(({ children, ...restProps }, forwardRef) => /* @__PURE__ */ React.createElement(StyledIconSlot, {
9
- ...restProps,
10
- ref: forwardRef,
11
- "aria-hidden": true,
12
- asChild: true
13
- }, children));
14
-
15
- const activeSelector = "&:active, &[data-pressed]";
16
- const disabledSelector = '&[disabled], &[aria-disabled="true"]';
17
- const iconSlotSelector = `& ${StyledIconSlot}`;
18
- const solidDisabled = {
19
- [disabledSelector]: {
20
- backgroundColor: "$background-neutrals-disabled",
21
- color: "$text-neutrals-disabled",
22
- [iconSlotSelector]: {
23
- color: "$icon-neutrals-disabled"
24
- }
11
+ const focusFilled = {
12
+ "&[data-focused]": {
13
+ boxShadow: `inset 0 0 0 1px white, ${focus.defaults["&:focus-visible"].boxShadow}`
25
14
  }
26
15
  };
27
- const outlineDisabled = {
28
- [disabledSelector]: {
29
- backgroundColor: "$background-neutrals",
30
- borderColor: "$border-neutrals-disabled",
31
- color: "$text-neutrals-disabled",
32
- [iconSlotSelector]: {
33
- color: "$icon-neutrals-disabled"
34
- }
16
+ const focusOutline = {
17
+ "&[data-focused]": {
18
+ ...focus.defaults,
19
+ borderColor: "transparent"
35
20
  }
36
21
  };
37
- const ghostDisabled = {
38
- [disabledSelector]: {
39
- color: "$text-neutrals-disabled",
40
- backgroundColor: "$transparent",
41
- [iconSlotSelector]: {
42
- color: "$icon-neutrals-disabled"
43
- }
44
- }
22
+ const focusDefault = {
23
+ "&[data-focused]": focus.defaults
45
24
  };
46
- const LABEL_OFFSET = 2;
47
- const StyledButton = styled(BaseButton, {
48
- userSelect: "none",
25
+ const pressedSelector = "&:active, &[data-pressed]";
26
+ const StyledButton = styled(Primitive.button, {
27
+ boxSizing: "border-box",
28
+ display: "inline-block",
29
+ outline: "none",
49
30
  whiteSpace: "nowrap",
50
31
  textOverflow: "ellipsis",
51
32
  textAlign: "center",
33
+ verticalAlign: "middle",
34
+ userSelect: "none",
35
+ fontFamily: "inherit",
36
+ fontStyle: "normal",
37
+ fontStretch: "normal",
38
+ letterSpacing: "normal",
39
+ fontWeight: "normal",
52
40
  position: "relative",
53
- width: "fit-content",
54
- maxWidth: "100%",
55
- lineHeight: 1.5,
56
- border: "1px solid transparent",
57
- "&[data-focused]": {
58
- boxShadow: "$focus-small-outline",
59
- borderColor: "$blue-500 !important"
60
- },
61
- [`& ${StyledIconSlot}:first-child`]: {
62
- marginLeft: -LABEL_OFFSET,
63
- marginRight: `calc($50 + ${LABEL_OFFSET}px)`
64
- },
65
- [`& ${StyledIconSlot}:last-child`]: {
66
- marginRight: -LABEL_OFFSET,
67
- marginLeft: `calc($50 + ${LABEL_OFFSET}px)`
41
+ cursor: "pointer",
42
+ border: "none",
43
+ textDecoration: "none",
44
+ backgroundColor: "transparent",
45
+ "&[disabled]": {
46
+ pointerEvents: "none",
47
+ opacity: 0.4
68
48
  },
69
49
  variants: {
70
50
  variant: {
71
- "solid-prominent": {
72
- backgroundColor: "$background-primary-prominent",
73
- color: "$text-primary-inverted",
74
- [iconSlotSelector]: {
75
- color: "$icon-primary-inverted"
76
- },
77
- "&:hover": {
78
- backgroundColor: "$background-primary-prominent-hover"
79
- },
80
- [activeSelector]: {
81
- backgroundColor: "$background-primary-prominent-active"
82
- },
83
- ...solidDisabled
51
+ primary: {},
52
+ secondary: {},
53
+ danger: {}
54
+ },
55
+ appearance: {
56
+ filled: {},
57
+ outlined: {},
58
+ flat: {}
59
+ },
60
+ size: {
61
+ large: {
62
+ padding: "14px 32px 18px 32px",
63
+ fontSize: "20px",
64
+ lineHeight: "28px",
65
+ height: "60px"
84
66
  },
85
- "outline-prominent": {
86
- backgroundColor: "$background-neutrals",
87
- borderColor: "$border-primary",
88
- color: "$text-primary",
89
- [iconSlotSelector]: {
90
- color: "$icon-primary"
91
- },
92
- "&:hover": {
93
- backgroundColor: "$background-primary-subtle-hover",
94
- borderColor: "$border-primary-hover",
95
- color: "$text-primary-hover",
96
- [iconSlotSelector]: {
97
- color: "$icon-primary-hover"
98
- }
99
- },
100
- [activeSelector]: {
101
- backgroundColor: "$background-primary-subtle-active",
102
- borderColor: "$border-primary-active",
103
- color: "$text-primary-active",
104
- [iconSlotSelector]: {
105
- color: "$icon-primary-active"
106
- }
107
- },
108
- ...outlineDisabled
67
+ medium: {
68
+ padding: "11px 24px 13px 24px",
69
+ fontSize: "16px",
70
+ lineHeight: "24px",
71
+ height: "48px"
109
72
  },
110
- "ghost-prominent": {
111
- backgroundColor: "transparent",
112
- color: "$text-primary",
113
- "&:hover": {
114
- backgroundColor: "$background-primary-subtle-hover",
115
- color: "$text-primary-hover",
116
- [iconSlotSelector]: {
117
- color: "$icon-primary-hover"
118
- }
119
- },
120
- [activeSelector]: {
121
- backgroundColor: "$background-primary-subtle-active",
122
- color: "$text-primary-active",
123
- [iconSlotSelector]: {
124
- color: "$icon-primary-active"
125
- }
126
- },
127
- ...ghostDisabled
73
+ small: {
74
+ padding: "7px 16px 9px 16px",
75
+ fontSize: "14px",
76
+ lineHeight: "20px",
77
+ height: "36px"
128
78
  },
129
- "solid-subtle": {
130
- backgroundColor: "$background-neutrals-subtle",
131
- color: "$text-neutrals",
132
- [iconSlotSelector]: {
133
- color: "$icon-neutrals"
134
- },
135
- "&:hover": {
136
- backgroundColor: "$background-neutrals-subtle-hover"
137
- },
138
- [activeSelector]: {
139
- backgroundColor: "$background-neutrals-subtle-active"
140
- },
141
- ...solidDisabled
79
+ "x-small": {
80
+ padding: "5px 12px 7px",
81
+ fontSize: "14px",
82
+ lineHeight: "20px",
83
+ height: "32px"
142
84
  },
143
- "outline-subtle": {
144
- backgroundColor: "$background-neutrals",
145
- border: "1px solid $border-neutrals",
146
- color: "$text-neutrals",
147
- [iconSlotSelector]: {
148
- color: "$icon-neutrals"
149
- },
85
+ "xx-small": {
86
+ padding: "3px 12px",
87
+ fontSize: "12px",
88
+ lineHeight: "18px",
89
+ height: "24px"
90
+ }
91
+ },
92
+ rounded: {
93
+ true: {
94
+ borderRadius: "$half"
95
+ }
96
+ },
97
+ loading: {
98
+ true: {
99
+ "&[disabled]": {
100
+ cursor: "default",
101
+ opacity: 1,
102
+ pointerEvents: "none",
103
+ "& > span": {
104
+ visibility: "hidden"
105
+ }
106
+ }
107
+ }
108
+ },
109
+ fluid: {
110
+ true: {
111
+ width: "100%",
112
+ display: "block"
113
+ }
114
+ }
115
+ },
116
+ compoundVariants: [
117
+ {
118
+ size: "small",
119
+ rounded: true,
120
+ css: {
121
+ padding: "10px 16px",
122
+ height: "40px"
123
+ }
124
+ },
125
+ {
126
+ size: "large",
127
+ rounded: false,
128
+ css: {
129
+ borderRadius: "$50"
130
+ }
131
+ },
132
+ {
133
+ size: "medium",
134
+ rounded: false,
135
+ css: {
136
+ borderRadius: "$50"
137
+ }
138
+ },
139
+ {
140
+ size: "small",
141
+ rounded: false,
142
+ css: {
143
+ borderRadius: "$50"
144
+ }
145
+ },
146
+ {
147
+ size: "x-small",
148
+ rounded: false,
149
+ css: {
150
+ borderRadius: "$50"
151
+ }
152
+ },
153
+ {
154
+ size: "xx-small",
155
+ rounded: false,
156
+ css: {
157
+ borderRadius: "$25"
158
+ }
159
+ },
160
+ {
161
+ variant: "primary",
162
+ appearance: "filled",
163
+ css: {
164
+ color: "$white",
165
+ backgroundColor: "$blue-600",
166
+ ...focusFilled,
150
167
  "&:hover": {
151
- backgroundColor: "$background-neutrals-subtle-hover",
152
- borderColor: "$border-neutrals-hover"
153
- },
154
- [activeSelector]: {
155
- backgroundColor: "$background-neutrals-subtle-active",
156
- borderColor: "$border-neutrals-active"
157
- },
158
- ...outlineDisabled
159
- },
160
- "ghost-subtle": {
161
- backgroundColor: "transparent",
162
- color: "$text-neutrals",
163
- [iconSlotSelector]: {
164
- color: "$icon-neutrals"
168
+ color: "$white",
169
+ backgroundColor: "$blue-700"
165
170
  },
171
+ [pressedSelector]: {
172
+ backgroundColor: "$blue-900"
173
+ }
174
+ }
175
+ },
176
+ {
177
+ variant: "primary",
178
+ appearance: "outlined",
179
+ css: {
180
+ color: "rgba(66, 98, 255, 1)",
181
+ border: "1px solid rgba(66, 98, 255, 1)",
182
+ ...focusOutline,
166
183
  "&:hover": {
167
- backgroundColor: "$background-neutrals-subtle-hover"
168
- },
169
- [activeSelector]: {
170
- backgroundColor: "$background-neutrals-subtle-active"
171
- },
172
- ...ghostDisabled
173
- },
174
- "solid-danger": {
175
- backgroundColor: "$background-danger-prominent",
176
- color: "$text-danger-inverted",
177
- [iconSlotSelector]: {
178
- color: "$icon-danger-inverted"
184
+ color: "rgba(66, 98, 255, 1)",
185
+ backgroundColor: "rgba(244, 246, 255, 1)"
179
186
  },
187
+ [pressedSelector]: {
188
+ backgroundColor: "rgba(240, 242, 255, 1)"
189
+ }
190
+ }
191
+ },
192
+ {
193
+ variant: "primary",
194
+ appearance: "flat",
195
+ css: {
196
+ color: "rgba(66, 98, 255, 1)",
197
+ ...focusDefault,
180
198
  "&:hover": {
181
- backgroundColor: "$background-danger-prominent-hover"
182
- },
183
- [activeSelector]: {
184
- backgroundColor: "$background-danger-prominent-active"
185
- },
186
- ...solidDisabled
187
- },
188
- "outline-danger": {
189
- backgroundColor: "$background-neutrals",
190
- borderColor: "$border-danger",
191
- color: "$text-danger",
192
- [iconSlotSelector]: {
193
- color: "$icon-danger"
199
+ color: "rgba(69, 91, 237, 1)",
200
+ backgroundColor: "rgba(245, 245, 247, 1)"
194
201
  },
202
+ [pressedSelector]: {
203
+ color: "rgba(61, 81, 212, 1)"
204
+ }
205
+ }
206
+ },
207
+ {
208
+ variant: "secondary",
209
+ appearance: "filled",
210
+ css: {
211
+ color: "rgba(5, 0, 56, 1)",
212
+ backgroundColor: "rgba(245, 245, 247, 1)",
213
+ ...focusFilled,
195
214
  "&:hover": {
196
- backgroundColor: "$background-danger",
197
- color: "$text-danger-hover",
198
- [iconSlotSelector]: {
199
- color: "$icon-danger-hover"
200
- }
201
- },
202
- [activeSelector]: {
203
- backgroundColor: "$background-danger-hover",
204
- color: "$text-danger-active",
205
- [iconSlotSelector]: {
206
- color: "$icon-danger-active"
207
- }
208
- },
209
- ...outlineDisabled
210
- },
211
- "ghost-danger": {
212
- backgroundColor: "transparent",
213
- color: "$text-danger",
214
- [iconSlotSelector]: {
215
- color: "$icon-danger"
215
+ color: "rgba(5, 0, 56, 1)",
216
+ backgroundColor: "rgba(240, 240, 243, 1)"
216
217
  },
218
+ [pressedSelector]: {
219
+ backgroundColor: "rgba(235, 235, 239, 1)"
220
+ }
221
+ }
222
+ },
223
+ {
224
+ variant: "secondary",
225
+ appearance: "outlined",
226
+ css: {
227
+ color: "rgba(5, 0, 56, 1)",
228
+ border: "1px solid rgba(205, 204, 215, 1)",
229
+ ...focusOutline,
217
230
  "&:hover": {
218
- backgroundColor: "$background-danger",
219
- color: "$text-danger-hover",
220
- [iconSlotSelector]: {
221
- color: "$icon-danger-hover"
222
- }
223
- },
224
- [activeSelector]: {
225
- backgroundColor: "$background-danger-hover",
226
- color: "$text-danger-active",
227
- [iconSlotSelector]: {
228
- color: "$icon-danger-active"
229
- }
231
+ color: "rgba(5, 0, 56, 1)",
232
+ backgroundColor: "rgba(245, 245, 247, 1)"
230
233
  },
231
- ...ghostDisabled
234
+ [pressedSelector]: {
235
+ backgroundColor: "rgba(235, 235, 239, 1)"
236
+ }
232
237
  }
233
238
  },
234
- size: {
235
- "x-large": {
236
- height: sizes.xLarge,
237
- fontSize: "$200",
238
- paddingX: `calc($200 + ${LABEL_OFFSET}px)`,
239
- [iconSlotSelector]: {
240
- width: "$icon-300",
241
- height: "$icon-300"
242
- }
243
- },
244
- large: {
245
- height: sizes.large,
246
- fontSize: "$200",
247
- paddingX: `calc($150 + ${LABEL_OFFSET}px)`,
248
- [iconSlotSelector]: {
249
- width: "$icon-300",
250
- height: "$icon-300"
251
- }
252
- },
253
- medium: {
254
- height: sizes.medium,
255
- fontSize: "$175",
256
- paddingX: `calc($100 + ${LABEL_OFFSET}px)`,
257
- [iconSlotSelector]: {
258
- width: "$icon-200",
259
- height: "$icon-200"
239
+ {
240
+ variant: "secondary",
241
+ appearance: "flat",
242
+ css: {
243
+ color: "rgba(5, 0, 56, 1)",
244
+ ...focusDefault,
245
+ "&:hover": {
246
+ color: "rgba(5, 0, 56, 1)",
247
+ backgroundColor: "rgba(245, 245, 247, 1)"
260
248
  }
261
- },
262
- small: {
263
- fontSize: "$175",
264
- height: "$6",
265
- paddingX: `calc($100 + ${LABEL_OFFSET}px)`,
266
- [iconSlotSelector]: {
267
- width: "$icon-200",
268
- height: "$icon-200"
249
+ }
250
+ },
251
+ {
252
+ variant: "danger",
253
+ appearance: "filled",
254
+ css: {
255
+ color: "$white",
256
+ backgroundColor: "rgba(217, 41, 41, 1)",
257
+ ...focusFilled,
258
+ "&:hover": {
259
+ backgroundColor: "rgba(199, 20, 20, 1)"
260
+ },
261
+ [pressedSelector]: {
262
+ backgroundColor: "rgba(184, 13, 13, 1)"
269
263
  }
270
264
  }
271
265
  },
272
- rounded: {
273
- true: {
274
- borderRadius: "$half"
266
+ {
267
+ variant: "danger",
268
+ appearance: "outlined",
269
+ css: {
270
+ color: "rgba(217, 41, 41, 1)",
271
+ border: "1px solid rgba(217, 41, 41, 1)",
272
+ ...focusOutline,
273
+ "&:hover": {
274
+ color: "rgba(217, 41, 41, 1)",
275
+ backgroundColor: "rgba(254, 247, 247, 1)"
276
+ },
277
+ [pressedSelector]: {
278
+ backgroundColor: "rgba(253, 242, 242, 1)"
279
+ }
275
280
  }
276
281
  },
277
- fluid: {
278
- true: {
279
- width: "100%",
280
- display: "block"
282
+ {
283
+ variant: "danger",
284
+ appearance: "flat",
285
+ css: {
286
+ color: "rgba(217, 41, 41, 1)",
287
+ ...focusDefault,
288
+ "&:hover": {
289
+ color: "rgba(217, 41, 41, 1)",
290
+ backgroundColor: "rgba(245, 245, 247, 1)"
291
+ }
281
292
  }
282
293
  }
283
- }
284
- });
285
- const StyledHiddenContent = styled(Primitive.span, {
286
- visibility: "hidden"
294
+ ]
287
295
  });
288
296
  const StyledSpinnerBox = styled(Primitive.div, {
289
297
  display: "flex",
@@ -299,44 +307,84 @@ const StyledSpinnerBox = styled(Primitive.div, {
299
307
 
300
308
  const Button = React.forwardRef(
301
309
  ({
302
- variant = "solid-prominent",
303
- size = "large",
310
+ variant = "primary",
311
+ appearance = "filled",
312
+ size = "medium",
304
313
  loading = false,
305
314
  rounded = false,
306
315
  fluid = false,
307
- "aria-disabled": ariaDisabled,
316
+ disabled = false,
317
+ href,
318
+ target,
319
+ rel,
308
320
  children,
321
+ onPress,
322
+ onClick,
323
+ asChild,
309
324
  ...restProps
310
325
  }, forwardRef) => {
311
- let spinnerSize = "medium";
312
- if (typeof size === "string" && ["small", "medium"].includes(size)) {
313
- spinnerSize = "small";
326
+ let spinnerSize;
327
+ if (typeof size === "string") {
328
+ spinnerSize = ["x-small", "xx-small"].includes(size) ? "small" : "medium";
329
+ } else {
330
+ spinnerSize = "medium";
314
331
  }
315
- const shouldHaveAriaDisabled = ariaDisabled === "true" || ariaDisabled === true || loading;
316
- const formattedChildren = Children.map(
317
- Children.toArray(children),
318
- (child) => {
319
- if (typeof child === "string" || typeof child === "boolean" || typeof child === "number") {
320
- return /* @__PURE__ */ React.createElement(Primitive.span, null, child);
321
- }
322
- return child;
323
- }
332
+ const _loading = loading === "true" || loading === true;
333
+ const shouldBeDisabled = disabled || _loading;
334
+ const asLink = href != null;
335
+ const ref = useRef(null);
336
+ const refWithFallback = forwardRef != null ? forwardRef : ref;
337
+ const { buttonProps, isPressed } = useButton(
338
+ {
339
+ isDisabled: shouldBeDisabled,
340
+ href,
341
+ onPress: onPress != null ? onPress : onClick,
342
+ allowFocusWhenDisabled: false,
343
+ ...restProps
344
+ },
345
+ refWithFallback
346
+ );
347
+ const { linkProps } = useLink(
348
+ {
349
+ isDisabled: disabled,
350
+ onPress: onPress != null ? onPress : onClick,
351
+ ...restProps
352
+ },
353
+ refWithFallback
324
354
  );
325
- const Content = loading ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(StyledSpinnerBox, null, /* @__PURE__ */ React.createElement(Spinner, {
355
+ const Content = /* @__PURE__ */ React.createElement(React.Fragment, null, _loading && /* @__PURE__ */ React.createElement(StyledSpinnerBox, null, /* @__PURE__ */ React.createElement(Spinner, {
326
356
  size: spinnerSize
327
- })), /* @__PURE__ */ React.createElement(StyledHiddenContent, null, formattedChildren)) : formattedChildren;
357
+ })), /* @__PURE__ */ React.createElement("span", null, children));
358
+ const tabIndexProp = shouldBeDisabled && {
359
+ tabIndex: -1
360
+ };
361
+ const { isFocusVisible, focusProps } = useFocusRing();
362
+ const elementProps = mergeProps(
363
+ restProps,
364
+ asLink ? linkProps : buttonProps,
365
+ focusProps
366
+ );
328
367
  return /* @__PURE__ */ React.createElement(StyledButton, {
329
- ...restProps,
368
+ ...elementProps,
330
369
  variant,
370
+ appearance,
371
+ size,
372
+ loading,
331
373
  rounded,
332
374
  fluid,
333
- size,
334
- "aria-disabled": shouldHaveAriaDisabled ? true : void 0,
335
- ref: forwardRef
336
- }, Content);
375
+ disabled: shouldBeDisabled,
376
+ asChild: asLink || asChild,
377
+ ...tabIndexProp,
378
+ "data-pressed": isPressed ? "" : void 0,
379
+ "data-focused": isFocusVisible ? "" : void 0,
380
+ ref: refWithFallback
381
+ }, asLink ? /* @__PURE__ */ React.createElement("a", {
382
+ href,
383
+ target,
384
+ rel: target === "_blank" ? `noopener noreferrer ${rel}` : rel
385
+ }, Content) : Content);
337
386
  }
338
387
  );
339
- Button.IconSlot = IconSlot;
340
388
 
341
389
  export { Button };
342
390
  //# sourceMappingURL=module.js.map