@rescui/ui-contexts 0.6.1 → 0.6.3-RUI-297-Add-react-compiler-to-the-packages-build-dbbefd7b8.14

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
@@ -1,3 +1,5 @@
1
- UI contexts
1
+ # UI contexts
2
2
 
3
- * [Usage examples of UI contexts](./docs/demo.md)
3
+ ## LLM
4
+
5
+ To get the docs for the LLM, check out [this index](./llm/index.md).
package/llm/index.md ADDED
@@ -0,0 +1,4 @@
1
+ - Utils
2
+ - [Theming](./utils/theming.md)
3
+ - [UI Contexts](./utils/ui-contexts.md)
4
+ - [Animations](./utils/animations.md)
@@ -0,0 +1,114 @@
1
+ # Animations
2
+
3
+ ## Animations
4
+
5
+ ### RescUI animations easing control
6
+
7
+ RescUI components use the `--rs-transition-function` CSS variable to control the easing function of their CSS transitions and animations. The variable is inherited, so it can be set for the whole app, for a section, or directly on a single component.
8
+
9
+ Each component keeps its own fallback value. For example, `Collapse` uses `ease` by default, while some special animations may keep their own timing function.
10
+
11
+ ### Component-level override
12
+
13
+ Set the variable on a component when only this component should use a custom easing function.
14
+
15
+ ```tsx
16
+ import { Collapse } from '@rescui/collapse';
17
+
18
+ const DemoCollapse = ({ className, title }) => (
19
+ <Collapse title={title} className={className}>
20
+ <div style={{ padding: '8px 0 16px' }}>
21
+ The same Collapse component uses a different easing function when
22
+ `--rs-transition-function` is set on it.
23
+ </div>
24
+ </Collapse>
25
+ );
26
+
27
+ render(
28
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
29
+ <DemoCollapse title="Default easing" />
30
+ <DemoCollapse
31
+ title={'Custom "bounce" easing: cubic-bezier(0.34, 2, 0.64, 1)'}
32
+ className="custom-bounce-animation-collapse"
33
+ />
34
+ <DemoCollapse
35
+ title={'Custom "stepped" easing: steps(4, end)'}
36
+ className="custom-stepped-animation-collapse"
37
+ />
38
+ </div>
39
+ );
40
+ ```
41
+
42
+ ```postcss
43
+ .custom-bounce-animation-collapse {
44
+ --rs-transition-function: cubic-bezier(0.34, 2, 0.64, 1);
45
+ }
46
+ .custom-stepped-animation-collapse {
47
+ --rs-transition-function: steps(4, end);
48
+ }
49
+ ```
50
+
51
+ ### Inline override
52
+
53
+ Use inline styles when the easing function is calculated in JavaScript or is part of local component state.
54
+
55
+ ```tsx
56
+ import { Collapse } from '@rescui/collapse';
57
+
58
+ const MyCollapse = () => (
59
+ <Collapse
60
+ title="Custom easing"
61
+ style={{ '--rs-transition-function': 'cubic-bezier(0.2, 0, 0, 1)' }}
62
+ >
63
+ Content
64
+ </Collapse>
65
+ );
66
+
67
+ render(<MyCollapse />);
68
+ ```
69
+
70
+ ### Section-level override
71
+
72
+ Because CSS variables are inherited, setting `--rs-transition-function` on a wrapper changes the easing function for all RescUI components inside it.
73
+
74
+ ```tsx
75
+ import { Collapse } from '@rescui/collapse';
76
+ import { Toggle } from '@rescui/toggle';
77
+ import { useState } from 'react';
78
+
79
+ const AnimatedSection = ({ className }) => {
80
+ const [checked, setChecked] = useState(false);
81
+
82
+ return (
83
+ <div className={className}>
84
+ <Collapse title="Collapse inside a section">Section content</Collapse>
85
+ <div style={{ marginTop: 16 }}>
86
+ <Toggle
87
+ checked={checked}
88
+ onChange={event => setChecked(event.target.checked)}
89
+ >
90
+ Toggle inside the same section
91
+ </Toggle>
92
+ </div>
93
+ </div>
94
+ );
95
+ };
96
+
97
+ render(<AnimatedSection className="custom-animation-section" />);
98
+ ```
99
+
100
+ ```postcss
101
+ .custom-animation-section {
102
+ --rs-transition-function: cubic-bezier(0.34, 2, 0.64, 1);
103
+ }
104
+ ```
105
+
106
+ ### App-level default
107
+
108
+ Set the variable on `:root` to change the default easing function for the whole application.
109
+
110
+ ```postcss
111
+ :root {
112
+ --rs-transition-function: cubic-bezier(0.4, 0, 0.2, 1);
113
+ }
114
+ ```
@@ -0,0 +1,201 @@
1
+ # Theming
2
+
3
+ ## Theming
4
+
5
+ ### RescUI Theming with CSS Variables
6
+
7
+ RescUI components support theming using CSS variables. The primary CSS variable for controlling the theme is `--rs-theme-dark`.
8
+
9
+ #### The `--rs-theme-dark` CSS Variable
10
+
11
+ The `--rs-theme-dark` CSS variable is used to toggle between light and dark themes in RescUI components. It accepts two values:
12
+
13
+ - `0`: Light theme (default)
14
+ - `1`: Dark theme
15
+
16
+ This variable affects the appearance of all RescUI components, including colors, backgrounds, borders, and other visual elements.
17
+
18
+ #### How It Works
19
+
20
+ When you set `--rs-theme-dark` to `1`, components will use their dark theme styles. When set to `0` or not set at all, components will use their light theme styles.
21
+
22
+ Each component in the RescUI library checks for this variable and applies the appropriate styles based on its value. This allows for consistent theming across all components.
23
+
24
+ #### Usage Examples
25
+
26
+ ##### Setting Theme at the Root Level
27
+
28
+ To set the theme for your entire application, add the CSS variable to your root element:
29
+
30
+ ```postcss
31
+ :root {
32
+ --rs-theme-dark: 0; /* Light theme */
33
+ }
34
+ ```
35
+
36
+ For dark theme:
37
+
38
+ ```postcss
39
+ :root {
40
+ --rs-theme-dark: 1; /* Dark theme */
41
+ }
42
+ ```
43
+
44
+ ##### Setting Theme for Specific Sections
45
+
46
+ You can also set the theme for specific sections of your application:
47
+
48
+ ```jsx
49
+ <div style={{ '--rs-theme-dark': 1 }}>
50
+ {/* All RescUI components in this div will use dark theme */}
51
+ <Button>Dark Theme Button</Button>
52
+ <Input placeholder="Dark Theme Input" />
53
+ </div>
54
+ ```
55
+
56
+ ##### Toggling Themes Dynamically
57
+
58
+ You can toggle between themes dynamically using JavaScript:
59
+
60
+ ```tsx
61
+ import { useState } from 'react';
62
+ import { Button } from '@rescui/button';
63
+ import { textCn } from '@rescui/typography';
64
+
65
+ const ThemeToggleExample = () => {
66
+ const [isDarkTheme, setIsDarkTheme] = useState(true);
67
+
68
+ return (
69
+ <div
70
+ style={{
71
+ '--rs-theme-dark': isDarkTheme ? 1 : 0,
72
+ background: isDarkTheme ? '#000' : '#f4f4f4',
73
+ padding: 24
74
+ }}
75
+ >
76
+ <Button mode="rock" onClick={() => setIsDarkTheme(!isDarkTheme)}>
77
+ Toggle Theme
78
+ </Button>
79
+ <p className={textCn('rs-text-2')} style={{ marginTop: 12 }}>
80
+ Current theme: {isDarkTheme ? 'Dark' : 'Light'}
81
+ </p>
82
+ </div>
83
+ );
84
+ };
85
+
86
+ render(<ThemeToggleExample />);
87
+ ```
88
+
89
+ #### The `--rs-theme-flip` CSS Variable
90
+
91
+ In addition to the `--rs-theme-dark` CSS Variable, RescUI components support the `--rs-theme-flip` CSS Variable. It also accepts two values:
92
+
93
+ - `0`: Normal theme (default)
94
+ - `1`: Inverted theme
95
+
96
+ It becomes useful when toggling the theme based on different CSS states of a component — for example, [rock cards](/cards/clickable/#rock-mode).
97
+
98
+ ```postcss attached
99
+ .flip-theme-on-hover {
100
+ --rs-theme-dark: 0; /* light theme by default */
101
+ background: #fff;
102
+ border: 1px solid black;
103
+
104
+ &:hover {
105
+ --rs-theme-flip: 1; /* components inside will be with inverted theme on hover */
106
+ background: #000;
107
+ border-color: white;
108
+ }
109
+ }
110
+ ```
111
+
112
+ ### ThemeProvider
113
+
114
+ While the CSS variable approach is recommended, RescUI also provides a React context-based theming solution through the `ThemeProvider` component:
115
+
116
+ `ThemeProvider` has issues with [server components](https://react.dev/reference/rsc/server-components) and server-side rendering when trying to [apply theme based on user preferences](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme). We recommend using CSS variables approach for theming instead.
117
+
118
+ ```tsx
119
+ import { ThemeProvider, useThemeWithUndefined } from '@rescui/ui-contexts';
120
+ import { Button } from '@rescui/button';
121
+ import { useTextStyles } from '@rescui/typography';
122
+
123
+ const ThemedSection = () => {
124
+ const theme = useThemeWithUndefined();
125
+ const textCn = useTextStyles();
126
+ const isDarkTheme = theme === 'dark';
127
+ return (
128
+ <div
129
+ style={{
130
+ background: isDarkTheme ? '#000' : '#f4f4f4',
131
+ padding: 24
132
+ }}
133
+ >
134
+ <Button>Dark Theme Button</Button>
135
+ <p className={textCn('rs-text-2')} style={{ marginTop: 12 }}>
136
+ Current theme: {isDarkTheme ? 'Dark' : 'Light'}
137
+ </p>
138
+ </div>
139
+ );
140
+ };
141
+
142
+ const App = () => (
143
+ <ThemeProvider theme="dark">
144
+ <ThemedSection />
145
+ </ThemeProvider>
146
+ );
147
+
148
+ render(<App />);
149
+ ```
150
+
151
+ See more in the [UI-contexts](/utils/ui-contexts/) section.
152
+
153
+ ### Best Practices
154
+
155
+ - **Prefer CSS Variables**: Use the `--rs-theme-dark` CSS variable directly when possible, as it provides better performance and flexibility.
156
+
157
+ - **Consistent Theming**: Apply the theme at the highest appropriate level in your component hierarchy to ensure consistent styling.
158
+
159
+ - **Component-Specific Overrides**: You can override the theme for specific components by setting the `--rs-theme-dark` variable on their container elements.
160
+
161
+ - **Media Queries**: You can use media queries to automatically switch between light and dark themes based on user preferences:
162
+
163
+ ```postcss
164
+ :root {
165
+ --rs-theme-dark: 0;
166
+ }
167
+
168
+ @media (prefers-color-scheme: dark) {
169
+ :root {
170
+ --rs-theme-dark: 1;
171
+ }
172
+ }
173
+ ```
174
+
175
+ - **Group Theme-Related Styles**: The `--rs-theme-dark` variable controls the theme only for RescUI components. To apply both RescUI and local styles from a single source, group theme-related styles together. For example, using [Postcss Mixins](https://github.com/postcss/postcss-mixins):
176
+
177
+ ```postcss
178
+ @define-mixin site-theme-light {
179
+ --rs-theme-dark: 0;
180
+ --main-background-color: #fff;
181
+ --secondary-border-color: #d1d1d2;
182
+ }
183
+
184
+ @define-mixin site-theme-dark {
185
+ --rs-theme-dark: 1;
186
+ --main-background-color: #000;
187
+ --secondary-border-color: #474749;
188
+ }
189
+
190
+ .light-section {
191
+ @mixin site-theme-light;
192
+ }
193
+ .dark-section {
194
+ @mixin site-theme-dark;
195
+ }
196
+
197
+ .inner-element {
198
+ background: var(--main-background-color);
199
+ border: 1px solid var(--secondary-border-color);
200
+ }
201
+ ```
@@ -0,0 +1,171 @@
1
+ # UI Contexts
2
+
3
+ UI Contexts allow you to set parameters for entire component trees and subtrees, making it easy to add stylistic variety to your pages without having to manually adjust all the components.
4
+
5
+ ## UI Contexts
6
+
7
+ ### ThemeContext
8
+
9
+ `ThemeProvider` has issues with [server components](https://react.dev/reference/rsc/server-components) and server-side rendering when trying to [apply theme based on user preferences](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme). We recommend using [CSS variables](/utils/theming/) approach for theming instead.
10
+
11
+ Provides the default theme to descendant components. Can be overridden by component's props.
12
+
13
+ Also used for some hooks like `useGlowHover`, `useTextStyles` and so on.
14
+
15
+ #### Usage
16
+
17
+ ```tsx
18
+ import { useState } from 'react';
19
+ import { ThemeProvider, useThemeWithUndefined } from '@rescui/ui-contexts';
20
+ import { useTextStyles } from '@rescui/typography';
21
+ import { Switcher } from '@rescui/switcher';
22
+
23
+ const MyCustomSectionComponent = ({ children }) => {
24
+ const theme = useThemeWithUndefined();
25
+
26
+ return (
27
+ <div
28
+ style={{
29
+ background: theme === 'dark' ? '#000' : '#F4F4F4',
30
+ padding: '20px'
31
+ }}
32
+ >
33
+ {children}
34
+ </div>
35
+ );
36
+ };
37
+
38
+ const MyCustomComponentThatUsingTheme = () => {
39
+ const textCn = useTextStyles();
40
+
41
+ return (
42
+ <div className={textCn('rs-text-2', { hardness: 'hard' })}>
43
+ I'm text with class from textCn
44
+ </div>
45
+ );
46
+ };
47
+
48
+ const Demo = () => {
49
+ const [theme, setTheme] = useState('light');
50
+
51
+ return (
52
+ <ThemeProvider theme={theme}>
53
+ <MyCustomSectionComponent>
54
+ <Switcher
55
+ size="xs"
56
+ options={[
57
+ { label: 'Light', value: 'light' },
58
+ { label: 'Dark', value: 'dark' }
59
+ ]}
60
+ value={theme}
61
+ onChange={setTheme}
62
+ />
63
+ <div style={{ marginTop: '24px' }}>
64
+ <MyCustomComponentThatUsingTheme />
65
+ </div>
66
+ </MyCustomSectionComponent>
67
+ </ThemeProvider>
68
+ );
69
+ };
70
+
71
+ render(<Demo />);
72
+ ```
73
+
74
+ #### Props
75
+
76
+ | Name | Type | Default | Description |
77
+ | --- | --- | --- | --- |
78
+ | `theme` | "light" \| "dark" | | |
79
+ | `ignoreThemeValueForCSSApi` | boolean | `false` | |
80
+
81
+ #### Always dark or light themed components
82
+
83
+ ##### The problem
84
+
85
+ Sometimes you need to have specific component (custom card, section, block...) to always be in a specific theme - for example, always dark section.
86
+
87
+ And if using `ThemeProvider` would help children components, it won't work for top-level hooks:
88
+
89
+ ```tsx
90
+ import { ThemeProvider } from '@rescui/ui-contexts';
91
+ import { Button } from '@rescui/button';
92
+ import { useTextStyles } from '@rescui/typography';
93
+
94
+ /* export */ const DarkSection = () => {
95
+ // by default light typography
96
+ const textCn = useTextStyles();
97
+
98
+ return (
99
+ <ThemeProvider theme="dark">
100
+ <div style={{ background: '#000', padding: '20px' }}>
101
+ <p className={textCn('rs-text-2', { hardness: 'hard' })}>
102
+ You won't see it, because it's a light typography text
103
+ </p>
104
+ <Button>I'm in the dark theme</Button>
105
+ </div>
106
+ </ThemeProvider>
107
+ );
108
+ };
109
+
110
+ render(<DarkSection />);
111
+ ```
112
+
113
+ ##### Manual solution
114
+
115
+ One of the solutions for that problem is to use the `createTextCn` helper with manually specified theme instead of the hook:
116
+
117
+ ```tsx
118
+ import { ThemeProvider } from '@rescui/ui-contexts';
119
+ import { Button } from '@rescui/button';
120
+ import { createTextCn } from '@rescui/typography';
121
+
122
+ /* export */ const DarkSection = () => {
123
+ // now its dark typography
124
+ const textCn = createTextCn('dark');
125
+
126
+ return (
127
+ <ThemeProvider theme="dark">
128
+ <div style={{ background: '#000', padding: '20px' }}>
129
+ <p className={textCn('rs-text-2', { hardness: 'hard' })}>
130
+ I'm the dark typography text
131
+ </p>
132
+ <Button>I'm in the dark theme</Button>
133
+ </div>
134
+ </ThemeProvider>
135
+ );
136
+ };
137
+
138
+ render(<DarkSection />);
139
+ ```
140
+
141
+ ##### Automatic solution
142
+
143
+ Another, more preferable solution, is to wrap your base component inside the `ThemeProvider` so all the hooks inside will use it:
144
+
145
+ ```tsx
146
+ import { ThemeProvider } from '@rescui/ui-contexts';
147
+ import { useTextStyles } from '@rescui/typography';
148
+
149
+ const DarkSectionInner = () => {
150
+ // dark typography
151
+ const textCn = useTextStyles();
152
+
153
+ return (
154
+ <div
155
+ className={textCn('rs-text-2', { hardness: 'hard' })}
156
+ style={{ background: '#000', padding: '20px' }}
157
+ >
158
+ The whole component and its children are in the dark theme
159
+ </div>
160
+ );
161
+ };
162
+
163
+ // use this component for export instead of the "Inner" one
164
+ /* export */ const DarkSection = () => (
165
+ <ThemeProvider theme="dark">
166
+ <DarkSectionInner />
167
+ </ThemeProvider>
168
+ );
169
+
170
+ render(<DarkSection />);
171
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rescui/ui-contexts",
3
- "version": "0.6.1",
3
+ "version": "0.6.3-RUI-297-Add-react-compiler-to-the-packages-build-dbbefd7b8.14+dbbefd7b8",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "author": "JetBrains",
@@ -9,6 +9,7 @@
9
9
  "src:main": "src/index.ts",
10
10
  "files": [
11
11
  "lib",
12
+ "llm",
12
13
  "typings",
13
14
  "LICENSE.txt"
14
15
  ],
@@ -20,14 +21,14 @@
20
21
  },
21
22
  "peerDependencies": {
22
23
  "prop-types": "^15",
23
- "react": ">=16.8.0 <20"
24
+ "react": ">=17.0.0 <20"
24
25
  },
25
26
  "devDependencies": {
26
- "@rescui/scripts": "^0.5.2"
27
+ "@rescui/scripts": "0.5.2"
27
28
  },
28
29
  "scripts": {
29
30
  "build": "rescui-scripts build"
30
31
  },
31
32
  "nx": {},
32
- "gitHead": "a04f6790abce8e72834eedce3512ee83513c5e78"
33
+ "gitHead": "dbbefd7b8e24da18262edf3baffa35039ae01af3"
33
34
  }