Skip to content

Commit

Permalink
Merge pull request #25 from grapp-dev/feature/paragraph-max-lines
Browse files Browse the repository at this point in the history
feat: add support for `max_lines` prop for paragraph component
  • Loading branch information
mobily authored Apr 14, 2024
2 parents 013409d + 03b3dd7 commit ebd6958
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/pages/docs/components/paragraph.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ n.paragraph({
types={['fun(lines: NuiLine[], component: Checkbox): nil']}
/>

#### max_lines

<Property
types={['number']}
/>
11 changes: 10 additions & 1 deletion lua/nui-components/paragraph.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function Paragraph:init(props, popup_options)
lines = "",
align = "left",
truncate = false,
max_lines = nil,
}, props),
fn.deep_merge({
buf_options = {
Expand All @@ -33,6 +34,7 @@ function Paragraph:prop_types()
lines = { "table", "string" },
align = "string",
truncate = "boolean",
max_lines = "number",
}
end

Expand Down Expand Up @@ -132,10 +134,17 @@ function Paragraph:on_layout()
local parent = self:get_parent()
local direction = parent and parent:get_direction() or "column"
local is_row_direction = direction == "row"
local props = self:get_props()

local height = math.max(1, #lines)

if props.max_lines then
height = math.min(props.max_lines, height)
end

return {
width = is_row_direction and math.max(1, max_width) or nil,
height = is_row_direction and nil or math.max(1, #lines),
height = is_row_direction and nil or height,
}
end

Expand Down

0 comments on commit ebd6958

Please sign in to comment.