diff --git a/.changepacks/changepack_log_react_native_css.json b/.changepacks/changepack_log_react_native_css.json new file mode 100644 index 000000000..77bab2bf9 --- /dev/null +++ b/.changepacks/changepack_log_react_native_css.json @@ -0,0 +1,8 @@ +{ + "changes": { + "bindings/devup-ui-binding/package.json": "Patch", + "bindings/devup-ui-wasm/package.json": "Patch" + }, + "note": "`codeExtractNative` compiles `css()` for React Native (part of #411): a call compiles to the style it describes, the value React Native's `style` takes, and `className` on a Devup UI element passes it on before the element's style props. `css()` takes objects of style props with responsive values, theme tokens and blocks, conditions choosing between objects, what another `css()` gives, and CSS text whose interpolations are whole values. A `css()` whose styles differ by theme, breakpoint or orientation must be called in a function component or a hook. A `style` prop holding Devup UI elements or `css()` calls now compiles them too. Web output is unchanged.", + "date": "2026-11-21T00:00:00.000Z" +} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 2bf0a8564..e1017f857 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -11,6 +11,7 @@ on: - feat/react-native-metro - feat/react-native-themes - feat/react-native-responsive + - feat/react-native-pressed # Pull requests and every job below run read-only. Only the `release` and # `deploy-pages` jobs get write permissions, and they run on pushes to main diff --git a/apps/expo/src/App.tsx b/apps/expo/src/App.tsx index 624128e25..6d8174a5f 100644 --- a/apps/expo/src/App.tsx +++ b/apps/expo/src/App.tsx @@ -1,6 +1,7 @@ import { Box, Button, + css, Flex, Image, Input, @@ -12,6 +13,9 @@ import { useState } from 'react' import { Badge } from './Badge' +/** The shape both buttons share */ +const button = css({ borderRadius: '8px', px: 5, py: 3 }) + export function App() { const [name, setName] = useState('') const [count, setCount] = useState(0) @@ -69,10 +73,8 @@ export function App() { + ) +} +``` + +`css()` takes what it does on the web: objects of style props (with +responsive values, theme tokens and the theme, platform and orientation +blocks), conditions choosing between them, what another `css()` gives, and +CSS text (`` css`padding: 8px; background-color: $primary;` ``, each +interpolation a whole value). The element's style props apply after its +`className`, and its `style` prop last. + +A `css()` whose styles differ by theme, breakpoint or orientation reads the +runtime, so it must be called in a function component or a hook. One that does +not can be called anywhere, such as at the top of the file. These are build +errors: + +- a class name (`className="p-4"`, `css('p-4')`) +- a press style in `css()`: give `_active` to the element itself +- selectors, nesting and at-rules in CSS text + +`css()` gives a style rather than a class on React Native, so pass it to +`className`, not to the `style` of a React Native component, which TypeScript +types as a string. + ## Limits of this version Only styles the build can decide are supported: literals, values read at runtime, theme tokens, responsive values, conditions between them and the -platform, theme and orientation blocks. These are build errors, reported by -Metro at the file, line and column: +platform, theme, orientation and press blocks, and `css()`. These are build +errors, reported by Metro at the file, line and column: - interaction states other than `_active`/`_pressed` (`_hover`, `_focus`, ...) -- `css()`, `styled()`, `globalCss()`, `keyframes()` and `Grid` +- `styled()`, `globalCss()`, `keyframes()` and `Grid` - any prop React Native has no style for - with `runtime: false`, a value that differs by theme or breakpoint, `_theme*` with more than one theme, `_portrait`, `_landscape`, and