@mirohq/design-system-button 2.0.17 → 3.0.0-button.1

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