@primer/components 32.1.1-rc.b4502a34 → 33.0.0-rc.9f3670b7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. package/CHANGELOG.md +15 -1
  2. package/contributor-docs/CONTRIBUTING.md +14 -58
  3. package/dist/browser.esm.js +104 -108
  4. package/dist/browser.esm.js.map +1 -1
  5. package/dist/browser.umd.js +104 -108
  6. package/dist/browser.umd.js.map +1 -1
  7. package/docs/content/BranchName.md +6 -5
  8. package/docs/content/Details.md +4 -8
  9. package/docs/content/Heading.md +5 -10
  10. package/docs/content/Label.md +6 -7
  11. package/docs/content/ProgressBar.mdx +7 -6
  12. package/docs/content/Text.md +0 -6
  13. package/docs/content/{ActionList2.mdx → drafts/ActionList2.mdx} +5 -9
  14. package/docs/content/drafts/ActionMenu2.mdx +251 -0
  15. package/docs/content/status.mdx +1 -1
  16. package/docs/content/system-props.mdx +1 -1
  17. package/docs/src/@primer/gatsby-theme-doctocat/live-code-scope.js +9 -1
  18. package/docs/src/@primer/gatsby-theme-doctocat/nav.yml +1 -1
  19. package/lib/ActionList2/Divider.d.ts +3 -2
  20. package/lib/ActionList2/Divider.js +10 -5
  21. package/lib/ActionList2/Item.js +21 -5
  22. package/lib/ActionList2/List.js +11 -1
  23. package/lib/ActionList2/MenuContext.d.ts +10 -0
  24. package/lib/ActionList2/MenuContext.js +15 -0
  25. package/lib/ActionList2/Selection.js +11 -0
  26. package/lib/ActionList2/index.d.ts +1 -2
  27. package/lib/ActionMenu2.d.ts +310 -0
  28. package/lib/ActionMenu2.js +91 -0
  29. package/lib/Avatar.d.ts +1 -2
  30. package/lib/Avatar.js +1 -1
  31. package/lib/BranchName.d.ts +1 -2
  32. package/lib/BranchName.js +1 -1
  33. package/lib/Details.d.ts +1 -2
  34. package/lib/Details.js +1 -3
  35. package/lib/Dropdown.d.ts +2 -66
  36. package/lib/Heading.d.ts +1 -2
  37. package/lib/Heading.js +1 -6
  38. package/lib/ProgressBar.d.ts +16 -11
  39. package/lib/ProgressBar.js +6 -10
  40. package/lib/Spinner.d.ts +1 -2
  41. package/lib/Spinner.js +1 -3
  42. package/lib/__tests__/Avatar.test.js +4 -2
  43. package/lib/__tests__/Avatar.types.test.d.ts +3 -0
  44. package/lib/__tests__/Avatar.types.test.js +31 -0
  45. package/lib/__tests__/BranchName.types.test.d.ts +3 -0
  46. package/lib/__tests__/BranchName.types.test.js +28 -0
  47. package/lib/__tests__/Details.types.test.d.ts +3 -0
  48. package/lib/__tests__/Details.types.test.js +28 -0
  49. package/lib/__tests__/Heading.test.js +63 -30
  50. package/lib/__tests__/Heading.types.test.d.ts +3 -0
  51. package/lib/__tests__/Heading.types.test.js +28 -0
  52. package/lib/drafts.d.ts +1 -0
  53. package/lib/drafts.js +13 -0
  54. package/lib/stories/ActionMenu2.stories.js +433 -0
  55. package/lib-esm/ActionList2/Divider.d.ts +3 -2
  56. package/lib-esm/ActionList2/Divider.js +8 -5
  57. package/lib-esm/ActionList2/Item.js +19 -5
  58. package/lib-esm/ActionList2/List.js +9 -1
  59. package/lib-esm/ActionList2/MenuContext.d.ts +10 -0
  60. package/lib-esm/ActionList2/MenuContext.js +3 -0
  61. package/lib-esm/ActionList2/Selection.js +9 -0
  62. package/lib-esm/ActionList2/index.d.ts +1 -2
  63. package/lib-esm/ActionMenu2.d.ts +310 -0
  64. package/lib-esm/ActionMenu2.js +67 -0
  65. package/lib-esm/Avatar.d.ts +1 -2
  66. package/lib-esm/Avatar.js +2 -2
  67. package/lib-esm/BranchName.d.ts +1 -2
  68. package/lib-esm/BranchName.js +2 -2
  69. package/lib-esm/Details.d.ts +1 -2
  70. package/lib-esm/Details.js +1 -2
  71. package/lib-esm/Dropdown.d.ts +2 -66
  72. package/lib-esm/Heading.d.ts +1 -2
  73. package/lib-esm/Heading.js +2 -6
  74. package/lib-esm/ProgressBar.d.ts +16 -11
  75. package/lib-esm/ProgressBar.js +7 -11
  76. package/lib-esm/Spinner.d.ts +1 -2
  77. package/lib-esm/Spinner.js +1 -2
  78. package/lib-esm/__tests__/Avatar.test.js +4 -2
  79. package/lib-esm/__tests__/Avatar.types.test.d.ts +3 -0
  80. package/lib-esm/__tests__/Avatar.types.test.js +16 -0
  81. package/lib-esm/__tests__/BranchName.types.test.d.ts +3 -0
  82. package/lib-esm/__tests__/BranchName.types.test.js +13 -0
  83. package/lib-esm/__tests__/Details.types.test.d.ts +3 -0
  84. package/lib-esm/__tests__/Details.types.test.js +13 -0
  85. package/lib-esm/__tests__/Heading.test.js +62 -30
  86. package/lib-esm/__tests__/Heading.types.test.d.ts +3 -0
  87. package/lib-esm/__tests__/Heading.types.test.js +13 -0
  88. package/lib-esm/drafts.d.ts +1 -0
  89. package/lib-esm/drafts.js +2 -1
  90. package/lib-esm/stories/ActionMenu2.stories.js +376 -0
  91. package/package.json +1 -1
  92. package/src/ActionList2/Divider.tsx +13 -8
  93. package/src/ActionList2/Item.tsx +13 -3
  94. package/src/ActionList2/List.tsx +6 -2
  95. package/src/ActionList2/MenuContext.tsx +6 -0
  96. package/src/ActionList2/Selection.tsx +9 -0
  97. package/src/ActionMenu2.tsx +94 -0
  98. package/src/Avatar.tsx +2 -4
  99. package/src/BranchName.tsx +3 -3
  100. package/src/Details.tsx +1 -5
  101. package/src/Heading.tsx +2 -9
  102. package/src/ProgressBar.tsx +11 -10
  103. package/src/Spinner.tsx +1 -3
  104. package/src/__tests__/Avatar.test.tsx +1 -1
  105. package/src/__tests__/Avatar.types.test.tsx +11 -0
  106. package/src/__tests__/BranchName.types.test.tsx +11 -0
  107. package/src/__tests__/Details.types.test.tsx +11 -0
  108. package/src/__tests__/Heading.test.tsx +71 -25
  109. package/src/__tests__/Heading.types.test.tsx +11 -0
  110. package/src/drafts.ts +1 -0
  111. package/src/stories/ActionMenu2.stories.tsx +551 -0
  112. package/stats.html +1 -1
@@ -1,17 +1,22 @@
1
1
  /// <reference types="react" />
2
2
  import { WidthProps } from 'styled-system';
3
- import { SystemCommonProps } from './constants';
4
3
  import { SxProp } from './sx';
5
- import { ComponentProps } from './utils/types';
6
- declare const Bar: import("styled-components").StyledComponent<"span", any, {
7
- progress?: string | number | undefined;
8
- } & SystemCommonProps, never>;
9
- declare const ProgressContainer: import("styled-components").StyledComponent<"span", any, {
10
- inline?: boolean | undefined;
11
- barSize?: "small" | "default" | "large" | undefined;
12
- } & WidthProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.Width<import("styled-system").TLengthStyledSystem>> & SystemCommonProps & SxProp, never>;
13
- export declare type ProgressBarProps = ComponentProps<typeof ProgressContainer> & ComponentProps<typeof Bar>;
14
- declare function ProgressBar({ progress, bg, theme, ...rest }: ProgressBarProps): JSX.Element;
4
+ declare type ProgressProp = {
5
+ progress?: string | number;
6
+ };
7
+ declare const sizeMap: {
8
+ small: string;
9
+ large: string;
10
+ default: string;
11
+ };
12
+ declare type StyledProgressContainerProps = {
13
+ inline?: boolean;
14
+ barSize?: keyof typeof sizeMap;
15
+ } & WidthProps & SxProp;
16
+ export declare type ProgressBarProps = {
17
+ bg: string;
18
+ } & StyledProgressContainerProps & ProgressProp;
19
+ declare function ProgressBar({ progress, bg, ...rest }: ProgressBarProps): JSX.Element;
15
20
  declare namespace ProgressBar {
16
21
  var defaultProps: {
17
22
  bg: string;
@@ -1,14 +1,12 @@
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
1
  import React from 'react';
4
2
  import styled from 'styled-components';
5
3
  import { width } from 'styled-system';
6
- import { COMMON, get } from './constants';
4
+ import { get } from './constants';
7
5
  import sx from './sx';
8
6
  const Bar = styled.span.withConfig({
9
7
  displayName: "ProgressBar__Bar",
10
8
  componentId: "sc-1tiva13-0"
11
- })(["width:", ";", ""], props => props.progress ? `${props.progress}%` : 0, COMMON);
9
+ })(["width:", ";", ";"], props => props.progress ? `${props.progress}%` : 0, sx);
12
10
  const sizeMap = {
13
11
  small: '5px',
14
12
  large: '10px',
@@ -17,20 +15,18 @@ const sizeMap = {
17
15
  const ProgressContainer = styled.span.withConfig({
18
16
  displayName: "ProgressBar__ProgressContainer",
19
17
  componentId: "sc-1tiva13-1"
20
- })(["display:", ";overflow:hidden;background-color:", ";border-radius:", ";height:", ";", " ", " ", ";"], props => props.inline ? 'inline-flex' : 'flex', get('colors.border.default'), get('radii.1'), props => sizeMap[props.barSize || 'default'], COMMON, width, sx);
18
+ })(["display:", ";overflow:hidden;background-color:", ";border-radius:", ";height:", ";", " ", ";"], props => props.inline ? 'inline-flex' : 'flex', get('colors.border.default'), get('radii.1'), props => sizeMap[props.barSize || 'default'], width, sx);
21
19
 
22
20
  function ProgressBar({
23
21
  progress,
24
22
  bg,
25
- theme,
26
23
  ...rest
27
24
  }) {
28
- return /*#__PURE__*/React.createElement(ProgressContainer, _extends({
29
- theme: theme
30
- }, rest), /*#__PURE__*/React.createElement(Bar, {
25
+ return /*#__PURE__*/React.createElement(ProgressContainer, rest, /*#__PURE__*/React.createElement(Bar, {
31
26
  progress: progress,
32
- bg: bg,
33
- theme: theme
27
+ sx: {
28
+ bg
29
+ }
34
30
  }));
35
31
  }
36
32
 
@@ -1,5 +1,4 @@
1
1
  /// <reference types="react" />
2
- import { SystemCommonProps } from './constants';
3
2
  import { SxProp } from './sx';
4
3
  import { ComponentProps } from './utils/types';
5
4
  declare const sizeMap: {
@@ -12,6 +11,6 @@ export interface SpinnerInternalProps {
12
11
  size?: keyof typeof sizeMap;
13
12
  }
14
13
  declare function Spinner({ size: sizeKey, ...props }: SpinnerInternalProps): JSX.Element;
15
- declare const StyledSpinner: import("styled-components").StyledComponent<typeof Spinner, any, SystemCommonProps & SxProp, never>;
14
+ declare const StyledSpinner: import("styled-components").StyledComponent<typeof Spinner, any, SxProp, never>;
16
15
  export declare type SpinnerProps = ComponentProps<typeof StyledSpinner>;
17
16
  export default StyledSpinner;
@@ -2,7 +2,6 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
2
2
 
3
3
  import React from 'react';
4
4
  import styled from 'styled-components';
5
- import { COMMON } from './constants';
6
5
  import sx from './sx';
7
6
  const sizeMap = {
8
7
  small: '16px',
@@ -41,6 +40,6 @@ Spinner.displayName = "Spinner";
41
40
  const StyledSpinner = styled(Spinner).withConfig({
42
41
  displayName: "Spinner__StyledSpinner",
43
42
  componentId: "sc-14tspit-0"
44
- })(["@keyframes rotate-keyframes{100%{transform:rotate(360deg);}}animation:rotate-keyframes 1s linear infinite;", " ", ""], COMMON, sx);
43
+ })(["@keyframes rotate-keyframes{100%{transform:rotate(360deg);}}animation:rotate-keyframes 1s linear infinite;", ""], sx);
45
44
  StyledSpinner.displayName = 'Spinner';
46
45
  export default StyledSpinner;
@@ -48,9 +48,11 @@ describe('Avatar', () => {
48
48
  });
49
49
  it('respects margin props', () => {
50
50
  expect(render( /*#__PURE__*/React.createElement(Avatar, {
51
- m: 2,
52
51
  src: "primer.png",
53
- alt: ""
52
+ alt: "",
53
+ sx: {
54
+ m: 2
55
+ }
54
56
  }))).toHaveStyleRule('margin', px(theme.space[2]));
55
57
  });
56
58
  });
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ export declare function shouldAcceptCallWithNoProps(): JSX.Element;
3
+ export declare function shouldNotAcceptSystemProps(): JSX.Element;
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import Avatar from '../Avatar';
3
+ export function shouldAcceptCallWithNoProps() {
4
+ return /*#__PURE__*/React.createElement(Avatar, {
5
+ src: "https://avatars.githubusercontent.com/primer"
6
+ });
7
+ }
8
+ shouldAcceptCallWithNoProps.displayName = "shouldAcceptCallWithNoProps";
9
+ export function shouldNotAcceptSystemProps() {
10
+ // @ts-expect-error system props should not be accepted
11
+ return /*#__PURE__*/React.createElement(Avatar, {
12
+ src: "https://avatars.githubusercontent.com/primer",
13
+ backgroundColor: "thistle"
14
+ });
15
+ }
16
+ shouldNotAcceptSystemProps.displayName = "shouldNotAcceptSystemProps";
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ export declare function shouldAcceptCallWithNoProps(): JSX.Element;
3
+ export declare function shouldNotAcceptSystemProps(): JSX.Element;
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import BranchName from '../BranchName';
3
+ export function shouldAcceptCallWithNoProps() {
4
+ return /*#__PURE__*/React.createElement(BranchName, null);
5
+ }
6
+ shouldAcceptCallWithNoProps.displayName = "shouldAcceptCallWithNoProps";
7
+ export function shouldNotAcceptSystemProps() {
8
+ // @ts-expect-error system props should not be accepted
9
+ return /*#__PURE__*/React.createElement(BranchName, {
10
+ backgroundColor: "thistle"
11
+ });
12
+ }
13
+ shouldNotAcceptSystemProps.displayName = "shouldNotAcceptSystemProps";
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ export declare function shouldAcceptCallWithNoProps(): JSX.Element;
3
+ export declare function shouldNotAcceptSystemProps(): JSX.Element;
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import Details from '../Details';
3
+ export function shouldAcceptCallWithNoProps() {
4
+ return /*#__PURE__*/React.createElement(Details, null);
5
+ }
6
+ shouldAcceptCallWithNoProps.displayName = "shouldAcceptCallWithNoProps";
7
+ export function shouldNotAcceptSystemProps() {
8
+ // @ts-expect-error system props should not be accepted
9
+ return /*#__PURE__*/React.createElement(Details, {
10
+ backgroundColor: "thistle"
11
+ });
12
+ }
13
+ shouldNotAcceptSystemProps.displayName = "shouldNotAcceptSystemProps";
@@ -4,6 +4,7 @@ import { render, behavesAsComponent, checkExports } from '../utils/testing';
4
4
  import { render as HTMLRender, cleanup } from '@testing-library/react';
5
5
  import { axe, toHaveNoViolations } from 'jest-axe';
6
6
  import 'babel-polyfill';
7
+ import ThemeProvider from '../ThemeProvider';
7
8
  expect.extend(toHaveNoViolations);
8
9
  const theme = {
9
10
  breakpoints: ['400px', '640px', '960px', '1280px'],
@@ -46,54 +47,85 @@ describe('Heading', () => {
46
47
  cleanup();
47
48
  });
48
49
  it('respects fontWeight', () => {
49
- expect(render( /*#__PURE__*/React.createElement(Heading, {
50
- fontWeight: "bold",
50
+ expect(render( /*#__PURE__*/React.createElement(ThemeProvider, {
51
51
  theme: theme
52
- }))).toHaveStyleRule('font-weight', theme.fontWeights.bold);
53
- expect(render( /*#__PURE__*/React.createElement(Heading, {
54
- fontWeight: "normal",
52
+ }, /*#__PURE__*/React.createElement(Heading, {
53
+ sx: {
54
+ fontWeight: 'bold'
55
+ }
56
+ })))).toHaveStyleRule('font-weight', theme.fontWeights.bold);
57
+ expect(render( /*#__PURE__*/React.createElement(ThemeProvider, {
55
58
  theme: theme
56
- }))).toHaveStyleRule('font-weight', theme.fontWeights.normal);
57
- expect(render( /*#__PURE__*/React.createElement(Heading, {
58
- fontWeight: "semibold",
59
+ }, /*#__PURE__*/React.createElement(Heading, {
60
+ sx: {
61
+ fontWeight: 'normal'
62
+ }
63
+ })))).toHaveStyleRule('font-weight', theme.fontWeights.normal);
64
+ expect(render( /*#__PURE__*/React.createElement(ThemeProvider, {
59
65
  theme: theme
60
- }))).toHaveStyleRule('font-weight', theme.fontWeights.semibold);
61
- expect(render( /*#__PURE__*/React.createElement(Heading, {
62
- fontWeight: "light",
66
+ }, /*#__PURE__*/React.createElement(Heading, {
67
+ sx: {
68
+ fontWeight: 'semibold'
69
+ }
70
+ })))).toHaveStyleRule('font-weight', theme.fontWeights.semibold);
71
+ expect(render( /*#__PURE__*/React.createElement(ThemeProvider, {
63
72
  theme: theme
64
- }))).toHaveStyleRule('font-weight', theme.fontWeights.light);
73
+ }, /*#__PURE__*/React.createElement(Heading, {
74
+ sx: {
75
+ fontWeight: 'light'
76
+ }
77
+ })))).toHaveStyleRule('font-weight', theme.fontWeights.light);
65
78
  });
66
79
  it('respects lineHeight', () => {
67
- expect(render( /*#__PURE__*/React.createElement(Heading, {
68
- lineHeight: "normal",
80
+ expect(render( /*#__PURE__*/React.createElement(ThemeProvider, {
69
81
  theme: theme
70
- }))).toHaveStyleRule('line-height', String(theme.lineHeights.normal));
71
- expect(render( /*#__PURE__*/React.createElement(Heading, {
72
- lineHeight: "condensed",
82
+ }, /*#__PURE__*/React.createElement(Heading, {
83
+ sx: {
84
+ lineHeight: 'normal'
85
+ }
86
+ })))).toHaveStyleRule('line-height', String(theme.lineHeights.normal));
87
+ expect(render( /*#__PURE__*/React.createElement(ThemeProvider, {
73
88
  theme: theme
74
- }))).toHaveStyleRule('line-height', String(theme.lineHeights.condensed));
75
- expect(render( /*#__PURE__*/React.createElement(Heading, {
76
- lineHeight: "condensedUltra",
89
+ }, /*#__PURE__*/React.createElement(Heading, {
90
+ sx: {
91
+ lineHeight: 'condensed'
92
+ }
93
+ })))).toHaveStyleRule('line-height', String(theme.lineHeights.condensed));
94
+ expect(render( /*#__PURE__*/React.createElement(ThemeProvider, {
77
95
  theme: theme
78
- }))).toHaveStyleRule('line-height', String(theme.lineHeights.condensedUltra));
96
+ }, /*#__PURE__*/React.createElement(Heading, {
97
+ sx: {
98
+ lineHeight: 'condensedUltra'
99
+ }
100
+ })))).toHaveStyleRule('line-height', String(theme.lineHeights.condensedUltra));
79
101
  });
80
102
  it('respects fontFamily="mono"', () => {
81
- expect(render( /*#__PURE__*/React.createElement(Heading, {
82
- fontFamily: "mono",
103
+ expect(render( /*#__PURE__*/React.createElement(ThemeProvider, {
83
104
  theme: theme
84
- }))).toHaveStyleRule('font-family', theme.fonts.mono);
105
+ }, /*#__PURE__*/React.createElement(Heading, {
106
+ sx: {
107
+ fontFamily: 'mono'
108
+ }
109
+ })))).toHaveStyleRule('font-family', theme.fonts.mono);
85
110
  });
86
111
  it('renders fontSize', () => {
87
112
  for (const fontSize of theme.fontSizes) {
88
- expect(render( /*#__PURE__*/React.createElement(Heading, {
89
- fontSize: fontSize,
113
+ expect(render( /*#__PURE__*/React.createElement(ThemeProvider, {
90
114
  theme: theme
91
- }))).toHaveStyleRule('font-size', `${fontSize}`);
115
+ }, /*#__PURE__*/React.createElement(Heading, {
116
+ sx: {
117
+ fontSize
118
+ }
119
+ })))).toHaveStyleRule('font-size', `${fontSize}`);
92
120
  }
93
121
  });
94
122
  it('respects the "fontStyle" prop', () => {
95
- expect(render( /*#__PURE__*/React.createElement(Heading, {
96
- fontStyle: "italic"
97
- }))).toHaveStyleRule('font-style', 'italic');
123
+ expect(render( /*#__PURE__*/React.createElement(ThemeProvider, {
124
+ theme: theme
125
+ }, /*#__PURE__*/React.createElement(Heading, {
126
+ sx: {
127
+ fontStyle: 'italic'
128
+ }
129
+ })))).toHaveStyleRule('font-style', 'italic');
98
130
  });
99
131
  });
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ export declare function shouldAcceptCallWithNoProps(): JSX.Element;
3
+ export declare function shouldNotAcceptSystemProps(): JSX.Element;
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import Heading from '../Heading';
3
+ export function shouldAcceptCallWithNoProps() {
4
+ return /*#__PURE__*/React.createElement(Heading, null);
5
+ }
6
+ shouldAcceptCallWithNoProps.displayName = "shouldAcceptCallWithNoProps";
7
+ export function shouldNotAcceptSystemProps() {
8
+ // @ts-expect-error system props should not be accepted
9
+ return /*#__PURE__*/React.createElement(Heading, {
10
+ backgroundColor: "thistle"
11
+ });
12
+ }
13
+ shouldNotAcceptSystemProps.displayName = "shouldNotAcceptSystemProps";
@@ -6,3 +6,4 @@
6
6
  */
7
7
  export * from './ActionList2';
8
8
  export * from './NewButton';
9
+ export * from './ActionMenu2';
package/lib-esm/drafts.js CHANGED
@@ -6,4 +6,5 @@
6
6
  */
7
7
  // Components
8
8
  export * from './ActionList2';
9
- export * from './NewButton';
9
+ export * from './NewButton';
10
+ export * from './ActionMenu2';