Skip to content

Commit

Permalink
fix(data-table): refactor to use exisiting func
Browse files Browse the repository at this point in the history
  • Loading branch information
tw15egan committed Mar 24, 2020
1 parent bff035d commit 190790c
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions packages/react/src/components/DataTable/TableExpandHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import cx from 'classnames';
import PropTypes from 'prop-types';
import requiredIfGivenPropExists from '../../prop-types/requiredIfGivenPropExists';
import React from 'react';
import { ChevronRight16 } from '@carbon/icons-react';
import { settings } from 'carbon-components';
Expand Down Expand Up @@ -49,21 +50,6 @@ const TableExpandHeader = ({
);
};

function isRequiredIfPropExists(requiredProp) {
function checker(props, propName, componentName) {
if (props[requiredProp] === undefined) {
return;
}
if (props[propName] === undefined) {
throw new Error(
`${componentName} requires ${propName} if ${requiredProp} is defined`
);
}
}

return checker;
}

TableExpandHeader.propTypes = {
className: PropTypes.string,
children: PropTypes.node,
Expand All @@ -72,18 +58,18 @@ TableExpandHeader.propTypes = {
* Specify the string read by a voice reader when the expand trigger is
* focused
*/
ariaLabel: isRequiredIfPropExists('ariaLabel'),
ariaLabel: requiredIfGivenPropExists('enableExpando', PropTypes.string),

/**
* Specify whether this row is expanded or not. This helps coordinate data
* attributes so that `TableExpandRow` and `TableExapndedRow` work together
*/
isExpanded: isRequiredIfPropExists('enableExpando'),
isExpanded: requiredIfGivenPropExists('enableExpando', PropTypes.bool),

/**
* Hook for when a listener initiates a request to expand the given row
*/
onExpand: isRequiredIfPropExists('enableExpando'),
onExpand: requiredIfGivenPropExists('enableExpando', PropTypes.func),

/**
* The description of the chevron right icon, to be put in its SVG `<title>` element.
Expand Down

0 comments on commit 190790c

Please sign in to comment.