@base-framework/atoms 1.0.67 → 1.0.68

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.
Files changed (3) hide show
  1. package/README.md +115 -0
  2. package/copilot.md +20 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -367,6 +367,121 @@ UseParent((parent) =>
367
367
  })
368
368
  ```
369
369
 
370
+ ### Responsive Breakpoint Atoms
371
+
372
+ The responsive breakpoint atoms provide Tailwind CSS-like mobile-first responsive rendering. These atoms conditionally render content based on the current window size, following the mobile-first approach where each breakpoint renders when the screen size matches OR is larger.
373
+
374
+ #### Available Breakpoint Atoms
375
+
376
+ - `OnXs` - 0px+ (always renders, useful for mobile-only content)
377
+ - `OnSm` - 640px+ (small devices and larger)
378
+ - `OnMd` - 768px+ (medium devices and larger)
379
+ - `OnLg` - 1024px+ (large devices and larger)
380
+ - `OnXl` - 1280px+ (extra large devices and larger)
381
+ - `On2Xl` - 1536px+ (2x extra large devices and larger)
382
+
383
+ #### Usage Examples
384
+
385
+ ```javascript
386
+ // Mobile-first navigation - show different nav styles for different screen sizes
387
+ Div({ class: "navigation" }, [
388
+ // Mobile navigation (always shows on xs, hidden on sm+)
389
+ OnXs(() =>
390
+ Div({ class: "mobile-nav" }, [
391
+ Button({ class: "hamburger" }, '☰'),
392
+ Div({ class: "mobile-menu hidden" }, [
393
+ A({ href: "/home" }, 'Home'),
394
+ A({ href: "/about" }, 'About')
395
+ ])
396
+ ])
397
+ ),
398
+
399
+ // Tablet and desktop navigation (shows on md+)
400
+ OnMd(() =>
401
+ Nav({ class: "desktop-nav" }, [
402
+ Ul({ class: "flex space-x-4" }, [
403
+ Li(A({ href: "/home" }, 'Home')),
404
+ Li(A({ href: "/about" }, 'About')),
405
+ Li(A({ href: "/contact" }, 'Contact'))
406
+ ])
407
+ ])
408
+ )
409
+ ])
410
+
411
+ // Responsive grid layouts
412
+ Div({ class: "content-area" }, [
413
+ // Mobile layout (1 column)
414
+ OnSm(() =>
415
+ Div({ class: "grid grid-cols-1 gap-4" }, [
416
+ Card({ title: "Mobile Card 1" }),
417
+ Card({ title: "Mobile Card 2" })
418
+ ])
419
+ ),
420
+
421
+ // Desktop layout (3 columns)
422
+ OnLg(() =>
423
+ Div({ class: "grid grid-cols-3 gap-6" }, [
424
+ Card({ title: "Desktop Card 1" }),
425
+ Card({ title: "Desktop Card 2" }),
426
+ Card({ title: "Desktop Card 3" })
427
+ ])
428
+ )
429
+ ])
430
+
431
+ // Access current window width in callback
432
+ OnXl((width, element, parent) => {
433
+ return Div({ class: "analytics-panel" }, [
434
+ H2('Large Screen Analytics'),
435
+ P(`Screen width: ${width}px`),
436
+ Chart({ width: width - 100 })
437
+ ]);
438
+ })
439
+
440
+ // Conditional content based on screen size
441
+ Div({ class: "hero-section" }, [
442
+ H1('Welcome'),
443
+
444
+ // Show detailed hero content only on larger screens
445
+ OnLg(() =>
446
+ Div({ class: "hero-details" }, [
447
+ P('Detailed description with more information...'),
448
+ Button({ class: "cta-large" }, 'Get Started Today')
449
+ ])
450
+ ),
451
+
452
+ // Show simplified content on smaller screens
453
+ OnSm(() =>
454
+ Button({ class: "cta-mobile" }, 'Start')
455
+ )
456
+ ])
457
+ ```
458
+
459
+ #### How Responsive Atoms Work
460
+
461
+ The responsive atoms use a global Data object that tracks the current window size and breakpoint. When the window is resized:
462
+
463
+ 1. The window width is measured
464
+ 2. The appropriate breakpoint name is determined (xs, sm, md, lg, xl, 2xl)
465
+ 3. The global `sizeData.size` property is updated
466
+ 4. All responsive atoms automatically re-evaluate and show/hide content accordingly
467
+
468
+ This system provides:
469
+ - **Efficient Performance**: Single global resize listener for all responsive atoms
470
+ - **Mobile-First**: Each breakpoint shows on matching size AND larger (Tailwind approach)
471
+ - **Automatic Cleanup**: No memory leaks, listeners are properly managed
472
+ - **SSR Safe**: Works in server-side rendering environments
473
+
474
+ #### Breakpoint Reference
475
+
476
+ | Breakpoint | Min Width | CSS Equivalent | Use Case |
477
+ |------------|-----------|----------------|----------|
478
+ | OnXs | 0px | (always) | Mobile phones |
479
+ | OnSm | 640px | @media (min-width: 640px) | Large phones, small tablets |
480
+ | OnMd | 768px | @media (min-width: 768px) | Tablets |
481
+ | OnLg | 1024px | @media (min-width: 1024px) | Laptops, desktops |
482
+ | OnXl | 1280px | @media (min-width: 1280px) | Large desktops |
483
+ | On2Xl | 1536px | @media (min-width: 1536px) | Extra large screens |
484
+
370
485
  ## Contributing
371
486
 
372
487
  Contributions to Base Framework are welcome. Follow these steps to contribute:
package/copilot.md CHANGED
@@ -36,9 +36,19 @@ const SecondaryButton = Atom((props, children) => Button({
36
36
  Located in `/src/on/` and `/src/use/` directories:
37
37
 
38
38
  - **On Atoms**: Conditional rendering based on data binding (`On`, `OnState`, `OnRoute`)
39
+ - **Responsive Atoms**: Mobile-first breakpoint rendering (`OnXs`, `OnSm`, `OnMd`, `OnLg`, `OnXl`, `On2Xl`)
39
40
  - **UseParent**: Provides access to parent component context
40
41
  - Use **comment placeholders** to maintain DOM position during dynamic updates
41
42
 
43
+ #### Responsive Breakpoint System
44
+ The responsive atoms (`OnXs`, `OnSm`, `OnMd`, `OnLg`, `OnXl`, `On2Xl`) use a Data-based size tracking system:
45
+
46
+ - Global `sizeData` object tracks current breakpoint and window width
47
+ - Single resize listener updates all responsive atoms efficiently
48
+ - Mobile-first approach: each breakpoint renders on matching size AND larger
49
+ - Tailwind CSS compatible breakpoints (640px, 768px, 1024px, 1280px, 1536px)
50
+ - Located in `/src/on/on-size.js` with re-exports in `/src/on/on.js`
51
+
42
52
  ## Development Workflows
43
53
 
44
54
  ### Build Process
@@ -50,6 +60,7 @@ npm run prepublishOnly # Pre-publish build step
50
60
  ### File Structure
51
61
  - `src/atoms.js`: Main export file with all HTML element atoms
52
62
  - `src/on/on.js`: Dynamic conditional rendering atoms
63
+ - `src/on/on-size.js`: Responsive breakpoint atoms and size tracking system
53
64
  - `src/use/use.js`: Parent component access utilities
54
65
  - `src/comment.js`: Comment placeholder utility
55
66
 
@@ -90,14 +101,22 @@ Atoms support multiple call patterns:
90
101
  - Handle previous element cleanup in `updateLayout` functions
91
102
  - Support data binding to component data, context, or state
92
103
 
104
+ ### Responsive Breakpoint Implementation
105
+ - Responsive atoms use Data object for efficient size tracking
106
+ - Single window resize listener manages all breakpoint updates
107
+ - Mobile-first rendering: each breakpoint shows on current size AND larger
108
+ - Automatic cleanup prevents memory leaks when components unmount
109
+ - Server-side rendering safe with window existence checks
110
+
93
111
  ### Base Framework Integration
94
112
  - Always import `Atom` from `@base-framework/base`
95
113
  - Use `Builder.build()` and `Builder.removeNode()` for DOM manipulation
96
114
  - Leverage `dataBinder` for reactive data connections
115
+ - Use `Data` class for global state management (e.g., responsive size tracking)
97
116
 
98
117
  ### TypeScript Support
99
118
  - Enable `allowJs: true` and `checkJs: true` in tsconfig.json
100
119
  - Generate declarations with `emitDeclarationOnly: true`
101
120
  - Map Base Framework types in `paths` configuration
102
121
 
103
- When working with this codebase, focus on maintaining the established patterns for atom creation, JSDoc documentation, and the flexible argument handling that allows atoms to work seamlessly within the Base Framework ecosystem.
122
+ When working with this codebase, focus on maintaining the established patterns for atom creation, JSDoc documentation, and the flexible argument handling that allows atoms to work seamlessly within the Base Framework ecosystem. The responsive breakpoint atoms demonstrate how to integrate with the Base Framework's Data system for efficient global state management.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base-framework/atoms",
3
- "version": "1.0.67",
3
+ "version": "1.0.68",
4
4
  "description": "This will add default atoms to the base framework.",
5
5
  "main": "./dist/atoms.js",
6
6
  "scripts": {