### React Pagination Component Examples
Source: https://context7.com/sima-land/ui-nucleons/llms.txt
Illustrates the use of the Pagination component for navigating through pages of content. It includes basic usage, custom styling, and an example demonstrating URL synchronization with a router. Dependencies include React and @sima-land/ui-nucleons/pagination.
```tsx
import { Pagination } from '@sima-land/ui-nucleons/pagination';
import { useState } from 'react';
function PaginationExample() {
const [currentPage, setCurrentPage] = useState(1);
const [items, setItems] = useState([]);
const totalPages = 25;
const itemsPerPage = 10;
const handlePageChange = async (event, button) => {
event.preventDefault();
const newPage = button.value;
setCurrentPage(newPage);
// Fetch data for the new page
try {
const response = await fetch(`/api/items?page=${newPage}&limit=${itemsPerPage}`);
const data = await response.json();
setItems(data.items);
// Scroll to top
window.scrollTo({ top: 0, behavior: 'smooth' });
} catch (error) {
console.error('Failed to fetch page:', error);
}
};
return (
);
}
// Example with URL sync
function PaginationWithRouter() {
const searchParams = new URLSearchParams(window.location.search);
const initialPage = parseInt(searchParams.get('page') || '1', 10);
const [currentPage, setCurrentPage] = useState(initialPage);
const handlePageChange = (event, button) => {
event.preventDefault();
const newPage = button.value;
setCurrentPage(newPage);
// Update URL
const url = new URL(window.location.href);
url.searchParams.set('page', newPage.toString());
window.history.pushState({}, '', url);
};
return (
);
}
```
--------------------------------
### Install UI-Nucleons via npm or yarn
Source: https://context7.com/sima-land/ui-nucleons/llms.txt
Instructions for installing the UI-Nucleons package using either npm or yarn package managers. This is the first step to integrate the component library into your project.
```bash
npm install @sima-land/ui-nucleons
# or
yarn add @sima-land/ui-nucleons
```
--------------------------------
### React Select Component Example
Source: https://context7.com/sima-land/ui-nucleons/llms.txt
Demonstrates the usage of the Select component for creating dropdown menus. It supports controlled and uncontrolled modes, custom opener and menu rendering, and integrates with other UI elements. Dependencies include React and @sima-land/ui-nucleons/select.
```tsx
import { Select } from '@sima-land/ui-nucleons/select';
import { SelectFieldBlock, SelectMenu, SelectOption } from '@sima-land/ui-nucleons/select';
import { useState } from 'react';
interface Option {
value: string;
label: string;
}
function SelectExample() {
const [value, setValue] = useState('');
const countries: Option[] = [
{ value: 'us', label: 'United States' },
{ value: 'uk', label: 'United Kingdom' },
{ value: 'ca', label: 'Canada' },
{ value: 'au', label: 'Australia' },
{ value: 'de', label: 'Germany' },
];
return (
{/* Controlled select */}
);
}
```
--------------------------------
### React Button Component Examples
Source: https://context7.com/sima-land/ui-nucleons/llms.txt
Demonstrates various use cases for the UI-Nucleons Button component, including primary, secondary, info, link appearances, different sizes, icon integration, loading states, and custom styling via CSS variables.
```tsx
import { Button } from '@sima-land/ui-nucleons/button';
import HomeSVG from '@sima-land/ui-quarks/icons/24x24/Stroked/Home';
import { useState } from 'react';
function ButtonExamples() {
const [loading, setLoading] = useState(false);
const handleSubmit = async () => {
setLoading(true);
try {
await fetch('/api/submit', { method: 'POST' });
} catch (error) {
console.error('Submit failed:', error);
} finally {
setLoading(false);
}
};
return (
{/* Primary button with loading state */}
{/* Button with icon */}
{/* Icon-only button */}
{/* Button as link */}
{/* Custom styled button */}
);
}
```
--------------------------------
### Webpack Configuration for CSS Modules and Assets
Source: https://context7.com/sima-land/ui-nucleons/llms.txt
Example Webpack configuration to handle CSS Modules, SCSS files, and image assets required by UI-Nucleons. Ensures proper module resolution and asset loading for styled components and responsive images.
```javascript
// webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.(css|scss)$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: {
auto: /\.(module|m)\.(css|scss)$/,
localIdentName: '[name]__[local]--[hash:hex:3]',
},
},
},
'sass-loader',
],
},
{
test: /\.(apng|avif|gif|jpg|jpeg|png|webp)$/,
type: 'asset/resource',
},
],
},
};
```
--------------------------------
### Menu Popup with Icon Button
Source: https://context7.com/sima-land/ui-nucleons/llms.txt
Illustrates creating a menu-style popup using the Popup component, triggered by an icon button. This example shows how to render a list of menu items within the popup and handle their actions. Dependencies include '@sima-land/ui-nucleons/popup' and '@sima-land/ui-nucleons/button'.
```tsx
// Menu popup example
function MenuPopup() {
const [anchorElement, setAnchorElement] = useState(null);
const buttonRef = useRef(null);
const menuItems = [
{ id: 1, label: 'Edit', action: () => console.log('Edit') },
{ id: 2, label: 'Duplicate', action: () => console.log('Duplicate') },
{ id: 3, label: 'Delete', action: () => console.log('Delete') },
];
return (
);
}
```
--------------------------------
### Basic Modal Usage with UI Nucleons
Source: https://context7.com/sima-land/ui-nucleons/llms.txt
Demonstrates how to implement a basic modal dialog using the Modal and ModalBody components from '@sima-land/ui-nucleons/modal'. Includes state management for opening/closing the modal and basic content structure. Dependencies: '@sima-land/ui-nucleons/modal', '@sima-land/ui-nucleons/button'.
```tsx
import { Modal, ModalBody } from '@sima-land/ui-nucleons/modal';
import { Button } from '@sima-land/ui-nucleons/button';
import { useState } from 'react';
function ModalExample() {
const [open, setOpen] = useState(false);
return (
<>
setOpen(true)}>
Open Modal
{open && (
setOpen(false)}
overlayProps={{
withScrollDisable: true,
}}
>
Confirm Action
Are you sure you want to proceed with this action?
)}
>
);
}
```
--------------------------------
### Basic Popup with Button Trigger
Source: https://context7.com/sima-land/ui-nucleons/llms.txt
Demonstrates a basic implementation of the Popup component triggered by a button click. It shows how to manage the anchor element and dismiss the popup. Dependencies include '@sima-land/ui-nucleons/popup' and '@sima-land/ui-nucleons/button'.
```tsx
import { Popup } from '@sima-land/ui-nucleons/popup';
import { Button } from '@sima-land/ui-nucleons/button';
import { useState, useRef } from 'react';
function PopupExample() {
const [anchorElement, setAnchorElement] = useState(null);
const buttonRef = useRef(null);
return (
);
}
```
--------------------------------
### Fullscreen Modal with UI Nucleons
Source: https://context7.com/sima-land/ui-nucleons/llms.txt
Illustrates the usage of the Modal component for a fullscreen view using the 'fullscreen' size prop. Shows how to manage content within the fullscreen modal, including header and scrollable body. Dependencies: '@sima-land/ui-nucleons/modal', '@sima-land/ui-nucleons/button'.
```tsx
// Fullscreen modal example
function FullscreenModalExample() {
const [open, setOpen] = useState(false);
return (
<>
setOpen(true)}>
Open Fullscreen
{open && (
setOpen(false)}
style={{
'--modal-overlay-padding': '0',
}}
>
Fullscreen Content
This modal takes up the entire screen
)}
>
);
}
```
--------------------------------
### Basic Carousel with Infinite Scroll
Source: https://context7.com/sima-land/ui-nucleons/llms.txt
Demonstrates a basic carousel implementation with infinite scrolling enabled. It takes an array of products, displays them with custom rendering, and allows navigation through an index. The controls are automatically shown based on content overflow.
```tsx
import { Carousel } from '@sima-land/ui-nucleons/carousel';
import { ArrowButton } from '@sima-land/ui-nucleons/arrow-button';
import { useState } from 'react';
interface Product {
id: number;
name: string;
image: string;
price: number;
}
function CarouselExample() {
const products: Product[] = [
{ id: 1, name: 'Product 1', image: '/img1.jpg', price: 1999 },
{ id: 2, name: 'Product 2', image: '/img2.jpg', price: 2499 },
{ id: 3, name: 'Product 3', image: '/img3.jpg', price: 1799 },
{ id: 4, name: 'Product 4', image: '/img4.jpg', price: 2999 },
{ id: 5, name: 'Product 5', image: '/img5.jpg', price: 1599 },
];
const [currentIndex, setCurrentIndex] = useState(0);
return (
{/* Basic carousel with infinite scroll */}
(
{product.name}
${product.price}
)}
withControls="auto"
draggable="auto"
/>
{/* Carousel with autoplay */}
(
);
}
```
--------------------------------
### Tooltip-Style Popup on Hover
Source: https://context7.com/sima-land/ui-nucleons/llms.txt
Shows how to use the Popup component as a tooltip, appearing when the user hovers over a specific element. The popup is managed using 'onMouseEnter' and 'onMouseLeave' events. Dependencies include '@sima-land/ui-nucleons/popup'.
```tsx
// Tooltip-style popup
function TooltipPopup() {
const [anchorElement, setAnchorElement] = useState(null);
return (
);
}
```
--------------------------------
### Responsive Design with useBreakpoint Hook (React)
Source: https://context7.com/sima-land/ui-nucleons/llms.txt
The useBreakpoint hook allows for conditional rendering and styling based on predefined design system breakpoints. It supports various query formats like 'xs+' or 'm-'. For performance optimization and SSR compatibility, it can be used with the optional BreakpointProvider.
```tsx
import { useBreakpoint, BreakpointProvider } from '@sima-land/ui-nucleons/hooks';
import { useState, useEffect } from 'react';
function ResponsiveComponent() {
// Check if screen is mobile (xs or s)
const isMobile = useBreakpoint('xs+');
// Check if screen is tablet or larger
const isTablet = useBreakpoint('m+');
// Check if screen is desktop
const isDesktop = useBreakpoint('l+');
return (
{isMobile &&
Mobile view (xs or s)
}
{isTablet && !isDesktop &&
Tablet view (m)
}
{isDesktop &&
Desktop view (l or xl)
}
);
}
// Optimized with provider
function App() {
return (
);
}
function ResponsiveLayout() {
const isMobile = useBreakpoint('xs+');
const isDesktop = useBreakpoint('l+');
return (
);
}
// Conditional rendering based on breakpoint
function Navigation() {
const isMobile = useBreakpoint('xs+');
if (isMobile) {
return ;
}
return ;
}
function MobileNav() {
return (
);
}
function DesktopNav() {
return (
);
}
```
--------------------------------
### TypeScript Type Declarations for CSS Modules
Source: https://context7.com/sima-land/ui-nucleons/llms.txt
TypeScript declaration files (.d.ts) for handling CSS module imports, including support for .module.css, .m.css, .module.scss, and .m.scss file extensions. This ensures type safety when importing styles.
```typescript
// src/custom.d.ts
declare module '*.module.css' {
const classes: { [key: string]: string };
export default classes;
}
declare module '*.m.css' {
const classes: { [key: string]: string };
export default classes;
}
declare module '*.module.scss' {
const classes: { [key: string]: string };
export default classes;
}
declare module '*.m.scss' {
const classes: { [key: string]: string };
export default classes;
}
```
--------------------------------
### Type-Safe Slot Distribution with defineSlots Helper (React)
Source: https://context7.com/sima-land/ui-nucleons/llms.txt
The defineSlots helper provides a type-safe way to distribute React children into named slots, simplifying component composition. It automatically detects child elements by their component type, ensuring strong TypeScript typing and flexible structure.
```tsx
import { defineSlots } from '@sima-land/ui-nucleons/helpers';
import { ReactNode } from 'react';
// Define slot components
function CardHeader({ children }: { children: ReactNode }) {
return {children};
}
function CardBody({ children }: { children: ReactNode }) {
return
{children}
;
}
function CardFooter({ children }: { children: ReactNode }) {
return ;
}
// Card component using slots
function Card({ children }: { children: ReactNode }) {
const slots = defineSlots(children, {
header: CardHeader,
body: CardBody,
footer: CardFooter,
});
return (
{slots.header}
{slots.body}
{slots.footer}
);
}
// Usage example
function CardExample() {
return (
Product Details
This is the main content area of the card.
It can contain any React elements.
Add to CartView Details
);
}
// Complex example with optional slots
function Dialog({ children }: { children: ReactNode }) {
const slots = defineSlots(children, {
header: CardHeader,
body: CardBody,
footer: CardFooter,
});
return (
);
}
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.