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

refactor(containedlist): added typescript types to containedlist #16115

Merged
merged 4 commits into from
Apr 30, 2024

Conversation

Gururajj77
Copy link
Contributor

Closes #16019

Added typescript types to ContainedList component

Changelog

New

  • added interfaces for props to ContainedList and ContainedListItem

Changed

  • Renamed files from .js to .tsx

Testing / Reviewing

This new PR holds the review comments from #16047

No new observations on testing.

Copy link

netlify bot commented Apr 2, 2024

Deploy Preview for v11-carbon-react ready!

Name Link
🔨 Latest commit 36c05bd
🔍 Latest deploy log https://app.netlify.com/sites/v11-carbon-react/deploys/662a7cefa3096e0008a4a6b9
😎 Deploy Preview https://deploy-preview-16115--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
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.

Just a couple small things I noticed

/**
* A label describing the contained list.
*/
label: ReactNode;
Copy link
Member

Choose a reason for hiding this comment

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

This accepts a string too, right?

Suggested change
label: ReactNode;
label: string | ReactNode;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I overlooked it, will make the changes.

import PropTypes from 'prop-types';
import classNames from 'classnames';
import { LayoutConstraint } from '../Layout';
import { useId } from '../../internal/useId';
import { usePrefix } from '../../internal/usePrefix';

const variants = ['on-page', 'disclosed'];
const variants: ('on-page' | 'disclosed')[] = ['on-page', 'disclosed'];
Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to use this root definition for both the proptypes and the TS interface? Something like this maybe

const variants = ['on-page', 'disclosed'] as const;

// I think this will be typed as 'on-page' | 'disclosed' because the typeof operator returns the inferred type?
type Variants = typeof variants[number]; 


// ...then below in the interface:

kind?: Variants;

Comment on lines 116 to 123
const isActionSearch =
React.isValidElement(action) &&
(typeof action.type === 'string'
? ['Search', 'ExpandableSearch'].includes(action.type)
: typeof action.type === 'function' &&
'displayName' in action.type &&
(action.type.displayName === 'Search' ||
action.type.displayName === 'ExpandableSearch'));
Copy link
Member

Choose a reason for hiding this comment

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

Is there any way to simplify this? It's really dense and hard to read. Is there another spot in the codebase we validate/check displayName/type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will to simplify this and make it more readable.

Copy link
Member

@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 👍 ✅

@tw15egan tw15egan enabled auto-merge April 25, 2024 16:47
@tw15egan tw15egan added this pull request to the merge queue Apr 30, 2024
Merged via the queue into carbon-design-system:main with commit b6e8253 Apr 30, 2024
20 checks passed
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 ContainedList and ContainedListItem
4 participants