-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add decorator in dataTable (#18114)
* chore: add decorator in dataTable * fix: replace slug with ai-lable * fix: test cases * fix: test case * fix: test cases * fix: changed const name as per PR suggestions * fix: css issues * fix: css * fix: test * fix: removed decorator stories * fix: test * fix: test --------- Co-authored-by: Taylor Jones <[email protected]>
- Loading branch information
1 parent
7b6d921
commit 69087c4
Showing
20 changed files
with
380 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
packages/react/src/components/DataTable/TableDecoratorRow.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* Copyright IBM Corp. 2016, 2023 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import PropTypes from 'prop-types'; | ||
import React, { ReactNode } from 'react'; | ||
import classNames from 'classnames'; | ||
import { usePrefix } from '../../internal/usePrefix'; | ||
import deprecate from '../../prop-types/deprecate'; | ||
|
||
export interface TableDecoratorRowProps { | ||
/** | ||
* The CSS class names of the cell that wraps the underlying input control | ||
*/ | ||
className?: string; | ||
|
||
/** | ||
* **Experimental**: Provide a `decorator` component to be rendered inside the `TableDecoratorRow` component | ||
*/ | ||
decorator?: ReactNode; | ||
} | ||
|
||
const TableDecoratorRow = ({ | ||
className, | ||
decorator, | ||
}: TableDecoratorRowProps) => { | ||
const prefix = usePrefix(); | ||
const TableDecoratorRowClasses = classNames({ | ||
...(className && { [className]: true }), | ||
[`${prefix}--table-column-decorator`]: true, | ||
[`${prefix}--table-column-decorator--active`]: decorator, | ||
}); | ||
|
||
let normalizedDecorator = React.isValidElement(decorator) | ||
? (decorator as ReactNode) | ||
: null; | ||
if ( | ||
normalizedDecorator && | ||
normalizedDecorator['type']?.displayName === 'AILabel' | ||
) { | ||
normalizedDecorator = React.cloneElement( | ||
normalizedDecorator as React.ReactElement<any>, | ||
{ | ||
size: 'mini', | ||
} | ||
); | ||
} | ||
|
||
return <td className={TableDecoratorRowClasses}>{normalizedDecorator}</td>; | ||
}; | ||
|
||
TableDecoratorRow.displayName = 'TableDecoratorRow'; | ||
TableDecoratorRow.propTypes = { | ||
/** | ||
* The CSS class names of the cell that wraps the underlying input control | ||
*/ | ||
className: PropTypes.string, | ||
|
||
/** | ||
* **Experimental**: Provide a `decorator` component to be rendered inside the `TableDecoratorRow` component | ||
*/ | ||
decorator: PropTypes.node, | ||
}; | ||
|
||
export default TableDecoratorRow; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.