Skip to content

Commit ebd6958

Browse files
authored
Merge pull request #25 from grapp-dev/feature/paragraph-max-lines
feat: add support for `max_lines` prop for paragraph component
2 parents 013409d + 03b3dd7 commit ebd6958

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

docs/pages/docs/components/paragraph.mdx

+5
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,8 @@ n.paragraph({
5353
types={['fun(lines: NuiLine[], component: Checkbox): nil']}
5454
/>
5555

56+
#### max_lines
57+
58+
<Property
59+
types={['number']}
60+
/>

lua/nui-components/paragraph.lua

+10-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function Paragraph:init(props, popup_options)
1919
lines = "",
2020
align = "left",
2121
truncate = false,
22+
max_lines = nil,
2223
}, props),
2324
fn.deep_merge({
2425
buf_options = {
@@ -33,6 +34,7 @@ function Paragraph:prop_types()
3334
lines = { "table", "string" },
3435
align = "string",
3536
truncate = "boolean",
37+
max_lines = "number",
3638
}
3739
end
3840

@@ -132,10 +134,17 @@ function Paragraph:on_layout()
132134
local parent = self:get_parent()
133135
local direction = parent and parent:get_direction() or "column"
134136
local is_row_direction = direction == "row"
137+
local props = self:get_props()
138+
139+
local height = math.max(1, #lines)
140+
141+
if props.max_lines then
142+
height = math.min(props.max_lines, height)
143+
end
135144

136145
return {
137146
width = is_row_direction and math.max(1, max_width) or nil,
138-
height = is_row_direction and nil or math.max(1, #lines),
147+
height = is_row_direction and nil or height,
139148
}
140149
end
141150

0 commit comments

Comments
 (0)