@primer/components 0.0.0-20211124581 → 0.0.0-202111255030

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.
Files changed (76) hide show
  1. package/CHANGELOG.md +1 -7
  2. package/dist/browser.esm.js +148 -166
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +156 -174
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/ActionList2/Divider.d.ts +2 -3
  7. package/lib/ActionList2/Divider.js +5 -10
  8. package/lib/ActionList2/Item.js +5 -21
  9. package/lib/ActionList2/List.js +1 -11
  10. package/lib/ActionList2/Selection.js +0 -11
  11. package/lib/ActionList2/index.d.ts +2 -1
  12. package/lib/Autocomplete/Autocomplete.d.ts +2 -10
  13. package/lib/Autocomplete/AutocompleteInput.d.ts +2 -10
  14. package/lib/Checkbox.d.ts +1 -1
  15. package/lib/NewButton/button-base.d.ts +6 -0
  16. package/lib/NewButton/button-base.js +69 -0
  17. package/lib/NewButton/button-link.d.ts +26 -0
  18. package/lib/NewButton/button-link.js +31 -0
  19. package/lib/NewButton/button.d.ts +2 -11
  20. package/lib/NewButton/button.js +6 -283
  21. package/lib/NewButton/icon-button.d.ts +4 -0
  22. package/lib/NewButton/icon-button.js +57 -0
  23. package/lib/NewButton/index.d.ts +6 -11
  24. package/lib/NewButton/index.js +18 -0
  25. package/lib/NewButton/styles.d.ts +202 -0
  26. package/lib/NewButton/styles.js +248 -0
  27. package/lib/NewButton/types.d.ts +28 -8
  28. package/lib/NewButton/types.js +19 -1
  29. package/lib/SelectMenu/SelectMenu.d.ts +2 -10
  30. package/lib/TextInput.d.ts +1 -8
  31. package/lib/TextInput.js +5 -16
  32. package/lib/TextInputWithTokens.d.ts +2 -10
  33. package/lib/_TextInputWrapper.d.ts +0 -3
  34. package/lib/_TextInputWrapper.js +7 -18
  35. package/lib/drafts.d.ts +0 -1
  36. package/lib/drafts.js +0 -13
  37. package/lib-esm/ActionList2/Divider.d.ts +2 -3
  38. package/lib-esm/ActionList2/Divider.js +5 -8
  39. package/lib-esm/ActionList2/Item.js +5 -19
  40. package/lib-esm/ActionList2/List.js +1 -9
  41. package/lib-esm/ActionList2/Selection.js +0 -9
  42. package/lib-esm/ActionList2/index.d.ts +2 -1
  43. package/lib-esm/Autocomplete/Autocomplete.d.ts +2 -10
  44. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +2 -10
  45. package/lib-esm/Checkbox.d.ts +1 -1
  46. package/lib-esm/NewButton/button-base.d.ts +6 -0
  47. package/lib-esm/NewButton/button-base.js +47 -0
  48. package/lib-esm/NewButton/button-link.d.ts +26 -0
  49. package/lib-esm/NewButton/button-link.js +15 -0
  50. package/lib-esm/NewButton/button.d.ts +2 -11
  51. package/lib-esm/NewButton/button.js +4 -275
  52. package/lib-esm/NewButton/icon-button.d.ts +4 -0
  53. package/lib-esm/NewButton/icon-button.js +35 -0
  54. package/lib-esm/NewButton/index.d.ts +6 -11
  55. package/lib-esm/NewButton/index.js +4 -1
  56. package/lib-esm/NewButton/styles.d.ts +202 -0
  57. package/lib-esm/NewButton/styles.js +229 -0
  58. package/lib-esm/NewButton/types.d.ts +28 -8
  59. package/lib-esm/NewButton/types.js +6 -1
  60. package/lib-esm/SelectMenu/SelectMenu.d.ts +2 -10
  61. package/lib-esm/TextInput.d.ts +1 -8
  62. package/lib-esm/TextInput.js +5 -16
  63. package/lib-esm/TextInputWithTokens.d.ts +2 -10
  64. package/lib-esm/_TextInputWrapper.d.ts +0 -3
  65. package/lib-esm/_TextInputWrapper.js +7 -18
  66. package/lib-esm/drafts.d.ts +0 -1
  67. package/lib-esm/drafts.js +1 -2
  68. package/package.json +1 -1
  69. package/lib/ActionList2/MenuContext.d.ts +0 -10
  70. package/lib/ActionList2/MenuContext.js +0 -15
  71. package/lib/ActionMenu2.d.ts +0 -310
  72. package/lib/ActionMenu2.js +0 -91
  73. package/lib-esm/ActionList2/MenuContext.d.ts +0 -10
  74. package/lib-esm/ActionList2/MenuContext.js +0 -3
  75. package/lib-esm/ActionMenu2.d.ts +0 -310
  76. package/lib-esm/ActionMenu2.js +0 -67
@@ -8,7 +8,6 @@ import Box from '../Box';
8
8
  import sx, { merge } from '../sx';
9
9
  import createSlots from '../utils/create-slots';
10
10
  import { ListContext } from './List';
11
- import { MenuContext } from './MenuContext';
12
11
  import { Selection } from './Selection';
13
12
  export const getVariantStyles = (variant, disabled) => {
14
13
  if (disabled) {
@@ -55,7 +54,6 @@ export const Item = /*#__PURE__*/React.forwardRef(({
55
54
  onSelect,
56
55
  sx: sxProp = {},
57
56
  id,
58
- role,
59
57
  _PrivateItemWrapper,
60
58
  ...props
61
59
  }, forwardedRef) => {
@@ -63,10 +61,6 @@ export const Item = /*#__PURE__*/React.forwardRef(({
63
61
  variant: listVariant,
64
62
  showDividers
65
63
  } = React.useContext(ListContext);
66
- const {
67
- itemRole,
68
- afterSelect
69
- } = React.useContext(MenuContext);
70
64
  const {
71
65
  theme
72
66
  } = useTheme();
@@ -141,23 +135,16 @@ export const Item = /*#__PURE__*/React.forwardRef(({
141
135
  const clickHandler = React.useCallback(event => {
142
136
  if (typeof onSelect !== 'function') return;
143
137
  if (disabled) return;
144
-
145
- if (!event.defaultPrevented) {
146
- onSelect(event); // if this Item is inside a Menu, close the Menu
147
-
148
- if (typeof afterSelect === 'function') afterSelect();
149
- }
150
- }, [onSelect, disabled, afterSelect]);
138
+ if (!event.defaultPrevented) onSelect(event);
139
+ }, [onSelect, disabled]);
151
140
  const keyPressHandler = React.useCallback(event => {
152
141
  if (typeof onSelect !== 'function') return;
153
142
  if (disabled) return;
154
143
 
155
144
  if (!event.defaultPrevented && [' ', 'Enter'].includes(event.key)) {
156
- onSelect(event); // if this Item is inside a Menu, close the Menu
157
-
158
- if (typeof afterSelect === 'function') afterSelect();
145
+ onSelect(event);
159
146
  }
160
- }, [onSelect, disabled, afterSelect]); // use props.id if provided, otherwise generate one.
147
+ }, [onSelect, disabled]); // use props.id if provided, otherwise generate one.
161
148
 
162
149
  const labelId = useSSRSafeId(id);
163
150
  const inlineDescriptionId = useSSRSafeId(id && `${id}--inline-description`);
@@ -179,8 +166,7 @@ export const Item = /*#__PURE__*/React.forwardRef(({
179
166
  "aria-disabled": disabled ? true : undefined,
180
167
  tabIndex: disabled || _PrivateItemWrapper ? undefined : 0,
181
168
  "aria-labelledby": `${labelId} ${slots.InlineDescription ? inlineDescriptionId : ''}`,
182
- "aria-describedby": slots.BlockDescription ? blockDescriptionId : undefined,
183
- role: role || itemRole
169
+ "aria-describedby": slots.BlockDescription ? blockDescriptionId : undefined
184
170
  }, props), /*#__PURE__*/React.createElement(ItemWrapper, null, /*#__PURE__*/React.createElement(Selection, {
185
171
  selected: selected
186
172
  }), slots.LeadingVisual, /*#__PURE__*/React.createElement(Box, {
@@ -3,7 +3,6 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
3
3
  import React from 'react';
4
4
  import styled from 'styled-components';
5
5
  import sx, { merge } from '../sx';
6
- import { MenuContext } from './MenuContext';
7
6
  export const ListContext = /*#__PURE__*/React.createContext({});
8
7
  const ListBox = styled.ul.withConfig({
9
8
  displayName: "List__ListBox",
@@ -13,7 +12,6 @@ export const List = /*#__PURE__*/React.forwardRef(({
13
12
  variant = 'inset',
14
13
  selectionVariant,
15
14
  showDividers = false,
16
- role,
17
15
  sx: sxProp = {},
18
16
  ...props
19
17
  }, forwardedRef) => {
@@ -23,14 +21,8 @@ export const List = /*#__PURE__*/React.forwardRef(({
23
21
  // reset ul styles
24
22
  paddingY: variant === 'inset' ? 2 : 0
25
23
  };
26
- /** if list is inside a Menu, it will get a role from the Menu */
27
-
28
- const {
29
- listRole
30
- } = React.useContext(MenuContext);
31
24
  return /*#__PURE__*/React.createElement(ListBox, _extends({
32
- sx: merge(styles, sxProp),
33
- role: role || listRole
25
+ sx: merge(styles, sxProp)
34
26
  }, props, {
35
27
  ref: forwardedRef
36
28
  }), /*#__PURE__*/React.createElement(ListContext.Provider, {
@@ -2,7 +2,6 @@ import React from 'react';
2
2
  import { CheckIcon } from '@primer/octicons-react';
3
3
  import { ListContext } from './List';
4
4
  import { GroupContext } from './Group';
5
- import { MenuContext } from './MenuContext';
6
5
  import { LeadingVisualContainer } from './Visuals';
7
6
  export const Selection = ({
8
7
  selected
@@ -13,9 +12,6 @@ export const Selection = ({
13
12
  const {
14
13
  selectionVariant: groupSelectionVariant
15
14
  } = React.useContext(GroupContext);
16
- const {
17
- parent
18
- } = React.useContext(MenuContext);
19
15
  /** selectionVariant in Group can override the selectionVariant in List root */
20
16
 
21
17
  const selectionVariant = typeof groupSelectionVariant !== 'undefined' ? groupSelectionVariant : listSelectionVariant; // if selectionVariant is not set on List, don't show selection
@@ -26,11 +22,6 @@ export const Selection = ({
26
22
  return null;
27
23
  }
28
24
 
29
- if (parent === 'ActionMenu') {
30
- throw new Error('ActionList cannot have a selectionVariant inside ActionMenu, please use DropdownMenu or SelectPanel instead. More information: https://primer.style/design/components/action-list#application');
31
- return null;
32
- }
33
-
34
25
  if (selectionVariant === 'single') {
35
26
  return /*#__PURE__*/React.createElement(LeadingVisualContainer, null, selected && /*#__PURE__*/React.createElement(CheckIcon, null));
36
27
  }
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
+ import { Divider } from './Divider';
2
3
  export type { ListProps as ActionListProps } from './List';
3
4
  export type { GroupProps } from './Group';
4
5
  export type { ItemProps } from './Item';
@@ -25,7 +26,7 @@ export declare const ActionList: import("@radix-ui/react-polymorphic").ForwardRe
25
26
  referrerPolicy?: import("react").HTMLAttributeReferrerPolicy | undefined;
26
27
  }>;
27
28
  /** Visually separates `Item`s or `Group`s in an `ActionList`. */
28
- Divider: import("react").FC<import("../sx").SxProp>;
29
+ Divider: typeof Divider;
29
30
  /** Secondary text which provides additional information about an `Item`. */
30
31
  Description: import("react").FC<import("./Description").DescriptionProps>;
31
32
  /** Icon (or similar) positioned before `Item` text. */
@@ -20,17 +20,11 @@ declare const _default: React.FC<{
20
20
  } & {
21
21
  as?: string | React.ComponentType<any> | undefined;
22
22
  forwardedAs?: string | React.ComponentType<any> | undefined;
23
- }, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "size" | "block" | "icon" | "variant" | "sx" | "className" | "disabled" | "leadingVisual" | "trailingVisual" | "contrast"> & {
23
+ }, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "theme" | "block" | "icon" | "variant" | "sx" | "className" | "disabled" | "contrast"> & {
24
24
  className?: string | undefined;
25
25
  icon?: React.ComponentType<{
26
26
  className?: string | undefined;
27
27
  }> | undefined;
28
- leadingVisual?: string | React.ComponentType<{
29
- className?: string | undefined;
30
- }> | undefined;
31
- trailingVisual?: string | React.ComponentType<{
32
- className?: string | undefined;
33
- }> | undefined;
34
28
  } & Pick<{
35
29
  color?: string | undefined;
36
30
  maxWidth?: import("styled-system").ResponsiveValue<import("csstype").Property.MaxWidth<import("styled-system").TLengthStyledSystem>, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
@@ -43,7 +37,6 @@ declare const _default: React.FC<{
43
37
  slot?: string | undefined;
44
38
  style?: React.CSSProperties | undefined;
45
39
  title?: string | undefined;
46
- size?: "small" | "large" | undefined;
47
40
  block?: boolean | undefined;
48
41
  variant?: "small" | "large" | undefined;
49
42
  role?: React.AriaRole | undefined;
@@ -301,10 +294,9 @@ declare const _default: React.FC<{
301
294
  disabled?: boolean | undefined;
302
295
  hasIcon?: boolean | undefined;
303
296
  contrast?: boolean | undefined;
304
- validationStatus?: "error" | "warning" | undefined;
305
297
  } & {
306
298
  theme?: any;
307
- }, "maxWidth" | "minWidth" | "width" | "size" | "block" | "variant" | "sx" | "disabled" | "contrast">, string | number | symbol> & React.RefAttributes<HTMLInputElement>>, {
299
+ }, "maxWidth" | "minWidth" | "width" | "theme" | "block" | "variant" | "sx" | "disabled" | "contrast">, string | number | symbol> & React.RefAttributes<HTMLInputElement>>, {
308
300
  as?: React.ComponentType<any> | undefined;
309
301
  }>;
310
302
  Menu: typeof AutocompleteMenu;
@@ -12,17 +12,11 @@ declare const AutocompleteInput: PolymorphicForwardRefComponent<React.ForwardRef
12
12
  } & {
13
13
  as?: string | React.ComponentType<any> | undefined;
14
14
  forwardedAs?: string | React.ComponentType<any> | undefined;
15
- }, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "size" | "block" | "icon" | "variant" | "sx" | "className" | "disabled" | "leadingVisual" | "trailingVisual" | "contrast"> & {
15
+ }, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "theme" | "block" | "icon" | "variant" | "sx" | "className" | "disabled" | "contrast"> & {
16
16
  className?: string | undefined;
17
17
  icon?: React.ComponentType<{
18
18
  className?: string | undefined;
19
19
  }> | undefined;
20
- leadingVisual?: string | React.ComponentType<{
21
- className?: string | undefined;
22
- }> | undefined;
23
- trailingVisual?: string | React.ComponentType<{
24
- className?: string | undefined;
25
- }> | undefined;
26
20
  } & Pick<{
27
21
  color?: string | undefined;
28
22
  maxWidth?: import("styled-system").ResponsiveValue<import("csstype").Property.MaxWidth<import("styled-system").TLengthStyledSystem>, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
@@ -35,7 +29,6 @@ declare const AutocompleteInput: PolymorphicForwardRefComponent<React.ForwardRef
35
29
  slot?: string | undefined;
36
30
  style?: React.CSSProperties | undefined;
37
31
  title?: string | undefined;
38
- size?: "small" | "large" | undefined;
39
32
  block?: boolean | undefined;
40
33
  variant?: "small" | "large" | undefined;
41
34
  role?: React.AriaRole | undefined;
@@ -293,9 +286,8 @@ declare const AutocompleteInput: PolymorphicForwardRefComponent<React.ForwardRef
293
286
  disabled?: boolean | undefined;
294
287
  hasIcon?: boolean | undefined;
295
288
  contrast?: boolean | undefined;
296
- validationStatus?: "error" | "warning" | undefined;
297
289
  } & {
298
290
  theme?: any;
299
- }, "maxWidth" | "minWidth" | "width" | "size" | "block" | "variant" | "sx" | "disabled" | "contrast">, string | number | symbol> & React.RefAttributes<HTMLInputElement>>, InternalAutocompleteInputProps>;
291
+ }, "maxWidth" | "minWidth" | "width" | "theme" | "block" | "variant" | "sx" | "disabled" | "contrast">, string | number | symbol> & React.RefAttributes<HTMLInputElement>>, InternalAutocompleteInputProps>;
300
292
  export declare type AutocompleteInputProps = ComponentProps<typeof AutocompleteInput>;
301
293
  export default AutocompleteInput;
@@ -25,5 +25,5 @@ export declare type CheckboxProps = {
25
25
  /**
26
26
  * An accessible, native checkbox component
27
27
  */
28
- declare const Checkbox: React.ForwardRefExoticComponent<Pick<CheckboxProps, "sx" | keyof React.InputHTMLAttributes<HTMLInputElement> | "validationStatus" | "indeterminate"> & React.RefAttributes<HTMLInputElement>>;
28
+ declare const Checkbox: React.ForwardRefExoticComponent<Pick<CheckboxProps, "sx" | keyof React.InputHTMLAttributes<HTMLInputElement> | "indeterminate" | "validationStatus"> & React.RefAttributes<HTMLInputElement>>;
29
29
  export default Checkbox;
@@ -0,0 +1,6 @@
1
+ import { ComponentPropsWithRef } from 'react';
2
+ import { ForwardRefComponent as PolymorphicForwardRefComponent } from '@radix-ui/react-polymorphic';
3
+ import { ButtonProps } from './types';
4
+ declare const ButtonBase: PolymorphicForwardRefComponent<"a" | "button", ButtonProps>;
5
+ export declare type ButtonBaseProps = ComponentPropsWithRef<typeof ButtonBase>;
6
+ export default ButtonBase;
@@ -0,0 +1,47 @@
1
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
3
+ import React, { forwardRef } from 'react';
4
+ import Box from '../Box';
5
+ import { merge } from '../sx';
6
+ import { useTheme } from '../ThemeProvider';
7
+ import { StyledButton } from './types';
8
+ import { getVariantStyles, getSizeStyles, getButtonStyles } from './styles';
9
+ const ButtonBase = /*#__PURE__*/forwardRef(({
10
+ children,
11
+ as: Component = 'button',
12
+ sx: sxProp = {},
13
+ ...props
14
+ }, forwardedRef) => {
15
+ const {
16
+ leadingIcon: LeadingIcon,
17
+ trailingIcon: TrailingIcon,
18
+ variant = 'default',
19
+ size = 'medium'
20
+ } = props;
21
+ const {
22
+ theme
23
+ } = useTheme();
24
+ const iconWrapStyles = {
25
+ display: 'inline-block'
26
+ };
27
+ const sxStyles = merge.all([getButtonStyles(theme), getSizeStyles(size, variant, false), getVariantStyles(variant, theme), sxProp]);
28
+ return /*#__PURE__*/React.createElement(StyledButton, _extends({
29
+ as: Component,
30
+ sx: sxStyles
31
+ }, props, {
32
+ ref: forwardedRef
33
+ }), LeadingIcon && /*#__PURE__*/React.createElement(Box, {
34
+ as: "span",
35
+ "data-component": "leadingIcon",
36
+ sx: iconWrapStyles
37
+ }, /*#__PURE__*/React.createElement(LeadingIcon, null)), /*#__PURE__*/React.createElement("span", {
38
+ "data-component": "text"
39
+ }, children), TrailingIcon && /*#__PURE__*/React.createElement(Box, {
40
+ as: "span",
41
+ "data-component": "trailingIcon",
42
+ sx: { ...iconWrapStyles,
43
+ ml: 2
44
+ }
45
+ }, /*#__PURE__*/React.createElement(TrailingIcon, null)));
46
+ });
47
+ export default ButtonBase;
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ import { ForwardRefComponent as PolymorphicForwardRefComponent } from '@radix-ui/react-polymorphic';
3
+ declare const LinkButton: PolymorphicForwardRefComponent<"a", Omit<(Pick<React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, "key" | keyof React.AnchorHTMLAttributes<HTMLAnchorElement>> & {
4
+ ref?: ((instance: HTMLAnchorElement | null) => void) | React.RefObject<HTMLAnchorElement> | null | undefined;
5
+ }) | (Pick<React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "key" | keyof React.ButtonHTMLAttributes<HTMLButtonElement>> & {
6
+ ref?: ((instance: HTMLButtonElement | null) => void) | React.RefObject<HTMLButtonElement> | null | undefined;
7
+ }), string | number | symbol> & {
8
+ leadingIcon?: React.FunctionComponent<import("@primer/octicons-react/dist/icons").IconProps> | undefined;
9
+ trailingIcon?: React.FunctionComponent<import("@primer/octicons-react/dist/icons").IconProps> | undefined;
10
+ children: React.ReactNode;
11
+ } & {
12
+ variant?: import("./types").VariantType | undefined;
13
+ size?: import("./types").Size | undefined;
14
+ disabled?: boolean | undefined;
15
+ } & import("../sx").SxProp & React.HTMLAttributes<HTMLButtonElement> & {
16
+ [x: string]: any;
17
+ [x: number]: any;
18
+ } & {
19
+ theme?: any;
20
+ } & {
21
+ as?: string | React.ComponentType<any> | undefined;
22
+ forwardedAs?: string | React.ComponentType<any> | undefined;
23
+ } & {
24
+ as?: "a" | "button" | undefined;
25
+ }>;
26
+ export default LinkButton;
@@ -0,0 +1,15 @@
1
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
3
+ import React, { forwardRef } from 'react';
4
+ import ButtonBase from './button-base';
5
+ const LinkButton = /*#__PURE__*/forwardRef(({
6
+ children,
7
+ as: Component = 'a',
8
+ ...props
9
+ }, forwardedRef) => {
10
+ return /*#__PURE__*/React.createElement(ButtonBase, _extends({
11
+ as: Component,
12
+ ref: forwardedRef
13
+ }, props), children);
14
+ });
15
+ export default LinkButton;
@@ -1,13 +1,4 @@
1
1
  import React from 'react';
2
- import { SxProp } from '../sx';
3
- import { VariantType } from './types';
4
- declare const Button: React.ForwardRefExoticComponent<{
5
- variant?: VariantType | undefined;
6
- size?: import("./types").Size | undefined;
7
- icon?: React.FunctionComponent<import("@primer/octicons-react/dist/icons").IconProps> | undefined;
8
- leadingIcon?: React.FunctionComponent<import("@primer/octicons-react/dist/icons").IconProps> | undefined;
9
- trailingIcon?: React.FunctionComponent<import("@primer/octicons-react/dist/icons").IconProps> | undefined;
10
- disabled?: boolean | undefined;
11
- children: React.ReactNode;
12
- } & SxProp & React.HTMLAttributes<HTMLButtonElement> & React.RefAttributes<HTMLButtonElement>>;
2
+ import { ButtonProps } from './types';
3
+ declare const Button: React.ForwardRefExoticComponent<Pick<ButtonProps, string | number | symbol> & React.RefAttributes<HTMLButtonElement>>;
13
4
  export { Button };
@@ -1,287 +1,16 @@
1
1
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
 
3
3
  import React, { forwardRef } from 'react';
4
- import Box from '../Box';
5
- import styled from 'styled-components';
6
- import sx, { merge } from '../sx';
7
- import { useTheme } from '../ThemeProvider';
8
- const TEXT_ROW_HEIGHT = '20px'; // custom value off the scale
9
-
10
- const getVariantStyles = (variant = 'default', theme) => {
11
- const style = {
12
- default: {
13
- color: 'btn.text',
14
- backgroundColor: 'btn.bg',
15
- boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.shadow}, ${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.insetShadow}`,
16
- '&:hover:not([disabled])': {
17
- backgroundColor: 'btn.hoverBg'
18
- },
19
- // focus must come before :active so that the active box shadow overrides
20
- '&:focus:not([disabled])': {
21
- boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.focusShadow}`
22
- },
23
- '&:active:not([disabled])': {
24
- backgroundColor: 'btn.selectedBg',
25
- boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.shadowActive}`
26
- },
27
- '&:disabled': {
28
- color: 'primer.fg.disabled',
29
- backgroundColor: 'btn.disabledBg'
30
- }
31
- },
32
- primary: {
33
- color: 'btn.primary.text',
34
- backgroundColor: 'btn.primary.bg',
35
- borderColor: 'border.subtle',
36
- boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.primary.shadow}`,
37
- '&:hover:not([disabled])': {
38
- color: 'btn.primary.hoverText',
39
- backgroundColor: 'btn.primary.hoverBg'
40
- },
41
- // focus must come before :active so that the active box shadow overrides
42
- '&:focus:not([disabled])': {
43
- boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.primary.focusShadow}`
44
- },
45
- '&:active:not([disabled])': {
46
- backgroundColor: 'btn.primary.selectedBg',
47
- boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.primary.selectedShadow}`
48
- },
49
- '&:disabled': {
50
- color: 'btn.primary.disabledText',
51
- backgroundColor: 'btn.primary.disabledBg'
52
- },
53
- '[data-component="ButtonCounter"]': {
54
- backgroundColor: 'btn.primary.counterBg',
55
- color: 'btn.primary.text'
56
- }
57
- },
58
- danger: {
59
- color: 'btn.danger.text',
60
- backgroundColor: 'btn.bg',
61
- boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.shadow}`,
62
- '&:hover:not([disabled])': {
63
- color: 'btn.danger.hoverText',
64
- backgroundColor: 'btn.danger.hoverBg',
65
- borderColor: 'btn.danger.hoverBorder',
66
- boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.danger.hoverShadow}`,
67
- '[data-component="ButtonCounter"]': {
68
- backgroundColor: 'btn.danger.hoverCounterBg',
69
- color: 'btn.danger.hoverText'
70
- }
71
- },
72
- // focus must come before :active so that the active box shadow overrides
73
- '&:focus:not([disabled])': {
74
- borderColor: 'btn.danger.focusBorder',
75
- boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.danger.focusShadow}`
76
- },
77
- '&:active:not([disabled])': {
78
- color: 'btn.danger.selectedText',
79
- backgroundColor: 'btn.danger.selectedBg',
80
- boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.danger.selectedShadow}`,
81
- borderColor: 'btn.danger.selectedBorder'
82
- },
83
- '&:disabled': {
84
- color: 'btn.danger.disabledText',
85
- backgroundColor: 'btn.danger.disabledBg',
86
- borderColor: 'btn.danger.disabledBorder',
87
- '[data-component="ButtonCounter"]': {
88
- backgroundColor: 'btn.danger.disabledCounterBg'
89
- }
90
- },
91
- '[data-component="ButtonCounter"]': {
92
- color: 'btn.danger.text',
93
- backgroundColor: 'btn.danger.counterBg'
94
- }
95
- },
96
- invisible: {
97
- color: 'accent.fg',
98
- backgroundColor: 'transparent',
99
- border: '0',
100
- boxShadow: 'none',
101
- '&:hover:not([disabled])': {
102
- backgroundColor: 'btn.hoverBg'
103
- },
104
- // focus must come before :active so that the active box shadow overrides
105
- '&:focus:not([disabled])': {
106
- boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.focusShadow}`
107
- },
108
- '&:active:not([disabled])': {
109
- backgroundColor: 'btn.selectedBg'
110
- },
111
- '&:disabled': {
112
- color: 'primer.fg.disabled'
113
- }
114
- },
115
- outline: {
116
- color: 'btn.outline.text',
117
- boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.shadow}`,
118
- '&:hover': {
119
- color: 'btn.outline.hoverText',
120
- backgroundColor: 'btn.outline.hoverBg',
121
- borderColor: 'outline.hoverBorder',
122
- boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.outline.hoverShadow}`,
123
- '[data-component="ButtonCounter"]': {
124
- backgroundColor: 'btn.outline.hoverCounterBg',
125
- color: 'btn.outline.hoverText'
126
- }
127
- },
128
- // focus must come before :active so that the active box shadow overrides
129
- '&:focus': {
130
- borderColor: 'btn.outline.focusBorder',
131
- boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.outline.focusShadow}`
132
- },
133
- '&:active:not([disabled])': {
134
- color: 'btn.outline.selectedText',
135
- backgroundColor: 'btn.outline.selectedBg',
136
- boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.outline.selectedShadow}`,
137
- borderColor: 'btn.outline.selectedBorder'
138
- },
139
- '&:disabled': {
140
- color: 'btn.outline.disabledText',
141
- backgroundColor: 'btn.outline.disabledBg',
142
- borderColor: 'btn.border',
143
- '[data-component="ButtonCounter"]': {
144
- backgroundColor: 'btn.outline.disabledCounterBg'
145
- }
146
- },
147
- '[data-component="ButtonCounter"]': {
148
- backgroundColor: 'btn.outline.counterBg',
149
- color: 'btn.outline.text'
150
- }
151
- }
152
- };
153
- return style[variant];
154
- };
155
-
156
- const getSizeStyles = (size = 'medium', variant = 'default', iconOnly) => {
157
- let paddingY, paddingX, fontSize;
158
-
159
- switch (size) {
160
- case 'small':
161
- paddingY = 3;
162
- paddingX = 12;
163
- fontSize = 0;
164
- break;
165
-
166
- case 'large':
167
- paddingY = 9;
168
- paddingX = 20;
169
- fontSize = 2;
170
- break;
171
-
172
- case 'medium':
173
- default:
174
- paddingY = 5;
175
- paddingX = 16;
176
- fontSize = 1;
177
- }
178
-
179
- if (iconOnly) {
180
- paddingX = paddingY + 2;
181
- }
182
-
183
- if (variant === 'invisible') {
184
- paddingY = paddingY + 1;
185
- }
186
-
187
- return {
188
- paddingY: `${paddingY}px`,
189
- paddingX: `${paddingX}px`,
190
- fontSize,
191
- '[data-component="ButtonCounter"]': {
192
- fontSize
193
- }
194
- };
195
- };
196
-
197
- const ButtonBase = styled.button.withConfig({
198
- displayName: "button__ButtonBase",
199
- componentId: "sc-15k5iqk-0"
200
- })(sx);
4
+ import ButtonBase from './button-base';
201
5
  const Button = /*#__PURE__*/forwardRef(({
202
6
  children,
203
- sx: sxProp = {},
204
7
  ...props
205
8
  }, forwardedRef) => {
206
- const {
207
- icon: Icon,
208
- leadingIcon: LeadingIcon,
209
- trailingIcon: TrailingIcon,
210
- variant = 'default',
211
- size = 'medium'
212
- } = props;
213
- const iconOnly = !!Icon;
214
- const {
215
- theme
216
- } = useTheme();
217
- const styles = {
218
- borderRadius: '2',
219
- border: '1px solid',
220
- borderColor: theme === null || theme === void 0 ? void 0 : theme.colors.btn.border,
221
- display: 'grid',
222
- gridTemplateAreas: '"leadingIcon text trailingIcon"',
223
- fontWeight: 'bold',
224
- lineHeight: TEXT_ROW_HEIGHT,
225
- whiteSpace: 'nowrap',
226
- verticalAlign: 'middle',
227
- cursor: 'pointer',
228
- appearance: 'none',
229
- userSelect: 'none',
230
- textDecoration: 'none',
231
- textAlign: 'center',
232
- '& > :not(:last-child)': {
233
- mr: '2'
234
- },
235
- '&:focus': {
236
- outline: 'none'
237
- },
238
- '&:disabled': {
239
- cursor: 'default'
240
- },
241
- '&:disabled svg': {
242
- opacity: '0.6'
243
- },
244
- '[data-component="leadingIcon"]': {
245
- gridArea: 'leadingIcon'
246
- },
247
- '[data-component="text"]': {
248
- gridArea: 'text'
249
- },
250
- '[data-component="trailingIcon"]': {
251
- gridArea: 'trailingIcon'
252
- }
253
- };
254
- const iconWrapStyles = {
255
- display: 'inline-block'
256
- };
257
- const sxStyles = merge.all([styles, getSizeStyles(size, variant, iconOnly), getVariantStyles(variant, theme), sxProp]);
258
9
  return /*#__PURE__*/React.createElement(ButtonBase, _extends({
259
- sx: sxStyles,
260
10
  ref: forwardedRef
261
- }, props), LeadingIcon && /*#__PURE__*/React.createElement(Box, {
262
- as: "span",
263
- "data-component": "leadingIcon",
264
- sx: iconWrapStyles,
265
- "aria-hidden": !iconOnly
266
- }, /*#__PURE__*/React.createElement(LeadingIcon, null)), /*#__PURE__*/React.createElement("span", {
267
- "data-component": "text",
268
- hidden: Icon ? true : false
269
- }, children), Icon && /*#__PURE__*/React.createElement(Box, {
270
- "data-component": "icon-only",
271
- as: "span",
272
- sx: {
273
- display: 'inline-block'
274
- },
275
- "aria-hidden": !iconOnly
276
- }, /*#__PURE__*/React.createElement(Icon, null)), TrailingIcon && /*#__PURE__*/React.createElement(Box, {
277
- as: "span",
278
- "data-component": "trailingIcon",
279
- sx: { ...iconWrapStyles,
280
- ml: 2
281
- },
282
- "aria-hidden": !iconOnly
283
- }, /*#__PURE__*/React.createElement(TrailingIcon, null)));
11
+ }, props, {
12
+ as: "button"
13
+ }), children);
284
14
  });
285
15
  Button.displayName = 'Button';
286
- Object.assign(Button, {});
287
16
  export { Button };
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { IconButtonProps } from './types';
3
+ declare const IconButton: React.ForwardRefExoticComponent<Pick<IconButtonProps, string | number | symbol> & React.RefAttributes<HTMLButtonElement>>;
4
+ export default IconButton;