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:
name | css property | example | output |
---|---|---|---|
size | width, height | { size: "l"} | {"width":"40px","height":"40px"} |
width | width | { width: "l"} | {"width":"40px"} |
height | height | { height: "l"} | {"height":"40px"} |
minSize | minWidth, minHeight | { minSize: "l"} | {"minWidth":"40px","minHeight":"40px"} |
maxSize | maxWidth, maxHeight | { maxSize: "l"} | {"maxWidth":"40px","maxHeight":"40px"} |
minWidth | minWidth | { minWidth: "l"} | {"minWidth":"40px"} |
maxWidth | maxWidth | { maxWidth: "l"} | {"maxWidth":"40px"} |
minHeight | minHeight | { minHeight: "l"} | {"minHeight":"40px"} |
maxHeight | maxHeight | { maxHeight: "l"} | {"maxHeight":"40px"} |
flexBasis | flexBasis | { flexBasis: "l"} | {"flexBasis":"40px"} |
blockSize | blockSize | { blockSize: "l"} | {"blockSize":"40px"} |
inlineSize | inlineSize | { inlineSize: "l"} | {"inlineSize":"40px"} |
maxBlockSize | maxBlockSize | { maxBlockSize: "l"} | {"maxBlockSize":"40px"} |
minBlockSize | minBlockSize | { minBlockSize: "l"} | {"minBlockSize":"40px"} |
minInlineSize | minInlineSize | { minInlineSize: "l"} | {"minInlineSize":"40px"} |
maxInlineSize | maxInlineSize | { 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.