Skip to content

Commit 9e34bde

Browse files
authored
Read style props through StyleInfo in AdjustCssLengthProperties (#6632)
## Problem The padding strategy relies on the `AdjustCssLengthProperties` command to update elements, both for reading and writing styles. In order for that to work in Tailwind projects, where elements don't have an inline style prop, `AdjustCssLengthProperties` needs to read element styles from the "right" property, otherwise the command wouldn't work as intended. ## Fix Use the `StyleInfo` system from to read the element style info. ### Details - Refactored `AdjustCssLengthProperties` to read elements styles through `styleInfo` - Created a bespoke prop, `LengthProperty`, to track which props are addressed by `LengthPropertyToAdjust`. This way it's easy to tell which props need to be supported by `StyleInfo` to have `AdjustCssLengthProperties` working well - Extended `StyleInfo` to support the props read by `AdjustCssLengthProperties` - Updated the style plugins to support the new `StyleInfo` props ### Manual Tests: I hereby swear that: - [x] I opened a hydrogen project and it loaded - [x] I could navigate to various routes in Play mode
1 parent b0fa40f commit 9e34bde

8 files changed

+263
-308
lines changed

editor/src/components/canvas/canvas-types.ts

+21-1
Original file line numberDiff line numberDiff line change
@@ -576,17 +576,37 @@ export function maybePropertyValue<T>(property: CSSStyleProperty<T>): T | null {
576576
}
577577

578578
export type FlexGapInfo = CSSStyleProperty<CSSNumber>
579-
580579
export type FlexDirectionInfo = CSSStyleProperty<FlexDirection>
580+
export type LeftInfo = CSSStyleProperty<CSSNumber>
581+
export type RightInfo = CSSStyleProperty<CSSNumber>
582+
export type TopInfo = CSSStyleProperty<CSSNumber>
583+
export type BottomInfo = CSSStyleProperty<CSSNumber>
584+
export type WidthInfo = CSSStyleProperty<CSSNumber>
585+
export type HeightInfo = CSSStyleProperty<CSSNumber>
586+
export type FlexBasisInfo = CSSStyleProperty<CSSNumber>
581587

582588
export interface StyleInfo {
583589
gap: FlexGapInfo | null
584590
flexDirection: FlexDirectionInfo | null
591+
left: LeftInfo | null
592+
right: RightInfo | null
593+
top: TopInfo | null
594+
bottom: BottomInfo | null
595+
width: WidthInfo | null
596+
height: HeightInfo | null
597+
flexBasis: FlexBasisInfo | null
585598
}
586599

587600
const emptyStyleInfo: StyleInfo = {
588601
gap: null,
589602
flexDirection: null,
603+
left: null,
604+
right: null,
605+
top: null,
606+
bottom: null,
607+
width: null,
608+
height: null,
609+
flexBasis: null,
590610
}
591611

592612
export const isStyleInfoKey = (key: string): key is keyof StyleInfo => key in emptyStyleInfo

0 commit comments

Comments
 (0)