@primer/components 0.0.0-20219283497 → 0.0.0-2021929153151

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 (162) hide show
  1. package/CHANGELOG.md +19 -1
  2. package/dist/browser.esm.js +447 -440
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +446 -439
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/ActionList2/Description.d.ts +6 -0
  7. package/lib/ActionList2/Description.js +53 -0
  8. package/lib/ActionList2/Divider.d.ts +5 -0
  9. package/lib/ActionList2/Divider.js +33 -0
  10. package/lib/ActionList2/Group.d.ts +11 -0
  11. package/lib/ActionList2/Group.js +55 -0
  12. package/lib/ActionList2/Header.d.ts +26 -0
  13. package/lib/ActionList2/Header.js +55 -0
  14. package/lib/ActionList2/Item.d.ts +48 -0
  15. package/lib/ActionList2/Item.js +204 -0
  16. package/lib/ActionList2/List.d.ts +26 -0
  17. package/lib/ActionList2/List.js +56 -0
  18. package/lib/ActionList2/Selection.d.ts +5 -0
  19. package/lib/ActionList2/Selection.js +73 -0
  20. package/lib/ActionList2/Visuals.d.ts +11 -0
  21. package/lib/ActionList2/Visuals.js +90 -0
  22. package/lib/ActionList2/hacks.d.ts +30 -0
  23. package/lib/ActionList2/hacks.js +38 -0
  24. package/lib/ActionList2/index.d.ts +28 -0
  25. package/lib/ActionList2/index.js +42 -0
  26. package/lib/ActionMenu.js +2 -2
  27. package/lib/Autocomplete/Autocomplete.d.ts +30 -30
  28. package/lib/Autocomplete/AutocompleteInput.d.ts +30 -30
  29. package/lib/Button/Button.d.ts +30 -30
  30. package/lib/Button/ButtonBase.d.ts +1 -1
  31. package/lib/Button/ButtonClose.d.ts +35 -35
  32. package/lib/Button/ButtonDanger.d.ts +30 -30
  33. package/lib/Button/ButtonInvisible.d.ts +30 -30
  34. package/lib/Button/ButtonOutline.d.ts +30 -30
  35. package/lib/Button/ButtonPrimary.d.ts +30 -30
  36. package/lib/Button/ButtonStyles.js +1 -1
  37. package/lib/CircleBadge.d.ts +2 -2
  38. package/lib/CircleOcticon.d.ts +38 -38
  39. package/lib/Dialog/Dialog.d.ts +4 -4
  40. package/lib/Dialog/Dialog.js +22 -12
  41. package/lib/Dialog.d.ts +41 -41
  42. package/lib/Dropdown.d.ts +215 -137
  43. package/lib/Dropdown.js +5 -6
  44. package/lib/DropdownMenu/DropdownButton.d.ts +37 -37
  45. package/lib/FilterList.d.ts +30 -30
  46. package/lib/Flash.d.ts +1 -1
  47. package/lib/Label.d.ts +1 -1
  48. package/lib/Position.d.ts +4 -4
  49. package/lib/SelectMenu/SelectMenu.d.ts +187 -187
  50. package/lib/SelectMenu/SelectMenuItem.d.ts +1 -1
  51. package/lib/SelectMenu/SelectMenuModal.d.ts +1 -1
  52. package/lib/TextInputWithTokens.d.ts +34 -30
  53. package/lib/TextInputWithTokens.js +102 -29
  54. package/lib/Timeline.d.ts +39 -39
  55. package/lib/Token/AvatarToken.d.ts +1 -1
  56. package/lib/Token/IssueLabelToken.d.ts +1 -1
  57. package/lib/Token/Token.d.ts +1 -1
  58. package/lib/Token/Token.js +13 -2
  59. package/lib/Token/TokenBase.js +0 -4
  60. package/lib/Token/_RemoveTokenButton.js +15 -2
  61. package/lib/_TextInputWrapper.js +1 -1
  62. package/lib/constants.js +1 -3
  63. package/lib/experiments.d.ts +1 -0
  64. package/lib/experiments.js +18 -0
  65. package/lib/index.d.ts +0 -2
  66. package/lib/index.js +0 -8
  67. package/lib/sx.d.ts +10 -2
  68. package/lib/sx.js +8 -0
  69. package/lib/theme.d.ts +78 -0
  70. package/lib/theme.js +3 -1
  71. package/lib/utils/create-slots.d.ts +17 -0
  72. package/lib/utils/create-slots.js +105 -0
  73. package/lib/utils/testing.d.ts +1 -1
  74. package/lib/utils/types/KeyPaths.d.ts +3 -0
  75. package/lib/utils/types/KeyPaths.js +1 -0
  76. package/lib/utils/use-force-update.d.ts +1 -0
  77. package/lib/utils/use-force-update.js +19 -0
  78. package/lib-esm/ActionList2/Description.d.ts +6 -0
  79. package/lib-esm/ActionList2/Description.js +37 -0
  80. package/lib-esm/ActionList2/Divider.d.ts +5 -0
  81. package/lib-esm/ActionList2/Divider.js +21 -0
  82. package/lib-esm/ActionList2/Group.d.ts +11 -0
  83. package/lib-esm/ActionList2/Group.js +38 -0
  84. package/lib-esm/ActionList2/Header.d.ts +26 -0
  85. package/lib-esm/ActionList2/Header.js +45 -0
  86. package/lib-esm/ActionList2/Item.d.ts +48 -0
  87. package/lib-esm/ActionList2/Item.js +176 -0
  88. package/lib-esm/ActionList2/List.d.ts +26 -0
  89. package/lib-esm/ActionList2/List.js +38 -0
  90. package/lib-esm/ActionList2/Selection.d.ts +5 -0
  91. package/lib-esm/ActionList2/Selection.js +55 -0
  92. package/lib-esm/ActionList2/Visuals.d.ts +11 -0
  93. package/lib-esm/ActionList2/Visuals.js +68 -0
  94. package/lib-esm/ActionList2/hacks.d.ts +30 -0
  95. package/lib-esm/ActionList2/hacks.js +30 -0
  96. package/lib-esm/ActionList2/index.d.ts +28 -0
  97. package/lib-esm/ActionList2/index.js +29 -0
  98. package/lib-esm/ActionMenu.js +2 -2
  99. package/lib-esm/Autocomplete/Autocomplete.d.ts +30 -30
  100. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +30 -30
  101. package/lib-esm/Button/Button.d.ts +30 -30
  102. package/lib-esm/Button/ButtonBase.d.ts +1 -1
  103. package/lib-esm/Button/ButtonClose.d.ts +35 -35
  104. package/lib-esm/Button/ButtonDanger.d.ts +30 -30
  105. package/lib-esm/Button/ButtonInvisible.d.ts +30 -30
  106. package/lib-esm/Button/ButtonOutline.d.ts +30 -30
  107. package/lib-esm/Button/ButtonPrimary.d.ts +30 -30
  108. package/lib-esm/Button/ButtonStyles.js +1 -1
  109. package/lib-esm/CircleBadge.d.ts +2 -2
  110. package/lib-esm/CircleOcticon.d.ts +38 -38
  111. package/lib-esm/Dialog/Dialog.d.ts +4 -4
  112. package/lib-esm/Dialog/Dialog.js +21 -12
  113. package/lib-esm/Dialog.d.ts +41 -41
  114. package/lib-esm/Dropdown.d.ts +215 -137
  115. package/lib-esm/Dropdown.js +3 -4
  116. package/lib-esm/DropdownMenu/DropdownButton.d.ts +37 -37
  117. package/lib-esm/FilterList.d.ts +30 -30
  118. package/lib-esm/Flash.d.ts +1 -1
  119. package/lib-esm/Label.d.ts +1 -1
  120. package/lib-esm/Position.d.ts +4 -4
  121. package/lib-esm/SelectMenu/SelectMenu.d.ts +187 -187
  122. package/lib-esm/SelectMenu/SelectMenuItem.d.ts +1 -1
  123. package/lib-esm/SelectMenu/SelectMenuModal.d.ts +1 -1
  124. package/lib-esm/TextInputWithTokens.d.ts +34 -30
  125. package/lib-esm/TextInputWithTokens.js +101 -30
  126. package/lib-esm/Timeline.d.ts +39 -39
  127. package/lib-esm/Token/AvatarToken.d.ts +1 -1
  128. package/lib-esm/Token/IssueLabelToken.d.ts +1 -1
  129. package/lib-esm/Token/Token.d.ts +1 -1
  130. package/lib-esm/Token/Token.js +13 -2
  131. package/lib-esm/Token/TokenBase.js +0 -4
  132. package/lib-esm/Token/_RemoveTokenButton.js +11 -2
  133. package/lib-esm/_TextInputWrapper.js +1 -1
  134. package/lib-esm/constants.js +1 -3
  135. package/lib-esm/experiments.d.ts +1 -0
  136. package/lib-esm/experiments.js +2 -0
  137. package/lib-esm/index.d.ts +0 -2
  138. package/lib-esm/index.js +0 -1
  139. package/lib-esm/sx.d.ts +10 -2
  140. package/lib-esm/sx.js +3 -1
  141. package/lib-esm/theme.d.ts +78 -0
  142. package/lib-esm/theme.js +2 -1
  143. package/lib-esm/utils/create-slots.d.ts +17 -0
  144. package/lib-esm/utils/create-slots.js +84 -0
  145. package/lib-esm/utils/testing.d.ts +1 -1
  146. package/lib-esm/utils/types/KeyPaths.d.ts +3 -0
  147. package/lib-esm/utils/types/KeyPaths.js +1 -0
  148. package/lib-esm/utils/use-force-update.d.ts +1 -0
  149. package/lib-esm/utils/use-force-update.js +6 -0
  150. package/package.json +4 -1
  151. package/lib/NewButton/button.d.ts +0 -581
  152. package/lib/NewButton/button.js +0 -297
  153. package/lib/NewButton/counter.d.ts +0 -6
  154. package/lib/NewButton/counter.js +0 -33
  155. package/lib/NewButton/index.d.ts +0 -4
  156. package/lib/NewButton/index.js +0 -21
  157. package/lib-esm/NewButton/button.d.ts +0 -581
  158. package/lib-esm/NewButton/button.js +0 -273
  159. package/lib-esm/NewButton/counter.d.ts +0 -6
  160. package/lib-esm/NewButton/counter.js +0 -21
  161. package/lib-esm/NewButton/index.d.ts +0 -4
  162. package/lib-esm/NewButton/index.js +0 -3
@@ -1,2 +1,80 @@
1
1
  import { theme } from './theme-preval';
2
+ import { KeyPaths } from './utils/types/KeyPaths';
2
3
  export default theme;
4
+ declare type ThemeColors = {
5
+ fg: {
6
+ default: string;
7
+ muted: string;
8
+ subtle: string;
9
+ onEmphasis: string;
10
+ };
11
+ canvas: {
12
+ default: string;
13
+ overlay: string;
14
+ inset: string;
15
+ subtle: string;
16
+ };
17
+ border: {
18
+ default: string;
19
+ muted: string;
20
+ subtle: string;
21
+ };
22
+ neutral: {
23
+ emphasisPlus: string;
24
+ emphasis: string;
25
+ muted: string;
26
+ subtle: string;
27
+ };
28
+ accent: {
29
+ fg: string;
30
+ emphasis: string;
31
+ muted: string;
32
+ subtle: string;
33
+ };
34
+ success: {
35
+ fg: string;
36
+ emphasis: string;
37
+ muted: string;
38
+ subtle: string;
39
+ };
40
+ attention: {
41
+ fg: string;
42
+ emphasis: string;
43
+ muted: string;
44
+ subtle: string;
45
+ };
46
+ severe: {
47
+ fg: string;
48
+ emphasis: string;
49
+ muted: string;
50
+ subtle: string;
51
+ };
52
+ danger: {
53
+ fg: string;
54
+ emphasis: string;
55
+ muted: string;
56
+ subtle: string;
57
+ };
58
+ done: {
59
+ fg: string;
60
+ emphasis: string;
61
+ muted: string;
62
+ subtle: string;
63
+ };
64
+ sponsors: {
65
+ fg: string;
66
+ emphasis: string;
67
+ muted: string;
68
+ subtle: string;
69
+ };
70
+ };
71
+ declare type ThemeShadows = {
72
+ shadow: {
73
+ small: string;
74
+ medium: string;
75
+ large: string;
76
+ extraLarge: string;
77
+ };
78
+ };
79
+ export declare type ThemeColorPaths = KeyPaths<ThemeColors>;
80
+ export declare type ThemeShadowPaths = KeyPaths<ThemeShadows>;
package/lib-esm/theme.js CHANGED
@@ -1,2 +1,3 @@
1
1
  import { theme } from './theme-preval';
2
- export default theme;
2
+ export default theme; // NOTE: for now, ThemeColors and ThemeShadows are handcrafted types. It would be nice if these
3
+ // were exports from primitives (or a different shape but derived from those exports).
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ /** createSlots is a factory that can create a
3
+ * typesafe Slots + Slot pair to use in a component definition
4
+ * For example: ActionList.Item uses createSlots to get a Slots wrapper
5
+ * + Slot component that is used by LeadingVisual, Description
6
+ */
7
+ declare const createSlots: <SlotNames extends string>(slotNames: SlotNames[]) => {
8
+ Slots: React.FC<{
9
+ context: Record<string, unknown>;
10
+ children: (slots: { [key in SlotNames]?: React.ReactNode; }) => React.ReactNode;
11
+ }>;
12
+ Slot: React.FC<{
13
+ name: SlotNames;
14
+ children: React.ReactNode | ((context: Record<string, unknown>) => React.ReactNode);
15
+ }>;
16
+ };
17
+ export default createSlots;
@@ -0,0 +1,84 @@
1
+ import React from 'react';
2
+ import { useForceUpdate } from './use-force-update';
3
+ /** createSlots is a factory that can create a
4
+ * typesafe Slots + Slot pair to use in a component definition
5
+ * For example: ActionList.Item uses createSlots to get a Slots wrapper
6
+ * + Slot component that is used by LeadingVisual, Description
7
+ */
8
+
9
+ const createSlots = slotNames => {
10
+ const SlotsContext = /*#__PURE__*/React.createContext({
11
+ registerSlot: () => null,
12
+ unregisterSlot: () => null,
13
+ context: {}
14
+ });
15
+ /** Slots uses a Double render strategy inspired by [reach-ui/descendants](https://github.com/reach/reach-ui/tree/develop/packages/descendants)
16
+ * Slot registers themself with the Slots parent.
17
+ * When all the children have mounted = registered themselves in slot,
18
+ * we re-render the parent component to render with slots
19
+ */
20
+
21
+ const Slots = ({
22
+ context,
23
+ children
24
+ }) => {
25
+ // initialise slots
26
+ const slotsDefinition = {};
27
+ slotNames.map(name => slotsDefinition[name] = null);
28
+ const slotsRef = React.useRef(slotsDefinition);
29
+ const rerenderWithSlots = useForceUpdate();
30
+ const [isMounted, setIsMounted] = React.useState(false); // fires after all the effects in children
31
+
32
+ React.useEffect(() => {
33
+ rerenderWithSlots();
34
+ setIsMounted(true);
35
+ }, [rerenderWithSlots]);
36
+ const registerSlot = React.useCallback((name, contents) => {
37
+ slotsRef.current[name] = contents; // don't render until the component mounts = all slots are registered
38
+
39
+ if (isMounted) rerenderWithSlots();
40
+ }, [isMounted, rerenderWithSlots]); // Slot can be removed from the tree as well,
41
+ // we need to unregister them from the slot
42
+
43
+ const unregisterSlot = React.useCallback(name => {
44
+ slotsRef.current[name] = null;
45
+ rerenderWithSlots();
46
+ }, [rerenderWithSlots]);
47
+ /**
48
+ * Slots uses a render prop API so abstract the
49
+ * implementation detail of using a context provider.
50
+ */
51
+
52
+ const slots = slotsRef.current;
53
+ return /*#__PURE__*/React.createElement(SlotsContext.Provider, {
54
+ value: {
55
+ registerSlot,
56
+ unregisterSlot,
57
+ context
58
+ }
59
+ }, children(slots));
60
+ };
61
+
62
+ const Slot = ({
63
+ name,
64
+ children
65
+ }) => {
66
+ const {
67
+ registerSlot,
68
+ unregisterSlot,
69
+ context
70
+ } = React.useContext(SlotsContext);
71
+ React.useEffect(() => {
72
+ registerSlot(name, typeof children === 'function' ? children(context) : children);
73
+ return () => unregisterSlot(name);
74
+ }, [name, children, registerSlot, unregisterSlot, context]);
75
+ return null;
76
+ };
77
+
78
+ return {
79
+ Slots,
80
+ Slot
81
+ };
82
+ };
83
+
84
+ export default createSlots;
@@ -53,7 +53,7 @@ export declare function render(component: React.ReactElement, theme?: {
53
53
  xlarge: string;
54
54
  };
55
55
  space: string[];
56
- colorSchemes: Record<"dark" | "light" | "light_protanopia" | "dark_dimmed" | "dark_high_contrast" | "dark_protanopia", Record<"colors" | "shadows", Partial<{
56
+ colorSchemes: Record<"light" | "light_protanopia" | "dark" | "dark_dimmed" | "dark_high_contrast" | "dark_protanopia", Record<"colors" | "shadows", Partial<{
57
57
  canvasDefaultTransparent: string;
58
58
  marketingIcon: {
59
59
  primary: string;
@@ -0,0 +1,3 @@
1
+ export declare type KeyPaths<O extends Record<string, unknown>> = {
2
+ [K in keyof O]: K extends string ? (O[K] extends string ? `${K}` : `${K}.${KeyPaths<O[K]>}`) : never;
3
+ }[keyof O];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare const useForceUpdate: () => () => void;
@@ -0,0 +1,6 @@
1
+ // Inspired from reach-ui: https://github.com/reach/reach-ui/blob/develop/packages/utils/src/use-force-update.ts
2
+ import React from 'react';
3
+ export const useForceUpdate = () => {
4
+ const [, rerender] = React.useState({});
5
+ return React.useCallback(() => rerender({}), []);
6
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/components",
3
- "version": "0.0.0-20219283497",
3
+ "version": "0.0.0-2021929153151",
4
4
  "description": "Primer react components",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib-esm/index.js",
@@ -124,6 +124,8 @@
124
124
  "lodash.isobject": "3.0.2",
125
125
  "prettier": "2.3.2",
126
126
  "react": "17.0.2",
127
+ "react-dnd": "14.0.4",
128
+ "react-dnd-html5-backend": "14.0.2",
127
129
  "react-dom": "17.0.2",
128
130
  "react-test-renderer": "17.0.2",
129
131
  "rollup": "2.56.3",
@@ -132,6 +134,7 @@
132
134
  "rollup-plugin-visualizer": "5.5.0",
133
135
  "semver": "7.3.5",
134
136
  "size-limit": "5.0.2",
137
+ "storybook-addon-performance": "0.16.1",
135
138
  "styled-components": "4.4.1",
136
139
  "typescript": "4.2.2"
137
140
  },