Skip to content

Commit

Permalink
Add line height as a style prop
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwillchen committed Jan 29, 2024
1 parent 04baea3 commit a7ddb31
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions mesop/component_helpers/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class Style:
height: Sets the height of the component. See [MDN doc](https://developer.mozilla.org/en-US/docs/Web/CSS/height).
justify_content: Aligns the flexible container's items on the main-axis. See [MDN doc](https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content).
letter_spacing: Increases or decreases the space between characters in text. See [MDN doc](https://developer.mozilla.org/en-US/docs/Web/CSS/letter-spacing).
line height: Set the line height (relative to the font size). See [MDN doc](https://developer.mozilla.org/en-US/docs/Web/CSS/line-height).
margin: Sets the margin space required on each side of an element. See [MDN doc](https://developer.mozilla.org/en-US/docs/Web/CSS/margin).
overflow_x: Specifies the handling of overflow in the horizontal direction. See [MDN doc](https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-x).
overflow_y: Specifies the handling of overflow in the vertical direction. See [MDN doc](https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-y).
Expand Down Expand Up @@ -194,6 +195,7 @@ class Style:
"stretch",
] | None = None
letter_spacing: int | str | None = None
line_height: int | str | None = None
margin: Margin | None = None
overflow_x: OverflowValues | None = None
overflow_y: OverflowValues | None = None
Expand Down Expand Up @@ -247,6 +249,7 @@ def to_style_proto(s: Style) -> pb.Style:
height=_px_str(s.height),
justify_content=s.justify_content,
letter_spacing=_px_str(s.letter_spacing),
line_height=str(s.line_height),
margin=_map_edge_insets(s.margin),
overflow_x=s.overflow_x,
overflow_y=s.overflow_y,
Expand Down
3 changes: 2 additions & 1 deletion mesop/protos/ui.proto
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ message UserDefinedType {
repeated Arg args = 1;
}

// Next id: 31
// Next id: 32
message Style {
optional string align_items = 1;
optional string background = 2;
Expand All @@ -239,6 +239,7 @@ message Style {
optional string height = 15;
optional string justify_content = 16;
optional string letter_spacing = 17;
optional string line_height = 31;
optional EdgeInsets margin = 18;
optional string overflow_x = 19;
optional string overflow_y = 20;
Expand Down
3 changes: 3 additions & 0 deletions mesop/web/src/utils/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ export function formatStyle(styleObj: Style): string {
if (styleObj.getLetterSpacing()) {
style += `letter-spacing: ${styleObj.getLetterSpacing()};`;
}
if (styleObj.getLineHeight()) {
style += `line-height: ${styleObj.getLineHeight()};`;
}
if (styleObj.getMargin()) {
const margin = styleObj.getMargin()!;
style += `margin: ${margin.getTop() || 0} ${margin.getRight() || 0} ${
Expand Down

0 comments on commit a7ddb31

Please sign in to comment.