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

fix(headercell): added new hover prop to control component hover state #928

Merged
merged 3 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export default {
control: { type: "select" },
options: ["left", "center", "right"],
},
hover: {
control: { type: "boolean" },
},
shouldShowTooltipOnHover: {
control: { type: "boolean" },
},
Expand All @@ -44,6 +47,7 @@ export const Default = {
active: false,
direction: "desc",
hideSortIcon: false,
hover: true,
shouldShowTooltipOnHover: true,
tooltipProps: { sdsStyle: "dark" },
tooltipText: "This is a header cell",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const CellBasicNameSpaceTest = (props: CellHeaderProps) => {
direction="asc"
active
hideSortIcon
hover
horizontalAlign="center"
shouldShowTooltipOnHover
tooltipProps={{ sdsStyle: "light" }}
Expand Down
19 changes: 13 additions & 6 deletions packages/components/src/core/CellHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface CellHeaderContentProps {
hideSortIcon?: boolean;
horizontalAlign?: "left" | "center" | "right";
children: React.ReactNode;
hover?: boolean;
}

interface CellHeaderRawProps
Expand All @@ -39,6 +40,7 @@ const CellHeaderContent = (
direction = "desc",
hideSortIcon = false,
horizontalAlign,
hover,
} = props;

const sdsIconName: keyof IconNameToSizes =
Expand All @@ -61,7 +63,7 @@ const CellHeaderContent = (
return (
<StyledCellHeaderContainer horizontalAlign={horizontalAlign}>
<span>{children}</span>
{(!hideSortIcon || active) && sortIcon}
{(!hideSortIcon || active) && hover && sortIcon}
</StyledCellHeaderContainer>
);
};
Expand All @@ -74,10 +76,11 @@ const CellHeader = forwardRef<HTMLTableCellElement, CellHeaderProps>(
tooltipProps,
tooltipText = "",
tooltipSubtitle,
hover = true,
...rest
} = props;

if (shouldShowTooltipOnHover) {
if (shouldShowTooltipOnHover && hover) {
return (
<Tooltip
arrow
Expand All @@ -87,15 +90,19 @@ const CellHeader = forwardRef<HTMLTableCellElement, CellHeaderProps>(
title={tooltipText}
{...tooltipProps}
>
<StyledTableHeader ref={ref} {...rest}>
<CellHeaderContent {...props}>{children}</CellHeaderContent>
<StyledTableHeader ref={ref} hover={hover} {...rest}>
<CellHeaderContent {...props} hover={hover}>
{children}
</CellHeaderContent>
</StyledTableHeader>
</Tooltip>
);
}
return (
<StyledTableHeader ref={ref} {...rest}>
<CellHeaderContent {...props}>{children}</CellHeaderContent>
<StyledTableHeader ref={ref} hover={hover} {...rest}>
<CellHeaderContent hover={hover} {...props}>
{children}
</CellHeaderContent>
</StyledTableHeader>
);
}
Expand Down
20 changes: 15 additions & 5 deletions packages/components/src/core/CellHeader/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface CellHeaderExtraProps extends CommonThemeProps {
active?: boolean;
hideSortIcon?: boolean;
horizontalAlign?: "left" | "center" | "right";
hover?: boolean;
}

const contentPositionMapping = {
Expand All @@ -27,6 +28,7 @@ const doNotForwardProps = [
"tooltipProps",
"tooltipText",
"hideSortIcon",
"hover",
];

export const StyledSortingIcon = styled(Icon, {
Expand Down Expand Up @@ -55,28 +57,36 @@ export const StyledTableHeader = styled("th", {
${focusVisibleA11yStyle}

${(props: CellHeaderExtraProps) => {
const { active = false, horizontalAlign = "left" } = props;
const { active = false, horizontalAlign = "left", hover = true } = props;
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like it defaults to "true" 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it ok? or should it be the other way around? 🤔
What do you think @clarsen-czi?

Copy link
Contributor

Choose a reason for hiding this comment

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

@clarsen-czi sorry I think we still need your feedback here 😁 🙏

If we default hover to true, it would mean that the CellHeader could have hover effect when no corresponding action is present/implemented, so the question here is whether we should default hover to false instead to prevent that?

Thank you!

Choose a reason for hiding this comment

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

Good call @tihuan! I agree that having it default to false makes the most sense. Thanks for the suggestion!


const spaces = getSpaces(props);
const semanticColors = getSemanticColors(props);

const defaultColor = active
? semanticColors?.accent?.textAction
: semanticColors?.base?.textSecondary;

const hoverColor = active
? semanticColors?.accent?.textActionHover
: semanticColors?.base?.textPrimary;

return `
color: ${active ? semanticColors?.accent?.textAction : semanticColors?.base?.textSecondary};
color: ${defaultColor};
padding: ${spaces?.l}px ${spaces?.m}px;
text-align: ${horizontalAlign};
min-width: 96px;
cursor: pointer;
cursor: ${hover ? "pointer" : "default"};
vertical-align: bottom;

& .MuiButtonBase-root {
outline: none;
}

&:hover {
color: ${active ? semanticColors?.accent?.textActionHover : semanticColors?.base?.textPrimary};
color: ${hover ? hoverColor : defaultColor};

& .MuiButtonBase-root {
color: ${active ? semanticColors?.accent?.textActionHover : semanticColors?.base?.textPrimary};
color: ${hoverColor};
opacity: 1;
}

Expand Down
Loading