Skip to content

Conversation

@GoldGroove06
Copy link
Contributor

@GoldGroove06 GoldGroove06 commented Jul 21, 2025

closes #1227

Summary by CodeRabbit

  • New Features

    • Introduced a modular NumberField component with subcomponents for input, increment, and decrement controls.
    • Supports controlled and uncontrolled usage with customizable step sizes, min/max limits, and form integration.
    • Added context-based state management for consistent behavior across NumberField parts.
    • Provided Storybook examples showcasing basic, controlled, and form-based NumberField usage.
  • Style

    • Added new styles for NumberField, including custom input appearance and styled increment/decrement buttons.
  • Documentation

    • Added Storybook stories demonstrating various NumberField use cases.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 21, 2025

Walkthrough

A new modular NumberField component for React is introduced, consisting of a root context provider and three subcomponents (Input, Increment, Decrement). The implementation includes context management, state handling for controlled and uncontrolled usage, keyboard event support, and a dedicated SCSS stylesheet. Storybook stories demonstrate usage scenarios.

Changes

Files/Groups Change Summary
src/components/ui/NumberField/NumberField.tsx Adds main NumberField wrapper component exposing Root, Input, Increment, Decrement as static properties.
src/components/ui/NumberField/contexts/NumberFieldContext.tsx Introduces NumberFieldContext and its type for state and handlers.
src/components/ui/NumberField/fragments/NumberFieldDecrement.tsx,
NumberFieldIncrement.tsx
Adds Decrement and Increment button components consuming context and handling step actions.
src/components/ui/NumberField/fragments/NumberFieldInput.tsx Adds controlled input component with keyboard and change handling via context.
src/components/ui/NumberField/fragments/NumberFieldRoot.tsx Adds Root provider component managing state, context, and step logic; exports props type.
src/components/ui/NumberField/stories/NumberField.stories.tsx Adds Storybook stories: Basic, Controlled, and FormExample for NumberField usage.
styles/themes/components/number-field.scss Adds SCSS styling for NumberField root, input, and buttons; hides native spinners; applies accent colors.
styles/themes/default.scss Imports new NumberField SCSS into global theme.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant NumberField.Root
    participant NumberFieldContext
    participant NumberField.Input
    participant NumberField.Increment
    participant NumberField.Decrement

    User->>NumberField.Root: Render with props
    NumberField.Root->>NumberFieldContext: Provide context (value, handlers)
    User->>NumberField.Input: Render inside Root
    NumberField.Input->>NumberFieldContext: Consume context (inputValue, handlers)
    User->>NumberField.Increment: Render inside Root
    NumberField.Increment->>NumberFieldContext: Consume context (handleStep)
    User->>NumberField.Decrement: Render inside Root
    NumberField.Decrement->>NumberFieldContext: Consume context (handleStep)
    User->>NumberField.Input: Type or press arrow keys
    NumberField.Input->>NumberFieldContext: Call handleOnChange or handleStep
    NumberFieldContext->>NumberField.Root: Update value/state
Loading

Estimated code review effort

3 (~45 minutes)

Suggested labels

automerge

Suggested reviewers

  • kotAPI

Poem

In the garden of code, a number field grew,
With buttons for hopping the value up or down too.
Context and stories, all styled with care,
Now numbers can dance with a bunny’s soft flair.
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-07-22T10_31_29_649Z-debug-0.log


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0dfc547 and 98da3ed.

📒 Files selected for processing (4)
  • src/components/ui/NumberField/fragments/NumberFieldDecrement.tsx (1 hunks)
  • src/components/ui/NumberField/fragments/NumberFieldIncrement.tsx (1 hunks)
  • src/components/ui/NumberField/fragments/NumberFieldInput.tsx (1 hunks)
  • src/components/ui/NumberField/fragments/NumberFieldRoot.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/components/ui/NumberField/fragments/NumberFieldIncrement.tsx
  • src/components/ui/NumberField/fragments/NumberFieldDecrement.tsx
  • src/components/ui/NumberField/fragments/NumberFieldInput.tsx
  • src/components/ui/NumberField/fragments/NumberFieldRoot.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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: 7

🧹 Nitpick comments (3)
src/components/ui/NumberField/fragments/NumberFieldIncrement.tsx (1)

5-8: Fix missing semicolon in type definition.

The className property is missing a semicolon.

 export type NumberFieldIncrementProps = {
-    className?: string
+    className?: string;
     children?: React.ReactNode
 }
src/components/ui/NumberField/fragments/NumberFieldInput.tsx (1)

44-46: Improve readability by formatting the input element.

The input element is on a single long line making it difficult to read and maintain.

Apply this diff to improve formatting:

 return (
-    <input type="number" onKeyDown={handleKeyDown} value={inputValue === '' ? '' : inputValue} onChange={(e) => { const val = e.target.value; handleOnChange(val === '' ? '' : Number(val)); }} id={id} name={name} disabled={disabled} readOnly={readOnly} required={required} className={clsx(`${rootClass}-input`, className)}/>
+    <input 
+        type="number"
+        onKeyDown={handleKeyDown}
+        value={inputValue === '' ? '' : inputValue}
+        onChange={(e) => {
+            const val = e.target.value;
+            handleOnChange(val === '' ? '' : Number(val));
+        }}
+        id={id}
+        name={name}
+        disabled={disabled}
+        readOnly={readOnly}
+        required={required}
+        className={clsx(`${rootClass}-input`, className)}
+    />
 );
src/components/ui/NumberField/stories/NumberField.stories.tsx (1)

24-24: Consider removing redundant defaultValue in controlled mode.

In the Controlled story, you're passing both value={value} and defaultValue={3}. When using controlled mode, the defaultValue prop is typically not needed since the value prop takes precedence.

Consider this change for clarity:

-<NumberField.Root value={value} onValueChange={setValue} defaultValue={3} step={1} min={0} max={10} largeStep={5}>
+<NumberField.Root value={value} onValueChange={setValue} step={1} min={0} max={10} largeStep={5}>
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c8b1a02 and 0dfc547.

📒 Files selected for processing (9)
  • src/components/ui/NumberField/NumberField.tsx (1 hunks)
  • src/components/ui/NumberField/contexts/NumberFieldContext.tsx (1 hunks)
  • src/components/ui/NumberField/fragments/NumberFieldDecrement.tsx (1 hunks)
  • src/components/ui/NumberField/fragments/NumberFieldIncrement.tsx (1 hunks)
  • src/components/ui/NumberField/fragments/NumberFieldInput.tsx (1 hunks)
  • src/components/ui/NumberField/fragments/NumberFieldRoot.tsx (1 hunks)
  • src/components/ui/NumberField/stories/NumberField.stories.tsx (1 hunks)
  • styles/themes/components/number-field.scss (1 hunks)
  • styles/themes/default.scss (1 hunks)
🧰 Additional context used
🧠 Learnings (7)
📓 Common learnings
Learnt from: kotAPI
PR: rad-ui/ui#1031
File: src/components/ui/Accordion/fragments/AccordionRoot.tsx:41-44
Timestamp: 2025-04-07T04:38:34.864Z
Learning: The Accordion component in rad-ui/ui supports both controlled and uncontrolled modes through props like `value`, `defaultValue`, and `onValueChange`. When implementing controlled components, remember to: 1) Initialize state from defaultValue, 2) Update internal state when value changes (controlled mode), 3) Call onValueChange callback, and 4) Prevent internal state updates when in controlled mode.
Learnt from: decipher-cs
PR: rad-ui/ui#417
File: src/components/ui/Dropdown/Dropdown.stories.tsx:43-50
Timestamp: 2024-12-12T08:34:33.079Z
Learning: Ensure to verify existing ARIA attributes in components before suggesting additions during code reviews, especially in the `Dropdown.Trigger` component in `src/components/ui/Dropdown/Dropdown.stories.tsx`.
src/components/ui/NumberField/fragments/NumberFieldDecrement.tsx (1)

Learnt from: decipher-cs
PR: #417
File: src/components/ui/Dropdown/Dropdown.stories.tsx:43-50
Timestamp: 2024-12-12T08:34:33.079Z
Learning: Ensure to verify existing ARIA attributes in components before suggesting additions during code reviews, especially in the Dropdown.Trigger component in src/components/ui/Dropdown/Dropdown.stories.tsx.

styles/themes/components/number-field.scss (1)

Learnt from: kotAPI
PR: #1031
File: src/components/ui/Accordion/fragments/AccordionRoot.tsx:41-44
Timestamp: 2025-04-07T04:38:34.864Z
Learning: The Accordion component in rad-ui/ui supports both controlled and uncontrolled modes through props like value, defaultValue, and onValueChange. When implementing controlled components, remember to: 1) Initialize state from defaultValue, 2) Update internal state when value changes (controlled mode), 3) Call onValueChange callback, and 4) Prevent internal state updates when in controlled mode.

src/components/ui/NumberField/NumberField.tsx (1)

Learnt from: decipher-cs
PR: #417
File: src/components/ui/Dropdown/Dropdown.stories.tsx:43-50
Timestamp: 2024-12-12T08:34:33.079Z
Learning: Ensure to verify existing ARIA attributes in components before suggesting additions during code reviews, especially in the Dropdown.Trigger component in src/components/ui/Dropdown/Dropdown.stories.tsx.

src/components/ui/NumberField/fragments/NumberFieldIncrement.tsx (1)

Learnt from: decipher-cs
PR: #417
File: src/components/ui/Dropdown/Dropdown.stories.tsx:43-50
Timestamp: 2024-12-12T08:34:33.079Z
Learning: Ensure to verify existing ARIA attributes in components before suggesting additions during code reviews, especially in the Dropdown.Trigger component in src/components/ui/Dropdown/Dropdown.stories.tsx.

src/components/ui/NumberField/stories/NumberField.stories.tsx (2)

Learnt from: decipher-cs
PR: #417
File: src/components/ui/Dropdown/Dropdown.stories.tsx:43-50
Timestamp: 2024-12-12T08:34:33.079Z
Learning: Ensure to verify existing ARIA attributes in components before suggesting additions during code reviews, especially in the Dropdown.Trigger component in src/components/ui/Dropdown/Dropdown.stories.tsx.

Learnt from: kotAPI
PR: #1031
File: src/components/ui/Accordion/fragments/AccordionRoot.tsx:41-44
Timestamp: 2025-04-07T04:38:34.864Z
Learning: The Accordion component in rad-ui/ui supports both controlled and uncontrolled modes through props like value, defaultValue, and onValueChange. When implementing controlled components, remember to: 1) Initialize state from defaultValue, 2) Update internal state when value changes (controlled mode), 3) Call onValueChange callback, and 4) Prevent internal state updates when in controlled mode.

src/components/ui/NumberField/fragments/NumberFieldRoot.tsx (1)

Learnt from: kotAPI
PR: #1031
File: src/components/ui/Accordion/fragments/AccordionRoot.tsx:41-44
Timestamp: 2025-04-07T04:38:34.864Z
Learning: The Accordion component in rad-ui/ui supports both controlled and uncontrolled modes through props like value, defaultValue, and onValueChange. When implementing controlled components, remember to: 1) Initialize state from defaultValue, 2) Update internal state when value changes (controlled mode), 3) Call onValueChange callback, and 4) Prevent internal state updates when in controlled mode.

🧬 Code Graph Analysis (1)
src/components/ui/NumberField/fragments/NumberFieldRoot.tsx (1)
src/core/hooks/useControllableState/index.tsx (1)
  • useControllableState (15-78)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (10)
styles/themes/default.scss (1)

40-40: LGTM! Import correctly integrated.

The number-field component import is properly placed in alphabetical order and follows the established pattern for component style imports.

src/components/ui/NumberField/NumberField.tsx (1)

11-14: LGTM! Clean compound component pattern.

The static property assignments follow a clean compound component pattern that enforces modular usage of the NumberField subcomponents.

styles/themes/components/number-field.scss (1)

16-25: LGTM! Excellent cross-browser spinner hiding.

The input styling properly removes native number input spinners across all major browsers using both webkit and standard properties.

src/components/ui/NumberField/fragments/NumberFieldDecrement.tsx (1)

12-15: LGTM! Proper context validation.

The context validation and error handling follow good practices, ensuring the component can only be used within the proper provider.

src/components/ui/NumberField/fragments/NumberFieldIncrement.tsx (1)

12-15: LGTM! Consistent error handling pattern.

The context validation follows the same reliable pattern used in the decrement component.

src/components/ui/NumberField/fragments/NumberFieldInput.tsx (1)

8-24: Good context usage and error handling.

The component properly validates context presence and provides a helpful error message. The destructuring of context values is clean and the type safety is maintained.

src/components/ui/NumberField/contexts/NumberFieldContext.tsx (1)

1-18: Well-structured context definition.

The context type is comprehensive and properly typed. The union type number | '' for inputValue is appropriate for handling empty form states, and the handler function signatures are clear and well-defined.

src/components/ui/NumberField/stories/NumberField.stories.tsx (1)

10-58: Excellent story coverage demonstrating component versatility.

The stories effectively showcase the three main usage patterns: uncontrolled, controlled, and form integration. The consistent prop usage and clear examples make this component easy to understand and use.

src/components/ui/NumberField/fragments/NumberFieldRoot.tsx (2)

26-32: Excellent implementation of controlled/uncontrolled pattern.

The use of useControllableState follows the established pattern from other components in the codebase. The component properly initializes from defaultValue and handles both controlled and uncontrolled modes correctly.


33-49: Solid boundary constraint implementation.

The handleOnChange function properly enforces min/max boundaries and handles the empty string case correctly. The logic flow is clear and handles edge cases appropriately.

Comment on lines 10 to 22
const NumberFieldDecrement = ({ children, className }: NumberFieldDecrementProps) => {
const context = useContext(NumberFieldContext);
if (!context) {
console.error('NumberFieldDecrement must be used within a NumberField');
return null;
}
const { handleStep, rootClass } = context;
return (
<button onClick={() => handleStep({ direction: 'decrement', type: 'small' })} className={clsx(`${rootClass}-decrement`, className)}>
{children}
</button>
);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add accessibility attributes and consider disabled state.

The button lacks accessibility attributes that would help screen readers understand its purpose. Consider adding ARIA attributes and disabled state support.

-const NumberFieldDecrement = ({ children, className }: NumberFieldDecrementProps) => {
+const NumberFieldDecrement = ({ children, className, ...buttonProps }: NumberFieldDecrementProps) => {
     const context = useContext(NumberFieldContext);
     if (!context) {
         console.error('NumberFieldDecrement must be used within a NumberField');
         return null;
     }
-    const { handleStep, rootClass } = context;
+    const { handleStep, rootClass, isDisabled } = context;
     return (
-        <button onClick={() => handleStep({ direction: 'decrement', type: 'small' })} className={clsx(`${rootClass}-decrement`, className)}>
+        <button 
+            onClick={() => handleStep({ direction: 'decrement', type: 'small' })} 
+            className={clsx(`${rootClass}-decrement`, className)}
+            aria-label="Decrement value"
+            disabled={isDisabled}
+            {...buttonProps}
+        >
             {children}
         </button>
     );

You'll also need to update the props type:

 export type NumberFieldDecrementProps = {
     className?: string;
     children?: React.ReactNode
-}
+} & React.ButtonHTMLAttributes<HTMLButtonElement>;

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/components/ui/NumberField/fragments/NumberFieldDecrement.tsx around lines
10 to 22, the button element lacks accessibility attributes and does not handle
a disabled state. Update the component to accept a disabled prop, add
appropriate ARIA attributes such as aria-label to describe the button's action,
and apply the disabled attribute to the button element when needed. Also, update
the NumberFieldDecrementProps type to include the disabled property to support
this functionality.

Comment on lines 10 to 23
const NumberFieldIncrement = ({ children, className }: NumberFieldIncrementProps) => {
const context = useContext(NumberFieldContext);
if (!context) {
console.error('NumberFieldIncrement must be used within a NumberField');
return null;
}
const { handleStep, rootClass } = context;

return (
<button onClick={() => handleStep({ direction: 'increment', type: 'small' })} className={clsx(`${rootClass}-increment`, className)}>
{children}
</button>
);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add accessibility attributes and consider disabled state.

Similar to the decrement component, this button needs accessibility attributes and disabled state support for a complete implementation.

-const NumberFieldIncrement = ({ children, className }: NumberFieldIncrementProps) => {
+const NumberFieldIncrement = ({ children, className, ...buttonProps }: NumberFieldIncrementProps) => {
     const context = useContext(NumberFieldContext);
     if (!context) {
         console.error('NumberFieldIncrement must be used within a NumberField');
         return null;
     }
-    const { handleStep, rootClass } = context;
+    const { handleStep, rootClass, isDisabled } = context;

     return (
-        <button onClick={() => handleStep({ direction: 'increment', type: 'small' })} className={clsx(`${rootClass}-increment`, className)}>
+        <button 
+            onClick={() => handleStep({ direction: 'increment', type: 'small' })} 
+            className={clsx(`${rootClass}-increment`, className)}
+            aria-label="Increment value"
+            disabled={isDisabled}
+            {...buttonProps}
+        >
             {children}
         </button>
     );

Update the props type as well:

 export type NumberFieldIncrementProps = {
     className?: string;
     children?: React.ReactNode
-}
+} & React.ButtonHTMLAttributes<HTMLButtonElement>;
📝 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 NumberFieldIncrement = ({ children, className }: NumberFieldIncrementProps) => {
const context = useContext(NumberFieldContext);
if (!context) {
console.error('NumberFieldIncrement must be used within a NumberField');
return null;
}
const { handleStep, rootClass } = context;
return (
<button onClick={() => handleStep({ direction: 'increment', type: 'small' })} className={clsx(`${rootClass}-increment`, className)}>
{children}
</button>
);
};
const NumberFieldIncrement = ({ children, className, ...buttonProps }: NumberFieldIncrementProps) => {
const context = useContext(NumberFieldContext);
if (!context) {
console.error('NumberFieldIncrement must be used within a NumberField');
return null;
}
const { handleStep, rootClass, isDisabled } = context;
return (
<button
onClick={() => handleStep({ direction: 'increment', type: 'small' })}
className={clsx(`${rootClass}-increment`, className)}
aria-label="Increment value"
disabled={isDisabled}
{...buttonProps}
>
{children}
</button>
);
};
export type NumberFieldIncrementProps = {
className?: string;
children?: React.ReactNode
} & React.ButtonHTMLAttributes<HTMLButtonElement>;
🤖 Prompt for AI Agents
In src/components/ui/NumberField/fragments/NumberFieldIncrement.tsx around lines
10 to 23, the increment button lacks accessibility attributes and disabled state
handling. Add appropriate ARIA attributes such as aria-label to describe the
button's action, and include a disabled prop to control when the button should
be inactive. Update the component's props type to accept a disabled boolean and
apply it to the button element, ensuring consistent behavior and accessibility
similar to the decrement component.

Comment on lines +6 to +9
const NumberField = () => {
console.warn('Direct usage of NumberField is not supported. Please use NumberField.Root, NumberField.Item instead.');
return null;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix incorrect component name in warning message.

The warning message mentions "NumberField.Item" but should reference "NumberField.Input" based on the actual subcomponents exposed.

-    console.warn('Direct usage of NumberField is not supported. Please use NumberField.Root, NumberField.Item instead.');
+    console.warn('Direct usage of NumberField is not supported. Please use NumberField.Root, NumberField.Input, NumberField.Increment, NumberField.Decrement instead.');
📝 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 NumberField = () => {
console.warn('Direct usage of NumberField is not supported. Please use NumberField.Root, NumberField.Item instead.');
return null;
};
const NumberField = () => {
console.warn(
'Direct usage of NumberField is not supported. Please use NumberField.Root, NumberField.Input, NumberField.Increment, NumberField.Decrement instead.'
);
return null;
};
🤖 Prompt for AI Agents
In src/components/ui/NumberField/NumberField.tsx between lines 6 and 9, the
warning message incorrectly references "NumberField.Item" instead of
"NumberField.Input". Update the warning string to mention "NumberField.Input" to
accurately reflect the actual subcomponents users should use.

Comment on lines +28 to +67
.rad-ui-number-field-increment{
width: 2rem;
height: 2rem;
display: flex;
align-items: center;
color: var(--rad-ui-color-accent-50);
justify-content: center;
border: 1px solid var(--rad-ui-color-accent-1000);
background: var(--rad-ui-color-accent-900);
cursor: pointer;
font-size: 1.25rem;
border-radius: 0.375rem;
transition: background 0.2s, border-color 0.2s;

&:hover {
background: var(--rad-ui-color-accent-800);
border-color: var(--rad-ui-color-accent-600);
}
}


.rad-ui-number-field-decrement {
width: 2rem;
height: 2rem;
display: flex;
align-items: center;
color: var(--rad-ui-color-accent-50);
justify-content: center;
border: 1px solid var(--rad-ui-color-accent-1000);
background: var(--rad-ui-color-accent-900);
cursor: pointer;
font-size: 1.25rem;
border-radius: 0.375rem;
transition: background 0.2s, border-color 0.2s;

&:hover {
background: var(--rad-ui-color-accent-800);
border-color: var(--rad-ui-color-accent-600);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Refactor to eliminate code duplication between increment and decrement buttons.

The increment and decrement button styles are nearly identical, leading to code duplication that violates the DRY principle.

+ .rad-ui-number-field-button {
+   width: 2rem;
+   height: 2rem;
+   display: flex;
+   align-items: center;
+   color: var(--rad-ui-color-accent-50);
+   justify-content: center;
+   border: 1px solid var(--rad-ui-color-accent-1000);
+   background: var(--rad-ui-color-accent-900);
+   cursor: pointer;
+   font-size: 1.25rem;
+   border-radius: 0.375rem;
+   transition: background 0.2s, border-color 0.2s;
+
+   &:hover {
+     background: var(--rad-ui-color-accent-800);
+     border-color: var(--rad-ui-color-accent-600);
+   }
+ }

- .rad-ui-number-field-increment{
-   width: 2rem;
-   height: 2rem;
-   display: flex;
-   align-items: center;
-   color: var(--rad-ui-color-accent-50);
-   justify-content: center;
-   border: 1px solid var(--rad-ui-color-accent-1000);
-   background: var(--rad-ui-color-accent-900);
-   cursor: pointer;
-   font-size: 1.25rem;
-   border-radius: 0.375rem;
-   transition: background 0.2s, border-color 0.2s;
-
-   &:hover {
-     background: var(--rad-ui-color-accent-800);
-     border-color: var(--rad-ui-color-accent-600);
-   }
- }

- .rad-ui-number-field-decrement {
-   width: 2rem;
-   height: 2rem;
-   display: flex;
-   align-items: center;
-   color: var(--rad-ui-color-accent-50);
-   justify-content: center;
-   border: 1px solid var(--rad-ui-color-accent-1000);
-   background: var(--rad-ui-color-accent-900);
-   cursor: pointer;
-   font-size: 1.25rem;
-   border-radius: 0.375rem;
-   transition: background 0.2s, border-color 0.2s;
-
-   &:hover {
-     background: var(--rad-ui-color-accent-800);
-     border-color: var(--rad-ui-color-accent-600);
-   }
- }

+ .rad-ui-number-field-increment {
+   @extend .rad-ui-number-field-button;
+ }
+
+ .rad-ui-number-field-decrement {
+   @extend .rad-ui-number-field-button;
+ }
📝 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
.rad-ui-number-field-increment{
width: 2rem;
height: 2rem;
display: flex;
align-items: center;
color: var(--rad-ui-color-accent-50);
justify-content: center;
border: 1px solid var(--rad-ui-color-accent-1000);
background: var(--rad-ui-color-accent-900);
cursor: pointer;
font-size: 1.25rem;
border-radius: 0.375rem;
transition: background 0.2s, border-color 0.2s;
&:hover {
background: var(--rad-ui-color-accent-800);
border-color: var(--rad-ui-color-accent-600);
}
}
.rad-ui-number-field-decrement {
width: 2rem;
height: 2rem;
display: flex;
align-items: center;
color: var(--rad-ui-color-accent-50);
justify-content: center;
border: 1px solid var(--rad-ui-color-accent-1000);
background: var(--rad-ui-color-accent-900);
cursor: pointer;
font-size: 1.25rem;
border-radius: 0.375rem;
transition: background 0.2s, border-color 0.2s;
&:hover {
background: var(--rad-ui-color-accent-800);
border-color: var(--rad-ui-color-accent-600);
}
}
.rad-ui-number-field-button {
width: 2rem;
height: 2rem;
display: flex;
align-items: center;
color: var(--rad-ui-color-accent-50);
justify-content: center;
border: 1px solid var(--rad-ui-color-accent-1000);
background: var(--rad-ui-color-accent-900);
cursor: pointer;
font-size: 1.25rem;
border-radius: 0.375rem;
transition: background 0.2s, border-color 0.2s;
&:hover {
background: var(--rad-ui-color-accent-800);
border-color: var(--rad-ui-color-accent-600);
}
}
.rad-ui-number-field-increment {
@extend .rad-ui-number-field-button;
}
.rad-ui-number-field-decrement {
@extend .rad-ui-number-field-button;
}
🤖 Prompt for AI Agents
In styles/themes/components/number-field.scss between lines 28 and 67, the
styles for .rad-ui-number-field-increment and .rad-ui-number-field-decrement are
nearly identical, causing code duplication. Refactor by extracting the shared
styles into a common class or placeholder selector and then extend or apply that
shared style to both increment and decrement classes to adhere to the DRY
principle.

@kotAPI kotAPI merged commit 1d76b2f into main Jul 23, 2025
7 checks passed
@kotAPI kotAPI deleted the feat/numfield branch July 23, 2025 12:13
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.

[New Feature] NumField Component

3 participants