@primer/components 0.0.0-202191841156 → 0.0.0-202191916821

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 (68) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/browser.esm.js +615 -615
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +180 -180
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/ActionList/Item.js +3 -3
  7. package/lib/ActionList2/Description.d.ts +5 -0
  8. package/lib/ActionList2/Description.js +45 -0
  9. package/lib/ActionList2/Divider.d.ts +8 -0
  10. package/lib/ActionList2/Divider.js +42 -0
  11. package/lib/ActionList2/Group.d.ts +8 -0
  12. package/lib/ActionList2/Group.js +39 -0
  13. package/lib/ActionList2/Header.d.ts +26 -0
  14. package/lib/ActionList2/Header.js +55 -0
  15. package/lib/ActionList2/Item.d.ts +52 -0
  16. package/lib/ActionList2/Item.js +171 -0
  17. package/lib/ActionList2/List.d.ts +18 -0
  18. package/lib/ActionList2/List.js +52 -0
  19. package/lib/ActionList2/Selection.d.ts +5 -0
  20. package/lib/ActionList2/Selection.js +67 -0
  21. package/lib/ActionList2/Visuals.d.ts +12 -0
  22. package/lib/ActionList2/Visuals.js +87 -0
  23. package/lib/ActionList2/hacks.d.ts +30 -0
  24. package/lib/ActionList2/hacks.js +38 -0
  25. package/lib/ActionList2/index.d.ts +26 -0
  26. package/lib/ActionList2/index.js +36 -0
  27. package/lib/Button/Button.js +1 -1
  28. package/lib/Button/ButtonTableList.js +1 -1
  29. package/lib/Pagination/Pagination.js +1 -1
  30. package/lib/_TextInputWrapper.js +1 -1
  31. package/lib/index.d.ts +1 -0
  32. package/lib/index.js +8 -0
  33. package/lib/utils/create-slots.d.ts +15 -0
  34. package/lib/utils/create-slots.js +101 -0
  35. package/lib/utils/use-force-update.d.ts +1 -0
  36. package/lib/utils/use-force-update.js +19 -0
  37. package/lib-esm/ActionList/Item.js +3 -3
  38. package/lib-esm/ActionList2/Description.d.ts +5 -0
  39. package/lib-esm/ActionList2/Description.js +30 -0
  40. package/lib-esm/ActionList2/Divider.d.ts +8 -0
  41. package/lib-esm/ActionList2/Divider.js +30 -0
  42. package/lib-esm/ActionList2/Group.d.ts +8 -0
  43. package/lib-esm/ActionList2/Group.js +29 -0
  44. package/lib-esm/ActionList2/Header.d.ts +26 -0
  45. package/lib-esm/ActionList2/Header.js +45 -0
  46. package/lib-esm/ActionList2/Item.d.ts +52 -0
  47. package/lib-esm/ActionList2/Item.js +172 -0
  48. package/lib-esm/ActionList2/List.d.ts +18 -0
  49. package/lib-esm/ActionList2/List.js +42 -0
  50. package/lib-esm/ActionList2/Selection.d.ts +5 -0
  51. package/lib-esm/ActionList2/Selection.js +50 -0
  52. package/lib-esm/ActionList2/Visuals.d.ts +12 -0
  53. package/lib-esm/ActionList2/Visuals.js +66 -0
  54. package/lib-esm/ActionList2/hacks.d.ts +30 -0
  55. package/lib-esm/ActionList2/hacks.js +30 -0
  56. package/lib-esm/ActionList2/index.d.ts +26 -0
  57. package/lib-esm/ActionList2/index.js +23 -0
  58. package/lib-esm/Button/Button.js +1 -1
  59. package/lib-esm/Button/ButtonTableList.js +1 -1
  60. package/lib-esm/Pagination/Pagination.js +1 -1
  61. package/lib-esm/_TextInputWrapper.js +1 -1
  62. package/lib-esm/index.d.ts +1 -0
  63. package/lib-esm/index.js +1 -0
  64. package/lib-esm/utils/create-slots.d.ts +15 -0
  65. package/lib-esm/utils/create-slots.js +80 -0
  66. package/lib-esm/utils/use-force-update.d.ts +1 -0
  67. package/lib-esm/utils/use-force-update.js +6 -0
  68. package/package.json +1 -1
@@ -0,0 +1,80 @@
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
+ });
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
+ const Slots = ({
21
+ children
22
+ }) => {
23
+ // initialise slots
24
+ const slotsDefinition = {};
25
+ slotNames.map(name => slotsDefinition[name] = null);
26
+ const slotsRef = React.useRef(slotsDefinition);
27
+ const rerenderWithSlots = useForceUpdate();
28
+ const [isMounted, setIsMounted] = React.useState(false); // fires after all the effects in children
29
+
30
+ React.useEffect(() => {
31
+ rerenderWithSlots();
32
+ setIsMounted(true);
33
+ }, [rerenderWithSlots]);
34
+ const slots = slotsRef.current;
35
+ const registerSlot = React.useCallback((name, contents) => {
36
+ slotsRef.current[name] = contents; // don't render until the component mounts = all slots are registered
37
+
38
+ if (isMounted) rerenderWithSlots();
39
+ }, [isMounted, rerenderWithSlots]); // Slot can be removed from the tree as well,
40
+ // we need to unregister them from the slot
41
+
42
+ const unregisterSlot = React.useCallback(name => {
43
+ slotsRef.current[name] = null;
44
+ rerenderWithSlots();
45
+ }, [rerenderWithSlots]);
46
+ /**
47
+ * Slots uses a render prop API so abstract the
48
+ * implementation detail of using a context provider.
49
+ */
50
+
51
+ return /*#__PURE__*/React.createElement(SlotsContext.Provider, {
52
+ value: {
53
+ registerSlot,
54
+ unregisterSlot
55
+ }
56
+ }, children(slots));
57
+ };
58
+
59
+ const Slot = ({
60
+ name,
61
+ children
62
+ }) => {
63
+ const {
64
+ registerSlot,
65
+ unregisterSlot
66
+ } = React.useContext(SlotsContext);
67
+ React.useEffect(() => {
68
+ registerSlot(name, children);
69
+ return () => unregisterSlot(name);
70
+ }, [name, children, registerSlot, unregisterSlot]);
71
+ return null;
72
+ };
73
+
74
+ return {
75
+ Slots,
76
+ Slot
77
+ };
78
+ };
79
+
80
+ export default createSlots;
@@ -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-202191841156",
3
+ "version": "0.0.0-202191916821",
4
4
  "description": "Primer react components",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib-esm/index.js",