@primer/components 0.0.0-202192822657 → 0.0.0-2021929142717

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 (166) hide show
  1. package/CHANGELOG.md +23 -1
  2. package/dist/browser.esm.js +53 -49
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +50 -46
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/ActionList/Item.d.ts +6 -0
  7. package/lib/ActionList/Item.js +5 -1
  8. package/lib/ActionList2/Description.d.ts +6 -0
  9. package/lib/ActionList2/Description.js +53 -0
  10. package/lib/ActionList2/Divider.d.ts +5 -0
  11. package/lib/ActionList2/Divider.js +33 -0
  12. package/lib/ActionList2/Group.d.ts +11 -0
  13. package/lib/ActionList2/Group.js +55 -0
  14. package/lib/ActionList2/Header.d.ts +26 -0
  15. package/lib/ActionList2/Header.js +55 -0
  16. package/lib/ActionList2/Item.d.ts +48 -0
  17. package/lib/ActionList2/Item.js +204 -0
  18. package/lib/ActionList2/List.d.ts +26 -0
  19. package/lib/ActionList2/List.js +56 -0
  20. package/lib/ActionList2/Selection.d.ts +5 -0
  21. package/lib/ActionList2/Selection.js +73 -0
  22. package/lib/ActionList2/Visuals.d.ts +11 -0
  23. package/lib/ActionList2/Visuals.js +90 -0
  24. package/lib/ActionList2/hacks.d.ts +30 -0
  25. package/lib/ActionList2/hacks.js +38 -0
  26. package/lib/ActionList2/index.d.ts +28 -0
  27. package/lib/ActionList2/index.js +42 -0
  28. package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +2 -4
  29. package/lib/Autocomplete/Autocomplete.d.ts +6 -8
  30. package/lib/Autocomplete/AutocompleteInput.d.ts +6 -8
  31. package/lib/Button/Button.d.ts +4 -4
  32. package/lib/Button/ButtonClose.d.ts +21 -21
  33. package/lib/Button/ButtonDanger.d.ts +4 -4
  34. package/lib/Button/ButtonInvisible.d.ts +4 -4
  35. package/lib/Button/ButtonOutline.d.ts +4 -4
  36. package/lib/Button/ButtonPrimary.d.ts +4 -4
  37. package/lib/CircleOcticon.d.ts +19 -19
  38. package/lib/Dialog.d.ts +21 -21
  39. package/lib/Dropdown.d.ts +82 -82
  40. package/lib/DropdownMenu/DropdownButton.d.ts +23 -23
  41. package/lib/FilterList.d.ts +19 -19
  42. package/lib/Position.d.ts +4 -4
  43. package/lib/SelectMenu/SelectMenu.d.ts +105 -107
  44. package/lib/SelectMenu/SelectMenuItem.d.ts +1 -1
  45. package/lib/SelectMenu/SelectMenuModal.d.ts +1 -1
  46. package/lib/TextInputWithTokens.d.ts +10 -8
  47. package/lib/TextInputWithTokens.js +102 -29
  48. package/lib/Timeline.d.ts +19 -19
  49. package/lib/Token/AvatarToken.d.ts +1 -1
  50. package/lib/Token/IssueLabelToken.d.ts +1 -1
  51. package/lib/Token/Token.d.ts +1 -1
  52. package/lib/Token/Token.js +13 -2
  53. package/lib/Token/TokenBase.js +0 -4
  54. package/lib/Token/_RemoveTokenButton.js +15 -2
  55. package/lib/_TextInputWrapper.js +1 -1
  56. package/lib/experiments.d.ts +1 -0
  57. package/lib/experiments.js +18 -0
  58. package/lib/sx.d.ts +2 -0
  59. package/lib/sx.js +8 -0
  60. package/lib/theme-preval.js +2 -2
  61. package/lib/utils/create-slots.d.ts +17 -0
  62. package/lib/utils/create-slots.js +105 -0
  63. package/lib/utils/testing.d.ts +1 -1
  64. package/lib/utils/use-force-update.d.ts +1 -0
  65. package/lib/utils/use-force-update.js +19 -0
  66. package/lib-esm/ActionList/Item.d.ts +6 -0
  67. package/lib-esm/ActionList/Item.js +5 -1
  68. package/lib-esm/ActionList2/Description.d.ts +6 -0
  69. package/lib-esm/ActionList2/Description.js +37 -0
  70. package/lib-esm/ActionList2/Divider.d.ts +5 -0
  71. package/lib-esm/ActionList2/Divider.js +21 -0
  72. package/lib-esm/ActionList2/Group.d.ts +11 -0
  73. package/lib-esm/ActionList2/Group.js +38 -0
  74. package/lib-esm/ActionList2/Header.d.ts +26 -0
  75. package/lib-esm/ActionList2/Header.js +45 -0
  76. package/lib-esm/ActionList2/Item.d.ts +48 -0
  77. package/lib-esm/ActionList2/Item.js +176 -0
  78. package/lib-esm/ActionList2/List.d.ts +26 -0
  79. package/lib-esm/ActionList2/List.js +38 -0
  80. package/lib-esm/ActionList2/Selection.d.ts +5 -0
  81. package/lib-esm/ActionList2/Selection.js +55 -0
  82. package/lib-esm/ActionList2/Visuals.d.ts +11 -0
  83. package/lib-esm/ActionList2/Visuals.js +68 -0
  84. package/lib-esm/ActionList2/hacks.d.ts +30 -0
  85. package/lib-esm/ActionList2/hacks.js +30 -0
  86. package/lib-esm/ActionList2/index.d.ts +28 -0
  87. package/lib-esm/ActionList2/index.js +29 -0
  88. package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +2 -4
  89. package/lib-esm/Autocomplete/Autocomplete.d.ts +6 -8
  90. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +6 -8
  91. package/lib-esm/Button/Button.d.ts +4 -4
  92. package/lib-esm/Button/ButtonClose.d.ts +21 -21
  93. package/lib-esm/Button/ButtonDanger.d.ts +4 -4
  94. package/lib-esm/Button/ButtonInvisible.d.ts +4 -4
  95. package/lib-esm/Button/ButtonOutline.d.ts +4 -4
  96. package/lib-esm/Button/ButtonPrimary.d.ts +4 -4
  97. package/lib-esm/CircleOcticon.d.ts +19 -19
  98. package/lib-esm/Dialog.d.ts +21 -21
  99. package/lib-esm/Dropdown.d.ts +82 -82
  100. package/lib-esm/DropdownMenu/DropdownButton.d.ts +23 -23
  101. package/lib-esm/FilterList.d.ts +19 -19
  102. package/lib-esm/Position.d.ts +4 -4
  103. package/lib-esm/SelectMenu/SelectMenu.d.ts +105 -107
  104. package/lib-esm/SelectMenu/SelectMenuItem.d.ts +1 -1
  105. package/lib-esm/SelectMenu/SelectMenuModal.d.ts +1 -1
  106. package/lib-esm/TextInputWithTokens.d.ts +10 -8
  107. package/lib-esm/TextInputWithTokens.js +101 -30
  108. package/lib-esm/Timeline.d.ts +19 -19
  109. package/lib-esm/Token/AvatarToken.d.ts +1 -1
  110. package/lib-esm/Token/IssueLabelToken.d.ts +1 -1
  111. package/lib-esm/Token/Token.d.ts +1 -1
  112. package/lib-esm/Token/Token.js +13 -2
  113. package/lib-esm/Token/TokenBase.js +0 -4
  114. package/lib-esm/Token/_RemoveTokenButton.js +11 -2
  115. package/lib-esm/_TextInputWrapper.js +1 -1
  116. package/lib-esm/experiments.d.ts +1 -0
  117. package/lib-esm/experiments.js +2 -0
  118. package/lib-esm/sx.d.ts +2 -0
  119. package/lib-esm/sx.js +3 -1
  120. package/lib-esm/theme-preval.js +2 -2
  121. package/lib-esm/utils/create-slots.d.ts +17 -0
  122. package/lib-esm/utils/create-slots.js +84 -0
  123. package/lib-esm/utils/testing.d.ts +1 -1
  124. package/lib-esm/utils/use-force-update.d.ts +1 -0
  125. package/lib-esm/utils/use-force-update.js +6 -0
  126. package/package.json +16 -14
  127. package/lib/DatePicker/DatePicker.d.ts +0 -48
  128. package/lib/DatePicker/DatePicker.js +0 -106
  129. package/lib/DatePicker/DatePickerAnchor.d.ts +0 -5
  130. package/lib/DatePicker/DatePickerAnchor.js +0 -194
  131. package/lib/DatePicker/DatePickerOverlay.d.ts +0 -3
  132. package/lib/DatePicker/DatePickerOverlay.js +0 -48
  133. package/lib/DatePicker/DatePickerPanel.d.ts +0 -2
  134. package/lib/DatePicker/DatePickerPanel.js +0 -126
  135. package/lib/DatePicker/Day.d.ts +0 -14
  136. package/lib/DatePicker/Day.js +0 -190
  137. package/lib/DatePicker/Month.d.ts +0 -9
  138. package/lib/DatePicker/Month.js +0 -120
  139. package/lib/DatePicker/dateParser.d.ts +0 -11
  140. package/lib/DatePicker/dateParser.js +0 -188
  141. package/lib/DatePicker/index.d.ts +0 -2
  142. package/lib/DatePicker/index.js +0 -13
  143. package/lib/DatePicker/useDatePicker.d.ts +0 -89
  144. package/lib/DatePicker/useDatePicker.js +0 -370
  145. package/lib/hooks/useDebounce.d.ts +0 -2
  146. package/lib/hooks/useDebounce.js +0 -24
  147. package/lib-esm/DatePicker/DatePicker.d.ts +0 -48
  148. package/lib-esm/DatePicker/DatePicker.js +0 -89
  149. package/lib-esm/DatePicker/DatePickerAnchor.d.ts +0 -5
  150. package/lib-esm/DatePicker/DatePickerAnchor.js +0 -167
  151. package/lib-esm/DatePicker/DatePickerOverlay.d.ts +0 -3
  152. package/lib-esm/DatePicker/DatePickerOverlay.js +0 -29
  153. package/lib-esm/DatePicker/DatePickerPanel.d.ts +0 -2
  154. package/lib-esm/DatePicker/DatePickerPanel.js +0 -100
  155. package/lib-esm/DatePicker/Day.d.ts +0 -14
  156. package/lib-esm/DatePicker/Day.js +0 -167
  157. package/lib-esm/DatePicker/Month.d.ts +0 -9
  158. package/lib-esm/DatePicker/Month.js +0 -96
  159. package/lib-esm/DatePicker/dateParser.d.ts +0 -11
  160. package/lib-esm/DatePicker/dateParser.js +0 -174
  161. package/lib-esm/DatePicker/index.d.ts +0 -2
  162. package/lib-esm/DatePicker/index.js +0 -1
  163. package/lib-esm/DatePicker/useDatePicker.d.ts +0 -89
  164. package/lib-esm/DatePicker/useDatePicker.js +0 -339
  165. package/lib-esm/hooks/useDebounce.d.ts +0 -2
  166. package/lib-esm/hooks/useDebounce.js +0 -16
@@ -2,7 +2,7 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
2
2
 
3
3
  import React from 'react';
4
4
  import { XIcon } from '@primer/octicons-react';
5
- import styled from 'styled-components';
5
+ import styled, { css } from 'styled-components';
6
6
  import { variant } from 'styled-system';
7
7
  import { get } from '../constants';
8
8
  import sx from '../sx';
@@ -34,7 +34,16 @@ const getTokenButtonIconSize = size => parseInt(tokenSizes[size || defaultTokenS
34
34
  const StyledTokenButton = styled.span.withConfig({
35
35
  displayName: "_RemoveTokenButton__StyledTokenButton",
36
36
  componentId: "sc-14lvcw1-0"
37
- })(["background-color:transparent;font-family:inherit;color:currentColor;cursor:pointer;display:inline-flex;justify-content:center;align-items:center;user-select:none;appearance:none;text-decoration:none;padding:0;transform:", ";align-self:baseline;border:0;border-radius:999px;&:hover,&:focus{background-color:", ";}&:active{background-color:", ";}", " ", ""], props => `translate(${props.borderOffset}px, -${props.borderOffset}px)`, get('colors.neutral.muted'), get('colors.neutral.subtle'), variants, sx);
37
+ })(["background-color:transparent;font-family:inherit;color:currentColor;cursor:pointer;display:inline-flex;justify-content:center;align-items:center;user-select:none;appearance:none;text-decoration:none;padding:0;transform:", ";align-self:baseline;border:0;border-radius:999px;", " &:hover,&:focus{background-color:", ";}&:active{background-color:", ";}", " ", ""], props => `translate(${props.borderOffset}px, -${props.borderOffset}px)`, props => {
38
+ switch (props.size) {
39
+ case 'large':
40
+ case 'extralarge':
41
+ return css(["margin-left:", ";"], get('space.2'));
42
+
43
+ default:
44
+ return css(["margin-left:", ";"], get('space.1'));
45
+ }
46
+ }, get('colors.neutral.muted'), get('colors.neutral.subtle'), variants, sx);
38
47
 
39
48
  const RemoveTokenButton = ({
40
49
  'aria-label': ariaLabel,
@@ -21,7 +21,7 @@ const sizeVariants = variant({
21
21
  const TextInputWrapper = styled.span.withConfig({
22
22
  displayName: "_TextInputWrapper__TextInputWrapper",
23
23
  componentId: "sc-5vfcis-0"
24
- })(["display:inline-flex;align-items:stretch;min-height:34px;font-size:", ";line-height:20px;color:", ";vertical-align:middle;background-repeat:no-repeat;background-position:right 8px center;border:1px solid ", ";border-radius:", ";outline:none;box-shadow:", ";", " .TextInput-icon{align-self:center;color:", ";margin:0 ", ";flex-shrink:0;}&:focus-within{border-color:", ";box-shadow:", ";}", " ", " ", " @media (min-width:", "){font-size:", ";}", " ", " ", " ", " ", ";"], get('fontSizes.1'), get('colors.fg.default'), get('colors.border.default'), get('radii.2'), get('shadows.primer.shadow.inset'), props => {
24
+ })(["display:inline-flex;align-items:stretch;min-height:34px;font-size:", ";line-height:20px;color:", ";vertical-align:middle;background-repeat:no-repeat;background-position:right 8px center;border:1px solid ", ";border-radius:", ";outline:none;box-shadow:", ";cursor:text;", " .TextInput-icon{align-self:center;color:", ";margin:0 ", ";flex-shrink:0;}&:focus-within{border-color:", ";box-shadow:", ";}", " ", " ", " @media (min-width:", "){font-size:", ";}", " ", " ", " ", " ", ";"], get('fontSizes.1'), get('colors.fg.default'), get('colors.border.default'), get('radii.2'), get('shadows.primer.shadow.inset'), props => {
25
25
  if (props.hasIcon) {
26
26
  return css(["padding:0;"]);
27
27
  } else {
@@ -0,0 +1 @@
1
+ export * from './ActionList2';
@@ -0,0 +1,2 @@
1
+ // Components
2
+ export * from './ActionList2';
package/lib-esm/sx.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import { SystemStyleObject } from '@styled-system/css';
2
+ import merge from 'deepmerge';
2
3
  export interface SxProp {
3
4
  sx?: SystemStyleObject;
4
5
  }
5
6
  declare const sx: (props: SxProp) => import("@styled-system/css").CssFunctionReturnType;
6
7
  export default sx;
8
+ export { merge };
package/lib-esm/sx.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import css from '@styled-system/css';
2
+ import merge from 'deepmerge';
2
3
 
3
4
  const sx = props => css(props.sx);
4
5
 
5
- export default sx;
6
+ export default sx;
7
+ export { merge };
@@ -515,7 +515,7 @@ module.exports = {
515
515
  }
516
516
  }
517
517
  },
518
- "light_colorblind": {
518
+ "light_protanopia": {
519
519
  "colors": {
520
520
  "canvasDefaultTransparent": "rgba(255,255,255,0)",
521
521
  "marketingIcon": {
@@ -2456,7 +2456,7 @@ module.exports = {
2456
2456
  }
2457
2457
  }
2458
2458
  },
2459
- "dark_colorblind": {
2459
+ "dark_protanopia": {
2460
2460
  "colors": {
2461
2461
  "canvasDefaultTransparent": "rgba(13,17,23,0)",
2462
2462
  "marketingIcon": {
@@ -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<"light" | "light_colorblind" | "dark" | "dark_dimmed" | "dark_high_contrast" | "dark_colorblind", 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 @@
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-202192822657",
3
+ "version": "0.0.0-2021929142717",
4
4
  "description": "Primer react components",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib-esm/index.js",
@@ -43,16 +43,20 @@
43
43
  "author": "GitHub, Inc.",
44
44
  "license": "MIT",
45
45
  "dependencies": {
46
- "@primer/octicons-react": "^16.1.0",
47
- "@primer/primitives": "6.0.0",
46
+ "@primer/octicons-react": "^13.0.0",
47
+ "@primer/primitives": "5.1.0",
48
48
  "@radix-ui/react-polymorphic": "0.0.14",
49
49
  "@react-aria/ssr": "3.1.0",
50
50
  "@styled-system/css": "5.1.5",
51
51
  "@styled-system/props": "5.1.5",
52
52
  "@styled-system/theme-get": "5.1.2",
53
+ "@types/history": "4.7.8",
54
+ "@types/styled-components": "5.1.11",
55
+ "@types/styled-system": "5.1.12",
56
+ "@types/styled-system__css": "5.0.16",
57
+ "@types/styled-system__theme-get": "5.0.1",
53
58
  "classnames": "2.3.1",
54
59
  "color2k": "1.2.4",
55
- "date-fns": "2.25.0",
56
60
  "deepmerge": "4.2.2",
57
61
  "focus-visible": "5.2.0",
58
62
  "styled-system": "5.1.5"
@@ -72,20 +76,15 @@
72
76
  "@rollup/plugin-commonjs": "19.0.2",
73
77
  "@rollup/plugin-node-resolve": "13.0.5",
74
78
  "@size-limit/preset-big-lib": "5.0.2",
75
- "@storybook/addon-a11y": "6.3.4",
76
- "@storybook/addon-actions": "^6.2.9",
77
- "@storybook/addon-essentials": "6.2.9",
78
- "@storybook/addon-links": "^6.2.9",
79
- "@storybook/react": "6.3.8",
79
+ "@storybook/addon-a11y": "6.3.12",
80
+ "@storybook/addon-actions": "^6.3.12",
81
+ "@storybook/addon-essentials": "6.3.12",
82
+ "@storybook/addon-links": "^6.3.12",
83
+ "@storybook/react": "6.3.12",
80
84
  "@testing-library/dom": "7.31.2",
81
85
  "@testing-library/react": "11.2.7",
82
86
  "@testing-library/react-hooks": "7.0.2",
83
87
  "@testing-library/user-event": "13.1.9",
84
- "@types/history": "4.7.9",
85
- "@types/styled-components": "5.1.15",
86
- "@types/styled-system": "5.1.13",
87
- "@types/styled-system__css": "5.0.16",
88
- "@types/styled-system__theme-get": "5.0.1",
89
88
  "@types/chroma-js": "2.1.3",
90
89
  "@types/enzyme": "3.10.9",
91
90
  "@types/jest": "26.0.23",
@@ -125,6 +124,8 @@
125
124
  "lodash.isobject": "3.0.2",
126
125
  "prettier": "2.3.2",
127
126
  "react": "17.0.2",
127
+ "react-dnd": "14.0.4",
128
+ "react-dnd-html5-backend": "14.0.2",
128
129
  "react-dom": "17.0.2",
129
130
  "react-test-renderer": "17.0.2",
130
131
  "rollup": "2.56.3",
@@ -133,6 +134,7 @@
133
134
  "rollup-plugin-visualizer": "5.5.0",
134
135
  "semver": "7.3.5",
135
136
  "size-limit": "5.0.2",
137
+ "storybook-addon-performance": "0.16.1",
136
138
  "styled-components": "4.4.1",
137
139
  "typescript": "4.2.2"
138
140
  },
@@ -1,48 +0,0 @@
1
- import React from 'react';
2
- import { OverlayProps } from '../Overlay';
3
- import { FocusTrapHookSettings } from '../hooks/useFocusTrap';
4
- import { FocusZoneHookSettings } from '../hooks/useFocusZone';
5
- import { DatePickerConfiguration, Selection } from './useDatePicker';
6
- declare type OpenGesture = 'anchor-click' | 'anchor-key-press';
7
- declare type CloseGesture = 'anchor-click' | 'click-outside' | 'escape';
8
- export interface DatePickerProps extends DatePickerConfiguration {
9
- /**
10
- * An override to the internal ref that will be spread on to the renderAnchor
11
- */
12
- anchorRef?: React.RefObject<HTMLElement>;
13
- /**
14
- * Settings to apply to the Focus Zone on the internal `Overlay` component.
15
- */
16
- focusTrapSettings?: Partial<FocusTrapHookSettings>;
17
- /**
18
- * Settings to apply to the Focus Zone on the internal `Overlay` component.
19
- */
20
- focusZoneSettings?: Partial<FocusZoneHookSettings>;
21
- initialValue?: 'today' | Date | string | null;
22
- iconOnly?: boolean;
23
- placeholder?: string;
24
- /**
25
- * Determines whether the overlay portion of the component should be shown or not
26
- */
27
- open?: boolean;
28
- /**
29
- * A callback which is called whenever the overlay is currently closed and an "open gesture" is detected.
30
- */
31
- onOpen?: (gesture: OpenGesture) => unknown;
32
- /**
33
- * A callback which is called whenever the overlay is currently open and a "close gesture" is detected.
34
- */
35
- onClose?: (gesture: CloseGesture) => unknown;
36
- /**
37
- * Props to be spread on the internal `Overlay` component.
38
- */
39
- overlayProps?: Partial<OverlayProps>;
40
- /**
41
- * A custom function component used to render the anchor element.
42
- * Will receive the selected text as `children` prop when an item is activated.
43
- */
44
- renderAnchor: <T extends React.HTMLAttributes<HTMLElement>>(props: T) => JSX.Element;
45
- value?: Selection;
46
- }
47
- export declare const DatePicker: React.FC<DatePickerProps>;
48
- export {};
@@ -1,106 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.DatePicker = void 0;
7
-
8
- var _react = _interopRequireWildcard(require("react"));
9
-
10
- var _DatePickerAnchor = require("./DatePickerAnchor");
11
-
12
- var _useDatePicker = require("./useDatePicker");
13
-
14
- var _DatePickerOverlay = require("./DatePickerOverlay");
15
-
16
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
-
18
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
-
20
- const DatePicker = ({
21
- anchorVariant,
22
- anchorRef: externalAnchorRef,
23
- confirmation,
24
- confirmUnsavedClose,
25
- dateFormat,
26
- disableWeekends,
27
- focusTrapSettings,
28
- focusZoneSettings,
29
- iconPlacement,
30
- maxDate,
31
- maxRangeSize,
32
- maxSelections,
33
- minDate,
34
- onOpen: onOpenExternal,
35
- onClose: onCloseExternal,
36
- open,
37
- overlayProps,
38
- placeholder,
39
- renderAnchor,
40
- showInputPrompt,
41
- value,
42
- variant,
43
- view,
44
- weekStartsOn
45
- }) => {
46
- const anchorRef = (0, _react.useRef)(null);
47
- const [isOpen, setIsOpen] = (0, _react.useState)(false);
48
- const datePickerConfiguration = {
49
- anchorVariant,
50
- confirmation,
51
- confirmUnsavedClose,
52
- dateFormat,
53
- disableWeekends,
54
- iconPlacement,
55
- maxDate: maxDate ? new Date(new Date(maxDate).toDateString()) : maxDate,
56
- maxRangeSize,
57
- maxSelections,
58
- minDate: minDate ? new Date(new Date(minDate).toDateString()) : minDate,
59
- placeholder,
60
- showInputPrompt,
61
- variant,
62
- view,
63
- weekStartsOn
64
- };
65
-
66
- const onOpen = gesture => {
67
- setIsOpen(true);
68
- onOpenExternal === null || onOpenExternal === void 0 ? void 0 : onOpenExternal(gesture);
69
- };
70
-
71
- const onClose = gesture => {
72
- setIsOpen(false);
73
- onCloseExternal === null || onCloseExternal === void 0 ? void 0 : onCloseExternal(gesture);
74
- };
75
-
76
- const toggleIsOpen = () => {
77
- if (isOpen) {
78
- setIsOpen(false);
79
- onCloseExternal === null || onCloseExternal === void 0 ? void 0 : onCloseExternal('anchor-click');
80
- } else {
81
- setIsOpen(true);
82
- onCloseExternal === null || onCloseExternal === void 0 ? void 0 : onCloseExternal('anchor-click');
83
- }
84
- };
85
-
86
- return /*#__PURE__*/_react.default.createElement(_useDatePicker.DatePickerProvider, {
87
- configuration: datePickerConfiguration,
88
- value: value,
89
- closePicker: () => setIsOpen(false)
90
- }, /*#__PURE__*/_react.default.createElement(_DatePickerAnchor.DatePickerAnchor, {
91
- ref: anchorRef,
92
- onAction: toggleIsOpen
93
- }), /*#__PURE__*/_react.default.createElement(_DatePickerOverlay.DatePickerOverlay, {
94
- anchorRef: externalAnchorRef !== null && externalAnchorRef !== void 0 ? externalAnchorRef : anchorRef,
95
- renderAnchor: renderAnchor,
96
- open: open !== null && open !== void 0 ? open : isOpen,
97
- onOpen: onOpen,
98
- onClose: onClose,
99
- overlayProps: overlayProps,
100
- focusTrapSettings: focusTrapSettings,
101
- focusZoneSettings: focusZoneSettings
102
- }));
103
- };
104
-
105
- exports.DatePicker = DatePicker;
106
- DatePicker.displayName = "DatePicker";
@@ -1,5 +0,0 @@
1
- import React from 'react';
2
- export interface DatePickerAnchorProps {
3
- onAction?: (event?: React.MouseEvent<HTMLDivElement> | React.KeyboardEvent<HTMLDivElement>) => void;
4
- }
5
- export declare const DatePickerAnchor: React.ForwardRefExoticComponent<DatePickerAnchorProps & React.RefAttributes<HTMLDivElement>>;
@@ -1,194 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.DatePickerAnchor = void 0;
7
-
8
- var _octiconsReact = require("@primer/octicons-react");
9
-
10
- var _styledComponents = _interopRequireDefault(require("styled-components"));
11
-
12
- var _react = _interopRequireWildcard(require("react"));
13
-
14
- var _Button = _interopRequireWildcard(require("../Button"));
15
-
16
- var _Text = _interopRequireDefault(require("../Text"));
17
-
18
- var _constants = require("../constants");
19
-
20
- var _StyledOcticon = _interopRequireDefault(require("../StyledOcticon"));
21
-
22
- var _useDatePicker = _interopRequireDefault(require("./useDatePicker"));
23
-
24
- var _TextInput = _interopRequireDefault(require("../TextInput"));
25
-
26
- var _Box = _interopRequireDefault(require("../Box"));
27
-
28
- var _dateParser = require("./dateParser");
29
-
30
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
31
-
32
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
33
-
34
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
-
36
- const DatePickerAnchorButton = (0, _styledComponents.default)(_Button.default).withConfig({
37
- displayName: "DatePickerAnchor__DatePickerAnchorButton",
38
- componentId: "sc-8gpb9d-0"
39
- })(["align-items:center;display:flex;flex-direction:row;justify-content:space-between;max-width:350px;overflow:hidden;& ", " ~ svg{margin-left:", ";}& svg ~ ", "{margin-left:", ";}"], _Text.default, (0, _constants.get)('space.2'), _Text.default, (0, _constants.get)('space.2'));
40
-
41
- const DatePickerAnchor = /*#__PURE__*/_react.default.forwardRef(({
42
- onAction
43
- }, ref) => {
44
- const {
45
- configuration: {
46
- anchorVariant,
47
- iconPlacement,
48
- placeholder,
49
- showInputPrompt,
50
- variant
51
- },
52
- disabled,
53
- formattedDate,
54
- onDateInput
55
- } = (0, _useDatePicker.default)();
56
- const [inputValue, setInputValue] = (0, _react.useState)(formattedDate);
57
- const inputRef = (0, _react.useRef)(null);
58
- const keyPressHandler = (0, _react.useCallback)(event => {
59
- if (disabled) {
60
- return;
61
- }
62
-
63
- if ([' ', 'Enter'].includes(event.key)) {
64
- onAction === null || onAction === void 0 ? void 0 : onAction(event);
65
- }
66
- }, [disabled, onAction]);
67
- const clickHandler = (0, _react.useCallback)(event => {
68
- if (disabled) {
69
- return;
70
- }
71
-
72
- onAction === null || onAction === void 0 ? void 0 : onAction(event);
73
- }, [disabled, onAction]);
74
- (0, _react.useEffect)(() => {
75
- if (document.activeElement !== inputRef.current) {
76
- setInputValue(formattedDate);
77
- }
78
- }, [formattedDate]);
79
- const onInputChangeHandler = (0, _react.useCallback)(e => {
80
- const value = e.currentTarget.value;
81
-
82
- if (!value) {
83
- setInputValue(value);
84
- return;
85
- }
86
-
87
- const parsedDate = (0, _dateParser.parseDate)(value, variant);
88
-
89
- if (parsedDate) {
90
- onDateInput(parsedDate);
91
- }
92
- }, [onDateInput, variant]);
93
-
94
- const onBlurHandler = () => {
95
- setInputValue(formattedDate);
96
- };
97
-
98
- if (anchorVariant === 'input') {
99
- const calendarButton = side => /*#__PURE__*/_react.default.createElement(_Button.ButtonInvisible, {
100
- onClick: clickHandler,
101
- sx: {
102
- width: '32px',
103
- px: '6px',
104
- position: 'absolute',
105
- [side]: '1px',
106
- top: '1px',
107
- bottom: '1px'
108
- }
109
- }, /*#__PURE__*/_react.default.createElement(_StyledOcticon.default, {
110
- icon: _octiconsReact.CalendarIcon
111
- }));
112
-
113
- const inputSx = () => {
114
- let sxObject = {};
115
-
116
- if (iconPlacement === 'start') {
117
- sxObject = { ...sxObject,
118
- pl: 5,
119
- pr: 2
120
- };
121
- } else if (iconPlacement === 'end') {
122
- sxObject = { ...sxObject,
123
- pl: 2,
124
- pr: 5
125
- };
126
- }
127
-
128
- if (showInputPrompt) {
129
- sxObject = { ...sxObject,
130
- pt: '20px'
131
- };
132
- }
133
-
134
- return sxObject;
135
- };
136
-
137
- const promptSx = () => {
138
- let sxObject = {
139
- position: 'absolute',
140
- top: '2px',
141
- fontSize: 0,
142
- color: 'fg.subtle'
143
- };
144
-
145
- if (iconPlacement === 'start') {
146
- sxObject = { ...sxObject,
147
- left: '36px'
148
- };
149
- }
150
-
151
- return sxObject;
152
- };
153
-
154
- return /*#__PURE__*/_react.default.createElement(_Box.default, {
155
- ref: ref,
156
- sx: {
157
- position: 'relative',
158
- display: 'flex',
159
- flex: 1
160
- }
161
- }, iconPlacement === 'start' && calendarButton('left'), showInputPrompt && /*#__PURE__*/_react.default.createElement(_Text.default, {
162
- sx: promptSx()
163
- }, "MM/DD/YYYY"), /*#__PURE__*/_react.default.createElement(_TextInput.default, {
164
- ref: inputRef,
165
- placeholder: placeholder,
166
- value: inputValue,
167
- onChange: onInputChangeHandler,
168
- sx: inputSx(),
169
- onBlur: onBlurHandler
170
- }), iconPlacement === 'end' && calendarButton('right'));
171
- }
172
-
173
- const calendarIcon = () => /*#__PURE__*/_react.default.createElement(_StyledOcticon.default, {
174
- icon: _octiconsReact.CalendarIcon,
175
- color: "fg.muted",
176
- sx: {
177
- my: '2px'
178
- }
179
- });
180
-
181
- return /*#__PURE__*/_react.default.createElement(_Box.default, {
182
- ref: ref
183
- }, /*#__PURE__*/_react.default.createElement(DatePickerAnchorButton, {
184
- onClick: clickHandler,
185
- onKeyPress: keyPressHandler
186
- }, iconPlacement === 'start' && calendarIcon(), anchorVariant !== 'icon-only' && /*#__PURE__*/_react.default.createElement(_Text.default, {
187
- sx: {
188
- overflow: 'hidden',
189
- textOverflow: 'ellipsis'
190
- }
191
- }, formattedDate), iconPlacement === 'end' && calendarIcon()));
192
- });
193
-
194
- exports.DatePickerAnchor = DatePickerAnchor;
@@ -1,3 +0,0 @@
1
- import React from 'react';
2
- import { AnchoredOverlayProps } from '../AnchoredOverlay';
3
- export declare const DatePickerOverlay: React.FC<AnchoredOverlayProps>;