Skip to main content

Opacities

Interface

Structure

interface Opacities {
[key: string]: number;
}

type Opacity = keyof Opacities;

Usage

// Types are re-exported for ease of use by other packages
// like @morfeo/core, @morfeo/web or @morfeo/react
import { Opacity, Opacities } from '@morfeo/spec';

Examples

Using the CLI compose command:

opacities.morfeo.ts
// Remove this line to add the slice to all of your themes
export const themeName = 'My Theme Name';
// Optional if you name the file opacities.morfeo.ts
export const sliceName = 'opacities';

export default {
none: 0,
light: 0.2,
medium: 0.6,
strong: 1,
};

Or manually:

opacities.ts
import { Opacities } from '@morfeo/spec';

const opacities: Opacities = {
none: 0,
light: 0.2,
medium: 0.6,
strong: 1,
};
theme.ts
import { opacities } from './opacities';

const myTheme = {
opacities,
...restOfTheTheme,
};

morfeo.setTheme('My Theme Name', myTheme);

Properties

In this table is shown the property you pass to morfeo.resolve, the actual CSS property or properties that will be generated, an example of usage, and the correspondent output:

namecss propertyexampleoutput
opacityopacity{ opacity: "medium"} {"opacity":0.6}

Extend Slice with custom properties

If you're using typescript and you add custom colors to your theme configuration, you'll need to merge the default Opacities interface with your custom one. We suggest creating a declaration file (for example: morfeo.d.ts or types.d.ts) like the following one:

import { opacities } from './path/to/your/custom/opacities';

type MyOpacities = typeof opacities;

declare module '@morfeo/spec' {
export interface Opacities extends MyOpacities {}
}

Read more about how to extend the default Morfeo Theme here.