@procore/core-react 11.25.1 → 11.25.2

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 (204) hide show
  1. package/babel.config.js +1 -1
  2. package/dist/Avatar/Avatar.styles.js +5 -5
  3. package/dist/AvatarStack/AvatarStack.styles.js +7 -7
  4. package/dist/Badge/Badge.styles.js +2 -2
  5. package/dist/Banner/Banner.styles.js +10 -10
  6. package/dist/Box/Box.styles.js +1 -1
  7. package/dist/Breadcrumbs/Breadcrumbs.styles.js +4 -4
  8. package/dist/Button/Button.styles.js +5 -5
  9. package/dist/Calendar/Calendar.styles.js +8 -8
  10. package/dist/Card/Card.styles.js +1 -1
  11. package/dist/Checkbox/Checkbox.styles.js +6 -6
  12. package/dist/ContactItem/ContactItem.styles.js +5 -5
  13. package/dist/Content/Content.styles.js +2 -2
  14. package/dist/DateInput/DateInput.styles.js +6 -6
  15. package/dist/DetailPage/DetailPage.styles.js +7 -7
  16. package/dist/Dropdown/Dropdown.styles.js +3 -3
  17. package/dist/DropdownFlyout/DropdownFlyout.styles.js +4 -4
  18. package/dist/Dropzone/Dropzone.js +1 -1
  19. package/dist/Dropzone/Dropzone.styles.js +9 -9
  20. package/dist/EmptyState/EmptyState.styles.js +6 -6
  21. package/dist/Field/Field.styles.js +3 -3
  22. package/dist/FileList/FileList.styles.js +4 -4
  23. package/dist/FileSelect/FileExplorer/FileExplorer.styles.js +9 -9
  24. package/dist/FileSelect/FileExplorer/FileExplorerSidebar.styles.js +3 -3
  25. package/dist/FileSelect/FileSelect.styles.js +2 -2
  26. package/dist/FileSelect/FileSelectDropzone/FileSelectDropzone.styles.js +3 -3
  27. package/dist/FileSelect/FileTokenList/FileTokenList.styles.js +2 -2
  28. package/dist/FileSelect/GridSource/GridSource.styles.js +6 -6
  29. package/dist/FileSelect/LocalSource/LocalSource.styles.js +4 -4
  30. package/dist/FileSelect/SourceItem/SourceItem.styles.js +3 -3
  31. package/dist/FileSelect/ThumbnailList/ThumbnailList.styles.js +6 -6
  32. package/dist/FileSelect/TreeSource/TreeSource.styles.js +1 -1
  33. package/dist/FileToken/FileToken.styles.js +4 -4
  34. package/dist/FilterToken/FilterToken.styles.js +2 -2
  35. package/dist/FlexList/FlexList.styles.js +1 -1
  36. package/dist/Form/Form.styles.js +16 -16
  37. package/dist/Grid/Grid.styles.js +2 -2
  38. package/dist/GroupSelect/GroupSelect.styles.js +1 -1
  39. package/dist/Input/Input.styles.js +1 -1
  40. package/dist/Link/Link.styles.js +1 -1
  41. package/dist/ListPage/ListPage.styles.js +8 -8
  42. package/dist/Loader/Loader.styles.js +2 -2
  43. package/dist/MenuImperative/MenuImperative.styles.js +10 -10
  44. package/dist/Modal/Modal.styles.js +13 -13
  45. package/dist/MultiSelect/MultiSelect.styles.js +6 -6
  46. package/dist/NextMenu/NextMenu.styles.js +3 -3
  47. package/dist/Notation/Notation.js +1 -1
  48. package/dist/NumberInput/NumberInput.styles.js +7 -7
  49. package/dist/Overlay/OverlayArrow.styles.js +1 -1
  50. package/dist/PageLayout/PageLayout.styles.js +13 -13
  51. package/dist/Pagination/Pagination.styles.js +5 -5
  52. package/dist/Panel/Panel.styles.js +11 -11
  53. package/dist/Pill/Pill.styles.js +2 -2
  54. package/dist/PillSelect/PillSelect.styles.js +4 -4
  55. package/dist/Popover/Popover.styles.js +2 -2
  56. package/dist/Portal/Portal.styles.js +1 -1
  57. package/dist/ProgressBar/ProgressBar.styles.js +2 -2
  58. package/dist/RadioButton/RadioButton.styles.js +3 -3
  59. package/dist/Required/Required.styles.js +3 -3
  60. package/dist/Search/Search.styles.js +5 -5
  61. package/dist/Section/Section.styles.js +6 -6
  62. package/dist/SegmentedController/SegmentedController.styles.js +4 -4
  63. package/dist/Select/Select.styles.js +7 -7
  64. package/dist/Semantic/Semantic.d.ts +6 -1
  65. package/dist/Semantic/Semantic.js +7 -1
  66. package/dist/Semantic/Semantic.js.map +1 -1
  67. package/dist/Semantic/Semantic.styles.d.ts +14 -4
  68. package/dist/Semantic/Semantic.styles.js +20 -10
  69. package/dist/Semantic/Semantic.styles.js.map +1 -1
  70. package/dist/Semantic/index.d.ts +1 -1
  71. package/dist/Semantic/index.js +1 -1
  72. package/dist/Semantic/index.js.map +1 -1
  73. package/dist/Sidebar/Sidebar.styles.js +7 -7
  74. package/dist/Slider/Slider.styles.js +5 -5
  75. package/dist/Spinner/Spinner.styles.js +7 -7
  76. package/dist/SuperSelect/SuperSelect.presets.styles.js +1 -1
  77. package/dist/SuperSelect/SuperSelect.styles.js +37 -37
  78. package/dist/Switch/Switch.styles.js +4 -4
  79. package/dist/Table/Table.styles.js +28 -28
  80. package/dist/TableShelf/TableShelf.styles.js +5 -5
  81. package/dist/Tabs/Tabs.styles.js +8 -8
  82. package/dist/Tearsheet/Tearsheet.styles.js +5 -5
  83. package/dist/TextArea/TextArea.styles.js +1 -1
  84. package/dist/TextEditorOutput/TextEditorOutput.styles.js +1 -1
  85. package/dist/Thumbnail/Thumbnail.styles.js +17 -17
  86. package/dist/ThumbnailGrid/ThumbnailGrid.styles.js +7 -7
  87. package/dist/TieredSelect/TieredSelect.styles.js +9 -9
  88. package/dist/Tile/Tile.styles.js +8 -8
  89. package/dist/Title/Title.styles.js +7 -7
  90. package/dist/Toast/Toast.styles.js +3 -3
  91. package/dist/ToggleButton/ToggleButton.styles.js +1 -1
  92. package/dist/Token/Token.styles.js +3 -3
  93. package/dist/ToolHeader/ToolHeader.styles.js +6 -6
  94. package/dist/Tooltip/Tooltip.styles.js +2 -2
  95. package/dist/Tree/Tree.styles.js +9 -9
  96. package/dist/Typeahead/Typeahead.styles.js +3 -3
  97. package/dist/Typography/Typography.styles.js +1 -1
  98. package/dist/Typography/Typography.table.story.js +2 -2
  99. package/dist/_typedoc/Avatar/Avatar.types.json +20 -20
  100. package/dist/_typedoc/AvatarStack/AvatarStack.types.json +23 -23
  101. package/dist/_typedoc/Badge/Badge.types.json +6 -6
  102. package/dist/_typedoc/Banner/Banner.types.json +13 -13
  103. package/dist/_typedoc/Box/Box.types.json +68 -68
  104. package/dist/_typedoc/Breadcrumbs/Breadcrumbs.types.json +10 -10
  105. package/dist/_typedoc/Button/Button.types.json +11 -11
  106. package/dist/_typedoc/Calendar/Calendar.types.json +80 -80
  107. package/dist/_typedoc/Card/Card.types.json +6 -6
  108. package/dist/_typedoc/Checkbox/Checkbox.types.json +9 -9
  109. package/dist/_typedoc/ContactItem/ContactItem.types.json +9 -9
  110. package/dist/_typedoc/DateInput/DateInput.types.json +35 -35
  111. package/dist/_typedoc/DateSelect/DateSelect.types.json +13 -13
  112. package/dist/_typedoc/DetailPage/DetailPage.types.json +4 -4
  113. package/dist/_typedoc/Dropdown/Dropdown.types.json +37 -37
  114. package/dist/_typedoc/DropdownFlyout/DropdownFlyout.types.json +29 -29
  115. package/dist/_typedoc/Dropzone/Dropzone.types.json +41 -41
  116. package/dist/_typedoc/EmptyState/EmptyState.types.json +14 -14
  117. package/dist/_typedoc/FileList/FileList.types.json +9 -9
  118. package/dist/_typedoc/FileSelect/FileSelect.types.json +26 -26
  119. package/dist/_typedoc/FileSelect/GridSource/GridSource.types.json +20 -20
  120. package/dist/_typedoc/FileSelect/LocalSource/LocalSource.types.json +14 -14
  121. package/dist/_typedoc/FileSelect/TreeSource/TreeSource.types.json +9 -9
  122. package/dist/_typedoc/Flex/Flex.types.json +27 -27
  123. package/dist/_typedoc/FlexList/FlexList.types.json +30 -30
  124. package/dist/_typedoc/Form/Form.types.json +726 -726
  125. package/dist/_typedoc/Grid/Grid.types.json +8 -8
  126. package/dist/_typedoc/GroupSelect/GroupSelect.types.json +52 -52
  127. package/dist/_typedoc/Input/Input.types.json +2 -2
  128. package/dist/_typedoc/Link/Link.types.json +4 -4
  129. package/dist/_typedoc/ListPage/ListPage.types.json +13 -13
  130. package/dist/_typedoc/Menu/Menu.types.json +62 -62
  131. package/dist/_typedoc/MenuImperative/MenuImperative.types.json +74 -74
  132. package/dist/_typedoc/Modal/Modal.types.json +41 -41
  133. package/dist/_typedoc/MultiSelect/MultiSelect.types.json +31 -31
  134. package/dist/_typedoc/Notation/Notation.types.json +4 -4
  135. package/dist/_typedoc/NumberInput/NumberInput.types.json +38 -38
  136. package/dist/_typedoc/OverlayTrigger/OverlayTrigger.types.json +31 -31
  137. package/dist/_typedoc/PageLayout/PageLayout.types.json +22 -22
  138. package/dist/_typedoc/Pagination/Pagination.types.json +7 -7
  139. package/dist/_typedoc/Panel/Panel.types.json +27 -27
  140. package/dist/_typedoc/Pill/Pill.types.json +2 -2
  141. package/dist/_typedoc/PillSelect/PillSelect.types.json +47 -47
  142. package/dist/_typedoc/Popover/Popover.types.json +14 -14
  143. package/dist/_typedoc/ProgressBar/ProgressBar.types.json +6 -6
  144. package/dist/_typedoc/RadioButton/RadioButton.types.json +6 -6
  145. package/dist/_typedoc/Required/Required.types.json +5 -5
  146. package/dist/_typedoc/Search/Search.types.json +18 -18
  147. package/dist/_typedoc/Section/Section.types.json +14 -14
  148. package/dist/_typedoc/SegmentedController/SegmentedController.types.json +20 -20
  149. package/dist/_typedoc/Select/Select.types.json +57 -57
  150. package/dist/_typedoc/Slider/Slider.types.json +6 -6
  151. package/dist/_typedoc/Spinner/Spinner.types.json +9 -9
  152. package/dist/_typedoc/Switch/Switch.types.json +3 -3
  153. package/dist/_typedoc/Table/Table.types.json +97 -97
  154. package/dist/_typedoc/Tabs/Tabs.types.json +17 -17
  155. package/dist/_typedoc/Tearsheet/Tearsheet.types.json +16 -16
  156. package/dist/_typedoc/TextArea/TextArea.types.json +3 -3
  157. package/dist/_typedoc/TextEditor/TextEditor.types.json +9 -9
  158. package/dist/_typedoc/TextEditorOutput/TextEditorOutput.types.json +4 -4
  159. package/dist/_typedoc/Thumbnail/Thumbnail.types.json +19 -19
  160. package/dist/_typedoc/TieredDropdown/TieredDropdown.types.json +42 -42
  161. package/dist/_typedoc/TieredSelect/TieredSelect.types.json +28 -28
  162. package/dist/_typedoc/Tile/Tile.types.json +30 -30
  163. package/dist/_typedoc/Toast/Toast.types.json +4 -4
  164. package/dist/_typedoc/ToggleButton/ToggleButton.types.json +3 -3
  165. package/dist/_typedoc/Token/Token.types.json +4 -4
  166. package/dist/_typedoc/ToolHeader/ToolHeader.types.json +10 -10
  167. package/dist/_typedoc/Tooltip/Tooltip.types.json +13 -13
  168. package/dist/_typedoc/Tree/Tree.types.json +86 -86
  169. package/dist/_typedoc/Typeahead/Typeahead.types.json +2 -2
  170. package/dist/_typedoc/Typography/Typography.types.json +8 -8
  171. package/dist/_typedoc/_utils/types.json +3 -3
  172. package/dist/index.d.ts +1 -0
  173. package/dist/index.js +1 -0
  174. package/dist/index.js.map +1 -1
  175. package/package.json +2 -2
  176. package/tsconfig.prod.json +7 -1
  177. package/dist/FileSelect/SourceItem/SourceItem.test.js +0 -53
  178. package/dist/MultiSelect/MultiSelect.test.js +0 -250
  179. package/dist/OverlayTrigger/OverlayTrigger.test.js +0 -483
  180. package/dist/SuperSelect/SuperSelect.utils.test.js +0 -717
  181. package/dist/SuperSelect/useSuperSelect.test.js +0 -1284
  182. package/dist/_hooks/OverflowObserver/OverflowObserver.test.js +0 -110
  183. package/dist/_hooks/__tests__/Anchor.test.js +0 -109
  184. package/dist/_hooks/__tests__/BoundingRect.test.js +0 -85
  185. package/dist/_hooks/__tests__/Buffer.test.js +0 -76
  186. package/dist/_hooks/__tests__/DateTime.test.js +0 -136
  187. package/dist/_hooks/__tests__/DelayedCallback.test.js +0 -119
  188. package/dist/_hooks/__tests__/DelayedToggle.test.js +0 -50
  189. package/dist/_hooks/__tests__/Deprecation.test.js +0 -58
  190. package/dist/_hooks/__tests__/Event.test.js +0 -46
  191. package/dist/_hooks/__tests__/EventListener.test.js +0 -124
  192. package/dist/_hooks/__tests__/Hotkey.test.js +0 -18
  193. package/dist/_hooks/__tests__/InjectedScript.test.js +0 -80
  194. package/dist/_hooks/__tests__/ListNavigation.test.js +0 -101
  195. package/dist/_hooks/__tests__/TextEntry.test.js +0 -92
  196. package/dist/_hooks/__tests__/Timer.test.js +0 -60
  197. package/dist/_hooks/__tests__/Trigger.test.js +0 -52
  198. package/dist/_hooks/__tests__/Visibility.test.js +0 -86
  199. package/dist/_hooks/__tests__/ZIndex.test.js +0 -76
  200. package/dist/_utils/__tests__/CalendarHelpers.test.js +0 -64
  201. package/dist/_utils/__tests__/filename.test.js +0 -27
  202. package/dist/_utils/__tests__/getAnchorPosition.test.js +0 -250
  203. package/dist/_utils/__tests__/mergeRefs.test.js +0 -58
  204. package/dist/_utils/__tests__/slotify.test.js +0 -152
@@ -1,86 +0,0 @@
1
- import {
2
- testContext,
3
- testHook,
4
- testRenderProp,
5
- } from '../../__tests__/helpers/state'
6
- import {
7
- useVisibility,
8
- useVisibilityContext,
9
- Visibility,
10
- VisibilityProvider,
11
- } from '../Visibility'
12
-
13
- const validateAPI = (api) => {
14
- expect(api.isVisible).toEqual(false)
15
- expect(api.show).toBeInstanceOf(Function)
16
- expect(api.hide).toBeInstanceOf(Function)
17
- expect(api.toggle).toBeInstanceOf(Function)
18
- }
19
-
20
- const apiTest = {
21
- test: 'api',
22
- config: {},
23
- callback: validateAPI,
24
- }
25
-
26
- const configTest = {
27
- test: 'config',
28
- config: {
29
- initialIsVisible: true,
30
- },
31
- callback: ({ isVisible }) => {
32
- expect(isVisible).toEqual(true)
33
- },
34
- }
35
-
36
- describe('Visibility', () => {
37
- testHook(useVisibility, [
38
- apiTest,
39
- configTest,
40
- {
41
- test: 'mutations',
42
- config: {},
43
- mutations: [
44
- ['show', null, ['isVisible', 'toBe', true]],
45
- ['hide', null, ['isVisible', 'toBe', false]],
46
- ['toggle', null, ['isVisible', 'toBe', true]],
47
- ['toggle', null, ['isVisible', 'toBe', false]],
48
- ],
49
- },
50
- ])
51
-
52
- testRenderProp(Visibility, 'visibility', [apiTest, configTest])
53
-
54
- testContext(VisibilityProvider, useVisibilityContext, [
55
- apiTest,
56
- configTest,
57
- {
58
- test: 'missing provider',
59
- config: {},
60
- injectProvider: false,
61
- callback: (context, { spy }) => {
62
- spy.mockImplementation(() => {})
63
-
64
- expect(context.isVisible).toBe(false)
65
- context.show()
66
- context.hide()
67
- context.toggle()
68
- expect(spy).toBeCalledTimes(3)
69
- expect(spy).toHaveBeenNthCalledWith(
70
- 1,
71
- 'Could not call `show`, please wrap your component in a `<VisibilityProvider>`'
72
- )
73
- expect(spy).toHaveBeenNthCalledWith(
74
- 2,
75
- 'Could not call `hide`, please wrap your component in a `<VisibilityProvider>`'
76
- )
77
- expect(spy).toHaveBeenNthCalledWith(
78
- 3,
79
- 'Could not call `toggle`, please wrap your component in a `<VisibilityProvider>`'
80
- )
81
-
82
- spy.mockRestore()
83
- },
84
- },
85
- ])
86
- })
@@ -1,76 +0,0 @@
1
- import {
2
- testContext,
3
- testHook,
4
- testRenderProp,
5
- } from '../../__tests__/helpers/state'
6
- import {
7
- defaultZIndex,
8
- useZIndex,
9
- useZIndexContext,
10
- ZIndex,
11
- ZIndexProvider,
12
- } from '../ZIndex'
13
-
14
- const validateAPI = (api) => {
15
- expect(api.value).toEqual(defaultZIndex)
16
- expect(api.increment).toBeInstanceOf(Function)
17
- }
18
-
19
- const apiTest = {
20
- test: 'api',
21
- config: {},
22
- callback: validateAPI,
23
- }
24
-
25
- const configTest = {
26
- test: 'config',
27
- config: { initialValue: 10 },
28
- callback: ({ value }) => expect(value).toEqual(10),
29
- }
30
-
31
- describe('ZIndex', () => {
32
- testHook(useZIndex, [
33
- apiTest,
34
- configTest,
35
- {
36
- test: 'mutations',
37
- config: {},
38
- mutations: [['increment', null, ['value', 'toBe', defaultZIndex + 1]]],
39
- },
40
- ])
41
-
42
- testRenderProp(ZIndex, 'zIndex', [apiTest, configTest])
43
-
44
- testContext(ZIndexProvider, useZIndexContext, [
45
- {
46
- test: 'api',
47
- config: {},
48
- callback: (api) => {
49
- expect(api.value).toEqual(defaultZIndex + 1)
50
- expect(api.increment).toBeInstanceOf(Function)
51
- },
52
- },
53
- {
54
- test: 'config',
55
- config: { initialValue: 10 },
56
- callback: ({ value }) => expect(value).toEqual(11),
57
- },
58
- {
59
- test: 'missing provider',
60
- config: {},
61
- injectProvider: false,
62
- callback: (context, { spy }) => {
63
- spy.mockImplementation(() => {})
64
-
65
- expect(context.value).toBe(defaultZIndex + 1)
66
- context.increment()
67
- expect(spy).toBeCalledTimes(1)
68
- expect(spy).toBeCalledWith(
69
- 'Could not call `increment`, please wrap your component in a `<ZIndexProvider>`'
70
- )
71
-
72
- spy.mockRestore()
73
- },
74
- },
75
- ])
76
- })
@@ -1,64 +0,0 @@
1
- import { addDays, getDay, startOfMonth, subDays } from 'date-fns'
2
- import {
3
- daysInCalendar,
4
- getDates,
5
- getDayOfWeekLabel,
6
- getMonthLabel,
7
- } from '../CalendarHelpers'
8
-
9
- describe('getDates', () => {
10
- it('should always have a length of daysInCalendar days', () => {
11
- const dateArray = getDates(new Date('2019-01-17'))
12
- expect(dateArray.length).toBe(daysInCalendar)
13
- })
14
-
15
- it('has the right start date', () => {
16
- const date = new Date('2019-2-2')
17
- const dateArray = getDates(date)
18
- const startDate = subDays(startOfMonth(date), getDay(startOfMonth(date)))
19
- expect(dateArray[0]).toEqual(startDate)
20
- })
21
-
22
- it('has the right end date', () => {
23
- const date = new Date('2019-2-2')
24
- const dateArray = getDates(date)
25
- const startDate = subDays(startOfMonth(date), getDay(startOfMonth(date)))
26
- const endDate = addDays(startDate, daysInCalendar - 1)
27
- expect(dateArray[daysInCalendar - 1]).toEqual(endDate)
28
- })
29
-
30
- it('in january, previous month days come from december of previous year', () => {
31
- const date = new Date('2019-01-02')
32
- const dateArray = getDates(date)
33
- expect(dateArray[0].getMonth()).toBe(11)
34
- expect(date.getFullYear() - dateArray[0].getFullYear()).toBe(1)
35
- })
36
-
37
- it('in december, next month days come from january of next year', () => {
38
- const date = new Date('2019-12-25')
39
- const dateArray = getDates(date)
40
- const lastDay = dateArray[daysInCalendar - 1]
41
- expect(lastDay.getMonth()).toBe(0)
42
- expect(lastDay.getFullYear() - date.getFullYear()).toBe(1)
43
- })
44
-
45
- it('is Jan month label', () => {
46
- const label = getMonthLabel(0, 'en-US')
47
- expect(label).toBe('Jan')
48
- })
49
-
50
- it('is Jun month label', () => {
51
- const label = getMonthLabel(5, 'en-US')
52
- expect(label).toBe('Jun')
53
- })
54
-
55
- it('is janv month label (fr)', () => {
56
- const label = getMonthLabel(0, 'fr-FR')
57
- expect(label).toBe('janv.')
58
- })
59
-
60
- it('day of week (fr)', () => {
61
- const label = getDayOfWeekLabel(0, 'fr-FR')
62
- expect(label).toBe('di')
63
- })
64
- })
@@ -1,27 +0,0 @@
1
- import { getFileExtension, parseFilename } from '../filename'
2
-
3
- describe('parseFilename', () => {
4
- it('should parse file name', () => {
5
- expect(parseFilename('a.png')).toEqual({
6
- filename: 'a',
7
- extension: 'png',
8
- isFilename: true,
9
- })
10
- })
11
-
12
- it('should handle non-filename strings', () => {
13
- expect(parseFilename('abcd-efg-hij')).toEqual({
14
- filename: '',
15
- extension: '',
16
- isFilename: false,
17
- })
18
- })
19
- })
20
-
21
- describe('getFileExtension', () => {
22
- it('should return file extension from a string', () => {
23
- expect(getFileExtension('a.png')).toEqual('png')
24
- expect(getFileExtension('abcd.jpg.png')).toEqual('png')
25
- expect(getFileExtension('abcd')).toEqual('')
26
- })
27
- })
@@ -1,250 +0,0 @@
1
- import {
2
- getAlignmentPosition,
3
- getAnchorPosition,
4
- getEdgePosition,
5
- } from '../getAnchorPosition'
6
-
7
- // TEST UTILS
8
- // ==========
9
-
10
- const getBox = (shape, position = { left: 0, top: 0 }) => ({
11
- ...position,
12
- ...shape,
13
- right: shape.width + position.left,
14
- bottom: shape.height + position.top,
15
- })
16
-
17
- const Dimensions = {
18
- target: { width: 100, height: 100 },
19
- overlay: { width: 400, height: 400 },
20
- container: { width: 1000, height: 1000 },
21
- }
22
-
23
- const Positions = {
24
- topLeft: { left: 200, top: 200 },
25
- bottomLeft: { left: 200, top: 800 },
26
- bottomRight: { left: 800, top: 800 },
27
- topRight: { left: 800, top: 200 },
28
- }
29
-
30
- const Targets = {
31
- topLeft: getBox(Dimensions.target, Positions.topLeft),
32
- topRight: getBox(Dimensions.target, Positions.topRight),
33
- bottomRight: getBox(Dimensions.target, Positions.bottomRight),
34
- bottomLeft: getBox(Dimensions.target, Positions.bottomLeft),
35
- }
36
-
37
- describe('getAnchorPosition', () => {
38
- const container = getBox(Dimensions.container)
39
- const overlay = getBox(Dimensions.overlay)
40
-
41
- it('places an overlay around a contained target', () => {
42
- const target = Targets.topLeft
43
- const position = getAnchorPosition(
44
- 'bottom-left',
45
- 0,
46
- container,
47
- target,
48
- overlay
49
- )
50
- expect(position.left).toBe(target.left)
51
- expect(position.top).toBe(target.bottom)
52
- })
53
-
54
- it('flips placement components as needed', () => {
55
- const target = Targets.bottomRight
56
- const position = getAnchorPosition(
57
- 'bottom-left',
58
- 0,
59
- container,
60
- target,
61
- overlay
62
- )
63
- expect(position.left).toBe(target.right - overlay.width)
64
- expect(position.top).toBe(target.top - overlay.height)
65
- })
66
-
67
- describe('Adjusts position according to padding', () => {
68
- const target = Targets.bottomLeft
69
- const edgePadding = 10
70
- const position = getAnchorPosition(
71
- 'top-left',
72
- edgePadding,
73
- container,
74
- target,
75
- overlay
76
- )
77
- it('adds edge padding', () => {
78
- expect(position.top).toBe(target.top - overlay.height - edgePadding)
79
- })
80
- it('does NOT add alignment padding', () => {
81
- expect(position.left).toBe(target.left)
82
- })
83
- })
84
-
85
- describe('anchors to side or flip if necessary', () => {
86
- it('anchors left', () => {
87
- const target = Targets.topRight
88
- const position = getEdgePosition({
89
- container,
90
- target,
91
- overlay,
92
- placement: 'left',
93
- })
94
- expect(position.left).toBe(target.left - overlay.width)
95
- })
96
- it('it anchors right when it should flip(left)', () => {
97
- const target = Targets.topLeft
98
- const position = getEdgePosition({
99
- container,
100
- target,
101
- overlay,
102
- placement: 'left',
103
- })
104
- expect(position.left).toBe(target.right)
105
- })
106
- it('anchors right', () => {
107
- const target = Targets.topLeft
108
- const position = getEdgePosition({
109
- container,
110
- target,
111
- overlay,
112
- placement: 'right',
113
- })
114
- expect(position.left).toBe(target.right)
115
- })
116
- it('it anchors left when it should flip(right)', () => {
117
- const target = Targets.topRight
118
- const position = getEdgePosition({
119
- container,
120
- target,
121
- overlay,
122
- placement: 'right',
123
- })
124
- expect(position.left).toBe(target.left - overlay.width)
125
- })
126
- it('anchors top', () => {
127
- const target = Targets.bottomLeft
128
- const position = getEdgePosition({
129
- container,
130
- target,
131
- overlay,
132
- placement: 'top',
133
- })
134
- expect(position.top).toBe(target.top - overlay.height)
135
- })
136
- it('it anchors bottom when it should flip(top)', () => {
137
- const target = Targets.topLeft
138
- const position = getEdgePosition({
139
- container,
140
- target,
141
- overlay,
142
- placement: 'top',
143
- })
144
- expect(position.top).toBe(target.bottom)
145
- })
146
- it('anchors bottom', () => {
147
- const target = Targets.topRight
148
- const position = getEdgePosition({
149
- container,
150
- target,
151
- overlay,
152
- placement: 'bottom',
153
- })
154
- expect(position.top).toBe(target.bottom)
155
- })
156
- it('it anchors top when it should flip(bottom)', () => {
157
- const target = Targets.bottomLeft
158
- const position = getEdgePosition({
159
- container,
160
- target,
161
- overlay,
162
- placement: 'bottom',
163
- })
164
- expect(position.top).toBe(target.top - overlay.height)
165
- })
166
- })
167
- describe('align horizontally/vertically or flip if necessary', () => {
168
- it('aligns left', () => {
169
- const target = Targets.topLeft
170
- const position = getAlignmentPosition({
171
- container,
172
- target,
173
- overlay,
174
- placement: 'left',
175
- })
176
- expect(position.left).toBe(target.left)
177
- })
178
- it('it aligns right when it should flip(left)', () => {
179
- const target = Targets.topRight
180
- const position = getAlignmentPosition({
181
- container,
182
- target,
183
- overlay,
184
- placement: 'left',
185
- })
186
- expect(position.left + overlay.width).toBe(target.right)
187
- })
188
- it('aligns right', () => {
189
- const target = Targets.topRight
190
- const position = getAlignmentPosition({
191
- container,
192
- target,
193
- overlay,
194
- placement: 'right',
195
- })
196
- expect(position.left + overlay.width).toBe(target.right)
197
- })
198
- it('it aligns left when it should flip(right)', () => {
199
- const target = Targets.topLeft
200
- const position = getAlignmentPosition({
201
- container,
202
- target,
203
- overlay,
204
- placement: 'right',
205
- })
206
- expect(position.left).toBe(target.left)
207
- })
208
-
209
- it('aligns top', () => {
210
- const target = Targets.topLeft
211
- const position = getAlignmentPosition({
212
- container,
213
- target,
214
- overlay,
215
- placement: 'top',
216
- })
217
- expect(position.top).toBe(target.top)
218
- })
219
- it('it aligns bottom when it should flip(top)', () => {
220
- const target = Targets.bottomLeft
221
- const position = getAlignmentPosition({
222
- container,
223
- target,
224
- overlay,
225
- placement: 'top',
226
- })
227
- expect(position.top + overlay.height).toBe(target.bottom)
228
- })
229
- it('aligns bottom', () => {
230
- const target = Targets.bottomLeft
231
- const position = getAlignmentPosition({
232
- container,
233
- target,
234
- overlay,
235
- placement: 'bottom',
236
- })
237
- expect(position.top + overlay.height).toBe(target.bottom)
238
- })
239
- it('it aligns top when it should flip(bottom)', () => {
240
- const target = Targets.topRight
241
- const position = getAlignmentPosition({
242
- container,
243
- target,
244
- overlay,
245
- placement: 'bottom',
246
- })
247
- expect(position.top).toBe(target.top)
248
- })
249
- })
250
- })
@@ -1,58 +0,0 @@
1
- import { mount } from 'enzyme'
2
- import React from 'react'
3
- import { assignRef, mergeRefs } from '../mergeRefs'
4
-
5
- const refValue = 'ref'
6
-
7
- describe('assignRef', () => {
8
- it('should call callback ref with value', () => {
9
- const refAsFunc = jest.fn()
10
- assignRef(refAsFunc, refValue)
11
-
12
- expect(refAsFunc).toHaveBeenCalledTimes(1)
13
- expect(refAsFunc).toHaveBeenCalledWith(refValue)
14
- })
15
-
16
- it('should assign value to ref object', () => {
17
- const refAsObj = { current: undefined }
18
- assignRef(refAsObj, refValue)
19
-
20
- expect(refAsObj.current).toBe(refValue)
21
- })
22
-
23
- it('should ignore when ref equals null', () => {
24
- const refAsObj = null
25
- assignRef(refAsObj, refValue)
26
-
27
- expect(refAsObj).toBe(null)
28
- })
29
- })
30
-
31
- test('mergeRefs', () => {
32
- const Dummy = React.forwardRef((_, forwardRef) => {
33
- React.useImperativeHandle(forwardRef, () => refValue)
34
- return null
35
- })
36
-
37
- const refAsFunc = jest.fn()
38
- const refAsObj = { current: undefined }
39
-
40
- const Example = ({ visible }) => {
41
- if (visible) {
42
- return <Dummy ref={mergeRefs(refAsFunc, refAsObj)} />
43
- }
44
- return null
45
- }
46
-
47
- const wrapper = mount(<Example visible />)
48
-
49
- expect(refAsFunc).toHaveBeenCalledTimes(1)
50
- expect(refAsFunc).toHaveBeenCalledWith(refValue)
51
- expect(refAsObj.current).toBe(refValue)
52
-
53
- wrapper.setProps({ visible: false })
54
-
55
- expect(refAsFunc).toHaveBeenCalledTimes(2)
56
- expect(refAsFunc).toHaveBeenCalledWith(null)
57
- expect(refAsObj.current).toBe(null)
58
- })
@@ -1,152 +0,0 @@
1
- import React from 'react'
2
-
3
- import { slotify } from '../slotify'
4
-
5
- const Foo = React.forwardRef(function Foo() {
6
- return <div />
7
- })
8
- const Bar = React.forwardRef(function Bar() {
9
- return <div />
10
- })
11
- const Baz = React.forwardRef(function Baz() {
12
- return <div />
13
- })
14
- const Unexpected = React.forwardRef(function Fatal() {
15
- return <div />
16
- })
17
-
18
- describe('slotify', () => {
19
- it('should display slot children if encountered', () => {
20
- const slots = slotify(
21
- [
22
- <Foo>
23
- <div id="foo-child" />
24
- </Foo>,
25
- <Bar>
26
- <div id="bar-child" />
27
- </Bar>,
28
- <Baz bazattr="xyz" />,
29
- ],
30
- {
31
- foo: Foo,
32
- bar: Bar,
33
- }
34
- )
35
-
36
- expect(slots).toEqual({
37
- foo: {
38
- slotProps: {},
39
- slotRef: null,
40
- slotChildren: <div id="foo-child" />,
41
- },
42
- bar: {
43
- slotProps: {},
44
- slotRef: null,
45
- slotChildren: <div id="bar-child" />,
46
- },
47
- })
48
- })
49
-
50
- it('should display only those slots that are expected to see', () => {
51
- const slots = slotify(
52
- [
53
- <Foo ref={{ fooref: true }} fooattr="123">
54
- <div id="foo-child" />
55
- </Foo>,
56
- <Bar ref={{ barref: true }} barattr="abc">
57
- <div id="bar-child" />
58
- </Bar>,
59
- <Unexpected />,
60
- ],
61
- {
62
- foo: Foo,
63
- bar: Bar,
64
- }
65
- )
66
-
67
- expect(slots).toEqual({
68
- foo: {
69
- slotProps: {
70
- fooattr: '123',
71
- },
72
- slotRef: {
73
- fooref: true,
74
- },
75
- slotChildren: <div id="foo-child" />,
76
- },
77
- bar: {
78
- slotProps: {
79
- barattr: 'abc',
80
- },
81
- slotRef: {
82
- barref: true,
83
- },
84
- slotChildren: <div id="bar-child" />,
85
- },
86
- })
87
- })
88
-
89
- it('should not display slots that are not encountered among the children', () => {
90
- const slots = slotify(
91
- [
92
- <Foo>
93
- <div id="foo-child" />
94
- </Foo>,
95
- <Bar>
96
- <div />
97
- </Bar>,
98
- <Baz>
99
- <div />
100
- </Baz>,
101
- ],
102
- {
103
- foo: Foo,
104
- }
105
- )
106
-
107
- expect(slots).toEqual({
108
- foo: {
109
- slotProps: {},
110
- slotRef: null,
111
- slotChildren: <div id="foo-child" />,
112
- },
113
- })
114
- })
115
-
116
- it('should return slot props', () => {
117
- const slots = slotify([<Foo fooattr="123" />], {
118
- foo: Foo,
119
- })
120
-
121
- expect(slots.foo).toEqual({
122
- slotProps: {
123
- fooattr: '123',
124
- },
125
- slotRef: null,
126
- })
127
- })
128
-
129
- it('should return slot ref', () => {
130
- const slots = slotify([<Bar ref={{ barref: true }} />], {
131
- bar: Bar,
132
- })
133
-
134
- expect(slots.bar).toEqual({
135
- slotProps: {},
136
- slotRef: {
137
- barref: true,
138
- },
139
- })
140
- })
141
-
142
- it('should return empty props object if the slot container does not have props', () => {
143
- const slots = slotify([<Baz />], {
144
- baz: Baz,
145
- })
146
-
147
- expect(slots.baz).toEqual({
148
- slotProps: {},
149
- slotRef: null,
150
- })
151
- })
152
- })