@salutejs/plasma-themes
TypeScript icon, indicating that this package has built-in type declarations

0.11.0 • Public • Published

Plasma Themes

Пакет предоставляет набор дизайн-токенов, а также тем, реализующих дизайн вертикали «Plasma».

Конфигурация пакета

Тема Библиотека Шрифты
plasma_b2c @salutejs/plasma-b2c SB Sans Display, SB Sans Text
plasma_web @salutejs/plasma-web SB Sans Display, SB Sans Text
stylesSalute - SB Sans Display, SB Sans Text

Установка и подключение

Установка зависимости:

npm i --save @salutejs/plasma-themes

Типографическая система основана на фирменных шрифтах. Для того чтобы шрифт было удобно поставлять в web-приложения, шрифт был загружен на CDN.

Для использования типографической системы необходимо загрузить два css файла в зависимости от используемых шрифтов в теме. Их необходимо добавить внутрь тега head. Если в качестве основы web-приложения вы используете create-react-app, вам необходимо изменить файл ./public/index.html.

<html>
    <head>
        <link rel="stylesheet" href="https://cdn-app.sberdevices.ru/shared-static/0.0.0/styles/SBSansText.0.2.0.css" />
        <link
            rel="stylesheet"
            href="https://cdn-app.sberdevices.ru/shared-static/0.0.0/styles/SBSansDisplay.0.2.0.css"
        />
    </head>
    <body>
        ...
    </body>
</html>

Подключение с помощью styled-component:

import React from 'react';
import { createGlobalStyle } from 'styled-components';

import { Button, BodyL } from '@salutejs/plasma-b2c';
import { plasma_b2c__light } from '@salutejs/plasma-themes';

const Theme = createGlobalStyle(plasma_b2c__light);

const App = () => {
    return (
        <>
            <Theme />
            <BodyL>Hello world</BodyL>
            <Button text="This is themed button" />
        </>
    );
};

export default App;

Подключение с помощью импорта css файла:

import React from 'react';

import { Button, BodyL } from '@salutejs/plasma-b2c';

import '@salutejs/plasma-themes/css/plasma_b2c__dark.css';

const App = () => {
    return (
        <>
            <BodyL>Hello world</BodyL>
            <Button text="This is themed button" />
        </>
    );
};

export default App;

Подключение с помощью импорта модульного css файла:

Потребуется дополнительно настроить TypeScript

import React from 'react';

import { Button, BodyL } from '@salutejs/plasma-b2c';

import styles from '@salutejs/plasma-themes/css/plasma_b2c.module.css';

const App = () => {
    return (
        <div className={styles.dark}>
            <BodyL>Hello world</BodyL>
            <Button text="This is themed button" />
        </div>
    );
};

export default App;

Использование токенов

Все css токены завернуты в js переменные для более удобного доступа:

/** Основной цвет текста */
export const textPrimary = 'var(--text-primary, #F5F5F5)';
/** Основной фон */
export const backgroundPrimary = 'var(--background-primary, #000000)';

Так же в пакете есть типографические токены, для случаев, когда необходимо точечно применить типографику к контейнеру.

/** Токены типографики для компонента DsplL */
export const dsplL = ({
    fontFamily: 'var(--plasma-typo-dspl-l-font-family)',
    fontSize: 'var(--plasma-typo-dspl-l-font-size)',
    fontStyle: 'var(--plasma-typo-dspl-l-font-style)',
    fontWeight: 'var(--plasma-typo-dspl-l-font-weight)',
    letterSpacing: 'var(--plasma-typo-dspl-l-letter-spacing)',
    lineHeight: 'var(--plasma-typo-dspl-l-line-height)',
} as unknown) as CSSObject;

Пример использования:

import React from 'react';
import styled from 'styled-components';

import { textAccent, backgroundPrimary, textL } from '@salutejs/plasma-themes/tokens';

const AppStyled = styled.div`
    padding: 30px;
    color: ${textAccent};
    background-color: ${backgroundPrimary};
`;

const Container = styled.div`
    ${textL};
    margin: 15px;
`;

const App = () => {
    return (
        <AppStyled>
            <Container>
                <span>Hello world</span>
            </Container>
        </AppStyled>
    );
};

export default App;

Readme

Keywords

none

Package Sidebar

Install

npm i @salutejs/plasma-themes

Weekly Downloads

312

Version

0.11.0

License

MIT

Unpacked Size

2.02 MB

Total Files

72

Last publish

Collaborators

  • salute-eva
  • awinogradov
  • turanchoks
  • salute-assistant