Skip to content
This repository has been archived by the owner on May 20, 2024. It is now read-only.

Commit

Permalink
Add gratuitous ragged edges look for feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksellen committed Dec 13, 2023
1 parent 480b101 commit b30fca1
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 1 deletion.
1 change: 1 addition & 0 deletions quasar.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module.exports = configure(function (ctx) {
'icons',
'detectMobileKeyboard',
'performance',
'directives',
],
css: [
'app.sass',
Expand Down
3 changes: 3 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
>
<LoadingProgress />
<RouterView />
<SvgFilters />
</template>

<script>
Expand Down Expand Up @@ -37,9 +38,11 @@ import { useUsersUpdater } from '@/users/queries'
import { useClearDataOnLogout, useTitleStatus } from '@/utils/composables'
import LoadingProgress from '@/topbar/components/LoadingProgress.vue'
import SvgFilters from '@/utils/components/SvgFilters.vue'
export default {
components: {
SvgFilters,
LoadingProgress,
},
setup () {
Expand Down
4 changes: 3 additions & 1 deletion src/activities/components/ActivityFeedbackItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<QCard
ref="itemRef"
:class="{ highlight: isHighlighted }"
class="overflow-hidden"
>
<div
v-if="bannerImageURL"
Expand Down Expand Up @@ -31,7 +32,8 @@
</QCardSection>
<QCardSection
v-if="activityType"
:style="{ backgroundColor: lighten(activityType.colour, 80) }"
v-ragged-edges
:style="{ background: `linear-gradient(170deg, ${lighten(activityType.colour, 75)}, ${lighten(activityType.colour, 85)})` }"
>
<div class="row no-wrap">
<QIcon
Expand Down
5 changes: 5 additions & 0 deletions src/boot/directives.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { raggedEdgesDirective } from '@/utils/svgUtils'

export default ({ app }) => {
app.directive('ragged-edges', raggedEdgesDirective)
}
56 changes: 56 additions & 0 deletions src/utils/components/SvgFilters.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<template>
<svg
xmlns="http://www.w3.org/2000/svg"
height="0"
width="0"
>
<defs>
<filter
v-for="variant in variants"
:id="`ragged-edges-${variant}`"
:key="variant"
>
<feTurbulence
id="turbulence"
type="fractalNoise"
baseFrequency="0.01"
numOctaves="4"
result="main"
:seed="variant"
/>
<feDisplacementMap
id="displacement"
in="SourceGraphic"
in2="main"
result="main"
scale="8"
/>
<feGaussianBlur stdDeviation="1" />
<feComponentTransfer result="main">
<feFuncA
type="gamma"
amplitude="50"
exponent="5"
/>
</feComponentTransfer>
<feComposite
in="SourceGraphic"
in2="main"
operator="over"
/>
</filter>
</defs>
</svg>
</template>

<script setup>
import { raggedEdgeVariations } from '@/utils/svgUtils'
const variants = Array.from({ length: raggedEdgeVariations }, (_, i) => i + 1)
const styleSheet = new CSSStyleSheet()
for (const variant of variants) {
styleSheet.insertRule(`.ragged-edges-${variant} { filter: url(#ragged-edges-${variant})}`)
}
document.adoptedStyleSheets.push(styleSheet)
</script>
16 changes: 16 additions & 0 deletions src/utils/svgUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,19 @@ function getRootDefs () {
export function addDefinition (definition) {
getRootDefs().appendChild(definition)
}

function randomInt (min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min
}

export const raggedEdgeVariations = 5

function getRaggedEdgesClassName () {
return `ragged-edges-${randomInt(1, raggedEdgeVariations)}`
}

export const raggedEdgesDirective = {
mounted (el) {
el.classList.add(getRaggedEdgesClassName())
},
}

0 comments on commit b30fca1

Please sign in to comment.