Skip to content

Commit

Permalink
feat: Table toobar add disabled status (#319)
Browse files Browse the repository at this point in the history
* fix: Fix fixed table style

Signed-off-by: yazhou <[email protected]>

* chore: remove console.log

Signed-off-by: yazhou <[email protected]>

* feat: Table add disabled state to FilterInput and Toolbar components

Signed-off-by: yazhou <[email protected]>

* ci: update version

Signed-off-by: yazhou <[email protected]>

* style: FilterInput disabled style

Signed-off-by: yazhou <[email protected]>

---------

Signed-off-by: yazhou <[email protected]>
  • Loading branch information
yazhouio authored Nov 12, 2024
1 parent 415f833 commit 9afc383
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 16 deletions.
14 changes: 14 additions & 0 deletions .changeset/few-grapes-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@kubed/code-editor': patch
'@kubed/diff-viewer': patch
'@kubed/components': patch
'@kubed/log-viewer': patch
'@kubed/charts': patch
'@kubed/hooks': patch
'@kubed/icons': patch
'@kubed/tests': patch
'kubed-documents': patch
---

1. Fix table fixed style.
2. Table toolbar support disabled status.
8 changes: 8 additions & 0 deletions packages/components/src/FilterInput/FilterInput.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ export const Wrapper = styled.div`
border-color: ${({ theme }) => theme.palette.border};
}
&.is-disabled {
border: solid 1px transparent;
opacity: 0.6;
cursor: not-allowed;
& > * {
pointer-events: none;
}
}
&.has-value,
&.is-focused {
background-color: ${({ theme }) => theme.palette.background};
Expand Down
7 changes: 6 additions & 1 deletion packages/components/src/FilterInput/FilterInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface FilterInputProps extends DefaultProps {
// renderMenuItem?: () => void;
initialKeyword?: string;
simpleMode?: boolean;
disabled?: boolean;
}

export const FilterInput = forwardRef<FilterInputProps, null>((props, ref) => {
Expand Down Expand Up @@ -261,7 +262,11 @@ export const FilterInput = forwardRef<FilterInputProps, null>((props, ref) => {

return (
<Wrapper
className={cx(props.className, { 'has-value': hasValue, 'is-focused': isFocused })}
className={cx(props.className, {
'has-value': hasValue,
'is-focused': isFocused,
'is-disabled': props.disabled,
})}
ref={ref}
>
<Magnifier className="icon-search" />
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/Table/BaseTable/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const TableRoot = styled('table')<{
},
...($stickyHeader && {
borderCollapse: 'separate',
width: 'max-content',
minWidth: '100%',
}),
}));

Expand Down
17 changes: 12 additions & 5 deletions packages/components/src/Table/BaseTable/TableCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type OwnerState = Pick<
| 'fixedLastLeft'
| 'fixedLastRight'
| 'hasBorder'
| 'width'
>;
const TableCellRoot = styled.td<{
$ownerState: OwnerState;
Expand All @@ -50,6 +51,7 @@ const TableCellRoot = styled.td<{
fixedLastLeft,
fixedLastRight,
hasBorder = false,
width,
},
}) => {
const paddingV =
Expand All @@ -70,6 +72,9 @@ const TableCellRoot = styled.td<{
return {
display: 'table-cell',
verticalAlign: 'inherit',
...(width && {
width: typeof width === 'number' ? `${width}px` : width,
}),
// boxShadow: `inset 0 -1px 0 0 ${theme.palette.accents_1}`,
...(size && {
height: {
Expand Down Expand Up @@ -104,16 +109,17 @@ const TableCellRoot = styled.td<{
zIndex: 1,
backgroundColor: theme.palette.background,
}),
...(stickyHeader && {
'&.with-sticky': {
position: 'sticky',
top: 0,
zIndex: fixed ? 3 : 2,
}),
'&.with-sticky': {
backgroundColor: 'white',
},
...(stickyHeader && {
position: 'sticky',
top: 0,
zIndex: 2,
},
zIndex: fixed ? 3 : 2,
}),
...(fixedLastLeft && {
'&:after': {
content: '""',
Expand Down Expand Up @@ -182,6 +188,7 @@ export const TableCell = React.forwardRef<
fixedLastLeft,
fixedLastRight,
hasBorder: hasBorder ?? (tableLv && tableLv.hasBorder),
width: other.width,
};
const isHeadCell = tableLv && tableLv.variant === 'head';
const component = isHeadCell ? 'th' : 'td';
Expand Down
14 changes: 12 additions & 2 deletions packages/components/src/Table/BaseTable/Toolbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ export interface ToolbarProps {
simpleMode?: boolean;
onChange?: (value: any) => void;
initialKeyword?: string;
disabled?: boolean;
};
onFilterInputChange?: (value: any) => void;
refetch?: any;
loading?: boolean;
refreshDisabled?: boolean;
settingMenuDisabled?: boolean;
}

export const Toolbar = (props: ToolbarProps) => {
Expand All @@ -54,6 +57,8 @@ export const Toolbar = (props: ToolbarProps) => {
loading,
enableSettingMenu = true,
className,
refreshDisabled,
settingMenuDisabled,
} = props;
return (
<ToolbarWrapper className={className}>
Expand All @@ -75,12 +80,17 @@ export const Toolbar = (props: ToolbarProps) => {
{toolbarLeft && <div className="toolbar-left">{toolbarLeft}</div>}
<div className="toolbar-item">{enableFilters && <FilterInput {...filterProps} />}</div>
<div className="toolbar-right">
<Button variant="text" className="btn-refresh" disabled={!!loading} onClick={refetch}>
<Button
variant="text"
className="btn-refresh"
disabled={!!loading || refreshDisabled}
onClick={refetch}
>
{loading ? <CircleLoader size={14} /> : <Refresh />}
</Button>
{enableSettingMenu && (
<Dropdown content={settingMenu} placement="bottom-end" maxWidth={160}>
<Button variant="text" className="btn-setting">
<Button variant="text" className="btn-setting" disabled={settingMenuDisabled}>
<Cogwheel />
</Button>
</Dropdown>
Expand Down
40 changes: 32 additions & 8 deletions packages/components/src/Table/Table.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,22 +170,23 @@ export const basicTableWithFixedColumn = () => {
style={{
height: '300px',
overflow: 'auto',
width: 500,
}}
>
<Table
stickyHeader
style={{
width: 700,
minWidth: '100%',
}}
>
<Table stickyHeader>
<colgroup>
<col width="100" />
<col width="200" />
<col />
<col />
<col />
<col />
<col />
<col />
<col />
<col />
<col />
<col />
<col />
<col width="100" />
</colgroup>
<TableHead hasBorder>
Expand All @@ -199,6 +200,14 @@ export const basicTableWithFixedColumn = () => {
<TableCell>Header 3</TableCell>
<TableCell>Header 3</TableCell>
<TableCell>Header 3</TableCell>
<TableCell>Header 3</TableCell>
<TableCell>Header 3</TableCell>
<TableCell>Header 3</TableCell>
<TableCell>Header 3</TableCell>
<TableCell>Header 3</TableCell>
<TableCell>Header 3</TableCell>
<TableCell>Header 3</TableCell>
<TableCell>Header 3</TableCell>
<TableCell fixed="right" fixedLastRight fixedWidth={0}>
Header 3
</TableCell>
Expand All @@ -218,6 +227,14 @@ export const basicTableWithFixedColumn = () => {
</TableCell>
<TableCell>{row.col3}</TableCell>
<TableCell>{row.col3}</TableCell>
<TableCell>{row.col3}</TableCell>
<TableCell>{row.col3}</TableCell>
<TableCell>{row.col3}</TableCell>
<TableCell>{row.col3}</TableCell>
<TableCell>{row.col3}</TableCell>
<TableCell>{row.col3}</TableCell>
<TableCell>{row.col3}</TableCell>
<TableCell>{row.col3}</TableCell>
<TableCell fixed="right" fixedLastRight fixedWidth={0}>
{row.col3}
</TableCell>
Expand Down Expand Up @@ -1053,8 +1070,15 @@ export const DataTableSimple = () => {
},
],
getProps: {
toolbar: () => {
return {
// refreshDisabled: true,
// settingMenuDisabled: true,
};
},
filters: () => {
return {
disabled: true,
simpleMode: false,
suggestions: [
{
Expand Down

0 comments on commit 9afc383

Please sign in to comment.