@scalewing/react-native 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/README.md +15 -0
- package/dist/alignment.d.ts +5 -0
- package/dist/alignment.js +12 -0
- package/dist/components/Box.d.ts +11 -0
- package/dist/components/Box.js +24 -0
- package/dist/components/Card.d.ts +8 -0
- package/dist/components/Card.js +18 -0
- package/dist/components/Inline.d.ts +10 -0
- package/dist/components/Inline.js +14 -0
- package/dist/components/Stack.d.ts +10 -0
- package/dist/components/Stack.js +13 -0
- package/dist/components/Text.d.ts +8 -0
- package/dist/components/Text.js +17 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +6 -0
- package/dist/map-spacing-style.d.ts +22 -0
- package/dist/map-spacing-style.js +28 -0
- package/dist/theme/ThemeProvider.d.ts +9 -0
- package/dist/theme/ThemeProvider.js +18 -0
- package/package.json +52 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Scalewing contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @scalewing/react-native
|
|
2
|
+
|
|
3
|
+
React Native / Expo primitives that consume the same Scalewing tokens as the DOM package.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { Card, Stack, Text, ThemeProvider } from '@scalewing/react-native';
|
|
7
|
+
|
|
8
|
+
<Card padding={4}>
|
|
9
|
+
<Text variant="title">Kickoff</Text>
|
|
10
|
+
</Card>
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
There is no CSS class API. `padding={4}` is spacing step 4, the same step as `sw-padding-4` on web.
|
|
14
|
+
|
|
15
|
+
React and React Native are peer dependencies so the host Expo app owns the runtime. Rationale: duplicating React Native inside this package would fight Metro and Expo upgrades.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type FlexAlignType, type FlexStyle } from 'react-native';
|
|
2
|
+
export type Align = 'start' | 'center' | 'end' | 'stretch';
|
|
3
|
+
export type Justify = 'start' | 'center' | 'end' | 'between';
|
|
4
|
+
export declare const alignItems: Record<Align, FlexAlignType>;
|
|
5
|
+
export declare const justifyContent: Record<Justify, FlexStyle['justifyContent']>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type RadiusStep, type SemanticColorKey } from '@scalewing/tokens';
|
|
2
|
+
import { type ReactNode } from 'react';
|
|
3
|
+
import { type ViewProps } from 'react-native';
|
|
4
|
+
import { type SpacingProps } from '../map-spacing-style.js';
|
|
5
|
+
export type BoxProps = SpacingProps & ViewProps & {
|
|
6
|
+
background?: Extract<SemanticColorKey, 'background' | 'surface'>;
|
|
7
|
+
border?: boolean;
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
radius?: RadiusStep;
|
|
10
|
+
};
|
|
11
|
+
export declare function Box({ background, border, padding, paddingBottom, paddingLeft, paddingRight, paddingTop, paddingX, paddingY, gap, radius, style, ...rest }: BoxProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import { mapSpacingStyle } from '../map-spacing-style.js';
|
|
4
|
+
import { useTheme } from '../theme/ThemeProvider.js';
|
|
5
|
+
export function Box({ background, border, padding, paddingBottom, paddingLeft, paddingRight, paddingTop, paddingX, paddingY, gap, radius, style, ...rest }) {
|
|
6
|
+
const theme = useTheme();
|
|
7
|
+
const resolvedStyle = {
|
|
8
|
+
...mapSpacingStyle(theme, {
|
|
9
|
+
gap,
|
|
10
|
+
padding,
|
|
11
|
+
paddingBottom,
|
|
12
|
+
paddingLeft,
|
|
13
|
+
paddingRight,
|
|
14
|
+
paddingTop,
|
|
15
|
+
paddingX,
|
|
16
|
+
paddingY,
|
|
17
|
+
}),
|
|
18
|
+
backgroundColor: background ? theme.colors[background] : undefined,
|
|
19
|
+
borderColor: border ? theme.colors.border : undefined,
|
|
20
|
+
borderRadius: radius ? theme.radius[radius] : undefined,
|
|
21
|
+
borderWidth: border ? 1 : undefined,
|
|
22
|
+
};
|
|
23
|
+
return _jsx(View, { style: [resolvedStyle, style], ...rest });
|
|
24
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type SpacingStep } from '@scalewing/tokens';
|
|
2
|
+
import { type BoxProps } from './Box.js';
|
|
3
|
+
export type CardVariant = 'outlined' | 'elevated';
|
|
4
|
+
export type CardProps = BoxProps & {
|
|
5
|
+
padding?: SpacingStep;
|
|
6
|
+
variant?: CardVariant;
|
|
7
|
+
};
|
|
8
|
+
export declare function Card({ padding, style, variant, ...rest }: CardProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Box } from './Box.js';
|
|
3
|
+
import { useTheme } from '../theme/ThemeProvider.js';
|
|
4
|
+
export function Card({ padding = 4, style, variant = 'outlined', ...rest }) {
|
|
5
|
+
const theme = useTheme();
|
|
6
|
+
return (_jsx(Box, { background: "surface", border: variant === 'outlined', padding: padding, radius: "md", style: [
|
|
7
|
+
variant === 'elevated'
|
|
8
|
+
? {
|
|
9
|
+
shadowColor: theme.colors.text,
|
|
10
|
+
shadowOffset: { height: 8, width: 0 },
|
|
11
|
+
shadowOpacity: 0.12,
|
|
12
|
+
shadowRadius: 16,
|
|
13
|
+
elevation: 3,
|
|
14
|
+
}
|
|
15
|
+
: undefined,
|
|
16
|
+
style,
|
|
17
|
+
], ...rest }));
|
|
18
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type SpacingStep } from '@scalewing/tokens';
|
|
2
|
+
import { type Align, type Justify } from '../alignment.js';
|
|
3
|
+
import { type BoxProps } from './Box.js';
|
|
4
|
+
export type InlineProps = BoxProps & {
|
|
5
|
+
align?: Align;
|
|
6
|
+
gap?: SpacingStep;
|
|
7
|
+
justify?: Justify;
|
|
8
|
+
wrap?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare function Inline({ align, gap, justify, style, wrap, ...rest }: InlineProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { alignItems, justifyContent, } from '../alignment.js';
|
|
3
|
+
import { Box } from './Box.js';
|
|
4
|
+
export function Inline({ align = 'center', gap = 0, justify = 'start', style, wrap = false, ...rest }) {
|
|
5
|
+
return (_jsx(Box, { gap: gap, style: [
|
|
6
|
+
{
|
|
7
|
+
alignItems: alignItems[align],
|
|
8
|
+
flexDirection: 'row',
|
|
9
|
+
flexWrap: wrap ? 'wrap' : 'nowrap',
|
|
10
|
+
justifyContent: justifyContent[justify],
|
|
11
|
+
},
|
|
12
|
+
style,
|
|
13
|
+
], ...rest }));
|
|
14
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type SpacingStep } from '@scalewing/tokens';
|
|
2
|
+
import { type Align, type Justify } from '../alignment.js';
|
|
3
|
+
import { type BoxProps } from './Box.js';
|
|
4
|
+
export type { Align, Justify };
|
|
5
|
+
export type StackProps = BoxProps & {
|
|
6
|
+
align?: Align;
|
|
7
|
+
gap?: SpacingStep;
|
|
8
|
+
justify?: Justify;
|
|
9
|
+
};
|
|
10
|
+
export declare function Stack({ align, gap, justify, style, ...rest }: StackProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { alignItems, justifyContent, } from '../alignment.js';
|
|
3
|
+
import { Box } from './Box.js';
|
|
4
|
+
export function Stack({ align = 'stretch', gap = 0, justify = 'start', style, ...rest }) {
|
|
5
|
+
return (_jsx(Box, { gap: gap, style: [
|
|
6
|
+
{
|
|
7
|
+
alignItems: alignItems[align],
|
|
8
|
+
flexDirection: 'column',
|
|
9
|
+
justifyContent: justifyContent[justify],
|
|
10
|
+
},
|
|
11
|
+
style,
|
|
12
|
+
], ...rest }));
|
|
13
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type SemanticColorKey, type TypographyVariant } from '@scalewing/tokens';
|
|
2
|
+
import { type TextProps as NativeTextProps } from 'react-native';
|
|
3
|
+
export type TextProps = NativeTextProps & {
|
|
4
|
+
color?: SemanticColorKey;
|
|
5
|
+
truncate?: boolean;
|
|
6
|
+
variant?: TypographyVariant;
|
|
7
|
+
};
|
|
8
|
+
export declare function Text({ color, style, truncate, variant, ...rest }: TextProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Text as NativeText, } from 'react-native';
|
|
3
|
+
import { useTheme } from '../theme/ThemeProvider.js';
|
|
4
|
+
export function Text({ color = 'text', style, truncate = false, variant = 'body', ...rest }) {
|
|
5
|
+
const theme = useTheme();
|
|
6
|
+
const type = theme.typography[variant];
|
|
7
|
+
return (_jsx(NativeText, { numberOfLines: truncate ? 1 : undefined, style: [
|
|
8
|
+
{
|
|
9
|
+
color: theme.colors[color],
|
|
10
|
+
fontSize: type.fontSize,
|
|
11
|
+
fontWeight: String(type.fontWeight),
|
|
12
|
+
letterSpacing: type.letterSpacing,
|
|
13
|
+
lineHeight: type.lineHeight,
|
|
14
|
+
},
|
|
15
|
+
style,
|
|
16
|
+
], ...rest }));
|
|
17
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Box, type BoxProps } from './components/Box.js';
|
|
2
|
+
export { Card, type CardProps, type CardVariant } from './components/Card.js';
|
|
3
|
+
export { Inline, type InlineProps } from './components/Inline.js';
|
|
4
|
+
export { Stack, type StackProps } from './components/Stack.js';
|
|
5
|
+
export { type Align, type Justify } from './alignment.js';
|
|
6
|
+
export { Text, type TextProps } from './components/Text.js';
|
|
7
|
+
export { ThemeProvider, useTheme, type ThemeProviderProps, } from './theme/ThemeProvider.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { Box } from './components/Box.js';
|
|
2
|
+
export { Card } from './components/Card.js';
|
|
3
|
+
export { Inline } from './components/Inline.js';
|
|
4
|
+
export { Stack } from './components/Stack.js';
|
|
5
|
+
export { Text } from './components/Text.js';
|
|
6
|
+
export { ThemeProvider, useTheme, } from './theme/ThemeProvider.js';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type SpacingStep, type Theme } from '@scalewing/tokens';
|
|
2
|
+
export type SpacingProps = {
|
|
3
|
+
padding?: SpacingStep;
|
|
4
|
+
paddingX?: SpacingStep;
|
|
5
|
+
paddingY?: SpacingStep;
|
|
6
|
+
paddingTop?: SpacingStep;
|
|
7
|
+
paddingRight?: SpacingStep;
|
|
8
|
+
paddingBottom?: SpacingStep;
|
|
9
|
+
paddingLeft?: SpacingStep;
|
|
10
|
+
gap?: SpacingStep;
|
|
11
|
+
};
|
|
12
|
+
export type NativeSpacingStyle = {
|
|
13
|
+
padding?: number;
|
|
14
|
+
paddingHorizontal?: number;
|
|
15
|
+
paddingVertical?: number;
|
|
16
|
+
paddingTop?: number;
|
|
17
|
+
paddingRight?: number;
|
|
18
|
+
paddingBottom?: number;
|
|
19
|
+
paddingLeft?: number;
|
|
20
|
+
gap?: number;
|
|
21
|
+
};
|
|
22
|
+
export declare function mapSpacingStyle(theme: Theme, props: SpacingProps): NativeSpacingStyle;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export function mapSpacingStyle(theme, props) {
|
|
2
|
+
const style = {};
|
|
3
|
+
if (props.padding !== undefined) {
|
|
4
|
+
style.padding = theme.space[props.padding];
|
|
5
|
+
}
|
|
6
|
+
if (props.paddingX !== undefined) {
|
|
7
|
+
style.paddingHorizontal = theme.space[props.paddingX];
|
|
8
|
+
}
|
|
9
|
+
if (props.paddingY !== undefined) {
|
|
10
|
+
style.paddingVertical = theme.space[props.paddingY];
|
|
11
|
+
}
|
|
12
|
+
if (props.paddingTop !== undefined) {
|
|
13
|
+
style.paddingTop = theme.space[props.paddingTop];
|
|
14
|
+
}
|
|
15
|
+
if (props.paddingRight !== undefined) {
|
|
16
|
+
style.paddingRight = theme.space[props.paddingRight];
|
|
17
|
+
}
|
|
18
|
+
if (props.paddingBottom !== undefined) {
|
|
19
|
+
style.paddingBottom = theme.space[props.paddingBottom];
|
|
20
|
+
}
|
|
21
|
+
if (props.paddingLeft !== undefined) {
|
|
22
|
+
style.paddingLeft = theme.space[props.paddingLeft];
|
|
23
|
+
}
|
|
24
|
+
if (props.gap !== undefined) {
|
|
25
|
+
style.gap = theme.space[props.gap];
|
|
26
|
+
}
|
|
27
|
+
return style;
|
|
28
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type ColorScheme, type ColorTokens, type Theme } from '@scalewing/tokens';
|
|
3
|
+
export type ThemeProviderProps = {
|
|
4
|
+
colorScheme?: ColorScheme | 'system';
|
|
5
|
+
colors?: Partial<ColorTokens>;
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
};
|
|
8
|
+
export declare function ThemeProvider({ colorScheme, colors, children, }: ThemeProviderProps): import("react").JSX.Element;
|
|
9
|
+
export declare function useTheme(): Theme;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useMemo } from 'react';
|
|
3
|
+
import { useColorScheme } from 'react-native';
|
|
4
|
+
import { createTheme, } from '@scalewing/tokens';
|
|
5
|
+
const ThemeContext = createContext(null);
|
|
6
|
+
export function ThemeProvider({ colorScheme = 'system', colors, children, }) {
|
|
7
|
+
const deviceScheme = useColorScheme() === 'dark' ? 'dark' : 'light';
|
|
8
|
+
const resolvedScheme = colorScheme === 'system' ? deviceScheme : colorScheme;
|
|
9
|
+
const theme = useMemo(() => createTheme({ colorScheme: resolvedScheme, colors }), [colors, resolvedScheme]);
|
|
10
|
+
return (_jsx(ThemeContext.Provider, { value: theme, children: children }));
|
|
11
|
+
}
|
|
12
|
+
export function useTheme() {
|
|
13
|
+
const theme = useContext(ThemeContext);
|
|
14
|
+
if (!theme) {
|
|
15
|
+
throw new Error('useTheme must be used within ThemeProvider');
|
|
16
|
+
}
|
|
17
|
+
return theme;
|
|
18
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@scalewing/react-native",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Scalewing React Native layout primitives.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://gitlab.com/dna-consulting/scalewing.git",
|
|
10
|
+
"directory": "packages/react-native"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://gitlab.com/dna-consulting/scalewing#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://gitlab.com/dna-consulting/scalewing/-/issues"
|
|
15
|
+
},
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"react-native": "./dist/index.js",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"CHANGELOG.md",
|
|
26
|
+
"dist",
|
|
27
|
+
"LICENSE",
|
|
28
|
+
"README.md"
|
|
29
|
+
],
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@scalewing/tokens": "0.1.0"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"react": "^19.0.0",
|
|
35
|
+
"react-native": ">=0.76.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/react": "^19.2.2",
|
|
39
|
+
"react": "19.2.3",
|
|
40
|
+
"react-native": "0.86.3"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "rm -rf dist && tsc -p tsconfig.json",
|
|
47
|
+
"test": "vitest run",
|
|
48
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
49
|
+
},
|
|
50
|
+
"main": "./dist/index.js",
|
|
51
|
+
"types": "./dist/index.d.ts"
|
|
52
|
+
}
|