From 186ccf783bfb6db7f12f7f8afc0fd27dc3346cbd Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Thu, 17 Nov 2022 01:16:53 +0900 Subject: [PATCH] Add a merged style to check types of react and native at the same time --- examples/expo-example/src/app.tsx | 14 ++--- examples/next-example/src/pages/_app.tsx | 4 +- examples/next-example/src/pages/_document.tsx | 2 +- examples/next-example/src/pages/index.tsx | 2 +- packages/yoshiki/src/index.ts | 44 +++++++++++---- packages/yoshiki/src/native/generator.tsx | 22 +++++--- packages/yoshiki/src/native/hover.tsx | 6 +- packages/yoshiki/src/native/index.ts | 2 +- packages/yoshiki/src/react/generator.tsx | 4 +- packages/yoshiki/src/react/shorthands.ts | 56 ------------------- .../yoshiki/src/{native => }/shorthands.ts | 7 +-- packages/yoshiki/src/type.ts | 16 ++++++ packages/yoshiki/src/web.ts | 13 ++++- packages/yoshiki/web.ts | 2 +- 14 files changed, 94 insertions(+), 100 deletions(-) delete mode 100644 packages/yoshiki/src/react/shorthands.ts rename packages/yoshiki/src/{native => }/shorthands.ts (81%) diff --git a/examples/expo-example/src/app.tsx b/examples/expo-example/src/app.tsx index 8b6f434..165dae4 100644 --- a/examples/expo-example/src/app.tsx +++ b/examples/expo-example/src/app.tsx @@ -12,7 +12,7 @@ const CustomBox = ({ color, ...props }: { color: string } & Stylable) => { const { css } = useYoshiki(); return ( - + Text inside the custom black box. ); @@ -26,7 +26,7 @@ const BoxWithoutProps = (props: Stylable) => { {...css( { backgroundColor: { xs: "#00ff00", md: "#ff0000" }, - hover: { alignContent: "center" }, + hover: { alignContent: "center", alignItems: "center" }, press: { alignContent: "center" }, focus: { alignContent: "center" }, }, @@ -34,13 +34,9 @@ const BoxWithoutProps = (props: Stylable) => { )} > Text inside the box without props (green on small screens, red on bigs) diff --git a/examples/next-example/src/pages/_app.tsx b/examples/next-example/src/pages/_app.tsx index 2cf3f62..9a9a8da 100644 --- a/examples/next-example/src/pages/_app.tsx +++ b/examples/next-example/src/pages/_app.tsx @@ -3,9 +3,9 @@ // Licensed under the MIT license. See LICENSE file in the project root for details. // -import { Theme, ThemeProvider, useYoshiki } from "yoshiki"; +import { Theme, ThemeProvider } from "yoshiki"; +import { useYoshiki, useMobileHover } from "yoshiki/web"; import { AppProps } from "next/app"; -import { useMobileHover } from "yoshiki"; declare module "yoshiki" { export interface Theme { diff --git a/examples/next-example/src/pages/_document.tsx b/examples/next-example/src/pages/_document.tsx index e464e33..0b0efe4 100644 --- a/examples/next-example/src/pages/_document.tsx +++ b/examples/next-example/src/pages/_document.tsx @@ -3,7 +3,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for details. // -import { StyleRegistryProvider, createStyleRegistry } from "yoshiki"; +import { StyleRegistryProvider, createStyleRegistry } from "yoshiki/web"; import Document, { DocumentContext } from "next/document"; Document.getInitialProps = async (ctx: DocumentContext) => { diff --git a/examples/next-example/src/pages/index.tsx b/examples/next-example/src/pages/index.tsx index 80a4c1f..efc4408 100644 --- a/examples/next-example/src/pages/index.tsx +++ b/examples/next-example/src/pages/index.tsx @@ -5,7 +5,7 @@ import Head from "next/head"; import Image from "next/image"; -import { useYoshiki, Stylable } from "yoshiki"; +import { useYoshiki, Stylable } from "yoshiki/web"; import { ReactNode } from "react"; const Box = ({ children, ...props }: { children?: ReactNode } & Stylable) => { diff --git a/packages/yoshiki/src/index.ts b/packages/yoshiki/src/index.ts index 1d7b11f..ae8ef0d 100644 --- a/packages/yoshiki/src/index.ts +++ b/packages/yoshiki/src/index.ts @@ -3,14 +3,38 @@ // Licensed under the MIT license. See LICENSE file in the project root for details. // -export { type Theme, breakpoints, useTheme, ThemeProvider } from "./theme"; +import { + useYoshiki as useWebYoshiki, + type Stylable as WebStylable, + type StylableHoverable as WebStylableHoverable, +} from "./web"; +import type { + Stylable as NativeStylable, + StylableHoverable as NativeStylableHoverable, +} from "./native"; -export { - useYoshiki, - useStyleRegistry, - StyleRegistryProvider, - createStyleRegistry, - type Stylable, - useMobileHover, - Pressable -} from "./react"; +import { YsStyleProps } from "./native/generator"; +import { Theme } from "./theme"; +import { WithState, EnhancedStyle } from "./type"; +import type { ViewStyle, ImageStyle, TextStyle } from "react-native"; + +export const useYoshiki = (): { + css: < + Style extends ViewStyle | TextStyle | ImageStyle, + State extends Partial>> | Record, + >( + style: EnhancedStyle