Skip to content

chore: updating dsrn to use named exports instead of default exports #650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2025

Conversation

georgewrmarshall
Copy link
Contributor

@georgewrmarshall georgewrmarshall commented May 8, 2025

Description

This PR standardizes the export conventions across the design system by converting all default exports to named exports in the design-system-react-native package.

The primary goals of this change are:

  1. Align export patterns between design-system-react and design-system-react-native
  2. Make component usage more consistent and predictable for developers
  3. Adopt best practices for module exports in TypeScript

Key changes include:

  • Converting component exports from default to named exports
  • Updating all import statements to use named imports
  • Standardizing barrel exports in index.ts files
  • Ensuring the root index.ts re-exports everything from components/index.ts

Allows us to do:

import {
  AvatarToken,
  AvatarTokenSize,
  BadgeNetwork,
  ButtonSize,
  ButtonIcon,
  ButtonIconSize,
  IconName,
  Text,
  TextVariant,
  TextColor,
  AvatarAccount,
  AvatarAccountVariant,
  Icon,
} from '@metamask/design-system-react-native';

Related issues

Fixes: #649

Manual testing steps

  1. Build the React Native package: yarn workspace @metamask/design-system-react-native build
  2. Verify that the build completes successfully
  3. Run tests: yarn workspace @metamask/design-system-react-native test
  4. Run storybook to check components render as necessary (storybook will error out on incorrect imports)

Screenshots/Recordings

Before

// Before - default export in component
const Component = () => { ... };
export default Component;

// Before - imports using default import
import Component from './Component';

After

// After - named export in component 
export const Component = () => { ... };

// After - imports using named import
import { Component } from './Component';

Manual storybook smoke test

My.Movie.2.mp4

Pre-merge author checklist

  • I've followed MetaMask Contributor Docs
  • I've completed the PR template to the best of my ability
  • I've included tests if applicable
  • I've documented my code using JSDoc format if applicable
  • I've applied the right labels on the PR (see labeling guidelines). 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.

@@ -0,0 +1,90 @@
export {
Copy link
Contributor Author

@georgewrmarshall georgewrmarshall May 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restructuring exports to align with React package conventions. We're using named exports and intentionally omitting withThemeProvider because:

  • App-level theming: Theme providers should be applied at the application root, not per-component
  • Cleaner API: Provides a more consistent interface for consumers
  • Performance: Prevents redundant context providers throughout the component tree
  • Flexibility: Allows applications to customize theme application strategy
  • Developer experience: Makes component dependencies and requirements more explicit

import TextOrChildrenComponent from './components/temp-components/TextOrChildren';
export const TextOrChildren = withThemeProvider(TextOrChildrenComponent);
export type { TextOrChildrenProps } from './components/temp-components/TextOrChildren';
export * from './components';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aligns with React package

@georgewrmarshall georgewrmarshall marked this pull request as ready for review May 8, 2025 00:27
@georgewrmarshall georgewrmarshall requested a review from a team as a code owner May 8, 2025 00:27
@georgewrmarshall georgewrmarshall merged commit 8032a4b into main May 11, 2025
37 checks passed
@georgewrmarshall georgewrmarshall deleted the fix/named-exports branch May 11, 2025 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Convert DSRN to named exports
2 participants