|
| 1 | +<!-- |
| 2 | + - SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 3 | + - SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | +--> |
| 5 | + |
| 6 | +<script setup lang="ts"> |
| 7 | +import { computed } from 'vue' |
| 8 | +import IconPlus from 'vue-material-design-icons/Plus.vue' |
| 9 | +
|
| 10 | +const props = defineProps<{ |
| 11 | + /** URL of the icon, painted as-is so the colors of the action are kept. */ |
| 12 | + icon?: string |
| 13 | + /** Color of the indicator; without one no indicator is rendered. */ |
| 14 | + color?: string |
| 15 | +}>() |
| 16 | +
|
| 17 | +// Escaped so a crafted path cannot break out of the url() token. |
| 18 | +const iconStyle = computed(() => ({ |
| 19 | + '--app-action-icon-url': `url("${(props.icon ?? '').replace(/["\\]/g, '\\$&')}")`, |
| 20 | +})) |
| 21 | +
|
| 22 | +const indicatorStyle = computed(() => ({ |
| 23 | + '--app-action-icon-indicator-color': props.color, |
| 24 | +})) |
| 25 | +</script> |
| 26 | + |
| 27 | +<template> |
| 28 | + <span class="app-action-icon"> |
| 29 | + <!-- @slot Icon to render instead of the `icon` URL, e.g. an inline icon component. --> |
| 30 | + <slot> |
| 31 | + <span |
| 32 | + v-if="icon" |
| 33 | + class="app-action-icon__img" |
| 34 | + :style="iconStyle" |
| 35 | + aria-hidden="true" /> |
| 36 | + </slot> |
| 37 | + <span |
| 38 | + v-if="color" |
| 39 | + class="app-action-icon__indicator" |
| 40 | + :style="indicatorStyle" |
| 41 | + aria-hidden="true"> |
| 42 | + <IconPlus /> |
| 43 | + </span> |
| 44 | + </span> |
| 45 | +</template> |
| 46 | + |
| 47 | +<style scoped lang="scss"> |
| 48 | +.app-action-icon { |
| 49 | + // Consumers size the icon through --app-action-icon-size, see AppMenuItem. |
| 50 | + --app-action-icon-glyph-size: calc(var(--app-action-icon-size, calc(var(--default-grid-baseline) * 12)) * 0.8); |
| 51 | + position: relative; |
| 52 | + box-sizing: border-box; |
| 53 | + display: flex; |
| 54 | + align-items: center; |
| 55 | + justify-content: center; |
| 56 | + width: var(--app-action-icon-size, calc(var(--default-grid-baseline) * 12)); |
| 57 | + height: var(--app-action-icon-size, calc(var(--default-grid-baseline) * 12)); |
| 58 | + transform: scale(var(--app-icon-scale, 1)); |
| 59 | + transition: transform var(--animation-quick) ease-out; |
| 60 | +
|
| 61 | + @media (prefers-reduced-motion: reduce) { |
| 62 | + transition: none; |
| 63 | + } |
| 64 | +
|
| 65 | + &__img { |
| 66 | + width: var(--app-action-icon-glyph-size); |
| 67 | + height: var(--app-action-icon-glyph-size); |
| 68 | + background: var(--app-action-icon-url) center / contain no-repeat; |
| 69 | + } |
| 70 | +
|
| 71 | + // Slotted icon components ship their own SVG dimensions. |
| 72 | + :deep(.material-design-icon) { |
| 73 | + width: var(--app-action-icon-glyph-size); |
| 74 | + height: var(--app-action-icon-glyph-size); |
| 75 | +
|
| 76 | + svg { |
| 77 | + width: 100%; |
| 78 | + height: 100%; |
| 79 | + } |
| 80 | + } |
| 81 | +
|
| 82 | + &__indicator { |
| 83 | + --app-action-icon-indicator-size: max(12px, calc(var(--app-action-icon-size, calc(var(--default-grid-baseline) * 12)) * 0.36)); |
| 84 | + position: absolute; |
| 85 | + inset-block-end: 0; |
| 86 | + inset-inline-end: 0; |
| 87 | + display: flex; |
| 88 | + align-items: center; |
| 89 | + justify-content: center; |
| 90 | + width: var(--app-action-icon-indicator-size); |
| 91 | + height: var(--app-action-icon-indicator-size); |
| 92 | + border-radius: 50%; |
| 93 | + background-color: var(--app-action-icon-indicator-color); |
| 94 | + // Separates the indicator from the icon underneath. |
| 95 | + border: 2px solid var(--color-main-background); |
| 96 | + box-sizing: content-box; |
| 97 | + // The indicator color is app-provided and saturated, so the glyph on top |
| 98 | + // of it cannot follow the theme text color. |
| 99 | + color: #fff; |
| 100 | +
|
| 101 | + :deep(svg) { |
| 102 | + width: 100%; |
| 103 | + height: 100%; |
| 104 | + } |
| 105 | + } |
| 106 | +} |
| 107 | +</style> |
0 commit comments