Coder Social home page Coder Social logo

milahu / svelte-layout-resizable Goto Github PK

View Code? Open in Web Editor NEW
28.0 4.0 4.0 55 KB

resizable layout component for svelte

Home Page: https://milahu.github.io/svelte-layout-resizable/demo/demo.html

License: Creative Commons Zero v1.0 Universal

Svelte 100.00%
svelte sveltejs svelte-components svelte-component vanillajs layout splitter

svelte-layout-resizable's Introduction

svelte-layout-resizable

resizable layout component for svelte

live demo

status

⚠️ deprecated in favor of

  • split - utilities for resizeable split views
  • areas - A Vue.js Blender style area manager to create custom layouts

usage

in your App.svelte add

<script>
  import L from 'svelte-layout-resizable';
</script>
<L row>
  <L>cell 1 in row</L>
  <L column>
    <L>cell 2.1 in column</L>
    <L>cell 2.2 in column</L>
    <L>cell 2.3 in column</L>
  </L>
  <L>cell 3 in row</L>
</L>

result:

screenshot of svelte-layout-resizable demo

<L row> is a broad container with css flex-direction: row

<L column> is a tall container with css flex-direction: column

if you dont like the <L> syntax
you can do import Layout from 'svelte-layout-resizable';
and use <Layout>cell</Layout>

style

the component defines only a minimal style
to implement containers and resize-handles

most users want to add style to their App.svelte, like

<style>
  /* layout */
  :global(body) {
    /* use full window size */
    padding: 0;
  }
  :global(.layout-cell>.middle>.center) {
    /* content cell: add scrollbars when needed */
    overflow: auto;
  }
  :global(.layout-cell>*>.frame) {
    /* frame color and border */
    /*background-color: #f4f4f4;*/
    border: solid 0.5px #a8a8a8;
  }
  :global(.layout-cell>*, .layout-cell>*>.frame) {
    /* frame size
       larger frames are better acccessible (touchscreen) */
    flex-basis: 2.5px !important;
  }
  /* use css classes on cells like
     <L class="overflow-hidden">....</L> */
  :global(.layout-cell>.middle>.center.overflow-hidden) {
    overflow: hidden !important;
  }
  /* use css classes on containers like
     <L row class="custom-row-container">....</L> */
  :global(.layout-row.custom-row-container) {
    color: orange;
  }
</style>

related

todo

  • avoid changing body style?
    only 'stop selecting text' in layout containers?

  • fix resize bug with many cells
    like a 3x3 layout
    in the center container

  • fix newStyle.marginLeft and newStyle.marginTop

  • allow to hide/deactivate resize handles
    on the outside of a class="root" container (better: find root container automatically)

  • allow resize from corner handles?

  • imitate goldenlayout.js and qt dockable widgets
    maybe as a separate node package, keep it small

    • allow to drag/move and dock cells to other containers

    • allow to expand one cell over the root layout

  • add a tab widget? out of scope?
    we already have svelte-tabs

  • support 'live resize' of layout
    con: need more CPU/GPU = debounce to like 10 FPS

  • beforeUpdate or onMount
    calculate sizes of all cells
    so when we have

    <L>
      <L s="0.6">1</L>
      <L>2</L>
    </L>
    

    then cell 2 should have size 0.4
    and not what css-flex suggests
    based on content size
    or did we use flex wrong?

  • check bounds on resize
    eventually shrink more cells

  • verify overflow on resize
    avoid unnecessary scrollbars

license

license is creative commons zero 1.0

svelte-layout-resizable's People

Contributors

milahu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

svelte-layout-resizable's Issues

doesnot work on SvelteKit

howto implement on sveltekit,? i try without success...

<script>
	import L from '$lib/components/Layout.svelte';
</script>

<L row>
	<L>cell 1 in row</L>
	<L column>
		<L>cell 2.1 in column</L>
		<L>cell 2.2 in column</L>
		<L>cell 2.3 in column</L>
	</L>
	<L>cell 3 in row</L>
</L>

css flex is too slow for live resize

to resize two of N cells in a flex layout, we must set the flex-size for all N cells
which is unnecessary (N-2 cells keep their size) and expensive (layout repaint?)

but we want to keep the flex layout
so on window resize, our layout keeps its proportions
(is this possible without flex?)

possible solution: use a "hybrid" approach.
on resize start, convert the flex layout to a non-flex layout = divs with fixed pixel sizes
on resize, change size only for 2 cells
after resize (or on mouseleave), convert back to flex layout

other solution: debounce the mousemove handler to a lower frame rate, like 10 FPS
so at least we waste less CPU time on resize

todo: how exactly does goldenlayout.js work?
its an older project, so probably they do not use css flex
good old html tables layout? display: inline-block? position: absolute? float?

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.