Skip to content

Commit 158375e

Browse files
committed
chore: style resize button
1 parent 9c1e385 commit 158375e

File tree

3 files changed

+58
-21
lines changed

3 files changed

+58
-21
lines changed

packages/module/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableResizableColumnsExample.tsx

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,31 @@ export const ResizableColumnsExample: FunctionComponent = () => {
124124
screenReaderText
125125
}
126126
},
127-
'Pull requests',
128-
{ cell: 'Workspaces', props: { info: { tooltip: 'More information' } } },
129-
{ cell: 'Last commit', props: { sort: { sortBy: {}, columnIndex: 4 } } }
127+
{
128+
cell: 'Pull requests',
129+
resizableProps: {
130+
isResizable: true,
131+
onResize,
132+
screenReaderText
133+
},
134+
props: { info: { tooltip: 'More information' } }
135+
},
136+
{
137+
cell: 'This is a really long title',
138+
resizableProps: {
139+
isResizable: true,
140+
onResize,
141+
screenReaderText
142+
},
143+
props: { info: { tooltip: 'More information' } }
144+
},
145+
{ cell: 'Last commit',
146+
resizableProps: {
147+
isResizable: true,
148+
onResize,
149+
screenReaderText
150+
},
151+
props: { sort: { sortBy: {}, columnIndex: 4 } } }
130152
];
131153

132154
return <DataViewTable isResizable aria-label="Repositories table" ouiaId={ouiaId} columns={columns} rows={rows} />;

packages/module/src/DataViewTh/DataViewTh.tsx

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,29 @@ import {
1111
} from 'react';
1212
import { Th, ThProps } from '@patternfly/react-table';
1313
import { Button, getLanguageDirection } from '@patternfly/react-core';
14+
import { createUseStyles } from 'react-jss';
15+
16+
import c_table_cell_PaddingBlockEnd from '@patternfly/react-tokens/dist/esm/c_table_cell_PaddingBlockEnd';
17+
import c_table_cell_PaddingInlineEnd from '@patternfly/react-tokens/dist/esm/c_table_cell_PaddingInlineEnd';
18+
import t_global_font_size_body_default from '@patternfly/react-tokens/dist/esm/t_global_font_size_body_default';
19+
20+
const ResizeIcon = () => (
21+
<svg className="pf-v6-svg" width="1em" height="1em" viewBox="0 0 1024 1024" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
22+
<path fillRule="evenodd" d="M52.7,529.8l190.5,161.9c18.6,15.9,50.5,4.7,50.5-17.8v-324c0-22.4-31.8-33.6-50.5-17.8L52.7,494.2c-11.5,9.8-11.5,25.8,0,35.6ZM480.8,12.9h62.4v998.3h-62.4V12.9ZM971.3,529.8l-190.5,161.9c-18.6,15.9-50.5,4.7-50.5-17.8v-324c0-22.4,31.8-33.6,50.5-17.8l190.5,161.9c11.5,9.8,11.5,25.8,0,35.6Z"/>
23+
</svg>
24+
);
25+
26+
const useStyles = createUseStyles({
27+
dataViewResizeableTh: {
28+
[c_table_cell_PaddingInlineEnd.name]: `calc(${t_global_font_size_body_default.var} * 2)`
29+
},
30+
dataViewResizableButton: {
31+
position: 'absolute',
32+
insetInlineEnd: `calc(${t_global_font_size_body_default.var} / 2)`,
33+
insetBlockEnd: c_table_cell_PaddingBlockEnd.var,
34+
cursor: 'grab'
35+
},
36+
});
1437
export interface DataViewThResizableProps {
1538
/** Whether the column is resizable */
1639
isResizable?: boolean;
@@ -53,13 +76,15 @@ export const DataViewTh: FC<DataViewThProps> = ({
5376
const thRef = useRef<HTMLTableCellElement>(null);
5477

5578
const [ width, setWidth ] = useState(resizableProps?.width ? resizableProps.width : 0);
79+
const classes = useStyles();
5680

5781
const isResizable = resizableProps?.isResizable || false;
5882
const increment = resizableProps?.increment || 5;
5983
const shiftIncrement = resizableProps?.shiftIncrement || 25;
6084
const resizeButtonAriaLabel = resizableProps?.resizeButtonAriaLabel;
6185
const onResize = resizableProps?.onResize || undefined;
6286
const screenReaderText = resizableProps?.screenReaderText || `Column ${width.toFixed(0)} pixels`;
87+
const dataViewThClassName = isResizable ? classes.dataViewResizeableTh : undefined;
6388

6489
const resizeButtonRef = useRef<HTMLButtonElement>(null);
6590
const setInitialVals = useRef(true);
@@ -260,20 +285,22 @@ export const DataViewTh: FC<DataViewThProps> = ({
260285
};
261286

262287
return (
263-
<Th {...thProps} {...props} style={width > 0 ? { minWidth: width } : undefined} ref={thRef}>
264-
{content}
288+
<Th {...thProps} {...props} style={width > 0 ? { minWidth: width } : undefined} ref={thRef} modifier="truncate" className={dataViewThClassName}>
289+
<span className="pf-v6-c-table__text">
290+
{content}
291+
</span>
265292
{isResizable && (
266293
<Button
267294
ref={resizeButtonRef}
268295
variant="plain"
296+
hasNoPadding
297+
icon={<ResizeIcon />}
269298
onMouseDown={handleMousedown}
270299
onKeyDown={handleKeys}
271300
onTouchStart={handleTouchStart}
272-
style={{ float: 'inline-end' }}
273301
aria-label={resizeButtonAriaLabel}
274-
>
275-
test
276-
</Button>
302+
className={classes.dataViewResizableButton}
303+
/>
277304
)}
278305
{isResizable && (
279306
<div aria-live="polite" className="pf-v6-screen-reader">

packages/module/src/DataViewTh/pf-resize.svg

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)