Allow button groups to be collapsed

This commit is contained in:
Andrew Kingston 2024-09-02 09:31:19 +01:00
parent 2d52eff96f
commit fae897f468
No known key found for this signature in database
7 changed files with 129 additions and 44 deletions

View File

@ -246,7 +246,7 @@ export default function positionDropdown(element, opts) {
} }
// Apply initial styles which don't need to change // Apply initial styles which don't need to change
element.style.position = "absolute" element.style.position = "fixed"
element.style.zIndex = "9999" element.style.zIndex = "9999"
// Set up a scroll listener // Set up a scroll listener

View File

@ -17,6 +17,7 @@
export let tooltip = undefined export let tooltip = undefined
export let newStyles = true export let newStyles = true
export let id export let id
export let ref
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
</script> </script>
@ -25,6 +26,7 @@
<button <button
{id} {id}
{type} {type}
bind:this={ref}
class:spectrum-Button--cta={cta} class:spectrum-Button--cta={cta}
class:spectrum-Button--primary={primary} class:spectrum-Button--primary={primary}
class:spectrum-Button--secondary={secondary} class:spectrum-Button--secondary={secondary}

View File

@ -60,7 +60,7 @@
$: darkMode = !currentTheme.includes("light") $: darkMode = !currentTheme.includes("light")
$: buttons = [ $: buttons = [
{ {
text: "Actions", text: "Action",
type: "cta", type: "cta",
icon: "ChevronDown", icon: "ChevronDown",
onClick: async (e, row, refresh) => { onClick: async (e, row, refresh) => {

View File

@ -447,6 +447,18 @@
"section": true, "section": true,
"name": "Layout", "name": "Layout",
"settings": [ "settings": [
{
"type": "boolean",
"label": "Collapse",
"key": "collapsed"
},
{
"type": "text",
"label": "Collapsed text",
"key": "collapsedText",
"dependsOn": "collapsed",
"placeholder": "Action"
},
{ {
"type": "select", "type": "select",
"label": "Direction", "label": "Direction",
@ -467,7 +479,11 @@
"barTitle": "Row layout" "barTitle": "Row layout"
} }
], ],
"defaultValue": "row" "defaultValue": "row",
"dependsOn": {
"setting": "collapsed",
"invert": true
}
}, },
{ {
"type": "select", "type": "select",
@ -501,7 +517,11 @@
"barTitle": "Align stretched horizontally" "barTitle": "Align stretched horizontally"
} }
], ],
"defaultValue": "left" "defaultValue": "left",
"dependsOn": {
"setting": "collapsed",
"invert": true
}
}, },
{ {
"type": "select", "type": "select",
@ -535,7 +555,11 @@
"barTitle": "Align stretched vertically" "barTitle": "Align stretched vertically"
} }
], ],
"defaultValue": "top" "defaultValue": "top",
"dependsOn": {
"setting": "collapsed",
"invert": true
}
}, },
{ {
"type": "select", "type": "select",
@ -557,7 +581,11 @@
"barTitle": "Grow container" "barTitle": "Grow container"
} }
], ],
"defaultValue": "shrink" "defaultValue": "shrink",
"dependsOn": {
"setting": "collapsed",
"invert": true
}
}, },
{ {
"type": "select", "type": "select",
@ -583,7 +611,11 @@
"value": "L" "value": "L"
} }
], ],
"defaultValue": "M" "defaultValue": "M",
"dependsOn": {
"setting": "collapsed",
"invert": true
}
}, },
{ {
"type": "boolean", "type": "boolean",
@ -591,7 +623,11 @@
"key": "wrap", "key": "wrap",
"showInBar": true, "showInBar": true,
"barIcon": "ModernGridView", "barIcon": "ModernGridView",
"barTitle": "Wrap" "barTitle": "Wrap",
"dependsOn": {
"setting": "collapsed",
"invert": true
}
} }
] ]
} }

View File

@ -1,44 +1,86 @@
<script> <script>
import BlockComponent from "../BlockComponent.svelte" import BlockComponent from "../BlockComponent.svelte"
import Block from "../Block.svelte" import Block from "../Block.svelte"
import { Button, Popover, Menu, MenuItem } from "@budibase/bbui"
import { getContext } from "svelte"
export let buttons = [] export let buttons = []
export let direction = "row" export let direction = "row"
export let hAlign = "left" export let hAlign = "left"
export let vAlign = "top" export let vAlign = "top"
export let gap = "S" export let gap = "S"
export let collapsed = false
export let collapsedText = "Action"
const { styleable, enrichButtonActions } = getContext("sdk")
const component = getContext("component")
const context = getContext("context")
let popover
let anchor
const handleCollapsedClick = async button => {
const fn = enrichButtonActions(button.onClick, $context)
await fn?.()
popover.hide()
}
</script> </script>
<Block> {#if collapsed}
<BlockComponent <div use:styleable={$component.styles}>
type="container" <Button
props={{ bind:ref={anchor}
direction, on:click={() => popover?.show()}
hAlign, icon="ChevronDown"
vAlign, cta
gap, >
wrap: true, {collapsedText || "Action"}
}} </Button>
styles={{ </div>
normal: { <Popover bind:this={popover} align="left" {anchor}>
height: "100%", <Menu>
}, {#each buttons as button}
}} <MenuItem
> on:click={() => handleCollapsedClick(button)}
{#each buttons as { text, type, quiet, disabled, onClick, size, icon, gap }} disabled={button.disabled}
<BlockComponent >
type="button" {button.text || "Button"}
props={{ </MenuItem>
text: text || "Button", {/each}
onClick, </Menu>
type, </Popover>
quiet, {:else}
disabled, <Block>
icon, <BlockComponent
gap, type="container"
size: size || "M", props={{
}} direction,
/> hAlign,
{/each} vAlign,
</BlockComponent> gap,
</Block> wrap: true,
}}
styles={{
normal: {
height: "100%",
},
}}
>
{#each buttons as { text, type, quiet, disabled, onClick, size, icon, gap }}
<BlockComponent
type="button"
props={{
text: text || "Button",
onClick,
type,
quiet,
disabled,
icon,
gap,
size: size || "M",
}}
/>
{/each}
</BlockComponent>
</Block>
{/if}

View File

@ -16,7 +16,12 @@
$: style = getStyle(width, selectedUser, metadata) $: style = getStyle(width, selectedUser, metadata)
const getStyle = (width, selectedUser, metadata) => { const getStyle = (width, selectedUser, metadata) => {
let style = width === "auto" ? "width: auto;" : `flex: 0 0 ${width}px;` let style
if (width === "auto" || width === "100%") {
style = `width: ${width};`
} else {
style = `flex: 0 0 ${width}px;`
}
if (selectedUser) { if (selectedUser) {
style += `--user-color :${selectedUser.color};` style += `--user-color :${selectedUser.color};`
} }

View File

@ -45,7 +45,7 @@
onMount(() => { onMount(() => {
const observer = new ResizeObserver(entries => { const observer = new ResizeObserver(entries => {
const width = entries?.[0]?.contentRect?.width ?? 0 const width = entries?.[0]?.contentRect?.width ?? 0
buttonColumnWidth.set(Math.floor(width) - 1) buttonColumnWidth.set(width)
}) })
observer.observe(container) observer.observe(container)
}) })
@ -113,7 +113,7 @@
on:mouseleave={$isDragging ? null : () => ($hoveredRowId = null)} on:mouseleave={$isDragging ? null : () => ($hoveredRowId = null)}
> >
<GridCell <GridCell
width={$buttonColumnWidth} width="100%"
highlighted={$hoveredRowId === BlankRowID} highlighted={$hoveredRowId === BlankRowID}
on:click={() => dispatch("add-row-inline")} on:click={() => dispatch("add-row-inline")}
/> />