Skip to content

Commit

Permalink
Merge pull request #40677 from nextcloud/fix/wcag-files
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv authored Sep 28, 2023
2 parents 45cac16 + 87ef6e4 commit 2080d9d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
29 changes: 14 additions & 15 deletions apps/files/src/components/FileEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
<!-- Size -->
<td v-if="isSizeAvailable"
:style="{ opacity: sizeOpacity }"
:style="sizeOpacity"
class="files-list__row-size"
data-cy-files-list-row-size
@click="openDetailsIfAvailable">
Expand All @@ -164,7 +164,7 @@
<!-- Mtime -->
<td v-if="isMtimeAvailable"
:style="{ opacity: mtimeOpacity }"
:style="mtimeOpacity"
class="files-list__row-mtime"
data-cy-files-list-row-mtime
@click="openDetailsIfAvailable">
Expand Down Expand Up @@ -371,17 +371,17 @@ export default Vue.extend({
return formatFileSize(size, true)
},
sizeOpacity() {
// Whatever theme is active, the contrast will pass WCAG AA
// with color main text over main background and an opacity of 0.7
const minOpacity = 0.7
const maxOpacitySize = 10 * 1024 * 1024
const size = parseInt(this.source.size, 10) || 0
if (!size || size < 0) {
return minOpacity
return {}
}
return minOpacity + (1 - minOpacity) * Math.pow((this.source.size / maxOpacitySize), 2)
const ratio = Math.round(Math.min(100, 100 * Math.pow((this.source.size / maxOpacitySize), 2)))
return {
color: `color-mix(in srgb, var(--color-main-text) ${ratio}%, var(--color-text-maxcontrast))`,
}
},
mtime() {
Expand All @@ -391,22 +391,21 @@ export default Vue.extend({
return this.t('files_trashbin', 'A long time ago')
},
mtimeOpacity() {
// Whatever theme is active, the contrast will pass WCAG AA
// with color main text over main background and an opacity of 0.7
const minOpacity = 0.7
const maxOpacityTime = 31 * 24 * 60 * 60 * 1000 // 31 days
const mtime = this.source.mtime?.getTime?.()
if (!mtime) {
return minOpacity
return {}
}
// 1 = today, 0 = 31 days ago
const factor = (maxOpacityTime - (Date.now() - mtime)) / maxOpacityTime
if (factor < 0) {
return minOpacity
const ratio = Math.round(Math.min(100, 100 * (maxOpacityTime - (Date.now() - mtime)) / maxOpacityTime))
if (ratio < 0) {
return {}
}
return {
color: `color-mix(in srgb, var(--color-main-text) ${ratio}%, var(--color-text-maxcontrast))`,
}
return minOpacity + (1 - minOpacity) * factor
},
mtimeTitle() {
if (this.source.mtime) {
Expand Down
9 changes: 6 additions & 3 deletions apps/files/src/components/FilesListVirtual.vue
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,11 @@ export default Vue.extend({
.files-list__row {
&:hover, &:focus, &:active, &--active, &--dragover {
background-color: var(--color-background-dark);
// WCAG AA compliant
background-color: var(--color-background-hover);
// text-maxcontrast have been designed to pass WCAG AA over
// a white background, we need to adjust then.
--color-text-maxcontrast: var(--color-main-text);
> * {
--color-border: var(--color-border-dark);
}
Expand Down Expand Up @@ -475,8 +479,7 @@ export default Vue.extend({
.files-list__row-mtime,
.files-list__row-size {
// opacity varies with the size
color: var(--color-main-text);
color: var(--color-text-maxcontrast);
}
.files-list__row-size {
width: calc(var(--row-height) * 1.5);
Expand Down
4 changes: 2 additions & 2 deletions dist/files-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-main.js.map

Large diffs are not rendered by default.

0 comments on commit 2080d9d

Please sign in to comment.