Библиотека компонентов для вертикали SDDS NETOLOGY
Реализация компонентов для создания веб-приложений.
Компоненты реализованы с помощью React и поставляются в двух вариантах:
- на предсобранном CSS,
- на styled-components.
Установка
Требуются react и react-dom версии 16.13.1 или выше.
$ npm install --save react react-dom
$ npm install --save @salutejs/sdds-netology @salutejs/plasma-themes
Дальнейшие шаги зависят от выбранного варианта поставки.
Для варианта на styled-components:
$ npm install --save styled-components@5.3.11
CSS-вариант дополнительных зависимостей не требует.
Варианты поставки
CSS-вариант является поставкой по умолчанию.
Один и тот же набор компонентов доступен из двух точек входа:
| Точка входа | Реализация | Дополнительные зависимости |
|---|---|---|
@salutejs/sdds-netology | предсобранный CSS | нет |
@salutejs/sdds-netology/styled-components | styled-components | styled-components@5.3.11 |
import { Button } from '@salutejs/sdds-netology';
// или
import { Button } from '@salutejs/sdds-netology/styled-components';
Подключение шрифтов
Для того чтобы шрифт было удобно поставлять в web-приложения, шрифт был загружен на CDN.
Типографическая система основана на фирменных шрифтах.
Для её использования, необходимо загрузить три css файла в зависимости от используемых шрифтов в теме.
- html
- NextJS
Если в качестве основы web-приложения вы используете create-react-app, вам необходимо изменить файл ./public/index.html.
Добавить внутрь тега head.
<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"
/>
<link
rel="stylesheet"
href="https://cdn-app.sberdevices.ru/shared-static/0.0.0/styles/SBSansTextMono.0.2.0.css"
/>
<title>Web App</title>
</head>
<body>
...
</body>
</html>
Если в качестве основы web-приложения вы используете Next.js, добавьте ссылки на шрифты через next/head — например, в ./pages/index.tsx.
import Head from "next/head";
import { H2, Button } from "@salutejs/sdds-netology";
export default function Home() {
return (
<>
<Head>
<title>Create Next App with sdds-netology components</title>
<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"
/>
<link
rel="stylesheet"
href="https://cdn-app.sberdevices.ru/shared-static/0.0.0/styles/SBSansTextMono.0.2.0.css"
/>
</Head>
<div>
<main>
<div>
<H2> SDDS NETOLOGY </H2>
<Button text="Hello" />
</div>
</main>
</div>
</>
);
}
Подключение темы
Тема включает в себя цветовые и типографические токены и подключается один раз в корне приложения.
Точкой входа является корень приложения:
- Если вы используете Create React App, делайте вызов внутри
src/index.tsx. - Если вы используете Next.js, создайте файл
pages/_app.tsxи подключите стили в нем.
Доступны светлая и тёмная темы — plasma_b2c__light и plasma_b2c__dark.
- css
- css-module
- styled-components
- sass
- sass-module
import React from 'react';
import { Button, BodyL } from '@salutejs/sdds-netology';
import '@salutejs/plasma-themes/css/plasma_b2c__light.css';
const App = () => {
return (
<>
<BodyL>Hello world</BodyL>
<Button text="This is themed button" />
</>
);
};
export default App;
Или подключите тему в файле, где собраны все стили приложения, например index.css
@import '@salutejs/plasma-themes/css/plasma_b2c__light.css';
Возможные дополнительные настройки в проекте:
Bundle tools:
TS:
Создайтеglobal.d.tsdeclare module "*.css" {
export default {
[index: string]: string;
}
}
import React from 'react';
import { Button, BodyL } from '@salutejs/sdds-netology';
import styles from '@salutejs/plasma-themes/css/plasma_b2c.module.css';
const App = () => {
return (
<div className={styles.light}>
<BodyL>Hello world</BodyL>
<Button text="This is themed button" />
</div>
);
};
export default App;
import React from 'react';
import { createGlobalStyle } from 'styled-components';
import { Button, BodyL } from '@salutejs/sdds-netology/styled-components';
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;
import React from 'react';
import { Button, BodyL } from '@salutejs/sdds-netology';
import './index.sass';
const App = () => {
return (
<>
<BodyL>Hello world</BodyL>
<Button text="This is themed button" />
</>
);
};
export default App;
В файле, где происходит подключение всех стилей, например index.sass
@use '@salutejs/plasma-themes/css/plasma_b2c__dark.css';
// остальные стили
Возможные дополнительные настройки в проекте:
Bundle tools:
TS:
Создайтеglobal.d.tsdeclare module "*.css" {
export default {
[index: string]: string;
}
}
import React from 'react';
import { Button, BodyL } from '@salutejs/sdds-netology';
import styles from './index.module.sass';
const App = () => {
return (
<div className={styles.dark}>
<BodyL>Hello world</BodyL>
<Button text="This is themed button" />
</div>
);
};
export default App;
В файле, где происходит подключение всех стилей, например index.module.sass
@use '@salutejs/plasma-themes/css/plasma_b2c.module.css'
Переключение тем
- css
- css-module
- styled-components
- sass
- sass-module
import React, { useLayoutEffect, useState } from 'react';
import { Switch } from '@salutejs/sdds-netology';
import './index.css';
const App = () => {
const [theme, setTheme] = useState('light');
useLayoutEffect(() => {
document.documentElement.className = theme;
}, [theme]);
return (
<div className="wrapper">
<Switch
label={`app theme: ${theme}`}
onChange={() => {
setTheme((theme) => (theme === 'light' ? 'dark' : 'light'));
}}
/>
</div>
);
};
export default App;
В файле, где происходит подключение всех стилей, например index.css
@import '@salutejs/plasma-themes/css/plasma_b2c.module.css';
Возможные дополнительные настройки в проекте:
Bundle tools:
TS:
Создайтеglobal.d.tsdeclare module "*.css" {
export default {
[index: string]: string;
}
}
import React, { useLayoutEffect, useState } from 'react';
import { Switch } from '@salutejs/sdds-netology';
import webThemes from '@salutejs/plasma-themes/css/plasma_b2c.module.css';
import './style.css';
const App = () => {
const [theme, setTheme] = useState('light');
useLayoutEffect(() => {
document.documentElement.className = webThemes[theme];
}, [theme]);
return (
<div className="wrapper">
<Switch
label={`app theme: ${theme}`}
onChange={() => {
setTheme((theme) => (theme === 'light' ? 'dark' : 'light'));
}}
/>
</div>
);
};
export default App;
import React, { useState } from 'react';
import { createGlobalStyle } from 'styled-components';
import { Switch } from '@salutejs/sdds-netology/styled-components';
import { plasma_b2c__light, plasma_b2c__dark } from '@salutejs/plasma-themes';
import './style.css';
const LightTheme = createGlobalStyle(plasma_b2c__light);
const DarkTheme = createGlobalStyle(plasma_b2c__dark);
const App = () => {
const [theme, setTheme] = useState('light');
return (
<>
{theme === 'light' ? <LightTheme /> : <DarkTheme />}
<div className="wrapper">
<Switch
label={`app theme: ${theme}`}
onChange={() => {
setTheme((theme) => (theme === 'light' ? 'dark' : 'light'));
}}
/>
</div>
</>
);
};
export default App;
import React, { useLayoutEffect, useState } from 'react';
import { Switch } from '@salutejs/sdds-netology';
import './index.sass';
const App = () => {
const [theme, setTheme] = useState('light');
useLayoutEffect(() => {
document.documentElement.className = theme;
}, [theme]);
return (
<div className="wrapper">
<Switch
label={`app theme: ${theme}`}
onChange={() => {
setTheme((theme) => (theme === 'light' ? 'dark' : 'light'));
}}
/>
</div>
);
};
export default App;
В файле, где происходит подключение всех стилей, например index.sass
@use '@salutejs/plasma-themes/css/plasma_b2c__dark.css'
// остальные стили
Возможные дополнительные настройки в проекте:
Bundle tools:
TS:
Создайтеglobal.d.tsdeclare module "*.css" {
export default {
[index: string]: string;
}
}
import React, { useLayoutEffect, useState } from 'react';
import { Switch } from '@salutejs/sdds-netology';
import './style.sass';
const App = () => {
const [theme, setTheme] = useState('light');
useLayoutEffect(() => {
document.documentElement.className = theme;
}, [theme]);
return (
<div className="wrapper">
<Switch
label={`app theme: ${theme}`}
onChange={() => {
setTheme((theme) => (theme === 'light' ? 'dark' : 'light'));
}}
/>
</div>
);
};
export default App;
В файле, где происходит подключение всех стилей, например index.sass
@use '@salutejs/plasma-themes/css/plasma_b2c.module.css'
Использование компонентов
Все компоненты доступны напрямую из пакета:
import { Button, BodyL } from '@salutejs/sdds-netology';
export const App = () => {
return (
<>
<BodyL>Hello, SDDS NETOLOGY!</BodyL>
<Button>Кнопка</Button>
</>
);
};
Использование токенов
Все 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;
Есть два пути импорта токенов:
Путь @salutejs/plasma-themes/tokens/plasma_b2c следует использовать, когда нужны токены, которые есть только в этой теме.
- базовый набор — из
@salutejs/plasma-themes/tokens - уникальные токены темы — из
@salutejs/plasma-themes/tokens/plasma_b2c
Пример использования:
import React from 'react';
import styled from 'styled-components';
import { textAccent, backgroundPrimary, textL } from '@salutejs/plasma-themes/tokens';
const AppStyled = styled.div`
padding: 2rem;
color: ${textAccent};
background-color: ${backgroundPrimary};
`;
const Container = styled.div`
${textL};
margin: 1rem;
`;
const App = () => {
return (
<AppStyled>
<Container>
<span>Hello world</span>
</Container>
</AppStyled>
);
};
export default App;
Что дальше
Подробные руководства собраны в разделе «Руководства»:
- Работа с Next — RSC,
'use client',transpilePackages - Как работать с MCP — актуальная документация для AI-агентов
- Как работать с иконками
- Поддержка React 16, 17 —
SSRProvider - FAQ