this.gui 0.0.5 → 0.0.6

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,83 +1,37 @@
1
- # This.GUI
1
+ <img src="https://suign.github.io/assets/imgs/this_GUI.svg" alt="Cleaker Me" width="377" height="377" align="right">
2
2
 
3
- `this.gui` is a comprehensive UI toolkit for web development, providing both pre-styled components and customizable themes for building responsive and modern user interfaces for [all.this](neurons.me/this).
4
-
5
- ## Installation
6
-
7
- Install `this.gui` via npm:
3
+ # THIS.GUI
8
4
 
5
+ Install `this.gui` via **npm**:
9
6
  ```shell
10
7
  npm install this.gui
11
8
  ```
9
+ The goal is to automate the UI generation process so users only pass data or configurations, and **this.GUI** handles the rest.
12
10
 
13
- this.gui serve a dual purpose: one as a utility provider for GUI-related functionalities across your technologies and another as a data provider for neural networks. Let's break down how this.gui could serve these two roles:
14
-
15
- GUI Provider (Utility Role): As a utility, this.gui can offer a consistent set of GUI components or services that other parts of your technology stack can use. This can include anything from standard UI elements to complex interaction patterns. By centralizing your GUI logic and components, you ensure consistency and reusability across your projects, which aligns well with it being categorized under utilities.
16
-
17
- Data Provider for Neural Networks (Data Role): The more intriguing role of this.gui involves transforming GUI interactions or states into data that can be fed into neural networks. This can be achieved in several ways, depending on what aspects of the GUI you wish to analyze or learn from:
18
-
19
- Interaction Data: Capturing user interactions with the GUI (clicks, navigation patterns, usage sequences, etc.) can provide valuable data for understanding user behavior or improving user experience.
11
+ 1. React is still required in the user’s project because the UI components provided are React components that need to be rendered by React.
20
12
 
21
- State Data: The state of the GUI at various points in time can offer insights into how users reach certain states, which can be used to optimize workflows or detect common issues.
13
+ The Key Value of this.gui:
22
14
 
23
- Visual Data: If the neural network is designed to work with visual data, screenshots or GUI element properties can be transformed into a format suitable for neural network input. This can be used for tasks like automated GUI testing, layout analysis, or even generating GUI designs.
15
+ • **Simplifies UI creation:** Users only pass configurations or data; they don’t need to deal with the intricacies of React.
16
+ • **Dynamic generation:** The components adapt and render based on the input you give them.
17
+ **• Automation:** You handle all the complexity of component creation, leaving users with a simplified interface to generate UIs.
24
18
 
25
- To facilitate these dual roles, your this.gui package might include different modules or subcomponents dedicated to each function. For instance, one module could focus on providing utility functions and components, while another could handle data extraction and transformation for neural network inputs.
26
19
 
27
- ## Usage
28
- Include `this.gui` styles and scripts in your project to utilize the library.
29
-
30
- ### Including Styles
31
- Link the `this.gui.css` in your HTML or import it in your JavaScript entry file:
32
-
33
- In HTML:
34
- ```html
35
- <link rel="stylesheet" href="/node_modules/this.gui/dist/this.gui.css">
36
- ```
37
-
38
- In JavaScript:
39
- ```javascript
40
- import 'this.gui/dist/this.gui.css';
41
- ```
42
20
 
43
- ### Including Scripts
44
- Reference the `this.gui.js` in your HTML or import it if you're using a module bundler:
45
-
46
- In HTML:
47
- ```html
48
- <script src="/node_modules/this.gui/dist/this.gui.js"></script>
49
- ```
50
-
51
- In JavaScript:
52
- ```javascript
53
- import 'this.gui';
54
- ```
55
-
56
- ## Themes
57
- `this.gui` offers light and dark themes that can be toggled using the `data-theme` attribute:
58
- ```html
59
- <body data-theme="dark">
60
- <!-- Content styled with the dark theme -->
61
- </body>
62
- ```
63
-
64
- ## Components
65
- To use `this.gui` components, add the respective classes to your HTML elements:
66
-
67
- ```html
68
- <button class="this-gui-button">Click Me</button>
69
- <div class="this-gui-card">
70
- <h3 class="this-gui-card-title">Card Title</h3>
71
- <p class="this-gui-card-content">Card content...</p>
72
- </div>
73
- ```
21
+ # About All.This
22
+ ###### Modular Data Structures
23
+ **[this.me](https://suign.github.io/this.me) - [this.audio](https://suign.github.io/this.audio) - [this.text](https://suign.github.io/this.text) - [this.wallet](https://suign.github.io/this.wallet) - [this.img](https://suign.github.io/this.img) - [this.pixel](https://suign.github.io/Pixels) - [be.this](https://suign.github.io/be.this) - [this.DOM](https://suign.github.io/this.DOM) - [this.env](https://suign.github.io/this.env/) - [this.GUI](https://suign.github.io/this.GUI) - [this.be](https://suign.github.io/this.be) - [this.video](https://suign.github.io/this.video) - [this.atom](https://suign.github.io/this.atom) - [this.dictionaries](https://suign.github.io/this.dictionaries/)**
74
24
 
75
- Refer to the official [documentation](https://suign.github.io/GUI) for detailed usage instructions and component references.
25
+ These classes encapsulate the functionalities to **domain-specific data.**
76
26
 
77
- ## Contribution
27
+ ## Neurons.me
28
+ ### License & Policies
29
+ - **License**: MIT License (see LICENSE for details).
78
30
 
79
- Contributions are welcome! To contribute to `this.gui`, please visit our [GitHub repository](https://github.com/suiGn/GUI).
31
+ - **Privacy Policy**: Respects user privacy; no collection/storage of personal data.
80
32
 
81
- ## License
33
+ - **Terms of Usage**: Use responsibly. No guarantees/warranties provided.
34
+ [Terms](https://www.neurons.me/terms-of-use) | [Privacy](https://www.neurons.me/privacy-policy)
35
+ [neurons.me](https://neurons.me)
82
36
 
83
- `this.gui` is available under the MIT license. See the LICENSE file for more info.
37
+ <img src="https://suign.github.io/assets/imgs/neurons_me_logo.png" alt="neurons.me logo" width="89">
package/dist/Styles.md ADDED
@@ -0,0 +1,446 @@
1
+ **Implementing Dynamic Styling with Separate CSS Files Using CSS Variables**
2
+
3
+ ---
4
+
5
+ Hello!
6
+
7
+ I understand that you prefer to keep your styles in separate `.css` files to maintain a clear separation between styles and component logic. This approach can indeed make it easier to update styles without touching the component code, and it's a common practice in larger projects.
8
+
9
+ To achieve dynamic styling with separate CSS files, we can use **CSS Custom Properties** (also known as **CSS Variables**). This allows us to define default styles in our CSS files and override them when necessary via inline styles or class names.
10
+
11
+ Let me guide you through how to implement this setup.
12
+
13
+ ---
14
+
15
+ ### **Overview**
16
+
17
+ - **CSS Custom Properties**: Define variables in your CSS files that can be overridden.
18
+ - **Component Structure**: Use class names to apply styles from CSS files.
19
+ - **Dynamic Overrides**: Pass style overrides as props to your components, which set CSS variables inline.
20
+
21
+ ---
22
+
23
+ ### **1. Defining Default Styles with CSS Variables**
24
+
25
+ **ExampleComponent.css**
26
+
27
+ ```css
28
+ /* src/components/ExampleComponent.css */
29
+
30
+ /* Define default CSS variables at the root level */
31
+ :root {
32
+ --container-background-color: #f9f9f9;
33
+ --container-padding: 16px;
34
+ --text-color: #333;
35
+ --text-font-family: 'Roboto', sans-serif;
36
+ }
37
+
38
+ /* Component styles using CSS variables */
39
+ .example-component {
40
+ background-color: var(--container-background-color);
41
+ padding: var(--container-padding);
42
+ }
43
+
44
+ .example-component__text {
45
+ color: var(--text-color);
46
+ font-family: var(--text-font-family);
47
+ }
48
+ ```
49
+
50
+ **Explanation:**
51
+
52
+ - **CSS Variables**: We define variables like `--container-background-color` and `--text-color` with default values.
53
+ - **Using Variables**: In the `.example-component` and `.example-component__text` classes, we use the `var(--variable-name)` syntax to apply these variables.
54
+
55
+ ---
56
+
57
+ ### **2. Creating the Component to Use CSS Variables**
58
+
59
+ **ExampleComponent.jsx**
60
+
61
+ ```jsx
62
+ // src/components/ExampleComponent.jsx
63
+
64
+ import React from 'react';
65
+ import './ExampleComponent.css';
66
+
67
+ const ExampleComponent = ({ text, styleOverrides = {} }) => {
68
+ // Inline style object to override CSS variables
69
+ const style = {
70
+ '--container-background-color': styleOverrides.backgroundColor,
71
+ '--container-padding': styleOverrides.padding,
72
+ '--text-color': styleOverrides.color,
73
+ '--text-font-family': styleOverrides.fontFamily,
74
+ };
75
+
76
+ return (
77
+ <div className="example-component" style={style}>
78
+ <p className="example-component__text">{text}</p>
79
+ </div>
80
+ );
81
+ };
82
+
83
+ export default ExampleComponent;
84
+ ```
85
+
86
+ **Explanation:**
87
+
88
+ - **Import CSS File**: We import the CSS file to apply the styles.
89
+ - **Style Overrides**: We accept a `styleOverrides` prop, which is an object containing any style overrides.
90
+ - **Inline Styles**: We create an inline `style` object that sets CSS variables, which will override the defaults.
91
+ - **Applying Styles**: The `style` object is applied to the outer `div`, and the CSS variables cascade to the child elements.
92
+
93
+ ---
94
+
95
+ ### **3. Using the Component with or Without Overrides**
96
+
97
+ **Usage Without Overrides (Defaults Applied):**
98
+
99
+ ```jsx
100
+ import React from 'react';
101
+ import ExampleComponent from './components/ExampleComponent';
102
+
103
+ function App() {
104
+ return (
105
+ <div>
106
+ <ExampleComponent text="This uses default styles." />
107
+ </div>
108
+ );
109
+ }
110
+
111
+ export default App;
112
+ ```
113
+
114
+ **Usage With Overrides (Custom Styles Applied):**
115
+
116
+ ```jsx
117
+ import React from 'react';
118
+ import ExampleComponent from './components/ExampleComponent';
119
+
120
+ function App() {
121
+ return (
122
+ <div>
123
+ <ExampleComponent
124
+ text="This uses custom styles."
125
+ styleOverrides={{
126
+ backgroundColor: '#e0f7fa',
127
+ padding: '24px',
128
+ color: '#006064',
129
+ fontFamily: "'Courier New', monospace",
130
+ }}
131
+ />
132
+ </div>
133
+ );
134
+ }
135
+
136
+ export default App;
137
+ ```
138
+
139
+ **Explanation:**
140
+
141
+ - When `styleOverrides` are provided, the component sets the corresponding CSS variables inline, overriding the defaults.
142
+ - The CSS variables set via the `style` prop have higher specificity and will take precedence.
143
+
144
+ ---
145
+
146
+ ### **4. Advantages of This Approach**
147
+
148
+ - **Separation of Concerns**: Styles are kept in CSS files, making them easier to manage and update.
149
+ - **Dynamic Styling**: Components can have their styles customized without modifying the CSS files or component code.
150
+ - **Scoped Styles**: By using class names, styles are scoped to specific components, reducing the risk of style collisions.
151
+ - **Flexibility**: You can easily change the theme or styles of your components by updating the CSS variables.
152
+
153
+ ---
154
+
155
+ ### **5. Detailed Implementation Guide**
156
+
157
+ #### **5.1. Define CSS Variables in a Global CSS File (Optional)**
158
+
159
+ If you have global styles or themes, you can define CSS variables in a global CSS file:
160
+
161
+ ```css
162
+ /* src/global.css */
163
+
164
+ :root {
165
+ --global-font-family: 'Roboto', sans-serif;
166
+ --global-text-color: #333;
167
+ /* Other global variables */
168
+ }
169
+
170
+ body {
171
+ font-family: var(--global-font-family);
172
+ color: var(--global-text-color);
173
+ }
174
+ ```
175
+
176
+ **Import Global Styles:**
177
+
178
+ ```jsx
179
+ // src/index.js or src/main.jsx
180
+
181
+ import './global.css';
182
+ ```
183
+
184
+ #### **5.2. Component CSS File Using Variables**
185
+
186
+ **ExampleComponent.css**
187
+
188
+ ```css
189
+ /* src/components/ExampleComponent.css */
190
+
191
+ /* Default CSS variables specific to ExampleComponent */
192
+ .example-component {
193
+ --container-background-color: #f9f9f9;
194
+ --container-padding: 16px;
195
+ --text-color: #333;
196
+ --text-font-family: 'Roboto', sans-serif;
197
+
198
+ background-color: var(--container-background-color);
199
+ padding: var(--container-padding);
200
+ }
201
+
202
+ .example-component__text {
203
+ color: var(--text-color);
204
+ font-family: var(--text-font-family);
205
+ }
206
+ ```
207
+
208
+ **Explanation:**
209
+
210
+ - **Component-Specific Variables**: We define default CSS variables within the `.example-component` class.
211
+ - **Local Scope**: These variables are scoped to `.example-component` and its descendants.
212
+
213
+ #### **5.3. Component Code with Style Overrides**
214
+
215
+ **ExampleComponent.jsx**
216
+
217
+ ```jsx
218
+ // src/components/ExampleComponent.jsx
219
+
220
+ import React from 'react';
221
+ import './ExampleComponent.css';
222
+
223
+ const ExampleComponent = ({ text, styleOverrides = {} }) => {
224
+ // Style object for CSS variable overrides
225
+ const style = {};
226
+
227
+ // Set CSS variables only if overrides are provided
228
+ if (styleOverrides.backgroundColor) {
229
+ style['--container-background-color'] = styleOverrides.backgroundColor;
230
+ }
231
+ if (styleOverrides.padding) {
232
+ style['--container-padding'] = styleOverrides.padding;
233
+ }
234
+ if (styleOverrides.color) {
235
+ style['--text-color'] = styleOverrides.color;
236
+ }
237
+ if (styleOverrides.fontFamily) {
238
+ style['--text-font-family'] = styleOverrides.fontFamily;
239
+ }
240
+
241
+ return (
242
+ <div className="example-component" style={style}>
243
+ <p className="example-component__text">{text}</p>
244
+ </div>
245
+ );
246
+ };
247
+
248
+ export default ExampleComponent;
249
+ ```
250
+
251
+ **Explanation:**
252
+
253
+ - **Conditional Overrides**: We only set CSS variables in the `style` object if overrides are provided, preventing unnecessary inline styles.
254
+ - **CSS Variable Syntax**: We use the CSS variable names defined in the CSS file.
255
+
256
+ ---
257
+
258
+ ### **6. Applying This Pattern to Other Components**
259
+
260
+ You can use this pattern for other components as well, such as buttons, headers, or cards.
261
+
262
+ **Button.css**
263
+
264
+ ```css
265
+ /* src/components/Button.css */
266
+
267
+ .button {
268
+ --button-background-color: #6200ee;
269
+ --button-text-color: #fff;
270
+ --button-padding: 8px 16px;
271
+ --button-font-family: 'Roboto', sans-serif;
272
+
273
+ background-color: var(--button-background-color);
274
+ color: var(--button-text-color);
275
+ padding: var(--button-padding);
276
+ font-family: var(--button-font-family);
277
+ border: none;
278
+ border-radius: 4px;
279
+ cursor: pointer;
280
+ }
281
+
282
+ .button:hover {
283
+ opacity: 0.9;
284
+ }
285
+ ```
286
+
287
+ **Button.jsx**
288
+
289
+ ```jsx
290
+ // src/components/Button.jsx
291
+
292
+ import React from 'react';
293
+ import './Button.css';
294
+
295
+ const Button = ({ children, onClick, styleOverrides = {} }) => {
296
+ const style = {};
297
+
298
+ if (styleOverrides.backgroundColor) {
299
+ style['--button-background-color'] = styleOverrides.backgroundColor;
300
+ }
301
+ if (styleOverrides.textColor) {
302
+ style['--button-text-color'] = styleOverrides.textColor;
303
+ }
304
+ if (styleOverrides.padding) {
305
+ style['--button-padding'] = styleOverrides.padding;
306
+ }
307
+ if (styleOverrides.fontFamily) {
308
+ style['--button-font-family'] = styleOverrides.fontFamily;
309
+ }
310
+
311
+ return (
312
+ <button className="button" style={style} onClick={onClick}>
313
+ {children}
314
+ </button>
315
+ );
316
+ };
317
+
318
+ export default Button;
319
+ ```
320
+
321
+ ---
322
+
323
+ ### **7. Notes and Best Practices**
324
+
325
+ - **Fallback Values**: Ensure that default values are set in the CSS files so that components render correctly even without overrides.
326
+ - **Specificity**: Inline styles (including CSS variables set via the `style` prop) have higher specificity than styles defined in CSS files, ensuring that overrides work as expected.
327
+ - **Performance**: Overusing inline styles can impact performance, but setting CSS variables via inline styles is generally efficient.
328
+ - **Naming Conventions**: Use consistent naming for CSS variables to maintain readability and ease of maintenance.
329
+ - **Avoiding Conflicts**: Since CSS variables are scoped to the component's class, you reduce the risk of variable name conflicts.
330
+
331
+ ---
332
+
333
+ ### **8. Potential Enhancements**
334
+
335
+ #### **8.1. Using CSS Modules**
336
+
337
+ If you want to ensure that class names are scoped to the component and avoid any potential conflicts, you can use CSS Modules.
338
+
339
+ **Renaming CSS Files**
340
+
341
+ - Rename your CSS files to `.module.css` (e.g., `ExampleComponent.module.css`).
342
+
343
+ **Importing Styles**
344
+
345
+ ```jsx
346
+ // ExampleComponent.jsx
347
+
348
+ import React from 'react';
349
+ import styles from './ExampleComponent.module.css';
350
+
351
+ // Use styles.exampleComponent instead of "example-component"
352
+ ```
353
+
354
+ **Adjusting CSS Variables Scope**
355
+
356
+ - CSS variables defined in CSS Modules are still global, so you need to ensure that variable names are unique or scoped appropriately.
357
+
358
+ #### **8.2. Theming with CSS Variables**
359
+
360
+ You can define a theme using CSS variables in a global CSS file and change the theme by swapping the values of these variables.
361
+
362
+ **theme.css**
363
+
364
+ ```css
365
+ /* src/theme.css */
366
+
367
+ :root {
368
+ --primary-color: #6200ee;
369
+ --secondary-color: #03dac6;
370
+ --background-color: #ffffff;
371
+ --text-color: #000000;
372
+ }
373
+
374
+ /* Light theme */
375
+ body.light-theme {
376
+ --background-color: #ffffff;
377
+ --text-color: #000000;
378
+ }
379
+
380
+ /* Dark theme */
381
+ body.dark-theme {
382
+ --background-color: #121212;
383
+ --text-color: #ffffff;
384
+ }
385
+ ```
386
+
387
+ **Applying Themes**
388
+
389
+ ```jsx
390
+ // src/App.jsx
391
+
392
+ import React, { useState } from 'react';
393
+ import './theme.css';
394
+
395
+ function App() {
396
+ const [theme, setTheme] = useState('light-theme');
397
+
398
+ // Toggle theme
399
+ const toggleTheme = () => {
400
+ setTheme((prevTheme) =>
401
+ prevTheme === 'light-theme' ? 'dark-theme' : 'light-theme'
402
+ );
403
+ };
404
+
405
+ return (
406
+ <div className={theme}>
407
+ <button onClick={toggleTheme}>Toggle Theme</button>
408
+ {/* Rest of your app */}
409
+ </div>
410
+ );
411
+ }
412
+
413
+ export default App;
414
+ ```
415
+
416
+ **Explanation:**
417
+
418
+ - By adding a class to the root element (`<div>`), you can change the values of CSS variables and thus theme your application.
419
+
420
+ ---
421
+
422
+ ### **9. Conclusion**
423
+
424
+ By keeping styles in separate `.css` files and utilizing CSS variables, you can achieve dynamic styling while maintaining a clear separation between your component logic and styles. This approach allows you to:
425
+
426
+ - **Maintain Clean Code**: Component files focus on logic and structure, while styles are kept in CSS files.
427
+ - **Easily Update Styles**: Modify styles without touching component code.
428
+ - **Implement Theming**: Use CSS variables to create themes and switch between them dynamically.
429
+ - **Override Styles**: Provide flexibility to override default styles when needed via props.
430
+
431
+ ---
432
+
433
+ ### **10. Next Steps**
434
+
435
+ - **Apply This Pattern**: Update your existing components to use CSS variables and style overrides as needed.
436
+ - **Define a Theme**: Create a global theme using CSS variables if you haven't already.
437
+ - **Optimize Naming**: Ensure consistent and clear naming conventions for your CSS variables.
438
+ - **Test Thoroughly**: Verify that styles are applied correctly and that overrides work as expected across different components.
439
+
440
+ ---
441
+
442
+ **Feel free to ask if you have any questions or need further assistance implementing this setup! I'm here to help you create a flexible and maintainable styling system for your application.**
443
+
444
+ ---
445
+
446
+ **Happy coding!** 😊