operational-ui
operational-ui copied to clipboard
Export `expandColor` function from `lib/utils/constants`
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
Hey, I would like to take this
DO IT
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.
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";