Skip to content

Commit ef3229e

Browse files
authored
Merge pull request #4 from grapp-dev/feat/add-winhighlight
feat: ✨ Allows modifying the appearance and behavior of the floating window
2 parents ce9985f + fb83d4b commit ef3229e

File tree

2 files changed

+60
-10
lines changed

2 files changed

+60
-10
lines changed

docs/pages/docs/component.mdx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,38 @@ Where `Padding` is:
586586
```
587587
</Property>
588588

589+
#### window
590+
591+
> Allows you to modify the appearance and behavior of the floating window.
592+
593+
<Property
594+
types={['WindowOptions']}
595+
>
596+
Where `WindowOptions` is:
597+
598+
```lua
599+
{
600+
blend = number,
601+
highlight = table | string
602+
}
603+
```
604+
605+
Examples:
606+
```lua
607+
window = {
608+
highlight = {
609+
FloatBorder = "Normal",
610+
NormalFloat = "String",
611+
}
612+
}
613+
614+
window = {
615+
highlight = "FloatBorder:Normal,NormalFloat:String"
616+
}
617+
```
618+
619+
</Property>
620+
589621
#### global_focus_key
590622

591623
> Specifies a global key used to focus on the component.

lua/nui-components/component/init.lua

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,7 @@ local fn = require("nui-components.utils.fn")
1010
local Component = Popup:extend("Component")
1111

1212
function Component:init(props, popup_options)
13-
popup_options = fn.deep_merge({
14-
enter = false,
15-
focusable = true,
16-
win_options = {
17-
winblend = 0,
18-
},
19-
zindex = 100,
20-
}, fn.default_to(popup_options, {}))
21-
22-
props = fn.merge({
13+
props = fn.deep_merge({
2314
hidden = false,
2415
mappings = fn.always({}),
2516
events = fn.always({}),
@@ -30,8 +21,34 @@ function Component:init(props, popup_options)
3021
on_mount = fn.ignore,
3122
on_unmount = fn.ignore,
3223
id = tostring(math.random()),
24+
window = {
25+
blend = 0,
26+
highlight = nil,
27+
},
3328
}, props)
3429

30+
local winhighlight = props.window.highlight
31+
32+
if winhighlight and type(winhighlight) == "table" then
33+
winhighlight = table.concat(
34+
fn.kreduce(winhighlight, function(acc, value, key)
35+
table.insert(acc, key .. ":" .. value)
36+
return acc
37+
end, {}),
38+
","
39+
)
40+
end
41+
42+
popup_options = fn.deep_merge({
43+
enter = false,
44+
focusable = true,
45+
win_options = {
46+
winblend = props.window.blend,
47+
winhighlight = winhighlight,
48+
},
49+
zindex = 100,
50+
}, popup_options)
51+
3552
if props.border_label and not props.border_style then
3653
props.border_style = "rounded"
3754
end
@@ -161,6 +178,7 @@ function Component:_default_prop_types()
161178
padding = { "table", "number", "nil" },
162179
autofocus = { "boolean", "nil" },
163180
validate = { "function", "nil" },
181+
window = "table",
164182
}
165183
end
166184

0 commit comments

Comments
 (0)