Skip to content

Instantly share code, notes, and snippets.

@Kashkovsky
Created April 25, 2018 13:33
Show Gist options
  • Save Kashkovsky/25de46d4d8d8b25115eb734e435b4e53 to your computer and use it in GitHub Desktop.
Save Kashkovsky/25de46d4d8d8b25115eb734e435b4e53 to your computer and use it in GitHub Desktop.
Overriding Office UI Fabric component styles using Styling API
import * as React from 'react';
import PropTypes from 'prop-types';
import { DefaultButton } from 'office-ui-fabric-react/lib/Button';
import { getStyles } from './Button.styles';
import { classNamesFunction, customizable, styled } from 'office-ui-fabric-react/lib/Utilities';
/** Button example */
export function Button({ label, disabled, onClick, isPrimary, className, getStyles, theme }) {
const classNames = classNamesFunction()(getStyles, {
theme: theme,
className
});
return (
<DefaultButton className={classNames.root} disabled={disabled} primary={isPrimary} onClick={onClick}>
{label}
</DefaultButton>
);
}
Button.propTypes = {
className: PropTypes.string.isRequired,
/** Button label */
label: PropTypes.string,
/** Button is disabled */
disabled: PropTypes.bool,
/** Mouse click event handler */
onCLick: PropTypes.func,
/** Primary button */
isPrimary: PropTypes.bool
};
export default styled(customizable('Button', ['theme'])(Button), getStyles);
export const getStyles = props => {
const { className, theme } = props;
const { palette, semanticColors } = theme;
return {
root: [
'ms-Button',
{
background: props.theme.palette.themePrimary,
// place your styles here
},
className
]
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment