Coder Social home page Coder Social logo

nirtamir2 / solid-wrap-balancer Goto Github PK

View Code? Open in Web Editor NEW
21.0 2.0 0.0 3.71 MB

Simple Solid Component That Makes Titles More Readable. Port of react-wrap-balancer to Solid.js

Home Page: https://solid-wrap-balancer.vercel.app

License: MIT License

CSS 21.70% TypeScript 68.06% Shell 0.24% JavaScript 9.99%
readable solid-start solidjs text wrap-balancer

solid-wrap-balancer's Introduction

solid-wrap-balancer

solid-wrap-balancer

pnpm

npm version

This project is a port of react-wrap-balancer made by Shu Ding to solid.js

Simple Solid.js Component That Makes Titles More Readable

Example

Introduction

Solid Wrap Balancer is a simple Solid Component that makes your titles more readable in different viewport sizes. It improves the wrapping to avoid situations like a single word in the last line, makes the content more “balanced”:

Demo

Usage

To start using the library, install it to your project:

npm i solid-wrap-balancer
# or
yarn add solid-wrap-balancer
# or
pnpm add solid-wrap-balancer

And wrap text content with it:

import { Balancer } from "solid-wrap-balancer";

// ...

function Title() {
  return (
    <h1>
      <Balancer>My Awesome Title</Balancer>
    </h1>
  );
}

If you have multiple <Balancer> components used, it’s recommended (but optional) to also use <BalancerProvider> to wrap the entire app. This will make them share the re-balance logic and reduce the HTML size:

import { BalancerProvider } from "react-wrap-balancer";

// ...

function App() {
  return (
    <BalancerProvider>
      <MyApp />
    </BalancerProvider>
  );
}

For full documentation and use cases, please visit solid-wrap-balancer.vercel.app.

About

This project is a port of react-wrap-balancer made by Shu Ding to solid.js

Flow

If there is a context - it initialize it with realyout function. The Rebalancer init script for each element, but if it has a context - it uses its existing relayout function from the global window context. In SSR it inject hte ratio prop to the element. When the component load it search for the script and call it with the component id. The script is a resizable observer that try to rebalance text according to ratio. If Decrease it's with to see if the height changes and go to the smallest width that the height keep the same. When unmount / ratio changes - clean observer and element function.

solid-wrap-balancer's People

Contributors

nirtamir2 avatar

Stargazers

 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

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.