Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/pages/docs/components/checkbox.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ local signal = n.create_signal({
n.checkbox({
label = "Display preview",
value = signal.is_preview_visible,
global_press_key = "<C-d>"
on_change = function(is_checked)
signal.is_preview_visible = is_checked
end,
Expand Down Expand Up @@ -65,6 +66,12 @@ n.checkbox({
types={['string']}
/>

#### global_press_key

<Property
types={['string[]', 'string']}
/>

#### prepare_lines

<Property
Expand Down
16 changes: 14 additions & 2 deletions lua/nui-components/checkbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function Checkbox:prop_types()
value = "boolean",
checked_sign = "string",
default_sign = "string",
global_press_key = { "table", "string", "nil" },
})
end

Expand All @@ -43,9 +44,20 @@ function Checkbox:mappings()
props.on_change(value, self)
end

return {
{ mode = { "n" }, key = props.press_key, handler = on_change },
local mappings = {
{ mode = { "n" }, key = props.press_key, handler = on_change },
}

if props.global_press_key then
table.insert(mappings, {
global = true,
mode = { "n", "i", "v" },
key = props.global_press_key,
handler = on_change,
})
end

return mappings
end

function Checkbox:initial_value()
Expand Down