Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the way to calculate processedProps #283

Merged
merged 3 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wise-teachers-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kuma-ui/system": patch
---

Fix the way to calculate processedProps
2 changes: 1 addition & 1 deletion packages/system/src/animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type AnimationProps = Partial<
CSSProperties<"animationIterationCount", true>
>;

const animationMappings: Record<AnimationKeys, string> = {
export const animationMappings: Record<AnimationKeys, string> = {
animation: "animation",
animationComposition: "animation-composition",
animationDelay: "animation-delay",
Expand Down
2 changes: 1 addition & 1 deletion packages/system/src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export type BackgroundProps<AutoPrefix extends string = string & {}> = Partial<
>
>;

const backgroundMappings: Record<BackgroundKeys, string> = {
export const backgroundMappings: Record<BackgroundKeys, string> = {
backgroundImage: "background-image",
bgImage: "background-image",
backgroundPosition: "background-position",
Expand Down
2 changes: 1 addition & 1 deletion packages/system/src/border.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export type BorderProps = Partial<
>
>;

const borderMappings: Record<BorderKeys, string> = {
export const borderMappings: Record<BorderKeys, string> = {
border: "border",
borderTop: "border-top",
borderRight: "border-right",
Expand Down
2 changes: 1 addition & 1 deletion packages/system/src/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export type ColorProps<T extends ThemeSystemType = ThemeSystemType> = Partial<
>
>;

const colorMappings: Record<ColorKeys, string> = {
export const colorMappings: Record<ColorKeys, string> = {
background: "background",
bg: "background",
backgroundColor: "background-color",
Expand Down
2 changes: 1 addition & 1 deletion packages/system/src/column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type ColumnProps = Partial<
>
>;

const columnMappings: Record<ColumnKeys, string> = {
export const columnMappings: Record<ColumnKeys, string> = {
columnCount: "column-count",
columnFill: "column-fill",
columnGap: "column-gap",
Expand Down
6 changes: 6 additions & 0 deletions packages/system/src/compose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { font } from "./font";
import { mask } from "./mask";
import { column } from "./column";
import { background } from "./background";
import { text } from "./text";

describe("compose function", () => {
test("should combine styles from multiple style functions", () => {
Expand All @@ -31,6 +32,7 @@ describe("compose function", () => {
shadow,
list,
effect,
text,
font,
mask,
column,
Expand Down Expand Up @@ -61,6 +63,8 @@ describe("compose function", () => {
bgAttachment: "fixed",
bgClip: "border-box",
bgOrigin: "content-box",
marginRight: 4,
textAlign: "right",
};
// Act
const styles = combinedFunction(props);
Expand Down Expand Up @@ -91,6 +95,8 @@ describe("compose function", () => {
expect(styles.base).toContain("background-attachment: fixed;");
expect(styles.base).toContain("background-clip: border-box;");
expect(styles.base).toContain("background-origin: content-box;");
expect(styles.base).toContain("margin-right: 4px;");
expect(styles.base).toContain("text-align: right;");
});

test("should not include invalid keys in the resulting CSS", () => {
Expand Down
61 changes: 42 additions & 19 deletions packages/system/src/compose.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import { AnimationProps } from "./animation";
import { SpaceProps } from "./space";
import { TypographyProps } from "./typography";
import { LayoutProps } from "./layout";
import { ColorProps } from "./color";
import { FlexProps } from "./flex";
import { BorderProps } from "./border";
import { OutlineProps } from "./outline";
import { PositionProps } from "./position";
import { ShadowProps } from "./shadow";
import { AnimationProps, animationMappings } from "./animation";
import { SpaceProps, spaceMappings } from "./space";
import { TypographyProps, typographyMappings } from "./typography";
import { LayoutProps, layoutMappings } from "./layout";
import { ColorProps, colorMappings } from "./color";
import { FlexProps, flexMappings } from "./flex";
import { BorderProps, borderMappings } from "./border";
import { OutlineProps, outlineMappings } from "./outline";
import { PositionProps, positionMappings } from "./position";
import { ShadowProps, shadowMappings } from "./shadow";
import { PseudoProps } from "./pseudo";
import { ThemeSystemType, ResponsiveStyle } from "./types";
import { styleCache } from "@kuma-ui/sheet";
import { GridProps } from "./grid";
import { ListProps } from "./list";
import { EffectProps } from "./effect";
import { TextProps } from "./text";
import { FontProps } from "./font";
import { MaskProps } from "./mask";
import { ColumnProps } from "./column";
import { BackgroundProps } from "./background";
import { GridProps, gridMappings } from "./grid";
import { ListProps, listMappings } from "./list";
import { EffectProps, effectMappings } from "./effect";
import { TextProps, textMappings } from "./text";
import { FontProps, fontMappings } from "./font";
import { MaskProps, maskMappings } from "./mask";
import { ColumnProps, columnMappings } from "./column";
import { BackgroundProps, backgroundMappings } from "./background";
import { StyledKeyType } from "./keys";

export type StyledProps<T extends ThemeSystemType = ThemeSystemType> =
TypographyProps<T> &
Expand All @@ -44,6 +45,28 @@ export type StyledProps<T extends ThemeSystemType = ThemeSystemType> =

export type StyleFunction = (props: StyledProps) => ResponsiveStyle;

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- FIXME
const styleMappings: Record<StyledKeyType, string> = Object.assign(
{},
animationMappings,
spaceMappings,
typographyMappings,
layoutMappings,
colorMappings,
flexMappings,
borderMappings,
outlineMappings,
positionMappings,
shadowMappings,
gridMappings,
listMappings,
effectMappings,
textMappings,
fontMappings,
maskMappings,
columnMappings,
backgroundMappings
);
/**
* Composes multiple style functions into a single style function.
* This allows for more efficient application of multiple style functions at once,
Expand Down Expand Up @@ -81,7 +104,7 @@ export const compose = (...styleFunctions: StyleFunction[]): StyleFunction => {

const processedProps = Object.keys(outputProps).filter((key) =>
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- FIXME
newStyles.base.includes(`${outputProps[key as keyof StyledProps]}:`)
newStyles.base.includes(`${styleMappings[key as StyledKeyType]}:`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good fix 🎉
It was not appropriate to use CSS values to extract processed props; it is correct to use CSS properties.

);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- FIXME
outputProps = Object.keys(outputProps).reduce((remainingProps, key) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/system/src/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type EffectProps = Partial<
>
>;

const effectMappings: Record<EffectKeys, string> = {
export const effectMappings: Record<EffectKeys, string> = {
transition: "transition",
transitionDuration: "transition-duration",
transitionProperty: "transition-property",
Expand Down
2 changes: 1 addition & 1 deletion packages/system/src/flex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type FlexProps = Partial<
CSSProperties<"gap", true>
>;

const flexMappings: Record<FlexKeys, string> = {
export const flexMappings: Record<FlexKeys, string> = {
flexDirection: "flex-direction",
flexDir: "flex-direction",
justifyContent: "justify-content",
Expand Down
2 changes: 1 addition & 1 deletion packages/system/src/font.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export type FontProps<T extends ThemeSystemType = ThemeSystemType> = Partial<
AddProperty<CSSProperties<"fontWeight", true>, T["fontWeights"]>
>;

const fontMappings: Record<FontKeys, string> = {
export const fontMappings: Record<FontKeys, string> = {
font: "font",
fontFamily: "font-family",
fontFeatureSettings: "font-feature-settings",
Expand Down
2 changes: 1 addition & 1 deletion packages/system/src/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type GridProps = Partial<
CSSProperties<Exclude<GridKeys, UnitKeys>> & CSSProperties<UnitKeys, true>
>;

const gridMappings: Record<GridKeys, string> = {
export const gridMappings: Record<GridKeys, string> = {
grid: "grid",
gridArea: "grid-area",
gridAutoColumns: "grid-auto-columns",
Expand Down
2 changes: 2 additions & 0 deletions packages/system/src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ export type StyledKeyType =
| AnimationKeys
| SpaceKeys
| TypographyKeys
| FontKeys
| TextKeys
| LayoutKeys
| ColorKeys
| FlexKeys
Expand Down
2 changes: 1 addition & 1 deletion packages/system/src/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type LayoutProps = Partial<
CSSProperties<"cursor">
>;

const layoutMappings: Record<LayoutKeys, string> = {
export const layoutMappings: Record<LayoutKeys, string> = {
width: "width",
minWidth: "min-width",
maxWidth: "max-width",
Expand Down
2 changes: 1 addition & 1 deletion packages/system/src/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type ListProps = Partial<
>
>;

const listMappings: Record<ListKeys, string> = {
export const listMappings: Record<ListKeys, string> = {
listStyle: "list-style",
listStyleImage: "list-style-image",
listStylePosition: "list-style-position",
Expand Down
2 changes: 1 addition & 1 deletion packages/system/src/mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export type MaskProps = Partial<
>
>;

const maskMappings: Record<MaskKeys, string> = {
export const maskMappings: Record<MaskKeys, string> = {
mask: "mask",
maskBorder: "mask-border",
maskBorderMode: "mask-border-mode",
Expand Down
2 changes: 1 addition & 1 deletion packages/system/src/outline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type OutlineProps = Partial<
CSSProperties<"outlineStyle">
>;

const outlineMappings: Record<OutlineKeys, string> = {
export const outlineMappings: Record<OutlineKeys, string> = {
outline: "outline",
outlineOffset: "outline-offset",
outlineWidth: "outline-width",
Expand Down
2 changes: 1 addition & 1 deletion packages/system/src/position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type PositionProps = Partial<
CSSProperties<"top" | "right" | "left" | "bottom" | "inset", true>
>;

const positionMappings: Record<PositionKeys, string> = {
export const positionMappings: Record<PositionKeys, string> = {
top: "top",
right: "right",
left: "left",
Expand Down
2 changes: 1 addition & 1 deletion packages/system/src/shadow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { applyResponsiveStyles } from "./responsive";

export type ShadowProps = Partial<CSSProperties<"boxShadow" | "textShadow">>;

const shadowMappings: Record<ShadowKeys, string> = {
export const shadowMappings: Record<ShadowKeys, string> = {
boxShadow: "box-shadow",
textShadow: "text-shadow",
} as const;
Expand Down
2 changes: 1 addition & 1 deletion packages/system/src/space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export type SpaceProps = Partial<
}
>;

const spaceMappings: Record<SpaceKeys, string> = {
export const spaceMappings: Record<SpaceKeys, string> = {
margin: "margin",
m: "margin",
marginTop: "margin-top",
Expand Down
2 changes: 1 addition & 1 deletion packages/system/src/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type TextProps = Partial<
CSSProperties<"textUnderlinePosition">
>;

const textMappings: Record<TextKeys, string> = {
export const textMappings: Record<TextKeys, string> = {
textAlign: "text-align",
textAlignLast: "text-align-last",
textCombineUpright: "text-combine-upright",
Expand Down
2 changes: 1 addition & 1 deletion packages/system/src/typography.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type TypographyProps<T extends ThemeSystemType = ThemeSystemType> =
CSSProperties<"wordBreak" | "writingMode">
>;

const typographyMappings: Record<TypographyKeys, string> = {
export const typographyMappings: Record<TypographyKeys, string> = {
hyphenateCharacter: "hyphenate-character",
hyphenateLimitChars: "hyphenate-limit-chars",
hyphens: "hyphens",
Expand Down