From b72a300f9efa86daf0fa558fa9c386bd2a556d14 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 20 Nov 2022 01:40:43 +0900 Subject: [PATCH] Add units functions --- examples/expo-example/src/app.tsx | 2 ++ examples/expo-example/src/common.tsx | 23 ++++++++++++++ .../expo-example/src/components/text.d.ts | 10 +++++++ .../src/components/text.native.tsx | 17 +++++++++++ .../expo-example/src/components/text.web.tsx | 19 ++++++++++++ packages/yoshiki/package.json | 1 + packages/yoshiki/src/index.ts | 27 +++++++++++++---- packages/yoshiki/src/native/generator.tsx | 25 ++++++++++++---- packages/yoshiki/src/native/index.ts | 10 ++++++- packages/yoshiki/src/native/units.ts | 11 +++++++ packages/yoshiki/src/shorthands.ts | 4 +-- packages/yoshiki/src/type.ts | 30 ++++++++++++------- packages/yoshiki/src/web.ts | 17 ----------- .../yoshiki/src/{react => web}/generator.tsx | 5 ++-- packages/yoshiki/src/{react => web}/hover.ts | 0 packages/yoshiki/src/{react => web}/index.tsx | 9 ++++++ .../yoshiki/src/{react => web}/registry.tsx | 0 packages/yoshiki/src/web/units.ts | 9 ++++++ 18 files changed, 173 insertions(+), 46 deletions(-) create mode 100644 examples/expo-example/src/common.tsx create mode 100644 examples/expo-example/src/components/text.d.ts create mode 100644 examples/expo-example/src/components/text.native.tsx create mode 100644 examples/expo-example/src/components/text.web.tsx create mode 100644 packages/yoshiki/src/native/units.ts delete mode 100644 packages/yoshiki/src/web.ts rename packages/yoshiki/src/{react => web}/generator.tsx (96%) rename packages/yoshiki/src/{react => web}/hover.ts (100%) rename packages/yoshiki/src/{react => web}/index.tsx (62%) rename packages/yoshiki/src/{react => web}/registry.tsx (100%) create mode 100644 packages/yoshiki/src/web/units.ts diff --git a/examples/expo-example/src/app.tsx b/examples/expo-example/src/app.tsx index 165dae4..48c0f65 100644 --- a/examples/expo-example/src/app.tsx +++ b/examples/expo-example/src/app.tsx @@ -7,6 +7,7 @@ import { StatusBar } from "expo-status-bar"; import { Text, View } from "react-native"; import { registerRootComponent } from "expo"; import { Pressable, Stylable, useYoshiki } from "yoshiki/native"; +import { Card } from "./common"; const CustomBox = ({ color, ...props }: { color: string } & Stylable) => { const { css } = useYoshiki(); @@ -60,6 +61,7 @@ function App() { + ); } diff --git a/examples/expo-example/src/common.tsx b/examples/expo-example/src/common.tsx new file mode 100644 index 0000000..6c00755 --- /dev/null +++ b/examples/expo-example/src/common.tsx @@ -0,0 +1,23 @@ +// +// Copyright (c) Zoe Roux and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. +// + +import { px, useYoshiki } from "yoshiki"; +import { P } from "./components/text"; + +export const Card = () => { + const { css } = useYoshiki(); + + return ( +

+ Test +

+ ); +}; diff --git a/examples/expo-example/src/components/text.d.ts b/examples/expo-example/src/components/text.d.ts new file mode 100644 index 0000000..0fb47f8 --- /dev/null +++ b/examples/expo-example/src/components/text.d.ts @@ -0,0 +1,10 @@ +// +// Copyright (c) Zoe Roux and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. +// + +import { FunctionComponent, ReactNode } from "react"; +import { Stylable } from "yoshiki"; + +export type PProps = Stylable<"text"> & { children: ReactNode | string}; +export declare const P: FunctionComponent; diff --git a/examples/expo-example/src/components/text.native.tsx b/examples/expo-example/src/components/text.native.tsx new file mode 100644 index 0000000..4507c56 --- /dev/null +++ b/examples/expo-example/src/components/text.native.tsx @@ -0,0 +1,17 @@ +// +// Copyright (c) Zoe Roux and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. +// + +import { forwardRef } from "react"; +import { Text } from "react-native"; +import { YsNative } from "yoshiki"; +import { PProps } from "./text"; + +export const P = forwardRef>(function _P({ children, ...props }, ref) { + return ( + + {children} + + ); +}); diff --git a/examples/expo-example/src/components/text.web.tsx b/examples/expo-example/src/components/text.web.tsx new file mode 100644 index 0000000..6f95f0b --- /dev/null +++ b/examples/expo-example/src/components/text.web.tsx @@ -0,0 +1,19 @@ +// +// Copyright (c) Zoe Roux and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. +// + +import { forwardRef } from "react"; +import { YsWeb } from "yoshiki"; +import { PProps } from "./text"; + +export const P = forwardRef>(function _P( + { children, ...props }, + ref, +) { + return ( +

+ {children} +

+ ); +}); diff --git a/packages/yoshiki/package.json b/packages/yoshiki/package.json index a264e19..123e8ad 100644 --- a/packages/yoshiki/package.json +++ b/packages/yoshiki/package.json @@ -14,6 +14,7 @@ "url": "https://github.com/AnonymusRaccoon/yoshiki/issues" }, "main": "src/index.ts", + "react-native": "src/native/index.ts", "types": "src/index.ts", "source": "src/index.ts", "scripts": { diff --git a/packages/yoshiki/src/index.ts b/packages/yoshiki/src/index.ts index ae8ef0d..c6ab52c 100644 --- a/packages/yoshiki/src/index.ts +++ b/packages/yoshiki/src/index.ts @@ -5,17 +5,20 @@ import { useYoshiki as useWebYoshiki, + Platform, type Stylable as WebStylable, type StylableHoverable as WebStylableHoverable, + type YsWeb, } from "./web"; import type { Stylable as NativeStylable, StylableHoverable as NativeStylableHoverable, + YsNative, } from "./native"; -import { YsStyleProps } from "./native/generator"; -import { Theme } from "./theme"; -import { WithState, EnhancedStyle } from "./type"; +import type { YsStyleProps } from "./native/generator"; +import type { Theme } from "./theme"; +import type { WithState, EnhancedStyle, Length } from "./type"; import type { ViewStyle, ImageStyle, TextStyle } from "react-native"; export const useYoshiki = (): { @@ -23,7 +26,7 @@ export const useYoshiki = (): { Style extends ViewStyle | TextStyle | ImageStyle, State extends Partial>> | Record, >( - style: EnhancedStyle