@xsolla/xui-core 0.128.0 → 0.129.0
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 +66 -5
- package/index.d.mts +3550 -3073
- package/index.d.ts +3550 -3073
- package/index.js +374 -927
- package/index.js.map +1 -1
- package/index.mjs +372 -926
- package/index.mjs.map +1 -1
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -27,31 +27,92 @@ function MyComponent() {
|
|
|
27
27
|
}
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
+
Per-component theme overrides with `useResolvedTheme`:
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
import { useResolvedTheme, ThemeOverrideProps } from '@xsolla/xui-core';
|
|
34
|
+
|
|
35
|
+
type MyWidgetProps = ThemeOverrideProps & { label: string };
|
|
36
|
+
|
|
37
|
+
function MyWidget({ label, themeMode, themeProductContext }: MyWidgetProps) {
|
|
38
|
+
const { theme, mode } = useResolvedTheme({ themeMode, themeProductContext });
|
|
39
|
+
return <div style={{ color: theme.colors.content.primary }}>{label}</div>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Usage — override theme per-instance without nesting providers
|
|
43
|
+
<MyWidget label="Global theme" />
|
|
44
|
+
<MyWidget label="Light override" themeMode="light" />
|
|
45
|
+
```
|
|
46
|
+
|
|
30
47
|
## Available Theme Modes
|
|
31
48
|
|
|
32
49
|
| Mode | Theme |
|
|
33
50
|
|------|-------|
|
|
34
|
-
| `"light"` | Pentagram Light (default) |
|
|
35
51
|
| `"dark"` | Pentagram Dark (default) |
|
|
36
|
-
| `"
|
|
37
|
-
| `"xsollaDark"` | Xsolla Dark |
|
|
52
|
+
| `"light"` | Pentagram Light |
|
|
38
53
|
| `"ltg-dark"` | LTG Dark |
|
|
39
54
|
|
|
40
|
-
|
|
55
|
+
## Per-Component Overrides
|
|
56
|
+
|
|
57
|
+
Every component accepts `themeMode` and `themeProductContext` props to override the global provider:
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
<Button themeMode="light" themeProductContext="b2c">Override Both</Button>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
For custom components, use `useResolvedTheme` instead of `useDesignSystem`.
|
|
41
64
|
|
|
42
65
|
## Exports
|
|
43
66
|
|
|
44
67
|
- `XUIProvider` — Root context provider; accepts `initialMode` (see theme modes above)
|
|
45
68
|
- `useDesignSystem` — Hook returning `{ theme, mode, setMode }`; falls back to dark theme if no provider
|
|
69
|
+
- `useResolvedTheme` — Hook returning resolved theme with per-component overrides applied; same return shape as `useDesignSystem`
|
|
70
|
+
- `ThemeOverrideProps` — Type: `{ themeMode?: ThemeMode; themeProductContext?: ProductContext }`
|
|
46
71
|
- `themeConfig` — Function returning the full theme object for a given `ThemeMode`
|
|
47
72
|
- `useId` — Stable unique ID hook; polyfills `React.useId` for React < 18
|
|
48
73
|
- `ModalIdContext` — Context holding the current modal's ID for portal-based components
|
|
49
74
|
- `useModalId` — Hook returning the current modal ID, or `null` if outside a modal
|
|
50
|
-
- `ThemeMode` — Type: `"dark"` | `"light"` | `"
|
|
75
|
+
- `ThemeMode` — Type: `"dark"` | `"light"` | `"ltg-dark"`
|
|
51
76
|
- `ThemeColors` — Type of the colour token object
|
|
52
77
|
- `colors` — Raw colour tokens for all themes
|
|
53
78
|
- `spacing` — Spacing scale (`xs`, `s`, `m`, `l`, `xl`)
|
|
54
79
|
- `radius` — Border-radius tokens (button, card, input, tag, avatar variants)
|
|
55
80
|
- `shadow` — Shadow tokens
|
|
56
81
|
- `fonts` — Font-family definitions
|
|
82
|
+
- `useResolvedTheme` — Hook that merges per-component `themeMode`/`themeProductContext` overrides with global context; returns same shape as `useDesignSystem`
|
|
83
|
+
- `ThemeOverrideProps` — Interface adding optional `themeMode` and `themeProductContext` to component props
|
|
57
84
|
- `isWeb` / `isNative` / `isIOS` / `isAndroid` — Platform detection booleans
|
|
85
|
+
|
|
86
|
+
## Per-Component Theme Override
|
|
87
|
+
|
|
88
|
+
Every component accepts optional `themeMode` and `themeProductContext` props to override the global theme on a per-instance basis, without nesting additional providers.
|
|
89
|
+
|
|
90
|
+
`useResolvedTheme` is the hook that powers this. It accepts an optional overrides object and returns the same `{ theme, mode, productContext }` shape as `useDesignSystem`:
|
|
91
|
+
|
|
92
|
+
```tsx
|
|
93
|
+
import { useResolvedTheme, ThemeOverrideProps } from '@xsolla/xui-core';
|
|
94
|
+
import { Box, Text } from '@xsolla/xui-primitives';
|
|
95
|
+
|
|
96
|
+
type CardProps = ThemeOverrideProps & { title: string };
|
|
97
|
+
|
|
98
|
+
export const Card = ({ title, themeMode, themeProductContext }: CardProps) => {
|
|
99
|
+
const { theme } = useResolvedTheme({ themeMode, themeProductContext });
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<Box backgroundColor={theme.colors.surface.primary}>
|
|
103
|
+
<Text color={theme.colors.content.primary}>{title}</Text>
|
|
104
|
+
</Box>
|
|
105
|
+
);
|
|
106
|
+
};
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
```tsx
|
|
110
|
+
// Consumer usage
|
|
111
|
+
<XUIProvider initialMode="dark">
|
|
112
|
+
<Card title="Dark card" />
|
|
113
|
+
<Card title="Light card" themeMode="light" />
|
|
114
|
+
<Card title="Paystation card" themeMode="light" themeProductContext="paystation" />
|
|
115
|
+
</XUIProvider>
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
When no overrides are passed, `useResolvedTheme` returns the global theme object by reference — zero overhead compared to `useDesignSystem`.
|