Skip to content

Commit 4a570fa

Browse files
Storybook: Minimize circular dependencies to avoid issues with vite
1 parent a15a4b1 commit 4a570fa

10 files changed

Lines changed: 37 additions & 19 deletions

File tree

assets/src/Control.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
useState,
44
useContext
55
} from 'react'
6-
import { ControlContext } from './index.tsx'
6+
import { ControlContext } from './context'
77

88
import { triggerEvent } from './events'
99
import { OverlayProvider } from 'react-aria'

assets/src/Element.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
useContext,
44
useEffect
55
} from 'react'
6-
import { ControlContext } from './index.tsx'
6+
import { ControlContext } from './context'
77

88
import types from './types.ts'
99
import DependendWrapper from './components/dependent/DependendWrapper'

assets/src/components/base/dialog/Dialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useRef } from 'react'
22
import { useDialog } from 'react-aria'
3-
import { Title } from '../../base'
3+
import Title from '../title/Title'
44

55
/**
66
* @see https://react-spectrum.adobe.com/react-aria/useDialog.html

assets/src/components/base/modal/Modal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
Overlay,
88
useModalOverlay
99
} from 'react-aria'
10-
import { ControlContext } from '../../../index.tsx'
10+
import { ControlContext } from '../../../context'
1111

1212
const Modal = ({ state, children, ...props }) => {
1313

assets/src/components/base/modal/ModalTrigger.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import { useOverlayTriggerState } from 'react-stately'
22
import { useOverlayTrigger } from 'react-aria'
33

4-
import {
5-
Button,
6-
Dialog,
7-
Modal
8-
} from '../../base'
4+
import Button from '../button/Button'
5+
import Dialog from '../dialog/Dialog'
6+
import Modal from './Modal'
97

108
const ModalTrigger = props => {
11-
9+
1210
// Some props names are going to be different when generated from PHP
1311
const content = props.content ?? props.children
14-
12+
1513
const state = useOverlayTriggerState(props)
1614
const { triggerProps, overlayProps } = useOverlayTrigger(
1715
{ type: 'dialog' },

assets/src/components/base/popover/Popover.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
Overlay,
99
usePopover
1010
} from 'react-aria'
11-
import { ControlContext } from '../../../index.tsx'
11+
import { ControlContext } from '../../../context'
1212

1313
function Popover({
1414
children,

assets/src/components/dynamic/settings-modal/DynamicFieldSettings.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import {
1313
} from 'react-aria'
1414
import { useOverlayTriggerState } from 'react-stately'
1515

16-
import { ControlContext, getConfig } from '../../../index.tsx'
16+
import { ControlContext } from '../../../context'
17+
import { getConfig } from '../../../index.tsx'
1718
import { Button, Title } from '../../base'
1819
import ComboBox from '../../field/combo-box'
1920
import Control from '../../../Control'

assets/src/components/field/checkbox/CheckboxStates.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export const LegacyVsTui: Story = {
6363

6464
export const InteractiveComparison: Story = {
6565
render: () => {
66+
6667
const [legacyChecked, setLegacyChecked] = useState(false)
6768
const [tuiChecked, setTuiChecked] = useState(false)
6869

assets/src/context.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { createContext } from 'react'
2+
3+
/**
4+
* Used to detect the current context from child components
5+
*
6+
* Extracted to its own module to avoid circular dependencies when
7+
* base components (Modal, Popover) need ControlContext, as index.tsx
8+
* imports types.ts which imports from the base barrel
9+
*
10+
* @see ./Control.tsx
11+
* @see ./Element.tsx
12+
* @see ./components/base/modal/Modal.tsx
13+
* @see ./components/base/popover/Popover.tsx
14+
* @see ./components/dynamic/settings-modal/DynamicFieldSettings.tsx
15+
*
16+
* The circular dependency won't cause issues with tangible-roller, but Vite
17+
* (used by Storybook) won't support it
18+
*
19+
* @see https://github.com/TangibleInc/fields/issues/11
20+
*/
21+
const ControlContext = createContext(null)
22+
23+
export { ControlContext }

assets/src/index.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
createRoot
44
} from 'react-dom'
55

6-
import { createContext } from 'react'
6+
import { ControlContext } from './context'
77

88
import {
99
config,
@@ -23,11 +23,6 @@ import types from './types'
2323
import fields from './fields'
2424
import * as utils from './utils'
2525

26-
/**
27-
* Used to detect the current context from child components
28-
*/
29-
const ControlContext = createContext(null)
30-
3126
const renderComponent = (props, type = 'field') => (
3227
type === 'element'
3328
? renderElement(props)

0 commit comments

Comments
 (0)