SDDS-FINPORTAL
Набор компонентов и утилит для создания web-приложений на базе ReactJS.
Использование
Библиотека реализована с помощью:
- typescript
- styled-components (рекомендуем использовать версию
5.3.1
)
Однако их использование необязательно!
Установка зависимостей
Убедитесь, что у вас установлен ReactJS!
$ npm install --save @salutejs/sdds-finportal @salutejs/sdds-themes
Для работы со styled-components
, необходимо установить
$ npm install --save styled-components@5.3.1
Использование компонентов
Все компоненты доступны напрямую из пакета
import styled from 'styled-components';
import { Button } from '@salutejs/sdds-finportal';
import { textAccent } from '@salutejs/sdds-themes/tokens';
export const App = () => {
const StyledP = styled.p`
color: ${textAccent};
`;
return (
<>
<Button>Hello, Plasma!</Button>
<StyledP>
Token usage example
</StyledP>
</>
);
};
Подключение шрифтов
Типографическая система основана на фирменных шрифтах.
Для того чтобы шрифт было удобно поставлять в 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"
/>
<title>Wep App</title>
</head>
<body>
...
</body>
</html>
Если в качестве основы web-приложения вы используете Next, вам необходимо изменить файл ./pages/index.html
.
import Head from "next/head";
import { H2, Button } from "@salutejs/sdds-finportal";
export default function Home() {
return (
<>
<Head>
<title>Create Next App with sdds-finportal 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"
/>
</Head>
<div>
<main>
<div>
<H2> Salute </H2>
<Button text="Hello" />
</div>
</main>
</div>
</>
);
}
Подключение темы
Точкой входа является корень приложения:
- Если вы используете Create React App, делайте вызов внутри
src/index.tsx
. - Если вы используете Next.js, создайте файл
pages/_app.tsx
и подключите стили в нем.
- styled-components
import React from 'react';
import { createGlobalStyle } from 'styled-components';
import { Button, BodyL } from '@salutejs/sdds-finportal';
import { sdds_finportal__light } from '@salutejs/sdds-themes';
const Theme = createGlobalStyle(sdds_finportal__light);
const App = () => {
return (
<>
<Theme />
<BodyL>Hello world</BodyL>
<Button text="This is themed button" />
</>
);
};
export default App;
Переключение тем
- styled-components
import React, { useState } from 'react';
import { createGlobalStyle } from 'styled-components';
import { Switch } from '@salutejs/sdds-finportal';
import { sdds_finportal__light, sdds_finportal__dark } from '@salutejs/sdds-themes';
const LightTheme = createGlobalStyle(sdds_finportal__light);
const DarkTheme = createGlobalStyle(sdds_finportal__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;