mirror of
https://github.com/zoriya/yoshiki.git
synced 2025-12-05 22:56:14 +00:00
Add ysMap
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
import Head from "next/head";
|
||||
import Image from "next/image";
|
||||
import { useYoshiki, Stylable, md } from "yoshiki/web";
|
||||
import { useYoshiki, Stylable, md, ysMap } from "yoshiki/web";
|
||||
import { ReactNode } from "react";
|
||||
|
||||
const Box = ({ children, ...props }: { children?: ReactNode } & Stylable) => {
|
||||
@@ -69,7 +69,7 @@ export default function Home(props: Stylable) {
|
||||
},
|
||||
hover: {
|
||||
text: {
|
||||
color: { xs: "blue", md: "black" },
|
||||
color: ysMap({ xs: "lue", md: "lack" }, (x) => `b${x}`),
|
||||
},
|
||||
},
|
||||
focus: {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "yoshiki",
|
||||
"version": "1.2.7",
|
||||
"version": "1.2.8",
|
||||
"author": "Zoe Roux <zoe.roux@sdg.moe> (https://github.com/zoriya)",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
|
||||
@@ -32,3 +32,5 @@ export { sm, md, lg, xl } from "./type";
|
||||
export const ThemeProvider = ({ theme, children }: { theme: Theme; children?: ReactNode }) => {
|
||||
return <ThemeContext.Provider value={theme}>{children}</ThemeContext.Provider>;
|
||||
};
|
||||
|
||||
export * from "../type";
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
//
|
||||
|
||||
import { breakpoints, Theme } from "./theme";
|
||||
import { isBreakpoints } from "./utils";
|
||||
|
||||
export type YoshikiStyle<Property> =
|
||||
| Property
|
||||
@@ -78,3 +79,19 @@ export const assignChilds = <Style>(
|
||||
}
|
||||
return target;
|
||||
};
|
||||
|
||||
export const ysMap = <Property>(
|
||||
value: YoshikiStyle<Property>,
|
||||
f: (p: Property) => Property,
|
||||
): YoshikiStyle<Property> => {
|
||||
if (typeof value === "function") {
|
||||
// @ts-ignore too hard to type right
|
||||
return (theme) => ysMap(value(theme), f);
|
||||
}
|
||||
if (isBreakpoints(value)) {
|
||||
return Object.fromEntries(
|
||||
Object.entries(value).map(([bp, bpValue]) => [bp, ysMap(bpValue, f)]),
|
||||
);
|
||||
}
|
||||
return f(value);
|
||||
};
|
||||
|
||||
@@ -25,3 +25,5 @@ export { useAutomaticTheme } from "./automatic-theme";
|
||||
|
||||
export const ThemeProvider = ({ theme, children }: { theme: Theme; children?: ReactNode }) =>
|
||||
createElement(ThemeContext.Provider, { value: theme }, [children]);
|
||||
|
||||
export * from "../type";
|
||||
|
||||
Reference in New Issue
Block a user