carbon-design-system / carbon

A design system built by IBM
https://www.carbondesignsystem.com
Apache License 2.0
7.88k stars 1.82k forks source link

[Feature Request]: As a Developer, I would like to import types from `@carbon/react` #16436

Open digiacomo-a opened 6 months ago

digiacomo-a commented 6 months ago

The problem

Users are often using reusable components to render Tags with different colors (type) based on some status. To achieve this, a TagType enum needs to be defined because we can not import it from carbon/react.

For instance:

enum TagType {
        red = 'red'
        green....
        ... 
}

interface CustomInterface {
  type: TagType,
  title: string,
}

The solution

Could be nice to define and export a TagType containing all supported types and then import it so that we can use it in our interfaces, couple of examples below.

Examples

Example of an interface for Props, with tagType

import {TagType} from '@carbon/react';

interface CustomInterface {
  tagType: TagType,
  title: string,
}

`<MyCustomCardWithTag tagType={TagType.red} title="Example" />`

Application/PAL

No response

Business priority

Low Priority = release date is not dependent on fix or not upcoming

Available extra resources

I'm happy to contribute if this change can be useful.

Code of Conduct

github-actions[bot] commented 6 months ago

Thank you for submitting a feature request. Your proposal is open and will soon be triaged by the Carbon team.

If your proposal is accepted and the Carbon team has bandwidth they will take on the issue, or else request you or other volunteers from the community to work on this issue.

tay1orjones commented 6 months ago

Yes this isn't exported from the root, but it's exported from the root source file and so you can import them like this:

import { TYPES } from '@carbon/react/es/components/Tag/Tag';

I'm not opposed to adding these to the root exports, but we won't be able to do that until everything is converted to .ts, https://github.com/carbon-design-system/carbon/issues/12513, https://github.com/carbon-design-system/carbon/issues/16360

For now I'll add this as a subitem of https://github.com/carbon-design-system/carbon/issues/16154

Gururajj77 commented 4 months ago

I think we have to have all the export types to be named

https://github.com/microsoft/TypeScript/pull/35200

github-actions[bot] commented 3 months ago

Thank you for submitting a feature request. Your proposal is open and will soon be triaged by the Carbon team.

If your proposal is accepted and the Carbon team has bandwidth they will take on the issue, or else request you or other volunteers from the community to work on this issue.

tay1orjones commented 3 weeks ago

If we upgrade to TS v5 we'd be able to just use

export type * from '@carbon/icons-react

in here

https://github.com/carbon-design-system/carbon/blob/51d41fa647bc8d31b428f5c485329664879d5a74/packages/react/icons/src/index.ts#L8

https://github.com/microsoft/TypeScript/pull/52217