Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This one just screams <braille-string> Web Component #1

Open
Danny-Engelman opened this issue Jul 11, 2024 · 0 comments
Open

This one just screams <braille-string> Web Component #1

Danny-Engelman opened this issue Jul 11, 2024 · 0 comments

Comments

@Danny-Engelman
Copy link

Danny-Engelman commented Jul 11, 2024

In a Web Component you can scope all your CSS and JS so you don't have any global dependencies.
The user then loads just one JS file defining the Web Component, and does not have to use DIV or classnames

Just a quick proof of concept (not refactoring JS and CSS):

JSFiddle: https://jsfiddle.net/WebComponents/yv6scarL/

<link href="https://evoluteur.github.io/braille-tools/css/braille-big.css" rel="stylesheet" type="text/css">
<script src="https://evoluteur.github.io/braille-tools/braille-tools.js" type="text/javascript" charset="utf-8"></script>

<braille-string>Hello World!</braille-string>
<braille-string>I can write Web Components</braille-string>

<script>
  customElements.define("braille-string", class extends HTMLElement {
    connectedCallback() {
      const braille = char => Object.assign(document.createElement("div"), {
        className: `br br-${char}`
      })
      this.render = (txt) => this.replaceWith(...txt.split("").map(braille));
      setTimeout(() => this.render(this.innerHTML)); // wait till innerHTML is parsed
    }
  });
</script>

Note: Every Braille character is a six bit value, so a PNG with all characters is not required, create them 6 dots dynamically

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant