Skip to content

Commit

Permalink
Merge pull request #149 from balena-io-modules/export-generateColorFr…
Browse files Browse the repository at this point in the history
…omString

export the generateHexColorFromString helper
  • Loading branch information
flowzone-app[bot] authored Nov 13, 2024
2 parents 349baef + cd1cb69 commit 5b9369a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/components/HighlightedName/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Typography, TypographyProps, useTheme } from '@mui/material';

const colorHash = new ColorHash();

export const generateColorFromString = memoize((text: string): string => {
export const generateHexColorFromString = memoize((text: string): string => {
return colorHash.hex(text.replace(/\s/g, ''));
});

Expand All @@ -25,7 +25,10 @@ export const HighlightedName = ({
...props
}: HighlightedNameProps) => {
const theme = useTheme();
const bgColor = useMemo(() => generateColorFromString(children), [children]);
const bgColor = useMemo(
() => generateHexColorFromString(children),
[children],
);

return (
<Typography
Expand Down
5 changes: 4 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ export type {
export { Announcement } from './components/Announcement';
export type { OrderedListItemProps } from './components/OrderedListItem';
export { OrderedListItem } from './components/OrderedListItem';
export { HighlightedName } from './components/HighlightedName';
export {
generateHexColorFromString,
HighlightedName,
} from './components/HighlightedName';
export type { RouterLinkWithTrackingProps } from './components/RouterLinkWithTracking';
export { RouterLinkWithTracking } from './components/RouterLinkWithTracking';
export { SnackbarProviderBase as SnackbarProvider } from './components/SnackbarProvider';
Expand Down

0 comments on commit 5b9369a

Please sign in to comment.