Skip to content

Commit

Permalink
Merge pull request #5045 from nextcloud/enh/dark-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusknorr authored Sep 4, 2023
2 parents 05b2648 + d3515de commit 54cc67d
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 101 deletions.
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@nextcloud/router": "^2.1.2",
"@nextcloud/vue": "^7.12.4",
"blueimp-md5": "^2.19.0",
"chroma-js": "^2.4.2",
"dompurify": "^3.0.5",
"lodash": "^4.17.21",
"markdown-it": "^13.0.1",
Expand Down
25 changes: 17 additions & 8 deletions src/components/cards/CardItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@

<CardMenu v-if="!editing && compactMode" :card="card" class="right" />
</div>

<transition-group v-if="card.labels && card.labels.length"
name="zoom"
tag="ul"
Expand Down Expand Up @@ -200,27 +201,28 @@ export default {
@import './../../css/animations';
@import './../../css/variables';

@mixin dark-card {
border: 2px solid var(--color-border-dark);
box-shadow: none;
}

.card {
transition: box-shadow 0.1s ease-in-out;
box-shadow: 0 0 2px 0 var(--color-box-shadow);
transition: border 0.1s ease-in-out;
border-radius: var(--border-radius-large);
font-size: 100%;
background-color: var(--color-main-background);
margin-bottom: $card-spacing;
border: 2px solid var(--color-border);

&:deep(*) {
cursor: pointer;
}

body.dark &, body.theme--dark & {
border: 2px solid var(--color-border);
}

&:hover {
box-shadow: 0 0 5px 0 var(--color-box-shadow);
border: 2px solid var(--color-border-dark);
}
&.current-card {
box-shadow: 0 0 5px 1px var(--color-box-shadow);
border: 2px solid var(--color-primary-element);
}

.card-upper {
Expand Down Expand Up @@ -326,4 +328,11 @@ export default {
color: transparent;
}
}

@media (prefers-color-scheme: dark) {
.card {
@include dark-card;
}

}
</style>
76 changes: 43 additions & 33 deletions src/components/cards/badges/DueDate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,61 @@
-->

<template>
<div v-if="card" class="duedate">
<div v-if="card" class="duedate" :data-due-state="dueState">
<transition name="zoom">
<div v-if="card.duedate" :class="dueIcon" :title="absoluteDate">
<span>{{ relativeDate }}</span>
<div v-if="card.duedate" class="due" :title="absoluteDate">
<Clock v-if="overdue" :size="16" />
<ClockOutline v-else :size="16" />
<span v-if="!compactMode" class="due--label">{{ relativeDate }}</span>
</div>
</transition>
</div>
</template>

<script>
import { mapState } from 'vuex'
import moment from '@nextcloud/moment'
import Clock from 'vue-material-design-icons/Clock.vue'
import ClockOutline from 'vue-material-design-icons/ClockOutline.vue'

const DueState = {
Future: 'Future',
Next: 'Next',
Now: 'Now',
Overdue: 'Overdue',
}
export default {
name: 'DueDate',
components: {
Clock,
ClockOutline,
},
props: {
card: {
type: Object,
default: null,
},
},
computed: {
dueIcon() {
...mapState({
compactMode: state => state.compactMode,
}),
dueState() {
const days = Math.floor(moment(this.card.duedate).diff(this.$root.time, 'seconds') / 60 / 60 / 24)
if (days < 0) {
return 'icon-calendar due icon overdue'
return DueState.Overdue
}
if (days === 0) {
return 'icon-calendar-dark due icon now'
return DueState.Now
}
if (days === 1) {
return 'icon-calendar-dark due icon next'
return DueState.Next
}
return 'icon-calendar-dark due icon'

return DueState.Future
},
overdue() {
return this.dueState === DueState.Overdue
},
relativeDate() {
const diff = moment(this.$root.time).diff(this.card.duedate, 'seconds')
Expand All @@ -63,55 +85,43 @@ export default {
return moment(this.card.duedate).fromNow()
},
absoluteDate() {
return moment(this.card.duedate).format('L')
return moment(this.card.duedate).format('LLLL')
},
},
}
</script>

<style lang="scss" scoped>
.icon.due {
.due {
background-position: 4px center;
border-radius: 3px;
border-radius: var(--border-radius-large);
margin-top: 9px;
margin-bottom: 9px;
padding: 3px 4px;
padding-right: 0;
padding: 2px 8px;
font-size: 90%;
display: flex;
align-items: center;
opacity: .5;
flex-shrink: 1;
z-index: 2;

.icon {
background-size: contain;
[data-due-state='Overdue'] & {
color: var(--color-main-background);
background-color: var(--color-error-text);
}

&.overdue {
background-color: var(--color-error);
color: var(--color-primary-element-text);
opacity: .7;
padding: 3px 4px;
}
&.now {
[data-due-state='Now'] & {
color: var(--color-main-background);
background-color: var(--color-warning);
opacity: .7;
padding: 3px 4px;
}
&.next {
background-color: var(--color-background-dark);
opacity: .7;
padding: 3px 4px;
}

&::before,
span {
margin-left: 20px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}

.due--label {
margin-left: 4px;
}
}

@media print {
Expand Down
63 changes: 3 additions & 60 deletions src/mixins/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,76 +20,19 @@
*
*/

import chroma from 'chroma-js'

export default {
methods: {
hexToRgb(hex) {
const result = /^#?([A-Fa-f\d]{2})([A-Fa-f\d]{2})([A-Fa-f\d]{2})$/i.exec(hex)
if (result) {
return {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16),
}
}
return null
},
rgb2hls(rgb) {
// RGB2HLS by Garry Tan
// http://axonflux.com/handy-rgb-to-hsl-and-rgb-to-hsv-color-model-c
const r = rgb.r / 255
const g = rgb.g / 255
const b = rgb.b / 255
const max = Math.max(r, g, b)
const min = Math.min(r, g, b)
let h
let s
const l = (max + min) / 2

if (max === min) {
h = s = 0 // achromatic
} else {
const d = max - min
s = l > 0.5 ? d / (2 - max - min) : d / (max + min)
switch (max) {
case r:
h = (g - b) / d + (g < b ? 6 : 0)
break
case g:
h = (b - r) / d + 2
break
case b:
h = (r - g) / d + 4
break
}
h /= 6
}
return {
h, l, s,
}
},
textColor(hex) {

const rgb = this.hexToRgb(hex)
if (rgb === null) {
return '#000000'
}
const { l } = this.rgb2hls(rgb)

if (l < 0.5) {
return '#ffffff'
} else {
return '#000000'
}

return chroma(hex).get('lab.l') > 50 ? '#000000' : '#ffffff'
},
colorIsValid(hex) {

const re = /[A-Fa-f0-9]{6}/
if (re.test(hex)) {
return true
}
return false

},
randomColor() {
return Math.floor(Math.random() * (0xffffff + 1)).toString(16).padStart(6, '0')
Expand Down

0 comments on commit 54cc67d

Please sign in to comment.