Skip to content

Commit 689bd8e

Browse files
chore: removing circular dependencies from imports (#447)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** This PR addresses the first part of circular dependency issues by fixing import paths across multiple components. Instead of using barrel imports (`'..'`), we now directly import from specific component files. This change: 1. Removes circular dependencies caused by barrel imports 2. Makes the import structure more explicit and maintainable 3. Prepares the codebase for further circular dependency fixes This update is very similar to the one implemented in the MetaMask extension, which can be referenced here: [MetaMask Extension PR #30267](MetaMask/metamask-extension#30267). That PR also focused on updating import paths in the `component-library` folder to resolve circular dependencies. The changes primarily affect: - Avatar components (Base, Favicon, Network, Token) - Button components (Base, Icon, Primary, Secondary, Tertiary) - Text and Icon component imports ## **Related issues** Partly fixes: #445 ## **Manual testing steps** 1. Run storybook and verify all stories for affected components render correctly 2. Run tests and ensure all tests pass 3. Check build process completes successfully ## **Screenshots/Recordings** ### **Before** N/A (No visual changes) ### **After** N/A (No visual changes) ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) - [x] I've completed the PR template to the best of my ability - [x] I've included tests if applicable - [x] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I've applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
1 parent cde6867 commit 689bd8e

21 files changed

+41
-39
lines changed

Diff for: packages/design-system-react/src/components/avatar-base/AvatarBase.stories.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import type { Meta, StoryObj } from '@storybook/react';
22
import React from 'react';
33

4-
import { Icon, IconName, IconSize, Text, TextVariant, TextColor } from '..';
4+
import { Icon, IconName, IconSize } from '../icon';
5+
import { TextColor } from '../text';
56
import { AvatarBase } from './AvatarBase';
67
import { AvatarBaseSize, AvatarBaseShape } from './AvatarBase.types';
78
import README from './README.mdx';

Diff for: packages/design-system-react/src/components/avatar-base/AvatarBase.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Slot } from '@radix-ui/react-slot';
22
import React from 'react';
33

44
import { twMerge } from '../../utils/tw-merge';
5-
import { Text, FontWeight, TextVariant, TextColor } from '..';
5+
import { Text, FontWeight, TextVariant, TextColor } from '../text';
66
import {
77
AVATAR_BASE_SIZE_CLASS_MAP,
88
AVATAR_BASE_SQUARE_BORDER_RADIUS_MAP,

Diff for: packages/design-system-react/src/components/avatar-favicon/AvatarFavicon.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { render, screen } from '@testing-library/react';
22
import React from 'react';
33

4-
import { TextColor } from '..';
4+
import { TextColor } from '../text';
55
import { AvatarFavicon } from './AvatarFavicon';
66
import { AvatarFaviconSize } from '.';
77

Diff for: packages/design-system-react/src/components/avatar-network/AvatarNetwork.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { render, screen } from '@testing-library/react';
22
import React from 'react';
33

4-
import { TextColor } from '..';
4+
import { TextColor } from '../text';
55
import { AvatarNetwork } from './AvatarNetwork';
66
import { AvatarNetworkSize } from '.';
77

Diff for: packages/design-system-react/src/components/avatar-token/AvatarToken.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { render, screen } from '@testing-library/react';
22
import React from 'react';
33

4-
import { TextColor } from '..';
4+
import { TextColor } from '../text';
55
import { AvatarToken } from './AvatarToken';
66
import { AvatarTokenSize } from '.';
77

Diff for: packages/design-system-react/src/components/button-base/ButtonBase.stories.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import type { Meta, StoryObj } from '@storybook/react';
22
import React from 'react';
33

4-
import { IconName, TextVariant } from '..';
4+
import { IconName } from '../icon';
5+
import { TextVariant } from '../text';
56
import { ButtonBase } from './ButtonBase';
67
import { ButtonBaseSize } from './ButtonBase.types';
78
import README from './README.mdx';

Diff for: packages/design-system-react/src/components/button-base/ButtonBase.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { render, screen } from '@testing-library/react';
22
import React from 'react';
33

4-
import { IconName } from '..';
4+
import { IconName } from '../icon';
55
import { ButtonBase } from './ButtonBase';
66
import { ButtonBaseSize } from './ButtonBase.types';
77

Diff for: packages/design-system-react/src/components/button-base/ButtonBase.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Slot, Slottable } from '@radix-ui/react-slot';
22
import React from 'react';
33

4-
import { FontWeight, Icon, IconName, IconSize, Text, TextColor } from '..';
4+
import { Text, FontWeight, TextColor } from '../text';
5+
import { Icon, IconName, IconSize } from '../icon';
56
import { twMerge } from '../../utils/tw-merge';
67
import { BUTTON_BASE_SIZE_CLASS_MAP } from './ButtonBase.constants';
78
import type { ButtonBaseProps } from './ButtonBase.types';

Diff for: packages/design-system-react/src/components/button-icon/ButtonIcon.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Meta, StoryObj } from '@storybook/react';
22
import React from 'react';
33

4-
import { IconName } from '..';
4+
import { IconName } from '../icon';
55
import { ButtonIcon } from './ButtonIcon';
66
import { ButtonIconSize } from './ButtonIcon.types';
77
import README from './README.mdx';

Diff for: packages/design-system-react/src/components/button-icon/ButtonIcon.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { render, screen } from '@testing-library/react';
22
import React from 'react';
33

4-
import { IconName, IconSize } from '..';
4+
import { IconName } from '../icon';
55
import { ButtonIcon } from './ButtonIcon';
66
import { ButtonIconSize } from './ButtonIcon.types';
77

Diff for: packages/design-system-react/src/components/button-primary/ButtonPrimary.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Meta, StoryObj } from '@storybook/react';
22
import React from 'react';
33

44
import { ButtonPrimarySize } from '.';
5-
import { IconName } from '..';
5+
import { IconName } from '../icon';
66
import { ButtonPrimary } from './ButtonPrimary';
77
import README from './README.mdx';
88

Diff for: packages/design-system-react/src/components/button-primary/ButtonPrimary.test.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { render, screen } from '@testing-library/react';
22
import React from 'react';
33

4-
import { ButtonPrimarySize, IconName } from '..';
4+
import { IconName } from '../icon';
5+
import { ButtonBaseSize } from '../button-base';
56
import { ButtonPrimary } from './ButtonPrimary';
67

78
describe('ButtonPrimary', () => {
@@ -118,11 +119,11 @@ describe('ButtonPrimary', () => {
118119

119120
it('renders with correct size classes', () => {
120121
const { rerender } = render(
121-
<ButtonPrimary size={ButtonPrimarySize.Sm}>Small</ButtonPrimary>,
122+
<ButtonPrimary size={ButtonBaseSize.Sm}>Small</ButtonPrimary>,
122123
);
123124
expect(screen.getByRole('button')).toHaveClass('h-8');
124125

125-
rerender(<ButtonPrimary size={ButtonPrimarySize.Lg}>Large</ButtonPrimary>);
126+
rerender(<ButtonPrimary size={ButtonBaseSize.Lg}>Large</ButtonPrimary>);
126127
expect(screen.getByRole('button')).toHaveClass('h-12');
127128
});
128129

Diff for: packages/design-system-react/src/components/button-secondary/ButtonSecondary.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Meta, StoryObj } from '@storybook/react';
22
import React from 'react';
33

44
import { ButtonSecondarySize } from '.';
5-
import { IconName } from '..';
5+
import { IconName } from '../icon';
66
import { ButtonSecondary } from './ButtonSecondary';
77
import README from './README.mdx';
88

Diff for: packages/design-system-react/src/components/button-secondary/ButtonSecondary.test.tsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { render, screen } from '@testing-library/react';
22
import React from 'react';
33

4-
import { ButtonSecondarySize, IconName } from '..';
4+
import { IconName } from '../icon';
5+
import { ButtonBaseSize } from '../button-base';
56
import { ButtonSecondary } from './ButtonSecondary';
67

78
describe('ButtonSecondary', () => {
@@ -103,13 +104,11 @@ describe('ButtonSecondary', () => {
103104

104105
it('renders with correct size classes', () => {
105106
const { rerender } = render(
106-
<ButtonSecondary size={ButtonSecondarySize.Sm}>Small</ButtonSecondary>,
107+
<ButtonSecondary size={ButtonBaseSize.Sm}>Small</ButtonSecondary>,
107108
);
108109
expect(screen.getByRole('button')).toHaveClass('h-8');
109110

110-
rerender(
111-
<ButtonSecondary size={ButtonSecondarySize.Lg}>Large</ButtonSecondary>,
112-
);
111+
rerender(<ButtonSecondary size={ButtonBaseSize.Lg}>Large</ButtonSecondary>);
113112
expect(screen.getByRole('button')).toHaveClass('h-12');
114113
});
115114

Diff for: packages/design-system-react/src/components/button-tertiary/ButtonTertiary.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Meta, StoryObj } from '@storybook/react';
22
import React from 'react';
33

44
import { ButtonTertiarySize } from '.';
5-
import { IconName } from '..';
5+
import { IconName } from '../icon';
66
import { ButtonTertiary } from './ButtonTertiary';
77
import README from './README.mdx';
88

Diff for: packages/design-system-react/src/components/button-tertiary/ButtonTertiary.test.tsx

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { render, screen } from '@testing-library/react';
22
import React from 'react';
33

4-
import { ButtonTertiarySize, IconName } from '..';
4+
import { IconName } from '../icon';
5+
import { ButtonBaseSize } from '../button-base';
56
import { ButtonTertiary } from './ButtonTertiary';
67

78
describe('ButtonTertiary', () => {
@@ -57,18 +58,14 @@ describe('ButtonTertiary', () => {
5758

5859
it('renders with correct size classes', () => {
5960
const { rerender } = render(
60-
<ButtonTertiary size={ButtonTertiarySize.Sm}>Small</ButtonTertiary>,
61+
<ButtonTertiary size={ButtonBaseSize.Sm}>Small</ButtonTertiary>,
6162
);
6263
expect(screen.getByRole('button')).toHaveClass('h-8');
6364

64-
rerender(
65-
<ButtonTertiary size={ButtonTertiarySize.Md}>Medium</ButtonTertiary>,
66-
);
65+
rerender(<ButtonTertiary size={ButtonBaseSize.Md}>Medium</ButtonTertiary>);
6766
expect(screen.getByRole('button')).toHaveClass('h-10');
6867

69-
rerender(
70-
<ButtonTertiary size={ButtonTertiarySize.Lg}>Large</ButtonTertiary>,
71-
);
68+
rerender(<ButtonTertiary size={ButtonBaseSize.Lg}>Large</ButtonTertiary>);
7269
expect(screen.getByRole('button')).toHaveClass('h-12');
7370
});
7471

Diff for: packages/design-system-react/src/components/button/Button.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Meta, StoryObj } from '@storybook/react';
22
import React from 'react';
33

44
import { ButtonSize } from '.';
5-
import { IconName } from '..';
5+
import { IconName } from '../icon';
66
import { Button } from './Button';
77
import { ButtonVariant } from './Button.types';
88
import README from './README.mdx';

Diff for: packages/design-system-react/src/components/button/Button.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { render, screen } from '@testing-library/react';
22
import React from 'react';
33

4-
import { IconName } from '..';
4+
import { IconName } from '../icon';
55
import { Button } from './Button';
66
import { ButtonVariant } from './Button.types';
77

Diff for: packages/design-system-react/src/components/button/Button.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React from 'react';
22

3-
import { ButtonTertiary, ButtonPrimary, ButtonSecondary } from '..';
4-
import type {
5-
ButtonTertiaryProps,
6-
ButtonPrimaryProps,
7-
ButtonSecondaryProps,
8-
} from '..';
3+
import { ButtonTertiary } from '../button-tertiary';
4+
import { ButtonPrimary } from '../button-primary';
5+
import { ButtonSecondary } from '../button-secondary';
6+
import type { ButtonTertiaryProps } from '../button-tertiary';
7+
import type { ButtonPrimaryProps } from '../button-primary';
8+
import type { ButtonSecondaryProps } from '../button-secondary';
99
import type { ButtonProps } from './Button.types';
1010
import { ButtonVariant } from './Button.types';
1111

Diff for: packages/design-system-react/src/components/text-button/TextButton.stories.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import type { Meta, StoryObj } from '@storybook/react';
22
import React from 'react';
33

4-
import { IconName, Text, TextVariant } from '..';
4+
import { IconName } from '../icon';
5+
import { Text, TextVariant } from '../text';
56
import README from './README.mdx';
67
import { TextButton } from './TextButton';
78

Diff for: packages/design-system-react/src/components/text-button/TextButton.test.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { render, screen } from '@testing-library/react';
22
import React from 'react';
33

4-
import { IconName, Text, TextVariant } from '..';
4+
import { IconName } from '../icon';
5+
import { Text, TextVariant } from '../text';
56
import { TextButton } from './TextButton';
67

78
describe('TextButton', () => {

0 commit comments

Comments
 (0)