Skip to content

Commit

Permalink
feat(checkbox/overflow-menu): Support wrapping classes (carbon-design…
Browse files Browse the repository at this point in the history
…-system#783)

It's more useful to be able to set the classname on the wrapping element
(which can be used to address internal elements)
  • Loading branch information
Paul Sachs authored and joshblack committed Apr 4, 2018
1 parent 6b61009 commit 8071ab0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/components/Checkbox/Checkbox-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ storiesOf('Checkbox', module)
id="checkbox-label-2"
labelText="Checkbox label hidden"
hideLabel={true}
wrapperClassName="wrapper-class"
/>
</fieldset>
)
Expand Down
23 changes: 18 additions & 5 deletions src/components/Checkbox/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,22 @@ const Checkbox = ({
onChange,
indeterminate,
hideLabel,
wrapperClassName,
...other
}) => {
let input;
const wrapperClasses = classNames('bx--checkbox-label', className);
const labelClasses = classNames({
const labelClasses = classNames('bx--checkbox-label', className);
const innerLabelClasses = classNames({
'bx--visually-hidden': hideLabel,
});
const wrapperClasses = classNames(
'bx--form-item',
'bx--checkbox-wrapper',
wrapperClassName
);

return (
<div className="bx--form-item bx--checkbox-wrapper">
<div className={wrapperClasses}>
<input
{...other}
type="checkbox"
Expand All @@ -34,8 +40,8 @@ const Checkbox = ({
}
}}
/>
<label htmlFor={id} className={wrapperClasses}>
<span className={labelClasses}>{labelText}</span>
<label htmlFor={id} className={labelClasses}>
<span className={innerLabelClasses}>{labelText}</span>
</label>
</div>
);
Expand All @@ -45,12 +51,19 @@ Checkbox.propTypes = {
checked: PropTypes.bool,
defaultChecked: PropTypes.bool,
indeterminate: PropTypes.bool,
/**
* The CSS class name to be placed on inner label element.
*/
className: PropTypes.string,
disabled: PropTypes.bool,
id: PropTypes.string.isRequired,
labelText: PropTypes.node.isRequired,
hideLabel: PropTypes.bool,
onChange: PropTypes.func,
/**
* The CSS class name to be placed on the wrapping element
*/
wrapperClassName: PropTypes.string,
};

Checkbox.defaultProps = {
Expand Down
11 changes: 9 additions & 2 deletions src/components/OverflowMenuItem/OverflowMenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const OverflowMenuItem = ({
closeMenu,
onClick,
primaryFocus,
wrapperClassName,
...other
}) => {
const overflowMenuBtnClasses = classNames(
Expand All @@ -22,7 +23,8 @@ const OverflowMenuItem = ({
{
'bx--overflow-menu--divider': hasDivider,
'bx--overflow-menu-options__option--danger': isDelete,
}
},
wrapperClassName
);

const handleClick = evt => {
Expand Down Expand Up @@ -50,10 +52,15 @@ const OverflowMenuItem = ({

OverflowMenuItem.propTypes = {
/**
* The CSS class names.
* The CSS class name to be placed on the button element
*/
className: PropTypes.string,

/**
* The CSS class name to be placed on the wrapper list item element
*/
wrapperClassName: PropTypes.string,

/**
* The text in the menu item.
*/
Expand Down

0 comments on commit 8071ab0

Please sign in to comment.