This repository has been archived by the owner on Aug 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb4e5eb
commit b4783c7
Showing
12 changed files
with
522 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<template> | ||
<div class="fd-button-split" role="group"> | ||
<!-- Provide a custom action button. The action button is bigger button with the text that should trigger some kind of action. You can use fd-split-button-action to render the default auxiliary-button and customize it. --> | ||
<slot v-bind="slotProps" name="action"> | ||
<fd-split-button-action @click="$emit('click')"> | ||
<!-- Provide a title. This is rendered inside the 'action' part of the split button (big area on the left). --> | ||
<slot /> | ||
</fd-split-button-action> | ||
</slot> | ||
<!-- Provide a custom auxiliary button. The auxiliary button should bring up some kind of menu/popover. You can use fd-split-button-auxiliary to render the default auxiliary-button and customize it. --> | ||
<slot v-bind="slotProps" name="auxiliary"> | ||
<fd-split-button-auxiliary @click="$emit('click:auxiliary')" /> | ||
</slot> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import FdSplitButtonAuxiliary from "./../SplitButtonAuxiliary/SplitButtonAuxiliary.vue"; | ||
import FdSplitButtonAction from "./../SplitButtonAction/SplitButtonAction.vue"; | ||
import Vue from "vue"; | ||
import ButtonTypes from "./../Button/ButtonTypes"; | ||
import IconMixin from "./../../mixins/Icon"; | ||
export default { | ||
name: "FdSplitButton", | ||
mixins: [IconMixin], | ||
components: { | ||
FdSplitButtonAction, | ||
FdSplitButtonAuxiliary | ||
}, | ||
provide() { | ||
return { | ||
splitButton: this.splitButton | ||
}; | ||
}, | ||
computed: { | ||
slotProps() { | ||
return this.splitButton; | ||
} | ||
}, | ||
props: { | ||
compact: Boolean, | ||
styling: { | ||
type: String, | ||
default: null, | ||
validator: value => ["emphasized", "light"].indexOf(value) >= 0 | ||
}, | ||
state: { | ||
type: String, | ||
default: "normal", | ||
validator: value => ["normal", "selected", "disabled"].indexOf(value) >= 0 | ||
}, | ||
type: { | ||
type: String, | ||
default: null, | ||
validator: value => ButtonTypes.indexOf(value) >= 0 | ||
} | ||
}, | ||
watch: { | ||
state(state) { | ||
this.splitButton.state = state; | ||
}, | ||
type(type) { | ||
this.splitButton.type = type; | ||
}, | ||
styling(styling) { | ||
this.splitButton.styling = styling; | ||
}, | ||
compact(compact) { | ||
this.splitButton.compact = compact; | ||
}, | ||
icon(icon) { | ||
this.splitButton.icon = icon; | ||
} | ||
}, | ||
data() { | ||
return { | ||
splitButton: Vue.observable({ | ||
state: this.state, | ||
type: this.type, | ||
styling: this.styling, | ||
compact: this.compact, | ||
icon: this.icon | ||
}) | ||
}; | ||
} | ||
}; | ||
</script> |
39 changes: 39 additions & 0 deletions
39
src/components/SplitButton/__tests__/__snapshots__/split-button.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Split Button renders correctly 1`] = ` | ||
<div | ||
class="fd-button-split" | ||
role="group" | ||
> | ||
<button | ||
class="fd-button" | ||
> | ||
Hello World | ||
</button> | ||
<button | ||
aria-label="More" | ||
class="fd-button sap-icon--slim-arrow-down fd-button" | ||
/> | ||
</div> | ||
`; | ||
|
||
exports[`Split Button when disabled renders correctly 1`] = ` | ||
<div | ||
class="fd-button-split" | ||
role="group" | ||
> | ||
<button | ||
class="fd-button is-disabled" | ||
disabled="disabled" | ||
> | ||
Hello World | ||
</button> | ||
<button | ||
aria-label="More" | ||
class="fd-button sap-icon--slim-arrow-down fd-button is-disabled" | ||
disabled="disabled" | ||
/> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { mount, createLocalVue } from "@vue/test-utils"; | ||
import FundamentalVue from "./../../../"; | ||
import FdSplitButton from "./../SplitButton.vue"; | ||
import FdSplitButtonAction from "./../../SplitButtonAction/SplitButtonAction.vue"; | ||
import FdSplitButtonAuxiliary from "./../../SplitButtonAuxiliary/SplitButtonAuxiliary.vue"; | ||
|
||
const createSplitButton = ({ propsData } = { propsData: {} }) => { | ||
const localVue = createLocalVue(); | ||
localVue.use(FundamentalVue); | ||
return mount(FdSplitButton, { | ||
localVue, | ||
propsData, | ||
slots: { | ||
default: "Hello World" | ||
} | ||
}); | ||
}; | ||
|
||
describe("Split Button", () => { | ||
test("renders correctly", () => { | ||
expect(createSplitButton().element).toMatchSnapshot(); | ||
}); | ||
|
||
test("emits click-event when action-button is clicked", () => { | ||
const wrapper = createSplitButton(); | ||
const actionButtonWrapper = wrapper.find(FdSplitButtonAction); | ||
expect(actionButtonWrapper.exists()).toBe(true); | ||
actionButtonWrapper.trigger("click"); | ||
expect(wrapper.emitted("click")).toHaveLength(1); | ||
}); | ||
|
||
test("emits click:auxiliary-event when auxiliary-button is clicked", () => { | ||
const wrapper = createSplitButton(); | ||
const auxiliaryButtonWrapper = wrapper.find(FdSplitButtonAuxiliary); | ||
expect(auxiliaryButtonWrapper.exists()).toBe(true); | ||
auxiliaryButtonWrapper.trigger("click"); | ||
expect(wrapper.emitted("click:auxiliary")).toHaveLength(1); | ||
expect(wrapper.emitted("click")).toBeUndefined(); | ||
}); | ||
|
||
describe("when disabled", () => { | ||
/** @type {import("@vue/test-utils").Wrapper<Vue>} */ | ||
let disabledWrapper; | ||
beforeEach(() => { | ||
disabledWrapper = createSplitButton({ | ||
propsData: { | ||
state: "disabled" | ||
} | ||
}); | ||
}); | ||
|
||
test("renders correctly", () => { | ||
expect(disabledWrapper.element).toMatchSnapshot(); | ||
}); | ||
|
||
test("click:auxiliary-event is not emitted when auxiliary-button is clicked", () => { | ||
const auxiliaryButtonWrapper = disabledWrapper.find( | ||
FdSplitButtonAuxiliary | ||
); | ||
expect(auxiliaryButtonWrapper.exists()).toBe(true); | ||
auxiliaryButtonWrapper.trigger("click"); | ||
expect(disabledWrapper.emitted("click:auxiliary")).toBeUndefined(); | ||
expect(disabledWrapper.emitted("click")).toBeUndefined(); | ||
}); | ||
|
||
test("click-event is not emitted when action-button is clicked", () => { | ||
const actionButtonWrapper = disabledWrapper.find(FdSplitButtonAction); | ||
expect(actionButtonWrapper.exists()).toBe(true); | ||
actionButtonWrapper.trigger("click"); | ||
expect(disabledWrapper.emitted("click:auxiliary")).toBeUndefined(); | ||
expect(disabledWrapper.emitted("click")).toBeUndefined(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import SplitButton from "./SplitButton.vue"; | ||
import { pluginify } from "./../../util"; | ||
export default pluginify(SplitButton); | ||
export { SplitButton }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<template> | ||
<fd-button | ||
v-bind="$attrs" | ||
v-on="$listeners" | ||
:state="state" | ||
:type="type" | ||
:styling="styling" | ||
:compact="compact" | ||
:icon="icon" | ||
> | ||
<slot /> | ||
</fd-button> | ||
</template> | ||
|
||
<script> | ||
import FdButton from "./../Button/Button.vue"; | ||
export default { | ||
name: "FdSplitButtonAction", | ||
components: { FdButton }, | ||
inject: ["splitButton"], | ||
computed: { | ||
state() { | ||
return this.splitButton.state; | ||
}, | ||
type() { | ||
return this.splitButton.type; | ||
}, | ||
styling() { | ||
return this.splitButton.styling; | ||
}, | ||
compact() { | ||
return this.splitButton.disacompactbled; | ||
}, | ||
icon() { | ||
return this.splitButton.icon; | ||
} | ||
} | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import SplitButtonAction from "./SplitButtonAction.vue"; | ||
import { pluginify } from "./../../util"; | ||
export default pluginify(SplitButtonAction); | ||
export { SplitButtonAction }; |
37 changes: 37 additions & 0 deletions
37
src/components/SplitButtonAuxiliary/SplitButtonAuxiliary.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<template> | ||
<fd-button | ||
class="fd-button sap-icon--slim-arrow-down" | ||
aria-label="More" | ||
:state="state" | ||
:type="type" | ||
:styling="styling" | ||
:compact="compact" | ||
v-bind="$attrs" | ||
v-on="$listeners" | ||
><slot | ||
/></fd-button> | ||
</template> | ||
|
||
<script> | ||
import FdButton from "./../Button/Button.vue"; | ||
export default { | ||
name: "FdSplitButtonAuxiliary", | ||
components: { FdButton }, | ||
inject: ["splitButton"], | ||
computed: { | ||
state() { | ||
return this.splitButton.state; | ||
}, | ||
type() { | ||
return this.splitButton.type; | ||
}, | ||
styling() { | ||
return this.splitButton.styling; | ||
}, | ||
compact() { | ||
return this.splitButton.disacompactbled; | ||
} | ||
} | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import SplitButtonAuxiliary from "./SplitButtonAuxiliary.vue"; | ||
import { pluginify } from "./../../util"; | ||
export default pluginify(SplitButtonAuxiliary); | ||
export { SplitButtonAuxiliary }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.