### Stack Component Installation
Source: https://github.com/nkzw-tech/stack/blob/main/README.md
Shows the command to install the `@nkzw/stack` package using npm. This is the standard method for adding the library to a project.
```bash
npm install @nkzw/stack
```
--------------------------------
### Stack Card Layout Example
Source: https://github.com/nkzw-tech/stack/blob/main/README.md
An example demonstrating the use of Stack for creating a card layout with vertical arrangement, gaps, padding, borders, and nested content.
```tsx
Card Title
Card content goes here
```
--------------------------------
### React Native Stack Component Examples
Source: https://context7.com/nkzw-tech/stack/llms.txt
Illustrates the usage of the Stack component for creating vertical lists, profile card layouts, and styled components with NativeWind. It requires React Native and optionally NativeWind for styled examples. The component facilitates flexible layout management with properties like 'vertical', 'gap', 'padding', and 'alignCenter'.
```tsx
import Stack from '@nkzw/stack';
import { Text, Image, TouchableOpacity } from 'react-native';
// Basic vertical list
const UserList = () => (
AliceBobCharlie
);
// Profile card layout
const ProfileCard = ({ user }) => (
{user.name}{user.email}MessageFollow
);
// NativeWind support (when installed)
const StyledCard = () => (
TitleDescription
);
```
--------------------------------
### Stack Content Alignment
Source: https://github.com/nkzw-tech/stack/blob/main/README.md
Align the content within the stack container. Supports 'center' and 'start'.
```tsx
Content
Content
```
--------------------------------
### Stack Component Usage: Vertical and Horizontal Layouts with Gap
Source: https://github.com/nkzw-tech/stack/blob/main/README.md
Provides examples of using the Stack component for both horizontal (default) and vertical layouts. It demonstrates how to apply a gap between child elements using the `gap` prop, including using a boolean `gap` for default spacing.
```tsx
import Stack from '@nkzw/stack';
// Horizontal layout (default).
Apple
Banana
Kiwi
// Vertical layout.
Apple
Banana
Kiwi
// Using boolean gap (uses default gap of 8px).
Apple
Banana
```
--------------------------------
### Stack Alignment (Cross Axis)
Source: https://github.com/nkzw-tech/stack/blob/main/README.md
Align items along the cross axis. Options include centering, aligning to the start, end, or baseline.
```tsx
// Center align items.
Centered
// Align to start.
At start
// Align to end.
At end
// Baseline alignment.
Small
Large
```
--------------------------------
### VStack Component: Vertical Layout Shorthand (React)
Source: https://context7.com/nkzw-tech/stack/llms.txt
Illustrates the use of the VStack component, a convenient shorthand for creating vertical stacks. This example demonstrates building a form with nested VStacks to manage layout and spacing for labels, inputs, and a submit button.
```tsx
import { VStack } from '@nkzw/stack';
// VStack is equivalent to
const Form = () => (
);
```
--------------------------------
### Stack Self Alignment
Source: https://github.com/nkzw-tech/stack/blob/main/README.md
Control the alignment of individual Stack children along the cross axis. Supports 'center', 'start', 'end', and 'stretch'.
```tsx
// Align self to center.
Self-centered
// Other self alignment options.
Self at start
Self at end
Self stretched
```
--------------------------------
### Stack Component: Basic and Complex Layouts (React)
Source: https://context7.com/nkzw-tech/stack/llms.txt
Demonstrates the fundamental usage of the Stack component for creating horizontal and vertical layouts with configurable gaps and alignment. It also showcases a more complex example with padding and nested Stack components for structuring UI elements.
```tsx
import Stack from '@nkzw/stack';
// Horizontal layout with 16px gap and centered items
const HorizontalList = () => (
A
B
C
);
// Vertical layout with boolean gap (uses default 8px)
const VerticalList = () => (
Apple
Banana
Kiwi
);
// Complex layout with padding and custom alignment
const CardLayout = () => (
Product Card
High quality product description
);
```
--------------------------------
### Use `asStack` to Convert Components
Source: https://github.com/nkzw-tech/stack/blob/main/README.md
The `asStack` utility allows any component to be converted into a Stack component, enabling seamless use of all Stack props.
```tsx
import { asStack } from '@nkzw/stack';
const Link = asStack(({ to, children, ...props }) => (
{children}
));
Home
;
```
--------------------------------
### Basic Stack Usage with Shorthand Props
Source: https://github.com/nkzw-tech/stack/blob/main/README.md
Demonstrates the basic usage of the Stack component with shorthand props like `vertical`, `gap`, and `center`. It shows how to render children, including platform-specific components like `div` for web and `View` for React Native.
```tsx
import Stack from '@nkzw/stack';
const Component = () => (
Apple
{/* Works on the web */}
Banana {/* Works in React Native */}
Kiwi
);
```
--------------------------------
### Stack Layout Options
Source: https://github.com/nkzw-tech/stack/blob/main/README.md
Configure layout direction, wrapping, and reversing. Supports inline flex, reverse, vertical reverse, and wrapping.
```tsx
// Inline flex.
Inline flex
// Reverse direction.
Apple (appears last)
Banana (appears first)
// Vertical reverse.
Apple (appears at bottom)
Banana (appears at top)
// Wrap (`flex-wrap: nowrap` is the default).
Apple
Banana
Kiwi
```
--------------------------------
### Stack Render as Different Elements
Source: https://github.com/nkzw-tech/stack/blob/main/README.md
Specify the HTML element or custom component that the Stack should render as, using the 'as' prop. This allows for semantic HTML or integrating with other components.
```tsx
Content
Home
About
```
--------------------------------
### Navigation Bar using Stack Component (TSX)
Source: https://github.com/nkzw-tech/stack/blob/main/README.md
Renders a responsive navigation bar using the Stack component. It includes a logo, navigation links, and a sign-in button. This component assumes the availability of a 'Stack' UI primitive.
```tsx
Logo
HomeAboutContact
```
--------------------------------
### VStack Shorthand for Vertical Stacks
Source: https://github.com/nkzw-tech/stack/blob/main/README.md
Introduces the `VStack` component as a shorthand for creating vertical stacks with the `@nkzw/stack` library. It functions identically to ``.
```tsx
import { VStack } from '@nkzw/stack';
Apple
Banana
Kiwi
;
// Same as ``.
```
--------------------------------
### Stack Component with NativeWind and CSS Classes
Source: https://github.com/nkzw-tech/stack/blob/main/README.md
Demonstrates integrating the Stack component with NativeWind, allowing the use of `className` prop for applying Tailwind CSS classes to style the stack and its children.
```tsx
AppleBananaKiwi
```
--------------------------------
### Build Grid Layout with Wrapping using Stack
Source: https://context7.com/nkzw-tech/stack/llms.txt
Demonstrates creating a grid-like layout with wrapping functionality using the Stack component. It's designed for displaying items like products, where each item has consistent styling and layout. The component accepts an array of products as input.
```tsx
import Stack from '@nkzw/stack';
// Grid-like layout with wrapping
const ProductGrid = ({ products }) => (
{products.map(product => (
{product.name}
{product.description}
${product.price}
))}
);
```
--------------------------------
### Create Responsive Header with Stack Component
Source: https://context7.com/nkzw-tech/stack/llms.txt
Implements a responsive navigation header using the Stack component. It arranges elements horizontally with alignment and spacing controls, suitable for website navigation. Dependencies include the @nkzw/stack library.
```tsx
import Stack from '@nkzw/stack';
// Responsive navigation header
const Header = () => (
MyApp
FeaturesPricingAbout
);
```
--------------------------------
### Default Flexbox Styles of Stack Component
Source: https://github.com/nkzw-tech/stack/blob/main/README.md
Illustrates the default CSS styles applied by the Stack component when rendered without any props. This includes `display`, `flexDirection`, `flexWrap`, and `justifyContent`.
```tsx
```
--------------------------------
### Stack Justification (Main Axis)
Source: https://github.com/nkzw-tech/stack/blob/main/README.md
Control the alignment of items along the main axis. Supports centering, aligning to the end, spacing around, between, and evenly. Includes 'safe' prop for web.
```tsx
// Center items.
Centered
// Align to end.
At end
// Space around items.
Apple
Banana
// Align between.
Between
// Space evenly.
Apple
Banana
// Space between (default).
Apple
Banana
// Renders with `justify-content: safe center`.
Centered
// Renders with `justify-content: safe flex-end`.
At end
```
--------------------------------
### Stack Flex Properties
Source: https://github.com/nkzw-tech/stack/blob/main/README.md
Apply standard flexbox properties like taking available space, growing to fill, and preventing shrinking.
```tsx
// Take all available space.
Full width/height
// Grow to fill container.
Stretched
// Prevent shrinking.
Won't shrink
```
--------------------------------
### Stack Default Gap Configuration
Source: https://github.com/nkzw-tech/stack/blob/main/README.md
Set a global default gap value for all Stack components. This affects `gap={true}` usage.
```tsx
import { setDefaultGap } from '@nkzw/stack';
setDefaultGap(12); // Now gap={true} will use 12px.
```
--------------------------------
### Enhancing Custom Components with 'asStack' Utility in React
Source: https://context7.com/nkzw-tech/stack/llms.txt
Explains how to use the 'asStack' utility from '@nkzw/stack' to wrap custom React components, enabling them to accept and utilize all Stack layout props (like gap, padding, center, vertical). This allows for consistent styling and layout management across both built-in Stack components and custom ones.
```tsx
import { asStack } from '@nkzw/stack';
// Custom Link component wrapped with Stack
const Link = asStack(({ to, children, ...props }) => (
{children}
));
// Custom Button component wrapped with Stack
const Button = asStack(({ variant = 'primary', children, ...props }) => (
));
// Usage with all Stack props available
const Navigation = () => (
);
// Custom Card component with Stack props
const Card = asStack(({ title, children, ...props }) => (
{title &&
{title}
}
{children}
));
const Dashboard = () => (
$12,345
↑ 12% from last month
);
```
--------------------------------
### Stack Padding Control
Source: https://github.com/nkzw-tech/stack/blob/main/README.md
Control padding for the Stack component. Padding can be set to match the gap, use a custom value, or use the default gap.
```tsx
// Add padding equal to the gap.
Content
// Custom padding value.
Content
// Padding using the default gap value.
Content
```
--------------------------------
### Stack Row and Column Gap Control
Source: https://github.com/nkzw-tech/stack/blob/main/README.md
Manage distinct gap values for rows and columns to create complex layouts. Supports vertical-only layouts with row gaps.
```tsx
// Different gaps for rows and columns.
Apple
Banana
Kiwi
Item 4
// Vertical layout with row gap.
Apple
Banana
```
--------------------------------
### Control Flex Growth and Sizing with @nkzw/stack
Source: https://context7.com/nkzw-tech/stack/llms.txt
Demonstrates how to control flex item behavior including growth, shrinkage, and sizing using properties like 'flex1', 'stretch', and 'shrink0' on the @nkzw/stack component. This allows for dynamic layout adjustments based on available space.
```tsx
import Stack from '@nkzw/stack';
const FlexExamples = () => (
{/* flex1: Takes all available space */}
Main Content (flex: 1)
This section grows to fill available space
{/* stretch: Grows to fill container */}
Fixed
Stretched
Fixed
{/* shrink0: Prevents shrinking */}
Won't Shrink
Can Shrink
);
```
--------------------------------
### Form Layout using Stack Component (TSX)
Source: https://github.com/nkzw-tech/stack/blob/main/README.md
Defines a structured form layout using the Stack component. It arranges input fields (name, email) vertically with labels and includes action buttons (Cancel, Submit). This component relies on the 'Stack' UI primitive.
```tsx
```
--------------------------------
### Implement Dashboard Layout with Sidebar using Stack
Source: https://context7.com/nkzw-tech/stack/llms.txt
Shows how to create a dashboard layout with a fixed sidebar and a main content area using the Stack component. It utilizes flex properties like `flex1` and `shrink0` for flexible sizing and arrangement. The layout is designed for administrative interfaces.
```tsx
import Stack from '@nkzw/stack';
// Sidebar layout with flex control
const DashboardLayout = () => (
{/* Sidebar */}
Dashboard
📊Analytics👥Users⚙️Settings
{/* Main content */}
Analytics
Total Users
1,234
Revenue
$45,678
);
```
--------------------------------
### Stack Component Usage in React Native with Gap
Source: https://github.com/nkzw-tech/stack/blob/main/README.md
Shows how to use the Stack component within a React Native application, applying a vertical layout with a specified gap between child `Text` components.
```tsx
AppleBananaKiwi
```
--------------------------------
### Gap and Padding Props: Spacing Control (React)
Source: https://context7.com/nkzw-tech/stack/llms.txt
Explains and demonstrates the various ways to control spacing using the `gap`, `padding`, `verticalPadding`, and `horizontalPadding` props within the Stack component. It covers boolean usage, specific values, and directional padding, adhering to a 4px grid system.
```tsx
import Stack from '@nkzw/stack';
// Available gap values: 0, 1, 2, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, or true
const SpacingExamples = () => (
<>
{/* Boolean gap uses default 8px */}
Uses 8px gap and padding
{/* Specific gap with padding matching gap */}
Item 1
Item 2
{/* Independent gap and padding values */}
16px gap, 32px padding
{/* Directional padding control */}
Content
{/* Row and column gap for wrapped layouts */}
1
2
3
4
>
);
```
--------------------------------
### Polymorphic Rendering with 'as' Prop in React
Source: https://context7.com/nkzw-tech/stack/llms.txt
Demonstrates rendering the Stack component as semantic HTML elements (like 'nav', 'a', 'form', 'label') or custom components (like 'react-router-dom's Link). This feature allows for flexible UI construction while maintaining type safety and leveraging Stack's layout props.
```tsx
import Stack from '@nkzw/stack';
import { Link } from 'react-router-dom';
// Render as semantic HTML elements
const SemanticLayout = () => (
Home
About
Contact
);
// Render as custom component (requires style prop support)
const NavigationWithRouter = () => (
🏠Home📦Products
);
// Form with semantic elements
const Form = () => (
UsernamePassword
);
```
--------------------------------
### Configuring Global Default Gap with 'setDefaultGap' in React
Source: https://context7.com/nkzw-tech/stack/llms.txt
Shows how to use the 'setDefaultGap' function from '@nkzw/stack' to set a global default value for the 'gap' prop. This simplifies spacing consistency across an application, allowing `gap` and `gap={true}` to use the configured default, while explicit pixel values still work.
```tsx
import { setDefaultGap } from '@nkzw/stack';
import Stack from '@nkzw/stack';
// Configure default gap at app initialization
setDefaultGap(12); // Now gap={true} will use 12px instead of 8px
// Application component
const App = () => (
{/* These will use 12px gap */}
Item 1
Item 2
{/* Still can use explicit values */}
Item A
Item B
{/* Boolean gap now uses configured default */}
Uses 12px gap
Because of setDefaultGap(12)
);
// Typically set in app entry point
// index.tsx or App.tsx
import { setDefaultGap } from '@nkzw/stack';
setDefaultGap(16); // Configure once at startup
export default App;
```
--------------------------------
### Stack Directional Padding
Source: https://github.com/nkzw-tech/stack/blob/main/README.md
Apply padding specifically to the vertical or horizontal axis, or set custom values for both. Can be mixed with gap properties.
```tsx
// Vertical padding only.
Content
// Horizontal padding only.
Content
// Custom directional padding.
Content
// Mix with gaps.
Content
```
--------------------------------
### Justify Items on Main Axis with @nkzw/stack
Source: https://context7.com/nkzw-tech/stack/llms.txt
Demonstrates how to control item positioning along the main axis using properties like 'center', 'end', 'between', 'evenly', and 'around' on the @nkzw/stack component. This is useful for distributing space and aligning content horizontally or vertically depending on the flex direction.
```tsx
import Stack from '@nkzw/stack';
const JustificationExamples = () => (
{/* Center items */}
Centered
{/* Align to end */}
At End
{/* Space between */}
Start
End
{/* Space evenly */}
A
B
C
{/* Space around */}
X
Y
Z
);
```
--------------------------------
### Align Items on Cross Axis with @nkzw/stack
Source: https://context7.com/nkzw-tech/stack/llms.txt
Illustrates how to control item positioning along the cross axis using properties like 'alignCenter', 'alignStart', 'alignEnd', and 'baseline' on the @nkzw/stack component. This is useful for aligning items when they have different heights or when the main axis is vertical.
```tsx
import Stack from '@nkzw/stack';
const AlignmentExamples = () => (
{/* Center align items */}
Small
Medium
Large
{/* Align to start */}
Start
Aligned
{/* Align to end */}
End
Aligned
{/* Baseline alignment */}
Small
Medium
Large
);
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.