Skip to content

Conversation

@jindaljyoti
Copy link
Contributor

@jindaljyoti jindaljyoti commented Mar 20, 2025

kbd component

image

Summary by CodeRabbit

  • New Features

    • The keyboard component now accepts an optional size attribute, allowing users to choose from four distinct size options (small, medium, large, and x-large). The component’s appearance—including font size, padding, and height—adjusts based on the selected size.
  • Documentation

    • A new display mode showcases the different size variants, offering an enhanced visual preview of the component’s capabilities.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 20, 2025

Walkthrough

This pull request enhances the Kbd component by introducing an optional size property. The component now conditionally adds a data-kbd-size attribute when the property is provided. The associated story file is updated with a new Size story that maps over a set of size options, rendering multiple instances of the component. Additionally, CSS rules have been added to style the component for four different sizes based on this data attribute.

Changes

File(s) Change Summary
src/components/ui/Kbd/Kbd.tsx Added an optional size?: string prop to KbdProps and updated the component function to include a default value for size, conditionally adding a data-kbd-size attribute.
src/components/ui/Kbd/stories/Kbd.stories.tsx Introduced a new constant Sizes and a Size story that renders multiple Kbd components with different sizes; the existing All story remains unchanged.
styles/themes/components/kbd.scss Added CSS rules for the .rad-ui-kbd class with four size variants ("small", "medium", "large", "x-large") that adjust font size, padding, and height based on data-kbd-size.

Sequence Diagram(s)

sequenceDiagram
    participant Story as Size Story
    participant Kbd as Kbd Component
    participant DOM as Rendered Element
    participant CSS as CSS Styles

    Story->>Kbd: Render <kbd> with size prop
    Kbd->>DOM: Return <kbd data-kbd-size="value">
    DOM->>CSS: Apply styles based on data attribute
Loading

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • GoldGroove06

Poem

I’m a little rabbit, hopping in delight,
Tweaking code with a size prop shining bright.
Kbd leaps with data attributes so fine,
Stories and CSS now elegantly align.
Merging dreams with each gentle code bite! 🐇
Hop on, for the code now feels just right!

✨ 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
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 (3)
styles/themes/components/kbd.scss (1)

29-52: Well-structured size variants with a minor improvement suggestion

The implementation of size variants is clean and follows a logical progression. The commented section header makes the purpose clear.

Consider using specific units (px, rem) for font-size instead of keywords (small, medium, large, x-large) to ensure more consistent cross-browser rendering:

&[data-kbd-size="small"]{
-    font-size: small;
+    font-size: 0.875rem; /* or 14px */
    padding: 2px 8px;
    height: 24px;
}

&[data-kbd-size="medium"]{
-    font-size: medium;
+    font-size: 1rem; /* or 16px */
    padding: 4px 12px;
    height: 32px;
}

/* And so on for other sizes */
src/components/ui/Kbd/Kbd.tsx (2)

5-5: Remove unused import

The useCreateDataAttribute hook is imported but not used in the component.

-import { useCreateDataAttribute } from '~/core/hooks/createDataAttribute';
🧰 Tools
🪛 GitHub Check: lint

[warning] 5-5:
'useCreateDataAttribute' is defined but never used


16-16: Fix spacing in default parameter value

There's a spacing issue with the default parameter according to your linting rules.

-const Kbd = ({ children, customRootClass, className, size= '', ...props }: KbdProps) => {
+const Kbd = ({ children, customRootClass, className, size = '', ...props }: KbdProps) => {
🧰 Tools
🪛 ESLint

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

(space-infix-ops)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 13d2485 and dd8188f.

📒 Files selected for processing (3)
  • src/components/ui/Kbd/Kbd.tsx (1 hunks)
  • src/components/ui/Kbd/stories/Kbd.stories.tsx (2 hunks)
  • styles/themes/components/kbd.scss (1 hunks)
🧰 Additional context used
🪛 ESLint
src/components/ui/Kbd/Kbd.tsx

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

(space-infix-ops)

🪛 GitHub Check: lint
src/components/ui/Kbd/Kbd.tsx

[warning] 5-5:
'useCreateDataAttribute' is defined but never used

🔇 Additional comments (5)
src/components/ui/Kbd/stories/Kbd.stories.tsx (2)

5-5: Good addition of size constants

The array of size options is well-defined and consistent with the implementation in the styles.


25-40: Well-structured size demonstration

The Size story effectively demonstrates all available size variants in an organized layout, providing a clear visual reference for the new feature.

src/components/ui/Kbd/Kbd.tsx (3)

12-13: Size property added correctly

The size property is correctly defined as an optional string in the KbdProps type.


13-13: Review props type definition

The props property is typed as an array of Records, which seems unusual. Typically, this would be a single Record object for spreading additional props onto the element.

-    props: Record<string, any>[];
+    props?: Record<string, any>;

Please verify if this change is correct for your component pattern.


19-23: Good implementation of conditional data attribute

The conditional addition of the data attribute when size is provided is clean and effective.

Copy link
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 (1)
src/components/ui/Kbd/Kbd.tsx (1)

16-16: Fix spacing around the default value assignment.

There should be spaces around the equals sign for the default value assignment.

-const Kbd = ({ children, customRootClass, className, size= '', ...props }: KbdProps) => {
+const Kbd = ({ children, customRootClass, className, size = '', ...props }: KbdProps) => {
🧰 Tools
🪛 ESLint

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

(space-infix-ops)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between dd8188f and cfaa882.

📒 Files selected for processing (1)
  • src/components/ui/Kbd/Kbd.tsx (1 hunks)
🧰 Additional context used
🪛 ESLint
src/components/ui/Kbd/Kbd.tsx

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

(space-infix-ops)

🔇 Additional comments (4)
src/components/ui/Kbd/Kbd.tsx (4)

5-5: Good addition of the useCreateDataAttribute hook.

Clean import of the necessary hook to support the new size functionality.


12-12: Properly typed the new size prop.

The optional size prop is correctly defined with TypeScript's optional property syntax.


19-19: Good use of the useCreateDataAttribute hook.

This is an effective way to create the data attribute for the size property.


21-21: Correctly applied data attributes to the kbd element.

The data attributes are properly spread into the JSX element along with other props.

@kotAPI kotAPI added the automerge A tag that tells kodiak bot to automerge PRs for us when tests and approval conditions are met label Mar 21, 2025
@kodiakhq kodiakhq bot merged commit b80534c into rad-ui:main Mar 21, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge A tag that tells kodiak bot to automerge PRs for us when tests and approval conditions are met

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants