All Projects → diegohaz → Singel

diegohaz / Singel

Licence: mit
Single Element Pattern

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Singel

Linter Farch
Make sure the filenames stay the same, control them! 👁
Stars: ✭ 101 (-75%)
Mutual labels:  linter, cli
Undercover
Actionable code coverage - detects untested code blocks in recent changes
Stars: ✭ 574 (+42.08%)
Mutual labels:  linter, cli
Lintly
Automated GitHub PR code reviewer for Python, JavaScript, CSS, and more.
Stars: ✭ 91 (-77.48%)
Mutual labels:  linter, cli
Eyo
🦔 CLI for restoring the letter «ё» (yo) in russian texts
Stars: ✭ 119 (-70.54%)
Mutual labels:  linter, cli
Protolint
A pluggable linter and fixer to enforce Protocol Buffer style and conventions.
Stars: ✭ 142 (-64.85%)
Mutual labels:  linter, cli
Reviewdog
🐶 Automated code review tool integrated with any code analysis tools regardless of programming language
Stars: ✭ 4,541 (+1024.01%)
Mutual labels:  linter, cli
Eslint Watch
ESLint with simple watching capabilities
Stars: ✭ 159 (-60.64%)
Mutual labels:  linter, cli
Isort
A Python utility / library to sort imports.
Stars: ✭ 4,377 (+983.42%)
Mutual labels:  linter, cli
Pipupgrade
🗽 Like yarn outdated/upgrade, but for pip. Upgrade all your pip packages and automate your Python Dependency Management.
Stars: ✭ 391 (-3.22%)
Mutual labels:  cli
Bpfd
Framework for running BPF programs with rules on Linux as a daemon. Container aware.
Stars: ✭ 396 (-1.98%)
Mutual labels:  cli
Lynt
✨ A zero config JavaScript linter with support for Typescript, Flow, and React.
Stars: ✭ 390 (-3.47%)
Mutual labels:  linter
Credo
A static code analysis tool for the Elixir language with a focus on code consistency and teaching.
Stars: ✭ 4,144 (+925.74%)
Mutual labels:  linter
Isogram
Generate Google Analytics tracking code with any isogrammic parameters you like
Stars: ✭ 396 (-1.98%)
Mutual labels:  cli
Moro
Simple CLI tool for tracking work hours. Note: Heavy changes are happening in this repository. Docs might not be up to date, and things might be broken. Only the released NPM version is stable.
Stars: ✭ 390 (-3.47%)
Mutual labels:  cli
Cli
CLI tool for dead-simple serverless Docker deployments on managed Kubernetes services. A self-hosted PaaS. ⚡️
Stars: ✭ 400 (-0.99%)
Mutual labels:  cli
Beats
A command-line drum machine. Convert a beat notated in YAML into a *.wav file.
Stars: ✭ 389 (-3.71%)
Mutual labels:  cli
Cinf
Command line tool to view namespaces and cgroups, useful for low-level container prodding
Stars: ✭ 389 (-3.71%)
Mutual labels:  cli
Cli
The Aurelia 1 command line tool. Use the CLI to create projects, scaffold components, and bundle your app for release.
Stars: ✭ 401 (-0.74%)
Mutual labels:  cli
Args
Toolkit for building command line interfaces
Stars: ✭ 399 (-1.24%)
Mutual labels:  cli
Fire Hpp
Fire for C++: Create fully functional CLIs using function signatures
Stars: ✭ 395 (-2.23%)
Mutual labels:  cli

singel

Generated with nod NPM version Build Status Coverage Status

Single Element Pattern (Singel) is a set of rules/best practices to create consistent, reliable and maintainable components in React and other component-based libraries. This is based on the idea that the building blocks of an application should resemble as most as possible native HTML elements. Read full article

This repo is a CLI tool for checking whether React components conform to the Singel pattern.


Example

Installation

$ npm i -g singel

Usage

$ singel path/to/**/Component.js --ignore "path/to/**/ignored/Component.js"

Projects applying Singel

Feel free to send a PR adding your open source project

Rules

Render only one element

// bad - 2 elements
const Element = props => (
  <div {...props}>
    <span />
  </div>
);

// good
const Element = props => (
  <div {...props} />
);

// good - if Element is good
const Element2 = props => (
  <Element {...props} />
);

Never break the app

// good
const Element = props => (
  <div {...props} />
);

// bad - will break if getId wasn't provided
const Element = ({ getId, ...props }) => (
  <div id={getId()} {...props} />
);

// bad - will break if foo wasn't provided
const Element = ({ foo, ...props }) => (
  <div id={foo.bar} {...props} />
);

Render all HTML attributes passed as props

// good
const Element = props => (
  <div {...props} />
);

// bad - not rendering id
const Element = ({ id, ...props }) => (
  <div {...props} />
);

// good
const Element = ({ id, ...props }) => (
  <div id={id} {...props} />
);

Always merge the styles passed as props

// good
const Element = props => (
  <div {...props} />
);

// bad - not rendering className
const Element = ({ className, ...props }) => (
  <div {...props} />
);

// bad - not rendering style
const Element = ({ style, ...props }) => (
  <div {...props} />
);

// bad - replacing className instead of appending
const Element = props => (
  <div className="foo" {...props} />
);

// bad - replacing style instead of merging
const Element = props => (
  <div style={{ padding: 0 }} {...props} />
);

// good
const Element = ({ className, ...props }) => (
  <div className={`foo ${className}`} {...props} />
);

// good
const Element = ({ style, ...props }) => (
  <div style={{ padding: 0, ...style }} {...props} />
);

Add all the event handlers passed as props

// good
const Element = props => (
  <div {...props} />
);

// bad - not passing onClick
const Element = ({ onClick, ...props }) => (
  <div {...props} />
);

// bad - replacing onClick prop
const Element = props => (
  <div {...props} onClick={myFunction} />
);

// good
const Element = ({ onClick, ...props }) => (
  <div onClick={onClick} {...props} />
);

// good - it's ok to replace internal event handlers
const Element = props => (
  <div onClick={myFunction} {...props} />
);

// good - calling internal and prop
const callAll = (...fns) => (...args) => 
  fns.forEach(fn => fn && fn(...args));

const Element = ({ onClick, ...props }) => (
  <div onClick={callAll(myFunction, onClick)} {...props} />
);

FAQ

How to handle nested elements?

Say you have a Button element and you want to display a Tooltip when it's hovered. The first rule you'll want to break is rendering only one element. To handle that you have some options:

  • Use CSS pseudo-elements (such as :after and :before);
  • Create a non-singel element, which is fine;
  • Nest styles instead of components.

Here's an example of how you can accomplish tha latter one:

/* could also be CSS-in-JS */
.button {
  position: relative;
  /* more button css */
}

.button:hover .tooltip {
  display: block;
}

.button .tooltip {
  display: none;
  position: absolute;
  /* more tooltip css */
}
const Button = ({ className, ...props }) => (
  <button className={`button ${className}`} {...props} />
);

Button.Tooltip = ({ className, ...props }) => (
  <div className={`tooltip ${className}`} {...props} />
);

Usage:

<Button className="my-specific-button">
  <Button.Tooltip className="my-specific-tooltip">
    😁
  </Button.Tooltip>
  Hover me
</Button>

Both Button and Button.Tooltip are single elements. You have all the benefits you would have by nesting them, but now with complete control over Button.Tooltip from outside.

License

MIT © Diego Haz

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].