Giter VIP home page Giter VIP logo

Comments (5)

noerw avatar noerw commented on July 28, 2024

What do you mean by dynamic?

In general you need to override the width and max-width CSS properties on the .leaflet-sidebar selector.
As the sidebar style is responsive, you'd need to override it for multiple media queries.

This is the default style you'd need to override:

@media (min-width: 768px) and (max-width: 991px) {
    .leaflet-sidebar {
      width: 305px;
      max-width: 305px; } }
@media (min-width: 992px) and (max-width: 1199px) {
    .leaflet-sidebar {
      width: 390px;
      max-width: 390px; } }
@media (min-width: 1200px) {
    .leaflet-sidebar {
      width: 460px;
      max-width: 460px; } }

from leaflet-sidebar-v2.

noerw avatar noerw commented on July 28, 2024

If you want to change the width when a tab was clicked, you can register an event and adjust the sidebar style in JS:

sidebar.on('content', function (e) {
  const sidebarElement = document.querySelector('.leaflet-sidebar') 
  switch (e.id) {
    case 'smalltab': // your tab IDs
      sidebarElement.style.width = '200px'
      sidebarElement.style.maxWidth = '200px'
      break
    case 'largetab':
      sidebarElement.style.width = '600px'
      sidebarElement.style.maxWidth = '600px'
      break
  }
})

This does not respect responsiveness however.

from leaflet-sidebar-v2.

Janphr avatar Janphr commented on July 28, 2024

Hey,

when I do this, the tabs won't close anymore. Any idea how to solve that?

from leaflet-sidebar-v2.

noerw avatar noerw commented on July 28, 2024

@Janphr
With the approach outlined above, you need to remove the style again on the closing event.
Maybe a better approach would be to write CSS classes for each tab with the desired width, and toggle the classes in the content event. The following shows what I mean but is untested

.leaflet-sidebar:not(.collapsed).mypanel {
  width: 600px;
  max-width: 600px;
}
sidebar.on('content', e => {
  const sidebarElement = document.querySelector('.leaflet-sidebar')
  sidebarElement.classList.remove('all', 'the', 'panel ids', 'you', 'want', 'to', 'handle', 'here')
  sidebarElement.classList.add(e.id)
})

from leaflet-sidebar-v2.

Janphr avatar Janphr commented on July 28, 2024

Thanks for the quick response!
Just added:

        if (L.DomUtil.hasClass(this, 'active')) {
            let sidebar = document.querySelector('.leaflet-sidebar')
            sidebar.style.width = 40 + 'px'
            sidebar.style.maxWidth = 40 + 'px'
            this._sidebar.close();

to the onTabClick function, which works fine.

*Just no smooth transition anymore, so I'll check out your solution

from leaflet-sidebar-v2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.