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