Skip to content

Commit

Permalink
Merge pull request #272 from marceloatg/feature/group-button
Browse files Browse the repository at this point in the history
slds-group-button-dropdown created
  • Loading branch information
marceloatg authored Nov 6, 2024
2 parents 5f4ccba + 7783b98 commit 3084f5b
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 3 deletions.
39 changes: 37 additions & 2 deletions docs/examples/test.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
<template>

<example-container class="slds-m-bottom_medium">
<slds-button-group :dropdown-options="dropdownOptions">
<slds-button
label="foo"
neutral
/>
</slds-button-group>
</example-container>

<example-container class="slds-m-bottom_medium">
<slds-menu
:options="dropdownOptions"
/>
</example-container>

<example-container class="slds-m-bottom_medium">
<span class="slds-icon_container slds-icon-utility-add slds-current-color" @click="foo">
<slds-svg class="slds-icon slds-icon_x-small slds-cursor_not-allowed" icon="utility:add"/>
</span>
</example-container>

<!-- Checkbox output group -->
<example-container class="slds-m-bottom_medium">
<slds-checkbox-output-group
Expand Down Expand Up @@ -421,8 +442,7 @@ import SldsMenu from "../../src/components/slds-menu/slds-menu.vue"
import SldsCheckboxButtonGroup from "../../src/components/slds-checkbox-button-group/slds-checkbox-button-group.vue"
import SldsVerticalNavigation from "../../src/components/slds-vertical-navigation/slds-vertical-navigation.vue"
import SldsVerticalNavigationItem from "../../src/components/slds-vertical-navigation/slds-vertical-navigation-item.vue"
import SldsVerticalNavigationSection
from "../../src/components/slds-vertical-navigation/slds-vertical-navigation-section.vue"
import SldsVerticalNavigationSection from "../../src/components/slds-vertical-navigation/slds-vertical-navigation-section.vue"
import SldsTabs from "../../src/components/slds-tabs/slds-tabs.vue"
import SldsPanel from "../../src/components/slds-panel/slds-panel.vue"
import SldsScopedTabs from "../../src/components/slds-scoped-tabs/slds-scoped-tabs.vue"
Expand All @@ -439,11 +459,15 @@ import SldsColumn from "../../src/components/slds-grid/slds-column.vue"
import SldsInput from "../../src/components/slds-input/slds-input.vue"
import SldsCheckboxGroup from "../../src/components/slds-checkbox-group/slds-checkbox-group.vue"
import SldsCheckboxOutputGroup from "../../src/components/slds-checkbox-output-group/slds-checkbox-output-group.vue"
import SldsSvg from "../../src/components/slds-svg/slds-svg.vue"
import SldsButtonGroup from "../../src/components/slds-button-group/slds-button-group.vue"
export default {
name: "test",
components: {
SldsButtonGroup,
SldsSvg,
SldsCheckboxOutputGroup,
SldsCheckboxGroup,
SldsInput,
Expand Down Expand Up @@ -477,6 +501,17 @@ export default {
return {
activeTab: "details",
dropdownOptions: [
{
label: "Cancel",
value: "cancel",
},
{
label: "Delete",
value: "delete",
},
],
activeScopedTab: "first",
checkboxButtonOptions: [
Expand Down
55 changes: 55 additions & 0 deletions src/components/slds-button-group/slds-button-group-dropdown.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<template>
<transition name="dropdown-right">
<div v-if="isOpen" class="slds-dropdown slds-dropdown_right slds-dropdown_actions">
<ul class="slds-dropdown__list" role="menu">
<li
v-for="(option, index) in dropdownOptions"
:key="index"
class="slds-dropdown__item"
role="presentation"
@click="handleClickOption(option)"
>
<a role="menuitem" tabindex="0">
<span class="slds-truncate">
{{ option.label }}
</span>
</a>
</li>
</ul>
</div>
</transition>
</template>

<script lang="ts">
import { defineComponent, PropType } from "vue"
import { DropdownOption } from "../slds-dropdown/dropdown-option"
import { EVENTS } from "../../constants"
export default defineComponent({
name: "SldsButtonGroupDropdown",
props: {
/**
* Dropdown options.
*/
dropdownOptions: { type: Array as PropType<DropdownOption[]>, default: () => [] as DropdownOption[] },
/**
* Indicates whether the dropdown is open.
*/
isOpen: { type: Boolean, required: true },
},
methods: {
/**
* Handles the click event on the option.
* @param option Clicked option.
*/
handleClickOption(option: DropdownOption): void {
if (option.isDivider || option.isHeading) return
this.$emit(EVENTS.CLICK_OPTION, option)
},
},
})
</script>

108 changes: 107 additions & 1 deletion src/components/slds-button-group/slds-button-group.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,119 @@
<template>
<div class="slds-button-group" role="group">

<slot/>

<div
v-if="showDropdownButton"
v-click-outside="handleClickOutside"
class="slds-dropdown-trigger slds-dropdown-trigger_click slds-is-open slds-button_last"
>

<slds-button-icon
bordered
:disabled="disabled"
icon-name="utility:down"
@click="handleClickButton"
/>

<slds-button-group-dropdown
:is-open="isOpen"
:dropdown-options="dropdownOptions"
@click-option="handleClickOption"
/>

</div>

</div>
</template>

<script lang="ts">
import { defineComponent } from "vue"
import { defineComponent, PropType } from "vue"
import SldsButtonIcon from "../slds-button-icon/slds-button-icon.vue"
import SldsButtonGroupDropdown from "./slds-button-group-dropdown.vue"
import { vOnClickOutside } from "@vueuse/components"
import { DropdownOption } from "../slds-dropdown/dropdown-option.ts"
export default defineComponent({
name: "SldsButtonGroup",
components: { SldsButtonGroupDropdown, SldsButtonIcon },
directives: {
ClickOutside: vOnClickOutside,
},
props: {
/**
* Indicates whether this component is disabled.
*/
disabled: Boolean,
/**
* Dropdown options.
*/
dropdownOptions: { type: Array as PropType<DropdownOption[]>, default: () => [] as DropdownOption[] },
},
data() {
return {
/**
* Indicates whether the dropdown is open.
*/
isOpen: false,
}
},
computed: {
/**
* Indicates whether the dropdown button is visible.
*/
showDropdownButton(): boolean {
return Boolean(this.dropdownOptions && this.dropdownOptions.length > 0)
},
},
methods: {
/**
* Handles the click event on the button.
*/
handleClickButton(): void {
if (this.isOpen) this.hideDropdown()
else if (!this.disabled) this.showDropdown()
},
/**
* Handles the click event on an option.
* @param option The clicked option.
*/
handleClickOption(option: DropdownOption): void {
if (this.disabled || option.disabled) return
this.$emit(option.value!)
this.hideDropdown()
},
/**
* Handles the click event outside this component.
*/
handleClickOutside(): void {
this.hideDropdown()
},
/**
* Hides the dropdown.
*/
hideDropdown(): void {
this.isOpen = false
},
/**
* Shows the dropdown.
*/
showDropdown(): void {
this.isOpen = true
},
},
})
</script>

0 comments on commit 3084f5b

Please sign in to comment.