pne-ui 5.0.0-rc.45 → 5.0.0-rc.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3099,8 +3099,20 @@ export const App = () => (
3099
3099
  )
3100
3100
  ```
3101
3101
 
3102
- Вторым аргументом `createPneTheme(skin, options)` принимает `PneCreateThemeOptions`: обычные `ThemeOptions` MUI и
3103
- `colorMode`. Переданные значения накладываются поверх темы `pne-ui`.
3102
+ Вторым аргументом `createPneTheme(skin, options)` принимает только `colorMode` (`'light'` по умолчанию или
3103
+ `'dark'`). Палитру, типографику и переопределения компонентов приложение в тему не передаёт: у всех приложений
3104
+ под одним скином тема одна. Если приложению не хватает цвета или вида, его добавляют в `pne-ui`. Свои цвета одной
3105
+ страницы (например, цвета графика) живут константами рядом с её компонентом, а не в теме.
3106
+
3107
+ Что тема задаёт сама, кроме вида компонентов:
3108
+
3109
+ - `palette.warning` — янтарный из шкалы UI Kit, одинаковый под любым скином и тот же, что у кнопки и
3110
+ уведомления-предупреждения: `main` `#A65C03`, `light` `#FA9A40`, `dark` `#8E4E01` в светлой теме, `#FA9A40` /
3111
+ `#FFC393` / `#D97A05` в тёмной. `light` — более яркий оттенок, а не подложка: от него MUI считает фон и текст
3112
+ своего `Alert`;
3113
+ - заголовки `Typography` (`h1`–`h6`, в том числе `subtitle1` / `subtitle2`) под скином Paynet: отступ, который
3114
+ `main.css` скина даёт заголовкам документа, снят; в тёмной теме заголовок без своего цвета берёт цвет текста
3115
+ вокруг, в светлой остаётся цвет скина. Отступ и цвет, заданные самому заголовку (`sx`, `color`), сохраняются.
3104
3116
 
3105
3117
  ### Светлая и тёмная схемы
3106
3118
 
@@ -7,7 +7,7 @@ const react_1 = tslib_1.__importStar(require("react"));
7
7
  const actionSpacing_1 = require("./actionSpacing");
8
8
  const createTheme_1 = require("./createTheme");
9
9
  const PneColorModeContext = (0, react_1.createContext)(null);
10
- const PneThemeProvider = ({ children, skin, mode: controlledMode, defaultMode = 'light', onModeChange, themeOptions, }) => {
10
+ const PneThemeProvider = ({ children, skin, mode: controlledMode, defaultMode = 'light', onModeChange, }) => {
11
11
  const [uncontrolledMode, setUncontrolledMode] = (0, react_1.useState)(defaultMode);
12
12
  const mode = controlledMode ?? uncontrolledMode;
13
13
  const setMode = (0, react_1.useCallback)((nextMode) => {
@@ -17,7 +17,7 @@ const PneThemeProvider = ({ children, skin, mode: controlledMode, defaultMode =
17
17
  onModeChange?.(nextMode);
18
18
  }, [controlledMode, onModeChange]);
19
19
  const contextValue = (0, react_1.useMemo)(() => ({ mode, setMode }), [mode, setMode]);
20
- const theme = (0, react_1.useMemo)(() => (0, createTheme_1.createPneTheme)(skin, { ...themeOptions, colorMode: mode }), [mode, skin, themeOptions]);
20
+ const theme = (0, react_1.useMemo)(() => (0, createTheme_1.createPneTheme)(skin, { colorMode: mode }), [mode, skin]);
21
21
  return (react_1.default.createElement(PneColorModeContext, { value: contextValue },
22
22
  react_1.default.createElement(styles_1.ThemeProvider, { theme: theme },
23
23
  react_1.default.createElement(actionSpacing_1.PneActionSpacingStyles, null),
@@ -12,6 +12,7 @@ const radioLook_1 = require("./radioLook");
12
12
  const iconButtonLook_1 = require("./iconButtonLook");
13
13
  const toggleLook_1 = require("./toggleLook");
14
14
  const tooltipLook_1 = require("./tooltipLook");
15
+ const typographyLook_1 = require("./typographyLook");
15
16
  const dropdownPalette_1 = require("./dropdownPalette");
16
17
  const modalPalette_1 = require("./modalPalette");
17
18
  const tablePalette_1 = require("./tablePalette");
@@ -163,27 +164,6 @@ const createSemanticSurfaces = (seed, mode) => ({
163
164
  },
164
165
  brand: createBrandPalette(seed, mode),
165
166
  });
166
- const isPlainObject = (value) => {
167
- if (value === null || typeof value !== 'object')
168
- return false;
169
- // A React element (the spinner of a waiting button) is one value, not a set of options.
170
- if ('$$typeof' in value)
171
- return false;
172
- const prototype = Object.getPrototypeOf(value);
173
- return prototype === Object.prototype || prototype === null;
174
- };
175
- const mergeThemeObjects = (base, override) => {
176
- if (!isPlainObject(base) || !isPlainObject(override)) {
177
- return (override === undefined ? base : override);
178
- }
179
- const result = { ...base };
180
- Object.entries(override).forEach(([key, value]) => {
181
- result[key] = key in result
182
- ? mergeThemeObjects(result[key], value)
183
- : value;
184
- });
185
- return result;
186
- };
187
167
  const createPneComponentOverrides = () => ({
188
168
  MuiFormHelperText: {
189
169
  styleOverrides: {
@@ -206,7 +186,20 @@ const createPneComponentOverrides = () => ({
206
186
  MuiRadio: (0, radioLook_1.createPneRadioOverrides)(exports.resolvePneSemanticPalette),
207
187
  MuiTooltip: (0, tooltipLook_1.createPneTooltipOverrides)(),
208
188
  MuiToggleButtonGroup: (0, toggleLook_1.createPneToggleGroupOverrides)(exports.resolvePneSemanticPalette),
189
+ MuiTypography: (0, typographyLook_1.createPneTypographyOverrides)(),
209
190
  });
191
+ /**
192
+ * The Amber of the UI Kit, as the warning button and toast. `main` is the fill a white label reads on
193
+ * and text on a light page (600), or text on a dark one (400). All three shades are named: MUI derives
194
+ * the tint and the text of its warning `Alert` from `light`, and the theme's `tonalOffset` would make a
195
+ * derived `light` nearly white.
196
+ */
197
+ const createWarningPalette = (mode) => {
198
+ const amber = themeColors_1.PNE_STATUS_COLORS.warning;
199
+ return mode === 'dark'
200
+ ? { main: amber[400], light: amber[300], dark: amber[500] }
201
+ : { main: amber[600], light: amber[400], dark: amber[700] };
202
+ };
210
203
  const createBaseThemeOptions = (skin, mode) => {
211
204
  const seed = (0, color_1.normalizeHexColor)(skin.experimentalColor);
212
205
  const pne = createSemanticPalette(seed, mode);
@@ -247,6 +240,7 @@ const createBaseThemeOptions = (skin, mode) => {
247
240
  contrastText: chooseContrastText(pne.brand.foreground),
248
241
  }
249
242
  : { main: seed },
243
+ warning: createWarningPalette(mode),
250
244
  pne,
251
245
  pneNeutral: { main: seed },
252
246
  pnePrimary: { main: seed },
@@ -256,16 +250,5 @@ const createBaseThemeOptions = (skin, mode) => {
256
250
  components: createPneComponentOverrides(),
257
251
  };
258
252
  };
259
- const createPneThemeOptions = (skin, options = {}) => {
260
- const { colorMode, palette, ...themeOverrides } = options;
261
- const { mode: paletteMode, ...paletteOverrides } = palette ?? {};
262
- const mode = colorMode ?? paletteMode ?? 'light';
263
- const normalizedMode = mode === 'dark' ? 'dark' : 'light';
264
- const overrides = {
265
- ...themeOverrides,
266
- ...(palette ? { palette: paletteOverrides } : {}),
267
- };
268
- return mergeThemeObjects(createBaseThemeOptions(skin, normalizedMode), overrides);
269
- };
270
- const createPneTheme = (skin, options, ...args) => (0, styles_1.createTheme)(createPneThemeOptions(skin, options), ...args);
253
+ const createPneTheme = (skin, options = {}) => (0, styles_1.createTheme)(createBaseThemeOptions(skin, options.colorMode === 'dark' ? 'dark' : 'light'));
271
254
  exports.createPneTheme = createPneTheme;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createPneTypographyOverrides = void 0;
4
+ const HEADING_TAGS = new Set(['h1', 'h2', 'h3', 'h4', 'h5', 'h6']);
5
+ // Typography's own tags for the variants that render a heading.
6
+ const HEADING_VARIANT_TAGS = {
7
+ h1: 'h1',
8
+ h2: 'h2',
9
+ h3: 'h3',
10
+ h4: 'h4',
11
+ h5: 'h5',
12
+ h6: 'h6',
13
+ subtitle1: 'h6',
14
+ subtitle2: 'h6',
15
+ };
16
+ const getTypographyTag = ({ component, variant = 'body1', variantMapping }) => {
17
+ if (component !== undefined)
18
+ return typeof component === 'string' ? component : undefined;
19
+ return variantMapping?.[variant] ?? HEADING_VARIANT_TAGS[variant];
20
+ };
21
+ /**
22
+ * Headings of a page that lives under the Paynet skin. The skin's main.css styles every h1-h6 of the
23
+ * document. Its colour belongs to the skin and stays in the light theme; in the dark one it stood 1.5:1
24
+ * on the page, so there a heading without a colour of its own takes the text around it. Its spacing
25
+ * belongs to no skin: h2's padding-top of 1.3em put titles 23px low, so a heading drops it in both
26
+ * themes. A padding or a colour the page gives the heading itself (`sx`, `color`) still wins.
27
+ */
28
+ const createPneTypographyOverrides = () => ({
29
+ styleOverrides: {
30
+ root: ({ ownerState, theme }) => {
31
+ const props = ownerState;
32
+ const tag = getTypographyTag(props);
33
+ if (!tag || !HEADING_TAGS.has(tag))
34
+ return {};
35
+ return {
36
+ padding: 0,
37
+ ...(theme.palette.mode === 'dark' && props.color === undefined
38
+ ? { color: 'inherit' }
39
+ : {}),
40
+ };
41
+ },
42
+ },
43
+ });
44
+ exports.createPneTypographyOverrides = createPneTypographyOverrides;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import type { Skin } from './common/paynet/skin';
3
- import { type PneColorMode, type PneCreateThemeOptions } from './createTheme';
3
+ import { type PneColorMode } from './createTheme';
4
4
  export type PneColorModeContextValue = {
5
5
  mode: PneColorMode;
6
6
  setMode: (mode: PneColorMode) => void;
@@ -13,8 +13,7 @@ export type PneThemeProviderProps = {
13
13
  /** In-memory fallback for stories and standalone consumers. No browser storage is used. */
14
14
  defaultMode?: PneColorMode;
15
15
  onModeChange?: (mode: PneColorMode) => void;
16
- themeOptions?: Omit<PneCreateThemeOptions, 'colorMode'>;
17
16
  };
18
- export declare const PneThemeProvider: ({ children, skin, mode: controlledMode, defaultMode, onModeChange, themeOptions, }: PneThemeProviderProps) => React.JSX.Element;
17
+ export declare const PneThemeProvider: ({ children, skin, mode: controlledMode, defaultMode, onModeChange, }: PneThemeProviderProps) => React.JSX.Element;
19
18
  export declare const usePneColorMode: () => PneColorModeContextValue;
20
19
  export default PneThemeProvider;
@@ -1,9 +1,9 @@
1
1
  import { ThemeProvider } from '@mui/material/styles';
2
2
  import React, { createContext, useCallback, use, useMemo, useState } from 'react';
3
3
  import { PneActionSpacingStyles } from './actionSpacing';
4
- import { createPneTheme, } from './createTheme';
4
+ import { createPneTheme } from './createTheme';
5
5
  const PneColorModeContext = createContext(null);
6
- export const PneThemeProvider = ({ children, skin, mode: controlledMode, defaultMode = 'light', onModeChange, themeOptions, }) => {
6
+ export const PneThemeProvider = ({ children, skin, mode: controlledMode, defaultMode = 'light', onModeChange, }) => {
7
7
  const [uncontrolledMode, setUncontrolledMode] = useState(defaultMode);
8
8
  const mode = controlledMode ?? uncontrolledMode;
9
9
  const setMode = useCallback((nextMode) => {
@@ -13,7 +13,7 @@ export const PneThemeProvider = ({ children, skin, mode: controlledMode, default
13
13
  onModeChange?.(nextMode);
14
14
  }, [controlledMode, onModeChange]);
15
15
  const contextValue = useMemo(() => ({ mode, setMode }), [mode, setMode]);
16
- const theme = useMemo(() => createPneTheme(skin, { ...themeOptions, colorMode: mode }), [mode, skin, themeOptions]);
16
+ const theme = useMemo(() => createPneTheme(skin, { colorMode: mode }), [mode, skin]);
17
17
  return (React.createElement(PneColorModeContext, { value: contextValue },
18
18
  React.createElement(ThemeProvider, { theme: theme },
19
19
  React.createElement(PneActionSpacingStyles, null),
@@ -1,4 +1,4 @@
1
- import { type Theme, type ThemeOptions } from '@mui/material/styles';
1
+ import { type Theme } from '@mui/material/styles';
2
2
  import { Skin } from './common/paynet/skin';
3
3
  import { type PneBrandRamp } from './brandRamp';
4
4
  import { type PneButtonPalette } from './buttonPalette';
@@ -77,10 +77,15 @@ export type PneSemanticPalette = {
77
77
  /** Link text on the page. */
78
78
  link: string;
79
79
  };
80
- export type PneCreateThemeOptions = Omit<ThemeOptions, 'skin'> & {
81
- /** PNE color mode. `palette.mode` remains supported for compatibility. */
80
+ /**
81
+ * Everything an application chooses about the theme besides its skin. The theme takes no palette,
82
+ * typography or component overrides: a colour or a look an application lacks is added to the library,
83
+ * so every application under one skin draws the same.
84
+ */
85
+ export type PneCreateThemeOptions = {
86
+ /** Light by default. */
82
87
  colorMode?: PneColorMode;
83
88
  };
84
89
  /** The PNE palette of a theme; one is built from `primary.main` for a theme made without `createPneTheme`. */
85
90
  export declare const resolvePneSemanticPalette: (theme: Theme) => PneSemanticPalette;
86
- export declare const createPneTheme: (skin: Skin, options?: PneCreateThemeOptions, ...args: object[]) => Theme;
91
+ export declare const createPneTheme: (skin: Skin, options?: PneCreateThemeOptions) => Theme;
@@ -9,13 +9,14 @@ import { createPneRadioOverrides } from './radioLook';
9
9
  import { createPneIconButtonOverrides, createPneSvgIconOverrides } from './iconButtonLook';
10
10
  import { createPneToggleGroupOverrides } from './toggleLook';
11
11
  import { createPneTooltipOverrides } from './tooltipLook';
12
+ import { createPneTypographyOverrides } from './typographyLook';
12
13
  import { createPneDropdownPalette } from './dropdownPalette';
13
14
  import { createPneModalPalette } from './modalPalette';
14
15
  import { createPneTablePalette } from './tablePalette';
15
16
  import { createPneToastPalette } from './toastPalette';
16
17
  import { createPneFieldPalette } from './fieldPalette';
17
18
  import { createPneSwitchPalette } from './switchPalette';
18
- import { PNE_DARK_COLORS, PNE_LIGHT_COLORS } from './themeColors';
19
+ import { PNE_DARK_COLORS, PNE_LIGHT_COLORS, PNE_STATUS_COLORS } from './themeColors';
19
20
  export { PNE_DARK_COLORS } from './themeColors';
20
21
  const MIN_FOREGROUND_CONTRAST = 4.5;
21
22
  const MIN_CONTROL_BOUNDARY_CONTRAST = 3;
@@ -158,27 +159,6 @@ const createSemanticSurfaces = (seed, mode) => ({
158
159
  },
159
160
  brand: createBrandPalette(seed, mode),
160
161
  });
161
- const isPlainObject = (value) => {
162
- if (value === null || typeof value !== 'object')
163
- return false;
164
- // A React element (the spinner of a waiting button) is one value, not a set of options.
165
- if ('$$typeof' in value)
166
- return false;
167
- const prototype = Object.getPrototypeOf(value);
168
- return prototype === Object.prototype || prototype === null;
169
- };
170
- const mergeThemeObjects = (base, override) => {
171
- if (!isPlainObject(base) || !isPlainObject(override)) {
172
- return (override === undefined ? base : override);
173
- }
174
- const result = { ...base };
175
- Object.entries(override).forEach(([key, value]) => {
176
- result[key] = key in result
177
- ? mergeThemeObjects(result[key], value)
178
- : value;
179
- });
180
- return result;
181
- };
182
162
  const createPneComponentOverrides = () => ({
183
163
  MuiFormHelperText: {
184
164
  styleOverrides: {
@@ -201,7 +181,20 @@ const createPneComponentOverrides = () => ({
201
181
  MuiRadio: createPneRadioOverrides(resolvePneSemanticPalette),
202
182
  MuiTooltip: createPneTooltipOverrides(),
203
183
  MuiToggleButtonGroup: createPneToggleGroupOverrides(resolvePneSemanticPalette),
184
+ MuiTypography: createPneTypographyOverrides(),
204
185
  });
186
+ /**
187
+ * The Amber of the UI Kit, as the warning button and toast. `main` is the fill a white label reads on
188
+ * and text on a light page (600), or text on a dark one (400). All three shades are named: MUI derives
189
+ * the tint and the text of its warning `Alert` from `light`, and the theme's `tonalOffset` would make a
190
+ * derived `light` nearly white.
191
+ */
192
+ const createWarningPalette = (mode) => {
193
+ const amber = PNE_STATUS_COLORS.warning;
194
+ return mode === 'dark'
195
+ ? { main: amber[400], light: amber[300], dark: amber[500] }
196
+ : { main: amber[600], light: amber[400], dark: amber[700] };
197
+ };
205
198
  const createBaseThemeOptions = (skin, mode) => {
206
199
  const seed = normalizeHexColor(skin.experimentalColor);
207
200
  const pne = createSemanticPalette(seed, mode);
@@ -242,6 +235,7 @@ const createBaseThemeOptions = (skin, mode) => {
242
235
  contrastText: chooseContrastText(pne.brand.foreground),
243
236
  }
244
237
  : { main: seed },
238
+ warning: createWarningPalette(mode),
245
239
  pne,
246
240
  pneNeutral: { main: seed },
247
241
  pnePrimary: { main: seed },
@@ -251,15 +245,4 @@ const createBaseThemeOptions = (skin, mode) => {
251
245
  components: createPneComponentOverrides(),
252
246
  };
253
247
  };
254
- const createPneThemeOptions = (skin, options = {}) => {
255
- const { colorMode, palette, ...themeOverrides } = options;
256
- const { mode: paletteMode, ...paletteOverrides } = palette ?? {};
257
- const mode = colorMode ?? paletteMode ?? 'light';
258
- const normalizedMode = mode === 'dark' ? 'dark' : 'light';
259
- const overrides = {
260
- ...themeOverrides,
261
- ...(palette ? { palette: paletteOverrides } : {}),
262
- };
263
- return mergeThemeObjects(createBaseThemeOptions(skin, normalizedMode), overrides);
264
- };
265
- export const createPneTheme = (skin, options, ...args) => createTheme(createPneThemeOptions(skin, options), ...args);
248
+ export const createPneTheme = (skin, options = {}) => createTheme(createBaseThemeOptions(skin, options.colorMode === 'dark' ? 'dark' : 'light'));
@@ -0,0 +1,9 @@
1
+ import type { Components, Theme } from '@mui/material/styles';
2
+ /**
3
+ * Headings of a page that lives under the Paynet skin. The skin's main.css styles every h1-h6 of the
4
+ * document. Its colour belongs to the skin and stays in the light theme; in the dark one it stood 1.5:1
5
+ * on the page, so there a heading without a colour of its own takes the text around it. Its spacing
6
+ * belongs to no skin: h2's padding-top of 1.3em put titles 23px low, so a heading drops it in both
7
+ * themes. A padding or a colour the page gives the heading itself (`sx`, `color`) still wins.
8
+ */
9
+ export declare const createPneTypographyOverrides: () => NonNullable<Components<Theme>['MuiTypography']>;
@@ -0,0 +1,40 @@
1
+ const HEADING_TAGS = new Set(['h1', 'h2', 'h3', 'h4', 'h5', 'h6']);
2
+ // Typography's own tags for the variants that render a heading.
3
+ const HEADING_VARIANT_TAGS = {
4
+ h1: 'h1',
5
+ h2: 'h2',
6
+ h3: 'h3',
7
+ h4: 'h4',
8
+ h5: 'h5',
9
+ h6: 'h6',
10
+ subtitle1: 'h6',
11
+ subtitle2: 'h6',
12
+ };
13
+ const getTypographyTag = ({ component, variant = 'body1', variantMapping }) => {
14
+ if (component !== undefined)
15
+ return typeof component === 'string' ? component : undefined;
16
+ return variantMapping?.[variant] ?? HEADING_VARIANT_TAGS[variant];
17
+ };
18
+ /**
19
+ * Headings of a page that lives under the Paynet skin. The skin's main.css styles every h1-h6 of the
20
+ * document. Its colour belongs to the skin and stays in the light theme; in the dark one it stood 1.5:1
21
+ * on the page, so there a heading without a colour of its own takes the text around it. Its spacing
22
+ * belongs to no skin: h2's padding-top of 1.3em put titles 23px low, so a heading drops it in both
23
+ * themes. A padding or a colour the page gives the heading itself (`sx`, `color`) still wins.
24
+ */
25
+ export const createPneTypographyOverrides = () => ({
26
+ styleOverrides: {
27
+ root: ({ ownerState, theme }) => {
28
+ const props = ownerState;
29
+ const tag = getTypographyTag(props);
30
+ if (!tag || !HEADING_TAGS.has(tag))
31
+ return {};
32
+ return {
33
+ padding: 0,
34
+ ...(theme.palette.mode === 'dark' && props.color === undefined
35
+ ? { color: 'inherit' }
36
+ : {}),
37
+ };
38
+ },
39
+ },
40
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pne-ui",
3
- "version": "5.0.0-rc.45",
3
+ "version": "5.0.0-rc.46",
4
4
  "description": "React component kit on MUI for Payneteasy applications",
5
5
  "repository": {
6
6
  "type": "git",