### Install and Develop xstyled Docs Site
Source: https://github.com/styled-components/xstyled/blob/main/website/README.md
Installs project dependencies and starts the development server for the xstyled documentation site. After running, access the site at localhost:8000.
```bash
npm install
npm run develop
```
--------------------------------
### Setup Theme and Preflight with Emotion
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/getting-started/installation.mdx
Demonstrates setting up the ThemeProvider and Preflight component from '@xstyled/emotion'. This is essential for applying global styles and theme configurations when using Emotion.
```javascript
import { defaultTheme, ThemeProvider, Preflight } from '@xstyled/emotion'
const theme = {
...defaultTheme,
// Customize your theme here
}
export default function App() {
return (
{/* ... */}
)
}
```
--------------------------------
### Setup Theme and Preflight with styled-components
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/getting-started/installation.mdx
Demonstrates setting up the ThemeProvider and Preflight component from '@xstyled/styled-components'. This is crucial for applying global styles and theme configurations to your application.
```javascript
import {
defaultTheme,
ThemeProvider,
Preflight,
} from '@xstyled/styled-components'
const theme = {
...defaultTheme,
// Customize your theme here
}
export default function App() {
return (
{/* ... */}
)
}
```
--------------------------------
### Install xstyled System Package
Source: https://github.com/styled-components/xstyled/blob/main/packages/system/README.md
Installs the core @xstyled/system package using npm. This package provides the foundational system for styling components and is a common starting point for using xstyled.
```bash
npm install @xstyled/system
```
--------------------------------
### Install xstyled
Source: https://github.com/styled-components/xstyled/blob/main/website/src/components/getting-started.mdx
Installs the xstyled library along with its peer dependency, styled-components, using npm. This is the initial step to integrate xstyled into your project.
```bash
npm install styled-components @xstyled/styled-components
```
--------------------------------
### Setup Theme and Preflight
Source: https://github.com/styled-components/xstyled/blob/main/website/src/components/getting-started.mdx
Demonstrates the setup of the ThemeProvider and Preflight component from '@xstyled/styled-components' in an application's entry point (e.g., App.js). It shows how to import default theme, customize it, and wrap the application to enable xstyled features.
```javascript
// App.js
import {
defaultTheme,
ThemeProvider,
Preflight,
} from '@xstyled/styled-components'
const theme = {
...defaultTheme,
// Customize your theme here
}
export default function App() {
return (
{/* ... */}
)
}
```
--------------------------------
### Start Web Benchmarks (Bash)
Source: https://github.com/styled-components/xstyled/blob/main/benchmarks/README.md
Starts the web benchmark application. This command runs the benchmark suite for @xstyled/styled-components against styled-components in real conditions. The application will be accessible at http://localhost:8083.
```bash
npm start
```
--------------------------------
### Install xstyled with Emotion
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/getting-started/installation.mdx
Installs the necessary packages for using xstyled with Emotion via npm. This command adds Emotion core packages and the xstyled integration package.
```npm
npm install @emotion/react @emotion/styled @xstyled/emotion
```
--------------------------------
### Install xstyled with styled-components
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/getting-started/installation.mdx
Installs the necessary packages for using xstyled with styled-components via npm. This command adds both styled-components and the xstyled integration package.
```npm
npm install styled-components @xstyled/styled-components
```
--------------------------------
### Install Dependencies
Source: https://github.com/styled-components/xstyled/blob/main/CONTRIBUTING.md
Installs project dependencies using npm, specifically using the `--legacy-peer-deps` flag to handle potential peer dependency conflicts.
```bash
npm install --legacy-peer-deps
```
--------------------------------
### Install xstyled
Source: https://github.com/styled-components/xstyled/blob/main/README.md
Installs the @xstyled/styled-components and styled-components packages using npm. This is the initial step to integrate xstyled into your React project.
```bash
npm install @xstyled/styled-components styled-components
```
--------------------------------
### xstyled v2 Declarative Components Example
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/getting-started/upgrade-guide.mdx
Demonstrates the philosophy of xstyled v2, which emphasizes the `x` namespace for creating declarative components and styling without writing raw CSS. It shows how to use the `x` object for styling elements like buttons.
```js
import { x } from '@xstyled/xstyled'
function Button() {
return (
Upgrade
)
}
```
--------------------------------
### xstyled v3 Plugins API Configuration
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/getting-started/upgrade-guide.mdx
Illustrates how to extend xstyled with plugins using a `xstyled.config.js` file. This example shows importing necessary functions and composing system utilities with custom ones like `borderInline`.
```js
import { createCss, system, compose } from '@xstyled/xstyled'
import { borderInline } from './utilities/border-inline'
export const { css, styled, x, createGlobalStyle } = createCss(
compose(system, borderInline),
)
```
--------------------------------
### Install @xstyled/prop-types
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/core-concepts/prop-types.mdx
Installs the @xstyled/prop-types package using npm.
```bash
npm i @xstyled/prop-types
```
--------------------------------
### xstyled v3 Object States Syntax
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/getting-started/upgrade-guide.mdx
Demonstrates the new object syntax for specifying states in xstyled v3, which are similar to breakpoints. This includes examples for simple states, mixed screen and state definitions, and nested states.
```js
```
```js
// Mixed screens and states
// Nested states
```
--------------------------------
### xstyled v3 Multiple Styles Example
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/getting-started/upgrade-guide.mdx
Shows how to use the new `multiple` option in the `style` function to declare styles that accept multiple values separated by a comma, such as `box-shadow`.
```js
```
--------------------------------
### Install xstyled with Emotion
Source: https://github.com/styled-components/xstyled/blob/main/packages/emotion/README.md
Installs the xstyled library along with its Emotion integration and React dependencies using npm. This command sets up the necessary packages for using xstyled in a React project.
```bash
npm install @xstyled/emotion @emotion/react @emotion/styled
```
--------------------------------
### Install xstyled with styled-components
Source: https://github.com/styled-components/xstyled/blob/main/packages/styled-components/README.md
Installs the xstyled package along with its peer dependency, styled-components, using npm. This command sets up the necessary libraries for using xstyled in a React project.
```bash
npm install @xstyled/styled-components styled-components
```
--------------------------------
### Responsive Marketing Page Layout Example
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/core-concepts/responsive-design.mdx
A comprehensive example of a marketing page component that adapts its layout based on screen size. It uses xstyled utilities to stack content on small screens and arrange it side-by-side on medium screens and larger, demonstrating responsive `display`, `flexShrink`, and `width`.
```jsx
<>
Case study
Finding customers for your new business
Getting a new business off the ground is a lot of hard work. Here
are five ideas you can use to find your first customers.
Case study
Finding customers for your new business
Getting a new business off the ground is a lot of hard work. Here are
five ideas you can use to find your first customers.
>
```
--------------------------------
### Responsive Min-Width Example (JSX)
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/sizing/min-width.mdx
Explains how to apply minimum width utilities at different breakpoints using responsive object notation. For example, `minWidth={{ md: 1 }}` applies `minWidth={1}` from the medium breakpoint upwards.
```jsx
```
--------------------------------
### Align Self: Flex-Start (jsx)
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/box-alignment/align-self.mdx
Use `alignSelf="flex-start"` to align an item to the start of the container's cross axis, overriding the container's `align-items` value. This example demonstrates an item positioned at the start.
```jsx
<>
1
2
3
1
2
3
>
```
--------------------------------
### Justify Self Start Alignment
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/box-alignment/justify-self.mdx
Illustrates `justifySelf='start'` for aligning a grid item to the beginning of its inline axis. The example uses a parent with `justifyItems='stretch'` to show the effect.
```jsx
<>
{Array.from({ length: 6 }, (_, index) => index + 1).map((value) => (
{value === 2 ? '1' : ''}
))}
{/* ... */}
1
{/* ... */}
{/* ... */}
{/* ... */}
{/* ... */}
>
```
--------------------------------
### Build and Develop Website
Source: https://github.com/styled-components/xstyled/blob/main/CONTRIBUTING.md
Commands to build the project packages and start the development server for the project's website. This is typically done after making code changes.
```bash
# build packages
npm run build
# run docs
cd website
npm run develop
```
--------------------------------
### Configure Theme Space in xstyled v2
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/getting-started/upgrade-guide.mdx
Example of how to define the `space` array in your xstyled theme for v2. Default `space` values are no longer provided, requiring explicit definition in the theme if not customized.
```js
const theme = {
space: [0, 4, 8, 16, 24, 48, 96, 144, 192, 240],
}
```
--------------------------------
### Write First Component
Source: https://github.com/styled-components/xstyled/blob/main/website/src/components/getting-started.mdx
Illustrates how to create a basic component using the `x` object provided by '@xstyled/styled-components'. This example shows applying styles like background color directly via props, leveraging xstyled's utility-first syntax.
```javascript
import { x } from '@xstyled/styled-components'
function Button(props) {
return
}
```
--------------------------------
### First Component with styled-components
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/getting-started/installation.mdx
Shows how to create your first component using xstyled's `x` object with styled-components. This allows for easy styling directly within your JSX.
```javascript
import { x } from '@xstyled/styled-components'
function Button(props) {
return
}
```
--------------------------------
### Toggle Color Mode with useColorMode Hook
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/core-concepts/dark-mode.mdx
Utilizes the `useColorMode` hook to get the current color mode and a function to set it. This example toggles between 'default' and 'dark' modes via a button click.
```jsx
import React from 'react'
import { useColorMode } from '@xstyled/styled-components'
function Example(props) {
const [colorMode, setColorMode] = useColorMode()
return (
)
}
```
--------------------------------
### Build xstyled Docs Site
Source: https://github.com/styled-components/xstyled/blob/main/website/README.md
Builds the static assets for the xstyled documentation site. This command compiles the site for deployment.
```bash
npm run build
```
--------------------------------
### Serve xstyled Docs Site Build
Source: https://github.com/styled-components/xstyled/blob/main/website/README.md
Serves the built version of the xstyled documentation site locally. This is useful for testing the production build before deployment. Access the served site at localhost:9000.
```bash
npm run serve
```
--------------------------------
### Responsive Utilities: Emotion vs. xstyled
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/getting-started/migrate-from-emotion.mdx
Demonstrates applying responsive styles, specifically width, using Emotion's media query syntax and xstyled's shorthand responsive props for simplified media query usage.
```jsx
/** @jsx jsx */
import { jsx } from '@emotion/react'
const Button = ({ children }) => {
return (
)
}
```
```jsx
import { x } from '@xstyled/emotion'
const Button = ({ children }) => {
return {children}
}
```
--------------------------------
### Justify Items: Start (xstyled)
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/box-alignment/justify-items.mdx
Demonstrates using the `justifyItems="start"` prop in xstyled to align grid items to the start of their inline axis. This utility maps to the CSS `justify-items: start;` property.
```jsx
<>
{Array.from({ length: 6 }, (_, index) => index + 1).map((value) => (
{value}
))}
1
2
3
4
5
6
>
```
--------------------------------
### Grid Row Start/End Lines with xstyled
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/grid/grid-row.mdx
Illustrates using `gridRow` to define the start and end grid lines for an element, or to span a specific number of rows from a starting line. CSS grid lines are 1-indexed.
```jsx
<>
1
2
3
123
>
```
--------------------------------
### First Component with Emotion
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/getting-started/installation.mdx
Illustrates creating a simple component using xstyled's `x` object with Emotion. This enables straightforward styling within your JSX when using Emotion.
```javascript
import { x } from '@xstyled/emotion'
function Button(props) {
return
}
```
--------------------------------
### Control Grid Start/End Lines with Grid Column
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/grid/grid-column.mdx
Illustrates using the `gridColumn` prop with specific line numbers or spans to control an element's starting and ending positions within a CSS grid. It covers `n / span x` and `span x / n` combinations, noting that grid lines start at 1.
```jsx
<>
1
2
3
4
1234
>
```
--------------------------------
### Responsive Utilities: styled-components vs xstyled (x.*)
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/getting-started/migrate-from-styled-components.mdx
Demonstrates xstyled's simplified responsive utilities using the 'x.*' syntax. It shows how to apply styles conditionally based on breakpoints (e.g., 'md') directly as props, which is more concise than using traditional CSS media queries within styled-components.
```javascript
import styled from 'styled-components'
const Button = styled.div`
width: 200px;
@media (min-width: 768px) {
width: 300px;
}
`
```
```jsx
import { x } from '@xstyled/emotion'
const Button = ({ children }) => {
return {children}
}
```
--------------------------------
### Import createCss for xstyled Configuration
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/core-concepts/adding-new-utilities.mdx
Demonstrates importing the `createCss` function from `@xstyled/...` to initialize xstyled configuration. This is the first step in setting up a custom xstyled configuration file.
```javascript
import { createCss } from '@xstyled/...'
```
--------------------------------
### Usage Example with Transition Timing Functions
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/transitions/transition-timing-function.mdx
Demonstrates how to use xstyled's `transitionTimingFunction` prop to control CSS transition easing curves for buttons. Includes examples for 'ease-in', 'ease-out', and 'ease-in-out'.
```jsx
<>
Hover me
Hover me
Hover me
Hover me
Hover me
Hover me
>
```
--------------------------------
### Justify Content Flex Start with xstyled
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/box-alignment/justify-content.mdx
Demonstrates using the `justifyContent='flex-start'` prop in xstyled to align flex items to the start of the container's main axis. This corresponds to the CSS `justify-content: flex-start;` property.
```jsx
1
2
3
```
--------------------------------
### Initialize xstyled with System Utilities
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/core-concepts/adding-new-utilities.mdx
Shows how to initialize xstyled by calling `createCss` with the `system` object, which includes all built-in xstyled utilities. This setup provides access to standard styling props.
```javascript
import { createCss, system } from '@xstyled/...'
export const { css, styled, x, createGlobalStyle } = createCss(system)
```
--------------------------------
### Lint and Test Project
Source: https://github.com/styled-components/xstyled/blob/main/CONTRIBUTING.md
Commands to ensure code quality by running the linter and to verify that the test suite passes. These are essential steps before submitting a pull request.
```sh-session
$ npm run lint
$ npm run test
```
--------------------------------
### xstyled Basic Positioning Examples
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/layout/top-right-bottom-left.mdx
Demonstrates various positioning utilities provided by xstyled, including absolute positioning, spanning edges, and pinning elements to corners. These examples showcase how to apply styles directly within JSX for layout control.
```jsx
<>
9
>
```
--------------------------------
### Configure Babel Macro for xstyled Styled Components
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/getting-started/migrate-from-styled-components.mdx
Sets up the `babel-plugin-macros` to use the styled-components Babel plugin with zero configuration for xstyled projects. This involves adding a specific configuration to your `package.json` or a `babel-plugin-macros` config file, pointing to the xstyled import module.
```js
// babel-plugin-macros.config.js
module.exports = {
// ...
// Other macros config
styledComponents: {
importModuleName: '@xstyled/styled-components',
},
}
```
--------------------------------
### Visible Overflow Example (jsx)
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/layout/overflow.mdx
Demonstrates the `overflow='visible'` prop in xstyled, which allows content to overflow the element's bounds without clipping. Any content that overflows the bounds of the element will then be visible. This example uses the xstyled library for React.
```jsx
<>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris
eleifend rutrum auctor. Phasellus convallis sagittis augue ut ornare.
Vestibulum et gravida lectus, sed ultrices sapien. Nullam aliquet elit
dui, vitae hendrerit lectus volutpat eget
Lorem ipsum dolor sit amet...
>
```
--------------------------------
### Background Attachment: Responsive Example
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/backgrounds/background-attachment.mdx
Shows how to control the background attachment at specific breakpoints using responsive object notation. For example, `backgroundAttachment={{ md: 'scroll' }}` applies the utility at medium screen sizes and above.
```jsx
```
--------------------------------
### Enhanced Styled Components: styled-components (Theme) vs xstyled (styled.*)
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/getting-started/migrate-from-styled-components.mdx
Illustrates how xstyled enhances the standard styled-components syntax by allowing direct use of design system tokens (space, colors, radii) as string literals. This contrasts with styled-components' reliance on theme provider access, making xstyled's approach more streamlined for projects with design systems.
```javascript
import styled from 'styled-components'
const Button = styled.button`
padding: ${(p) => `${p.theme.space[2]} ${p.theme.space[4]}`};
color: ${(p) => p.theme.colors.white};
border-radius: ${(p) => p.theme.radii.md};
font-weight: ${(p) => p.theme.fontWeights.semibold};
transition: ${(p) => p.theme.transitions.default};
background-color: ${(p) => p.theme.colors['emerald-500']};
&:hover {
background-color: ${(p) => p.theme.colors['emerald-800']};
}
&:focus {
outline: none;
box-shadow: ${(p) => p.theme.shadows['emerald-ring']};
}
`
```
```javascript
import styled from '@xstyled/styled-components'
const Button = styled.button`
padding-top: 2;
padding-bottom: 2;
padding-right: 4;
padding-left: 4;
color: white;
border-radius: md;
font-weight: semibold;
transition: default;
background-color: emerald-500;
&:hover {
background-color: emerald-800;
}
&:focus {
outline: none;
box-shadow: emerald-ring;
}
`
```
--------------------------------
### Auto Overflow Example (jsx)
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/layout/overflow.mdx
Demonstrates the `overflow='auto'` prop in xstyled, which adds scrollbars to an element only when its content overflows. This is useful for containing large amounts of text or elements within a fixed-size container. This example uses the xstyled library for React.
```jsx
<>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris
eleifend rutrum auctor. Phasellus convallis sagittis augue ut ornare.
Vestibulum et gravida lectus, sed ultrices sapien. Nullam aliquet elit
dui, vitae hendrerit lectus volutpat eget. In porttitor tincidunt
egestas. Pellentesque laoreet ligula at est vulputate facilisis. Etiam
tristique justo ut odio placerat ornare. Cras bibendum, orci at ornare
tincidunt, lacus nunc gravida enim, sit amet euismod nunc lectus in
lectus. Ut dictum nulla et arcu aliquet ornare. Aliquam et dapibus
lectus. Aenean mattis elit mi, sed ultricies augue consectetur id. Sed
id magna malesuada, luctus urna a, bibendum tortor. Cras cursus cursus
ex. Nulla fringilla elit vitae imperdiet scelerisque. Donec ac sem eu
diam convallis mollis a sed leo. Proin congue augue turpis, eget
rutrum dolor ultricies non. Nulla blandit venenatis dapibus. Sed
tincidunt mollis elit, quis suscipit nibh eleifend quis. Donec ex
lorem, auctor eu rutrum in, blandit id dolor. Nulla molestie arcu
turpis. In id felis vulputate, tempor massa eget, malesuada mauris.
Quisque fringilla consequat metus, luctus scelerisque leo fringilla
vel.
Lorem ipsum dolor sit amet...
>
```
--------------------------------
### Run CLI Benchmarks (Bash)
Source: https://github.com/styled-components/xstyled/blob/main/benchmarks/README.md
Executes various command-line interface benchmarks for xstyled libraries. These commands compare @xstyled/system, @xstyled/styled-components, and @xstyled/emotion against their respective counterparts.
```bash
npm run bench-system
```
```bash
npm run bench-styled-components
```
```bash
npm run bench-emotion
```
--------------------------------
### xstyled Responsive alignSelf Example
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/box-alignment/align-self.mdx
Shows how to apply responsive styles to the alignSelf prop using xstyled's object notation. This example demonstrates setting alignSelf="center" specifically for medium screen sizes and above.
```jsx
{/* ... */}
```
--------------------------------
### xstyled: Responsive Flex Wrap Example
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/flexbox/flex-wrap.mdx
Demonstrates applying `flexWrap` responsively using object notation. For instance, `flexWrap={{ md: 'wrap-reverse' }}` applies `wrap-reverse` at medium screen sizes and above. This allows for dynamic layout adjustments based on breakpoints.
```jsx
{/* ... */}
```
--------------------------------
### xstyled alignContent space-around Example
Source: https://github.com/styled-components/xstyled/blob/main/website/pages/docs/box-alignment/align-content.mdx
Demonstrates how to use alignContent="space-around" in xstyled to distribute rows within a flex container, ensuring equal space around each line. This example visualizes the distribution with colored boxes.
```jsx
<>
<>
{Array.from({ length: 5 }, (_, index) => index + 1).map((value) => (
{value}
))}
>