Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(NcActionButton): support menu styling #4724

Merged
merged 3 commits into from
Oct 31, 2023
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
10 changes: 9 additions & 1 deletion src/assets/action.scss
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
&__longtext {
cursor: pointer;
// allow the use of `\n`
white-space: pre-wrap;
white-space: pre-wrap !important;
}

&__name {
Expand All @@ -126,5 +126,13 @@
max-width: 100%;
display: inline-block;
}

&__menu-icon {
// Push to the right
margin-left: auto;
// Align with right end of the button
// This is the padding-right
margin-right: -$icon-margin;
}
}
}
75 changes: 43 additions & 32 deletions src/components/NcActionButton/NcActionButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,32 @@ This component is made to be used inside of the [NcActions](#NcActions) componen

```vue
<template>
<div style="display: flex; align-items: center;">
<NcActions>
<NcActionButton @click="showMessage('Delete')">
<template #icon>
<Delete :size="20" />
</template>
Delete
</NcActionButton>
<NcActionButton :close-after-click="true" @click="showMessage('Delete and close menu')">
<template #icon>
<Delete :size="20" />
</template>
Delete and close
</NcActionButton>
<NcActionButton :close-after-click="true" @click="focusInput">
<template #icon>
<Plus :size="20" />
</template>
Create
</NcActionButton>
<NcActionButton :disabled="true" @click="showMessage('Disabled')">
<template #icon>
<Delete :size="20" />
</template>
Disabled button
</NcActionButton>
</NcActions>
<input ref="input" />
</div>
<NcActions>
<NcActionButton @click="showMessage('Delete')">
<template #icon>
<Delete :size="20" />
</template>
Delete
</NcActionButton>
<NcActionButton :close-after-click="true" @click="showMessage('Delete and close menu')">
<template #icon>
<Delete :size="20" />
</template>
Delete and close
</NcActionButton>
<NcActionButton :is-menu="true">
<template #icon>
<Plus :size="20" />
</template>
Create
</NcActionButton>
<NcActionButton :disabled="true" @click="showMessage('Disabled')">
<template #icon>
<Delete :size="20" />
</template>
Disabled button
</NcActionButton>
</NcActions>
</template>
<script>
import Delete from 'vue-material-design-icons/Delete'
Expand All @@ -69,9 +66,6 @@ This component is made to be used inside of the [NcActions](#NcActions) componen
showMessage(msg) {
alert(msg)
},
focusInput() {
this.$nextTick(() => this.$refs.input.focus())
},
},
}
</script>
Expand Down Expand Up @@ -217,13 +211,17 @@ export default {
<!-- default text display -->
<span v-else class="action-button__text">{{ text }}</span>

<!-- right arrow icon when there is a sub-menu -->
<ChevronRightIcon v-if="isMenu" class="action-button__menu-icon" />

<!-- fake slot to gather inner text -->
<slot v-if="false" />
</button>
</li>
</template>

<script>
import ChevronRightIcon from 'vue-material-design-icons/ChevronRight.vue'
import ActionTextMixin from '../../mixins/actionText.js'

/**
Expand All @@ -232,6 +230,9 @@ import ActionTextMixin from '../../mixins/actionText.js'
export default {
name: 'NcActionButton',

components: {
ChevronRightIcon,
},
mixins: [ActionTextMixin],

props: {
Expand All @@ -242,13 +243,23 @@ export default {
type: Boolean,
default: false,
},

/**
* aria-hidden attribute for the icon slot
*/
ariaHidden: {
type: Boolean,
default: null,
},

/**
* If this is a menu, a chevron icon will
* be added at the end of the line
*/
isMenu: {
type: Boolean,
default: false,
},
},
computed: {
/**
Expand Down
Loading