Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for classes prop to Button components #188

Merged
merged 1 commit into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/components/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { SvgIcon } from './SvgIcon';
/**
* @typedef ButtonProps
* @prop {import('preact').Ref<HTMLButtonElement>} [buttonRef]
* @prop {string} [classes] - Optional CSS class name(s) to use _in addition_
* to the button component's own clases
* @prop {string} [className] - Optional CSS class name that will _replace_
* the button component's own classes
* @prop {string} [icon] - Name of `SvgIcon` to render in the button
* @prop {'left'|'right'} [iconPosition] - Icon positioned to left or to
* right of button text
Expand Down Expand Up @@ -46,6 +50,7 @@ import { SvgIcon } from './SvgIcon';
function ButtonBase({
// Custom props.
buttonRef,
classes,
className,
icon,
iconPosition = 'left',
Expand Down Expand Up @@ -73,7 +78,8 @@ function ButtonBase({
`${className}--${variant}`,
{
[`${className}--icon-${iconPosition}`]: icon,
}
},
classes
)}
type={type}
{...ariaProps}
Expand Down
10 changes: 10 additions & 0 deletions src/components/test/buttons-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ function addCommonTests({ componentName, createComponentFn, withIcon = true }) {
assert.isFalse(wrapper.find('button').hasClass(className));
});

it('applies extra classes after component classes', () => {
const wrapper = createComponentFn({ classes: 'foo bar' });

const wrapperClasses = wrapper
.find(`button.${className}.foo.bar`)
.getDOMNode().classList;
assert.equal(wrapperClasses.item(wrapperClasses.length - 1), 'bar');
assert.equal(wrapperClasses.item(wrapperClasses.length - 2), 'foo');
});

it('adds inline styles when provided', () => {
const wrapper = createComponentFn({ style: { backgroundColor: 'pink' } });

Expand Down