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: add types to ComboButton #16038

Merged

Conversation

cuppajoey
Copy link
Contributor

@cuppajoey cuppajoey commented Mar 22, 2024

Closes #15178

Convert ComboButton to Typescript and export newly added interface ComboButtonProps.

Changelog

New

  • Rename ComboButton/index.jsComboButton/index.tsx.
  • Introduce and export ComboButtonProps.

Changed

  • Fix typo in ComboButton.propTypes.label description.

Testing / Reviewing

  • Verify new types match the component's PropTypes.
  • Check for Type errors.

Convert `ComboButton` to Typescript and export newly added
interface `ComboButtonProps`.
@cuppajoey cuppajoey requested a review from a team as a code owner March 22, 2024 20:05
Copy link

netlify bot commented Mar 22, 2024

Deploy Preview for v11-carbon-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 02fb31f
🔍 Latest deploy log https://app.netlify.com/sites/v11-carbon-react/deploys/65fde4940cd45a0008fbe3ac
😎 Deploy Preview https://deploy-preview-16038--v11-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor Author

@cuppajoey cuppajoey left a comment

Choose a reason for hiding this comment

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

I apologize for the diff. I did execute git mv instead of directly renaming the file, but after the pre-commit hooks ran it updated the diff 🫠.

In an effort to make the review easier, I documented my changes below.

/**
* Specify the size of the buttons and menu.
*/
size?: 'sm' | 'md' | 'lg';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since size is passed to Button, IconButton, and Menu, I typed it statically as each component accepts different, additional values.

For example, Menu also accepts xs, which Button and IconButton do not accept. Conversely, the latter components accept xl and 2xl.

Comment on lines +97 to +98
const containerRef = useRef<HTMLDivElement>(null);
const menuRef = useRef<React.ComponentRef<typeof Menu>>(null);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added types for containerRef and menuRef.

}
}

function handlePrimaryActionClick(e: React.MouseEvent<HTMLButtonElement>) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added type for the event (e) argument.

Comment on lines +125 to +132
if (menuRef.current) {
menuRef.current.style.inlineSize = `${width}px`;
menuRef.current.style.minInlineSize = `${width}px`;

if (menuAlignment !== 'bottom' && menuAlignment !== 'top') {
menuRef.current.style.inlineSize = `fit-content`;
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a null-check for menuRef.current.

disabled: PropTypes.bool,

/**
* Provide the label to be rendered on the primary action button.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed a typo: "renderd" → "rendered".

return defaultTranslations[messageId];
}

interface ComboButtonProps {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

New types for component props.

Where possible, I pulled the types dynamically from the components that consume these props e.g., children is passed to Menu.children.

'carbon.combo-button.additional-actions': 'Additional actions',
};

function defaultTranslateWithId(messageId: string) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added type for messageId.

translateWithId?: (id: string) => string;
}

const ComboButton = React.forwardRef<HTMLDivElement, ComboButtonProps>(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added types for ComboButton and its props.

Copy link
Member

@tay1orjones tay1orjones left a comment

Choose a reason for hiding this comment

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

Looks great, thanks so much!

@alisonjoseph alisonjoseph added this pull request to the merge queue Apr 1, 2024
Merged via the queue into carbon-design-system:main with commit daddb69 Apr 1, 2024
20 checks passed
preetibansalui pushed a commit to tay1orjones/carbon that referenced this pull request Apr 24, 2024
Convert `ComboButton` to Typescript and export newly added
interface `ComboButtonProps`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add TypeScript types to ComboButton
3 participants