1.0.4 • Published 2 years ago
@microsoft/arbutus.style-utilities v1.0.4
Style: Utilities
Collection of utilities for styling with Griffel.
Get Started
npm i @microsoft/arbutus.style-utilitiesUsage
mapToStyles
mapToStyles is designed to help generating styles variants. It generates Griffel classes from a map of values.
import { mapToStyles } from '@microsoft/arbutus.style-utilities';Parameters
mapAn object, where the key will become a class name, and the value will be passed to thestyleFunction.styleFunctionA function that takes the value from themapand returns aGriffelStyle.
Returns
An object with keys from the map and values as GriffelStyle returned by the styleFunction.
Example
Step 1: Create a map of variants for your component.
type ColorValue = string;
const textColors = { primary: 'red', secondary: 'blue' };
const textStyleFunction = (color: ColorValue) => ({
color,
'&:visited': { color },
});
const textColorClasses = mapToStyles<ColorValue, typeof textColors>(
textColors,
textStyleFunction,
);
// Output
// {
// primary: {
// color: 'red',
// '&:visited: { color: 'red'}}
// },
// secondary: {
// color: 'blue',
// '&:visited: { color: 'blue'}}
// },
// }