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 Copy and CopyButton #15213

Merged
merged 32 commits into from
Mar 12, 2024

Conversation

Tresau
Copy link
Contributor

@Tresau Tresau commented Nov 15, 2023

Closes #13551
Closes #13227

Add TypeScript types for Copy and CopyButton

Changelog

New

  • Types for Copy and CopyButton

Changed

  • .js -> .tsx file extensions for Copy and CopyButton

Removed

  • n/a

Testing / Reviewing

Verify that the unit tests run and pass.
Verify that the Storybook for CopyButton works as intended.

@Tresau Tresau requested a review from a team as a code owner November 15, 2023 16:44
Comment on lines 111 to 120
// TODO: remove these two lines when IconButton is properly typed, revert TypedIconButton component to IconButton
type IconButtonType = React.ButtonHTMLAttributes<HTMLButtonElement> & {
closeOnActivation?: boolean;
align: string;
label: string | undefined;
};
const TypedIconButton = IconButton as React.FC<IconButtonType>;

return (
<IconButton
<TypedIconButton
Copy link
Contributor Author

Choose a reason for hiding this comment

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

IconButton is not currently typed and as a result causes errors without defining a type for it. #15057 is currently in PR and adds types for IconButton allowing us to remove these lines then. As a result I can either wait on #15057 and remove these lines, or continue with this approach and clean up this todo in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also, should i change the extends for the Copy component as well to extend Carbon button rather than the native button

Copy link
Contributor

Choose a reason for hiding this comment

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

@Tresau-IBM, sorry for the delay on this one. Now that #15057 has been merged, can we use IconButton?

Copy link

netlify bot commented Nov 15, 2023

Deploy Preview for v11-carbon-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 944e3c8
🔍 Latest deploy log https://app.netlify.com/sites/v11-carbon-react/deploys/65f050803490f6000865f3ca
😎 Deploy Preview https://deploy-preview-15213--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.

import Copy from '../Copy';
import { LayoutConstraint } from '../Layout';
import { usePrefix } from '../../internal/usePrefix';
import { noopFn } from '../../internal/noopFn';

export interface CopyButtonProps extends ButtonProps<'button'> {
Copy link
Contributor Author

@Tresau Tresau Nov 29, 2023

Choose a reason for hiding this comment

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

I have changed this to extend Carbon's ButtonProps rather than the native button. I have done this because CodeSnippet passes a size prop to CopyButton, which gets used by Button down the line. Should i also change the Copy type to extend ButtonProps? IS this even the best way to handle the issue, or the correct way to extend the Carbon button.

@tw15egan
Copy link
Contributor

tw15egan commented Feb 5, 2024

@Tresau-IBM now that the types for IconButton have been merged (#15057) has been merged, can this be updated?

@Tresau
Copy link
Contributor Author

Tresau commented Feb 13, 2024

@Tresau-IBM now that the types for IconButton have been merged (#15057) has been merged, can this be updated?

sorry for the delay, was unavailable, will update this shortly :)

@andreancardona
Copy link
Contributor

@Tresau-IBM are you able to resolve the conflicts? Thank you!

@Tresau
Copy link
Contributor Author

Tresau commented Mar 7, 2024

@tw15egan @andreancardona, the conflicts have been resolved and the workaround for IconButton has been removed.

Copy link
Contributor

@tw15egan tw15egan left a comment

Choose a reason for hiding this comment

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

LGTM 👍 ✅ Thanks for sticking with this one 🙏

@tay1orjones tay1orjones added this pull request to the merge queue Mar 12, 2024
Merged via the queue into carbon-design-system:main with commit e443e39 Mar 12, 2024
20 checks passed
@carbon-automation
Copy link
Contributor

Hey there! v11.53.0 was just released that references this issue/PR.

preetibansalui pushed a commit to tay1orjones/carbon that referenced this pull request Apr 24, 2024
* feat: add types to Copy and CopyButton

* refactor: update index files to ts

* refactor: extend Carbon Button rather than native button

* refactor: use IconButtun instead of manually created TypedButton

---------

Co-authored-by: Andrea N. Cardona <[email protected]>
Co-authored-by: TJ Egan <[email protected]>
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 Copy Add TypeScript types to CopyButton
4 participants