From eb81408577f2a7de06b3d8482286fc197d623fea Mon Sep 17 00:00:00 2001 From: "D.A. Kahn" Date: Fri, 12 Mar 2021 14:38:08 -0600 Subject: [PATCH 1/4] fix(StructuredList): refactor es6 class components --- .../StructuredList/StructuredList.js | 583 +++++++++--------- 1 file changed, 286 insertions(+), 297 deletions(-) diff --git a/packages/react/src/components/StructuredList/StructuredList.js b/packages/react/src/components/StructuredList/StructuredList.js index d303b4373851..4c4039f5388e 100644 --- a/packages/react/src/components/StructuredList/StructuredList.js +++ b/packages/react/src/components/StructuredList/StructuredList.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import React, { Component } from 'react'; +import React, { useState } from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import { settings } from 'carbon-components'; @@ -14,312 +14,301 @@ import deprecate from '../../prop-types/deprecate'; const { prefix } = settings; -export class StructuredListWrapper extends Component { - static propTypes = { - /** - * Specify a label to be read by screen readers on the container node - */ - ariaLabel: PropTypes.string, - - /** - * Specify whether a border should be added to your StructuredListWrapper - */ - border: deprecate( - PropTypes.bool, - `\nThe prop \`border\` will be removed in the next major version of Carbon.` - ), - - /** - * Provide the contents of your StructuredListWrapper - */ - children: PropTypes.node, - - /** - * Specify an optional className to be applied to the container node - */ - className: PropTypes.string, - - /** - * Specify whether your StructuredListWrapper should have selections - */ - selection: PropTypes.bool, - }; - - static defaultProps = { - selection: false, - ariaLabel: 'Structured list section', - }; - - render() { - const { - children, - selection, - className, - ariaLabel, - border: _border, - ...other - } = this.props; - - const classes = classNames(`${prefix}--structured-list`, className, { - [`${prefix}--structured-list--selection`]: selection, - }); - - return ( -
- {children} -
- ); - } +export function StructuredListWrapper(props) { + const { + children, + selection, + className, + ariaLabel, + border: _border, + ...other + } = props; + const classes = classNames(`${prefix}--structured-list`, className, { + [`${prefix}--structured-list--selection`]: selection, + }); + + return ( +
+ {children} +
+ ); } -export class StructuredListHead extends Component { - static propTypes = { - /** - * Provide the contents of your StructuredListHead - */ - children: PropTypes.node, - - /** - * Specify an optional className to be applied to the node - */ - className: PropTypes.string, - }; - - render() { - const { children, className, ...other } = this.props; - - const classes = classNames(`${prefix}--structured-list-thead`, className); - return ( -
- {children} -
- ); - } +StructuredListWrapper.propTypes = { + /** + * Specify a label to be read by screen readers on the container node + */ + ariaLabel: PropTypes.string, + + /** + * Specify whether a border should be added to your StructuredListWrapper + */ + border: deprecate( + PropTypes.bool, + `\nThe prop \`border\` will be removed in the next major version of Carbon.` + ), + + /** + * Provide the contents of your StructuredListWrapper + */ + children: PropTypes.node, + + /** + * Specify an optional className to be applied to the container node + */ + className: PropTypes.string, + + /** + * Specify whether your StructuredListWrapper should have selections + */ + selection: PropTypes.bool, +}; + +StructuredListWrapper.defaultProps = { + selection: false, + ariaLabel: 'Structured list section', +}; + +export function StructuredListHead(props) { + const { children, className, ...other } = props; + const classes = classNames(`${prefix}--structured-list-thead`, className); + + return ( +
+ {children} +
+ ); } +StructuredListHead.propTypes = { + /** + * Provide the contents of your StructuredListHead + */ + children: PropTypes.node, + + /** + * Specify an optional className to be applied to the node + */ + className: PropTypes.string, +}; + const getInstanceId = setupGetInstanceId(); -export class StructuredListInput extends Component { - static propTypes = { - /** - * Specify an optional className to be applied to the input - */ - className: PropTypes.string, - - /** - * Specify whether the underlying input should be checked by default - */ - defaultChecked: PropTypes.bool, - - /** - * Specify a custom `id` for the input - */ - id: PropTypes.string, - - /** - * Provide a `name` for the input - */ - name: PropTypes.string, - - /** - * Provide an optional hook that is called each time the input is updated - */ - onChange: PropTypes.func, - - /** - * Provide a `title` for the input - */ - title: PropTypes.string, - - /** - * Specify the value of the input - */ - value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, - }; - - static defaultProps = { - onChange: () => {}, - value: 'value', - title: 'title', - }; - - constructor(props) { - super(props); - this.uid = this.props.id || getInstanceId(); - } - - render() { - const { className, value, name, title, ...other } = this.props; - const classes = classNames(`${prefix}--structured-list-input`, className); - return ( - - ); - } +export function StructuredListBody(props) { + const { children, className, ...other } = props; + const classes = classNames(`${prefix}--structured-list-tbody`, className); + const { labelRows, setLabelRows } = useState(null); + const { rowSelected, setRowSelected } = useState(0); + + return ( +
+ {children} +
+ ); } -export class StructuredListRow extends Component { - static propTypes = { - /** - * Provide the contents of your StructuredListRow - */ - children: PropTypes.node, - - /** - * Specify an optional className to be applied to the container node - */ - className: PropTypes.string, - - /** - * Specify whether your StructuredListRow should be used as a header row - */ - head: PropTypes.bool, - - /** - * Specify whether a `