@mirohq/design-system-button 2.1.0 → 2.1.2-button.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,297 +1,289 @@
1
- import React, { useRef } from 'react';
2
- import { useButton } from '@react-aria/button';
3
- import { mergeProps } from '@react-aria/utils';
1
+ import React, { Children } from 'react';
4
2
  import { Spinner } from '@mirohq/design-system-spinner';
5
- import { useLink } from '@react-aria/link';
6
- import { useFocusRing } from '@react-aria/focus';
7
3
  import { Primitive } from '@mirohq/design-system-primitive';
8
4
  import { styled } from '@mirohq/design-system-stitches';
9
- import { focus } from '@mirohq/design-system-styles';
5
+ import { BaseButton, sizes } from '@mirohq/design-system-base-button';
10
6
 
11
- const focusFilled = {
12
- "&[data-focused]": {
13
- boxShadow: `inset 0 0 0 1px white, ${focus.defaults["&:focus-visible"].boxShadow}`
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
+ }
14
25
  }
15
26
  };
16
- const focusOutline = {
17
- "&[data-focused]": {
18
- ...focus.defaults,
19
- borderColor: "transparent"
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
+ }
20
35
  }
21
36
  };
22
- const focusDefault = {
23
- "&[data-focused]": focus.defaults
37
+ const ghostDisabled = {
38
+ [disabledSelector]: {
39
+ color: "$text-neutrals-disabled",
40
+ backgroundColor: "$transparent",
41
+ [iconSlotSelector]: {
42
+ color: "$icon-neutrals-disabled"
43
+ }
44
+ }
24
45
  };
25
- const pressedSelector = "&:active, &[data-pressed]";
26
- const StyledButton = styled(Primitive.button, {
27
- boxSizing: "border-box",
28
- display: "inline-block",
29
- outline: "none",
46
+ const LABEL_OFFSET = 2;
47
+ const StyledButton = styled(BaseButton, {
48
+ userSelect: "none",
30
49
  whiteSpace: "nowrap",
31
50
  textOverflow: "ellipsis",
32
51
  textAlign: "center",
33
- verticalAlign: "middle",
34
- userSelect: "none",
35
- fontFamily: "inherit",
36
- fontStyle: "normal",
37
- fontStretch: "normal",
38
- letterSpacing: "normal",
39
- fontWeight: "normal",
40
52
  position: "relative",
41
- cursor: "pointer",
42
- border: "none",
43
- textDecoration: "none",
44
- backgroundColor: "transparent",
45
- "&[disabled]": {
46
- pointerEvents: "none",
47
- opacity: 0.4
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)`
48
68
  },
49
69
  variants: {
50
70
  variant: {
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"
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
66
84
  },
67
- medium: {
68
- padding: "11px 24px 13px 24px",
69
- fontSize: "16px",
70
- lineHeight: "24px",
71
- height: "48px"
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
72
109
  },
73
- small: {
74
- padding: "7px 16px 9px 16px",
75
- fontSize: "14px",
76
- lineHeight: "20px",
77
- height: "36px"
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
78
128
  },
79
- "x-small": {
80
- padding: "5px 12px 7px",
81
- fontSize: "14px",
82
- lineHeight: "20px",
83
- height: "32px"
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
84
142
  },
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,
143
+ "outline-subtle": {
144
+ backgroundColor: "$background-neutrals",
145
+ border: "1px solid $border-neutrals",
146
+ color: "$text-neutrals",
147
+ [iconSlotSelector]: {
148
+ color: "$icon-neutrals"
149
+ },
167
150
  "&:hover": {
168
- color: "$white",
169
- backgroundColor: "$blue-700"
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"
170
165
  },
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,
183
166
  "&:hover": {
184
- color: "rgba(66, 98, 255, 1)",
185
- backgroundColor: "rgba(244, 246, 255, 1)"
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"
186
179
  },
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,
198
180
  "&:hover": {
199
- color: "rgba(69, 91, 237, 1)",
200
- backgroundColor: "rgba(245, 245, 247, 1)"
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"
201
194
  },
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,
214
195
  "&:hover": {
215
- color: "rgba(5, 0, 56, 1)",
216
- backgroundColor: "rgba(240, 240, 243, 1)"
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"
217
216
  },
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,
230
217
  "&:hover": {
231
- color: "rgba(5, 0, 56, 1)",
232
- backgroundColor: "rgba(245, 245, 247, 1)"
218
+ backgroundColor: "$background-danger",
219
+ color: "$text-danger-hover",
220
+ [iconSlotSelector]: {
221
+ color: "$icon-danger-hover"
222
+ }
233
223
  },
234
- [pressedSelector]: {
235
- backgroundColor: "rgba(235, 235, 239, 1)"
236
- }
224
+ [activeSelector]: {
225
+ backgroundColor: "$background-danger-hover",
226
+ color: "$text-danger-active",
227
+ [iconSlotSelector]: {
228
+ color: "$icon-danger-active"
229
+ }
230
+ },
231
+ ...ghostDisabled
237
232
  }
238
233
  },
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)"
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"
248
242
  }
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)"
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"
260
+ }
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"
263
269
  }
264
270
  }
265
271
  },
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
- }
272
+ rounded: {
273
+ true: {
274
+ borderRadius: "$half"
280
275
  }
281
276
  },
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
- }
277
+ fluid: {
278
+ true: {
279
+ width: "100%",
280
+ display: "block"
292
281
  }
293
282
  }
294
- ]
283
+ }
284
+ });
285
+ const StyledHiddenContent = styled(Primitive.span, {
286
+ visibility: "hidden"
295
287
  });
296
288
  const StyledSpinnerBox = styled(Primitive.div, {
297
289
  display: "flex",
@@ -307,84 +299,44 @@ const StyledSpinnerBox = styled(Primitive.div, {
307
299
 
308
300
  const Button = React.forwardRef(
309
301
  ({
310
- variant = "primary",
311
- appearance = "filled",
312
- size = "medium",
302
+ variant = "solid-prominent",
303
+ size = "large",
313
304
  loading = false,
314
305
  rounded = false,
315
306
  fluid = false,
316
- disabled = false,
317
- href,
318
- target,
319
- rel,
307
+ "aria-disabled": ariaDisabled,
320
308
  children,
321
- onPress,
322
- onClick,
323
- asChild,
324
309
  ...restProps
325
310
  }, forwardRef) => {
326
- let spinnerSize;
327
- if (typeof size === "string") {
328
- spinnerSize = ["x-small", "xx-small"].includes(size) ? "small" : "medium";
329
- } else {
330
- spinnerSize = "medium";
311
+ let spinnerSize = "medium";
312
+ if (typeof size === "string" && ["small", "medium"].includes(size)) {
313
+ spinnerSize = "small";
331
314
  }
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
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
+ }
354
324
  );
355
- const Content = /* @__PURE__ */ React.createElement(React.Fragment, null, _loading && /* @__PURE__ */ React.createElement(StyledSpinnerBox, null, /* @__PURE__ */ React.createElement(Spinner, {
325
+ const Content = loading ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(StyledSpinnerBox, null, /* @__PURE__ */ React.createElement(Spinner, {
356
326
  size: spinnerSize
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
- );
327
+ })), /* @__PURE__ */ React.createElement(StyledHiddenContent, null, formattedChildren)) : formattedChildren;
367
328
  return /* @__PURE__ */ React.createElement(StyledButton, {
368
- ...elementProps,
329
+ ...restProps,
369
330
  variant,
370
- appearance,
371
- size,
372
- loading,
373
331
  rounded,
374
332
  fluid,
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);
333
+ size,
334
+ "aria-disabled": shouldHaveAriaDisabled ? true : void 0,
335
+ ref: forwardRef
336
+ }, Content);
386
337
  }
387
338
  );
339
+ Button.IconSlot = IconSlot;
388
340
 
389
341
  export { Button };
390
342
  //# sourceMappingURL=module.js.map