+
+
+
+
+
+
diff --git a/docs/src/components/Footer.astro b/docs/src/components/Footer.astro
new file mode 100644
index 00000000..ac79e101
--- /dev/null
+++ b/docs/src/components/Footer.astro
@@ -0,0 +1,90 @@
+---
+import { Image } from 'astro:assets'
+import CodemaskLogo from '../assets/codemask-black.svg'
+import Clouds from '../assets/footer-clouds.svg'
+
+const motto = 'Bridging Your Idea to the digital world\nYour experts in mobile and web development'
+---
+
+
+
+
diff --git a/docs/src/components/Hero.astro b/docs/src/components/Hero.astro
new file mode 100644
index 00000000..696433c2
--- /dev/null
+++ b/docs/src/components/Hero.astro
@@ -0,0 +1,300 @@
+---
+import { Image } from 'astro:assets'
+import Github from '../assets/github.svg'
+import Unicorn from '../assets/unicorn.svg'
+import CloudA from '../assets/cloud-a.svg'
+import CloudB from '../assets/cloud-b.svg'
+import HeroMobile from '../assets/hero-mobile.svg'
+import ArrowDown from '../assets/arrow-down.svg'
+import MediaImage from './MediaImage.astro'
+---
+
+
+
+
+
+
diff --git a/docs/src/components/nav/Nav.astro b/docs/src/components/nav/Nav.astro
new file mode 100644
index 00000000..69343c2e
--- /dev/null
+++ b/docs/src/components/nav/Nav.astro
@@ -0,0 +1,88 @@
+---
+import { Image } from 'astro:assets'
+import Logo from '../../assets/logo.svg'
+import Hamburger from './Hamburger.astro'
+import { links } from './data'
+---
+
+
+
+
diff --git a/docs/src/components/nav/data.ts b/docs/src/components/nav/data.ts
new file mode 100644
index 00000000..9e599a77
--- /dev/null
+++ b/docs/src/components/nav/data.ts
@@ -0,0 +1,14 @@
+export const links = [
+ {
+ name: 'Sponsors',
+ href: 'other/sponsors/'
+ },
+ {
+ name: 'Examples',
+ href: 'examples/all/'
+ },
+ {
+ name: 'Blog',
+ href: 'https://www.reactnativecrossroads.com/'
+ }
+]
diff --git a/docs/src/content/docs/example/breakpoints.mdx b/docs/src/content/docs/example/breakpoints.mdx
deleted file mode 100644
index e4376f40..00000000
--- a/docs/src/content/docs/example/breakpoints.mdx
+++ /dev/null
@@ -1,62 +0,0 @@
----
-title: Breakpoints
----
-
-import Seo from '../../../components/Seo.astro'
-
-
- Any style can change based on breakpoints. To do this, change a value to an object:
-
- ```ts
- const stylesheet = createStyleSheet(theme => ({
- container: {
- flex: 1,
- justifyContent: 'center',
- alignItems: 'center',
- backgroundColor: {
- // your breakpoints
- xs: theme.colors.background,
- sm: theme.colors.barbie
- }
- },
- text: {
- color: theme.colors.typography
- }
- }))
- ```
-
- You can even use it with nested objects like `transform` or `shadowOffset`:
-
- ```ts
- const stylesheet = createStyleSheet(theme => ({
- container: {
- flex: 1,
- justifyContent: 'center',
- alignItems: 'center',
- backgroundColor: {
- xs: theme.colors.background,
- sm: theme.colors.barbie
- },
- transform: [
- {
- translateX: 100
- },
- {
- scale: {
- xs: 1.5,
- ':w[500]': 1
- }
- }
- ]
- }
- }))
- ```
-
- Library will choose the correct value (based on screen width) in the runtime.
-
-
diff --git a/docs/src/content/docs/example/dynamic-functions.mdx b/docs/src/content/docs/example/dynamic-functions.mdx
deleted file mode 100644
index b0f7596e..00000000
--- a/docs/src/content/docs/example/dynamic-functions.mdx
+++ /dev/null
@@ -1,69 +0,0 @@
----
-title: Dynamic functions
----
-
-import Seo from '../../../components/Seo.astro'
-
-
- Every style can be transformed to dynamic function to take additional parameters from JSX:
-
- ```tsx
- export const ExampleUnistyles = () => {
- const { styles } = useStyles(stylesheet)
-
- return (
-
- {posts.map((post, index) => (
-
-
- {post.title}
-
-
- ))}
-
- )
- }
-
- const stylesheet = createStyleSheet({
- scrollContainer: {
- flex: 1,
- justifyContent: 'center',
- alignItems: 'center',
- },
- // dynamic function
- post: (index: number) => ({
- backgroundColor: index % 2 === 0 ? 'gold' : 'silver',
- })
- })
- ```
- If you use a dynamic function, library will wrap it in a `Proxy` to make sure the correct values of breakpoints will be used:
-
- ```ts
- const stylesheet = createStyleSheet(theme => ({
- scrollContainer: {
- flex: 1,
- justifyContent: 'center',
- alignItems: 'center',
- },
- post: (index: number) => ({
- // breakpoints and media queries works with dynamic function
- backgroundColor: {
- xs: index % 2 === 0
- ? theme.colors.gold
- : theme.colors.silver,
- sm: theme.colors.red
- }
- })
- }))
-```
-
-
diff --git a/docs/src/content/docs/example/dynamic-themes.mdx b/docs/src/content/docs/example/dynamic-themes.mdx
deleted file mode 100644
index 52087a4c..00000000
--- a/docs/src/content/docs/example/dynamic-themes.mdx
+++ /dev/null
@@ -1,76 +0,0 @@
----
-title: Dynamic themes
----
-
-import Seo from '../../../components/Seo.astro'
-
-
-
-You can incorporate as many themes as you desire in your application. While there's flexibility in how you structure your theme, it's essential to maintain consistency with the TypeScript type:
-
-To promote reusability and maintainability, it's a good practice to share as many values between themes as possible:
-
-```ts
-// move shared colors to object
-const sharedColors = {
- barbie: '#ff9ff3',
- oak: '#1dd1a1',
- sky: '#48dbfb',
- fog: '#c8d6e5',
- aloes: '#00d2d3'
-}
-
-export const lightTheme = {
- colors: {
- // reuse or override them
- ...sharedColors,
- backgroundColor: '#ffffff',
- typography: '#000000'
- }
- // other keys in common with darkTheme
-}
-
-export const darkTheme = {
- colors: {
- // reuse or override them
- ...sharedColors,
- backgroundColor: '#000000',
- typography: '#ffffff'
- }
- // other keys in common with lightTheme
-}
-
-// export type that will be used to describe your theme
-export type AppTheme = typeof lightTheme | typeof darkTheme
-```
-
-With the themes set up, modify your `createUnistyles` to consume your `AppTheme` type:
-
-```ts
-export const { useStyles, createStyleSheet } = createUnistyles(breakpoints)
-```
-
-The final step is to switch your theme based on certain states, persisted values, databases, etc.:
-
-```tsx
-export const App: React.FunctionComponent = () => {
- // obtain here your dark or light theme. It can be storage, state, mmkv, or whatever you use
- // const [yourAppTheme] = useState(lightTheme)
- // const [yourAppTheme] = useYourStorage()
- // const [yourAppTheme] = useMMKVObject(Theme)
-
- // switching theme will re-render your stylesheets automatically
- return (
-
-
-
- )
-}
-```
-
-
diff --git a/docs/src/content/docs/example/media-queries.mdx b/docs/src/content/docs/example/media-queries.mdx
deleted file mode 100644
index bdabaeda..00000000
--- a/docs/src/content/docs/example/media-queries.mdx
+++ /dev/null
@@ -1,45 +0,0 @@
----
-title: Media queries
----
-import Seo from '../../../components/Seo.astro'
-
-
-
-For more advanced usage and pixel perfect designs you can also use a custom media queries. Library supports 4 types of media queries (w-width, h-height):
-
-```ts
-:w[200, 500] - with upper and lower bounds, it translates to width from 200-500px
-:w[, 800] - with upper bound only, it's equal to width from 0-800px
-:h[400] - lower bound only, it means height from 400px
-:h[200, 300]:w[500] - combined queries for both width and height
-```
-
-Media queries can be mixed with breakpoints, but have a bigger priority:
-
-```tsx
-const stylesheet = createStyleSheet(theme => ({
- container: {
- justifyContent: 'center',
- alignItems: 'center',
- flexDirection: {
- xs: 'column',
- sm: 'row',
- },
- backgroundColor: {
- md: theme.colors.background,
- // even though md might overlap with >600px, lib will use 'barbie'
- ':w[600]': theme.colors.barbie
- }
- },
- text: {
- color: theme.colors.typography
- }
-}))
-```
-
-
diff --git a/docs/src/content/docs/example/variants.mdx b/docs/src/content/docs/example/variants.mdx
deleted file mode 100644
index e92bace4..00000000
--- a/docs/src/content/docs/example/variants.mdx
+++ /dev/null
@@ -1,135 +0,0 @@
----
-title: Variants
----
-
-import Seo from '../../../components/Seo.astro'
-
-
-
-`react-native-unistyles` isn't a UI/component library, so you're in charge of designing variants. With no restrictions and using your creativity, you can easily create variants for your components.
-
-Let's examine variants for the `Text` component. Imagine you want to create several variants for your `Typography` components:
-- Heading
-- Regular
-- Thin
-
-To achieve this, add variants to your theme:
-
-```ts
-export const lightTheme = {
- colors: {
- ...sharedColors,
- backgroundColor: '#ffffff',
- typography: '#000000'
- },
- components: {
- typography: {
- base: {
- fontFamily: 'Roboto',
- fontSize: 12,
- },
- heading: {
- fontFamily: 'Roboto-Medium',
- fontSize: 24,
- },
- regular: {
- fontFamily: 'Roboto',
- fontSize: 12,
- },
- thin: {
- fontFamily: 'Roboto-Thin',
- fontSize: 12,
- },
- bold: {
- fontWeight: 'bold'
- }
- }
- }
-}
-```
-Next, create a base component:
-
-```tsx
-import React from 'react'
-import type { PropsWithChildren } from 'react'
-import { Text, TextStyle } from 'react-native'
-import { createStyleSheet, useStyles } from 'lib/styles'
-
-interface BaseTextProps extends PropsWithChildren {
- bold: boolean,
- style: TextStyle
-}
-
-export const BaseText: React.FunctionComponent = ({
- children,
- bold = false,
- style = {}
-}) => {
- const {styles} = useStyles(stylesheet)
-
- return (
-
- {children}
-
- )
-}
-
-const stylesheet = createStyleSheet(theme => ({
- baseText: {
- ...theme.components.typography.base
- },
- bold: {
- ...theme.components.typography.bold
- }
-}))
-```
-Remember, that if you want to spread styles like so you need to export your theme "as const" for TypeScript.
-This is how React Native types works, and you can see the same behavior with StyleSheet.create.
-
-Now, let's create another variant, e.g., Heading:
-
-```tsx
-import React from 'react'
-import type { PropsWithChildren } from 'react'
-import { Text, TextStyle } from 'react-native'
-import { createStyleSheet, useStyles } from 'lib/styles'
-import { BaseText } from 'lib/components'
-
-interface BaseTextProps extends PropsWithChildren {
- bold: boolean,
- text: string
-}
-
-export const Heading: React.FunctionComponent = ({
- text,
- bold = false
-}) => {
- const { theme } = useStyles()
-
- return (
-
- {text}
-
- )
-}
-```
-And so on...
-
-
diff --git a/docs/src/content/docs/examples/all.mdx b/docs/src/content/docs/examples/all.mdx
new file mode 100644
index 00000000..c9740d32
--- /dev/null
+++ b/docs/src/content/docs/examples/all.mdx
@@ -0,0 +1,64 @@
+---
+title: Examples
+---
+
+import Seo from '../../../components/Seo.astro'
+
+
+
+
+### Explore Examples with Unistyles 2.0
+
+:::tip
+Delve into a variety of examples that demonstrate the practical applications and capabilities of Unistyles 2.0.
+Collection of examples is hosted on GitHub, making it easy for you to browse, learn, and get inspired.
+:::
+
+
+#### Theming
+
+- No registered themes [link](https://github.com/jpudysz/react-native-unistyles/tree/main/examples/expo/src/examples/NoThemesScreen.tsx)
+- Single theme [link](https://github.com/jpudysz/react-native-unistyles/tree/main/examples/expo/src/examples/SingleThemeScreen.tsx)
+- Two themes [link](https://github.com/jpudysz/react-native-unistyles/tree/main/examples/expo/src/examples/TwoThemesScreen.tsx)
+- Multiple themes [link](https://github.com/jpudysz/react-native-unistyles/tree/main/examples/expo/src/examples/MultipleThemesScreen.tsx)
+- Adaptive mode [link](https://github.com/jpudysz/react-native-unistyles/tree/main/examples/expo/src/examples/LightDarkThemesScreen.tsx)
+- Adaptive mode with multiple themes [link](https://github.com/jpudysz/react-native-unistyles/tree/main/examples/expo/src/examples/MultipleThemesAdaptiveScreen.tsx)
+
+#### Breakpoints
+
+- No registered breakpoints [link](https://github.com/jpudysz/react-native-unistyles/tree/main/examples/expo/src/examples/NoBreakpointsScreen.tsx)
+- With breakpoints [link](https://github.com/jpudysz/react-native-unistyles/tree/main/examples/expo/src/examples/WithBreakpointsScreen.tsx)
+- With orientation breakpoints [link](https://github.com/jpudysz/react-native-unistyles/tree/main/examples/expo/src/examples/OrientationBreakpoints.tsx)
+
+#### Media queries
+
+- mq util [link](https://github.com/jpudysz/react-native-unistyles/tree/main/examples/expo/src/examples/MediaQueriesWidthHeight.tsx)
+- mixed with breakpoints [link](https://github.com/jpudysz/react-native-unistyles/tree/main/examples/expo/src/examplesMixedMediaQueries.tsx)
+
+#### Variants
+
+- Selected variant [link](https://github.com/jpudysz/react-native-unistyles/tree/main/examples/expo/src/examples/VariantsScreen.tsx)
+- Default variant [link](https://github.com/jpudysz/react-native-unistyles/tree/main/examples/expo/src/examples/DefaultVariantScreen.tsx)
+
+#### Plugins
+- Auto guideline plugin [link](https://github.com/jpudysz/react-native-unistyles/tree/main/examples/expo/src/examples/AutoGuidelinePluginScreen.tsx)
+- High contrast plugin [link](https://github.com/jpudysz/react-native-unistyles/tree/main/examples/expo/src/examples/HighContrastPluginScreen.tsx)
+
+#### UnistylesRuntime
+
+- All runtime values [link](https://github.com/jpudysz/react-native-unistyles/tree/main/examples/expo/src/examples/RuntimeScreen.tsx)
+- Runtime in stylesheet [link](https://github.com/jpudysz/react-native-unistyles/tree/main/examples/expo/src/examples/RuntimeWithStyleSheetScreen.tsx)
+
+#### Other
+- Memoization [link](https://github.com/jpudysz/react-native-unistyles/tree/main/examples/expo/src/examples/MemoizationScreen.tsx)
+- PlatformColor [link](https://github.com/jpudysz/react-native-unistyles/tree/main/examples/expo/src/examples/PlatformColorsScreen.tsx)
+- Compatibility with StyleSheet [link](https://github.com/jpudysz/react-native-unistyles/tree/main/examples/expo/src/examples/StyleSheetScreen.tsx)
+- useStyles with no arguments [link](https://github.com/jpudysz/react-native-unistyles/tree/main/examples/expo/src/examples/NoStyleSheetScreen.tsx)
+- Advanced nested stylesheeets with perfect TypeScript support [link](https://github.com/jpudysz/react-native-unistyles/tree/main/examples/expo/src/examples/TypeScriptValidatorTest.tsx)
+
+
diff --git a/docs/src/content/docs/index.mdx b/docs/src/content/docs/index.mdx
deleted file mode 100644
index 2c55b4f1..00000000
--- a/docs/src/content/docs/index.mdx
+++ /dev/null
@@ -1,65 +0,0 @@
----
-title: Welcome to Unistyles
-template: splash
-hero:
- tagline: Level up your React Native StyleSheet!
- image:
- file: ../../assets/logo.svg
- actions:
- - text: Get started
- link: /start/setup/
- icon: right-arrow
- variant: primary
- - text: Examples
- link: https://github.com/jpudysz/react-native-unistyles/tree/main/examples
- icon: external
----
-
-import { Card, CardGrid } from '@astrojs/starlight/components'
-import Codemask from '../../components/Codemask.astro'
-import Seo from '../../components/Seo.astro'
-
-
-
- - ⚡ Blazing fast, adds around ~3ms on top of StyleSheet*
- - 🎳 Share up to 100% of your styles across platforms in monorepo
- - 🎯 Doesn't introduce new components
- - 🖥️ Supports custom breakpoints and css-like media queries
- - 🎨 Access theme in your StyleSheets and components
- - 🪄 Supports dynamic functions to access values from JSX
- - 🥳 Compatible with Expo, Expo Go, Bare React Native and React Native Web
- - ⚔️ No 3rd party dependencies
-
- *-based on this [benchmark](https://github.com/efstathiosntonas/react-native-style-libraries-benchmark)
-
-
-
- Read about what drove me to create this library in this blog post [here](https://www.reactnativecrossroads.com/posts/level-up-react-native-styles).
-
-
-
- If you found the `react-native-unistyles` time-saving and valuable, please consider sponsoring my work. Your support enables me to continue creating libraries with a fresh approach.
-
- Github: https://github.com/sponsors/jpudysz
-
- Ko-fi: https://ko-fi.com/jpudysz
-
- Your support is greatly appreciated and helps me dedicate more time and resources to creating quality libraries. Thank you for all the support!
-
-
-
-
diff --git a/docs/src/content/docs/other/for-library-authors.mdx b/docs/src/content/docs/other/for-library-authors.mdx
new file mode 100644
index 00000000..c85bce46
--- /dev/null
+++ b/docs/src/content/docs/other/for-library-authors.mdx
@@ -0,0 +1,119 @@
+---
+title: For library authors
+---
+
+import Seo from '../../../components/Seo.astro'
+
+
+
+Unistyles is highly extensible and can be utilized to build UI Kits and other kinds of projects.
+
+## Using Unistyles in your library
+
+`UnistylesRegistry` can be invoked lazily after resolving user-required configurations, such as themes and plugins.
+
+You can call `UnistylesRegistry` multiple times to override configurations.
+However, keep in mind that `UnistylesRegistry` makes a roundtrip to C++, which can add up to **1ms** of additional setup time for Unistyles.
+
+To manipulate your config without replacing it, you should use [UnistylesRuntime](/reference/unistyles-runtime/).
+
+## Timing
+
+Unistyles core does not have an asynchronous API.
+This means you can invoke `UnistylesRegistry` right before the first `useStyle` call:
+
+```tsx
+import { UnistylesRegistry, useInitialTheme, useStyles } from 'react-native-unistyles'
+
+export const App: React.FunctionComponent = () => {
+ UnistylesRegistry
+ .addConfig(...)
+ .addBreakpoints(...)
+
+ useInitialTheme('dark')
+
+ const { styles } = useStyles(stylesheet)
+
+ return (
+ // your app
+ )
+}
+
+// stylesheet
+```
+
+:::tip
+Registering themes at runtime is also possible, although it is not yet implemented in the core.
+If you need this feature, please open a discussion.
+:::
+
+## Plugins
+
+You can extend Unistyles with your plugins that may transform the output to the desired style.
+Currently, Unistyles supports one lifecycle hook: [onParsedStyle](/reference/plugins/).
+
+## When does Unistyles re-render?
+
+Unistyles only re-renders when it receives an event from C++. This means `useStyles` supports component memoization.
+
+You should expect re-renders only when:
+- The theme changes.
+- The device orientation changes.
+- The screen size changes (web only).
+- A plugin is registered or unregistered.
+- The variant changes.
+
+:::tip
+Storing library config in `UnistylesRuntime` is also a possibility.
+If you need this feature, please open a discussion.
+:::
+
+## No React Context
+
+Unistyles does not use the React Context API. This means that users do not need to wrap their app with a `Provider`,
+reducing boilerplate and making your library more user-friendly.
+
+## New architecture ready
+
+Unistyles handles all native configurations and supports new architecture,
+ensuring you don't need to worry about Fabric or other low-level concepts.
+
+Your UI Kit can support all React Native apps out of the box.
+
+## Minimum requirements
+
+Unistyles is compatible with:
+- React Native version >=0.66
+- TypeScript >4.0
+- iOS 11+
+- Android 5+
+
+## CSS styles
+
+There is ongoing work on custom CSS compiler that could
+entirely replace the React Native Web StyleSheet API,
+offering better Developer Experience (DX) and more predictable re-renders, e.g. with media queries.
+
+Unistyles 2.0 was developed with this feature in mind.
+If you are interested, please open a discussion and share your use case.
+
+## Why choose Unistyles?
+
+Unistyles offers a unique architecture not available in any other library. Built on top of the React Native StyleSheet API, it is fully compatible with it.
+
+Without component abstraction, you have the freedom to build one. Unistyles supports various platforms and is easily extendable, particularly with plugins and variants.
+
+With its smart architecture, you can maintain the same rendering time as the [core](/start/benchmarks/).
+
+:::tip
+If you need any cool feature to support your UI Kit, please open a [discussion](https://github.com/jpudysz/react-native-unistyles/discussions).
+
+I'm happy to help you with your use case!
+:::
+
+
diff --git a/docs/src/content/docs/other/for-sponsors.mdx b/docs/src/content/docs/other/for-sponsors.mdx
new file mode 100644
index 00000000..f4de2952
--- /dev/null
+++ b/docs/src/content/docs/other/for-sponsors.mdx
@@ -0,0 +1,48 @@
+---
+title: For Sponsors
+---
+
+import Seo from '../../../components/Seo.astro'
+
+
+
+:::tip
+Your support can significantly advance the development of Unistyles 2.0 to new heights. We are seeking sponsors to collaborate in creating a more robust, feature-rich library, including the development of a custom compiler.
+:::
+
+### Why sponsor Unistyles?
+
+- **Advancing Innovation**: Your sponsorship helps in the continuous innovation and improvement of Unistyles. This support is crucial for developing new features and maintaining the library
+- **Benefit for Developers and Companies**: Both individual developers and large companies that profit from using Unistyles stand to gain from its enhancements. Your support ensures that Unistyles remains a cutting-edge tool in your development arsenal
+- **Limited Free Time Challenge**: The development of innovative libraries like Unistyles is often constrained by the limited free time of creators. Sponsorship can provide the necessary resources for dedicated development time
+
+### How to sponsor?
+
+- **Github Sponsorship**: [link](https://github.com/sponsors/jpudysz)
+- **Ko-Fi**: [link](https://ko-fi.com/jpudysz)
+
+### Free options
+- **Sharing Unistyles**: A free yet impactful way to support us is by sharing information about Unistyles within your network. Spreading the word helps increase our visibility and user base
+- **Twitter Shoutout**: Give us a shoutout on Twitter. Public endorsements and mentions can significantly boost our project's presence and reach
+
+### Other options
+
+:::tip[Hire Codemask]
+If you're looking to hire a skilled React Native team, Codemask is open for collaboration. We offer expertise and quality in building React Native applications.
+
+[Contact Codemask](https://codemask.com)
+:::
+
+:::tip[Build Native Library]
+ If your company is seeking to build a native library, either as an open-source project or a private one, we are open to being hired for such projects.
+Our expertise ensures that your project's goals are met with the highest standards.
+
+[Contace me](https://x.com/jpudysz)
+:::
+
+
diff --git a/docs/src/content/docs/other/sponsors.mdx b/docs/src/content/docs/other/sponsors.mdx
new file mode 100644
index 00000000..efb7019a
--- /dev/null
+++ b/docs/src/content/docs/other/sponsors.mdx
@@ -0,0 +1,98 @@
+---
+title: Sponsors
+---
+
+import Seo from '../../../components/Seo.astro'
+import Sponsor from '../../../components/Sponsor.astro'
+import { Card } from '@astrojs/starlight/components'
+
+
+
+:::tip
+Do you want to become a sponsor? Read a guide [for sponsors](/other/for-sponsors/).
+:::
+
+### GOLD
+
+🥇
+
+### Silver
+
+
+
+
+
+
+### Bronze
+
+🥉
+
+### Individuals
+
+
+
+
+
+### Contributors
+
+
+
+
+
+
+
+
+
+
+
diff --git a/docs/src/content/docs/reference/breakpoints.mdx b/docs/src/content/docs/reference/breakpoints.mdx
new file mode 100644
index 00000000..3489e26e
--- /dev/null
+++ b/docs/src/content/docs/reference/breakpoints.mdx
@@ -0,0 +1,185 @@
+---
+title: Breakpoints
+---
+
+import Seo from '../../../components/Seo.astro'
+
+
+
+Breakpoints are user-defined key/value pairs that describe the boundaries of screen sizes.
+There's no limit to the number of breakpoints; you can define as many as you want.
+
+### Register breakpoints
+
+To register your breakpoints, create an object with **any** keys:
+
+```tsx
+// breakpoints.ts
+export const breakpoints = {
+ xs: 0,
+ sm: 576,
+ md: 768,
+ lg: 992,
+ xl: 1200,
+ superLarge: 2000,
+ tvLike: 4000
+} as const
+```
+
+The first breakpoint **must** start with `0`. This is required to simulate CSS cascading, e.g., everything below 576px (`sm` breakoint)
+will resolve to `xs` breakpoint.
+
+:::danger
+If you try to register a breakpoint that doesn't start with 0, Unistyles will throw an error:
+
+"You are trying to register breakpoints that don't start from 0"
+:::
+
+If you use TypeScript you need to override the library's type:
+
+```tsx /name/
+import { breakpoints } from './breakpoints'
+
+type AppBreakpoints = typeof breakpoints
+
+declare module 'react-native-unistyles' {
+ export interface UnistylesBreakpoints extends AppBreakpoints {}
+}
+```
+
+Finally, to register the breakpoints, call `UnistylesRegistry`:
+
+```tsx /addBreakpoints/
+import { UnistylesRegistry } from 'react-native-unistyles'
+import { breakpoints } from './breakpoints'
+
+UnistylesRegistry
+ .addBreakpoints(breakpoints)
+```
+
+To learn more follow setup [guide](/start/setup/).
+
+### How to use breakpoints?
+
+Any style can change based on breakpoints. To do this, change a `value` to an `object`:
+
+```diff lang="tsx" /xs/ /sm/ del="backgroundColor: theme.colors.background" ins="backgroundColor: {"
+const stylesheet = createStyleSheet(theme => ({
+ container: {
+ flex: 1,
+ justifyContent: 'center',
+ alignItems: 'center',
+ backgroundColor: theme.colors.background,
+ backgroundColor: {
++ // your breakpoints
++ xs: theme.colors.background,
++ sm: theme.colors.barbie
++ }
+ },
+ text: {
+ color: theme.colors.typography
+ }
+}))
+```
+
+You can even use it with nested objects like `transform` or `shadowOffset`:
+
+```ts /xs/ /sm/ /xl/
+const stylesheet = createStyleSheet(theme => ({
+ container: {
+ flex: 1,
+ justifyContent: 'center',
+ alignItems: 'center',
+ backgroundColor: {
+ xs: theme.colors.background,
+ sm: theme.colors.barbie
+ },
+ transform: [
+ {
+ translateX: 100
+ },
+ {
+ scale: {
+ xs: 1.5,
+ xl: 0.9
+ }
+ }
+ ]
+ }
+}))
+```
+
+Breakpoints are also avilable with [variants](/reference/variants/).
+
+
+### Built-in breakpoints `landscape` and `portrait`
+
+Even if you don't use custom breakpoints, you can still utilize Unistyles' predefined breakpoints available on mobile devices: `portrait` and `landscape`.
+
+- `portrait` will resolve to your device's width in portrait mode
+- `landscape` will resolve to your device's width in landscape mode
+
+:::tip
+These breakpoints are only available on mobile unless you register your own.
+:::
+
+```ts /landscape/ /portrait/
+const stylesheet = createStyleSheet(theme => ({
+ container: {
+ flex: 1,
+ justifyContent: 'center',
+ alignItems: 'center',
+ backgroundColor: {
+ landscape: theme.colors.background,
+ portrait: theme.colors.barbie
+ }
+ }
+}))
+```
+
+### Access the current breakpoint
+
+You can access the current breakpoint with the `useStyles` hook:
+
+```tsx
+const { breakpoint } = useStyles(stylesheet)
+```
+
+or with `UnistylesRuntime`:
+
+```tsx /UnistylesRuntime.breakpoint/
+import { UnistylesRuntime } from 'react-native-unistyles'
+
+// check the current breakpoint
+export const CurrentBreakpoint = () => (
+
+ Current breakpoint is {UnistylesRuntime.breakpoint}
+
+)
+```
+
+### Get registered breakpoints
+
+Access your registered breakpoints object with `UnsitylesRuntime`:
+
+```tsx /UnistylesRuntime.breakpoints/
+import { UnistylesRuntime } from 'react-native-unistyles'
+
+// check the registered breakpoints
+export const RegisteredBreakpoints = () => (
+
+ My registered breakpoint are {JSON.stringify(UnistylesRuntime.breakpoints)}
+
+)
+```
+
+:::tip[UnistylesRuntime]
+UnistylesRuntime is a powerful feature, and you can learn more about it [here](/reference/unistyles-runtime).
+:::
+
+
diff --git a/docs/src/content/docs/reference/compound-variants.mdx b/docs/src/content/docs/reference/compound-variants.mdx
new file mode 100644
index 00000000..9fd036ec
--- /dev/null
+++ b/docs/src/content/docs/reference/compound-variants.mdx
@@ -0,0 +1,120 @@
+---
+title: Compound variants
+---
+
+import Seo from '../../../components/Seo.astro'
+
+
+
+Unistyles does not have first-class support for compound variants, but you can easily create them yourself.
+
+First, you need to define your variants as described in [this guide](/reference/variants).
+
+```tsx /size/ /color/
+const stylesheet = createStyleSheet({
+ container: {
+ variants: {
+ size: {
+ small: {
+ width: 100,
+ height: 100
+ },
+ medium: {
+ width: 200,
+ height: 200
+ },
+ large: {
+ width: 300,
+ height: 300
+ }
+ },
+ color: {
+ red: {
+ backgroundColor: 'red'
+ },
+ green: {
+ backgroundColor: 'green'
+ },
+ blue: {
+ backgroundColor: 'blue'
+ }
+ }
+ }
+ }
+})
+```
+
+The easiest way to create a compound variant is to use the [dynamic function](/reference/dynamic-functions/).
+
+```tsx /size/ /color/
+const stylesheet = createStyleSheet({
+ container: {
+ variants: {
+ size: {
+ small: {
+ width: 100,
+ height: 100
+ },
+ medium: {
+ width: 200,
+ height: 200
+ },
+ large: {
+ width: 300,
+ height: 300
+ }
+ },
+ color: {
+ red: {
+ backgroundColor: 'red'
+ },
+ green: {
+ backgroundColor: 'green'
+ },
+ blue: {
+ backgroundColor: 'blue'
+ }
+ }
+ }
+ },
+ extraStyle = (size, color) => {
+ if (size === 'small' && color === 'red') {
+ return {
+ borderWidth: 1,
+ borderColor: 'black'
+ }
+ }
+
+ if (size === 'medium' && color === 'green') {
+ return {
+ borderWidth: 2,
+ borderColor: 'black'
+ }
+ }
+
+ return {}
+ }
+})
+```
+
+You can now merge both styles into one component, as with the regular `StyleSheet.create`:
+
+```tsx /size/ /color/
+const MyComponent = ({ size, color }) => {
+ const { styles } = useStyles(stylesheet, {
+ size,
+ color
+ })
+
+ return (
+
+ )
+}
+```
+
+
diff --git a/docs/src/content/docs/reference/create-stylesheet.mdx b/docs/src/content/docs/reference/create-stylesheet.mdx
index a512ec63..df02a5a4 100644
--- a/docs/src/content/docs/reference/create-stylesheet.mdx
+++ b/docs/src/content/docs/reference/create-stylesheet.mdx
@@ -10,52 +10,56 @@ import Seo from '../../../components/Seo.astro'
description: 'How to use createStyleSheet from react-native-unistyles'
}}
>
- `createStyleSheet` is interchangeable with `StyleSheet.create`. You can use objects, and it will function identically to its React Native counterpart.
-
- ```ts
- const stylesheet = createStyleSheet({
- container: {
- flex: 1,
- justifyContent: 'center',
- alignItems: 'center',
- },
- })
- ```
- The difference is that you can now use breakpoints and media queries:
-
- ```ts
- const stylesheet = createStyleSheet({
- container: {
- flex: 1,
- justifyContent: 'center',
- alignItems: 'center',
- flexDirection: {
- xs: 'row',
- sm: 'column',
- ':w[800]': 'row'
- }
- },
- })
- ```
-
- `createStyleSheet` also accepts a function, to which the library will inject your theme:
-
- ```ts
- const stylesheet = createStyleSheet(theme => ({
- container: {
- flex: 1,
- justifyContent: 'center',
- alignItems: 'center',
- flexDirection: {
- xs: 'row',
- sm: 'column',
- ':w[800]': 'row'
- },
- backgroundColor: theme.colors.background
- },
- }))
- ```
-
- Importantly, you'll receive the same TypeScript hints as with `StyleSheet.create`!
+
+Utility for building your `StyleSheets` with superpowers.
+It can be imported from the `react-native-unistyles`:
+
+```ts
+import { createStyleSheet } from 'react-native-unistyles'
+```
+
+This tool is interchangeable with React Native's `StyleSheet.create`.
+
+:::tip[Learn more]
+Interested in incrementally migrating from StyleSheet? [Read this guide](/start/migration-from-stylesheet/)
+:::
+
+
+`crateStyleSheet` accepts both `object` or `function`.
+
+### Basic usage (object)
+
+If you pass an object to the `createStyleSheet` it will work the same like with `StyleSheet.create`.
+With this tool you can now use [variants](/reference/variants/), [breakpoints](/reference/breakpoints/) and
+[media queries](/reference/media-queries/).
+
+```ts
+const stylesheet = createStyleSheet({
+ container: {
+ flex: 1,
+ justifyContent: 'center',
+ alignItems: 'center',
+ },
+})
+```
+
+### Basic usage (function)
+
+When you pass a function to `createStyleSheet` it automatically injects a `theme` as the first argument for you.
+
+To register your themes please follow [setup](/start/setup/) and [theming](/reference/theming/) guides.
+
+```ts /theme/
+const stylesheet = createStyleSheet(theme => ({
+ container: {
+ flex: 1,
+ justifyContent: 'center',
+ alignItems: 'center',
+ backgroundColor: theme.colors.background
+ },
+}))
+```
+
+Importantly, you'll receive the same TypeScript hints as with `StyleSheet.create`!
diff --git a/docs/src/content/docs/reference/dynamic-functions.mdx b/docs/src/content/docs/reference/dynamic-functions.mdx
new file mode 100644
index 00000000..c8f86714
--- /dev/null
+++ b/docs/src/content/docs/reference/dynamic-functions.mdx
@@ -0,0 +1,65 @@
+---
+title: Dynamic functions
+---
+
+import Seo from '../../../components/Seo.astro'
+
+
+
+If you need to pass a value from JSX to your `stylesheet` you can do so using a concept called `dynamic function`.
+
+### Usage
+
+To use a dynamic function, change your stylesheet's value from an `object` to a `function`:
+
+```diff lang="tsx" del="container: {" ins="container: () => ({"
+const stylesheet = createStyleSheet(theme => ({
+ container: {
+ container: () => ({
+ backgroundColor: theme.colors.background,
+ flex: 1,
+ justifyContent: 'center,
+ alignItems: 'center'
+- }
++ })
+}))
+```
+
+Now, you can pass any number of arguments, all with TypeScript hints:
+
+```tsx /maxWidth/ /isOdd/
+export const Example = ({ maxWidth, isOdd, children }) => {
+ const { styles } = useStyles(stylesheet)
+
+ return (
+
+ {children}
+
+ )
+}
+
+const stylesheet = createStyleSheet(theme => ({
+ container: (maxWidth: number, isOdd: boolean) => ({
+ backgroundColor: theme.colors.background,
+ flex: 1,
+ justifyContent: 'center,
+ alignItems: 'center',
+ maxWidth,
+ borderBottomWidth: isOdd ? 1 : undefined
+ })
+}))
+```
+
+:::caution
+It's worth mentioning that while using dynamic functions may be convenient,
+you should limit their number to a minimum. There are a few downsides to be aware of:
+- On the web, styles created with dynamic functions are always inlined in the `style` attribute
+- The `container` style from the example above will recompute the styles every time the component re-renders
+:::
+
+
diff --git a/docs/src/content/docs/reference/errors.mdx b/docs/src/content/docs/reference/errors.mdx
new file mode 100644
index 00000000..20d89b13
--- /dev/null
+++ b/docs/src/content/docs/reference/errors.mdx
@@ -0,0 +1,111 @@
+---
+title: Errors
+---
+
+import Seo from '../../../components/Seo.astro'
+
+
+
+Unistyles will only throw errors when it is used incorrectly.
+
+### RuntimeUnavailable
+
+:::danger[RuntimeUnavailable]
+*"Unistyles runtime is not available. Make sure you followed the installation instructions"*
+:::
+
+This error will be thrown if you try to use Unistyles before it was initialized.
+Make sure you followed the installation [setup](/start/setup/).
+
+Still getting this error? Check [FAQ](/reference/faq/).
+
+### ThemeNotFound / ThemeNotRegistered
+
+:::danger[ThemeNotFound / ThemeNotRegistered]
+*"You are trying to get a theme that is not registered with UnistylesRegistry"*
+
+and
+
+*"You are trying to set a theme that was not registered with UnistylesRegistry"*
+:::
+
+
+These errors occur when you call `UnistylesRuntime.setTheme` with a theme that has not been registered with `UnistylesRegistry`.
+This situation can arise if you don't use TypeScript. Confirm that all your themes are registered with `UnistylesRegistry.addThemes` before using them.
+
+### ThemeNotSelected
+
+:::danger[ThemeNotSelected]
+*"Your themes are registered, but you didn't select the initial theme"*
+:::
+
+This error is thrown if you have registered multiple themes but failed to select an initial one.
+
+Follow theming [guide](/reference/theming/) to learn how to select the initial theme.
+
+### ThemesCannotBeEmpty
+
+:::danger[ThemesCannotBeEmpty]
+*"You are trying to register empty themes object"*
+:::
+
+This error occurs if you attempt to register an empty themes object with `UnistylesRegistry.addThemes`.
+
+The `addThemes` method expects a key-value pair with at least one theme.
+
+Follow theming [guide](/reference/theming/) to learn how to register your themes.
+
+If you don't want to use themes, simply don't register them.
+
+### BreakpointsCannotBeEmpty
+
+:::danger[BreakpointsCannotBeEmpty]
+*"You are trying to register empty breakpoints object"*
+:::
+
+This error will be thrown if you try to register empty breakpoints object with `UnistylesRegistry.addBreakpoints`.
+
+Breakpoints are optional, if you don't want to use them, simply don't register them.
+
+### BreakpointsMustStartFromZero
+
+:::danger[BreakpointsMustStartFromZero]
+*"You are trying to register breakpoints that don't start from 0"*
+:::
+
+This error occurs when you attempt to register breakpoints that do not start from 0.
+Begin your first breakpoint with a value of 0 to mimic CSS cascade.
+
+### InvalidPluginName
+
+:::danger[InvalidPluginName]
+*"Plugin name can't start from reserved prefix __unistyles"*
+:::
+
+This error is thrown if you attempt to register a plugin with a name that begins with the `__unistyles` prefix.
+This prefix is reserved for Unistyles' internal plugins.
+
+### DuplicatePluginName
+
+:::danger[DuplicatePluginName]
+*"You are trying to register a plugin with a name that is already registered"*
+:::
+
+This error occurs when you attempt to register a plugin with a name that has already been registered.
+Review your list of plugins. Perhaps you included the same plugin twice? Or, maybe a plugin with the same name has already been created by someone from the community?
+
+### CantRemoveInternalPlugin
+
+:::danger[CantRemoveInternalPlugin]
+*"You are trying to remove an internal unistyles plugin"*
+:::
+
+This error is thrown if you attempt to remove an internal Unistyles plugin.
+Currently, it's not possible to remove internal plugins as they are essential for Unistyles to function properly.
+
+
diff --git a/docs/src/content/docs/reference/faq.mdx b/docs/src/content/docs/reference/faq.mdx
new file mode 100644
index 00000000..759c6697
--- /dev/null
+++ b/docs/src/content/docs/reference/faq.mdx
@@ -0,0 +1,62 @@
+---
+title: FAQ
+---
+
+import { Card, CardGrid } from '@astrojs/starlight/components'
+import Seo from '../../../components/Seo.astro'
+
+
+
+Here, you can find answers to the most frequently asked questions about Unistyles.
+
+### Why Unistyles runtime is not available?
+
+This error occurs when you try to use a Unistyles feature without proper installation.
+
+Possible causes include:
+- Running the app in Expo Go, which is not supported.
+- Running your Expo project without rebuilding it using the `expo prebuild` command
+- Forgetting to execute `pod install` in your bare React Native project
+- Omitting the import of the file where you set up your UnistylesRegistry eg. in your `App.tsx` file
+
+### I'm trying to override library types, but I'm receiving error that react-native-unistyles is not found?
+
+To override types, you must import something from `react-native-unistyles`, such as `UnistylesRegistry`.
+
+### Adaptive mode doesn't work for me
+
+To enable adaptive mode, you need to register two themes named `light` and `dark` and set the `adaptiveThemes` flag to true within `UnistylesRegistry`.
+
+If your app still doesn't automatically switch themes, ensure that:
+- For Expo your `app.json` contains a `userInterfaceStyle` key with the value `automatic`
+- For bare React Native, your `Info.plist` does not have the `UIUserInterfaceStyle` key set to a hardcoded value
+- `Appearance` from `react-native` is set to `null`
+- You have phone with iOS 13+ or Android 10+
+- Your device supports dark mode
+
+### I'm getting some TypeScript error for my stylesheet
+
+This should not occur, but if it does, please create a new issue in the GitHub repository.
+
+Unistyles is built with first-class support for TypeScript, inferring all the types for you.
+There should be no need for extra steps. Please include your stylesheet and the error you're encountering in the issue.
+
+### Does Unistyles support PlatformColor?
+
+Yes, it does! You can even use PlatformColor in your themes!
+
+### Are class components supported?
+
+No, the library only supports functional components.
+If you need support for class components, you would need to create a wrapper component.
+
+### How to use Unistyles with Expo?
+
+Unistyles supports Expo. However, it can't be used with Expo Go.
+
+
diff --git a/docs/src/content/docs/reference/media-queries.mdx b/docs/src/content/docs/reference/media-queries.mdx
new file mode 100644
index 00000000..3def189a
--- /dev/null
+++ b/docs/src/content/docs/reference/media-queries.mdx
@@ -0,0 +1,168 @@
+---
+title: Media Queries
+---
+
+import Seo from '../../../components/Seo.astro'
+
+
+
+Media queries provide more power and allow you to style cross-platform apps with pixel-perfect accuracy.
+
+### Basic usage
+
+To use media queries, you need to import the `mq` utility and convert your value to an `object`:
+
+```diff lang="tsx" /mq/ del="backgroundColor: theme.colors.background," ins="backgroundColor: {"
+import { createStyleSheet, mq } from 'react-native-unistyles'
+
+const stylesheet = createStyleSheet(theme => ({
+ container: {
+ flex: 1,
+ justifyContent: 'center',
+ alignItems: 'center'
+ backgroundColor: theme.colors.background,
+ backgroundColor: {
++ [mq.only.width(240, 380)]: theme.colors.background,
++ [mq.only.width(380)]: theme.colors.barbie
++ }
+ }
+}))
+```
+
+The `mq` utility provides Intellisense for quickly building your media queries.
+
+### Advanced usage
+
+You can also combine `width` media queries with `height` media queries:
+
+```tsx /mq/
+import { createStyleSheet, mq } from 'react-native-unistyles'
+
+const stylesheet = createStyleSheet(theme => ({
+ container: {
+ flex: 1,
+ justifyContent: 'center',
+ alignItems: 'center'
+ backgroundColor: theme.colors.background,
+ backgroundColor: {
+ [mq.width(240, 380).and.height(300)]: theme.colors.background,
+ [mq.width(380).and.height(300)]: theme.colors.barbie
+ }
+ }
+}))
+```
+
+Or use only `height` media queries:
+
+```tsx /mq/
+import { createStyleSheet, mq } from 'react-native-unistyles'
+
+const stylesheet = createStyleSheet(theme => ({
+ container: {
+ flex: 1,
+ justifyContent: 'center',
+ alignItems: 'center'
+ backgroundColor: theme.colors.background,
+ backgroundColor: {
+ [mq.only.height(300, 500)]: theme.colors.background,
+ [mq.only.height(500)]: theme.colors.barbie
+ }
+ }
+}))
+```
+
+You can also reuse your defined [breakpoints](/reference/breakpoints/):
+
+```tsx /xl/
+import { createStyleSheet, mq } from 'react-native-unistyles'
+
+const stylesheet = createStyleSheet(theme => ({
+ container: {
+ flex: 1,
+ justifyContent: 'center',
+ alignItems: 'center'
+ backgroundColor: theme.colors.background,
+ backgroundColor: {
+ [mq.only.height(500)]: theme.colors.background,
+ [mq.only.width(200, 'xl')]: theme.colors.barbie
+ }
+ }
+}))
+```
+
+### Reference
+
+```shell title="Available combinations"
+mq.only.width // target only width
+mq.only.height // target only height
+mq.width(...).and.height(...) // target both width and height
+mq.height(...).and.width(...) // target both height and width
+```
+
+```shell title="Available values"
+(100, 200) // from 100 to 199
+(400, 'xl') // from 400 to 'xl' breakpoint
+('sm', 'md') // from 'sm' to 'md' breakpoint
+(undefined, 1000) // from 0 to 999
+(null, 800) // from 0 to 799
+(500) // from 500 onwards
+```
+
+```shell title="Full example"
+mq.only.width(100, 200) // width from 100 to 199
+mq.height(500).and.width('sm') // heigh from 500 onwards and width from 'sm' breakpoint onwards
+mq.only.height(null, 1000) // height from 0 to 999
+```
+
+:::tip
+If you pass an invalid range to mq utility eg. ('xl', 'sm') or (500, 200) the media query will be marked as invalid and won't be used to resolve your styles.
+:::
+
+### Combining media queries with breakpoints
+
+You can mix media queries with breakpoints, but media queries will always have higher priority:
+
+```tsx
+import { createStyleSheet, mq} from 'react-native-unistyles'
+
+const stylesheet = createStyleSheet(theme => ({
+ container: {
+ flex: 1,
+ justifyContent: 'center',
+ alignItems: 'center'
+ backgroundColor: {
+ sm: theme.colors.background,
+ // Unistyles will firsly resolve to this style, even though sm may be also correct
+ [mq.only.width(200, 'xl')]: theme.colors.barbie
+ }
+ }
+}))
+```
+
+### CSS Media Queries
+
+CSS Media Queries support is only available on the web.
+To use CSS Media Queries set `experimentalCSSMediaQueries` with `UnistylesRegistry`:
+
+```tsx /experimentalCSSMediaQueries/
+import { UnistylesRegistry } from 'react-native-unistyles'
+
+UnistylesRegistry
+ .addConfig({
+ experimentalCSSMediaQueries: true
+ })
+```
+
+:::tip
+CSS Media queries is an experimental feature and doesn't support all properties yet.
+It will be moved to stable in Unistyles 3.0.
+:::
+
+With `experimentalCSSMediaQueries` set to `false`, Unsityles will compute your styles in the JavaScript.
+
+
diff --git a/docs/src/content/docs/reference/plugins.mdx b/docs/src/content/docs/reference/plugins.mdx
new file mode 100644
index 00000000..aff2f424
--- /dev/null
+++ b/docs/src/content/docs/reference/plugins.mdx
@@ -0,0 +1,168 @@
+---
+title: Plugins
+---
+
+import Seo from '../../../components/Seo.astro'
+
+
+
+If you find that Unistyles lacks certain features, you can easily extend its functionality with plugins.
+
+Plugins are functions that accept a style object and return a new style object.
+They are resolved in the order in which they were passed to the `addConfig` function in [UnistylesRegistry](/reference/unistyles-registry).
+
+### Create a plugin
+
+To create a plugin, you need to import the `UnistylesPlugin` type:
+
+```ts
+import type { UnistylesPlugin } from 'react-native-unistyles'
+
+```
+
+Then, create a function that conforms to this type:
+
+```tsx /myPlugin/
+export const myPlugin: UnistylesPlugin = {
+ name: 'myPlugin',
+ onParsedStyle: (key, styles, runtime) => {
+ // parse styles here
+ }
+}
+```
+
+Your plugin must have a unique name; otherwise, it will be rejected from the registry.
+
+:::tip
+Unistyles uses plugins internally, hence you can't prefix your plugin's name with `__unistyles` prefix.
+:::
+
+### onParsedStyle
+
+The `onParsedStyle` function is called for every style object in the stylesheet passed to the `useStyles` hook.
+These objects are processed **after** Unistyles has finished parsing them, so they do not include:
+- variants
+- breakpoints
+- theme
+- media queries
+
+For example:
+
+```tsx /container/ /text/
+const stylesheet = createStyleSheet(theme => ({
+ container: {
+ backgroundColor: theme.colors.primary,
+ padding: 10
+ },
+ text: {
+ color: theme.colors.typography,
+ fontSize: {
+ sm: 12,
+ md: 14
+ }
+ }
+}))
+```
+
+You will get, for instance, the following calls:
+
+```tsx /onParsedStyle/
+onParsedStyle('container', {
+ backgroundColor: 'pink',
+ padding: 10
+}, runtime)
+
+onParsedStyle('text', {
+ color: '#000000',
+ fontSize: 12
+}, runtime)
+```
+
+Your function will be called twice: once for the `container` and once for `text` styles.
+
+| Argument | Type | Description |
+| --- | --- | --- |
+| key | string | Name of the style eg. `container` or `text` |
+| styles | StyleObject | Style object for the corresponding key |
+| runtime | [UnistylesRuntime](/reference/unistyles-runtime/) | Runtime with all required information about your configuration eg. breakpoint, themes etc. |
+
+### Register plugins with `UnistylesRegistry`
+
+Once you have your plugin, you can register it with `UnistylesRegistry`:
+
+```tsx /plugins/
+import { UnistylesRegistry } from 'react-native-unistyles'
+import { myPlugin1 } from './myPlugin1'
+import { myPlugin2 } from './myPlugin2'
+
+UnistylesRegistry
+ .addConfig({
+ plugins: [myPlugin1, myPlugin2]
+ })
+```
+
+
+### Enable plugin at runtime
+
+Unistyles offers the option to register plugins at runtime, allowing you to enable them only for specific components.
+
+```tsx /UnistylesRuntime.addPlugin/
+import { UnistylesRuntime } from 'react-native-unistyles'
+import { myPlugin } from './myPlugin'
+
+export const EnablePlugin: React.FunctionComponent = () => (
+
diff --git a/docs/src/content/docs/reference/server-side-rendering.mdx b/docs/src/content/docs/reference/server-side-rendering.mdx
new file mode 100644
index 00000000..a0385620
--- /dev/null
+++ b/docs/src/content/docs/reference/server-side-rendering.mdx
@@ -0,0 +1,104 @@
+---
+title: Server Side Rendering
+---
+
+import Seo from '../../../components/Seo.astro'
+
+
+
+Unistyles can render styles on the server-side, which is useful, for example, for SEO purposes.
+
+### Server side configuration
+
+You just need to modify the `__document.ts` or `__document.js` file in your project root.
+
+```diff lang="tsx"
+export const getInitialProps = async ({ renderPage }) => {
+ AppRegistry.registerComponent('Main', () => Main)
+
++ UnistylesRegistry
++ .addBreakpoints({
++ xs: 0,
++ sm: 300,
++ md: 500,
++ lg: 800,
++ xl: 1200
++ })
++ .addThemes({
++ light: theme
++ })
+
+ const { getStyleElement } = AppRegistry.getApplication('Main')
+ const page = await renderPage()
+ const styles = [
+ ,
+ getStyleElement()
+ ]
+
+ return { ...page, styles: React.Children.toArray(styles) }
+}
+```
+
+### Client side configuration
+
+You need to import a file where you configured Unistyles with `UnistylesRegistry`.
+Some dynamic features like breakpoint are not available on the server. That's why you need additional configuration with the `isClient` flag.
+
+```tsx /import './styles'/ /isClient/
+import React, { useEffect, useState } from 'react'
+import { View, Text, ActivityIndicator } from 'react-native'
+import { useStyles } from 'react-native-unistyles'
+import './styles'
+
+export const HomeScreen = () => {
+ const { styles, breakpoint, theme } = useStyles(stylesheet)
+ const [isClient, setIsClient] = useState(false)
+
+ useEffect(() => {
+ // this will run only on client side
+ setIsClient(true)
+ }, [])
+
+ return (
+
+
+ Welcome to Expo + Next.js + Unistyles 👋
+
+
+ Current breakpoint: {isClient ? breakpoint : null}
+
+
+ I like {theme.colors.barbie} color
+
+
+
+ Click me 🦄
+
+
+ {!isClient && (
+
+
+
+ )}
+
+ )
+}
+
+const stylesheet = ...
+```
+
+:::caution
+SSR support is still experimental and may not work in all cases.
+It still requires JS to compute your styles.
+
+There is ongoing work to make it work without JS as static styles.
+This feature will land in Unistyles 3.0!
+:::
+
+
+
diff --git a/docs/src/content/docs/reference/theming.mdx b/docs/src/content/docs/reference/theming.mdx
new file mode 100644
index 00000000..ce300dbf
--- /dev/null
+++ b/docs/src/content/docs/reference/theming.mdx
@@ -0,0 +1,260 @@
+---
+title: Theming
+---
+
+import Seo from '../../../components/Seo.astro'
+
+
+
+
+Theming in `Unistyles` differs from other libraries as it doesn't impose any specific syntax.
+
+**Any JavaScript object can be a Unistyles theme**.
+
+There is also no limit to the number of themes. You can even register dozens of them, for example, if your app sells some premium ones.
+
+Theming is optional. If you dont't register themes with [UnistylesRegistry](/reference/unistyles-registry)
+the library will use an empty object by default.
+
+### Create a theme
+
+You can organize your themes however you want:
+
+```tsx
+const myTheme = {
+ // any keys
+ colors: {
+ // your colors
+ },
+ components: {
+ // any number of nesting
+ button: {
+ deepKey: {}
+ }
+ },
+ utils: {
+ // you can even use functions here
+ hexToRGBA: () => {}
+ },
+ // or compute your themes with functions and spread operators
+ ...premiumFeatures,
+ ...getMyColors()
+}
+```
+
+If you use TypeScript you need to override the library's type:
+
+```tsx /name/
+type AppThemes = {
+ name: typeof myTheme
+}
+
+declare module 'react-native-unistyles' {
+ export interface UnistylesThemes extends AppThemes {}
+}
+```
+
+Finally, to register the theme, you need to call `UnistylesRegistry`:
+
+```tsx /name/
+import { UnistylesRegistry } from 'react-native-unistyles'
+import { myTheme } from './themes'
+
+UnistylesRegistry
+ .addThemes({
+ name: myTheme,
+ // you can add more themes here
+ })
+```
+
+Where `name` is the unique name of your theme.
+
+:::tip
+Your themes may have different shapes, but it's generally not recommended.
+:::
+
+### Select theme
+
+If you've registered more than one theme, Unistyles won't know which one is the initial one.
+At this point, you have 3 options:
+
+- If you know the initial theme upfront, select it with `addConfig` from [UnistylesRegistry](/reference/unistyles-registry)
+
+```tsx /initialTheme/
+UnistylesRegistry
+ .addThemes({
+ light: myTheme,
+ premium: premiumTheme
+ })
+ .addConfig({
+ initialTheme: 'premium'
+ })
+```
+
+- If you need to resolve the user-selected theme during runtime, call [useInitialTheme](/reference/use-initial-theme) before
+using your first `useStyles` hook:
+
+```tsx /useInitialTheme/
+import { useInitialTheme, useStyles } from 'react-native-unistyles'
+
+// can be read from any storage eg. MMKV/SQL/FileSystem/Appearance
+const userTheme = ...
+
+useInitialTheme(userTheme)
+
+// useInitialTheme must be called before the first useStyles hook
+// it's so fast that you can even call it in the same component!
+const { styles } = useStyles(stylesheet)
+```
+
+- Use adaptive themes, as mentioned below
+
+:::danger
+Without a selected theme, Unistyles will throw an error:
+
+"Your themes are registered, but you didn't select the initial theme"
+:::
+
+### Get the current theme
+
+To get the current theme, you can either obtain it from the `useStyles` hook:
+
+```tsx /theme/
+const { theme } = useStyles()
+```
+
+or access it in the `createStyleSheet` function:
+
+```tsx /theme/
+const stylesheet = createStyleSheet(theme => ({
+ ...
+}))
+```
+
+### Get the current theme name
+
+To get the current theme name, import `UnistylesRuntime`:
+
+```tsx /UnistylesRuntime.themeName/
+import { UnistylesRuntime } from 'react-native-unistyles'
+
+// access the current theme name in your component
+export const UserTheme = () => (
+
+ Selected theme is {UnistylesRuntime.themeName}
+
+)
+```
+
+### Adaptive themes
+
+Adaptive themes allow Unistyles to automatically manage the selection of your themes based on device scheme settings.
+To enable this, you need to meet two conditions:
+
+- register two themes with reserved names `light` and `dark`:
+
+```tsx /light:/ /dark:/
+UnistylesRegistry
+ .addThemes({
+ light: lightTheme,
+ dark: darkTheme,
+ // you may have more themes
+ })
+```
+
+- Explicitly enable `adaptiveThemes`:
+
+```tsx /adaptiveThemes/
+UnistylesRegistry
+ .addThemes({
+ light: lightTheme,
+ dark: darkTheme,
+ // you may have more themes
+ })
+ .addConfig({
+ adaptiveThemes: true
+ })
+```
+
+### Toggle adaptive themes during runtime
+
+To toggle adaptive theme support at any point, use `UnistylesRuntime`:
+
+```tsx /UnistylesRuntime.setAdaptiveThemes.*/
+import { UnistylesRuntime } from 'react-native-unistyles'
+
+// toggle support for adaptive themes at any point
+export const ToggleAdaptiveThemes = () => (
+ UnistylesRuntime.setAdaptiveThemes(false)}
+ />
+)
+```
+
+### Check if adaptive themes are enabled
+
+To check if adaptive themes are enabled, again use `UnistylesRuntime`:
+
+```tsx /UnistylesRuntime.hasAdaptiveThemes/
+import { UnistylesRuntime } from 'react-native-unistyles'
+
+// check if you've enabled adaptive themes
+export const AdaptiveThemes = () => (
+
+ Adaptive themes are {UnistylesRuntime.hasAdaptiveThemes ? 'enabled' : 'disabled'}
+
+)
+```
+
+### Get device color scheme
+
+Check your device color preference with `UnistylesRuntime`:
+
+```tsx /colorScheme/
+import { UnistylesRuntime } from 'react-native-unistyles'
+
+// check the current device scheme preference
+export const UserTheme = () => (
+
+ My device is using the {UnistylesRuntime.colorScheme} scheme.
+
+)
+```
+
+Available options are: `dark`, `light` or `unspecified` for devices that don't support color schemes.
+
+:::caution
+Unistyles will read your device settings, not user preferences. It's not compatible with the React Native `Appearance` module.
+:::
+
+If your app's theme is not changing based on device settings, please refer to the [FAQ](/reference/faq/)
+
+### Change theme
+
+With Unistyles 2.0, we no longer use a React Context. However, this doesn't mean you can't change the theme.
+In fact, it's even easier as you don't need to re-render the entire app.
+To change the theme at any time, simply call `setTheme` function:
+
+```tsx /UnistylesRuntime.setTheme.*/
+import { UnistylesRuntime } from 'react-native-unistyles'
+
+// change the theme in any component
+export const ChangeTheme = () => (
+ UnistylesRuntime.setTheme('dark')}
+ />
+)
+```
+
+:::tip[UnistylesRuntime]
+UnistylesRuntime is a powerful feature, and you can learn more about it [here](/reference/unistyles-runtime).
+:::
+
+
diff --git a/docs/src/content/docs/reference/unistyles-registry.mdx b/docs/src/content/docs/reference/unistyles-registry.mdx
new file mode 100644
index 00000000..9f8f5a34
--- /dev/null
+++ b/docs/src/content/docs/reference/unistyles-registry.mdx
@@ -0,0 +1,31 @@
+---
+title: Unistyles Registry
+---
+
+import Seo from '../../../components/Seo.astro'
+
+
+
+UnistylesRegistry is a singleton that allows you to register `themes`, `breakpoints` and pass additional `config`.
+
+:::tip
+You should call `UnistylesRegistry` only once in your application. If you want to interact with `Unistyles` during runtime use [UnistylesRuntime](/reference/unistyles-runtime/) instead.
+:::
+
+There is no required timing for when you should call it. It can be done, for example, in your `App.tsx` file or somewhere deeper.
+
+### List of available actions
+
+| Key | Description | Default value | More info |
+|----------|:-------------:|------:|------:|
+| adaptiveThemes | Enable Unistyles to automatically switch between `dark` and `light` themes based on the device settings. | false | [link](/reference/theming/#adaptive-themes) |
+| initialTheme | If you have registered more than one theme and know the initial theme upfront, you can pass the theme name here. | undefined | [link](/reference/theming/#select-theme) |
+| plugins | A list of plugins that Unistyles will call after resolving the StyleSheet. | [] | [link](/reference/plugins/) |
+| experimentalCSSMediaQueries | Web only: Inject CSS media queries instead of inline styles. | false | [link](/reference/web-support/) |
+
+
diff --git a/docs/src/content/docs/reference/unistyles-runtime.mdx b/docs/src/content/docs/reference/unistyles-runtime.mdx
new file mode 100644
index 00000000..38ba4227
--- /dev/null
+++ b/docs/src/content/docs/reference/unistyles-runtime.mdx
@@ -0,0 +1,89 @@
+---
+title: Unistyles Runtime
+---
+
+import Seo from '../../../components/Seo.astro'
+
+
+
+Unistyles Runtime is the most powerful part of Unistyles 2.0.
+It replaces much of the functionality previously handled by the React Native API. It also keeps track of your device dimensions, orientation, theme, preferred scheme, etc.
+
+You can interact with Unistyles via `UnistylesRuntime` in your code.
+
+:::tip
+Unistyles Runtime is a Host Object (created in C++). It's always up to date and allows you to interact with the native side of Unistyles.
+:::
+
+## Usage
+
+You can import `UnistylesRuntime` from `react-native-unistyles`:
+
+```tsx /UnistylesRuntime/
+import { UnistylesRuntime } from 'react-native-unistyles'
+```
+
+and use it anywhere in your code, even outside a component.
+
+## Getters
+
+| Name | Type | Description |
+| ---- | ---- | ----------- |
+| colorScheme | string | Get your device's color scheme. Available options `dark`, `light` or `unspecified` |
+| hasAdaptiveThemes | boolean | Indicates if you have enabled [adaptive themes](/reference/theming#adaptive-themes) |
+| themeName | string | Name of the selected theme or an empty string if you don't use themes |
+| breakpoint | string / undefined | Current breakpoint or always undefined if you don't use breakpoints |
+| breakpoints | Object | Your breakpoints registered with [UnistylesRegistry](/reference/unistyles-registry/) |
+| enabledPlugins | string[] | Names of currently enabled plugins |
+| screen | Object | Screen dimensions |
+| orientation | ScreenOrientation | Your device's orientation |
+
+## Setters
+
+| Name | Type | Description |
+| ---- | ---- | ----------- |
+| setTheme | (themeName: string) => void | Change the current theme |
+| setAdaptiveThemes | (enabled: boolean) => void | Toggle [adaptive themes](/reference/theming#adaptive-themes) |
+| addPlugin | (plugin: UnistylesPlugin) => void | Enable a [plugin](/reference/plugins/) |
+| removePlugin | (plugin: UnistylesPlugin) => void | Disable a [plugin](/reference/plugins/) |
+
+### Why doesn't `UnistylesRuntime` re-render my component?
+
+You should think of `UnistylesRuntime` as a JavaScript object.
+It's not a React component, so it doesn't re-render your component when, for example, screen size or breakpoint changes.
+
+### How to re-render my stylesheets based on `UnistylesRuntime`?
+
+If you use `UnistylesRuntime` in your `createStyleSheet` it will automatically re-render your styles to get the correct values in real-time.
+
+One example could be reading device width and height.
+
+Using `Dimensions` from React Native won't work as intended, as it will always return the same value.
+
+```tsx /UnistylesRuntime/
+import { UnistylesRuntime, createStyleSheet } from 'react-native-unistyles'
+
+// your component
+
+const stylesheet = createStyleSheet(theme => ({
+ container: {
+ backgroundColor: theme.colors.background,
+ width: UnistylesRuntime.screen.width,
+ height: UnistylesRuntime.screen.height
+ }
+}))
+```
+
+:::tip
+Your stylesheets with `UnistylesRuntime` will only be re-rendered when:
+- screen size changes
+- orientation changes
+- breakpoint changes
+:::
+
+
diff --git a/docs/src/content/docs/reference/use-initial-theme.mdx b/docs/src/content/docs/reference/use-initial-theme.mdx
new file mode 100644
index 00000000..618fcc33
--- /dev/null
+++ b/docs/src/content/docs/reference/use-initial-theme.mdx
@@ -0,0 +1,37 @@
+---
+title: useInitialTheme
+---
+
+import Seo from '../../../components/Seo.astro'
+
+
+
+This hook is optional, but its use is required under certain circumstances, as described in the [theming guide](/reference/theming/#select-theme).
+
+If you're using multiple themes and need to determine the initial theme during runtime, this hook is necessary to select the initial theme.
+
+```tsx /useInitialTheme/
+import { useInitialTheme, useStyles } from 'react-native-unistyles'
+
+// can be read from any storage eg. MMKV/SQL/FileSystem/Appearance
+const userTheme = ...
+
+useInitialTheme(userTheme)
+
+// useInitialTheme must be called before the first useStyles hook
+// it's so fast that you can even call it in the same component!
+const { styles } = useStyles(stylesheet)
+```
+
+:::danger
+Without a selected theme, Unistyles will throw an error:
+
+"Your themes are registered, but you didn't select the initial theme"
+:::
+
+
diff --git a/docs/src/content/docs/reference/use-styles.mdx b/docs/src/content/docs/reference/use-styles.mdx
index 31658eb9..be4a4009 100644
--- a/docs/src/content/docs/reference/use-styles.mdx
+++ b/docs/src/content/docs/reference/use-styles.mdx
@@ -1,7 +1,7 @@
---
title: useStyles
---
-
+import { Card } from '@astrojs/starlight/components'
import Seo from '../../../components/Seo.astro'
- `useStyle` ties everything together and handles the heavy lifting. Without `useStyles`, you can't utilize features like:
+
+Hook that ties everything together and handles the heavy lifting.
+
+
+Without `useStyles`, you can't utilize features like:
- breakpoints
- media queries
- themes
+ - variants
+
+
+It can be imported from the `react-native-unistyles`:
+
+```ts
+import { useStyles } from 'react-native-unistyles'
+```
+
+`useStyles` accepts two optional arguments: `stylesheet` and `variants`.
+
+To learn more about variants follow [this guide](/reference/variants/).
+
+### Basic usage (no arguments)
+
+If you need to access your `theme` or the current `breakpoint` in your component you can call `useStyles` without any arguemnts.
+
+```tsx
+const { theme, breakpoint } = useStyles()
+```
+
+### Basic usage (stylesheet)
+
+For more advanced usage, pass your `stylesheet` generated with [createStyleSheet](/reference/create-stylesheet/):
+
+```tsx
+// you can still access theme and current breakpoint
+const { styles, theme, breakpoint } = useStyles(stylesheet)
+```
+
+The `styles` returned are compatible with any React Native component and satisfy the TypeScript type requirements.
+
+### Basic usage (breakpoint)
+
+If you haven't registered your breakpoints with `UnistylesRegistry` it will be always `undefined`.
+Otherwise it's will be defined string like `sm`, `md` or `xl`.
+
+With `breakpoint` you can manipulate the JSX to hide or show some components:
+
+```tsx /breakpoint/
+export const Example = () => {
+ const { styles, breakpoint } = useStyles(stylesheet)
+
+ return (
+
+
+
+
+
+
+
+
+ )
+}
+```
+
+
+:::caution
+Unistyles has no `Hidden` and `Visible` components. It's just an idea to show you what can you achieve.
+:::
+
+
+### Basic usage (theme)
+
+
+Sometimes, you may need to access your `theme` values outside of the stylesheet.
+An example of this could be when working with a built-in React Native Button component.
+
+```tsx /theme/
+import React from 'react'
+import { Button } from 'react-native'
+import { useStyles } from 'react-native-unistyles'
+
+export const Example = () => {
+ const { theme } = useStyles()
+
+ return (
+ {}}
+ />
+ )
+}
+```
- _useStyles_ allows you to skip the `stylesheet` if you only want to access the `theme`:
-
- ```tsx
- const { theme } = useStyles()
- ```
-
- For more advanced usage, pass your `stylesheet` generated with `createStyleSheet`:
-
- ```tsx
- // you can still access theme
- const { styles, theme } = useStyles(stylesheet)
- ```
-
- You can also access the current `breakpoint` to manipulate the JSX or dynamically select your styles:
-
- ```tsx
- // access breakpoint
- const { styles, breakpoint } = useStyles(stylesheet)
-
- // The breakpoint is always defined and is a string. It can be values like sm, md, lg, etc.
- ```
-
- Show or hide components based on breakpoint (with your own implementation of Visible/Hidden components):
-
- ```tsx
- export const Example = () => {
- const { styles, breakpoint } = useStyles(stylesheet)
-
- return (
-
-
-
-
-
-
-
-
- )
- }
- ```
-
- Access styles based on breakpoint (may be helpful for variants):
-
- ```tsx
- export const Example = () => {
- const { styles, breakpoint } = useStyles(stylesheet)
-
- return (
-
- )
- }
-
- const stylesheet = createStyleSheet(theme => ({
- container: {
- flex: 1,
- justifyContent: 'center'
- },
- 'variant-xs': {
- // some xs styles
- },
- 'variant-sm': {
- // some md styles
- },
- // etc.
- }))
- ```
+:::tip[Advanced usage]
+For more advanced usage follow the next guides.
+:::
diff --git a/docs/src/content/docs/reference/variants.mdx b/docs/src/content/docs/reference/variants.mdx
new file mode 100644
index 00000000..30b2e357
--- /dev/null
+++ b/docs/src/content/docs/reference/variants.mdx
@@ -0,0 +1,342 @@
+---
+title: Variants
+---
+
+import Seo from '../../../components/Seo.astro'
+
+
+
+Variants were the most requested feature in version 1.0 and are now available to use!
+You can mix them with other Unistyles features like [media queries](/reference/media-queries/) and d[breakpoints](/reference/breakpoints/).
+
+## Basic usage
+
+Variants are objects that can be nested in any style object:
+
+```tsx /variants:/
+const stylesheet = createStyleSheet(theme => ({
+ container: {
+ backgroundColor: theme.colors.background,
+ variants: {
+ // here you can define your variants
+ }
+ },
+ text: {
+ color: theme.colors.text,
+ variants: {
+ // here you can define other variants!
+ }
+ }
+}))
+```
+
+Variants contain `groups` of atomic variants.
+
+To define a group, first you need to name it and then define variants within it:
+
+```tsx /color/ /size/ /otherGroupName/
+const stylesheet = createStyleSheet(theme => ({
+ container: {
+ flex: 1,
+ variants: {
+ color: {},
+ size: {},
+ otherGroupName: {}
+ }
+ }
+}
+```
+
+These groups will later be used to select your variants, so remember to name them appropriately.
+
+With the given structure, you can now define your variants that can contain any number of styles. You can also use
+`breakpoints`, `media queries` or styles like `transform`:
+
+```tsx /color:/ /size:/ /otherGroupName:/
+const stylesheet = createStyleSheet(theme => ({
+ container: {
+ flex: 1,
+ variants: {
+ color: {
+ primary: {
+ backgroundColor: theme.colors.primary
+ },
+ secondary: {
+ backgroundColor: theme.colors.secondary
+ }
+ },
+ size: {
+ small: {
+ width: 100,
+ height: 100
+ },
+ medium: {
+ width: 200,
+ height: 200
+ },
+ large: {
+ width: 300,
+ height: 300
+ }
+ },
+ otherGroupName: {
+ // other variants
+ }
+ }
+ }
+}
+```
+
+## Selecting variants
+
+With your named groups, you can now select any variant from your stylesheet using the `useStyles` hook:
+
+```tsx /useStyles/ /color/ /size/
+import { useStyles } from 'react-native-unistyles'
+
+const Component = () => {
+ const styles = useStyles(stylesheet, {
+ color: 'primary',
+ size: 'small'
+ })
+
+ return (
+
+ )
+}
+
+const stylesheet = ...
+```
+
+TypeScript will provide perfect autocompletion for your variants, ensuring accuracy!
+
+## Default variant
+
+You can define a `default` variant that will be used when you don't pass any variant to the `useStyles` hook:
+
+```tsx /default/
+const stylesheet = createStyleSheet(theme => ({
+ container: {
+ flex: 1,
+ variants: {
+ color: {
+ primary: {
+ backgroundColor: theme.colors.primary
+ },
+ secondary: {
+ backgroundColor: theme.colors.secondary
+ },
+ default: {
+ backgroundColor: theme.colors.barbie
+ }
+ }
+ }
+ }
+}
+```
+
+## Options to select the variant
+
+If you pass `undefined` or `empty object` Unsityles will try to find the `default` variant in your stylesheet:
+
+```tsx /undefined/ /{}/
+const { styles } = useStyles(stylesheet, undefined) // will use default variant (if any)
+const { styles } = useStyles(stylesheet, {}) // will use default variant (if any)
+```
+
+Passing an object with named keys and `undefined` will work the same way dafaulting to the `default` option:
+
+```tsx /undefined/
+const { styles } = useStyles(stylesheet, {
+ color: undefined // will use default variant (if any)
+})
+```
+
+Lastly, you can pass the correct variant name for a variant group:
+
+```tsx /secondary/
+const { styles } = useStyles(stylesheet, {
+ color: 'secondary' // will use secondary variant
+})
+```
+
+## Pass variants as component props
+
+Variants were designed to be used as component props:
+
+```tsx /color/ /size/
+import React from 'react'
+import { useStyles } from 'react-native-unistyles'
+
+enum Color = {
+ primary = 'primary',
+ secondary = 'secondary'
+}
+
+enum Size = {
+ small = 'small',
+ medium = 'medium',
+ large = 'large'
+}
+
+type ComponentProps = {
+ color: Color
+ size: Size
+}
+
+const Component: React.FunctionComponent = ({ color, size }) => {
+ const { styles } = useStyles(stylesheet, {
+ color,
+ size
+ })
+
+ return (
+
+ )
+}
+```
+
+:::tip
+Unistyles will automatically re-render if your variant props change.
+:::
+
+## Defining the same variant across multiple styles
+
+It's possible to define the same variant group across multiple styles:
+
+```tsx /size:/
+const stylesheet = createStyleSheet(theme => ({
+ container: {
+ flex: 1,
+ variants: {
+ size: {
+ small: {
+ width: 100,
+ height: 100
+ },
+ medium: {
+ width: 200,
+ height: 200
+ },
+ large: {
+ width: 300,
+ height: 300
+ }
+ }
+ }
+ },
+ text: {
+ fontWeight: 'bold',
+ variants: {
+ size: {
+ small: {
+ fontSize: 12
+ },
+ medium: {
+ fontSize: 16
+ },
+ large: {
+ fontSize: 20
+ }
+ }
+ }
+ }
+}
+```
+
+:::caution
+Unistyles will work as intended, selecting the correct variant for each style.
+However, you need to repeat all your options like `small`, `medium`, and `large` in each style to avoid TypeScript errors.
+:::
+
+```tsx /size:/ /missing medium and large variants!/
+const stylesheet = createStyleSheet(theme => ({
+ container: {
+ flex: 1,
+ variants: {
+ size: {
+ small: {
+ width: 100,
+ height: 100
+ },
+ medium: {
+ width: 200,
+ height: 200
+ },
+ large: {
+ width: 300,
+ height: 300
+ }
+ }
+ }
+ },
+ text: {
+ fontWeight: 'bold',
+ variants: {
+ size: {
+ small: {
+ fontSize: 12
+ },
+ // missing medium and large variants!
+ }
+ }
+ }
+}
+```
+
+In this case, the generated TypeScript type will be:
+
+```
+size: ('small' | 'medium' | 'large') | ('small')
+```
+
+If you don't need all variants and want the correct type, please add empty variants:
+
+```tsx /size:/
+const stylesheet = createStyleSheet(theme => ({
+ container: {
+ flex: 1,
+ variants: {
+ size: {
+ small: {
+ width: 100,
+ height: 100
+ },
+ medium: {
+ width: 200,
+ height: 200
+ },
+ large: {
+ width: 300,
+ height: 300
+ }
+ }
+ }
+ },
+ text: {
+ fontWeight: 'bold',
+ variants: {
+ size: {
+ small: {
+ fontSize: 12
+ },
+ medium: {},
+ large: {}
+ }
+ }
+ }
+}
+```
+
+The generated TypeScript type will then be:
+
+```
+size: ('small' | 'medium' | 'large')
+```
+
+
diff --git a/docs/src/content/docs/reference/web-support.mdx b/docs/src/content/docs/reference/web-support.mdx
new file mode 100644
index 00000000..ac78222c
--- /dev/null
+++ b/docs/src/content/docs/reference/web-support.mdx
@@ -0,0 +1,27 @@
+---
+title: Web support
+---
+
+import Seo from '../../../components/Seo.astro'
+
+
+
+Unistyles offers first-class support for `React Native Web`.
+No additional configuration is needed to use it. Your stylesheets will function identically on both mobile and web platforms.
+
+### CSS Media Queries
+
+By default, Unistyles will re-evaluate your media queries in JavaScript. However, there is an option to delegate this responsibility to the browser using CSS Media Queries.
+
+To enable this feature, set `experimentalCSSMediaQueries` to `true` in your [UnistylesRegistry](/reference/unistyles-registry/).
+
+:::caution
+This feature is experimental and might not work in all cases. It was developed to showcase a preview of what Unistyles 3.0 will be capable of.
+:::
+
+
diff --git a/docs/src/content/docs/show-case/projects.mdx b/docs/src/content/docs/show-case/projects.mdx
new file mode 100644
index 00000000..55098e73
--- /dev/null
+++ b/docs/src/content/docs/show-case/projects.mdx
@@ -0,0 +1,49 @@
+---
+title: Projects
+---
+
+import Seo from '../../../components/Seo.astro'
+
+
+
+### Community Projects Built with Unistyles 2.0
+
+:::tip
+We're excited to showcase the amazing projects that our community will buid using Unistyles 2.0.
+
+This is a great opportunity for you to gain more visibility for your work and for everyone to see the potential and versatility of Unistyles 2.0 in action.
+
+:::
+
+### How to Share Your Project?
+
+If you've built a project using Unistyles 2.0 and want to share it with the community, here’s how you can do it:
+
+- [Discord](https://discord.gg/akGHf27P4C) - Send a direct message to me on Discord
+- [Twitter](https://x.com/jpudysz) - Tag me in your project posts on Twitter
+- [Email](mailto:contact@reactnativecrossroads.com) - Send an email with details about your project
+
+
+### Why Share Your Project?
+
+- **Visibility**: Get your project in front of a wide audience of developers and potential users
+- **Feedback**: Receive valuable feedback from the community to help improve your project
+- **Inspiration**: Inspire others with what you’ve achieved and show the capabilities of Unistyles 2.0
+- **Connect**: Connect with other developers, which can lead to collaborations and new opportunities
+
+### What to Include in Your Submission?
+
+- A brief description of your project.
+- Key features and how Unistyles 2.0 has been utilized
+- Links to the project repository, live demos, or any relevant resources
+- Screenshots or videos showcasing your project
+- Any other information you think might be interesting or useful to the community
+
+We're looking forward to seeing your incredible projects and sharing them with the wider Unistyles community! Your contributions not only demonstrate the power of Unistyles 2.0 but also help inspire and guide new users.
+
+
diff --git a/docs/src/content/docs/show-case/ui-kits.mdx b/docs/src/content/docs/show-case/ui-kits.mdx
new file mode 100644
index 00000000..efde0602
--- /dev/null
+++ b/docs/src/content/docs/show-case/ui-kits.mdx
@@ -0,0 +1,48 @@
+---
+title: UI Kits
+---
+
+import Seo from '../../../components/Seo.astro'
+
+
+
+### UI Kits built with Unistyles 2.0
+
+:::tip
+We're excited to showcase all UI Kits that our community will buid using Unistyles 2.0.
+
+This is a great opportunity for you to gain more visibility for your work and for everyone to see the potential and versatility of Unistyles 2.0 in action.
+:::
+
+### How to Share Your UI Kit?
+
+If you've built a UI Kit using Unistyles 2.0 and want to share it with the community, here’s how you can do it:
+
+- [Discord](https://discord.gg/akGHf27P4C) - Send a direct message to me on Discord
+- [Twitter](https://x.com/jpudysz) - Tag me in your project posts on Twitter
+- [Email](mailto:contact@reactnativecrossroads.com) - Send an email with details about your project
+
+### Why Share Your UI Kit?
+
+- **Visibility**: Expose your UI Kit to a broad audience, including developers and potential users
+- **Feedback**: Gain valuable insights and feedback from the community to refine your UI Kit
+- **Inspiration**: Your work can inspire others and demonstrate the extensive capabilities of Unistyles 2.0
+- **Networking**: Connect with fellow developers and open doors to potential collaborations and new opportunities
+
+
+### What to Include in Your Submission?
+- A brief introduction to your UI Kit
+- Key features and the integration of Unistyles 2.0 in your UI Kit
+- Links to the UI Kit repository, live demos, or any relevant resources
+- Screenshots, videos, or other media showcasing the UI Kit
+- Any other details you think will interest or benefit the community
+
+
+We can't wait to see your innovative UI Kits and share them with our extensive Unistyles community! Your creations not only showcase the versatility of Unistyles 2.0 but also serve as a valuable resource and inspiration for others in the field.
+
+
diff --git a/docs/src/content/docs/start/basic-usage.mdx b/docs/src/content/docs/start/basic-usage.mdx
index eca665b2..08557455 100644
--- a/docs/src/content/docs/start/basic-usage.mdx
+++ b/docs/src/content/docs/start/basic-usage.mdx
@@ -8,23 +8,25 @@ import Seo from '../../../components/Seo.astro'
-
- After the initial setup, you only need to focus on two functions responsible for your styles:
- - `createStyleSheet` which replaces `StyleSheet.create`
- - `useStyles` which parses your styles and ensures TypeScript compatibility with media queries and breakpoints
-
-
- ```tsx
+
+
+:::tip[Did you know?]
+The library was designed to keep your components clean.
+You don't need to worry about importing custom components or creating styles based on an opinionated syntax.
+:::
+
+After the initial setup, you only need to focus on two functions responsible for your styles:
+
+- `createStyleSheet` which replaces `StyleSheet.create`
+- `useStyles` which parses your styles and ensures TypeScript compatibility with media queries and breakpoints
+
+ ```tsx title="Simple example with theming"
import React from 'react'
import { View, Text } from 'react-native'
- // access createStyleSheet and useStyles exported from factory
- import { createStyleSheet, useStyles } from 'lib/styles'
+ import { createStyleSheet, useStyles } from 'react-native-unistyles'
export const ExampleUnistyles = () => {
const { styles } = useStyles(stylesheet)
@@ -49,5 +51,5 @@ import Seo from '../../../components/Seo.astro'
color: theme.colors.typography
}
}))
-```
+ ```
diff --git a/docs/src/content/docs/start/benchmarks.mdx b/docs/src/content/docs/start/benchmarks.mdx
new file mode 100644
index 00000000..0da5650b
--- /dev/null
+++ b/docs/src/content/docs/start/benchmarks.mdx
@@ -0,0 +1,86 @@
+---
+title: Benchamarks
+---
+
+import { Card } from '@astrojs/starlight/components'
+import Seo from '../../../components/Seo.astro'
+import Benchmark1 from '../../../assets/benchmark-1.png'
+import Benchmark2 from '../../../assets/benchmark-2.png'
+import Benchmark3 from '../../../assets/benchmark-3.png'
+import Benchmark4 from '../../../assets/benchmark-4.png'
+import Benchmark5 from '../../../assets/benchmark-5.png'
+
+
+
+ In this guide, I will try to explain what you can expect from Unistyles and the potential render penalty when using it in your project.
+
+ As developers, we appreciate powerful libraries that address all our needs in terms of syntax, scalability, and cross-platform support.
+ Unistyles was designed to be the fastest styling solution on the market. Before we delve further, it's important to note that this library is not a UI Kit.
+ It provides low-level functionality for developers who either want full control of styling in their commercial projects or for library authors to build UI Kits on top of it.
+
+
+It's also worth mentioning that there won't be a faster way than passing your objects to `StyleSheet.create`.
+Unfortunately, the functionalities of StyleSheet are limited. Building a fully-featured, cross-platform app without some additional help is challenging.
+
+:::caution
+Benchmarks are publicly available in the Unistyles 2.0 repository and were measured in release mode.
+:::
+
+### Startup time
+
+
+
+
+:::tip[Initialization time]
+The startup time of Unistyles 2.x is about 0.2 ms slower than Unistyles 1.x due to an additional roundtrip to C++.
+:::
+
+### Most popular benchamrk in the RN community
+
+Many libraries utilize a test to render 1000 views styled with each respective library.
+You can find them [here](https://github.com/efstathiosntonas/react-native-style-libraries-benchmark)
+and [here](https://gluestack.io/ui/docs/performance/benchmarks).
+
+Unistyles will consistently be the fastest solution compared to these alternatives because it avoids
+abstraction in components and parses the StyleSheet just once for the 1000 views.
+
+
+
+### Rendering 100 useStyles hooks
+
+Let's modify the benchmark to create a more challenging scenario for Unistyles. We'll render 100 StyleSheets vs 100 `useStyles` hooks.
+This scenario is designed to represent the worst-case scenario for a production app, which simultaneously mounts 100 individual components, each with separate StyleSheets.
+
+
+
+The performance overhead of Unistyles 2.x, when compared to StyleSheet, is approximately **0.03 milliseconds per view**.
+This number was determined by subtracting the average time of StyleSheet from that of Unistyles 2.x and then dividing the result by the number of views.
+
+### Rendering large lists with 1000 items
+
+Let's delve deeper and consider a scenario where your app needs to render up to 1000 separate views using the useStyles hook.
+This might simulate a complex app featuring a non-virtualized list.
+
+
+
+This benchmark illustrates the scenario for using traditional StyleSheets vs Unistyles 2.x in rendering large lists in React Native applications. We can also observe that as the number of views increases, the performance overhead decreases in favor of Unistyles 2.x.
+This time, the cost per view is approximately **0.01 milliseconds per view**.
+
+### Rendering large list with all features
+
+In the final benchmark, we compare the performance of a plain StyleSheet against Unistyles 2.x, which incorporates a comprehensive range of features. Unistyles 2.x is tested with three registered themes,
+breakpoints, and the full utilization of all its features: media queries (mq), breakpoints, variants, and theme integration.
+
+
+
+:::tip[Rendering time]
+Did you know that a blink of the eye takes around 120ms?
+Unistyles can render your 1000 views in an even shorter period of time! 👀
+:::
+
+
diff --git a/docs/src/content/docs/start/introduction.mdx b/docs/src/content/docs/start/introduction.mdx
new file mode 100644
index 00000000..bc7d4aa3
--- /dev/null
+++ b/docs/src/content/docs/start/introduction.mdx
@@ -0,0 +1,95 @@
+---
+title: Introduction
+---
+
+import { Card, Tabs, TabItem, CardGrid, Icon } from '@astrojs/starlight/components'
+import Seo from '../../../components/Seo.astro'
+import Logo from '../../../assets/logo.svg'
+
+
+
+