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