Skip to content

Commit 14a2776

Browse files
authored
refactor(react): remove circular dependencies (#4236)
* refactor(react): remove circular references * refactor(bundle): throw error when circular dependency is detected * chore: add changeset * chore: fix toolbarbutton import * chore: fix eslint warnings --------- Co-authored-by: Josh Black <[email protected]>
1 parent 959f6c1 commit 14a2776

File tree

14 files changed

+72
-56
lines changed

14 files changed

+72
-56
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react': minor
3+
---
4+
5+
Refactor project to avoid circular dependencies

packages/react/rollup.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ const baseConfig = {
219219
return
220220
}
221221

222+
if (warning.code === 'CIRCULAR_DEPENDENCY') {
223+
throw warning
224+
}
225+
222226
defaultHandler(warning)
223227
},
224228
}

packages/react/src/ActionList/Group.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react'
22
import {useId} from '../hooks/useId'
33
import Box from '../Box'
44
import {SxProp, BetterSystemStyleObject, merge} from '../sx'
5-
import {ListContext, ActionListProps} from './List'
5+
import {ListContext, type ActionListProps} from './shared'
66
import {AriaRole} from '../utils/types'
77
import {default as Heading} from '../Heading'
88
import type {ActionListHeadingProps} from './Heading'

packages/react/src/ActionList/Heading.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {defaultSxProp} from '../utils/defaultSxProp'
44
import {useRefObjectAsForwardedRef} from '../hooks'
55
import {ForwardRefComponent as PolymorphicForwardRefComponent} from '../utils/polymorphic'
66
import {default as HeadingComponent} from '../Heading'
7-
import {ListContext} from './List'
7+
import {ListContext} from './shared'
88
import VisuallyHidden from '../_VisuallyHidden'
99
import {ActionListContainerContext} from './ActionListContainerContext'
1010
import {invariant} from '../utils/invariant'

packages/react/src/ActionList/Item.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {ForwardRefComponent as PolymorphicForwardRefComponent} from '../utils/po
1212
import {ActionListContainerContext} from './ActionListContainerContext'
1313
import {Description} from './Description'
1414
import {GroupContext} from './Group'
15-
import {ActionListProps, ListContext} from './List'
15+
import {type ActionListProps, ListContext} from './shared'
1616
import {Selection} from './Selection'
1717
import {ActionListItemProps, getVariantStyles, ItemContext, TEXT_ROW_HEIGHT} from './shared'
1818
import {LeadingVisual, TrailingVisual, VisualProps} from './Visuals'

packages/react/src/ActionList/LinkItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Link from '../Link'
44
import {SxProp, merge} from '../sx'
55
import {Item} from './Item'
66
import {ActionListItemProps} from './shared'
7-
import {Box} from '..'
7+
import Box from '../Box'
88

99
// adopted from React.AnchorHTMLAttributes
1010
type LinkProps = {

packages/react/src/ActionList/List.tsx

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,12 @@ import React from 'react'
22
import {ForwardRefComponent as PolymorphicForwardRefComponent} from '../utils/polymorphic'
33
import styled from 'styled-components'
44
import sx, {SxProp, merge} from '../sx'
5-
import {AriaRole} from '../utils/types'
65
import {ActionListContainerContext} from './ActionListContainerContext'
76
import {defaultSxProp} from '../utils/defaultSxProp'
87
import {useSlots} from '../hooks/useSlots'
98
import {Heading} from './Heading'
109
import {useId} from '../hooks/useId'
11-
12-
export type ActionListProps = React.PropsWithChildren<{
13-
/**
14-
* `inset` children are offset (vertically and horizontally) from `List`’s edges, `full` children are flush (vertically and horizontally) with `List` edges
15-
*/
16-
variant?: 'inset' | 'full'
17-
/**
18-
* Whether multiple Items or a single Item can be selected.
19-
*/
20-
selectionVariant?: 'single' | 'multiple'
21-
/**
22-
* Display a divider above each `Item` in this `List` when it does not follow a `Header` or `Divider`.
23-
*/
24-
showDividers?: boolean
25-
/**
26-
* The ARIA role describing the function of `List` component. `listbox` or `menu` are a common values.
27-
*/
28-
role?: AriaRole
29-
}> &
30-
SxProp
31-
32-
type ContextProps = Pick<ActionListProps, 'variant' | 'selectionVariant' | 'showDividers' | 'role'> & {
33-
headingId?: string
34-
}
35-
36-
export const ListContext = React.createContext<ContextProps>({})
10+
import {ListContext, type ActionListProps} from './shared'
3711

3812
const ListBox = styled.ul<SxProp>(sx)
3913

packages/react/src/ActionList/Selection.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React from 'react'
22
import {CheckIcon} from '@primer/octicons-react'
3-
import {ListContext, ActionListProps} from './List'
43
import {GroupContext, ActionListGroupProps} from './Group'
5-
import {ActionListItemProps} from './shared'
4+
import {type ActionListProps, type ActionListItemProps, ListContext} from './shared'
65
import {LeadingVisualContainer} from './Visuals'
76
import Box from '../Box'
87

packages/react/src/ActionList/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {Description} from './Description'
77
import {LeadingVisual, TrailingVisual} from './Visuals'
88
import {Heading} from './Heading'
99

10-
export type {ActionListProps} from './List'
10+
export type {ActionListProps} from './shared'
1111
export type {ActionListGroupProps} from './Group'
1212
export type {ActionListItemProps} from './shared'
1313
export type {ActionListLinkItemProps} from './LinkItem'

packages/react/src/ActionList/shared.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,29 @@ export const getVariantStyles = (
108108
}
109109

110110
export const TEXT_ROW_HEIGHT = '20px' // custom value off the scale
111+
112+
export type ActionListProps = React.PropsWithChildren<{
113+
/**
114+
* `inset` children are offset (vertically and horizontally) from `List`’s edges, `full` children are flush (vertically and horizontally) with `List` edges
115+
*/
116+
variant?: 'inset' | 'full'
117+
/**
118+
* Whether multiple Items or a single Item can be selected.
119+
*/
120+
selectionVariant?: 'single' | 'multiple'
121+
/**
122+
* Display a divider above each `Item` in this `List` when it does not follow a `Header` or `Divider`.
123+
*/
124+
showDividers?: boolean
125+
/**
126+
* The ARIA role describing the function of `List` component. `listbox` or `menu` are a common values.
127+
*/
128+
role?: AriaRole
129+
}> &
130+
SxProp
131+
132+
type ContextProps = Pick<ActionListProps, 'variant' | 'selectionVariant' | 'showDividers' | 'role'> & {
133+
headingId?: string
134+
}
135+
136+
export const ListContext = React.createContext<ContextProps>({})

0 commit comments

Comments
 (0)