Commit 2b31104a authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Add support for inline styles to shared buttons

To apply theming from settings, we need to be able to set inline styles
on buttons.
parent 7ae13649
...@@ -15,6 +15,7 @@ import { SvgIcon } from '@hypothesis/frontend-shared'; ...@@ -15,6 +15,7 @@ import { SvgIcon } from '@hypothesis/frontend-shared';
* @prop {boolean} [pressed] - Is this button currently "active?" (set * @prop {boolean} [pressed] - Is this button currently "active?" (set
* `aria-pressed`) * `aria-pressed`)
* @prop {() => any} [onClick] * @prop {() => any} [onClick]
* @prop {Object} [style] - Optional inline styles
* @prop {string} [title] - Button title; used for `aria-label` attribute * @prop {string} [title] - Button title; used for `aria-label` attribute
* @prop {'primary'} [variant] - For styling: element variant * @prop {'primary'} [variant] - For styling: element variant
*/ */
...@@ -41,6 +42,7 @@ function ButtonBase({ ...@@ -41,6 +42,7 @@ function ButtonBase({
expanded, expanded,
pressed, pressed,
onClick = () => {}, onClick = () => {},
style = {},
title, title,
variant, variant,
}) { }) {
...@@ -68,6 +70,7 @@ function ButtonBase({ ...@@ -68,6 +70,7 @@ function ButtonBase({
})} })}
onClick={onClick} onClick={onClick}
{...otherAttributes} {...otherAttributes}
style={style}
> >
{children} {children}
</button> </button>
......
...@@ -62,6 +62,15 @@ function addCommonTests({ componentName, createComponentFn, withIcon = true }) { ...@@ -62,6 +62,15 @@ function addCommonTests({ componentName, createComponentFn, withIcon = true }) {
assert.isFalse(wrapper.find('button').hasClass(componentName)); assert.isFalse(wrapper.find('button').hasClass(componentName));
}); });
it('adds inline styles when provided', () => {
const wrapper = createComponentFn({ style: { backgroundColor: 'pink' } });
assert.equal(
wrapper.getDOMNode().getAttribute('style'),
'background-color: pink;'
);
});
[ [
{ {
propName: 'expanded', propName: 'expanded',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment