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

feat: Adds visible prop to TableCellActions #24831

Merged
merged 3 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
43 changes: 43 additions & 0 deletions apps/vr-tests-react-components/src/stories/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,49 @@ storiesOf('Table - cell actions', module)
</Table>
),
{ includeDarkMode: true, includeHighContrast: true, includeRtl: true },
)
.addStory(
'always visible',
() => (
<Table>
<TableHeader>
<TableRow>
{columns.map(column => (
<TableHeaderCell key={column.columnKey}>{column.label}</TableHeaderCell>
))}
</TableRow>
</TableHeader>
<TableBody>
{items.map(item => (
<TableRow key={item.file.label} className="row">
<TableCell>
<TableCellLayout media={item.file.icon}>
{item.file.label}
<TableCellActions visible>
<Button icon={<EditRegular />} appearance="subtle" />
<Button icon={<MoreHorizontalRegular />} appearance="subtle" />
</TableCellActions>
</TableCellLayout>
</TableCell>
<TableCell>
<TableCellLayout
media={
<Avatar name={item.author.label} badge={{ status: item.author.status as PresenceBadgeStatus }} />
}
>
{item.author.label}
</TableCellLayout>
</TableCell>
<TableCell>{item.lastUpdated.label}</TableCell>
<TableCell>
<TableCellLayout media={item.lastUpdate.icon}>{item.lastUpdate.label}</TableCellLayout>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
),
{ includeDarkMode: true, includeHighContrast: true, includeRtl: true },
);

storiesOf('Table', module)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "feat: Adds `visible` prop to `TableCellActions`",
"packageName": "@fluentui/react-table",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,17 @@ export const TableCellActions: ForwardRefComponent<TableCellActionsProps>;
export const tableCellActionsClassNames: SlotClassNames<TableCellActionsSlots>;

// @public
export type TableCellActionsProps = ComponentProps<TableCellActionsSlots> & {};
export type TableCellActionsProps = ComponentProps<TableCellActionsSlots> & {
visible?: boolean;
};

// @public (undocumented)
export type TableCellActionsSlots = {
root: Slot<'div'>;
};

// @public
export type TableCellActionsState = ComponentState<TableCellActionsSlots>;
export type TableCellActionsState = ComponentState<TableCellActionsSlots> & Pick<Required<TableCellActionsProps>, 'visible'>;

// @public (undocumented)
export const tableCellClassName = "fui-TableCell";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@ export type TableCellActionsSlots = {
/**
* TableCellActions Props
*/
export type TableCellActionsProps = ComponentProps<TableCellActionsSlots> & {};
export type TableCellActionsProps = ComponentProps<TableCellActionsSlots> & {
/**
* When true, the actions are always visible regardless of row hover.
* Can be useful keeping the actions visible when a popout surface is opened.
*/
visible?: boolean;
};

/**
* State used in rendering TableCellActions
*/
export type TableCellActionsState = ComponentState<TableCellActionsSlots>;
export type TableCellActionsState = ComponentState<TableCellActionsSlots> &
Pick<Required<TableCellActionsProps>, 'visible'>;
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ export const useTableCellActions_unstable = (
ref: useMergedRefs(ref, useFocusWithin()),
...props,
}),
visible: props.visible ?? false,
};
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { makeStyles, mergeClasses } from '@griffel/react';
import { tokens } from '@fluentui/react-theme';
import type { TableCellActionsSlots, TableCellActionsState } from './TableCellActions.types';
import type { SlotClassNames } from '@fluentui/react-utilities';
import { createCustomFocusIndicatorStyle } from '@fluentui/react-tabster';
Expand All @@ -19,7 +18,6 @@ const useStyles = makeStyles({
transform: 'translateY(-50%)',
opacity: 0,
marginLeft: 'auto',
backgroundColor: tokens.colorNeutralBackground1Hover,

...createCustomFocusIndicatorStyle(
{
Expand All @@ -28,14 +26,23 @@ const useStyles = makeStyles({
{ selector: 'focus-within' },
),
},

visible: {
opacity: 1,
},
});

/**
* Apply styling to the TableCellActions slots based on the state
*/
export const useTableCellActionsStyles_unstable = (state: TableCellActionsState): TableCellActionsState => {
const styles = useStyles();
state.root.className = mergeClasses(tableCellActionsClassNames.root, styles.root, state.root.className);
state.root.className = mergeClasses(
tableCellActionsClassNames.root,
styles.root,
state.visible && styles.visible,
state.root.className,
);

return state;
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ const useStyles = makeStyles({
color: tokens.colorNeutralForeground1,
':hover': {
backgroundColor: tokens.colorNeutralBackground1Hover,
color: tokens.colorNeutralForeground1Hover,
[`& .${tableCellActionsClassNames.root}`]: {
backgroundColor: tokens.colorNeutralBackground1Hover,
opacity: 1,
},
},
Expand Down