Skip to main content

Sizes

Interface

Structure

interface Sizes {
[key: string]: string;
}

type Size = keyof Sizes;

Usage

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

Examples

Using the CLI compose command:

sizes.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 sizes.morfeo.ts
export const sliceName = 'sizes';

export default {
'2xs': '8px',
xs: '16px',
s: '24px',
m: '32px',
l: '40px',
xl: '48px',
'2xl': '56px',
none: '0px',
};

Or manually:

sizes.ts
import { Sizes } from '@morfeo/spec';

const sizes: Sizes = {
'2xs': '8px',
xs: '16px',
s: '24px',
m: '32px',
l: '40px',
xl: '48px',
'2xl': '56px',
none: '0px',
};
theme.ts
import { sizes } from './sizes';

const myTheme = {
sizes,
...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
sizewidth, height{ size: "l"} {"width":"40px","height":"40px"}
widthwidth{ width: "l"} {"width":"40px"}
heightheight{ height: "l"} {"height":"40px"}
minSizeminWidth, minHeight{ minSize: "l"} {"minWidth":"40px","minHeight":"40px"}
maxSizemaxWidth, maxHeight{ maxSize: "l"} {"maxWidth":"40px","maxHeight":"40px"}
minWidthminWidth{ minWidth: "l"} {"minWidth":"40px"}
maxWidthmaxWidth{ maxWidth: "l"} {"maxWidth":"40px"}
minHeightminHeight{ minHeight: "l"} {"minHeight":"40px"}
maxHeightmaxHeight{ maxHeight: "l"} {"maxHeight":"40px"}
flexBasisflexBasis{ flexBasis: "l"} {"flexBasis":"40px"}
blockSizeblockSize{ blockSize: "l"} {"blockSize":"40px"}
inlineSizeinlineSize{ inlineSize: "l"} {"inlineSize":"40px"}
maxBlockSizemaxBlockSize{ maxBlockSize: "l"} {"maxBlockSize":"40px"}
minBlockSizeminBlockSize{ minBlockSize: "l"} {"minBlockSize":"40px"}
minInlineSizeminInlineSize{ minInlineSize: "l"} {"minInlineSize":"40px"}
maxInlineSizemaxInlineSize{ maxInlineSize: "l"} {"maxInlineSize":"40px"}

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 Sizes 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 { sizes } from './path/to/your/custom/sizes';

type MySizes = typeof sizes;

declare module '@morfeo/spec' {
export interface Sizes extends MySizes {}
}

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