new-component
Ian Cleary (iancleary)
Description
Welcome! This is a CLI for creating styled-components for React projects quickly.
Note: I've rewrote Josh W Comeau's new-component NPM package in Python 🐍 and adapted it to my preferences. It is an excellent project and you should check it out!
I didn't understand styled components at first. At the time of this writing, I'm looking to develop my understanding of CSS, upon the advice of Josh W Comeau's blog post "The styled-components Happy Path".
After you read that article, you'll gather that this CLI aims to combine the wisdom of Josh's templates with my personal preferences.
- Adding the
import styled from "styled-components"in the newcomponent.jsfile. - Adding a
styled.Wrappercomponent definition (and making it .the parent html element in the React Component'srenderfunction)
Quickstart
❯ pipx install new-component
❯ new-component --help
That will output the following:
Usage: new_component [OPTIONS] NAME
Creates an new component directory in a React project, with opinionated
defaults for styled-components.
See https://styled-components.com/ for more information.
Arguments:
NAME Name of component to create. [required]
Options:
-d, --directory TEXT The directory in which to create the component.
[default: src/components/]
-e, --extension TEXT The file extension for the created component files.
[default: js]
-v, --version Show the application's version and exit.
--install-completion Install completion for the current shell.
--show-completion Show completion for the current shell, to copy it or
customize the installation.
--help Show this message and exit.
Example Usage
The first and only argument is the name of the component to create.
❯ new-component Backdrop
Created a new Backdrop Component 💅 🚀!
/Users/iancleary/Personal/new-component/src/components/Test4
The path printed is the absolute path to new component folder.
It will very based upon your setup!
This command created two files:
src/components/Backdrop/index.js
src/components/Backdrop/Backdrop.js
The contents of the files will be as follows:
// `src/components/Backdrop/index.js`
export { default } from "./Backdrop"
// `src/components/Backdrop/Backdrop.js`
import React from "react"
import styled from "styled-components"
const Backdrop = ({children}) => {
return (
<Wrapper>
{children}
</Wrapper>
)
};
const Wrapper = styled.div`
/* CSS Goes Here */
`
export default Backdrop
Configuration
Configuration can be done through 3 different ways:
- Creating a global
settings.jsonin your home directory (~/.config/new-component/settings.json). - Creating a local
.new-component-config.jsonin your project's root directory. - Command-line arguments.
The resulting values are merged, with command-line values overwriting local values, and local values overwriting global ones.
API Reference
Directory
Controls the desired directory for the created component. Defaults to src/components
Usage:
Command line: --directory <value> or -d <value>
JSON config: { "directory": <value> }
File Extension
Controls the file extension for the created components. Can be either js (default) or jsx.
Usage:
Command line: --extension <value> or -e <value>
JSON config: { "extension": <value> }
Further information
I will likely evolve this CLI as I learn more; I'm on my way 😊
- Add different component types
- Promote better patterns to ensure CSS (single source of styles, Isolated CSS)
Thanks to Josh W Comeau's blog post "The styled-components Happy Path for starting my education! Again, it puts this README in perspective.
Enjoy quickly creating styled components 💅 🚀!
Contributing
I created this CLI for my opinionated uses and may not accept changes.
See CONTRIBUTING.md.
Metadata
Release files for new-component 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| new-component-0.6.0.tar.gz | 10.8 kB | Without provenance | Details for new-component-0.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| new_component-0.6.0-py3-none-any.whl | Python 3 | none | any | Details for new_component-0.6.0-py3-none-any.whl |
Total release size: 21.8 kB
Release files / new-component-0.6.0.tar.gz
| Download URL | new-component-0.6.0.tar.gz |
|---|---|
| Size | 10.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
41c86d7d6a72021c7a43430bbcabe4dff4da8000c96b0240f4f19458616071eb
|
|
BLAKE2b-256 checksum How to use checksums |
7a9e7e67bd531574a9c5d2c4ee40114fe2d12273b010fd251d02d2a23f30a88d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
pdm/2.6.1 CPython/3.11.3
|
Release files / new_component-0.6.0-py3-none-any.whl
| Download URL | new_component-0.6.0-py3-none-any.whl |
|---|---|
| Size | 11.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
10308a28cd0fa92b90e5144380ae9268153c5f4d8e59cdd067efa79c146e7bb6
|
|
BLAKE2b-256 checksum How to use checksums |
e44d9429f19247a98821cea921eeecb9e1ea63957b3a9b029f5957dcda16149b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
pdm/2.6.1 CPython/3.11.3
|
Security for new-component 0.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.