1.16.0 • Published 2 years ago

@magnesium/typography v1.16.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@magnesium/typography

The Magnesium Design typography system help you to define your typographic styles.

Installing

npm install @magnesium/typography

Usage

Styles

@use "@magnesium/typography/styles";

This will generate the default typography classes, see CSS Classes section for more.

Configuration

You can define the typography style variables before importing any Magnesium components:

@use "@magnesium/typography" with (
    $styles: (
        body: (
            font-size: 20px
        )
    )
);

Options

NameDefaultDescription
$stylesSee Scales section.Sets a list of theme scales.
$font-family"Open Sans", sans-serifSets the font family styles.
$font-baseline16pxSets the font baseline for rem styles.
$font-smoothingtrueSets the font smoothing default styles.

Scales

NameDescription
bodySets the "body" properties.
headline-1Sets the "headline 1" properties.
headline-2Sets the "headline 2" properties.
headline-3Sets the "headline 3" properties.
headline-4Sets the "headline 4" properties.
headline-5Sets the "headline 5" properties.
headline-6Sets the "headline 6" properties.

You can also define new styles for typography:

@use "@magnesium/typography" with (
    $styles: (
        body-2: (
            font-size: 16px
        )
    )
);

The new key named body-2 is now available with any other default typography keys.

Customization

CSS custom properties

The variable {style} correspond with the list of $styles keys, do not hesitate to check it for more examples!

CSS custom propertyDescription
--mg-typography-{style}Override the selected style.

CSS classes

CSS ClassDescription
mg-typography--{style}Sets the typography to the selected style.

API

Sass mixins

MixinDescription
baseSets base styles.
typography($style, $exclude-props...)Sets the selected style on selector, with excluded properties option.
font-smoothingSets the font smoothing rules.
ellipsisSets the ellipsis rules.
ellipsis-multiline($line, $orient)Sets the ellipsis-multiline rules.

Typography rule with typography.base()

The following Sass...

@use "@magnesium/typography";

.foo {
    @include typography.base;
}

...will produce the following CSS...

.foo {
    font-family: var(--mg-typography-font-family, 'Open Sans', sans-serif);
    font-size: 100%;
}

Typography rule with typography.typography()

The following Sass...

@use "@magnesium/typography";

.foo {
    @include typography.typography(body);
}

.bar {
    // With excluded properties options.
    @include typography.typography(body, font-size, line-height, text-decoration, text-transform);
}

...will produce the following CSS...

.foo {
    line-height: var(--mg-typography-body-line-height, 1.25rem);
    font-family: var(--mg-typography-body-font-family, var(--mg-typography-font-family, 'Open Sans', sans-serif));
    font-size: var(--mg-typography-body-font-size, 1rem);
    font-weight: var(--mg-typography-body-font-weight, 400);
    letter-spacing: var(--mg-typography-body-letter-spacing, normal);
    text-decoration: var(--mg-typography-body-text-decoration, inherit);
    text-transform: var(--mg-typography-body-text-transform, inherit);
}

.bar {
    font-family: var(--mg-typography-body-font-family, var(--mg-typography-font-family, 'Open Sans', sans-serif));
    font-weight: var(--mg-typography-body-font-weight, 400);
    letter-spacing: var(--mg-typography-body-letter-spacing, normal);
}

Font smoothing with typography.font-smoothing()

The following Sass...

@use "@magnesium/typography";

.foo {
    @include typography.font-smoothing;
}

...will produce the following CSS...

.foo {
    -moz-osx-font-smoothing: grayscale;
    -webkit-font-smoothing: antialiased;
}

Ellipsis with typography.ellipsis()

The following Sass...

@use "@magnesium/typography";

.foo {
    @include typography.ellipsis;
}

...will produce the following CSS...

.foo {
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
}

Ellipsis multiline with typography.ellipsis-multiline()

The following Sass...

@use "@magnesium/typography";

.foo {
    @include typography.ellipsis-multiline(2, vertical);
}

...will produce the following CSS...

.foo {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
1.15.0

2 years ago

1.14.0

2 years ago

1.16.0

2 years ago

1.13.2

2 years ago

1.13.1

2 years ago

1.11.3

2 years ago

1.13.0

2 years ago

1.12.1

2 years ago

1.11.2

2 years ago

1.12.0

2 years ago

1.11.1

2 years ago

1.12.0-beta.1

2 years ago

2.0.0-beta.1

2 years ago

1.11.0

2 years ago

1.10.0

2 years ago

1.9.1

2 years ago

1.9.0

2 years ago

1.9.0-beta.1

2 years ago

1.9.4

2 years ago

1.9.3

2 years ago

1.9.2

2 years ago

1.8.1

2 years ago

1.8.0

2 years ago

1.7.0

2 years ago

1.6.0

2 years ago

1.5.1

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago

1.5.0

2 years ago

1.4.1

2 years ago

1.3.2

2 years ago

1.4.0

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.0.0-alpha.8

2 years ago

1.0.0-alpha.7

2 years ago

1.0.0-alpha.6

2 years ago

1.0.0-alpha.5

2 years ago

1.0.0-alpha.4

2 years ago

1.0.0-alpha.3

2 years ago

1.0.0-alpha.2

2 years ago

1.0.0-alpha.1

2 years ago

1.0.0-alpha.0

2 years ago