Matryoshka
Matryoshka is a generic and versatile set of SASS functions, mixins and Javascript tools, hybridly based on Atomic Design and ITCSS to start building your own design system.
What’s different with other frameworks?
It builds your own custom classes based on your own settings.
matryoshka/
├── components/ <!-- Files that build CSS declarations -->
├── engine/ <!-- Core files -->
└── settings/ <!-- Settings file(s) -->
_core.scss <!-- Core imports - required -->
_components.scss <!-- Components imports - optional -->
Components
.my-
CSS declarations of UI elements like grids, buttons, forms, tables, etc.
Modifiers
.mod-
Apply variations on the component. Modifiers are always attached to a component.
Utilities
.u-
CSS utilities classes that override components and modifiers with the !important
rule. For example .u-p-foo
returns spacing called foo as padding.
<div class="u-[CSS shorthand property]-[Pattern name][Optional screen size pattern name]"></div>
<!-- Utility padding foo -->
<div class="u-p-foo"></div>
<!-- Returns padding: [foo value + design system unit] !important
For example padding: 20px !important; -->
<!-- Utility padding foo on bar screen size -->
<div class="u-p-foo-bar"></div>
<!-- Returns
@media (bar screen width) {
padding: [foo value + design system unit] !important
} -->
- u- is the prefix to use to call utility class name
- CSS shorthand property refers to CSS property here is the list
- Pattern name refers to the name of your pattern (color, spacing, font size, etc) from your own Matryoshka settings
- Optional screen size pattern name refers to an optional responsive suffix based on your own screen sizes settings
$ds-sreen-sizes
Responsive display
matryoshka/components/utilities/responsive-display.scss
Responsive display refers to $ds-screen-sizes
. It is used to build responsive class utilities, when you want to display someting on a specified screen size.
Responsive Applicable for each screen size |
Custom attributes Responsive shorthand through HTML attributes |
---|---|
✔ | ✔ |
Responsive classes | Description |
---|---|
.u-hidden-foo |
Hide only - Display none - on foo screen size |
.u-visible-foo |
Show only - Display initial - on foo screen size |
Call responsive display utilities with custom data attributes to quickly apply a responive display on several screen sizes at once. Just separate screen sizes with space or comma or both.
Responsive display attributes | Description |
---|---|
.u-hidden="foo, bar" |
Hide only - Display none - on foo and bar screen sizes |
.u-visible="foo, bar" |
Show only - Display initial - on foo and bar screen sizes |
Spacings - Responsive
matryoshka/components/utilities/spacings.scss
Spacings refer to margins and paddings. $ds-spacings
is used to build margins and paddings class utilities.
Paddings classes | Description |
---|---|
.u-p-foo |
Padding foo spacing |
.u-pt-foo |
Padding top foo spacing |
.u-pr-foo |
Padding right foo spacing |
.u-pb-foo |
Padding bottom foo spacing |
.u-pl-foo |
Padding left foo spacing |
.u-p-foo-bar |
Padding foo spacing for bar screen size |
.u-pt-foo-bar |
Padding top foo spacing for bar screen size |
.u-pr-foo-bar |
Padding right foo spacing for bar screen size |
.u-pb-foo-bar |
Padding bottom foo spacing for bar screen size |
.u-pl-foo-bar |
Padding left foo spacing for bar screen size |
Margins classes | Description |
---|---|
.u-m-foo |
Margin foo spacing |
.u-mt-foo |
Margin top foo spacing |
.u-mr-foo |
Margin right foo spacing |
.u-mb-foo |
Margin bottom foo spacing |
.u-ml-foo |
Margin left foo spacing |
.u-m-foo-bar |
Margin foo spacing for bar screen size |
.u-mt-foo-bar |
Margin top foo spacing for bar screen size |
.u-mr-foo-bar |
Margin right foo spacing for bar screen size |
.u-mb-foo-bar |
Margin bottom foo spacing for bar screen size |
.u-ml-foo-bar |
Margin left foo spacing for bar screen size |
Spacings come with custom responsive data attributes to quickly apply a spacing on several screen sizes at once. Just separate screen sizes with space or comma or both.
Responsive paddings attributes | Description |
---|---|
.u-p-foo="bar, two, thre" |
Padding foo spacing for bar, two and thre screen sizes |
.u-pt-foo="bar, two, thre" |
Padding top foo spacing for bar, two and thre screen sizes |
.u-pr-foo="bar, two, thre" |
Padding right foo spacing for bar, two and thre screen sizes |
.u-pb-foo="bar, two, thre" |
Padding bottom foo spacing for bar, two and thre screen sizes |
.u-pl-foo="bar, two, thre" |
Padding left foo spacing for bar, two and thre screen sizes |
Responsive margins attributes | Description |
---|---|
.u-m-foo="bar, two, thre" |
Margin foo spacing for bar, two and thre screen sizes |
.u-mt-foo="bar, two, thre" |
Margin top foo spacing for bar, two and thre screen sizes |
.u-mr-foo="bar, two, thre" |
Margin right foo spacing for bar, two and thre screen sizes |
.u-mb-foo="bar, two, thre" |
Margin bottom foo spacing for bar, two and thre screen sizes |
.u-ml-foo="bar, two, thre" |
Margin left foo spacing for bar, two and thre screen sizes |
Core
_core.scss
Settings and main functionalities. Include _core.scss
to get all the functions and mixins. No CSS declaration is compiled from this file. Only core functions, mixins and variables. You may include this file in any SASS file, no changes will be made. Only core functions.
Components
_components.scss
Components are CSS classes presets ready to use. HTML5 tags are considered as components. Matryoshka comes with basic components called utilities. To add components, add @import components/yourComponent.scss
in the file _components.scss
.
Components are html/css structures presets that can be customized with defined patterns called modifers. Each component has its own modifiers coming with its own documentation.
mod-
means modifier and must be added to an existing component.
<div class="componentName">
<div class="componentName mod-modifierName">
In addition, components can be easily customized with utilities:
<div class="componentName mod-modifierName u-c-colorName">
Available components
- Alerts w/ Javascript
- Badges
- Buttons
- Dropdowns w/ Javascript
- Forms
- Grid
- Lists
- Modals w/ Javascript
- Tabs w/ Javascript
Settings
The most important part for the user, this file contains all Matryoshka parameters.
Unit
$ds-unit
The unit that will be used by default. You can enter any CSS valid unit.
// Example
$ds-unit: px;
Colors
$ds-colors
In Matryoshka, colors are organised in groups - color families into a SASS map $ds-colors
. There are 3 type of color families:
Automatic
Enter a single valid CSS color and Matryoshka computes a set of matched contrasted colors with the same hue. The computed set is depending on your own settings in $ds-contrasts
.
- SASS variable type: string
- Learn more about CSS colors
// Example
$ds-colors: (
automaticFamilyName: #1234ef
);
Manual
You manually enter a SASS map of custom valid CSS colors with one colors set as reference.
- SASS variable type: map
- Learn more about CSS colors
// Example
$ds-colors: (
manualReferenceFamilyName: (
0: #1234ef, // 0 (required) is the reference color
colorName1: red,
colorName2: hsl(50, 10%, 50%),
colorName3: rgba(0, 10, 25, .8)
)
);
Custom
You enter a simple SASS map of valid CSS colors.
- SASS variable type: map
- Learn more about CSS colors
customColorGroupName: (
colorName1: #123456,
colorName2: orange,
colorName3: hsl(79.7, 50%, 20%)
)
);
Contrasts
$ds-contrasts
This feature is enabled only if the color family is set as automatic.
Useful for automatic contrast adjustments and accessibility. Matryoshka automatically computes matching color sets from color groups defined as automatic in $ds-colors
. Returned colors are rendered with the same hue as the reference color, only lightness is modified.
- Enter any name as contrast name
- Contrasts values must be integer between -100 and +100
- SASS variable type: map
Contrast > 0
Renders matched colors from the reference color, optimized and recommended for readability. If reference color is light, returns a dark color and vice-versa. For example, if full black is set as reference color, returns full white.
Contrast < 0
Emphasizes, accent the current luminance of the reference color. If the color is dark, result gets darker. May render unexpected colors, use knowingly. For example, if full black is set as reference color, returns full black.
Contrast = 100
This value is very useful to automatically obtain the proper web contrast for readability.
- Returns white
#ffffff
if the input color luminance is below or equal the luminance threshold - Returns black
#000000
if the input color luminance is above the luminance threshold
Contrast = -100
Opposite behavior of contrast = 100.
- Returns white
#ffffff
if the input color luminance is below or equal the luminance threshold - Returns black
#000000
if the input color luminance is above the luminance threshold
Example with dark color
// Example
$ds-colors: (
autoFamilyName: #123456
);
// with
$ds-contrasts: (
max: 100, // Returns a fully contrasted color, recommended for proper web contrast
light: 30, // Returns contrasted color, recommended for proper web contrast
light-rev: -50, // Returns accentuated contrast, not recommended for proper web contrast
max-rev: -100 // Returns fully accentuated contrast, not recommended for proper web contrast
);
.u-bc-autoFamilyName-max
//color: #ffffff !important;
.u-bc-autoFamilyName-light
//color: #2771bb !important;
.u-bc-autoFamilyName
//color: #123456 !important;
.u-bc-autoFamilyName-light-rev
//color: #0d243c !important;
.u-bc-autoFamilyName-max-rev
//color: #000000 !important;
Example with light color
// Example
$ds-colors: (
autoFamilyName: #d3e8f8
);
// with
$ds-contrasts: (
max: 100, // Returns a fully contrasted color, recommended for proper web contrast
light: 30, // Returns contrasted color, recommended for proper web contrast
light-rev: -50, // Returns accentuated contrast, not recommended for proper web contrast
max-rev: -100 // Returns fully accentuated contrast, not recommended for proper web contrast
);
.u-bc-autoFamilyName-max
//color: #000000 !important;
.u-bc-autoFamilyName-light
//color: #5caae5 !important;
.u-bc-autoFamilyName
//color: #d3e8f8 !important;
.u-bc-autoFamilyName-light-rev
//color: #e0effa !important;
.u-bc-autoFamilyName-max-rev
//color: #ffffff !important;
Luminance method
Matryoshka comes with functions that computes color contrasts automatically. These functions can be adjusted to your needs with luminance method and luminance threshold.
Method
$ds-luminance-method
Sets the method to apply on automatic contrasts.
- SASS variable type: SASS number
- Possible values:
Threshold
$ds-luminance-threshold
Define the luminance threshold between light and dark.
- SASS variable type: SASS number
- Possible values: Float between 0 and 1
0.5
default
Screen sizes
$ds-screen-sizes
Sets the different screen sizes you wish to use. It is recommended to use semantic names, easy to remenber and to use, they are used to name your CSS classes utilities.
- SASS variable type: SASS map
- Enter any name as screen size name
- Enter an
integer
as value without unit - Always use
infinite
as value for the largest screen
Example 1
Example with Bootstrap break points and naming
$ds-screen-sizes: (
xs: 576,
sm: 768,
md: 992,
lg: 1250,
xl: infinite
);
You get these utilities classes
.u-hidden-xs
.u-hidden-sm
.u-hidden-md
.u-hidden-lg
.u-hidden-xl
u-hidden="md, lg, xl"
.u-visible-xs
.u-visible-sm
.u-visible-md
.u-visible-lg
.u-visible-xl
u-visible="md, lg, xl"
Example 2
Custom example with custom break points and naming.
// Other custom example
$ds-screen-sizes: (
mini: 400,
medium: 808,
large: 1024,
wide: infinite
);
You get these utilities classes
.u-hidden-mini
.u-hidden-medium
.u-hidden-large
.u-hidden-wide
u-hidden="mini, large"
.u-visible-mini
.u-visible-medium
.u-visible-large
.u-visible-wide
u-visible="mini, large"
Fonts
$ds-fonts
Matryoshka enables easy fonts integration for local fonts, Google Fonts and web safe font. Each font type is declared as a SASS map.
Google Fonts
Matryoshka supports Google Fonts as follows:
// Example of a Google Font declaration
$ds-fonts: (
myCustomGoogleFontName: ( // Your own font family name
type: 'google', // Sets the font type
name: 'Montserrat', // The Google font name
weight: 'Bold', // Sets the weight of the font, leave empty '' for default weight
fallback: 'sans-serif' // Sets a web safe fallback font. Value can be any web safe font.
)
);
- SASS variable type: SASS map
- Enter any name that will be used as font family name
myCustomGoogleFontName: (
Your own font family name (that has nothing to do with your font file name).type: 'google'
sets that it is a Google Font.name: 'Montserrat'
sets a valid Google Font family nameweight: 'Bold'
sets a valid weight of the Google Font, leave empty''
for default weightfallback: ''
sets a web safe fallback font. Value can be any web safe font.
)
Local fonts
When your font files are placed locally.
// Example of a local font declaration
$ds-fonts: (
myCustomLocalFontName: ( // Your own font family name
type: 'local', // Sets the font type
name: 'myFontFile', // The font file names without extension (*.ttf, *.woff, etc)
path: '../path/to/the/fonts/folder/',
fallback: 'sans-serif'
)
);
- SASS variable type: SASS map
- Enter any name that will be used as font family name
myCustomLocalFontName: (
Your own font family name (that has nothing to do with your font file name).type: 'local'
sets that it is a local font.path: '../path/to/the/fonts/folder/'
is the relative path to the folder containing your font files from the compiled CSS path.name: 'myFontFile'
is the font file name without extension (.ttf, .woff, etc), assuming you have a folder with your font files calledmyFontFile.ttf
myFontFile.woff
myFontFile.woff2
myFontFile.otf
myFontFile.svg
- etc
fallback: ''
sets a web safe fallback font. Value can be any web safe font.
)
Web safe fonts
You can also simply use a web safe font
// Example of a web safe font declaration
$ds-fonts: (
myCustomLocalFontName: ( // Your own font family name
type: 'local', // Sets the font type
name: 'myFontFile', // The font file names without extension (*.ttf, *.woff, etc)
path: '../path/to/the/fonts/folder/',
fallback: 'sans-serif'
)
);
- SASS variable type: SASS map
- Enter any name that will be used as font family name
myCustomWebsafeFontName: (
Your own web safe font family name (that has nothing to do with your font name).type: 'websafe'
sets that it is a web safe font.name: 'sans-serif'
must be a valid web safe font name.
)
Font sizes
$ds-font-sizes
Here is the list of all the different font sizes that will be used into your design system.
- SASS variable type: SASS map
- Enter any name for each font size
- Each value must be an
integer
without unit, assuming your design system unit$ds-unit
Example
Example of a set of font sizes
$ds-font-sizes: (
xxs: 10,
sm: 18,
xxl: 64
);
You get these utilities classes
.u-fs-xxs
.u-fs-sm
.u-fs-xxl
Assuming your have the following screen size set
// Other custom example
$ds-screen-sizes: (
mini: 400,
medium: 808,
wide: infinite
);
.u-fs-xxs-mini
.u-fs-xxs-large
.u-fs-xxs-wide
u-fs-xxs="mini, medium"
Typography
$ds-typography
Typography is a SASS map that contains your own list of CSS properties dedicated to fonts. You can use is through SASS mixin. The goal is to obtain a typography consistency into your design system and avoid misuse of fonts.
- SASS variable type: SASS map
- Enter any name that will be used as typography name
myTypographyName: (
Your own typography.font-family
sets the name of a font family declared into$ds-fonts
.- Assuming you have a font family name called
foo
, enterfont-family: foo
. - Using font families names from
$ds-fonts
is recommended but you can use any static valid family name (like web safe)
- Assuming you have a font family name called
any-other-valid-css-property
You may include as much as valid CSS properties as you want.- For consistency purpose, it is recommended to use Matryoshka functions for values when applicable:
my-font-size(nameOfTheFontSize)
my-color(nameOfTheColor[, optional contrastName])
)
Example 1
// Assuming we have the a font family called myFontFamilyName
$ds-fonts: (
myFontFamilyName: (
type: 'local',
name: 'myFontFile',
path: '../path/to/the/fonts/folder/',
fallback: 'sans-serif'
)
);
$ds-typography: (
caps: (
font-family: myFontFamilyName,
text-transform: uppercase
),
default: (
font-family: myFontFamilyName,
text-transform: capitalize,
font-size: my-font-size(small) // Example with a Matryoshka function
)
);
// Call typography with its mixin
@include my-typography(caps)
// Renders
// font-family: myFontFamilyName, sans-serif;
// text-transform: uppercase;
// Call typography with its mixin
@include my-typography(default)
// Renders
// font-family: myFontFamilyName, sans-serif;
// text-transform: capitalize;
// font-size: 16px; // Assuming 'small' is a font size 16 with $ds-unit = px
Spacings
$ds-spacings
For design consistency, Matryoshka uses a list of spacings that can be used for any purpose like margins and paddings.
- SASS variable type: SASS map
- Enter any name as spacing name
- Enter an
integer
as value without unit
$ds-spacings: (
none: 0,
md: 25,
xxl: 128
);
You get these utilities classes
.u-p-none
.u-p-md
.u-p-xxl
.u-m-none
.u-m-md
.u-m-xxl
Assuming we have the following screen sizes
// Other custom example
$ds-screen-sizes: (
mini: 400,
medium: 808,
large: 1024,
wide: infinite
);
.u-m-none-mini
.u-m-none-medium
.u-m-none-large
.u-m-none-wide
...
.u-p-none-mini
.u-p-none-medium
.u-p-none-large
.u-p-none-wide
...
Borders
$ds-borders
A list of borders shorthands.
- SASS variable type: SASS map
- Enter any name as border name
- Enter a valid CSS border shorthand as value. For consistency purpose, it is recommended to use Matryoshka functions for values when applicable:
- For colors
my-spacing(spacingName)
- For border width
my-color(nameOfTheColor[, optional contrastName])
- For colors
// Example
$ds-borders: (
main: my-spacing(ultraMini) solid my-color(brand), // With Matryoshka functions
light: 1px solid #123456 // With custom values
);
.u-b-main
.u-b-light
.u-bt-main
.u-bt-light
Border radius
$ds-border-radius
A simple list of border radius.
- SASS variable type: SASS map
- Enter any name as border radius name
- Enter an
integer
as value
// Example
$ds-border-radius: (
none: 0,
small: 4,
large: 9
);
Utilities
Utilities are atoms that overrides components and modifiers CSS with conventional naming as follows.
u-
means utility that returns CSS values always with the important rule !important
<div class="u-c-myColorName"></div>
// Renders for example color: #123456 !important
Global utilities
Colors | Render |
---|---|
u-c-myColorName |
color: [value] !important |
u-bc-myColorName |
background-color: [value] !important |
Text alignment | Render |
---|---|
u-ta-left |
text-align: left !important |
u-ta-center |
text-align: center !important |
u-ta-right |
text-align: right !important |
Typography | Render |
---|---|
u-typo-myTypoName |
All typography name properties + !important |
Spacings | Render |
---|---|
u-m-mySpacingName |
margin: [value+unit] !important |
u-mt-mySpacingName |
margin-top: [value+unit] !important |
u-mr-mySpacingName |
margin-right: [value+unit] !important |
u-mb-mySpacingName |
margin-bottom [value+unit] !important |
u-ml-mySpacingName |
margin-left: [value+unit] !important |
u-p-mySpacingName |
padding: [value+unit] !important |
u-pt-mySpacingName |
padding-top: [value+unit] !important |
u-pr-mySpacingName |
padding-right: [value+unit] !important |
u-pb-mySpacingName |
padding-bottom [value+unit] !important |
u-pl-mySpacingName |
padding-left: [value+unit] !important |
Responsive utilities
For responsiveness, text alignment and spacings utilities classes are available
Responsive text alignment classes | Render only on myScreenSizeName screen size |
---|---|
u-ta-left-myScreenSizeName |
text-align: left !important |
u-ta-center-myScreenSizeName |
text-align: center !important |
u-ta-right-myScreenSizeName |
text-align: right !important |
Responsive spacings classes | Render only on myScreenSizeName screen size |
---|---|
u-m-mySpacingName-myScreenSizeName |
margin: [value+unit] !important |
u-mt-mySpacingName-myScreenSizeName |
margin-top: [value+unit] !important |
u-mr-mySpacingName-myScreenSizeName |
margin-right: [value+unit] !important |
u-mb-mySpacingName-myScreenSizeName |
margin-bottom: [value+unit] !important |
u-ml-mySpacingName-myScreenSizeName |
margin-left: [value+unit] !important |
u-p-mySpacingName-myScreenSizeName |
padding: [value+unit] !important |
u-pt-mySpacingName-myScreenSizeName |
padding-top: [value+unit] !important |
u-pr-mySpacingName-myScreenSizeName |
padding-right: [value+unit] !important |
u-pb-mySpacingName-myScreenSizeName |
padding-bottom: [value+unit] !important |
u-pl-mySpacingName-myScreenSizeName |
padding-left: [value+unit] !important |
Alternate responsive utilities with HTML attributes
This method is similar to standard CSS classes utilities but comes with extended feature: Multiple screen size selection.
HTML attribute
u-m-spacingName="screenName1, screenName2, screenName3"
is similar to
class="u-m-spacingName-screenName1 u-m-spacingName-screenName2 u-m-spacingName-screenName3"