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

Add dynamic file extension icons to the MediaManager #1061

Merged

Conversation

damsfx
Copy link
Contributor

@damsfx damsfx commented Feb 22, 2024

This PR add dynamic icons for files that have no preview in thumbnails and large thumbnails views.
This icon show the file extension in a colored label.
List mode view is unchanged.

Before :
image
image

After :
image
image

@LukeTowers
Copy link
Member

@damsfx this looks great! Could you make the new file icons the same size as the old ones though? I don't think they need to be made as big as the thumbnail previews; it helps differentiate them.

@LukeTowers LukeTowers added enhancement PRs that implement a new feature or substantial change needs response Issues/PRs where a maintainer is awaiting a response from the submitter labels Feb 26, 2024
@damsfx
Copy link
Contributor Author

damsfx commented Feb 26, 2024

@LukeTowers The icons size have been adjust to best match original size.
The dynamic icons are only slightly larger, to make the labels easier to read.

image

image

@LukeTowers LukeTowers added this to the 1.2.5 milestone Mar 1, 2024
@LukeTowers
Copy link
Member

One final request @damsfx, would it make sense to also add this to the preview sidebar when the file is selected?

@damsfx
Copy link
Contributor Author

damsfx commented Mar 4, 2024

One final request @damsfx, would it make sense to also add this to the preview sidebar when the file is selected?

Done @LukeTowers .

image

@bennothommo
Copy link
Member

bennothommo commented Mar 5, 2024

I love this, @damsfx - really good work!

@WebVPF
Copy link
Contributor

WebVPF commented Mar 5, 2024

Wouldn't it be better to specify the color via CSS?

Delete:

$colorsByExtension = [
    '#B73FD9' => ['css', 'less', 'scss'],
    '#EA9B47' => ['html', 'xml'],
    '#A9A9A9' => ['js', 'json'],
    '#E30713' => ['pdf'],
    '#248BD0' => ['txt'],
    '#F29200' => ['ai'],
    '#F9B234' => ['eps'],
    '#2DAAE2' => ['psd'],
    '#C4CA10' => ['ttf', 'otf', 'woff', 'woff2'],
    '#0F70B7' => ['doc', 'docx', 'rtf', 'odt'],
    '#3BAA34' => ['csv', 'ods', 'xls', 'xlsx'],
    '#D04526' => ['odp', 'ppt', 'pptx'],
    '#363A56' => ['rar', 'tar', 'zip'],
    '#576D7E' => ['default'], // Default color
];

$labelColor = '#576D7E'; // Default color
foreach ($colorsByExtension as $color => $extensions) {
    if (in_array($extension, $extensions)) {
        $labelColor = $color;
        break;
    }
}

Change Color label by adding class="label-file-ext file-<?= $extension ?>" attribute and removing inline styles:

<!-- Colour label -->
<path class="label-file-ext file-<?= $extension ?>" d="M203.125,203.125c0,4.297 -3.516,7.813 -7.813,7.813l-171.875,-0c-4.296,-0 -7.812,-3.516 -7.812,-7.813l-0,-78.125c-0,-4.297 3.516,-7.813 7.812,-7.813l171.875,0.001c4.297,-0.001 7.813,3.515 7.813,7.812l0,78.125Z" />

Add to CSS:

.label-file-ext {
    fill: #576D7E; /* Default color */
    fill-rule: nonzero;
}
.file-css,
.file-less,
.file-scss {
    fill: #B73FD9;
}
.file-html,
.file-xml {
    fill: #EA9B47;
}
.file-js,
.file-json {
    fill: #A9A9A9;
}
.file-pdf {
    fill: #E30713;
}
.file-txt {
    fill: #248BD0;
}
.file-ai {
    fill: #F29200;
}
.file-eps {
    fill: #F9B234;
}
.file-psd {
    fill: #2DAAE2;
}
.file-ttf,
.file-otf,
.file-woff,
.file-woff2 {
    fill: #C4CA10;
}
.file-doc,
.file-docx,
.file-rtf,
.file-odt {
    fill: #0F70B7;
}
.file-csv,
.file-ods,
.file-xls,
.file-xlsx {
    fill: #3BAA34;
}
.file-odp,
.file-ppt,
.file-pptx {
    fill: #D04526;
}
.file-rar,
.file-tar,
.file-zip {
    fill: #363A56;
}

@LukeTowers
Copy link
Member

Oooh, that's even better @WebVPF! @damsfx are you able to make that change? Then I think it should be good to merge. Looking fantastic!

@damsfx
Copy link
Contributor Author

damsfx commented Mar 5, 2024

@LukeTowers @WebVPF All svg styles moved to css.

@LukeTowers LukeTowers added Status: Completed and removed needs response Issues/PRs where a maintainer is awaiting a response from the submitter labels Mar 6, 2024
@LukeTowers LukeTowers changed the title Mediamanager add dynamic file icons Add dynamic file extension icons to the MediaManager Mar 6, 2024
@LukeTowers LukeTowers merged commit 9e8c043 into wintercms:develop Mar 6, 2024
10 checks passed
@damsfx damsfx deleted the mediamanager-dynamic-file-icons branch March 6, 2024 13:53
@damsfx
Copy link
Contributor Author

damsfx commented Mar 6, 2024

@LukeTowers @bennothommo @WebVPF Thanks for your help and feedback on this little addition to WinterCMS.

@LukeTowers
Copy link
Member

@damsfx thanks for the contribution! I love seeing all the extra little bits of polish that people add, it brings me joy to see as I interact with Winter on various client sites :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement PRs that implement a new feature or substantial change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants