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