Skip to content
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

feat: add Delineator component #25610

Merged
merged 10 commits into from
Jul 11, 2024
Merged

feat: add Delineator component #25610

merged 10 commits into from
Jul 11, 2024

Conversation

OGPoyraz
Copy link
Member

@OGPoyraz OGPoyraz commented Jul 1, 2024

Description

This PR aims to add Delineator component which heavily influenced by SnapsDelineator with small visual differences and decoupled from snaps context.

Open in GitHub Codespaces

Related issues

Fixes: #24995

Manual testing steps

This component has no usage for now, hence it could be seen in the storybook.

  1. Run yarn storybook
  2. Search for Delineator component to see it visually

Screenshots/Recordings

Screenshot 2024-07-01 at 14 23 09

Pre-merge author checklist

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.

@OGPoyraz OGPoyraz added the team-confirmations Push issues to confirmations team label Jul 1, 2024
@OGPoyraz OGPoyraz requested a review from a team as a code owner July 1, 2024 12:29
default:
return TextColor.textAlternative;
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Above function can be a simple object key -> value could be DelineatorType -> TextColor

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call but then default value needs to be determined by an || operator.

const textColorMap = {
  [DelineatorType.Error]: TextColor.errorDefault,
};

/// usage
textColorMap[type] || TextColor.textAlternative;

{overrideTextComponentColorByType({
component: headerComponent,
type,
})}
Copy link
Contributor

Choose a reason for hiding this comment

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

Here is it not possible to pass color prop without cloning the component ?

Copy link
Member Author

@OGPoyraz OGPoyraz Jul 2, 2024

Choose a reason for hiding this comment

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

I am actually not fan of this but there is no way to override that property rather than this.

Normally the parent needs to set the <Text> component color becuase they also set the type. However this is an extra security to override whatever send in headerComponent

Do you think we should remove this and let parent set the color?

// Normal usage
<Delineator
    headerComponent={
    <Text
    color={TextColor.textAlternative}
    marginLeft={1}
    variant={TextVariant.bodySm}
  >
    Insights from <b>Forta</b>
  </Text>
    }
    iconName={IconName.Wallet}
  >
Content
  </Delineator>

// Error usage  - Actually expected the text color to be send in error color
<Delineator
type="error"
    headerComponent={
    <Text
    color={TextColor.errorDefault}
    marginLeft={1}
    variant={TextVariant.bodySm}
  >
    Insights from <b>Forta</b>
  </Text>
    }
    iconName={IconName.Wallet}
  >
Content
  </Delineator>
  

Copy link
Member

Choose a reason for hiding this comment

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

I agree that this component setting the colour is best since it enforces the consistent styling, plus believe cloning is best practice to override child properties.

};
}
return { ...defaultIconProps, ...iconProps };
};
Copy link
Contributor

@jpuri jpuri Jul 1, 2024

Choose a reason for hiding this comment

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

Is it possible to have icon without iconsProps as inverseIconColorProp ? backgroundColor seems to be only property changing above.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call, adrdressed this in 7b0a644

onExpandChange,
type,
wrapperBoxProps,
}) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Will it be required to have props isExpanded, onExpandChange one level above. Or they can be part of this component itself ?

Copy link
Member Author

@OGPoyraz OGPoyraz Jul 2, 2024

Choose a reason for hiding this comment

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

I think it will create unnecessary state management overload where this component is used if we leave the expand state to parent. I've added onExpandChange because I saw that SnapsDelineator needs such callback (probably for metrics etc)

ui/components/ui/delineator/delineator.tsx Outdated Show resolved Hide resolved
ui/components/ui/delineator/delineator.tsx Outdated Show resolved Hide resolved
ui/components/ui/delineator/delineator.tsx Outdated Show resolved Hide resolved
ui/components/ui/delineator/delineator.tsx Outdated Show resolved Hide resolved
{overrideTextComponentColorByType({
component: headerComponent,
type,
})}
Copy link
Member

Choose a reason for hiding this comment

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

I agree that this component setting the colour is best since it enforces the consistent styling, plus believe cloning is best practice to override child properties.

ui/components/ui/delineator/delineator.tsx Outdated Show resolved Hide resolved
@metamaskbot
Copy link
Collaborator

Builds ready [12500e4]
Page Load Metrics (146 ± 151 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint611471022311
domContentLoaded96027147
load411514146315151
domInteractive96027147
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Copy link

codecov bot commented Jul 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.81%. Comparing base (5ee57a6) to head (d5f38f1).
Report is 26 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #25610      +/-   ##
===========================================
+ Coverage    69.77%   69.81%   +0.03%     
===========================================
  Files         1376     1380       +4     
  Lines        48403    48628     +225     
  Branches     13348    13407      +59     
===========================================
+ Hits         33773    33945     +172     
- Misses       14630    14683      +53     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

jpuri
jpuri previously approved these changes Jul 11, 2024
Copy link
Contributor

@jpuri jpuri left a comment

Choose a reason for hiding this comment

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

looks good

matthewwalsh0
matthewwalsh0 previously approved these changes Jul 11, 2024
ui/components/ui/delineator/delineator.tsx Outdated Show resolved Hide resolved
Copy link

sonarcloud bot commented Jul 11, 2024

@metamaskbot
Copy link
Collaborator

Builds ready [d5f38f1]
Page Load Metrics (155 ± 179 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint6913899199
domContentLoaded95524126
load421781155374179
domInteractive95524126
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@OGPoyraz OGPoyraz merged commit 5f75083 into develop Jul 11, 2024
73 checks passed
@OGPoyraz OGPoyraz deleted the 24995-build-delineator branch July 11, 2024 08:48
@github-actions github-actions bot locked and limited conversation to collaborators Jul 11, 2024
@metamaskbot metamaskbot added the release-12.2.0 Issue or pull request that will be included in release 12.2.0 label Jul 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.2.0 Issue or pull request that will be included in release 12.2.0 team-confirmations Push issues to confirmations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build expandable UI component to allow users to add content to the page, keeping the design aligned
5 participants