Giter Site home page Giter Site logo

sitedata / mechanical-ragger Goto Github PK

View Code? Open in Web Editor NEW

This project forked from oakstudios/mechanical-ragger

0.0 0.0 0.0 60.87 MB

Mechanical text ragging for the web

Home Page: https://oakstudios.github.io/mechanical-ragger/#essay

License: MIT License

JavaScript 18.88% TypeScript 81.12%

mechanical-ragger's Introduction

Mechanical Ragger

Demo

Installation

npm i @oakstudios/mechanical-ragger

Web Component

  1. Load the web component. Choose the option that best suits your needs:

    Using a script tag placed at the end of the body:

    <!-- this automatically registers the component in the window as mechanical-ragger -->
    <script src="https://unpkg.com/@oakstudios/[email protected]/web-component-auto-register.js"></script>

    OR importing the same auto-register function in JS:

    import "@oakstudios/mechanical-ragger/web-component-auto-register";

    OR registering the component manually:

    import MechanicalRagger from "@oakstudios/mechanical-ragger/web-component";
    
    customElements.define("mechanical-ragger", MechanicalRagger);
  2. Then add it to your HTML:

    <mechanical-ragger>
      Lorem ipsum dolor sit amet consectetur adipisicing elit.
    </mechanical-ragger>

React Component

import MechanicalRagger from "@oakstudios/mechanical-ragger/react";

export default () => {
  return <MechanicalRagger>Lorem ipsum dolor sit amet.</MechanicalRagger>;
};

Other Frameworks

While web components can be used in most any framework, if you'd like deep integration with the framework of your choosing, you can use src/web-component.js and src/react.jsx to reference in implementing mechanical-ragger elsewhere.

The npm package also exposes the MechanicalRaggerCore module that these use. eg:

import MechanicalRaggerCore from "@oakstudios/mechanical-ragger/core";

Options

--ragging-width

mechanical-ragger inherits the depth of the mechanical ragging from a CSS custom property. To set this to a value other than the default, apply the custom property anywhere in the DOM containing the mechanical-ragger.

/* Globally... */
body {
  --ragging-width: 3rem;
}

/* Or Locally */
mechanical-ragger:nth-child(1) {
  --ragging-width: 4rem;
}
mechanical-ragger:nth-child(2) {
  --ragging-width: 2rem;
}

Because this is a CSS custom property, you can change this value in the same place that you set the rest of your styles. The value will also respect other runtime conditions like media queries and application state.

mechanical-ragger {
  --ragging-width: 2rem;
}
/* Media Queries */
@media (min-width: 480px) {
  mechanical-ragger {
    --ragging-width: 3rem;
  }
}
/* User Preferences */
body.no-ragging mechanical-ragger {
  --ragging-width: 0px;
}

You can also use any css unit (ch, em, rem, vw, etc)

Best Practices

ℹ️ Tidying line-ends

You may hope for text lines to reach closer to the end of each line to make the ragging cleaner. HTML and CSS both offer tools to manage this.

In CSS:

mechanical-ragger {
  /* Insert hyphens according to browser hyphenation dictionaries */
  hyphens: auto;

  /* Or only inserts hyphens at the author's request */
  hyphens: manual;
}

With hyphens: manual, use the &shy; HTML entity in your text to suggest hyphenation breakpoints to the browser.

In HTML, the <wbr> tag can be used to suggest a word breakpoint without hyphenation.

⚠️ Browser handling of line-heights.

Chrome and other browsers do not allow for floating-point decimal line-heights. All line-heights are rounded to the nearest CSS pixel (px values that do not factor in screen pixel-density). To ensure that the ragging does not fall out of sync with the text it controls, opt for line-heights that evaluate to whole pixels.

Development

Package

npm run build in the root directory. The resulting modules are generated from the src/ directory, to the root directory. This is the structure used in the npm package.

Docs

cd into the docs/ directory, where you can interact with the create-react-app instance.

cd docs

npm run start

mechanical-ragger's People

Contributors

danielgamage avatar mikabusante avatar sskylar 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.