Comments (11)
The next step is making a fork of this repo, cloning it locally, adding an option to https://github.com/fabiocaccamo/django-admin-interface/blob/main/admin_interface/models.py#L138 and adding the markup to https://github.com/fabiocaccamo/django-admin-interface/blob/main/admin_interface/templates/admin_interface/language_chooser.html
from django-admin-interface.
Some problem with the markdown
from django-admin-interface.
Hello @fabiocaccamo !
When I wrote the issue 314 I also realized that we could set the dropdown CSS style to keep the same design across different O.S.
Since I was trying to contribute to you and make an improved style on that component for my current projects I discovered that is a native component. It means the style depends on the OS.
from django-admin-interface.
Sources
- https://stackoverflow.com/questions/75552987/why-is-my-dropdown-list-showing-differently-on-phone-than-desktop-and-how-can-i
- https://html.spec.whatwg.org/multipage/rendering.html#native-appearance-2
- https://drafts.csswg.org/css-ui/#native-appearance
from django-admin-interface.
So I decided to develop a dropdown based on this sample to combine solutions to render always the same design.
from django-admin-interface.
2023-09-01.11.59.16.mp4
from django-admin-interface.
I believe it could be improved by the team and used on new releases...
Sharing codes
../templates/language_chooser.html
{% load static %}
<script src="{% static 'js/extra_base_site.js' %}"></script>
{% load admin_interface_tags %}
...
../css/extra_base_site.css
#logout-form button {
color: #747474;
}
#logout-form button:hover {
color: #333333;
}
.admin-interface .language-chooser {
display: inline-block;
position: unset !important;
}
.language-chooser-select-form select {
margin-top: -9px;
margin-left: -15px;
font-size: 11px;
font-weight: 300;
outline: none;
border: 0px;
border-style: none !important;
appearance: none !important;
-webkit-appearance: none;
-moz-appearance: none;
-ms-appearance: none;
color: #747474;
border-radius: 0 !important;
}
.language-chooser-select-form::before {
content: '/';
font-size: 11px;
font-weight: 300;
left: -17px;
color: #747474;
display: inline-block;
position: absolute;
}
.language-chooser-select-form::after {
content: '';
border-width: 5px;
border-style: solid;
border-color: transparent;
border-top-color: #ccc;
display: inline-block;
border-radius: 2px;
position: absolute;
right: -10px;
bottom: 10px;
}
.language-chooser-select-form select:hover {
color: #333333;
}
@media (max-width: 768px),
(max-width: 1024px) {
.language-chooser-select-form select {
margin-top: 0px !important;
margin-left: 0px !important;
}
.language-chooser-select-form::before {
left: -1px !important;
top: 5px !important;
}
}
.language-chooser-select-form .selector-options {
list-style: none;
width: 14px;
margin-left: -15px;
margin-top: -7px;
background: #fff;
color: #747474;
border-radius: 0 !important;
z-index: 9999;
position: fixed;
box-shadow:
rgba(0, 0, 0, 0.14) 0px 4px 8px,
rgba(0, 0, 0, 0.12) 0px 0px 2px;
}
.language-chooser-select-form .selector-options ul {
padding-inline: inherit;
margin-left: -15px;
}
.language-chooser-select-form .selector-options li {
display: flex;
width: 15px;
cursor: pointer;
transition: background 0.3s ease;
font-size: 11px;
font-weight: 300;
margin-left: -30px;
}
.language-chooser-select-form .selector-options li:hover {
color: #333333;
}
.active_language {
font-weight: 600 !important;
}
../js/extra_base_site.js
document.addEventListener('DOMContentLoaded', function () {
const get_elements = document.querySelectorAll('.language-chooser-select-form');
get_elements.forEach(form => {
const select = form.querySelector('select');
let isDropdownOpen = false; // Variável para rastrear o estado do dropdown
select.addEventListener('change', e => {
console.log('changed', e.target.value);
});
select.addEventListener('mousedown', e => {
if (window.innerWidth >= 420) {
e.preventDefault();
if (isDropdownOpen) {
// Se o dropdown estiver aberto, feche-o
closeDropdown();
} else {
const options = select.querySelectorAll('option');
const dropDown = document.createElement('ul');
dropDown.className = "selector-options";
options.forEach(option => {
const dropDownOption = document.createElement('li');
dropDownOption.textContent = option.textContent;
// Adicionar a classe "active" ao <li> correspondente ao <option> ativo
if (option.value === select.value) {
dropDownOption.classList.add('active_language');
}
dropDownOption.addEventListener('mousedown', (e) => {
e.stopPropagation();
select.value = option.value;
select.dispatchEvent(new Event('change'));
closeDropdown(); // Feche o dropdown após selecionar uma opção
});
dropDown.appendChild(dropDownOption);
});
select.parentNode.appendChild(dropDown);
// Defina o estado do dropdown como aberto
isDropdownOpen = true;
// Adicione um evento de clique ao documento para fechar o dropdown
document.addEventListener('click', clickOutsideDropdown);
}
}
});
// Função para fechar o dropdown
function closeDropdown() {
const dropDown = select.parentNode.querySelector('.selector-options');
if (dropDown) {
dropDown.remove();
isDropdownOpen = false;
document.removeEventListener('click', clickOutsideDropdown);
}
}
// Função para fechar o dropdown ao clicar fora dele
function clickOutsideDropdown(e) {
if (!select.parentNode.contains(e.target)) {
closeDropdown();
}
}
});
});
from django-admin-interface.
Hi @saymoncoppi,
I think many people, myself included, prefer native controls instead of custom ones.
Anyway, this is a good idea and I'm open to support a new language chooser control style: "Dropdown".
Feel free to submit a PR!
PS. In the CSS, the theme CSS variables should be used:
https://github.com/fabiocaccamo/django-admin-interface#add-theme-support-to-third-party-libraries
from django-admin-interface.
Hello @fabiocaccamo honestly I don't know which is the next step to take. Is it ok for you if we schedule a call to talk about it? Maybe you could teach me what should I do... feel free to call me any time
from django-admin-interface.
Here you can find also a step by step guide:
https://github.com/fabiocaccamo/django-admin-interface#testing
from django-admin-interface.
@saymoncoppi I close this issue because it's not my intention to implement a custom dropdown.
from django-admin-interface.
Related Issues (20)
- Fiedsets as tabs CSS issue HOT 6
- Unicode Characters Not Slugified Properly in Inlines Tabs HOT 1
- "support show_change_link with related modal" feature is missing since version 0.20.0 HOT 4
- Language chooser is broken with `prefix_default_language=False` HOT 2
- Filter Input Fields collapsing on different layouts HOT 1
- Adding Support for `django-rosetta` Package HOT 1
- TemplateDoesNotExist with use django-nested-admin HOT 2
- Bug in display of related links with autocomplete fields HOT 5
- django.db.utils.ProgrammingError: relation "admin_interface_theme" does not exist HOT 2
- Unnecessary warning for missing django.middleware.locale.LocaleMiddleware if using customized middleware HOT 4
- Enable possibility to use a static file as logo HOT 18
- Object of type Theme is not JSON serializable HOT 20
- The default View Site link not showing in the mobile version HOT 1
- Popup window freezes in Chrome after save HOT 4
- Django admin date_hierarchy linking is not working anymore HOT 6
- Related modal window includes the header. HOT 4
- Serving static files with Amazon S3 and signed querystring problem
- Multi tenancy support HOT 4
- missing check for show_inlines_as_tabs in template HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-admin-interface.