Skip to content

add variant and size for callout#924

Merged
GoldGroove06 merged 2 commits intorad-ui:mainfrom
jindaljyoti:callout_variant_size
Mar 11, 2025
Merged

add variant and size for callout#924
GoldGroove06 merged 2 commits intorad-ui:mainfrom
jindaljyoti:callout_variant_size

Conversation

@jindaljyoti
Copy link
Copy Markdown
Contributor

@jindaljyoti jindaljyoti commented Mar 9, 2025

Callout component
image

image

Docs Page
image

image

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced new components for showcasing Callout variations, sizes, and colors.
    • Added optional properties for variant and size to the Callout component, enhancing its flexibility.
  • Documentation

    • Enhanced the documentation with additional sections and code usage examples for the Callout component, including variants, sizes, and color options.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 9, 2025

Walkthrough

This pull request introduces new documentation components for the Callout feature. Three new code usage files asynchronously retrieve source code from respective example files using a shared utility function and export a constant object. Additionally, three new React components—demonstrating callout variants, sizes, and colors—have been added. The documentation page is updated to import these examples and usage constants, adding dedicated sections to display the variations.

Changes

File(s) Change Summary
docs/.../docs/colorCodeUsage.js, docs/.../docs/sizeCodeUsage.js, docs/.../docs/variantCodeUsage.js New files that asynchronously import source code from corresponding example files using getSourceCodeFromPath and export a constant object named code.
docs/.../examples/CalloutColor.tsx, docs/.../examples/CalloutSizes.tsx, docs/.../examples/CalloutVariants.tsx New React components that render different styles of the Callout component by iterating over arrays for variants, sizes, and colors.
docs/.../page.mdx Updated documentation page to import the new usage constants and components, adding sections titled "Variants", "Sizes", and "Color".
src/components/ui/Callout/Callout.tsx, src/components/ui/Callout/fragments/CalloutRoot.tsx Added optional properties variant and size to CalloutProps and CalloutRootProps, modifying the component to utilize these new props.
src/components/ui/Callout/stories/Callout.stories.tsx Introduced new constants for Variants and Sizes, and added new story exports to demonstrate the Callout component with different sizes and variants.
styles/themes/components/callout.scss Added new styles for the .rad-ui-callout component, defining styles for new variants (outline, soft) and sizes (small, medium, large, x-large).

Sequence Diagram(s)

sequenceDiagram
    participant D as Documentation Page
    participant CU as Code Usage File
    participant E as Example Component
    D->>+CU: Import usage file (color/size/variant)
    CU->>+E: Call getSourceCodeFromPath (asynchronously fetch source)
    E-->>-CU: Return source code
    CU-->>-D: Export code constant
    D->>D: Render Documentation.ComponentHero with example & code
Loading

Possibly related PRs

  • add variant and size for blockquote #922: The changes in the main PR and the retrieved PR are related as both introduce new files for code usage examples that import the same utility function and export a constant object with a code property.
  • migration b2 #841: The changes in the main PR, which introduce new files for code usage examples of the Callout component, are related to the modifications in the retrieved PR that updates the Callout.stories.tsx file.
  • Mdx migration b2 #891: The changes in the main PR, which introduce new files for color, size, and variant code usage of the Callout component, are related to the retrieved PR as both involve the addition of similar code usage files.

Suggested labels

automerge

Suggested reviewers

  • GoldGroove06

Poem

Hopping through the lines, I spin a cheerful tune,
As code and docs unite beneath a coding moon.
Variants, sizes, and colors parade in joyful flow,
With asynchronous magic making our examples glow.
I'm a happy rabbit heralding each new, lovely change—
In our digital garden, improvements rearrange!
(_/)(•.•)(> <) Hop on, the future's bright and strange!

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @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
Copy Markdown
Contributor

@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

🧹 Nitpick comments (8)
docs/app/docs/components/callout/examples/CalloutSizes.tsx (2)

9-21: Consider using better keys for list rendering

The component currently uses array indices as React keys, which could potentially cause issues with component rerendering if the lists are modified. Consider using more stable and unique keys.

-{variants.map((variant, index) => {
-    return <div key={index} className='flex justify-center flex-wrap gap-4'>
+{variants.map((variant) => {
+    return <div key={variant} className='flex justify-center flex-wrap gap-4'>

And similarly for the nested map:

-{sizes.map((size, index) => {
-    return (
-       <Callout key={index} size={size} variant={variant}>
+{sizes.map((size) => {
+    return (
+       <Callout key={`${variant}-${size}`} size={size} variant={variant}>

5-22: TypeScript type annotations would improve maintainability

Consider adding TypeScript type annotations for the component's props, variables, and return type to improve code maintainability and catch potential type errors early.

-const CalloutSizes = () => {
+const CalloutSizes: React.FC = () => {
    const sizes = ['small', 'medium', 'large', 'x-large'];
    const variants = ['soft', 'outline'];

Additionally, you could create type definitions for sizes and variants:

+type CalloutSize = 'small' | 'medium' | 'large' | 'x-large';
+type CalloutVariant = 'soft' | 'outline';

 const CalloutSizes: React.FC = () => {
-    const sizes = ['small', 'medium', 'large', 'x-large'];
-    const variants = ['soft', 'outline'];
+    const sizes: CalloutSize[] = ['small', 'medium', 'large', 'x-large'];
+    const variants: CalloutVariant[] = ['soft', 'outline'];
docs/app/docs/components/callout/examples/CalloutColor.tsx (2)

6-7: Consider extending color demonstration beyond 'pink'

The component name CalloutColor suggests it demonstrates multiple colors, but it only shows 'pink' in the implementation. Consider showing multiple color options to better align with the component name and purpose.


11-18: Avoid using array index as React key when possible

Using array indices as keys (key={index}) can lead to unexpected behavior if the array items get reordered. Consider using a more stable identifier or a composite key.

- {sizes.map((size, index) => {
-   return (
-    <Callout key={index} size={size} variant={variant} color='pink'>
+ {sizes.map((size) => {
+   return (
+    <Callout key={`${variant}-${size}`} size={size} variant={variant} color='pink'>
docs/app/docs/components/callout/examples/CalloutVariants.tsx (2)

9-12: Improve variant descriptions for clarity and grammar

The descriptions in calloutStyleDescription have grammatical errors and don't clearly differentiate between variants.

const calloutStyleDescription = {
-  soft: 'Soft callout have a soft background color and a border.',
-  outline: 'Outline callout have a border and a background color.',
+  soft: 'Soft callouts have a subtle background color with a matching border.',
+  outline: 'Outline callouts have a prominent border with a minimal background color.'
};

24-24: Use className instead of inline styles for consistency

The component uses className for styling elsewhere but switches to inline styles for the Separator. For consistency, consider using className throughout.

- <Separator orientation="horizontal" style={{ marginTop: 20 }} />
+ <Separator orientation="horizontal" className="mt-5" />
docs/app/docs/components/callout/page.mdx (2)

28-39: LGTM! Good organization of component variations

The documentation is well structured with separate sections for variants, sizes, and colors. The implementation effectively showcases the different features of the Callout component.

However, consider adding brief introductory text for each section to explain the purpose and use cases for different variants, sizes, and colors.


31-32: Remove unnecessary blank line

There's an extra blank line between sections that disrupts the consistent spacing throughout the document.

            </Documentation.ComponentHero>
-  
-
            <Documentation.ComponentHero title='Sizes' codeUsage={sizeCodeUsage}>
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2cb51d0 and b8144d9.

📒 Files selected for processing (7)
  • docs/app/docs/components/callout/docs/colorCodeUsage.js (1 hunks)
  • docs/app/docs/components/callout/docs/sizeCodeUsage.js (1 hunks)
  • docs/app/docs/components/callout/docs/variantCodeUsage.js (1 hunks)
  • docs/app/docs/components/callout/examples/CalloutColor.tsx (1 hunks)
  • docs/app/docs/components/callout/examples/CalloutSizes.tsx (1 hunks)
  • docs/app/docs/components/callout/examples/CalloutVariants.tsx (1 hunks)
  • docs/app/docs/components/callout/page.mdx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (3)
docs/app/docs/components/callout/docs/variantCodeUsage.js (1)

1-9: Code structure looks good!

This file correctly imports the utility function and asynchronously fetches the source code for the Callout variants example. The export structure follows a consistent pattern that appears to be used throughout the documentation system.

docs/app/docs/components/callout/docs/sizeCodeUsage.js (1)

1-9: Code structure looks good!

This file correctly imports the utility function and asynchronously fetches the source code for the Callout sizes example. The export structure follows a consistent pattern that appears to be used throughout the documentation system.

docs/app/docs/components/callout/docs/colorCodeUsage.js (1)

1-9: Code structure looks good!

This file correctly imports the utility function and asynchronously fetches the source code for the Callout color example. The export structure follows a consistent pattern that appears to be used throughout the documentation system.

Copy link
Copy Markdown
Contributor

@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: 2

🧹 Nitpick comments (6)
styles/themes/components/callout.scss (2)

20-25: Simplify border declarations for better readability

The border declarations for the "soft" variant can be simplified using CSS shorthand notation instead of defining each side separately.

    &[data-callout-variant="soft"]{
-        border-top: 1px solid var(--rad-ui-color-accent-600);
-        border-left: 1px solid var(--rad-ui-color-accent-600);
-        border-right: 1px solid var(--rad-ui-color-accent-600);
-        border-bottom: 1px solid var(--rad-ui-color-accent-600);
+        border: 1px solid var(--rad-ui-color-accent-600);
        color: var(--rad-ui-color-accent-950);
        background-color:  var(--rad-ui-color-accent-400);

33-37: Consider using explicit font size values for better consistency

Currently, the size variants use relative keywords (small, medium, large, x-large) for font-size which can vary across browsers. Consider using explicit values (px, rem) for better consistency.

You could replace the relative keywords with explicit values, for example:

    &[data-callout-size="small"]{
-        font-size: small;
+        font-size: 12px;
        padding: 4px 8px;
        height: 24px;
    }

    &[data-callout-size="medium"]{
-        font-size: medium;
+        font-size: 14px;
        padding: 4px 12px;
        height: 32px;
    }

    &[data-callout-size="large"]{
-        font-size: large;
+        font-size: 16px;
        padding: 4px 16px;
        height: 40px;
    }

    &[data-callout-size="x-large"]{
-        font-size: x-large;
+        font-size: 18px;
        padding: 4px 24px;
        height: 48px;
    }

Also applies to: 39-43, 45-49, 51-55

src/components/ui/Callout/fragments/CalloutRoot.tsx (1)

28-32: Remove redundant data-accent-color attribute assignment

The data-accent-color attribute is being set twice: once in the data_attributes object and once directly in the JSX.

    if (color) {
        data_attributes['data-accent-color'] = color;
    }

-    return <div className={clsx(rootClass, className)} data-accent-color={color ?? undefined} {...data_attributes} {...props}>
+    return <div className={clsx(rootClass, className)} {...data_attributes} {...props}>
        {children}
    </div>;
src/components/ui/Callout/stories/Callout.stories.tsx (3)

69-73: Improve rendering of Callout components with size props

The code is functional but could be more readable. Consider adding spacing between the Callout components to improve visual clarity in the storybook.

                    <span key={index} className="inline-flex items-start space-x-2">
                        {Sizes.map((size, index) => {
-                            return <Callout key={index} size={size} variant={variant} >
+                            return <Callout key={index} size={size} variant={variant} className="mr-4 mb-2">
                                 <InfoIcon/> <span>This is a Callout</span>
                            </Callout>;
                        })}

89-93: Fix excessive indentation and whitespace

The code has excessive indentation which makes it inconsistent with the surrounding code structure.

        <div className='flex space-x-2'>
-
-                        {Variants.map((variant, index) => {
-                            return <Callout key={index}  variant={variant} >
-                                 <InfoIcon/> <span>This is a Callout</span>
-                            </Callout>;
-                        })}
+            {Variants.map((variant, index) => {
+                return <Callout key={index} variant={variant}>
+                    <InfoIcon/> <span>This is a Callout</span>
+                </Callout>;
+            })}

90-90: Remove extra whitespace in variant prop

There's an extra space between key={index} and variant={variant}.

-                            return <Callout key={index}  variant={variant} >
+                            return <Callout key={index} variant={variant}>
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b8144d9 and 6e39761.

📒 Files selected for processing (4)
  • src/components/ui/Callout/Callout.tsx (1 hunks)
  • src/components/ui/Callout/fragments/CalloutRoot.tsx (1 hunks)
  • src/components/ui/Callout/stories/Callout.stories.tsx (2 hunks)
  • styles/themes/components/callout.scss (1 hunks)
🧰 Additional context used
🪛 ESLint
src/components/ui/Callout/Callout.tsx

[error] 19-19: Operator '=' must be spaced.

(space-infix-ops)


[error] 19-19: Operator '=' must be spaced.

(space-infix-ops)

src/components/ui/Callout/fragments/CalloutRoot.tsx

[error] 16-16: Operator '=' must be spaced.

(space-infix-ops)


[error] 16-16: Operator '=' must be spaced.

(space-infix-ops)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build

}

const CalloutRoot = ({ children, className, color, customRootClass, ...props }: CalloutRootProps) => {
const CalloutRoot = ({ children, className, color, variant='', size='', customRootClass, ...props }: CalloutRootProps) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix spacing around default value assignments

The ESLint hint indicates missing spaces around the equals signs for default value assignments.

-const CalloutRoot = ({ children, className, color, variant='', size='', customRootClass, ...props }: CalloutRootProps) => {
+const CalloutRoot = ({ children, className, color, variant = '', size = '', customRootClass, ...props }: CalloutRootProps) => {
📝 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
const CalloutRoot = ({ children, className, color, variant='', size='', customRootClass, ...props }: CalloutRootProps) => {
const CalloutRoot = ({ children, className, color, variant = '', size = '', customRootClass, ...props }: CalloutRootProps) => {
🧰 Tools
🪛 ESLint

[error] 16-16: Operator '=' must be spaced.

(space-infix-ops)


[error] 16-16: Operator '=' must be spaced.

(space-infix-ops)

const COMPONENT_NAME = 'Callout';
const Callout = ({ children, className = '', color, customRootClass, ...props }: CalloutProps) => {
return (<CalloutRoot customRootClass={customRootClass} className={clsx(className)} color={color ?? undefined} {...props}>
const Callout = ({ children, className = '', color, variant='', size='', customRootClass, ...props }: CalloutProps) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix spacing around default value assignments

The ESLint hint indicates missing spaces around the equals signs for default value assignments.

-const Callout = ({ children, className = '', color, variant='', size='', customRootClass, ...props }: CalloutProps) => {
+const Callout = ({ children, className = '', color, variant = '', size = '', customRootClass, ...props }: CalloutProps) => {
📝 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
const Callout = ({ children, className = '', color, variant='', size='', customRootClass, ...props }: CalloutProps) => {
const Callout = ({ children, className = '', color, variant = '', size = '', customRootClass, ...props }: CalloutProps) => {
🧰 Tools
🪛 ESLint

[error] 19-19: Operator '=' must be spaced.

(space-infix-ops)


[error] 19-19: Operator '=' must be spaced.

(space-infix-ops)

@GoldGroove06 GoldGroove06 merged commit e86d34d into rad-ui:main Mar 11, 2025
This was referenced Mar 11, 2025
@coderabbitai coderabbitai Bot mentioned this pull request May 7, 2025
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