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

Add linksCn (links className helper) to UI-Kit #1024

Merged
merged 12 commits into from
Feb 12, 2025
Merged

Add linksCn (links className helper) to UI-Kit #1024

merged 12 commits into from
Feb 12, 2025

Conversation

almsh
Copy link
Contributor

@almsh almsh commented Jan 24, 2025

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a flexible link styling utility function linkCn with customizable variants.
    • Added comprehensive Storybook stories for link components.
  • Documentation

    • Updated Storybook typography category title.
    • Reorganized typography module exports.
  • Refactor

    • Simplified link rendering in multiple components.
    • Removed typography stories file.
  • Style

    • Enhanced link styling with more dynamic class generation.
    • Improved link component visual customization options.
  • Bug Fixes

    • Updated link security attributes for improved safety.
    • Enhanced link functionality to support region-specific routing.

Copy link

vercel bot commented Jan 24, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
public ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 12, 2025 10:33am

Copy link

coderabbitai bot commented Jan 24, 2025

📝 Walkthrough

Walkthrough

This pull request introduces a linkCn utility function for consistent link styling across the application. The changes include adding a new links module in the UI component library, creating Storybook stories for link components, and updating link implementations in various website components. The modifications enhance the module's interface and provide more flexible styling options for links.

Changes

File Change Summary
ui/src/components/typography/index.ts Added export for links module
ui/src/components/typography/links.ts Introduced linkCn utility function for link styling
ui/src/stories/links.stories.tsx Added comprehensive Storybook stories for link components
ui/src/stories/typography.stories.tsx Updated Storybook title
website/src/app/[lang]/[region]/(website)/transparency/evidence/section-card.tsx Imported and used linkCn for link styling
website/src/components/faq/faq-section.tsx Imported and used linkCn for link styling
website/src/app/[lang]/[region]/(website)/about-us/(sections)/landing-page.tsx Imported and used linkCn for link styling
website/src/app/[lang]/[region]/(blue-theme)/donate/individual/page.tsx Imported and used linkCn for link styling
website/src/app/[lang]/[region]/(website)/(home)/(sections)/faq.tsx Updated FAQ link rendering to use linkCn
website/src/app/[lang]/[region]/(website)/me/contributions/page.tsx Imported and used linkCn for link styling
website/src/app/[lang]/[region]/(website)/me/donation-certificates/donation-certificates-table.tsx Imported and used linkCn for link styling
website/src/app/[lang]/[region]/(website)/me/subscriptions/subscriptions-client.tsx Imported and used linkCn for link styling
website/src/app/not-found.tsx Updated link rendering to use linkCn
ui/src/components/typography/typography.stories.tsx File removed

Possibly Related PRs

Suggested Labels

feature

Suggested Reviewers

  • andrashee
  • socialincome-dev
  • ssandino

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

github-actions bot commented Jan 24, 2025

Visit the preview URL for this PR (updated for commit 6b0c969):

https://si-admin-staging--pr1024-almsh-uikit-links-cljf3ycc.web.app

(expires Wed, 19 Feb 2025 10:26:20 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: b7b0969384059dce6ea8fad1ee1d1737e54e6676

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
ui/src/components/typography/links.ts (1)

57-123: Consider extending variants to support 'muted'.
You may want to add 'muted' as a value under variant to match usage in other files. This might prevent styling mismatches and keeps the design consistent.

  variants: {
    variant: {
      default: 'text-foreground ...',
      accent: 'text-accent ...',
      destructive: 'text-destructive ...',
+     muted: 'text-foreground/60 hover:text-foreground/80',
    },
    ...
  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b8afaca and bbe4337.

📒 Files selected for processing (7)
  • ui/src/components/typography/index.ts (1 hunks)
  • ui/src/components/typography/links.ts (1 hunks)
  • ui/src/components/typography/typography.stories.tsx (0 hunks)
  • ui/src/stories/links.stories.tsx (1 hunks)
  • ui/src/stories/typography.stories.tsx (1 hunks)
  • website/src/app/[lang]/[region]/(website)/transparency/evidence/section-card.tsx (2 hunks)
  • website/src/components/faq/faq-section.tsx (2 hunks)
💤 Files with no reviewable changes (1)
  • ui/src/components/typography/typography.stories.tsx
✅ Files skipped from review due to trivial changes (2)
  • ui/src/components/typography/index.ts
  • ui/src/stories/typography.stories.tsx
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Deploy admin on Firebase (social-income-staging) / Deploy admin on Firebase
  • GitHub Check: Test website

website/src/components/faq/faq-section.tsx Outdated Show resolved Hide resolved
Comment on lines 55 to 56
<Link href={fragment.href} className={linkCn({ variant: 'muted' })}>
{fragment.text}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Use a valid variant instead of 'muted'.
The variant field in linkCn only supports 'default', 'accent', or 'destructive'. Consider adding a 'muted' variant to linkCn or switch to a supported variant.

Example fix:

- <Link href={fragment.href} className={linkCn({ variant: 'muted' })}>
+ <Link href={fragment.href} className={linkCn({ variant: 'default' })}>
  {fragment.text}
</Link>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<Link href={fragment.href} className={linkCn({ variant: 'muted' })}>
{fragment.text}
<Link href={fragment.href} className={linkCn({ variant: 'default' })}>
{fragment.text}

Comment on lines +217 to +224
interface WithControlsProps {
children: string;
variant: 'default' | 'accent' | 'destructive';
size: 'inherit' | 'sm' | 'md' | 'lg' | 'xl' | '4xl';
underline: 'none' | 'hover' | 'always';
icon: boolean;
arrow: boolean | 'external';
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Align arrow prop type with internal usage.
Your type definition only allows boolean | 'external', but you're also using 'internal'. Update the type to include 'internal' and false for consistency.

-interface WithControlsProps {
-  arrow: boolean | 'external';
+interface WithControlsProps {
+  arrow: false | 'internal' | 'external';
   // ...
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
interface WithControlsProps {
children: string;
variant: 'default' | 'accent' | 'destructive';
size: 'inherit' | 'sm' | 'md' | 'lg' | 'xl' | '4xl';
underline: 'none' | 'hover' | 'always';
icon: boolean;
arrow: boolean | 'external';
}
interface WithControlsProps {
children: string;
variant: 'default' | 'accent' | 'destructive';
size: 'inherit' | 'sm' | 'md' | 'lg' | 'xl' | '4xl';
underline: 'none' | 'hover' | 'always';
icon: boolean;
arrow: false | 'internal' | 'external';
}

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
ui/src/stories/links.stories.tsx (1)

89-89: Use getIconSizeClassByLinkSize for consistent icon sizing.

Replace hardcoded icon sizes with the helper function for consistency.

-<svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+<svg className={getIconSizeClassByLinkSize('md')} fill="none" viewBox="0 0 24 24" stroke="currentColor">

Also applies to: 100-100

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bbe4337 and 91925a9.

📒 Files selected for processing (2)
  • ui/src/stories/links.stories.tsx (1 hunks)
  • website/src/app/[lang]/[region]/(website)/transparency/evidence/section-card.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • website/src/app/[lang]/[region]/(website)/transparency/evidence/section-card.tsx
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Test shared code
  • GitHub Check: Test website
  • GitHub Check: Test functions
  • GitHub Check: Test admin
  • GitHub Check: Prettify
  • GitHub Check: Security checks (typescript)
🔇 Additional comments (2)
ui/src/stories/links.stories.tsx (2)

217-224: Fix inconsistent arrow prop types.

The arrow prop type in WithControlsProps doesn't match its usage in LinkStoryProps and the actual implementation.


226-241: Verify icon sizes for 'sm' and 'md'.

Both 'sm' and 'md' sizes return 'h-3 w-3'. Please verify if this is intentional.

Also, consider adding unit tests for this helper function.

Would you like me to help generate unit tests for this function?

Comment on lines +89 to +96
<svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1"
/>
</svg>
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Extract duplicated SVG path to a reusable component.

The same SVG path data is duplicated in multiple places. Extract it into a reusable component to improve maintainability.

+const LinkIconSvg = ({ className }: { className: string }) => (
+  <svg className={className} fill="none" viewBox="0 0 24 24" stroke="currentColor">
+    <path
+      strokeLinecap="round"
+      strokeLinejoin="round"
+      strokeWidth={2}
+      d="M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1"
+    />
+  </svg>
+);

Also applies to: 100-107, 301-308

Copy link
Contributor

@mkue mkue left a comment

Choose a reason for hiding this comment

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

nice! I updated the className in the Links that we already used now 👍

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
website/src/app/[lang]/[region]/(website)/me/contributions/page.tsx (1)

22-26: 🛠️ Refactor suggestion

Remove redundant styling layers.

Using both linkCn and Button component creates unnecessary style layering. Consider using either:

  1. Just the Button component for interaction
  2. Just Link with linkCn for navigation
-<Link className={linkCn()} href={`/${lang}/${region}/donate/one-time`}>
-  <Button Icon={PlusCircleIcon} variant="ghost" size="lg" className="w-full">
-    {translator.t('contributions.one-time-payment')}
-  </Button>
-</Link>
+<Button
+  as={Link}
+  href={`/${lang}/${region}/donate/one-time`}
+  Icon={PlusCircleIcon}
+  variant="ghost"
+  size="lg"
+  className="w-full"
+>
+  {translator.t('contributions.one-time-payment')}
+</Button>
🧹 Nitpick comments (7)
website/src/app/[lang]/[region]/(website)/arts/section-card.tsx (1)

4-4: Consider customizing linkCn for complex link structure.

The default linkCn configuration might not be optimal for a link containing an icon and text. Consider specifying variants and options.

-<Link className={linkCn()} href={link.href} target="_blank">
+<Link className={linkCn({ variant: 'primary', icon: true })} href={link.href} target="_blank">

Also applies to: 32-32

website/src/app/[lang]/[region]/(website)/books/section-1.tsx (1)

23-23: Add email variant to linkCn.

Use the email variant for consistent styling of email links.

-<Link className={linkCn()} href="mailto: [email protected]">
+<Link className={linkCn({ variant: 'email' })} href="mailto: [email protected]">
website/src/app/[lang]/[region]/(blue-theme)/donate/individual/page.tsx (1)

32-36: Remove duplicate hover styling.

The parent div's hover:underline class conflicts with linkCn's hover behavior.

-<div className="mt-4 hover:underline">
+<div className="mt-4">
   <Link className={linkCn()} href={`/${lang}/${region}/donate/one-time`}>
     {translator.t('one-time-donation')}
   </Link>
 </div>
website/src/app/[lang]/[region]/(website)/app/page.tsx (1)

31-38: Add store variant to linkCn.

Store links should use a specific variant for consistent styling across the application.

<Link
-  className={linkCn()}
+  className={linkCn({ variant: 'store' })}
   href="https://play.google.com/store/apps/details?id=org.socialincome.app"
   target="_blank"
   rel="noopener noreferrer"
>

Apply the same change to the Apple Store link as well.

Also applies to: 44-51

website/src/app/[lang]/[region]/(website)/me/donation-certificates/donation-certificates-table.tsx (1)

33-33: Add download attribute for better accessibility.

The link points to a PDF download, so it should have the download attribute.

-<Link className={linkCn()} href={data} target="_blank" rel="noopener noreferrer">
+<Link className={linkCn()} href={data} target="_blank" rel="noopener noreferrer" download>
website/src/app/[lang]/[region]/(website)/me/subscriptions/subscriptions-client.tsx (1)

92-96: Consider using Button's href prop instead.

Since you're wrapping a Button with a Link, consider using Button's built-in href prop for a cleaner implementation.

-<Link className={linkCn()} href={`/${lang}/${region}/donate/individual`}>
-  <Button Icon={PlusCircleIcon} variant="ghost" size="lg" className="w-full">
-    {translations.newSubscription}
-  </Button>
-</Link>
+<Button 
+  href={`/${lang}/${region}/donate/individual`}
+  Icon={PlusCircleIcon} 
+  variant="ghost" 
+  size="lg" 
+  className="w-full"
+>
+  {translations.newSubscription}
+</Button>
website/src/app/[lang]/[region]/(website)/campaign/[campaign]/page.tsx (1)

364-373: Consider adding external arrow indicator.

For consistency with other external links in the codebase, consider adding the external arrow indicator.

-className={linkCn({ underline: 'none' })}
+className={linkCn({ underline: 'none', arrow: 'external' })}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 91925a9 and 6b0c969.

⛔ Files ignored due to path filters (1)
  • website/src/app/[lang]/[region]/(website)/csr/anthony.jpg is excluded by !**/*.jpg
📒 Files selected for processing (15)
  • website/src/app/[lang]/[region]/(blue-theme)/donate/individual/page.tsx (2 hunks)
  • website/src/app/[lang]/[region]/(website)/(home)/(sections)/faq.tsx (2 hunks)
  • website/src/app/[lang]/[region]/(website)/about-us/(sections)/landing-page.tsx (3 hunks)
  • website/src/app/[lang]/[region]/(website)/app/page.tsx (3 hunks)
  • website/src/app/[lang]/[region]/(website)/arts/section-card.tsx (2 hunks)
  • website/src/app/[lang]/[region]/(website)/books/section-1.tsx (2 hunks)
  • website/src/app/[lang]/[region]/(website)/campaign/[campaign]/page.tsx (2 hunks)
  • website/src/app/[lang]/[region]/(website)/csr/page.tsx (0 hunks)
  • website/src/app/[lang]/[region]/(website)/legal/layout-client.tsx (0 hunks)
  • website/src/app/[lang]/[region]/(website)/me/contributions/page.tsx (2 hunks)
  • website/src/app/[lang]/[region]/(website)/me/donation-certificates/donation-certificates-table.tsx (2 hunks)
  • website/src/app/[lang]/[region]/(website)/me/subscriptions/subscriptions-client.tsx (2 hunks)
  • website/src/app/[lang]/[region]/(website)/transparency/evidence/section-card.tsx (2 hunks)
  • website/src/app/not-found.tsx (1 hunks)
  • website/src/components/faq/faq-section.tsx (2 hunks)
💤 Files with no reviewable changes (2)
  • website/src/app/[lang]/[region]/(website)/legal/layout-client.tsx
  • website/src/app/[lang]/[region]/(website)/csr/page.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • website/src/app/[lang]/[region]/(website)/transparency/evidence/section-card.tsx
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Test shared code
  • GitHub Check: Test admin
  • GitHub Check: Test website
  • GitHub Check: Test functions
  • GitHub Check: Prettify
🔇 Additional comments (4)
website/src/app/not-found.tsx (1)

2-2: Clean implementation of linkCn with improved layout.

The changes properly integrate the linkCn utility while enhancing the layout with better flexbox centering.

Also applies to: 9-9, 16-17

website/src/app/[lang]/[region]/(website)/(home)/(sections)/faq.tsx (1)

7-7: Well-configured linkCn implementation with proper region handling.

The changes demonstrate good use of linkCn options and proper region parameter handling.

Also applies to: 23-30

website/src/components/faq/faq-section.tsx (1)

43-50: Implementation looks good!

The link implementation correctly uses the external arrow variant and proper security attributes.

website/src/app/[lang]/[region]/(website)/about-us/(sections)/landing-page.tsx (1)

41-43: LGTM!

The implementation correctly uses linkCn with appropriate configurations and includes security attributes for external links.

Also applies to: 69-76, 82-89

@mkue mkue merged commit c57153a into main Feb 12, 2025
18 of 19 checks passed
@mkue mkue deleted the almsh/uikit-links branch February 12, 2025 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants