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

Export expandColor function from lib/utils/constants #1136

Open
mpotomin opened this issue Jul 15, 2019 · 4 comments
Open

Export expandColor function from lib/utils/constants #1136

mpotomin opened this issue Jul 15, 2019 · 4 comments

Comments

@mpotomin
Copy link
Contributor

As a library user, I would like to have an access to expandColor function located in @operational/components/lib/utils/constants therefore it would be nice to have it exported as a part of public lib API

@harshil1712
Copy link
Contributor

Hey, I would like to take this

@TejasQ
Copy link
Contributor

TejasQ commented Jul 16, 2019

DO IT

lol

@harshil1712
Copy link
Contributor

In constants.ts file the expandColor is already exported.

Line 277

export const expandColor = (
  theme: OperationalStyleConstants,
  colorToBeExpanded?: keyof OperationalStyleConstants["color"] | string,
): string | null => {
  if (!colorToBeExpanded) {
    return null
  }
  if (String(colorToBeExpanded).includes(".")) {
    return get(theme, colorToBeExpanded, "red")
  }
  const hexRegEx = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{8}$)|(^#[0-9A-F]{4}$)|(^#[0-9A-F]{3}$)|currentColor/i
  const isHex = hexRegEx.test(colorToBeExpanded)
  if (isHex) {
    return colorToBeExpanded
  }

  /**
   * This function is typically used in checks.
   * If falsy, it returns a fallback color, hence
   * the empty string return for a falsy value.
   */
  return (theme.color as any)[colorToBeExpanded] || ""
}

I am not sure what I am supposed to here. @TejasQ @mpotomin can you please guide me? Thank you.

@mpotomin
Copy link
Contributor Author

mpotomin commented Jul 19, 2019

Hey @harshil1712.

expandColor is indeed exported from the constants.ts, but for for a library user, who would want to use this function, the import statement in their code would look like

import { expandColor } from "@operational/components/lib/utils/constants";

It looks a bit awkward and gives the feeling of getting things from the library internals.

We could improve that by exporting this function as a part of the library's public API. You can find the example of the util function styled exported at this line of index.ts

Exporting expandColor same way would allow consuming it with a nicer statement:

import {  expandColor } from "@operational/components";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants