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(Input): new promo component and tokens update #1441

Merged
merged 5 commits into from
Nov 28, 2024
Merged

Conversation

marcinsawicki
Copy link
Contributor

@marcinsawicki marcinsawicki commented Nov 27, 2024

Resolves: #1345, #1420

Description

New promo variant as a separate component.
Tokens update.

Storybook

https://feature-1345--613a8e945a5665003a05113b.chromatic.com

Checklist

Obligatory:

  • Self review (use this as your final check for proposed changes before requesting the review)
  • Add correct label
  • Assign pull request with the correct issue

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced InputPromo component with promotional styling options.
    • Added new stories for InputPromo showcasing various states and types.
  • Enhancements

    • Updated input component types for better structure and clarity.
    • Simplified color scheme by removing legacy theme definitions.
    • Enhanced CSS with new properties for promotional input borders.
    • Added new entries for promotional border colors in the color definitions.
    • Introduced new shadow effects for active fields in light and dark themes.
    • Updated hover and default border colors for promotional inputs.
  • Bug Fixes

    • Updated shadow and focus ring variables for improved visual consistency across themes.
  • Chores

    • Cleaned up deprecated color variables and improved overall code clarity.

@marcinsawicki marcinsawicki added the feature New feature or request label Nov 27, 2024
@marcinsawicki marcinsawicki added this to the Cycle #10 milestone Nov 27, 2024
@marcinsawicki marcinsawicki self-assigned this Nov 27, 2024
Copy link
Contributor

coderabbitai bot commented Nov 27, 2024

Walkthrough

This pull request introduces significant updates to the React component library, particularly focusing on the Input component and its related types. Key changes include the introduction of a new promotional input variant, updates to type definitions, and the addition of new CSS variables for styling. The modifications enhance type safety and maintainability while aligning the components with the latest design specifications.

Changes

File Change Summary
packages/react-components/src/components/AutoComplete/types.ts Updated import from InputProps to IInputProps and modified AutoCompleteProps accordingly.
packages/react-components/src/components/FormField/FormField.stories.tsx Replaced InputProps with IInputProps in ExampleInput function signature.
packages/react-components/src/components/Input/Input.module.scss Added $base-class variable and new modifier class &--promo for promotional styling.
packages/react-components/src/components/Input/Input.spec.tsx Updated test file to use IInputProps instead of InputProps.
packages/react-components/src/components/Input/Input.stories.tsx Introduced InputPromo component and updated stories to use IInputProps.
packages/react-components/src/components/Input/Input.tsx Renamed Input to InputComponent, introduced InputPromo, and updated props and interfaces.
packages/react-components/src/components/Input/types.ts Added several new interfaces for input components, enhancing type definitions.
packages/react-components/src/foundations/color-scheme.css Removed .lc-legacy-theme class, simplifying the color scheme definitions.
packages/react-components/src/foundations/design-token.ts Added InputPromoBorderDefault and InputPromoBorderHover properties to DesignToken.
packages/react-components/src/foundations/shadow.css Removed legacy shadow variables, updated light and dark theme variables.
packages/react-components/src/stories/foundations/Color/data.ts Added new entries for InputPromoBorderDefault and InputPromoBorderHover in ColorsData.
packages/react-components/src/themes/dark.scss Introduced new promotional border properties in dark theme.
packages/react-components/src/themes/light.scss Added new promotional border properties and updated deprecated variables.

Assessment against linked issues

Objective Addressed Explanation
New Input component for specific cases (#1345)
New prop kind: Promo (#1345)

Possibly related PRs

Suggested reviewers

  • Vladko-uxds
  • VadymBezpalko

🪧 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 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.

@marcinsawicki marcinsawicki linked an issue Nov 27, 2024 that may be closed by this pull request
4 tasks
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: 2

🧹 Outside diff range and nitpick comments (11)
packages/react-components/src/components/Input/types.ts (3)

3-6: Add JSDoc comments for the IInputIcon interface and its properties.

Improve documentation by adding descriptions for the interface and its properties.

+/**
+ * Interface for configuring an icon within an input component
+ */
 export interface IInputIcon {
+  /**
+   * React element to be rendered as the icon
+   */
   source: React.ReactElement;
+  /**
+   * Position of the icon within the input
+   */
   place: 'left' | 'right';
 }

28-33: Document the dimensions for each input size.

The size options would be clearer with specific dimensions or use cases for each variant.

 /**
- * Specify the input size
+ * Specify the input size
+ * - xsmall: [specify dimensions/use case]
+ * - compact: [specify dimensions/use case]
+ * - medium: [specify dimensions/use case]
+ * - large: [specify dimensions/use case]
  */

37-46: Consider alternative design approaches.

Two potential issues:

  1. Required mainClassName might be too restrictive. Consider making it optional and providing a default.
  2. isPromo boolean overlaps with the separate IInputPromoProps interface, which could lead to confusion.

Consider using a discriminated union instead:

export type InputProps = 
  | (IInputGlobalProps & { variant: 'default'; size?: InputSize })
  | (IInputPromoProps & { variant: 'promo' });
packages/react-components/src/components/Input/Input.module.scss (1)

35-43: Consider improvements to the promo variant

Two suggestions for the promo variant:

  1. Consider making the height configurable through a CSS variable for better maintainability
  2. The promo variant should have its own focus state styles to maintain consistency with the hover state customization
 &--promo {
   border: 2px solid var(--input-promo-border-default);
   padding: 0 var(--spacing-4);
-  height: 52px;
+  height: var(--input-promo-height, 52px);

   &:hover {
     border-color: var(--input-promo-border-hover);
   }
+
+  &:focus {
+    border-color: var(--input-promo-border-focus);
+  }
 }
packages/react-components/src/components/Input/Input.spec.tsx (1)

Line range hint 15-106: Add test coverage for new promo variant

The test suite is comprehensive but missing coverage for the new promotional input variant mentioned in the PR objectives.

Please add test cases for:

  • Promo variant rendering
  • Promo-specific styling
  • Promo-specific behavior

Would you like me to help draft the test cases for the promo variant?

packages/react-components/src/components/Input/Input.stories.tsx (2)

126-128: Consider adding args table configuration.

The basic InputPromo story could benefit from the same argTypes configuration as the Default story to improve documentation.

+InputPromo.args = {
+  inputSize: 'medium',
+  placeholder: 'Placeholder text',
+};

126-200: LGTM! Comprehensive story coverage.

The new stories provide excellent coverage of the InputPromo component variants, following the same consistent pattern as the regular Input stories.

Consider adding JSDoc comments to describe promo-specific features and use cases.

packages/react-components/src/themes/light.scss (1)

215-215: Consider using the SCSS variable for consistency.

The hardcoded value #43434b should reference $decor-gray600 to maintain consistency with other color definitions.

-  --action-high-contrast-hover: #43434b;
+  --action-high-contrast-hover: #{$decor-gray600};
packages/react-components/src/themes/dark.scss (1)

398-399: Use design tokens for color values

Consider using the existing design tokens instead of hardcoded values:

- --input-promo-border-default: #62626d;
- --input-promo-border-hover: #8d8d95;
+ --input-promo-border-default: var(--decor-gray500);
+ --input-promo-border-hover: var(--decor-gray300);

Also, consider adding --input-promo-border-disabled for consistency with other input variants.

packages/react-components/src/foundations/design-token.ts (1)

386-387: Add JSDoc comments to document the new tokens

The new promo input tokens follow the naming conventions, but would benefit from documentation.

+  /** Border color for promo input in default state */
   InputPromoBorderDefault: '--input-promo-border-default',
+  /** Border color for promo input in hover state */
   InputPromoBorderHover: '--input-promo-border-hover',
packages/react-components/src/stories/foundations/Color/data.ts (1)

1479-1488: Add descriptions for the new color tokens.

The implementation looks good, but please add meaningful descriptions to maintain consistency with other tokens in the ColorsData object.

Apply this diff:

   InputPromoBorderDefault: {
     group: ColorGroup.BorderBasic,
-    desc: '',
+    desc: 'Default border color for promotional input component',
     deprecated: false,
   },
   InputPromoBorderHover: {
     group: ColorGroup.BorderBasic,
-    desc: '',
+    desc: 'Hover state border color for promotional input component',
     deprecated: false,
   },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 75e7e14 and ac8d91f.

📒 Files selected for processing (13)
  • packages/react-components/src/components/AutoComplete/types.ts (2 hunks)
  • packages/react-components/src/components/FormField/FormField.stories.tsx (2 hunks)
  • packages/react-components/src/components/Input/Input.module.scss (2 hunks)
  • packages/react-components/src/components/Input/Input.spec.tsx (1 hunks)
  • packages/react-components/src/components/Input/Input.stories.tsx (3 hunks)
  • packages/react-components/src/components/Input/Input.tsx (5 hunks)
  • packages/react-components/src/components/Input/types.ts (1 hunks)
  • packages/react-components/src/foundations/color-scheme.css (0 hunks)
  • packages/react-components/src/foundations/design-token.ts (1 hunks)
  • packages/react-components/src/foundations/shadow.css (2 hunks)
  • packages/react-components/src/stories/foundations/Color/data.ts (1 hunks)
  • packages/react-components/src/themes/dark.scss (1 hunks)
  • packages/react-components/src/themes/light.scss (2 hunks)
💤 Files with no reviewable changes (1)
  • packages/react-components/src/foundations/color-scheme.css
🔇 Additional comments (20)
packages/react-components/src/components/Input/types.ts (1)

8-26: LGTM! Well-structured base interface with clear documentation.

The interface provides a solid foundation for input components with essential props and proper JSDoc comments.

packages/react-components/src/components/AutoComplete/types.ts (2)

5-5: LGTM! Interface naming follows TypeScript conventions

The change to IInputProps aligns with TypeScript interface naming conventions and provides better module organization by importing directly from the types file.


16-16: Verify the interface compatibility across components

The change from InputProps to IInputProps looks good, but let's ensure all consuming components are updated.

✅ Verification successful

All consuming components are correctly using IInputProps

The codebase shows consistent usage of IInputProps. The AutoCompleteProps interface correctly extends from IInputProps, and all other components that need this interface are importing and using it properly. No instances of an old InputProps interface were found that would conflict with this change.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining usages of old InputProps interface
# and verify IInputProps usage consistency

# Search for old InputProps usage
echo "Checking for old InputProps usage..."
rg "InputProps" --type ts

# Search for new IInputProps usage to verify consistency
echo "Verifying IInputProps usage..."
rg "IInputProps" --type ts

Length of output: 6676

packages/react-components/src/components/Input/Input.module.scss (1)

1-3: LGTM! Good use of SCSS variable for maintainability

The introduction of $base-class variable makes the component's base class name configurable from a single location.

packages/react-components/src/components/FormField/FormField.stories.tsx (2)

5-6: LGTM: Clean import restructuring

The separation of types into a dedicated types file follows best practices for better code organization.


30-32: LGTM: Type definition update aligns with new input system

The switch to IInputProps maintains consistency with the new promo component changes.

✅ Verification successful

Type definition is correctly used and consistent

The usage of IInputProps in FormField.stories is properly imported from Input/types and aligns with the component's type system. The interface extends IInputGlobalProps with an additional inputSize prop, making it the correct choice for the Input component usage.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify consistent usage of IInputProps across the codebase
ast-grep --pattern 'IInputProps'

Length of output: 550


Script:

#!/bin/bash
# Check the content of Input/types.ts to verify IInputProps definition
cat packages/react-components/src/components/Input/types.ts

# Check if there are any other input-related interfaces that might conflict
rg "interface.*Input" --type ts

Length of output: 2058

packages/react-components/src/foundations/shadow.css (3)

58-58: Good contrast adjustment for dark theme

The increased opacity (25%) for active field state in dark theme provides better visibility while maintaining the design aesthetic.


Line range hint 10-10: Verify impact of focus shadow color change

The focus shadow color change (#4284f5 → #0059e1) appears to be more accessible, but let's verify it doesn't break existing components.

✅ Verification successful

Focus shadow color change is safe and consistent

The new color #0059e1 is already being used as the focus shadow color in the light theme, and multiple components are correctly using the --shadow-focus CSS variable. The change maintains design system consistency.

  • Components using focus shadow:
    • Switch
    • OnboardingChecklist
    • Checkbox
    • Button
    • ActionCard
    • Accordion
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any components that might be affected by the focus shadow change
rg --type css "4284f5"

Length of output: 22


Script:

#!/bin/bash
# Search for any components that might be affected by the focus shadow color
rg --type css "0059e1|#0059e1"

# Also search for any shadow-related CSS variables that might reference focus shadows
rg --type css "shadow.*focus|focus.*shadow"

Length of output: 2399


27-27: Verify contrast ratio for active field state

The 15% opacity for active field state in light theme might be too subtle for some users.

✅ Verification successful

Active field state opacity values are appropriately set for both themes

The opacity values are well-considered:

  • Light theme: 15% opacity provides subtle but visible feedback
  • Dark theme: 25% opacity ensures better visibility in dark mode
  • Consistent with existing shadow patterns in the codebase
  • Follows accessibility guidelines found in documentation regarding contrast and keyboard interactions
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are any accessibility guidelines or contrast ratio requirements in the codebase
rg -i "contrast|a11y|accessibility" "*.md"

Length of output: 89


Script:

#!/bin/bash
# Search for accessibility-related content in all markdown files recursively
fd -e md -x rg -i "contrast|a11y|accessibility" {}

# Check for any design tokens or guidelines documentation
fd -e md -g "*design*" -g "*token*" -g "*style*" -g "*theme*" -x rg -i "contrast|color|opacity" {}

# Look for any test files related to these design tokens
fd -e test.js -e test.ts -e spec.js -e spec.ts -x rg -i "shadow|active.*field|focus" {}

# Check if there are similar opacity values used elsewhere in CSS
fd -e css -x rg -i "opacity|rgb.*\/\s*[0-9]+%" {}

Length of output: 2904


Script:

#!/bin/bash
# Check for opacity values in CSS files with fixed regex
fd -e css -x rg -l "opacity:|rgb.*\([^)]*\/\s*\d+%\)" {}

# Look for similar active states in CSS
fd -e css -x rg "active.*field|--state-active" {}

# Check the shadow.css file content
cat packages/react-components/src/foundations/shadow.css

Length of output: 5048

packages/react-components/src/components/Input/Input.spec.tsx (2)

9-10: LGTM! Clean type import update


12-13: Verify type consistency across test helpers

The type update looks good, but let's ensure all test utilities are updated consistently.

✅ Verification successful

Type consistency verified across input components

Each input component follows its own consistent type naming convention:

  • Input: IInputProps
  • SearchInput: ISearchInputProps
  • NumericInput: NumericInputProps
  • TagInput: TagInputProps<T>
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining uses of InputProps in test files
rg "InputProps" --type ts --type tsx | grep -i "spec\|test"

Length of output: 87


Script:

#!/bin/bash
# Search for test files first
fd ".*\.(spec|test)\.(ts|tsx)$"

# Then search for InputProps pattern in those files
fd ".*\.(spec|test)\.(ts|tsx)$" --exec rg -l "InputProps" {}

Length of output: 5685


Script:

#!/bin/bash
# Check the actual usage context of InputProps in the identified files
rg -B2 -A2 "InputProps" ./packages/react-components/src/components/Input/Input.spec.tsx ./packages/react-components/src/components/TagInput/TagInput.spec.tsx ./packages/react-components/src/components/SearchInput/SearchInput.spec.tsx ./packages/react-components/src/components/NumericInput/NumericInput.spec.tsx

Length of output: 4613

packages/react-components/src/components/Input/Input.stories.tsx (2)

9-10: LGTM! Clean import structure and consistent type naming.

The aliasing of InputPromo to InputPromoComponent improves clarity, and the interface naming follows the 'I' prefix convention.


31-31: LGTM! Consistent type usage.

Type update aligns with the new interface naming convention.

packages/react-components/src/themes/light.scss (1)

400-401: LGTM! New promo input border properties.

The values align well with the existing color system and support the new promo input component requirements.

packages/react-components/src/components/Input/Input.tsx (6)

13-18: Imports restructured for better type management.

Importing all the necessary types from './types' improves code organization and maintainability.


Line range hint 24-30: renderIcon function correctly utilizes IInputIcon interface.

The renderIcon function properly clones the icon element with appropriate class names based on its placement and disability state.


Line range hint 36-85: Enhanced InputComponent with new props for flexibility.

Adding mainClassName and isPromo props to InputComponent increases its versatility, allowing for customized styling and promotional variants.


85-85: Conditional text size aligns with promo requirements.

Setting the Text component's size based on isPromo ensures that promotional inputs have the intended larger text size.


122-133: Input component simplifies size-based styling.

The Input component now wraps InputComponent, applying mainClassName based on inputSize, which streamlines the usage of input sizes throughout the codebase.


137-150: Introduced InputPromo for promotional input variants.

The new InputPromo component effectively applies promotional styles and sets isPromo, fulfilling the PR's objective to create a promo variant.

@vladko-uxds
Copy link

Need to add shadow when filed is active (typing mode or focussed) shadow --state-active-field
Monosnap Forms : Input - Input Promo ⋅ Storybook 2024-11-27 13-48-01

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

🧹 Outside diff range and nitpick comments (2)
packages/react-components/src/components/Input/Input.tsx (2)

Line range hint 24-34: Add return type annotation for better type safety

The renderIcon function should explicitly declare its return type for better maintainability.

-const renderIcon = (icon: IInputIcon, disabled?: boolean) =>
+const renderIcon = (icon: IInputIcon, disabled?: boolean): JSX.Element =>

Line range hint 85-89: Fix tabIndex attribute name

The HTML attribute should be tabIndex (camelCase) instead of tab-index (kebab-case) in React.

-        tab-index="0"
+        tabIndex={0}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between f51aab0 and e26dcd5.

📒 Files selected for processing (1)
  • packages/react-components/src/components/Input/Input.tsx (5 hunks)
🔇 Additional comments (3)
packages/react-components/src/components/Input/Input.tsx (3)

13-18: LGTM! Clean type organization

Good separation of concerns by moving interfaces to a separate types file.


122-133: LGTM! Clean wrapper implementation

Good use of default props and proper component composition.


135-150: Verify shadow effect implementation

Per vladko-uxds's feedback, ensure the promo variant includes the requested shadow effect on focus.

✅ Verification successful

Shadow effect is properly implemented

The promo variant includes the requested shadow effect on focus:

&--promo {
  &.#{$base-class}--focused,
  &.#{$base-class}--focused:hover {
    box-shadow: var(--state-active-field);
  }
}
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for shadow-related CSS properties in the styles
rg -g '*.scss' -g '*.css' 'box-shadow.*promo.*focused'

Length of output: 56


Script:

#!/bin/bash
# Let's try a broader search for shadow styles in promo variant
rg -g '*.scss' -g '*.css' '\.promo.*box-shadow'

# Also search for the specific class name pattern
rg -g '*.scss' -g '*.css' "${baseClass}--promo.*box-shadow"

# Search for any shadow properties in the component's style file
fd -e scss -e css "Input" --exec rg "box-shadow" {}

Length of output: 640


Script:

#!/bin/bash
# Let's find and check the Input component's style file content
fd -e scss -e css "Input" --exec cat {}

# Also search for any focus-related styles
fd -e scss -e css "Input" --exec rg "focus|focused" {}

Length of output: 9769

Copy link

@vladko-uxds vladko-uxds left a comment

Choose a reason for hiding this comment

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

👍

@marcinsawicki marcinsawicki merged commit 151a4d8 into main Nov 28, 2024
7 checks passed
@marcinsawicki marcinsawicki deleted the feature/1345 branch November 28, 2024 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
Development

Successfully merging this pull request may close these issues.

[Tokens] - add new [Inputs] - new kind Promo, size
3 participants